jas_icc.h
1 /*
2 * Copyright (c) 2002-2003 Michael David Adams.
3 * All rights reserved.
4 */
5
6 /* __START_OF_JASPER_LICENSE__
7 *
8 * JasPer License Version 2.0
9 *
10 * Copyright (c) 2001-2006 Michael David Adams
11 * Copyright (c) 1999-2000 Image Power, Inc.
12 * Copyright (c) 1999-2000 The University of British Columbia
13 *
14 * All rights reserved.
15 *
16 * Permission is hereby granted, free of charge, to any person (the
17 * "User") obtaining a copy of this software and associated documentation
18 * files (the "Software"), to deal in the Software without restriction,
19 * including without limitation the rights to use, copy, modify, merge,
20 * publish, distribute, and/or sell copies of the Software, and to permit
21 * persons to whom the Software is furnished to do so, subject to the
22 * following conditions:
23 *
24 * 1. The above copyright notices and this permission notice (which
25 * includes the disclaimer below) shall be included in all copies or
26 * substantial portions of the Software.
27 *
28 * 2. The name of a copyright holder shall not be used to endorse or
29 * promote products derived from the Software without specific prior
30 * written permission.
31 *
32 * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
33 * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
34 * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
35 * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
36 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
37 * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
38 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
39 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
40 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
41 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
42 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
43 * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
44 * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
45 * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
46 * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
47 * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
48 * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
49 * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
50 * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
51 * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
52 * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
53 * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
54 * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
55 * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
56 * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
57 * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
58 *
59 * __END_OF_JASPER_LICENSE__
60 */
61
62 #ifndef JAS_ICC_H
63 #define JAS_ICC_H
64
65 /* The configuration header file should be included first. */
66 #include <jasper/jas_config.h>
67
68 #include <jasper/jas_types.h>
69 #include <jasper/jas_stream.h>
70
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74
75 /* Profile file signature. */
76 #define JAS_ICC_MAGIC 0x61637370
77
78 #define JAS_ICC_HDRLEN 128
79
80 /* Profile/device class signatures. */
81 #define JAS_ICC_CLAS_IN 0x73636e72 /* input device */
82 #define JAS_ICC_CLAS_DPY 0x6d6e7472 /* display device */
83 #define JAS_ICC_CLAS_OUT 0x70727472 /* output device */
84 #define JAS_ICC_CLAS_LNK 0x6c696e6b /* device link */
85 #define JAS_ICC_CLAS_CNV 0x73706163 /* color space conversion */
86 #define JAS_ICC_CLAS_ABS 0x61627374 /* abstract */
87 #define JAS_ICC_CLAS_NAM 0x6e6d636c /* named color */
88
89 /* Color space signatures. */
90 #define JAS_ICC_COLORSPC_XYZ 0x58595a20 /* XYZ */
91 #define JAS_ICC_COLORSPC_LAB 0x4c616220 /* LAB */
92 #define JAS_ICC_COLORSPC_LUV 0x4c757620 /* LUV */
93 #define JAS_ICC_COLORSPC_YCBCR 0x59436272 /* YCbCr */
94 #define JAS_ICC_COLORSPC_YXY 0x59787920 /* Yxy */
95 #define JAS_ICC_COLORSPC_RGB 0x52474220 /* RGB */
96 #define JAS_ICC_COLORSPC_GRAY 0x47524159 /* Gray */
97 #define JAS_ICC_COLORSPC_HSV 0x48535620 /* HSV */
98 #define JAS_ICC_COLORSPC_HLS 0x484c5320 /* HLS */
99 #define JAS_ICC_COLORSPC_CMYK 0x434d594b /* CMYK */
100 #define JAS_ICC_COLORSPC_CMY 0x434d5920 /* CMY */
101 #define JAS_ICC_COLORSPC_2 0x32434c52 /* 2 channel color */
102 #define JAS_ICC_COLORSPC_3 0x33434c52 /* 3 channel color */
103 #define JAS_ICC_COLORSPC_4 0x34434c52 /* 4 channel color */
104 #define JAS_ICC_COLORSPC_5 0x35434c52 /* 5 channel color */
105 #define JAS_ICC_COLORSPC_6 0x36434c52 /* 6 channel color */
106 #define JAS_ICC_COLORSPC_7 0x37434c52 /* 7 channel color */
107 #define JAS_ICC_COLORSPC_8 0x38434c52 /* 8 channel color */
108 #define JAS_ICC_COLORSPC_9 0x39434c52 /* 9 channel color */
109 #define JAS_ICC_COLORSPC_10 0x41434c52 /* 10 channel color */
110 #define JAS_ICC_COLORSPC_11 0x42434c52 /* 11 channel color */
111 #define JAS_ICC_COLORSPC_12 0x43434c52 /* 12 channel color */
112 #define JAS_ICC_COLORSPC_13 0x44434c52 /* 13 channel color */
113 #define JAS_ICC_COLORSPC_14 0x45434c52 /* 14 channel color */
114 #define JAS_ICC_COLORSPC_15 0x46434c52 /* 15 channel color */
115
116 /* Profile connection color space (PCS) signatures. */
117 #define JAS_ICC_REFCOLORSPC_XYZ 0x58595a20 /* CIE XYZ */
118 #define JAS_ICC_REFCOLORSPC_LAB 0x4c616220 /* CIE Lab */
119
120 /* Primary platform signatures. */
121 #define JAS_ICC_PLATFORM_APPL 0x4150504c /* Apple Computer */
122 #define JAS_ICC_PLATFORM_MSFT 0x4d534654 /* Microsoft */
123 #define JAS_ICC_PLATFORM_SGI 0x53474920 /* Silicon Graphics */
124 #define JAS_ICC_PLATFORM_SUNW 0x53554e57 /* Sun Microsystems */
125 #define JAS_ICC_PLATFORM_TGNT 0x54474e54 /* Taligent */
126
127 /* Profile flags. */
128 #define JAS_ICC_FLAGS_EMBED 0x01 /* embedded */
129 #define JAS_ICC_FLAGS_NOSEP 0x02 /* no separate use */
130
131 /* Attributes. */
132 #define JAS_ICC_ATTR_TRANS 0x01 /* transparent */
133 #define JAS_ICC_ATTR_MATTE 0x02 /* matte */
134
135 /* Rendering intents. */
136 #define JAS_ICC_INTENT_PER 0 /* perceptual */
137 #define JAS_ICC_INTENT_REL 1 /* relative colorimetric */
138 #define JAS_ICC_INTENT_SAT 2 /* saturation */
139 #define JAS_ICC_INTENT_ABS 3 /* absolute colorimetric */
140
141 /* Tag signatures. */
142 #define JAS_ICC_TAG_ATOB0 0x41324230 /* */
143 #define JAS_ICC_TAG_ATOB1 0x41324231 /* */
144 #define JAS_ICC_TAG_ATOB2 0x41324232 /* */
145 #define JAS_ICC_TAG_BLUMATCOL 0x6258595a /* */
146 #define JAS_ICC_TAG_BLUTRC 0x62545243 /* */
147 #define JAS_ICC_TAG_BTOA0 0x42324130 /* */
148 #define JAS_ICC_TAG_BTOA1 0x42324131 /* */
149 #define JAS_ICC_TAG_BTOA2 0x42324132 /* */
150 #define JAS_ICC_TAG_CALTIME 0x63616c74 /* */
151 #define JAS_ICC_TAG_CHARTARGET 0x74617267 /* */
152 #define JAS_ICC_TAG_CPYRT 0x63707274 /* */
153 #define JAS_ICC_TAG_CRDINFO 0x63726469 /* */
154 #define JAS_ICC_TAG_DEVMAKERDESC 0x646d6e64 /* */
155 #define JAS_ICC_TAG_DEVMODELDESC 0x646d6464 /* */
156 #define JAS_ICC_TAG_DEVSET 0x64657673 /* */
157 #define JAS_ICC_TAG_GAMUT 0x67616d74 /* */
158 #define JAS_ICC_TAG_GRYTRC 0x6b545243 /* */
159 #define JAS_ICC_TAG_GRNMATCOL 0x6758595a /* */
160 #define JAS_ICC_TAG_GRNTRC 0x67545243 /* */
161 #define JAS_ICC_TAG_LUM 0x6c756d69 /* */
162 #define JAS_ICC_TAG_MEASURE 0x6d656173 /* */
163 #define JAS_ICC_TAG_MEDIABLKPT 0x626b7074 /* */
164 #define JAS_ICC_TAG_MEDIAWHIPT 0x77747074 /* */
165 #define JAS_ICC_TAG_NAMCOLR 0x6e636f6c /* */
166 #define JAS_ICC_TAG_NAMCOLR2 0x6e636c32 /* */
167 #define JAS_ICC_TAG_OUTRESP 0x72657370 /* */
168 #define JAS_ICC_TAG_PREVIEW0 0x70726530 /* */
169 #define JAS_ICC_TAG_PREVIEW1 0x70726531 /* */
170 #define JAS_ICC_TAG_PREVIEW2 0x70726532 /* */
171 #define JAS_ICC_TAG_PROFDESC 0x64657363 /* */
172 #define JAS_ICC_TAG_PROFSEQDESC 0x70736571 /* */
173 #define JAS_ICC_TAG_PSDCRD0 0x70736430 /* */
174 #define JAS_ICC_TAG_PSCRDD1 0x70736431 /* */
175 #define JAS_ICC_TAG_PSCRDD2 0x70736432 /* */
176 #define JAS_ICC_TAG_PSCRDD3 0x70736433 /* */
177 #define JAS_ICC_TAG_PS2CSA 0x70733273 /* */
178 #define JAS_ICC_TAG_PS2RENINTENT 0x70733269 /* */
179 #define JAS_ICC_TAG_REDMATCOL 0x7258595a /* */
180 #define JAS_ICC_TAG_REDTRC 0x72545243 /* */
181 #define JAS_ICC_TAG_SCRNGDES 0x73637264 /* */
182 #define JAS_ICC_TAG_SCRNG 0x7363726e /* */
183 #define JAS_ICC_TAG_TECH 0x74656368 /* */
184 #define JAS_ICC_TAG_UCRBG 0x62666420 /* */
185 #define JAS_ICC_TAG_VIEWCONDDESC 0x76756564 /* */
186 #define JAS_ICC_TAG_VIEWCOND 0x76696577 /* */
187
188 /* Type signatures. */
189 #define JAS_ICC_TYPE_CRDINFO 0x63726469 /* CRD information */
190 #define JAS_ICC_TYPE_CURV 0x63757276 /* curve */
191 #define JAS_ICC_TYPE_DATA 0x64617461 /* data */
192 #define JAS_ICC_TYPE_TIME 0x6474696d /* date/time */
193 #define JAS_ICC_TYPE_DEVSET 0x64657673 /* device settings */
194 #define JAS_ICC_TYPE_LUT16 0x6d667432 /* */
195 #define JAS_ICC_TYPE_LUT8 0x6d667431 /* */
196 #define JAS_ICC_TYPE_MEASURE 0x6d656173 /* */
197 #define JAS_ICC_TYPE_NAMCOLR 0x6e636f6c /* */
198 #define JAS_ICC_TYPE_NAMCOLR2 0x6e636c32 /* */
199 #define JAS_ICC_TYPE_PROFSEQDESC 0x70736571 /* profile sequence description */
200 #define JAS_ICC_TYPE_RESPCURVSET16 0x72637332 /* response curve set 16 */
201 #define JAS_ICC_TYPE_SF32 0x73663332 /* signed 32-bit fixed-point */
202 #define JAS_ICC_TYPE_SCRNG 0x7363726e /* screening */
203 #define JAS_ICC_TYPE_SIG 0x73696720 /* signature */
204 #define JAS_ICC_TYPE_TXTDESC 0x64657363 /* text description */
205 #define JAS_ICC_TYPE_TXT 0x74657874 /* text */
206 #define JAS_ICC_TYPE_UF32 0x75663332 /* unsigned 32-bit fixed-point */
207 #define JAS_ICC_TYPE_UCRBG 0x62666420 /* */
208 #define JAS_ICC_TYPE_UI16 0x75693136 /* */
209 #define JAS_ICC_TYPE_UI32 0x75693332 /* */
210 #define JAS_ICC_TYPE_UI8 0x75693038 /* */
211 #define JAS_ICC_TYPE_UI64 0x75693634 /* */
212 #define JAS_ICC_TYPE_VIEWCOND 0x76696577 /* */
213 #define JAS_ICC_TYPE_XYZ 0x58595a20 /* XYZ */
214
215 typedef uint_fast8_t jas_iccuint8_t;
216 typedef uint_fast16_t jas_iccuint16_t;
217 typedef uint_fast32_t jas_iccuint32_t;
218 typedef int_fast32_t jas_iccsint32_t;
219 typedef int_fast32_t jas_iccs15fixed16_t;
220 typedef uint_fast32_t jas_iccu16fixed16_t;
221 typedef uint_fast64_t jas_iccuint64_t;
222 typedef uint_fast32_t jas_iccsig_t;
223
224 typedef jas_iccsig_t jas_icctagsig_t;
225 typedef jas_iccsig_t jas_icctagtype_t;
226 typedef jas_iccsig_t jas_iccattrname_t;
227
228 /* Date/time type. */
229 typedef struct {
230 jas_iccuint16_t year;
231 jas_iccuint16_t month;
232 jas_iccuint16_t day;
233 jas_iccuint16_t hour;
234 jas_iccuint16_t min;
235 jas_iccuint16_t sec;
236 } jas_icctime_t;
237
238 /* XYZ type. */
239 typedef struct {
240 jas_iccs15fixed16_t x;
241 jas_iccs15fixed16_t y;
242 jas_iccs15fixed16_t z;
243 } jas_iccxyz_t;
244
245 /* Curve type. */
246 typedef struct {
247 jas_iccuint32_t numents;
248 jas_iccuint16_t *ents;
249 } jas_icccurv_t;
250
251 /* Text description type. */
252 typedef struct {
253 jas_iccuint32_t asclen;
254 char *ascdata; /* ASCII invariant description */
255 jas_iccuint32_t uclangcode; /* Unicode language code */
256 jas_iccuint32_t uclen; /* Unicode localizable description count */
257 jas_uchar *ucdata; /* Unicode localizable description */
258 jas_iccuint16_t sccode; /* ScriptCode code */
259 jas_iccuint8_t maclen; /* Localizable Macintosh description count */
260 jas_uchar macdata[69]; /* Localizable Macintosh description */
261 } jas_icctxtdesc_t;
262
263 /* Text type. */
264 typedef struct {
265 char *string; /* ASCII character string */
266 } jas_icctxt_t;
267
268 typedef struct {
269 jas_iccuint8_t numinchans;
270 jas_iccuint8_t numoutchans;
271 jas_iccsint32_t e[3][3];
272 jas_iccuint8_t clutlen;
273 jas_iccuint8_t *clut;
274 jas_iccuint16_t numintabents;
275 jas_iccuint8_t **intabs;
276 jas_iccuint8_t *intabsbuf;
277 jas_iccuint16_t numouttabents;
278 jas_iccuint8_t **outtabs;
279 jas_iccuint8_t *outtabsbuf;
280 } jas_icclut8_t;
281
282 typedef struct {
283 jas_iccuint8_t numinchans;
284 jas_iccuint8_t numoutchans;
285 jas_iccsint32_t e[3][3];
286 jas_iccuint8_t clutlen;
287 jas_iccuint16_t *clut;
288 jas_iccuint16_t numintabents;
289 jas_iccuint16_t **intabs;
290 jas_iccuint16_t *intabsbuf;
291 jas_iccuint16_t numouttabents;
292 jas_iccuint16_t **outtabs;
293 jas_iccuint16_t *outtabsbuf;
294 } jas_icclut16_t;
295
296 struct jas_iccattrval_s;
297
298 typedef struct {
299 void (*destroy)(struct jas_iccattrval_s *);
300 int (*copy)(struct jas_iccattrval_s *, struct jas_iccattrval_s *);
301 int (*input)(struct jas_iccattrval_s *, jas_stream_t *, int);
302 int (*output)(struct jas_iccattrval_s *, jas_stream_t *);
303 int (*getsize)(struct jas_iccattrval_s *);
304 void (*dump)(struct jas_iccattrval_s *, FILE *);
305 } jas_iccattrvalops_t;
306
307 /* Attribute value type (type and value information). */
308 typedef struct jas_iccattrval_s {
309 int refcnt; /* reference count */
310 jas_iccsig_t type; /* type */
311 jas_iccattrvalops_t *ops; /* type-dependent operations */
312 union {
313 jas_iccxyz_t xyz;
314 jas_icccurv_t curv;
315 jas_icctxtdesc_t txtdesc;
316 jas_icctxt_t txt;
317 jas_icclut8_t lut8;
318 jas_icclut16_t lut16;
319 } data; /* value */
320 } jas_iccattrval_t;
321
322 /* Header type. */
323 typedef struct {
324 jas_iccuint32_t size; /* profile size */
325 jas_iccsig_t cmmtype; /* CMM type signature */
326 jas_iccuint32_t version; /* profile version */
327 jas_iccsig_t clas; /* profile/device class signature */
328 jas_iccsig_t colorspc; /* color space of data */
329 jas_iccsig_t refcolorspc; /* profile connection space */
330 jas_icctime_t ctime; /* creation time */
331 jas_iccsig_t magic; /* profile file signature */
332 jas_iccsig_t platform; /* primary platform */
333 jas_iccuint32_t flags; /* profile flags */
334 jas_iccsig_t maker; /* device manufacturer signature */
335 jas_iccsig_t model; /* device model signature */
336 jas_iccuint64_t attr; /* device setup attributes */
337 jas_iccsig_t intent; /* rendering intent */
338 jas_iccxyz_t illum; /* illuminant */
339 jas_iccsig_t creator; /* profile creator signature */
340 } jas_icchdr_t;
341
342 typedef struct {
343 jas_iccsig_t name;
344 jas_iccattrval_t *val;
345 } jas_iccattr_t;
346
347 typedef struct {
348 int numattrs;
349 int maxattrs;
350 jas_iccattr_t *attrs;
351 } jas_iccattrtab_t;
352
353 typedef struct jas_icctagtabent_s {
354 jas_iccuint32_t tag;
355 jas_iccuint32_t off;
356 jas_iccuint32_t len;
357 void *data;
358 struct jas_icctagtabent_s *first;
359 } jas_icctagtabent_t;
360
361 typedef struct {
362 jas_iccuint32_t numents;
363 jas_icctagtabent_t *ents;
364 } jas_icctagtab_t;
365
366 /* ICC profile type. */
367 typedef struct {
368 jas_icchdr_t hdr;
369 jas_icctagtab_t tagtab;
370 jas_iccattrtab_t *attrtab;
371 } jas_iccprof_t;
372
373 typedef struct {
374 jas_iccuint32_t type;
375 jas_iccattrvalops_t ops;
376 } jas_iccattrvalinfo_t;
377
378 JAS_DLLEXPORT jas_iccprof_t *jas_iccprof_load(jas_stream_t *in);
379 JAS_DLLEXPORT int jas_iccprof_save(jas_iccprof_t *prof, jas_stream_t *out);
380 JAS_DLLEXPORT void jas_iccprof_destroy(jas_iccprof_t *prof);
381 JAS_DLLEXPORT jas_iccattrval_t *jas_iccprof_getattr(jas_iccprof_t *prof,
382 jas_iccattrname_t name);
383 JAS_DLLEXPORT int jas_iccprof_setattr(jas_iccprof_t *prof, jas_iccattrname_t name,
384 jas_iccattrval_t *val);
385 JAS_DLLEXPORT void jas_iccprof_dump(jas_iccprof_t *prof, FILE *out);
386 JAS_DLLEXPORT jas_iccprof_t *jas_iccprof_copy(jas_iccprof_t *prof);
387 JAS_DLLEXPORT int jas_iccprof_gethdr(jas_iccprof_t *prof, jas_icchdr_t *hdr);
388 JAS_DLLEXPORT int jas_iccprof_sethdr(jas_iccprof_t *prof, jas_icchdr_t *hdr);
389
390 JAS_DLLEXPORT void jas_iccattrval_destroy(jas_iccattrval_t *attrval);
391 JAS_DLLEXPORT void jas_iccattrval_dump(jas_iccattrval_t *attrval, FILE *out);
392 JAS_DLLEXPORT int jas_iccattrval_allowmodify(jas_iccattrval_t **attrval);
393 JAS_DLLEXPORT jas_iccattrval_t *jas_iccattrval_clone(jas_iccattrval_t *attrval);
394 JAS_DLLEXPORT jas_iccattrval_t *jas_iccattrval_create(jas_iccuint32_t type);
395
396 JAS_DLLEXPORT void jas_iccattrtab_dump(jas_iccattrtab_t *attrtab, FILE *out);
397
398 extern jas_uchar jas_iccprofdata_srgb[];
399 extern int jas_iccprofdata_srgblen;
400 extern jas_uchar jas_iccprofdata_sgray[];
401 extern int jas_iccprofdata_sgraylen;
402 JAS_DLLEXPORT jas_iccprof_t *jas_iccprof_createfrombuf(jas_uchar *buf, int len);
403 JAS_DLLEXPORT jas_iccprof_t *jas_iccprof_createfromclrspc(int clrspc);
404
405 #ifdef __cplusplus
406 }
407 #endif
408
409 #endif