34 const int width = aImage.GetWidth();
35 const int height = aImage.GetHeight();
37 if( aMaxTextureSize <= 0 || ( width <= aMaxTextureSize && height <= aMaxTextureSize ) )
40 const double scale = std::min(
static_cast<double>( aMaxTextureSize ) / width,
41 static_cast<double>( aMaxTextureSize ) / height );
43 const int newWidth = std::clamp(
KiROUND( width *
scale ), 1, aMaxTextureSize );
44 const int newHeight = std::clamp(
KiROUND( height *
scale ), 1, aMaxTextureSize );
46 return aImage.Scale( newWidth, newHeight, wxIMAGE_QUALITY_HIGH );
50std::vector<uint8_t>
RgbToRgba(
const uint8_t* aRgb,
const uint8_t* aAlpha,
size_t aPixelCount )
52 std::vector<uint8_t> rgba( aPixelCount * 4 );
54 for(
size_t ii = 0; ii < aPixelCount; ++ii )
56 rgba[ii * 4 + 0] = aRgb[ii * 3 + 0];
57 rgba[ii * 4 + 1] = aRgb[ii * 3 + 1];
58 rgba[ii * 4 + 2] = aRgb[ii * 3 + 2];
59 rgba[ii * 4 + 3] = aAlpha ? aAlpha[ii] : wxIMAGE_ALPHA_OPAQUE;
68 const size_t pixelCount =
static_cast<size_t>( aImage.GetWidth() ) * aImage.GetHeight();
70 std::vector<uint8_t> rgba =
71 RgbToRgba( aImage.GetData(), aImage.HasAlpha() ? aImage.GetAlpha() :
nullptr, pixelCount );
73 if( !aImage.HasAlpha() && aImage.HasMask() )
75 const uint8_t maskRed = aImage.GetMaskRed();
76 const uint8_t maskGreen = aImage.GetMaskGreen();
77 const uint8_t maskBlue = aImage.GetMaskBlue();
79 for(
size_t ii = 0; ii < pixelCount; ++ii )
81 uint8_t* px = &rgba[ii * 4];
83 if( px[0] == maskRed && px[1] == maskGreen && px[2] == maskBlue )
84 px[3] = wxIMAGE_ALPHA_TRANSPARENT;