use of com.facebook.imagepipeline.common.RotationOptions in project fresco by facebook.
the class ImagePipelineUtilsImpl method createDecodedImageRequestBuilder.
@Nullable
protected ImageRequestBuilder createDecodedImageRequestBuilder(@Nullable ImageRequestBuilder imageRequestBuilder, DecodedImageOptions imageOptions) {
if (imageRequestBuilder == null) {
return null;
}
ResizeOptions resizeOptions = imageOptions.getResizeOptions();
if (resizeOptions != null) {
imageRequestBuilder.setResizeOptions(resizeOptions);
}
RotationOptions rotationOptions = imageOptions.getRotationOptions();
if (rotationOptions != null) {
imageRequestBuilder.setRotationOptions(rotationOptions);
}
ImageDecodeOptions imageDecodeOptions = mImageDecodeOptionsProvider.create(imageRequestBuilder, imageOptions);
if (imageDecodeOptions != null) {
imageRequestBuilder.setImageDecodeOptions(imageDecodeOptions);
}
imageRequestBuilder.setLocalThumbnailPreviewsEnabled(imageOptions.areLocalThumbnailPreviewsEnabled());
Postprocessor postprocessor = imageOptions.getPostprocessor();
if (postprocessor != null) {
imageRequestBuilder.setPostprocessor(postprocessor);
}
if (imageOptions.isProgressiveDecodingEnabled() != null) {
imageRequestBuilder.setProgressiveRenderingEnabled(imageOptions.isProgressiveDecodingEnabled());
}
return imageRequestBuilder;
}
use of com.facebook.imagepipeline.common.RotationOptions in project fresco by facebook.
the class SimpleImageTranscoder method transcode.
@Override
public ImageTranscodeResult transcode(EncodedImage encodedImage, OutputStream outputStream, @Nullable RotationOptions rotationOptions, @Nullable ResizeOptions resizeOptions, @Nullable ImageFormat outputFormat, @Nullable Integer quality) {
if (quality == null) {
quality = JpegTranscoderUtils.DEFAULT_JPEG_QUALITY;
}
if (rotationOptions == null) {
rotationOptions = RotationOptions.autoRotate();
}
final int sampleSize = this.getSampleSize(encodedImage, rotationOptions, resizeOptions);
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = sampleSize;
Bitmap resizedBitmap;
try {
resizedBitmap = BitmapFactory.decodeStream(encodedImage.getInputStream(), null, options);
} catch (OutOfMemoryError oom) {
FLog.e(TAG, "Out-Of-Memory during transcode", oom);
return new ImageTranscodeResult(TranscodeStatus.TRANSCODING_ERROR);
}
if (resizedBitmap == null) {
FLog.e(TAG, "Couldn't decode the EncodedImage InputStream ! ");
return new ImageTranscodeResult(TranscodeStatus.TRANSCODING_ERROR);
}
Matrix transformationMatrix = JpegTranscoderUtils.getTransformationMatrix(encodedImage, rotationOptions);
Bitmap srcBitmap = resizedBitmap;
try {
if (transformationMatrix != null) {
srcBitmap = Bitmap.createBitmap(resizedBitmap, 0, 0, resizedBitmap.getWidth(), resizedBitmap.getHeight(), transformationMatrix, false);
}
srcBitmap.compress(getOutputFormat(outputFormat), quality, outputStream);
return new ImageTranscodeResult(sampleSize > DownsampleUtil.DEFAULT_SAMPLE_SIZE ? TranscodeStatus.TRANSCODING_SUCCESS : TranscodeStatus.TRANSCODING_NO_RESIZING);
} catch (OutOfMemoryError oom) {
FLog.e(TAG, "Out-Of-Memory during transcode", oom);
return new ImageTranscodeResult(TranscodeStatus.TRANSCODING_ERROR);
} finally {
srcBitmap.recycle();
resizedBitmap.recycle();
}
}
use of com.facebook.imagepipeline.common.RotationOptions in project fresco by facebook.
the class ImagePipelineUtilsImplTest method testBuildImageRequest_whenRotatingEnabled_thenSetRotateOptions.
@Test
public void testBuildImageRequest_whenRotatingEnabled_thenSetRotateOptions() {
RotationOptions rotationOptions = RotationOptions.forceRotation(RotationOptions.ROTATE_270);
final ImageOptions imageOptions = ImageOptions.create().rotate(rotationOptions).build();
ImageRequest imageRequest = mImagePipelineUtils.buildImageRequest(URI, imageOptions);
assertThat(imageRequest).isNotNull();
assertThat(imageRequest.getSourceUri()).isEqualTo(URI);
assertThat(imageRequest.getRotationOptions()).isEqualTo(rotationOptions);
}
Aggregations