目录

Dynamic Metadata Generation for Images

With the C APIs provided by the ImageProcessing module, you can generate dynamic metadata for HDR images.

A typical usage scenario is image editing, as shown in the figure below.

Specifications

Supported data input formats

Input ColorSpaceName Input HdrMetadataType Input PIXEL_FORMAT
BT2020_PQ_LIMIT / BT2020_PQ HDR_METADATA_TYPE_ALTERNATE PIXEL_FORMAT_YCBCR_P010 / PIXEL_FORMAT_YCRCB_P010 / PIXEL_FORMAT_RGBA_1010102
BT2020_HLG_LIMIT / BT2020_HLG HDR_METADATA_TYPE_ALTERNATE PIXEL_FORMAT_YCBCR_P010 / PIXEL_FORMAT_YCRCB_P010 / PIXEL_FORMAT_RGBA_1010102
BT2020_PQ_LIMIT / BT2020_PQ HDR_METADATA_TYPE_BASE PIXEL_FORMAT_YCBCR_P010 / PIXEL_FORMAT_YCRCB_P010 / PIXEL_FORMAT_RGBA_1010102
BT2020_HLG_LIMIT / BT2020_HLG HDR_METADATA_TYPE_BASE PIXEL_FORMAT_YCBCR_P010 / PIXEL_FORMAT_YCRCB_P010 / PIXEL_FORMAT_RGBA_1010102
BT2020_PQ_LIMIT / BT2020_PQ HDR_METADATA_TYPE_NONE PIXEL_FORMAT_YCBCR_P010 / PIXEL_FORMAT_YCRCB_P010 / PIXEL_FORMAT_RGBA_1010102
BT2020_HLG_LIMIT / BT2020_HLG HDR_METADATA_TYPE_NONE PIXEL_FORMAT_YCBCR_P010 / PIXEL_FORMAT_YCRCB_P010 / PIXEL_FORMAT_RGBA_1010102

Supported resolution specifications

Minimum Resolution (Unit: Pixel) Maximum Resolution (Unit: Pixel)
32*32 8880*8880

Memory specifications:

The memory type for the PixelMap object to be processed must be the DMA memory.

Development Guidelines

For details, see sample code.

[h2]Linking the Dynamic Libraries in the CMake Script

add_library(entry SHARED napi_init.cpp ImageProcessing/ImageProcessing.cpp)
target_link_libraries(entry PUBLIC ${BASE_LIBRARY})

[h2]Procedure on the ArkTS Side

  1. Obtain a 10-bit PixelMap from the decoder.

    const photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
    photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;
    photoSelectOptions.maxSelectNumber = 1;
    const photoViewPicker = new photoAccessHelper.PhotoViewPicker();
    photoViewPicker.select(photoSelectOptions)
      .then((photoSelectResult: photoAccessHelper.PhotoSelectResult) => {
        let fd = fileIo.openSync(photoSelectResult.photoUris[0], fileIo.OpenMode.READ_ONLY);
        const imageSource = image.createImageSource(fd.fd);
        let option: image.DecodingOptions = {};
        option.index = 0;
        option.desiredDynamicRange = image.DecodingDynamicRange.AUTO;
        this.pixelMapSrc = imageSource.createPixelMapSync(option);
        this.getColorSpace();
        this.hasPhoto = true;
      })
  2. Configure the color framework and metadata.

    let colorSpaceBT2020_HLG : colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceManager.ColorSpace.BT2020_HLG);
    hdrpixelMap.setColorSpace(colorSpaceBT2020_HLG);
    hdrpixelMap.setMetadata(image.HdrMetadataKey.HDR_METADATA_TYPE, image.HdrMetadataType.ALTERNATE);

[h2]Procedure on the Native Side

  1. Add the header files.

    #include <multimedia/image_framework/image_mdk_common.h>
    #include <multimedia/image_framework/image_pixel_map_mdk.h>
    #include <multimedia/image_framework/image/pixelmap_native.h>
    #include <multimedia/video_processing_engine/image_processing.h>
    #include <multimedia/video_processing_engine/image_processing_types.h>
    #include <native_color_space_manager/native_color_space_manager.h>
  2. (Optional) Initialize the environment.

    This is usually executed on the initial use within a process to preemptively handle certain time-consuming operations.

    ImageProcessing_ErrorCode ret =  OH_ImageProcessing_InitializeEnvironment();
  3. (Optional) Check for capability support. Perform this operation before using the corresponding capability.

    // Input format.
    ImageProcessing_ColorSpaceInfo SRC_INFO;
    SRC_INFO.colorSpace = BT2020_HLG;
    SRC_INFO.metadataType = HDR_METADATA_TYPE_ALTERNATE;
    SRC_INFO.pixelFormat = PIXEL_FORMAT_RGBA_1010102;
    // Capability query.
    bool flag = OH_ImageProcessing_IsMetadataGenerationSupported(&SRC_INFO);
  4. Convert the ArkTS PixelMap to a C++ PixelMap.

    OH_PixelmapNative* hdr = nullptr;
    OH_PixelmapNative_ConvertPixelmapNativeFromNapi(env, argValue[0], &hdr);
  5. Create an image metadata generation module.

  6. The application may create such a module by using the image processing engine. In the code snippet below, the following variables are used:

    instance: image processing module instance.

    IMAGE_PROCESSING_TYPE_METADATA_GENERATION: image metadata generation type.

    IMAGE_PROCESSING_SUCCESS: expected return value.

    OH_ImageProcessing* instance = nullptr;
    ret = OH_ImageProcessing_Create(&instance, IMAGE_PROCESSING_TYPE_METADATA_GENERATION);
  7. Execute the algorithm.

    ret = OH_ImageProcessing_GenerateMetadata(instance, hdr);
  8. Destroy the image processing instance.

    ret = OH_ImageProcessing_Destroy(instance);
    instance = nullptr;
  9. Deinitialize the environment.

    ret = OH_ImageProcessing_DeinitializeEnvironment();

Complete Sample Code

ArkTS sample code:

C++ sample code: