Decodes compressed image data (PNG) into a platform-native texture created from it. More...
#include <GuiImageData.h>
Classes | |
| struct | DecodedImage |
| CPU-only decode result from decodeToRgba(): raw RGBA8 pixel data that has NOT been uploaded to a platform texture yet. More... | |
Public Member Functions | |
| GuiImageData () | |
| Constructor. | |
| GuiImageData (const uint8_t *i, int w=0, int h=0) | |
| Constructor Converts the PNG format image data to a platform-native texture, allocated and owned by this object. | |
| GuiImageData (const uint8_t *i, uint8_t *dst, int maxw=0, int maxh=0) | |
| Constructor Converts the PNG format image data to a platform-native texture, decoded directly into a caller-supplied buffer. | |
| GuiImageData (void *t, int w, int h, bool takeOwnership=true) | |
| Constructor Populates an image directly with an already-created platform-native texture. | |
| ~GuiImageData () | |
| Destructor. | |
| bool | reload (const uint8_t *pngData, int maxw=0, int maxh=0) |
| Decodes new PNG data into this object's own texture, reusing the existing allocation whenever the platform's ImageRenderer says it can hold the new image instead of freeing and reallocating. | |
| void * | getTexture () |
| Gets the attached platform-native texture. | |
| int | getWidth () |
| Gets the image width. | |
| int | getHeight () |
| Gets the image height. | |
| bool | uploadDecoded (DecodedImage &&decoded) |
| Uploads a DecodedImage produced by decodeToRgba() into this object's own texture, reusing the existing allocation whenever ImageRenderer::canReuseTexture() allows (same policy as reload()). | |
| bool | loadClipped (const uint8_t *pngData, int boxW, int boxH, float radius, float inset=0.0f, float offsetX=0.0f, float offsetY=0.0f) |
| Decodes PNG data and fits it into a box of a given size, then masks it with a rounded rectangle: the image is centred in the box (never scaled), anything that falls outside the box or the rounded corners is cropped, and the mask edge is anti-aliased. | |
| void | clear () |
| Releases any owned texture and resets this object to the same (empty) state as a default-constructed GuiImageData. | |
Static Public Member Functions | |
| static void | setDecodeScratch (void *buffer, unsigned int size) |
| Sets the scratch buffer that every decode (the PNG-decoding constructors, reload(), decodeToRgba() and loadClipped()) will stage its raw, uncompressed pixel rows into while it runs. | |
| static Mutex & | scratchLock () |
| static DecodedImage | decodeToRgba (const uint8_t *pngData, int maxw=0, int maxh=0) |
| Decodes a PNG buffer into plain RGBA8 pixels, resizing to fit maxw/maxh the same way the decoding constructors/reload() do. | |
Protected Attributes | |
| void * | texture |
| Attached platform-native texture. | |
| int | height |
| Height of image. | |
| int | width |
| Width of image. | |
Decodes compressed image data (PNG) into a platform-native texture created from it.
Currently designed for use only with PNG files.
Definition at line 16 of file GuiImageData.h.
| GuiImageData::GuiImageData | ( | ) |
Constructor.
Definition at line 41 of file GuiImageData.cpp.
| GuiImageData::GuiImageData | ( | const uint8_t * | i, |
| int | w = 0, | ||
| int | h = 0 ) |
Constructor Converts the PNG format image data to a platform-native texture, allocated and owned by this object.
| i | Source image data (PNG) |
| w | Max image width (0 = not set) |
| h | Max image height (0 = not set) |
Definition at line 51 of file GuiImageData.cpp.
| GuiImageData::GuiImageData | ( | const uint8_t * | i, |
| uint8_t * | dst, | ||
| int | maxw = 0, | ||
| int | maxh = 0 ) |
Constructor Converts the PNG format image data to a platform-native texture, decoded directly into a caller-supplied buffer.
| i | Source image data (PNG) |
| dst | Destination texture buffer, owned by the caller |
| maxw | Max image width (0 = not set) |
| maxh | Max image height (0 = not set) |
Definition at line 64 of file GuiImageData.cpp.
| GuiImageData::GuiImageData | ( | void * | t, |
| int | w, | ||
| int | h, | ||
| bool | takeOwnership = true ) |
Constructor Populates an image directly with an already-created platform-native texture.
| t | Platform-native texture |
| w | Image width |
| h | Image height |
| takeOwnership | If true (default), this object will destroy t when it is destroyed or replaced. |
Definition at line 78 of file GuiImageData.cpp.
| GuiImageData::~GuiImageData | ( | ) |
Destructor.
Definition at line 88 of file GuiImageData.cpp.
| void GuiImageData::clear | ( | ) |
Releases any owned texture and resets this object to the same (empty) state as a default-constructed GuiImageData.
Useful for explicitly freeing GPU memory before the object itself is destroyed.
Definition at line 93 of file GuiImageData.cpp.
|
static |
Decodes a PNG buffer into plain RGBA8 pixels, resizing to fit maxw/maxh the same way the decoding constructors/reload() do.
| pngData | Source image data (PNG) |
| maxw | Max image width (0 = not set) |
| maxh | Max image height (0 = not set) |
Definition at line 132 of file GuiImageData.cpp.
|
inline |
|
inline |
Gets the attached platform-native texture.
Definition at line 57 of file GuiImageData.h.
|
inline |
| bool GuiImageData::loadClipped | ( | const uint8_t * | pngData, |
| int | boxW, | ||
| int | boxH, | ||
| float | radius, | ||
| float | inset = 0.0f, | ||
| float | offsetX = 0.0f, | ||
| float | offsetY = 0.0f ) |
Decodes PNG data and fits it into a box of a given size, then masks it with a rounded rectangle: the image is centred in the box (never scaled), anything that falls outside the box or the rounded corners is cropped, and the mask edge is anti-aliased.
Replaces this object's texture; its size becomes the box size. Use it for a picture that sits on a code-drawn button, so it can't spill over the button's border or corners.
| pngData | Source image data (PNG) |
| boxW | Box width, in design-canvas pixels |
| boxH | Box height, in design-canvas pixels |
| radius | Corner radius of the box (clamped to half the shorter side) |
| inset | Shrinks the mask on every side, eg. to stay inside a stroke |
| offsetX | Moves the image horizontally from centre (negative = left) |
| offsetY | Moves the image vertically from centre (negative = up) |
Definition at line 316 of file GuiImageData.cpp.
| bool GuiImageData::reload | ( | const uint8_t * | pngData, |
| int | maxw = 0, | ||
| int | maxh = 0 ) |
Decodes new PNG data into this object's own texture, reusing the existing allocation whenever the platform's ImageRenderer says it can hold the new image instead of freeing and reallocating.
| pngData | Source image data (PNG) |
| maxw | Max image width (0 = not set) |
| maxh | Max image height (0 = not set) |
Definition at line 123 of file GuiImageData.cpp.
|
static |
Definition at line 36 of file GuiImageData.cpp.
|
static |
Sets the scratch buffer that every decode (the PNG-decoding constructors, reload(), decodeToRgba() and loadClipped()) will stage its raw, uncompressed pixel rows into while it runs.
| buffer | Scratch buffer, owned and sized by the caller |
| size | Size of buffer, in bytes |
Definition at line 30 of file GuiImageData.cpp.
| bool GuiImageData::uploadDecoded | ( | DecodedImage && | decoded | ) |
Uploads a DecodedImage produced by decodeToRgba() into this object's own texture, reusing the existing allocation whenever ImageRenderer::canReuseTexture() allows (same policy as reload()).
Must be called on the main/GPU thread.
| decoded | Result of a prior decodeToRgba() call |
Definition at line 265 of file GuiImageData.cpp.
|
protected |
Height of image.
Definition at line 121 of file GuiImageData.h.
|
protected |
Attached platform-native texture.
Definition at line 120 of file GuiImageData.h.
|
protected |
Width of image.
Definition at line 122 of file GuiImageData.h.