libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
image.h
Go to the documentation of this file.
1
8#pragma once
9
12#include <promeki/core/buffer.h>
15
17
48class Image {
50 public:
53
56
59
61 Image() = default;
62
69
76 Image(const Size2Du32 &s, int pixfmt, const MemSpace &ms = MemSpace::Default) :
77 Image(ImageDesc(s, pixfmt), ms) { }
78
86 Image(size_t w, size_t h, int pixfmt, const MemSpace &ms = MemSpace::Default) :
87 Image(ImageDesc(w, h, pixfmt), ms) { }
88
93 bool isValid() const {
94 return _desc.isValid();
95 }
96
101 const ImageDesc &desc() const {
102 return _desc;
103 }
104
109 int pixelFormatID() const {
110 return _desc.pixelFormatID();
111 }
112
117 const PixelFormat *pixelFormat() const {
118 return _desc.pixelFormat();
119 }
120
125 const Size2Du32 &size() const {
126 return _desc.size();
127 }
128
133 size_t width() const {
134 return _desc.width();
135 }
136
141 size_t height() const {
142 return _desc.height();
143 }
144
149 const Metadata &metadata() const {
150 return _desc.metadata();
151 }
152
158 return _desc.metadata();
159 }
160
166 size_t lineStride(int plane = 0) const {
167 return _desc.pixelFormat()->lineStride(plane, _desc);
168 }
169
175 const Buffer::Ptr &plane(int index = 0) const {
176 return _planeList[index];
177 }
178
183 const Buffer::PtrList &planes() const {
184 return _planeList;
185 }
186
192 void *data(int index = 0) const {
193 return _planeList[index]->data();
194 }
195
201 Error fill(char value) const {
202 if(_planeList.isEmpty()) return Error::Invalid;
203 for(auto &p : _planeList) {
204 Error err = p->fill(value);
205 if(err.isError()) return err;
206 }
207 return Error::Ok;
208 }
209
220 bool isExclusive() const {
221 for(const auto &p : _planeList) {
222 if(p.referenceCount() > 1) return false;
223 }
224 return true;
225 }
226
238 for(auto &p : _planeList) {
239 p.modify();
240 }
241 return;
242 }
243
248 bool isCompressed() const {
249 const PixelFormat *pf = _desc.pixelFormat();
250 return pf != nullptr && pf->isCompressed();
251 }
252
265 size_t compressedSize() const {
266 if(!isCompressed() || _planeList.isEmpty()) return 0;
267 return _planeList[0]->size();
268 }
269
291 static Image fromCompressedData(const void *data, size_t size,
292 size_t width, size_t height, int pixfmt,
293 const Metadata &metadata = Metadata());
294
300 return _desc.pixelFormat()->createPaintEngine(*this);
301 }
302
310
311 private:
312 ImageDesc _desc;
313 Buffer::PtrList _planeList;
314
315 bool allocate(const MemSpace &ms);
316};
317
promeki::List< Ptr > PtrList
List of shared Buffer pointers.
Definition buffer.h:104
Lightweight error code wrapper for the promeki library.
Definition error.h:39
@ Ok
No error.
Definition error.h:51
@ Invalid
Invalid value or argument (EINVAL).
Definition error.h:66
Describes the format and layout of a single image.
Definition imagedesc.h:33
size_t height() const
Returns the image height in pixels.
Definition imagedesc.h:95
bool isValid() const
Returns true if this image description has valid dimensions and pixel format.
Definition imagedesc.h:71
const Metadata & metadata() const
Returns a const reference to the metadata.
Definition imagedesc.h:187
int pixelFormatID() const
Returns the pixel format identifier.
Definition imagedesc.h:63
const Size2Du32 & size() const
Returns the image dimensions.
Definition imagedesc.h:79
const PixelFormat * pixelFormat() const
Returns a pointer to the PixelFormat descriptor for this image.
Definition imagedesc.h:173
size_t width() const
Returns the image width in pixels.
Definition imagedesc.h:87
Raster image with pixel format, planes, and metadata.
Definition image.h:48
size_t height() const
Returns the image height in pixels.
Definition image.h:141
Error fill(char value) const
Fills all image planes with the given byte value.
Definition image.h:201
void * data(int index=0) const
Returns a raw data pointer for the given plane.
Definition image.h:192
promeki::List< Ptr > PtrList
List of shared Image pointers.
Definition image.h:58
PaintEngine createPaintEngine() const
Creates a paint engine for drawing on this image.
Definition image.h:299
Image(const Size2Du32 &s, int pixfmt, const MemSpace &ms=MemSpace::Default)
Constructs an image from a size and pixel format ID.
Definition image.h:76
void ensureExclusive()
Ensures exclusive ownership of all plane buffers.
Definition image.h:237
SharedPtr< Image > Ptr
Shared pointer type for Image.
Definition image.h:52
Image convert(PixelFormat::ID pixelFormat, const Metadata &metadata) const
Converts this image to a different pixel format.
const Metadata & metadata() const
Returns a const reference to the image metadata.
Definition image.h:149
const Buffer::Ptr & plane(int index=0) const
Returns the buffer for the given image plane.
Definition image.h:175
Image()=default
Constructs an invalid (empty) image.
Image(size_t w, size_t h, int pixfmt, const MemSpace &ms=MemSpace::Default)
Constructs an image from width, height, and pixel format ID.
Definition image.h:86
int pixelFormatID() const
Returns the pixel format identifier.
Definition image.h:109
bool isExclusive() const
Returns true if all plane buffers are exclusively owned.
Definition image.h:220
const Size2Du32 & size() const
Returns the image dimensions.
Definition image.h:125
Image(const ImageDesc &desc, const MemSpace &ms=MemSpace::Default)
Constructs an image from an image descriptor.
size_t compressedSize() const
Returns the compressed data size in bytes.
Definition image.h:265
bool isCompressed() const
Returns true if this image uses a compressed pixel format.
Definition image.h:248
size_t width() const
Returns the image width in pixels.
Definition image.h:133
size_t lineStride(int plane=0) const
Returns the line stride in bytes for the given plane.
Definition image.h:166
bool isValid() const
Returns true if the image has a valid descriptor and allocated planes.
Definition image.h:93
const ImageDesc & desc() const
Returns the image descriptor.
Definition image.h:101
Metadata & metadata()
Returns a mutable reference to the image metadata.
Definition image.h:157
const Buffer::PtrList & planes() const
Returns the list of all plane buffers.
Definition image.h:183
promeki::List< Image > List
List of Image values.
Definition image.h:55
const PixelFormat * pixelFormat() const
Returns a pointer to the PixelFormat object.
Definition image.h:117
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.
Dynamic array container wrapping std::vector.
Definition list.h:40
List()=default
Default constructor. Creates an empty list.
Abstraction for memory allocation in different address spaces.
Definition memspace.h:30
@ Default
Alias for System memory.
Definition memspace.h:36
Key-value metadata container using typed Variant values.
Definition metadata.h:68
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
ID
The ID of the unique packing format for the pixel.
Definition pixelformat.h:46
#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
const T & value(const Result< T > &r)
Returns the value from a Result.
Definition result.h:56
#define PROMEKI_SHARED_FINAL(TYPE)
Macro for non-polymorphic native shared objects.
Definition sharedptr.h:88