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 | |
| 54 | #ifdef __cplusplus |
| 55 | extern "C" { |
| 56 | #endif |
| 57 | |
| 58 | struct AAsset; |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 59 | |
| 60 | #if __ANDROID_API__ >= 30 |
| 61 | |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 62 | /** |
| 63 | * {@link AImageDecoder} functions result code. Many functions will return one of these |
| 64 | * to indicate success ({@link ANDROID_IMAGE_DECODER_SUCCESS}) or the reason |
| 65 | * for the failure. On failure, any out-parameters should be considered |
| 66 | * uninitialized, except where specified. |
| 67 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 68 | enum { |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 69 | /** |
| 70 | * Decoding was successful and complete. |
| 71 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 72 | ANDROID_IMAGE_DECODER_SUCCESS = 0, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 73 | /** |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 74 | * The input is incomplete. |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 75 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 76 | ANDROID_IMAGE_DECODER_INCOMPLETE = -1, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 77 | /** |
| 78 | * The input contained an error after decoding some lines. |
| 79 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 80 | ANDROID_IMAGE_DECODER_ERROR = -2, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 81 | /** |
| 82 | * Could not convert. For example, attempting to decode an image with |
| 83 | * alpha to an opaque format. |
| 84 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 85 | ANDROID_IMAGE_DECODER_INVALID_CONVERSION = -3, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 86 | /** |
| 87 | * The scale is invalid. It may have overflowed, or it may be incompatible |
| 88 | * with the current alpha setting. |
| 89 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 90 | ANDROID_IMAGE_DECODER_INVALID_SCALE = -4, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 91 | /** |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 92 | * Some other parameter is invalid. |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 93 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 94 | ANDROID_IMAGE_DECODER_BAD_PARAMETER = -5, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 95 | /** |
| 96 | * Input was invalid before decoding any pixels. |
| 97 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 98 | ANDROID_IMAGE_DECODER_INVALID_INPUT = -6, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 99 | /** |
| 100 | * A seek was required and it failed. |
| 101 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 102 | ANDROID_IMAGE_DECODER_SEEK_ERROR = -7, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 103 | /** |
| 104 | * Some other error. For example, an internal allocation failed. |
| 105 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 106 | ANDROID_IMAGE_DECODER_INTERNAL_ERROR = -8, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 107 | /** |
| 108 | * AImageDecoder did not recognize the format. |
| 109 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 110 | ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT = -9 |
| 111 | }; |
| 112 | |
| 113 | struct AImageDecoder; |
| 114 | |
| 115 | /** |
| 116 | * Opaque handle for decoding images. |
| 117 | * |
| 118 | * Create using one of the following: |
| 119 | * - {@link AImageDecoder_createFromAAsset} |
| 120 | * - {@link AImageDecoder_createFromFd} |
| 121 | * - {@link AImageDecoder_createFromBuffer} |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 122 | * |
| 123 | * After creation, {@link AImageDecoder_getHeaderInfo} can be used to retrieve |
| 124 | * information about the encoded image. Other functions, like |
| 125 | * {@link AImageDecoder_setTargetSize}, can be used to specify how to decode, and |
| 126 | * {@link AImageDecoder_decode} will decode into client provided memory. |
| 127 | * |
| 128 | * {@link AImageDecoder} objects are NOT thread-safe, and should not be shared across |
| 129 | * threads. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 130 | */ |
| 131 | typedef struct AImageDecoder AImageDecoder; |
| 132 | |
| 133 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 134 | * Create a new {@link AImageDecoder} from an {@link AAsset}. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 135 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 136 | * Available since API level 30. |
| 137 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 138 | * @param asset {@link AAsset} containing encoded image data. Client is still |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 139 | * responsible for calling {@link AAsset_close} on it, which may be |
| 140 | * done after deleting the returned {@link AImageDecoder}. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 141 | * @param outDecoder On success (i.e. return value is |
| 142 | * {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to |
| 143 | * a newly created {@link AImageDecoder}. Caller is |
| 144 | * responsible for calling {@link AImageDecoder_delete} on it. |
| 145 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 146 | * indicating the reason for the failure. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 147 | * |
| 148 | * Errors: |
| 149 | * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The asset was truncated before |
| 150 | * reading the image header. |
| 151 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: One of the parameters is |
| 152 | * null. |
| 153 | * - {@link ANDROID_IMAGE_DECODER_INVALID_INPUT}: There is an error in the |
| 154 | * header. |
| 155 | * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The asset failed to seek. |
| 156 | * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a |
| 157 | * failure to allocate memory. |
| 158 | * - {@link ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT}: The format is not |
| 159 | * supported. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 160 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 161 | int AImageDecoder_createFromAAsset(struct AAsset* _Nonnull asset, |
| 162 | AImageDecoder* _Nonnull * _Nonnull outDecoder) |
Leon Scroggins III | a9f397b | 2020-01-27 12:42:56 -0500 | [diff] [blame] | 163 | __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 164 | |
| 165 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 166 | * Create a new {@link AImageDecoder} from a file descriptor. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 167 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 168 | * Available since API level 30. |
| 169 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 170 | * @param fd Seekable, readable, open file descriptor for encoded data. |
| 171 | * Client is still responsible for closing it, which may be done |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 172 | * after deleting the returned {@link AImageDecoder}. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 173 | * @param outDecoder On success (i.e. return value is |
| 174 | * {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to |
| 175 | * a newly created {@link AImageDecoder}. Caller is |
| 176 | * responsible for calling {@link AImageDecoder_delete} on it. |
| 177 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 178 | * indicating the reason for the failure. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 179 | * |
| 180 | * Errors: |
| 181 | * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The file was truncated before |
| 182 | * reading the image header. |
| 183 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The {@link AImageDecoder} is |
| 184 | * null, or |fd| does not represent a valid, seekable file descriptor. |
| 185 | * - {@link ANDROID_IMAGE_DECODER_INVALID_INPUT}: There is an error in the |
| 186 | * header. |
| 187 | * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The descriptor failed to seek. |
| 188 | * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a |
| 189 | * failure to allocate memory. |
| 190 | * - {@link ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT}: The format is not |
| 191 | * supported. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 192 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 193 | int AImageDecoder_createFromFd(int fd, AImageDecoder* _Nonnull * _Nonnull outDecoder) |
| 194 | __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 195 | |
| 196 | /** |
| 197 | * Create a new AImageDecoder from a buffer. |
| 198 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 199 | * Available since API level 30. |
| 200 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 201 | * @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] | 202 | * the {@link AImageDecoder} is used. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 203 | * @param length Byte length of buffer. |
| 204 | * @param outDecoder On success (i.e. return value is |
| 205 | * {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to |
| 206 | * a newly created {@link AImageDecoder}. Caller is |
| 207 | * responsible for calling {@link AImageDecoder_delete} on it. |
| 208 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 209 | * indicating the reason for the failure. |
| 210 | * |
| 211 | * Errors: |
| 212 | * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The encoded image was truncated before |
| 213 | * reading the image header. |
| 214 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: One of the parameters is |
| 215 | * invalid. |
| 216 | * - {@link ANDROID_IMAGE_DECODER_INVALID_INPUT}: There is an error in the |
| 217 | * header. |
| 218 | * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a |
| 219 | * failure to allocate memory. |
| 220 | * - {@link ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT}: The format is not |
| 221 | * supported. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 222 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 223 | int AImageDecoder_createFromBuffer(const void* _Nonnull buffer, size_t length, |
| 224 | AImageDecoder* _Nonnull * _Nonnull outDecoder) |
| 225 | __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Delete the AImageDecoder. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 229 | * |
| 230 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 231 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 232 | void AImageDecoder_delete(AImageDecoder* _Nonnull decoder) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 233 | |
| 234 | /** |
| 235 | * Choose the desired output format. |
| 236 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 237 | * Available since API level 30. |
| 238 | * |
Leon Scroggins III | 5d0445c | 2020-01-23 09:43:43 -0500 | [diff] [blame] | 239 | * @param format {@link AndroidBitmapFormat} to use for the output. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 240 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 241 | * indicating the reason for the failure. On failure, the |
| 242 | * {@link AImageDecoder} uses the format it was already planning |
| 243 | * to use (either its default or a previously successful setting |
| 244 | * from this function). |
| 245 | * |
| 246 | * Errors: |
| 247 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The |
| 248 | * {@link AImageDecoder} is null or |format| does not correspond to an |
| 249 | * {@link AndroidBitmapFormat}. |
| 250 | * - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION}: The |
| 251 | * {@link AndroidBitmapFormat} is incompatible with the image. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 252 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 253 | int AImageDecoder_setAndroidBitmapFormat(AImageDecoder* _Nonnull decoder, |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 254 | int32_t format) __INTRODUCED_IN(30); |
| 255 | |
Leon Scroggins III | 1be112f | 2020-01-15 04:26:44 -0500 | [diff] [blame] | 256 | /** |
| 257 | * Specify whether the output's pixels should be unpremultiplied. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 258 | * |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 259 | * By default, {@link AImageDecoder_decodeImage} will premultiply the pixels, if they have alpha. |
| 260 | * 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] | 261 | * opaque image. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 262 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 263 | * Available since API level 30. |
| 264 | * |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 265 | * @param unpremultipliedRequired Pass true to leave the pixels unpremultiplied. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 266 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 267 | * indicating the reason for the failure. |
| 268 | * |
| 269 | * Errors: |
| 270 | * - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION}: Unpremultiplied is not |
| 271 | * possible due to an existing scale set by |
| 272 | * {@link AImageDecoder_setTargetSize}. |
| 273 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The |
| 274 | * {@link AImageDecoder} is null. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 275 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 276 | int AImageDecoder_setUnpremultipliedRequired(AImageDecoder* _Nonnull decoder, |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 277 | bool unpremultipliedRequired) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 278 | |
| 279 | /** |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 280 | * Choose the dataspace for the output. |
| 281 | * |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 282 | * Ignored by {@link ANDROID_BITMAP_FORMAT_A_8}, which does not support |
| 283 | * an {@link ADataSpace}. |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 284 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 285 | * Available since API level 30. |
| 286 | * |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 287 | * @param dataspace The {@link ADataSpace} to decode into. An ADataSpace |
| 288 | * specifies how to interpret the colors. By default, |
| 289 | * AImageDecoder will decode into the ADataSpace specified by |
| 290 | * {@link AImageDecoderHeaderInfo_getDataSpace}. If this |
| 291 | * parameter is set to a different ADataSpace, AImageDecoder |
| 292 | * will transform the output into the specified ADataSpace. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 293 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 294 | * indicating the reason for the failure. |
| 295 | * |
| 296 | * Errors: |
| 297 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The |
| 298 | * {@link AImageDecoder} is null or |dataspace| does not correspond to an |
| 299 | * {@link ADataSpace} value. |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 300 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 301 | int AImageDecoder_setDataSpace(AImageDecoder* _Nonnull decoder, int32_t dataspace) |
| 302 | __INTRODUCED_IN(30); |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 303 | |
| 304 | /** |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 305 | * Specify the output size for a decoded image. |
| 306 | * |
| 307 | * Future calls to {@link AImageDecoder_decodeImage} will sample or scale the |
| 308 | * encoded image to reach the desired size. If a crop rect is set (via |
| 309 | * {@link AImageDecoder_setCrop}), it must be contained within the dimensions |
| 310 | * specified by width and height, and the output image will be the size of the |
| 311 | * crop rect. |
| 312 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 313 | * Available since API level 30. |
| 314 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 315 | * @param width Width of the output (prior to cropping). |
| 316 | * This will affect future calls to |
| 317 | * {@link AImageDecoder_getMinimumStride}, which will now return |
| 318 | * a value based on this width. |
| 319 | * @param height Height of the output (prior to cropping). |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 320 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 321 | * indicating the reason for the failure. |
| 322 | * |
| 323 | * Errors: |
| 324 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The |
| 325 | * {@link AImageDecoder} is null. |
| 326 | * - {@link ANDROID_IMAGE_DECODER_INVALID_SCALE}: |width| or |height| is <= 0, |
| 327 | * the size is too big, any existing crop is not contained by the new image dimensions, |
| 328 | * or the scale is incompatible with a previous call to |
| 329 | * {@link AImageDecoder_setUnpremultipliedRequired}(true). |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 330 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 331 | int AImageDecoder_setTargetSize(AImageDecoder* _Nonnull decoder, int32_t width, |
| 332 | int32_t height) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 333 | |
Leon Scroggins III | f27256b | 2020-01-19 21:13:04 -0500 | [diff] [blame] | 334 | |
| 335 | /** |
| 336 | * Compute the dimensions to use for a given sampleSize. |
| 337 | * |
| 338 | * Although AImageDecoder can scale to an arbitrary target size (see |
| 339 | * {@link AImageDecoder_setTargetSize}), some sizes may be more efficient than |
| 340 | * others. This computes the most efficient target size to use to reach a |
| 341 | * particular sampleSize. |
| 342 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 343 | * Available since API level 30. |
| 344 | * |
Leon Scroggins III | f27256b | 2020-01-19 21:13:04 -0500 | [diff] [blame] | 345 | * @param sampleSize A subsampling rate of the original image. Must be greater |
| 346 | * than or equal to 1. A sampleSize of 2 means to skip every |
| 347 | * other pixel/line, resulting in a width and height that are |
| 348 | * 1/2 of the original dimensions, with 1/4 the number of |
| 349 | * pixels. |
| 350 | * @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] | 351 | * in the direction that the decoder can do most efficiently. |
Leon Scroggins III | f27256b | 2020-01-19 21:13:04 -0500 | [diff] [blame] | 352 | * @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] | 353 | * in the direction that the decoder can do most efficiently. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 354 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 355 | * indicating the reason for the failure. |
| 356 | * |
| 357 | * Errors: |
| 358 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The |
| 359 | * {@link AImageDecoder}, |width| or |height| is null or |sampleSize| is < 1. |
Leon Scroggins III | f27256b | 2020-01-19 21:13:04 -0500 | [diff] [blame] | 360 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 361 | int AImageDecoder_computeSampledSize(const AImageDecoder* _Nonnull decoder, int sampleSize, |
| 362 | int32_t* _Nonnull width, int32_t* _Nonnull height) |
| 363 | __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 364 | /** |
| 365 | * Specify how to crop the output after scaling (if any). |
| 366 | * |
| 367 | * Future calls to {@link AImageDecoder_decodeImage} will crop their output to |
| 368 | * the specified {@link ARect}. Clients will only need to allocate enough memory |
| 369 | * for the cropped ARect. |
| 370 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 371 | * Available since API level 30. |
| 372 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 373 | * @param crop Rectangle describing a crop of the decode. It must be contained inside of |
| 374 | * the (possibly scaled, by {@link AImageDecoder_setTargetSize}) |
| 375 | * image dimensions. This will affect future calls to |
| 376 | * {@link AImageDecoder_getMinimumStride}, which will now return a |
| 377 | * value based on the width of the crop. An empty ARect - |
| 378 | * specifically { 0, 0, 0, 0 } - may be used to remove the cropping |
| 379 | * behavior. Any other empty or unsorted ARects will result in |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 380 | * returning {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 381 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 382 | * indicating the reason for the failure. |
| 383 | * |
| 384 | * Errors: |
| 385 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The |
| 386 | * {@link AImageDecoder} is null or the crop is not contained by the |
| 387 | * (possibly scaled) image dimensions. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 388 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 389 | int AImageDecoder_setCrop(AImageDecoder* _Nonnull decoder, ARect crop) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 390 | |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 391 | struct AImageDecoderHeaderInfo; |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 392 | /** |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 393 | * Opaque handle for representing information about the encoded image. Retrieved |
| 394 | * using {@link AImageDecoder_getHeaderInfo} and passed to methods like |
| 395 | * {@link AImageDecoderHeaderInfo_getWidth} and |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 396 | * {@link AImageDecoderHeaderInfo_getHeight}. |
| 397 | */ |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 398 | typedef struct AImageDecoderHeaderInfo AImageDecoderHeaderInfo; |
| 399 | |
| 400 | /** |
| 401 | * Return an opaque handle for reading header info. |
| 402 | * |
| 403 | * This is owned by the {@link AImageDecoder} and will be destroyed when the |
| 404 | * AImageDecoder is destroyed via {@link AImageDecoder_delete}. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 405 | * |
| 406 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 407 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 408 | const AImageDecoderHeaderInfo* _Nonnull AImageDecoder_getHeaderInfo( |
| 409 | const AImageDecoder* _Nonnull decoder) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 410 | |
| 411 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 412 | * Report the native width of the encoded image. This is also the logical |
| 413 | * pixel width of the output, unless {@link AImageDecoder_setTargetSize} is |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 414 | * used to choose a different size or {@link AImageDecoder_setCrop} is used to |
| 415 | * set a crop rect. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 416 | * |
| 417 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 418 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 419 | int32_t AImageDecoderHeaderInfo_getWidth(const AImageDecoderHeaderInfo* _Nonnull) |
| 420 | __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 421 | |
| 422 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 423 | * Report the native height of the encoded image. This is also the logical |
| 424 | * pixel height of the output, unless {@link AImageDecoder_setTargetSize} is |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 425 | * used to choose a different size or {@link AImageDecoder_setCrop} is used to |
| 426 | * set a crop rect. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 427 | * |
| 428 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 429 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 430 | int32_t AImageDecoderHeaderInfo_getHeight(const AImageDecoderHeaderInfo* _Nonnull) |
| 431 | __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 432 | |
| 433 | /** |
| 434 | * Report the mimeType of the encoded image. |
| 435 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 436 | * Available since API level 30. |
| 437 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 438 | * @return a string literal describing the mime type. |
| 439 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 440 | const char* _Nonnull AImageDecoderHeaderInfo_getMimeType( |
| 441 | const AImageDecoderHeaderInfo* _Nonnull) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 442 | |
| 443 | /** |
Leon Scroggins III | 5d0445c | 2020-01-23 09:43:43 -0500 | [diff] [blame] | 444 | * Report the {@link AndroidBitmapFormat} the AImageDecoder will decode to |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 445 | * 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] | 446 | * for the image and the system. Note that this does not indicate the |
| 447 | * encoded format of the image. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 448 | * |
| 449 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 450 | */ |
Leon Scroggins III | 5d0445c | 2020-01-23 09:43:43 -0500 | [diff] [blame] | 451 | int32_t AImageDecoderHeaderInfo_getAndroidBitmapFormat( |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 452 | const AImageDecoderHeaderInfo* _Nonnull) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 453 | |
| 454 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 455 | * 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] | 456 | * contains no alpha (according to its header), this will return |
| 457 | * {@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] | 458 | * this returns {@link ANDROID_BITMAP_FLAGS_ALPHA_PREMUL}, because |
| 459 | * {@link AImageDecoder_decodeImage} will premultiply pixels by default. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 460 | * |
| 461 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 462 | */ |
| 463 | int AImageDecoderHeaderInfo_getAlphaFlags( |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 464 | const AImageDecoderHeaderInfo* _Nonnull) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 465 | |
| 466 | /** |
Leon Scroggins III | 8cee65e | 2020-01-30 14:20:42 -0500 | [diff] [blame] | 467 | * Report the dataspace the AImageDecoder will decode to by default. |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 468 | * |
Leon Scroggins III | 8cee65e | 2020-01-30 14:20:42 -0500 | [diff] [blame] | 469 | * By default, {@link AImageDecoder_decodeImage} will not do any color |
| 470 | * conversion. |
| 471 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 472 | * Available since API level 30. |
| 473 | * |
Leon Scroggins III | 8cee65e | 2020-01-30 14:20:42 -0500 | [diff] [blame] | 474 | * @return The {@link ADataSpace} representing the way the colors |
| 475 | * are encoded (or {@link ADATASPACE_UNKNOWN} if there is not a |
| 476 | * corresponding ADataSpace). This specifies how to interpret the colors |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 477 | * in the decoded image, unless {@link AImageDecoder_setDataSpace} is |
| 478 | * called to decode to a different ADataSpace. |
| 479 | * |
| 480 | * Note that ADataSpace only exposes a few values. This may return |
Leon Scroggins III | 8cee65e | 2020-01-30 14:20:42 -0500 | [diff] [blame] | 481 | * {@link ADATASPACE_UNKNOWN}, even for Named ColorSpaces, if they have |
| 482 | * no corresponding {@link ADataSpace}. |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 483 | */ |
| 484 | int32_t AImageDecoderHeaderInfo_getDataSpace( |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 485 | const AImageDecoderHeaderInfo* _Nonnull) __INTRODUCED_IN(30); |
Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 486 | |
| 487 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 488 | * Return the minimum stride that can be used in |
| 489 | * {@link AImageDecoder_decodeImage). |
| 490 | * |
| 491 | * This stride provides no padding, meaning it will be exactly equal to the |
| 492 | * width times the number of bytes per pixel for the {@link AndroidBitmapFormat} |
| 493 | * being used. |
| 494 | * |
| 495 | * If the output is scaled (via {@link AImageDecoder_setTargetSize}) and/or |
| 496 | * cropped (via {@link AImageDecoder_setCrop}), this takes those into account. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 497 | * |
| 498 | * Available since API level 30. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 499 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 500 | size_t AImageDecoder_getMinimumStride(AImageDecoder* _Nonnull decoder) __INTRODUCED_IN(30); |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 501 | |
| 502 | /** |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 503 | * 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] | 504 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame] | 505 | * Available since API level 30. |
| 506 | * |
Leon Scroggins III | 1b38971 | 2020-10-09 13:12:39 -0400 | [diff] [blame^] | 507 | * Starting in API level 31, it can be used to decode all of the frames of an |
| 508 | * animated image (i.e. GIF, WebP, HEIF) using new APIs (TODO (scroggo): list |
| 509 | * and describe here). |
| 510 | * |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 511 | * @param decoder Opaque object representing the decoder. |
| 512 | * @param pixels On success, will be filled with the result |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 513 | * of the decode. Must be large enough to hold |size| bytes. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 514 | * @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] | 515 | * {@link AImageDecoder_getMinimumStride} and a multiple of the |
| 516 | * bytes per pixel of the {@link AndroidBitmapFormat}. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 517 | * @param size Size of the pixel buffer in bytes. Must be at least |
| 518 | * stride * (height - 1) + |
Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 519 | * {@link AImageDecoder_getMinimumStride}. |
Leon Scroggins III | bb5ffd2 | 2020-02-06 11:45:16 -0500 | [diff] [blame] | 520 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value |
| 521 | * indicating the reason for the failure. |
| 522 | * |
| 523 | * Errors: |
| 524 | * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The image was truncated. A |
| 525 | * partial image was decoded, and undecoded lines have been initialized to all |
| 526 | * zeroes. |
| 527 | * - {@link ANDROID_IMAGE_DECODER_ERROR}: The image contained an error. A |
| 528 | * partial image was decoded, and undecoded lines have been initialized to all |
| 529 | * zeroes. |
| 530 | * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The {@link AImageDecoder} or |
| 531 | * |pixels| is null, the stride is not large enough or not pixel aligned, or |
| 532 | * |size| is not large enough. |
| 533 | * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The asset or file descriptor |
| 534 | * failed to seek. |
| 535 | * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a |
| 536 | * failure to allocate memory. |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 537 | */ |
Leon Scroggins III | 4a8ecfe | 2020-10-07 10:53:24 -0400 | [diff] [blame] | 538 | int AImageDecoder_decodeImage(AImageDecoder* _Nonnull decoder, |
| 539 | void* _Nonnull pixels, size_t stride, |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 540 | size_t size) __INTRODUCED_IN(30); |
| 541 | |
| 542 | #endif // __ANDROID_API__ >= 30 |
| 543 | |
Leon Scroggins III | 1b38971 | 2020-10-09 13:12:39 -0400 | [diff] [blame^] | 544 | #if __ANDROID_API__ >= 31 |
| 545 | |
| 546 | /** |
| 547 | * Return true iff the image is animated - i.e. has multiple frames. |
| 548 | * |
| 549 | * Introduced in API 31. |
| 550 | * |
| 551 | * This may require seeking past the first frame to verify whether |
| 552 | * there is a following frame (e.g. for GIF). |
| 553 | * |
| 554 | * Errors: |
| 555 | * - returns false if |decoder| is null. |
| 556 | */ |
| 557 | bool AImageDecoder_isAnimated(AImageDecoder* _Nonnull decoder) |
| 558 | __INTRODUCED_IN(31); |
| 559 | |
| 560 | #endif // __ANDROID_API__ >= 31 |
| 561 | |
Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 562 | #ifdef __cplusplus |
| 563 | } |
| 564 | #endif |
| 565 | |
| 566 | #endif // ANDROID_IMAGE_DECODER_H |
| 567 | |
| 568 | /** @} */ |