Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/* Copyright (C) 2001 1999 Aladdin Enterprises.  All rights reserved.
2
 
3
  This software is provided AS-IS with no warranty, either express or
4
  implied.
5
 
6
  This software is distributed under license and may not be copied,
7
  modified or distributed except as expressly authorized under the terms
8
  of the license contained in the file LICENSE in this distribution.
9
 
10
  For more information about licensing, please refer to
11
  http://www.ghostscript.com/licensing/. For information on
12
  commercial licensing, go to http://www.artifex.com/licensing/ or
13
  contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14
  San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15
*/
16
 
17
/* $Id: gsicc.h,v 1.7 2002/12/03 02:41:04 dan Exp $ */
18
/* Structures for ICCBased color space parameters */
19
/* requires: gspsace.h, gscolor2.h */
20
 
21
#ifndef gsicc_INCLUDED
22
#  define gsicc_INCLUDED
23
 
24
#include "gscie.h"
25
 
26
/*
27
 * The gs_cie_icc_s structure will exist in all instantiations of the
28
 * graphic library, whether or not they provide support of the ICCBased
29
 * color spaces. If such support is not provided, we cannot assume that
30
 * the ICC support library (icclib) is included in the source code, so
31
 * we also cannot assume that the header file icc.h is available during
32
 * compilation. Hence we cannot include icc.h in this file.
33
 *
34
 * The following two opaque declarations are used to get around this
35
 * limitation.
36
 */
37
struct _icc;
38
struct _icmLuBase;
39
 
40
/*
41
 * ICCBased color spaces are a feature of PDF 1.3. They are effectively a
42
 * variation of the CIEBased color spaces, in which the mapping to XYZ space
43
 * is accomplished via an ICC profile rather than via matrices and procedures
44
 * in a color space dictionary.
45
 *
46
 * For historical reasons, the graphic library code for mapping XYZ colors
47
 * to the device color model assumes that a CIEBasedABC color space is
48
 * being used (there is a small exception for CIEBasedA). The mechanism used
49
 * by the CIE joint caches is dependent on this. To remain compatibile with
50
 * this arrangement, the gs_cie_icc_s structure must contain the
51
 * gs_cie_common_elements prefix, even though this structure serves only
52
 * as carrier of the white and black point information (all other parameters
53
 * are set to their default values).
54
 *
55
 * The icclib code was originally created to read from a file using the
56
 * stdio library. We can generalize the module to work with a positionable
57
 * stream with a simple change of header files. Somewhat more difficult
58
 * issues are involved adapting icclib to the graphic libraries memory
59
 * management scheme.
60
 *
61
 * The stream that comprises the filter is initially a PostScript object.
62
 * As such, it subject save/restore, garbage collection, relocation, may
63
 * be accessed and closed explicitly by the PostScript code. Most
64
 * significantly, a given stream structure instance may be re-used once it
65
 * has been closed.
66
 *
67
 * Unfortunately, the icclib code retains the stream pointer for
68
 * (potentially) long periods of time, and is blissfully unaware of all of
69
 * these possibilities. We also would like very much to avoid having to
70
 * make it aware of these complexities (so that we may easily use future
71
 * upgrades). The following methods are used to achieve this goal:
72
 *
73
 *    This color space structure may be used only so long as the PostScript
74
 *    color space array that generated it is still accessible. If this array
75
 *    is accessible, the stream is also accessible. Hence, we do not need to
76
 *    provide access to that stream via this this object, nor can we loose
77
 *    the stream via save/restore.
78
 *
79
 *    The color space objects themselves (the top-level profile structure
80
 *    pointed to by picc and the lookup object pointed to by plu) are 
81
 *    allocated in non-garbage collected ("foreign") memory, so we do not
82
 *    have to indicate access via this structure, nor do we have to be
83
 *    concerned about relocation of these structures.
84
 *
85
 *    (Supporting relocation in icclib would require significant changes
86
 *    to the library, which would complicate any future upgrades. To
87
 *    support garbage collection would, at a minimum, require a modified
88
 *    set of operands for the allocation procedure used by the library,
89
 *    which also seems ill advised.)
90
 *
91
 *    Because the input stream structure is re-locatable, it is necessary
92
 *    to update the stream pointer held in the profile data structure
93
 *    prior to any call to the module. We retain a pointer to the stream
94
 *    in the gs_cie_icc_s structure, for which a structure descriptor is
95
 *    provided, and use this to update the value held by the icc library.
96
 *    The method update_file_ptr has been added to the _icc structure to
97
 *    facilitate this process.
98
 *
99
 *    In principle, a user should not close the stream object included
100
 *    in a color space until that space is no longer needed. But there is
101
 *    no language-level mechanism to detect/prevent such activities, so
102
 *    we must deal with that possibility here. The method employed
103
 *    mimics that used with PostScript file objects. The file_id field is
104
 *    initialized to the value of (instrp->read_id | instrp->write_id),
105
 *    and is compared with this value prior to any call. If the values are
106
 *    no longer the same, the stream has been closed and a suitable
107
 *    error is generated.
108
 */
109
struct gs_cie_icc_s {
110
    gs_cie_common_elements;
111
 
112
    /* number of components, and their associated range */
113
    uint                num_components;
114
    gs_range4           Range;
115
 
116
    /* stream object, and the associated read id */
117
    unsigned short      file_id;
118
    stream *            instrp;
119
 
120
    /* the following are set when the structure is initialized */
121
 
122
    /* must the profile connection space undergo an L*a*b* ==> XYZ conversion */
123
    bool                pcs_is_cielab;
124
 
125
    /* top-level icclib data structure for the profile */
126
    struct _icc *       picc;
127
 
128
    /* "lookup" data structure in the ICC profile */
129
    struct _icmLuBase * plu;
130
 
131
    /* icclib file object for ICC stream */
132
    struct _icmFile   * pfile;
133
};
134
 
135
/*
136
 * The gs_cie_icc_s structure is responsible for foreign memory that must be
137
 * freed when the object is no longer accessible. It is the only CIE space
138
 * structure that contains such pointers. We make use of the finalization
139
 * procedure to handle this task.
140
 */
141
#define private_st_cie_icc()    /* in gscsicc.c */            \
142
    gs_private_st_suffix_add1_final( st_cie_icc,              \
143
                                     gs_cie_icc,              \
144
                                     "gs_cie_icc",            \
145
                                     cie_icc_enum_ptrs,       \
146
                                     cie_icc_reloc_ptrs,      \
147
                                     cie_icc_finalize,        \
148
                                     st_cie_common_elements_t,\
149
                                     instrp )
150
 
151
/* typedef struct gs_cie_icc_s gs_cie_icc; */   /* in gscspace.h */
152
 
153
 
154
/* 
155
 * Build an ICCBased color space.
156
 *
157
 * As with all of the CIE base color space constructurs, this will build
158
 * an gs_cie_icc_s structure with a reference count of 1 (not 0). If the
159
 * color space is passed to gs_setcolorspace, that procedure  will increment
160
 * the reference count again. To prevent the color space from being allocated
161
 * permanently, the client should call cs_adjust_count(pcspace, -1).
162
 * THIS IS A BUG IN THE API.
163
 *
164
 * The client is responsible for initializing the alternative color space
165
 * information.
166
 */
167
extern  int     gs_cspace_build_CIEICC( gs_color_space **   ppcspace,
168
					void *              client_data,
169
					gs_memory_t *       pmem );
170
 
171
int
172
gx_load_icc_profile(gs_cie_icc *picc_info);
173
 
174
/*
175
 * Increment color space reference counts.
176
 */
177
void
178
gx_increment_cspace_count(const gs_color_space * pcs);
179
 
180
#endif /* gsicc_INCLUDED */