From 572f32079020c238587361fdaf8c3f367890f2f5 Mon Sep 17 00:00:00 2001 From: Sachin Tewari Date: Mon, 1 Jul 2024 07:24:22 -0700 Subject: [PATCH] Convert imagepipeline-base/src/main/java/com/facebook/imageutils Reviewed By: oprisnik Differential Revision: D59222625 fbshipit-source-id: 025e0c4e5a6d0a63864ed8431096e22ed81aa6d4 --- .../transcoder/ImageTranscoderFactory.java | 29 ------------- .../transcoder/ImageTranscoderFactory.kt | 27 ++++++++++++ .../transcoder/TranscodeStatus.java | 41 ------------------- .../transcoder/TranscodeStatus.kt | 33 +++++++++++++++ .../facebook/imageutils/StreamProcessor.kt | 2 +- .../transcoder/MultiImageTranscoderFactory.kt | 2 +- .../SimpleImageTranscoderFactory.java | 2 +- 7 files changed, 63 insertions(+), 73 deletions(-) delete mode 100644 imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/ImageTranscoderFactory.java create mode 100644 imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/ImageTranscoderFactory.kt delete mode 100644 imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/TranscodeStatus.java create mode 100644 imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/TranscodeStatus.kt diff --git a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/ImageTranscoderFactory.java b/imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/ImageTranscoderFactory.java deleted file mode 100644 index 977ee863cd..0000000000 --- a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/ImageTranscoderFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.imagepipeline.transcoder; - -import com.facebook.imageformat.ImageFormat; -import javax.annotation.Nullable; - -public interface ImageTranscoderFactory { - - /** - * Creates an {@link ImageTranscoder} that enables or disables resizing depending on {@code - * isResizingEnabled}. It can return null if the {@link ImageFormat} is not supported by this - * {@link ImageTranscoder}. - * - *

Note that if JPEG images are not supported, we will fallback to our native {@link - * ImageTranscoder} implementation. - * - * @param imageFormat the {@link ImageFormat} of the input images. - * @param isResizingEnabled true if resizing is allowed. - * @return The {@link ImageTranscoder} or null if the image format is not supported. - */ - @Nullable - ImageTranscoder createImageTranscoder(ImageFormat imageFormat, boolean isResizingEnabled); -} diff --git a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/ImageTranscoderFactory.kt b/imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/ImageTranscoderFactory.kt new file mode 100644 index 0000000000..d8aa49df5d --- /dev/null +++ b/imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/ImageTranscoderFactory.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.imagepipeline.transcoder + +import com.facebook.imageformat.ImageFormat + +interface ImageTranscoderFactory { + + /** + * Creates an [ImageTranscoder] that enables or disables resizing depending on + * `isResizingEnabled`. It can return null if the [ImageFormat] is not supported by this + * [ImageTranscoder]. + * + * Note that if JPEG images are not supported, we will fallback to our native [ImageTranscoder] + * implementation. + * + * @param imageFormat the [ImageFormat] of the input images. + * @param isResizingEnabled true if resizing is allowed. + * @return The [ImageTranscoder] or null if the image format is not supported. + */ + fun createImageTranscoder(imageFormat: ImageFormat, isResizingEnabled: Boolean): ImageTranscoder? +} diff --git a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/TranscodeStatus.java b/imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/TranscodeStatus.java deleted file mode 100644 index 9ad7910c3c..0000000000 --- a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/TranscodeStatus.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.imagepipeline.transcoder; - -import static com.facebook.imagepipeline.transcoder.TranscodeStatus.TRANSCODING_ERROR; -import static com.facebook.imagepipeline.transcoder.TranscodeStatus.TRANSCODING_NO_RESIZING; -import static com.facebook.imagepipeline.transcoder.TranscodeStatus.TRANSCODING_SUCCESS; -import static java.lang.annotation.RetentionPolicy.SOURCE; - -import androidx.annotation.IntDef; -import java.lang.annotation.Retention; - -/** Status used by {@link ImageTranscodeResult} to supply additional information. */ -@Retention(SOURCE) -@IntDef({ - TRANSCODING_SUCCESS, - TRANSCODING_NO_RESIZING, - TRANSCODING_ERROR, -}) -public @interface TranscodeStatus { - - /** Status flag to show that the image was transcoded successfully. */ - final - /** Status flag to show that the image was transcoded successfully. */ - int TRANSCODING_SUCCESS = 0; - - /** Status flag to show that the input image transcoded successfully without resizing. */ - final - /** Status flag to show that the input image transcoded successfully without resizing. */ - int TRANSCODING_NO_RESIZING = 1; - - /** Status flag to show that an error occured while transcoding the image. */ - final - /** Status flag to show that an error occured while transcoding the image. */ - int TRANSCODING_ERROR = 2; -} diff --git a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/TranscodeStatus.kt b/imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/TranscodeStatus.kt new file mode 100644 index 0000000000..005c19a4d9 --- /dev/null +++ b/imagepipeline-base/src/main/java/com/facebook/imagepipeline/transcoder/TranscodeStatus.kt @@ -0,0 +1,33 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.imagepipeline.transcoder + +import androidx.annotation.IntDef + +/** Status used by [ImageTranscodeResult] to supply additional information. */ +@Retention(AnnotationRetention.SOURCE) +@IntDef( + TranscodeStatus.TRANSCODING_SUCCESS, + TranscodeStatus.TRANSCODING_NO_RESIZING, + TranscodeStatus.TRANSCODING_ERROR, +) +annotation class TranscodeStatus { + companion object { + /** Status flag to show that the image was transcoded successfully. */ + /** Status flag to show that the image was transcoded successfully. */ + const val TRANSCODING_SUCCESS: Int = 0 + + /** Status flag to show that the input image transcoded successfully without resizing. */ + /** Status flag to show that the input image transcoded successfully without resizing. */ + const val TRANSCODING_NO_RESIZING: Int = 1 + + /** Status flag to show that an error occurred while transcoding the image. */ + /** Status flag to show that an error occurred while transcoding the image. */ + const val TRANSCODING_ERROR: Int = 2 + } +} diff --git a/imagepipeline-base/src/main/java/com/facebook/imageutils/StreamProcessor.kt b/imagepipeline-base/src/main/java/com/facebook/imageutils/StreamProcessor.kt index fa45e88f47..2b4417e37b 100644 --- a/imagepipeline-base/src/main/java/com/facebook/imageutils/StreamProcessor.kt +++ b/imagepipeline-base/src/main/java/com/facebook/imageutils/StreamProcessor.kt @@ -13,7 +13,7 @@ import java.io.InputStream /** Util for processing Stream. */ internal object StreamProcessor { /** - * Consumes up to 4 bytes and returns them as int (taking into account endianess). Throws + * Consumes up to 4 bytes and returns them as int (taking into account endianness). Throws * exception if specified number of bytes cannot be consumed. * * @param stream the input stream to read bytes from diff --git a/imagepipeline/src/main/java/com/facebook/imagepipeline/transcoder/MultiImageTranscoderFactory.kt b/imagepipeline/src/main/java/com/facebook/imagepipeline/transcoder/MultiImageTranscoderFactory.kt index 09cd2b3fd7..8e8ca3d178 100644 --- a/imagepipeline/src/main/java/com/facebook/imagepipeline/transcoder/MultiImageTranscoderFactory.kt +++ b/imagepipeline/src/main/java/com/facebook/imagepipeline/transcoder/MultiImageTranscoderFactory.kt @@ -28,7 +28,7 @@ class MultiImageTranscoderFactory( override fun createImageTranscoder( imageFormat: ImageFormat, isResizingEnabled: Boolean - ): ImageTranscoder? { + ): ImageTranscoder { // Use custom ImageTranscoder, if any var imageTranscoder = getCustomImageTranscoder(imageFormat, isResizingEnabled) // Use ImageTranscoder based on type passed, if any diff --git a/imagepipeline/src/main/java/com/facebook/imagepipeline/transcoder/SimpleImageTranscoderFactory.java b/imagepipeline/src/main/java/com/facebook/imagepipeline/transcoder/SimpleImageTranscoderFactory.java index bc2077c2f8..74368f62a5 100644 --- a/imagepipeline/src/main/java/com/facebook/imagepipeline/transcoder/SimpleImageTranscoderFactory.java +++ b/imagepipeline/src/main/java/com/facebook/imagepipeline/transcoder/SimpleImageTranscoderFactory.java @@ -11,7 +11,7 @@ import com.facebook.infer.annotation.Nullsafe; /** Factory class to create an {@link SimpleImageTranscoder} */ -@Nullsafe(Nullsafe.Mode.STRICT) +@Nullsafe(Nullsafe.Mode.LOCAL) public class SimpleImageTranscoderFactory implements ImageTranscoderFactory { private final int mMaxBitmapSize;