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