1/* 2 * Copyright (C) 2010 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 17package android.graphics; 18 19public class ImageFormat { 20 /* 21 * these constants are chosen to be binary compatible with their previous 22 * location in PixelFormat.java 23 */ 24 25 public static final int UNKNOWN = 0; 26 27 /** 28 * RGB format used for pictures encoded as RGB_565. See 29 * {@link android.hardware.Camera.Parameters#setPictureFormat(int)}. 30 */ 31 public static final int RGB_565 = 4; 32 33 /** 34 * <p>Android YUV format.</p> 35 * 36 * <p>This format is exposed to software decoders and applications.</p> 37 * 38 * <p>YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed 39 * by (W/2) x (H/2) Cr and Cb planes.</p> 40 * 41 * <p>This format assumes 42 * <ul> 43 * <li>an even width</li> 44 * <li>an even height</li> 45 * <li>a horizontal stride multiple of 16 pixels</li> 46 * <li>a vertical stride equal to the height</li> 47 * </ul> 48 * </p> 49 * 50 * <pre> y_size = stride * height 51 * c_stride = ALIGN(stride/2, 16) 52 * c_size = c_stride * height/2 53 * size = y_size + c_size * 2 54 * cr_offset = y_size 55 * cb_offset = y_size + c_size</pre> 56 * 57 * <p>For the {@link android.hardware.camera2} API, the {@link #YUV_420_888} format is 58 * recommended for YUV output instead.</p> 59 * 60 * <p>For the older camera API, this format is guaranteed to be supported for 61 * {@link android.hardware.Camera} preview images since API level 12; for earlier API versions, 62 * check {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}. 63 * 64 * <p>Note that for camera preview callback use (see 65 * {@link android.hardware.Camera#setPreviewCallback}), the 66 * <var>stride</var> value is the smallest possible; that is, it is equal 67 * to: 68 * 69 * <pre>stride = ALIGN(width, 16)</pre> 70 * 71 * @see android.hardware.Camera.Parameters#setPreviewCallback 72 * @see android.hardware.Camera.Parameters#setPreviewFormat 73 * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats 74 * </p> 75 */ 76 public static final int YV12 = 0x32315659; 77 78 /** 79 * <p>Android Y8 format.</p> 80 * 81 * <p>Y8 is a YUV planar format comprised of a WxH Y plane only, with each pixel 82 * being represented by 8 bits. It is equivalent to just the Y plane from {@link #YV12} 83 * format.</p> 84 * 85 * <p>This format assumes 86 * <ul> 87 * <li>an even width</li> 88 * <li>an even height</li> 89 * <li>a horizontal stride multiple of 16 pixels</li> 90 * </ul> 91 * </p> 92 * 93 * <pre> y_size = stride * height </pre> 94 * 95 * <p>For example, the {@link android.media.Image} object can provide data 96 * in this format from a {@link android.hardware.camera2.CameraDevice} 97 * through a {@link android.media.ImageReader} object if this format is 98 * supported by {@link android.hardware.camera2.CameraDevice}.</p> 99 * 100 * @see android.media.Image 101 * @see android.media.ImageReader 102 * @see android.hardware.camera2.CameraDevice 103 * 104 * @hide 105 */ 106 public static final int Y8 = 0x20203859; 107 108 /** 109 * <p>Android Y16 format.</p> 110 * 111 * Y16 is a YUV planar format comprised of a WxH Y plane, with each pixel 112 * being represented by 16 bits. It is just like {@link #Y8}, but has 16 113 * bits per pixel (little endian).</p> 114 * 115 * <p>This format assumes 116 * <ul> 117 * <li>an even width</li> 118 * <li>an even height</li> 119 * <li>a horizontal stride multiple of 16 pixels</li> 120 * </ul> 121 * </p> 122 * 123 * <pre> y_size = stride * height </pre> 124 * 125 * <p>For example, the {@link android.media.Image} object can provide data 126 * in this format from a {@link android.hardware.camera2.CameraDevice} 127 * through a {@link android.media.ImageReader} object if this format is 128 * supported by {@link android.hardware.camera2.CameraDevice}.</p> 129 * 130 * @see android.media.Image 131 * @see android.media.ImageReader 132 * @see android.hardware.camera2.CameraDevice 133 * 134 * @hide 135 */ 136 public static final int Y16 = 0x20363159; 137 138 /** 139 * YCbCr format, used for video. 140 * 141 * <p>For the {@link android.hardware.camera2} API, the {@link #YUV_420_888} format is 142 * recommended for YUV output instead.</p> 143 * 144 * <p>Whether this format is supported by the old camera API can be determined by 145 * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.</p> 146 * 147 */ 148 public static final int NV16 = 0x10; 149 150 /** 151 * YCrCb format used for images, which uses the NV21 encoding format. 152 * 153 * <p>This is the default format 154 * for {@link android.hardware.Camera} preview images, when not otherwise set with 155 * {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}.</p> 156 * 157 * <p>For the {@link android.hardware.camera2} API, the {@link #YUV_420_888} format is 158 * recommended for YUV output instead.</p> 159 */ 160 public static final int NV21 = 0x11; 161 162 /** 163 * YCbCr format used for images, which uses YUYV (YUY2) encoding format. 164 * 165 * <p>For the {@link android.hardware.camera2} API, the {@link #YUV_420_888} format is 166 * recommended for YUV output instead.</p> 167 * 168 * <p>This is an alternative format for {@link android.hardware.Camera} preview images. Whether 169 * this format is supported by the camera hardware can be determined by 170 * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.</p> 171 */ 172 public static final int YUY2 = 0x14; 173 174 /** 175 * Compressed JPEG format. 176 * 177 * <p>This format is always supported as an output format for the 178 * {@link android.hardware.camera2} API, and as a picture format for the older 179 * {@link android.hardware.Camera} API</p> 180 */ 181 public static final int JPEG = 0x100; 182 183 /** 184 * <p>Multi-plane Android YUV 420 format</p> 185 * 186 * <p>This format is a generic YCbCr format, capable of describing any 4:2:0 187 * chroma-subsampled planar or semiplanar buffer (but not fully interleaved), 188 * with 8 bits per color sample.</p> 189 * 190 * <p>Images in this format are always represented by three separate buffers 191 * of data, one for each color plane. Additional information always 192 * accompanies the buffers, describing the row stride and the pixel stride 193 * for each plane.</p> 194 * 195 * <p>The order of planes in the array returned by 196 * {@link android.media.Image#getPlanes() Image#getPlanes()} is guaranteed such that 197 * plane #0 is always Y, plane #1 is always U (Cb), and plane #2 is always V (Cr).</p> 198 * 199 * <p>The Y-plane is guaranteed not to be interleaved with the U/V planes 200 * (in particular, pixel stride is always 1 in 201 * {@link android.media.Image.Plane#getPixelStride() yPlane.getPixelStride()}).</p> 202 * 203 * <p>The U/V planes are guaranteed to have the same row stride and pixel stride 204 * (in particular, 205 * {@link android.media.Image.Plane#getRowStride() uPlane.getRowStride()} 206 * == {@link android.media.Image.Plane#getRowStride() vPlane.getRowStride()} and 207 * {@link android.media.Image.Plane#getPixelStride() uPlane.getPixelStride()} 208 * == {@link android.media.Image.Plane#getPixelStride() vPlane.getPixelStride()}; 209 * ).</p> 210 * 211 * <p>For example, the {@link android.media.Image} object can provide data 212 * in this format from a {@link android.hardware.camera2.CameraDevice} 213 * through a {@link android.media.ImageReader} object.</p> 214 * 215 * @see android.media.Image 216 * @see android.media.ImageReader 217 * @see android.hardware.camera2.CameraDevice 218 */ 219 public static final int YUV_420_888 = 0x23; 220 221 /** 222 * <p>Multi-plane Android YUV 422 format</p> 223 * 224 * <p>This format is a generic YCbCr format, capable of describing any 4:2:2 225 * chroma-subsampled (planar, semiplanar or interleaved) format, 226 * with 8 bits per color sample.</p> 227 * 228 * <p>Images in this format are always represented by three separate buffers 229 * of data, one for each color plane. Additional information always 230 * accompanies the buffers, describing the row stride and the pixel stride 231 * for each plane.</p> 232 * 233 * <p>The order of planes in the array returned by 234 * {@link android.media.Image#getPlanes() Image#getPlanes()} is guaranteed such that 235 * plane #0 is always Y, plane #1 is always U (Cb), and plane #2 is always V (Cr).</p> 236 * 237 * <p>In contrast to the {@link #YUV_420_888} format, the Y-plane may have a pixel 238 * stride greater than 1 in 239 * {@link android.media.Image.Plane#getPixelStride() yPlane.getPixelStride()}.</p> 240 * 241 * <p>The U/V planes are guaranteed to have the same row stride and pixel stride 242 * (in particular, 243 * {@link android.media.Image.Plane#getRowStride() uPlane.getRowStride()} 244 * == {@link android.media.Image.Plane#getRowStride() vPlane.getRowStride()} and 245 * {@link android.media.Image.Plane#getPixelStride() uPlane.getPixelStride()} 246 * == {@link android.media.Image.Plane#getPixelStride() vPlane.getPixelStride()}; 247 * ).</p> 248 * 249 * <p>For example, the {@link android.media.Image} object can provide data 250 * in this format from a {@link android.media.MediaCodec} 251 * through {@link android.media.MediaCodec#getOutputImage} object.</p> 252 * 253 * @see android.media.Image 254 * @see android.media.MediaCodec 255 */ 256 public static final int YUV_422_888 = 0x27; 257 258 /** 259 * <p>Multi-plane Android YUV 444 format</p> 260 * 261 * <p>This format is a generic YCbCr format, capable of describing any 4:4:4 262 * (planar, semiplanar or interleaved) format, 263 * with 8 bits per color sample.</p> 264 * 265 * <p>Images in this format are always represented by three separate buffers 266 * of data, one for each color plane. Additional information always 267 * accompanies the buffers, describing the row stride and the pixel stride 268 * for each plane.</p> 269 * 270 * <p>The order of planes in the array returned by 271 * {@link android.media.Image#getPlanes() Image#getPlanes()} is guaranteed such that 272 * plane #0 is always Y, plane #1 is always U (Cb), and plane #2 is always V (Cr).</p> 273 * 274 * <p>In contrast to the {@link #YUV_420_888} format, the Y-plane may have a pixel 275 * stride greater than 1 in 276 * {@link android.media.Image.Plane#getPixelStride() yPlane.getPixelStride()}.</p> 277 * 278 * <p>The U/V planes are guaranteed to have the same row stride and pixel stride 279 * (in particular, 280 * {@link android.media.Image.Plane#getRowStride() uPlane.getRowStride()} 281 * == {@link android.media.Image.Plane#getRowStride() vPlane.getRowStride()} and 282 * {@link android.media.Image.Plane#getPixelStride() uPlane.getPixelStride()} 283 * == {@link android.media.Image.Plane#getPixelStride() vPlane.getPixelStride()}; 284 * ).</p> 285 * 286 * <p>For example, the {@link android.media.Image} object can provide data 287 * in this format from a {@link android.media.MediaCodec} 288 * through {@link android.media.MediaCodec#getOutputImage} object.</p> 289 * 290 * @see android.media.Image 291 * @see android.media.MediaCodec 292 */ 293 public static final int YUV_444_888 = 0x28; 294 295 /** 296 * <p>Multi-plane Android RGB format</p> 297 * 298 * <p>This format is a generic RGB format, capable of describing most RGB formats, 299 * with 8 bits per color sample.</p> 300 * 301 * <p>Images in this format are always represented by three separate buffers 302 * of data, one for each color plane. Additional information always 303 * accompanies the buffers, describing the row stride and the pixel stride 304 * for each plane.</p> 305 * 306 * <p>The order of planes in the array returned by 307 * {@link android.media.Image#getPlanes() Image#getPlanes()} is guaranteed such that 308 * plane #0 is always R (red), plane #1 is always G (green), and plane #2 is always B 309 * (blue).</p> 310 * 311 * <p>All three planes are guaranteed to have the same row strides and pixel strides.</p> 312 * 313 * <p>For example, the {@link android.media.Image} object can provide data 314 * in this format from a {@link android.media.MediaCodec} 315 * through {@link android.media.MediaCodec#getOutputImage} object.</p> 316 * 317 * @see android.media.Image 318 * @see android.media.MediaCodec 319 */ 320 public static final int FLEX_RGB_888 = 0x29; 321 322 /** 323 * <p>Multi-plane Android RGBA format</p> 324 * 325 * <p>This format is a generic RGBA format, capable of describing most RGBA formats, 326 * with 8 bits per color sample.</p> 327 * 328 * <p>Images in this format are always represented by four separate buffers 329 * of data, one for each color plane. Additional information always 330 * accompanies the buffers, describing the row stride and the pixel stride 331 * for each plane.</p> 332 * 333 * <p>The order of planes in the array returned by 334 * {@link android.media.Image#getPlanes() Image#getPlanes()} is guaranteed such that 335 * plane #0 is always R (red), plane #1 is always G (green), plane #2 is always B (blue), 336 * and plane #3 is always A (alpha). This format may represent pre-multiplied or 337 * non-premultiplied alpha.</p> 338 * 339 * <p>All four planes are guaranteed to have the same row strides and pixel strides.</p> 340 * 341 * <p>For example, the {@link android.media.Image} object can provide data 342 * in this format from a {@link android.media.MediaCodec} 343 * through {@link android.media.MediaCodec#getOutputImage} object.</p> 344 * 345 * @see android.media.Image 346 * @see android.media.MediaCodec 347 */ 348 public static final int FLEX_RGBA_8888 = 0x2A; 349 350 /** 351 * <p>General raw camera sensor image format, usually representing a 352 * single-channel Bayer-mosaic image. Each pixel color sample is stored with 353 * 16 bits of precision.</p> 354 * 355 * <p>The layout of the color mosaic, the maximum and minimum encoding 356 * values of the raw pixel data, the color space of the image, and all other 357 * needed information to interpret a raw sensor image must be queried from 358 * the {@link android.hardware.camera2.CameraDevice} which produced the 359 * image.</p> 360 */ 361 public static final int RAW_SENSOR = 0x20; 362 363 /** 364 * <p> 365 * Android 10-bit raw format 366 * </p> 367 * <p> 368 * This is a single-plane, 10-bit per pixel, densely packed (in each row), 369 * unprocessed format, usually representing raw Bayer-pattern images coming 370 * from an image sensor. 371 * </p> 372 * <p> 373 * In an image buffer with this format, starting from the first pixel of 374 * each row, each 4 consecutive pixels are packed into 5 bytes (40 bits). 375 * Each one of the first 4 bytes contains the top 8 bits of each pixel, The 376 * fifth byte contains the 2 least significant bits of the 4 pixels, the 377 * exact layout data for each 4 consecutive pixels is illustrated below 378 * ({@code Pi[j]} stands for the jth bit of the ith pixel): 379 * </p> 380 * <table> 381 * <thead> 382 * <tr> 383 * <th align="center"></th> 384 * <th align="center">bit 7</th> 385 * <th align="center">bit 6</th> 386 * <th align="center">bit 5</th> 387 * <th align="center">bit 4</th> 388 * <th align="center">bit 3</th> 389 * <th align="center">bit 2</th> 390 * <th align="center">bit 1</th> 391 * <th align="center">bit 0</th> 392 * </tr> 393 * </thead> <tbody> 394 * <tr> 395 * <td align="center">Byte 0:</td> 396 * <td align="center">P0[9]</td> 397 * <td align="center">P0[8]</td> 398 * <td align="center">P0[7]</td> 399 * <td align="center">P0[6]</td> 400 * <td align="center">P0[5]</td> 401 * <td align="center">P0[4]</td> 402 * <td align="center">P0[3]</td> 403 * <td align="center">P0[2]</td> 404 * </tr> 405 * <tr> 406 * <td align="center">Byte 1:</td> 407 * <td align="center">P1[9]</td> 408 * <td align="center">P1[8]</td> 409 * <td align="center">P1[7]</td> 410 * <td align="center">P1[6]</td> 411 * <td align="center">P1[5]</td> 412 * <td align="center">P1[4]</td> 413 * <td align="center">P1[3]</td> 414 * <td align="center">P1[2]</td> 415 * </tr> 416 * <tr> 417 * <td align="center">Byte 2:</td> 418 * <td align="center">P2[9]</td> 419 * <td align="center">P2[8]</td> 420 * <td align="center">P2[7]</td> 421 * <td align="center">P2[6]</td> 422 * <td align="center">P2[5]</td> 423 * <td align="center">P2[4]</td> 424 * <td align="center">P2[3]</td> 425 * <td align="center">P2[2]</td> 426 * </tr> 427 * <tr> 428 * <td align="center">Byte 3:</td> 429 * <td align="center">P3[9]</td> 430 * <td align="center">P3[8]</td> 431 * <td align="center">P3[7]</td> 432 * <td align="center">P3[6]</td> 433 * <td align="center">P3[5]</td> 434 * <td align="center">P3[4]</td> 435 * <td align="center">P3[3]</td> 436 * <td align="center">P3[2]</td> 437 * </tr> 438 * <tr> 439 * <td align="center">Byte 4:</td> 440 * <td align="center">P3[1]</td> 441 * <td align="center">P3[0]</td> 442 * <td align="center">P2[1]</td> 443 * <td align="center">P2[0]</td> 444 * <td align="center">P1[1]</td> 445 * <td align="center">P1[0]</td> 446 * <td align="center">P0[1]</td> 447 * <td align="center">P0[0]</td> 448 * </tr> 449 * </tbody> 450 * </table> 451 * <p> 452 * This format assumes 453 * <ul> 454 * <li>a width multiple of 4 pixels</li> 455 * <li>an even height</li> 456 * </ul> 457 * </p> 458 * 459 * <pre>size = row stride * height</pre> where the row stride is in <em>bytes</em>, 460 * not pixels. 461 * 462 * <p> 463 * Since this is a densely packed format, the pixel stride is always 0. The 464 * application must use the pixel data layout defined in above table to 465 * access each row data. When row stride is equal to {@code width * (10 / 8)}, there 466 * will be no padding bytes at the end of each row, the entire image data is 467 * densely packed. When stride is larger than {@code width * (10 / 8)}, padding 468 * bytes will be present at the end of each row. 469 * </p> 470 * <p> 471 * For example, the {@link android.media.Image} object can provide data in 472 * this format from a {@link android.hardware.camera2.CameraDevice} (if 473 * supported) through a {@link android.media.ImageReader} object. The 474 * {@link android.media.Image#getPlanes() Image#getPlanes()} will return a 475 * single plane containing the pixel data. The pixel stride is always 0 in 476 * {@link android.media.Image.Plane#getPixelStride()}, and the 477 * {@link android.media.Image.Plane#getRowStride()} describes the vertical 478 * neighboring pixel distance (in bytes) between adjacent rows. 479 * </p> 480 * 481 * @see android.media.Image 482 * @see android.media.ImageReader 483 * @see android.hardware.camera2.CameraDevice 484 */ 485 public static final int RAW10 = 0x25; 486 487 /** 488 * <p> 489 * Android 12-bit raw format 490 * </p> 491 * <p> 492 * This is a single-plane, 12-bit per pixel, densely packed (in each row), 493 * unprocessed format, usually representing raw Bayer-pattern images coming 494 * from an image sensor. 495 * </p> 496 * <p> 497 * In an image buffer with this format, starting from the first pixel of each 498 * row, each two consecutive pixels are packed into 3 bytes (24 bits). The first 499 * and second byte contains the top 8 bits of first and second pixel. The third 500 * byte contains the 4 least significant bits of the two pixels, the exact layout 501 * data for each two consecutive pixels is illustrated below (Pi[j] stands for 502 * the jth bit of the ith pixel): 503 * </p> 504 * <table> 505 * <thead> 506 * <tr> 507 * <th align="center"></th> 508 * <th align="center">bit 7</th> 509 * <th align="center">bit 6</th> 510 * <th align="center">bit 5</th> 511 * <th align="center">bit 4</th> 512 * <th align="center">bit 3</th> 513 * <th align="center">bit 2</th> 514 * <th align="center">bit 1</th> 515 * <th align="center">bit 0</th> 516 * </tr> 517 * </thead> <tbody> 518 * <tr> 519 * <td align="center">Byte 0:</td> 520 * <td align="center">P0[11]</td> 521 * <td align="center">P0[10]</td> 522 * <td align="center">P0[ 9]</td> 523 * <td align="center">P0[ 8]</td> 524 * <td align="center">P0[ 7]</td> 525 * <td align="center">P0[ 6]</td> 526 * <td align="center">P0[ 5]</td> 527 * <td align="center">P0[ 4]</td> 528 * </tr> 529 * <tr> 530 * <td align="center">Byte 1:</td> 531 * <td align="center">P1[11]</td> 532 * <td align="center">P1[10]</td> 533 * <td align="center">P1[ 9]</td> 534 * <td align="center">P1[ 8]</td> 535 * <td align="center">P1[ 7]</td> 536 * <td align="center">P1[ 6]</td> 537 * <td align="center">P1[ 5]</td> 538 * <td align="center">P1[ 4]</td> 539 * </tr> 540 * <tr> 541 * <td align="center">Byte 2:</td> 542 * <td align="center">P1[ 3]</td> 543 * <td align="center">P1[ 2]</td> 544 * <td align="center">P1[ 1]</td> 545 * <td align="center">P1[ 0]</td> 546 * <td align="center">P0[ 3]</td> 547 * <td align="center">P0[ 2]</td> 548 * <td align="center">P0[ 1]</td> 549 * <td align="center">P0[ 0]</td> 550 * </tr> 551 * </tbody> 552 * </table> 553 * <p> 554 * This format assumes 555 * <ul> 556 * <li>a width multiple of 4 pixels</li> 557 * <li>an even height</li> 558 * </ul> 559 * </p> 560 * 561 * <pre>size = row stride * height</pre> where the row stride is in <em>bytes</em>, 562 * not pixels. 563 * 564 * <p> 565 * Since this is a densely packed format, the pixel stride is always 0. The 566 * application must use the pixel data layout defined in above table to 567 * access each row data. When row stride is equal to {@code width * (12 / 8)}, there 568 * will be no padding bytes at the end of each row, the entire image data is 569 * densely packed. When stride is larger than {@code width * (12 / 8)}, padding 570 * bytes will be present at the end of each row. 571 * </p> 572 * <p> 573 * For example, the {@link android.media.Image} object can provide data in 574 * this format from a {@link android.hardware.camera2.CameraDevice} (if 575 * supported) through a {@link android.media.ImageReader} object. The 576 * {@link android.media.Image#getPlanes() Image#getPlanes()} will return a 577 * single plane containing the pixel data. The pixel stride is always 0 in 578 * {@link android.media.Image.Plane#getPixelStride()}, and the 579 * {@link android.media.Image.Plane#getRowStride()} describes the vertical 580 * neighboring pixel distance (in bytes) between adjacent rows. 581 * </p> 582 * 583 * @see android.media.Image 584 * @see android.media.ImageReader 585 * @see android.hardware.camera2.CameraDevice 586 */ 587 public static final int RAW12 = 0x26; 588 589 /** 590 * <p>Android dense depth image format.</p> 591 * 592 * <p>Each pixel is 16 bits, representing a depth ranging measurement from a depth camera or 593 * similar sensor. The 16-bit sample consists of a confidence value and the actual ranging 594 * measurement.</p> 595 * 596 * <p>The confidence value is an estimate of correctness for this sample. It is encoded in the 597 * 3 most significant bits of the sample, with a value of 0 representing 100% confidence, a 598 * value of 1 representing 0% confidence, a value of 2 representing 1/7, a value of 3 599 * representing 2/7, and so on.</p> 600 * 601 * <p>As an example, the following sample extracts the range and confidence from the first pixel 602 * of a DEPTH16-format {@link android.media.Image}, and converts the confidence to a 603 * floating-point value between 0 and 1.f inclusive, with 1.f representing maximum confidence: 604 * 605 * <pre> 606 * ShortBuffer shortDepthBuffer = img.getPlanes()[0].getBuffer().asShortBuffer(); 607 * short depthSample = shortDepthBuffer.get() 608 * short depthRange = (short) (depthSample & 0x1FFF); 609 * short depthConfidence = (short) ((depthSample >> 13) & 0x7); 610 * float depthPercentage = depthConfidence == 0 ? 1.f : (depthConfidence - 1) / 7.f; 611 * </pre> 612 * </p> 613 * 614 * <p>This format assumes 615 * <ul> 616 * <li>an even width</li> 617 * <li>an even height</li> 618 * <li>a horizontal stride multiple of 16 pixels</li> 619 * </ul> 620 * </p> 621 * 622 * <pre> y_size = stride * height </pre> 623 * 624 * When produced by a camera, the units for the range are millimeters. 625 */ 626 public static final int DEPTH16 = 0x44363159; 627 628 /** 629 * Android sparse depth point cloud format. 630 * 631 * <p>A variable-length list of 3D points plus a confidence value, with each point represented 632 * by four floats; first the X, Y, Z position coordinates, and then the confidence value.</p> 633 * 634 * <p>The number of points is {@code (size of the buffer in bytes) / 16}. 635 * 636 * <p>The coordinate system and units of the position values depend on the source of the point 637 * cloud data. The confidence value is between 0.f and 1.f, inclusive, with 0 representing 0% 638 * confidence and 1.f representing 100% confidence in the measured position values.</p> 639 * 640 * <p>As an example, the following code extracts the first depth point in a DEPTH_POINT_CLOUD 641 * format {@link android.media.Image}: 642 * <pre> 643 * FloatBuffer floatDepthBuffer = img.getPlanes()[0].getBuffer().asFloatBuffer(); 644 * float x = floatDepthBuffer.get(); 645 * float y = floatDepthBuffer.get(); 646 * float z = floatDepthBuffer.get(); 647 * float confidence = floatDepthBuffer.get(); 648 * </pre> 649 * 650 */ 651 public static final int DEPTH_POINT_CLOUD = 0x101; 652 653 /** 654 * Android private opaque image format. 655 * <p> 656 * The choices of the actual format and pixel data layout are entirely up to 657 * the device-specific and framework internal implementations, and may vary 658 * depending on use cases even for the same device. The buffers of this 659 * format can be produced by components like 660 * {@link android.media.ImageWriter ImageWriter} , and interpreted correctly 661 * by consumers like {@link android.hardware.camera2.CameraDevice 662 * CameraDevice} based on the device/framework private information. However, 663 * these buffers are not directly accessible to the application. 664 * </p> 665 * <p> 666 * When an {@link android.media.Image Image} of this format is obtained from 667 * an {@link android.media.ImageReader ImageReader} or 668 * {@link android.media.ImageWriter ImageWriter}, the 669 * {@link android.media.Image#getPlanes() getPlanes()} method will return an 670 * empty {@link android.media.Image.Plane Plane} array. 671 * </p> 672 * <p> 673 * If a buffer of this format is to be used as an OpenGL ES texture, the 674 * framework will assume that sampling the texture will always return an 675 * alpha value of 1.0 (i.e. the buffer contains only opaque pixel values). 676 * </p> 677 */ 678 public static final int PRIVATE = 0x22; 679 680 /** 681 * Use this function to retrieve the number of bits per pixel of an 682 * ImageFormat. 683 * 684 * @param format 685 * @return the number of bits per pixel of the given format or -1 if the 686 * format doesn't exist or is not supported. 687 */ 688 public static int getBitsPerPixel(int format) { 689 switch (format) { 690 case RGB_565: 691 return 16; 692 case NV16: 693 return 16; 694 case YUY2: 695 return 16; 696 case YV12: 697 return 12; 698 case Y8: 699 return 8; 700 case Y16: 701 case DEPTH16: 702 return 16; 703 case NV21: 704 return 12; 705 case YUV_420_888: 706 return 12; 707 case YUV_422_888: 708 return 16; 709 case YUV_444_888: 710 return 24; 711 case FLEX_RGB_888: 712 return 24; 713 case FLEX_RGBA_8888: 714 return 32; 715 case RAW_SENSOR: 716 return 16; 717 case RAW10: 718 return 10; 719 case RAW12: 720 return 12; 721 } 722 return -1; 723 } 724 725 /** 726 * Determine whether or not this is a public-visible {@code format}. 727 * 728 * <p>In particular, {@code @hide} formats will return {@code false}.</p> 729 * 730 * <p>Any other formats (including UNKNOWN) will return {@code false}.</p> 731 * 732 * @param format an integer format 733 * @return a boolean 734 * 735 * @hide 736 */ 737 public static boolean isPublicFormat(int format) { 738 switch (format) { 739 case RGB_565: 740 case NV16: 741 case YUY2: 742 case YV12: 743 case JPEG: 744 case NV21: 745 case YUV_420_888: 746 case YUV_422_888: 747 case YUV_444_888: 748 case FLEX_RGB_888: 749 case FLEX_RGBA_8888: 750 case RAW_SENSOR: 751 case RAW10: 752 case RAW12: 753 case DEPTH16: 754 case DEPTH_POINT_CLOUD: 755 case PRIVATE: 756 return true; 757 } 758 759 return false; 760 } 761} 762