JasPer  2.0.33
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 /* The configuration header file should be included first. */
71 #include <jasper/jas_config.h>
72 
73 #include <jasper/jas_icc.h>
74 
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 
79 typedef unsigned jas_clrspc_t;
80 
81 /* transform operations */
82 typedef enum {
83  JAS_CMXFORM_OP_FWD = 0,
84  JAS_CMXFORM_OP_REV = 1,
85  JAS_CMXFORM_OP_PROOF = 2,
86  JAS_CMXFORM_OP_GAMUT = 3,
87 } jas_cmxform_op_t;
88 
89 /* rendering intents */
90 typedef enum {
91  JAS_CMXFORM_INTENT_PER = 0,
92  JAS_CMXFORM_INTENT_RELCLR = 1,
93  JAS_CMXFORM_INTENT_ABSCLR = 2,
94  JAS_CMXFORM_INTENT_SAT = 3,
95 } jas_cmxform_intent_t;
96 
97 #define JAS_CMXFORM_NUMINTENTS 4
98 
99 typedef enum {
100  JAS_CMXFORM_OPTM_SPEED = 0,
101  JAS_CMXFORM_OPTM_SIZE = 1,
102  JAS_CMXFORM_OPTM_ACC = 2,
103 } jas_cmxform_optm_t;
104 
105 
106 #define jas_clrspc_create(fam, mbr) (((fam) << 8) | (mbr))
107 #define jas_clrspc_fam(clrspc) ((clrspc) >> 8)
108 #define jas_clrspc_mbr(clrspc) ((clrspc) & 0xff)
109 #define jas_clrspc_isgeneric(clrspc) (!jas_clrspc_mbr(clrspc))
110 #define jas_clrspc_isunknown(clrspc) ((clrspc) & JAS_CLRSPC_UNKNOWNMASK)
111 
112 #define JAS_CLRSPC_UNKNOWNMASK 0x4000
113 
114 /* color space families */
115 #define JAS_CLRSPC_FAM_UNKNOWN 0
116 #define JAS_CLRSPC_FAM_XYZ 1
117 #define JAS_CLRSPC_FAM_LAB 2
118 #define JAS_CLRSPC_FAM_GRAY 3
119 #define JAS_CLRSPC_FAM_RGB 4
120 #define JAS_CLRSPC_FAM_YCBCR 5
121 
122 /* specific color spaces */
123 #define JAS_CLRSPC_UNKNOWN JAS_CLRSPC_UNKNOWNMASK
124 #define JAS_CLRSPC_CIEXYZ jas_clrspc_create(JAS_CLRSPC_FAM_XYZ, 1)
125 #define JAS_CLRSPC_CIELAB jas_clrspc_create(JAS_CLRSPC_FAM_LAB, 1)
126 #define JAS_CLRSPC_SGRAY jas_clrspc_create(JAS_CLRSPC_FAM_GRAY, 1)
127 #define JAS_CLRSPC_SRGB jas_clrspc_create(JAS_CLRSPC_FAM_RGB, 1)
128 #define JAS_CLRSPC_SYCBCR jas_clrspc_create(JAS_CLRSPC_FAM_YCBCR, 1)
129 
130 /* generic color spaces */
131 #define JAS_CLRSPC_GENRGB jas_clrspc_create(JAS_CLRSPC_FAM_RGB, 0)
132 #define JAS_CLRSPC_GENGRAY jas_clrspc_create(JAS_CLRSPC_FAM_GRAY, 0)
133 #define JAS_CLRSPC_GENYCBCR jas_clrspc_create(JAS_CLRSPC_FAM_YCBCR, 0)
134 
135 #define JAS_CLRSPC_CHANIND_YCBCR_Y 0
136 #define JAS_CLRSPC_CHANIND_YCBCR_CB 1
137 #define JAS_CLRSPC_CHANIND_YCBCR_CR 2
138 
139 #define JAS_CLRSPC_CHANIND_RGB_R 0
140 #define JAS_CLRSPC_CHANIND_RGB_G 1
141 #define JAS_CLRSPC_CHANIND_RGB_B 2
142 
143 #define JAS_CLRSPC_CHANIND_GRAY_Y 0
144 
145 typedef double jas_cmreal_t;
146 
147 struct jas_cmpxform_s;
148 
149 typedef struct {
150  long *buf;
151  unsigned prec;
152  int sgnd;
153  unsigned width;
154  unsigned height;
155 } jas_cmcmptfmt_t;
156 
157 typedef struct {
158  unsigned numcmpts;
159  jas_cmcmptfmt_t *cmptfmts;
160 } jas_cmpixmap_t;
161 
162 typedef struct {
163  void (*destroy)(struct jas_cmpxform_s *pxform);
164  int (*apply)(const struct jas_cmpxform_s *pxform, const jas_cmreal_t *in, jas_cmreal_t *out, unsigned cnt);
165  void (*dump)(struct jas_cmpxform_s *pxform);
166 } jas_cmpxformops_t;
167 
168 typedef struct {
169  jas_cmreal_t *data;
170  unsigned size;
171 } jas_cmshapmatlut_t;
172 
173 typedef struct {
174  int mono;
175  int order;
176  int useluts;
177  int usemat;
178  jas_cmshapmatlut_t luts[3];
179  jas_cmreal_t mat[3][4];
180 } jas_cmshapmat_t;
181 
182 typedef struct {
183  int order;
184 } jas_cmshaplut_t;
185 
186 typedef struct {
187  unsigned inclrspc;
188  unsigned outclrspc;
189 } jas_cmclrspcconv_t;
190 
191 #define jas_align_t double
192 
193 typedef struct jas_cmpxform_s {
194  unsigned refcnt;
195  const jas_cmpxformops_t *ops;
196  unsigned numinchans;
197  unsigned numoutchans;
198  union {
199  jas_align_t dummy;
200  jas_cmshapmat_t shapmat;
201  jas_cmshaplut_t shaplut;
202  jas_cmclrspcconv_t clrspcconv;
203  } data;
204 } jas_cmpxform_t;
205 
206 typedef struct {
207  unsigned numpxforms;
208  unsigned maxpxforms;
209  jas_cmpxform_t **pxforms;
210 } jas_cmpxformseq_t;
211 
212 typedef struct {
213  unsigned numinchans;
214  unsigned numoutchans;
215  jas_cmpxformseq_t *pxformseq;
216 } jas_cmxform_t;
217 
218 #define JAS_CMPROF_TYPE_DEV 1
219 #define JAS_CMPROF_TYPE_CLRSPC 2
220 
221 #define JAS_CMPROF_NUMPXFORMSEQS 13
222 
223 typedef struct {
224  jas_clrspc_t clrspc;
225  unsigned numchans;
226  unsigned refclrspc;
227  unsigned numrefchans;
228  jas_iccprof_t *iccprof;
229  jas_cmpxformseq_t *pxformseqs[JAS_CMPROF_NUMPXFORMSEQS];
230 } jas_cmprof_t;
231 
232 #if 0
233 typedef int_fast32_t jas_cmattrname_t;
234 typedef int_fast32_t jas_cmattrval_t;
235 typedef int_fast32_t jas_cmattrtype_t;
236 /* Load a profile. */
237 int jas_cmprof_load(jas_cmprof_t *prof, jas_stream_t *in, unsigned fmt);
238 /* Save a profile. */
239 int jas_cmprof_save(jas_cmprof_t *prof, jas_stream_t *out, unsigned fmt);
240 /* Set an attribute of a profile. */
241 int jas_cm_prof_setattr(jas_cm_prof_t *prof, jas_cm_attrname_t name, void *val);
242 /* Get an attribute of a profile. */
243 void *jas_cm_prof_getattr(jas_cm_prof_t *prof, jas_cm_attrname_t name);
244 #endif
245 
246 JAS_DLLEXPORT jas_cmxform_t *jas_cmxform_create(const jas_cmprof_t *inprof, const jas_cmprof_t *outprof,
247  const jas_cmprof_t *proofprof, jas_cmxform_op_t op, jas_cmxform_intent_t intent, jas_cmxform_optm_t optimize);
248 
249 JAS_DLLEXPORT void jas_cmxform_destroy(jas_cmxform_t *xform);
250 
251 /* Apply a transform to data. */
252 JAS_DLLEXPORT int jas_cmxform_apply(const jas_cmxform_t *xform, const jas_cmpixmap_t *in,
253  jas_cmpixmap_t *out);
254 
255 /* Create a profile. */
256 JAS_DLLEXPORT jas_cmprof_t *jas_cmprof_createfromiccprof(const jas_iccprof_t *iccprof);
257 JAS_DLLEXPORT jas_cmprof_t *jas_cmprof_createfromclrspc(jas_clrspc_t clrspc);
258 
259 /* Destroy a profile. */
260 JAS_DLLEXPORT void jas_cmprof_destroy(jas_cmprof_t *prof);
261 
262 unsigned jas_clrspc_numchans(jas_clrspc_t clrspc);
263 JAS_DLLEXPORT jas_iccprof_t *jas_iccprof_createfromcmprof(const jas_cmprof_t *prof);
264 
265 #define jas_cmprof_clrspc(prof) ((prof)->clrspc)
266 JAS_DLLEXPORT jas_cmprof_t *jas_cmprof_copy(const jas_cmprof_t *prof);
267 
268 #ifdef __cplusplus
269 }
270 #endif
271 
272 #endif
jas_image_destroy
void jas_image_destroy(jas_image_t *image)
Deallocate any resources associated with an image.
Definition: jas_image.c:303
jas_image_cmptprec
#define jas_image_cmptprec(image, cmptno)
Get the precision of the sample data for a component.
Definition: jas_image.h:427
jas_malloc.h
JasPer Memory Allocator.
jasper.h
JasPer Main Header.
jas_stream_fopen
jas_stream_t * jas_stream_fopen(const char *filename, const char *mode)
Open a file as a stream.
Definition: jas_stream.c:301
jas_image_numcmpts
#define jas_image_numcmpts(image)
Get the number of image components.
Definition: jas_image.h:386
jas_stream_close
int jas_stream_close(jas_stream_t *stream)
Close a stream.
Definition: jas_stream.c:610
jas_image_readcmpt
int jas_image_readcmpt(jas_image_t *image, unsigned cmptno, jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height, jas_matrix_t *data)
Read a rectangular region of an image component.
Definition: jas_image.c:470
jas_stream_fdopen
jas_stream_t * jas_stream_fdopen(int fd, const char *mode)
Open a file descriptor as a stream.
Definition: jas_stream.c:540
jas_image_getfmt
int jas_image_getfmt(jas_stream_t *in)
Get the format of image data in a stream.
Definition: jas_image.c:753
jas_image_cmptheight
#define jas_image_cmptheight(image, cmptno)
Get the height of a component.
Definition: jas_image.h:415
jas_image_strtofmt
int jas_image_strtofmt(const char *name)
Get the ID for the image format with the specified name.
Definition: jas_image.c:735
jas_init
JAS_DLLEXPORT int jas_init()
Initialize the JasPer library.
Definition: jas_init.c:77
jas_image_writecmpt
int jas_image_writecmpt(jas_image_t *image, unsigned cmptno, jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height, const jas_matrix_t *data)
Write a rectangular region of an image component.
Definition: jas_image.c:570
jas_stream_memopen
jas_stream_t * jas_stream_memopen(char *buf, int bufsize)
Open a memory buffer as a stream.
Definition: jas_stream.c:276
jas_image_fmttostr
const char * jas_image_fmttostr(int fmt)
Get the name of the image format with the specified ID.
Definition: jas_image.c:744
jas_debug.h
JasPer Debugging-Related Functionality.
jas_image_cmptwidth
#define jas_image_cmptwidth(image, cmptno)
Get the width of a component.
Definition: jas_image.h:409
jas_image_rawsize
uint_fast32_t jas_image_rawsize(const jas_image_t *image)
Get the raw size of an image (i.e., the nominal size of the image without any compression.
Definition: jas_image.c:816
jas_image_create
jas_image_t * jas_image_create(unsigned numcmpts, const jas_image_cmptparm_t *cmptparms, jas_clrspc_t clrspc)
Create an image.
Definition: jas_image.c:127
jas_icc.h
ICC Profile.
jas_image_encode
int jas_image_encode(jas_image_t *image, jas_stream_t *out, int fmt, const char *optstr)
Write an image to a stream in a specified format.
Definition: jas_image.c:454
jas_cm.h
JasPer Color Management.
jas_image_clearfmts
void jas_image_clearfmts()
Clear the table of image formats.
Definition: jas_image.c:666
jas_image_decode
jas_image_t * jas_image_decode(jas_stream_t *in, int fmt, const char *optstr)
Create an image from a stream in some specified format.
Definition: jas_image.c:416
jas_image_t
Image class.
Definition: jas_image.h:202
jas_math.h
Math-Related Code.
jas_image_cmptparm_t
Component parameters class.
Definition: jas_image.h:243