Raster image with pixel format, planes, and metadata.
More...
#include <image.h>
Raster image with pixel format, planes, and metadata.
Holds image pixel data organized into one or more memory planes according to the image's pixel format. Provides convenience accessors for dimensions, pixel format, and metadata, as well as pixel format conversion and paint engine creation. When shared ownership is needed, use Image::Ptr.
- Compressed images
- Image also represents compressed (encoded) image data such as JPEG. A compressed image uses a compressed pixel format (e.g. PixelFormat::JPEG_RGB8) and stores the encoded bitstream in its single plane buffer. Use isCompressed() to test whether an image is compressed, compressedSize() to get the encoded byte count, and data() to access the raw encoded bytes. The preferred way to create a compressed image is the fromCompressedData() factory.
- Example — creating a compressed image
1920, 1080,
Raster image with pixel format, planes, and metadata.
Definition image.h:48
promeki::List< Image > List
List of Image values.
Definition image.h:55
static Image fromCompressedData(const void *data, size_t size, size_t width, size_t height, int pixfmt, const Metadata &metadata=Metadata())
Creates a compressed image from pre-encoded data.
◆ Image() [1/3]
Constructs an image from an image descriptor.
- Parameters
-
| desc | Image descriptor specifying size, pixel format, and metadata. |
| ms | Memory space to allocate plane buffers from. |
◆ Image() [2/3]
Constructs an image from a size and pixel format ID.
- Parameters
-
| s | Image dimensions. |
| pixfmt | Pixel format identifier. |
| ms | Memory space to allocate from. |
◆ Image() [3/3]
Constructs an image from width, height, and pixel format ID.
- Parameters
-
| w | Image width in pixels. |
| h | Image height in pixels. |
| pixfmt | Pixel format identifier. |
| ms | Memory space to allocate from. |
◆ compressedSize()
| size_t Image::compressedSize |
( |
| ) |
const |
|
inline |
Returns the compressed data size in bytes.
For compressed images, the encoded bitstream lives in the first plane buffer. This method returns that buffer's logical size, which is the actual encoded byte count. Use data() to obtain a pointer to the encoded bytes.
Returns 0 for uncompressed images or if no planes are allocated.
- Returns
- The compressed data size, or 0.
◆ convert()
Converts this image to a different pixel format.
- Parameters
-
| pixelFormat | The target pixel format ID. |
| metadata | Metadata to attach to the converted image. |
- Returns
- A new Image in the target pixel format.
◆ createPaintEngine()
Creates a paint engine for drawing on this image.
- Returns
- A PaintEngine configured for this image's pixel format.
◆ data()
| void * Image::data |
( |
int |
index = 0 | ) |
const |
|
inline |
Returns a raw data pointer for the given plane.
- Parameters
-
| index | The plane index (defaults to 0). |
- Returns
- A void pointer to the plane's pixel data.
◆ desc()
Returns the image descriptor.
- Returns
- A const reference to the ImageDesc.
◆ ensureExclusive()
| void Image::ensureExclusive |
( |
| ) |
|
|
inline |
Ensures exclusive ownership of all plane buffers.
For each plane Buffer::Ptr, calls modify() to trigger a copy-on-write detach if the reference count is greater than 1. In a linear pipeline where only one consumer holds a reference, this is a no-op. In fan-out scenarios where multiple consumers share the same buffers, this creates private copies so that the caller can safely mutate the pixel data.
◆ fill()
Fills all image planes with the given byte value.
- Parameters
-
| value | The byte value to fill with. |
- Returns
- Error::Ok on success, or an error if no planes exist or a fill fails.
◆ fromCompressedData()
Creates a compressed image from pre-encoded data.
This is the preferred way to construct a compressed Image. It allocates a plane buffer sized to hold the encoded data, copies the bytes in, sets the buffer's logical size to size, and attaches the supplied metadata. The resulting Image reports isCompressed() == true and compressedSize() == size.
The width and height describe the original uncompressed dimensions — they are stored in the ImageDesc so that downstream consumers know the frame size without decoding.
- Parameters
-
| data | Pointer to the compressed data. |
| size | Size of the compressed data in bytes. |
| width | Original image width in pixels. |
| height | Original image height in pixels. |
| pixfmt | Compressed pixel format ID (e.g. PixelFormat::JPEG_RGB8). |
| metadata | Optional metadata to attach (e.g. timecode). |
- Returns
- A valid compressed Image, or an invalid Image on failure.
◆ height()
| size_t Image::height |
( |
| ) |
const |
|
inline |
Returns the image height in pixels.
- Returns
- The height.
◆ isCompressed()
| bool Image::isCompressed |
( |
| ) |
const |
|
inline |
Returns true if this image uses a compressed pixel format.
- Returns
- true if the pixel format is compressed (e.g. JPEG).
◆ isExclusive()
| bool Image::isExclusive |
( |
| ) |
const |
|
inline |
Returns true if all plane buffers are exclusively owned.
A plane is exclusive when its Buffer::Ptr has a reference count of 1 (or is null). This is useful for determining whether it is safe to mutate the pixel data in place without affecting other consumers that may share the same buffers.
- Returns
- true if every plane buffer has referenceCount() <= 1.
◆ isValid()
| bool Image::isValid |
( |
| ) |
const |
|
inline |
Returns true if the image has a valid descriptor and allocated planes.
- Returns
- true if the image descriptor is valid.
◆ lineStride()
| size_t Image::lineStride |
( |
int |
plane = 0 | ) |
const |
|
inline |
Returns the line stride in bytes for the given plane.
- Parameters
-
| plane | The plane index (defaults to 0). |
- Returns
- The number of bytes per scanline.
◆ metadata() [1/2]
Returns a mutable reference to the image metadata.
- Returns
- The metadata.
◆ metadata() [2/2]
Returns a const reference to the image metadata.
- Returns
- The metadata.
◆ pixelFormat()
◆ pixelFormatID()
| int Image::pixelFormatID |
( |
| ) |
const |
|
inline |
Returns the pixel format identifier.
- Returns
- The pixel format ID integer.
◆ plane()
Returns the buffer for the given image plane.
- Parameters
-
| index | The plane index (defaults to 0). |
- Returns
- A const reference to the Buffer shared pointer.
◆ planes()
Returns the list of all plane buffers.
- Returns
- A const reference to the Buffer::PtrList.
◆ size()
Returns the image dimensions.
- Returns
- A const reference to the Size2Du32.
◆ width()
Returns the image width in pixels.
- Returns
- The width.
The documentation for this class was generated from the following file: