libgui 3.00
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiImageData.h
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2009-2026
4 * GuiImageData.h
5 ***************************************************************************/
6#pragma once
7
8#include <memory>
9#include <cstdlib>
10
11#include "../drivers/Mutex.h"
12
17{
18 public:
27 GuiImageData(const uint8_t * i, int w=0, int h=0);
35 GuiImageData(const uint8_t * i, uint8_t * dst, int maxw=0, int maxh=0);
44 GuiImageData(void * t, int w, int h, bool takeOwnership = true);
54 bool reload(const uint8_t * pngData, int maxw = 0, int maxh = 0);
57 void * getTexture() { return texture; }
60 int getWidth() { return width; }
63 int getHeight() { return height; }
69 static void setDecodeScratch(void * buffer, unsigned int size);
73 static Mutex & scratchLock();
74
78 {
79 std::unique_ptr<uint8_t, decltype(&free)> rgba{nullptr, free};
80 int width = 0;
81 int height = 0;
83 bool assetScaled = true;
84 bool valid() const { return rgba != nullptr; }
85 };
86
92 static DecodedImage decodeToRgba(const uint8_t * pngData, int maxw = 0, int maxh = 0);
99 bool uploadDecoded(DecodedImage && decoded);
114 bool loadClipped(const uint8_t * pngData, int boxW, int boxH, float radius, float inset = 0.0f, float offsetX = 0.0f, float offsetY = 0.0f);
118 void clear();
119 protected:
120 void * texture;
121 int height;
122 int width;
123 private:
124 bool ownsTexture;
125 int capWidth;
126 int capHeight;
129 bool decodeImage(const uint8_t * pngData, int * width, int * height, int maxw, int maxh);
130};
int width
Width of image.
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 con...
~GuiImageData()
Destructor.
void clear()
Releases any owned texture and resets this object to the same (empty) state as a default-constructed ...
bool uploadDecoded(DecodedImage &&decoded)
Uploads a DecodedImage produced by decodeToRgba() into this object's own texture, reusing the existin...
GuiImageData()
Constructor.
void * texture
Attached platform-native texture.
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 pla...
static void setDecodeScratch(void *buffer, unsigned int size)
Sets the scratch buffer that every decode (the PNG-decoding constructors, 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 ...
void * getTexture()
Gets the attached platform-native texture.
int getWidth()
Gets the image width.
int height
Height of image.
int getHeight()
Gets the image height.
static Mutex & scratchLock()
A simple mutual-exclusion lock.
Definition Mutex.h:14
CPU-only decode result from decodeToRgba(): raw RGBA8 pixel data that has NOT been uploaded to a plat...
std::unique_ptr< uint8_t, decltype(&free)> rgba
row-major RGBA8, or null if decode failed
bool assetScaled
False when maxw/maxh constrained this decode to a caller-specified pixel box.