diff options
| author | 2023-10-26 01:29:19 +0000 | |
|---|---|---|
| committer | 2023-11-10 22:15:37 +0000 | |
| commit | bfd2380f756131e7b511f125c310fbf1b04eb199 (patch) | |
| tree | 6c974203208201319f70b94c94b324e5e38ad262 /graphics/java/android | |
| parent | ad930513bbc2e5b69eaa76f230c1f289785fc5d1 (diff) | |
Add EXIF support to JPEG/R Java encoding API
Bug: b/299202809
Test: YuvImageTest.java
Change-Id: If1aa9598f75062e7d0684d5d0f4b60f1e4a19f4d
Diffstat (limited to 'graphics/java/android')
| -rw-r--r-- | graphics/java/android/framework_graphics.aconfig | 7 | ||||
| -rw-r--r-- | graphics/java/android/graphics/YuvImage.java | 41 |
2 files changed, 45 insertions, 3 deletions
diff --git a/graphics/java/android/framework_graphics.aconfig b/graphics/java/android/framework_graphics.aconfig index 9a0a22a08a0c..6c81a608241c 100644 --- a/graphics/java/android/framework_graphics.aconfig +++ b/graphics/java/android/framework_graphics.aconfig @@ -5,4 +5,11 @@ flag { namespace: "core_graphics" description: "Add a function without unused exact param for computeBounds." bug: "304478551" +} + +flag { + name: "yuv_image_compress_to_ultra_hdr" + namespace: "core_graphics" + description: "Feature flag for YUV image compress to Ultra HDR." + bug: "308978825" }
\ No newline at end of file diff --git a/graphics/java/android/graphics/YuvImage.java b/graphics/java/android/graphics/YuvImage.java index 6b5238b20cdc..b3bed00ac6f6 100644 --- a/graphics/java/android/graphics/YuvImage.java +++ b/graphics/java/android/graphics/YuvImage.java @@ -16,6 +16,9 @@ package android.graphics; +import com.android.graphics.flags.Flags; + +import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.Nullable; import java.io.OutputStream; @@ -243,6 +246,36 @@ public class YuvImage { new byte[WORKING_COMPRESS_STORAGE]); } + /** + * Compress the HDR image into JPEG/R format. + * + * Sample usage: + * hdr_image.compressToJpegR(sdr_image, 90, stream); + * + * For the SDR image, only YUV_420_888 image format is supported, and the following + * color spaces are supported: + * ColorSpace.Named.SRGB, + * ColorSpace.Named.DISPLAY_P3 + * + * For the HDR image, only YCBCR_P010 image format is supported, and the following + * color spaces are supported: + * ColorSpace.Named.BT2020_HLG, + * ColorSpace.Named.BT2020_PQ + * + * @param sdr The SDR image, only ImageFormat.YUV_420_888 is supported. + * @param quality Hint to the compressor, 0-100. 0 meaning compress for + * small size, 100 meaning compress for max quality. + * @param stream OutputStream to write the compressed data. + * @return True if the compression is successful. + * @throws IllegalArgumentException if input images are invalid; quality is not within [0, + * 100]; or stream is null. + */ + public boolean compressToJpegR(@NonNull YuvImage sdr, int quality, + @NonNull OutputStream stream) { + byte[] emptyExif = new byte[0]; + return compressToJpegR(sdr, quality, stream, emptyExif); + } + /** * Compress the HDR image into JPEG/R format. * @@ -263,12 +296,14 @@ public class YuvImage { * @param quality Hint to the compressor, 0-100. 0 meaning compress for * small size, 100 meaning compress for max quality. * @param stream OutputStream to write the compressed data. + * @param exif Exchangeable image file format. * @return True if the compression is successful. * @throws IllegalArgumentException if input images are invalid; quality is not within [0, * 100]; or stream is null. */ + @FlaggedApi(Flags.FLAG_YUV_IMAGE_COMPRESS_TO_ULTRA_HDR) public boolean compressToJpegR(@NonNull YuvImage sdr, int quality, - @NonNull OutputStream stream) { + @NonNull OutputStream stream, @NonNull byte[] exif) { if (sdr == null) { throw new IllegalArgumentException("SDR input cannot be null"); } @@ -304,7 +339,7 @@ public class YuvImage { return nativeCompressToJpegR(mData, mColorSpace.getDataSpace(), sdr.getYuvData(), sdr.getColorSpace().getDataSpace(), mWidth, mHeight, quality, stream, - new byte[WORKING_COMPRESS_STORAGE]); + new byte[WORKING_COMPRESS_STORAGE], exif); } @@ -416,5 +451,5 @@ public class YuvImage { private static native boolean nativeCompressToJpegR(byte[] hdr, int hdrColorSpaceId, byte[] sdr, int sdrColorSpaceId, int width, int height, int quality, - OutputStream stream, byte[] tempStorage); + OutputStream stream, byte[] tempStorage, byte[] exif); } |