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