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