Devices running Android 10 support the HEIC compressed image format, a high efficiency video encoding (HEVC) specific brand of the high efficiency image file format (HEIF) as specified in ISO/IEC 23008-12. HEIC-encoded images offer better image quality with smaller file sizes as compared to JPEG files.
HEIC images are generated by the camera framework requesting an uncompressed image from the camera HAL and sending it to the media subsystem to be encoded by an HEIC or HEVC encoder.
Requirements
To support the HEIC image format, your device must have a hardware encoder
supporting
MIMETYPE_IMAGE_ANDROID_HEIC
or
MIMETYPE_VIDEO_HEVC
with the
constant quality mode.
Implementation
To support the HEIC image format on your device, implement an HEIC/HEVC codec
and provide support for the required stream configurations, which are the
IMPLEMENTATION_DEFINED/YUV streams and JPEG app segment streams.
Media
Implement the HEIC/HEVC codec in constant quality (CQ) mode for the corresponding hardware as follows:
- The HEVC type codec consumes either the
IMPLEMENTATION_DEFINEDformat with theGRALLOC_USAGE_HW_VIDEO_ENCODERusage or theHAL_PIXEL_FORMAT_YCBCR_420_888format depending on the image size. - The HEIC type codec consumes the
IMPLEMENTATION_DEFINEDformat with theGRALLOC_USAGE_HW_IMAGE_ENCODERusage.
Camera
In the static metadata, set ANDROID_HEIC_INFO_SUPPORTED to true, and
ANDROID_HEIC_INFO_MAX_JPEG_APP_SEGMENTS_COUNT to a value between [1, 16],
indicating the number of JPEG app segments.
For each mandatory stream combination, your camera device must support swapping a JPEG stream with a HEIC stream of the same size.
For an HEIC output stream at the public API, the camera service creates two HAL internal streams:
- A BLOB stream with the
JPEG_APPS_SEGMENTusage flag to store app segments including EXIF and thumbnail segments - An
IMPLEMENTATION_DEFINEDorYCBCR_420_888stream the size of the HEIC stream depending on the target codec and HEIC stream size
Based on ANDROID_HEIC_INFO_MAX_JPEG_APP_SEGMENTS_COUNT, the camera framework
allocates buffers large enough for the camera HAL to populate the JPEG app
segments. The APP1 segment is required but segments following the APP1
segment (APP2 and above) are optional. The camera framework overrides the EXIF
tags in the APP1 segment that can be derived from the capture result metadata
or are related to the main image bitstream and sends them to MediaMuxer.
Because the media encoder embeds the orientation in the metadata of output
images, to ensure a consistent orientation between the main image and thumbnail,
the camera HAL must not rotate the thumbnail image based on
android.jpeg.orientation. The framework writes the orientation into the EXIF
metadata and HEIC container.
The static, control, and dynamic metadata tags related to the JPEG format also
apply to the HEIC format. For example, the android.jpeg.orientation and
android.jpeg.quality metadata tags in the capture request are used to control
the orientation and quality of HEIC images.
To use the HEIC format in an app, use the HEIC public API.
For more information, see the following sources.
Camera HAL
Graphic buffer data space
Graphic buffer usage space
Validation
To validate that your implementation supports HEIC images, use the
TestingCamera2
test app and run the following camera CTS and VTS tests.
Camera CTS tests
NativeImageReaderTest#testHeicImageReaderTest#testHeicImageReaderTest#testRepeatingHeicReprocessCaptureTest#testBasicYuvToHeicReprocessingReprocessCaptureTest#testBasicOpaqueToHeicReprocessingRobustnessTest#testMandatoryOutputCombinationsStillCaptureTest#testHeicExif
Camera VTS tests