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.
To ensure real-time response, you are advised to create only one instance at a time.
Only an image that meets the following conditions can be processed:
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. |
add_library(entry SHARED napi_init.cpp ImageProcessing/ImageProcessing.cpp)
target_link_libraries(entry PUBLIC ${BASE_LIBRARY}) 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>
(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();
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:
// Create an image detail enhancement module instance. OH_ImageProcessing* imageProcessor = nullptr; ImageProcessing_ErrorCode ret = OH_ImageProcessing_Create(&imageProcessor, IMAGE_PROCESSING_TYPE_DETAIL_ENHANCER);
(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); Start detail enhancement.
// Start detail enhancement. ImageProcessing_ErrorCode ret = OH_ImageProcessing_EnhanceDetail(imageProcessor, srcImage, dstImage);
Destroy the image processing instance.
ImageProcessing_ErrorCode ret = OH_ImageProcessing_Destroy(imageProcessor); imageProcessor = nullptr;
Deinitialize the environment.
OH_ImageProcessing_DeinitializeEnvironment();