mirror of
https://github.com/AntonioND/ulibrary.git
synced 2025-06-18 23:05:50 -04:00

The compiler will be able to warn us if we use a value that doesn't correspond to the expected enum, which can be a source of bugs.
52 lines
1.3 KiB
C
52 lines
1.3 KiB
C
#include "ulib.h"
|
|
#include "jpeg/gba-jpeg.h"
|
|
#include "jpeg/gba-jpeg-decode.h"
|
|
|
|
UL_IMAGE *ulLoadImageJPG(VIRTUAL_FILE *f, UL_IMAGE_LOCATION location,
|
|
UL_IMAGE_FORMATS pixelFormat)
|
|
{
|
|
UL_IMAGE *img = NULL;
|
|
const unsigned char *input, *input_free;
|
|
|
|
// Format 16 bits obligatoire pour le JPG!
|
|
if (ul_pixelWidth[pixelFormat] != 16)
|
|
return NULL;
|
|
|
|
input = (const unsigned char*)ulReadEntireFileToMemory(f, NULL);
|
|
input_free = input;
|
|
|
|
if (input)
|
|
{
|
|
int width, height;
|
|
JPEG_Decoder decoder;
|
|
|
|
JPEG_Decoder_ReadHeaders(&decoder, &input);
|
|
width = decoder.frame.width;
|
|
height = decoder.frame.height;
|
|
|
|
// Crée l'image dans laquelle on mettra notre bitmap
|
|
img = ulCreateImage(width, height, UL_IN_RAM, pixelFormat, 0);
|
|
|
|
if (img)
|
|
{
|
|
if (!JPEG_Decoder_ReadImage (&decoder, &input, img->texture, img->sysSizeX, img->sysSizeY))
|
|
{
|
|
ulDeleteImage(img);
|
|
img = NULL;
|
|
}
|
|
}
|
|
|
|
free((void*)input_free);
|
|
|
|
if (location == UL_IN_VRAM)
|
|
{
|
|
if (!ulRealizeImage(img))
|
|
{
|
|
ulDeleteImage(img);
|
|
return NULL;
|
|
}
|
|
}
|
|
}
|
|
return img;
|
|
}
|