[NEW] GRRLIB_LoadTextureJPGEx, uses the size parameter

This commit is contained in:
Crayon2000 2009-12-15 18:27:31 +00:00
parent 33405a6e70
commit e51984ed9b
2 changed files with 22 additions and 10 deletions

View file

@ -278,20 +278,12 @@ GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) {
/** /**
* Load a texture from a buffer. * Load a texture from a buffer.
* Take care to have the JPG finnish with 0xFF 0xD9!! * Take care to have the JPG finnish with 0xFF 0xD9!
* @author DrTwox
* @param my_jpg The JPEG buffer to load. * @param my_jpg The JPEG buffer to load.
* @return A GRRLIB_texImg structure filled with image information. * @return A GRRLIB_texImg structure filled with image information.
*/ */
GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg) { GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg) {
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg));
int n = 0; int n = 0;
unsigned int i;
if(my_texture == NULL)
return NULL;
if ((my_jpg[0]==0xFF) && (my_jpg[1]==0xD8) && (my_jpg[2]==0xFF)) { if ((my_jpg[0]==0xFF) && (my_jpg[1]==0xD8) && (my_jpg[2]==0xFF)) {
while(true) { while(true) {
@ -302,10 +294,29 @@ GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg) {
n+=2; n+=2;
} }
return GRRLIB_LoadTextureJPGEx(my_jpg, n);
}
/**
* Load a texture from a buffer.
* @author DrTwox
* @param my_jpg The JPEG buffer to load.
* @param my_size Size of the JPEG buffer to load.
* @return A GRRLIB_texImg structure filled with image information.
*/
GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const int my_size) {
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg));
unsigned int i;
if(my_texture == NULL)
return NULL;
jpeg_create_decompress(&cinfo); jpeg_create_decompress(&cinfo);
cinfo.err = jpeg_std_error(&jerr); cinfo.err = jpeg_std_error(&jerr);
cinfo.progress = NULL; cinfo.progress = NULL;
jpeg_memory_src(&cinfo, my_jpg, n); jpeg_memory_src(&cinfo, my_jpg, my_size);
jpeg_read_header(&cinfo, TRUE); jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo); jpeg_start_decompress(&cinfo);
unsigned char *tempBuffer = malloc(cinfo.output_width * cinfo.output_height * cinfo.num_components); unsigned char *tempBuffer = malloc(cinfo.output_width * cinfo.output_height * cinfo.num_components);

View file

@ -130,6 +130,7 @@ void GRRLIB_CompoEnd(int posx, int posy, GRRLIB_texImg *tex);
GRRLIB_texImg* GRRLIB_LoadTexture (const u8 *my_img) ; GRRLIB_texImg* GRRLIB_LoadTexture (const u8 *my_img) ;
GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png) ; GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png) ;
GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg) ; GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg) ;
GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const int) ;
GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) ; GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) ;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------