libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
pixelformat_old.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <vector>
11#include <cstdint>
13#include <promeki/core/string.h>
14#include <promeki/core/util.h>
15#include <promeki/core/size2d.h>
16
17#define PROMEKI_FOURCC(code) \
18( \
19 static_cast<PixelFormat::FourCC>(code[0]) | \
20 (static_cast<PixelFormat::FourCC>(code[1])) << 8 | \
21 (static_cast<PixelFormat::FourCC>(code[2])) << 16 | \
22 (static_cast<PixelFormat::FourCC>(code[3])) << 24 \
23)
24
26
27class Image;
28class Pixel;
29
40class PixelFormat {
41 public:
43 enum ID {
44 Invalid = 0,
45 RGBA8,
46 RGB8,
47 RGB10,
48 YUV8_422,
50 };
51
60
62 enum CompType {
63 CompEmpty = 0,
64 CompAlpha,
65 CompRed,
66 CompGreen,
67 CompBlue,
68 CompY,
69 CompCb,
70 CompCr
71 };
72
74 using Comp = uint16_t;
75
77 using CompList = std::vector<Comp>;
78
80 struct CompDesc {
81 int plane;
83 size_t bits;
84 };
85
91 typedef size_t (*StrideFunc)(const Size2Du32 &size);
92
98 typedef size_t (*SizeFunc)(const Size2Du32 &size);
99
106 typedef bool (*FillFunc)(const Image &img, const Comp *comps);
107
113 typedef Pixel (*CreatePixelFunc)(const Comp *comps);
114
116 struct PlaneDesc {
117 String name;
120 };
121
124
126 struct Data {
133 bool hasAlpha;
134 std::vector<FourCC> fourccList;
135 std::vector<CompDesc> compList;
136 std::vector<PlaneDesc> planeList;
137
142 };
143
149 static const String &formatName(ID id);
150
156
159 d = o.d;
160 return *this;
161 }
162
164 bool operator==(const PixelFormat &o) const {
165 return d->id == o.d->id;
166 }
167
169 bool operator!=(const PixelFormat &o) const {
170 return d->id != o.d->id;
171 }
172
174 bool isValid() const {
175 return d->id != Invalid;
176 }
177
179 const Data &data() const { return *d; }
180
182 ID id() const { return d->id; }
183
185 const String &name() const { return d->name; }
186
188 const String &desc() const { return d->desc; }
189
191 size_t comps() const { return d->compList.size(); }
192
194 size_t planes() const { return d->planeList.size(); }
195
202 size_t stride(const Size2Du32 &s, int p = 0) const {
203 StrideFunc func = d->planeList[p].stride;
204 return func == nullptr ? 0 : func(s);
205 }
206
213 size_t size(const Size2Du32 &s, int p = 0) const {
214 SizeFunc func = d->planeList[p].size;
215 return func == nullptr ? 0 : func(s);
216 }
217
224 bool fill(const Image &img, const CompList &comps) const {
225 return fill(img, comps.data(), comps.size());
226 }
227
235 bool fill(const Image &img, const Comp *comps, size_t compCount) const;
236
243 Pixel createPixel(const Comp *comps, size_t compCount) const;
244
245 private:
246 const Data *d = nullptr;
247
248 static const Data *lookup(ID id);
249};
250
252
Raster image with pixel format, planes, and metadata.
Definition image.h:48
Dynamic array container wrapping std::vector.
Definition list.h:40
size_t size() const noexcept
Returns the number of elements in the list.
Definition list.h:301
T * data() noexcept
Returns a pointer to the underlying contiguous storage.
Definition list.h:286
Describes a pixel packing format and provides format-specific operations.
Definition pixelformat.h:43
size_t(* StrideFunc)(const Size2Du32 &size)
Function that returns the number of bytes per line.
Definition pixelformat_old.h:91
Pixel(* CreatePixelFunc)(const Comp *comps)
Function that computes a Pixel from component inputs.
Definition pixelformat_old.h:113
const String & desc() const
Returns the human-readable description.
Definition pixelformat_old.h:188
std::vector< Comp > CompList
List of component values.
Definition pixelformat_old.h:77
static const String & formatName(ID id)
Returns the human-readable name for a given format ID.
bool operator!=(const PixelFormat &o) const
Returns true if the formats have different IDs.
Definition pixelformat_old.h:169
Pixel createPixel(const Comp *comps, size_t compCount) const
Creates a Pixel from a component array.
size_t size(const Size2Du32 &s, int p=0) const
Returns the total byte size for the given image size and plane.
Definition pixelformat_old.h:213
static const PixelFormat * lookup(int id)
Looks up a registered pixel format by its ID.
size_t planes() const
Returns the number of planes in this format.
Definition pixelformat_old.h:194
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
@ YUV10_422
10-bit YUV with 4:2:2 chroma subsampling.
Definition pixelformat.h:52
@ 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
const Data & data() const
Returns a const reference to the underlying Data descriptor.
Definition pixelformat_old.h:179
bool operator==(const PixelFormat &o) const
Returns true if both formats have the same ID.
Definition pixelformat_old.h:164
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
bool fill(const Image &img, const CompList &comps) const
Fills an image with the pixel value defined by a component list.
Definition pixelformat_old.h:224
bool(* FillFunc)(const Image &img, const Comp *comps)
Function that fills an image with a pixel value from a component array.
Definition pixelformat_old.h:106
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
PixelFormat(ID id=Invalid)
Constructs a PixelFormat from an ID.
Definition pixelformat_old.h:155
bool fill(const Image &img, const Comp *comps, size_t compCount) const
Fills an image with the pixel value defined by a component array.
ID id() const
Returns the format ID.
Definition pixelformat_old.h:182
size_t(* SizeFunc)(const Size2Du32 &size)
Function that returns the total number of bytes for an image of the given size.
Definition pixelformat_old.h:98
bool isValid() const
Returns true if this pixel format is valid (not Invalid).
Definition pixelformat_old.h:174
PixelFormat & operator=(const PixelFormat &o)
Copy assignment operator.
Definition pixelformat_old.h:158
size_t compCount() const
Returns the number of components in this pixel format.
Definition pixelformat.h:151
uint32_t FourCC
FourCC code type.
Definition pixelformat_old.h:123
size_t comps() const
Returns the number of components in this format.
Definition pixelformat_old.h:191
const String & name() const
Returns the short format name.
Definition pixelformat_old.h:185
size_t stride(const Size2Du32 &s, int p=0) const
Returns the line stride in bytes for the given image size and plane.
Definition pixelformat_old.h:202
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
Aggregate descriptor holding all metadata for a pixel format.
Definition pixelformat_old.h:126
size_t bytesPerBlock
Bytes per encoded block.
Definition pixelformat_old.h:132
CreatePixelFunc createPixel
Function to create a Pixel from component values.
Definition pixelformat_old.h:139
ID id
Format identifier.
Definition pixelformat_old.h:127
size_t pixelsPerBlock
Pixels per encoded block.
Definition pixelformat_old.h:131
String name
Short format name.
Definition pixelformat_old.h:128
std::vector< CompDesc > compList
Component descriptors.
Definition pixelformat_old.h:135
bool hasAlpha
Whether format has alpha.
Definition pixelformat_old.h:133
std::vector< PlaneDesc > planeList
Plane descriptors.
Definition pixelformat_old.h:136
std::vector< FourCC > fourccList
Associated FourCC codes.
Definition pixelformat_old.h:134
FillFunc fill
Function to fill an image with a pixel value.
Definition pixelformat_old.h:141
Sampling sampling
Chroma subsampling mode.
Definition pixelformat_old.h:130
String desc
Human-readable description.
Definition pixelformat_old.h:129
Describes a single image plane.
Definition pixelformat.h:87
StrideFunc stride
Function to compute line stride.
Definition pixelformat_old.h:118
SizeFunc size
Function to compute plane size.
Definition pixelformat_old.h:119
String name
Human-readable name for the plane.
Definition pixelformat.h:88