]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - jpeg.c
rewrote Cmd_StuffCmds_f (commandline parser), it now properly handles quoted strings...
[xonotic/darkplaces.git] / jpeg.c
diff --git a/jpeg.c b/jpeg.c
index 063a86f427c216331b26647bb3f68bb3e0356bcf..2637a03085829eca52d48e7dacc1ff0434c5cd45 100644 (file)
--- a/jpeg.c
+++ b/jpeg.c
@@ -395,7 +395,6 @@ Try to load the JPEG DLL
 qboolean JPEG_OpenLibrary (void)
 {
        const char* dllname;
-       const dllfunction_t *func;
 
        // Already loaded?
        if (jpeg_dll)
@@ -407,27 +406,14 @@ qboolean JPEG_OpenLibrary (void)
        dllname = "libjpeg.so.62";
 #endif
 
-       // Initializations
-       for (func = jpegfuncs; func && func->name != NULL; func++)
-               *func->funcvariable = NULL;
-
        // Load the DLL
-       if (! (jpeg_dll = Sys_LoadLibrary (dllname)))
+       if (! Sys_LoadLibrary (dllname, &jpeg_dll, jpegfuncs))
        {
-               Con_Printf ("Can't find %s. JPEG support disabled\n", dllname);
+               Con_Printf ("JPEG support disabled\n");
                return false;
        }
 
-       // Get the function adresses
-       for (func = jpegfuncs; func && func->name != NULL; func++)
-               if (!(*func->funcvariable = (void *) Sys_GetProcAddress (jpeg_dll, func->name)))
-               {
-                       Con_Printf ("missing function \"%s\" - broken JPEG library!\n", func->name);
-                       JPEG_CloseLibrary ();
-                       return false;
-               }
-
-       Con_Printf ("%s loaded. JPEG support enabled\n", dllname);
+       Con_Printf ("JPEG support enabled\n");
        return true;
 }
 
@@ -441,11 +427,7 @@ Unload the JPEG DLL
 */
 void JPEG_CloseLibrary (void)
 {
-       if (!jpeg_dll)
-               return;
-
-       Sys_UnloadLibrary (jpeg_dll);
-       jpeg_dll = NULL;
+       Sys_UnloadLibrary (&jpeg_dll);
 }
 
 
@@ -534,6 +516,11 @@ qbyte* JPEG_LoadImage (qbyte *f, int matchwidth, int matchheight)
                qjpeg_destroy_decompress (&cinfo);
                return NULL;
        }
+       if (image_width > 4096 || image_height > 4096 || image_width <= 0 || image_height <= 0)
+       {
+               Con_Printf("JPEG_LoadImage: invalid image size %ix%i\n", image_width, image_height);
+               return NULL;
+       }
 
        image_rgba = Mem_Alloc(tempmempool, image_width * image_height * 4);
        scanline = Mem_Alloc(tempmempool, image_width * cinfo.output_components);
@@ -673,7 +660,7 @@ qboolean JPEG_SaveImage_preflipped (const char *filename, int width, int height,
        // No DLL = no JPEGs
        if (!jpeg_dll)
        {
-               Con_Print("You need the libjpeg library to save JPEG images\n");
+               Con_Print("You need the libjpeg library to save JPEG images\n");
                return false;
        }
 
@@ -695,7 +682,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, 90, TRUE);  // 90% quality; FIXME: use a cvar
+       qjpeg_set_quality (&cinfo, scr_screenshot_jpeg_quality.value * 100, TRUE);
        qjpeg_start_compress (&cinfo, true);
 
        // Compress each scanline