Search in sources :

Example 1 with ImageMetaData

use of com.facebook.imageutils.ImageMetaData 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 2 with ImageMetaData

use of com.facebook.imageutils.ImageMetaData 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 3 with ImageMetaData

use of com.facebook.imageutils.ImageMetaData 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)

Example 4 with ImageMetaData

use of com.facebook.imageutils.ImageMetaData in project fresco by facebook.

the class AddImageTransformMetaDataProducerTest method testOnNewResultNotLast_RotationNotFound.

@Test
public void testOnNewResultNotLast_RotationNotFound() {
    when(ImageFormatChecker.getImageFormat_WrapIOException(any(InputStream.class))).thenReturn(DefaultImageFormats.JPEG);
    when(JfifUtil.getOrientation(any(InputStream.class))).thenReturn(0);
    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 5 with ImageMetaData

use of com.facebook.imageutils.ImageMetaData in project fresco by facebook.

the class EncodedImage method readImageMetaData.

/**
 * We get the size from a generic image
 */
private ImageMetaData readImageMetaData() {
    InputStream inputStream = null;
    ImageMetaData metaData = null;
    try {
        inputStream = this.getInputStream();
        metaData = BitmapUtil.decodeDimensionsAndColorSpace(inputStream);
        mColorSpace = metaData.getColorSpace();
        Pair<Integer, Integer> dimensions = metaData.getDimensions();
        if (dimensions != null) {
            mWidth = dimensions.first;
            mHeight = dimensions.second;
        }
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
            // Head in the sand
            }
        }
    }
    return metaData;
}
Also used : PooledByteBufferInputStream(com.facebook.common.memory.PooledByteBufferInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ImageMetaData(com.facebook.imageutils.ImageMetaData) IOException(java.io.IOException)

Aggregations

ImageMetaData (com.facebook.imageutils.ImageMetaData)5 InputStream (java.io.InputStream)5 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)4 PooledByteBufferInputStream (com.facebook.common.memory.PooledByteBufferInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1