summaryrefslogtreecommitdiff
path: root/pcl/pcpalet.h
blob: 4df5b4924bef2450db55359a2b5d2470767b50bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* Portions Copyright (C) 2001 artofcode LLC.
   Portions Copyright (C) 1996, 2001 Artifex Software Inc.
   Portions Copyright (C) 1988, 2000 Aladdin Enterprises.
   This software is based in part on the work of the Independent JPEG Group.
   All Rights Reserved.

   This software is distributed under license and may not be copied, modified
   or distributed except as expressly authorized under the terms of that
   license.  Refer to licensing information at http://www.artifex.com/ or
   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
   San Rafael, CA  94903, (415)492-9861, for further information. */
/*$Id$ */

/* pcpalet.h - PCL palette object */

#ifndef pcpalet_INCLUDED
#define pcpalet_INCLUDED

#include "gx.h"
#include "gsstruct.h"
#include "gsrefct.h"
#include "pcident.h"
#include "pcstate.h"
#include "pcommand.h"
#include "pclookup.h"
#include "pcdither.h"
#include "pccid.h"
#include "pcindxed.h"
#include "pcht.h"
#include "pccrd.h"

/*
 * The PCL palette.
 *
 * The identifier is used to indicate when colored patterns need to be
 * re-rendered.
 *
 * A curious feature of the PCL palette is not the object itself, but the
 * manner in which it is stored in the PCL state. During normal operation,
 * the PCL state does not maintain a reference to a plette. Rather, it
 * maintains a current installed palette ID, which can be searched for the
 * in the appropriate dictionary to find the current palette. Changes to
 * the current palette update this entry directly.
 *
 * In the case of a called or overlayed macro, however, the saved PCL state
 * will create its own reference to the palette, as well as retaining the
 * current palette id. in effect at the time the palette was saved. When the
 * state is subsequently restored, the save palette is once more associated
 * with the save palette id. Hence, the end of a called or overlay macro can
 * lead to a redefinition in the palette store. This is inconsistent with
 * the way all other identified objects are handled in PCL, but it is the
 * mechanism HP selected.
 */
struct pcl_palette_s {
    rc_header           rc;
    pcl_gsid_t          id;
    pcl_cs_indexed_t *  pindexed;
    pcl_crd_t *         pcrd;
    pcl_ht_t *          pht;
};

#ifndef pcl_palette_DEFINED
#define pcl_palette_DEFINED
typedef struct pcl_palette_s    pcl_palette_t;
#endif

#define private_st_palette_t()                  \
    gs_private_st_ptrs3( st_palette_t,          \
                         pcl_palette_t,         \
                         "pcl palette object",  \
                         palette_enum_ptrs,     \
                         palette_reloc_ptrs,    \
                         pindexed,              \
                         pcrd,                  \
                         pht                    \
                         )


/*
 * The usual init, copy,and release macros.
 */
#define pcl_palette_init_from(pto, pfrom)   \
    BEGIN                                   \
    rc_increment(pfrom);                    \
    (pto) = (pfrom);                        \
    END

#define pcl_palette_copy_from(pto, pfrom)           \
    BEGIN                                           \
    if ((pto) != (pfrom)) {                         \
        rc_increment(pfrom);                        \
        rc_decrement(pto, "pcl_palette_copy_from"); \
        (pto) = (pfrom);                            \
    }                                               \
    END

#define pcl_palette_release(pbase)           \
    rc_decrement(pbase, "pcl_frgrnd_release")


/*
 * Get the color space type for the base color space of a palette.
 */
#define pcl_palette_get_cspace(ppalet)  \
    ((pcl_cspace_type_t)((ppalet)->pindexed->cid.cspace))

/*
 * Get the pixel encoding mode from the current palette.
 */
#define pcl_palette_get_encoding(ppalet)    \
    ((pcl_encoding_type_t)((ppalet)->pindexed->cid.encoding))

/*
 * Get the number of bits per index from the current palette.
 */
#define pcl_palette_get_bits_per_index(ppalet)  \
    ((ppalet)->pindexed->cid.bits_per_index)

/*
 * Get the number of bits per primary from the current palette.
 */
#define pcl_palette_get_bits_per_primary(ppalet, i) \
    ((ppalet)->pindexed->cid.bits_per_primary[i])

/*
 * Macro to return the number or entries in the current palette.
 */
#define pcl_palette_get_num_entries(ppalet) \
    pcl_cs_indexed_get_num_entries((ppalet)->pindexed)

/*
 * Macro to return a pointer to the array of pen widths.
 */
#define pcl_palette_get_pen_widths(ppalet)  \
    pcl_cs_indexed_get_pen_widths((ppalet)->pindexed)

/*
 * Set the normalization values for an indexed color space. This is needed
 * only for the GL/2 CR command; PCL sets normalization information via the
 * configure image data command, which builds a new indexed color space.
 *
 * Returns 0 on success, < 0 in the event of an error.
 */
int pcl_palette_CR(
    pcl_state_t *   pcs,
    floatp          wht0,
    floatp          wht1,
    floatp          wht2,
    floatp          blk0,
    floatp          blk1,
    floatp          blk2
);

/*
 * Set the number of entries in a color palette. This is needed only for the
 * GL/2 NP command; PCL sets the number of entries in a palette via the
 * configure image data command, which creates a new indexed color space.
 *
 * Returns 0 on success, < 0 in the event of an error.
 */
int pcl_palette_NP(pcl_state_t * pcs, int num_entries);

/*
 * Set a pen width. Note that this does NOT change the palette id. This
 * procedure can only be called from GL/2, hence the procedure name.
 *
 * Returns 0 on success, < 0 in the even of an error;
 */
int pcl_palette_PW(pcl_state_t * pcs, int pen, floatp width);

/*
 * Support for the GL/2 IN command. This is actually implemented in pccid.c,
 * but an interface is included here for consistency.
 */
#define pcl_palette_IN(pcs) pcl_cid_IN(pcs)

/*
 * Set the render method for the palette.
 *
 * Returns 0 on success, < 0 in the event of an error.
 */
int pcl_palette_set_render_method(
    pcl_state_t *    pcs,
    uint             render_method
);

/*
 * Set gamma correction information for a palette.
 *
 * Gamma correction and the color lookup table for device specific color spaces
 * perform the same function, but are of different origins. Hence, while a
 * configure image data command will discard all color lookup tables, it inherits
 * the gamma configuration parameter from the existing palette. In addition,
 * while there is an "unset" command for color lookup tables, there is no such
 * command for gamma correction: to override the existing gamma correction,
 * either specify a new one or download a color correction table for a device
 * specific color space.
 *
 * Returns 0 on success, < 0 in the event of an error.
 */
int pcl_palette_set_gamma(pcl_state_t * pcs, float gamma);

/*
 * Set color lookup table information for a palette.
 *
 * Lookup tables for device-specific and device-independent color spaces are
 * implemented in different ways. The former are implemented via transfer
 * functions, and thus affect the halftone component of the current palette.
 * The latter are implemented in the device-independent color spaces themselves,
 * and thus affect the color spaces component of the palette.
 *
 * An anachronism of the PCL is that, while color lookup tables may be set
 * individually for different color spaces, they only be cleared all at once.
 * This is accomplished by calling this routine with a null lookup table pointer.
 *
 * Returns 0 on success, < 0 in the event of an error.
 */
int pcl_palette_set_lookup_tbl(
    pcl_state_t *       pcs,
    pcl_lookup_tbl_t *  plktbl
);

/*
 * Set an entry in a color palette.
 *
 * Returns 0 on success, < 0 in the event of an error. The returned code will
 * normally be ignored.
 */
int pcl_palette_set_color(
    pcl_state_t *   pcs,
    int             indx,
    const float     comps[3]
);

/*
 * Set a palette entry to its default color.
 *
 * Returns 0 on success, < 0 in the event of an error. The returned code will
 * normally be ignored.
 */
int pcl_palette_set_default_color(
    pcl_state_t *   pcs,
    int             indx
);

/*
 * Set the user-defined dither matrix.
 *
 * Returns 0 on success, < 0 in the event of an error.
 */
int pcl_palette_set_udither(
    pcl_state_t *   pcs,
    pcl_udither_t * pdither
);

/*
 * Overwrite the current palette with new a new image data configuration.
 * This will rebuild the indexed color space, and discard any currently
 * installed color lookup tables.
 *
 * Tf the operand "fixed" is true, this procedure is being called as part of
 * a "simple color mode" command, and the resulting color palette will have
 * fixed entries.
 *
 * The boolean operand gl2 indicates if this call is being made as the result
 * of an IN command in GL/2. If so, the default set of entries in the color
 * palette is modified.
 *
 * Returns 0 on success, < 0 in the event of an error.
 */
int pcl_palette_set_cid(
    pcl_state_t *       pcs,
    pcl_cid_data_t *    pcid,
    bool                fixed,
    bool                gl2
);

/*
 * Set the view illuminant for a palette.
 *
 * Returns 0 on success, < 0 in the event of an error.
 */
int pcl_palette_set_view_illuminant(
    pcl_state_t *       pcs,
    const gs_vector3 *  pwht_pt
);

/*
 * Check that all parts of a PCL palette have been built. If not, build the
 * necessary default objects.
 *
 * Returns 0 on success, < 0 in the event of an error.
 */
int pcl_palette_check_complete(pcl_state_t * pcs);


#define private_st_pstack_entry_t()		\
    gs_private_st_ptrs1( st_pstack_entry_t,	\
                     pstack_entry_t,		\
                     "palette stack entry",	\
                     pstack_enum_ptrs,		\
                     pstack_reloc_ptrs,		\
                     ppalet			\
                     );

/*
 * Entry points to the palette-related commands.
 */
extern  const pcl_init_t    pcl_palette_init;
extern  const pcl_init_t    pcl_color_init;


/* free default objects (pcs->pdfl_*) 
 * called at end of process.
 */
void pcl_free_default_objects(gs_memory_t *mem, pcl_state_t *pcs);


#endif		/* pcpalet_INCLUDED */