Skip to content

Commit

Permalink
Have resize options round down in the bottom quarter of an interval
Browse files Browse the repository at this point in the history
  • Loading branch information
tyronen committed Jun 4, 2015
1 parent d0ee3bf commit c50ff41
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ private static TriState shouldTransform(ImageRequest request, ImageTransformMeta
getScaleNumerator(request, metaData) != JpegTranscoder.SCALE_DENOMINATOR);
}

@VisibleForTesting static int roundNumerator(float maxRatio) {
return (int) (0.75f + maxRatio * JpegTranscoder.SCALE_DENOMINATOR);
}

private static int getScaleNumerator(ImageRequest imageRequest, ImageTransformMetaData metaData) {
final ResizeOptions resizeOptions = imageRequest.getResizeOptions();
if (resizeOptions == null) {
Expand All @@ -187,8 +191,7 @@ private static int getScaleNumerator(ImageRequest imageRequest, ImageTransformMe

final float widthRatio = ((float) resizeOptions.width) / widthAfterRotation;
final float heightRatio = ((float) resizeOptions.height) / heightAfterRotation;
final int numerator =
(int) Math.ceil(Math.max(widthRatio, heightRatio) * JpegTranscoder.SCALE_DENOMINATOR);
int numerator = roundNumerator(Math.max(widthRatio, heightRatio));

if (numerator > MAX_JPEG_SCALE_NUMERATOR) {
return MAX_JPEG_SCALE_NUMERATOR;
Expand Down

0 comments on commit c50ff41

Please sign in to comment.