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