kimgio: verify the image color space earlier in jp2 plugin

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-11-27 18:23:35 +02:00
parent a0afe27554
commit d598c3cccf

View file

@ -179,15 +179,6 @@ bool JP2Handler::read(QImage *image)
return false; return false;
} }
*image = QImage(ojimage->comps->w, ojimage->comps->h, QImage::Format_ARGB32);
if (Q_UNLIKELY(image->isNull())) {
kWarning() << "Could not create image";
opj_destroy_codec(ojcodec);
opj_stream_destroy(ojstream);
opj_image_destroy(ojimage);
return false;
}
switch (ojimage->color_space) { switch (ojimage->color_space) {
case OPJ_CLRSPC_UNKNOWN: case OPJ_CLRSPC_UNKNOWN:
case OPJ_CLRSPC_UNSPECIFIED: { case OPJ_CLRSPC_UNSPECIFIED: {
@ -210,6 +201,15 @@ bool JP2Handler::read(QImage *image)
} }
} }
*image = QImage(ojimage->comps->w, ojimage->comps->h, QImage::Format_ARGB32);
if (Q_UNLIKELY(image->isNull())) {
kWarning() << "Could not create image";
opj_destroy_codec(ojcodec);
opj_stream_destroy(ojstream);
opj_image_destroy(ojimage);
return false;
}
switch (ojimage->numcomps) { switch (ojimage->numcomps) {
case 4: { case 4: {
QRgb* imagebits = reinterpret_cast<QRgb*>(image->bits()); QRgb* imagebits = reinterpret_cast<QRgb*>(image->bits());