|
CGVIS Utils
|
#include <Image.h>
Public Member Functions | |
| Image (const Vec4 &color) | |
| Construct a 1×1 RGBA image initialized from a color in [0,1]. | |
| Image (uint32_t width=100, uint32_t height=100, uint8_t componentCount=4) | |
| Construct an empty image with given geometry and channel count. | |
| Image (uint32_t width, uint32_t height, uint8_t componentCount, std::vector< uint8_t > data) | |
Construct from raw data (moves or copies data). | |
| void | multiply (const Vec4 &color) |
| Component‑wise multiply by a color; upgrades RGB→RGBA if needed. | |
| void | generateAlpha (uint8_t alpha=255) |
Ensure an alpha channel exists and set it to alpha for all pixels. | |
| void | generateAlphaFromLuminance () |
| Create or overwrite alpha from luminance of RGB. | |
| size_t | computeIndex (uint32_t x, uint32_t y, uint8_t component) const |
| Compute flat buffer index for a pixel component. | |
| uint8_t | getValue (uint32_t x, uint32_t y, uint8_t component) const |
| Read a component value at (x,y). | |
| uint8_t | sample (float x, float y, uint8_t component) const |
| Bilinear sample at normalized coordinates in [0,1]. | |
| uint8_t | getLumiValue (uint32_t x, uint32_t y) const |
| Luminance from components at (x,y). | |
| void | setValue (uint32_t x, uint32_t y, uint8_t component, uint8_t value) |
| Write a single component at (x,y). | |
| void | setValue (uint32_t x, uint32_t y, uint8_t value) |
| Set RGB (or first three channels) at (x,y) to a uniform value. | |
| void | setNormalizedValue (uint32_t x, uint32_t y, float value) |
| Set RGB at (x,y) from a normalized scalar in [0,1]. | |
| void | setNormalizedValue (uint32_t x, uint32_t y, uint8_t component, float value) |
| Set one component at (x,y) from a normalized scalar in [0,1]. | |
| std::string | toCode (const std::string &varName="myImage", bool padding=false) const |
| Emit C++ code that reconstructs this image. | |
| std::string | toACIIArt (bool bSmallTable=true) const |
| Render a coarse ASCII art representation of the image. | |
| Image | filter (const Grid2D &filter) const |
| Convolve image with a small 2D filter kernel (no borders). | |
| Image | toGrayscale () const |
| Convert to single‑channel grayscale using luminance. | |
| Image | crop (uint32_t blX, uint32_t blY, uint32_t trX, uint32_t trY) const |
| Crop a rectangle. | |
| Image | resample (uint32_t newWidth) const |
| Aspect‑preserving resample to a new width. | |
| Image | cropToAspectAndResample (uint32_t newWidth, uint32_t newHeight) const |
| Crop to match target aspect, then downsample to target size. | |
| Image | flipHorizontal () const |
| Flip rows (vertical mirror around horizontal axis). | |
| Image | flipVertical () const |
| Flip columns (horizontal mirror around vertical axis). | |
Static Public Member Functions | |
| static Image | genTestImage (uint32_t width, uint32_t height) |
| Generate a colored test pattern (RGB bands + luminance ramp). | |
Public Attributes | |
Dimensions and storage | |
| uint32_t | width |
| Image width in pixels. | |
| uint32_t | height |
| Image height in pixels. | |
| uint8_t | componentCount |
| Number of components per pixel (1–4). | |
| std::vector< uint8_t > | data |
| Interleaved pixel data of size width*height*componentCount. | |
| Image::Image | ( | const Vec4 & | color | ) |
Construct a 1×1 RGBA image initialized from a color in [0,1].
| color | RGBA color; each component is multiplied by 255 and cast to byte. |
| Image::Image | ( | uint32_t | width = 100, |
| uint32_t | height = 100, | ||
| uint8_t | componentCount = 4 ) |
Construct an empty image with given geometry and channel count.
| width | Width in pixels. |
| height | Height in pixels. |
| componentCount | Components per pixel (default 4 = RGBA). |
| Image::Image | ( | uint32_t | width, |
| uint32_t | height, | ||
| uint8_t | componentCount, | ||
| std::vector< uint8_t > | data ) |
Construct from raw data (moves or copies data).
| width | Width in pixels. |
| height | Height in pixels. |
| componentCount | Components per pixel. |
| data | Interleaved pixel data of size width*height*componentCount. |
| size_t Image::computeIndex | ( | uint32_t | x, |
| uint32_t | y, | ||
| uint8_t | component ) const |
Compute flat buffer index for a pixel component.
| x | Zero‑based x coordinate. |
| y | Zero‑based y coordinate. |
| component | Component index (0..componentCount-1). |
| Image Image::crop | ( | uint32_t | blX, |
| uint32_t | blY, | ||
| uint32_t | trX, | ||
| uint32_t | trY ) const |
Crop a rectangle.
| blX,blY | Bottom‑left inclusive pixel. |
| trX,trY | Top‑right exclusive pixel. |
| Image Image::cropToAspectAndResample | ( | uint32_t | newWidth, |
| uint32_t | newHeight ) const |
Crop to match target aspect, then downsample to target size.
| newWidth | Target width. |
| newHeight | Target height. |
Convolve image with a small 2D filter kernel (no borders).
| filter | Convolution kernel (must expose size and getValue()). |
| Image Image::flipHorizontal | ( | ) | const |
Flip rows (vertical mirror around horizontal axis).
| Image Image::flipVertical | ( | ) | const |
Flip columns (horizontal mirror around vertical axis).
| void Image::generateAlpha | ( | uint8_t | alpha = 255 | ) |
Ensure an alpha channel exists and set it to alpha for all pixels.
| alpha | Alpha value to assign when creating/filling the A channel. |
If the image has 3 channels, it is converted to RGBA by appending an alpha channel with the given value.
| void Image::generateAlphaFromLuminance | ( | ) |
Create or overwrite alpha from luminance of RGB.
If the image has 3 channels, converts to RGBA and sets A = 0.299*R + 0.587*G + 0.114*B. If already RGBA, only A is updated.
|
static |
Generate a colored test pattern (RGB bands + luminance ramp).
| width | Desired width. |
| height | Desired height. |
| uint8_t Image::getLumiValue | ( | uint32_t | x, |
| uint32_t | y ) const |
Luminance from components at (x,y).
| uint8_t Image::getValue | ( | uint32_t | x, |
| uint32_t | y, | ||
| uint8_t | component ) const |
Read a component value at (x,y).
| x | Zero‑based x. |
| y | Zero‑based y. |
| component | Component index (0..componentCount-1). |
| void Image::multiply | ( | const Vec4 & | color | ) |
Component‑wise multiply by a color; upgrades RGB→RGBA if needed.
| color | Color in [0,1] applied per channel. |
For 3‑channel images, a new alpha channel is added (set to 255*color.a) and componentCount becomes 4.
| Image Image::resample | ( | uint32_t | newWidth | ) | const |
Aspect‑preserving resample to a new width.
| newWidth | Target width; height is chosen to preserve aspect. |
| uint8_t Image::sample | ( | float | x, |
| float | y, | ||
| uint8_t | component ) const |
Bilinear sample at normalized coordinates in [0,1].
| x | Normalized x (0 at left, 1 at right). |
| y | Normalized y (0 at bottom, 1 at top). |
| component | Component index (0..componentCount-1). |
| void Image::setNormalizedValue | ( | uint32_t | x, |
| uint32_t | y, | ||
| float | value ) |
Set RGB at (x,y) from a normalized scalar in [0,1].
| x,y | Pixel coordinates. |
| value | Scalar mapped to 0..255 for channels 0..2. |
| void Image::setNormalizedValue | ( | uint32_t | x, |
| uint32_t | y, | ||
| uint8_t | component, | ||
| float | value ) |
Set one component at (x,y) from a normalized scalar in [0,1].
| x,y | Pixel coordinates. |
| component | Component index to write. |
| value | Scalar mapped to 0..255. |
| void Image::setValue | ( | uint32_t | x, |
| uint32_t | y, | ||
| uint8_t | component, | ||
| uint8_t | value ) |
Write a single component at (x,y).
| x,y | Pixel coordinates. |
| component | Component index to write. |
| value | Byte to store. |
| void Image::setValue | ( | uint32_t | x, |
| uint32_t | y, | ||
| uint8_t | value ) |
Set RGB (or first three channels) at (x,y) to a uniform value.
| x,y | Pixel coordinates. |
| value | Byte assigned to channels 0..2. |
| std::string Image::toACIIArt | ( | bool | bSmallTable = true | ) | const |
Render a coarse ASCII art representation of the image.
| bSmallTable | Select a shorter LUT (true) or a more detailed one (false). |
| std::string Image::toCode | ( | const std::string & | varName = "myImage", |
| bool | padding = false ) const |
Emit C++ code that reconstructs this image.
| varName | Variable name used in the generated snippet. |
| padding | If true, pad numeric literals for readability. |
| Image Image::toGrayscale | ( | ) | const |
Convert to single‑channel grayscale using luminance.
| uint8_t Image::componentCount |
Number of components per pixel (1–4).
| std::vector<uint8_t> Image::data |
Interleaved pixel data of size width*height*componentCount.
| uint32_t Image::height |
Image height in pixels.
| uint32_t Image::width |
Image width in pixels.