jpeg handler: store Grayscale16 format images as grayscale, not rgb

No point in storing multiple channels when we have single channel
data. And as jpeg anyway has only 8 bpc, information loss is
unavoidable, so just convert to Grayscale8 and store as that.

Fixes: QTBUG-107810
Change-Id: Ib62038acf07d4b875b8416825fb0095510c14b5b
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
Eirik Aavitsland 2022-10-21 13:56:30 +02:00
parent 7d99fa8e5b
commit 311e508154

View File

@ -532,6 +532,7 @@ static bool do_write_jpeg_image(struct jpeg_compress_struct &cinfo,
cinfo.in_color_space = gray ? JCS_GRAYSCALE : JCS_RGB;
break;
case QImage::Format_Grayscale8:
case QImage::Format_Grayscale16:
gray = true;
cinfo.input_components = 1;
cinfo.in_color_space = JCS_GRAYSCALE;
@ -630,6 +631,12 @@ static bool do_write_jpeg_image(struct jpeg_compress_struct &cinfo,
case QImage::Format_Grayscale8:
memcpy(row, image.constScanLine(cinfo.next_scanline), w);
break;
case QImage::Format_Grayscale16:
{
QImage rowImg = image.copy(0, cinfo.next_scanline, w, 1).convertToFormat(QImage::Format_Grayscale8);
memcpy(row, rowImg.constScanLine(0), w);
}
break;
case QImage::Format_RGB888:
memcpy(row, image.constScanLine(cinfo.next_scanline), w * 3);
break;