diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index f587b8e97..4d60e162f 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -74,9 +74,12 @@ void ImageComponent::resize(bool rasterize) glm::vec2 resizeScale {mTargetSize.x / mSize.x, mTargetSize.y / mSize.y}; if (resizeScale.x < resizeScale.y) { - // This will be mTargetSize.x. We can't exceed it, nor be lower than it. + // SVG rasterization is determined by height and rasterization is done in terms of + // pixels. If rounding is off enough in the rasterization step (for images with + // extreme aspect ratios), it can cause cutoff when the aspect ratio breaks. + // So we always make sure to round accordingly to avoid such issues. mSize.x *= resizeScale.x; - mSize.y = std::min(mSize.y * resizeScale.x, mTargetSize.y); + mSize.y = floorf(std::min(mSize.y * resizeScale.x, mTargetSize.y)); } else { // This will be mTargetSize.y(). We can't exceed it. diff --git a/es-core/src/resources/TextureData.cpp b/es-core/src/resources/TextureData.cpp index 47391786d..a369bdb98 100644 --- a/es-core/src/resources/TextureData.cpp +++ b/es-core/src/resources/TextureData.cpp @@ -108,31 +108,22 @@ bool TextureData::initSVGFromMemory(const std::string& fileData) } if (rasterize) { - float height {static_cast(mHeight)}; const float aspectW {svgImage->width / static_cast(mWidth)}; const float aspectH {svgImage->height / static_cast(mHeight)}; - if (mScalableNonAspect && aspectW != aspectH) { - // If the size property has been used to override the aspect ratio of the SVG image, - // then we need to rasterize at a lower resolution and let the GPU scale the texture. - // This is necessary as the rasterization always maintains the image aspect ratio. + // If the size property has been used to override the aspect ratio of the SVG image, + // then we need to rasterize at a lower resolution and let the GPU scale the texture. + // This is necessary as the rasterization always maintains the image aspect ratio. + if (mScalableNonAspect && aspectW != aspectH) mWidth = static_cast(std::round(svgImage->width / aspectH)); - } - else { - // For very wide and short images we need to check that the target width is enough - // to fit the rasterized image, if not we'll decrease the height as needed. - const float requiredWidth {height * (svgImage->width / svgImage->height)}; - if (std::round(requiredWidth) > static_cast(mWidth)) - height = std::floor(height * (static_cast(mWidth) / requiredWidth)); - } std::vector tempVector; tempVector.reserve(mWidth * mHeight * 4); NSVGrasterizer* rast {nsvgCreateRasterizer()}; - nsvgRasterize(rast, svgImage, 0, 0, height / svgImage->height, tempVector.data(), mWidth, - mHeight, mWidth * 4); + nsvgRasterize(rast, svgImage, 0, 0, static_cast(mHeight) / svgImage->height, + tempVector.data(), mWidth, mHeight, mWidth * 4); nsvgDeleteRasterizer(rast);