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);
}
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());
}
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());
}
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);
}
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());
}
Aggregations