~ubuntu-branches/ubuntu/trusty/libjpeg-turbo/trusty-proposed

« back to all changes in this revision

Viewing changes to jdmaster.c

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2013-07-28 16:52:51 UTC
  • mfrom: (1.2.2) (5.1.1 precise-proposed)
  • Revision ID: package-import@ubuntu.com-20130728165251-0koil348goxsbqyp
Tags: 1.3.0-0ubuntu1
* New upstream release.
  - drop debian/patches/branch-updates.diff
  - refresh tjunittest.patch (now renamed to install-tjunittest.patch)
* Update debian/control:
  - add myself to Uploaders.
* Update debian/copyright:
  - add RSA Data Security copyright (md5).
* Update debian/libturbojpeg.install:
  - install libturbojpeg.so.0* (needed by tjunittest and tjbench).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * jdmaster.c
3
3
 *
 
4
 * This file was part of the Independent JPEG Group's software:
4
5
 * Copyright (C) 1991-1997, Thomas G. Lane.
 
6
 * Modified 2002-2009 by Guido Vollbeding.
 
7
 * Modifications:
5
8
 * Copyright (C) 2009-2011, D. R. Commander.
6
 
 * This file is part of the Independent JPEG Group's software.
7
9
 * For conditions of distribution and use, see the accompanying README file.
8
10
 *
9
11
 * This file contains master control logic for the JPEG decompressor.
89
91
 * Compute output image dimensions and related values.
90
92
 * NOTE: this is exported for possible use by application.
91
93
 * Hence it mustn't do anything that can't be done twice.
 
94
 */
 
95
 
 
96
#if JPEG_LIB_VERSION >= 80
 
97
GLOBAL(void)
 
98
#else
 
99
LOCAL(void)
 
100
#endif
 
101
jpeg_core_output_dimensions (j_decompress_ptr cinfo)
 
102
/* Do computations that are needed before master selection phase.
 
103
 * This function is used for transcoding and full decompression.
 
104
 */
 
105
{
 
106
#ifdef IDCT_SCALING_SUPPORTED
 
107
  int ci;
 
108
  jpeg_component_info *compptr;
 
109
 
 
110
  /* Compute actual output image dimensions and DCT scaling choices. */
 
111
  if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom) {
 
112
    /* Provide 1/block_size scaling */
 
113
    cinfo->output_width = (JDIMENSION)
 
114
      jdiv_round_up((long) cinfo->image_width, (long) DCTSIZE);
 
115
    cinfo->output_height = (JDIMENSION)
 
116
      jdiv_round_up((long) cinfo->image_height, (long) DCTSIZE);
 
117
    cinfo->_min_DCT_h_scaled_size = 1;
 
118
    cinfo->_min_DCT_v_scaled_size = 1;
 
119
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 2) {
 
120
    /* Provide 2/block_size scaling */
 
121
    cinfo->output_width = (JDIMENSION)
 
122
      jdiv_round_up((long) cinfo->image_width * 2L, (long) DCTSIZE);
 
123
    cinfo->output_height = (JDIMENSION)
 
124
      jdiv_round_up((long) cinfo->image_height * 2L, (long) DCTSIZE);
 
125
    cinfo->_min_DCT_h_scaled_size = 2;
 
126
    cinfo->_min_DCT_v_scaled_size = 2;
 
127
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 3) {
 
128
    /* Provide 3/block_size scaling */
 
129
    cinfo->output_width = (JDIMENSION)
 
130
      jdiv_round_up((long) cinfo->image_width * 3L, (long) DCTSIZE);
 
131
    cinfo->output_height = (JDIMENSION)
 
132
      jdiv_round_up((long) cinfo->image_height * 3L, (long) DCTSIZE);
 
133
    cinfo->_min_DCT_h_scaled_size = 3;
 
134
    cinfo->_min_DCT_v_scaled_size = 3;
 
135
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 4) {
 
136
    /* Provide 4/block_size scaling */
 
137
    cinfo->output_width = (JDIMENSION)
 
138
      jdiv_round_up((long) cinfo->image_width * 4L, (long) DCTSIZE);
 
139
    cinfo->output_height = (JDIMENSION)
 
140
      jdiv_round_up((long) cinfo->image_height * 4L, (long) DCTSIZE);
 
141
    cinfo->_min_DCT_h_scaled_size = 4;
 
142
    cinfo->_min_DCT_v_scaled_size = 4;
 
143
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 5) {
 
144
    /* Provide 5/block_size scaling */
 
145
    cinfo->output_width = (JDIMENSION)
 
146
      jdiv_round_up((long) cinfo->image_width * 5L, (long) DCTSIZE);
 
147
    cinfo->output_height = (JDIMENSION)
 
148
      jdiv_round_up((long) cinfo->image_height * 5L, (long) DCTSIZE);
 
149
    cinfo->_min_DCT_h_scaled_size = 5;
 
150
    cinfo->_min_DCT_v_scaled_size = 5;
 
151
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 6) {
 
152
    /* Provide 6/block_size scaling */
 
153
    cinfo->output_width = (JDIMENSION)
 
154
      jdiv_round_up((long) cinfo->image_width * 6L, (long) DCTSIZE);
 
155
    cinfo->output_height = (JDIMENSION)
 
156
      jdiv_round_up((long) cinfo->image_height * 6L, (long) DCTSIZE);
 
157
    cinfo->_min_DCT_h_scaled_size = 6;
 
158
    cinfo->_min_DCT_v_scaled_size = 6;
 
159
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 7) {
 
160
    /* Provide 7/block_size scaling */
 
161
    cinfo->output_width = (JDIMENSION)
 
162
      jdiv_round_up((long) cinfo->image_width * 7L, (long) DCTSIZE);
 
163
    cinfo->output_height = (JDIMENSION)
 
164
      jdiv_round_up((long) cinfo->image_height * 7L, (long) DCTSIZE);
 
165
    cinfo->_min_DCT_h_scaled_size = 7;
 
166
    cinfo->_min_DCT_v_scaled_size = 7;
 
167
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 8) {
 
168
    /* Provide 8/block_size scaling */
 
169
    cinfo->output_width = (JDIMENSION)
 
170
      jdiv_round_up((long) cinfo->image_width * 8L, (long) DCTSIZE);
 
171
    cinfo->output_height = (JDIMENSION)
 
172
      jdiv_round_up((long) cinfo->image_height * 8L, (long) DCTSIZE);
 
173
    cinfo->_min_DCT_h_scaled_size = 8;
 
174
    cinfo->_min_DCT_v_scaled_size = 8;
 
175
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 9) {
 
176
    /* Provide 9/block_size scaling */
 
177
    cinfo->output_width = (JDIMENSION)
 
178
      jdiv_round_up((long) cinfo->image_width * 9L, (long) DCTSIZE);
 
179
    cinfo->output_height = (JDIMENSION)
 
180
      jdiv_round_up((long) cinfo->image_height * 9L, (long) DCTSIZE);
 
181
    cinfo->_min_DCT_h_scaled_size = 9;
 
182
    cinfo->_min_DCT_v_scaled_size = 9;
 
183
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 10) {
 
184
    /* Provide 10/block_size scaling */
 
185
    cinfo->output_width = (JDIMENSION)
 
186
      jdiv_round_up((long) cinfo->image_width * 10L, (long) DCTSIZE);
 
187
    cinfo->output_height = (JDIMENSION)
 
188
      jdiv_round_up((long) cinfo->image_height * 10L, (long) DCTSIZE);
 
189
    cinfo->_min_DCT_h_scaled_size = 10;
 
190
    cinfo->_min_DCT_v_scaled_size = 10;
 
191
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 11) {
 
192
    /* Provide 11/block_size scaling */
 
193
    cinfo->output_width = (JDIMENSION)
 
194
      jdiv_round_up((long) cinfo->image_width * 11L, (long) DCTSIZE);
 
195
    cinfo->output_height = (JDIMENSION)
 
196
      jdiv_round_up((long) cinfo->image_height * 11L, (long) DCTSIZE);
 
197
    cinfo->_min_DCT_h_scaled_size = 11;
 
198
    cinfo->_min_DCT_v_scaled_size = 11;
 
199
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 12) {
 
200
    /* Provide 12/block_size scaling */
 
201
    cinfo->output_width = (JDIMENSION)
 
202
      jdiv_round_up((long) cinfo->image_width * 12L, (long) DCTSIZE);
 
203
    cinfo->output_height = (JDIMENSION)
 
204
      jdiv_round_up((long) cinfo->image_height * 12L, (long) DCTSIZE);
 
205
    cinfo->_min_DCT_h_scaled_size = 12;
 
206
    cinfo->_min_DCT_v_scaled_size = 12;
 
207
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 13) {
 
208
    /* Provide 13/block_size scaling */
 
209
    cinfo->output_width = (JDIMENSION)
 
210
      jdiv_round_up((long) cinfo->image_width * 13L, (long) DCTSIZE);
 
211
    cinfo->output_height = (JDIMENSION)
 
212
      jdiv_round_up((long) cinfo->image_height * 13L, (long) DCTSIZE);
 
213
    cinfo->_min_DCT_h_scaled_size = 13;
 
214
    cinfo->_min_DCT_v_scaled_size = 13;
 
215
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 14) {
 
216
    /* Provide 14/block_size scaling */
 
217
    cinfo->output_width = (JDIMENSION)
 
218
      jdiv_round_up((long) cinfo->image_width * 14L, (long) DCTSIZE);
 
219
    cinfo->output_height = (JDIMENSION)
 
220
      jdiv_round_up((long) cinfo->image_height * 14L, (long) DCTSIZE);
 
221
    cinfo->_min_DCT_h_scaled_size = 14;
 
222
    cinfo->_min_DCT_v_scaled_size = 14;
 
223
  } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 15) {
 
224
    /* Provide 15/block_size scaling */
 
225
    cinfo->output_width = (JDIMENSION)
 
226
      jdiv_round_up((long) cinfo->image_width * 15L, (long) DCTSIZE);
 
227
    cinfo->output_height = (JDIMENSION)
 
228
      jdiv_round_up((long) cinfo->image_height * 15L, (long) DCTSIZE);
 
229
    cinfo->_min_DCT_h_scaled_size = 15;
 
230
    cinfo->_min_DCT_v_scaled_size = 15;
 
231
  } else {
 
232
    /* Provide 16/block_size scaling */
 
233
    cinfo->output_width = (JDIMENSION)
 
234
      jdiv_round_up((long) cinfo->image_width * 16L, (long) DCTSIZE);
 
235
    cinfo->output_height = (JDIMENSION)
 
236
      jdiv_round_up((long) cinfo->image_height * 16L, (long) DCTSIZE);
 
237
    cinfo->_min_DCT_h_scaled_size = 16;
 
238
    cinfo->_min_DCT_v_scaled_size = 16;
 
239
  }
 
240
 
 
241
  /* Recompute dimensions of components */
 
242
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
 
243
       ci++, compptr++) {
 
244
    compptr->_DCT_h_scaled_size = cinfo->_min_DCT_h_scaled_size;
 
245
    compptr->_DCT_v_scaled_size = cinfo->_min_DCT_v_scaled_size;
 
246
  }
 
247
 
 
248
#else /* !IDCT_SCALING_SUPPORTED */
 
249
 
 
250
  /* Hardwire it to "no scaling" */
 
251
  cinfo->output_width = cinfo->image_width;
 
252
  cinfo->output_height = cinfo->image_height;
 
253
  /* jdinput.c has already initialized DCT_scaled_size,
 
254
   * and has computed unscaled downsampled_width and downsampled_height.
 
255
   */
 
256
 
 
257
#endif /* IDCT_SCALING_SUPPORTED */
 
258
}
 
259
 
 
260
 
 
261
/*
 
262
 * Compute output image dimensions and related values.
 
263
 * NOTE: this is exported for possible use by application.
 
264
 * Hence it mustn't do anything that can't be done twice.
92
265
 * Also note that it may be called before the master module is initialized!
93
266
 */
94
267
 
105
278
  if (cinfo->global_state != DSTATE_READY)
106
279
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
107
280
 
 
281
  /* Compute core output image dimensions and DCT scaling choices. */
 
282
  jpeg_core_output_dimensions(cinfo);
 
283
 
108
284
#ifdef IDCT_SCALING_SUPPORTED
109
285
 
110
 
  /* Compute actual output image dimensions and DCT scaling choices. */
111
 
  if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
112
 
    /* Provide 1/8 scaling */
113
 
    cinfo->output_width = (JDIMENSION)
114
 
      jdiv_round_up((long) cinfo->image_width, 8L);
115
 
    cinfo->output_height = (JDIMENSION)
116
 
      jdiv_round_up((long) cinfo->image_height, 8L);
117
 
#if JPEG_LIB_VERSION >= 70
118
 
    cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 1;
119
 
#else
120
 
    cinfo->min_DCT_scaled_size = 1;
121
 
#endif
122
 
  } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
123
 
    /* Provide 1/4 scaling */
124
 
    cinfo->output_width = (JDIMENSION)
125
 
      jdiv_round_up((long) cinfo->image_width, 4L);
126
 
    cinfo->output_height = (JDIMENSION)
127
 
      jdiv_round_up((long) cinfo->image_height, 4L);
128
 
#if JPEG_LIB_VERSION >= 70
129
 
    cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 2;
130
 
#else
131
 
    cinfo->min_DCT_scaled_size = 2;
132
 
#endif
133
 
  } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
134
 
    /* Provide 1/2 scaling */
135
 
    cinfo->output_width = (JDIMENSION)
136
 
      jdiv_round_up((long) cinfo->image_width, 2L);
137
 
    cinfo->output_height = (JDIMENSION)
138
 
      jdiv_round_up((long) cinfo->image_height, 2L);
139
 
#if JPEG_LIB_VERSION >= 70
140
 
    cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 4;
141
 
#else
142
 
    cinfo->min_DCT_scaled_size = 4;
143
 
#endif
144
 
  } else {
145
 
    /* Provide 1/1 scaling */
146
 
    cinfo->output_width = cinfo->image_width;
147
 
    cinfo->output_height = cinfo->image_height;
148
 
#if JPEG_LIB_VERSION >= 70
149
 
    cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE;
150
 
#else
151
 
    cinfo->min_DCT_scaled_size = DCTSIZE;
152
 
#endif
153
 
  }
154
286
  /* In selecting the actual DCT scaling for each component, we try to
155
287
   * scale up the chroma components via IDCT scaling rather than upsampling.
156
288
   * This saves time if the upsampler gets to use 1:1 scaling.
157
 
   * Note this code assumes that the supported DCT scalings are powers of 2.
 
289
   * Note this code adapts subsampling ratios which are powers of 2.
158
290
   */
159
291
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
160
292
       ci++, compptr++) {
161
293
    int ssize = cinfo->_min_DCT_scaled_size;
162
294
    while (ssize < DCTSIZE &&
163
 
           (compptr->h_samp_factor * ssize * 2 <=
164
 
            cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) &&
165
 
           (compptr->v_samp_factor * ssize * 2 <=
166
 
            cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size)) {
 
295
           ((cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) %
 
296
            (compptr->h_samp_factor * ssize * 2) == 0) &&
 
297
           ((cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size) %
 
298
            (compptr->v_samp_factor * ssize * 2) == 0)) {
167
299
      ssize = ssize * 2;
168
300
    }
169
301
#if JPEG_LIB_VERSION >= 70