Qt: Move scaling helper to cpp file

This commit is contained in:
Stenzek
2025-08-31 12:48:28 +10:00
parent d499d8e2d8
commit abde6e4316
4 changed files with 27 additions and 16 deletions

View File

@@ -502,7 +502,7 @@ void GameListModel::fixIconPixmapSize(QPixmap& pm)
const int new_height = static_cast<int>(static_cast<float>(height) / scale);
if (width != new_width || height != new_height)
QtUtils::scaleMemoryCardIconWithSharpBilinear(pm, std::max(new_width, new_height));
QtUtils::ResizeSharpBilinear(pm, std::max(new_width, new_height), MEMORY_CARD_ICON_SIZE);
}
int GameListModel::getCoverArtSize() const

View File

@@ -97,7 +97,7 @@ public:
QImage src_image = QImage(reinterpret_cast<const uchar*>(frame.pixels), MemoryCardImage::ICON_WIDTH,
MemoryCardImage::ICON_HEIGHT, QImage::Format_RGBA8888);
if (src_image.width() != icon_size || src_image.height() != icon_size)
QtUtils::scaleMemoryCardIconWithSharpBilinear(src_image, icon_size);
QtUtils::ResizeSharpBilinear(src_image, icon_size, MemoryCardImage::ICON_HEIGHT);
src_image.setDevicePixelRatio(dpr);

View File

@@ -325,6 +325,29 @@ QIcon QtUtils::GetIconForLanguage(std::string_view language_name)
QString::fromStdString(QtHost::GetResourcePath(GameDatabase::GetLanguageFlagResourceName(language_name), true)));
}
template<typename T>
static void ResizeSharpBilinearT(T& pm, int size, int base_size)
{
// Sharp Bilinear scaling
// First, scale the icon by the largest integer size using nearest-neighbor...
const int integer_icon_size = static_cast<int>(size / base_size) * base_size;
pm = pm.scaled(integer_icon_size, integer_icon_size, Qt::IgnoreAspectRatio, Qt::FastTransformation);
// ...then scale any remainder using bilinear interpolation.
if (size - integer_icon_size > 0)
pm = pm.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
void QtUtils::ResizeSharpBilinear(QPixmap& pm, int size, int base_size)
{
ResizeSharpBilinearT(pm, size, base_size);
}
void QtUtils::ResizeSharpBilinear(QImage& pm, int size, int base_size)
{
ResizeSharpBilinearT(pm, size, base_size);
}
qreal QtUtils::GetDevicePixelRatioForWidget(const QWidget* widget)
{
const QScreen* screen_for_ratio = widget->screen();

View File

@@ -117,20 +117,8 @@ QIcon GetIconForCompatibility(GameDatabase::CompatibilityRating rating);
QIcon GetIconForLanguage(std::string_view language_name);
/// Scales a Memory Card Icon (QPixmap or QImage) using Sharp Bilinear scaling
template<typename T>
inline void scaleMemoryCardIconWithSharpBilinear(T& pm, int size)
{
const int base_size = 16;
// Sharp Bilinear scaling
// First, scale the icon by the largest integer size using nearest-neighbor...
const int integer_icon_size = static_cast<int>(size / base_size) * base_size;
pm = pm.scaled(integer_icon_size, integer_icon_size, Qt::IgnoreAspectRatio, Qt::FastTransformation);
// ...then scale any remainder using bilinear interpolation.
if (size - integer_icon_size > 0)
pm = pm.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
void ResizeSharpBilinear(QPixmap& pm, int size, int base_size);
void ResizeSharpBilinear(QImage& pm, int size, int base_size);
/// Returns the pixel ratio/scaling factor for a widget.
qreal GetDevicePixelRatioForWidget(const QWidget* widget);