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