Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 18 | * @defgroup ImageDecoder |
| 19 | * |
| 20 | * Functions for converting encoded images into RGBA pixels. |
| 21 | * |
| 22 | * Similar to the Java counterpart android.graphics.ImageDecoder, it can be used |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 23 | * to decode images in the following formats: |
| 24 | * - JPEG |
| 25 | * - PNG |
| 26 | * - GIF |
| 27 | * - WebP |
| 28 | * - BMP |
| 29 | * - ICO |
| 30 | * - WBMP |
| 31 | * - HEIF |
| 32 | * - Digital negatives (via the DNG SDK) |
| 33 | * <p>It has similar options for scaling, cropping, and choosing the output format. |
| 34 | * Unlike the Java API, which can create an android.graphics.Bitmap or |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 35 | * android.graphics.drawable.Drawable object, AImageDecoder decodes directly |
| 36 | * into memory provided by the client. For more information, see the |
| 37 | * <a href="https://developer.android.com/ndk/guides/image-decoder">Image decoder</a> |
| 38 | * developer guide. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 39 | * @{ |
| 40 | */ |
| 41 | |
| 42 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 43 | * @file imagedecoder.h |
| 44 | * @brief API for decoding images. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 45 | */ |
| 46 | |
| 47 | #ifndef ANDROID_IMAGE_DECODER_H |
| 48 | #define ANDROID_IMAGE_DECODER_H |
| 49 | |
| 50 | #include "bitmap.h" |
Leon Scroggins III | a9f397b | 2020-01-27 12:42:56 -0500 | [diff] [blame] | 51 | #include <android/rect.h> |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 52 | #include <stdint.h> |
| 53 | |
Leon Scroggins III | 726a550 | 2021-01-08 14:25:31 -0500 | [diff] [blame] | 54 | #ifndef __ANDROID__ |
| 55 | // Value copied from 'bionic/libc/include/android/api-level.h' which is not available on |
| 56 | // non Android systems. It is set to 10000 which is same as __ANDROID_API_FUTURE__ value. |
| 57 | #ifndef __ANDROID_API__ |
| 58 | #define __ANDROID_API__ 10000 |
| 59 | #endif |
| 60 | |
| 61 | // Value copied from 'bionic/libc/include/android/versioning.h' which is not available on |
| 62 | // non Android systems |
| 63 | #ifndef __INTRODUCED_IN |
| 64 | #define __INTRODUCED_IN(api_level) |
| 65 | #endif |
| 66 | #endif |
| 67 | |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 68 | #ifdef __cplusplus |
| 69 | extern "C" { |
| 70 | #endif |
| 71 | |
| 72 | struct AAsset; |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 73 | |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 74 | /** |
Leon Scroggins III | 3b3700e | 2020-12-29 11:52:12 -0500 | [diff] [blame] | 75 | * {@link AImageDecoder} functions result code. |
| 76 | * |
| 77 | * Introduced in API 30. |
| 78 | * |
| 79 | * Many functions will return this to indicate success |
| 80 | * ({@link ANDROID_IMAGE_DECODER_SUCCESS}) or the reason for the failure. On |
| 81 | * failure, any out-parameters should be considered uninitialized, except where |
Leon Scroggins III | 9b9fb39 | 2020-12-03 16:55:36 -0500 | [diff] [blame] | 82 | * specified. Use {@link AImageDecoder_resultToString} for a readable |
| 83 | * version of the result code. |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 84 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 85 | enum { |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 86 | /** |
| 87 | * Decoding was successful and complete. |
| 88 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 89 | ANDROID_IMAGE_DECODER_SUCCESS = 0, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 90 | /** |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 91 | * The input is incomplete. |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 92 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 93 | ANDROID_IMAGE_DECODER_INCOMPLETE = -1, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 94 | /** |
| 95 | * The input contained an error after decoding some lines. |
| 96 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 97 | ANDROID_IMAGE_DECODER_ERROR = -2, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 98 | /** |
| 99 | * Could not convert. For example, attempting to decode an image with |
| 100 | * alpha to an opaque format. |
| 101 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 102 | ANDROID_IMAGE_DECODER_INVALID_CONVERSION = -3, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 103 | /** |
| 104 | * The scale is invalid. It may have overflowed, or it may be incompatible |
| 105 | * with the current alpha setting. |
| 106 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 107 | ANDROID_IMAGE_DECODER_INVALID_SCALE = -4, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 108 | /** |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 109 | * Some other parameter is invalid. |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 110 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 111 | ANDROID_IMAGE_DECODER_BAD_PARAMETER = -5, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 112 | /** |
| 113 | * Input was invalid before decoding any pixels. |
| 114 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 115 | ANDROID_IMAGE_DECODER_INVALID_INPUT = -6, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 116 | /** |
| 117 | * A seek was required and it failed. |
| 118 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 119 | ANDROID_IMAGE_DECODER_SEEK_ERROR = -7, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 120 | /** |
| 121 | * Some other error. For example, an internal allocation failed. |
| 122 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 123 | ANDROID_IMAGE_DECODER_INTERNAL_ERROR = -8, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 124 | /** |
| 125 | * AImageDecoder did not recognize the format. |
| 126 | */ |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 127 | ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT = -9, |
| 128 | /** |
| 129 | * The animation has reached the end. |
| 130 | */ |
| 131 | ANDROID_IMAGE_DECODER_FINISHED = -10, |
| 132 | /** |
| 133 | * This method cannot be called while the AImageDecoder is in its current |
| 134 | * state. For example, various setters (like {@link AImageDecoder_setTargetSize}) |
| 135 | * can only be called while the AImageDecoder is set to decode the first |
| 136 | * frame of an animation. This ensures that any blending and/or restoring |
| 137 | * prior frames works correctly. |
| 138 | */ |
| 139 | ANDROID_IMAGE_DECODER_INVALID_STATE = -11, |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 140 | }; |
| 141 | |
Leon Scroggins III | 9b9fb39 | 2020-12-03 16:55:36 -0500 | [diff] [blame] | 142 | /** |
| 143 | * Return a constant string value representing the error code. |
| 144 | * |
| 145 | * Introduced in API 31. |
| 146 | * |
| 147 | * Pass the return value from an {@link AImageDecoder} method (e.g. |
| 148 | * {@link AImageDecoder_decodeImage}) for a text string representing the error |
| 149 | * code. |
| 150 | * |
| 151 | * Errors: |
| 152 | * - Returns null for a value out of range. |
| 153 | */ |
| 154 | const char* _Nullable AImageDecoder_resultToString(int)__INTRODUCED_IN(31); |
| 155 | |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 156 | struct AImageDecoder; |
| 157 | |
| 158 | /** |
| 159 | * Opaque handle for decoding images. |
| 160 | * |
Leon Scroggins III | 3b3700e | 2020-12-29 11:52:12 -0500 | [diff] [blame] | 161 | * Introduced in API 30 |
| 162 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 163 | * Create using one of the following: |
| 164 | * - {@link AImageDecoder_createFromAAsset} |
| 165 | * - {@link AImageDecoder_createFromFd} |
| 166 | * - {@link AImageDecoder_createFromBuffer} |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 167 | * |
| 168 | * After creation, {@link AImageDecoder_getHeaderInfo} can be used to retrieve |
| 169 | * information about the encoded image. Other functions, like |
| 170 | * {@link AImageDecoder_setTargetSize}, can be used to specify how to decode, and |
Leon Scroggins III | ac9f749 | 2020-12-28 15:33:13 -0500 | [diff] [blame] | 171 | * {@link AImageDecoder_decodeImage} will decode into client provided memory. |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 172 | * |
| 173 | * {@link AImageDecoder} objects are NOT thread-safe, and should not be shared across |
| 174 | * threads. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 175 | */ |
| 176 | typedef struct AImageDecoder AImageDecoder; |
| 177 | |
| 178 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 179 | * Create a new {@link AImageDecoder} from an {@link AAsset}. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 180 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 181 | * Available since API level 30. |
| 182 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 183 | * @param asset {@link AAsset} containing encoded image data. Client is still |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 184 | * responsible for calling {@link AAsset_close} on it, which may be |
| 185 | * done after deleting the returned {@link AImageDecoder}. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 186 | * @param outDecoder On success (i.e. return value is |
| 187 | * {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to |
| 188 | * a newly created {@link AImageDecoder}. Caller is |
| 189 | * responsible for calling {@link AImageDecoder_delete} on it. |
| 190 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 191 | * indicating the reason for the failure. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 192 | * |
| 193 | * Errors: |
| 194 | * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The asset was truncated before |
| 195 | * reading the image header. |
| 196 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: One of the parameters is |
| 197 | * null. |
| 198 | * - {@link ANDROID_IMAGE_DECODER_INVALID_INPUT}: There is an error in the |
| 199 | * header. |
| 200 | * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The asset failed to seek. |
| 201 | * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a |
| 202 | * failure to allocate memory. |
| 203 | * - {@link ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT}: The format is not |
| 204 | * supported. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 205 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 206 | int AImageDecoder_createFromAAsset(struct AAsset* _Nonnull asset, |
Leon Scroggins III | b2ee00d | 2021-01-07 15:37:34 -0500 | [diff] [blame] | 207 | AImageDecoder* _Nullable * _Nonnull outDecoder) |
Leon Scroggins III | a9f397b | 2020-01-27 12:42:56 -0500 | [diff] [blame] | 208 | __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 209 | |
| 210 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 211 | * Create a new {@link AImageDecoder} from a file descriptor. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 212 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 213 | * Available since API level 30. |
| 214 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 215 | * @param fd Seekable, readable, open file descriptor for encoded data. |
| 216 | * Client is still responsible for closing it, which may be done |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 217 | * after deleting the returned {@link AImageDecoder}. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 218 | * @param outDecoder On success (i.e. return value is |
| 219 | * {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to |
| 220 | * a newly created {@link AImageDecoder}. Caller is |
| 221 | * responsible for calling {@link AImageDecoder_delete} on it. |
| 222 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 223 | * indicating the reason for the failure. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 224 | * |
| 225 | * Errors: |
| 226 | * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The file was truncated before |
| 227 | * reading the image header. |
| 228 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The {@link AImageDecoder} is |
| 229 | * null, or |fd| does not represent a valid, seekable file descriptor. |
| 230 | * - {@link ANDROID_IMAGE_DECODER_INVALID_INPUT}: There is an error in the |
| 231 | * header. |
| 232 | * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The descriptor failed to seek. |
| 233 | * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a |
| 234 | * failure to allocate memory. |
| 235 | * - {@link ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT}: The format is not |
| 236 | * supported. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 237 | */ |
Leon Scroggins III | b2ee00d | 2021-01-07 15:37:34 -0500 | [diff] [blame] | 238 | int AImageDecoder_createFromFd(int fd, AImageDecoder* _Nullable * _Nonnull outDecoder) |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 239 | __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * Create a new AImageDecoder from a buffer. |
| 243 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 244 | * Available since API level 30. |
| 245 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 246 | * @param buffer Pointer to encoded data. Must be valid for the entire time |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 247 | * the {@link AImageDecoder} is used. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 248 | * @param length Byte length of buffer. |
| 249 | * @param outDecoder On success (i.e. return value is |
| 250 | * {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to |
| 251 | * a newly created {@link AImageDecoder}. Caller is |
| 252 | * responsible for calling {@link AImageDecoder_delete} on it. |
| 253 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 254 | * indicating the reason for the failure. |
| 255 | * |
| 256 | * Errors: |
| 257 | * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The encoded image was truncated before |
| 258 | * reading the image header. |
| 259 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: One of the parameters is |
| 260 | * invalid. |
| 261 | * - {@link ANDROID_IMAGE_DECODER_INVALID_INPUT}: There is an error in the |
| 262 | * header. |
| 263 | * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a |
| 264 | * failure to allocate memory. |
| 265 | * - {@link ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT}: The format is not |
| 266 | * supported. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 267 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 268 | int AImageDecoder_createFromBuffer(const void* _Nonnull buffer, size_t length, |
Leon Scroggins III | b2ee00d | 2021-01-07 15:37:34 -0500 | [diff] [blame] | 269 | AImageDecoder* _Nullable * _Nonnull outDecoder) |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 270 | __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 271 | |
| 272 | /** |
| 273 | * Delete the AImageDecoder. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 274 | * |
| 275 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 276 | */ |
Leon Scroggins III | b2ee00d | 2021-01-07 15:37:34 -0500 | [diff] [blame] | 277 | void AImageDecoder_delete(AImageDecoder* _Nullable decoder) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 278 | |
| 279 | /** |
| 280 | * Choose the desired output format. |
| 281 | * |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 282 | * If the encoded image represents an animation, this must be called while on |
| 283 | * the first frame (e.g. before calling {@link AImageDecoder_advanceFrame} or |
| 284 | * after calling {@link AImageDecoder_rewind}). |
| 285 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 286 | * Available since API level 30. |
| 287 | * |
Leon Scroggins III | 5d0445c | 2020-01-23 09:43:43 -0500 | [diff] [blame] | 288 | * @param format {@link AndroidBitmapFormat} to use for the output. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 289 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 290 | * indicating the reason for the failure. On failure, the |
| 291 | * {@link AImageDecoder} uses the format it was already planning |
| 292 | * to use (either its default or a previously successful setting |
| 293 | * from this function). |
| 294 | * |
| 295 | * Errors: |
| 296 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The |
| 297 | * {@link AImageDecoder} is null or |format| does not correspond to an |
| 298 | * {@link AndroidBitmapFormat}. |
| 299 | * - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION}: The |
| 300 | * {@link AndroidBitmapFormat} is incompatible with the image. |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 301 | * - {@link ANDROID_IMAGE_DECODER_INVALID_STATE}: The animation is not on |
| 302 | * the first frame. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 303 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 304 | int AImageDecoder_setAndroidBitmapFormat(AImageDecoder* _Nonnull decoder, |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 305 | int32_t format) __INTRODUCED_IN(30); |
| 306 | |
Leon Scroggins III | 1be112f | 2020-01-15 04:26:44 -0500 | [diff] [blame] | 307 | /** |
| 308 | * Specify whether the output's pixels should be unpremultiplied. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 309 | * |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 310 | * By default, {@link AImageDecoder_decodeImage} will premultiply the pixels, if they have alpha. |
| 311 | * Pass true to this method to leave them unpremultiplied. This has no effect on an |
Leon Scroggins III | 1be112f | 2020-01-15 04:26:44 -0500 | [diff] [blame] | 312 | * opaque image. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 313 | * |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 314 | * If the encoded image represents an animation, this must be called while on |
| 315 | * the first frame (e.g. before calling {@link AImageDecoder_advanceFrame} or |
| 316 | * after calling {@link AImageDecoder_rewind}). |
| 317 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 318 | * Available since API level 30. |
| 319 | * |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 320 | * @param unpremultipliedRequired Pass true to leave the pixels unpremultiplied. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 321 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 322 | * indicating the reason for the failure. |
| 323 | * |
| 324 | * Errors: |
| 325 | * - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION}: Unpremultiplied is not |
| 326 | * possible due to an existing scale set by |
| 327 | * {@link AImageDecoder_setTargetSize}. |
| 328 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The |
| 329 | * {@link AImageDecoder} is null. |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 330 | * - {@link ANDROID_IMAGE_DECODER_INVALID_STATE}: The animation is not on |
| 331 | * the first frame. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 332 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 333 | int AImageDecoder_setUnpremultipliedRequired(AImageDecoder* _Nonnull decoder, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 334 | bool unpremultipliedRequired) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 335 | |
| 336 | /** |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 337 | * Choose the dataspace for the output. |
| 338 | * |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 339 | * Ignored by {@link ANDROID_BITMAP_FORMAT_A_8}, which does not support |
| 340 | * an {@link ADataSpace}. |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 341 | * |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 342 | * If the encoded image represents an animation, this must be called while on |
| 343 | * the first frame (e.g. before calling {@link AImageDecoder_advanceFrame} or |
| 344 | * after calling {@link AImageDecoder_rewind}). |
| 345 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 346 | * Available since API level 30. |
| 347 | * |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 348 | * @param dataspace The {@link ADataSpace} to decode into. An ADataSpace |
| 349 | * specifies how to interpret the colors. By default, |
| 350 | * AImageDecoder will decode into the ADataSpace specified by |
| 351 | * {@link AImageDecoderHeaderInfo_getDataSpace}. If this |
| 352 | * parameter is set to a different ADataSpace, AImageDecoder |
| 353 | * will transform the output into the specified ADataSpace. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 354 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 355 | * indicating the reason for the failure. |
| 356 | * |
| 357 | * Errors: |
| 358 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The |
| 359 | * {@link AImageDecoder} is null or |dataspace| does not correspond to an |
| 360 | * {@link ADataSpace} value. |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 361 | * - {@link ANDROID_IMAGE_DECODER_INVALID_STATE}: The animation is not on |
| 362 | * the first frame. |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 363 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 364 | int AImageDecoder_setDataSpace(AImageDecoder* _Nonnull decoder, int32_t dataspace) |
| 365 | __INTRODUCED_IN(30); |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 366 | |
| 367 | /** |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 368 | * Specify the output size for a decoded image. |
| 369 | * |
| 370 | * Future calls to {@link AImageDecoder_decodeImage} will sample or scale the |
| 371 | * encoded image to reach the desired size. If a crop rect is set (via |
| 372 | * {@link AImageDecoder_setCrop}), it must be contained within the dimensions |
| 373 | * specified by width and height, and the output image will be the size of the |
| 374 | * crop rect. |
| 375 | * |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 376 | * If the encoded image represents an animation, this must be called while on |
| 377 | * the first frame (e.g. before calling {@link AImageDecoder_advanceFrame} or |
| 378 | * after calling {@link AImageDecoder_rewind}). |
| 379 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 380 | * Available since API level 30. |
| 381 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 382 | * @param width Width of the output (prior to cropping). |
| 383 | * This will affect future calls to |
| 384 | * {@link AImageDecoder_getMinimumStride}, which will now return |
| 385 | * a value based on this width. |
| 386 | * @param height Height of the output (prior to cropping). |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 387 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 388 | * indicating the reason for the failure. |
| 389 | * |
| 390 | * Errors: |
| 391 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The |
| 392 | * {@link AImageDecoder} is null. |
| 393 | * - {@link ANDROID_IMAGE_DECODER_INVALID_SCALE}: |width| or |height| is <= 0, |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 394 | * the size is too big, any existing crop is not contained by the new image |
| 395 | * dimensions, or the scale is incompatible with a previous call to |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 396 | * {@link AImageDecoder_setUnpremultipliedRequired}(true). |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 397 | * - {@link ANDROID_IMAGE_DECODER_INVALID_STATE}: The animation is not on |
| 398 | * the first frame. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 399 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 400 | int AImageDecoder_setTargetSize(AImageDecoder* _Nonnull decoder, int32_t width, |
| 401 | int32_t height) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 402 | |
Leon Scroggins III | f27256b | 2020-01-19 21:13:04 -0500 | [diff] [blame] | 403 | /** |
| 404 | * Compute the dimensions to use for a given sampleSize. |
| 405 | * |
| 406 | * Although AImageDecoder can scale to an arbitrary target size (see |
| 407 | * {@link AImageDecoder_setTargetSize}), some sizes may be more efficient than |
| 408 | * others. This computes the most efficient target size to use to reach a |
| 409 | * particular sampleSize. |
| 410 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 411 | * Available since API level 30. |
| 412 | * |
Leon Scroggins III | f27256b | 2020-01-19 21:13:04 -0500 | [diff] [blame] | 413 | * @param sampleSize A subsampling rate of the original image. Must be greater |
| 414 | * than or equal to 1. A sampleSize of 2 means to skip every |
| 415 | * other pixel/line, resulting in a width and height that are |
| 416 | * 1/2 of the original dimensions, with 1/4 the number of |
| 417 | * pixels. |
| 418 | * @param width Out parameter for the width sampled by sampleSize, and rounded |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 419 | * in the direction that the decoder can do most efficiently. |
Leon Scroggins III | f27256b | 2020-01-19 21:13:04 -0500 | [diff] [blame] | 420 | * @param height Out parameter for the height sampled by sampleSize, and rounded |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 421 | * in the direction that the decoder can do most efficiently. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 422 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 423 | * indicating the reason for the failure. |
| 424 | * |
| 425 | * Errors: |
| 426 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The |
| 427 | * {@link AImageDecoder}, |width| or |height| is null or |sampleSize| is < 1. |
Leon Scroggins III | f27256b | 2020-01-19 21:13:04 -0500 | [diff] [blame] | 428 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 429 | int AImageDecoder_computeSampledSize(const AImageDecoder* _Nonnull decoder, int sampleSize, |
| 430 | int32_t* _Nonnull width, int32_t* _Nonnull height) |
| 431 | __INTRODUCED_IN(30); |
Leon Scroggins III | 3b3700e | 2020-12-29 11:52:12 -0500 | [diff] [blame] | 432 | |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 433 | /** |
| 434 | * Specify how to crop the output after scaling (if any). |
| 435 | * |
| 436 | * Future calls to {@link AImageDecoder_decodeImage} will crop their output to |
| 437 | * the specified {@link ARect}. Clients will only need to allocate enough memory |
| 438 | * for the cropped ARect. |
| 439 | * |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 440 | * If the encoded image represents an animation, this must be called while on |
| 441 | * the first frame (e.g. before calling {@link AImageDecoder_advanceFrame} or |
| 442 | * after calling {@link AImageDecoder_rewind}). |
| 443 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 444 | * Available since API level 30. |
| 445 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 446 | * @param crop Rectangle describing a crop of the decode. It must be contained inside of |
| 447 | * the (possibly scaled, by {@link AImageDecoder_setTargetSize}) |
| 448 | * image dimensions. This will affect future calls to |
| 449 | * {@link AImageDecoder_getMinimumStride}, which will now return a |
| 450 | * value based on the width of the crop. An empty ARect - |
| 451 | * specifically { 0, 0, 0, 0 } - may be used to remove the cropping |
| 452 | * behavior. Any other empty or unsorted ARects will result in |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 453 | * returning {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 454 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 455 | * indicating the reason for the failure. |
| 456 | * |
| 457 | * Errors: |
| 458 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 459 | * {@link AImageDecoder} is null, or the crop is not contained by the |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 460 | * (possibly scaled) image dimensions. |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 461 | * - {@link ANDROID_IMAGE_DECODER_INVALID_STATE}: The animation is not on |
| 462 | * the first frame. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 463 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 464 | int AImageDecoder_setCrop(AImageDecoder* _Nonnull decoder, ARect crop) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 465 | |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 466 | struct AImageDecoderHeaderInfo; |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 467 | /** |
Leon Scroggins III | 3b3700e | 2020-12-29 11:52:12 -0500 | [diff] [blame] | 468 | * Opaque handle for representing information about the encoded image. |
| 469 | * |
| 470 | * Introduced in API 30 |
| 471 | * |
| 472 | * Retrieved using {@link AImageDecoder_getHeaderInfo} and passed to methods |
| 473 | * like {@link AImageDecoderHeaderInfo_getWidth} and |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 474 | * {@link AImageDecoderHeaderInfo_getHeight}. |
| 475 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 476 | typedef struct AImageDecoderHeaderInfo AImageDecoderHeaderInfo; |
| 477 | |
| 478 | /** |
| 479 | * Return an opaque handle for reading header info. |
| 480 | * |
| 481 | * This is owned by the {@link AImageDecoder} and will be destroyed when the |
| 482 | * AImageDecoder is destroyed via {@link AImageDecoder_delete}. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 483 | * |
| 484 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 485 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 486 | const AImageDecoderHeaderInfo* _Nonnull AImageDecoder_getHeaderInfo( |
| 487 | const AImageDecoder* _Nonnull decoder) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 488 | |
| 489 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 490 | * Report the native width of the encoded image. This is also the logical |
| 491 | * pixel width of the output, unless {@link AImageDecoder_setTargetSize} is |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 492 | * used to choose a different size or {@link AImageDecoder_setCrop} is used to |
| 493 | * set a crop rect. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 494 | * |
| 495 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 496 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 497 | int32_t AImageDecoderHeaderInfo_getWidth(const AImageDecoderHeaderInfo* _Nonnull) |
| 498 | __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 499 | |
| 500 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 501 | * Report the native height of the encoded image. This is also the logical |
| 502 | * pixel height of the output, unless {@link AImageDecoder_setTargetSize} is |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 503 | * used to choose a different size or {@link AImageDecoder_setCrop} is used to |
| 504 | * set a crop rect. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 505 | * |
| 506 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 507 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 508 | int32_t AImageDecoderHeaderInfo_getHeight(const AImageDecoderHeaderInfo* _Nonnull) |
| 509 | __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 510 | |
| 511 | /** |
| 512 | * Report the mimeType of the encoded image. |
| 513 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 514 | * Available since API level 30. |
| 515 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 516 | * @return a string literal describing the mime type. |
| 517 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 518 | const char* _Nonnull AImageDecoderHeaderInfo_getMimeType( |
| 519 | const AImageDecoderHeaderInfo* _Nonnull) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 520 | |
| 521 | /** |
Leon Scroggins III | 5d0445c | 2020-01-23 09:43:43 -0500 | [diff] [blame] | 522 | * Report the {@link AndroidBitmapFormat} the AImageDecoder will decode to |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 523 | * by default. {@link AImageDecoder} will try to choose one that is sensible |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 524 | * for the image and the system. Note that this does not indicate the |
| 525 | * encoded format of the image. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 526 | * |
| 527 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 528 | */ |
Leon Scroggins III | 5d0445c | 2020-01-23 09:43:43 -0500 | [diff] [blame] | 529 | int32_t AImageDecoderHeaderInfo_getAndroidBitmapFormat( |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 530 | const AImageDecoderHeaderInfo* _Nonnull) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 531 | |
| 532 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 533 | * Report how the {@link AImageDecoder} will handle alpha by default. If the image |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 534 | * contains no alpha (according to its header), this will return |
| 535 | * {@link ANDROID_BITMAP_FLAGS_ALPHA_OPAQUE}. If the image may contain alpha, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 536 | * this returns {@link ANDROID_BITMAP_FLAGS_ALPHA_PREMUL}, because |
| 537 | * {@link AImageDecoder_decodeImage} will premultiply pixels by default. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 538 | * |
| 539 | * Available since API level 30. |
Leon Scroggins III | ac9f749 | 2020-12-28 15:33:13 -0500 | [diff] [blame] | 540 | * |
| 541 | * Starting in API level 31, an AImageDecoder may contain multiple frames of an |
| 542 | * animation, but this method still only reports whether the first frame has |
| 543 | * alpha. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 544 | */ |
| 545 | int AImageDecoderHeaderInfo_getAlphaFlags( |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 546 | const AImageDecoderHeaderInfo* _Nonnull) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 547 | |
| 548 | /** |
Leon Scroggins III | 8cee65e | 2020-01-30 14:20:42 -0500 | [diff] [blame] | 549 | * Report the dataspace the AImageDecoder will decode to by default. |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 550 | * |
Leon Scroggins III | 8cee65e | 2020-01-30 14:20:42 -0500 | [diff] [blame] | 551 | * By default, {@link AImageDecoder_decodeImage} will not do any color |
| 552 | * conversion. |
| 553 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 554 | * Available since API level 30. |
| 555 | * |
Leon Scroggins III | 8cee65e | 2020-01-30 14:20:42 -0500 | [diff] [blame] | 556 | * @return The {@link ADataSpace} representing the way the colors |
| 557 | * are encoded (or {@link ADATASPACE_UNKNOWN} if there is not a |
| 558 | * corresponding ADataSpace). This specifies how to interpret the colors |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 559 | * in the decoded image, unless {@link AImageDecoder_setDataSpace} is |
| 560 | * called to decode to a different ADataSpace. |
| 561 | * |
| 562 | * Note that ADataSpace only exposes a few values. This may return |
Leon Scroggins III | 8cee65e | 2020-01-30 14:20:42 -0500 | [diff] [blame] | 563 | * {@link ADATASPACE_UNKNOWN}, even for Named ColorSpaces, if they have |
| 564 | * no corresponding {@link ADataSpace}. |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 565 | */ |
| 566 | int32_t AImageDecoderHeaderInfo_getDataSpace( |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 567 | const AImageDecoderHeaderInfo* _Nonnull) __INTRODUCED_IN(30); |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 568 | |
| 569 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 570 | * Return the minimum stride that can be used in |
| 571 | * {@link AImageDecoder_decodeImage). |
| 572 | * |
| 573 | * This stride provides no padding, meaning it will be exactly equal to the |
| 574 | * width times the number of bytes per pixel for the {@link AndroidBitmapFormat} |
| 575 | * being used. |
| 576 | * |
| 577 | * If the output is scaled (via {@link AImageDecoder_setTargetSize}) and/or |
| 578 | * cropped (via {@link AImageDecoder_setCrop}), this takes those into account. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 579 | * |
| 580 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 581 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 582 | size_t AImageDecoder_getMinimumStride(AImageDecoder* _Nonnull decoder) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 583 | |
| 584 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 585 | * Decode the image into pixels, using the settings of the {@link AImageDecoder}. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 586 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 587 | * Available since API level 30. |
| 588 | * |
Leon Scroggins III | 1b38971 | 2020-10-09 13:12:39 -0400 | [diff] [blame] | 589 | * Starting in API level 31, it can be used to decode all of the frames of an |
Leon Scroggins III | ec2cbe3 | 2021-01-12 12:59:21 -0500 | [diff] [blame] | 590 | * animated image (i.e. GIF, WebP) using new APIs. Internally, |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 591 | * AImageDecoder keeps track of its "current frame" - that is, the frame that |
| 592 | * will be decoded by a call to AImageDecoder_decodeImage. At creation time, the |
| 593 | * current frame is always the first frame, and multiple calls to this method |
| 594 | * will each decode the first frame. {@link AImageDecoder_advanceFrame} advances |
| 595 | * the current frame to the following frame, so that future calls to this method |
| 596 | * will decode that frame. Some frames may update only part of the image. They |
| 597 | * may only update a sub-rectangle (see {@link |
| 598 | * AImageDecoderFrameInfo_getFrameRect}), or they may have alpha (see |
| 599 | * {@link AImageDecoderFrameInfo_hasAlphaWithinBounds}). In these cases, this |
| 600 | * method assumes that the prior frame is still residing in the |pixels| buffer, |
| 601 | * decodes only the new portion, and blends it with the buffer. Frames that change |
| 602 | * the entire |pixels| buffer are "independent", and do not require the prior |
| 603 | * frame to remain in the buffer. The first frame is always independent. A |
| 604 | * sophisticated client can use information from the {@link AImageDecoderFrameInfo} |
| 605 | * to determine whether other frames are independent, or what frames they rely on. |
| 606 | * |
| 607 | * If the current frame is marked {@link ANDROID_IMAGE_DECODER_DISPOSE_OP_PREVIOUS}, |
Leon Scroggins III | 78859b4 | 2021-01-13 11:48:34 -0500 | [diff] [blame] | 608 | * AImageDecoder_decodeImage will store the |pixels| buffer prior to decoding |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 609 | * (note: this only happens for the first in a string of consecutive |
| 610 | * ANDROID_IMAGE_DECODER_DISPOSE_OP_PREVIOUS frames). After advancing to the |
Leon Scroggins III | 78859b4 | 2021-01-13 11:48:34 -0500 | [diff] [blame] | 611 | * following frame, AImageDecoder_decodeImage will restore that buffer prior to |
| 612 | * decoding that frame. This is the default behavior, but it can be disabled |
| 613 | * by passing false to {@link AImageDecoder_setInternallyHandleDisposePrevious}. |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 614 | * |
| 615 | * Ignoring timing information, display, etc, a client wishing to decode all |
| 616 | * frames of an animated image may conceptually use code like the following: |
| 617 | * |
| 618 | * while (true) { |
| 619 | * int result = AImageDecoder_decodeImage(decoder, pixels, stride, size); |
| 620 | * if (result != ANDROID_IMAGE_DECODER_SUCCESS) break; |
| 621 | * |
| 622 | * // Display or save the image in |pixels|, keeping the buffer intact for |
| 623 | * // AImageDecoder to decode the next frame correctly. |
| 624 | * Application_viewImage(pixels); |
| 625 | * |
| 626 | * result = AImageDecoder_advanceFrame(decoder); |
| 627 | * if (result != ANDROID_IMAGE_DECODER_SUCCESS) break; |
| 628 | * } |
Leon Scroggins III | 1b38971 | 2020-10-09 13:12:39 -0400 | [diff] [blame] | 629 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 630 | * @param decoder Opaque object representing the decoder. |
| 631 | * @param pixels On success, will be filled with the result |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 632 | * of the decode. Must be large enough to hold |size| bytes. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 633 | * @param stride Width in bytes of a single row. Must be at least |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 634 | * {@link AImageDecoder_getMinimumStride} and a multiple of the |
| 635 | * bytes per pixel of the {@link AndroidBitmapFormat}. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 636 | * @param size Size of the pixel buffer in bytes. Must be at least |
| 637 | * stride * (height - 1) + |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 638 | * {@link AImageDecoder_getMinimumStride}. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 639 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 640 | * indicating the reason for the failure. |
| 641 | * |
| 642 | * Errors: |
| 643 | * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The image was truncated. A |
| 644 | * partial image was decoded, and undecoded lines have been initialized to all |
| 645 | * zeroes. |
| 646 | * - {@link ANDROID_IMAGE_DECODER_ERROR}: The image contained an error. A |
| 647 | * partial image was decoded, and undecoded lines have been initialized to all |
| 648 | * zeroes. |
| 649 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The {@link AImageDecoder} or |
| 650 | * |pixels| is null, the stride is not large enough or not pixel aligned, or |
| 651 | * |size| is not large enough. |
| 652 | * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The asset or file descriptor |
| 653 | * failed to seek. |
| 654 | * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a |
| 655 | * failure to allocate memory. |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 656 | * - {@link ANDROID_IMAGE_DECODER_FINISHED}: The input contains no |
| 657 | * more frames. No decoding occurred. The client must call |
| 658 | * {@link AImageDecoder_rewind} before calling |
| 659 | * {@link AImageDecoder_decodeImage} again. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 660 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 661 | int AImageDecoder_decodeImage(AImageDecoder* _Nonnull decoder, |
| 662 | void* _Nonnull pixels, size_t stride, |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 663 | size_t size) __INTRODUCED_IN(30); |
| 664 | |
Leon Scroggins III | 1b38971 | 2020-10-09 13:12:39 -0400 | [diff] [blame] | 665 | /** |
| 666 | * Return true iff the image is animated - i.e. has multiple frames. |
| 667 | * |
| 668 | * Introduced in API 31. |
| 669 | * |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 670 | * A single frame GIF is considered to *not* be animated. This may require |
| 671 | * seeking past the first frame to verify whether there is a following frame. |
Leon Scroggins III | 1b38971 | 2020-10-09 13:12:39 -0400 | [diff] [blame] | 672 | * |
| 673 | * Errors: |
| 674 | * - returns false if |decoder| is null. |
| 675 | */ |
| 676 | bool AImageDecoder_isAnimated(AImageDecoder* _Nonnull decoder) |
| 677 | __INTRODUCED_IN(31); |
| 678 | |
Leon Scroggins III | 728a9ac | 2020-10-12 10:34:05 -0400 | [diff] [blame] | 679 | enum { |
| 680 | /* |
| 681 | * Reported by {@link AImageDecoder_getRepeatCount} if the |
| 682 | * animation should repeat forever. |
Leon Scroggins III | 3b3700e | 2020-12-29 11:52:12 -0500 | [diff] [blame] | 683 | * |
| 684 | * Introduced in API 31 |
Leon Scroggins III | 728a9ac | 2020-10-12 10:34:05 -0400 | [diff] [blame] | 685 | */ |
| 686 | ANDROID_IMAGE_DECODER_INFINITE = INT32_MAX, |
| 687 | }; |
| 688 | |
| 689 | /** |
| 690 | * Report how many times the animation should repeat. |
| 691 | * |
| 692 | * Introduced in API 31. |
| 693 | * |
| 694 | * This does not include the first play through. e.g. a repeat |
| 695 | * count of 4 means that each frame is played 5 times. |
| 696 | * |
| 697 | * {@link ANDROID_IMAGE_DECODER_INFINITE} means to repeat forever. |
| 698 | * |
| 699 | * This may require seeking. |
| 700 | * |
| 701 | * For non-animated formats, this returns 0. It may return non-zero for |
| 702 | * an image with only one frame (i.e. {@link AImageDecoder_isAnimated} returns |
| 703 | * false) if the encoded image contains a repeat count. |
| 704 | * |
| 705 | * @return Number of times to repeat on success or a value |
| 706 | * indicating the reason for the failure. |
| 707 | * |
| 708 | * Errors: |
| 709 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The AImageDecoder |
| 710 | * is null. |
| 711 | */ |
Jiyong Park | f1f2090 | 2021-01-13 08:28:13 +0900 | [diff] [blame] | 712 | int32_t AImageDecoder_getRepeatCount(AImageDecoder* _Nonnull decoder) |
Leon Scroggins III | 728a9ac | 2020-10-12 10:34:05 -0400 | [diff] [blame] | 713 | __INTRODUCED_IN(31); |
| 714 | |
Leon Scroggins III | 5528700 | 2020-10-13 11:30:11 -0400 | [diff] [blame] | 715 | /** |
| 716 | * Advance to the next frame in the animation. |
| 717 | * |
| 718 | * Introduced in API 31. |
| 719 | * |
| 720 | * The AImageDecoder keeps track internally which frame it is ready to decode |
| 721 | * (the "current frame"). Initially it is set to decode the first frame, and |
| 722 | * each call to {@link AImageDecoder_decodeImage} will continue to decode |
| 723 | * the same frame until this method (or {@link AImageDecoder_rewind}) |
| 724 | * is called. |
| 725 | * |
| 726 | * Note that this can be used to skip a frame without decoding it. But |
| 727 | * some frames depend on (i.e. blend with) prior frames, and |
| 728 | * AImageDecoder_decodeImage assumes that the prior frame is in the |
| 729 | * |pixels| buffer. In addition, AImageDecoder_decodeImage handles caching and |
| 730 | * restoring frames (see {@link ANDROID_IMAGE_DECODER_DISPOSE_OP_PREVIOUS}), so |
| 731 | * skipping frames in an image with such frames may not produce the correct |
| 732 | * results. |
| 733 | * |
| 734 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 735 | * indicating the reason for the failure. |
| 736 | * |
| 737 | * Errors: |
| 738 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The AImageDecoder |
| 739 | * represents an image that is not animated (see |
| 740 | * {@link AImageDecoder_isAnimated}) or the AImageDecoder is null. |
| 741 | * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The input appears |
| 742 | * to be truncated. The client must call {@link AImageDecoder_rewind} |
| 743 | * before calling {@link AImageDecoder_decodeImage} again. |
| 744 | * - {@link ANDROID_IMAGE_DECODER_ERROR}: The input contains an error. |
| 745 | * The client must call {@link AImageDecoder_rewind} before |
| 746 | * calling {@link AImageDecoder_decodeImage} again. |
| 747 | * - {@link ANDROID_IMAGE_DECODER_FINISHED}: The input contains no |
| 748 | * more frames. The client must call {@link AImageDecoder_rewind} |
| 749 | * before calling {@link AImageDecoder_decodeImage} again. |
| 750 | */ |
| 751 | int AImageDecoder_advanceFrame(AImageDecoder* _Nonnull decoder) |
| 752 | __INTRODUCED_IN(31); |
| 753 | |
| 754 | /** |
| 755 | * Return to the beginning of the animation. |
| 756 | * |
| 757 | * Introduced in API 31. |
| 758 | * |
| 759 | * After this call, the AImageDecoder will be ready to decode the |
| 760 | * first frame of the animation. This can be called after reaching |
| 761 | * the end of the animation or an error or in the middle of the |
| 762 | * animation. |
| 763 | * |
| 764 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 765 | * indicating the reason for the failure. |
| 766 | * |
| 767 | * Errors: |
| 768 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The AImageDecoder |
| 769 | * represents an image that is not animated (see |
| 770 | * {@link AImageDecoder_isAnimated}) or the AImageDecoder is |
| 771 | * null. |
| 772 | * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The asset or file |
| 773 | * descriptor failed to seek. |
| 774 | */ |
| 775 | int AImageDecoder_rewind(AImageDecoder* _Nonnull decoder) |
| 776 | __INTRODUCED_IN(31); |
| 777 | |
Leon Scroggins III | ac9f749 | 2020-12-28 15:33:13 -0500 | [diff] [blame] | 778 | struct AImageDecoderFrameInfo; |
| 779 | |
| 780 | /** |
| 781 | * Opaque handle to animation information about a single frame. |
| 782 | * |
| 783 | * Introduced in API 31 |
| 784 | * |
| 785 | * The duration (retrieved with {@link AImageDecoderFrameInfo_getDuration}) is |
| 786 | * necessary for clients to display the animation at the proper speed. The other |
| 787 | * information is helpful for a client that wants to determine what frames are |
| 788 | * independent (or what frames they depend on), but is unnecessary for |
| 789 | * a simple client that wants to sequentially display all frames. |
| 790 | */ |
| 791 | typedef struct AImageDecoderFrameInfo AImageDecoderFrameInfo; |
| 792 | |
Leon Scroggins III | ac9f749 | 2020-12-28 15:33:13 -0500 | [diff] [blame] | 793 | /** |
| 794 | * Create an uninitialized AImageDecoderFrameInfo. |
| 795 | * |
| 796 | * Introduced in API 31. |
| 797 | * |
| 798 | * This can be passed to {@link AImageDecoder_getFrameInfo} to fill |
| 799 | * in information about the current frame. It may be reused. |
| 800 | * |
| 801 | * Must be deleted with {@link AImageDecoderFrameInfo_delete}. |
| 802 | */ |
| 803 | AImageDecoderFrameInfo* _Nullable AImageDecoderFrameInfo_create() |
| 804 | __INTRODUCED_IN(31); |
| 805 | |
| 806 | /** |
| 807 | * Delete an AImageDecoderFrameInfo. |
| 808 | * |
| 809 | * Introduced in API 31. |
| 810 | */ |
| 811 | void AImageDecoderFrameInfo_delete( |
| 812 | AImageDecoderFrameInfo* _Nullable info) __INTRODUCED_IN(31); |
| 813 | |
| 814 | /** |
| 815 | * Fill |info| with information about the current frame. |
| 816 | * |
| 817 | * Introduced in API 31. |
| 818 | * |
| 819 | * Initially, this will return information about the first frame. |
| 820 | * {@link AImageDecoder_advanceFrame} and |
| 821 | * {@link AImageDecoder_rewind} can be used to change which frame |
| 822 | * is the current frame. |
| 823 | * |
| 824 | * If the image only has one frame, this will fill the {@link |
| 825 | * AImageDecoderFrameInfo} with the encoded info, if any, or reasonable |
| 826 | * defaults. |
| 827 | * |
| 828 | * @param decoder Opaque object representing the decoder. |
| 829 | * @param info Opaque object to hold frame information. On success, will be |
| 830 | * filled with information regarding the current frame. |
| 831 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 832 | * indicating the reason for the failure. |
| 833 | * |
| 834 | * Errors: |
| 835 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: One of the parameters is null. |
| 836 | * - {@link ANDROID_IMAGE_DECODER_FINISHED}: The input contains no |
| 837 | * more frames. The client must call {@link AImageDecoder_rewind} to reset the |
| 838 | * current frame to a valid frame (0). |
| 839 | */ |
| 840 | int AImageDecoder_getFrameInfo(AImageDecoder* _Nonnull decoder, |
| 841 | AImageDecoderFrameInfo* _Nonnull info) __INTRODUCED_IN(31); |
| 842 | |
| 843 | /** |
| 844 | * Report the number of nanoseconds to show the current frame. |
| 845 | * |
| 846 | * Introduced in API 31. |
| 847 | * |
| 848 | * Errors: |
| 849 | * - returns 0 if |info| is null. |
| 850 | */ |
| 851 | int64_t AImageDecoderFrameInfo_getDuration( |
| 852 | const AImageDecoderFrameInfo* _Nonnull info) __INTRODUCED_IN(31); |
| 853 | |
| 854 | /** |
| 855 | * The rectangle of the image (within 0, 0, |
| 856 | * {@link AImageDecoder_getWidth}, {@link AImageDecoder_getHeight}) |
| 857 | * updated by this frame. |
| 858 | * |
| 859 | * Introduced in API 31. |
| 860 | * |
| 861 | * Note that this is unaffected by calls to |
| 862 | * {@link AImageDecoder_setTargetSize} or |
| 863 | * {@link AImageDecoder_setCrop}. |
| 864 | * |
| 865 | * A frame may update only part of the image. This will always be |
| 866 | * contained by the image’s dimensions. |
| 867 | * |
| 868 | * This, along with other information in AImageDecoderFrameInfo, |
| 869 | * can be useful for determining whether a frame is independent, but |
| 870 | * the decoder handles blending frames, so a simple |
| 871 | * sequential client does not need this. |
| 872 | * |
| 873 | * Errors: |
| 874 | * - returns an empty ARect if |info| is null. |
| 875 | */ |
| 876 | ARect AImageDecoderFrameInfo_getFrameRect( |
| 877 | const AImageDecoderFrameInfo* _Nonnull info) __INTRODUCED_IN(31); |
| 878 | |
| 879 | /** |
| 880 | * Whether the new portion of this frame may contain alpha. |
| 881 | * |
| 882 | * Introduced in API 31. |
| 883 | * |
| 884 | * Note that this may differ from whether the composed frame has |
| 885 | * alpha. If this frame does not fill the entire image dimensions |
| 886 | * (see {@link AImageDecoderFrameInfo_getFrameRect}) or it blends |
| 887 | * with an opaque frame, for example, the composed frame’s alpha |
| 888 | * may not match. It is also conservative; for example, if a color |
| 889 | * index-based frame has a color with alpha but does not use it, |
| 890 | * this will still return true. |
| 891 | * |
| 892 | * This, along with other information in AImageDecoderFrameInfo, |
| 893 | * can be useful for determining whether a frame is independent, but |
| 894 | * the decoder handles blending frames, so a simple |
| 895 | * sequential client does not need this. |
| 896 | * |
| 897 | * Errors: |
| 898 | * - returns false if |info| is null. |
| 899 | */ |
| 900 | bool AImageDecoderFrameInfo_hasAlphaWithinBounds( |
| 901 | const AImageDecoderFrameInfo* _Nonnull info) __INTRODUCED_IN(31); |
| 902 | |
Leon Scroggins III | ac9f749 | 2020-12-28 15:33:13 -0500 | [diff] [blame] | 903 | /** |
| 904 | * How a frame is “disposed” before showing the next one. |
| 905 | * |
| 906 | * Introduced in API 31. |
| 907 | * |
| 908 | * This, along with other information in AImageDecoderFrameInfo, |
| 909 | * can be useful for determining whether a frame is independent, but |
| 910 | * the decoder handles disposing of frames, so a simple |
| 911 | * sequential client does not need this. |
| 912 | */ |
| 913 | enum { |
| 914 | // No disposal. The following frame will be drawn directly |
| 915 | // on top of this one. |
| 916 | ANDROID_IMAGE_DECODER_DISPOSE_OP_NONE = 1, |
Leon Scroggins III | 78859b4 | 2021-01-13 11:48:34 -0500 | [diff] [blame] | 917 | // The frame’s rectangle is cleared to transparent (by AImageDecoder) |
| 918 | // before decoding the next frame. |
Leon Scroggins III | ac9f749 | 2020-12-28 15:33:13 -0500 | [diff] [blame] | 919 | ANDROID_IMAGE_DECODER_DISPOSE_OP_BACKGROUND = 2, |
Leon Scroggins III | 78859b4 | 2021-01-13 11:48:34 -0500 | [diff] [blame] | 920 | // The frame’s rectangle is reverted to the prior frame before decoding |
| 921 | // the next frame. This is handled by AImageDecoder, unless |
| 922 | // {@link AImageDecoder_setInternallyHandleDisposePrevious} is set to false. |
Leon Scroggins III | ac9f749 | 2020-12-28 15:33:13 -0500 | [diff] [blame] | 923 | ANDROID_IMAGE_DECODER_DISPOSE_OP_PREVIOUS = 3, |
| 924 | }; |
| 925 | |
Leon Scroggins III | ac9f749 | 2020-12-28 15:33:13 -0500 | [diff] [blame] | 926 | /** |
| 927 | * Return how this frame is “disposed” before showing the next one. |
| 928 | * |
| 929 | * Introduced in API 31. |
| 930 | * |
| 931 | * This, along with other information in AImageDecoderFrameInfo, |
| 932 | * can be useful for determining whether a frame is independent, but |
| 933 | * the decoder handles disposing of frames, so a simple |
| 934 | * sequential client does not need this. |
| 935 | * |
| 936 | * @return one of: |
| 937 | * - {@link ANDROID_IMAGE_DECODER_DISPOSE_OP_NONE} |
| 938 | * - {@link ANDROID_IMAGE_DECODER_DISPOSE_OP_BACKGROUND} |
| 939 | * - {@link ANDROID_IMAGE_DECODER_DISPOSE_OP_PREVIOUS} |
| 940 | * Errors: |
| 941 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} if |info| is null. |
| 942 | */ |
| 943 | int32_t AImageDecoderFrameInfo_getDisposeOp( |
| 944 | const AImageDecoderFrameInfo* _Nonnull info) __INTRODUCED_IN(31); |
| 945 | |
Leon Scroggins III | ac9f749 | 2020-12-28 15:33:13 -0500 | [diff] [blame] | 946 | /** |
| 947 | * How a frame is blended with the previous frame. |
| 948 | * |
| 949 | * Introduced in API 31. |
| 950 | * |
| 951 | * This, along with other information in AImageDecoderFrameInfo, |
| 952 | * can be useful for determining whether a frame is independent, but |
| 953 | * the decoder handles blending frames, so a simple |
| 954 | * sequential client does not need this. |
| 955 | */ |
| 956 | enum { |
| 957 | // This frame replaces existing content. This corresponds |
| 958 | // to webp’s “do not blend”. |
| 959 | ANDROID_IMAGE_DECODER_BLEND_OP_SRC = 1, |
| 960 | // This frame blends with the previous frame. |
| 961 | ANDROID_IMAGE_DECODER_BLEND_OP_SRC_OVER = 2, |
| 962 | }; |
| 963 | |
Leon Scroggins III | ac9f749 | 2020-12-28 15:33:13 -0500 | [diff] [blame] | 964 | /** |
| 965 | * Return how this frame is blended with the previous frame. |
| 966 | * |
| 967 | * Introduced in API 31. |
| 968 | * |
| 969 | * This, along with other information in AImageDecoderFrameInfo, |
| 970 | * can be useful for determining whether a frame is independent, but |
| 971 | * the decoder handles blending frames, so a simple |
| 972 | * sequential client does not need this. |
| 973 | * |
| 974 | * @return one of: |
| 975 | * - {@link ANDROID_IMAGE_DECODER_BLEND_OP_SRC} |
| 976 | * - {@link ANDROID_IMAGE_DECODER_BLEND_OP_SRC_OVER} |
| 977 | * Errors: |
| 978 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} if |info| is null. |
| 979 | */ |
| 980 | int32_t AImageDecoderFrameInfo_getBlendOp( |
| 981 | const AImageDecoderFrameInfo* _Nonnull info) |
| 982 | __INTRODUCED_IN(31); |
| 983 | |
Leon Scroggins III | 78859b4 | 2021-01-13 11:48:34 -0500 | [diff] [blame] | 984 | /** |
| 985 | * Whether to have AImageDecoder store the frame prior to a |
| 986 | * frame marked {@link ANDROID_IMAGE_DECODER_DISPOSE_OP_PREVIOUS}. |
| 987 | * |
| 988 | * Introduced in API 31. |
| 989 | * |
| 990 | * The default is true. Many images will not have such a frame (it |
| 991 | * is not supported by WebP, and only some GIFs use it). But |
| 992 | * if frame i is ANDROID_IMAGE_DECODER_DISPOSE_OP_PREVIOUS, then i+1 |
| 993 | * may depend on i-1. When this setting is true, AImageDecoder will |
| 994 | * defensively copy frame i-1 (i.e. the contents of |pixels| in |
| 995 | * {@link AImageDecoder_decodeImage}) into an internal buffer so that |
| 996 | * it can be used to decode i+1. |
| 997 | * |
| 998 | * AImageDecoder will only store a single frame, at the size specified |
| 999 | * by {@link AImageDecoder_setTargetSize} (or the original dimensions |
| 1000 | * if that method has not been called), and will discard it when it is |
| 1001 | * no longer necessary. |
| 1002 | * |
| 1003 | * A client that desires to manually store such frames may set this to |
| 1004 | * false, so that AImageDecoder does not need to store this extra |
| 1005 | * frame. Instead, when decoding the same |
| 1006 | * ANDROID_IMAGE_DECODER_DISPOSE_OP_PREVIOUS frame i, AImageDecoder |
| 1007 | * will decode directly into |pixels|, assuming the client stored i-1. |
| 1008 | * When asked to decode frame i+1, AImageDecoder will now assume that |
| 1009 | * the client provided i-1 in |pixels|. |
| 1010 | * |
| 1011 | * @param handleInternally Whether AImageDecoder will internally |
| 1012 | * handle ANDROID_IMAGE_DECODER_DISPOSE_OP_PREVIOUS |
| 1013 | * frames. |
| 1014 | */ |
| 1015 | void AImageDecoder_setInternallyHandleDisposePrevious( |
| 1016 | AImageDecoder* _Nonnull decoder, bool handleInternally) |
| 1017 | __INTRODUCED_IN(31); |
| 1018 | |
| 1019 | |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 1020 | #ifdef __cplusplus |
| 1021 | } |
| 1022 | #endif |
| 1023 | |
| 1024 | #endif // ANDROID_IMAGE_DECODER_H |
| 1025 | |
| 1026 | /** @} */ |