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-2014 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 //---------------------------------------------------------------------------------
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 #define _cmsALIGNMEM(x) (((x)+(sizeof(void *) - 1)) & ~(sizeof(void *) - 1))
90
91 // Maximum encodeable values in floating point
92 #define MAX_ENCODEABLE_XYZ (1.0 + 32767.0/32768.0)
93 #define MIN_ENCODEABLE_ab2 (-128.0)
94 #define MAX_ENCODEABLE_ab2 ((65535.0/256.0) - 128.0)
95 #define MIN_ENCODEABLE_ab4 (-128.0)
96 #define MAX_ENCODEABLE_ab4 (127.0)
97
98 // Maximum of channels for internal pipeline evaluation
99 #define MAX_STAGE_CHANNELS 128
100
101 // Unused parameter warning supression
102 #define cmsUNUSED_PARAMETER(x) ((void)x)
103
104 // The specification for "inline" is section 6.7.4 of the C99 standard (ISO/IEC 9899:1999).
105 // unfortunately VisualC++ does not conform that
106 #if defined(_MSC_VER) || defined(__BORLANDC__)
107 # define cmsINLINE __inline
108 #else
109 # define cmsINLINE static inline
110 #endif
111
112 // Other replacement functions
113 #ifdef _MSC_VER
114 # ifndef snprintf
115 # define snprintf _snprintf
116 # endif
117 # ifndef vsnprintf
118 # define vsnprintf _vsnprintf
119 # endif
120 #endif
121
122
123 // A fast way to convert from/to 16 <-> 8 bits
124 #define FROM_8_TO_16(rgb) (cmsUInt16Number) ((((cmsUInt16Number) (rgb)) << 8)|(rgb))
125 #define FROM_16_TO_8(rgb) (cmsUInt8Number) ((((rgb) * 65281 + 8388608) >> 24) & 0xFF)
126
127 // Code analysis is broken on asserts
128 #ifdef _MSC_VER
129 # if (_MSC_VER >= 1500)
130 # define _cmsAssert(a) { assert((a)); __analysis_assume((a)); }
131 # else
132 # define _cmsAssert(a) assert((a))
133 # endif
134 #else
135 # define _cmsAssert(a) assert((a))
136 #endif
137
138 //---------------------------------------------------------------------------------
139
140 // Determinant lower than that are assumed zero (used on matrix invert)
141 #define MATRIX_DET_TOLERANCE 0.0001
142
143 //---------------------------------------------------------------------------------
144
145 // Fixed point
674 void _cmsAllocMutexPluginChunk(struct _cmsContext_struct* ctx,
675 const struct _cmsContext_struct* src);
676
677 // ----------------------------------------------------------------------------------
678 // MLU internal representation
679 typedef struct {
680
681 cmsUInt16Number Language;
682 cmsUInt16Number Country;
683
684 cmsUInt32Number StrW; // Offset to current unicode string
685 cmsUInt32Number Len; // Length in bytes
686
687 } _cmsMLUentry;
688
689 struct _cms_MLU_struct {
690
691 cmsContext ContextID;
692
693 // The directory
694 int AllocatedEntries;
695 int UsedEntries;
696 _cmsMLUentry* Entries; // Array of pointers to strings allocated in MemPool
697
698 // The Pool
699 cmsUInt32Number PoolSize; // The maximum allocated size
700 cmsUInt32Number PoolUsed; // The used size
701 void* MemPool; // Pointer to begin of memory pool
702 };
703
704 // Named color list internal representation
705 typedef struct {
706
707 char Name[cmsMAX_PATH];
708 cmsUInt16Number PCS[3];
709 cmsUInt16Number DeviceColorant[cmsMAXCHANNELS];
710
711 } _cmsNAMEDCOLOR;
712
713 struct _cms_NAMEDCOLORLIST_struct {
714
715 cmsUInt32Number nColors;
743 // Creation time
744 struct tm Created;
745
746 // Only most important items found in ICC profiles
747 cmsUInt32Number Version;
748 cmsProfileClassSignature DeviceClass;
749 cmsColorSpaceSignature ColorSpace;
750 cmsColorSpaceSignature PCS;
751 cmsUInt32Number RenderingIntent;
752
753 cmsUInt32Number flags;
754 cmsUInt32Number manufacturer, model;
755 cmsUInt64Number attributes;
756 cmsUInt32Number creator;
757
758 cmsProfileID ProfileID;
759
760 // Dictionary
761 cmsUInt32Number TagCount;
762 cmsTagSignature TagNames[MAX_TABLE_TAG];
763 cmsTagSignature TagLinked[MAX_TABLE_TAG]; // The tag to wich is linked (0=none)
764 cmsUInt32Number TagSizes[MAX_TABLE_TAG]; // Size on disk
765 cmsUInt32Number TagOffsets[MAX_TABLE_TAG];
766 cmsBool TagSaveAsRaw[MAX_TABLE_TAG]; // True to write uncooked
767 void * TagPtrs[MAX_TABLE_TAG];
768 cmsTagTypeHandler* TagTypeHandlers[MAX_TABLE_TAG]; // Same structure may be serialized on different types
769 // depending on profile version, so we keep track of the
770 // type handler for each tag in the list.
771 // Special
772 cmsBool IsWrite;
773
774 // Keep a mutex for cmsReadTag -- Note that this only works if the user includes a mutex plugin
775 void * UsrMutex;
776
777 } _cmsICCPROFILE;
778
779 // IO helpers for profiles
780 cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc);
781 cmsBool _cmsWriteHeader(_cmsICCPROFILE* Icc, cmsUInt32Number UsedSpace);
782 int _cmsSearchTag(_cmsICCPROFILE* Icc, cmsTagSignature sig, cmsBool lFollowLinks);
783
971 // Transform logic ------------------------------------------------------------------------------------------------------
972
973 struct _cmstransform_struct;
974
975 typedef struct {
976
977 // 1-pixel cache (16 bits only)
978 cmsUInt16Number CacheIn[cmsMAXCHANNELS];
979 cmsUInt16Number CacheOut[cmsMAXCHANNELS];
980
981 } _cmsCACHE;
982
983
984
985 // Transformation
986 typedef struct _cmstransform_struct {
987
988 cmsUInt32Number InputFormat, OutputFormat; // Keep formats for further reference
989
990 // Points to transform code
991 _cmsTransformFn xform;
992
993 // Formatters, cannot be embedded into LUT because cache
994 cmsFormatter16 FromInput;
995 cmsFormatter16 ToOutput;
996
997 cmsFormatterFloat FromInputFloat;
998 cmsFormatterFloat ToOutputFloat;
999
1000 // 1-pixel cache seed for zero as input (16 bits, read only)
1001 _cmsCACHE Cache;
1002
1003 // A Pipeline holding the full (optimized) transform
1004 cmsPipeline* Lut;
1005
1006 // A Pipeline holding the gamut check. It goes from the input space to bilevel
1007 cmsPipeline* GamutCheck;
1008
1009 // Colorant tables
1010 cmsNAMEDCOLORLIST* InputColorant; // Input Colorant table
1011 cmsNAMEDCOLORLIST* OutputColorant; // Colorant table (for n chans > CMYK)
1017 // White points (informative only)
1018 cmsCIEXYZ EntryWhitePoint;
1019 cmsCIEXYZ ExitWhitePoint;
1020
1021 // Profiles used to create the transform
1022 cmsSEQ* Sequence;
1023
1024 cmsUInt32Number dwOriginalFlags;
1025 cmsFloat64Number AdaptationState;
1026
1027 // The intent of this transform. That is usually the last intent in the profilechain, but may differ
1028 cmsUInt32Number RenderingIntent;
1029
1030 // An id that uniquely identifies the running context. May be null.
1031 cmsContext ContextID;
1032
1033 // A user-defined pointer that can be used to store data for transform plug-ins
1034 void* UserData;
1035 _cmsFreeUserDataFn FreeUserData;
1036
1037 } _cmsTRANSFORM;
1038
1039 // --------------------------------------------------------------------------------------------------
1040
1041 cmsHTRANSFORM _cmsChain2Lab(cmsContext ContextID,
1042 cmsUInt32Number nProfiles,
1043 cmsUInt32Number InputFormat,
1044 cmsUInt32Number OutputFormat,
1045 const cmsUInt32Number Intents[],
1046 const cmsHPROFILE hProfiles[],
1047 const cmsBool BPC[],
1048 const cmsFloat64Number AdaptationStates[],
1049 cmsUInt32Number dwFlags);
1050
1051
1052 cmsToneCurve* _cmsBuildKToneCurve(cmsContext ContextID,
1053 cmsUInt32Number nPoints,
1054 cmsUInt32Number nProfiles,
1055 const cmsUInt32Number Intents[],
1056 const cmsHPROFILE hProfiles[],
1057 const cmsBool BPC[],
1058 const cmsFloat64Number AdaptationStates[],
1059 cmsUInt32Number dwFlags);
|
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-2016 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 //---------------------------------------------------------------------------------
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 supression
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 #endif
129
130
131 // A fast way to convert from/to 16 <-> 8 bits
132 #define FROM_8_TO_16(rgb) (cmsUInt16Number) ((((cmsUInt16Number) (rgb)) << 8)|(rgb))
133 #define FROM_16_TO_8(rgb) (cmsUInt8Number) ((((cmsUInt32Number)(rgb) * 65281U + 8388608U) >> 24) & 0xFFU)
134
135 // Code analysis is broken on asserts
136 #ifdef _MSC_VER
137 # if (_MSC_VER >= 1500)
138 # define _cmsAssert(a) { assert((a)); __analysis_assume((a)); }
139 # else
140 # define _cmsAssert(a) assert((a))
141 # endif
142 #else
143 # define _cmsAssert(a) assert((a))
144 #endif
145
146 //---------------------------------------------------------------------------------
147
148 // Determinant lower than that are assumed zero (used on matrix invert)
149 #define MATRIX_DET_TOLERANCE 0.0001
150
151 //---------------------------------------------------------------------------------
152
153 // Fixed point
682 void _cmsAllocMutexPluginChunk(struct _cmsContext_struct* ctx,
683 const struct _cmsContext_struct* src);
684
685 // ----------------------------------------------------------------------------------
686 // MLU internal representation
687 typedef struct {
688
689 cmsUInt16Number Language;
690 cmsUInt16Number Country;
691
692 cmsUInt32Number StrW; // Offset to current unicode string
693 cmsUInt32Number Len; // Length in bytes
694
695 } _cmsMLUentry;
696
697 struct _cms_MLU_struct {
698
699 cmsContext ContextID;
700
701 // The directory
702 cmsUInt32Number AllocatedEntries;
703 cmsUInt32Number UsedEntries;
704 _cmsMLUentry* Entries; // Array of pointers to strings allocated in MemPool
705
706 // The Pool
707 cmsUInt32Number PoolSize; // The maximum allocated size
708 cmsUInt32Number PoolUsed; // The used size
709 void* MemPool; // Pointer to begin of memory pool
710 };
711
712 // Named color list internal representation
713 typedef struct {
714
715 char Name[cmsMAX_PATH];
716 cmsUInt16Number PCS[3];
717 cmsUInt16Number DeviceColorant[cmsMAXCHANNELS];
718
719 } _cmsNAMEDCOLOR;
720
721 struct _cms_NAMEDCOLORLIST_struct {
722
723 cmsUInt32Number nColors;
751 // Creation time
752 struct tm Created;
753
754 // Only most important items found in ICC profiles
755 cmsUInt32Number Version;
756 cmsProfileClassSignature DeviceClass;
757 cmsColorSpaceSignature ColorSpace;
758 cmsColorSpaceSignature PCS;
759 cmsUInt32Number RenderingIntent;
760
761 cmsUInt32Number flags;
762 cmsUInt32Number manufacturer, model;
763 cmsUInt64Number attributes;
764 cmsUInt32Number creator;
765
766 cmsProfileID ProfileID;
767
768 // Dictionary
769 cmsUInt32Number TagCount;
770 cmsTagSignature TagNames[MAX_TABLE_TAG];
771 cmsTagSignature TagLinked[MAX_TABLE_TAG]; // The tag to which is linked (0=none)
772 cmsUInt32Number TagSizes[MAX_TABLE_TAG]; // Size on disk
773 cmsUInt32Number TagOffsets[MAX_TABLE_TAG];
774 cmsBool TagSaveAsRaw[MAX_TABLE_TAG]; // True to write uncooked
775 void * TagPtrs[MAX_TABLE_TAG];
776 cmsTagTypeHandler* TagTypeHandlers[MAX_TABLE_TAG]; // Same structure may be serialized on different types
777 // depending on profile version, so we keep track of the
778 // type handler for each tag in the list.
779 // Special
780 cmsBool IsWrite;
781
782 // Keep a mutex for cmsReadTag -- Note that this only works if the user includes a mutex plugin
783 void * UsrMutex;
784
785 } _cmsICCPROFILE;
786
787 // IO helpers for profiles
788 cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc);
789 cmsBool _cmsWriteHeader(_cmsICCPROFILE* Icc, cmsUInt32Number UsedSpace);
790 int _cmsSearchTag(_cmsICCPROFILE* Icc, cmsTagSignature sig, cmsBool lFollowLinks);
791
979 // Transform logic ------------------------------------------------------------------------------------------------------
980
981 struct _cmstransform_struct;
982
983 typedef struct {
984
985 // 1-pixel cache (16 bits only)
986 cmsUInt16Number CacheIn[cmsMAXCHANNELS];
987 cmsUInt16Number CacheOut[cmsMAXCHANNELS];
988
989 } _cmsCACHE;
990
991
992
993 // Transformation
994 typedef struct _cmstransform_struct {
995
996 cmsUInt32Number InputFormat, OutputFormat; // Keep formats for further reference
997
998 // Points to transform code
999 _cmsTransform2Fn xform;
1000
1001 // Formatters, cannot be embedded into LUT because cache
1002 cmsFormatter16 FromInput;
1003 cmsFormatter16 ToOutput;
1004
1005 cmsFormatterFloat FromInputFloat;
1006 cmsFormatterFloat ToOutputFloat;
1007
1008 // 1-pixel cache seed for zero as input (16 bits, read only)
1009 _cmsCACHE Cache;
1010
1011 // A Pipeline holding the full (optimized) transform
1012 cmsPipeline* Lut;
1013
1014 // A Pipeline holding the gamut check. It goes from the input space to bilevel
1015 cmsPipeline* GamutCheck;
1016
1017 // Colorant tables
1018 cmsNAMEDCOLORLIST* InputColorant; // Input Colorant table
1019 cmsNAMEDCOLORLIST* OutputColorant; // Colorant table (for n chans > CMYK)
1025 // White points (informative only)
1026 cmsCIEXYZ EntryWhitePoint;
1027 cmsCIEXYZ ExitWhitePoint;
1028
1029 // Profiles used to create the transform
1030 cmsSEQ* Sequence;
1031
1032 cmsUInt32Number dwOriginalFlags;
1033 cmsFloat64Number AdaptationState;
1034
1035 // The intent of this transform. That is usually the last intent in the profilechain, but may differ
1036 cmsUInt32Number RenderingIntent;
1037
1038 // An id that uniquely identifies the running context. May be null.
1039 cmsContext ContextID;
1040
1041 // A user-defined pointer that can be used to store data for transform plug-ins
1042 void* UserData;
1043 _cmsFreeUserDataFn FreeUserData;
1044
1045 // A way to provide backwards compatibility with full xform plugins
1046 _cmsTransformFn OldXform;
1047
1048 } _cmsTRANSFORM;
1049
1050 // Copies extra channels from input to output if the original flags in the transform structure
1051 // instructs to do so. This function is called on all standard transform functions.
1052 void _cmsHandleExtraChannels(_cmsTRANSFORM* p, const void* in,
1053 void* out,
1054 cmsUInt32Number PixelsPerLine,
1055 cmsUInt32Number LineCount,
1056 const cmsStride* Stride);
1057
1058 // -----------------------------------------------------------------------------------------------------------------------
1059
1060 cmsHTRANSFORM _cmsChain2Lab(cmsContext ContextID,
1061 cmsUInt32Number nProfiles,
1062 cmsUInt32Number InputFormat,
1063 cmsUInt32Number OutputFormat,
1064 const cmsUInt32Number Intents[],
1065 const cmsHPROFILE hProfiles[],
1066 const cmsBool BPC[],
1067 const cmsFloat64Number AdaptationStates[],
1068 cmsUInt32Number dwFlags);
1069
1070
1071 cmsToneCurve* _cmsBuildKToneCurve(cmsContext ContextID,
1072 cmsUInt32Number nPoints,
1073 cmsUInt32Number nProfiles,
1074 const cmsUInt32Number Intents[],
1075 const cmsHPROFILE hProfiles[],
1076 const cmsBool BPC[],
1077 const cmsFloat64Number AdaptationStates[],
1078 cmsUInt32Number dwFlags);
|