new Tester(DownsampleStrategy.FIT_CENTER) .setTargetDimensions(100, 100) .givenSquareImageWithDimensionOf(100, onAllApisAndAllFormatsExpect(100, 100)) .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(100, 100)) .givenSquareImageWithDimensionOf(400, onAllApisAndAllFormatsExpect(100, 100)) .givenImageWithDimensionsOf(300, 300, atAndAbove(KITKAT).with(allFormats().expect(100, 100)),
new Tester(DownsampleStrategy.AT_MOST) .setTargetDimensions(100, 100) .givenSquareImageWithDimensionOf(100, onAllApisAndAllFormatsExpect(100, 100)) .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(100, 100)) .givenSquareImageWithDimensionOf(400, onAllApisAndAllFormatsExpect(100, 100)) .givenSquareImageWithDimensionOf(300, onAllApisAndAllFormatsExpect(75, 75)) .givenImageWithDimensionsOf(799, 100, atAndAbove(VERSION_CODES.N) formats(PNG, WEBP) .expect(100, 12))) .givenImageWithDimensionsOf(801, 100, onAllApisAndAllFormatsExpect(50, 6)) .givenImageWithDimensionsOf(100, 800, atAndAbove(VERSION_CODES.N) formats(PNG, WEBP) .expect(12, 100))) .givenImageWithDimensionsOf(87, 78, onAllApisAndAllFormatsExpect(87, 78)) .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200)) .givenSquareImageWithDimensionOf(450, onAllApisAndAllFormatsExpect(450, 450)) .givenImageWithDimensionsOf(200, 450, onAllApisAndAllFormatsExpect(200, 450)) .run();
new Tester(DownsampleStrategy.CENTER_INSIDE) .setTargetDimensions(100, 100) .givenSquareImageWithDimensionOf(100, onAllApisAndAllFormatsExpect(100, 100)) .givenSquareImageWithDimensionOf(400, onAllApisAndAllFormatsExpect(100, 100)) .givenImageWithDimensionsOf(300, 300, atAndAbove(KITKAT).with(allFormats().expect(100, 100)), atAndAbove(KITKAT).with(allFormats().expect(13, 100)), below(KITKAT).with(allFormats().expect(25, 200))) .givenImageWithDimensionsOf(87, 78, onAllApisAndAllFormatsExpect(87, 78)) .setTargetDimensions(897, 897) .givenImageWithDimensionsOf(2208, 1520, .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200)) .givenSquareImageWithDimensionOf(450, onAllApisAndAllFormatsExpect(450, 450)) .givenImageWithDimensionsOf(200, 450, onAllApisAndAllFormatsExpect(200, 450)) .run();
@Test public void calculateScaling_withCenterOutside() throws IOException { new Tester(DownsampleStrategy.CENTER_OUTSIDE) .setTargetDimensions(100, 100) .givenSquareImageWithDimensionOf(100, onAllApisAndAllFormatsExpect(100, 100)) .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(100, 100)) .givenSquareImageWithDimensionOf(400, onAllApisAndAllFormatsExpect(100, 100)) .givenImageWithDimensionsOf(300, 300, atAndAbove(KITKAT).with(allFormats().expect(100, 100)), below(KITKAT).with(allFormats().expect(150, 150))) .givenImageWithDimensionsOf(799, 100, onAllApisAndAllFormatsExpect(799, 100)) .givenImageWithDimensionsOf(800, 100, onAllApisAndAllFormatsExpect(800, 100)) .givenImageWithDimensionsOf(801, 100, onAllApisAndAllFormatsExpect(801, 100)) .givenImageWithDimensionsOf(100, 800, onAllApisAndAllFormatsExpect(100, 800)) .givenImageWithDimensionsOf(87, 78, atAndAbove(KITKAT).with(allFormats().expect(112, 100)), below(KITKAT).with(allFormats().expect(87, 78))) // Upscaling .setTargetDimensions(500, 500) .givenSquareImageWithDimensionOf(200, atAndAbove(KITKAT).with(allFormats().expect(500, 500)), below(KITKAT).with(allFormats().expect(200, 200))) .givenSquareImageWithDimensionOf(450, atAndAbove(KITKAT).with(allFormats().expect(500, 500)), below(KITKAT).with(allFormats().expect(450, 450))) .givenImageWithDimensionsOf(200, 450, atAndAbove(KITKAT).with(allFormats().expect(500, 1125)), below(KITKAT).with(allFormats().expect(200, 450))) .run(); }
@Test public void calculateScaling_withNone() throws IOException { new Tester(DownsampleStrategy.NONE) .setTargetDimensions(100, 100) .givenSquareImageWithDimensionOf(100, onAllApisAndAllFormatsExpect(100, 100)) .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200)) .givenSquareImageWithDimensionOf(400, onAllApisAndAllFormatsExpect(400, 400)) .givenSquareImageWithDimensionOf(300, onAllApisAndAllFormatsExpect(300, 300)) .givenImageWithDimensionsOf(799, 100, onAllApisAndAllFormatsExpect(799, 100)) .givenImageWithDimensionsOf(800, 100, onAllApisAndAllFormatsExpect(800, 100)) .givenImageWithDimensionsOf(801, 100, onAllApisAndAllFormatsExpect(801, 100)) .givenImageWithDimensionsOf(100, 800, onAllApisAndAllFormatsExpect(100, 800)) .givenImageWithDimensionsOf(87, 78, onAllApisAndAllFormatsExpect(87, 78)) .setTargetDimensions(500, 500) .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200)) .givenSquareImageWithDimensionOf(450, onAllApisAndAllFormatsExpect(450, 450)) .givenImageWithDimensionsOf(200, 450, onAllApisAndAllFormatsExpect(200, 450)) .run(); }
@Test public void calculateScaling_withAtLeast() throws IOException { new Tester(DownsampleStrategy.AT_LEAST) .setTargetDimensions(100, 100) .givenSquareImageWithDimensionOf(100, onAllApisAndAllFormatsExpect(100, 100)) .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(100, 100)) .givenSquareImageWithDimensionOf(300, onAllApisAndAllFormatsExpect(150, 150)) .givenImageWithDimensionsOf(799, 100, onAllApisAndAllFormatsExpect(799, 100)) .givenImageWithDimensionsOf(800, 100, onAllApisAndAllFormatsExpect(800, 100)) .givenImageWithDimensionsOf(801, 100, onAllApisAndAllFormatsExpect(801, 100)) .givenImageWithDimensionsOf(100, 800, onAllApisAndAllFormatsExpect(100, 800)) .givenImageWithDimensionsOf(87, 78, onAllApisAndAllFormatsExpect(87, 78)) // Upscaling .setTargetDimensions(500, 500) .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200)) .givenSquareImageWithDimensionOf(450, onAllApisAndAllFormatsExpect(450, 450)) .givenImageWithDimensionsOf(200, 450, onAllApisAndAllFormatsExpect(200, 450)) .run(); }