Search in sources :

Example 61 with ShadowBitmap

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

the class BitmapHunterTest method keepsAspectRationWhileResizingWhenDesiredWidthIs0.

@Test
public void keepsAspectRationWhileResizingWhenDesiredWidthIs0() {
    Request request = new Request.Builder(URI_1).resize(20, 0).build();
    Bitmap source = Bitmap.createBitmap(40, 20, ARGB_8888);
    Bitmap result = transformResult(request, source, 0);
    ShadowBitmap shadowBitmap = shadowOf(result);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).containsExactly("scale 0.5 0.5");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 62 with ShadowBitmap

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

the class BitmapHunterTest method onlyScaleDownOriginalSmallerWidthIs0.

@Test
public void onlyScaleDownOriginalSmallerWidthIs0() {
    Bitmap source = Bitmap.createBitmap(50, 50, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(0, 60).onlyScaleDown().build();
    Bitmap result = transformResult(data, source, 0);
    assertThat(result).isSameInstanceAs(source);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isNull();
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Test(org.junit.Test)

Example 63 with ShadowBitmap

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

the class BitmapHunterTest method rotation180Sizing.

@Test
public void rotation180Sizing() {
    Request data = new Request.Builder(URI_1).rotate(180).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()).isSameInstanceAs(source);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).contains("scale 0.5 1.0");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 64 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()).isSameInstanceAs(source);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).containsExactly("rotate 90.0");
    assertThat(shadowMatrix.getSetOperations()).containsEntry("rotate", "-45.0");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 65 with ShadowBitmap

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

the class BitmapHunterTest method exifRotationNoSizing.

@Test
public void exifRotationNoSizing() {
    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()).isSameInstanceAs(source);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).contains("rotate 90.0");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

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