目录

Scaling Images

With the C APIs provided by the ImageProcessing module, you can enhance the detail of images and scale them. The processed data is suitable for use in display, encoding, and storage.

Typical use cases include: decoding images to obtain image buffers > applying image super-resolution > displaying the results.

Constraints

  1. To ensure real-time response, you are advised to create only one instance at a time.

  2. Only an image that meets the following conditions can be processed:

    • The image is a standard dynamic range (SDR) image.
    • The image pixel format is RGBA, BGRA, NV12, or NV21, and the output format is the same as the input format.
    • The memory type for the PixelMap object to be processed must be the DMA memory.
  3. Four levels of algorithms are provided, each offering better processing outcomes at the expense of increased performance degradation.

    Quality Level

    Input Resolution

    (Unit: Pixel)

    Output Resolution

    (Unit: Pixel)

    Description
    NONE

    Width: [32, 3000]

    Height: [32, 3000]

    Width: [32, 3000]

    Height: [32, 3000]

    Applies only to scaling scenarios. Changing the aspect ratio is supported, but no detail enhancement is provided.
    LOW

    Width: [32, 3000]

    Height: [32, 3000]

    Width: [32, 3000]

    Height: [32, 3000]

    Applies only to scaling scenarios. Changing the aspect ratio is supported.

    During scaling, a basic level of detail enhancement is provided at a high processing speed.

    This quality level is the default setting.

    MEDIUM

    Width: [32, 3000]

    Height: [32, 3000]

    Width: [32, 3000]

    Height: [32, 3000]

    Applies only to scaling scenarios. Changing the aspect ratio is supported.

    During scaling, a moderate level of detail enhancement is provided at a balanced processing speed.

    HIGH

    Width: [512, 2000]

    Height: [512, 2000]

    Width: [512, 2000]

    Height: [512, 2000]

    Applies to scaling and detail enhancement scenarios. Changing the aspect ratio is supported.

    During scaling, a high level of detail enhancement is provided at a relatively low processing speed.

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]How to Develop

  1. Add the header files.

    #include <hilog/log.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 <multimedia/player_framework/native_avformat.h>
    #include <napi/native_api.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. Create a detail enhancement module.

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

    • imageProcessor: detail enhancement module instance.
    • IMAGE_PROCESSING_TYPE_DETAIL_ENHANCER: detail enhancement type.
    • IMAGE_PROCESSING_SUCCESS: expected return value.
    // Create an image detail enhancement module instance.
    OH_ImageProcessing* imageProcessor = nullptr;
    ImageProcessing_ErrorCode ret = OH_ImageProcessing_Create(&imageProcessor, IMAGE_PROCESSING_TYPE_DETAIL_ENHANCER);
  4. (Optional) Configure the detail enhancement quality level, which can be HIGH, MEDIUM, LOW, or NONE. If it is not configured, the LOW level is used by default.

    // Create a format instance.
    OH_AVFormat* parameter = OH_AVFormat_Create();
    // Specify the quality level.
    OH_AVFormat_SetIntValue(parameter, IMAGE_DETAIL_ENHANCER_PARAMETER_KEY_QUALITY_LEVEL,
        IMAGE_DETAIL_ENHANCER_QUALITY_LEVEL_HIGH);
    // Configure parameters.
    ImageProcessing_ErrorCode ret = OH_ImageProcessing_SetParameter(imageProcessor,parameter);
  5. Start detail enhancement.

    // Start detail enhancement.
    ImageProcessing_ErrorCode ret = OH_ImageProcessing_EnhanceDetail(imageProcessor, srcImage, dstImage);
  6. Destroy the image processing instance.

    ImageProcessing_ErrorCode ret = OH_ImageProcessing_Destroy(imageProcessor);
    imageProcessor = nullptr;
  7. Deinitialize the environment.

    OH_ImageProcessing_DeinitializeEnvironment();

Complete Sample Code

ArkTS sample code:

C++ sample code: