1 /* 2 * Copyright (C) 2023 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 image 18 * @{ 19 * 20 * @brief Provides APIs for obtaining pixel map data and information. 21 * 22 * @Syscap SystemCapability.Multimedia.Image.Core 23 * @since 12 24 */ 25 26 /** 27 * @file pixelmap_native.h 28 * 29 * @brief Declares the APIs that can access a pixel map. 30 * 31 * @library libpixelmap.so 32 * @Syscap SystemCapability.Multimedia.Image.Core 33 * @since 12 34 */ 35 36 #ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PIXELMAP_NATIVE_H 37 #define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PIXELMAP_NATIVE_H 38 #include "image_common.h" 39 #include "napi/native_api.h" 40 #include "napi/native_node_api.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /** 47 * @brief Define a Pixelmap struct type, used for pixelmap pointer controls. 48 * 49 * @since 12 50 */ 51 struct OH_PixelmapNative; 52 typedef struct OH_PixelmapNative OH_PixelmapNative; 53 54 /** 55 * @brief Define a native buffer type, used for retrieving a native buffer. 56 * 57 * @since 12 58 */ 59 struct OH_NativeBuffer; 60 typedef struct OH_NativeBuffer OH_NativeBuffer; 61 62 /** 63 * @brief Define a native ColorSpaceManager type, used for retrieving a native ColorSpaceManager. 64 * 65 * @since 13 66 */ 67 typedef struct OH_NativeColorSpaceManager OH_NativeColorSpaceManager; 68 69 /** 70 * @brief Define a pixelmap alpha type. 71 * 72 * @since 12 73 */ 74 typedef enum { 75 /* 76 * Unknown format 77 */ 78 PIXELMAP_ALPHA_TYPE_UNKNOWN = 0, 79 /* 80 * Opaque format 81 */ 82 PIXELMAP_ALPHA_TYPE_OPAQUE = 1, 83 /* 84 * Premultiplied format 85 */ 86 PIXELMAP_ALPHA_TYPE_PREMULTIPLIED = 2, 87 /* 88 * UnPremultiplied format 89 */ 90 PIXELMAP_ALPHA_TYPE_UNPREMULTIPLIED = 3, 91 }PIXELMAP_ALPHA_TYPE; 92 93 typedef enum { 94 /* 95 * Unknown format 96 */ 97 PIXEL_FORMAT_UNKNOWN = 0, 98 /* 99 * RGB_565 format 100 */ 101 PIXEL_FORMAT_RGB_565 = 2, 102 /* 103 * RGBA_8888 format 104 */ 105 PIXEL_FORMAT_RGBA_8888 = 3, 106 /* 107 * BGRA_8888 format 108 */ 109 PIXEL_FORMAT_BGRA_8888 = 4, 110 /* 111 * RGB_888 format 112 */ 113 PIXEL_FORMAT_RGB_888 = 5, 114 /* 115 * ALPHA_8 format 116 */ 117 PIXEL_FORMAT_ALPHA_8 = 6, 118 /* 119 * RGBA_F16 format 120 */ 121 PIXEL_FORMAT_RGBA_F16 = 7, 122 /* 123 * NV21 format 124 */ 125 PIXEL_FORMAT_NV21 = 8, 126 /* 127 * NV12 format 128 */ 129 PIXEL_FORMAT_NV12 = 9, 130 /* 131 * RGBA_1010102 format 132 */ 133 PIXEL_FORMAT_RGBA_1010102 = 10, 134 /* 135 * YCBCR_P010 format 136 */ 137 PIXEL_FORMAT_YCBCR_P010 = 11, 138 /* 139 * YCRCB_P010 format 140 */ 141 PIXEL_FORMAT_YCRCB_P010 = 12, 142 } PIXEL_FORMAT; 143 144 typedef enum { 145 IMAGE_FORMAT_UNKNOWN, 146 IMAGE_FORMAT_YUV_TYPE, 147 IMAGE_FORMAT_RGB_TYPE 148 } IMAGE_FORMAT; 149 150 /** 151 * @brief Defines the anti-aliasing level. 152 * 153 * @since 12 154 */ 155 typedef enum { 156 /** 157 * Nearest-neighbor interpolation algorithm 158 */ 159 OH_PixelmapNative_AntiAliasing_NONE = 0, 160 /** 161 * Bilinear interpolation algorithm 162 */ 163 OH_PixelmapNative_AntiAliasing_LOW = 1, 164 /** 165 * Bilinear interpolation algorithm with mipmap linear filtering 166 */ 167 OH_PixelmapNative_AntiAliasing_MEDIUM = 2, 168 /** 169 * Cubic interpolation algorithm 170 */ 171 OH_PixelmapNative_AntiAliasing_HIGH = 3, 172 } OH_PixelmapNative_AntiAliasingLevel; 173 174 /** 175 * @brief Enumerates the HDR metadata types that need to be stored in Pixelmap. 176 * 177 * @since 12 178 */ 179 typedef enum { 180 /** 181 * Indicates the types of metadata that image needs to use. 182 */ 183 HDR_METADATA_TYPE = 0, 184 /** 185 * Static metadata key. 186 */ 187 HDR_STATIC_METADATA = 1, 188 /** 189 * Dynamic metadata key. 190 */ 191 HDR_DYNAMIC_METADATA = 2, 192 /** 193 * Gainmap metadata key. 194 */ 195 HDR_GAINMAP_METADATA = 3, 196 } OH_Pixelmap_HdrMetadataKey; 197 198 /** 199 * @brief Value for HDR_METADATA_TYPE. 200 * 201 * @since 12 202 */ 203 typedef enum { 204 /** 205 * No metadata. 206 */ 207 HDR_METADATA_TYPE_NONE = 0, 208 /** 209 * Indicates that metadata will be used for the base image. 210 */ 211 HDR_METADATA_TYPE_BASE = 1, 212 /** 213 * Indicates that metadata will be used for the gainmap image. 214 */ 215 HDR_METADATA_TYPE_GAINMAP = 2, 216 /** 217 * Indicates that metadata will be used for the alternate image. 218 */ 219 HDR_METADATA_TYPE_ALTERNATE = 3, 220 } OH_Pixelmap_HdrMetadataType; 221 222 /** 223 * @brief Value for HDR_DYNAMIC_METADATA. 224 * 225 * @since 12 226 */ 227 typedef struct OH_Pixelmap_HdrStaticMetadata { 228 /** 229 * The X-coordinate of the primary colors. The length of the array is three. Store in the order of r, g, b. 230 */ 231 float displayPrimariesX[3]; 232 /** 233 * The Y-coordinate of the primary colors. The length of the array is three. Store in the order of r, g, b. 234 */ 235 float displayPrimariesY[3]; 236 /** 237 * The X-coordinate of the white point value. 238 */ 239 float whitePointX; 240 /** 241 * The Y-coordinate of the white point value. 242 */ 243 float whitePointY; 244 /** 245 * Max luminance. 246 */ 247 float maxLuminance; 248 /** 249 * Min luminance. 250 */ 251 float minLuminance; 252 /** 253 * Maximun brightness of displayed content. 254 */ 255 float maxContentLightLevel; 256 /** 257 * Maximun average brightness of displayed content. 258 */ 259 float maxFrameAverageLightLevel; 260 } OH_Pixelmap_HdrStaticMetadata; 261 262 /** 263 * @brief Value for HDR_DYNAMIC_METADATA. 264 * 265 * @since 12 266 */ 267 typedef struct OH_Pixelmap_HdrDynamicMetadata { 268 /** 269 * The value of dynamic metadata. 270 */ 271 uint8_t* data; 272 /** 273 * The length of dynamic metadata. 274 */ 275 uint32_t length; 276 } OH_Pixelmap_HdrDynamicMetadata; 277 278 /** 279 * @brief Value for HDR_GAINMAP_METADATA. 280 * 281 * @since 12 282 */ 283 typedef struct OH_Pixelmap_HdrGainmapMetadata { 284 /** 285 * The version used by the writer. 286 */ 287 uint16_t writerVersion; 288 /** 289 * The minmum version a parser needs to understand. 290 */ 291 uint16_t minVersion; 292 /** 293 * The number of gain map channels, with a value of 1 or 3. 294 */ 295 uint8_t gainmapChannelNum; 296 /** 297 * Indicate whether to use the color space of the base image. 298 */ 299 bool useBaseColorFlag; 300 /** 301 * The baseline hdr headroom. 302 */ 303 float baseHdrHeadroom; 304 /** 305 * The alternate hdr headroom. 306 */ 307 float alternateHdrHeadroom; 308 /** 309 * The per-component max gain map values. 310 */ 311 float gainmapMax[3]; 312 /** 313 * The per-component min gain map values. 314 */ 315 float gainmapMin[3]; 316 /** 317 * The per-component gamma values. 318 */ 319 float gamma[3]; 320 /** 321 * The per-component baseline offset. 322 */ 323 float baselineOffset[3]; 324 /** 325 * The per-component alternate offset. 326 */ 327 float alternateOffset[3]; 328 } OH_Pixelmap_HdrGainmapMetadata; 329 330 /** 331 * @brief Value for HDR_METADATA_KEY. Corresponding relationship with HDR_METADATA_KEY. 332 * 333 * @since 12 334 */ 335 typedef struct OH_Pixelmap_HdrMetadataValue { 336 /** 337 * The value corresponding to the HDR_METADATA_TYPE key 338 */ 339 OH_Pixelmap_HdrMetadataType type; 340 /** 341 * The value corresponding to the HDR_STATIC_METADATA key 342 */ 343 OH_Pixelmap_HdrStaticMetadata staticMetadata; 344 /** 345 * The value corresponding to the HDR_DYNAMIC_METADATA key 346 */ 347 OH_Pixelmap_HdrDynamicMetadata dynamicMetadata; 348 /** 349 * The value corresponding to the HDR_GAINMAP_METADATA key 350 */ 351 OH_Pixelmap_HdrGainmapMetadata gainmapMetadata; 352 } OH_Pixelmap_HdrMetadataValue; 353 354 /** 355 * @brief Defines the options used for creating a pixel map. 356 * 357 * @since 12 358 */ 359 struct OH_Pixelmap_InitializationOptions; 360 typedef struct OH_Pixelmap_InitializationOptions OH_Pixelmap_InitializationOptions; 361 362 /** 363 * @brief Create a for InitializationOtions struct. 364 * 365 * @param options The InitializationOtions pointer will be operated. 366 * @return Returns {@link Image_ErrorCode} 367 * @since 12 368 */ 369 Image_ErrorCode OH_PixelmapInitializationOptions_Create(OH_Pixelmap_InitializationOptions **options); 370 371 /** 372 * @brief Get width number for InitializationOtions struct. 373 * 374 * @param options The InitializationOtions pointer will be operated. 375 * @param width the number of image width. 376 * @return Returns {@link Image_ErrorCode} 377 * @since 12 378 */ 379 Image_ErrorCode OH_PixelmapInitializationOptions_GetWidth(OH_Pixelmap_InitializationOptions *options, 380 uint32_t *width); 381 382 /** 383 * @brief Set width number for InitializationOtions struct. 384 * 385 * @param options The InitializationOtions pointer will be operated. 386 * @param width the number of image width. 387 * @return Returns {@link Image_ErrorCode} 388 * @since 12 389 */ 390 Image_ErrorCode OH_PixelmapInitializationOptions_SetWidth(OH_Pixelmap_InitializationOptions *options, 391 uint32_t width); 392 393 /** 394 * @brief Get height number for InitializationOtions struct. 395 * 396 * @param options The InitializationOtions pointer will be operated. 397 * @param height the number of image height. 398 * @return Returns {@link Image_ErrorCode} 399 * @since 12 400 */ 401 Image_ErrorCode OH_PixelmapInitializationOptions_GetHeight(OH_Pixelmap_InitializationOptions *options, 402 uint32_t *height); 403 404 /** 405 * @brief Set height number for InitializationOtions struct. 406 * 407 * @param options The InitializationOtions pointer will be operated. 408 * @param height the number of image height. 409 * @return Returns {@link Image_ErrorCode} 410 * @since 12 411 */ 412 Image_ErrorCode OH_PixelmapInitializationOptions_SetHeight(OH_Pixelmap_InitializationOptions *options, 413 uint32_t height); 414 415 /** 416 * @brief Get pixelFormat number for InitializationOtions struct. 417 * 418 * @param options The InitializationOtions pointer will be operated. 419 * @param pixelFormat the number of image pixelFormat. 420 * @return Returns {@link Image_ErrorCode} 421 * @since 12 422 */ 423 Image_ErrorCode OH_PixelmapInitializationOptions_GetPixelFormat(OH_Pixelmap_InitializationOptions *options, 424 int32_t *pixelFormat); 425 426 /** 427 * @brief Set pixelFormat number for InitializationOtions struct. 428 * 429 * @param options The InitializationOtions pointer will be operated. 430 * @param pixelFormat the number of image pixelFormat. 431 * @return Returns {@link Image_ErrorCode} 432 * @since 12 433 */ 434 Image_ErrorCode OH_PixelmapInitializationOptions_SetPixelFormat(OH_Pixelmap_InitializationOptions *options, 435 int32_t pixelFormat); 436 437 /** 438 * @brief Get pixelFormat number for InitializationOtions struct. 439 * 440 * @param options The InitializationOtions pointer will be operated. 441 * @param srcpixelFormat the number of image srcpixelFormat. 442 * @return Returns {@link Image_ErrorCode} 443 * @since 12 444 */ 445 Image_ErrorCode OH_PixelmapInitializationOptions_GetSrcPixelFormat(OH_Pixelmap_InitializationOptions *options, 446 int32_t *srcpixelFormat); 447 448 /** 449 * @brief Set pixelFormat number for InitializationOtions struct. 450 * 451 * @param options The InitializationOtions pointer will be operated. 452 * @param srcpixelFormat the number of image srcpixelFormat. 453 * @return Returns {@link Image_ErrorCode} 454 * @since 12 455 */ 456 Image_ErrorCode OH_PixelmapInitializationOptions_SetSrcPixelFormat(OH_Pixelmap_InitializationOptions *options, 457 int32_t srcpixelFormat); 458 459 /** 460 * @brief Get rowStride for InitializationOptions struct. 461 * 462 * @param options The InitializationOptions pointer will be operated. 463 * @param rowStride the rowStride of image buffer. 464 * @return Returns {@link Image_ErrorCode} IMAGE_SUCCESS - if the operation is successful. 465 * returns {@link Image_ErrorCode} IMAGE_BAD_PARAMETER - if rowStride is null. 466 * returns {@link Image_ErrorCode} IMAGE_UNKNOWN_ERROR - inner unknown error, maybe options is released. 467 * @since 12 468 */ 469 Image_ErrorCode OH_PixelmapInitializationOptions_GetRowStride(OH_Pixelmap_InitializationOptions *options, 470 int32_t *rowStride); 471 472 /** 473 * @brief Set rowStride number for InitializationOptions struct. 474 * 475 * @param options The InitializationOptions pointer will be operated. 476 * @param rowStride the rowStride of image buffer. 477 * @return Returns {@link Image_ErrorCode} IMAGE_SUCCESS - if the operation is successful. 478 * returns {@link Image_ErrorCode} IMAGE_BAD_PARAMETER - if rowStride does not match width. 479 * returns {@link Image_ErrorCode} IMAGE_UNKNOWN_ERROR - inner unknown error, maybe options is released. 480 * @since 12 481 */ 482 Image_ErrorCode OH_PixelmapInitializationOptions_SetRowStride(OH_Pixelmap_InitializationOptions *options, 483 int32_t rowStride); 484 485 /** 486 * @brief Get alphaType number for InitializationOtions struct. 487 * 488 * @param options The InitializationOtions pointer will be operated. 489 * @param alphaType the number of image alphaType. 490 * @return Returns {@link Image_ErrorCode} 491 * @since 12 492 */ 493 Image_ErrorCode OH_PixelmapInitializationOptions_GetAlphaType(OH_Pixelmap_InitializationOptions *options, 494 int32_t *alphaType); 495 496 /** 497 * @brief Set alphaType number for InitializationOtions struct. 498 * 499 * @param options The InitializationOtions pointer will be operated. 500 * @param alphaType the number of image alphaType. 501 * @return Returns {@link Image_ErrorCode} 502 * @since 12 503 */ 504 Image_ErrorCode OH_PixelmapInitializationOptions_SetAlphaType(OH_Pixelmap_InitializationOptions *options, 505 int32_t alphaType); 506 507 /** 508 * @brief Get editable for InitializationOptions struct. 509 * 510 * @param options The InitializationOptions pointer will be operated. 511 * @param editable The boolean value representing the editable status. 512 * @return Returns {@link Image_ErrorCode} IMAGE_SUCCESS - if the operation is successful. 513 * returns {@link Image_ErrorCode} IMAGE_BAD_PARAMETER - if options or editable is invalid. 514 * @since 18 515 */ 516 Image_ErrorCode OH_PixelmapInitializationOptions_GetEditable(OH_Pixelmap_InitializationOptions *options, 517 bool *editable); 518 519 /** 520 * @brief Set editable for InitializationOptions struct. 521 * 522 * @param options The InitializationOptions pointer will be operated. 523 * @param editable The boolean value representing the editable status. 524 * @return Returns {@link Image_ErrorCode} IMAGE_SUCCESS - if the operation is successful. 525 * returns {@link Image_ErrorCode} IMAGE_BAD_PARAMETER - if options is invalid. 526 * @since 18 527 */ 528 Image_ErrorCode OH_PixelmapInitializationOptions_SetEditable(OH_Pixelmap_InitializationOptions *options, 529 bool editable); 530 531 /** 532 * @brief delete InitializationOtions pointer. 533 * 534 * @param options The InitializationOtions pointer will be operated. 535 * @return Returns {@link Image_ErrorCode} 536 * @since 12 537 */ 538 Image_ErrorCode OH_PixelmapInitializationOptions_Release(OH_Pixelmap_InitializationOptions *options); 539 540 /** 541 * @brief Defines the pixel map information. 542 * 543 * @since 12 544 */ 545 struct OH_Pixelmap_ImageInfo; 546 typedef struct OH_Pixelmap_ImageInfo OH_Pixelmap_ImageInfo; 547 548 /** 549 * @brief Create imageinfo struct . 550 * 551 * @param info The imageinfo pointer will be operated. 552 * @return Returns {@link Image_ErrorCode} 553 * @since 12 554 */ 555 Image_ErrorCode OH_PixelmapImageInfo_Create(OH_Pixelmap_ImageInfo **info); 556 557 /** 558 * @brief Get width number for imageinfo struct. 559 * 560 * @param info The imageinfo pointer will be operated. 561 * @param width The number of imageinfo width. 562 * @return Returns {@link Image_ErrorCode} 563 * @since 12 564 */ 565 Image_ErrorCode OH_PixelmapImageInfo_GetWidth(OH_Pixelmap_ImageInfo *info, uint32_t *width); 566 567 /** 568 * @brief Get height number for imageinfo struct. 569 * 570 * @param info The imageinfo pointer will be operated. 571 * @param height The number of imageinfo height. 572 * @return Returns {@link Image_ErrorCode} 573 * @since 12 574 */ 575 Image_ErrorCode OH_PixelmapImageInfo_GetHeight(OH_Pixelmap_ImageInfo *info, uint32_t *height); 576 577 /** 578 * @brief Get alphaMode number for imageinfo struct. 579 * 580 * @param info The imageinfo pointer will be operated. 581 * @param alphaMode The number of imageinfo alphaMode. 582 * @return Image functions result code. 583 * {@link IMAGE_SUCCESS} if the execution is successful. 584 * {@link IMAGE_BAD_PARAMETER} pixelmapNative is nullptr, or pixelmapNapi is not a pixelmap. 585 * @since 20 586 */ 587 Image_ErrorCode OH_PixelmapImageInfo_GetAlphaMode(OH_Pixelmap_ImageInfo *info, int32_t *alphaMode); 588 589 /** 590 * @brief Get rowStride number for imageinfo struct. 591 * 592 * @param info The imageinfo pointer will be operated. 593 * @param rowStride The number of imageinfo rowStride. 594 * @return Returns {@link Image_ErrorCode} 595 * @since 12 596 */ 597 Image_ErrorCode OH_PixelmapImageInfo_GetRowStride(OH_Pixelmap_ImageInfo *info, uint32_t *rowStride); 598 599 /** 600 * @brief Get pixelFormat number for imageinfo struct. 601 * 602 * @param info The imageinfo pointer will be operated. 603 * @param pixelFormat The number of imageinfo pixelFormat. 604 * @return Returns {@link Image_ErrorCode} 605 * @since 12 606 */ 607 Image_ErrorCode OH_PixelmapImageInfo_GetPixelFormat(OH_Pixelmap_ImageInfo *info, int32_t *pixelFormat); 608 609 /** 610 * @brief Get density number for imageinfo struct. 611 * 612 * @param info The imageinfo pointer will be operated. 613 * @param density The number of imageinfo density. 614 * @return Returns {@link Image_ErrorCode} 615 * @since 12 616 */ 617 Image_ErrorCode OH_PixelmapImageInfo_GetAlphaType(OH_Pixelmap_ImageInfo *info, int32_t *alphaType); 618 619 /** 620 * @brief Get isHdr boolean for imageinfo struct. 621 * 622 * @param info The imageinfo pointer will be operated. 623 * @param isHdr Whether the image has a high dynamic range. 624 * @return Returns {@link Image_ErrorCode} 625 * @since 12 626 */ 627 Image_ErrorCode OH_PixelmapImageInfo_GetDynamicRange(OH_Pixelmap_ImageInfo *info, bool *isHdr); 628 629 /** 630 * @brief Delete imageinfo struct pointer. 631 * 632 * @param info The imageinfo pointer will be operated. 633 * @return Returns {@link Image_ErrorCode} 634 * @since 12 635 */ 636 Image_ErrorCode OH_PixelmapImageInfo_Release(OH_Pixelmap_ImageInfo *info); 637 638 /** 639 * @brief Creates a <b>PixelMap</b> object. 640 * 641 * @param data Color buffer in BGRA_8888 format. 642 * @param dataLength Color buffer size in BGRA_8888 format. 643 * @param options IPixel properties, including the alpha type, size, pixel format, and editable. 644 * @param pixelmap Pixelmap pointer for created. 645 * @return Returns {@link Image_ErrorCode} 646 * @since 12 647 */ 648 Image_ErrorCode OH_PixelmapNative_CreatePixelmap(uint8_t *data, size_t dataLength, 649 OH_Pixelmap_InitializationOptions *options, OH_PixelmapNative **pixelmap); 650 651 /** 652 * @brief Creates a pixelmap based on options {@link OH_Pixelmap_InitializationOptions}, the memory type used by the 653 * pixelmap can be specified by allocatorType {@link IMAGE_ALLOCATOR_MODE}. By default, the system selects the memory 654 * type based on the image type, image size, platform capability, etc. When processing the pixelmap returned by this 655 * interface, please always consider the impact of stride. 656 * 657 * @param data Input color buffer in BGRA_8888 format by default. 658 * @param dataLength Length of input buffer in bytes. 659 * @param options Pixelmap initialization properties including size, pixel format, alpha type, and editable flags. 660 * @param allocator Indicate which memory type will be used by the returned pixelmap. 661 * @param pixelmap Output parameter receiving the created pixelmap object pointer. 662 * @return Function result code: 663 * {@link IMAGE_SUCCESS} If the operation is successful. 664 * {@link IMAGE_BAD_PARAMETER} If the param is nullptr or invalid. 665 * {@link IMAGE_TOO_LARGE} too large data or image. 666 * {@link IMAGE_UNSUPPORTED_OPERATION} unsupported operations. 667 * {@link IMAGE_DMA_OPERATION_FAILED} DMA operation failed. 668 * {@link IMAGE_ALLOCATOR_MODE_UNSUPPROTED} unsupported allocator mode, e.g., 669 * use share memory to create a HDR image as only DMA supported hdr metadata. 670 * @since 20 671 */ 672 Image_ErrorCode OH_PixelmapNative_CreatePixelmapUsingAllocator(uint8_t *data, size_t dataLength, 673 OH_Pixelmap_InitializationOptions *options, IMAGE_ALLOCATOR_MODE allocator, OH_PixelmapNative **pixelmap); 674 675 /** 676 * @brief Convert a native <b>PixelMap</b> object to <b>PixelMap</b> napi object. 677 * 678 * @param env Indicates the NAPI environment pointer. 679 * @param pixelmapNative Indicates a pointer to the <b>PixelMap</b> object created at the native layer. 680 * @param pixelmapNapi the <b>PixelMap</b> pointer will be converted. 681 * @return Image functions result code. 682 * {@link IMAGE_SUCCESS} if the execution is successful. 683 * {@link IMAGE_BAD_PARAMETER} pixelmapNative is nullptr 684 * @since 12 685 */ 686 Image_ErrorCode OH_PixelmapNative_ConvertPixelmapNativeToNapi(napi_env env, OH_PixelmapNative *pixelmapNative, 687 napi_value *pixelmapNapi); 688 689 /** 690 * @brief Convert a <b>PixelMap</b> napi object to native <b>PixelMap</b> object. 691 * 692 * @param env Indicates the NAPI environment pointer. 693 * @param pixelmapNapi Indicates napi <b>PixelMap</b> object. 694 * @param pixelmapNative Indicates native <b>PixelMap</b> pointer to created. 695 * @return Image functions result code. 696 * {@link IMAGE_SUCCESS} if the execution is successful. 697 * {@link IMAGE_BAD_PARAMETER} pixelmapNative is nullptr, or pixelmapNapi is not a PixelMap 698 * @since 12 699 */ 700 Image_ErrorCode OH_PixelmapNative_ConvertPixelmapNativeFromNapi(napi_env env, napi_value pixelmapNapi, 701 OH_PixelmapNative **pixelmapNative); 702 703 /** 704 * @brief Reads data of this pixel map to an Buffer. If this pixel map is created in the BGRA_8888 format, 705 * the data read is the same as the original data. 706 * 707 * @param pixelmap The Pixelmap pointer will be operated. 708 * @param destination Buffer to which the image pixel map data will be written. 709 * @param bufferSize Buffer size to which the image pixel map data will be written. 710 * @return Returns {@link Image_ErrorCode} 711 * @see OH_PixelmapNative 712 * @since 12 713 */ 714 Image_ErrorCode OH_PixelmapNative_ReadPixels(OH_PixelmapNative *pixelmap, uint8_t *destination, size_t *bufferSize); 715 716 /** 717 * @brief Reads image data in an Buffer and writes the data to a Pixelmap object. 718 * 719 * @param pixelmap The Pixelmap pointer will be operated. 720 * @param source Buffer from which the image data will be read. 721 * @param bufferSize Buffer size from which the image data will be read. 722 * @return Returns {@link Image_ErrorCode} 723 * @see OH_PixelmapNative 724 * @since 12 725 */ 726 Image_ErrorCode OH_PixelmapNative_WritePixels(OH_PixelmapNative *pixelmap, uint8_t *source, size_t bufferSize); 727 728 /** 729 * @brief Get argb pixel buffer from pixelmap. 730 * 731 * @param pixelmap The Pixelmap pointer to be operated. 732 * @param destination Buffer to which the image pixel map data will be written. 733 * @param bufferSize Buffer size to which the image pixel map data will be written. 734 * @return Function result code: 735 * {@link IMAGE_SUCCESS} If the operation is successful. 736 * {@link IMAGE_BAD_PARAMETER} If invalid parameter, destination and bufferSize are incorrect. 737 * {@link IMAGE_UNSUPPORTED_CONVERSION} If format does not support conversion to argb or conversion failed. 738 * {@link IMAGE_ALLOC_FAILED} If device has no memory. 739 * {@link IMAGE_COPY_FAILED} If memory copy failed. 740 * @see OH_PixelmapNative 741 * @since 13 742 */ 743 Image_ErrorCode OH_PixelmapNative_GetArgbPixels(OH_PixelmapNative *pixelmap, uint8_t *destination, size_t *bufferSize); 744 745 /** 746 * @brief Convert {@link OH_PixelmapNative} to standard dynamic range. 747 * 748 * @param pixelmap The Pixelmap pointer will be operated. Pointer connot be null. 749 * @return Returns {@link Image_ErrorCode} IMAGE_SUCCESS - The operation is successful. 750 * returns {@link Image_ErrorCode} IMAGE_BAD_PARAMETER - Parameter error.Possible causes:Parameter verification failed. 751 * returns {@link Image_ErrorCode} IMAGE_UNSUPPORTED_OPERATION - Unsupported operation.Pixelmap can't be converted. 752 * @since 12 753 */ 754 Image_ErrorCode OH_PixelmapNative_ToSdr(OH_PixelmapNative *pixelmap); 755 756 /** 757 * @brief Obtains pixel map information of this image. 758 * 759 * @param pixelmap The Pixelmap pointer will be operated. 760 * @param imageInfo Indicates the pointer to the image information. 761 * @return Returns {@link Image_ErrorCode} 762 * @see OH_PixelmapNative OH_Pixelmap_ImageInfo 763 * @since 12 764 */ 765 Image_ErrorCode OH_PixelmapNative_GetImageInfo(OH_PixelmapNative *pixelmap, OH_Pixelmap_ImageInfo *imageInfo); 766 767 /** 768 * @brief Sets an opacity rate for this image pixel map. 769 * 770 * @param pixelmap The Pixelmap pointer will be operated. 771 * @param rate Opacity rate to set. The value ranges from 0 to 1. 772 * @return Returns {@link Image_ErrorCode} 773 * @see OH_PixelmapNative 774 * @since 12 775 */ 776 Image_ErrorCode OH_PixelmapNative_Opacity(OH_PixelmapNative *pixelmap, float rate); 777 778 /** 779 * @brief Scales this image based on the input width and height. 780 * 781 * @param pixelmap The Pixelmap pointer will be operated. 782 * @param scaleX Scaling ratio of the width. 783 * @param scaleY Scaling ratio of the height. 784 * @return Returns {@link Image_ErrorCode} 785 * @see OH_PixelmapNative 786 * @since 12 787 */ 788 Image_ErrorCode OH_PixelmapNative_Scale(OH_PixelmapNative *pixelmap, float scaleX, float scaleY); 789 790 /** 791 * @brief Scales this image based on the input width and height with anti-aliasing. 792 * 793 * @param pixelmap The Pixelmap pointer will be operated. 794 * @param scaleX Scaling ratio of the width. 795 * @param scaleY Scaling ratio of the height. 796 * @param level The anti-aliasing algorithm to be used. 797 * @return Returns {@link Image_ErrorCode} IMAGE_SUCCESS - if the operation is successful. 798 * returns {@link Image_ErrorCode} IMAGE_BAD_PARAMETER - if invalid parameter, x and y are incorrect. 799 * returns {@link Image_ErrorCode} IMAGE_TOO_LARGE - if image is too large. 800 * returns {@link Image_ErrorCode} IMAGE_ALLOC_FAILED - if device has no memory. 801 * returns {@link Image_ErrorCode} IMAGE_UNKNOWN_ERROR - inner unknown error, maybe source pixelmap is released. 802 * @see OH_PixelmapNative 803 * @since 12 804 */ 805 Image_ErrorCode OH_PixelmapNative_ScaleWithAntiAliasing(OH_PixelmapNative *pixelmap, float scaleX, float scaleY, 806 OH_PixelmapNative_AntiAliasingLevel level); 807 808 /** 809 * @brief Translates this image based on the input coordinates. 810 * 811 * @param pixelmap The Pixelmap pointer will be operated. 812 * @param x The distance to be translate in the X direction. 813 * @param y The distance to be translate in the Y direction. 814 * @return Returns {@link Image_ErrorCode} 815 * @see OH_PixelmapNative 816 * @since 12 817 */ 818 Image_ErrorCode OH_PixelmapNative_Translate(OH_PixelmapNative *pixelmap, float x, float y); 819 820 /** 821 * @brief Create a scaled pixelmap based on the source pixelmap and the input width and height. 822 * 823 * @param srcPixelmap The source native pixelmap. 824 * @param dstPixelmap The destination native pixelmap for create. 825 * @param scaleX Scaling ratio of the width. 826 * @param scaleY Scaling ratio of the height. 827 * @return Function result code: 828 * {@link IMAGE_SUCCESS} If the execution is successful. 829 * {@link IMAGE_BAD_PARAMETER} If the param is nullptr or invalid. 830 * @see OH_PixelmapNative 831 * @since 16 832 */ 833 Image_ErrorCode OH_PixelmapNative_CreateScaledPixelMap(OH_PixelmapNative *srcPixelmap, OH_PixelmapNative **dstPixelmap, 834 float scaleX, float scaleY); 835 836 /** 837 * @brief Create a scaled pixelmap based on the source pixelmap and the input width and height with anti-aliasing. 838 * 839 * @param srcPixelmap The source native pixelmap. 840 * @param dstPixelmap The destination native pixelmap for create. 841 * @param scaleX Scaling ratio of the width. 842 * @param scaleY Scaling ratio of the height. 843 * @param level The anti-aliasing algorithm to be used. 844 * @return Function result code: 845 * {@link IMAGE_SUCCESS} If the execution is successful. 846 * {@link IMAGE_BAD_PARAMETER} If the param is nullptr or invalid. 847 * {@link IMAGE_TOO_LARGE} If image is too large. 848 * {@link IMAGE_ALLOC_FAILED} If device has no memory. 849 * @see OH_PixelmapNative 850 * @since 16 851 */ 852 Image_ErrorCode OH_PixelmapNative_CreateScaledPixelMapWithAntiAliasing(OH_PixelmapNative *srcPixelmap, 853 OH_PixelmapNative **dstPixelmap, float scaleX, float scaleY, OH_PixelmapNative_AntiAliasingLevel level); 854 855 /** 856 * @brief Rotates this image based on the input angle. 857 * 858 * @param pixelmap The Pixelmap pointer will be operated. 859 * @param angle Angle to rotate. 860 * @return Returns {@link Image_ErrorCode} 861 * @see OH_PixelmapNative 862 * @since 12 863 */ 864 Image_ErrorCode OH_PixelmapNative_Rotate(OH_PixelmapNative *pixelmap, float angle); 865 866 /** 867 * @brief Flips this image horizontally or vertically, or both. 868 * 869 * @param pixelmap The Pixelmap pointer will be operated. 870 * @param shouldFilpHorizontally Whether to flip the image horizontally. 871 * @param shouldFilpVertically Whether to flip the image vertically. 872 * @return Returns {@link Image_ErrorCode} 873 * @see OH_PixelmapNative 874 * @since 12 875 */ 876 Image_ErrorCode OH_PixelmapNative_Flip(OH_PixelmapNative *pixelmap, bool shouldFilpHorizontally, 877 bool shouldFilpVertically); 878 879 /** 880 * @brief Crops this image based on the input size. 881 * 882 * @param pixelmap The Pixelmap pointer will be operated. 883 * @param region Area size, read according to area. 884 * @return Returns {@link Image_ErrorCode} 885 * @see OH_PixelmapNative 886 * @since 12 887 */ 888 Image_ErrorCode OH_PixelmapNative_Crop(OH_PixelmapNative *pixelmap, Image_Region *region); 889 890 /** 891 * @brief Releases an <b>OH_PixelmapNative</b> object. 892 * 893 * @param pixelmap The Pixelmap pointer will be operated. 894 * @return Returns {@link Image_ErrorCode} 895 * @see OH_PixelmapNative 896 * @since 12 897 */ 898 Image_ErrorCode OH_PixelmapNative_Release(OH_PixelmapNative *pixelmap); 899 900 /** 901 * @brief Destroys an <b>OH_PixelmapNative</b> object and deallocates its resources. 902 * 903 * @param pixelmap A pointer to the OH_PixelmapNative pointer to destroy. 904 * @return Returns {@link Image_ErrorCode} IMAGE_SUCCESS - if the operation is successful. 905 * returns {@link Image_ErrorCode} IMAGE_BAD_PARAMETER - if pixelmap is null or *pixelmap is null. 906 * @since 18 907 */ 908 Image_ErrorCode OH_PixelmapNative_Destroy(OH_PixelmapNative **pixelmap); 909 910 /** 911 * @brief Converting images to alpha format 912 * 913 * @param srcpixelmap The source pixel map pointer will be operated. 914 * @param dstpixelmap The destination pixel map pointer will be operated. 915 * @param isPremul Whether it is pre-multiplied, true for prediction, false for non-pre-multiplied. 916 * @return Returns {@link Image_ErrorCode} 917 * @since 12 918 */ 919 Image_ErrorCode OH_PixelmapNative_ConvertAlphaFormat(OH_PixelmapNative* srcpixelmap, 920 OH_PixelmapNative* dstpixelmap, const bool isPremul); 921 922 /** 923 * @brief Create a empty <b>PixelMap</b> object. 924 * 925 * @param options IPixel properties, including the alpha type, size, pixel format, and editable. 926 * @param pixelmap Pixelmap pointer for created. 927 * @return Returns {@link Image_ErrorCode} 928 * @since 12 929 */ 930 Image_ErrorCode OH_PixelmapNative_CreateEmptyPixelmap(OH_Pixelmap_InitializationOptions *options, 931 OH_PixelmapNative **pixelmap); 932 933 /** 934 * @brief Creates a empty pixelmap based on options {@link OH_Pixelmap_InitializationOptions}, 935 * the memory type used by the pixelmap can be specified by 936 * allocatorType {@link IMAGE_ALLOCATOR_MODE}. By default, the system selects the memory 937 * type based on the image type, image size, platform capability, etc. When processing the pixelmap returned by this 938 * interface, please always consider the impact of stride. 939 * 940 * @param options Pixelmap initialization properties including size, pixel format, alpha type, and editable flags. 941 * @param allocator Indicate which memory type will be used by the returned pixelmap. 942 * @param pixelmap Output parameter receiving the created pixelmap object pointer. 943 * @return Function result code: 944 * {@link IMAGE_SUCCESS} If the operation is successful. 945 * {@link IMAGE_BAD_PARAMETER} If the param is nullptr or invalid. 946 * {@link IMAGE_TOO_LARGE} too large data or image. 947 * {@link IMAGE_UNSUPPORTED_OPERATION} unsupported operations. 948 * {@link IMAGE_ALLOCATOR_MODE_UNSUPPROTED} unsupported allocator mode, e.g., use 949 * share memory to create a HDR image as only DMA supported hdr metadata. 950 * @since 20 951 */ 952 Image_ErrorCode OH_PixelmapNative_CreateEmptyPixelmapUsingAllocator( 953 OH_Pixelmap_InitializationOptions *options, IMAGE_ALLOCATOR_MODE allocator, OH_PixelmapNative **pixelmap); 954 955 /** 956 * @brief Convert the image format based on the input target pixel format. 957 * 958 * @param srcPixelMap Source Image PixelMap. 959 * @param destPixelMap Destination Image PixelMap. 960 * @param destPixelFormat Destination Image PixelFormat. 961 * @return Returns {@link Image_ErrorCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 962 * @since 12 963 */ 964 Image_ErrorCode OH_PixelMapNative_ConvertPixelFormat(OH_PixelmapNative *srcPixelMap, OH_PixelmapNative **destPixelMap, 965 int32_t destPixelFormat); 966 967 /** 968 * @brief Get metadata. 969 * 970 * @param pixelmap The Pixelmap pointer to be operated. 971 * @param key Type of metadata. 972 * @param value Value of metadata. 973 * @return Returns {@link Image_ErrorCode} IMAGE_SUCCESS - if the operation is successful. 974 * returns {@link Image_ErrorCode} IMAGE_BAD_PARAMETER - if invalid parameter, key and value are incorrect. 975 * returns {@link Image_ErrorCode} IMAGE_DMA_NOT_EXIST - if DMA memory dose not exist. 976 * returns {@link Image_ErrorCode} IMAGE_COPY_FAILED - if memory copy failed. 977 * @see OH_PixelMapNative 978 * @since 12 979 */ 980 Image_ErrorCode OH_PixelmapNative_GetMetadata(OH_PixelmapNative *pixelmap, OH_Pixelmap_HdrMetadataKey key, 981 OH_Pixelmap_HdrMetadataValue **value); 982 983 /** 984 * @brief Set metadata. 985 * 986 * @param pixelmap The Pixelmap pointer to be operated. 987 * @param key Type of metadata. 988 * @param value Value of metadata. 989 * @return Returns {@link Image_ErrorCode} IMAGE_SUCCESS - if the operation is successful. 990 * returns {@link Image_ErrorCode} IMAGE_BAD_PARAMETER - if invalid parameter, key and value are incorrect. 991 * returns {@link Image_ErrorCode} IMAGE_DMA_NOT_EXIST - if DMA memory dose not exist. 992 * returns {@link Image_ErrorCode} IMAGE_COPY_FAILED - if memory copy failed. 993 * @see OH_PixelMapNative 994 * @since 12 995 */ 996 Image_ErrorCode OH_PixelmapNative_SetMetadata(OH_PixelmapNative *pixelmap, OH_Pixelmap_HdrMetadataKey key, 997 OH_Pixelmap_HdrMetadataValue *value); 998 999 /** 1000 * @brief Get the native buffer from the PixelMap. 1001 * 1002 * @param pixelmap The PixelMap to get the native buffer from. 1003 * @param nativeBuffer The native buffer to retrieve. 1004 * @return Returns {@link Image_ErrorCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 1005 * returns {@link Image_ErrorCode} IMAGE_BAD_PARAMETER - if invalid parameter, pixelmap or nativeBuffer is null. 1006 * returns {@link Image_ErrorCode} IMAGE_DMA_NOT_EXIST - if DMA memory dose not exist. 1007 * returns {@link Image_ErrorCode} IMAGE_DMA_OPERATION_FAILED - if operations related to DMA memory has failed. 1008 * @see OH_PixelmapNative 1009 * @since 12 1010 */ 1011 Image_ErrorCode OH_PixelmapNative_GetNativeBuffer(OH_PixelmapNative *pixelmap, OH_NativeBuffer **nativeBuffer); 1012 1013 /** 1014 * @brief Get the native colorspace from the PixelMap. 1015 * 1016 * @param pixelmap The native pixelmap to get the native colorspace from. 1017 * @param colorSpaceNative The native colorspace to retrieve. 1018 * @return Function result code: 1019 * {@link IMAGE_SUCCESS} If the execution is successful. 1020 * {@link IMAGE_BAD_PARAMETER} The param of pixelmap or colorSpaceNative is nullptr or invalid. 1021 * @see OH_PixelmapNative 1022 * @since 13 1023 */ 1024 Image_ErrorCode OH_PixelmapNative_GetColorSpaceNative(OH_PixelmapNative *pixelmap, 1025 OH_NativeColorSpaceManager **colorSpaceNative); 1026 1027 /** 1028 * @brief Set the native colorspace for the PixelMap. 1029 * 1030 * @param pixelmap The native pixelmap to set the native colorspace for. 1031 * @param colorSpaceNative The native colorspace to set. 1032 * @return Function result code: 1033 * {@link IMAGE_SUCCESS} If the execution is successful. 1034 * {@link IMAGE_BAD_PARAMETER} The param of pixelmap or colorSpaceNative is nullptr or invalid. 1035 * @see OH_PixelmapNative 1036 * @since 13 1037 */ 1038 Image_ErrorCode OH_PixelmapNative_SetColorSpaceNative(OH_PixelmapNative *pixelmap, 1039 OH_NativeColorSpaceManager *colorSpaceNative); 1040 1041 /** 1042 * @brief Set pixelmap memory name. 1043 * 1044 * @param pixelmap The Pixelmap pointer to be operated. 1045 * @param name The pointer of name that needs to be set. 1046 * @param size The size of name size that needs to be set. 1047 * @return Function result code: 1048 * {@link IMAGE_SUCCESS} If the operation is successful. 1049 * {@link IMAGE_BAD_PARAMETER} If invalid parameter, name and size are incorrect. 1050 * {@link IMAGE_UNSUPPORTED_MEMORY_FORMAT} If memory format is unsupported. 1051 * @see OH_PixelmapNative 1052 * @since 13 1053 */ 1054 Image_ErrorCode OH_PixelmapNative_SetMemoryName(OH_PixelmapNative *pixelmap, char *name, size_t *size); 1055 1056 /** 1057 * @brief Get the total number of bytes occupied by all pixels in the Pixelmap, without any padding. 1058 * 1059 * @param pixelmap The Pixelmap pointer to be operated. 1060 * @param byteCount The total number of bytes to be retrieved. 1061 * @return Function result code: 1062 * {@link IMAGE_SUCCESS} If the operation is successful. 1063 * {@link IMAGE_BAD_PARAMETER} If invalid parameter, pixelmap or byteCount are invalid. 1064 * @see OH_PixelmapNative 1065 * @since 16 1066 */ 1067 Image_ErrorCode OH_PixelmapNative_GetByteCount(OH_PixelmapNative *pixelmap, uint32_t *byteCount); 1068 1069 /** 1070 * @brief Get the size of the allocated memory used to store this pixelmap's pixels. 1071 * 1072 * @param pixelmap The Pixelmap pointer to be operated. 1073 * @param allocationByteCount The size of the allocated memory. 1074 * @return Function result code: 1075 * {@link IMAGE_SUCCESS} If the operation is successful. 1076 * {@link IMAGE_BAD_PARAMETER} If invalid parameter, pixelmap or allocationByteCount are invalid. 1077 * @see OH_PixelmapNative 1078 * @since 16 1079 */ 1080 Image_ErrorCode OH_PixelmapNative_GetAllocationByteCount(OH_PixelmapNative *pixelmap, uint32_t *allocationByteCount); 1081 1082 /** 1083 * @brief Obtains the memory address of a PixelMap and locks the memory. 1084 * When the memory is locked, any operation that modifies or releases the PixelMap will fail and return 1085 * {@link IMAGE_BAD_PARAMETER}. 1086 * 1087 * @param pixelmap The PixelMap pointer to be operated. 1088 * @param addr The double pointer to the memory address of the PixelMap. 1089 * @return Function result code: 1090 * {@link IMAGE_SUCCESS} If the operation is successful. 1091 * {@link IMAGE_BAD_PARAMETER} If invalid parameter, pixelmap or addr are invalid. 1092 * {@link IMAGE_LOCK_UNLOCK_FAILED} If memory failed to be locked. 1093 * @see OH_PixelmapNative 1094 * @since 15 1095 */ 1096 Image_ErrorCode OH_PixelmapNative_AccessPixels(OH_PixelmapNative *pixelmap, void **addr); 1097 1098 /** 1099 * @brief Unlocks the memory of the PixelMap data. 1100 * This function is used with {@link OH_PixelmapNative_AccessPixels} in pairs. 1101 * 1102 * @param pixelmap The PixelMap pointer to be operated. 1103 * @return Function result code: 1104 * {@link IMAGE_SUCCESS} If the operation is successful. 1105 * {@link IMAGE_BAD_PARAMETER} If invalid parameter, pixelmap is invalid. 1106 * {@link IMAGE_LOCK_UNLOCK_FAILED} If memory failed to be unlocked. 1107 * @see OH_PixelmapNative 1108 * @since 15 1109 */ 1110 Image_ErrorCode OH_PixelmapNative_UnaccessPixels(OH_PixelmapNative *pixelmap); 1111 1112 #ifdef __cplusplus 1113 }; 1114 #endif 1115 /** @} */ 1116 #endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PIXELMAP_NATIVE_H 1117