From 84cb293e712ba2db7a946a166a83e1d0fdec3297 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 23 Feb 2022 00:04:02 +0000 Subject: [PATCH] Make wxBitmap::Rescale() less horrible for commonly used icons Make the results look somewhat better by using wxIMAGE_QUALITY_NEAREST which preserves sharp horizontal and vertical edges in the images which are common in the icons, with which this function is often used, instead of blurring them as wxIMAGE_QUALITY_HIGH does. This is also much (factor of ~40) faster, which shouldn't hurt neither. --- interface/wx/bitmap.h | 4 ++-- src/common/bmpbase.cpp | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/interface/wx/bitmap.h b/interface/wx/bitmap.h index 7f06e9cec6..b39d1a6faa 100644 --- a/interface/wx/bitmap.h +++ b/interface/wx/bitmap.h @@ -837,8 +837,8 @@ public: This function is just a convenient wrapper for wxImage::Rescale() used to resize the given @a bmp to the requested size. If you need more control over resizing, e.g. to specify the quality option different - from ::wxIMAGE_QUALITY_HIGH used by default, please use wxImage - function directly instead. + from ::wxIMAGE_QUALITY_NEAREST used by this function, please use the + wxImage function directly instead. Both the bitmap itself and size must be valid. diff --git a/src/common/bmpbase.cpp b/src/common/bmpbase.cpp index d511ee5a04..320a80ebb3 100644 --- a/src/common/bmpbase.cpp +++ b/src/common/bmpbase.cpp @@ -70,8 +70,11 @@ void wxBitmapHelpers::Rescale(wxBitmap& bmp, const wxSize& sizeNeeded) wxCHECK_RET( sizeNeeded.IsFullySpecified(), wxS("New size must be given") ); #if wxUSE_IMAGE + // Note that we use "nearest" rescale mode here to preserve sharp edges in + // the icons for which this function is often used. It's also consistent + // with what wxDC::DrawBitmap() does, i.e. the fallback method below. wxImage img = bmp.ConvertToImage(); - img.Rescale(sizeNeeded.x, sizeNeeded.y, wxIMAGE_QUALITY_HIGH); + img.Rescale(sizeNeeded.x, sizeNeeded.y, wxIMAGE_QUALITY_NEAREST); bmp = wxBitmap(img); #else // !wxUSE_IMAGE // Fallback method of scaling the bitmap