Search in sources :

Example 6 with ImageFormat

use of com.facebook.imageformat.ImageFormat in project fresco by facebook.

the class WebpTranscodeProducer method shouldTranscode.

private static TriState shouldTranscode(final EncodedImage encodedImage) {
    Preconditions.checkNotNull(encodedImage);
    InputStream is = Preconditions.checkNotNull(encodedImage.getInputStream());
    ImageFormat imageFormat = ImageFormatChecker.getImageFormat_WrapIOException(is);
    if (DefaultImageFormats.isStaticWebpFormat(imageFormat)) {
        final WebpTranscoder webpTranscoder = WebpTranscoderFactory.getWebpTranscoder();
        if (webpTranscoder == null) {
            return TriState.NO;
        }
        return TriState.valueOf(!webpTranscoder.isWebpNativelySupported(imageFormat));
    } else if (imageFormat == ImageFormat.UNKNOWN) {
        // in which case the decision whether to transcode or not cannot be made yet
        return TriState.UNSET;
    }
    // if the image format is known, but it is not WebP, then the image shouldn't be transcoded
    return TriState.NO;
}
Also used : InputStream(java.io.InputStream) ImageFormat(com.facebook.imageformat.ImageFormat) WebpTranscoder(com.facebook.imagepipeline.nativecode.WebpTranscoder)

Example 7 with ImageFormat

use of com.facebook.imageformat.ImageFormat in project fresco by facebook.

the class EncodedImage method internalParseMetaData.

/**
 * Sets the encoded image meta data.
 */
private void internalParseMetaData() {
    final ImageFormat imageFormat = ImageFormatChecker.getImageFormat_WrapIOException(getInputStream());
    mImageFormat = imageFormat;
    // BitmapUtil.decodeDimensions has a bug where it will return 100x100 for some WebPs even though
    // those are not its actual dimensions
    final Pair<Integer, Integer> dimensions;
    if (DefaultImageFormats.isWebpFormat(imageFormat)) {
        dimensions = readWebPImageSize();
    } else {
        dimensions = readImageMetaData().getDimensions();
    }
    if (imageFormat == DefaultImageFormats.JPEG && mRotationAngle == UNKNOWN_ROTATION_ANGLE) {
        // Load the JPEG rotation angle only if we have the dimensions
        if (dimensions != null) {
            mExifOrientation = JfifUtil.getOrientation(getInputStream());
            mRotationAngle = JfifUtil.getAutoRotateAngleFromOrientation(mExifOrientation);
        }
    } else if (imageFormat == DefaultImageFormats.HEIF && mRotationAngle == UNKNOWN_ROTATION_ANGLE) {
        mExifOrientation = HeifExifUtil.getOrientation(getInputStream());
        mRotationAngle = JfifUtil.getAutoRotateAngleFromOrientation(mExifOrientation);
    } else if (mRotationAngle == UNKNOWN_ROTATION_ANGLE) {
        mRotationAngle = 0;
    }
}
Also used : ImageFormat(com.facebook.imageformat.ImageFormat)

Aggregations

ImageFormat (com.facebook.imageformat.ImageFormat)7 InputStream (java.io.InputStream)3 CacheKey (com.facebook.cache.common.CacheKey)2 MultiCacheKey (com.facebook.cache.common.MultiCacheKey)2 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)2 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)2 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)2 ArrayList (java.util.ArrayList)2 ImagePipelineConfig (com.facebook.imagepipeline.core.ImagePipelineConfig)1 ImagePipelineExperiments (com.facebook.imagepipeline.core.ImagePipelineExperiments)1 WebpTranscoder (com.facebook.imagepipeline.nativecode.WebpTranscoder)1 Before (org.junit.Before)1