mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-13 09:54:32 +00:00
Qt: Move scaling helper to cpp file
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user