From f04aced37fbb4bb49745350b76bc26f4b8d00e7e Mon Sep 17 00:00:00 2001 From: Crayon2000 Date: Mon, 8 Feb 2010 16:25:50 +0000 Subject: [PATCH] [BUG] Problem with GRAYSCALE JPEG image. (Solved by DrTwox) --- GRRLIB/GRRLIB/GRRLIB_texEdit.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/GRRLIB/GRRLIB/GRRLIB_texEdit.c b/GRRLIB/GRRLIB/GRRLIB_texEdit.c index 2710043..f490a89 100644 --- a/GRRLIB/GRRLIB/GRRLIB_texEdit.c +++ b/GRRLIB/GRRLIB/GRRLIB_texEdit.c @@ -317,14 +317,17 @@ GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const int my_size) { cinfo.progress = NULL; jpeg_mem_src(&cinfo, (unsigned char *)my_jpg, my_size); jpeg_read_header(&cinfo, TRUE); + if(cinfo.jpeg_color_space == JCS_GRAYSCALE) { + cinfo.out_color_space = JCS_RGB; + } 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.output_components); JSAMPROW row_pointer[1]; - row_pointer[0] = malloc(cinfo.output_width * cinfo.num_components); + row_pointer[0] = malloc(cinfo.output_width * cinfo.output_components); size_t location = 0; while (cinfo.output_scanline < cinfo.output_height) { jpeg_read_scanlines(&cinfo, row_pointer, 1); - for (i = 0; i < cinfo.image_width * cinfo.num_components; i++) { + for (i = 0; i < cinfo.image_width * cinfo.output_components; i++) { /* Put the decoded scanline into the tempBuffer */ tempBuffer[ location++ ] = row_pointer[0][i]; }