~ubuntu-branches/ubuntu/maverick/freeimage/maverick-201010060008

« back to all changes in this revision

Viewing changes to Source/LibJPEG/jdmaster.c

  • Committer: Stefano Rivera
  • Date: 2010-07-24 15:39:47 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: stefanor@ubuntu.com-20100724153947-bcu8otnpzm8wbzzg
Tags: 3.13.1-0ubuntu1
* New upstream release. Closes: (LP: #607800)
 - Updated debian/freeimage-get-orig-source script.
 - Removing no longer necessary debian/patches/* and
   the patch system in debian/rules.
 - Updated debian/rules to work with the new Makefiles.
 - Drop from -O3 to -O2 and use lzma compression saves
   ~10 MB of free space. 
* lintian stuff
 - fixed debhelper-but-no-misc-depends
 - fixed ldconfig-symlink-missing-for-shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * jdmaster.c
3
3
 *
4
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
 
5
 * Modified 2002-2008 by Guido Vollbeding.
5
6
 * This file is part of the Independent JPEG Group's software.
6
7
 * For conditions of distribution and use, see the accompanying README file.
7
8
 *
61
62
      cinfo->comp_info[2].v_samp_factor != 1)
62
63
    return FALSE;
63
64
  /* furthermore, it doesn't work if we've scaled the IDCTs differently */
64
 
  if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
65
 
      cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
66
 
      cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
 
65
  if (cinfo->comp_info[0].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||
 
66
      cinfo->comp_info[1].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||
 
67
      cinfo->comp_info[2].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||
 
68
      cinfo->comp_info[0].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size ||
 
69
      cinfo->comp_info[1].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size ||
 
70
      cinfo->comp_info[2].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size)
67
71
    return FALSE;
68
72
  /* ??? also need to test for upsample-time rescaling, when & if supported */
69
73
  return TRUE;                  /* by golly, it'll work... */
102
106
      jdiv_round_up((long) cinfo->image_width, 8L);
103
107
    cinfo->output_height = (JDIMENSION)
104
108
      jdiv_round_up((long) cinfo->image_height, 8L);
105
 
    cinfo->min_DCT_scaled_size = 1;
 
109
    cinfo->min_DCT_h_scaled_size = 1;
 
110
    cinfo->min_DCT_v_scaled_size = 1;
106
111
  } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
107
112
    /* Provide 1/4 scaling */
108
113
    cinfo->output_width = (JDIMENSION)
109
114
      jdiv_round_up((long) cinfo->image_width, 4L);
110
115
    cinfo->output_height = (JDIMENSION)
111
116
      jdiv_round_up((long) cinfo->image_height, 4L);
112
 
    cinfo->min_DCT_scaled_size = 2;
 
117
    cinfo->min_DCT_h_scaled_size = 2;
 
118
    cinfo->min_DCT_v_scaled_size = 2;
 
119
  } else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 3) {
 
120
    /* Provide 3/8 scaling */
 
121
    cinfo->output_width = (JDIMENSION)
 
122
      jdiv_round_up((long) cinfo->image_width * 3L, 8L);
 
123
    cinfo->output_height = (JDIMENSION)
 
124
      jdiv_round_up((long) cinfo->image_height * 3L, 8L);
 
125
    cinfo->min_DCT_h_scaled_size = 3;
 
126
    cinfo->min_DCT_v_scaled_size = 3;
113
127
  } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
114
128
    /* Provide 1/2 scaling */
115
129
    cinfo->output_width = (JDIMENSION)
116
130
      jdiv_round_up((long) cinfo->image_width, 2L);
117
131
    cinfo->output_height = (JDIMENSION)
118
132
      jdiv_round_up((long) cinfo->image_height, 2L);
119
 
    cinfo->min_DCT_scaled_size = 4;
120
 
  } else {
 
133
    cinfo->min_DCT_h_scaled_size = 4;
 
134
    cinfo->min_DCT_v_scaled_size = 4;
 
135
  } else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 5) {
 
136
    /* Provide 5/8 scaling */
 
137
    cinfo->output_width = (JDIMENSION)
 
138
      jdiv_round_up((long) cinfo->image_width * 5L, 8L);
 
139
    cinfo->output_height = (JDIMENSION)
 
140
      jdiv_round_up((long) cinfo->image_height * 5L, 8L);
 
141
    cinfo->min_DCT_h_scaled_size = 5;
 
142
    cinfo->min_DCT_v_scaled_size = 5;
 
143
  } else if (cinfo->scale_num * 4 <= cinfo->scale_denom * 3) {
 
144
    /* Provide 3/4 scaling */
 
145
    cinfo->output_width = (JDIMENSION)
 
146
      jdiv_round_up((long) cinfo->image_width * 3L, 4L);
 
147
    cinfo->output_height = (JDIMENSION)
 
148
      jdiv_round_up((long) cinfo->image_height * 3L, 4L);
 
149
    cinfo->min_DCT_h_scaled_size = 6;
 
150
    cinfo->min_DCT_v_scaled_size = 6;
 
151
  } else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 7) {
 
152
    /* Provide 7/8 scaling */
 
153
    cinfo->output_width = (JDIMENSION)
 
154
      jdiv_round_up((long) cinfo->image_width * 7L, 8L);
 
155
    cinfo->output_height = (JDIMENSION)
 
156
      jdiv_round_up((long) cinfo->image_height * 7L, 8L);
 
157
    cinfo->min_DCT_h_scaled_size = 7;
 
158
    cinfo->min_DCT_v_scaled_size = 7;
 
159
  } else if (cinfo->scale_num <= cinfo->scale_denom) {
121
160
    /* Provide 1/1 scaling */
122
161
    cinfo->output_width = cinfo->image_width;
123
162
    cinfo->output_height = cinfo->image_height;
124
 
    cinfo->min_DCT_scaled_size = DCTSIZE;
 
163
    cinfo->min_DCT_h_scaled_size = DCTSIZE;
 
164
    cinfo->min_DCT_v_scaled_size = DCTSIZE;
 
165
  } else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 9) {
 
166
    /* Provide 9/8 scaling */
 
167
    cinfo->output_width = cinfo->image_width + (JDIMENSION)
 
168
      jdiv_round_up((long) cinfo->image_width, 8L);
 
169
    cinfo->output_height = cinfo->image_height + (JDIMENSION)
 
170
      jdiv_round_up((long) cinfo->image_height, 8L);
 
171
    cinfo->min_DCT_h_scaled_size = 9;
 
172
    cinfo->min_DCT_v_scaled_size = 9;
 
173
  } else if (cinfo->scale_num * 4 <= cinfo->scale_denom * 5) {
 
174
    /* Provide 5/4 scaling */
 
175
    cinfo->output_width = cinfo->image_width + (JDIMENSION)
 
176
      jdiv_round_up((long) cinfo->image_width, 4L);
 
177
    cinfo->output_height = cinfo->image_height + (JDIMENSION)
 
178
      jdiv_round_up((long) cinfo->image_height, 4L);
 
179
    cinfo->min_DCT_h_scaled_size = 10;
 
180
    cinfo->min_DCT_v_scaled_size = 10;
 
181
  } else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 11) {
 
182
    /* Provide 11/8 scaling */
 
183
    cinfo->output_width = cinfo->image_width + (JDIMENSION)
 
184
      jdiv_round_up((long) cinfo->image_width * 3L, 8L);
 
185
    cinfo->output_height = cinfo->image_height + (JDIMENSION)
 
186
      jdiv_round_up((long) cinfo->image_height * 3L, 8L);
 
187
    cinfo->min_DCT_h_scaled_size = 11;
 
188
    cinfo->min_DCT_v_scaled_size = 11;
 
189
  } else if (cinfo->scale_num * 2 <= cinfo->scale_denom * 3) {
 
190
    /* Provide 3/2 scaling */
 
191
    cinfo->output_width = cinfo->image_width + (JDIMENSION)
 
192
      jdiv_round_up((long) cinfo->image_width, 2L);
 
193
    cinfo->output_height = cinfo->image_height + (JDIMENSION)
 
194
      jdiv_round_up((long) cinfo->image_height, 2L);
 
195
    cinfo->min_DCT_h_scaled_size = 12;
 
196
    cinfo->min_DCT_v_scaled_size = 12;
 
197
  } else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 13) {
 
198
    /* Provide 13/8 scaling */
 
199
    cinfo->output_width = cinfo->image_width + (JDIMENSION)
 
200
      jdiv_round_up((long) cinfo->image_width * 5L, 8L);
 
201
    cinfo->output_height = cinfo->image_height + (JDIMENSION)
 
202
      jdiv_round_up((long) cinfo->image_height * 5L, 8L);
 
203
    cinfo->min_DCT_h_scaled_size = 13;
 
204
    cinfo->min_DCT_v_scaled_size = 13;
 
205
  } else if (cinfo->scale_num * 4 <= cinfo->scale_denom * 7) {
 
206
    /* Provide 7/4 scaling */
 
207
    cinfo->output_width = cinfo->image_width + (JDIMENSION)
 
208
      jdiv_round_up((long) cinfo->image_width * 3L, 4L);
 
209
    cinfo->output_height = cinfo->image_height + (JDIMENSION)
 
210
      jdiv_round_up((long) cinfo->image_height * 3L, 4L);
 
211
    cinfo->min_DCT_h_scaled_size = 14;
 
212
    cinfo->min_DCT_v_scaled_size = 14;
 
213
  } else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 15) {
 
214
    /* Provide 15/8 scaling */
 
215
    cinfo->output_width = cinfo->image_width + (JDIMENSION)
 
216
      jdiv_round_up((long) cinfo->image_width * 7L, 8L);
 
217
    cinfo->output_height = cinfo->image_height + (JDIMENSION)
 
218
      jdiv_round_up((long) cinfo->image_height * 7L, 8L);
 
219
    cinfo->min_DCT_h_scaled_size = 15;
 
220
    cinfo->min_DCT_v_scaled_size = 15;
 
221
  } else {
 
222
    /* Provide 2/1 scaling */
 
223
    cinfo->output_width = cinfo->image_width << 1;
 
224
    cinfo->output_height = cinfo->image_height << 1;
 
225
    cinfo->min_DCT_h_scaled_size = 16;
 
226
    cinfo->min_DCT_v_scaled_size = 16;
125
227
  }
126
228
  /* In selecting the actual DCT scaling for each component, we try to
127
229
   * scale up the chroma components via IDCT scaling rather than upsampling.
128
230
   * This saves time if the upsampler gets to use 1:1 scaling.
129
 
   * Note this code assumes that the supported DCT scalings are powers of 2.
 
231
   * Note this code adapts subsampling ratios which are powers of 2.
130
232
   */
131
233
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
132
234
       ci++, compptr++) {
133
 
    int ssize = cinfo->min_DCT_scaled_size;
134
 
    while (ssize < DCTSIZE &&
135
 
           (compptr->h_samp_factor * ssize * 2 <=
136
 
            cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
137
 
           (compptr->v_samp_factor * ssize * 2 <=
138
 
            cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
139
 
      ssize = ssize * 2;
140
 
    }
141
 
    compptr->DCT_scaled_size = ssize;
 
235
    int ssize = 1;
 
236
    while (cinfo->min_DCT_h_scaled_size * ssize <=
 
237
           (cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
 
238
           (cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {
 
239
      ssize = ssize * 2;
 
240
    }
 
241
    compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
 
242
    ssize = 1;
 
243
    while (cinfo->min_DCT_v_scaled_size * ssize <=
 
244
           (cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
 
245
           (cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {
 
246
      ssize = ssize * 2;
 
247
    }
 
248
    compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
 
249
 
 
250
    /* We don't support IDCT ratios larger than 2. */
 
251
    if (compptr->DCT_h_scaled_size > compptr->DCT_v_scaled_size * 2)
 
252
        compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2;
 
253
    else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2)
 
254
        compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2;
142
255
  }
143
256
 
144
257
  /* Recompute downsampled dimensions of components;
149
262
    /* Size in samples, after IDCT scaling */
150
263
    compptr->downsampled_width = (JDIMENSION)
151
264
      jdiv_round_up((long) cinfo->image_width *
152
 
                    (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
 
265
                    (long) (compptr->h_samp_factor * compptr->DCT_h_scaled_size),
153
266
                    (long) (cinfo->max_h_samp_factor * DCTSIZE));
154
267
    compptr->downsampled_height = (JDIMENSION)
155
268
      jdiv_round_up((long) cinfo->image_height *
156
 
                    (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
 
269
                    (long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size),
157
270
                    (long) (cinfo->max_v_samp_factor * DCTSIZE));
158
271
  }
159
272
 
373
486
  jinit_inverse_dct(cinfo);
374
487
  /* Entropy decoding: either Huffman or arithmetic coding. */
375
488
  if (cinfo->arith_code) {
376
 
    ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
 
489
    jinit_arith_decoder(cinfo);
377
490
  } else {
378
 
    if (cinfo->progressive_mode) {
379
 
#ifdef D_PROGRESSIVE_SUPPORTED
380
 
      jinit_phuff_decoder(cinfo);
381
 
#else
382
 
      ERREXIT(cinfo, JERR_NOT_COMPILED);
383
 
#endif
384
 
    } else
385
 
      jinit_huff_decoder(cinfo);
 
491
    jinit_huff_decoder(cinfo);
386
492
  }
387
493
 
388
494
  /* Initialize principal buffer controllers. */