From 94d294bb5215719363a746a6371abe9bb1100626 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Fri, 6 Sep 2019 13:22:46 -0400 Subject: Add Bitmap.CompressFormat#WEBP_LOSSY/LOSSLESS Bug: 135133301 Test: Iadbd8cf3b69a150b9e38ad556392346e1bb27084 WEBP does not give clients explicit control of how to do their WEBP encode. Add new formats that do. Update the docs for the existing formats (and the new ones) to explain more precisely how quality is interpreted. Change-Id: I9583903c21ab2048fed8e7ed501ee8377ea5ba36 --- graphics/java/android/graphics/Bitmap.java | 47 +++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'graphics/java/android') diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 44710178da5e..d900a42b1e66 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -1359,9 +1359,44 @@ public final class Bitmap implements Parcelable { * Specifies the known formats a bitmap can be compressed into */ public enum CompressFormat { - JPEG (0), - PNG (1), - WEBP (2); + /** + * Compress to the JPEG format. {@code quality} of {@code 0} means + * compress for the smallest size. {@code 100} means compress for max + * visual quality. + */ + JPEG (0), + /** + * Compress to the PNG format. PNG is lossless, so {@code quality} is + * ignored. + */ + PNG (1), + /** + * Compress to the WEBP format. {@code quality} of {@code 0} means + * compress for the smallest size. {@code 100} means compress for max + * visual quality. As of {@link android.os.Build.VERSION_CODES#Q}, a + * value of {@code 100} results in a file in the lossless WEBP format. + * Otherwise the file will be in the lossy WEBP format. + * + * @deprecated in favor of the more explicit + * {@link CompressFormat#WEBP_LOSSY} and + * {@link CompressFormat#WEBP_LOSSLESS}. + */ + @Deprecated + WEBP (2), + /** + * Compress to the WEBP lossy format. {@code quality} of {@code 0} means + * compress for the smallest size. {@code 100} means compress for max + * visual quality. + */ + WEBP_LOSSY (3), + /** + * Compress to the WEBP lossless format. {@code quality} refers to how + * much effort to put into compression. A value of {@code 0} means to + * compress quickly, resulting in a relatively large file size. + * {@code 100} means to spend more time compressing, resulting in a + * smaller file. + */ + WEBP_LOSSLESS (4); CompressFormat(int nativeInt) { this.nativeInt = nativeInt; @@ -1385,10 +1420,8 @@ public final class Bitmap implements Parcelable { * pixels). * * @param format The format of the compressed image - * @param quality Hint to the compressor, 0-100. 0 meaning compress for - * small size, 100 meaning compress for max quality. Some - * formats, like PNG which is lossless, will ignore the - * quality setting + * @param quality Hint to the compressor, 0-100. The value is interpreted + * differently depending on the {@link CompressFormat}. * @param stream The outputstream to write the compressed data. * @return true if successfully compressed to the specified stream. */ -- cgit v1.2.3-59-g8ed1b