====================
JPEG_LoadImage
-Load a JPEG image into a RGBA buffer
+Load a JPEG image into a BGRA buffer
====================
*/
-unsigned char* JPEG_LoadImage (const unsigned char *f, int filesize, int matchwidth, int matchheight)
+unsigned char* JPEG_LoadImage_BGRA (const unsigned char *f, int filesize)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
- unsigned char *image_rgba, *scanline;
+ unsigned char *image_buffer, *scanline;
unsigned int line;
// No DLL = no JPEGs
image_width = cinfo.image_width;
image_height = cinfo.image_height;
- if ((matchwidth && image_width != matchwidth) || (matchheight && image_height != matchheight))
- {
- qjpeg_finish_decompress (&cinfo);
- 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 = (unsigned char *)Mem_Alloc(tempmempool, image_width * image_height * 4);
+ image_buffer = (unsigned char *)Mem_Alloc(tempmempool, image_width * image_height * 4);
scanline = (unsigned char *)Mem_Alloc(tempmempool, image_width * cinfo.output_components);
- if (!image_rgba || !scanline)
+ if (!image_buffer || !scanline)
{
- if (!image_rgba)
- Mem_Free (image_rgba);
+ if (image_buffer)
+ Mem_Free (image_buffer);
+ 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);
qjpeg_read_scanlines (&cinfo, &scanline, 1);
- // Convert the image to RGBA
+ // Convert the image to BGRA
switch (cinfo.output_components)
{
// RGB images
case 3:
- buffer_ptr = &image_rgba[image_width * line * 4];
+ buffer_ptr = &image_buffer[image_width * line * 4];
for (ind = 0; ind < image_width * 3; ind += 3, buffer_ptr += 4)
{
- buffer_ptr[0] = scanline[ind];
+ buffer_ptr[2] = scanline[ind];
buffer_ptr[1] = scanline[ind + 1];
- buffer_ptr[2] = scanline[ind + 2];
+ buffer_ptr[0] = scanline[ind + 2];
buffer_ptr[3] = 255;
}
break;
// Greyscale images (default to it, just in case)
case 1:
default:
- buffer_ptr = &image_rgba[image_width * line * 4];
+ buffer_ptr = &image_buffer[image_width * line * 4];
for (ind = 0; ind < image_width; ind++, buffer_ptr += 4)
{
buffer_ptr[0] = scanline[ind];
qjpeg_finish_decompress (&cinfo);
qjpeg_destroy_decompress (&cinfo);
- return image_rgba;
+ return image_buffer;
}
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