Search in sources :

Example 1 with UnitTransformation

use of com.bumptech.glide.load.resource.UnitTransformation in project glide by bumptech.

the class ReEncodingGifResourceEncoder method encode.

@Override
public boolean encode(Resource<GifDrawable> resource, File file, Options options) {
    GifDrawable drawable = resource.get();
    Transformation<Bitmap> transformation = drawable.getFrameTransformation();
    boolean isTransformed = !(transformation instanceof UnitTransformation);
    if (isTransformed && options.get(ENCODE_TRANSFORMATION)) {
        return encodeTransformedToFile(drawable, file);
    } else {
        return writeDataDirect(drawable.getBuffer(), file);
    }
}
Also used : Bitmap(android.graphics.Bitmap) UnitTransformation(com.bumptech.glide.load.resource.UnitTransformation) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable)

Example 2 with UnitTransformation

use of com.bumptech.glide.load.resource.UnitTransformation in project glide by bumptech.

the class GifDrawableTransformationTest method testSetsTransformationAsFrameTransformation.

@Test
@SuppressWarnings("unchecked")
public void testSetsTransformationAsFrameTransformation() {
    Resource<GifDrawable> resource = mockResource();
    GifDrawable gifDrawable = mock(GifDrawable.class);
    Transformation<Bitmap> unitTransformation = UnitTransformation.get();
    when(gifDrawable.getFrameTransformation()).thenReturn(unitTransformation);
    when(gifDrawable.getIntrinsicWidth()).thenReturn(500);
    when(gifDrawable.getIntrinsicHeight()).thenReturn(500);
    when(resource.get()).thenReturn(gifDrawable);
    Bitmap firstFrame = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    when(gifDrawable.getFirstFrame()).thenReturn(firstFrame);
    final int width = 123;
    final int height = 456;
    Bitmap expectedBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Resource<Bitmap> expectedResource = mockResource();
    when(expectedResource.get()).thenReturn(expectedBitmap);
    when(wrapped.transform(Util.<Bitmap>anyResource(), anyInt(), anyInt())).thenReturn(expectedResource);
    transformation.transform(resource, width, height);
    verify(gifDrawable).setFrameTransformation(isA(Transformation.class), eq(expectedBitmap));
}
Also used : Bitmap(android.graphics.Bitmap) Transformation(com.bumptech.glide.load.Transformation) UnitTransformation(com.bumptech.glide.load.resource.UnitTransformation) Test(org.junit.Test)

Aggregations

Bitmap (android.graphics.Bitmap)2 UnitTransformation (com.bumptech.glide.load.resource.UnitTransformation)2 Transformation (com.bumptech.glide.load.Transformation)1 GifDrawable (com.bumptech.glide.load.resource.gif.GifDrawable)1 Test (org.junit.Test)1