Skip to main content

Image

Image

A binary image structure containing pixel data and dimensions. More…

#include <Image.hpp>

Public Functions

Name
Image() =default
Default constructor creates an empty image.
Image(std::vector< uint8_t > pixel_data, ImageSize image_size)
Constructs an image with specified data and size.
Image(ImageSize image_size)
Constructs an image with specified dimensions, initialized to zero.
uint8_t at(int row, int col) const
Gets the pixel value at the specified coordinates.
void set(int row, int col, uint8_t value)
Sets the pixel value at the specified coordinates.
size_t pixel_count() const
Gets the total number of pixels in the image.
bool empty() const
Checks if the image is empty (no pixels).

Public Attributes

Name
std::vector< uint8_t > data
Pixel data in row-major order (0 = background, non-zero = foreground).
ImageSize size
Image dimensions (width and height).

Detailed Description

struct Image;

A binary image structure containing pixel data and dimensions.

Note: Data Layout: ROW-MAJOR ORDER

  • Memory layout: [row0_col0, row0_col1, …, row0_colW-1, row1_col0, row1_col1, …]
  • Index formula: pixel(row, col) = data[row * width + col]
  • Iterating through data linearly processes all columns of row 0, then row 1, etc.

This struct encapsulates a binary image represented as a 1D vector of uint8_t values along with its dimensions. The pixel data is stored in row-major order, meaning that pixels are stored row by row, with each row’s pixels stored contiguously.

For an image with width W and height H, the pixel at position (row, col) can be accessed at index: row * width + col

Public Functions Documentation

function Image

Image() =default

Default constructor creates an empty image.

function Image

inline Image(
    std::vector< uint8_t > pixel_data,
    ImageSize image_size
)

Constructs an image with specified data and size.

Parameters:

  • pixel_data Image pixel data in row-major order
  • image_size Image dimensions

Precondition:

  • pixel_data.size() must equal image_size.width * image_size.height
  • image_size.width and image_size.height must be greater than 0

function Image

inline explicit Image(
    ImageSize image_size
)

Constructs an image with specified dimensions, initialized to zero.

Parameters:

  • image_size Image dimensions

Precondition: image_size.width and image_size.height must be greater than 0

function at

inline uint8_t at(
    int row,
    int col
) const

Gets the pixel value at the specified coordinates.

Parameters:

  • row Row index (0-based)
  • col Column index (0-based)

Return: uint8_t Pixel value at (row, col)

Precondition:

  • row must be in range [0, size.height)
  • col must be in range [0, size.width)

function set

inline void set(
    int row,
    int col,
    uint8_t value
)

Sets the pixel value at the specified coordinates.

Parameters:

  • row Row index (0-based)
  • col Column index (0-based)
  • value Pixel value to set

Precondition:

  • row must be in range [0, size.height)
  • col must be in range [0, size.width)

function pixel_count

inline size_t pixel_count() const

Gets the total number of pixels in the image.

Return: size_t Total pixel count (width * height), or 0 if image is empty

function empty

inline bool empty() const

Checks if the image is empty (no pixels).

Return: bool True if the image has no pixels, false otherwise

Public Attributes Documentation

variable data

std::vector< uint8_t > data;

Pixel data in row-major order (0 = background, non-zero = foreground).

variable size

ImageSize size;

Image dimensions (width and height).


Updated on 2026-11-13 at 20:25:39 +0000