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