1 /* 2 * Copyright (c) 2024 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 * @addtogroup ImageEffect 18 * @{ 19 * 20 * @brief Provides APIs for obtaining and using a image filter. 21 * 22 * @since 12 23 */ 24 25 /** 26 * @file image_effect_filter.h 27 * 28 * @brief Declares the functions for setting filter parameters, registering custom filter and filter lookup information. 29 * 30 * @library libimage_effect.so 31 * @syscap SystemCapability.Multimedia.ImageEffect.Core 32 * @since 12 33 */ 34 35 #ifndef NATIVE_IMAGE_EFFECT_FILTER_H 36 #define NATIVE_IMAGE_EFFECT_FILTER_H 37 38 #include <stdint.h> 39 #include "image_effect_errors.h" 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 typedef struct OH_PixelmapNative OH_PixelmapNative; 46 47 /** 48 * @brief Define the new type name OH_EffectFilter for struct OH_EffectFilter 49 * 50 * @syscap SystemCapability.Multimedia.ImageEffect.Core 51 * @since 12 52 */ 53 typedef struct OH_EffectFilter OH_EffectFilter; 54 55 /** 56 * @brief Define the brightness filter name that contain the parameter matched with the key refer to 57 * {@link OH_EFFECT_FILTER_INTENSITY_KEY} and the value refer to {@link ImageEffect_Any} that contain the data type of 58 * {@link EFFECT_DATA_TYPE_FLOAT} 59 * 60 * @syscap SystemCapability.Multimedia.ImageEffect.Core 61 * @since 12 62 */ 63 #define OH_EFFECT_BRIGHTNESS_FILTER "Brightness" 64 65 /** 66 * @brief Define the contrast filter name that contain the parameter matched with the key refer to 67 * {@link OH_EFFECT_FILTER_INTENSITY_KEY} and the value refer to {@link ImageEffect_Any} that contain the data type of 68 * {@link EFFECT_DATA_TYPE_FLOAT} 69 * 70 * @syscap SystemCapability.Multimedia.ImageEffect.Core 71 * @since 12 72 */ 73 #define OH_EFFECT_CONTRAST_FILTER "Contrast" 74 75 /** 76 * @brief Define the crop filter name that contain the parameter matched with the key refer to 77 * {@link OH_EFFECT_FILTER_REGION_KEY} and the value refer to {@link ImageEffect_Any} that contain the data type of 78 * {@link EFFECT_DATA_TYPE_PTR} for @{link ImageEffect_Region} 79 * 80 * @syscap SystemCapability.Multimedia.ImageEffect.Core 81 * @since 12 82 */ 83 #define OH_EFFECT_CROP_FILTER "Crop" 84 85 /** 86 * @brief Define the key that means intensity 87 * 88 * @syscap SystemCapability.Multimedia.ImageEffect.Core 89 * @since 12 90 */ 91 #define OH_EFFECT_FILTER_INTENSITY_KEY "FilterIntensity" 92 93 /** 94 * @brief Define the key that means region and matches the value ref to {@link ImageEffect_Any} contain the data type of 95 * {@link EFFECT_DATA_TYPE_PTR} for @{link ImageEffect_Region} 96 * 97 * @syscap SystemCapability.Multimedia.ImageEffect.Core 98 * @since 12 99 */ 100 #define OH_EFFECT_FILTER_REGION_KEY "FilterRegion" 101 102 /** 103 * @brief Enumerates the data type 104 * 105 * @syscap SystemCapability.Multimedia.ImageEffect.Core 106 * @since 12 107 */ 108 typedef enum ImageEffect_DataType { 109 /** unknown data type */ 110 EFFECT_DATA_TYPE_UNKNOWN = 0, 111 /** int32_t data type */ 112 EFFECT_DATA_TYPE_INT32 = 1, 113 /** float data type */ 114 EFFECT_DATA_TYPE_FLOAT = 2, 115 /** double data type */ 116 EFFECT_DATA_TYPE_DOUBLE = 3, 117 /** char data type */ 118 EFFECT_DATA_TYPE_CHAR = 4, 119 /** long data type */ 120 EFFECT_DATA_TYPE_LONG = 5, 121 /** bool data type */ 122 EFFECT_DATA_TYPE_BOOL = 6, 123 /** point data type */ 124 EFFECT_DATA_TYPE_PTR = 7, 125 } ImageEffect_DataType; 126 127 /** 128 * @brief Data value for the union 129 * 130 * @syscap SystemCapability.Multimedia.ImageEffect.Core 131 * @since 12 132 */ 133 typedef union ImageEffect_DataValue { 134 /** Parameter of 32-bit integer value matches with {@link EFFECT_DATA_TYPE_INT32} */ 135 int32_t int32Value; 136 /** Parameter of float value matches with {@link EFFECT_DATA_TYPE_FLOAT} */ 137 float floatValue; 138 /** Parameter of double value matches with {@link EFFECT_DATA_TYPE_DOUBLE} */ 139 double doubleValue; 140 /** Parameter of character value matches with {@link EFFECT_DATA_TYPE_CHAR} */ 141 char charValue; 142 /** Parameter of long integer value matches with {@link EFFECT_DATA_TYPE_LONG} */ 143 long longValue; 144 /** Parameter of bool value matches with {@link EFFECT_DATA_TYPE_BOOL} */ 145 bool boolValue; 146 /** Parameter of point value matches with {@link EFFECT_DATA_TYPE_PTR} */ 147 void *ptrValue; 148 } ImageEffect_DataValue; 149 150 /** 151 * @brief Data parameter struct information 152 * 153 * @syscap SystemCapability.Multimedia.ImageEffect.Core 154 * @since 12 155 */ 156 typedef struct ImageEffect_Any { 157 /** Effect any data type */ 158 ImageEffect_DataType dataType = ImageEffect_DataType::EFFECT_DATA_TYPE_UNKNOWN; 159 /** Effect any data value */ 160 ImageEffect_DataValue dataValue = { 0 }; 161 } ImageEffect_Any; 162 163 /** 164 * @brief Enumerates the pixel format type 165 * 166 * @syscap SystemCapability.Multimedia.ImageEffect.Core 167 * @since 12 168 */ 169 typedef enum ImageEffect_Format { 170 /** Unknown pixel format */ 171 EFFECT_PIXEL_FORMAT_UNKNOWN = 0, 172 /** RGBA8888 pixel format */ 173 EFFECT_PIXEL_FORMAT_RGBA8888 = 1, 174 /** NV21 pixel format */ 175 EFFECT_PIXEL_FORMAT_NV21 = 2, 176 /** NV12 pixel format */ 177 EFFECT_PIXEL_FORMAT_NV12 = 3, 178 /** RGBA 10bit pixel format */ 179 EFFECT_PIXEL_FORMAT_RGBA1010102 = 4, 180 /** YCBCR420 semi-planar 10bit pixel format */ 181 EFFECT_PIXEL_FORMAT_YCBCR_P010 = 5, 182 /** YCRCB420 semi-planar 10bit pixel format */ 183 EFFECT_PIXEL_FORMAT_YCRCB_P010 = 6, 184 } ImageEffect_Format; 185 186 /** 187 * @brief Enumerates the effect buffer type 188 * 189 * @syscap SystemCapability.Multimedia.ImageEffect.Core 190 * @since 12 191 */ 192 typedef enum ImageEffect_BufferType { 193 /** Unknown buffer type */ 194 EFFECT_BUFFER_TYPE_UNKNOWN = 0, 195 /** Pixel buffer type */ 196 EFFECT_BUFFER_TYPE_PIXEL = 1, 197 /** Texture buffer type */ 198 EFFECT_BUFFER_TYPE_TEXTURE = 2, 199 } ImageEffect_BufferType; 200 201 /** 202 * @brief Define the new type name OH_EffectFilterInfo for struct OH_EffectFilterInfo 203 * 204 * @syscap SystemCapability.Multimedia.ImageEffect.Core 205 * @since 12 206 */ 207 typedef struct OH_EffectFilterInfo OH_EffectFilterInfo; 208 209 /** 210 * @brief Create an OH_EffectFilterInfo instance. It should be noted that the life cycle of the OH_EffectFilterInfo 211 * instance pointed to by the return value * needs to be manually released by {@link OH_EffectFilterInfo_Release} 212 * 213 * @syscap SystemCapability.Multimedia.ImageEffect.Core 214 * @return Returns a pointer to an OH_EffectFilterInfo instance if the execution is successful, otherwise returns 215 * nullptr 216 * @since 12 217 */ 218 OH_EffectFilterInfo *OH_EffectFilterInfo_Create(); 219 220 /** 221 * @brief Set the filter name for OH_EffectFilterInfo structure 222 * 223 * @syscap SystemCapability.Multimedia.ImageEffect.Core 224 * @param info Encapsulate OH_EffectFilterInfo structure instance pointer 225 * @param name Indicates the filter name 226 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 227 * {@link ImageEffect_ErrorCode} 228 * @since 12 229 */ 230 ImageEffect_ErrorCode OH_EffectFilterInfo_SetFilterName(OH_EffectFilterInfo *info, const char *name); 231 232 /** 233 * @brief Get the filter name from OH_EffectFilterInfo structure 234 * 235 * @syscap SystemCapability.Multimedia.ImageEffect.Core 236 * @param info Encapsulate OH_EffectFilterInfo structure instance pointer 237 * @param name Indicates the filter name 238 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 239 * {@link ImageEffect_ErrorCode} 240 * @since 12 241 */ 242 ImageEffect_ErrorCode OH_EffectFilterInfo_GetFilterName(OH_EffectFilterInfo *info, char **name); 243 244 /** 245 * @brief Set the supported buffer types for OH_EffectFilterInfo structure 246 * 247 * @syscap SystemCapability.Multimedia.ImageEffect.Core 248 * @param info Encapsulate OH_EffectFilterInfo structure instance pointer 249 * @param size The size of {@link ImageEffect_BufferType} that can be supported 250 * @param bufferTypeArray Array of {@link ImageEffect_BufferType} that can be supported 251 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 252 * {@link ImageEffect_ErrorCode} 253 * @since 12 254 */ 255 ImageEffect_ErrorCode OH_EffectFilterInfo_SetSupportedBufferTypes(OH_EffectFilterInfo *info, uint32_t size, 256 ImageEffect_BufferType *bufferTypeArray); 257 258 /** 259 * @brief Get the supported buffer types from OH_EffectFilterInfo structure 260 * 261 * @syscap SystemCapability.Multimedia.ImageEffect.Core 262 * @param info Encapsulate OH_EffectFilterInfo structure instance pointer 263 * @param size The size of {@link OH_EffectBufferInfoType} that can be supported 264 * @param bufferTypeArray Array of {@link OH_EffectBufferInfoType} that can be supported 265 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 266 * {@link ImageEffect_ErrorCode} 267 * @since 12 268 */ 269 ImageEffect_ErrorCode OH_EffectFilterInfo_GetSupportedBufferTypes(OH_EffectFilterInfo *info, uint32_t *size, 270 ImageEffect_BufferType **bufferTypeArray); 271 272 /** 273 * @brief Set the supported formats for OH_EffectFilterInfo structure 274 * 275 * @syscap SystemCapability.Multimedia.ImageEffect.Core 276 * @param info Encapsulate OH_EffectFilterInfo structure instance pointer 277 * @param size The size of {@link ImageEffect_Format} that can be supported 278 * @param formatArray Array of {@link ImageEffect_Format} that can be supported 279 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 280 * {@link ImageEffect_ErrorCode} 281 * @since 12 282 */ 283 ImageEffect_ErrorCode OH_EffectFilterInfo_SetSupportedFormats(OH_EffectFilterInfo *info, uint32_t size, 284 ImageEffect_Format *formatArray); 285 286 /** 287 * @brief Get the supported formats from OH_EffectFilterInfo structure 288 * 289 * @syscap SystemCapability.Multimedia.ImageEffect.Core 290 * @param info Encapsulate OH_EffectFilterInfo structure instance pointer 291 * @param size The size of {@link ImageEffect_Format} that can be supported 292 * @param formatArray Array of {@link ImageEffect_Format} that can be supported 293 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 294 * {@link ImageEffect_ErrorCode} 295 * @since 12 296 */ 297 ImageEffect_ErrorCode OH_EffectFilterInfo_GetSupportedFormats(OH_EffectFilterInfo *info, uint32_t *size, 298 ImageEffect_Format **formatArray); 299 300 /** 301 * @brief Clear the internal resources of the OH_EffectFilterInfo and destroy the OH_EffectFilterInfo instance 302 * 303 * @syscap SystemCapability.Multimedia.ImageEffect.Core 304 * @param info Encapsulate OH_EffectFilterInfo structure instance pointer 305 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 306 * {@link ImageEffect_ErrorCode} 307 * @since 12 308 */ 309 ImageEffect_ErrorCode OH_EffectFilterInfo_Release(OH_EffectFilterInfo *info); 310 311 /** 312 * @brief EffectFilter names information 313 * 314 * @syscap SystemCapability.Multimedia.ImageEffect.Core 315 * @since 12 316 */ 317 typedef struct ImageEffect_FilterNames { 318 /** EffectFilter names array size */ 319 uint32_t size = 0; 320 /** EffectFilter names memory block */ 321 const char **nameList = nullptr; 322 } ImageEffect_FilterNames; 323 324 /** 325 * @brief Define the new type name OH_EffectBufferInfo for struct OH_EffectBufferInfo 326 * 327 * @syscap SystemCapability.Multimedia.ImageEffect.Core 328 * @since 12 329 */ 330 typedef struct OH_EffectBufferInfo OH_EffectBufferInfo; 331 332 /** 333 * @brief Create an OH_EffectBufferInfo instance. It should be noted that the life cycle of the OH_EffectBufferInfo 334 * instance pointed to by the return value * needs to be manually released by {@link OH_EffectBufferInfo_Release} 335 * 336 * @syscap SystemCapability.Multimedia.ImageEffect.Core 337 * @return Returns a pointer to an OH_EffectBufferInfo instance if the execution is successful, otherwise returns 338 * nullptr 339 * @since 12 340 */ 341 OH_EffectBufferInfo *OH_EffectBufferInfo_Create(); 342 343 /** 344 * @brief Set access to the address of the image in memory 345 * 346 * @syscap SystemCapability.Multimedia.ImageEffect.Core 347 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 348 * @param addr Indicates the address of the image in memory 349 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 350 * {@link ImageEffect_ErrorCode} 351 * @since 12 352 */ 353 ImageEffect_ErrorCode OH_EffectBufferInfo_SetAddr(OH_EffectBufferInfo *info, void *addr); 354 355 /** 356 * @brief Provide direct access to the address of the image in memory for rendering the filter effects 357 * 358 * @syscap SystemCapability.Multimedia.ImageEffect.Core 359 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 360 * @param addr Indicates the address of the image in memory 361 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 362 * {@link ImageEffect_ErrorCode} 363 * @since 12 364 */ 365 ImageEffect_ErrorCode OH_EffectBufferInfo_GetAddr(OH_EffectBufferInfo *info, void **addr); 366 367 /** 368 * @brief Set the width of the image in pixels 369 * 370 * @syscap SystemCapability.Multimedia.ImageEffect.Core 371 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 372 * @param width Indicates the width of the image 373 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 374 * {@link ImageEffect_ErrorCode} 375 * @since 12 376 */ 377 ImageEffect_ErrorCode OH_EffectBufferInfo_SetWidth(OH_EffectBufferInfo *info, int32_t width); 378 379 /** 380 * @brief Get the width of the image in pixels 381 * 382 * @syscap SystemCapability.Multimedia.ImageEffect.Core 383 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 384 * @param width Indicates the width of the image 385 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 386 * {@link ImageEffect_ErrorCode} 387 * @since 12 388 */ 389 ImageEffect_ErrorCode OH_EffectBufferInfo_GetWidth(OH_EffectBufferInfo *info, int32_t *width); 390 391 /** 392 * @brief Set the height of the image in pixels 393 * 394 * @syscap SystemCapability.Multimedia.ImageEffect.Core 395 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 396 * @param height Indicates the height of the image 397 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 398 * {@link ImageEffect_ErrorCode} 399 * @since 12 400 */ 401 ImageEffect_ErrorCode OH_EffectBufferInfo_SetHeight(OH_EffectBufferInfo *info, int32_t height); 402 403 /** 404 * @brief Get the height of the image in pixels 405 * 406 * @syscap SystemCapability.Multimedia.ImageEffect.Core 407 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 408 * @param height Indicates the height of the image 409 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 410 * {@link ImageEffect_ErrorCode} 411 * @since 12 412 */ 413 ImageEffect_ErrorCode OH_EffectBufferInfo_GetHeight(OH_EffectBufferInfo *info, int32_t *height); 414 415 /** 416 * @brief Set number of bytes per row for the image 417 * 418 * @syscap SystemCapability.Multimedia.ImageEffect.Core 419 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 420 * @param rowSize Indicates number of bytes per row 421 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 422 * {@link ImageEffect_ErrorCode} 423 * @since 12 424 */ 425 ImageEffect_ErrorCode OH_EffectBufferInfo_SetRowSize(OH_EffectBufferInfo *info, int32_t rowSize); 426 427 /** 428 * @brief Get number of bytes per row for the image 429 * 430 * @syscap SystemCapability.Multimedia.ImageEffect.Core 431 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 432 * @param rowSize Indicates number of bytes per row 433 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 434 * {@link ImageEffect_ErrorCode} 435 * @since 12 436 */ 437 ImageEffect_ErrorCode OH_EffectBufferInfo_GetRowSize(OH_EffectBufferInfo *info, int32_t *rowSize); 438 439 /** 440 * @brief Set the format of the image for OH_EffectBufferInfo 441 * 442 * @syscap SystemCapability.Multimedia.ImageEffect.Core 443 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 444 * @param format Indicates {@link ImageEffect_Format} of the image 445 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 446 * {@link ImageEffect_ErrorCode} 447 * @since 12 448 */ 449 ImageEffect_ErrorCode OH_EffectBufferInfo_SetEffectFormat(OH_EffectBufferInfo *info, ImageEffect_Format format); 450 451 /** 452 * @brief Get the format of the image from OH_EffectBufferInfo 453 * 454 * @syscap SystemCapability.Multimedia.ImageEffect.Core 455 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 456 * @param format Indicates {@link ImageEffect_Format} of the image 457 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 458 * {@link ImageEffect_ErrorCode} 459 * @since 12 460 */ 461 ImageEffect_ErrorCode OH_EffectBufferInfo_GetEffectFormat(OH_EffectBufferInfo *info, ImageEffect_Format *format); 462 463 /** 464 * @brief Set the timestamp of the image for OH_EffectBufferInfo 465 * 466 * @syscap SystemCapability.Multimedia.ImageEffect.Core 467 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 468 * @param timestamp Indicates the timestamp of the image frame data for the OHNativeWindow input type. 469 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 470 * {@link ImageEffect_ErrorCode} 471 * {@link EFFECT_ERROR_PARAM_INVALID}, the input parameter is a null pointer. 472 * @since 12 473 */ 474 ImageEffect_ErrorCode OH_EffectBufferInfo_SetTimestamp(OH_EffectBufferInfo *info, int64_t timestamp); 475 476 /** 477 * @brief Get the timestamp of the image from OH_EffectBufferInfo 478 * 479 * @syscap SystemCapability.Multimedia.ImageEffect.Core 480 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 481 * @param timestamp Indicates the timestamp of the image frame data for the OHNativeWindow input type. 482 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 483 * {@link ImageEffect_ErrorCode} 484 * {@link EFFECT_ERROR_PARAM_INVALID}, the input parameter is a null pointer. 485 * @since 12 486 */ 487 ImageEffect_ErrorCode OH_EffectBufferInfo_GetTimestamp(OH_EffectBufferInfo *info, int64_t *timestamp); 488 489 /** 490 * @brief Sets the texture ID of the image for an OH_EffectBufferInfo struct. 491 * 492 * @syscap SystemCapability.Multimedia.ImageEffect.Core 493 * @param info Pointer to an instance of the OH_EffectBufferInfo struct. 494 * @param textureId Pointer to the texture ID of the image. 495 * @return Returns EFFECT_SUCCESS if the operation is successful; returns EFFECT_ERROR_PARAM_INVALID if the 496 * parameter is missing. 497 * @since 20 498 */ 499 ImageEffect_ErrorCode OH_EffectBufferInfo_SetTextureId(OH_EffectBufferInfo *info, int32_t textureId); 500 501 /** 502 * @brief Obtains the texture ID of an image from an OH_EffectBufferInfo struct. 503 * 504 * @syscap SystemCapability.Multimedia.ImageEffect.Core 505 * @param info Pointer to an instance of the OH_EffectBufferInfo struct. 506 * @param textureId Texture ID of the image. 507 * @return Returns EFFECT_SUCCESS if the operation is successful; returns EFFECT_ERROR_PARAM_INVALID if the 508 * parameter is missing. 509 * @since 20 510 */ 511 ImageEffect_ErrorCode OH_EffectBufferInfo_GetTextureId(OH_EffectBufferInfo *info, int32_t *textureId); 512 513 /** 514 * @brief Clear the internal resources of the OH_EffectBufferInfo and destroy the OH_EffectBufferInfo instance 515 * 516 * @syscap SystemCapability.Multimedia.ImageEffect.Core 517 * @param info Encapsulate OH_EffectBufferInfo structure instance pointer 518 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 519 * {@link ImageEffect_ErrorCode} 520 * @since 12 521 */ 522 ImageEffect_ErrorCode OH_EffectBufferInfo_Release(OH_EffectBufferInfo *info); 523 524 /** 525 * @brief When executing the method of {@link OH_EffectFilter_SetValue} for the delegate filter, the function pointer 526 * will be called for checking the parameters is valid for the delegate filter 527 * 528 * @syscap SystemCapability.Multimedia.ImageEffect.Core 529 * @param filter Encapsulate OH_EffectFilter structure instance pointer 530 * @param key Indicates the key of the filter 531 * @param value Indicates the value corresponding to the key of the filter 532 * @return Returns true if the parameter is valid, otherwise returns false 533 * @since 12 534 */ 535 typedef bool (*OH_EffectFilterDelegate_SetValue)(OH_EffectFilter *filter, const char *key, 536 const ImageEffect_Any *value); 537 538 /** 539 * @brief Actively execute this callback function at the end of invoking the method of 540 * {@link OH_EffectFilterDelegate_Render} for passing possible new OH_EffectBufferInfo to the next filter. It should be 541 * noted that when passing new OH_EffectBufferInfo, the buffer in OH_EffectBufferInfo needs to be manually released 542 * after the execution of the function ends 543 * 544 * @syscap SystemCapability.Multimedia.ImageEffect.Core 545 * @param filter Encapsulate OH_EffectFilter structure instance pointer 546 * @param info Indicates the information of the image, such as width, height, etc. See {@link OH_EffectBufferInfo} 547 * @since 12 548 */ 549 typedef void (*OH_EffectFilterDelegate_PushData)(OH_EffectFilter *filter, OH_EffectBufferInfo *info); 550 551 /** 552 * @brief When the method of OH_ImageEffect_Start is executed on delegate filter that is contained in OH_ImageEffect, 553 * the function pointer will be called for rendering the delegate filter effects 554 * 555 * @syscap SystemCapability.Multimedia.ImageEffect.Core 556 * @param filter Encapsulate OH_EffectFilter structure instance pointer 557 * @param info Indicates the information of the image, such as width, height, etc. See {@link OH_EffectBufferInfo} 558 * @param pushData Indicates the callback function for passing possible new OH_EffectBufferInfo to the next filter. See 559 * {@link OH_EffectFilterDelegate_PushData} 560 * @return Returns true if this function point is executed successfully, otherwise returns false 561 * @since 12 562 */ 563 typedef bool (*OH_EffectFilterDelegate_Render)(OH_EffectFilter *filter, OH_EffectBufferInfo *info, 564 OH_EffectFilterDelegate_PushData pushData); 565 566 /** 567 * @brief When the method of OH_ImageEffect_Save is executed on delegate filter that is contained in OH_ImageEffect, 568 * the function pointer will be called for serializing the delegate filter parameters 569 * 570 * @syscap SystemCapability.Multimedia.ImageEffect.Core 571 * @param filter Encapsulate OH_EffectFilter structure instance pointer 572 * @param info Indicates the serialized information that is obtained by converting the delegate filter parameters to 573 * JSON string 574 * @return Returns true if this function point is executed successfully, otherwise returns false 575 * @since 12 576 */ 577 typedef bool (*OH_EffectFilterDelegate_Save)(OH_EffectFilter *filter, char **info); 578 579 /** 580 * @brief When the method of OH_ImageEffect_Restore is executed on delegate filter that is contained in OH_ImageEffect, 581 * the function pointer will be called for deserializing the delegate filter parameters 582 * 583 * @syscap SystemCapability.Multimedia.ImageEffect.Core 584 * @param info Indicates the serialized information that is obtained by converting the delegate filter parameters to 585 * JSON string 586 * @return Returns a pointer to an OH_EffectFilter instance if the execution is successful, otherwise returns nullptr 587 * @since 12 588 */ 589 typedef OH_EffectFilter *(*OH_EffectFilterDelegate_Restore)(const char *info); 590 591 /** 592 * @brief A collection of all callback function pointers in OH_EffectFilter. Register an instance of this structure to 593 * the OH_EffectFilter instance by invoking {@link OH_EffectFilter_Register}, and perform related rendering operations 594 * through the callback 595 * 596 * @syscap SystemCapability.Multimedia.ImageEffect.Core 597 * @since 12 598 */ 599 typedef struct ImageEffect_FilterDelegate { 600 /** Monitor checking parameters */ 601 OH_EffectFilterDelegate_SetValue setValue; 602 /** Monitor render */ 603 OH_EffectFilterDelegate_Render render; 604 /** Monitor serialize */ 605 OH_EffectFilterDelegate_Save save; 606 /** Monitor deserialize */ 607 OH_EffectFilterDelegate_Restore restore; 608 } ImageEffect_FilterDelegate; 609 610 /** 611 * @brief Describes the region information 612 * 613 * @syscap SystemCapability.Multimedia.ImageEffect.Core 614 * @since 12 615 */ 616 typedef struct ImageEffect_Region { 617 /** X coordinate of the start point of a line */ 618 int32_t x0; 619 /** Y coordinate of the start point of a line */ 620 int32_t y0; 621 /** X coordinate of the end point of a line */ 622 int32_t x1; 623 /** Y coordinate of the end point of a line */ 624 int32_t y1; 625 } ImageEffect_Region; 626 627 /** 628 * @brief Describes the image size information 629 * 630 * @syscap SystemCapability.Multimedia.ImageEffect.Core 631 * @since 12 632 */ 633 typedef struct ImageEffect_Size { 634 /** Image width, in pixels */ 635 int32_t width; 636 /** Image height, in pixels */ 637 int32_t height; 638 } ImageEffect_Size; 639 640 /** 641 * @brief Create an OH_EffectFilter instance. It should be noted that the life cycle of the OH_EffectFilter instance 642 * pointed to by the return value * needs to be manually released by {@link OH_EffectFilter_Release} 643 * 644 * @syscap SystemCapability.Multimedia.ImageEffect.Core 645 * @param name Indicates the filter name. For example, see {@link OH_EFFECT_BRIGHTNESS_FILTER} 646 * @return Returns a pointer to an OH_EffectFilter instance if the execution is successful, otherwise returns nullptr 647 * @since 12 648 */ 649 OH_EffectFilter *OH_EffectFilter_Create(const char *name); 650 651 /** 652 * @brief Set the filter parameter. It can be set multiple parameters by invoking this function multiple times 653 * 654 * @syscap SystemCapability.Multimedia.ImageEffect.Core 655 * @param filter Encapsulate OH_EffectFilter structure instance pointer 656 * @param key Indicates the key of the filter. For example, see {@link OH_EFFECT_FILTER_INTENSITY_KEY} 657 * @param value Indicates the value corresponding to the key of the filter 658 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 659 * {@link ImageEffect_ErrorCode} 660 * @since 12 661 */ 662 ImageEffect_ErrorCode OH_EffectFilter_SetValue(OH_EffectFilter *filter, const char *key, const ImageEffect_Any *value); 663 664 /** 665 * @brief Get the filter parameter 666 * 667 * @syscap SystemCapability.Multimedia.ImageEffect.Core 668 * @param filter Encapsulate OH_EffectFilter structure instance pointer 669 * @param key Indicates the key of the filter 670 * @param value Indicates the value corresponding to the key of the filter 671 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 672 * {@link ImageEffect_ErrorCode} 673 * @since 12 674 */ 675 ImageEffect_ErrorCode OH_EffectFilter_GetValue(OH_EffectFilter *filter, const char *key, ImageEffect_Any *value); 676 677 /** 678 * @brief Register the delegate filter 679 * 680 * @syscap SystemCapability.Multimedia.ImageEffect.Core 681 * @param info Indicates the capabilities supported by delegate filter, see {@link OH_EffectFilterInfo} 682 * @param delegate A collection of all callback functions, see {@link ImageEffect_FilterDelegate} 683 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 684 * {@link ImageEffect_ErrorCode} 685 * @since 12 686 */ 687 ImageEffect_ErrorCode OH_EffectFilter_Register(const OH_EffectFilterInfo *info, 688 const ImageEffect_FilterDelegate *delegate); 689 690 /** 691 * @brief Lookup for the filter names that matches the lookup condition. It should be noted that the allocated memory of 692 * ImageEffect_FilterNames can be manually released by invoking {@link OH_EffectFilter_ReleaseFilterNames} if need 693 * 694 * @syscap SystemCapability.Multimedia.ImageEffect.Core 695 * @param key Indicates the lookup condition 696 * @return Returns Filter name array that matches the key, see {@link ImageEffect_FilterNames} 697 * @since 12 698 */ 699 ImageEffect_FilterNames *OH_EffectFilter_LookupFilters(const char *key); 700 701 /** 702 * @brief Clear the internal cached resources of the ImageEffect_FilterNames 703 * 704 * @syscap SystemCapability.Multimedia.ImageEffect.Core 705 * @since 12 706 */ 707 void OH_EffectFilter_ReleaseFilterNames(); 708 709 /** 710 * @brief Lookup for the capabilities that supported by the filter 711 * 712 * @syscap SystemCapability.Multimedia.ImageEffect.Core 713 * @param name Indicates the filter name 714 * @param info Indicates the capabilities supported by the filter, see {@link OH_EffectFilterInfo} 715 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 716 * {@link ImageEffect_ErrorCode} 717 * @since 12 718 */ 719 ImageEffect_ErrorCode OH_EffectFilter_LookupFilterInfo(const char *name, OH_EffectFilterInfo *info); 720 721 /** 722 * @brief Render the filter effects. The function is designed to support the same input and output image 723 * 724 * @syscap SystemCapability.Multimedia.ImageEffect.Core 725 * @param filter Encapsulate OH_EffectFilter structure instance pointer 726 * @param inputPixelmap Indicates the input image 727 * @param outputPixelmap Indicates the output image 728 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 729 * {@link ImageEffect_ErrorCode} 730 * @since 12 731 */ 732 ImageEffect_ErrorCode OH_EffectFilter_Render(OH_EffectFilter *filter, OH_PixelmapNative *inputPixelmap, 733 OH_PixelmapNative *outputPixelmap); 734 735 /** 736 * @brief Applies the filter effect using texture IDs. This function does not support using the same texture 737 * for both input and output. 738 * 739 * @syscap SystemCapability.Multimedia.ImageEffect.Core 740 * @param filter Pointer to an instance of the OH_EffectFilter struct. 741 * @param inputTextureId ID of the input texture. This ID must be valid and bound to a texture of the 742 * GL_TEXTURE_2D type. 743 * @param outputTextureId ID of the output texture. This ID must be valid. If it is not bound to a texture, it 744 * will automatically be bound to a GL_TEXTURE_2D type. If the texture is already bound and the size is 745 * inappropriate, the rendered result may be cropped or partially filled into this texture. 746 * @param colorSpace Color space of the image. 747 * @return Returns EFFECT_SUCCESS if the operation is successful; returns EFFECT_ERROR_PARAM_INVALID if the 748 * parameter is missing. 749 * @since 20 750 */ 751 ImageEffect_ErrorCode OH_EffectFilter_RenderWithTextureId(OH_EffectFilter *filter, int32_t inputTextureId, 752 int32_t outputTextureId, int32_t colorSpace); 753 754 /** 755 * @brief Clear the internal resources of the OH_EffectFilter and destroy the OH_EffectFilter instance 756 * 757 * @syscap SystemCapability.Multimedia.ImageEffect.Core 758 * @param filter Encapsulate OH_EffectFilter structure instance pointer 759 * @return Returns EFFECT_SUCCESS if the execution is successful, otherwise returns a specific error code, refer to 760 * {@link ImageEffect_ErrorCode} 761 * @since 12 762 */ 763 ImageEffect_ErrorCode OH_EffectFilter_Release(OH_EffectFilter *filter); 764 765 #ifdef __cplusplus 766 } 767 #endif 768 #endif // NATIVE_IMAGE_EFFECT_FILTER_H 769 /** @} */