Merge pull request #441 from pjft/image-fix

Fix for image resize flicker when using MaxSize
This commit is contained in:
John Rassa 2018-06-04 14:28:17 -07:00 committed by GitHub
commit 27670e48d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -58,17 +58,16 @@ void ImageComponent::resize()
if(resizeScale.x() < resizeScale.y())
{
mSize[0] *= resizeScale.x();
mSize[1] *= resizeScale.x();
mSize[0] *= resizeScale.x(); // this will be mTargetSize.x(). We can't exceed it, nor be lower than it.
// we need to make sure we're not creating an image larger than max size
mSize[1] = Math::min(Math::round(mSize[1] *= resizeScale.x()), mTargetSize.y());
}else{
mSize[0] *= resizeScale.y();
mSize[1] *= resizeScale.y();
}
mSize[1] = Math::round(mSize[1] *= resizeScale.y()); // this will be mTargetSize.y(). We can't exceed it.
// for SVG rasterization, always calculate width from rounded height (see comment above)
mSize[1] = Math::round(mSize[1]);
mSize[0] = (mSize[1] / textureSize.y()) * textureSize.x();
// we need to make sure we're not creating an image larger than max size
mSize[0] = Math::min((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x());
}
}else if(mTargetIsMin)
{
mSize = textureSize;
@ -91,8 +90,9 @@ void ImageComponent::resize()
}
// for SVG rasterization, always calculate width from rounded height (see comment above)
mSize[1] = Math::round(mSize[1]);
mSize[0] = (mSize[1] / textureSize.y()) * textureSize.x();
// we need to make sure we're not creating an image smaller than min size
mSize[1] = Math::max(Math::round(mSize[1]), mTargetSize.y());
mSize[0] = Math::max((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x());
}else{
// if both components are set, we just stretch