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