mirror of
https://github.com/wiiu-env/libgui.git
synced 2025-01-26 23:15:27 +01:00
GuiImageData: Add option to load directly from a file (#19)
This commit is contained in:
parent
4a0e27624b
commit
9c1b9ba442
@ -31,6 +31,9 @@ public:
|
|||||||
//!\param imgSize The image size
|
//!\param imgSize The image size
|
||||||
GuiImageData(const uint8_t *img, int32_t imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8);
|
GuiImageData(const uint8_t *img, int32_t imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8);
|
||||||
|
|
||||||
|
//!\param path Image path
|
||||||
|
GuiImageData(const char *path, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat);
|
||||||
|
|
||||||
//!Destructor
|
//!Destructor
|
||||||
virtual ~GuiImageData();
|
virtual ~GuiImageData();
|
||||||
|
|
||||||
@ -39,6 +42,10 @@ public:
|
|||||||
//!\param imgSize The image size
|
//!\param imgSize The image size
|
||||||
void loadImage(const uint8_t *img, int32_t imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8);
|
void loadImage(const uint8_t *img, int32_t imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8);
|
||||||
|
|
||||||
|
//!Load image from file
|
||||||
|
//!\param path Image path
|
||||||
|
void loadImageFromFile(const char *path, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat);
|
||||||
|
|
||||||
//! getter functions
|
//! getter functions
|
||||||
virtual const GX2Texture *getTexture() const {
|
virtual const GX2Texture *getTexture() const {
|
||||||
return texture;
|
return texture;
|
||||||
|
@ -14,10 +14,12 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <gui/GuiImageData.h>
|
#include <gui/GuiImageData.h>
|
||||||
#include <gui/memory.h>
|
#include <gui/memory.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,6 +40,16 @@ GuiImageData::GuiImageData(const uint8_t *img, int32_t imgSize, GX2TexClampMode
|
|||||||
loadImage(img, imgSize, textureClamp, textureFormat);
|
loadImage(img, imgSize, textureClamp, textureFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the GuiImageData class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
GuiImageData::GuiImageData(const char *path, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat) {
|
||||||
|
texture = NULL;
|
||||||
|
sampler = NULL;
|
||||||
|
loadImageFromFile(path, textureClamp, textureFormat);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor for the GuiImageData class.
|
* Destructor for the GuiImageData class.
|
||||||
*/
|
*/
|
||||||
@ -70,6 +82,24 @@ void GuiImageData::releaseData(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiImageData::loadImageFromFile(const char *path, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat) {
|
||||||
|
FILE *file = fopen(path, "rb");
|
||||||
|
if (file) {
|
||||||
|
off_t i = ftello(file);
|
||||||
|
if (fseek(file, 0, SEEK_END) == 0) {
|
||||||
|
off_t fileSize = ftello(file);
|
||||||
|
if (fileSize > 8) {
|
||||||
|
fseeko(file, i, SEEK_SET);
|
||||||
|
uint8_t buffer[fileSize];
|
||||||
|
if (fread(buffer, 1, fileSize, file) == fileSize) {
|
||||||
|
loadImage(buffer, fileSize, textureClamp, textureFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GuiImageData::loadImage(const uint8_t *img, int32_t imgSize, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat) {
|
void GuiImageData::loadImage(const uint8_t *img, int32_t imgSize, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat) {
|
||||||
if (!img || (imgSize < 8)) {
|
if (!img || (imgSize < 8)) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user