]>
git.ipfire.org Git - thirdparty/cups.git/blob - pstoraster/zfdecode.c
1 /* Copyright (C) 1994, 1996, 1998 Aladdin Enterprises. All rights reserved.
3 This file is part of GNU Ghostscript.
5 GNU Ghostscript is distributed in the hope that it will be useful, but
6 WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
7 to anyone for the consequences of using it or for whether it serves any
8 particular purpose or works at all, unless he says so in writing. Refer
9 to the GNU General Public License for full details.
11 Everyone is granted permission to copy, modify and redistribute GNU
12 Ghostscript, but only under the conditions described in the GNU General
13 Public License. A copy of this license is supposed to have been given
14 to you along with GNU Ghostscript so you can know your rights and
15 responsibilities. It should be in a file named COPYING. Among other
16 things, the copyright notice and this notice must be preserved on all
19 Aladdin Enterprises supports the work of the GNU Project, but is not
20 affiliated with the Free Software Foundation or the GNU Project. GNU
21 Ghostscript, as distributed by Aladdin Enterprises, does not require any
22 GNU software to build or run it.
26 /* Additional decoding filter creation */
35 #include "ilevel.h" /* for LL3 test */
38 #include "stream.h" /* for setting is_temp */
49 /* Import the Level 2 scanner extensions. */
50 extern const stream_template
*scan_ascii85_template
;
52 /* Initialize the Level 2 scanner for ASCII85 strings. */
56 scan_ascii85_template
= &s_A85D_template
;
59 /* ------ ASCII85 filters ------ */
61 /* We include both encoding and decoding filters here, */
62 /* because it would be a nuisance to separate them. */
64 /* <target> ASCII85Encode/filter <file> */
65 /* <target> <dict> ASCII85Encode/filter <file> */
69 return filter_write_simple(op
, &s_A85E_template
);
72 /* <source> ASCII85Decode/filter <file> */
73 /* <source> <dict> ASCII85Decode/filter <file> */
77 return filter_read_simple(op
, &s_A85D_template
);
80 /* ------ CCITTFaxDecode filter ------ */
82 /* Common setup for encoding and decoding filters. */
83 extern stream_state_proc_put_params(s_CF_put_params
, stream_CF_state
);
85 zcf_setup(os_ptr op
, stream_CF_state
* pcfs
)
88 int code
= dict_param_list_read(&list
, op
, NULL
, false);
92 s_CF_set_defaults_inline(pcfs
);
93 code
= s_CF_put_params((gs_param_list
*) & list
, pcfs
);
94 iparam_list_release(&list
);
98 /* <source> <dict> CCITTFaxDecode/filter <file> */
99 /* <source> CCITTFaxDecode/filter <file> */
104 stream_CFD_state cfs
;
107 if (r_has_type(op
, t_dictionary
)) {
108 check_dict_read(*op
);
112 code
= zcf_setup(dop
, (stream_CF_state
*) & cfs
);
115 return filter_read(op
, 0, &s_CFD_template
, (stream_state
*) & cfs
, 0);
118 /* ------ Common setup for possibly pixel-oriented decoding filters ------ */
120 /* Forward declarations */
121 int zpd_setup(P2(os_ptr op
, stream_PDiff_state
* ppds
));
122 int zpp_setup(P2(os_ptr op
, stream_PNGP_state
* ppps
));
125 filter_read_predictor(os_ptr op
, int npop
, const stream_template
* template,
129 stream_PDiff_state pds
;
130 stream_PNGP_state pps
;
132 if (r_has_type(op
, t_dictionary
)) {
133 if ((code
= dict_int_param(op
, "Predictor", 0, 15, 1, &predictor
)) < 0)
136 case 0: /* identity */
138 case 1: /* identity */
140 case 2: /* componentwise horizontal differencing */
141 code
= zpd_setup(op
, &pds
);
150 code
= zpp_setup(op
, &pps
);
153 return_error(e_rangecheck
);
160 return filter_read(op
, npop
, template, st
, 0);
162 /* We need to cascade filters. */
163 ref rsource
, rdict
, rfd
;
166 /* Save the operands, just in case. */
167 ref_assign(&rsource
, op
- 1);
168 ref_assign(&rdict
, op
);
169 code
= filter_read(op
, 1, template, st
, 0);
172 /* filter_read changed osp.... */
174 ref_assign(&rfd
, op
);
177 filter_read(op
, 0, &s_PDiffD_template
, (stream_state
*) & pds
, 0) :
178 filter_read(op
, 0, &s_PNGPD_template
, (stream_state
*) & pps
, 0));
180 /* Restore the operands. Don't bother trying to clean up */
181 /* the first stream. */
183 ref_assign(op
- 1, &rsource
);
184 ref_assign(op
, &rdict
);
187 filter_mark_temp(&rfd
, 2); /* Mark the decompression stream as temporary. */
192 /* ------ Generalized LZW/GIF decoding filter ------ */
194 /* Common setup for encoding and decoding filters. */
196 zlz_setup(os_ptr op
, stream_LZW_state
* plzs
)
201 if (r_has_type(op
, t_dictionary
)) {
202 check_dict_read(*op
);
206 if ( (code
= dict_int_param(dop
, "EarlyChange", 0, 1, 1,
207 &plzs
->EarlyChange
)) < 0 ||
209 * The following are not PostScript standard, although
210 * LanguageLevel 3 provides the first two under different
213 (code
= dict_int_param(dop
, "InitialCodeLength", 2, 11, 8,
214 &plzs
->InitialCodeLength
)) < 0 ||
215 (code
= dict_bool_param(dop
, "FirstBitLowOrder", false,
216 &plzs
->FirstBitLowOrder
)) < 0 ||
217 (code
= dict_bool_param(dop
, "BlockData", false,
218 &plzs
->BlockData
)) < 0
224 /* <source> LZWDecode/filter <file> */
225 /* <source> <dict> LZWDecode/filter <file> */
229 stream_LZW_state lzs
;
230 int code
= zlz_setup(op
, &lzs
);
234 if (LL3_ENABLED
&& r_has_type(op
, t_dictionary
)) {
237 if ((code
= dict_bool_param(op
, "LowBitFirst", lzs
.FirstBitLowOrder
,
238 &lzs
.FirstBitLowOrder
)) < 0 ||
239 (code
= dict_int_param(op
, "UnitSize", 3, 8, 8,
243 if (code
== 0 /* UnitSize specified */ )
244 lzs
.InitialCodeLength
= unit_size
+ 1;
246 return filter_read_predictor(op
, 0, &s_LZWD_template
,
247 (stream_state
*) & lzs
);
250 /* ------ Color differencing filters ------ */
252 /* We include both encoding and decoding filters here, */
253 /* because it would be a nuisance to separate them. */
255 /* Common setup for encoding and decoding filters. */
257 zpd_setup(os_ptr op
, stream_PDiff_state
* ppds
)
261 check_type(*op
, t_dictionary
);
262 check_dict_read(*op
);
263 if ((code
= dict_int_param(op
, "Colors", 1, 4, 1,
264 &ppds
->Colors
)) < 0 ||
265 (code
= dict_int_param(op
, "BitsPerComponent", 1, 8, 8,
267 (bpc
& (bpc
- 1)) != 0 ||
268 (code
= dict_int_param(op
, "Columns", 1, max_int
, 1,
271 return (code
< 0 ? code
: gs_note_error(e_rangecheck
));
272 ppds
->BitsPerComponent
= bpc
;
276 /* <target> <dict> PixelDifferenceEncode/filter <file> */
280 stream_PDiff_state pds
;
281 int code
= zpd_setup(op
, &pds
);
285 return filter_write(op
, 0, &s_PDiffE_template
, (stream_state
*) & pds
, 0);
288 /* <source> <dict> PixelDifferenceDecode/filter <file> */
292 stream_PDiff_state pds
;
293 int code
= zpd_setup(op
, &pds
);
297 return filter_read(op
, 0, &s_PDiffD_template
, (stream_state
*) & pds
, 0);
300 /* ------ PNG pixel predictor filters ------ */
302 /* Common setup for encoding and decoding filters. */
304 zpp_setup(os_ptr op
, stream_PNGP_state
* ppps
)
308 check_type(*op
, t_dictionary
);
309 check_dict_read(*op
);
310 if ((code
= dict_int_param(op
, "Colors", 1, 16, 1,
311 &ppps
->Colors
)) < 0 ||
312 (code
= dict_int_param(op
, "BitsPerComponent", 1, 16, 8,
314 (bpc
& (bpc
- 1)) != 0 ||
315 (code
= dict_uint_param(op
, "Columns", 1, max_uint
, 1,
316 &ppps
->Columns
)) < 0 ||
317 (code
= dict_int_param(op
, "Predictor", 10, 15, 15,
318 &ppps
->Predictor
)) < 0
320 return (code
< 0 ? code
: gs_note_error(e_rangecheck
));
321 ppps
->BitsPerComponent
= bpc
;
325 /* <target> <dict> PNGPredictorEncode/filter <file> */
329 stream_PNGP_state pps
;
330 int code
= zpp_setup(op
, &pps
);
334 return filter_write(op
, 0, &s_PNGPE_template
, (stream_state
*) & pps
, 0);
337 /* <source> <dict> PNGPredictorDecode/filter <file> */
341 stream_PNGP_state pps
;
342 int code
= zpp_setup(op
, &pps
);
346 return filter_read(op
, 0, &s_PNGPD_template
, (stream_state
*) & pps
, 0);
349 /* ---------------- Initialization procedure ---------------- */
351 const op_def zfdecode_op_defs
[] =
353 op_def_begin_filter(),
354 {"1ASCII85Encode", zA85E
},
355 {"1ASCII85Decode", zA85D
},
356 {"2CCITTFaxDecode", zCFD
},
357 {"1LZWDecode", zLZWD
},
358 {"2PixelDifferenceDecode", zPDiffD
},
359 {"2PixelDifferenceEncode", zPDiffE
},
360 {"2PNGPredictorDecode", zPNGPD
},
361 {"2PNGPredictorEncode", zPNGPE
},
362 op_def_end(zfdecode_init
)