Search in sources :

Example 6 with TrivialPooledByteBuffer

use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.

the class KitKatPurgeableDecoderTest method setUp.

@Before
public void setUp() {
    mFlexByteArrayPool = mock(FlexByteArrayPool.class);
    mBitmap = MockBitmapFactory.create();
    mBitmapCounter = new BitmapCounter(MAX_BITMAP_COUNT, MAX_BITMAP_SIZE);
    mockStatic(BitmapCounterProvider.class);
    when(BitmapCounterProvider.get()).thenReturn(mBitmapCounter);
    mockStatic(BitmapFactory.class);
    when(BitmapFactory.decodeByteArray(any(byte[].class), anyInt(), anyInt(), any(BitmapFactory.Options.class))).thenReturn(mBitmap);
    mInputBuf = new byte[LENGTH];
    PooledByteBuffer input = new TrivialPooledByteBuffer(mInputBuf, POINTER);
    mByteBufferRef = CloseableReference.of(input);
    mEncodedImage = new EncodedImage(mByteBufferRef);
    mDecodeBuf = new byte[LENGTH + 2];
    mDecodeBufRef = CloseableReference.of(mDecodeBuf, mock(ResourceReleaser.class));
    when(mFlexByteArrayPool.get(Integer.valueOf(LENGTH))).thenReturn(mDecodeBufRef);
    mockStatic(Bitmaps.class);
    mKitKatPurgeableDecoder = new KitKatPurgeableDecoder(mFlexByteArrayPool);
}
Also used : BitmapCounter(com.facebook.imagepipeline.memory.BitmapCounter) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) FlexByteArrayPool(com.facebook.imagepipeline.memory.FlexByteArrayPool) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Before(org.junit.Before)

Example 7 with TrivialPooledByteBuffer

use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.

the class ProgressiveJpegParserTest method testOnPartialWebp.

@Test
public void testOnPartialWebp() {
    final TrivialPooledByteBuffer byteBuffer = new TrivialPooledByteBuffer(mPartialWebpBytes);
    mProgressiveJpegParser.parseMoreData(buildEncodedImage(byteBuffer));
    assertFalse(mProgressiveJpegParser.isJpeg());
}
Also used : TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)

Example 8 with TrivialPooledByteBuffer

use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.

the class EncodedImageTest method testIsJpegCompleteAt_notComplete.

@Test
public void testIsJpegCompleteAt_notComplete() {
    byte[] encodedBytes = new byte[ENCODED_BYTES_LENGTH];
    encodedBytes[ENCODED_BYTES_LENGTH - 2] = 0;
    encodedBytes[ENCODED_BYTES_LENGTH - 1] = 0;
    PooledByteBuffer buf = new TrivialPooledByteBuffer(encodedBytes);
    EncodedImage encodedImage = new EncodedImage(CloseableReference.of(buf));
    encodedImage.setImageFormat(DefaultImageFormats.JPEG);
    assertFalse(encodedImage.isCompleteAt(ENCODED_BYTES_LENGTH));
}
Also used : PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)

Example 9 with TrivialPooledByteBuffer

use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.

the class EncodedImageTest method testParseMetaData_JPEG.

@Test
public void testParseMetaData_JPEG() throws IOException {
    PooledByteBuffer buf = new TrivialPooledByteBuffer(ByteStreams.toByteArray(EncodedImageTest.class.getResourceAsStream("images/image.jpg")));
    EncodedImage encodedImage = new EncodedImage(CloseableReference.of(buf));
    encodedImage.parseMetaData();
    assertSame(DefaultImageFormats.JPEG, encodedImage.getImageFormat());
    assertEquals(550, encodedImage.getWidth());
    assertEquals(468, encodedImage.getHeight());
    assertEquals(0, encodedImage.getRotationAngle());
}
Also used : PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)

Example 10 with TrivialPooledByteBuffer

use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.

the class EncodedImageTest method testParseMetaData_PNG.

@Test
public void testParseMetaData_PNG() throws IOException {
    PooledByteBuffer buf = new TrivialPooledByteBuffer(ByteStreams.toByteArray(EncodedImageTest.class.getResourceAsStream("images/image.png")));
    EncodedImage encodedImage = new EncodedImage(CloseableReference.of(buf));
    encodedImage.parseMetaData();
    assertSame(DefaultImageFormats.PNG, encodedImage.getImageFormat());
    assertEquals(800, encodedImage.getWidth());
    assertEquals(600, encodedImage.getHeight());
    assertEquals(0, encodedImage.getRotationAngle());
}
Also used : PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)

Aggregations

TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)23 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)9 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)8 Test (org.junit.Test)8 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)6 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)6 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)6 Bitmap (android.graphics.Bitmap)5 Rect (android.graphics.Rect)5 AnimatedDrawableBackend (com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend)4 AnimatedImageCompositor (com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor)4 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)4 Before (org.junit.Before)4 GifImage (com.facebook.animated.gif.GifImage)3 WebPImage (com.facebook.animated.webp.WebPImage)3 BitmapCounter (com.facebook.imagepipeline.memory.BitmapCounter)2 BitmapFactory (android.graphics.BitmapFactory)1 UiThreadImmediateExecutorService (com.facebook.common.executors.UiThreadImmediateExecutorService)1 BitmapPool (com.facebook.imagepipeline.memory.BitmapPool)1 FlexByteArrayPool (com.facebook.imagepipeline.memory.FlexByteArrayPool)1