From de03b0de95c09f64acb66ab2e694d1c4e51a49ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Ko=C5=82odziejski?= Date: Tue, 5 Jul 2022 21:33:03 +0200 Subject: [PATCH] IMAGES: Added comments describing use case for CMYK color space format --- image/jpeg.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/image/jpeg.cpp b/image/jpeg.cpp index 0cd4df41db4..ffb197ae005 100644 --- a/image/jpeg.cpp +++ b/image/jpeg.cpp @@ -271,8 +271,13 @@ bool JPEGDecoder::loadStream(Common::SeekableReadStream &stream) { break; } - if (cinfo.num_components == 4) + // Semi-hack: + // In case 4 components jpeglib expect CMYK or CYYK color space output. + // To avoid any color space conversion, CMYK must be used. + // HPL1 engine use it to pass RGBA jpeg bitmaps. + if (cinfo.num_components == 4) { cinfo.out_color_space = JCS_CMYK; + } // Actually start decompressing the image jpeg_start_decompress(&cinfo); @@ -297,6 +302,10 @@ bool JPEGDecoder::loadStream(Common::SeekableReadStream &stream) { default: break; } + // Size of output pixel must match 4 bytes. + if (cinfo.out_color_space == JCS_CMYK) { + assert(_surface.format.bytesPerPixel == 4); + } // Allocate buffer for one scanline JDIMENSION pitch = cinfo.output_width * _surface.format.bytesPerPixel;