10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 // This file is available under and governed by the GNU General Public 26 // License version 2 only, as published by the Free Software Foundation. 27 // However, the following notice accompanied the original version of this 28 // file: 29 // 30 31 // 32 // Little Color Management System 33 // Copyright (c) 1998-2017 Marti Maria Saguer 34 // 35 // Permission is hereby granted, free of charge, to any person obtaining 36 // a copy of this software and associated documentation files (the "Software"), 37 // to deal in the Software without restriction, including without limitation 38 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 39 // and/or sell copies of the Software, and to permit persons to whom the Software 40 // is furnished to do so, subject to the following conditions: 41 // 42 // The above copyright notice and this permission notice shall be included in 43 // all copies or substantial portions of the Software. 44 // 45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 52 // 53 //--------------------------------------------------------------------------------- 59 #ifndef _lcms_plugin_H 60 # include "lcms2_plugin.h" 61 #endif 62 63 // ctype is part of C99 as per 7.1.2 64 #include <ctype.h> 65 66 // assert macro is part of C99 as per 7.2 67 #include <assert.h> 68 69 // Some needed constants 70 #ifndef M_PI 71 # define M_PI 3.14159265358979323846 72 #endif 73 74 #ifndef M_LOG10E 75 # define M_LOG10E 0.434294481903251827651 76 #endif 77 78 // BorlandC 5.5, VC2003 are broken on that 79 #if defined(__BORLANDC__) || (_MSC_VER < 1400) // 1400 == VC++ 8.0 80 #define sinf(x) (float)sin((float)x) 81 #define sqrtf(x) (float)sqrt((float)x) 82 #endif 83 84 85 // Alignment of ICC file format uses 4 bytes (cmsUInt32Number) 86 #define _cmsALIGNLONG(x) (((x)+(sizeof(cmsUInt32Number)-1)) & ~(sizeof(cmsUInt32Number)-1)) 87 88 // Alignment to memory pointer 89 90 // (Ultra)SPARC with gcc requires ptr alignment of 8 bytes 91 // even though sizeof(void *) is only four: for greatest flexibility 92 // allow the build to specify ptr alignment. 93 #ifndef CMS_PTR_ALIGNMENT 94 # define CMS_PTR_ALIGNMENT sizeof(void *) 95 #endif 96 97 #define _cmsALIGNMEM(x) (((x)+(CMS_PTR_ALIGNMENT - 1)) & ~(CMS_PTR_ALIGNMENT - 1)) 98 99 // Maximum encodeable values in floating point 100 #define MAX_ENCODEABLE_XYZ (1.0 + 32767.0/32768.0) 101 #define MIN_ENCODEABLE_ab2 (-128.0) 102 #define MAX_ENCODEABLE_ab2 ((65535.0/256.0) - 128.0) 103 #define MIN_ENCODEABLE_ab4 (-128.0) 104 #define MAX_ENCODEABLE_ab4 (127.0) 105 106 // Maximum of channels for internal pipeline evaluation 107 #define MAX_STAGE_CHANNELS 128 108 109 // Unused parameter warning suppression 110 #define cmsUNUSED_PARAMETER(x) ((void)x) 111 112 // The specification for "inline" is section 6.7.4 of the C99 standard (ISO/IEC 9899:1999). 113 // unfortunately VisualC++ does not conform that 114 #if defined(_MSC_VER) || defined(__BORLANDC__) 115 # define cmsINLINE __inline 116 #else 117 # define cmsINLINE static inline 118 #endif 119 120 // Other replacement functions 121 #ifdef _MSC_VER 122 # ifndef snprintf 123 # define snprintf _snprintf 124 # endif 125 # ifndef vsnprintf 126 # define vsnprintf _vsnprintf 127 # endif 128 129 /// Properly define some macros to accommodate 130 /// older MSVC versions. 131 # if _MSC_VER <= 1700 132 #include <float.h> 133 #define isnan _isnan 134 #define isinf(x) (!_finite((x))) 135 # endif 136 137 #endif 138 139 // A fast way to convert from/to 16 <-> 8 bits 140 #define FROM_8_TO_16(rgb) (cmsUInt16Number) ((((cmsUInt16Number) (rgb)) << 8)|(rgb)) 141 #define FROM_16_TO_8(rgb) (cmsUInt8Number) ((((cmsUInt32Number)(rgb) * 65281U + 8388608U) >> 24) & 0xFFU) 142 143 // Code analysis is broken on asserts 144 #ifdef _MSC_VER 145 # if (_MSC_VER >= 1500) 146 # define _cmsAssert(a) { assert((a)); __analysis_assume((a)); } 147 # else 148 # define _cmsAssert(a) assert((a)) 149 # endif 150 #else 151 # define _cmsAssert(a) assert((a)) 152 #endif 153 154 //--------------------------------------------------------------------------------- 155 156 // Determinant lower than that are assumed zero (used on matrix invert) 947 cmsContext ContextID; // Environment 948 949 cmsBool SaveAs8Bits; // Implementation-specific: save as 8 bits if possible 950 }; 951 952 // LUT reading & creation ------------------------------------------------------------------------------------------- 953 954 // Read tags using low-level function, provide necessary glue code to adapt versions, etc. All those return a brand new copy 955 // of the LUTS, since ownership of original is up to the profile. The user should free allocated resources. 956 957 CMSCHECKPOINT cmsPipeline* CMSEXPORT _cmsReadInputLUT(cmsHPROFILE hProfile, cmsUInt32Number Intent); 958 CMSCHECKPOINT cmsPipeline* CMSEXPORT _cmsReadOutputLUT(cmsHPROFILE hProfile, cmsUInt32Number Intent); 959 CMSCHECKPOINT cmsPipeline* CMSEXPORT _cmsReadDevicelinkLUT(cmsHPROFILE hProfile, cmsUInt32Number Intent); 960 961 // Special values 962 cmsBool _cmsReadMediaWhitePoint(cmsCIEXYZ* Dest, cmsHPROFILE hProfile); 963 cmsBool _cmsReadCHAD(cmsMAT3* Dest, cmsHPROFILE hProfile); 964 965 // Profile linker -------------------------------------------------------------------------------------------------- 966 967 cmsPipeline* _cmsLinkProfiles(cmsContext ContextID, 968 cmsUInt32Number nProfiles, 969 cmsUInt32Number TheIntents[], 970 cmsHPROFILE hProfiles[], 971 cmsBool BPC[], 972 cmsFloat64Number AdaptationStates[], 973 cmsUInt32Number dwFlags); 974 975 // Sequence -------------------------------------------------------------------------------------------------------- 976 977 cmsSEQ* _cmsReadProfileSequence(cmsHPROFILE hProfile); 978 cmsBool _cmsWriteProfileSequence(cmsHPROFILE hProfile, const cmsSEQ* seq); 979 cmsSEQ* _cmsCompileProfileSequence(cmsContext ContextID, cmsUInt32Number nProfiles, cmsHPROFILE hProfiles[]); 980 981 982 // LUT optimization ------------------------------------------------------------------------------------------------ 983 984 CMSCHECKPOINT cmsUInt16Number CMSEXPORT _cmsQuantizeVal(cmsFloat64Number i, cmsUInt32Number MaxSamples); 985 986 cmsUInt32Number _cmsReasonableGridpointsByColorspace(cmsColorSpaceSignature Colorspace, cmsUInt32Number dwFlags); | 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 // This file is available under and governed by the GNU General Public 26 // License version 2 only, as published by the Free Software Foundation. 27 // However, the following notice accompanied the original version of this 28 // file: 29 // 30 //--------------------------------------------------------------------------------- 31 // 32 // Little Color Management System 33 // Copyright (c) 1998-2020 Marti Maria Saguer 34 // 35 // Permission is hereby granted, free of charge, to any person obtaining 36 // a copy of this software and associated documentation files (the "Software"), 37 // to deal in the Software without restriction, including without limitation 38 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 39 // and/or sell copies of the Software, and to permit persons to whom the Software 40 // is furnished to do so, subject to the following conditions: 41 // 42 // The above copyright notice and this permission notice shall be included in 43 // all copies or substantial portions of the Software. 44 // 45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 52 // 53 //--------------------------------------------------------------------------------- 59 #ifndef _lcms_plugin_H 60 # include "lcms2_plugin.h" 61 #endif 62 63 // ctype is part of C99 as per 7.1.2 64 #include <ctype.h> 65 66 // assert macro is part of C99 as per 7.2 67 #include <assert.h> 68 69 // Some needed constants 70 #ifndef M_PI 71 # define M_PI 3.14159265358979323846 72 #endif 73 74 #ifndef M_LOG10E 75 # define M_LOG10E 0.434294481903251827651 76 #endif 77 78 // BorlandC 5.5, VC2003 are broken on that 79 #if defined(__BORLANDC__) || (defined(_MSC_VER) && (_MSC_VER < 1400)) // 1400 == VC++ 8.0 80 #define sinf(x) (float)sin((float)x) 81 #define sqrtf(x) (float)sqrt((float)x) 82 #endif 83 84 85 // Alignment of ICC file format uses 4 bytes (cmsUInt32Number) 86 #define _cmsALIGNLONG(x) (((x)+(sizeof(cmsUInt32Number)-1)) & ~(sizeof(cmsUInt32Number)-1)) 87 88 // Alignment to memory pointer 89 90 // (Ultra)SPARC with gcc requires ptr alignment of 8 bytes 91 // even though sizeof(void *) is only four: for greatest flexibility 92 // allow the build to specify ptr alignment. 93 #ifndef CMS_PTR_ALIGNMENT 94 # define CMS_PTR_ALIGNMENT sizeof(void *) 95 #endif 96 97 #define _cmsALIGNMEM(x) (((x)+(CMS_PTR_ALIGNMENT - 1)) & ~(CMS_PTR_ALIGNMENT - 1)) 98 99 // Maximum encodeable values in floating point 100 #define MAX_ENCODEABLE_XYZ (1.0 + 32767.0/32768.0) 101 #define MIN_ENCODEABLE_ab2 (-128.0) 102 #define MAX_ENCODEABLE_ab2 ((65535.0/256.0) - 128.0) 103 #define MIN_ENCODEABLE_ab4 (-128.0) 104 #define MAX_ENCODEABLE_ab4 (127.0) 105 106 // Maximum of channels for internal pipeline evaluation 107 #define MAX_STAGE_CHANNELS 128 108 109 // Unused parameter warning suppression 110 #define cmsUNUSED_PARAMETER(x) ((void)x) 111 112 // The specification for "inline" is section 6.7.4 of the C99 standard (ISO/IEC 9899:1999). 113 // unfortunately VisualC++ does not conform that 114 #if defined(_MSC_VER) || defined(__BORLANDC__) 115 # define cmsINLINE __inline 116 #else 117 # define cmsINLINE static inline 118 #endif 119 120 // Allow signed overflow, we know this is harmless in this particular context 121 #if defined(__clang__) 122 # define CMS_NO_SANITIZE __attribute__((no_sanitize("signed-integer-overflow"))) 123 #else 124 # define CMS_NO_SANITIZE 125 #endif 126 127 // Other replacement functions 128 #ifdef _MSC_VER 129 # ifndef snprintf 130 # define snprintf _snprintf 131 # endif 132 # ifndef vsnprintf 133 # define vsnprintf _vsnprintf 134 # endif 135 136 /// Properly define some macros to accommodate 137 /// older MSVC versions. 138 # if defined(_MSC_VER) && _MSC_VER <= 1700 139 #include <float.h> 140 #define isnan _isnan 141 #define isinf(x) (!_finite((x))) 142 # endif 143 144 #if !defined(_MSC_VER) && (defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L) 145 #if !defined(isinf) 146 #define isinf(x) (!finite((x))) 147 #endif 148 #endif 149 150 151 #endif 152 153 // A fast way to convert from/to 16 <-> 8 bits 154 #define FROM_8_TO_16(rgb) (cmsUInt16Number) ((((cmsUInt16Number) (rgb)) << 8)|(rgb)) 155 #define FROM_16_TO_8(rgb) (cmsUInt8Number) ((((cmsUInt32Number)(rgb) * 65281U + 8388608U) >> 24) & 0xFFU) 156 157 // Code analysis is broken on asserts 158 #ifdef _MSC_VER 159 # if (_MSC_VER >= 1500) 160 # define _cmsAssert(a) { assert((a)); __analysis_assume((a)); } 161 # else 162 # define _cmsAssert(a) assert((a)) 163 # endif 164 #else 165 # define _cmsAssert(a) assert((a)) 166 #endif 167 168 //--------------------------------------------------------------------------------- 169 170 // Determinant lower than that are assumed zero (used on matrix invert) 961 cmsContext ContextID; // Environment 962 963 cmsBool SaveAs8Bits; // Implementation-specific: save as 8 bits if possible 964 }; 965 966 // LUT reading & creation ------------------------------------------------------------------------------------------- 967 968 // Read tags using low-level function, provide necessary glue code to adapt versions, etc. All those return a brand new copy 969 // of the LUTS, since ownership of original is up to the profile. The user should free allocated resources. 970 971 CMSCHECKPOINT cmsPipeline* CMSEXPORT _cmsReadInputLUT(cmsHPROFILE hProfile, cmsUInt32Number Intent); 972 CMSCHECKPOINT cmsPipeline* CMSEXPORT _cmsReadOutputLUT(cmsHPROFILE hProfile, cmsUInt32Number Intent); 973 CMSCHECKPOINT cmsPipeline* CMSEXPORT _cmsReadDevicelinkLUT(cmsHPROFILE hProfile, cmsUInt32Number Intent); 974 975 // Special values 976 cmsBool _cmsReadMediaWhitePoint(cmsCIEXYZ* Dest, cmsHPROFILE hProfile); 977 cmsBool _cmsReadCHAD(cmsMAT3* Dest, cmsHPROFILE hProfile); 978 979 // Profile linker -------------------------------------------------------------------------------------------------- 980 981 // Link several profiles to obtain a single LUT modelling the whole color transform. Intents, Black point 982 // compensation and Adaptation parameters may vary across profiles. BPC and Adaptation refers to the PCS 983 // after the profile. I.e, BPC[0] refers to connexion between profile(0) and profile(1) 984 cmsPipeline* _cmsLinkProfiles(cmsContext ContextID, 985 cmsUInt32Number nProfiles, 986 cmsUInt32Number TheIntents[], 987 cmsHPROFILE hProfiles[], 988 cmsBool BPC[], 989 cmsFloat64Number AdaptationStates[], 990 cmsUInt32Number dwFlags); 991 992 // Sequence -------------------------------------------------------------------------------------------------------- 993 994 cmsSEQ* _cmsReadProfileSequence(cmsHPROFILE hProfile); 995 cmsBool _cmsWriteProfileSequence(cmsHPROFILE hProfile, const cmsSEQ* seq); 996 cmsSEQ* _cmsCompileProfileSequence(cmsContext ContextID, cmsUInt32Number nProfiles, cmsHPROFILE hProfiles[]); 997 998 999 // LUT optimization ------------------------------------------------------------------------------------------------ 1000 1001 CMSCHECKPOINT cmsUInt16Number CMSEXPORT _cmsQuantizeVal(cmsFloat64Number i, cmsUInt32Number MaxSamples); 1002 1003 cmsUInt32Number _cmsReasonableGridpointsByColorspace(cmsColorSpaceSignature Colorspace, cmsUInt32Number dwFlags); |