]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - jpeg.c
patch from div0 that enables printf format warnings in gcc
[xonotic/darkplaces.git] / jpeg.c
diff --git a/jpeg.c b/jpeg.c
index 44bbb5fec7df99c2b4db78aac9f8e2194047242c..c85c90a681f825e586cd87d9898a25e2979b097e 100644 (file)
--- a/jpeg.c
+++ b/jpeg.c
@@ -470,12 +470,12 @@ static void JPEG_SkipInputData (j_decompress_ptr cinfo, long num_bytes)
     cinfo->src->bytes_in_buffer -= num_bytes;
 }
 
-static void JPEG_MemSrc (j_decompress_ptr cinfo, const unsigned char *buffer)
+static void JPEG_MemSrc (j_decompress_ptr cinfo, const unsigned char *buffer, size_t filesize)
 {
        cinfo->src = (struct jpeg_source_mgr *)cinfo->mem->alloc_small ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (struct jpeg_source_mgr));
 
        cinfo->src->next_input_byte = buffer;
-       cinfo->src->bytes_in_buffer = fs_filesize;
+       cinfo->src->bytes_in_buffer = filesize;
 
        cinfo->src->init_source = JPEG_Noop;
        cinfo->src->fill_input_buffer = JPEG_FillInputBuffer;
@@ -498,7 +498,7 @@ JPEG_LoadImage
 Load a JPEG image into a RGBA buffer
 ====================
 */
-unsigned char* JPEG_LoadImage (const unsigned char *f, int matchwidth, int matchheight)
+unsigned char* JPEG_LoadImage (const unsigned char *f, int filesize, int matchwidth, int matchheight)
 {
        struct jpeg_decompress_struct cinfo;
        struct jpeg_error_mgr jerr;
@@ -511,7 +511,7 @@ unsigned char* JPEG_LoadImage (const unsigned char *f, int matchwidth, int match
 
        cinfo.err = qjpeg_std_error (&jerr);
        qjpeg_create_decompress (&cinfo);
-       JPEG_MemSrc (&cinfo, f);
+       JPEG_MemSrc (&cinfo, f, filesize);
        qjpeg_read_header (&cinfo, TRUE);
        qjpeg_start_decompress (&cinfo);
 
@@ -534,8 +534,10 @@ unsigned char* JPEG_LoadImage (const unsigned char *f, int matchwidth, int match
        scanline = (unsigned char *)Mem_Alloc(tempmempool, image_width * cinfo.output_components);
        if (!image_rgba || !scanline)
        {
-               if (!image_rgba)
+               if (image_rgba)
                        Mem_Free (image_rgba);
+               if (scanline)
+                       Mem_Free (scanline);
 
                Con_Printf("JPEG_LoadImage: not enough memory for %i by %i image\n", image_width, image_height);
                qjpeg_finish_decompress (&cinfo);
@@ -690,7 +692,7 @@ qboolean JPEG_SaveImage_preflipped (const char *filename, int width, int height,
        cinfo.in_color_space = JCS_RGB;
        cinfo.input_components = 3;
        qjpeg_set_defaults (&cinfo);
-       qjpeg_set_quality (&cinfo, scr_screenshot_jpeg_quality.value * 100, TRUE);
+       qjpeg_set_quality (&cinfo, (int)(scr_screenshot_jpeg_quality.value * 100), TRUE);
        qjpeg_start_compress (&cinfo, true);
 
        // Compress each scanline