From e51984ed9b79ed7b1eede2577d9818c0c06c3ce6 Mon Sep 17 00:00:00 2001 From: Crayon2000 Date: Tue, 15 Dec 2009 18:27:31 +0000 Subject: [PATCH] [NEW] GRRLIB_LoadTextureJPGEx, uses the size parameter --- GRRLIB/GRRLIB/GRRLIB_texEdit.c | 31 ++++++++++++++++++++---------- GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/GRRLIB/GRRLIB/GRRLIB_texEdit.c b/GRRLIB/GRRLIB/GRRLIB_texEdit.c index 832e6ea..c4e3883 100644 --- a/GRRLIB/GRRLIB/GRRLIB_texEdit.c +++ b/GRRLIB/GRRLIB/GRRLIB_texEdit.c @@ -278,20 +278,12 @@ GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) { /** * Load a texture from a buffer. - * Take care to have the JPG finnish with 0xFF 0xD9!! - * @author DrTwox + * Take care to have the JPG finnish with 0xFF 0xD9! * @param my_jpg The JPEG buffer to load. * @return A GRRLIB_texImg structure filled with image information. */ 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; - unsigned int i; - - if(my_texture == NULL) - return NULL; if ((my_jpg[0]==0xFF) && (my_jpg[1]==0xD8) && (my_jpg[2]==0xFF)) { while(true) { @@ -302,10 +294,29 @@ GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg) { 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); cinfo.err = jpeg_std_error(&jerr); cinfo.progress = NULL; - jpeg_memory_src(&cinfo, my_jpg, n); + jpeg_memory_src(&cinfo, my_jpg, my_size); jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress(&cinfo); unsigned char *tempBuffer = malloc(cinfo.output_width * cinfo.output_height * cinfo.num_components); diff --git a/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h b/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h index 6e5ff66..9d965b3 100644 --- a/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h +++ b/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h @@ -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_LoadTexturePNG (const u8 *my_png) ; 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) ; //------------------------------------------------------------------------------