1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gdevpsds.h 8022 2007-06-05 22:23:38Z giles $ */
15
/* Image processing stream interface for PostScript and PDF writers */
17
#ifndef gdevpsds_INCLUDED
18
# define gdevpsds_INCLUDED
23
/* ---------------- Depth conversion ---------------- */
25
/* Convert between 1/2/4/12 bits and 8 bits. */
26
typedef struct stream_1248_state_s {
28
/* The following are set at initialization time. */
29
uint samples_per_row; /* >0 */
30
int bits_per_sample; /* 1, 2, 4, 12 */
31
/* The following are updated dynamically. */
32
uint left; /* # of samples left in current row */
35
/* Convert N (1, 2, 4, 12) bits to 8. */
36
extern const stream_template s_1_8_template;
37
extern const stream_template s_2_8_template;
38
extern const stream_template s_4_8_template;
39
extern const stream_template s_12_8_template;
41
/* Reduce 8 bits to N (1, 2, 4). */
42
/* We do not currently support converting 8 bits to 12. */
43
extern const stream_template s_8_1_template;
44
extern const stream_template s_8_2_template;
45
extern const stream_template s_8_4_template;
47
/* Initialize an expansion or reduction stream. */
48
int s_1248_init(stream_1248_state *ss, int Columns, int samples_per_pixel);
50
/* ---------------- Color space conversion ---------------- */
52
/* Convert (8-bit) CMYK to RGB. */
53
typedef struct stream_C2R_state_s {
55
/* The following are set at initialization time. */
56
const gs_imager_state *pis; /* for UCR & BG */
59
#define private_st_C2R_state() /* in gdevpsds.c */\
60
gs_private_st_ptrs1(st_C2R_state, stream_C2R_state, "stream_C2R_state",\
61
c2r_enum_ptrs, c2r_reloc_ptrs, pis)
62
extern const stream_template s_C2R_template;
64
/* Initialize a CMYK => RGB conversion stream. */
65
int s_C2R_init(stream_C2R_state *ss, const gs_imager_state *pis);
67
/* Convert an image to indexed form (IndexedEncode filter). */
68
typedef struct stream_IE_state_s {
70
/* The client sets the following before initializing the stream. */
71
int BitsPerComponent; /* 1, 2, 4, 8 */
73
int Width; /* pixels per scan line, > 0 */
74
int BitsPerIndex; /* 1, 2, 4, 8 */
76
* Note: this is not quite the same as the Decode array for images:
77
* [0..1] designates the range of the corresponding component of the
78
* color space, not the literal values 0..1. This is the same for
79
* all color spaces except Lab, where the default values here are
80
* [0 1 0 1 0 1] rather than [0 100 amin amax bmin bmax].
84
* The client must provide a Table whose size is at least
85
* ((1 << BitsPerIndex) + 1) * NumComponents. After the stream is
86
* closed, the first (N + 1) * NumComponents bytes of the Table
87
* will hold the palette, where N is the contents of the last byte of
91
/* The following change dynamically. */
92
int hash_table[400]; /* holds byte offsets in Table */
93
int next_index; /* next Table offset to assign */
101
#define private_st_IE_state() /* in gdevpsds.c */\
102
gs_public_st_composite(st_IE_state, stream_IE_state, "stream_IE_state",\
103
ie_state_enum_ptrs, ie_state_reloc_ptrs)
105
extern const stream_template s_IE_template;
107
/* ---------------- Downsampling ---------------- */
109
/* Downsample, possibly with anti-aliasing. */
110
#define stream_Downsample_state_common\
111
stream_state_common;\
112
/* The client sets the following before initialization. */\
114
int WidthIn, HeightIn;\
115
int XFactor, YFactor;\
117
bool padX, padY; /* keep excess samples */\
118
/* The following are updated dynamically. */\
119
int x, y /* position within input image */
120
#define s_Downsample_set_defaults_inline(ss)\
121
((ss)->AntiAlias = (ss)->padX = (ss)->padY = false)
122
typedef struct stream_Downsample_state_s {
123
stream_Downsample_state_common;
124
} stream_Downsample_state;
126
/* Return the number of samples after downsampling. */
127
int s_Downsample_size_out(int size_in, int factor, bool pad);
130
typedef struct stream_Subsample_state_s {
131
stream_Downsample_state_common;
132
} stream_Subsample_state;
133
extern const stream_template s_Subsample_template;
136
typedef struct stream_Average_state_s {
137
stream_Downsample_state_common;
140
uint *sums; /* accumulated sums for average */
141
} stream_Average_state;
143
#define private_st_Average_state() /* in gdevpsds.c */\
144
gs_private_st_ptrs1(st_Average_state, stream_Average_state,\
145
"stream_Average_state", avg_enum_ptrs, avg_reloc_ptrs, sums)
146
extern const stream_template s_Average_template;
148
/* ---------------- Image compression chooser ---------------- */
150
typedef struct stream_compr_chooser_state_s {
153
uint width, height, depth, bits_per_sample;
154
uint samples_count, bits_left;
157
ulong upper_plateaus, lower_plateaus;
159
} stream_compr_chooser_state;
161
#define private_st_compr_chooser_state() /* in gdevpsds.c */\
162
gs_private_st_ptrs1(st_compr_chooser_state, stream_compr_chooser_state, \
163
"stream_compr_chooser_state",\
164
compr_chooser_enum_ptrs, compr_chooser_reloc_ptrs, sample)
166
extern const stream_template s_compr_chooser_template;
168
/* Set image dimensions. */
170
s_compr_chooser_set_dimensions(stream_compr_chooser_state * st, int width,
171
int height, int depth, int bits_per_sample);
174
uint s_compr_chooser__get_choice(stream_compr_chooser_state *st, bool force);
176
/* ---------------- Am image color conversion filter ---------------- */
178
#ifndef gx_device_DEFINED
179
# define gx_device_DEFINED
180
typedef struct gx_device_s gx_device;
183
typedef struct stream_image_colors_state_s stream_image_colors_state;
185
struct stream_image_colors_state_s {
187
uint width, height, depth, bits_per_sample;
188
byte output_bits_buffer;
189
uint output_bits_buffered;
190
uint output_component_bits_written;
191
uint output_component_index;
192
uint output_depth, output_bits_per_sample;
195
uint row_bits_passed;
196
uint row_alignment_bytes;
197
uint row_alignment_bytes_left;
198
uint input_component_index;
199
uint input_bits_buffer;
200
uint input_bits_buffered;
201
uint input_color[GS_IMAGE_MAX_COLOR_COMPONENTS];
202
uint output_color[GS_IMAGE_MAX_COLOR_COMPONENTS];
203
uint MaskColor[GS_IMAGE_MAX_COLOR_COMPONENTS * 2];
204
float Decode[GS_IMAGE_MAX_COLOR_COMPONENTS * 2];
205
const gs_color_space *pcs;
207
const gs_imager_state *pis;
208
int (*convert_color)(stream_image_colors_state *);
211
#define private_st_image_colors_state() /* in gdevpsds.c */\
212
gs_private_st_ptrs3(st_stream_image_colors_state, stream_image_colors_state,\
213
"stream_image_colors_state", stream_image_colors_enum_ptrs,\
214
stream_image_colors_reloc_ptrs, pcs, pdev, pis)
216
extern const stream_template s_image_colors_template;
218
void s_image_colors_set_dimensions(stream_image_colors_state * st,
219
int width, int height, int depth, int bits_per_sample);
221
void s_image_colors_set_mask_colors(stream_image_colors_state * ss, uint *MaskColor);
223
void s_image_colors_set_color_space(stream_image_colors_state * ss, gx_device *pdev,
224
const gs_color_space *pcs, const gs_imager_state *pis,
227
extern const stream_template s__image_colors_template;
229
#endif /* gdevpsds_INCLUDED */