| 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 | 
|  | 23 | * to decode images like PNG, JPEG, GIF, WEBP and HEIF. It has similar options | 
|  | 24 | * for scaling, cropping, and choosing the output format. Unlike the Java API, | 
|  | 25 | * which can create an android.graphics.Bitmap or | 
|  | 26 | * android.graphics.drawable.Drawable object, AImageDecoder decodes directly | 
|  | 27 | * into memory provided by the client. For more information, see the | 
|  | 28 | * <a href="https://developer.android.com/ndk/guides/image-decoder">Image decoder</a> | 
|  | 29 | * developer guide. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 30 | * @{ | 
|  | 31 | */ | 
|  | 32 |  | 
|  | 33 | /** | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 34 | * @file imagedecoder.h | 
|  | 35 | * @brief API for decoding images. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 36 | */ | 
|  | 37 |  | 
|  | 38 | #ifndef ANDROID_IMAGE_DECODER_H | 
|  | 39 | #define ANDROID_IMAGE_DECODER_H | 
|  | 40 |  | 
|  | 41 | #include "bitmap.h" | 
| Leon Scroggins III | a9f397b | 2020-01-27 12:42:56 -0500 | [diff] [blame] | 42 | #include <android/rect.h> | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 43 | #include <stdint.h> | 
|  | 44 |  | 
|  | 45 | #ifdef __cplusplus | 
|  | 46 | extern "C" { | 
|  | 47 | #endif | 
|  | 48 |  | 
|  | 49 | struct AAsset; | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 50 |  | 
|  | 51 | #if __ANDROID_API__ >= 30 | 
|  | 52 |  | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 53 | /** | 
|  | 54 | *  {@link AImageDecoder} functions result code. Many functions will return one of these | 
|  | 55 | *  to indicate success ({@link ANDROID_IMAGE_DECODER_SUCCESS}) or the reason | 
|  | 56 | *  for the failure. On failure, any out-parameters should be considered | 
|  | 57 | *  uninitialized, except where specified. | 
|  | 58 | */ | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 59 | enum { | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 60 | /** | 
|  | 61 | * Decoding was successful and complete. | 
|  | 62 | */ | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 63 | ANDROID_IMAGE_DECODER_SUCCESS = 0, | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 64 | /** | 
|  | 65 | * The input was incomplete. | 
|  | 66 | */ | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 67 | ANDROID_IMAGE_DECODER_INCOMPLETE = -1, | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 68 | /** | 
|  | 69 | * The input contained an error after decoding some lines. | 
|  | 70 | */ | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 71 | ANDROID_IMAGE_DECODER_ERROR = -2, | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 72 | /** | 
|  | 73 | * Could not convert. For example, attempting to decode an image with | 
|  | 74 | * alpha to an opaque format. | 
|  | 75 | */ | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 76 | ANDROID_IMAGE_DECODER_INVALID_CONVERSION = -3, | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 77 | /** | 
|  | 78 | * The scale is invalid. It may have overflowed, or it may be incompatible | 
|  | 79 | * with the current alpha setting. | 
|  | 80 | */ | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 81 | ANDROID_IMAGE_DECODER_INVALID_SCALE = -4, | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 82 | /** | 
|  | 83 | * Some other parameter was bad. | 
|  | 84 | */ | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 85 | ANDROID_IMAGE_DECODER_BAD_PARAMETER = -5, | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 86 | /** | 
|  | 87 | * Input was invalid before decoding any pixels. | 
|  | 88 | */ | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 89 | ANDROID_IMAGE_DECODER_INVALID_INPUT = -6, | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 90 | /** | 
|  | 91 | * A seek was required and it failed. | 
|  | 92 | */ | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 93 | ANDROID_IMAGE_DECODER_SEEK_ERROR = -7, | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 94 | /** | 
|  | 95 | * Some other error. For example, an internal allocation failed. | 
|  | 96 | */ | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 97 | ANDROID_IMAGE_DECODER_INTERNAL_ERROR = -8, | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 98 | /** | 
|  | 99 | * AImageDecoder did not recognize the format. | 
|  | 100 | */ | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 101 | ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT = -9 | 
|  | 102 | }; | 
|  | 103 |  | 
|  | 104 | struct AImageDecoder; | 
|  | 105 |  | 
|  | 106 | /** | 
|  | 107 | * Opaque handle for decoding images. | 
|  | 108 | * | 
|  | 109 | * Create using one of the following: | 
|  | 110 | * - {@link AImageDecoder_createFromAAsset} | 
|  | 111 | * - {@link AImageDecoder_createFromFd} | 
|  | 112 | * - {@link AImageDecoder_createFromBuffer} | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 113 | * | 
|  | 114 | * After creation, {@link AImageDecoder_getHeaderInfo} can be used to retrieve | 
|  | 115 | * information about the encoded image. Other functions, like | 
|  | 116 | * {@link AImageDecoder_setTargetSize}, can be used to specify how to decode, and | 
|  | 117 | * {@link AImageDecoder_decode} will decode into client provided memory. | 
|  | 118 | * | 
|  | 119 | * {@link AImageDecoder} objects are NOT thread-safe, and should not be shared across | 
|  | 120 | * threads. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 121 | */ | 
|  | 122 | typedef struct AImageDecoder AImageDecoder; | 
|  | 123 |  | 
|  | 124 | /** | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 125 | * Create a new {@link AImageDecoder} from an {@link AAsset}. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 126 | * | 
|  | 127 | * @param asset {@link AAsset} containing encoded image data. Client is still | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 128 | *              responsible for calling {@link AAsset_close} on it, which may be | 
|  | 129 | *              done after deleting the returned {@link AImageDecoder}. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 130 | * @param outDecoder On success (i.e. return value is | 
|  | 131 | *                   {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to | 
|  | 132 | *                   a newly created {@link AImageDecoder}. Caller is | 
|  | 133 | *                   responsible for calling {@link AImageDecoder_delete} on it. | 
|  | 134 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 135 | *         indicating the reason for the failure. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 136 | */ | 
| Leon Scroggins III | a9f397b | 2020-01-27 12:42:56 -0500 | [diff] [blame] | 137 | int AImageDecoder_createFromAAsset(struct AAsset* asset, AImageDecoder** outDecoder) | 
|  | 138 | __INTRODUCED_IN(30); | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 139 |  | 
|  | 140 | /** | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 141 | * Create a new {@link AImageDecoder} from a file descriptor. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 142 | * | 
|  | 143 | * @param fd Seekable, readable, open file descriptor for encoded data. | 
|  | 144 | *           Client is still responsible for closing it, which may be done | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 145 | *           after deleting the returned {@link AImageDecoder}. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 146 | * @param outDecoder On success (i.e. return value is | 
|  | 147 | *                   {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to | 
|  | 148 | *                   a newly created {@link AImageDecoder}. Caller is | 
|  | 149 | *                   responsible for calling {@link AImageDecoder_delete} on it. | 
|  | 150 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 151 | *         indicating the reason for the failure. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 152 | */ | 
|  | 153 | int AImageDecoder_createFromFd(int fd, AImageDecoder** outDecoder) __INTRODUCED_IN(30); | 
|  | 154 |  | 
|  | 155 | /** | 
|  | 156 | * Create a new AImageDecoder from a buffer. | 
|  | 157 | * | 
|  | 158 | * @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] | 159 | *               the {@link AImageDecoder} is used. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 160 | * @param length Byte length of buffer. | 
|  | 161 | * @param outDecoder On success (i.e. return value is | 
|  | 162 | *                   {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to | 
|  | 163 | *                   a newly created {@link AImageDecoder}. Caller is | 
|  | 164 | *                   responsible for calling {@link AImageDecoder_delete} on it. | 
|  | 165 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value | 
|  | 166 | *         indicating reason for the failure. | 
|  | 167 | */ | 
|  | 168 | int AImageDecoder_createFromBuffer(const void* buffer, size_t length, | 
|  | 169 | AImageDecoder** outDecoder) __INTRODUCED_IN(30); | 
|  | 170 |  | 
|  | 171 | /** | 
|  | 172 | * Delete the AImageDecoder. | 
|  | 173 | */ | 
|  | 174 | void AImageDecoder_delete(AImageDecoder* decoder) __INTRODUCED_IN(30); | 
|  | 175 |  | 
|  | 176 | /** | 
|  | 177 | * Choose the desired output format. | 
|  | 178 | * | 
| Leon Scroggins III | 5d0445c | 2020-01-23 09:43:43 -0500 | [diff] [blame] | 179 | * @param format {@link AndroidBitmapFormat} to use for the output. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 180 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} if the format is compatible | 
|  | 181 | *         with the image and {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION} | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 182 | *         otherwise. In the latter case, the {@link AImageDecoder} uses the | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 183 | *         format it was already planning to use (either its default | 
|  | 184 | *         or a previously successful setting from this function). | 
|  | 185 | */ | 
|  | 186 | int AImageDecoder_setAndroidBitmapFormat(AImageDecoder*, | 
|  | 187 | int32_t format) __INTRODUCED_IN(30); | 
|  | 188 |  | 
| Leon Scroggins III | 1be112f | 2020-01-15 04:26:44 -0500 | [diff] [blame] | 189 | /** | 
|  | 190 | * Specify whether the output's pixels should be unpremultiplied. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 191 | * | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 192 | * By default, {@link AImageDecoder_decodeImage} will premultiply the pixels, if they have alpha. | 
|  | 193 | * 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] | 194 | * opaque image. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 195 | * | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 196 | * @param unpremultipliedRequired Pass true to leave the pixels unpremultiplied. | 
|  | 197 | * @return an enum describing whether the call succeeded. | 
|  | 198 | *         - {@link ANDROID_IMAGE_DECODER_SUCCESS} on success | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 199 | *         - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION} if the conversion | 
|  | 200 | *           is not possible | 
|  | 201 | *         - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for bad parameters | 
|  | 202 | */ | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 203 | int AImageDecoder_setUnpremultipliedRequired(AImageDecoder*, | 
|  | 204 | bool unpremultipliedRequired) __INTRODUCED_IN(30); | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 205 |  | 
|  | 206 | /** | 
| Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 207 | * Choose the dataspace for the output. | 
|  | 208 | * | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 209 | * Ignored by {@link ANDROID_BITMAP_FORMAT_A_8}, which does not support | 
|  | 210 | * an {@link ADataSpace}. | 
| Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 211 | * | 
|  | 212 | * @param dataspace The {@link ADataSpace} to decode into. An ADataSpace | 
|  | 213 | *                  specifies how to interpret the colors. By default, | 
|  | 214 | *                  AImageDecoder will decode into the ADataSpace specified by | 
|  | 215 | *                  {@link AImageDecoderHeaderInfo_getDataSpace}. If this | 
|  | 216 | *                  parameter is set to a different ADataSpace, AImageDecoder | 
|  | 217 | *                  will transform the output into the specified ADataSpace. | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 218 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or | 
|  | 219 | *         {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for a null | 
|  | 220 | *         {@link AImageDecoder} or an integer that does not correspond to an | 
|  | 221 | *         {@link ADataSpace} value. | 
| Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 222 | */ | 
|  | 223 | int AImageDecoder_setDataSpace(AImageDecoder*, int32_t dataspace) __INTRODUCED_IN(30); | 
|  | 224 |  | 
|  | 225 | /** | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 226 | * Specify the output size for a decoded image. | 
|  | 227 | * | 
|  | 228 | * Future calls to {@link AImageDecoder_decodeImage} will sample or scale the | 
|  | 229 | * encoded image to reach the desired size. If a crop rect is set (via | 
|  | 230 | * {@link AImageDecoder_setCrop}), it must be contained within the dimensions | 
|  | 231 | * specified by width and height, and the output image will be the size of the | 
|  | 232 | * crop rect. | 
|  | 233 | * | 
|  | 234 | * @param width Width of the output (prior to cropping). | 
|  | 235 | *              This will affect future calls to | 
|  | 236 | *              {@link AImageDecoder_getMinimumStride}, which will now return | 
|  | 237 | *              a value based on this width. | 
|  | 238 | * @param height Height of the output (prior to cropping). | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 239 | * @return an enum describing whether the call succeeded. | 
|  | 240 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or | 
|  | 241 | *         {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} if the {@link AImageDecoder} | 
|  | 242 | *         pointer is null, width or height is <= 0, or any existing crop is | 
|  | 243 | *         not contained by the new image dimensions. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 244 | */ | 
| Leon Scroggins III | 5d0445c | 2020-01-23 09:43:43 -0500 | [diff] [blame] | 245 | int AImageDecoder_setTargetSize(AImageDecoder*, int32_t width, int32_t height) __INTRODUCED_IN(30); | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 246 |  | 
| Leon Scroggins III | f27256b | 2020-01-19 21:13:04 -0500 | [diff] [blame] | 247 |  | 
|  | 248 | /** | 
|  | 249 | * Compute the dimensions to use for a given sampleSize. | 
|  | 250 | * | 
|  | 251 | * Although AImageDecoder can scale to an arbitrary target size (see | 
|  | 252 | * {@link AImageDecoder_setTargetSize}), some sizes may be more efficient than | 
|  | 253 | * others. This computes the most efficient target size to use to reach a | 
|  | 254 | * particular sampleSize. | 
|  | 255 | * | 
|  | 256 | * @param sampleSize A subsampling rate of the original image. Must be greater | 
|  | 257 | *                   than or equal to 1. A sampleSize of 2 means to skip every | 
|  | 258 | *                   other pixel/line, resulting in a width and height that are | 
|  | 259 | *                   1/2 of the original dimensions, with 1/4 the number of | 
|  | 260 | *                   pixels. | 
|  | 261 | * @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] | 262 | *              in the direction that the decoder can do most efficiently. | 
| Leon Scroggins III | f27256b | 2020-01-19 21:13:04 -0500 | [diff] [blame] | 263 | * @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] | 264 | *               in the direction that the decoder can do most efficiently. | 
|  | 265 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or | 
|  | 266 | *         {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for bad input. | 
| Leon Scroggins III | f27256b | 2020-01-19 21:13:04 -0500 | [diff] [blame] | 267 | */ | 
|  | 268 | int AImageDecoder_computeSampledSize(const AImageDecoder*, int sampleSize, | 
| Leon Scroggins III | 5d0445c | 2020-01-23 09:43:43 -0500 | [diff] [blame] | 269 | int32_t* width, int32_t* height) __INTRODUCED_IN(30); | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 270 | /** | 
|  | 271 | * Specify how to crop the output after scaling (if any). | 
|  | 272 | * | 
|  | 273 | * Future calls to {@link AImageDecoder_decodeImage} will crop their output to | 
|  | 274 | * the specified {@link ARect}. Clients will only need to allocate enough memory | 
|  | 275 | * for the cropped ARect. | 
|  | 276 | * | 
|  | 277 | * @param crop Rectangle describing a crop of the decode. It must be contained inside of | 
|  | 278 | *             the (possibly scaled, by {@link AImageDecoder_setTargetSize}) | 
|  | 279 | *             image dimensions. This will affect future calls to | 
|  | 280 | *             {@link AImageDecoder_getMinimumStride}, which will now return a | 
|  | 281 | *             value based on the width of the crop. An empty ARect - | 
|  | 282 | *             specifically { 0, 0, 0, 0 } - may be used to remove the cropping | 
|  | 283 | *             behavior. Any other empty or unsorted ARects will result in | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 284 | *             returning {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}. | 
|  | 285 | * @return an enum describing whether the call succeeded. | 
|  | 286 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or | 
|  | 287 | *         {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} if the {@link AImageDecoder} | 
|  | 288 | *         pointer is null or the crop is not contained by the image | 
|  | 289 | *         dimensions. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 290 | */ | 
|  | 291 | int AImageDecoder_setCrop(AImageDecoder*, ARect crop) __INTRODUCED_IN(30); | 
|  | 292 |  | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 293 | struct AImageDecoderHeaderInfo; | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 294 | /** | 
|  | 295 | * Opaque handle for representing information about the encoded image. It can | 
|  | 296 | * be passed to methods like {@link AImageDecoderHeaderInfo_getWidth} and | 
|  | 297 | * {@link AImageDecoderHeaderInfo_getHeight}. | 
|  | 298 | */ | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 299 | typedef struct AImageDecoderHeaderInfo AImageDecoderHeaderInfo; | 
|  | 300 |  | 
|  | 301 | /** | 
|  | 302 | * Return an opaque handle for reading header info. | 
|  | 303 | * | 
|  | 304 | * This is owned by the {@link AImageDecoder} and will be destroyed when the | 
|  | 305 | * AImageDecoder is destroyed via {@link AImageDecoder_delete}. | 
|  | 306 | */ | 
|  | 307 | const AImageDecoderHeaderInfo* AImageDecoder_getHeaderInfo( | 
|  | 308 | const AImageDecoder*) __INTRODUCED_IN(30); | 
|  | 309 |  | 
|  | 310 | /** | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 311 | * Report the native width of the encoded image. This is also the logical | 
|  | 312 | * pixel width of the output, unless {@link AImageDecoder_setTargetSize} is | 
|  | 313 | * used to choose a different size. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 314 | */ | 
|  | 315 | int32_t AImageDecoderHeaderInfo_getWidth(const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); | 
|  | 316 |  | 
|  | 317 | /** | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 318 | * Report the native height of the encoded image. This is also the logical | 
|  | 319 | * pixel height of the output, unless {@link AImageDecoder_setTargetSize} is | 
|  | 320 | * used to choose a different size. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 321 | */ | 
|  | 322 | int32_t AImageDecoderHeaderInfo_getHeight(const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); | 
|  | 323 |  | 
|  | 324 | /** | 
|  | 325 | * Report the mimeType of the encoded image. | 
|  | 326 | * | 
|  | 327 | * @return a string literal describing the mime type. | 
|  | 328 | */ | 
|  | 329 | const char* AImageDecoderHeaderInfo_getMimeType( | 
|  | 330 | const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); | 
|  | 331 |  | 
|  | 332 | /** | 
| Leon Scroggins III | 5d0445c | 2020-01-23 09:43:43 -0500 | [diff] [blame] | 333 | * Report the {@link AndroidBitmapFormat} the AImageDecoder will decode to | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 334 | * 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] | 335 | * for the image and the system. Note that this does not indicate the | 
|  | 336 | * encoded format of the image. | 
|  | 337 | */ | 
| Leon Scroggins III | 5d0445c | 2020-01-23 09:43:43 -0500 | [diff] [blame] | 338 | int32_t AImageDecoderHeaderInfo_getAndroidBitmapFormat( | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 339 | const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); | 
|  | 340 |  | 
|  | 341 | /** | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 342 | * 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] | 343 | * contains no alpha (according to its header), this will return | 
|  | 344 | * {@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] | 345 | * this returns {@link ANDROID_BITMAP_FLAGS_ALPHA_PREMUL}, because | 
|  | 346 | * {@link AImageDecoder_decodeImage} will premultiply pixels by default. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 347 | */ | 
|  | 348 | int AImageDecoderHeaderInfo_getAlphaFlags( | 
|  | 349 | const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); | 
|  | 350 |  | 
|  | 351 | /** | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 352 | * Report the dataspace the {@link AImageDecoder} will decode to by default. | 
| Leon Scroggins III | 20d480c | 2020-01-15 15:32:59 -0500 | [diff] [blame] | 353 | * AImageDecoder will try to choose one that is sensible for the | 
|  | 354 | * image and the system. Note that this may not exactly match the ICC | 
|  | 355 | * profile (or other color information) stored in the encoded image. | 
|  | 356 | * | 
|  | 357 | * @return The {@link ADataSpace} most closely representing the way the colors | 
|  | 358 | *         are encoded (or {@link ADATASPACE_UNKNOWN} if there is not an | 
|  | 359 | *         approximate ADataSpace). This specifies how to interpret the colors | 
|  | 360 | *         in the decoded image, unless {@link AImageDecoder_setDataSpace} is | 
|  | 361 | *         called to decode to a different ADataSpace. | 
|  | 362 | * | 
|  | 363 | *         Note that ADataSpace only exposes a few values. This may return | 
|  | 364 | *         ADATASPACE_UNKNOWN, even for Named ColorSpaces, if they have no | 
|  | 365 | *         corresponding ADataSpace. | 
|  | 366 | */ | 
|  | 367 | int32_t AImageDecoderHeaderInfo_getDataSpace( | 
|  | 368 | const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); | 
|  | 369 |  | 
|  | 370 | /** | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 371 | * Return the minimum stride that can be used in | 
|  | 372 | * {@link AImageDecoder_decodeImage). | 
|  | 373 | * | 
|  | 374 | * This stride provides no padding, meaning it will be exactly equal to the | 
|  | 375 | * width times the number of bytes per pixel for the {@link AndroidBitmapFormat} | 
|  | 376 | * being used. | 
|  | 377 | * | 
|  | 378 | * If the output is scaled (via {@link AImageDecoder_setTargetSize}) and/or | 
|  | 379 | * cropped (via {@link AImageDecoder_setCrop}), this takes those into account. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 380 | */ | 
|  | 381 | size_t AImageDecoder_getMinimumStride(AImageDecoder*) __INTRODUCED_IN(30); | 
|  | 382 |  | 
|  | 383 | /** | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 384 | * 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] | 385 | * | 
|  | 386 | * @param decoder Opaque object representing the decoder. | 
|  | 387 | * @param pixels On success, will be filled with the result | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 388 | *               of the decode. Must be large enough to hold |size| bytes. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 389 | * @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] | 390 | *               {@link AImageDecoder_getMinimumStride} and a multiple of the | 
|  | 391 | *               bytes per pixel of the {@link AndroidBitmapFormat}. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 392 | * @param size Size of the pixel buffer in bytes. Must be at least | 
|  | 393 | *             stride * (height - 1) + | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 394 | *             {@link AImageDecoder_getMinimumStride}. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 395 | * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success, or an error code | 
|  | 396 | *         from the same enum describing the failure. | 
| Leon Scroggins III | 97fea5f | 2020-01-30 12:18:20 -0500 | [diff] [blame] | 397 | *         {@link ANDROID_IMAGE_DECODER_INCOMPLETE} or | 
|  | 398 | *         {@link ANDROID_IMAGE_DECODER_ERROR} means that a partial image was | 
|  | 399 | *         decoded, and undecoded lines have been initialized to all zeroes. | 
| Leon Scroggins III | 2f98494 | 2019-11-22 17:02:23 -0500 | [diff] [blame] | 400 | */ | 
|  | 401 | int AImageDecoder_decodeImage(AImageDecoder* decoder, | 
|  | 402 | void* pixels, size_t stride, | 
|  | 403 | size_t size) __INTRODUCED_IN(30); | 
|  | 404 |  | 
|  | 405 | #endif // __ANDROID_API__ >= 30 | 
|  | 406 |  | 
|  | 407 | #ifdef __cplusplus | 
|  | 408 | } | 
|  | 409 | #endif | 
|  | 410 |  | 
|  | 411 | #endif // ANDROID_IMAGE_DECODER_H | 
|  | 412 |  | 
|  | 413 | /** @} */ |