Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd397eac authored by Jernej Virag's avatar Jernej Virag
Browse files

Prevent LocalImageResolver from upscaling images

LocalImageResolver should not upscale the image if it's already smaller than the maximum width.

Bug: 228719813
Test: atest LocalImageResolverTest
      New test failed before change / passed after change
Change-Id: I4fc09d1955fe94159cf0e2e8125044712f3c3134
parent 82e82e14
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -198,6 +198,11 @@ public class LocalImageResolver {
                }

                final Size size = info.getSize();
                if (size.getWidth() <= maxWidth && size.getHeight() <= maxHeight) {
                    // We don't want to upscale images needlessly.
                    return;
                }

                if (size.getWidth() > size.getHeight()) {
                    if (size.getWidth() > maxWidth) {
                        final int targetHeight = size.getHeight() * maxWidth / size.getWidth();
+11 −0
Original line number Diff line number Diff line
@@ -194,6 +194,17 @@ public class LocalImageResolverTest {
        assertThat(bd.getBitmap().getHeight()).isGreaterThan(51);
    }

    @Test
    public void resolveImage_smallBitmapIcon_passedSmallerSize_dontResize() {
        Icon icon = Icon.createWithResource(mContext.getResources(), R.drawable.test32x24);
        Drawable d = LocalImageResolver.resolveImage(icon, mContext, 600, 450);

        assertThat(d).isInstanceOf(BitmapDrawable.class);
        BitmapDrawable bd = (BitmapDrawable) d;
        assertThat(bd.getBitmap().getWidth()).isEqualTo(32);
        assertThat(bd.getBitmap().getHeight()).isEqualTo(24);
    }

    @Test
    public void resolveImage_largeBitmapIcon_passedSize_resizeToDefinedSize() {
        Icon icon = Icon.createWithBitmap(