Search in sources :

Example 46 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class ArtDecoderTest method setUp.

@Before
public void setUp() throws Exception {
    final Random random = new Random();
    random.setSeed(RANDOM_SEED);
    mEncodedBytes = new byte[ENCODED_BYTES_LENGTH];
    random.nextBytes(mEncodedBytes);
    mPooledByteBuffer = new TrivialPooledByteBuffer(mEncodedBytes);
    mBitmapPool = mock(BitmapPool.class);
    Pools.SynchronizedPool<ByteBuffer> pool = new Pools.SynchronizedPool<ByteBuffer>(1);
    pool.release(ByteBuffer.allocate(16 * 1024));
    mArtDecoder = new ArtDecoder(mBitmapPool, pool);
    mByteBufferRef = CloseableReference.of(mPooledByteBuffer);
    mEncodedImage = new EncodedImage(mByteBufferRef);
    mEncodedImage.setImageFormat(DefaultImageFormats.JPEG);
    mBitmap = MockBitmapFactory.create();
    doReturn(mBitmap).when(mBitmapPool).get(MockBitmapFactory.DEFAULT_BITMAP_SIZE);
    mBitmapFactoryDefaultAnswer = new Answer<Bitmap>() {

        @Override
        public Bitmap answer(InvocationOnMock invocation) throws Throwable {
            final BitmapFactory.Options options = (BitmapFactory.Options) invocation.getArguments()[2];
            options.outWidth = MockBitmapFactory.DEFAULT_BITMAP_WIDTH;
            options.outHeight = MockBitmapFactory.DEFAULT_BITMAP_HEIGHT;
            verifyBitmapFactoryOptions(options);
            return options.inJustDecodeBounds ? null : mBitmap;
        }
    };
    whenBitmapFactoryDecodeStream().thenAnswer(mBitmapFactoryDefaultAnswer);
    mBitmapRegionDecoder = mock(BitmapRegionDecoder.class);
    whenBitmapRegionDecoderNewInstance().thenReturn(mBitmapRegionDecoder);
    ByteBuffer buf = mArtDecoder.mDecodeBuffers.acquire();
    mTempStorage = buf.array();
    mArtDecoder.mDecodeBuffers.release(buf);
}
Also used : BitmapRegionDecoder(android.graphics.BitmapRegionDecoder) Pools(androidx.core.util.Pools) BitmapPool(com.facebook.imagepipeline.memory.BitmapPool) ByteBuffer(java.nio.ByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Bitmap(android.graphics.Bitmap) Random(java.util.Random) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) MockBitmapFactory(com.facebook.imagepipeline.testing.MockBitmapFactory) BitmapFactory(android.graphics.BitmapFactory) Before(org.junit.Before)

Example 47 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class AddImageTransformMetaDataProducerTest method testOnNewResultNotLast_DimensionsNotFound.

@Test
public void testOnNewResultNotLast_DimensionsNotFound() {
    int rotationAngle = 180;
    int orientation = 1;
    when(ImageFormatChecker.getImageFormat_WrapIOException(any(InputStream.class))).thenReturn(DefaultImageFormats.JPEG);
    when(JfifUtil.getAutoRotateAngleFromOrientation(orientation)).thenReturn(rotationAngle);
    when(JfifUtil.getOrientation(any(InputStream.class))).thenReturn(orientation);
    when(BitmapUtil.decodeDimensionsAndColorSpace(any(InputStream.class))).thenReturn(new ImageMetaData(-1, -1, null));
    mAddMetaDataConsumer.onNewResult(mIntermediateResult, Consumer.NO_FLAGS);
    ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
    verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(Consumer.NO_FLAGS));
    EncodedImage encodedImage = argumentCaptor.getValue();
    assertTrue(EncodedImage.isValid(encodedImage));
    assertEquals(-1, encodedImage.getRotationAngle());
    assertEquals(-1, encodedImage.getWidth());
    assertEquals(-1, encodedImage.getHeight());
}
Also used : InputStream(java.io.InputStream) ImageMetaData(com.facebook.imageutils.ImageMetaData) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 48 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class AddImageTransformMetaDataProducerTest method testOnNewResultNotLastAndJpeg.

@Test
public void testOnNewResultNotLastAndJpeg() {
    int rotationAngle = 180;
    int orientation = 1;
    int width = 10;
    int height = 20;
    when(ImageFormatChecker.getImageFormat_WrapIOException(any(InputStream.class))).thenReturn(DefaultImageFormats.JPEG);
    when(JfifUtil.getAutoRotateAngleFromOrientation(orientation)).thenReturn(rotationAngle);
    when(JfifUtil.getOrientation(any(InputStream.class))).thenReturn(orientation);
    when(BitmapUtil.decodeDimensionsAndColorSpace(any(InputStream.class))).thenReturn(new ImageMetaData(width, height, null));
    mAddMetaDataConsumer.onNewResult(mFinalResult, Consumer.IS_LAST);
    ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
    verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(Consumer.IS_LAST));
    EncodedImage encodedImage = argumentCaptor.getValue();
    assertTrue(EncodedImage.isValid(encodedImage));
    assertEquals(DefaultImageFormats.JPEG, encodedImage.getImageFormat());
    assertEquals(rotationAngle, encodedImage.getRotationAngle());
    assertEquals(width, encodedImage.getWidth());
    assertEquals(height, encodedImage.getHeight());
}
Also used : InputStream(java.io.InputStream) ImageMetaData(com.facebook.imageutils.ImageMetaData) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 49 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class AddImageTransformMetaDataProducerTest method testOnNullResult.

@Test
public void testOnNullResult() {
    mAddMetaDataConsumer.onNewResult(null, Consumer.IS_LAST);
    ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
    verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(Consumer.IS_LAST));
    EncodedImage encodedImage = argumentCaptor.getValue();
    assertEquals(encodedImage, null);
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 50 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class AddImageTransformMetaDataProducerTest method testOnNewResultLastAndJpeg.

@Test
public void testOnNewResultLastAndJpeg() {
    int rotationAngle = 180;
    int orientation = 1;
    int width = 10;
    int height = 20;
    when(ImageFormatChecker.getImageFormat_WrapIOException(any(InputStream.class))).thenReturn(DefaultImageFormats.JPEG);
    when(JfifUtil.getAutoRotateAngleFromOrientation(orientation)).thenReturn(rotationAngle);
    when(JfifUtil.getOrientation(any(InputStream.class))).thenReturn(orientation);
    when(BitmapUtil.decodeDimensionsAndColorSpace(any(InputStream.class))).thenReturn(new ImageMetaData(width, height, null));
    mAddMetaDataConsumer.onNewResult(mFinalResult, Consumer.IS_LAST);
    ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
    verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(Consumer.IS_LAST));
    EncodedImage encodedImage = argumentCaptor.getValue();
    assertTrue(EncodedImage.isValid(encodedImage));
    assertEquals(DefaultImageFormats.JPEG, encodedImage.getImageFormat());
    assertEquals(rotationAngle, encodedImage.getRotationAngle());
    assertEquals(width, encodedImage.getWidth());
    assertEquals(height, encodedImage.getHeight());
}
Also used : InputStream(java.io.InputStream) ImageMetaData(com.facebook.imageutils.ImageMetaData) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Aggregations

EncodedImage (com.facebook.imagepipeline.image.EncodedImage)108 Test (org.junit.Test)32 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)20 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)12 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)12 CacheKey (com.facebook.cache.common.CacheKey)11 Rect (android.graphics.Rect)9 TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)9 InputStream (java.io.InputStream)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)9 AnimatedDrawableBackend (com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend)8 AnimatedImageCompositor (com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor)8 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)8 Before (org.junit.Before)8 Bitmap (android.graphics.Bitmap)7 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)7 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)7 FakeClock (com.facebook.imagepipeline.testing.FakeClock)6 TestExecutorService (com.facebook.imagepipeline.testing.TestExecutorService)6