libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
pixelformat.h
Go to the documentation of this file.
1
8#pragma once
9#include <cstdint>
11#include <promeki/core/string.h>
12#include <promeki/core/list.h>
13#include <promeki/core/fourcc.h>
14#include <promeki/core/size2d.h>
15#include <promeki/core/point.h>
16#include <promeki/core/util.h>
17
24#define PROMEKI_REGISTER_PIXELFORMAT(name) [[maybe_unused]] static int PROMEKI_CONCAT(__promeki_pixelformat_, PROMEKI_UNIQUE_ID) = \
25 PixelFormat::registerPixelFormat(new name);
26
27
29
30class Image;
31class ImageDesc;
32class PaintEngine;
33
44 public:
57
66
78
80 struct CompDesc {
81 int plane;
83 size_t bits;
84 };
85
87 struct PlaneDesc {
89 };
90
96 static int registerPixelFormat(PixelFormat *pixelFormat);
97
103 static const PixelFormat *lookup(int id);
104
106 PixelFormat() = default;
107
109 virtual ~PixelFormat() {}
110
112 bool isValid() const { return _id != Invalid; }
113
115 int id() const { return _id; }
116
118 String name() const { return _name; }
119
121 String desc() const { return _desc; }
122
124 Sampling sampling() const { return _sampling; }
125
127 size_t pixelsPerBlock() const { return _pixelsPerBlock; }
128
130 size_t bytesPerBlock() const { return _bytesPerBlock; }
131
133 bool hasAlpha() const { return _hasAlpha; }
134
145 bool isCompressed() const { return _compressed; }
146
148 const FourCCList &fourccList() const { return _fourccList; }
149
151 size_t compCount() const { return _compList.size(); }
152
158 const CompDesc &compDesc(size_t index) const { return _compList[index]; }
159
161 size_t planeCount() const { return _planeList.size(); }
162
168 const PlaneDesc &planeDesc(size_t index) const { return _planeList[index]; }
169
175 bool isValidPlane(size_t index) const { return index < _planeList.size(); }
176
182 bool isValidCompCount(size_t ct) const { return ct >= _compList.size(); }
183
190 size_t lineStride(size_t planeIndex, const ImageDesc &desc) const;
191
198 size_t planeSize(size_t planeIndex, const ImageDesc &desc) const;
199
206
207 protected:
208 int _id = Invalid;
212 size_t _pixelsPerBlock = 0;
213 size_t _bytesPerBlock = 0;
214 bool _hasAlpha = false;
215 bool _compressed = false;
219
226 virtual size_t __lineStride(size_t planeIndex, const ImageDesc &desc) const;
227
234 virtual size_t __planeSize(size_t planeIndex, const ImageDesc &desc) const;
235
241 virtual PaintEngine __createPaintEngine(const Image &image) const;
242};
243
245
Describes the format and layout of a single image.
Definition imagedesc.h:33
Raster image with pixel format, planes, and metadata.
Definition image.h:48
size_t size() const noexcept
Returns the number of elements in the list.
Definition list.h:301
2D drawing engine for rendering primitives onto images.
Definition paintengine.h:30
Describes a pixel packing format and provides format-specific operations.
Definition pixelformat.h:43
size_t _bytesPerBlock
Bytes per encoded block.
Definition pixelformat.h:213
virtual size_t __lineStride(size_t planeIndex, const ImageDesc &desc) const
Virtual implementation of lineStride().
const CompDesc & compDesc(size_t index) const
Returns the component descriptor at the given index.
Definition pixelformat.h:158
FourCCList _fourccList
Associated FourCC codes.
Definition pixelformat.h:216
size_t planeCount() const
Returns the number of planes in this pixel format.
Definition pixelformat.h:161
Sampling _sampling
Chroma subsampling mode.
Definition pixelformat.h:211
static const PixelFormat * lookup(int id)
Looks up a registered pixel format by its ID.
virtual ~PixelFormat()
Virtual destructor.
Definition pixelformat.h:109
bool isValidPlane(size_t index) const
Returns true if the given plane index is valid.
Definition pixelformat.h:175
bool _hasAlpha
Whether format has alpha.
Definition pixelformat.h:214
const PlaneDesc & planeDesc(size_t index) const
Returns the plane descriptor at the given index.
Definition pixelformat.h:168
bool _compressed
Whether format is compressed.
Definition pixelformat.h:215
ID
The ID of the unique packing format for the pixel.
Definition pixelformat.h:46
@ YUV8_422
8-bit YUV with 4:2:2 chroma subsampling.
Definition pixelformat.h:51
@ RGBA8
8-bit RGBA (32 bits per pixel).
Definition pixelformat.h:48
@ RGB8
8-bit RGB (24 bits per pixel).
Definition pixelformat.h:49
@ JPEG_RGBA8
JPEG-compressed 8-bit RGBA.
Definition pixelformat.h:53
@ YUV10_422
10-bit YUV with 4:2:2 chroma subsampling.
Definition pixelformat.h:52
@ JPEG_YUV8_422
JPEG-compressed 8-bit YUV 4:2:2.
Definition pixelformat.h:55
@ JPEG_RGB8
JPEG-compressed 8-bit RGB.
Definition pixelformat.h:54
@ Invalid
Invalid or uninitialized pixel format.
Definition pixelformat.h:47
@ RGB10
10-bit RGB.
Definition pixelformat.h:50
int id() const
Returns the unique ID of this pixel format.
Definition pixelformat.h:115
Sampling
Chroma subsampling mode.
Definition pixelformat.h:59
@ Sampling444
4:4:4 (no chroma subsampling).
Definition pixelformat.h:61
@ Sampling422
4:2:2 (horizontal chroma subsampling by 2).
Definition pixelformat.h:62
@ Sampling420
4:2:0 (horizontal and vertical chroma subsampling by 2).
Definition pixelformat.h:64
@ Sampling411
4:1:1 (horizontal chroma subsampling by 4).
Definition pixelformat.h:63
@ SamplingUndefined
Undefined or unknown sampling.
Definition pixelformat.h:60
List< CompDesc > _compList
Component descriptors.
Definition pixelformat.h:217
bool hasAlpha() const
Returns true if this format includes an alpha channel.
Definition pixelformat.h:133
List< PlaneDesc > _planeList
Plane descriptors.
Definition pixelformat.h:218
int _id
Unique format identifier.
Definition pixelformat.h:208
bool isValidCompCount(size_t ct) const
Returns true if the given component count is sufficient.
Definition pixelformat.h:182
CompType
Pixel component type.
Definition pixelformat.h:68
@ CompBlue
Blue color component.
Definition pixelformat.h:73
@ CompY
Luma (Y) component.
Definition pixelformat.h:74
@ CompEmpty
Empty or unused component slot.
Definition pixelformat.h:69
@ CompRed
Red color component.
Definition pixelformat.h:71
@ CompCb
Blue-difference chroma (Cb/U) component.
Definition pixelformat.h:75
@ CompAlpha
Alpha (transparency) component.
Definition pixelformat.h:70
@ CompGreen
Green color component.
Definition pixelformat.h:72
@ CompCr
Red-difference chroma (Cr/V) component.
Definition pixelformat.h:76
Sampling sampling() const
Returns the chroma subsampling mode.
Definition pixelformat.h:124
static int registerPixelFormat(PixelFormat *pixelFormat)
Registers a pixel format in the global registry.
String desc() const
Returns a human-readable description of this pixel format.
Definition pixelformat.h:121
bool isCompressed() const
Returns true if this is a compressed pixel format.
Definition pixelformat.h:145
PixelFormat()=default
Default constructor.
size_t lineStride(size_t planeIndex, const ImageDesc &desc) const
Returns the number of bytes per line for a given plane.
String _name
Short format name.
Definition pixelformat.h:209
String name() const
Returns the short name of this pixel format.
Definition pixelformat.h:118
virtual size_t __planeSize(size_t planeIndex, const ImageDesc &desc) const
Virtual implementation of planeSize().
bool isValid() const
Returns true if this pixel format is valid (not Invalid).
Definition pixelformat.h:112
size_t pixelsPerBlock() const
Returns the number of pixels in one encoded block.
Definition pixelformat.h:127
size_t compCount() const
Returns the number of components in this pixel format.
Definition pixelformat.h:151
size_t planeSize(size_t planeIndex, const ImageDesc &desc) const
Returns the total byte size of a given plane.
virtual PaintEngine __createPaintEngine(const Image &image) const
Virtual implementation of createPaintEngine().
const FourCCList & fourccList() const
Returns the list of FourCC codes associated with this format.
Definition pixelformat.h:148
PaintEngine createPaintEngine(const Image &img) const
Creates a PaintEngine that can draw on the given image.
size_t bytesPerBlock() const
Returns the number of bytes in one encoded block.
Definition pixelformat.h:130
size_t _pixelsPerBlock
Pixels per encoded block.
Definition pixelformat.h:212
String _desc
Human-readable description.
Definition pixelformat.h:210
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
Describes a single component within the pixel format.
Definition pixelformat.h:80
int plane
Index of the plane this component resides in.
Definition pixelformat.h:81
CompType type
The type of this component.
Definition pixelformat.h:82
size_t bits
Number of bits used by this component.
Definition pixelformat.h:83
Describes a single image plane.
Definition pixelformat.h:87
String name
Human-readable name for the plane.
Definition pixelformat.h:88