Qt: Use hasAlphaChannel() for ARGB32 check

pull/3563/head
Stenzek 2 months ago
parent e470269d01
commit dc7eec7eac
No known key found for this signature in database

@ -71,39 +71,12 @@ static void resizeAndPadImage(QImage* image, int expected_width, int expected_he
bool expand_to_fill)
{
// Get source image in RGB32 format for QPainter.
QImage::Format format;
switch (image->format())
{
case QImage::Format_ARGB32:
case QImage::Format_ARGB32_Premultiplied:
case QImage::Format_ARGB8565_Premultiplied:
case QImage::Format_ARGB6666_Premultiplied:
case QImage::Format_ARGB8555_Premultiplied:
case QImage::Format_ARGB4444_Premultiplied:
case QImage::Format_RGBA8888:
case QImage::Format_RGBA8888_Premultiplied:
case QImage::Format_A2BGR30_Premultiplied:
case QImage::Format_A2RGB30_Premultiplied:
case QImage::Format_Alpha8:
case QImage::Format_RGBA64:
case QImage::Format_RGBA64_Premultiplied:
case QImage::Format_RGBA16FPx4:
case QImage::Format_RGBA16FPx4_Premultiplied:
case QImage::Format_RGBA32FPx4:
case QImage::Format_RGBA32FPx4_Premultiplied:
format = QImage::Format_ARGB32_Premultiplied;
break;
default:
format = QImage::Format_RGB32;
break;
}
// fill_with_top_left is used for the game list background, which cannot be transparent.
format = fill_with_top_left ? QImage::Format_RGB32 : format;
if (image->format() != format)
*image = image->convertToFormat(format);
const QImage::Format original_format = image->format();
const QImage::Format expected_format =
(image->hasAlphaChannel() && !fill_with_top_left) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
if (original_format != expected_format)
*image = image->convertToFormat(expected_format);
const qreal dpr = image->devicePixelRatio();
const int dpr_expected_width = static_cast<int>(static_cast<qreal>(expected_width) * dpr);
@ -134,7 +107,7 @@ static void resizeAndPadImage(QImage* image, int expected_width, int expected_he
if ((image_height < dpr_expected_height) != expand_to_fill)
yoffs = static_cast<int>(static_cast<qreal>((dpr_expected_height - image_height) / 2) / dpr);
QImage padded_image(dpr_expected_width, dpr_expected_height, format);
QImage padded_image(dpr_expected_width, dpr_expected_height, expected_format);
padded_image.setDevicePixelRatio(dpr);
if (fill_with_top_left)
padded_image.fill(image->pixel(0, 0));

Loading…
Cancel
Save