mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-06-03 00:58:15 -04:00
JXL: fixed bug when saving grayscale images without color profile
Saving grayscale images at less than 100% quality made the file unreadable. Fix also a regression while loading GrayA images introduced with MR !250
This commit is contained in:
parent
c38a1a0248
commit
a664baa9f9
BIN
autotests/read/jxl/testcard_graya.jxl
Normal file
BIN
autotests/read/jxl/testcard_graya.jxl
Normal file
Binary file not shown.
BIN
autotests/read/jxl/testcard_graya.png
Normal file
BIN
autotests/read/jxl/testcard_graya.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.4 KiB |
@ -243,23 +243,21 @@ bool QJpegXLHandler::countALLFrames()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_gray = m_basicinfo.num_color_channels == 1 && m_basicinfo.num_extra_channels == 0;
|
||||
JxlColorEncoding color_encoding;
|
||||
if (m_basicinfo.uses_original_profile == JXL_FALSE) {
|
||||
JxlColorEncodingSetToSRGB(&color_encoding, JXL_FALSE);
|
||||
JxlColorEncodingSetToSRGB(&color_encoding, is_gray ? JXL_TRUE : JXL_FALSE);
|
||||
JxlDecoderSetPreferredColorProfile(m_decoder, &color_encoding);
|
||||
}
|
||||
|
||||
bool loadalpha;
|
||||
|
||||
bool loadalpha = false;
|
||||
if (m_basicinfo.alpha_bits > 0) {
|
||||
loadalpha = true;
|
||||
} else {
|
||||
loadalpha = false;
|
||||
}
|
||||
|
||||
m_input_pixel_format.endianness = JXL_NATIVE_ENDIAN;
|
||||
m_input_pixel_format.align = 0;
|
||||
m_input_pixel_format.num_channels = m_basicinfo.num_color_channels == 1 ? 1 : 4;
|
||||
m_input_pixel_format.num_channels = is_gray ? 1 : 4;
|
||||
|
||||
if (m_basicinfo.bits_per_sample > 8) { // high bit depth
|
||||
#ifdef JXL_HDR_PRESERVATION_DISABLED
|
||||
@ -270,7 +268,7 @@ bool QJpegXLHandler::countALLFrames()
|
||||
m_input_pixel_format.data_type = is_fp ? JXL_TYPE_FLOAT16 : JXL_TYPE_UINT16;
|
||||
m_buffer_size = (size_t)m_basicinfo.xsize * (size_t)m_basicinfo.ysize * m_input_pixel_format.num_channels * 2;
|
||||
|
||||
if (m_basicinfo.num_color_channels == 1) {
|
||||
if (is_gray) {
|
||||
m_input_pixel_format.data_type = JXL_TYPE_UINT16;
|
||||
m_input_image_format = m_target_image_format = QImage::Format_Grayscale16;
|
||||
m_buffer_size = (size_t)m_basicinfo.xsize * (size_t)m_basicinfo.ysize * m_input_pixel_format.num_channels * 2;
|
||||
@ -294,7 +292,7 @@ bool QJpegXLHandler::countALLFrames()
|
||||
m_input_pixel_format.data_type = JXL_TYPE_UINT8;
|
||||
m_buffer_size = (size_t)m_basicinfo.xsize * (size_t)m_basicinfo.ysize * m_input_pixel_format.num_channels;
|
||||
|
||||
if (m_basicinfo.num_color_channels == 1) {
|
||||
if (is_gray) {
|
||||
m_input_image_format = m_target_image_format = QImage::Format_Grayscale8;
|
||||
} else {
|
||||
m_input_image_format = QImage::Format_RGBA8888;
|
||||
@ -630,7 +628,7 @@ bool QJpegXLHandler::write(const QImage &image)
|
||||
// no profile or Qt-unsupported ICC profile
|
||||
iccprofile = tmpcs.iccProfile();
|
||||
// note: lossless encoding requires uses_original_profile = JXL_TRUE
|
||||
if (iccprofile.size() > 0 || m_quality == 100) {
|
||||
if (iccprofile.size() > 0 || m_quality == 100 || is_gray) {
|
||||
output_info.uses_original_profile = JXL_TRUE;
|
||||
}
|
||||
}
|
||||
@ -808,7 +806,7 @@ bool QJpegXLHandler::write(const QImage &image)
|
||||
}
|
||||
} else {
|
||||
JxlColorEncoding color_profile;
|
||||
JxlColorEncodingSetToSRGB(&color_profile, JXL_FALSE);
|
||||
JxlColorEncodingSetToSRGB(&color_profile, is_gray ? JXL_TRUE : JXL_FALSE);
|
||||
|
||||
status = JxlEncoderSetColorEncoding(encoder, &color_profile);
|
||||
if (status != JXL_ENC_SUCCESS) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user