• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 /**
18  * @addtogroup Media
19  * @{
20  */
21 
22 /**
23  * @file NdkImage.h
24  */
25 
26 /*
27  * This file defines an NDK API.
28  * Do not remove methods.
29  * Do not change method signatures.
30  * Do not change the value of constants.
31  * Do not change the size of any of the classes defined in here.
32  * Do not reference types that are not part of the NDK.
33  * Do not #include files that aren't part of the NDK.
34  */
35 
36 #ifndef _NDK_IMAGE_H
37 #define _NDK_IMAGE_H
38 
39 #include <sys/cdefs.h>
40 
41 #include "NdkMediaError.h"
42 
43 #if __ANDROID_API__ >= 26
44 #include <android/hardware_buffer.h>
45 #endif /* __ANDROID_API__ >= 26 */
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #if __ANDROID_API__ >= 24
52 
53 /**
54  * AImage is an opaque type that provides access to image generated by {@link AImageReader}.
55  */
56 typedef struct AImage AImage;
57 
58 // Formats not listed here will not be supported by AImageReader
59 enum AIMAGE_FORMATS {
60     /**
61      * 32 bits RGBA format, 8 bits for each of the four channels.
62      *
63      * <p>
64      * Corresponding formats:
65      * <ul>
66      * <li>AHardwareBuffer: AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM</li>
67      * <li>Vulkan: VK_FORMAT_R8G8B8A8_UNORM</li>
68      * <li>OpenGL ES: GL_RGBA8</li>
69      * </ul>
70      * </p>
71      *
72      * @see AImage
73      * @see AImageReader
74      * @see AHardwareBuffer
75      */
76     AIMAGE_FORMAT_RGBA_8888         = 0x1,
77 
78     /**
79      * 32 bits RGBX format, 8 bits for each of the four channels.
80      *
81      * <p>
82      * Corresponding formats:
83      * <ul>
84      * <li>AHardwareBuffer: AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM</li>
85      * <li>Vulkan: VK_FORMAT_R8G8B8A8_UNORM</li>
86      * <li>OpenGL ES: GL_RGBA8</li>
87      * </ul>
88      * </p>
89      *
90      * @see AImage
91      * @see AImageReader
92      * @see AHardwareBuffer
93      */
94     AIMAGE_FORMAT_RGBX_8888         = 0x2,
95 
96     /**
97      * 24 bits RGB format, 8 bits for each of the three channels.
98      *
99      * <p>
100      * Corresponding formats:
101      * <ul>
102      * <li>AHardwareBuffer: AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM</li>
103      * <li>Vulkan: VK_FORMAT_R8G8B8_UNORM</li>
104      * <li>OpenGL ES: GL_RGB8</li>
105      * </ul>
106      * </p>
107      *
108      * @see AImage
109      * @see AImageReader
110      * @see AHardwareBuffer
111      */
112     AIMAGE_FORMAT_RGB_888           = 0x3,
113 
114     /**
115      * 16 bits RGB format, 5 bits for Red channel, 6 bits for Green channel,
116      * and 5 bits for Blue channel.
117      *
118      * <p>
119      * Corresponding formats:
120      * <ul>
121      * <li>AHardwareBuffer: AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM</li>
122      * <li>Vulkan: VK_FORMAT_R5G6B5_UNORM_PACK16</li>
123      * <li>OpenGL ES: GL_RGB565</li>
124      * </ul>
125      * </p>
126      *
127      * @see AImage
128      * @see AImageReader
129      * @see AHardwareBuffer
130      */
131     AIMAGE_FORMAT_RGB_565           = 0x4,
132 
133     /**
134      * 64 bits RGBA format, 16 bits for each of the four channels.
135      *
136      * <p>
137      * Corresponding formats:
138      * <ul>
139      * <li>AHardwareBuffer: AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT</li>
140      * <li>Vulkan: VK_FORMAT_R16G16B16A16_SFLOAT</li>
141      * <li>OpenGL ES: GL_RGBA16F</li>
142      * </ul>
143      * </p>
144      *
145      * @see AImage
146      * @see AImageReader
147      * @see AHardwareBuffer
148      */
149     AIMAGE_FORMAT_RGBA_FP16         = 0x16,
150 
151     /**
152      * Multi-plane Android YUV 420 format.
153      *
154      * <p>This format is a generic YCbCr format, capable of describing any 4:2:0
155      * chroma-subsampled planar or semiplanar buffer (but not fully interleaved),
156      * with 8 bits per color sample.</p>
157      *
158      * <p>Images in this format are always represented by three separate buffers
159      * of data, one for each color plane. Additional information always
160      * accompanies the buffers, describing the row stride and the pixel stride
161      * for each plane.</p>
162      *
163      * <p>The order of planes is guaranteed such that plane #0 is always Y, plane #1 is always
164      * U (Cb), and plane #2 is always V (Cr).</p>
165      *
166      * <p>The Y-plane is guaranteed not to be interleaved with the U/V planes
167      * (in particular, pixel stride is always 1 in {@link AImage_getPlanePixelStride}).</p>
168      *
169      * <p>The U/V planes are guaranteed to have the same row stride and pixel stride, that is, the
170      * return value of {@link AImage_getPlaneRowStride} for the U/V plane are guaranteed to be the
171      * same, and the return value of {@link AImage_getPlanePixelStride} for the U/V plane are also
172      * guaranteed to be the same.</p>
173      *
174      * <p>For example, the {@link AImage} object can provide data
175      * in this format from a {@link ACameraDevice} through an {@link AImageReader} object.</p>
176      *
177      * <p>This format is always supported as an output format for the android Camera2 NDK API.</p>
178      *
179      * @see AImage
180      * @see AImageReader
181      * @see ACameraDevice
182      */
183     AIMAGE_FORMAT_YUV_420_888       = 0x23,
184 
185     /**
186      * Compressed JPEG format.
187      *
188      * <p>This format is always supported as an output format for the android Camera2 NDK API.</p>
189      */
190     AIMAGE_FORMAT_JPEG              = 0x100,
191 
192     /**
193      * 16 bits per pixel raw camera sensor image format, usually representing a single-channel
194      * Bayer-mosaic image.
195      *
196      * <p>The layout of the color mosaic, the maximum and minimum encoding
197      * values of the raw pixel data, the color space of the image, and all other
198      * needed information to interpret a raw sensor image must be queried from
199      * the {@link ACameraDevice} which produced the image.</p>
200      */
201     AIMAGE_FORMAT_RAW16             = 0x20,
202 
203     /**
204      * Private raw camera sensor image format, a single channel image with implementation depedent
205      * pixel layout.
206      *
207      * <p>AIMAGE_FORMAT_RAW_PRIVATE is a format for unprocessed raw image buffers coming from an
208      * image sensor. The actual structure of buffers of this format is implementation-dependent.</p>
209      *
210      */
211     AIMAGE_FORMAT_RAW_PRIVATE       = 0x24,
212 
213     /**
214      * Android 10-bit raw format.
215      *
216      * <p>
217      * This is a single-plane, 10-bit per pixel, densely packed (in each row),
218      * unprocessed format, usually representing raw Bayer-pattern images coming
219      * from an image sensor.
220      * </p>
221      * <p>
222      * In an image buffer with this format, starting from the first pixel of
223      * each row, each 4 consecutive pixels are packed into 5 bytes (40 bits).
224      * Each one of the first 4 bytes contains the top 8 bits of each pixel, The
225      * fifth byte contains the 2 least significant bits of the 4 pixels, the
226      * exact layout data for each 4 consecutive pixels is illustrated below
227      * (Pi[j] stands for the jth bit of the ith pixel):
228      * </p>
229      * <table>
230      * <tr>
231      * <th align="center"></th>
232      * <th align="center">bit 7</th>
233      * <th align="center">bit 6</th>
234      * <th align="center">bit 5</th>
235      * <th align="center">bit 4</th>
236      * <th align="center">bit 3</th>
237      * <th align="center">bit 2</th>
238      * <th align="center">bit 1</th>
239      * <th align="center">bit 0</th>
240      * </tr>
241      * <tr>
242      * <td align="center">Byte 0:</td>
243      * <td align="center">P0[9]</td>
244      * <td align="center">P0[8]</td>
245      * <td align="center">P0[7]</td>
246      * <td align="center">P0[6]</td>
247      * <td align="center">P0[5]</td>
248      * <td align="center">P0[4]</td>
249      * <td align="center">P0[3]</td>
250      * <td align="center">P0[2]</td>
251      * </tr>
252      * <tr>
253      * <td align="center">Byte 1:</td>
254      * <td align="center">P1[9]</td>
255      * <td align="center">P1[8]</td>
256      * <td align="center">P1[7]</td>
257      * <td align="center">P1[6]</td>
258      * <td align="center">P1[5]</td>
259      * <td align="center">P1[4]</td>
260      * <td align="center">P1[3]</td>
261      * <td align="center">P1[2]</td>
262      * </tr>
263      * <tr>
264      * <td align="center">Byte 2:</td>
265      * <td align="center">P2[9]</td>
266      * <td align="center">P2[8]</td>
267      * <td align="center">P2[7]</td>
268      * <td align="center">P2[6]</td>
269      * <td align="center">P2[5]</td>
270      * <td align="center">P2[4]</td>
271      * <td align="center">P2[3]</td>
272      * <td align="center">P2[2]</td>
273      * </tr>
274      * <tr>
275      * <td align="center">Byte 3:</td>
276      * <td align="center">P3[9]</td>
277      * <td align="center">P3[8]</td>
278      * <td align="center">P3[7]</td>
279      * <td align="center">P3[6]</td>
280      * <td align="center">P3[5]</td>
281      * <td align="center">P3[4]</td>
282      * <td align="center">P3[3]</td>
283      * <td align="center">P3[2]</td>
284      * </tr>
285      * <tr>
286      * <td align="center">Byte 4:</td>
287      * <td align="center">P3[1]</td>
288      * <td align="center">P3[0]</td>
289      * <td align="center">P2[1]</td>
290      * <td align="center">P2[0]</td>
291      * <td align="center">P1[1]</td>
292      * <td align="center">P1[0]</td>
293      * <td align="center">P0[1]</td>
294      * <td align="center">P0[0]</td>
295      * </tr>
296      * </table>
297      * <p>
298      * This format assumes
299      * <ul>
300      * <li>a width multiple of 4 pixels</li>
301      * <li>an even height</li>
302      * </ul>
303      * </p>
304      *
305      * <pre>size = row stride * height</pre> where the row stride is in <em>bytes</em>,
306      * not pixels.
307      *
308      * <p>
309      * Since this is a densely packed format, the pixel stride is always 0. The
310      * application must use the pixel data layout defined in above table to
311      * access each row data. When row stride is equal to (width * (10 / 8)), there
312      * will be no padding bytes at the end of each row, the entire image data is
313      * densely packed. When stride is larger than (width * (10 / 8)), padding
314      * bytes will be present at the end of each row.
315      * </p>
316      * <p>
317      * For example, the {@link AImage} object can provide data in this format from a
318      * {@link ACameraDevice} (if supported) through a {@link AImageReader} object.
319      * The number of planes returned by {@link AImage_getNumberOfPlanes} will always be 1.
320      * The pixel stride is undefined ({@link AImage_getPlanePixelStride} will return
321      * {@link AMEDIA_ERROR_UNSUPPORTED}), and the {@link AImage_getPlaneRowStride} described the
322      * vertical neighboring pixel distance (in bytes) between adjacent rows.
323      * </p>
324      *
325      * @see AImage
326      * @see AImageReader
327      * @see ACameraDevice
328      */
329     AIMAGE_FORMAT_RAW10             = 0x25,
330 
331     /**
332      * Android 12-bit raw format.
333      *
334      * <p>
335      * This is a single-plane, 12-bit per pixel, densely packed (in each row),
336      * unprocessed format, usually representing raw Bayer-pattern images coming
337      * from an image sensor.
338      * </p>
339      * <p>
340      * In an image buffer with this format, starting from the first pixel of each
341      * row, each two consecutive pixels are packed into 3 bytes (24 bits). The first
342      * and second byte contains the top 8 bits of first and second pixel. The third
343      * byte contains the 4 least significant bits of the two pixels, the exact layout
344      * data for each two consecutive pixels is illustrated below (Pi[j] stands for
345      * the jth bit of the ith pixel):
346      * </p>
347      * <table>
348      * <tr>
349      * <th align="center"></th>
350      * <th align="center">bit 7</th>
351      * <th align="center">bit 6</th>
352      * <th align="center">bit 5</th>
353      * <th align="center">bit 4</th>
354      * <th align="center">bit 3</th>
355      * <th align="center">bit 2</th>
356      * <th align="center">bit 1</th>
357      * <th align="center">bit 0</th>
358      * </tr>
359      * <tr>
360      * <td align="center">Byte 0:</td>
361      * <td align="center">P0[11]</td>
362      * <td align="center">P0[10]</td>
363      * <td align="center">P0[ 9]</td>
364      * <td align="center">P0[ 8]</td>
365      * <td align="center">P0[ 7]</td>
366      * <td align="center">P0[ 6]</td>
367      * <td align="center">P0[ 5]</td>
368      * <td align="center">P0[ 4]</td>
369      * </tr>
370      * <tr>
371      * <td align="center">Byte 1:</td>
372      * <td align="center">P1[11]</td>
373      * <td align="center">P1[10]</td>
374      * <td align="center">P1[ 9]</td>
375      * <td align="center">P1[ 8]</td>
376      * <td align="center">P1[ 7]</td>
377      * <td align="center">P1[ 6]</td>
378      * <td align="center">P1[ 5]</td>
379      * <td align="center">P1[ 4]</td>
380      * </tr>
381      * <tr>
382      * <td align="center">Byte 2:</td>
383      * <td align="center">P1[ 3]</td>
384      * <td align="center">P1[ 2]</td>
385      * <td align="center">P1[ 1]</td>
386      * <td align="center">P1[ 0]</td>
387      * <td align="center">P0[ 3]</td>
388      * <td align="center">P0[ 2]</td>
389      * <td align="center">P0[ 1]</td>
390      * <td align="center">P0[ 0]</td>
391      * </tr>
392      * </table>
393      * <p>
394      * This format assumes
395      * <ul>
396      * <li>a width multiple of 4 pixels</li>
397      * <li>an even height</li>
398      * </ul>
399      * </p>
400      *
401      * <pre>size = row stride * height</pre> where the row stride is in <em>bytes</em>,
402      * not pixels.
403      *
404      * <p>
405      * Since this is a densely packed format, the pixel stride is always 0. The
406      * application must use the pixel data layout defined in above table to
407      * access each row data. When row stride is equal to (width * (12 / 8)), there
408      * will be no padding bytes at the end of each row, the entire image data is
409      * densely packed. When stride is larger than (width * (12 / 8)), padding
410      * bytes will be present at the end of each row.
411      * </p>
412      * <p>
413      * For example, the {@link AImage} object can provide data in this format from a
414      * {@link ACameraDevice} (if supported) through a {@link AImageReader} object.
415      * The number of planes returned by {@link AImage_getNumberOfPlanes} will always be 1.
416      * The pixel stride is undefined ({@link AImage_getPlanePixelStride} will return
417      * {@link AMEDIA_ERROR_UNSUPPORTED}), and the {@link AImage_getPlaneRowStride} described the
418      * vertical neighboring pixel distance (in bytes) between adjacent rows.
419      * </p>
420      *
421      * @see AImage
422      * @see AImageReader
423      * @see ACameraDevice
424      */
425     AIMAGE_FORMAT_RAW12             = 0x26,
426 
427     /**
428      * Android dense depth image format.
429      *
430      * <p>Each pixel is 16 bits, representing a depth ranging measurement from a depth camera or
431      * similar sensor. The 16-bit sample consists of a confidence value and the actual ranging
432      * measurement.</p>
433      *
434      * <p>The confidence value is an estimate of correctness for this sample.  It is encoded in the
435      * 3 most significant bits of the sample, with a value of 0 representing 100% confidence, a
436      * value of 1 representing 0% confidence, a value of 2 representing 1/7, a value of 3
437      * representing 2/7, and so on.</p>
438      *
439      * <p>As an example, the following sample extracts the range and confidence from the first pixel
440      * of a DEPTH16-format {@link AImage}, and converts the confidence to a floating-point value
441      * between 0 and 1.f inclusive, with 1.f representing maximum confidence:
442      *
443      * <pre>
444      *    uint16_t* data;
445      *    int dataLength;
446      *    AImage_getPlaneData(image, 0, (uint8_t**)&data, &dataLength);
447      *    uint16_t depthSample = data[0];
448      *    uint16_t depthRange = (depthSample & 0x1FFF);
449      *    uint16_t depthConfidence = ((depthSample >> 13) & 0x7);
450      *    float depthPercentage = depthConfidence == 0 ? 1.f : (depthConfidence - 1) / 7.f;
451      * </pre>
452      * </p>
453      *
454      * <p>This format assumes
455      * <ul>
456      * <li>an even width</li>
457      * <li>an even height</li>
458      * <li>a horizontal stride multiple of 16 pixels</li>
459      * </ul>
460      * </p>
461      *
462      * <pre> y_size = stride * height </pre>
463      *
464      * When produced by a camera, the units for the range are millimeters.
465      */
466     AIMAGE_FORMAT_DEPTH16           = 0x44363159,
467 
468     /**
469      * Android sparse depth point cloud format.
470      *
471      * <p>A variable-length list of 3D points plus a confidence value, with each point represented
472      * by four floats; first the X, Y, Z position coordinates, and then the confidence value.</p>
473      *
474      * <p>The number of points is ((size of the buffer in bytes) / 16).
475      *
476      * <p>The coordinate system and units of the position values depend on the source of the point
477      * cloud data. The confidence value is between 0.f and 1.f, inclusive, with 0 representing 0%
478      * confidence and 1.f representing 100% confidence in the measured position values.</p>
479      *
480      * <p>As an example, the following code extracts the first depth point in a DEPTH_POINT_CLOUD
481      * format {@link AImage}:
482      * <pre>
483      *    float* data;
484      *    int dataLength;
485      *    AImage_getPlaneData(image, 0, (uint8_t**)&data, &dataLength);
486      *    float x = data[0];
487      *    float y = data[1];
488      *    float z = data[2];
489      *    float confidence = data[3];
490      * </pre>
491      *
492      */
493     AIMAGE_FORMAT_DEPTH_POINT_CLOUD = 0x101,
494 
495     /**
496      * Android private opaque image format.
497      *
498      * <p>The choices of the actual format and pixel data layout are entirely up to the
499      * device-specific and framework internal implementations, and may vary depending on use cases
500      * even for the same device. Also note that the contents of these buffers are not directly
501      * accessible to the application.</p>
502      *
503      * <p>When an {@link AImage} of this format is obtained from an {@link AImageReader} or
504      * {@link AImage_getNumberOfPlanes()} method will return zero.</p>
505      */
506     AIMAGE_FORMAT_PRIVATE           = 0x22
507 };
508 
509 /**
510  * Data type describing an cropped rectangle returned by {@link AImage_getCropRect}.
511  *
512  * <p>Note that the right and bottom coordinates are exclusive, so the width of the rectangle is
513  * (right - left) and the height of the rectangle is (bottom - top).</p>
514  */
515 typedef struct AImageCropRect {
516     int32_t left;
517     int32_t top;
518     int32_t right;
519     int32_t bottom;
520 } AImageCropRect;
521 
522 /**
523  * Return the image back the the system and delete the AImage object from memory.
524  *
525  * <p>Do NOT use the image pointer after this method returns.
526  * Note that if the parent {@link AImageReader} is closed, all the {@link AImage} objects acquired
527  * from the parent reader will be returned to system. All AImage_* methods except this method will
528  * return {@link AMEDIA_ERROR_INVALID_OBJECT}. Application still needs to call this method on those
529  * {@link AImage} objects to fully delete the {@link AImage} object from memory.</p>
530  *
531  * @param image The {@link AImage} to be deleted.
532  */
533 void AImage_delete(AImage* image);
534 
535 /**
536  * Query the width of the input {@link AImage}.
537  *
538  * @param image the {@link AImage} of interest.
539  * @param width the width of the image will be filled here if the method call succeeeds.
540  *
541  * @return <ul>
542  *         <li>{@link AMEDIA_OK} if the method call succeeds.</li>
543  *         <li>{@link AMEDIA_ERROR_INVALID_PARAMETER} if image or width is NULL.</li>
544  *         <li>{@link AMEDIA_ERROR_INVALID_OBJECT} if the {@link AImageReader} generated this
545  *                 image has been deleted.</li></ul>
546  */
547 media_status_t AImage_getWidth(const AImage* image, /*out*/int32_t* width);
548 
549 /**
550  * Query the height of the input {@link AImage}.
551  *
552  * @param image the {@link AImage} of interest.
553  * @param height the height of the image will be filled here if the method call succeeeds.
554  *
555  * @return <ul>
556  *         <li>{@link AMEDIA_OK} if the method call succeeds.</li>
557  *         <li>{@link AMEDIA_ERROR_INVALID_PARAMETER} if image or height is NULL.</li>
558  *         <li>{@link AMEDIA_ERROR_INVALID_OBJECT} if the {@link AImageReader} generated this
559  *                 image has been deleted.</li></ul>
560  */
561 media_status_t AImage_getHeight(const AImage* image, /*out*/int32_t* height);
562 
563 /**
564  * Query the format of the input {@link AImage}.
565  *
566  * <p>The format value will be one of AIMAGE_FORMAT_* enum value.</p>
567  *
568  * @param image the {@link AImage} of interest.
569  * @param format the format of the image will be filled here if the method call succeeeds.
570  *
571  * @return <ul>
572  *         <li>{@link AMEDIA_OK} if the method call succeeds.</li>
573  *         <li>{@link AMEDIA_ERROR_INVALID_PARAMETER} if image or format is NULL.</li>
574  *         <li>{@link AMEDIA_ERROR_INVALID_OBJECT} if the {@link AImageReader} generated this
575  *                 image has been deleted.</li></ul>
576  */
577 media_status_t AImage_getFormat(const AImage* image, /*out*/int32_t* format);
578 
579 /**
580  * Query the cropped rectangle of the input {@link AImage}.
581  *
582  * <p>The crop rectangle specifies the region of valid pixels in the image, using coordinates in the
583  * largest-resolution plane.</p>
584  *
585  * @param image the {@link AImage} of interest.
586  * @param rect the cropped rectangle of the image will be filled here if the method call succeeeds.
587  *
588  * @return <ul>
589  *         <li>{@link AMEDIA_OK} if the method call succeeds.</li>
590  *         <li>{@link AMEDIA_ERROR_INVALID_PARAMETER} if image or rect is NULL.</li>
591  *         <li>{@link AMEDIA_ERROR_INVALID_OBJECT} if the {@link AImageReader} generated this
592  *                 image has been deleted.</li></ul>
593  */
594 media_status_t AImage_getCropRect(const AImage* image, /*out*/AImageCropRect* rect);
595 
596 /**
597  * Query the timestamp of the input {@link AImage}.
598  *
599  * <p>
600  * The timestamp is measured in nanoseconds, and is normally monotonically increasing. The
601  * timestamps for the images from different sources may have different timebases therefore may not
602  * be comparable. The specific meaning and timebase of the timestamp depend on the source providing
603  * images. For images generated by camera, the timestamp value will match
604  * {@link ACAMERA_SENSOR_TIMESTAMP} of the {@link ACameraMetadata} in
605  * {@link ACameraCaptureSession_captureCallbacks#onCaptureStarted} and
606  * {@link ACameraCaptureSession_captureCallbacks#onCaptureCompleted} callback.
607  * </p>
608  *
609  * @param image the {@link AImage} of interest.
610  * @param timestampNs the timestamp of the image will be filled here if the method call succeeeds.
611  *
612  * @return <ul>
613  *         <li>{@link AMEDIA_OK} if the method call succeeds.</li>
614  *         <li>{@link AMEDIA_ERROR_INVALID_PARAMETER} if image or timestampNs is NULL.</li>
615  *         <li>{@link AMEDIA_ERROR_INVALID_OBJECT} if the {@link AImageReader} generated this
616  *                 image has been deleted.</li></ul>
617  */
618 media_status_t AImage_getTimestamp(const AImage* image, /*out*/int64_t* timestampNs);
619 
620 /**
621  * Query the number of planes of the input {@link AImage}.
622  *
623  * <p>The number of plane of an {@link AImage} is determined by its format, which can be queried by
624  * {@link AImage_getFormat} method.</p>
625  *
626  * @param image the {@link AImage} of interest.
627  * @param numPlanes the number of planes of the image will be filled here if the method call
628  *         succeeeds.
629  *
630  * @return <ul>
631  *         <li>{@link AMEDIA_OK} if the method call succeeds.</li>
632  *         <li>{@link AMEDIA_ERROR_INVALID_PARAMETER} if image or numPlanes is NULL.</li>
633  *         <li>{@link AMEDIA_ERROR_INVALID_OBJECT} if the {@link AImageReader} generated this
634  *                 image has been deleted.</li></ul>
635  */
636 media_status_t AImage_getNumberOfPlanes(const AImage* image, /*out*/int32_t* numPlanes);
637 
638 /**
639  * Query the pixel stride of the input {@link AImage}.
640  *
641  * <p>This is the distance between two consecutive pixel values in a row of pixels. It may be
642  * larger than the size of a single pixel to account for interleaved image data or padded formats.
643  * Note that pixel stride is undefined for some formats such as {@link AIMAGE_FORMAT_RAW_PRIVATE},
644  * and calling this method on images of these formats will cause {@link AMEDIA_ERROR_UNSUPPORTED}
645  * being returned.
646  * For formats where pixel stride is well defined, the pixel stride is always greater than 0.</p>
647  *
648  * @param image the {@link AImage} of interest.
649  * @param planeIdx the index of the plane. Must be less than the number of planes of input image.
650  * @param pixelStride the pixel stride of the image will be filled here if the method call succeeeds.
651  *
652  * @return <ul>
653  *         <li>{@link AMEDIA_OK} if the method call succeeds.</li>
654  *         <li>{@link AMEDIA_ERROR_INVALID_PARAMETER} if image or pixelStride is NULL, or planeIdx
655  *                 is out of the range of [0, numOfPlanes - 1].</li>
656  *         <li>{@link AMEDIA_ERROR_UNSUPPORTED} if pixel stride is undefined for the format of input
657  *                 image.</li>
658  *         <li>{@link AMEDIA_ERROR_INVALID_OBJECT} if the {@link AImageReader} generated this
659  *                 image has been deleted.</li>
660  *         <li>{@link AMEDIA_IMGREADER_CANNOT_LOCK_IMAGE} if the {@link AImage} cannot be locked
661  *                 for CPU access.</li></ul>
662  */
663 media_status_t AImage_getPlanePixelStride(
664         const AImage* image, int planeIdx, /*out*/int32_t* pixelStride);
665 
666 /**
667  * Query the row stride of the input {@link AImage}.
668  *
669  * <p>This is the distance between the start of two consecutive rows of pixels in the image. Note
670  * that row stried is undefined for some formats such as {@link AIMAGE_FORMAT_RAW_PRIVATE}, and
671  * calling this method on images of these formats will cause {@link AMEDIA_ERROR_UNSUPPORTED}
672  * being returned.
673  * For formats where row stride is well defined, the row stride is always greater than 0.</p>
674  *
675  * @param image the {@link AImage} of interest.
676  * @param planeIdx the index of the plane. Must be less than the number of planes of input image.
677  * @param rowStride the row stride of the image will be filled here if the method call succeeeds.
678  *
679  * @return <ul>
680  *         <li>{@link AMEDIA_OK} if the method call succeeds.</li>
681  *         <li>{@link AMEDIA_ERROR_INVALID_PARAMETER} if image or rowStride is NULL, or planeIdx
682  *                 is out of the range of [0, numOfPlanes - 1].</li>
683  *         <li>{@link AMEDIA_ERROR_UNSUPPORTED} if row stride is undefined for the format of input
684  *                 image.</li>
685  *         <li>{@link AMEDIA_ERROR_INVALID_OBJECT} if the {@link AImageReader} generated this
686  *                 image has been deleted.</li>
687  *         <li>{@link AMEDIA_IMGREADER_CANNOT_LOCK_IMAGE} if the {@link AImage} cannot be locked
688  *                 for CPU access.</li></ul>
689  */
690 media_status_t AImage_getPlaneRowStride(
691         const AImage* image, int planeIdx, /*out*/int32_t* rowStride);
692 
693 /**
694  * Get the data pointer of the input image for direct application access.
695  *
696  * <p>Note that once the {@link AImage} or the parent {@link AImageReader} is deleted, the data
697  * pointer from previous AImage_getPlaneData call becomes invalid. Do NOT use it after the
698  * {@link AImage} or the parent {@link AImageReader} is deleted.</p>
699  *
700  * @param image the {@link AImage} of interest.
701  * @param planeIdx the index of the plane. Must be less than the number of planes of input image.
702  * @param data the data pointer of the image will be filled here if the method call succeeeds.
703  * @param dataLength the valid length of data will be filled here if the method call succeeeds.
704  *
705  * @return <ul>
706  *         <li>{@link AMEDIA_OK} if the method call succeeds.</li>
707  *         <li>{@link AMEDIA_ERROR_INVALID_PARAMETER} if image, data or dataLength is NULL, or
708  *                 planeIdx is out of the range of [0, numOfPlanes - 1].</li>
709  *         <li>{@link AMEDIA_ERROR_INVALID_OBJECT} if the {@link AImageReader} generated this
710  *                 image has been deleted.</li>
711  *         <li>{@link AMEDIA_IMGREADER_CANNOT_LOCK_IMAGE} if the {@link AImage} cannot be locked
712  *                 for CPU access.</li></ul>
713  */
714 media_status_t AImage_getPlaneData(
715         const AImage* image, int planeIdx,
716         /*out*/uint8_t** data, /*out*/int* dataLength);
717 
718 #endif /* __ANDROID_API__ >= 24 */
719 
720 #if __ANDROID_API__ >= 26
721 
722 /*
723  * Return the image back the the system and delete the AImage object from memory asynchronously.
724  *
725  * <p>Similar to {@link AImage_delete}, do NOT use the image pointer after this method returns.
726  * However, the caller can still hold on to the {@link AHardwareBuffer} returned from this image and
727  * signal the release of the hardware buffer back to the {@link AImageReader}'s queue using
728  * releaseFenceFd.</p>
729  *
730  * @param image The {@link AImage} to be deleted.
731  * @param releaseFenceFd A sync fence fd defined in {@link sync.h}, which signals the release of
732  *         underlying {@link AHardwareBuffer}.
733  *
734  * @see sync.h
735  */
736 void AImage_deleteAsync(AImage* image, int releaseFenceFd);
737 
738 /**
739  * Get the hardware buffer handle of the input image intended for GPU and/or hardware access.
740  *
741  * <p>Note that no reference on the returned {@link AHardwareBuffer} handle is acquired
742  * automatically. Once the {@link AImage} or the parent {@link AImageReader} is deleted, the
743  * {@link AHardwareBuffer} handle from previous {@link AImage_getHardwareBuffer} becomes
744  * invalid.</p>
745  *
746  * <p>If the caller ever needs to hold on a reference to the {@link AHardwareBuffer} handle after
747  * the {@link AImage} or the parent {@link AImageReader} is deleted, it must call {@link
748  * AHardwareBuffer_acquire} to acquire an extra reference, and call {@link AHardwareBuffer_release}
749  * once it has finished using it in order to properly deallocate the underlying memory managed by
750  * {@link AHardwareBuffer}. If the caller has acquired extra reference on an {@link AHardwareBuffer}
751  * returned from this function, it must also listen to {@link onBufferFreed} callback to be
752  * notified when the buffer is no longer used by {@link AImageReader}.</p>
753  *
754  * @param image the {@link AImage} of interest.
755  * @param outBuffer The memory area pointed to by buffer will contain the acquired AHardwareBuffer
756  *         handle.
757  * @return <ul>
758  *         <li>{@link AMEDIA_OK} if the method call succeeds.</li>
759  *         <li>{@link AMEDIA_ERROR_INVALID_PARAMETER} if image or buffer is NULL</li></ul>
760  *
761  * @see AImageReader_ImageCallback
762  */
763 media_status_t AImage_getHardwareBuffer(const AImage* image, /*out*/AHardwareBuffer** buffer);
764 
765 #endif /* __ANDROID_API__ >= 26 */
766 
767 #ifdef __cplusplus
768 } // extern "C"
769 #endif
770 
771 #endif //_NDK_IMAGE_H
772 
773 /** @} */
774