blob: 2aac33cf7e36385fde9b00660562ac9ca877590e [file] [log] [blame]
Leon Scroggins III2f984942019-11-22 17:02:23 -05001/*
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 III97fea5f2020-01-30 12:18:20 -050018 * @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 IIIbb5ffd22020-02-06 11:45:16 -050023 * 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 III97fea5f2020-01-30 12:18:20 -050035 * 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 III2f984942019-11-22 17:02:23 -050039 * @{
40 */
41
42/**
Leon Scroggins III97fea5f2020-01-30 12:18:20 -050043 * @file imagedecoder.h
44 * @brief API for decoding images.
Leon Scroggins III2f984942019-11-22 17:02:23 -050045 */
46
47#ifndef ANDROID_IMAGE_DECODER_H
48#define ANDROID_IMAGE_DECODER_H
49
50#include "bitmap.h"
Leon Scroggins IIIa9f397b2020-01-27 12:42:56 -050051#include <android/rect.h>
Leon Scroggins III2f984942019-11-22 17:02:23 -050052#include <stdint.h>
53
54#ifdef __cplusplus
55extern "C" {
56#endif
57
58struct AAsset;
Leon Scroggins III2f984942019-11-22 17:02:23 -050059
Leon Scroggins III97fea5f2020-01-30 12:18:20 -050060/**
61 * {@link AImageDecoder} functions result code. Many functions will return one of these
62 * to indicate success ({@link ANDROID_IMAGE_DECODER_SUCCESS}) or the reason
63 * for the failure. On failure, any out-parameters should be considered
64 * uninitialized, except where specified.
65 */
Leon Scroggins III2f984942019-11-22 17:02:23 -050066enum {
Leon Scroggins III97fea5f2020-01-30 12:18:20 -050067 /**
68 * Decoding was successful and complete.
69 */
Leon Scroggins III2f984942019-11-22 17:02:23 -050070 ANDROID_IMAGE_DECODER_SUCCESS = 0,
Leon Scroggins III97fea5f2020-01-30 12:18:20 -050071 /**
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -050072 * The input is incomplete.
Leon Scroggins III97fea5f2020-01-30 12:18:20 -050073 */
Leon Scroggins III2f984942019-11-22 17:02:23 -050074 ANDROID_IMAGE_DECODER_INCOMPLETE = -1,
Leon Scroggins III97fea5f2020-01-30 12:18:20 -050075 /**
76 * The input contained an error after decoding some lines.
77 */
Leon Scroggins III2f984942019-11-22 17:02:23 -050078 ANDROID_IMAGE_DECODER_ERROR = -2,
Leon Scroggins III97fea5f2020-01-30 12:18:20 -050079 /**
80 * Could not convert. For example, attempting to decode an image with
81 * alpha to an opaque format.
82 */
Leon Scroggins III2f984942019-11-22 17:02:23 -050083 ANDROID_IMAGE_DECODER_INVALID_CONVERSION = -3,
Leon Scroggins III97fea5f2020-01-30 12:18:20 -050084 /**
85 * The scale is invalid. It may have overflowed, or it may be incompatible
86 * with the current alpha setting.
87 */
Leon Scroggins III2f984942019-11-22 17:02:23 -050088 ANDROID_IMAGE_DECODER_INVALID_SCALE = -4,
Leon Scroggins III97fea5f2020-01-30 12:18:20 -050089 /**
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -050090 * Some other parameter is invalid.
Leon Scroggins III97fea5f2020-01-30 12:18:20 -050091 */
Leon Scroggins III2f984942019-11-22 17:02:23 -050092 ANDROID_IMAGE_DECODER_BAD_PARAMETER = -5,
Leon Scroggins III97fea5f2020-01-30 12:18:20 -050093 /**
94 * Input was invalid before decoding any pixels.
95 */
Leon Scroggins III2f984942019-11-22 17:02:23 -050096 ANDROID_IMAGE_DECODER_INVALID_INPUT = -6,
Leon Scroggins III97fea5f2020-01-30 12:18:20 -050097 /**
98 * A seek was required and it failed.
99 */
Leon Scroggins III2f984942019-11-22 17:02:23 -0500100 ANDROID_IMAGE_DECODER_SEEK_ERROR = -7,
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500101 /**
102 * Some other error. For example, an internal allocation failed.
103 */
Leon Scroggins III2f984942019-11-22 17:02:23 -0500104 ANDROID_IMAGE_DECODER_INTERNAL_ERROR = -8,
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500105 /**
106 * AImageDecoder did not recognize the format.
107 */
Leon Scroggins III2f984942019-11-22 17:02:23 -0500108 ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT = -9
109};
110
111struct AImageDecoder;
112
113/**
114 * Opaque handle for decoding images.
115 *
116 * Create using one of the following:
117 * - {@link AImageDecoder_createFromAAsset}
118 * - {@link AImageDecoder_createFromFd}
119 * - {@link AImageDecoder_createFromBuffer}
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500120 *
121 * After creation, {@link AImageDecoder_getHeaderInfo} can be used to retrieve
122 * information about the encoded image. Other functions, like
123 * {@link AImageDecoder_setTargetSize}, can be used to specify how to decode, and
124 * {@link AImageDecoder_decode} will decode into client provided memory.
125 *
126 * {@link AImageDecoder} objects are NOT thread-safe, and should not be shared across
127 * threads.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500128 */
129typedef struct AImageDecoder AImageDecoder;
130
131/**
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500132 * Create a new {@link AImageDecoder} from an {@link AAsset}.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500133 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700134 * Available since API level 30.
135 *
Leon Scroggins III2f984942019-11-22 17:02:23 -0500136 * @param asset {@link AAsset} containing encoded image data. Client is still
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500137 * responsible for calling {@link AAsset_close} on it, which may be
138 * done after deleting the returned {@link AImageDecoder}.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500139 * @param outDecoder On success (i.e. return value is
140 * {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to
141 * a newly created {@link AImageDecoder}. Caller is
142 * responsible for calling {@link AImageDecoder_delete} on it.
143 * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500144 * indicating the reason for the failure.
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500145 *
146 * Errors:
147 * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The asset was truncated before
148 * reading the image header.
149 * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: One of the parameters is
150 * null.
151 * - {@link ANDROID_IMAGE_DECODER_INVALID_INPUT}: There is an error in the
152 * header.
153 * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The asset failed to seek.
154 * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a
155 * failure to allocate memory.
156 * - {@link ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT}: The format is not
157 * supported.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500158 */
Leon Scroggins IIIa9f397b2020-01-27 12:42:56 -0500159int AImageDecoder_createFromAAsset(struct AAsset* asset, AImageDecoder** outDecoder)
160 __INTRODUCED_IN(30);
Leon Scroggins III2f984942019-11-22 17:02:23 -0500161
162/**
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500163 * Create a new {@link AImageDecoder} from a file descriptor.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500164 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700165 * Available since API level 30.
166 *
Leon Scroggins III2f984942019-11-22 17:02:23 -0500167 * @param fd Seekable, readable, open file descriptor for encoded data.
168 * Client is still responsible for closing it, which may be done
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500169 * after deleting the returned {@link AImageDecoder}.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500170 * @param outDecoder On success (i.e. return value is
171 * {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to
172 * a newly created {@link AImageDecoder}. Caller is
173 * responsible for calling {@link AImageDecoder_delete} on it.
174 * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500175 * indicating the reason for the failure.
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500176 *
177 * Errors:
178 * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The file was truncated before
179 * reading the image header.
180 * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The {@link AImageDecoder} is
181 * null, or |fd| does not represent a valid, seekable file descriptor.
182 * - {@link ANDROID_IMAGE_DECODER_INVALID_INPUT}: There is an error in the
183 * header.
184 * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The descriptor failed to seek.
185 * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a
186 * failure to allocate memory.
187 * - {@link ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT}: The format is not
188 * supported.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500189 */
190int AImageDecoder_createFromFd(int fd, AImageDecoder** outDecoder) __INTRODUCED_IN(30);
191
192/**
193 * Create a new AImageDecoder from a buffer.
194 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700195 * Available since API level 30.
196 *
Leon Scroggins III2f984942019-11-22 17:02:23 -0500197 * @param buffer Pointer to encoded data. Must be valid for the entire time
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500198 * the {@link AImageDecoder} is used.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500199 * @param length Byte length of buffer.
200 * @param outDecoder On success (i.e. return value is
201 * {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to
202 * a newly created {@link AImageDecoder}. Caller is
203 * responsible for calling {@link AImageDecoder_delete} on it.
204 * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500205 * indicating the reason for the failure.
206 *
207 * Errors:
208 * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The encoded image was truncated before
209 * reading the image header.
210 * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: One of the parameters is
211 * invalid.
212 * - {@link ANDROID_IMAGE_DECODER_INVALID_INPUT}: There is an error in the
213 * header.
214 * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a
215 * failure to allocate memory.
216 * - {@link ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT}: The format is not
217 * supported.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500218 */
219int AImageDecoder_createFromBuffer(const void* buffer, size_t length,
220 AImageDecoder** outDecoder) __INTRODUCED_IN(30);
221
222/**
223 * Delete the AImageDecoder.
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700224 *
225 * Available since API level 30.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500226 */
227void AImageDecoder_delete(AImageDecoder* decoder) __INTRODUCED_IN(30);
228
229/**
230 * Choose the desired output format.
231 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700232 * Available since API level 30.
233 *
Leon Scroggins III5d0445c2020-01-23 09:43:43 -0500234 * @param format {@link AndroidBitmapFormat} to use for the output.
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500235 * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value
236 * indicating the reason for the failure. On failure, the
237 * {@link AImageDecoder} uses the format it was already planning
238 * to use (either its default or a previously successful setting
239 * from this function).
240 *
241 * Errors:
242 * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The
243 * {@link AImageDecoder} is null or |format| does not correspond to an
244 * {@link AndroidBitmapFormat}.
245 * - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION}: The
246 * {@link AndroidBitmapFormat} is incompatible with the image.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500247 */
248int AImageDecoder_setAndroidBitmapFormat(AImageDecoder*,
249 int32_t format) __INTRODUCED_IN(30);
250
Leon Scroggins III1be112f2020-01-15 04:26:44 -0500251/**
252 * Specify whether the output's pixels should be unpremultiplied.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500253 *
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500254 * By default, {@link AImageDecoder_decodeImage} will premultiply the pixels, if they have alpha.
255 * Pass true to this method to leave them unpremultiplied. This has no effect on an
Leon Scroggins III1be112f2020-01-15 04:26:44 -0500256 * opaque image.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500257 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700258 * Available since API level 30.
259 *
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500260 * @param unpremultipliedRequired Pass true to leave the pixels unpremultiplied.
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500261 * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value
262 * indicating the reason for the failure.
263 *
264 * Errors:
265 * - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION}: Unpremultiplied is not
266 * possible due to an existing scale set by
267 * {@link AImageDecoder_setTargetSize}.
268 * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The
269 * {@link AImageDecoder} is null.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500270 */
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500271int AImageDecoder_setUnpremultipliedRequired(AImageDecoder*,
272 bool unpremultipliedRequired) __INTRODUCED_IN(30);
Leon Scroggins III2f984942019-11-22 17:02:23 -0500273
274/**
Leon Scroggins III20d480c2020-01-15 15:32:59 -0500275 * Choose the dataspace for the output.
276 *
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500277 * Ignored by {@link ANDROID_BITMAP_FORMAT_A_8}, which does not support
278 * an {@link ADataSpace}.
Leon Scroggins III20d480c2020-01-15 15:32:59 -0500279 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700280 * Available since API level 30.
281 *
Leon Scroggins III20d480c2020-01-15 15:32:59 -0500282 * @param dataspace The {@link ADataSpace} to decode into. An ADataSpace
283 * specifies how to interpret the colors. By default,
284 * AImageDecoder will decode into the ADataSpace specified by
285 * {@link AImageDecoderHeaderInfo_getDataSpace}. If this
286 * parameter is set to a different ADataSpace, AImageDecoder
287 * will transform the output into the specified ADataSpace.
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500288 * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value
289 * indicating the reason for the failure.
290 *
291 * Errors:
292 * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The
293 * {@link AImageDecoder} is null or |dataspace| does not correspond to an
294 * {@link ADataSpace} value.
Leon Scroggins III20d480c2020-01-15 15:32:59 -0500295 */
296int AImageDecoder_setDataSpace(AImageDecoder*, int32_t dataspace) __INTRODUCED_IN(30);
297
298/**
Leon Scroggins III2f984942019-11-22 17:02:23 -0500299 * Specify the output size for a decoded image.
300 *
301 * Future calls to {@link AImageDecoder_decodeImage} will sample or scale the
302 * encoded image to reach the desired size. If a crop rect is set (via
303 * {@link AImageDecoder_setCrop}), it must be contained within the dimensions
304 * specified by width and height, and the output image will be the size of the
305 * crop rect.
306 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700307 * Available since API level 30.
308 *
Leon Scroggins III2f984942019-11-22 17:02:23 -0500309 * @param width Width of the output (prior to cropping).
310 * This will affect future calls to
311 * {@link AImageDecoder_getMinimumStride}, which will now return
312 * a value based on this width.
313 * @param height Height of the output (prior to cropping).
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500314 * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value
315 * indicating the reason for the failure.
316 *
317 * Errors:
318 * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The
319 * {@link AImageDecoder} is null.
320 * - {@link ANDROID_IMAGE_DECODER_INVALID_SCALE}: |width| or |height| is <= 0,
321 * the size is too big, any existing crop is not contained by the new image dimensions,
322 * or the scale is incompatible with a previous call to
323 * {@link AImageDecoder_setUnpremultipliedRequired}(true).
Leon Scroggins III2f984942019-11-22 17:02:23 -0500324 */
Leon Scroggins III5d0445c2020-01-23 09:43:43 -0500325int AImageDecoder_setTargetSize(AImageDecoder*, int32_t width, int32_t height) __INTRODUCED_IN(30);
Leon Scroggins III2f984942019-11-22 17:02:23 -0500326
Leon Scroggins IIIf27256b2020-01-19 21:13:04 -0500327
328/**
329 * Compute the dimensions to use for a given sampleSize.
330 *
331 * Although AImageDecoder can scale to an arbitrary target size (see
332 * {@link AImageDecoder_setTargetSize}), some sizes may be more efficient than
333 * others. This computes the most efficient target size to use to reach a
334 * particular sampleSize.
335 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700336 * Available since API level 30.
337 *
Leon Scroggins IIIf27256b2020-01-19 21:13:04 -0500338 * @param sampleSize A subsampling rate of the original image. Must be greater
339 * than or equal to 1. A sampleSize of 2 means to skip every
340 * other pixel/line, resulting in a width and height that are
341 * 1/2 of the original dimensions, with 1/4 the number of
342 * pixels.
343 * @param width Out parameter for the width sampled by sampleSize, and rounded
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500344 * in the direction that the decoder can do most efficiently.
Leon Scroggins IIIf27256b2020-01-19 21:13:04 -0500345 * @param height Out parameter for the height sampled by sampleSize, and rounded
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500346 * in the direction that the decoder can do most efficiently.
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500347 * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value
348 * indicating the reason for the failure.
349 *
350 * Errors:
351 * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The
352 * {@link AImageDecoder}, |width| or |height| is null or |sampleSize| is < 1.
Leon Scroggins IIIf27256b2020-01-19 21:13:04 -0500353 */
354int AImageDecoder_computeSampledSize(const AImageDecoder*, int sampleSize,
Leon Scroggins III5d0445c2020-01-23 09:43:43 -0500355 int32_t* width, int32_t* height) __INTRODUCED_IN(30);
Leon Scroggins III2f984942019-11-22 17:02:23 -0500356/**
357 * Specify how to crop the output after scaling (if any).
358 *
359 * Future calls to {@link AImageDecoder_decodeImage} will crop their output to
360 * the specified {@link ARect}. Clients will only need to allocate enough memory
361 * for the cropped ARect.
362 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700363 * Available since API level 30.
364 *
Leon Scroggins III2f984942019-11-22 17:02:23 -0500365 * @param crop Rectangle describing a crop of the decode. It must be contained inside of
366 * the (possibly scaled, by {@link AImageDecoder_setTargetSize})
367 * image dimensions. This will affect future calls to
368 * {@link AImageDecoder_getMinimumStride}, which will now return a
369 * value based on the width of the crop. An empty ARect -
370 * specifically { 0, 0, 0, 0 } - may be used to remove the cropping
371 * behavior. Any other empty or unsorted ARects will result in
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500372 * returning {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}.
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500373 * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value
374 * indicating the reason for the failure.
375 *
376 * Errors:
377 * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The
378 * {@link AImageDecoder} is null or the crop is not contained by the
379 * (possibly scaled) image dimensions.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500380 */
381int AImageDecoder_setCrop(AImageDecoder*, ARect crop) __INTRODUCED_IN(30);
382
Leon Scroggins III2f984942019-11-22 17:02:23 -0500383struct AImageDecoderHeaderInfo;
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500384/**
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500385 * Opaque handle for representing information about the encoded image. Retrieved
386 * using {@link AImageDecoder_getHeaderInfo} and passed to methods like
387 * {@link AImageDecoderHeaderInfo_getWidth} and
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500388 * {@link AImageDecoderHeaderInfo_getHeight}.
389 */
Leon Scroggins III2f984942019-11-22 17:02:23 -0500390typedef struct AImageDecoderHeaderInfo AImageDecoderHeaderInfo;
391
392/**
393 * Return an opaque handle for reading header info.
394 *
395 * This is owned by the {@link AImageDecoder} and will be destroyed when the
396 * AImageDecoder is destroyed via {@link AImageDecoder_delete}.
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700397 *
398 * Available since API level 30.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500399 */
400const AImageDecoderHeaderInfo* AImageDecoder_getHeaderInfo(
401 const AImageDecoder*) __INTRODUCED_IN(30);
402
403/**
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500404 * Report the native width of the encoded image. This is also the logical
405 * pixel width of the output, unless {@link AImageDecoder_setTargetSize} is
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500406 * used to choose a different size or {@link AImageDecoder_setCrop} is used to
407 * set a crop rect.
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700408 *
409 * Available since API level 30.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500410 */
411int32_t AImageDecoderHeaderInfo_getWidth(const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30);
412
413/**
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500414 * Report the native height of the encoded image. This is also the logical
415 * pixel height of the output, unless {@link AImageDecoder_setTargetSize} is
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500416 * used to choose a different size or {@link AImageDecoder_setCrop} is used to
417 * set a crop rect.
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700418 *
419 * Available since API level 30.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500420 */
421int32_t AImageDecoderHeaderInfo_getHeight(const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30);
422
423/**
424 * Report the mimeType of the encoded image.
425 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700426 * Available since API level 30.
427 *
Leon Scroggins III2f984942019-11-22 17:02:23 -0500428 * @return a string literal describing the mime type.
429 */
430const char* AImageDecoderHeaderInfo_getMimeType(
431 const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30);
432
433/**
Leon Scroggins III5d0445c2020-01-23 09:43:43 -0500434 * Report the {@link AndroidBitmapFormat} the AImageDecoder will decode to
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500435 * by default. {@link AImageDecoder} will try to choose one that is sensible
Leon Scroggins III2f984942019-11-22 17:02:23 -0500436 * for the image and the system. Note that this does not indicate the
437 * encoded format of the image.
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700438 *
439 * Available since API level 30.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500440 */
Leon Scroggins III5d0445c2020-01-23 09:43:43 -0500441int32_t AImageDecoderHeaderInfo_getAndroidBitmapFormat(
Leon Scroggins III2f984942019-11-22 17:02:23 -0500442 const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30);
443
444/**
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500445 * Report how the {@link AImageDecoder} will handle alpha by default. If the image
Leon Scroggins III2f984942019-11-22 17:02:23 -0500446 * contains no alpha (according to its header), this will return
447 * {@link ANDROID_BITMAP_FLAGS_ALPHA_OPAQUE}. If the image may contain alpha,
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500448 * this returns {@link ANDROID_BITMAP_FLAGS_ALPHA_PREMUL}, because
449 * {@link AImageDecoder_decodeImage} will premultiply pixels by default.
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700450 *
451 * Available since API level 30.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500452 */
453int AImageDecoderHeaderInfo_getAlphaFlags(
454 const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30);
455
456/**
Leon Scroggins III8cee65e2020-01-30 14:20:42 -0500457 * Report the dataspace the AImageDecoder will decode to by default.
Leon Scroggins III20d480c2020-01-15 15:32:59 -0500458 *
Leon Scroggins III8cee65e2020-01-30 14:20:42 -0500459 * By default, {@link AImageDecoder_decodeImage} will not do any color
460 * conversion.
461 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700462 * Available since API level 30.
463 *
Leon Scroggins III8cee65e2020-01-30 14:20:42 -0500464 * @return The {@link ADataSpace} representing the way the colors
465 * are encoded (or {@link ADATASPACE_UNKNOWN} if there is not a
466 * corresponding ADataSpace). This specifies how to interpret the colors
Leon Scroggins III20d480c2020-01-15 15:32:59 -0500467 * in the decoded image, unless {@link AImageDecoder_setDataSpace} is
468 * called to decode to a different ADataSpace.
469 *
470 * Note that ADataSpace only exposes a few values. This may return
Leon Scroggins III8cee65e2020-01-30 14:20:42 -0500471 * {@link ADATASPACE_UNKNOWN}, even for Named ColorSpaces, if they have
472 * no corresponding {@link ADataSpace}.
Leon Scroggins III20d480c2020-01-15 15:32:59 -0500473 */
474int32_t AImageDecoderHeaderInfo_getDataSpace(
475 const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30);
476
477/**
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500478 * Return the minimum stride that can be used in
479 * {@link AImageDecoder_decodeImage).
480 *
481 * This stride provides no padding, meaning it will be exactly equal to the
482 * width times the number of bytes per pixel for the {@link AndroidBitmapFormat}
483 * being used.
484 *
485 * If the output is scaled (via {@link AImageDecoder_setTargetSize}) and/or
486 * cropped (via {@link AImageDecoder_setCrop}), this takes those into account.
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700487 *
488 * Available since API level 30.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500489 */
490size_t AImageDecoder_getMinimumStride(AImageDecoder*) __INTRODUCED_IN(30);
491
492/**
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500493 * Decode the image into pixels, using the settings of the {@link AImageDecoder}.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500494 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700495 * Available since API level 30.
496 *
Leon Scroggins III2f984942019-11-22 17:02:23 -0500497 * @param decoder Opaque object representing the decoder.
498 * @param pixels On success, will be filled with the result
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500499 * of the decode. Must be large enough to hold |size| bytes.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500500 * @param stride Width in bytes of a single row. Must be at least
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500501 * {@link AImageDecoder_getMinimumStride} and a multiple of the
502 * bytes per pixel of the {@link AndroidBitmapFormat}.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500503 * @param size Size of the pixel buffer in bytes. Must be at least
504 * stride * (height - 1) +
Leon Scroggins III97fea5f2020-01-30 12:18:20 -0500505 * {@link AImageDecoder_getMinimumStride}.
Leon Scroggins IIIbb5ffd22020-02-06 11:45:16 -0500506 * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value
507 * indicating the reason for the failure.
508 *
509 * Errors:
510 * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The image was truncated. A
511 * partial image was decoded, and undecoded lines have been initialized to all
512 * zeroes.
513 * - {@link ANDROID_IMAGE_DECODER_ERROR}: The image contained an error. A
514 * partial image was decoded, and undecoded lines have been initialized to all
515 * zeroes.
516 * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The {@link AImageDecoder} or
517 * |pixels| is null, the stride is not large enough or not pixel aligned, or
518 * |size| is not large enough.
519 * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The asset or file descriptor
520 * failed to seek.
521 * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a
522 * failure to allocate memory.
Leon Scroggins III2f984942019-11-22 17:02:23 -0500523 */
524int AImageDecoder_decodeImage(AImageDecoder* decoder,
525 void* pixels, size_t stride,
526 size_t size) __INTRODUCED_IN(30);
527
Leon Scroggins III2f984942019-11-22 17:02:23 -0500528#ifdef __cplusplus
529}
530#endif
531
532#endif // ANDROID_IMAGE_DECODER_H
533
534/** @} */