Android 图像格式HAL_PIXEL_FORMAT_* vs ImageFormt.*对应关系
Posted alibli
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 图像格式HAL_PIXEL_FORMAT_* vs ImageFormt.*对应关系相关的知识,希望对你有一定的参考价值。
目录
二、ImageFormat与HAL Pixel Format对应关系
一、常用HAL_PIXEL_FORMAT_*
HAL_PIXEL_FORMAT_*是hal中用到的图像像素格式,对应app侧的ImageFormat.*。定义位置在system/core/include/system/下面的几个文件,最常用的几种格式定义在graphics-base-v1.0.h。如下:
typedef enum
HAL_PIXEL_FORMAT_RGBA_8888 = 1,
HAL_PIXEL_FORMAT_RGBX_8888 = 2,
HAL_PIXEL_FORMAT_RGB_888 = 3,
HAL_PIXEL_FORMAT_RGB_565 = 4,
HAL_PIXEL_FORMAT_BGRA_8888 = 5,
HAL_PIXEL_FORMAT_YCBCR_422_SP = 16,
HAL_PIXEL_FORMAT_YCRCB_420_SP = 17,
HAL_PIXEL_FORMAT_YCBCR_422_I = 20,
HAL_PIXEL_FORMAT_RGBA_FP16 = 22,
HAL_PIXEL_FORMAT_RAW16 = 32,
HAL_PIXEL_FORMAT_BLOB = 33,
HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED = 34,
HAL_PIXEL_FORMAT_YCBCR_420_888 = 35,
HAL_PIXEL_FORMAT_RAW_OPAQUE = 36,
HAL_PIXEL_FORMAT_RAW10 = 37,
HAL_PIXEL_FORMAT_RAW12 = 38,
HAL_PIXEL_FORMAT_RGBA_1010102 = 43,
HAL_PIXEL_FORMAT_Y8 = 538982489,
HAL_PIXEL_FORMAT_Y16 = 540422489,
HAL_PIXEL_FORMAT_YV12 = 842094169,
android_pixel_format_t;
如果遇到其他不常用的格式,搜下同目录下几个文件。
二、ImageFormat与HAL Pixel Format对应关系
对应关系如下:
YUV:
ImageFormat/PixelFormat | Value | HAL Pixel Format | Value |
---|---|---|---|
ImageFormat.YUV_420_888 | 35 (0x00000023) | HAL_PIXEL_FORMAT_YCBCR_420_888 | 35 |
ImageFormat.YV12 | 842094169 (0x32315659) | HAL_PIXEL_FORMAT_YV12 | 842094169 |
ImageFormat.NV21 | 17 (0x00000011) | HAL_PIXEL_FORMAT_YCRCB_420_SP | 17 |
ImageFormat.NV16 | 16 (0x00000010) | HAL_PIXEL_FORMAT_YCBCR_422_SP | 16 |
ImageFormat.YUY2 | 20 (0x00000014) | HAL_PIXEL_FORMAT_YCBCR_422_I | 20 |
ImageFormat.Y8 | 538982489 (0x20203859) | HAL_PIXEL_FORMAT_Y8 | 538982489 |
ImageFormat.YCBCR_P010 | 54 (0x00000036) | HAL_PIXEL_FORMAT_YCBCR_P010 | 54 |
RGB:
ImageFormat/PixelFormat | Value | HAL Pixel Format | Value |
---|---|---|---|
PixelFormat.RGBA_8888 | 1 (0x00000001) | HAL_PIXEL_FORMAT_RGBA_8888 | 1 |
PixelFormat.RGBX_8888 | 2 (0x00000002) | HAL_PIXEL_FORMAT_RGBX_8888 | 2 |
PixelFormat.RGB_888 | 3 (0x00000003) | HAL_PIXEL_FORMAT_RGB_888 | 3 |
PixelFormat.RGB_565 | 4 (0x00000004) | HAL_PIXEL_FORMAT_RGB_565 | 4 |
Not Supported | NA | HAL_PIXEL_FORMAT_BGRA_8888 | 5 |
PixelFormat.RGBA_F16 | 22 (0x00000016) | HAL_PIXEL_FORMAT_RGBA_FP16 | 22 |
PixelFormat.RGBA_1010102 | 43 (0x0000002b) | HAL_PIXEL_FORMAT_RGBA_1010102 | 43 |
JPEG、DEPTH、RAW等:
ImageFormat/PixelFormat | Value | HAL Pixel Format | Value |
---|---|---|---|
ImageFormat.JPEG | 256 (0x00000100) | HAL_PIXEL_FORMAT_BLOB | 33 |
ImageFormat.DEPTH_POINT_CLOUD | 257 (0x00000101) | HAL_PIXEL_FORMAT_BLOB | 33 |
ImageFormat.DEPTH_JPEG | 1768253795 (0x69656963) | HAL_PIXEL_FORMAT_BLOB | 33 |
ImageFormat.HEIC | 1212500294 (0x48454946) | HAL_PIXEL_FORMAT_BLOB | 33 |
ImageFormat.DEPTH16 | 1144402265 (0x44363159) | HAL_PIXEL_FORMAT_Y16 | 540422489 |
ImageFormat.RAW_DEPTH | 4098(0x1002) | HAL_PIXEL_FORMAT_RAW16 | 32 |
ImageFormat.RAW_SENSOR | 32 (0x00000020) | HAL_PIXEL_FORMAT_RAW16 | 32 |
ImageFormat.RAW_PRIVATE | 36 (0x00000024) | HAL_PIXEL_FORMAT_RAW_OPAQUE | 36 |
ImageFormat.RAW10 | 37 (0x00000025) | HAL_PIXEL_FORMAT_RAW10 | 37 |
ImageFormat.RAW12 | 38 (0x00000026) | HAL_PIXEL_FORMAT_RAW12 | 38 |
ImageFormat.PRIVATE | 34 (0x00000022) | HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED | 34 |
Data Space
可以看出,同一个HAL pixel format可能对应几种image format,如何确定是哪种?用Data Space:
ImageFormat | Data Space | Stream Configuration Metadata |
---|---|---|
JPEG | HAL_DATASPACE_V0_JFIF | SCALER_AVAILABLE_STREAM_CONFIGURATIONS |
DEPTH_POINT_CLOUD DEPTH16 RAW_DEPTH | HAL_DATASPACE_DEPTH | DEPTH_AVAILABLE_DEPTH _STREAM_CONFIGURATIONS |
DEPTH_JPEG | HAL_DATASPACE_DYNAMIC_DEPTH | DEPTH_AVAILABLE_DYNAMIC _DEPTH_STREAM_CONFIGURATIONS |
HEIC | HAL_DATASPACE_HEIF | HEIC_AVAILABLE_HEIC_STREAM_CONFIGURATIONS |
Others | HAL_DATASPACE_UNKNOWN | SCALER_AVAILABLE_STREAM_CONFIGURATIONS |
三、具体图像格式内存分布
优秀博客:Android中的图像格式_android_如浴春风_InfoQ写作社区
参考:
第9讲 StreamConfigurationMap详解一 - Android Camera2 API|极客笔记 (deepinout.com)
以上是关于Android 图像格式HAL_PIXEL_FORMAT_* vs ImageFormt.*对应关系的主要内容,如果未能解决你的问题,请参考以下文章
Android Camera2 ImageReader 图像格式 YUV
如何在 android 中以 html 格式的电子邮件发送图像?