Search in sources :

Example 1 with ShadowBitmap

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

the class BitmapHunterTest method centerInsideTallTooSmall.

@Test
public void centerInsideTallTooSmall() {
    Bitmap source = Bitmap.createBitmap(20, 10, 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 2 with ShadowBitmap

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

the class BitmapHunterTest method exifRotationWithManualRotation.

@Test
public void exifRotationWithManualRotation() {
    Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
    Request data = new Request.Builder(URI_1).rotate(-45).build();
    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()).containsOnly("rotate 90.0");
    assertThat(shadowMatrix.getSetOperations()).contains(entry("rotate", "-45.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 3 with ShadowBitmap

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

the class BitmapHunterTest method centerCropResultMatchesTargetSizeWhileDesiredWidthIs0.

@Test
public void centerCropResultMatchesTargetSizeWhileDesiredWidthIs0() {
    Request request = new Request.Builder(URI_1).resize(0, 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(642);
    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 4 with ShadowBitmap

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

the class BitmapHunterTest method exifTranspose.

@Test
public void exifTranspose() {
    Request data = new Request.Builder(URI_1).rotate(-45).build();
    Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
    Bitmap result = transformResult(data, source, ORIENTATION_TRANSPOSE);
    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 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 5 with ShadowBitmap

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

the class MediaStoreRequestHandlerTest method assertBitmapsEqual.

private static void assertBitmapsEqual(Bitmap a, Bitmap b) {
    ShadowBitmap shadowA = shadowOf(a);
    ShadowBitmap shadowB = shadowOf(b);
    if (shadowA.getHeight() != shadowB.getHeight()) {
        fail();
    }
    if (shadowA.getWidth() != shadowB.getWidth()) {
        fail();
    }
    if (shadowA.getDescription() != null ? !shadowA.getDescription().equals(shadowB.getDescription()) : shadowB.getDescription() != null) {
        fail();
    }
}
Also used : ShadowBitmap(org.robolectric.shadows.ShadowBitmap)

Aggregations

ShadowBitmap (org.robolectric.shadows.ShadowBitmap)74 Bitmap (android.graphics.Bitmap)73 Test (org.junit.Test)73 Matrix (android.graphics.Matrix)67 ShadowMatrix (org.robolectric.shadows.ShadowMatrix)67 BitmapHunter.forRequest (com.squareup.picasso.BitmapHunter.forRequest)39 TestUtils.makeBitmap (com.squareup.picasso.TestUtils.makeBitmap)39 BitmapHunter.forRequest (com.squareup.picasso3.BitmapHunter.forRequest)34 TestUtils.makeBitmap (com.squareup.picasso3.TestUtils.makeBitmap)34