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
|
/* Copyright (C) 1996, 1997, 1998 Aladdin Enterprises. All rights
reserved. Unauthorized use, copying, and/or distribution
prohibited. */
/* pccolor.c - commands to add colors to a PCL palette */
#include "std.h"
#include "pcommand.h"
#include "pcstate.h"
#include "pcpalet.h"
/*
* Prior to being assigned into a palette, the PCL color component values are
* simple globals; they are not saved and restored with the PCL state.
*
* This implies that color components may not be converted until the set
* color index command is executed, as it is not possible to predict for
* which palette they will be used.
*
* NB: contrary to the documentation, all of the set color component commands
* and the assign color index command are allowed but ignored in graphics
* mode (i.e.: they do NOT end graphics mode, as one would expect from the
* documentation).
*/
/*
* ESC * v <cc> A
*/
private int
set_color_comp_1(
pcl_args_t * pargs,
pcl_state_t * pcs
)
{
if (!pcs->raster_state.graphics_mode)
pcs->color_comps[0] = float_arg(pargs);
return 0;
}
/*
* ESC * v <cc> B
*/
private int
set_color_comp_2(
pcl_args_t * pargs,
pcl_state_t * pcs
)
{
if (!pcs->raster_state.graphics_mode)
pcs->color_comps[1] = float_arg(pargs);
return 0;
}
/*
* ESC * v <cc> C
*/
private int
set_color_comp_3(
pcl_args_t * pargs,
pcl_state_t * pcs
)
{
if (!pcs->raster_state.graphics_mode)
pcs->color_comps[2] = float_arg(pargs);
return 0;
}
/*
* ESC * v <indx> I
*
* Set a color into the active palette.
*
* This implementation matches HP's documentation, in that out-of-range indices
* will not affect the palette, but will reset the color component registers.
* This matches the behavior of the HP Color Laser Jet 5/5M, but not that of
* the HP DeskJet 1600C/CM. For the latter, negative indices are ignored and
* the color component registers are NOT cleared, while positive indices are
* interpreted modulo the palette size.
*/
private int
assign_color_index(
pcl_args_t * pargs,
pcl_state_t * pcs
)
{
int indx = int_arg(pargs);
if (!pcs->raster_state.graphics_mode) {
if ((indx >= 0) && (indx < pcl_palette_get_num_entries(pcs->ppalet)))
pcl_palette_set_color(pcs, indx, pcs->color_comps);
pcs->color_comps[0] = 0.0;
pcs->color_comps[1] = 0.0;
pcs->color_comps[2] = 0.0;
}
return 0;
}
/*
* Initialization
*/
private int
color_do_registration(
pcl_parser_state_t *pcl_parser_state,
gs_memory_t * pmem
)
{
/* Register commands */
DEFINE_CLASS('*')
{
'v', 'A',
PCL_COMMAND( "Color Component 1",
set_color_comp_1,
pca_neg_ok | pca_big_error | pca_raster_graphics
)
},
{
'v', 'B',
PCL_COMMAND( "Color Component 2",
set_color_comp_2,
pca_neg_ok | pca_big_error | pca_raster_graphics
)
},
{
'v', 'C',
PCL_COMMAND( "Color Component 3",
set_color_comp_3,
pca_neg_ok | pca_big_error | pca_raster_graphics
)
},
{
'v', 'I',
PCL_COMMAND( "Assign Color Index",
assign_color_index,
pca_neg_ok | pca_big_ignore | pca_raster_graphics
)
},
END_CLASS
return 0;
}
/*
* Handle the various forms of reset.
*/
private void
color_do_reset(
pcl_state_t * pcs,
pcl_reset_type_t type
)
{
static const uint mask = ( pcl_reset_initial
| pcl_reset_cold
| pcl_reset_printer );
if ((type & mask) != 0) {
pcs->color_comps[0] = 0.0;
pcs->color_comps[1] = 0.0;
pcs->color_comps[2] = 0.0;
}
}
/*
* There is no copy operation for this module, as the color components are
* just globals.
*/
const pcl_init_t pcl_color_init = { color_do_registration, color_do_reset, 0 };
|