mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2026-05-28 05:39:08 -04:00
jxl: fix crash on lossy gray images
There was a rare crash during decoding of some lossy gray images. Problem was reported in https://github.com/libjxl/libjxl/issues/4549 This is a workaround which avoids JxlDecoderSetCms call.
This commit is contained in:
@@ -258,14 +258,16 @@ bool QJpegXLHandler::countALLFrames()
|
|||||||
bool is_gray = m_basicinfo.num_color_channels == 1 && m_basicinfo.alpha_bits == 0;
|
bool is_gray = m_basicinfo.num_color_channels == 1 && m_basicinfo.alpha_bits == 0;
|
||||||
JxlColorEncoding color_encoding;
|
JxlColorEncoding color_encoding;
|
||||||
if (m_basicinfo.uses_original_profile == JXL_FALSE && m_basicinfo.have_animation == JXL_FALSE) {
|
if (m_basicinfo.uses_original_profile == JXL_FALSE && m_basicinfo.have_animation == JXL_FALSE) {
|
||||||
const JxlCmsInterface *jxlcms = JxlGetDefaultCms();
|
if (!is_gray) {
|
||||||
if (jxlcms) {
|
const JxlCmsInterface *jxlcms = JxlGetDefaultCms();
|
||||||
status = JxlDecoderSetCms(m_decoder, *jxlcms);
|
if (jxlcms) {
|
||||||
if (status != JXL_DEC_SUCCESS) {
|
status = JxlDecoderSetCms(m_decoder, *jxlcms);
|
||||||
qCWarning(LOG_JXLPLUGIN, "JxlDecoderSetCms ERROR");
|
if (status != JXL_DEC_SUCCESS) {
|
||||||
|
qCWarning(LOG_JXLPLUGIN, "JxlDecoderSetCms ERROR");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCWarning(LOG_JXLPLUGIN, "No JPEG XL CMS Interface");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
qCWarning(LOG_JXLPLUGIN, "No JPEG XL CMS Interface");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JxlColorEncodingSetToSRGB(&color_encoding, is_gray ? JXL_TRUE : JXL_FALSE);
|
JxlColorEncodingSetToSRGB(&color_encoding, is_gray ? JXL_TRUE : JXL_FALSE);
|
||||||
@@ -853,7 +855,11 @@ bool QJpegXLHandler::write(const QImage &image)
|
|||||||
|
|
||||||
size_t pixel_count = size_t(image.width()) * image.height();
|
size_t pixel_count = size_t(image.width()) * image.height();
|
||||||
if (MAX_IMAGE_PIXELS && pixel_count > MAX_IMAGE_PIXELS) {
|
if (MAX_IMAGE_PIXELS && pixel_count > MAX_IMAGE_PIXELS) {
|
||||||
qCWarning(LOG_JXLPLUGIN, "Image (%dx%d) will not be saved because it has more than %d megapixels!", image.width(), image.height(), MAX_IMAGE_PIXELS / 1024 / 1024);
|
qCWarning(LOG_JXLPLUGIN,
|
||||||
|
"Image (%dx%d) will not be saved because it has more than %d megapixels!",
|
||||||
|
image.width(),
|
||||||
|
image.height(),
|
||||||
|
MAX_IMAGE_PIXELS / 1024 / 1024);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1838,17 +1844,20 @@ bool QJpegXLHandler::rewind()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const JxlCmsInterface *jxlcms = JxlGetDefaultCms();
|
bool is_gray = m_basicinfo.num_color_channels == 1 && m_basicinfo.alpha_bits == 0;
|
||||||
if (jxlcms) {
|
|
||||||
status = JxlDecoderSetCms(m_decoder, *jxlcms);
|
if (!is_gray) {
|
||||||
if (status != JXL_DEC_SUCCESS) {
|
const JxlCmsInterface *jxlcms = JxlGetDefaultCms();
|
||||||
qCWarning(LOG_JXLPLUGIN, "JxlDecoderSetCms ERROR");
|
if (jxlcms) {
|
||||||
|
status = JxlDecoderSetCms(m_decoder, *jxlcms);
|
||||||
|
if (status != JXL_DEC_SUCCESS) {
|
||||||
|
qCWarning(LOG_JXLPLUGIN, "JxlDecoderSetCms ERROR");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCWarning(LOG_JXLPLUGIN, "No JPEG XL CMS Interface");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
qCWarning(LOG_JXLPLUGIN, "No JPEG XL CMS Interface");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_gray = m_basicinfo.num_color_channels == 1 && m_basicinfo.alpha_bits == 0;
|
|
||||||
JxlColorEncoding color_encoding;
|
JxlColorEncoding color_encoding;
|
||||||
JxlColorEncodingSetToSRGB(&color_encoding, is_gray ? JXL_TRUE : JXL_FALSE);
|
JxlColorEncodingSetToSRGB(&color_encoding, is_gray ? JXL_TRUE : JXL_FALSE);
|
||||||
JxlDecoderSetPreferredColorProfile(m_decoder, &color_encoding);
|
JxlDecoderSetPreferredColorProfile(m_decoder, &color_encoding);
|
||||||
|
|||||||
Reference in New Issue
Block a user