X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=jpeg.c;h=4934b75899220afaa8820512e42a8c418abe1f37;hb=aa33d8f8642530f7f266d6cde1422f95aa74b2be;hp=b65e04a49e8e042137161b655cb657fbf62e76c5;hpb=5cf8eacc9621cf85f9d0474e59289b13d083260f;p=xonotic%2Fdarkplaces.git diff --git a/jpeg.c b/jpeg.c index b65e04a4..4934b758 100644 --- a/jpeg.c +++ b/jpeg.c @@ -23,6 +23,7 @@ #include "quakedef.h" +#include "image.h" #include "jpeg.h" @@ -394,40 +395,33 @@ Try to load the JPEG DLL */ qboolean JPEG_OpenLibrary (void) { - const char* dllname; - const dllfunction_t *func; + const char* dllnames [] = + { +#if defined(WIN64) + "libjpeg64.dll", +#elif defined(WIN32) + "libjpeg.dll", +#elif defined(MACOSX) + "libjpeg.62.dylib", +#else + "libjpeg.so.62", + "libjpeg.so", +#endif + NULL + }; // Already loaded? if (jpeg_dll) return true; -#ifdef WIN32 - dllname = "libjpeg.dll"; -#else - 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 (dllnames, &jpeg_dll, jpegfuncs)) { - Con_DPrintf("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_DPrintf("%s loaded. JPEG support enabled\n", dllname); + Con_Printf ("JPEG support enabled\n"); return true; } @@ -441,11 +435,7 @@ Unload the JPEG DLL */ void JPEG_CloseLibrary (void) { - if (!jpeg_dll) - return; - - Sys_UnloadLibrary (jpeg_dll); - jpeg_dll = NULL; + Sys_UnloadLibrary (&jpeg_dll); } @@ -480,9 +470,9 @@ 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, qbyte *buffer) +static void JPEG_MemSrc (j_decompress_ptr cinfo, const qbyte *buffer) { - cinfo->src = cinfo->mem->alloc_small ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (struct jpeg_source_mgr)); + 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; @@ -508,7 +498,7 @@ JPEG_LoadImage Load a JPEG image into a RGBA buffer ==================== */ -qbyte* JPEG_LoadImage (qbyte *f, int matchwidth, int matchheight) +qbyte* JPEG_LoadImage (const qbyte *f, int matchwidth, int matchheight) { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; @@ -540,8 +530,8 @@ qbyte* JPEG_LoadImage (qbyte *f, int matchwidth, int matchheight) return NULL; } - image_rgba = Mem_Alloc(tempmempool, image_width * image_height * 4); - scanline = Mem_Alloc(tempmempool, image_width * cinfo.output_components); + image_rgba = (qbyte *)Mem_Alloc(tempmempool, image_width * image_height * 4); + scanline = (qbyte *)Mem_Alloc(tempmempool, image_width * cinfo.output_components); if (!image_rgba || !scanline) { if (!image_rgba) @@ -640,7 +630,7 @@ static void JPEG_TermDestination (j_compress_ptr cinfo) // Write any data remaining in the buffer if (datacount > 0) - if (FS_Write (dest->outfile, dest->buffer, datacount) != datacount) + if (FS_Write (dest->outfile, dest->buffer, datacount) != (fs_offset_t)datacount) error_in_jpeg = true; } @@ -678,12 +668,12 @@ qboolean JPEG_SaveImage_preflipped (const char *filename, int width, int height, // No DLL = no JPEGs if (!jpeg_dll) { - Con_Printf ("You need the libjpeg library to save JPEG images\n"); + Con_Print("You need the libjpeg library to save JPEG images\n"); return false; } // Open the file - file = FS_Open (filename, "wb", true); + file = FS_Open (filename, "wb", true, false); if (!file) return false; @@ -700,7 +690,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