Skip to content

File include/brisk/graphics/Image.hpp


EImageError class

EImageError

Custom exception class for image-related errors.

This class derives from the standard runtime_error to provide specific error handling for image processing.


ImageFormat enum

enum class ImageFormat : uint16_t

Enumeration representing various image formats, combining pixel type and pixel format.


imageFormat function

constexpr ImageFormat imageFormat(PixelType type,
                                  PixelFormat format)

Combines PixelType and PixelFormat enumerations into an ImageFormat type.
Param type The pixel type (e.g., U8, U16, F32).
Param format The pixel format (e.g., RGB, RGBA, Greyscale).
Returns The combined ImageFormat value.


ImageFormat enum

enum class ImageFormat : uint16_t

Enumeration representing various image formats, combining pixel type and pixel format.


toPixelType function

constexpr PixelType toPixelType(ImageFormat format) noexcept

Extracts the PixelType from an ImageFormat.
Param format The ImageFormat value.
Returns The corresponding PixelType.


toPixelFormat function

constexpr PixelFormat
toPixelFormat(ImageFormat format) noexcept

Extracts the PixelFormat from an ImageFormat.
Param format The ImageFormat value.
Returns The corresponding PixelFormat.


pixelFormatCompatible function

constexpr bool
pixelFormatCompatible(PixelFormat requestedFormat,
                      PixelFormat actualFormat) noexcept

Checks if a requested PixelFormat is compatible with an actual PixelFormat.
Param requestedFormat The requested pixel format.
Param actualFormat The actual pixel format.
Returns True if compatible, false otherwise.


pixelTypeCompatible function

constexpr bool
pixelTypeCompatible(PixelType requestedType,
                    PixelType actualType) noexcept

Checks if a requested PixelType is compatible with an actual PixelType.
Param requestedType The requested pixel type.
Param actualType The actual pixel type.
Returns True if compatible, false otherwise.


imageFormatCompatible function

constexpr bool
imageFormatCompatible(ImageFormat requestedFormat,
                      ImageFormat actualFormat) noexcept

Checks if a requested ImageFormat is compatible with an actual ImageFormat.
Param requestedFormat The requested image format.
Param actualFormat The actual image format.
Returns True if compatible, false otherwise.


(unnamed) class

(unnamed struct at / src / include / brisk / graphics /
 Image.hpp : 190 : 13)

StridedData class

template <typename T> StridedData

Represents a strided data structure for accessing image data.
Template param T The data type of the pixel data (can be const or non-const).

data variable (StridedData::data)

T *data

Pointer to the pixel data.

byteStride variable (StridedData::byteStride)

int32_t byteStride

Stride in bytes between consecutive rows. Can be negative.

line function (StridedData::line)

T *line(int32_t y) const

Retrieves a pointer to the start of a given row.
Param y The row index.
Returns Pointer to the first pixel in the specified row.


convertPixels function

void convertPixels(PixelFormat dstFmt,
                   StridedData<uint8_t> dst,
                   PixelFormat srcFmt,
                   StridedData<const uint8_t> src,
                   Size size)

Converts pixel data between different formats.
Param dstFmt Destination pixel format.
Param dst Destination image data with stride.
Param srcFmt Source pixel format.
Param src Source image data with stride.
Param size The dimensions of the image.


AccessMode enum

enum class AccessMode

Defines access modes for image data.

R enumerator (AccessMode::R)

Read access.

W enumerator (AccessMode::W)

Write access.

RW enumerator (AccessMode::RW)

Read and write access.


ImageData class

template <typename T> ImageData

Represents image data with size, stride, and component count.
Template param T The data type of the image pixels (can be const or non-const).

data variable (ImageData::data)

T *data

Pointer to the pixel data.

size variable (ImageData::size)

Size size

Dimensions of the image.

byteStride variable (ImageData::byteStride)

int32_t byteStride

Stride in bytes between consecutive rows. Can be negative.

components variable (ImageData::components)

int32_t components

Number of color components per pixel.

operator StridedData<type-parameter-0-0> function (ImageData::operator StridedData<type-parameter-0-0>)

operator StridedData<T>() const

Implicit conversion to StridedData<T>.

ImageData<T> function (ImageData::ImageData<T>)

ImageData(T *data, Size size, int32_t byteStride,
          int32_t components)
    : data(data), size(size), byteStride(byteStride),
      components(components)

Constructs an ImageData object.
Param data Pointer to the pixel data.
Param size Image dimensions.
Param byteStride Byte stride between rows.
Param components Number of color components per pixel.

ImageData(const ImageData<std::remove_const_t<T>> &other)
  requires(std::is_const_v<T>)
    : data(other.data), size(other.size),
      byteStride(other.byteStride),
      components(other.components)

Conversion from ImageData<T> to ImageData<const T>.

to function (ImageData::to)

template <typename U> ImageData<U> to() const

Converts the image data to another type.
Template param U The target data type.
Returns Converted ImageData<U>.

copyFrom function (ImageData::copyFrom)

void copyFrom(const ImageData<const T> &src) const

Copies pixel data from another ImageData object.
Param src Source ImageData object.

subrect function (ImageData::subrect)

ImageData subrect(Rectangle rect) const

Extracts a subregion of the image.
Param rect The rectangle defining the subregion.
Returns A new ImageData object representing the subregion.

memoryWidth function (ImageData::memoryWidth)

int32_t memoryWidth() const

Computes the width in memory (in color components, not bytes).

memorySize function (ImageData::memorySize)

size_t memorySize() const

Computes the total memory size of the image in color components.

area function (ImageData::area)

size_t area() const

Computes the total number of pixels in the image.

byteSize function (ImageData::byteSize)

size_t byteSize() const

Computes the total memory size in bytes.

line function (ImageData::line)

T *line(int32_t y) const

Retrieves a pointer to the start of a given row.
Param y The row index.
Returns Pointer to the first pixel in the specified row.

pixel function (ImageData::pixel)

template <typename U = T>
U *pixel(int32_t x, int32_t y) const

Retrieves a pointer to a specific pixel.
Template param U Optional return type (defaults to T).
Param x X-coordinate of the pixel.
Param y Y-coordinate of the pixel.
Returns Pointer to the specified pixel.

LineIterator class (ImageData::LineIterator)

LineIterator

Iterator for traversing image rows.

lineIterator function (ImageData::lineIterator)

LineIterator lineIterator() const

Returns an iterator to the first row.

lineReverseIterator function (ImageData::lineReverseIterator)

LineIterator lineReverseIterator() const

Returns a reverse iterator to the last row.


MappedRegion class

MappedRegion

Represents a mapped region within an image.

origin variable (MappedRegion::origin)

Point origin

Origin point of the mapped region.

flags variable (MappedRegion::flags)

ImageMapFlags flags = ImageMapFlags::Default

Mapping flags.


PixelOf class (Internal::PixelOf)

template <ImageFormat format> PixelOf

template <ImageFormat format> PixelOf

ImageAccess class

template <ImageFormat ImageFmt, AccessMode Mode> ImageAccess

Provides controlled access to image data with specified format and access mode.
Template param ImageFmt The format of the image.
Template param Mode The access mode (read, write, or read-write).

FmtPixelFormat variable (ImageAccess::FmtPixelFormat)

constexpr static PixelFormat FmtPixelFormat =
    toPixelFormat(ImageFmt)

Pixel format and type information derived from ImageFmt.

ImageAccess<ImageFmt, Mode> function (ImageAccess::ImageAccess<ImageFmt, Mode>)

ImageAccess(ImageAccess &&other) : m_data

Constructs an ImageAccess object by moving from another instance.

UnmapFn class (ImageAccess::UnmapFn)

UnmapFn

Functor for handling unmapping of image data.

ImageAccess<ImageFmt, Mode> function (ImageAccess::ImageAccess<ImageFmt, Mode>)

ImageAccess(const std::tuple<ImageData<value_type>,
                             MappedRegion> &dataMapped,
            UnmapFn commit, ImageFormat format)
    : ImageAccess(std::get<0>(dataMapped),
                  std::get<1>(dataMapped), commit, format)

Constructs an ImageAccess from mapped image data.
Param dataMapped A tuple containing the image data and mapped region.
Param commit The unmapping function to be called on destruction.
Param format The image format.

ImageAccess(const ImageData<value_type> &data,
            const MappedRegion &mapped, UnmapFn commit,
            ImageFormat format)
    : m_data(data), m_mapped(mapped),
      m_commit(std::move(commit)), m_format(format)

Constructs ImageAccess with given data, mapped region, commit function, and format.
Param data The image data.
Param mapped The mapped region of the image.
Param commit The commit function.
Param format The image format.

swap function (ImageAccess::swap)

void swap(ImageAccess &other)

Swaps the contents of this instance with another.
Param other The other ImageAccess instance.

throwRangeError function (ImageAccess::throwRangeError)

static void throwRangeError(const std::string &str)

Throws a range error exception.
Param str The error message.

operator() function (ImageAccess::operator())

reference operator()(int32_t x, int32_t y) const
  requires(FmtPixelType != PixelType::Unknown)

Accesses pixel data at the specified coordinates.
Param x The x-coordinate.
Param y The y-coordinate.
Returns Reference to the pixel data.

size function (ImageAccess::size)

Size size() const

Returns the size of the image.
Returns The image size.

width function (ImageAccess::width)

int32_t width() const

Returns the width of the image.
Returns The image width.

height function (ImageAccess::height)

int32_t height() const

Returns the height of the image.
Returns The image height.

memoryWidth function (ImageAccess::memoryWidth)

int32_t memoryWidth() const

Returns the image width in memory (in color components, not bytes).
Returns The memory width.

copyFrom function (ImageAccess::copyFrom)

template <ImageFormat SrcImageFmt, AccessMode SrcMode>
void copyFrom(const ImageAccess<SrcImageFmt, SrcMode> &src)
  requires(Mode != AccessMode::R)

Copies data from another ImageAccess.
Param src The source ImageAccess instance.

~ImageAccess<ImageFmt, Mode> function (ImageAccess::~ImageAccess<ImageFmt, Mode>)

~ImageAccess()

Destructor that commits any pending changes.

data function (ImageAccess::data)

pointer data() const

Returns a pointer to the image data.
Returns Pointer to the image data.

byteStride function (ImageAccess::byteStride)

int32_t byteStride() const

Returns the byte stride of the image.
Returns The byte stride.

memorySize function (ImageAccess::memorySize)

size_t memorySize() const

Returns the total size of the image in color components.
Returns The memory size in color components.

byteSize function (ImageAccess::byteSize)

size_t byteSize() const

Returns the byte size of the image.
Returns The byte size of the image.

format function (ImageAccess::format)

ImageFormat format() const

Returns the format of the image.
Returns The image format.

pixelType function (ImageAccess::pixelType)

PixelType pixelType() const

Returns the pixel type of the image.
Returns The pixel type.

pixelFormat function (ImageAccess::pixelFormat)

PixelFormat pixelFormat() const

Returns the pixel format of the image.
Returns The pixel format.

components function (ImageAccess::components)

int32_t components() const

Returns the number of components in a pixel (1-4).
Returns The number of components.

lineIterator function (ImageAccess::lineIterator)

LineIterator lineIterator() const

Returns an iterator for traversing the lines of the image.
Returns Line iterator.

lineReverseIterator function (ImageAccess::lineReverseIterator)

LineIterator lineReverseIterator() const

Returns a reverse iterator for traversing the lines of the image.
Returns Line reverse iterator.

line function (ImageAccess::line)

pointer line(int32_t y) const

Retrieves a pointer to the start of a specific line.
Param y The y-coordinate of the line.
Returns Pointer to the start of the line.

writeTo function (ImageAccess::writeTo)

void writeTo(BytesMutableView data,
             bool flipY = false) const

Writes the image data to the contiguous memory buffer.
Param data The memory buffer to write to.
Param flipY Whether to flip the image vertically.

readFrom function (ImageAccess::readFrom)

void readFrom(BytesView data, bool flipY = false) const
  requires(Mode != AccessMode::R)

Reads the image data from the contiguous memory buffer.
Param data The memory buffer to read from.
Param flipY Whether to flip the image vertically.

isContiguous function (ImageAccess::isContiguous)

bool isContiguous() const

Checks if the image data is contiguous in memory.
Returns True if the data is contiguous, false otherwise.

isTopDown function (ImageAccess::isTopDown)

bool isTopDown() const

Checks if the image is stored top-down.
Returns True if the image is top-down, false otherwise.

clear function (ImageAccess::clear)

void clear(ColorW fillColor)
  requires(Mode != AccessMode::R)

Clears the image with a specified fill color.
Param fillColor The color to fill the image with.

flip function (ImageAccess::flip)

void flip(FlipAxis axis) const
  requires(Mode != AccessMode::R)

Flips the image along the specified axis.
Param axis The axis to flip along.

forPixels function (ImageAccess::forPixels)

template <ImageFormat Hint = ImageFmt, typename Fn>
void forPixels(Fn &&fn)

Iterates over the pixels of the image and applies the provided function.

This function allows applying a custom operation on each pixel of the image. It takes into account the image format and pixel type, and adapts the iteration accordingly.
Template param Hint The image format hint (default is ImageFmt).
Param fn The function to apply to each pixel. The function must take the pixel's x and y coordinates along with a reference to the pixel's value.

premultiplyAlpha function (ImageAccess::premultiplyAlpha)

void premultiplyAlpha()
  requires(Mode != AccessMode::R)

Premultiplies the alpha channel for each pixel in the image.

This function modifies the image's color data by premultiplying the alpha value for each pixel. The alpha premultiplication is only performed if the image has an alpha channel.

This function is only available when the access mode is not read-only (Mode != AccessMode::R).

unpremultiplyAlpha function (ImageAccess::unpremultiplyAlpha)

void unpremultiplyAlpha()
  requires(Mode != AccessMode::R)

Unpremultiplies the alpha channel for each pixel in the image.

This function modifies the image's color data by unpremultiplying the alpha value for each pixel. The alpha unpremultiplication is only performed if the image has an alpha channel.

This function is only available when the access mode is not read-only (Mode != AccessMode::R).

imageData function (ImageAccess::imageData)

const ImageData<value_type> &imageData() const

Retrieves the image data.
Returns The image data.

ImageAccess class (ImageAccess::ImageAccess)

template <ImageFormat format, AccessMode> ImageAccess

copyFrom function (ImageAccess::copyFrom)

template <ImageFormat SrcImageFmt = ImageFmt>
void copyFrom(
    const ImageData<const PixelOf<SrcImageFmt>> &src)
  requires(Mode != AccessMode::R)

Copies data from the source image.
Param src The source image data.

swapItem function (ImageAccess::swapItem)

void swapItem(value_type *a, int32_t ax, value_type *b,
              int32_t bx) const

Swaps two pixel items in the image.
Param a Pointer to the first pixel.
Param ax Index of the first pixel in the row.
Param b Pointer to the second pixel.
Param bx Index of the second pixel in the row.


Image class

Image

RenderDevice class

RenderDevice

ImageBackend class (Internal::ImageBackend)

ImageBackend

begin function (Internal::ImageBackend::begin)

virtual void begin(AccessMode mode, Rectangle rect) = 0

Can transfer image data from backend if the image is changed on GPU since previous call to update

end function (Internal::ImageBackend::end)

virtual void end(AccessMode mode, Rectangle rect) = 0

Can transfer image data to backend


allocateImageData function

template <typename T>
inline ImageData<T>
allocateImageData(Size size, int32_t components = 1,
                  int32_t strideAlignment = 1)

Allocates memory for image data with the specified size, components, and alignment.

This function allocates memory for an image with the given width, height, and number of components per pixel. The memory is aligned based on the specified strideAlignment. It ensures that the image size is valid, with a maximum width or height less than 65536. It also computes the necessary byte stride and allocates memory accordingly.
Template param T The color component type (e.g., uint8_t, float).
Param size The size of the image (width and height).
Param components The number of components per pixel (1-4, default is 1).
Param strideAlignment The alignment of the stride in bytes (default is 1).
Returns The allocated ImageData<T\> structure containing the image data.
Exceptions If the image size is too large (width or height >= 65536).


deallocateImageData function

template <typename T>
inline void deallocateImageData(const ImageData<T> &data)

Deallocates memory used by the image data.

This function frees the memory allocated for the image data by calling the aligned free function.
Template param T The pixel type (e.g., uint8_t, float).
Param data The ImageData<T\> structure containing the image data to be deallocated.


Image class

Image

width function (Image::width)

int32_t width() const noexcept

Returns the width of the image.
Returns The width of the image in pixels.

height function (Image::height)

int32_t height() const noexcept

Returns the height of the image.
Returns The height of the image in pixels.

size function (Image::size)

Size size() const noexcept

Returns the size of the image.
Returns The size of the image in pixels.

bounds function (Image::bounds)

Rectangle bounds() const noexcept

Returns the bounds of the image.

This function returns a Rectangle that represents the bounds of the image, starting from the origin (0, 0) to the image size.
Returns A Rectangle representing the bounds of the image.

byteSize function (Image::byteSize)

size_t byteSize() const noexcept

Returns the total byte size of the image data.
Returns The total byte size of the image data.

pixelType function (Image::pixelType)

PixelType pixelType() const noexcept

Returns the pixel type of the image.
Returns The pixel type of the image.

format function (Image::format)

ImageFormat format() const noexcept

Returns the image format.
Returns The image format of the image.

pixelFormat function (Image::pixelFormat)

PixelFormat pixelFormat() const noexcept

Returns the pixel format of the image.
Returns The pixel format of the image.

componentsPerPixel function (Image::componentsPerPixel)

int32_t componentsPerPixel() const noexcept

Returns the number of color components per pixel in the image (1-4).
Returns The number of color components per pixel.

bytesPerPixel function (Image::bytesPerPixel)

int32_t bytesPerPixel() const noexcept

Returns the number of bytes per pixel.

This function returns the number of bytes required to store a single pixel based on the pixel type and pixel format.
Returns The number of bytes per pixel.

isGreyscale function (Image::isGreyscale)

bool isGreyscale() const noexcept

Checks if the image is greyscale.
Returns true if the image is greyscale, otherwise false.

isColor function (Image::isColor)

bool isColor() const noexcept

Checks if the image is a color image.
Returns true if the image is a color image, otherwise false.

hasAlpha function (Image::hasAlpha)

bool hasAlpha() const noexcept

Checks if the image has an alpha channel.
Returns true if the image has an alpha channel, otherwise false.

isAlphaOnly function (Image::isAlphaOnly)

bool isAlphaOnly() const noexcept

Checks if the image contains only alpha data.
Returns true if the image is alpha-only, otherwise false.

isLinear function (Image::isLinear)

bool isLinear() const noexcept

Checks if the image is linear (non-gamma encoded).
Returns true if the image is linear, otherwise false.

mapRead function (Image::mapRead)

template <ImageFormat format = ImageFormat::Unknown>
ImageAccess<format, AccessMode::R> mapRead() const

Maps the image for reading.

Maps the image data for reading with the specified format.
Template param format The image format (default is ImageFormat::Unknown).
Returns An ImageAccess object for reading.

mapWrite function (Image::mapWrite)

template <ImageFormat format = ImageFormat::Unknown>
ImageAccess<format, AccessMode::W> mapWrite()

Maps the image for writing.

Maps the image data for writing with the specified format.
Template param format The image format (default is ImageFormat::Unknown).
Returns An ImageAccess object for writing.

mapReadWrite function (Image::mapReadWrite)

template <ImageFormat format = ImageFormat::Unknown>
ImageAccess<format, AccessMode::RW> mapReadWrite()

Maps the image for read and write.

Maps the image data for both reading and writing with the specified format.
Template param format The image format (default is ImageFormat::Unknown).
Returns An ImageAccess object for read and write access.

mapRead function (Image::mapRead)

template <ImageFormat format = ImageFormat::Unknown>
ImageAccess<format, AccessMode::R>
mapRead(Rectangle rect) const

Maps a rectangular region of the image for reading.

Maps the specified rectangular region of the image for reading.
Template param format The image format (default is ImageFormat::Unknown).
Param rect The rectangular region to map.
Returns An ImageAccess object for reading the region.

mapWrite function (Image::mapWrite)

template <ImageFormat format = ImageFormat::Unknown>
ImageAccess<format, AccessMode::W> mapWrite(Rectangle rect)

Maps a rectangular region of the image for writing.

Maps the specified rectangular region of the image for writing.
Template param format The image format (default is ImageFormat::Unknown).
Param rect The rectangular region to map.
Returns An ImageAccess object for writing the region.

mapReadWrite function (Image::mapReadWrite)

template <ImageFormat format = ImageFormat::Unknown>
ImageAccess<format, AccessMode::RW>
mapReadWrite(Rectangle rect)

Maps a rectangular region of the image for read and write.

Maps the specified rectangular region of the image for both reading and writing.
Template param format The image format (default is ImageFormat::Unknown).
Param rect The rectangular region to map.
Returns An ImageAccess object for read and write access to the region.

clear function (Image::clear)

void clear(ColorW value)

Clears the image with a specified color.

Clears the entire image by writing the specified color value to it.
Param value The color to clear the image with.

copyFrom function (Image::copyFrom)

void copyFrom(const Rc<const Image> &source,
              Rectangle sourceRect, Rectangle destRect)

Copies data from another image.

Copies a rectangular region of data from the source image to the destination image.
Param source The source image.
Param sourceRect The region to copy from the source.
Param destRect The region to copy to in the destination.

void copyFrom(const Rc<const Image> &source)

Copies data from another image (full bounds).

Copies data from the source image's bounds to the destination image's bounds.
Param source The source image.

data function (Image::data)

ImageData<UntypedPixel> data() const noexcept

Returns the image data.

Returns the image data as an ImageData<UntypedPixel\> object.
Returns The image data.

Image function (Image::Image)

explicit Image(Size size,
               ImageFormat format = ImageFormat::RGBA)
    : Image(allocateImageData<UntypedPixel>(
                size, pixelSize(toPixelType(format),
                                toPixelFormat(format))),
            format, &deallocateImageData<UntypedPixel>)

Creates an image with the specified size, pixel type, and pixel format, and allocates memory for it.

This constructor creates an 8-bit RGBA image by default with a gamma-corrected sRGB color space.
Param size The size of the image.
Param format The image format (default is ImageFormat::RGBA).

explicit Image(Size size, ImageFormat format,
               ColorW fillColor)
    : Image(size, format)

Constructs an image with the given size, pixel format, and fills it with a color.

This constructor creates an image with the specified size and pixel format, then fills the image with the provided fillColor.
Param size The size of the image.
Param format The pixel format of the image.
Param fillColor The color to fill the image with.

explicit Image(void* data, Size size, int32_t byteStride, ImageFormat format)
    : Image(ImageData<UntypedPixel>

Constructs an image by referencing existing data (no data copy).

This constructor creates an image by referencing existing data, without copying it. The caller is responsible for managing the lifetime of the data.
Param data Pointer to the existing image data.
Param size The size of the image.
Param byteStride The byte stride between rows of pixels.
Param format The pixel format of the image.

~Image function (Image::~Image)

~Image()

Destructor to clean up the image.

This destructor deallocates the image data if a deleter is provided.

copy function (Image::copy)

Rc<Image> copy(bool copyPixels = true) const

Creates a copy of the image.

Creates a new Image object with the same size and format as the original image. Optionally, copies the pixel data from the original image.
Param copyPixels Whether to copy the pixel data (default is true).
Returns A new Rc<Image\> containing the copied image.


Auto-generated from sources, Revision , https://github.com/brisklib/brisk/blob//include/brisk/