• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     EXTERNAL_MAX,
139     INTERNAL_START = 100,
140     CMYK = INTERNAL_START + 1,
141     ASTC_4x4,
142     ASTC_6x6,
143     ASTC_8x8,
144 };
145 
146 enum class DecodeDynamicRange : int32_t {
147     AUTO = 0,
148     SDR = 1,
149     HDR = 2,
150 };
151 
152 enum class EncodeDynamicRange : int32_t {
153     AUTO = 0, //10bit jpeg will be encode as HDR_VIVID_DUAL, others will be encode as SDR
154     SDR,
155     HDR_VIVID_DUAL,
156     HDR_VIVID_SINGLE,
157 };
158 
159 enum class AlphaType : int32_t {
160     IMAGE_ALPHA_TYPE_UNKNOWN = 0,
161     IMAGE_ALPHA_TYPE_OPAQUE = 1,   // image pixels are stored as opaque.
162     IMAGE_ALPHA_TYPE_PREMUL = 2,   // image have alpha component, and all pixels have premultiplied by alpha value.
163     IMAGE_ALPHA_TYPE_UNPREMUL = 3, // image have alpha component, and all pixels stored without premultiply alpha value.
164 };
165 
166 enum class MemoryUsagePreference : int32_t {
167     DEFAULT = 0,
168     LOW_RAM = 1,  // low memory
169 };
170 
171 enum class FinalOutputStep : int32_t {
172     NO_CHANGE = 0,
173     CONVERT_CHANGE = 1,
174     ROTATE_CHANGE = 2,
175     SIZE_CHANGE = 3,
176     DENSITY_CHANGE = 4
177 };
178 
179 enum class ResolutionQuality : int32_t {
180     UNKNOWN = 0,
181     LOW = 1,
182     MEDIUM,
183     HIGH
184 };
185 
186 struct ColorYuv420 {
187     uint8_t colorY = 0;
188     uint8_t colorU = 0;
189     uint8_t colorV = 0;
190 };
191 
192 struct Position {
193     int32_t x = 0;
194     int32_t y = 0;
195 };
196 
197 struct Rect {
198     int32_t left = 0;
199     int32_t top = 0;
200     int32_t width = 0;
201     int32_t height = 0;
202 };
203 
204 struct Size {
205     int32_t width = 0;
206     int32_t height = 0;
207 };
208 
209 struct ImageInfo {
210     Size size;
211     PixelFormat pixelFormat = PixelFormat::UNKNOWN;
212     ColorSpace colorSpace = ColorSpace::SRGB;
213     AlphaType alphaType = AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
214     int32_t baseDensity = 0;
215     std::string encodedFormat;
216 };
217 
218 struct YUVDataInfo {
219     Size imageSize = {0, 0};
220     uint32_t yWidth = 0;
221     uint32_t yHeight = 0;
222     uint32_t uvWidth = 0;
223     uint32_t uvHeight = 0;
224     uint32_t yStride = 0;
225     uint32_t uStride = 0;
226     uint32_t vStride = 0;
227     uint32_t uvStride = 0;
228     uint32_t yOffset = 0;
229     uint32_t uOffset = 0;
230     uint32_t vOffset = 0;
231     uint32_t uvOffset = 0;
232 };
233 
234 struct Convert10bitInfo {
235     PixelFormat srcPixelFormat = PixelFormat::UNKNOWN;
236     uint32_t srcBytes = 0;
237     PixelFormat dstPixelFormat = PixelFormat::UNKNOWN;
238     uint32_t dstBytes = 0;
239 };
240 
241 struct YUVStrideInfo {
242     uint32_t yStride = 0;
243     uint32_t uvStride = 0;
244     uint32_t yOffset = 0;
245     uint32_t uvOffset = 0;
246 };
247 
248 struct RGBDataInfo {
249     int32_t width = 0;
250     int32_t height = 0;
251     uint32_t stride = 0;
252 };
253 
254 struct DestConvertInfo {
255     uint32_t width = 0;
256     uint32_t height = 0;
257     PixelFormat format = PixelFormat::UNKNOWN;
258     AllocatorType allocType = AllocatorType::SHARE_MEM_ALLOC;
259     uint8_t *buffer = nullptr;
260     uint32_t bufferSize = 0;
261     uint32_t yStride = 0;
262     uint32_t uvStride = 0;
263     uint32_t yOffset = 0;
264     uint32_t uvOffset = 0;
265     void *context = nullptr;
266 };
267 
268 struct SrcConvertParam {
269     uint32_t width = 0;
270     uint32_t height = 0;
271     AllocatorType allocType = AllocatorType::SHARE_MEM_ALLOC ;
272     PixelFormat format = PixelFormat::UNKNOWN;
273     const uint8_t *buffer = nullptr;
274     uint32_t bufferSize = 0;
275     int stride[4] = {0, 0, 0, 0};
276     const uint8_t *slice[4] = {nullptr, nullptr, nullptr, nullptr};
277 };
278 
279 struct DestConvertParam {
280     uint32_t width = 0;
281     uint32_t height = 0;
282     AllocatorType allocType = AllocatorType::SHARE_MEM_ALLOC;
283     PixelFormat format = PixelFormat::UNKNOWN;
284     uint8_t *buffer = nullptr;
285     uint32_t bufferSize = 0;
286     int stride[4] = {0, 0, 0, 0};
287     uint8_t *slice[4] = {nullptr, nullptr, nullptr, nullptr};
288 };
289 
290 struct FillColor {
291     bool isValidColor = false;
292     uint32_t color = 0;
293 };
294 
295 struct SVGResize {
296     bool isValidPercentage = false;
297     uint32_t resizePercentage = 100;
298 };
299 
300 struct SVGDecodeOptions {
301     FillColor fillColor;
302     FillColor strokeColor;
303     SVGResize SVGResize;
304 };
305 
306 struct DecodeOptions {
307     int32_t fitDensity = 0;
308     Rect CropRect;
309     Size desiredSize;
310     Rect desiredRegion;
311     float rotateDegrees = 0;
312     uint32_t rotateNewDegrees = 0;
313     static constexpr uint32_t DEFAULT_SAMPLE_SIZE = 1;
314     uint32_t sampleSize = DEFAULT_SAMPLE_SIZE;
315     PixelFormat desiredPixelFormat = PixelFormat::UNKNOWN;
316 #if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM)
317     AllocatorType allocatorType = AllocatorType::HEAP_ALLOC;
318 #else
319     AllocatorType allocatorType = AllocatorType::DEFAULT;
320 #endif
321     ColorSpace desiredColorSpace = ColorSpace::SRGB;
322     bool allowPartialImage = true;
323     bool editable = false;
324     MemoryUsagePreference preference = MemoryUsagePreference::DEFAULT;
325     SVGDecodeOptions SVGOpts;
326     std::shared_ptr<OHOS::ColorManager::ColorSpace> desiredColorSpaceInfo = nullptr;
327     bool preferDma = false;
328     bool fastAstc = false;
329     uint16_t invokeType = 0;
330     DecodeDynamicRange desiredDynamicRange = DecodeDynamicRange::SDR;
331     ResolutionQuality resolutionQuality = ResolutionQuality::UNKNOWN;
332     bool isAisr = false;
333 };
334 
335 enum class ScaleMode : int32_t {
336     FIT_TARGET_SIZE = 0,
337     CENTER_CROP = 1,
338 };
339 
340 enum class IncrementalMode { FULL_DATA = 0, INCREMENTAL_DATA = 1 };
341 
342 // used in ScalePixelMapEx
343 enum class AntiAliasingOption : int32_t {
344     NONE = 0, // SWS_POINT_NEAREST
345     LOW = 1, // SWS_BILINEAR
346     MEDIUM = 2, // SWS_BICUBIC
347     HIGH = 3, // SWS_AREA
348     FAST_BILINEAER = 4, // SWS_FAST_BILINEAER
349     BICUBLIN = 5, // SWS_AREA
350     GAUSS = 6, // SWS_GAUSS
351     SINC = 7, // SWS_SINC
352     LANCZOS = 8, // SWS_LANCZOS
353     SPLINE = 9, // SWS_SPLINE
354     SLR = 10, // SLR
355 };
356 
357 enum class AuxiliaryPictureType {
358     NONE = 0,
359     GAINMAP = 1,
360     DEPTH_MAP = 2,
361     UNREFOCUS_MAP = 3,
362     LINEAR_MAP = 4,
363     FRAGMENT_MAP = 5,
364 };
365 
366 struct AuxiliaryPictureInfo {
367     AuxiliaryPictureType auxiliaryPictureType = AuxiliaryPictureType::NONE;
368     Size size;
369     uint32_t rowStride = 0;
370     PixelFormat pixelFormat = PixelFormat::UNKNOWN;
371     ColorSpace colorSpace = ColorSpace::SRGB;
372     std::string jpegTagName = "";
373 };
374 
375 enum class MetadataType {
376     EXIF = 1,
377     FRAGMENT = 2,
378 };
379 
380 struct DecodingOptionsForPicture {
381     std::set<AuxiliaryPictureType> desireAuxiliaryPictures;
382 };
383 
384 typedef struct PictureError {
385     uint32_t errorCode = 0;
386     std::string errorInfo = "";
387 } PICTURE_ERR;
388 
389 struct MaintenanceData {
390     std::shared_ptr<uint8_t[]> data_;
391     size_t size_ = 0;
MaintenanceDataMaintenanceData392     MaintenanceData(std::shared_ptr<uint8_t[]> data, size_t size) : data_(data), size_(size) {}
393 };
394 
395 } // namespace Media
396 } // namespace OHOS
397 
398 #endif // INTERFACES_INNERKITS_INCLUDE_IMAGE_TYPE_H_
399