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 IMAGE_TYPE_H 17 #define IMAGE_TYPE_H 18 19 #include <inttypes.h> 20 21 namespace OHOS { 22 namespace Media { 23 #ifdef _WIN32 24 #define NATIVEEXPORT __declspec(dllexport) 25 #else 26 #define NATIVEEXPORT 27 #endif 28 29 enum class AllocatorType : int32_t { 30 // keep same with java AllocatorType 31 DEFAULT = 0, 32 HEAP_ALLOC = 1, 33 SHARE_MEM_ALLOC = 2, 34 CUSTOM_ALLOC = 3, // external 35 }; 36 37 enum class ColorSpace : int32_t { 38 // unknown color space. 39 UNKNOWN = 0, 40 41 // based on SMPTE RP 431-2-2007 & IEC 61966-2.1:1999. 42 DISPLAY_P3 = 1, 43 44 // standard Red Green Blue based on IEC 61966-2.1:1999. 45 SRGB = 2, 46 47 // SRGB with a linear transfer function based on IEC 61966-2.1:1999. 48 LINEAR_SRGB = 3, 49 50 // based on IEC 61966-2-2:2003. 51 EXTENDED_SRGB = 4, 52 53 // based on IEC 61966-2-2:2003. 54 LINEAR_EXTENDED_SRGB = 5, 55 56 // based on standard illuminant D50 as the white point. 57 GENERIC_XYZ = 6, 58 59 // based on CIE XYZ D50 as the profile conversion space. 60 GENERIC_LAB = 7, 61 62 // based on SMPTE ST 2065-1:2012. 63 ACES = 8, 64 65 // based on Academy S-2014-004. 66 ACES_CG = 9, 67 68 // based on Adobe RGB (1998). 69 ADOBE_RGB_1998 = 10, 70 71 // based on SMPTE RP 431-2-2007. 72 DCI_P3 = 11, 73 74 // based on Rec. ITU-R BT.709-5. 75 ITU_709 = 12, 76 77 // based on Rec. ITU-R BT.2020-1. 78 ITU_2020 = 13, 79 80 // based on ROMM RGB ISO 22028-2:2013. 81 ROMM_RGB = 14, 82 83 // based on 1953 standard. 84 NTSC_1953 = 15, 85 86 // based on SMPTE C. 87 SMPTE_C = 16, 88 }; 89 90 enum class EncodedFormat : int32_t { 91 UNKNOWN = 0, 92 JPEG = 1, 93 PNG = 2, 94 GIF = 3, 95 HEIF = 4, 96 }; 97 98 enum class PixelFormat : int32_t { 99 UNKNOWN = 0, 100 ARGB_8888 = 1, // Each pixel is stored on 4 bytes. 101 RGB_565 = 2, // Each pixel is stored on 2 bytes 102 RGBA_8888 = 3, 103 BGRA_8888 = 4, 104 RGB_888 = 5, 105 ALPHA_8 = 6, 106 RGBA_F16 = 7, 107 NV21 = 8, // Each pixel is sotred on 3/2 bytes. 108 NV12 = 9, 109 CMYK = 10, 110 }; 111 112 enum class AlphaType : int32_t { 113 IMAGE_ALPHA_TYPE_UNKNOWN = 0, 114 IMAGE_ALPHA_TYPE_OPAQUE = 1, // image pixels are stored as opaque. 115 IMAGE_ALPHA_TYPE_PREMUL = 2, // image have alpha component, and all pixels have premultiplied by alpha value. 116 IMAGE_ALPHA_TYPE_UNPREMUL = 3, // image have alpha component, and all pixels stored without premultiply alpha value. 117 }; 118 119 enum class MemoryUsagePreference : int32_t { 120 DEFAULT = 0, 121 LOW_RAM = 1, // low memory 122 }; 123 124 enum class FinalOutputStep : int32_t { 125 NO_CHANGE = 0, 126 CONVERT_CHANGE = 1, 127 ROTATE_CHANGE = 2, 128 SIZE_CHANGE = 3, 129 DENSITY_CHANGE = 4 130 }; 131 132 struct Position { 133 int32_t x = 0; 134 int32_t y = 0; 135 }; 136 137 struct Rect { 138 int32_t left = 0; 139 int32_t top = 0; 140 int32_t width = 0; 141 int32_t height = 0; 142 }; 143 144 struct Size { 145 int32_t width = 0; 146 int32_t height = 0; 147 }; 148 149 struct ImageInfo { 150 Size size; 151 PixelFormat pixelFormat = PixelFormat::UNKNOWN; 152 ColorSpace colorSpace = ColorSpace::SRGB; 153 AlphaType alphaType = AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN; 154 int32_t baseDensity = 0; 155 }; 156 157 struct DecodeOptions { 158 int32_t fitDensity = 0; 159 Rect CropRect; 160 Size desiredSize; 161 Rect desiredRegion; 162 float rotateDegrees = 0; 163 uint32_t rotateNewDegrees = 0; 164 static constexpr uint32_t DEFAULT_SAMPLE_SIZE = 1; 165 uint32_t sampleSize = DEFAULT_SAMPLE_SIZE; 166 PixelFormat desiredPixelFormat = PixelFormat::UNKNOWN; 167 AllocatorType allocatorType = AllocatorType::HEAP_ALLOC; 168 ColorSpace desiredColorSpace = ColorSpace::SRGB; 169 bool allowPartialImage = true; 170 bool editable = false; 171 MemoryUsagePreference preference = MemoryUsagePreference::DEFAULT; 172 }; 173 174 enum class ScaleMode : int32_t { 175 FIT_TARGET_SIZE = 0, 176 CENTER_CROP = 1, 177 }; 178 179 enum class IncrementalMode { FULL_DATA = 0, INCREMENTAL_DATA = 1 }; 180 } // namespace Media 181 } // namespace OHOS 182 183 #endif // IMAGE_TYPE_H 184