@Test public void exifRotation() throws Exception { Request data = new Request.Builder(URI_1).rotate(-45).build(); Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888); Bitmap result = transformResult(data, source, 90); ShadowBitmap shadowBitmap = shadowOf(result); assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source); Matrix matrix = shadowBitmap.getCreatedFromMatrix(); ShadowMatrix shadowMatrix = shadowOf(matrix); assertThat(shadowMatrix.getPreOperations()).containsOnly("rotate 90.0"); }
@Implementation public boolean invert(Matrix inverse) { final SimpleMatrix inverseMatrix = mMatrix.invert(); if (inverseMatrix != null) { if (inverse != null) { final ShadowMatrix shadowInverse = (ShadowMatrix) ShadowExtractor.extract(inverse); shadowInverse.mMatrix = inverseMatrix; } return true; } return false; }
@Test public void centerInsideWideTooSmall() throws Exception { Bitmap source = Bitmap.createBitmap(10, 20, ARGB_8888); Request data = new Request.Builder(URI_1).resize(50, 50).centerInside().build(); Bitmap result = transformResult(data, source, 0); ShadowBitmap shadowBitmap = shadowOf(result); assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source); Matrix matrix = shadowBitmap.getCreatedFromMatrix(); ShadowMatrix shadowMatrix = shadowOf(matrix); assertThat(shadowMatrix.getPreOperations()).containsOnly("scale 2.5 2.5"); }
@Test public void pivotRotation() throws Exception { Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888); Request data = new Request.Builder(URI_1).rotate(-45, 10, 10).build(); Bitmap result = transformResult(data, source, 0); ShadowBitmap shadowBitmap = shadowOf(result); assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source); Matrix matrix = shadowBitmap.getCreatedFromMatrix(); ShadowMatrix shadowMatrix = shadowOf(matrix); assertThat(shadowMatrix.getSetOperations()).contains(entry("rotate", "-45.0 10.0 10.0")); }
@Test public void centerCropWideTooLarge() throws Exception { Bitmap source = Bitmap.createBitmap(200, 100, ARGB_8888); Request data = new Request.Builder(URI_1).resize(50, 50).centerCrop().build(); Bitmap result = transformResult(data, source, 0); ShadowBitmap shadowBitmap = shadowOf(result); assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source); assertThat(shadowBitmap.getCreatedFromX()).isEqualTo(50); assertThat(shadowBitmap.getCreatedFromY()).isEqualTo(0); assertThat(shadowBitmap.getCreatedFromWidth()).isEqualTo(100); assertThat(shadowBitmap.getCreatedFromHeight()).isEqualTo(100); Matrix matrix = shadowBitmap.getCreatedFromMatrix(); ShadowMatrix shadowMatrix = shadowOf(matrix); assertThat(shadowMatrix.getPreOperations()).containsOnly("scale 0.5 0.5"); }