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,
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 struct DecodeOptions {
308     int32_t fitDensity = 0;
309     Rect CropRect;
310     Size desiredSize;
311     Rect desiredRegion;
312     float rotateDegrees = 0;
313     uint32_t rotateNewDegrees = 0;
314     static constexpr uint32_t DEFAULT_SAMPLE_SIZE = 1;
315     uint32_t sampleSize = DEFAULT_SAMPLE_SIZE;
316     PixelFormat desiredPixelFormat = PixelFormat::UNKNOWN;
317     PixelFormat photoDesiredPixelFormat = PixelFormat::UNKNOWN;
318 #if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM)
319     AllocatorType allocatorType = AllocatorType::HEAP_ALLOC;
320 #else
321     AllocatorType allocatorType = AllocatorType::DEFAULT;
322 #endif
323     ColorSpace desiredColorSpace = ColorSpace::SRGB;
324     bool allowPartialImage = true;
325     bool editable = false;
326     MemoryUsagePreference preference = MemoryUsagePreference::DEFAULT;
327     SVGDecodeOptions SVGOpts;
328     std::shared_ptr<OHOS::ColorManager::ColorSpace> desiredColorSpaceInfo = nullptr;
329     bool preferDma = false;
330     bool fastAstc = false;
331     uint16_t invokeType = 0;
332     DecodeDynamicRange desiredDynamicRange = DecodeDynamicRange::SDR;
333     ResolutionQuality resolutionQuality = ResolutionQuality::UNKNOWN;
334     bool isAisr = false;
335 };
336 
337 enum class ScaleMode : int32_t {
338     FIT_TARGET_SIZE = 0,
339     CENTER_CROP = 1,
340 };
341 
342 enum class IncrementalMode { FULL_DATA = 0, INCREMENTAL_DATA = 1 };
343 
344 // used in ScalePixelMapEx
345 enum class AntiAliasingOption : int32_t {
346     NONE = 0, // SWS_POINT_NEAREST
347     LOW = 1, // SWS_BILINEAR
348     MEDIUM = 2, // SWS_BICUBIC
349     HIGH = 3, // SWS_AREA
350     FAST_BILINEAER = 4, // SWS_FAST_BILINEAER
351     BICUBLIN = 5, // SWS_AREA
352     GAUSS = 6, // SWS_GAUSS
353     SINC = 7, // SWS_SINC
354     LANCZOS = 8, // SWS_LANCZOS
355     SPLINE = 9, // SWS_SPLINE
356     SLR = 10, // SLR
357 };
358 
359 enum class AuxiliaryPictureType {
360     NONE = 0,
361     GAINMAP = 1,
362     DEPTH_MAP = 2,
363     UNREFOCUS_MAP = 3,
364     LINEAR_MAP = 4,
365     FRAGMENT_MAP = 5,
366 };
367 
368 struct AuxiliaryPictureInfo {
369     AuxiliaryPictureType auxiliaryPictureType = AuxiliaryPictureType::NONE;
370     Size size;
371     uint32_t rowStride = 0;
372     PixelFormat pixelFormat = PixelFormat::UNKNOWN;
373     ColorSpace colorSpace = ColorSpace::SRGB;
374     std::string jpegTagName = "";
375 };
376 
377 enum class MetadataType {
378     EXIF = 1,
379     FRAGMENT = 2,
380 };
381 
382 struct DecodingOptionsForPicture {
383     std::set<AuxiliaryPictureType> desireAuxiliaryPictures;
384     PixelFormat desiredPixelFormat = PixelFormat::RGBA_8888;
385     AllocatorType allocatorType = AllocatorType::DMA_ALLOC;
386 };
387 
388 typedef struct PictureError {
389     uint32_t errorCode = 0;
390     std::string errorInfo = "";
391 } PICTURE_ERR;
392 
393 struct MaintenanceData {
394     std::shared_ptr<uint8_t[]> data_;
395     size_t size_ = 0;
MaintenanceDataMaintenanceData396     MaintenanceData(std::shared_ptr<uint8_t[]> data, size_t size) : data_(data), size_(size) {}
397 };
398 
399 } // namespace Media
400 } // namespace OHOS
401 
402 #endif // INTERFACES_INNERKITS_INCLUDE_IMAGE_TYPE_H_
403