Rename setAlphaFlags to setUnpremultipliedRequired
Bug: 135133301
Test: I48e49ee08ab1954eddf62ecae87942aeb128c10d
There is never any reason to request OPAQUE. If the image is already
opaque, using PREMUL or UNPREMUL has no effect. If the image is not
opaque, the requesting OPAQUE is an error. This behavior is not
helpful.
In addition, this matches the Java API for
android.graphics.ImageDecoder.
Lastly, the old API was confusing for animated images. It is possible
for the first frame to be opaque, while a later frame is not. Requesting
OPAQUE seems reasonable for this image, until decoding the non-opaque
frame, at which point the inconsistency shows. Having a setting of
unpremul or not makes it obvious what will happen for the later frame.
Change-Id: I3381582e27894e1072db9b8635f3762b801f5d69
diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h
index 50daaba..4b6446c 100644
--- a/include/android/imagedecoder.h
+++ b/include/android/imagedecoder.h
@@ -143,23 +143,20 @@
int AImageDecoder_setAndroidBitmapFormat(AImageDecoder*,
int32_t format) __INTRODUCED_IN(30);
-/*
- * Choose the desired output format.
+/**
+ * Specify whether the output's pixels should be unpremultiplied.
*
- * Must be one of:
- * {@link ANDROID_BITMAP_FLAGS_ALPHA_PREMUL}
- * {@link ANDROID_BITMAP_FLAGS_ALPHA_OPAQUE}
- * {@link ANDROID_BITMAP_FLAGS_ALPHA_UNPREMUL}
+ * By default, the decoder will premultiply the pixels, if they have alpha. Pass
+ * false to this method to leave them unpremultiplied. This has no effect on an
+ * opaque image.
*
- * Note: An OPAQUE image may be set to any of them.
- * A non-OPAQUE image may not be set to OPAQUE
- *
+ * @param required Pass true to leave the pixels unpremultiplied.
* @return - {@link ANDROID_IMAGE_DECODER_SUCCESS} on success
* - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION} if the conversion
* is not possible
* - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for bad parameters
*/
-int AImageDecoder_setAlphaFlags(AImageDecoder*, int alphaFlags) __INTRODUCED_IN(30);
+int AImageDecoder_setUnpremultipliedRequired(AImageDecoder*, bool required) __INTRODUCED_IN(30);
/**
* Specify the output size for a decoded image.