use of org.robolectric.shadows.ShadowBitmap in project picasso by square.
the class BitmapHunterTest method onlyScaleDownOriginalBigger.
@Test
public void onlyScaleDownOriginalBigger() {
Bitmap source = Bitmap.createBitmap(100, 100, ARGB_8888);
Request data = new Request.Builder(URI_1).resize(50, 50).onlyScaleDown().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 0.5 0.5");
}
use of org.robolectric.shadows.ShadowBitmap in project picasso by square.
the class BitmapHunterTest method centerCropWithGravityVerticalTop.
@Test
public void centerCropWithGravityVerticalTop() {
Bitmap source = Bitmap.createBitmap(10, 20, ARGB_8888);
Request data = new Request.Builder(URI_1).resize(40, 40).centerCrop(Gravity.TOP).build();
Bitmap result = transformResult(data, source, 0);
ShadowBitmap shadowBitmap = shadowOf(result);
assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source);
assertThat(shadowBitmap.getCreatedFromX()).isEqualTo(0);
assertThat(shadowBitmap.getCreatedFromY()).isEqualTo(0);
assertThat(shadowBitmap.getCreatedFromWidth()).isEqualTo(10);
assertThat(shadowBitmap.getCreatedFromHeight()).isEqualTo(10);
Matrix matrix = shadowBitmap.getCreatedFromMatrix();
ShadowMatrix shadowMatrix = shadowOf(matrix);
assertThat(shadowMatrix.getPreOperations()).containsOnly("scale 4.0 4.0");
}
use of org.robolectric.shadows.ShadowBitmap in project picasso by square.
the class BitmapHunterTest method centerInsideResultMatchesTargetSizeWhileDesiredHeightIs0.
@Test
public void centerInsideResultMatchesTargetSizeWhileDesiredHeightIs0() {
Request request = new Request.Builder(URI_1).resize(1080, 0).centerInside().build();
Bitmap source = Bitmap.createBitmap(640, 640, ARGB_8888);
Bitmap result = transformResult(request, source, 0);
ShadowBitmap shadowBitmap = shadowOf(result);
Matrix matrix = shadowBitmap.getCreatedFromMatrix();
ShadowMatrix shadowMatrix = shadowOf(matrix);
String scalePreOperation = shadowMatrix.getPreOperations().get(0);
assertThat(scalePreOperation).startsWith("scale ");
float scaleX = Float.valueOf(scalePreOperation.split(" ")[1]);
float scaleY = Float.valueOf(scalePreOperation.split(" ")[2]);
int transformedWidth = Math.round(result.getWidth() * scaleX);
int transformedHeight = Math.round(result.getHeight() * scaleY);
assertThat(transformedWidth).isEqualTo(1080);
assertThat(transformedHeight).isEqualTo(1080);
}
use of org.robolectric.shadows.ShadowBitmap in project picasso by square.
the class BitmapHunterTest method rotation90Sizing.
@Test
public void rotation90Sizing() throws Exception {
Request data = new Request.Builder(URI_1).rotate(90).resize(5, 10).build();
Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
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()).contains("scale 1.0 0.5");
}
use of org.robolectric.shadows.ShadowBitmap in project picasso by square.
the class BitmapHunterTest method exifVerticalFlip.
@Test
public void exifVerticalFlip() {
Request data = new Request.Builder(URI_1).rotate(-45).build();
Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
Bitmap result = transformResult(data, source, ORIENTATION_FLIP_VERTICAL);
ShadowBitmap shadowBitmap = shadowOf(result);
assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source);
Matrix matrix = shadowBitmap.getCreatedFromMatrix();
ShadowMatrix shadowMatrix = shadowOf(matrix);
assertThat(shadowMatrix.getPostOperations()).containsOnly("scale -1.0 1.0");
assertThat(shadowMatrix.getPreOperations()).containsOnly("rotate 180.0");
}
Aggregations