Search in sources :

Example 6 with ShadowMatrix

use of org.robolectric.shadows.ShadowMatrix in project picasso by square.

the class BitmapHunterTest method exifRotationSizing.

@Test
public void exifRotationSizing() throws Exception {
    Request data = new Request.Builder(URI_1).resize(5, 10).build();
    Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
    Bitmap result = transformResult(data, source, ORIENTATION_ROTATE_90);
    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");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 7 with ShadowMatrix

use of org.robolectric.shadows.ShadowMatrix in project picasso by square.

the class BitmapHunterTest method centerCropResultMatchesTargetSize.

@Test
public void centerCropResultMatchesTargetSize() {
    Request request = new Request.Builder(URI_1).resize(1080, 642).centerCrop().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(642);
}
Also used : TestUtils.makeBitmap(com.squareup.picasso.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 8 with ShadowMatrix

use of org.robolectric.shadows.ShadowMatrix in project picasso by square.

the class BitmapHunterTest method centerInsideWideTooSmall.

@Test
public void centerInsideWideTooSmall() {
    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");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 9 with ShadowMatrix

use of org.robolectric.shadows.ShadowMatrix in project picasso by square.

the class BitmapHunterTest method exifRotationNoSizing.

@Test
public void exifRotationNoSizing() throws Exception {
    Request data = new Request.Builder(URI_1).build();
    Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
    Bitmap result = transformResult(data, source, ORIENTATION_ROTATE_90);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).contains("rotate 90.0");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 10 with ShadowMatrix

use of org.robolectric.shadows.ShadowMatrix in project picasso by square.

the class BitmapHunterTest method centerCropTallTooSmall.

@Test
public void centerCropTallTooSmall() {
    Bitmap source = Bitmap.createBitmap(10, 20, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(40, 40).centerCrop().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(5);
    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");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Aggregations

Bitmap (android.graphics.Bitmap)36 Matrix (android.graphics.Matrix)36 BitmapHunter.forRequest (com.squareup.picasso.BitmapHunter.forRequest)36 TestUtils.makeBitmap (com.squareup.picasso.TestUtils.makeBitmap)36 Test (org.junit.Test)36 ShadowBitmap (org.robolectric.shadows.ShadowBitmap)36 ShadowMatrix (org.robolectric.shadows.ShadowMatrix)36