RGB/SGI writer: fix alpha detection and image limit size

This commit is contained in:
Mirco Miranda 2023-05-07 10:46:23 +02:00 committed by Albert Astals Cid
parent c9fec5e408
commit d787c12727
2 changed files with 8 additions and 11 deletions

View File

@ -672,11 +672,13 @@ bool SGIImage::writeImage(const QImage &image)
_dim = 3, _zsize = 3;
}
if (img.format() == QImage::Format_ARGB32) {
if (img.hasAlphaChannel()) {
_dim = 3, _zsize++;
}
img = img.convertToFormat(QImage::Format_RGB32);
if (img.format() != QImage::Format_ARGB32) {
img = img.convertToFormat(QImage::Format_ARGB32);
}
if (img.isNull()) {
// qDebug() << "can't convert image to depth 32";
return false;
@ -685,7 +687,7 @@ bool SGIImage::writeImage(const QImage &image)
const int w = img.width();
const int h = img.height();
if (w > 65536 || h > 65536) {
if (w > 65535 || h > 65535) {
return false;
}
@ -712,12 +714,6 @@ bool SGIImage::writeImage(const QImage &image)
rle_size += _rlevector[i]->size();
}
// qDebug() << "minimum intensity: " << _pixmin;
// qDebug() << "maximum intensity: " << _pixmax;
// qDebug() << "saved scanlines: " << _numrows - _rlemap.size();
// qDebug() << "total savings: " << (verbatim_size - rle_size) << " bytes";
// qDebug() << "compression: " << (rle_size * 100.0 / verbatim_size) << '%';
if (verbatim_size <= rle_size) {
writeVerbatim(img);
} else {

View File

@ -430,10 +430,11 @@ bool TGAHandler::write(const QImage &image)
QImage img(image);
const bool hasAlpha = img.hasAlphaChannel();
if (hasAlpha && img.format() != QImage::Format_ARGB32)
if (hasAlpha && img.format() != QImage::Format_ARGB32) {
img = img.convertToFormat(QImage::Format_ARGB32);
else if (!hasAlpha && img.format() != QImage::Format_RGB32)
} else if (!hasAlpha && img.format() != QImage::Format_RGB32) {
img = img.convertToFormat(QImage::Format_RGB32);
}
if (img.isNull()) {
qDebug() << "TGAHandler::write: image conversion to 32 bits failed!";
return false;