jas_cm.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 /*
63 * Color Management
64 *
65 * $Id$
66 */
67
68 #ifndef JAS_CM_H
69 #define JAS_CM_H
70
71 /* The configuration header file should be included first. */
72 #include <jasper/jas_config.h>
73
74 #include <jasper/jas_icc.h>
75
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79
80 typedef int jas_clrspc_t;
81
82 /* transform operations */
83 #define JAS_CMXFORM_OP_FWD 0
84 #define JAS_CMXFORM_OP_REV 1
85 #define JAS_CMXFORM_OP_PROOF 2
86 #define JAS_CMXFORM_OP_GAMUT 3
87
88 /* rendering intents */
89 #define JAS_CMXFORM_INTENT_PER 0
90 #define JAS_CMXFORM_INTENT_RELCLR 1
91 #define JAS_CMXFORM_INTENT_ABSCLR 2
92 #define JAS_CMXFORM_INTENT_SAT 3
93 #define JAS_CMXFORM_NUMINTENTS 4
94
95 #define JAS_CMXFORM_OPTM_SPEED 0
96 #define JAS_CMXFORM_OPTM_SIZE 1
97 #define JAS_CMXFORM_OPTM_ACC 2
98
99
100 #define jas_clrspc_create(fam, mbr) (((fam) << 8) | (mbr))
101 #define jas_clrspc_fam(clrspc) ((clrspc) >> 8)
102 #define jas_clrspc_mbr(clrspc) ((clrspc) & 0xff)
103 #define jas_clrspc_isgeneric(clrspc) (!jas_clrspc_mbr(clrspc))
104 #define jas_clrspc_isunknown(clrspc) ((clrspc) & JAS_CLRSPC_UNKNOWNMASK)
105
106 #define JAS_CLRSPC_UNKNOWNMASK 0x4000
107
108 /* color space families */
109 #define JAS_CLRSPC_FAM_UNKNOWN 0
110 #define JAS_CLRSPC_FAM_XYZ 1
111 #define JAS_CLRSPC_FAM_LAB 2
112 #define JAS_CLRSPC_FAM_GRAY 3
113 #define JAS_CLRSPC_FAM_RGB 4
114 #define JAS_CLRSPC_FAM_YCBCR 5
115
116 /* specific color spaces */
117 #define JAS_CLRSPC_UNKNOWN JAS_CLRSPC_UNKNOWNMASK
118 #define JAS_CLRSPC_CIEXYZ jas_clrspc_create(JAS_CLRSPC_FAM_XYZ, 1)
119 #define JAS_CLRSPC_CIELAB jas_clrspc_create(JAS_CLRSPC_FAM_LAB, 1)
120 #define JAS_CLRSPC_SGRAY jas_clrspc_create(JAS_CLRSPC_FAM_GRAY, 1)
121 #define JAS_CLRSPC_SRGB jas_clrspc_create(JAS_CLRSPC_FAM_RGB, 1)
122 #define JAS_CLRSPC_SYCBCR jas_clrspc_create(JAS_CLRSPC_FAM_YCBCR, 1)
123
124 /* generic color spaces */
125 #define JAS_CLRSPC_GENRGB jas_clrspc_create(JAS_CLRSPC_FAM_RGB, 0)
126 #define JAS_CLRSPC_GENGRAY jas_clrspc_create(JAS_CLRSPC_FAM_GRAY, 0)
127 #define JAS_CLRSPC_GENYCBCR jas_clrspc_create(JAS_CLRSPC_FAM_YCBCR, 0)
128
129 #define JAS_CLRSPC_CHANIND_YCBCR_Y 0
130 #define JAS_CLRSPC_CHANIND_YCBCR_CB 1
131 #define JAS_CLRSPC_CHANIND_YCBCR_CR 2
132
133 #define JAS_CLRSPC_CHANIND_RGB_R 0
134 #define JAS_CLRSPC_CHANIND_RGB_G 1
135 #define JAS_CLRSPC_CHANIND_RGB_B 2
136
137 #define JAS_CLRSPC_CHANIND_GRAY_Y 0
138
139 typedef double jas_cmreal_t;
140
141 struct jas_cmpxform_s;
142
143 typedef struct {
144 long *buf;
145 int prec;
146 int sgnd;
147 int width;
148 int height;
149 } jas_cmcmptfmt_t;
150
151 typedef struct {
152 int numcmpts;
153 jas_cmcmptfmt_t *cmptfmts;
154 } jas_cmpixmap_t;
155
156 typedef struct {
157 void (*destroy)(struct jas_cmpxform_s *pxform);
158 int (*apply)(struct jas_cmpxform_s *pxform, jas_cmreal_t *in, jas_cmreal_t *out, int cnt);
159 void (*dump)(struct jas_cmpxform_s *pxform);
160 } jas_cmpxformops_t;
161
162 typedef struct {
163 jas_cmreal_t *data;
164 int size;
165 } jas_cmshapmatlut_t;
166
167 typedef struct {
168 int mono;
169 int order;
170 int useluts;
171 int usemat;
172 jas_cmshapmatlut_t luts[3];
173 jas_cmreal_t mat[3][4];
174 } jas_cmshapmat_t;
175
176 typedef struct {
177 int order;
178 } jas_cmshaplut_t;
179
180 typedef struct {
181 int inclrspc;
182 int outclrspc;
183 } jas_cmclrspcconv_t;
184
185 #define jas_align_t double
186
187 typedef struct jas_cmpxform_s {
188 int refcnt;
189 jas_cmpxformops_t *ops;
190 int numinchans;
191 int numoutchans;
192 union {
193 jas_align_t dummy;
194 jas_cmshapmat_t shapmat;
195 jas_cmshaplut_t shaplut;
196 jas_cmclrspcconv_t clrspcconv;
197 } data;
198 } jas_cmpxform_t;
199
200 typedef struct {
201 int numpxforms;
202 int maxpxforms;
203 jas_cmpxform_t **pxforms;
204 } jas_cmpxformseq_t;
205
206 typedef struct {
207 int numinchans;
208 int numoutchans;
209 jas_cmpxformseq_t *pxformseq;
210 } jas_cmxform_t;
211
212 #define JAS_CMPROF_TYPE_DEV 1
213 #define JAS_CMPROF_TYPE_CLRSPC 2
214
215 #define JAS_CMPROF_NUMPXFORMSEQS 13
216
217 typedef struct {
218 int clrspc;
219 int numchans;
220 int refclrspc;
221 int numrefchans;
222 jas_iccprof_t *iccprof;
223 jas_cmpxformseq_t *pxformseqs[JAS_CMPROF_NUMPXFORMSEQS];
224 } jas_cmprof_t;
225
226 #if 0
227 typedef int_fast32_t jas_cmattrname_t;
228 typedef int_fast32_t jas_cmattrval_t;
229 typedef int_fast32_t jas_cmattrtype_t;
230 /* Load a profile. */
231 int jas_cmprof_load(jas_cmprof_t *prof, jas_stream_t *in, int fmt);
232 /* Save a profile. */
233 int jas_cmprof_save(jas_cmprof_t *prof, jas_stream_t *out, int fmt);
234 /* Set an attribute of a profile. */
235 int jas_cm_prof_setattr(jas_cm_prof_t *prof, jas_cm_attrname_t name, void *val);
236 /* Get an attribute of a profile. */
237 void *jas_cm_prof_getattr(jas_cm_prof_t *prof, jas_cm_attrname_t name);
238 #endif
239
240 jas_cmxform_t *jas_cmxform_create(jas_cmprof_t *inprof, jas_cmprof_t *outprof,
241 jas_cmprof_t *proofprof, int op, int intent, int optimize);
242
243 void jas_cmxform_destroy(jas_cmxform_t *xform);
244
245 /* Apply a transform to data. */
246 int jas_cmxform_apply(jas_cmxform_t *xform, jas_cmpixmap_t *in,
247 jas_cmpixmap_t *out);
248
249 int jas_cxform_optimize(jas_cmxform_t *xform, int optimize);
250
251 /* Create a profile. */
252 JAS_DLLEXPORT jas_cmprof_t *jas_cmprof_createfromiccprof(jas_iccprof_t *iccprof);
253 JAS_DLLEXPORT jas_cmprof_t *jas_cmprof_createfromclrspc(int clrspc);
254
255 /* Destroy a profile. */
256 JAS_DLLEXPORT void jas_cmprof_destroy(jas_cmprof_t *prof);
257
258 int jas_clrspc_numchans(int clrspc);
259 jas_iccprof_t *jas_iccprof_createfromcmprof(jas_cmprof_t *prof);
260
261 #define jas_cmprof_clrspc(prof) ((prof)->clrspc)
262 JAS_DLLEXPORT jas_cmprof_t *jas_cmprof_copy(jas_cmprof_t *prof);
263
264 #ifdef __cplusplus
265 }
266 #endif
267
268 #endif