1 /* 2 */ 3 4 /* 5 6 Copyright (C) 2014 Ferrero Andrea 7 8 This program is free software: you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation, either version 3 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program. If not, see <http://www.gnu.org/licenses/>. 20 21 22 */ 23 24 /* 25 26 These files are distributed with PhotoFlow - http://aferrero2707.github.io/PhotoFlow/ 27 28 */ 29 30 #include "format_info.hh" 31 32 33 namespace PF { 34 35 int8_t FormatInfo<int8_t>::MIN = SCHAR_MIN; 36 int8_t FormatInfo<int8_t>::MAX = SCHAR_MAX; 37 int8_t FormatInfo<int8_t>::HALF = 0; 38 FormatInfo<int8_t>::PROMOTED FormatInfo<int8_t>::RANGE = 39 (FormatInfo<int8_t>::PROMOTED)FormatInfo<int8_t>::MAX - FormatInfo<int8_t>::MIN; 40 41 42 uint8_t FormatInfo<uint8_t>::MIN = 0; 43 uint8_t FormatInfo<uint8_t>::MAX = UCHAR_MAX; 44 uint8_t FormatInfo<uint8_t>::HALF = UCHAR_MAX/2; 45 FormatInfo<uint8_t>::PROMOTED FormatInfo<uint8_t>::RANGE = FormatInfo<uint8_t>::MAX; 46 47 template<> 48 bool FormatInfo<float>::IS_FLOAT = true; 49 50 // 16-bit base types 51 #if (USHRT_MAX == 65535U) 52 #define PF_USHRT_MAX USHRT_MAX 53 #define PF_SHRT_MIN SHRT_MIN 54 #define PF_SHRT_MAX SHRT_MAX 55 #elif (UINT_MAX == 65535U) 56 #define PF_USHRT_MAX UINT_MAX 57 #define PF_SHRT_MIN INT_MIN 58 #define PF_SHRT_MAX INT_MAX 59 #else 60 # error "Unable to find 16 bits unsigned type, unsupported compiler" 61 #endif 62 63 int16_t FormatInfo<int16_t>::MIN = PF_SHRT_MIN; 64 int16_t FormatInfo<int16_t>::MAX = PF_SHRT_MAX; 65 int16_t FormatInfo<int16_t>::HALF = 0; 66 FormatInfo<int16_t>::PROMOTED FormatInfo<int16_t>::RANGE = 67 (FormatInfo<int16_t>::PROMOTED)FormatInfo<int16_t>::MAX - FormatInfo<int16_t>::MIN; 68 69 70 uint16_t FormatInfo<uint16_t>::MIN = 0; 71 uint16_t FormatInfo<uint16_t>::MAX = PF_USHRT_MAX; 72 uint16_t FormatInfo<uint16_t>::HALF = PF_USHRT_MAX/2; 73 FormatInfo<uint16_t>::PROMOTED FormatInfo<uint16_t>::RANGE = FormatInfo<uint16_t>::MAX; 74 75 76 // 16-bit base types 77 #if (UINT_MAX == 4294967295U) 78 #define PF_UINT_MAX UINT_MAX 79 #define PF_INT_MIN INT_MIN 80 #define PF_INT_MAX INT_MAX 81 #elif (ULONG_MAX == 4294967295U) 82 #define PF_UINT_MAX ULONG_MAX 83 #define PF_INT_MIN LONG_MIN 84 #define PF_INT_MAX LONG_MAX 85 #else 86 # error "Unable to find 16 bits unsigned type, unsupported compiler" 87 #endif 88 89 int32_t FormatInfo<int32_t>::MIN = PF_INT_MIN; 90 int32_t FormatInfo<int32_t>::MAX = PF_INT_MAX; 91 int32_t FormatInfo<int32_t>::HALF = 0; 92 FormatInfo<int32_t>::PROMOTED FormatInfo<int32_t>::RANGE = 93 (FormatInfo<int32_t>::PROMOTED)FormatInfo<int32_t>::MAX - FormatInfo<int32_t>::MIN; 94 95 96 uint32_t FormatInfo<uint32_t>::MIN = 0; 97 uint32_t FormatInfo<uint32_t>::MAX = PF_UINT_MAX; 98 uint32_t FormatInfo<uint32_t>::HALF = PF_UINT_MAX/2; 99 FormatInfo<uint32_t>::PROMOTED FormatInfo<uint32_t>::RANGE = FormatInfo<uint32_t>::MAX; 100 101 102 } 103 104 vips2lcms_pixel_format(VipsBandFormat vipsFmt,cmsHPROFILE pin)105cmsUInt32Number PF::vips2lcms_pixel_format( VipsBandFormat vipsFmt, cmsHPROFILE pin ) 106 { 107 cmsUInt32Number result; 108 switch( vipsFmt ) { 109 case VIPS_FORMAT_UCHAR: 110 case VIPS_FORMAT_CHAR: 111 switch( cmsGetColorSpace( pin ) ) { 112 case cmsSigRgbData: 113 result = TYPE_RGB_8; 114 break; 115 case cmsSigLabData: 116 result = TYPE_Lab_8; 117 break; 118 case cmsSigCmykData: 119 result = TYPE_CMYK_8; 120 break; 121 default: break; 122 } 123 break; 124 case VIPS_FORMAT_USHORT: 125 case VIPS_FORMAT_SHORT: 126 // short int is 16-bit 127 #if (USHRT_MAX == 65535U) 128 switch( cmsGetColorSpace( pin ) ) { 129 case cmsSigRgbData: 130 result = TYPE_RGB_16; 131 break; 132 case cmsSigLabData: 133 result = TYPE_Lab_16; 134 break; 135 case cmsSigCmykData: 136 result = TYPE_CMYK_16; 137 break; 138 case cmsSigXYZData: 139 result = TYPE_XYZ_16; 140 break; 141 default: break; 142 } 143 #endif 144 break; 145 case VIPS_FORMAT_UINT: 146 case VIPS_FORMAT_INT: 147 #if (UINT_MAX == 65535U) 148 switch( cmsGetColorSpace( pin ) ) { 149 case cmsSigRgbData: 150 result = TYPE_RGB_16; 151 break; 152 case cmsSigLabData: 153 result = TYPE_Lab_16; 154 break; 155 case cmsSigCmykData: 156 result = TYPE_CMYK_16; 157 break; 158 case cmsSigXYZData: 159 result = TYPE_XYZ_16; 160 break; 161 default: break; 162 } 163 #endif 164 break; 165 case VIPS_FORMAT_FLOAT: 166 switch( cmsGetColorSpace( pin ) ) { 167 case cmsSigRgbData: 168 result = TYPE_RGB_FLT; 169 break; 170 case cmsSigLabData: 171 result = TYPE_Lab_FLT; 172 break; 173 case cmsSigCmykData: 174 result = TYPE_CMYK_FLT; 175 break; 176 case cmsSigXYZData: 177 result = TYPE_XYZ_FLT; 178 break; 179 default: break; 180 } 181 break; 182 case VIPS_FORMAT_DOUBLE: 183 switch( cmsGetColorSpace( pin ) ) { 184 case cmsSigRgbData: 185 result = TYPE_RGB_DBL; 186 break; 187 case cmsSigLabData: 188 result = TYPE_Lab_DBL; 189 break; 190 case cmsSigCmykData: 191 result = TYPE_CMYK_DBL; 192 break; 193 case cmsSigXYZData: 194 result = TYPE_XYZ_DBL; 195 break; 196 default: break; 197 } 198 break; 199 default: 200 break; 201 } 202 return result; 203 } 204 205 206 207