Image
-
class Image
An immutable snapshot of pixel data.
Images are created from Surfaces via makeSnapshot() and can be drawn onto any Surface via canvas->drawImage(). This is the mechanism for compositing multiple surfaces together.
Public Types
-
enum class StorageType : u8
Storage backend for the image data.
Values:
-
enumerator CpuPixmap
CPU-side pixel buffer.
-
enumerator GpuTexture
GPU texture handle.
-
enumerator CpuPixmap
Public Functions
-
inline u64 backendTextureHandle() const
Get the opaque backend texture handle.
- Returns:
Texture handle for GPU-backed images; 0 otherwise.
-
inline PixelFormat format() const
Get pixel format.
- Returns:
The pixel format of this image.
-
inline u32 glTextureId() const
Get the GL texture ID.
- Returns:
OpenGL texture name (truncated from u64 to u32).
-
inline i32 height() const
Get image height.
- Returns:
Height in pixels.
-
inline const PixmapInfo &info() const
Get full pixmap info.
- Returns:
Reference to the PixmapInfo descriptor.
-
inline bool isCpuBacked() const
Check if image is CPU-backed.
- Returns:
True if stored as a CPU pixmap.
-
inline bool isGpuBacked() const
Check if image is GPU-backed.
- Returns:
True if stored as a GPU texture.
-
inline const void *pixels() const
Get raw pixel pointer (CPU-backed images only).
- Returns:
Pointer to pixel data, or nullptr for GPU-backed images.
-
inline const u32 *pixels32() const
Get pixel data as 32-bit words.
- Returns:
Pointer to pixel data cast to u32*.
-
inline StorageType storageType() const
Get the storage type.
- Returns:
-
inline i32 stride() const
Get row stride in bytes.
- Returns:
Bytes per row.
-
inline u64 uniqueId() const
Get a stable unique identity for backend caches.
- Returns:
Unique image ID.
-
inline bool valid() const
Check if the image contains valid data.
- Returns:
True if dimensions are positive and backing storage is present.
-
inline i32 width() const
Get image width.
- Returns:
Width in pixels.
Public Static Functions
Create an image from a backend-specific GPU texture handle.
- Parameters:
textureHandle – Opaque handle (e.g. GLuint for GL, VkImage for Vulkan).
width – Texture width in pixels.
height – Texture height in pixels.
fmt – Pixel format (default RGBA8888).
lifetimeToken – Optional shared_ptr whose destructor releases the texture.
- Returns:
Shared pointer to the new Image.
Convenience: create from a GL texture ID.
- Parameters:
textureId – OpenGL texture name.
width – Texture width in pixels.
height – Texture height in pixels.
fmt – Pixel format (default RGBA8888).
lifetimeToken – Optional shared_ptr whose destructor releases the texture.
- Returns:
Shared pointer to the new Image.
-
enum class StorageType : u8