JasPer  4.2.4
jas_cm.h
Go to the documentation of this file.
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 
67 #ifndef JAS_CM_H
68 #define JAS_CM_H
69 
70 /******************************************************************************\
71 *
72 \******************************************************************************/
73 
74 /* The configuration header file should be included first. */
75 #include <jasper/jas_config.h>
76 
77 #include <jasper/jas_types.h>
78 #include <jasper/jas_icc.h>
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
89 /******************************************************************************\
90 * Types and Macros.
91 \******************************************************************************/
92 
97 typedef unsigned jas_clrspc_t;
98 
103 typedef enum {
104  JAS_CMXFORM_OP_FWD = 0,
105  JAS_CMXFORM_OP_REV = 1,
106  JAS_CMXFORM_OP_PROOF = 2,
107  JAS_CMXFORM_OP_GAMUT = 3,
109 
114 typedef enum {
115  JAS_CMXFORM_INTENT_PER = 0,
116  JAS_CMXFORM_INTENT_RELCLR = 1,
117  JAS_CMXFORM_INTENT_ABSCLR = 2,
118  JAS_CMXFORM_INTENT_SAT = 3,
120 
125 #define JAS_CMXFORM_NUMINTENTS 4
126 
131 typedef enum {
132  JAS_CMXFORM_OPTM_SPEED = 0,
133  JAS_CMXFORM_OPTM_SIZE = 1,
134  JAS_CMXFORM_OPTM_ACC = 2,
136 
141 #define jas_clrspc_create(fam, mbr) (((fam) << 8) | (mbr))
142 
148 #define jas_clrspc_fam(clrspc) ((clrspc) >> 8)
149 
154 #define jas_clrspc_mbr(clrspc) ((clrspc) & 0xff)
155 
160 #define jas_clrspc_isgeneric(clrspc) (!jas_clrspc_mbr(clrspc))
161 
166 #define jas_clrspc_isunknown(clrspc) ((clrspc) & JAS_CLRSPC_UNKNOWNMASK)
167 
168 #define JAS_CLRSPC_UNKNOWNMASK 0x4000
169 
173 #define JAS_CLRSPC_FAM_UNKNOWN 0
174 #define JAS_CLRSPC_FAM_XYZ 1
175 #define JAS_CLRSPC_FAM_LAB 2
176 #define JAS_CLRSPC_FAM_GRAY 3
177 #define JAS_CLRSPC_FAM_RGB 4
178 #define JAS_CLRSPC_FAM_YCBCR 5
179 
183 #define JAS_CLRSPC_UNKNOWN JAS_CLRSPC_UNKNOWNMASK
184 #define JAS_CLRSPC_CIEXYZ jas_clrspc_create(JAS_CLRSPC_FAM_XYZ, 1)
185 #define JAS_CLRSPC_CIELAB jas_clrspc_create(JAS_CLRSPC_FAM_LAB, 1)
186 #define JAS_CLRSPC_SGRAY jas_clrspc_create(JAS_CLRSPC_FAM_GRAY, 1)
187 #define JAS_CLRSPC_SRGB jas_clrspc_create(JAS_CLRSPC_FAM_RGB, 1)
188 #define JAS_CLRSPC_SYCBCR jas_clrspc_create(JAS_CLRSPC_FAM_YCBCR, 1)
189 
193 #define JAS_CLRSPC_GENRGB jas_clrspc_create(JAS_CLRSPC_FAM_RGB, 0)
194 #define JAS_CLRSPC_GENGRAY jas_clrspc_create(JAS_CLRSPC_FAM_GRAY, 0)
195 #define JAS_CLRSPC_GENYCBCR jas_clrspc_create(JAS_CLRSPC_FAM_YCBCR, 0)
196 
197 #define JAS_CLRSPC_CHANIND_YCBCR_Y 0
198 #define JAS_CLRSPC_CHANIND_YCBCR_CB 1
199 #define JAS_CLRSPC_CHANIND_YCBCR_CR 2
200 
201 #define JAS_CLRSPC_CHANIND_RGB_R 0
202 #define JAS_CLRSPC_CHANIND_RGB_G 1
203 #define JAS_CLRSPC_CHANIND_RGB_B 2
204 
205 #define JAS_CLRSPC_CHANIND_GRAY_Y 0
206 
210 typedef double jas_cmreal_t;
211 
212 struct jas_cmpxform_s;
213 
218 typedef struct {
219  long *buf;
220  unsigned prec;
221  int sgnd;
222  unsigned width;
223  unsigned height;
225 
230 typedef struct {
231  unsigned numcmpts;
232  jas_cmcmptfmt_t *cmptfmts;
234 
239 typedef struct {
240  void (*destroy)(struct jas_cmpxform_s *pxform);
241  int (*apply)(const struct jas_cmpxform_s *pxform, const jas_cmreal_t *in, jas_cmreal_t *out, unsigned cnt);
242  void (*dump)(struct jas_cmpxform_s *pxform);
244 
249 typedef struct {
250  jas_cmreal_t *data;
251  unsigned size;
253 
258 typedef struct {
259  int mono;
260  int order;
261  int useluts;
262  int usemat;
263  jas_cmshapmatlut_t luts[3];
264  jas_cmreal_t mat[3][4];
266 
271 typedef struct {
272  int order;
274 
279 typedef struct {
280  unsigned inclrspc;
281  unsigned outclrspc;
283 
288 typedef struct jas_cmpxform_s {
289  unsigned refcnt;
290  const jas_cmpxformops_t *ops;
291  unsigned numinchans;
292  unsigned numoutchans;
293  union {
294  max_align_t dummy;
295  jas_cmshapmat_t shapmat;
296  jas_cmshaplut_t shaplut;
297  jas_cmclrspcconv_t clrspcconv;
298  } data;
300 
305 typedef struct {
306  unsigned numpxforms;
307  unsigned maxpxforms;
308  jas_cmpxform_t **pxforms;
310 
315 typedef struct {
316  unsigned numinchans;
317  unsigned numoutchans;
318  jas_cmpxformseq_t *pxformseq;
319 } jas_cmxform_t;
320 
321 #define JAS_CMPROF_TYPE_DEV 1
322 #define JAS_CMPROF_TYPE_CLRSPC 2
323 
324 #define JAS_CMPROF_NUMPXFORMSEQS 13
325 
329 typedef struct {
330  jas_clrspc_t clrspc;
331  unsigned numchans;
332  unsigned refclrspc;
333  unsigned numrefchans;
334  jas_iccprof_t *iccprof;
335  jas_cmpxformseq_t *pxformseqs[JAS_CMPROF_NUMPXFORMSEQS];
336 } jas_cmprof_t;
337 
338 /******************************************************************************\
339 *
340 \******************************************************************************/
341 
342 #if 0
343 typedef int_fast32_t jas_cmattrname_t;
344 typedef int_fast32_t jas_cmattrval_t;
345 typedef int_fast32_t jas_cmattrtype_t;
346 /* Load a profile. */
347 int jas_cmprof_load(jas_cmprof_t *prof, jas_stream_t *in, unsigned fmt);
348 /* Save a profile. */
349 int jas_cmprof_save(jas_cmprof_t *prof, jas_stream_t *out, unsigned fmt);
350 /* Set an attribute of a profile. */
351 int jas_cm_prof_setattr(jas_cm_prof_t *prof, jas_cm_attrname_t name, void *val);
352 /* Get an attribute of a profile. */
353 void *jas_cm_prof_getattr(jas_cm_prof_t *prof, jas_cm_attrname_t name);
354 #endif
355 
356 /******************************************************************************\
357 * Color-management (CM) profile class.
358 \******************************************************************************/
359 
371 JAS_EXPORT
372 jas_cmprof_t *jas_cmprof_createfromiccprof(const jas_iccprof_t *iccprof);
373 
385 JAS_EXPORT
387 
393 JAS_EXPORT
394 void jas_cmprof_destroy(jas_cmprof_t *prof);
395 
407 JAS_EXPORT
409 
421 JAS_EXPORT
422 jas_iccprof_t *jas_iccprof_createfromcmprof(const jas_cmprof_t *prof);
423 
424 /******************************************************************************\
425 * Color-Management (CM) Transform.
426 \******************************************************************************/
427 
438 JAS_EXPORT
440  const jas_cmprof_t *outprof, const jas_cmprof_t *proofprof,
442  jas_cmxform_optm_t optimize);
443 
450 JAS_EXPORT
452 
463 JAS_EXPORT
464 int jas_cmxform_apply(const jas_cmxform_t *xform, const jas_cmpixmap_t *in,
465  jas_cmpixmap_t *out);
466 
467 /******************************************************************************\
468 * Miscellany.
469 \******************************************************************************/
470 
479 unsigned jas_clrspc_numchans(jas_clrspc_t clrspc);
480 
489 #define jas_cmprof_clrspc(prof) ((prof)->clrspc)
490 
495 #ifdef __cplusplus
496 }
497 #endif
498 
499 #endif
jas_cmxform_optm_t
Transform optimization.
Definition: jas_cm.h:131
JAS_EXPORT jas_cmprof_t * jas_cmprof_createfromiccprof(const jas_iccprof_t *iccprof)
Create a color-management profile from an ICC profile.
Definition: jas_cm.c:291
unsigned jas_clrspc_t
Color space.
Definition: jas_cm.h:97
unsigned jas_clrspc_numchans(jas_clrspc_t clrspc)
Get the number of channels associated with a particular color space.
Definition: jas_cm.c:1410
double jas_cmreal_t
Definition: jas_cm.h:210
JAS_EXPORT void jas_cmxform_destroy(jas_cmxform_t *xform)
Destroy a transform.
Definition: jas_cm.c:661
JAS_EXPORT jas_iccprof_t * jas_iccprof_createfromcmprof(const jas_cmprof_t *prof)
Create a ICC profile from a CM profile.
Definition: jas_cm.c:1425
jas_cmxform_intent_t
Rendering intents.
Definition: jas_cm.h:114
jas_cmxform_op_t
Transform operations.
Definition: jas_cm.h:103
JAS_EXPORT jas_cmprof_t * jas_cmprof_copy(const jas_cmprof_t *prof)
Copy a color-management profile.
Definition: jas_cm.c:407
JAS_EXPORT jas_cmprof_t * jas_cmprof_createfromclrspc(jas_clrspc_t clrspc)
Create a color-management profile from a color space.
Definition: jas_cm.c:169
struct jas_cmpxform_s jas_cmpxform_t
Transform class.
JAS_EXPORT int jas_cmxform_apply(const jas_cmxform_t *xform, const jas_cmpixmap_t *in, jas_cmpixmap_t *out)
Apply a transform to data.
Definition: jas_cm.c:552
JAS_EXPORT void jas_cmprof_destroy(jas_cmprof_t *prof)
Destroy a color-management profile.
Definition: jas_cm.c:393
JAS_EXPORT jas_cmxform_t * jas_cmxform_create(const jas_cmprof_t *inprof, const jas_cmprof_t *outprof, const jas_cmprof_t *proofprof, jas_cmxform_op_t op, jas_cmxform_intent_t intent, jas_cmxform_optm_t optimize)
Create a transform from a CM profile.
Definition: jas_cm.c:437
ICC Profile.
Primitive Types.
Color space conversion.
Definition: jas_cm.h:279
Component format.
Definition: jas_cm.h:218
Pixmap (i.e., multicomponent) format.
Definition: jas_cm.h:230
Definition: jas_cm.h:329
Transform class.
Definition: jas_cm.h:288
Transform operations.
Definition: jas_cm.h:239
Primitive transform sequence class.
Definition: jas_cm.h:305
Shaper look-up table (LUT).
Definition: jas_cm.h:271
Shaper matrix.
Definition: jas_cm.h:258
Shaper matrix look-up table (LUT).
Definition: jas_cm.h:249
Primitive transform class.
Definition: jas_cm.h:315
I/O stream object.
Definition: jas_stream.h:206