1 /* vim: set ts=8 sw=8 noexpandtab: */
3 // Copyright (C) 2009 Mozilla Foundation
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the Software
10 // is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
17 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include "qcmstypes.h"
26 /* used as a lookup table for the output transformation.
27 * we refcount them so we only need to have one around per output
28 * profile, instead of duplicating them per transform */
29 struct precache_output
32 /* We previously used a count of 65536 here but that seems like more
33 * precision than we actually need. By reducing the size we can
34 * improve startup performance and reduce memory usage. ColorSync on
35 * 10.5 uses 4097 which is perhaps because they use a fixed point
36 * representation where 1. is represented by 0x1000. */
37 #define PRECACHE_OUTPUT_SIZE 8192
38 #define PRECACHE_OUTPUT_MAX (PRECACHE_OUTPUT_SIZE-1)
39 uint8_t data
[PRECACHE_OUTPUT_SIZE
];
43 #define ALIGN __declspec(align(16))
45 #define ALIGN __attribute__(( aligned (16) ))
48 typedef struct _qcms_format_type
{
53 struct _qcms_transform
{
54 float ALIGN matrix
[3][4];
55 float *input_gamma_table_r
;
56 float *input_gamma_table_g
;
57 float *input_gamma_table_b
;
59 float *input_clut_table_r
;
60 float *input_clut_table_g
;
61 float *input_clut_table_b
;
62 uint16_t input_clut_table_length
;
67 float *output_clut_table_r
;
68 float *output_clut_table_g
;
69 float *output_clut_table_b
;
70 uint16_t output_clut_table_length
;
72 float *input_gamma_table_gray
;
80 uint16_t *output_gamma_lut_r
;
81 uint16_t *output_gamma_lut_g
;
82 uint16_t *output_gamma_lut_b
;
84 uint16_t *output_gamma_lut_gray
;
86 size_t output_gamma_lut_r_length
;
87 size_t output_gamma_lut_g_length
;
88 size_t output_gamma_lut_b_length
;
90 size_t output_gamma_lut_gray_length
;
92 struct precache_output
*output_table_r
;
93 struct precache_output
*output_table_g
;
94 struct precache_output
*output_table_b
;
96 void (*transform_fn
)(struct _qcms_transform
*transform
, unsigned char *src
, unsigned char *dest
, size_t length
, struct _qcms_format_type output_format
);
104 struct qcms_modular_transform
;
106 typedef void (*transform_module_fn_t
)(struct qcms_modular_transform
*transform
, float *src
, float *dest
, size_t length
);
108 struct qcms_modular_transform
{
109 struct matrix matrix
;
112 float *input_clut_table_r
;
113 float *input_clut_table_g
;
114 float *input_clut_table_b
;
115 uint16_t input_clut_table_length
;
120 float *output_clut_table_r
;
121 float *output_clut_table_g
;
122 float *output_clut_table_b
;
123 uint16_t output_clut_table_length
;
125 uint16_t *output_gamma_lut_r
;
126 uint16_t *output_gamma_lut_g
;
127 uint16_t *output_gamma_lut_b
;
129 size_t output_gamma_lut_r_length
;
130 size_t output_gamma_lut_g_length
;
131 size_t output_gamma_lut_b_length
;
133 transform_module_fn_t transform_module_fn
;
134 struct qcms_modular_transform
*next_transform
;
137 typedef int32_t s15Fixed16Number
;
138 typedef uint16_t uInt16Number
;
139 typedef uint8_t uInt8Number
;
155 uint8_t num_in_channels
;
156 uint8_t num_out_channels
;
157 // 16 is the upperbound, actual is 0..num_in_channels.
158 uint8_t num_grid_points
[16];
160 s15Fixed16Number e00
;
161 s15Fixed16Number e01
;
162 s15Fixed16Number e02
;
163 s15Fixed16Number e03
;
164 s15Fixed16Number e10
;
165 s15Fixed16Number e11
;
166 s15Fixed16Number e12
;
167 s15Fixed16Number e13
;
168 s15Fixed16Number e20
;
169 s15Fixed16Number e21
;
170 s15Fixed16Number e22
;
171 s15Fixed16Number e23
;
173 // reversed elements (for mBA)
177 struct curveType
*a_curves
[10];
178 struct curveType
*b_curves
[10];
179 struct curveType
*m_curves
[10];
180 float clut_table_data
[];
183 /* should lut8Type and lut16Type be different types? */
184 struct lutType
{ // used by lut8Type/lut16Type (mft2) only
185 uint8_t num_input_channels
;
186 uint8_t num_output_channels
;
187 uint8_t num_clut_grid_points
;
189 s15Fixed16Number e00
;
190 s15Fixed16Number e01
;
191 s15Fixed16Number e02
;
192 s15Fixed16Number e10
;
193 s15Fixed16Number e11
;
194 s15Fixed16Number e12
;
195 s15Fixed16Number e20
;
196 s15Fixed16Number e21
;
197 s15Fixed16Number e22
;
199 uint16_t num_input_table_entries
;
200 uint16_t num_output_table_entries
;
209 /* this is from an intial idea of having the struct correspond to the data in
210 * the file. I decided that it wasn't a good idea.
224 }; // I guess we need to pack this?
227 #define RGB_SIGNATURE 0x52474220
228 #define GRAY_SIGNATURE 0x47524159
229 #define XYZ_SIGNATURE 0x58595A20
230 #define LAB_SIGNATURE 0x4C616220
232 struct _qcms_profile
{
233 char description
[64];
235 uint32_t color_space
;
237 qcms_intent rendering_intent
;
238 struct XYZNumber redColorant
;
239 struct XYZNumber blueColorant
;
240 struct XYZNumber greenColorant
;
241 struct curveType
*redTRC
;
242 struct curveType
*blueTRC
;
243 struct curveType
*greenTRC
;
244 struct curveType
*grayTRC
;
245 struct lutType
*A2B0
;
246 struct lutType
*B2A0
;
247 struct lutmABType
*mAB
;
248 struct lutmABType
*mBA
;
249 struct matrix chromaticAdaption
;
251 struct precache_output
*output_table_r
;
252 struct precache_output
*output_table_g
;
253 struct precache_output
*output_table_b
;
257 #define inline _inline
260 /* produces the nearest float to 'a' with a maximum error
261 * of 1/1024 which happens for large values like 0x40000040 */
262 static inline float s15Fixed16Number_to_float(s15Fixed16Number a
)
264 return ((int32_t)a
)/65536.f
;
267 static inline s15Fixed16Number
double_to_s15Fixed16Number(double v
)
269 return (int32_t)(v
*65536);
272 static inline float uInt8Number_to_float(uInt8Number a
)
274 return ((int32_t)a
)/255.f
;
277 static inline float uInt16Number_to_float(uInt16Number a
)
279 return ((int32_t)a
)/65535.f
;
283 void precache_release(struct precache_output
*p
);
284 qcms_bool
set_rgb_colorants(qcms_profile
*profile
, qcms_CIE_xyY white_point
, qcms_CIE_xyYTRIPLE primaries
);
286 void qcms_transform_data_rgb_out_lut_sse2(qcms_transform
*transform
,
290 qcms_format_type output_format
);
291 void qcms_transform_data_rgba_out_lut_sse2(qcms_transform
*transform
,
295 qcms_format_type output_format
);
296 void qcms_transform_data_rgb_out_lut_sse1(qcms_transform
*transform
,
300 qcms_format_type output_format
);
301 void qcms_transform_data_rgba_out_lut_sse1(qcms_transform
*transform
,
305 qcms_format_type output_format
);
307 extern qcms_bool qcms_supports_iccv4
;
312 long __cdecl
_InterlockedIncrement(long volatile *);
313 long __cdecl
_InterlockedDecrement(long volatile *);
314 #pragma intrinsic(_InterlockedIncrement)
315 #pragma intrinsic(_InterlockedDecrement)
317 #define qcms_atomic_increment(x) _InterlockedIncrement((long volatile *)&x)
318 #define qcms_atomic_decrement(x) _InterlockedDecrement((long volatile*)&x)
322 #define qcms_atomic_increment(x) __sync_add_and_fetch(&x, 1)
323 #define qcms_atomic_decrement(x) __sync_sub_and_fetch(&x, 1)