CGVIS Utils
Loading...
Searching...
No Matches
Image Class Reference

#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.

Constructor & Destructor Documentation

◆ Image() [1/3]

Image::Image ( const Vec4 & color)

Construct a 1×1 RGBA image initialized from a color in [0,1].

Parameters
colorRGBA color; each component is multiplied by 255 and cast to byte.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Image() [2/3]

Image::Image ( uint32_t width = 100,
uint32_t height = 100,
uint8_t componentCount = 4 )

Construct an empty image with given geometry and channel count.

Parameters
widthWidth in pixels.
heightHeight in pixels.
componentCountComponents per pixel (default 4 = RGBA).
Postcondition
Data buffer is allocated but contents are uninitialized.

◆ Image() [3/3]

Image::Image ( uint32_t width,
uint32_t height,
uint8_t componentCount,
std::vector< uint8_t > data )

Construct from raw data (moves or copies data).

Parameters
widthWidth in pixels.
heightHeight in pixels.
componentCountComponents per pixel.
dataInterleaved pixel data of size width*height*componentCount.

Member Function Documentation

◆ computeIndex()

size_t Image::computeIndex ( uint32_t x,
uint32_t y,
uint8_t component ) const

Compute flat buffer index for a pixel component.

Parameters
xZero‑based x coordinate.
yZero‑based y coordinate.
componentComponent index (0..componentCount-1).
Returns
Index into data.
Here is the caller graph for this function:

◆ crop()

Image Image::crop ( uint32_t blX,
uint32_t blY,
uint32_t trX,
uint32_t trY ) const

Crop a rectangle.

Parameters
blX,blYBottom‑left inclusive pixel.
trX,trYTop‑right exclusive pixel.
Returns
Cropped image with same component count.
Here is the call graph for this function:

◆ cropToAspectAndResample()

Image Image::cropToAspectAndResample ( uint32_t newWidth,
uint32_t newHeight ) const

Crop to match target aspect, then downsample to target size.

Parameters
newWidthTarget width.
newHeightTarget height.
Returns
Cropped and averaged image.
Here is the call graph for this function:

◆ filter()

Image Image::filter ( const Grid2D & filter) const

Convolve image with a small 2D filter kernel (no borders).

Parameters
filterConvolution kernel (must expose size and getValue()).
Returns
Filtered image (borders untouched / not written).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flipHorizontal()

Image Image::flipHorizontal ( ) const

Flip rows (vertical mirror around horizontal axis).

Returns
Flipped image with same dimensions.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flipVertical()

Image Image::flipVertical ( ) const

Flip columns (horizontal mirror around vertical axis).

Returns
Flipped image with same dimensions.
Here is the call graph for this function:

◆ generateAlpha()

void Image::generateAlpha ( uint8_t alpha = 255)

Ensure an alpha channel exists and set it to alpha for all pixels.

Parameters
alphaAlpha 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.

◆ generateAlphaFromLuminance()

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.

◆ genTestImage()

Image Image::genTestImage ( uint32_t width,
uint32_t height )
static

Generate a colored test pattern (RGB bands + luminance ramp).

Parameters
widthDesired width.
heightDesired height.
Returns
RGBA test image.
Here is the call graph for this function:

◆ getLumiValue()

uint8_t Image::getLumiValue ( uint32_t x,
uint32_t y ) const

Luminance from components at (x,y).

Returns
Grayscale value; for 1/2 channels uses first / average, for 3/4 channels uses 0.299R+0.587G+0.114B.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getValue()

uint8_t Image::getValue ( uint32_t x,
uint32_t y,
uint8_t component ) const

Read a component value at (x,y).

Parameters
xZero‑based x.
yZero‑based y.
componentComponent index (0..componentCount-1).
Returns
Byte value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ multiply()

void Image::multiply ( const Vec4 & color)

Component‑wise multiply by a color; upgrades RGB→RGBA if needed.

Parameters
colorColor 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.

◆ resample()

Image Image::resample ( uint32_t newWidth) const

Aspect‑preserving resample to a new width.

Parameters
newWidthTarget width; height is chosen to preserve aspect.
Returns
Resampled image.
Here is the call graph for this function:

◆ sample()

uint8_t Image::sample ( float x,
float y,
uint8_t component ) const

Bilinear sample at normalized coordinates in [0,1].

Parameters
xNormalized x (0 at left, 1 at right).
yNormalized y (0 at bottom, 1 at top).
componentComponent index (0..componentCount-1).
Returns
Interpolated byte value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setNormalizedValue() [1/2]

void Image::setNormalizedValue ( uint32_t x,
uint32_t y,
float value )

Set RGB at (x,y) from a normalized scalar in [0,1].

Parameters
x,yPixel coordinates.
valueScalar mapped to 0..255 for channels 0..2.
Here is the call graph for this function:

◆ setNormalizedValue() [2/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].

Parameters
x,yPixel coordinates.
componentComponent index to write.
valueScalar mapped to 0..255.
Here is the call graph for this function:

◆ setValue() [1/2]

void Image::setValue ( uint32_t x,
uint32_t y,
uint8_t component,
uint8_t value )

Write a single component at (x,y).

Parameters
x,yPixel coordinates.
componentComponent index to write.
valueByte to store.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setValue() [2/2]

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.

Parameters
x,yPixel coordinates.
valueByte assigned to channels 0..2.
Here is the call graph for this function:

◆ toACIIArt()

std::string Image::toACIIArt ( bool bSmallTable = true) const

Render a coarse ASCII art representation of the image.

Parameters
bSmallTableSelect a shorter LUT (true) or a more detailed one (false).
Returns
Multiline string with ASCII shading.
Here is the call graph for this function:

◆ toCode()

std::string Image::toCode ( const std::string & varName = "myImage",
bool padding = false ) const

Emit C++ code that reconstructs this image.

Parameters
varNameVariable name used in the generated snippet.
paddingIf true, pad numeric literals for readability.
Returns
A string containing valid C++ initialization code.
Here is the caller graph for this function:

◆ toGrayscale()

Image Image::toGrayscale ( ) const

Convert to single‑channel grayscale using luminance.

Returns
Grayscale image with componentCount = 1.
Here is the call graph for this function:

Member Data Documentation

◆ componentCount

uint8_t Image::componentCount

Number of components per pixel (1–4).

◆ data

std::vector<uint8_t> Image::data

Interleaved pixel data of size width*height*componentCount.

◆ height

uint32_t Image::height

Image height in pixels.

◆ width

uint32_t Image::width

Image width in pixels.


The documentation for this class was generated from the following files: