blob: 604e29161c49da1802c33d2dde20c895b7d1fd3c [file] [log] [blame]
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +00001/*
2 * jdmaster.c
3 *
DRCa73e8702012-12-31 02:52:30 +00004 * This file was part of the Independent JPEG Group's software:
Thomas G. Lane5ead57a1998-03-27 00:00:00 +00005 * Copyright (C) 1991-1997, Thomas G. Lane.
DRC27fb3fc2012-01-28 01:48:07 +00006 * Modified 2002-2009 by Guido Vollbeding.
DRCa6ef2822013-09-28 03:23:49 +00007 * libjpeg-turbo Modifications:
DRC67ce3b22011-12-19 02:21:03 +00008 * Copyright (C) 2009-2011, D. R. Commander.
DRC78df2e62014-05-12 09:23:57 +00009 * Copyright (C) 2013, Linaro Limited.
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000010 * For conditions of distribution and use, see the accompanying README file.
11 *
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000012 * This file contains master control logic for the JPEG decompressor.
13 * These routines are concerned with selecting the modules to be executed
14 * and with determining the number of passes and the work to be done in each
15 * pass.
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000016 */
17
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000018#define JPEG_INTERNALS
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000019#include "jinclude.h"
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000020#include "jpeglib.h"
DRC36a6eec2010-10-08 08:05:44 +000021#include "jpegcomp.h"
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000022
23
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000024/* Private state */
25
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000026typedef struct {
27 struct jpeg_decomp_master pub; /* public fields */
28
DRCe5eaf372014-05-09 18:00:32 +000029 int pass_number; /* # of passes completed */
Thomas G. Lanebc79e061995-08-02 00:00:00 +000030
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000031 boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
32
Thomas G. Lanebc79e061995-08-02 00:00:00 +000033 /* Saved references to initialized quantizer modules,
34 * in case we need to switch modes.
35 */
36 struct jpeg_color_quantizer * quantizer_1pass;
37 struct jpeg_color_quantizer * quantizer_2pass;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000038} my_decomp_master;
39
40typedef my_decomp_master * my_master_ptr;
41
42
43/*
44 * Determine whether merged upsample/color conversion should be used.
45 * CRUCIAL: this must match the actual capabilities of jdmerge.c!
46 */
47
Thomas G. Lane489583f1996-02-07 00:00:00 +000048LOCAL(boolean)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000049use_merged_upsample (j_decompress_ptr cinfo)
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000050{
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000051#ifdef UPSAMPLE_MERGING_SUPPORTED
52 /* Merging is the equivalent of plain box-filter upsampling */
53 if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
54 return FALSE;
DRC78df2e62014-05-12 09:23:57 +000055 /* jdmerge.c only supports YCC=>RGB and YCC=>RGB565 color conversion */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000056 if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
DRC720e1612009-04-05 21:51:25 +000057 (cinfo->out_color_space != JCS_RGB &&
DRC78df2e62014-05-12 09:23:57 +000058 cinfo->out_color_space != JCS_RGB565 &&
DRC720e1612009-04-05 21:51:25 +000059 cinfo->out_color_space != JCS_EXT_RGB &&
60 cinfo->out_color_space != JCS_EXT_RGBX &&
61 cinfo->out_color_space != JCS_EXT_BGR &&
62 cinfo->out_color_space != JCS_EXT_BGRX &&
63 cinfo->out_color_space != JCS_EXT_XBGR &&
DRC67ce3b22011-12-19 02:21:03 +000064 cinfo->out_color_space != JCS_EXT_XRGB &&
65 cinfo->out_color_space != JCS_EXT_RGBA &&
66 cinfo->out_color_space != JCS_EXT_BGRA &&
67 cinfo->out_color_space != JCS_EXT_ABGR &&
DRC78df2e62014-05-12 09:23:57 +000068 cinfo->out_color_space != JCS_EXT_ARGB))
69 return FALSE;
70 if ((cinfo->out_color_space == JCS_RGB565 &&
71 cinfo->out_color_components != 3) ||
72 (cinfo->out_color_space != JCS_RGB565 &&
73 cinfo->out_color_components != rgb_pixelsize[cinfo->out_color_space]))
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000074 return FALSE;
75 /* and it only handles 2h1v or 2h2v sampling ratios */
76 if (cinfo->comp_info[0].h_samp_factor != 2 ||
77 cinfo->comp_info[1].h_samp_factor != 1 ||
78 cinfo->comp_info[2].h_samp_factor != 1 ||
79 cinfo->comp_info[0].v_samp_factor > 2 ||
80 cinfo->comp_info[1].v_samp_factor != 1 ||
81 cinfo->comp_info[2].v_samp_factor != 1)
82 return FALSE;
83 /* furthermore, it doesn't work if we've scaled the IDCTs differently */
DRC49967cd2010-10-09 19:57:51 +000084 if (cinfo->comp_info[0]._DCT_scaled_size != cinfo->_min_DCT_scaled_size ||
85 cinfo->comp_info[1]._DCT_scaled_size != cinfo->_min_DCT_scaled_size ||
86 cinfo->comp_info[2]._DCT_scaled_size != cinfo->_min_DCT_scaled_size)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000087 return FALSE;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000088 /* ??? also need to test for upsample-time rescaling, when & if supported */
DRCe5eaf372014-05-09 18:00:32 +000089 return TRUE; /* by golly, it'll work... */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000090#else
91 return FALSE;
92#endif
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000093}
94
95
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000096/*
Thomas G. Lanebc79e061995-08-02 00:00:00 +000097 * Compute output image dimensions and related values.
98 * NOTE: this is exported for possible use by application.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000099 * Hence it mustn't do anything that can't be done twice.
DRC27fb3fc2012-01-28 01:48:07 +0000100 */
101
102#if JPEG_LIB_VERSION >= 80
103GLOBAL(void)
104#else
105LOCAL(void)
106#endif
107jpeg_core_output_dimensions (j_decompress_ptr cinfo)
108/* Do computations that are needed before master selection phase.
109 * This function is used for transcoding and full decompression.
110 */
111{
112#ifdef IDCT_SCALING_SUPPORTED
113 int ci;
114 jpeg_component_info *compptr;
115
116 /* Compute actual output image dimensions and DCT scaling choices. */
117 if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom) {
118 /* Provide 1/block_size scaling */
119 cinfo->output_width = (JDIMENSION)
120 jdiv_round_up((long) cinfo->image_width, (long) DCTSIZE);
121 cinfo->output_height = (JDIMENSION)
122 jdiv_round_up((long) cinfo->image_height, (long) DCTSIZE);
123 cinfo->_min_DCT_h_scaled_size = 1;
124 cinfo->_min_DCT_v_scaled_size = 1;
125 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 2) {
126 /* Provide 2/block_size scaling */
127 cinfo->output_width = (JDIMENSION)
128 jdiv_round_up((long) cinfo->image_width * 2L, (long) DCTSIZE);
129 cinfo->output_height = (JDIMENSION)
130 jdiv_round_up((long) cinfo->image_height * 2L, (long) DCTSIZE);
131 cinfo->_min_DCT_h_scaled_size = 2;
132 cinfo->_min_DCT_v_scaled_size = 2;
133 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 3) {
134 /* Provide 3/block_size scaling */
135 cinfo->output_width = (JDIMENSION)
136 jdiv_round_up((long) cinfo->image_width * 3L, (long) DCTSIZE);
137 cinfo->output_height = (JDIMENSION)
138 jdiv_round_up((long) cinfo->image_height * 3L, (long) DCTSIZE);
139 cinfo->_min_DCT_h_scaled_size = 3;
140 cinfo->_min_DCT_v_scaled_size = 3;
141 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 4) {
142 /* Provide 4/block_size scaling */
143 cinfo->output_width = (JDIMENSION)
144 jdiv_round_up((long) cinfo->image_width * 4L, (long) DCTSIZE);
145 cinfo->output_height = (JDIMENSION)
146 jdiv_round_up((long) cinfo->image_height * 4L, (long) DCTSIZE);
147 cinfo->_min_DCT_h_scaled_size = 4;
148 cinfo->_min_DCT_v_scaled_size = 4;
149 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 5) {
150 /* Provide 5/block_size scaling */
151 cinfo->output_width = (JDIMENSION)
152 jdiv_round_up((long) cinfo->image_width * 5L, (long) DCTSIZE);
153 cinfo->output_height = (JDIMENSION)
154 jdiv_round_up((long) cinfo->image_height * 5L, (long) DCTSIZE);
155 cinfo->_min_DCT_h_scaled_size = 5;
156 cinfo->_min_DCT_v_scaled_size = 5;
157 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 6) {
158 /* Provide 6/block_size scaling */
159 cinfo->output_width = (JDIMENSION)
160 jdiv_round_up((long) cinfo->image_width * 6L, (long) DCTSIZE);
161 cinfo->output_height = (JDIMENSION)
162 jdiv_round_up((long) cinfo->image_height * 6L, (long) DCTSIZE);
163 cinfo->_min_DCT_h_scaled_size = 6;
164 cinfo->_min_DCT_v_scaled_size = 6;
165 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 7) {
166 /* Provide 7/block_size scaling */
167 cinfo->output_width = (JDIMENSION)
168 jdiv_round_up((long) cinfo->image_width * 7L, (long) DCTSIZE);
169 cinfo->output_height = (JDIMENSION)
170 jdiv_round_up((long) cinfo->image_height * 7L, (long) DCTSIZE);
171 cinfo->_min_DCT_h_scaled_size = 7;
172 cinfo->_min_DCT_v_scaled_size = 7;
173 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 8) {
174 /* Provide 8/block_size scaling */
175 cinfo->output_width = (JDIMENSION)
176 jdiv_round_up((long) cinfo->image_width * 8L, (long) DCTSIZE);
177 cinfo->output_height = (JDIMENSION)
178 jdiv_round_up((long) cinfo->image_height * 8L, (long) DCTSIZE);
179 cinfo->_min_DCT_h_scaled_size = 8;
180 cinfo->_min_DCT_v_scaled_size = 8;
181 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 9) {
182 /* Provide 9/block_size scaling */
183 cinfo->output_width = (JDIMENSION)
184 jdiv_round_up((long) cinfo->image_width * 9L, (long) DCTSIZE);
185 cinfo->output_height = (JDIMENSION)
186 jdiv_round_up((long) cinfo->image_height * 9L, (long) DCTSIZE);
187 cinfo->_min_DCT_h_scaled_size = 9;
188 cinfo->_min_DCT_v_scaled_size = 9;
189 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 10) {
190 /* Provide 10/block_size scaling */
191 cinfo->output_width = (JDIMENSION)
192 jdiv_round_up((long) cinfo->image_width * 10L, (long) DCTSIZE);
193 cinfo->output_height = (JDIMENSION)
194 jdiv_round_up((long) cinfo->image_height * 10L, (long) DCTSIZE);
195 cinfo->_min_DCT_h_scaled_size = 10;
196 cinfo->_min_DCT_v_scaled_size = 10;
197 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 11) {
198 /* Provide 11/block_size scaling */
199 cinfo->output_width = (JDIMENSION)
200 jdiv_round_up((long) cinfo->image_width * 11L, (long) DCTSIZE);
201 cinfo->output_height = (JDIMENSION)
202 jdiv_round_up((long) cinfo->image_height * 11L, (long) DCTSIZE);
203 cinfo->_min_DCT_h_scaled_size = 11;
204 cinfo->_min_DCT_v_scaled_size = 11;
205 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 12) {
206 /* Provide 12/block_size scaling */
207 cinfo->output_width = (JDIMENSION)
208 jdiv_round_up((long) cinfo->image_width * 12L, (long) DCTSIZE);
209 cinfo->output_height = (JDIMENSION)
210 jdiv_round_up((long) cinfo->image_height * 12L, (long) DCTSIZE);
211 cinfo->_min_DCT_h_scaled_size = 12;
212 cinfo->_min_DCT_v_scaled_size = 12;
213 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 13) {
214 /* Provide 13/block_size scaling */
215 cinfo->output_width = (JDIMENSION)
216 jdiv_round_up((long) cinfo->image_width * 13L, (long) DCTSIZE);
217 cinfo->output_height = (JDIMENSION)
218 jdiv_round_up((long) cinfo->image_height * 13L, (long) DCTSIZE);
219 cinfo->_min_DCT_h_scaled_size = 13;
220 cinfo->_min_DCT_v_scaled_size = 13;
221 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 14) {
222 /* Provide 14/block_size scaling */
223 cinfo->output_width = (JDIMENSION)
224 jdiv_round_up((long) cinfo->image_width * 14L, (long) DCTSIZE);
225 cinfo->output_height = (JDIMENSION)
226 jdiv_round_up((long) cinfo->image_height * 14L, (long) DCTSIZE);
227 cinfo->_min_DCT_h_scaled_size = 14;
228 cinfo->_min_DCT_v_scaled_size = 14;
229 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 15) {
230 /* Provide 15/block_size scaling */
231 cinfo->output_width = (JDIMENSION)
232 jdiv_round_up((long) cinfo->image_width * 15L, (long) DCTSIZE);
233 cinfo->output_height = (JDIMENSION)
234 jdiv_round_up((long) cinfo->image_height * 15L, (long) DCTSIZE);
235 cinfo->_min_DCT_h_scaled_size = 15;
236 cinfo->_min_DCT_v_scaled_size = 15;
237 } else {
238 /* Provide 16/block_size scaling */
239 cinfo->output_width = (JDIMENSION)
240 jdiv_round_up((long) cinfo->image_width * 16L, (long) DCTSIZE);
241 cinfo->output_height = (JDIMENSION)
242 jdiv_round_up((long) cinfo->image_height * 16L, (long) DCTSIZE);
243 cinfo->_min_DCT_h_scaled_size = 16;
244 cinfo->_min_DCT_v_scaled_size = 16;
245 }
246
247 /* Recompute dimensions of components */
248 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
249 ci++, compptr++) {
250 compptr->_DCT_h_scaled_size = cinfo->_min_DCT_h_scaled_size;
251 compptr->_DCT_v_scaled_size = cinfo->_min_DCT_v_scaled_size;
252 }
253
254#else /* !IDCT_SCALING_SUPPORTED */
255
256 /* Hardwire it to "no scaling" */
257 cinfo->output_width = cinfo->image_width;
258 cinfo->output_height = cinfo->image_height;
259 /* jdinput.c has already initialized DCT_scaled_size,
260 * and has computed unscaled downsampled_width and downsampled_height.
261 */
262
263#endif /* IDCT_SCALING_SUPPORTED */
264}
265
266
267/*
268 * Compute output image dimensions and related values.
269 * NOTE: this is exported for possible use by application.
270 * Hence it mustn't do anything that can't be done twice.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000271 * Also note that it may be called before the master module is initialized!
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000272 */
273
Thomas G. Lane489583f1996-02-07 00:00:00 +0000274GLOBAL(void)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000275jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
276/* Do computations that are needed before master selection phase */
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +0000277{
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000278#ifdef IDCT_SCALING_SUPPORTED
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000279 int ci;
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +0000280 jpeg_component_info *compptr;
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000281#endif
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +0000282
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000283 /* Prevent application from calling me at wrong times */
284 if (cinfo->global_state != DSTATE_READY)
285 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
286
Guido Vollbeding989630f2010-01-10 00:00:00 +0000287 /* Compute core output image dimensions and DCT scaling choices. */
288 jpeg_core_output_dimensions(cinfo);
289
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000290#ifdef IDCT_SCALING_SUPPORTED
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +0000291
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000292 /* In selecting the actual DCT scaling for each component, we try to
293 * scale up the chroma components via IDCT scaling rather than upsampling.
294 * This saves time if the upsampler gets to use 1:1 scaling.
DRCc8fb7582012-02-03 06:55:26 +0000295 * Note this code adapts subsampling ratios which are powers of 2.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000296 */
297 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
298 ci++, compptr++) {
DRC49967cd2010-10-09 19:57:51 +0000299 int ssize = cinfo->_min_DCT_scaled_size;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000300 while (ssize < DCTSIZE &&
DRCe5eaf372014-05-09 18:00:32 +0000301 ((cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) %
302 (compptr->h_samp_factor * ssize * 2) == 0) &&
303 ((cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size) %
304 (compptr->v_samp_factor * ssize * 2) == 0)) {
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000305 ssize = ssize * 2;
306 }
DRC36a6eec2010-10-08 08:05:44 +0000307#if JPEG_LIB_VERSION >= 70
308 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = ssize;
309#else
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000310 compptr->DCT_scaled_size = ssize;
DRC36a6eec2010-10-08 08:05:44 +0000311#endif
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000312 }
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000313
314 /* Recompute downsampled dimensions of components;
315 * application needs to know these if using raw downsampled data.
316 */
317 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
318 ci++, compptr++) {
319 /* Size in samples, after IDCT scaling */
320 compptr->downsampled_width = (JDIMENSION)
321 jdiv_round_up((long) cinfo->image_width *
DRCe5eaf372014-05-09 18:00:32 +0000322 (long) (compptr->h_samp_factor * compptr->_DCT_scaled_size),
323 (long) (cinfo->max_h_samp_factor * DCTSIZE));
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000324 compptr->downsampled_height = (JDIMENSION)
325 jdiv_round_up((long) cinfo->image_height *
DRCe5eaf372014-05-09 18:00:32 +0000326 (long) (compptr->v_samp_factor * compptr->_DCT_scaled_size),
327 (long) (cinfo->max_v_samp_factor * DCTSIZE));
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000328 }
329
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000330#else /* !IDCT_SCALING_SUPPORTED */
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000331
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000332 /* Hardwire it to "no scaling" */
333 cinfo->output_width = cinfo->image_width;
334 cinfo->output_height = cinfo->image_height;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000335 /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
336 * and has computed unscaled downsampled_width and downsampled_height.
337 */
338
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000339#endif /* IDCT_SCALING_SUPPORTED */
340
341 /* Report number of components in selected colorspace. */
342 /* Probably this should be in the color conversion module... */
343 switch (cinfo->out_color_space) {
344 case JCS_GRAYSCALE:
345 cinfo->out_color_components = 1;
346 break;
347 case JCS_RGB:
DRC720e1612009-04-05 21:51:25 +0000348 case JCS_EXT_RGB:
349 case JCS_EXT_RGBX:
350 case JCS_EXT_BGR:
351 case JCS_EXT_BGRX:
352 case JCS_EXT_XBGR:
353 case JCS_EXT_XRGB:
DRC67ce3b22011-12-19 02:21:03 +0000354 case JCS_EXT_RGBA:
355 case JCS_EXT_BGRA:
356 case JCS_EXT_ABGR:
357 case JCS_EXT_ARGB:
DRC720e1612009-04-05 21:51:25 +0000358 cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000359 break;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000360 case JCS_YCbCr:
DRC78df2e62014-05-12 09:23:57 +0000361 case JCS_RGB565:
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000362 cinfo->out_color_components = 3;
363 break;
364 case JCS_CMYK:
365 case JCS_YCCK:
366 cinfo->out_color_components = 4;
367 break;
DRCe5eaf372014-05-09 18:00:32 +0000368 default: /* else must be same colorspace as in file */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000369 cinfo->out_color_components = cinfo->num_components;
370 break;
371 }
372 cinfo->output_components = (cinfo->quantize_colors ? 1 :
DRCe5eaf372014-05-09 18:00:32 +0000373 cinfo->out_color_components);
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000374
375 /* See if upsampler will want to emit more than one row at a time */
376 if (use_merged_upsample(cinfo))
377 cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
378 else
379 cinfo->rec_outbuf_height = 1;
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +0000380}
381
382
383/*
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000384 * Several decompression processes need to range-limit values to the range
385 * 0..MAXJSAMPLE; the input value may fall somewhat outside this range
386 * due to noise introduced by quantization, roundoff error, etc. These
387 * processes are inner loops and need to be as fast as possible. On most
388 * machines, particularly CPUs with pipelines or instruction prefetch,
389 * a (subscript-check-less) C table lookup
DRCe5eaf372014-05-09 18:00:32 +0000390 * x = sample_range_limit[x];
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000391 * is faster than explicit tests
DRCe5eaf372014-05-09 18:00:32 +0000392 * if (x < 0) x = 0;
393 * else if (x > MAXJSAMPLE) x = MAXJSAMPLE;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000394 * These processes all use a common table prepared by the routine below.
395 *
396 * For most steps we can mathematically guarantee that the initial value
397 * of x is within MAXJSAMPLE+1 of the legal range, so a table running from
398 * -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial
DRCe5eaf372014-05-09 18:00:32 +0000399 * limiting step (just after the IDCT), a wildly out-of-range value is
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000400 * possible if the input data is corrupt. To avoid any chance of indexing
401 * off the end of memory and getting a bad-pointer trap, we perform the
402 * post-IDCT limiting thus:
DRCe5eaf372014-05-09 18:00:32 +0000403 * x = range_limit[x & MASK];
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000404 * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit
405 * samples. Under normal circumstances this is more than enough range and
406 * a correct output will be generated; with bogus input data the mask will
407 * cause wraparound, and we will safely generate a bogus-but-in-range output.
408 * For the post-IDCT step, we want to convert the data from signed to unsigned
409 * representation by adding CENTERJSAMPLE at the same time that we limit it.
410 * So the post-IDCT limiting table ends up looking like this:
411 * CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE,
412 * MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
413 * 0 (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
414 * 0,1,...,CENTERJSAMPLE-1
415 * Negative inputs select values from the upper half of the table after
416 * masking.
417 *
418 * We can save some space by overlapping the start of the post-IDCT table
419 * with the simpler range limiting table. The post-IDCT table begins at
420 * sample_range_limit + CENTERJSAMPLE.
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +0000421 */
422
Thomas G. Lane489583f1996-02-07 00:00:00 +0000423LOCAL(void)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000424prepare_range_limit_table (j_decompress_ptr cinfo)
425/* Allocate and fill in the sample_range_limit table */
426{
427 JSAMPLE * table;
428 int i;
429
430 table = (JSAMPLE *)
431 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
DRC5de454b2014-05-18 19:04:03 +0000432 (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * sizeof(JSAMPLE));
DRCe5eaf372014-05-09 18:00:32 +0000433 table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000434 cinfo->sample_range_limit = table;
435 /* First segment of "simple" table: limit[x] = 0 for x < 0 */
DRC5de454b2014-05-18 19:04:03 +0000436 MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * sizeof(JSAMPLE));
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000437 /* Main part of "simple" table: limit[x] = x */
438 for (i = 0; i <= MAXJSAMPLE; i++)
439 table[i] = (JSAMPLE) i;
DRCe5eaf372014-05-09 18:00:32 +0000440 table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000441 /* End of simple table, rest of first half of post-IDCT table */
442 for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
443 table[i] = MAXJSAMPLE;
444 /* Second half of post-IDCT table */
445 MEMZERO(table + (2 * (MAXJSAMPLE+1)),
DRC5de454b2014-05-18 19:04:03 +0000446 (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * sizeof(JSAMPLE));
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000447 MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
DRC5de454b2014-05-18 19:04:03 +0000448 cinfo->sample_range_limit, CENTERJSAMPLE * sizeof(JSAMPLE));
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000449}
450
451
452/*
453 * Master selection of decompression modules.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000454 * This is done once at jpeg_start_decompress time. We determine
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000455 * which modules will be used and give them appropriate initialization calls.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000456 * We also initialize the decompressor input side to begin consuming data.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000457 *
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000458 * Since jpeg_read_header has finished, we know what is in the SOF
459 * and (first) SOS markers. We also have all the application parameter
460 * settings.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000461 */
462
Thomas G. Lane489583f1996-02-07 00:00:00 +0000463LOCAL(void)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000464master_selection (j_decompress_ptr cinfo)
465{
466 my_master_ptr master = (my_master_ptr) cinfo->master;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000467 boolean use_c_buffer;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000468 long samplesperrow;
469 JDIMENSION jd_samplesperrow;
470
471 /* Initialize dimensions and other stuff */
472 jpeg_calc_output_dimensions(cinfo);
473 prepare_range_limit_table(cinfo);
474
475 /* Width of an output scanline must be representable as JDIMENSION. */
476 samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
477 jd_samplesperrow = (JDIMENSION) samplesperrow;
478 if ((long) jd_samplesperrow != samplesperrow)
479 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
480
481 /* Initialize my private state */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000482 master->pass_number = 0;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000483 master->using_merged_upsample = use_merged_upsample(cinfo);
484
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000485 /* Color quantizer selection */
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000486 master->quantizer_1pass = NULL;
487 master->quantizer_2pass = NULL;
488 /* No mode changes if not using buffered-image mode. */
489 if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
490 cinfo->enable_1pass_quant = FALSE;
491 cinfo->enable_external_quant = FALSE;
492 cinfo->enable_2pass_quant = FALSE;
493 }
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000494 if (cinfo->quantize_colors) {
495 if (cinfo->raw_data_out)
496 ERREXIT(cinfo, JERR_NOTIMPL);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000497 /* 2-pass quantizer only works in 3-component color space. */
498 if (cinfo->out_color_components != 3) {
499 cinfo->enable_1pass_quant = TRUE;
500 cinfo->enable_external_quant = FALSE;
501 cinfo->enable_2pass_quant = FALSE;
502 cinfo->colormap = NULL;
503 } else if (cinfo->colormap != NULL) {
504 cinfo->enable_external_quant = TRUE;
505 } else if (cinfo->two_pass_quantize) {
506 cinfo->enable_2pass_quant = TRUE;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000507 } else {
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000508 cinfo->enable_1pass_quant = TRUE;
509 }
510
511 if (cinfo->enable_1pass_quant) {
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000512#ifdef QUANT_1PASS_SUPPORTED
513 jinit_1pass_quantizer(cinfo);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000514 master->quantizer_1pass = cinfo->cquantize;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000515#else
516 ERREXIT(cinfo, JERR_NOT_COMPILED);
517#endif
518 }
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000519
520 /* We use the 2-pass code to map to external colormaps. */
521 if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
522#ifdef QUANT_2PASS_SUPPORTED
523 jinit_2pass_quantizer(cinfo);
524 master->quantizer_2pass = cinfo->cquantize;
525#else
526 ERREXIT(cinfo, JERR_NOT_COMPILED);
527#endif
528 }
529 /* If both quantizers are initialized, the 2-pass one is left active;
530 * this is necessary for starting with quantization to an external map.
531 */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000532 }
533
534 /* Post-processing: in particular, color conversion first */
535 if (! cinfo->raw_data_out) {
536 if (master->using_merged_upsample) {
537#ifdef UPSAMPLE_MERGING_SUPPORTED
538 jinit_merged_upsampler(cinfo); /* does color conversion too */
539#else
540 ERREXIT(cinfo, JERR_NOT_COMPILED);
541#endif
542 } else {
543 jinit_color_deconverter(cinfo);
544 jinit_upsampler(cinfo);
545 }
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000546 jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000547 }
548 /* Inverse DCT */
549 jinit_inverse_dct(cinfo);
550 /* Entropy decoding: either Huffman or arithmetic coding. */
551 if (cinfo->arith_code) {
DRC66f97e62010-11-23 05:49:54 +0000552#ifdef D_ARITH_CODING_SUPPORTED
Guido Vollbeding1e247ac1998-03-28 00:00:00 +0000553 jinit_arith_decoder(cinfo);
DRC66f97e62010-11-23 05:49:54 +0000554#else
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000555 ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
DRC66f97e62010-11-23 05:49:54 +0000556#endif
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000557 } else {
558 if (cinfo->progressive_mode) {
559#ifdef D_PROGRESSIVE_SUPPORTED
560 jinit_phuff_decoder(cinfo);
561#else
562 ERREXIT(cinfo, JERR_NOT_COMPILED);
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000563#endif
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000564 } else
565 jinit_huff_decoder(cinfo);
566 }
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000567
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000568 /* Initialize principal buffer controllers. */
569 use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
570 jinit_d_coef_controller(cinfo, use_c_buffer);
571
572 if (! cinfo->raw_data_out)
573 jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000574
575 /* We can now tell the memory manager to allocate virtual arrays. */
576 (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000577
578 /* Initialize input side of decompressor to consume first scan. */
579 (*cinfo->inputctl->start_input_pass) (cinfo);
580
581#ifdef D_MULTISCAN_FILES_SUPPORTED
582 /* If jpeg_start_decompress will read the whole file, initialize
583 * progress monitoring appropriately. The input step is counted
584 * as one pass.
585 */
586 if (cinfo->progress != NULL && ! cinfo->buffered_image &&
587 cinfo->inputctl->has_multiple_scans) {
588 int nscans;
589 /* Estimate number of scans to set pass_limit. */
590 if (cinfo->progressive_mode) {
591 /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
592 nscans = 2 + 3 * cinfo->num_components;
593 } else {
594 /* For a nonprogressive multiscan file, estimate 1 scan per component. */
595 nscans = cinfo->num_components;
596 }
597 cinfo->progress->pass_counter = 0L;
598 cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
599 cinfo->progress->completed_passes = 0;
600 cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
601 /* Count the input pass as done */
602 master->pass_number++;
603 }
604#endif /* D_MULTISCAN_FILES_SUPPORTED */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000605}
606
607
608/*
609 * Per-pass setup.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000610 * This is called at the beginning of each output pass. We determine which
611 * modules will be active during this pass and give them appropriate
612 * start_pass calls. We also set is_dummy_pass to indicate whether this
613 * is a "real" output pass or a dummy pass for color quantization.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000614 * (In the latter case, jdapistd.c will crank the pass to completion.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000615 */
616
Thomas G. Lane489583f1996-02-07 00:00:00 +0000617METHODDEF(void)
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000618prepare_for_output_pass (j_decompress_ptr cinfo)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000619{
620 my_master_ptr master = (my_master_ptr) cinfo->master;
621
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000622 if (master->pub.is_dummy_pass) {
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000623#ifdef QUANT_2PASS_SUPPORTED
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000624 /* Final pass of 2-pass quantization */
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000625 master->pub.is_dummy_pass = FALSE;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000626 (*cinfo->cquantize->start_pass) (cinfo, FALSE);
627 (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
628 (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000629#else
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000630 ERREXIT(cinfo, JERR_NOT_COMPILED);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000631#endif /* QUANT_2PASS_SUPPORTED */
632 } else {
633 if (cinfo->quantize_colors && cinfo->colormap == NULL) {
634 /* Select new quantization method */
635 if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
DRCe5eaf372014-05-09 18:00:32 +0000636 cinfo->cquantize = master->quantizer_2pass;
637 master->pub.is_dummy_pass = TRUE;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000638 } else if (cinfo->enable_1pass_quant) {
DRCe5eaf372014-05-09 18:00:32 +0000639 cinfo->cquantize = master->quantizer_1pass;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000640 } else {
DRCe5eaf372014-05-09 18:00:32 +0000641 ERREXIT(cinfo, JERR_MODE_CHANGE);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000642 }
643 }
644 (*cinfo->idct->start_pass) (cinfo);
645 (*cinfo->coef->start_output_pass) (cinfo);
646 if (! cinfo->raw_data_out) {
647 if (! master->using_merged_upsample)
DRCe5eaf372014-05-09 18:00:32 +0000648 (*cinfo->cconvert->start_pass) (cinfo);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000649 (*cinfo->upsample->start_pass) (cinfo);
650 if (cinfo->quantize_colors)
DRCe5eaf372014-05-09 18:00:32 +0000651 (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000652 (*cinfo->post->start_pass) (cinfo,
DRCe5eaf372014-05-09 18:00:32 +0000653 (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000654 (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
655 }
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000656 }
657
658 /* Set up progress monitor's pass info if present */
659 if (cinfo->progress != NULL) {
660 cinfo->progress->completed_passes = master->pass_number;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000661 cinfo->progress->total_passes = master->pass_number +
DRCe5eaf372014-05-09 18:00:32 +0000662 (master->pub.is_dummy_pass ? 2 : 1);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000663 /* In buffered-image mode, we assume one more output pass if EOI not
664 * yet reached, but no more passes if EOI has been reached.
665 */
666 if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
667 cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
668 }
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000669 }
670}
671
672
673/*
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000674 * Finish up at end of an output pass.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000675 */
676
Thomas G. Lane489583f1996-02-07 00:00:00 +0000677METHODDEF(void)
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000678finish_output_pass (j_decompress_ptr cinfo)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000679{
680 my_master_ptr master = (my_master_ptr) cinfo->master;
681
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000682 if (cinfo->quantize_colors)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000683 (*cinfo->cquantize->finish_pass) (cinfo);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000684 master->pass_number++;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000685}
686
687
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000688#ifdef D_MULTISCAN_FILES_SUPPORTED
689
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000690/*
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000691 * Switch to a new external colormap between output passes.
692 */
693
Thomas G. Lane489583f1996-02-07 00:00:00 +0000694GLOBAL(void)
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000695jpeg_new_colormap (j_decompress_ptr cinfo)
696{
697 my_master_ptr master = (my_master_ptr) cinfo->master;
698
699 /* Prevent application from calling me at wrong times */
700 if (cinfo->global_state != DSTATE_BUFIMAGE)
701 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
702
703 if (cinfo->quantize_colors && cinfo->enable_external_quant &&
704 cinfo->colormap != NULL) {
705 /* Select 2-pass quantizer for external colormap use */
706 cinfo->cquantize = master->quantizer_2pass;
707 /* Notify quantizer of colormap change */
708 (*cinfo->cquantize->new_color_map) (cinfo);
709 master->pub.is_dummy_pass = FALSE; /* just in case */
710 } else
711 ERREXIT(cinfo, JERR_MODE_CHANGE);
712}
713
714#endif /* D_MULTISCAN_FILES_SUPPORTED */
715
716
717/*
718 * Initialize master decompression control and select active modules.
719 * This is performed at the start of jpeg_start_decompress.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000720 */
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +0000721
Thomas G. Lane489583f1996-02-07 00:00:00 +0000722GLOBAL(void)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000723jinit_master_decompress (j_decompress_ptr cinfo)
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +0000724{
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000725 my_master_ptr master;
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +0000726
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000727 master = (my_master_ptr)
728 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
DRC5de454b2014-05-18 19:04:03 +0000729 sizeof(my_decomp_master));
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000730 cinfo->master = (struct jpeg_decomp_master *) master;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000731 master->pub.prepare_for_output_pass = prepare_for_output_pass;
732 master->pub.finish_output_pass = finish_output_pass;
733
734 master->pub.is_dummy_pass = FALSE;
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +0000735
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000736 master_selection(cinfo);
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +0000737}