2 |
- |
1 |
/* Copyright (C) 1997, 2000 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: gdevpsds.h,v 1.12 2005/02/26 18:07:43 igor Exp $ */
|
|
|
18 |
/* Image processing stream interface for PostScript and PDF writers */
|
|
|
19 |
|
|
|
20 |
#ifndef gdevpsds_INCLUDED
|
|
|
21 |
# define gdevpsds_INCLUDED
|
|
|
22 |
|
|
|
23 |
#include "strimpl.h"
|
|
|
24 |
#include "gsiparam.h"
|
|
|
25 |
|
|
|
26 |
/* ---------------- Depth conversion ---------------- */
|
|
|
27 |
|
|
|
28 |
/* Convert between 1/2/4/12 bits and 8 bits. */
|
|
|
29 |
typedef struct stream_1248_state_s {
|
|
|
30 |
stream_state_common;
|
|
|
31 |
/* The following are set at initialization time. */
|
|
|
32 |
uint samples_per_row; /* >0 */
|
|
|
33 |
int bits_per_sample; /* 1, 2, 4, 12 */
|
|
|
34 |
/* The following are updated dynamically. */
|
|
|
35 |
uint left; /* # of samples left in current row */
|
|
|
36 |
} stream_1248_state;
|
|
|
37 |
|
|
|
38 |
/* Convert N (1, 2, 4, 12) bits to 8. */
|
|
|
39 |
extern const stream_template s_1_8_template;
|
|
|
40 |
extern const stream_template s_2_8_template;
|
|
|
41 |
extern const stream_template s_4_8_template;
|
|
|
42 |
extern const stream_template s_12_8_template;
|
|
|
43 |
|
|
|
44 |
/* Reduce 8 bits to N (1, 2, 4). */
|
|
|
45 |
/* We do not currently support converting 8 bits to 12. */
|
|
|
46 |
extern const stream_template s_8_1_template;
|
|
|
47 |
extern const stream_template s_8_2_template;
|
|
|
48 |
extern const stream_template s_8_4_template;
|
|
|
49 |
|
|
|
50 |
/* Initialize an expansion or reduction stream. */
|
|
|
51 |
int s_1248_init(stream_1248_state *ss, int Columns, int samples_per_pixel);
|
|
|
52 |
|
|
|
53 |
/* ---------------- Color space conversion ---------------- */
|
|
|
54 |
|
|
|
55 |
/* Convert (8-bit) CMYK to RGB. */
|
|
|
56 |
typedef struct stream_C2R_state_s {
|
|
|
57 |
stream_state_common;
|
|
|
58 |
/* The following are set at initialization time. */
|
|
|
59 |
const gs_imager_state *pis; /* for UCR & BG */
|
|
|
60 |
} stream_C2R_state;
|
|
|
61 |
|
|
|
62 |
#define private_st_C2R_state() /* in gdevpsds.c */\
|
|
|
63 |
gs_private_st_ptrs1(st_C2R_state, stream_C2R_state, "stream_C2R_state",\
|
|
|
64 |
c2r_enum_ptrs, c2r_reloc_ptrs, pis)
|
|
|
65 |
extern const stream_template s_C2R_template;
|
|
|
66 |
|
|
|
67 |
/* Initialize a CMYK => RGB conversion stream. */
|
|
|
68 |
int s_C2R_init(stream_C2R_state *ss, const gs_imager_state *pis);
|
|
|
69 |
|
|
|
70 |
/* Convert an image to indexed form (IndexedEncode filter). */
|
|
|
71 |
typedef struct stream_IE_state_s {
|
|
|
72 |
stream_state_common;
|
|
|
73 |
/* The client sets the following before initializing the stream. */
|
|
|
74 |
int BitsPerComponent; /* 1, 2, 4, 8 */
|
|
|
75 |
int NumComponents;
|
|
|
76 |
int Width; /* pixels per scan line, > 0 */
|
|
|
77 |
int BitsPerIndex; /* 1, 2, 4, 8 */
|
|
|
78 |
/*
|
|
|
79 |
* Note: this is not quite the same as the Decode array for images:
|
|
|
80 |
* [0..1] designates the range of the corresponding component of the
|
|
|
81 |
* color space, not the literal values 0..1. This is the same for
|
|
|
82 |
* all color spaces except Lab, where the default values here are
|
|
|
83 |
* [0 1 0 1 0 1] rather than [0 100 amin amax bmin bmax].
|
|
|
84 |
*/
|
|
|
85 |
const float *Decode;
|
|
|
86 |
/*
|
|
|
87 |
* The client must provide a Table whose size is at least
|
|
|
88 |
* ((1 << BitsPerIndex) + 1) * NumComponents. After the stream is
|
|
|
89 |
* closed, the first (N + 1) * NumComponents bytes of the Table
|
|
|
90 |
* will hold the palette, where N is the contents of the last byte of
|
|
|
91 |
* the Table.
|
|
|
92 |
*/
|
|
|
93 |
gs_bytestring Table;
|
|
|
94 |
/* The following change dynamically. */
|
|
|
95 |
int hash_table[400]; /* holds byte offsets in Table */
|
|
|
96 |
int next_index; /* next Table offset to assign */
|
|
|
97 |
uint byte_in;
|
|
|
98 |
int in_bits_left;
|
|
|
99 |
int next_component;
|
|
|
100 |
uint byte_out;
|
|
|
101 |
int x;
|
|
|
102 |
} stream_IE_state;
|
|
|
103 |
|
|
|
104 |
#define private_st_IE_state() /* in gdevpsds.c */\
|
|
|
105 |
gs_public_st_composite(st_IE_state, stream_IE_state, "stream_IE_state",\
|
|
|
106 |
ie_state_enum_ptrs, ie_state_reloc_ptrs)
|
|
|
107 |
|
|
|
108 |
extern const stream_template s_IE_template;
|
|
|
109 |
|
|
|
110 |
/* ---------------- Downsampling ---------------- */
|
|
|
111 |
|
|
|
112 |
/* Downsample, possibly with anti-aliasing. */
|
|
|
113 |
#define stream_Downsample_state_common\
|
|
|
114 |
stream_state_common;\
|
|
|
115 |
/* The client sets the following before initialization. */\
|
|
|
116 |
int Colors;\
|
|
|
117 |
int WidthIn, HeightIn;\
|
|
|
118 |
int XFactor, YFactor;\
|
|
|
119 |
bool AntiAlias;\
|
|
|
120 |
bool padX, padY; /* keep excess samples */\
|
|
|
121 |
/* The following are updated dynamically. */\
|
|
|
122 |
int x, y /* position within input image */
|
|
|
123 |
#define s_Downsample_set_defaults_inline(ss)\
|
|
|
124 |
((ss)->AntiAlias = (ss)->padX = (ss)->padY = false)
|
|
|
125 |
typedef struct stream_Downsample_state_s {
|
|
|
126 |
stream_Downsample_state_common;
|
|
|
127 |
} stream_Downsample_state;
|
|
|
128 |
|
|
|
129 |
/* Return the number of samples after downsampling. */
|
|
|
130 |
int s_Downsample_size_out(int size_in, int factor, bool pad);
|
|
|
131 |
|
|
|
132 |
/* Subsample */
|
|
|
133 |
typedef struct stream_Subsample_state_s {
|
|
|
134 |
stream_Downsample_state_common;
|
|
|
135 |
} stream_Subsample_state;
|
|
|
136 |
extern const stream_template s_Subsample_template;
|
|
|
137 |
|
|
|
138 |
/* Average */
|
|
|
139 |
typedef struct stream_Average_state_s {
|
|
|
140 |
stream_Downsample_state_common;
|
|
|
141 |
uint sum_size;
|
|
|
142 |
uint copy_size;
|
|
|
143 |
uint *sums; /* accumulated sums for average */
|
|
|
144 |
} stream_Average_state;
|
|
|
145 |
|
|
|
146 |
#define private_st_Average_state() /* in gdevpsds.c */\
|
|
|
147 |
gs_private_st_ptrs1(st_Average_state, stream_Average_state,\
|
|
|
148 |
"stream_Average_state", avg_enum_ptrs, avg_reloc_ptrs, sums)
|
|
|
149 |
extern const stream_template s_Average_template;
|
|
|
150 |
|
|
|
151 |
/* ---------------- Image compression chooser ---------------- */
|
|
|
152 |
|
|
|
153 |
typedef struct stream_compr_chooser_state_s {
|
|
|
154 |
stream_state_common;
|
|
|
155 |
uint choice;
|
|
|
156 |
uint width, height, depth, bits_per_sample;
|
|
|
157 |
uint samples_count, bits_left;
|
|
|
158 |
ulong packed_data;
|
|
|
159 |
byte *sample;
|
|
|
160 |
ulong upper_plateaus, lower_plateaus;
|
|
|
161 |
ulong gradients;
|
|
|
162 |
} stream_compr_chooser_state;
|
|
|
163 |
|
|
|
164 |
#define private_st_compr_chooser_state() /* in gdevpsds.c */\
|
|
|
165 |
gs_private_st_ptrs1(st_compr_chooser_state, stream_compr_chooser_state, \
|
|
|
166 |
"stream_compr_chooser_state",\
|
|
|
167 |
compr_chooser_enum_ptrs, compr_chooser_reloc_ptrs, sample)
|
|
|
168 |
|
|
|
169 |
extern const stream_template s_compr_chooser_template;
|
|
|
170 |
|
|
|
171 |
/* Set image dimensions. */
|
|
|
172 |
int
|
|
|
173 |
s_compr_chooser_set_dimensions(stream_compr_chooser_state * st, int width,
|
|
|
174 |
int height, int depth, int bits_per_sample);
|
|
|
175 |
|
|
|
176 |
/* Get choice */
|
|
|
177 |
uint s_compr_chooser__get_choice(stream_compr_chooser_state *st, bool force);
|
|
|
178 |
|
|
|
179 |
/* ---------------- Am image color conversion filter ---------------- */
|
|
|
180 |
|
|
|
181 |
#ifndef gx_device_DEFINED
|
|
|
182 |
# define gx_device_DEFINED
|
|
|
183 |
typedef struct gx_device_s gx_device;
|
|
|
184 |
#endif
|
|
|
185 |
|
|
|
186 |
typedef struct stream_image_colors_state_s stream_image_colors_state;
|
|
|
187 |
|
|
|
188 |
struct stream_image_colors_state_s {
|
|
|
189 |
stream_state_common;
|
|
|
190 |
uint width, height, depth, bits_per_sample;
|
|
|
191 |
byte output_bits_buffer;
|
|
|
192 |
uint output_bits_buffered;
|
|
|
193 |
uint output_component_bits_written;
|
|
|
194 |
uint output_component_index;
|
|
|
195 |
uint output_depth, output_bits_per_sample;
|
|
|
196 |
uint raster;
|
|
|
197 |
uint row_bits;
|
|
|
198 |
uint row_bits_passed;
|
|
|
199 |
uint row_alignment_bytes;
|
|
|
200 |
uint row_alignment_bytes_left;
|
|
|
201 |
uint input_component_index;
|
|
|
202 |
uint input_bits_buffer;
|
|
|
203 |
uint input_bits_buffered;
|
|
|
204 |
uint input_color[GS_IMAGE_MAX_COLOR_COMPONENTS];
|
|
|
205 |
uint output_color[GS_IMAGE_MAX_COLOR_COMPONENTS];
|
|
|
206 |
uint MaskColor[GS_IMAGE_MAX_COLOR_COMPONENTS * 2];
|
|
|
207 |
float Decode[GS_IMAGE_MAX_COLOR_COMPONENTS * 2];
|
|
|
208 |
const gs_color_space *pcs;
|
|
|
209 |
gx_device *pdev;
|
|
|
210 |
const gs_imager_state *pis;
|
|
|
211 |
int (*convert_color)(stream_image_colors_state *);
|
|
|
212 |
};
|
|
|
213 |
|
|
|
214 |
#define private_st_image_colors_state() /* in gdevpsds.c */\
|
|
|
215 |
gs_private_st_ptrs3(st_stream_image_colors_state, stream_image_colors_state,\
|
|
|
216 |
"stream_image_colors_state", stream_image_colors_enum_ptrs,\
|
|
|
217 |
stream_image_colors_reloc_ptrs, pcs, pdev, pis)
|
|
|
218 |
|
|
|
219 |
extern const stream_template s_image_colors_template;
|
|
|
220 |
|
|
|
221 |
void s_image_colors_set_dimensions(stream_image_colors_state * st,
|
|
|
222 |
int width, int height, int depth, int bits_per_sample);
|
|
|
223 |
|
|
|
224 |
void s_image_colors_set_mask_colors(stream_image_colors_state * ss, uint *MaskColor);
|
|
|
225 |
|
|
|
226 |
void s_image_colors_set_color_space(stream_image_colors_state * ss, gx_device *pdev,
|
|
|
227 |
const gs_color_space *pcs, const gs_imager_state *pis,
|
|
|
228 |
float *Decode);
|
|
|
229 |
|
|
|
230 |
extern const stream_template s__image_colors_template;
|
|
|
231 |
|
|
|
232 |
#endif /* gdevpsds_INCLUDED */
|