1/* 2 * Copyright (C) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file Provides the capability of image quality processing. 18 * @kit ImageKit 19 */ 20 21import image from './@ohos.multimedia.image'; 22 23/** 24 * This module provides the capability of content processing for images, including image scaling. 25 * @namespace videoProcessingEngine 26 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 27 * @crossplatform 28 * @form 29 * @since 18 30 */ 31declare namespace videoProcessingEngine { 32 /** 33 * Levels of processing quality for detail enhancement. 34 * @enum {number} 35 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 36 * @crossplatform 37 * @form 38 * @since 18 39 */ 40 enum QualityLevel { 41 /** 42 * No detail enhancement. 43 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 44 * @crossplatform 45 * @form 46 * @since 18 47 */ 48 NONE = 0, 49 /** 50 * A low level of detail enhancement quality but with a fast speed. It's the default level. 51 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 52 * @crossplatform 53 * @form 54 * @since 18 55 */ 56 LOW = 1, 57 /** 58 * A medium level of detail enhancement quality. Its speed is between the low setting and high setting. 59 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 60 * @crossplatform 61 * @form 62 * @since 18 63 */ 64 MEDIUM = 2, 65 /** 66 * A high level of detail enhancement quality but with a relatively slow speed. 67 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 68 * @crossplatform 69 * @form 70 * @since 18 71 */ 72 HIGH = 3 73 } 74 75 /** 76 * Provides the ImageProcessor type, including the processing function. 77 * @typedef ImageProcessor 78 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 79 * @crossplatform 80 * @form 81 * @since 18 82 */ 83 interface ImageProcessor { 84 /** 85 * The function generate the destinationImage from sourceImage with necessary scaling operation 86 * <br>according to width and height. Different levels of scaling methonds are provided to 87 * <br>balance performance and image quality. This method uses a promise to return the result. 88 * @param { image.PixelMap } sourceImage - The source pixelmap. 89 * @param { number } width - The zoom value of width. 90 * @param { number } height - The zoom value of height. 91 * @param { QualityLevel } [level] - The quality level. 92 * @returns { Promise<image.PixelMap> } A Promise instance used to return the PixelMap object. 93 * @throws { BusinessError } 801 - Capability not supported. Function enhanceDetail can not work correctly due to 94 * <br>limited device capabilities. 95 * @throws { BusinessError } 29200007 - Out of memory. 96 * @throws { BusinessError } 29200009 - Input value is invalid. This error is returned for 97 * <br>all of the following error conditions: 98 * <br>1 - Invalid input or output image buffer - The image buffer width(height) 99 * <br>is too large or colorspace is incorrect. 100 * <br>2 - Invalid parameter - The parameter does not contain valid information, 101 * <br>such as detail enhancer level is incorrect. 102 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 103 * @crossplatform 104 * @form 105 * @since 18 106 */ 107 enhanceDetail(sourceImage: image.PixelMap, width: number, height: number, level?: QualityLevel): Promise<image.PixelMap>; 108 109 /** 110 * The function generate the destinationImage from sourceImage with necessary scaling operation 111 * <br>according to width and height. Different levels of scaling methonds are provided to 112 * <br>balance performance and image quality. 113 * @param { image.PixelMap } sourceImage - The source pixelmap. 114 * @param { number } width - The zoom value of width. 115 * @param { number } height - The zoom value of height. 116 * @param { QualityLevel } [level] - The quality level. 117 * @returns { image.PixelMap } Returns the destination pixelmap instance . 118 * <br>if the operation is successful; Otherwise, return undefined. 119 * @throws { BusinessError } 801 - Capability not supported. Function enhanceDetailSync can not work correctly due 120 * <br>to limited device capabilities. 121 * @throws { BusinessError } 29200004 - Failed to process image buffer. For example, the processing times out. 122 * @throws { BusinessError } 29200007 - Out of memory. 123 * @throws { BusinessError } 29200009 - Input value is invalid. This error is returned for 124 * <br>all of the following error conditions: 125 * <br>1 - Invalid input or output image buffer - The image buffer width(height) 126 * <br>is too large or colorspace is incorrect. 127 * <br>2 - Invalid parameter - The parameter does not contain valid information, 128 * <br>such as detail enhancer level is incorrect. 129 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 130 * @crossplatform 131 * @form 132 * @since 18 133 */ 134 enhanceDetailSync(sourceImage: image.PixelMap, width: number, height: number, level?: QualityLevel): image.PixelMap; 135 136 /** 137 * The function generate the destinationImage from sourceImage with necessary scaling operation 138 * <br>according to the zoom ratio. Different levels of scaling methonds are provided to 139 * <br>balance performance and image quality. This method uses a promise to return the result. 140 * @param { image.PixelMap } sourceImage - The source pixelmap. 141 * @param { number } scale - The zoom ratio. 142 * @param { QualityLevel } [level] - The quality level. 143 * @returns { Promise<image.PixelMap> } A Promise instance used to return the PixelMap object. 144 * @throws { BusinessError } 801 - Capability not supported. Function enhanceDetail can not work correctly due to 145 * <br>limited device capabilities. 146 * @throws { BusinessError } 29200007 - Out of memory. 147 * @throws { BusinessError } 29200009 - Input value is invalid. This error is returned for 148 * <br>all of the following error conditions: 149 * <br>1 - Invalid input or output image buffer - The image buffer width(height) 150 * <br>is too large or colorspace is incorrect. 151 * <br>2 - Invalid parameter - The parameter does not contain valid information, 152 * <br>such as detail enhancer level is incorrect. 153 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 154 * @crossplatform 155 * @form 156 * @since 18 157 */ 158 enhanceDetail(sourceImage: image.PixelMap, scale: number, level?: QualityLevel): Promise<image.PixelMap>; 159 160 /** 161 * The function generate the destinationImage from sourceImage with necessary scaling operation 162 * <br>according to the zoom ratio. Different levels of scaling methonds are provided to 163 * <br>balance performance and image quality. 164 * @param { image.PixelMap } sourceImage - The source pixelmap. 165 * @param { number } scale - The zoom ratio. 166 * @param { QualityLevel } [level] - The quality level. 167 * @returns { image.PixelMap } Returns the destination pixelmap instance 168 * <br>if the operation is successful; Otherwise, return undefined. 169 * @throws { BusinessError } 801 - Capability not supported. Function enhanceDetailSync can not work correctly due 170 * <br>to limited device capabilities. 171 * @throws { BusinessError } 29200004 - Failed to process image buffer. For example, the processing times out. 172 * @throws { BusinessError } 29200007 - Out of memory. 173 * @throws { BusinessError } 29200009 - Input value is invalid. This error is returned for 174 * <br>all of the following error conditions: 175 * <br>1 - Invalid input or output image buffer - The image buffer width(height) 176 * <br>is too large or colorspace is incorrect. 177 * <br>2 - Invalid parameter - The parameter does not contain valid information, 178 * <br>such as detail enhancer level is incorrect. 179 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 180 * @crossplatform 181 * @form 182 * @since 18 183 */ 184 enhanceDetailSync(sourceImage: image.PixelMap, scale: number, level?: QualityLevel): image.PixelMap; 185 } 186 187 /** 188 * Initialize global environment for image processing. 189 * @returns { Promise<void> } A Promise instance used to return the operation result. 190 * If the operation fails, an error message is returned. 191 * @throws { BusinessError } 801 - Capability not supported. Function initializeEnvironment can not work correctly 192 * <br>due to limited device capabilities. 193 * @throws { BusinessError } 29200002 - The global environment initialization for image processing failed, 194 * <br>such as failure to initialize the GPU environment. 195 * @throws { BusinessError } 29200006 - The operation is not permitted. This may be caused by incorrect status. 196 * @throws { BusinessError } 29200007 - Out of memory. 197 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 198 * @crossplatform 199 * @form 200 * @since 18 201 */ 202 function initializeEnvironment(): Promise<void>; 203 /** 204 * Deinitialize global environment for image processing. 205 * @returns { Promise<void> } A Promise instance used to return the operation result. 206 * If the operation fails, an error message is returned. 207 * @throws { BusinessError } 29200006 - The operation is not permitted. This may be caused by incorrect status. 208 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 209 * @crossplatform 210 * @form 211 * @since 18 212 */ 213 function deinitializeEnvironment(): Promise<void>; 214 /** 215 * Create an image processing instance. 216 * @returns { ImageProcessor } Returns the ImageProcessor instance if 217 * <br>the operation is successful; returns null otherwise. 218 * @throws { BusinessError } 801 - Capability not supported. Function create can not work correctly due to limited 219 * <br>device capabilities. 220 * @throws { BusinessError } 29200003 - Failed to create image processing instance. For example, 221 * <br>the number of instances exceeds the upper limit. 222 * @throws { BusinessError } 29200007 - Out of memory. 223 * @syscap SystemCapability.Multimedia.VideoProcessingEngine 224 * @crossplatform 225 * @form 226 * @since 18 227 */ 228 function create(): ImageProcessor; 229} 230 231export default videoProcessingEngine; 232