1 /* 2 * Copyright (C) 2021 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 #ifndef INTERFACES_INNERKITS_INCLUDE_IMAGE_TYPE_H_ 17 #define INTERFACES_INNERKITS_INCLUDE_IMAGE_TYPE_H_ 18 19 #include <cinttypes> 20 #include <set> 21 #include <string> 22 #include <sstream> 23 #include <vector> 24 #include "color_space.h" 25 26 namespace OHOS { 27 namespace Media { 28 #ifdef _WIN32 29 #define NATIVEEXPORT __declspec(dllexport) 30 #else 31 #define NATIVEEXPORT 32 #endif 33 34 #define FRAGMENT_METADATA_KEY_X "XInOriginal" 35 #define FRAGMENT_METADATA_KEY_Y "YInOriginal" 36 #define FRAGMENT_METADATA_KEY_WIDTH "FragmentImageWidth" 37 #define FRAGMENT_METADATA_KEY_HEIGHT "FragmentImageHeight" 38 39 #define GIF_METADATA_KEY_DELAY_TIME "GifDelayTime" 40 #define GIF_METADATA_KEY_DISPOSAL_TYPE "GifDisposalType" 41 42 // There is no definite tag name for gainmap 43 #define AUXILIARY_TAG_GAINMAP "" 44 #define AUXILIARY_TAG_DEPTH_MAP_BACK "DepthP" 45 #define AUXILIARY_TAG_DEPTH_MAP_FRONT "VShapEn" 46 #define AUXILIARY_TAG_UNREFOCUS_MAP "edof" 47 #define AUXILIARY_TAG_LINEAR_MAP "HighBit" 48 #define AUXILIARY_TAG_FRAGMENT_MAP "Fragmnt" 49 50 #define HEIF_AUXTTYPE_ID_GAINMAP "urn:iso:std:iso:ts:21496:-1" 51 #define HEIF_AUXTTYPE_ID_DEPTH_MAP "urn:com:huawei:photo:5:0:0:aux:depthmap" 52 #define HEIF_AUXTTYPE_ID_UNREFOCUS_MAP "urn:com:huawei:photo:5:0:0:aux:unrefocusmap" 53 #define HEIF_AUXTTYPE_ID_LINEAR_MAP "urn:com:huawei:photo:5:0:0:aux:linearhmap" 54 #define HEIF_AUXTTYPE_ID_FRAGMENT_MAP "urn:com:huawei:photo:5:0:0:aux:fragmentmap" 55 56 constexpr uint8_t ASTC_EXTEND_INFO_TLV_NUM_6 = 6; 57 58 #define RFIMAGE_ID "urn:com:huawei:photo:5:1:0:meta:Res-Map" 59 #define METADATA_TAG_RESMAP "Res-Map\0" 60 61 enum class AllocatorType : int32_t { 62 // keep same with java AllocatorType 63 DEFAULT = 0, 64 HEAP_ALLOC = 1, 65 SHARE_MEM_ALLOC = 2, 66 CUSTOM_ALLOC = 3, // external 67 DMA_ALLOC = 4, // SurfaceBuffer 68 }; 69 70 enum class ColorSpace : int32_t { 71 // unknown color space. 72 UNKNOWN = 0, 73 74 // based on SMPTE RP 431-2-2007 & IEC 61966-2.1:1999. 75 DISPLAY_P3 = 1, 76 77 // standard Red Green Blue based on IEC 61966-2.1:1999. 78 SRGB = 2, 79 80 // SRGB with a linear transfer function based on IEC 61966-2.1:1999. 81 LINEAR_SRGB = 3, 82 83 // based on IEC 61966-2-2:2003. 84 EXTENDED_SRGB = 4, 85 86 // based on IEC 61966-2-2:2003. 87 LINEAR_EXTENDED_SRGB = 5, 88 89 // based on standard illuminant D50 as the white point. 90 GENERIC_XYZ = 6, 91 92 // based on CIE XYZ D50 as the profile conversion space. 93 GENERIC_LAB = 7, 94 95 // based on SMPTE ST 2065-1:2012. 96 ACES = 8, 97 98 // based on Academy S-2014-004. 99 ACES_CG = 9, 100 101 // based on Adobe RGB (1998). 102 ADOBE_RGB_1998 = 10, 103 104 // based on SMPTE RP 431-2-2007. 105 DCI_P3 = 11, 106 107 // based on Rec. ITU-R BT.709-5. 108 ITU_709 = 12, 109 110 // based on Rec. ITU-R BT.2020-1. 111 ITU_2020 = 13, 112 113 // based on ROMM RGB ISO 22028-2:2013. 114 ROMM_RGB = 14, 115 116 // based on 1953 standard. 117 NTSC_1953 = 15, 118 119 // based on SMPTE C. 120 SMPTE_C = 16, 121 }; 122 123 enum class EncodedFormat : int32_t { 124 UNKNOWN = 0, 125 JPEG = 1, 126 PNG = 2, 127 GIF = 3, 128 HEIF = 4, 129 WEBP = 5, 130 DNG = 6 131 }; 132 133 enum class PixelFormat : int32_t { 134 UNKNOWN = 0, 135 ARGB_8888 = 1, // Each pixel is stored on 4 bytes. 136 RGB_565 = 2, // Each pixel is stored on 2 bytes 137 RGBA_8888 = 3, 138 BGRA_8888 = 4, 139 RGB_888 = 5, 140 ALPHA_8 = 6, 141 RGBA_F16 = 7, 142 NV21 = 8, // Each pixel is sorted on 3/2 bytes. 143 NV12 = 9, 144 RGBA_1010102 = 10, 145 YCBCR_P010 = 11, // NV12_P010 146 YCRCB_P010 = 12, // NV21_P010 147 RGBA_U16 = 13, // Interim format for ffmpeg and skia conversion 148 YUV_400 = 14, 149 EXTERNAL_MAX, 150 INTERNAL_START = 100, 151 CMYK = INTERNAL_START + 1, 152 ASTC_4x4 = 102, 153 ASTC_6x6, 154 ASTC_8x8, 155 }; 156 157 enum class DecodeDynamicRange : int32_t { 158 AUTO = 0, 159 SDR = 1, 160 HDR = 2, 161 }; 162 163 enum class EncodeDynamicRange : int32_t { 164 AUTO = 0, //10bit jpeg will be encode as HDR_VIVID_DUAL, others will be encode as SDR 165 SDR, 166 HDR_VIVID_DUAL, 167 HDR_VIVID_SINGLE, 168 }; 169 170 enum class AlphaType : int32_t { 171 IMAGE_ALPHA_TYPE_UNKNOWN = 0, 172 IMAGE_ALPHA_TYPE_OPAQUE = 1, // image pixels are stored as opaque. 173 IMAGE_ALPHA_TYPE_PREMUL = 2, // image have alpha component, and all pixels have premultiplied by alpha value. 174 IMAGE_ALPHA_TYPE_UNPREMUL = 3, // image have alpha component, and all pixels stored without premultiply alpha value. 175 }; 176 177 enum class MemoryUsagePreference : int32_t { 178 DEFAULT = 0, 179 LOW_RAM = 1, // low memory 180 }; 181 182 enum class FinalOutputStep : int32_t { 183 NO_CHANGE = 0, 184 CONVERT_CHANGE = 1, 185 ROTATE_CHANGE = 2, 186 SIZE_CHANGE = 3, 187 DENSITY_CHANGE = 4 188 }; 189 190 enum class ResolutionQuality : int32_t { 191 UNKNOWN = 0, 192 LOW = 1, 193 MEDIUM, 194 HIGH 195 }; 196 197 struct ColorYuv420 { 198 uint8_t colorY = 0; 199 uint8_t colorU = 0; 200 uint8_t colorV = 0; 201 }; 202 203 struct Position { 204 int32_t x = 0; 205 int32_t y = 0; 206 }; 207 208 struct Rect { 209 int32_t left = 0; 210 int32_t top = 0; 211 int32_t width = 0; 212 int32_t height = 0; 213 }; 214 215 struct Size { 216 int32_t width = 0; 217 int32_t height = 0; 218 }; 219 220 struct ImageInfo { 221 Size size; 222 PixelFormat pixelFormat = PixelFormat::UNKNOWN; 223 ColorSpace colorSpace = ColorSpace::SRGB; 224 AlphaType alphaType = AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN; 225 int32_t baseDensity = 0; 226 std::string encodedFormat; 227 }; 228 229 struct YUVDataInfo { 230 Size imageSize = {0, 0}; 231 uint32_t yWidth = 0; 232 uint32_t yHeight = 0; 233 uint32_t uvWidth = 0; 234 uint32_t uvHeight = 0; 235 uint32_t yStride = 0; 236 uint32_t uStride = 0; 237 uint32_t vStride = 0; 238 uint32_t uvStride = 0; 239 uint32_t yOffset = 0; 240 uint32_t uOffset = 0; 241 uint32_t vOffset = 0; 242 uint32_t uvOffset = 0; ToStringYUVDataInfo243 std::string ToString() const { 244 std::stringstream message; 245 message << " yWidth: " << yWidth << ", yHeight: " << yHeight << ", uvWidth: " << uvWidth << 246 ", uvHeight: " << uvHeight << ", yStride: " << yStride << ", uStride: " << uStride << 247 ", vStride: " << vStride << ", uvStride: " << uvStride << ", yOffset: " << yOffset << 248 ", uOffset: " << uOffset << ", vOffset: " << vOffset << ", uvOffset: " << uvOffset; 249 return message.str(); 250 } 251 }; 252 253 struct Convert10bitInfo { 254 PixelFormat srcPixelFormat = PixelFormat::UNKNOWN; 255 uint32_t srcBytes = 0; 256 PixelFormat dstPixelFormat = PixelFormat::UNKNOWN; 257 uint32_t dstBytes = 0; 258 }; 259 260 struct YUVStrideInfo { 261 uint32_t yStride = 0; 262 uint32_t uvStride = 0; 263 uint32_t yOffset = 0; 264 uint32_t uvOffset = 0; 265 }; 266 267 struct RGBDataInfo { 268 int32_t width = 0; 269 int32_t height = 0; 270 uint32_t stride = 0; 271 }; 272 273 struct DestConvertInfo { 274 uint32_t width = 0; 275 uint32_t height = 0; 276 PixelFormat format = PixelFormat::UNKNOWN; 277 AllocatorType allocType = AllocatorType::SHARE_MEM_ALLOC; 278 uint8_t *buffer = nullptr; 279 uint32_t bufferSize = 0; 280 uint32_t yStride = 0; 281 uint32_t uvStride = 0; 282 uint32_t yOffset = 0; 283 uint32_t uvOffset = 0; 284 void *context = nullptr; 285 }; 286 287 struct SrcConvertParam { 288 uint32_t width = 0; 289 uint32_t height = 0; 290 AllocatorType allocType = AllocatorType::SHARE_MEM_ALLOC ; 291 PixelFormat format = PixelFormat::UNKNOWN; 292 const uint8_t *buffer = nullptr; 293 uint32_t bufferSize = 0; 294 int stride[4] = {0, 0, 0, 0}; 295 const uint8_t *slice[4] = {nullptr, nullptr, nullptr, nullptr}; 296 }; 297 298 struct DestConvertParam { 299 uint32_t width = 0; 300 uint32_t height = 0; 301 AllocatorType allocType = AllocatorType::SHARE_MEM_ALLOC; 302 PixelFormat format = PixelFormat::UNKNOWN; 303 uint8_t *buffer = nullptr; 304 uint32_t bufferSize = 0; 305 int stride[4] = {0, 0, 0, 0}; 306 uint8_t *slice[4] = {nullptr, nullptr, nullptr, nullptr}; 307 }; 308 309 struct FillColor { 310 bool isValidColor = false; 311 uint32_t color = 0; 312 }; 313 314 struct SVGResize { 315 bool isValidPercentage = false; 316 uint32_t resizePercentage = 100; 317 }; 318 319 struct SVGDecodeOptions { 320 FillColor fillColor; 321 FillColor strokeColor; 322 SVGResize SVGResize; 323 }; 324 325 enum class CropAndScaleStrategy : int32_t { 326 DEFAULT = 0, 327 /** 328 * First scale, then crop. 329 */ 330 SCALE_FIRST = 1, 331 /** 332 * Perform region decoding first, then scaling. 333 */ 334 CROP_FIRST = 2 335 }; 336 337 class PixelMap; 338 struct DecodeOptions { 339 int32_t fitDensity = 0; 340 Rect CropRect; 341 Size desiredSize; 342 Rect desiredRegion; 343 float rotateDegrees = 0; 344 uint32_t rotateNewDegrees = 0; 345 static constexpr uint32_t DEFAULT_SAMPLE_SIZE = 1; 346 uint32_t sampleSize = DEFAULT_SAMPLE_SIZE; 347 PixelFormat desiredPixelFormat = PixelFormat::UNKNOWN; 348 PixelFormat photoDesiredPixelFormat = PixelFormat::UNKNOWN; 349 #if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM) 350 AllocatorType allocatorType = AllocatorType::HEAP_ALLOC; 351 #else 352 AllocatorType allocatorType = AllocatorType::DEFAULT; 353 #endif 354 ColorSpace desiredColorSpace = ColorSpace::SRGB; 355 bool allowPartialImage = true; 356 bool editable = false; 357 MemoryUsagePreference preference = MemoryUsagePreference::DEFAULT; 358 SVGDecodeOptions SVGOpts; 359 std::shared_ptr<OHOS::ColorManager::ColorSpace> desiredColorSpaceInfo = nullptr; 360 bool preferDma = false; 361 bool fastAstc = false; 362 uint16_t invokeType = 0; 363 DecodeDynamicRange desiredDynamicRange = DecodeDynamicRange::SDR; 364 ResolutionQuality resolutionQuality = ResolutionQuality::UNKNOWN; 365 bool isAisr = false; 366 // CreatePixelMapUsingAllocatorType is true, CreatePixelMap is false. 367 bool isAppUseAllocator = false; 368 std::shared_ptr<PixelMap> reusePixelmap = nullptr; 369 CropAndScaleStrategy cropAndScaleStrategy = CropAndScaleStrategy::DEFAULT; 370 bool isCreateWideGamutSdrPixelMap = false; 371 }; 372 373 enum class ScaleMode : int32_t { 374 FIT_TARGET_SIZE = 0, 375 CENTER_CROP = 1, 376 }; 377 378 enum class IncrementalMode { FULL_DATA = 0, INCREMENTAL_DATA = 1 }; 379 380 // used in ScalePixelMapEx 381 enum class AntiAliasingOption : int32_t { 382 NONE = 0, // SWS_POINT_NEAREST 383 LOW = 1, // SWS_BILINEAR 384 MEDIUM = 2, // SWS_BICUBIC 385 HIGH = 3, // SWS_AREA 386 FAST_BILINEAER = 4, // SWS_FAST_BILINEAER 387 BICUBLIN = 5, // SWS_AREA 388 GAUSS = 6, // SWS_GAUSS 389 SINC = 7, // SWS_SINC 390 LANCZOS = 8, // SWS_LANCZOS 391 SPLINE = 9, // SWS_SPLINE 392 SLR = 10, // SLR 393 }; 394 395 enum class AuxiliaryPictureType { 396 NONE = 0, 397 GAINMAP = 1, 398 DEPTH_MAP = 2, 399 UNREFOCUS_MAP = 3, 400 LINEAR_MAP = 4, 401 FRAGMENT_MAP = 5, 402 }; 403 404 struct AuxiliaryPictureInfo { 405 AuxiliaryPictureType auxiliaryPictureType = AuxiliaryPictureType::NONE; 406 Size size; 407 uint32_t rowStride = 0; 408 PixelFormat pixelFormat = PixelFormat::UNKNOWN; 409 ColorSpace colorSpace = ColorSpace::SRGB; 410 std::string jpegTagName = ""; 411 }; 412 413 enum class MetadataType { 414 EXIF = 1, 415 FRAGMENT = 2, 416 GIF = 5, 417 UNKNOWN = 0 418 }; 419 420 struct DecodingOptionsForPicture { 421 std::set<AuxiliaryPictureType> desireAuxiliaryPictures; 422 PixelFormat desiredPixelFormat = PixelFormat::RGBA_8888; 423 AllocatorType allocatorType = AllocatorType::DMA_ALLOC; 424 }; 425 426 typedef struct PictureError { 427 uint32_t errorCode = 0; 428 std::string errorInfo = ""; 429 } PICTURE_ERR; 430 431 struct MaintenanceData { 432 std::shared_ptr<uint8_t[]> data_; 433 size_t size_ = 0; MaintenanceDataMaintenanceData434 MaintenanceData(std::shared_ptr<uint8_t[]> data, size_t size) : data_(data), size_(size) {} 435 }; 436 437 enum class YuvConversion : int { 438 BT601 = 0, 439 BT709 = 1, 440 BT2020 = 2, 441 BT240 = 3, 442 BTFCC = 4, 443 BT_MAX, 444 }; 445 446 struct YUVConvertColorSpaceDetails { 447 // Range: 0 means limit range, 1 means full range. 448 uint8_t srcRange = 0; 449 uint8_t dstRange = 0; 450 YuvConversion srcYuvConversion = YuvConversion::BT601; 451 YuvConversion dstYuvConversion = YuvConversion::BT601; 452 }; 453 454 struct AstcMetadata { 455 std::vector<uint8_t> hdrMetadataTypeVec; 456 std::vector<uint8_t> colorSpaceInfoVec; 457 std::vector<uint8_t> staticData; 458 std::vector<uint8_t> dynamicData; 459 }; 460 461 struct AstcExtendInfo { 462 uint32_t extendBufferSumBytes = 0; 463 uint8_t extendNums = ASTC_EXTEND_INFO_TLV_NUM_6; 464 uint8_t extendInfoType[ASTC_EXTEND_INFO_TLV_NUM_6]; 465 uint32_t extendInfoLength[ASTC_EXTEND_INFO_TLV_NUM_6]; 466 uint8_t *extendInfoValue[ASTC_EXTEND_INFO_TLV_NUM_6]; 467 AstcMetadata astcMetadata; // metadata for astc 468 }; 469 470 enum class AstcExtendInfoType : uint8_t { 471 COLOR_SPACE = 0, 472 PIXEL_FORMAT = 1, 473 HDR_METADATA_TYPE = 2, 474 HDR_COLORSPACE_INFO = 3, 475 HDR_STATIC_DATA = 4, 476 HDR_DYNAMIC_DATA = 5, 477 }; 478 } // namespace Media 479 } // namespace OHOS 480 481 #endif // INTERFACES_INNERKITS_INCLUDE_IMAGE_TYPE_H_ 482