提交 f5ba3740 编写于 作者: J judds 提交者: Sam Judd

Use accurate rounding in FitCenter when checking to see if we can skip

floor is necessary to make sure that we populate all pixels in the
Bitmap, but it's not necessary to use to check if our input Bitmap has
already been transformed and can be returned as is. Using floor can
cause us to re-draw a Bitmap unnecessarily.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167789795
上级 a41cc9b9
......@@ -127,11 +127,10 @@ public final class TransformationUtils {
final float heightPercentage = height / (float) inBitmap.getHeight();
final float minPercentage = Math.min(widthPercentage, heightPercentage);
// take the floor of the target width/height, not round. If the matrix
// passed into drawBitmap rounds differently, we want to slightly
// overdraw, not underdraw, to avoid artifacts from bitmap reuse.
final int targetWidth = (int) (minPercentage * inBitmap.getWidth());
final int targetHeight = (int) (minPercentage * inBitmap.getHeight());
// Round here in case we've decoded exactly the image we want, but take the floor below to
// avoid a line of garbage or blank pixels in images.
int targetWidth = Math.round(minPercentage * inBitmap.getWidth());
int targetHeight = Math.round(minPercentage * inBitmap.getHeight());
if (inBitmap.getWidth() == targetWidth && inBitmap.getHeight() == targetHeight) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
......@@ -140,6 +139,12 @@ public final class TransformationUtils {
return inBitmap;
}
// Take the floor of the target width/height, not round. If the matrix
// passed into drawBitmap rounds differently, we want to slightly
// overdraw, not underdraw, to avoid artifacts from bitmap reuse.
targetWidth = (int) (minPercentage * inBitmap.getWidth());
targetHeight = (int) (minPercentage * inBitmap.getHeight());
Bitmap.Config config = getSafeConfig(inBitmap);
Bitmap toReuse = pool.get(targetWidth, targetHeight, config);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册