Coverage Report

Created: 2025-06-22 06:27

/src/libjpeg-turbo/src/jdmainct.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * jdmainct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1996, Thomas G. Lane.
6
 * libjpeg-turbo Modifications:
7
 * Copyright (C) 2010, 2016, 2022, 2024, D. R. Commander.
8
 * For conditions of distribution and use, see the accompanying README.ijg
9
 * file.
10
 *
11
 * This file contains the main buffer controller for decompression.
12
 * The main buffer lies between the JPEG decompressor proper and the
13
 * post-processor; it holds downsampled data in the JPEG colorspace.
14
 *
15
 * Note that this code is bypassed in raw-data mode, since the application
16
 * supplies the equivalent of the main buffer in that case.
17
 */
18
19
#include "jinclude.h"
20
#include "jdmainct.h"
21
22
23
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
24
25
/*
26
 * In the current system design, the main buffer need never be a full-image
27
 * buffer; any full-height buffers will be found inside the coefficient,
28
 * difference, or postprocessing controllers.  Nonetheless, the main controller
29
 * is not trivial.  Its responsibility is to provide context rows for
30
 * upsampling/rescaling, and doing this in an efficient fashion is a bit
31
 * tricky.
32
 *
33
 * Postprocessor input data is counted in "row groups".  A row group
34
 * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
35
 * sample rows of each component.  (We require DCT_scaled_size values to be
36
 * chosen such that these numbers are integers.  In practice DCT_scaled_size
37
 * values will likely be powers of two, so we actually have the stronger
38
 * condition that DCT_scaled_size / min_DCT_scaled_size is an integer.)
39
 * Upsampling will typically produce max_v_samp_factor pixel rows from each
40
 * row group (times any additional scale factor that the upsampler is
41
 * applying).
42
 *
43
 * The coefficient or difference controller will deliver data to us one iMCU
44
 * row at a time; each iMCU row contains v_samp_factor * DCT_scaled_size sample
45
 * rows, or exactly min_DCT_scaled_size row groups.  (This amount of data
46
 * corresponds to one row of MCUs when the image is fully interleaved.)  Note
47
 * that the number of sample rows varies across components, but the number of
48
 * row groups does not.  Some garbage sample rows may be included in the last
49
 * iMCU row at the bottom of the image.
50
 *
51
 * Depending on the vertical scaling algorithm used, the upsampler may need
52
 * access to the sample row(s) above and below its current input row group.
53
 * The upsampler is required to set need_context_rows TRUE at global selection
54
 * time if so.  When need_context_rows is FALSE, this controller can simply
55
 * obtain one iMCU row at a time from the coefficient or difference controller
56
 * and dole it out as row groups to the postprocessor.
57
 *
58
 * When need_context_rows is TRUE, this controller guarantees that the buffer
59
 * passed to postprocessing contains at least one row group's worth of samples
60
 * above and below the row group(s) being processed.  Note that the context
61
 * rows "above" the first passed row group appear at negative row offsets in
62
 * the passed buffer.  At the top and bottom of the image, the required
63
 * context rows are manufactured by duplicating the first or last real sample
64
 * row; this avoids having special cases in the upsampling inner loops.
65
 *
66
 * The amount of context is fixed at one row group just because that's a
67
 * convenient number for this controller to work with.  The existing
68
 * upsamplers really only need one sample row of context.  An upsampler
69
 * supporting arbitrary output rescaling might wish for more than one row
70
 * group of context when shrinking the image; tough, we don't handle that.
71
 * (This is justified by the assumption that downsizing will be handled mostly
72
 * by adjusting the DCT_scaled_size values, so that the actual scale factor at
73
 * the upsample step needn't be much less than one.)
74
 *
75
 * To provide the desired context, we have to retain the last two row groups
76
 * of one iMCU row while reading in the next iMCU row.  (The last row group
77
 * can't be processed until we have another row group for its below-context,
78
 * and so we have to save the next-to-last group too for its above-context.)
79
 * We could do this most simply by copying data around in our buffer, but
80
 * that'd be very slow.  We can avoid copying any data by creating a rather
81
 * strange pointer structure.  Here's how it works.  We allocate a workspace
82
 * consisting of M+2 row groups (where M = min_DCT_scaled_size is the number
83
 * of row groups per iMCU row).  We create two sets of redundant pointers to
84
 * the workspace.  Labeling the physical row groups 0 to M+1, the synthesized
85
 * pointer lists look like this:
86
 *                   M+1                          M-1
87
 * master pointer --> 0         master pointer --> 0
88
 *                    1                            1
89
 *                   ...                          ...
90
 *                   M-3                          M-3
91
 *                   M-2                           M
92
 *                   M-1                          M+1
93
 *                    M                           M-2
94
 *                   M+1                          M-1
95
 *                    0                            0
96
 * We read alternate iMCU rows using each master pointer; thus the last two
97
 * row groups of the previous iMCU row remain un-overwritten in the workspace.
98
 * The pointer lists are set up so that the required context rows appear to
99
 * be adjacent to the proper places when we pass the pointer lists to the
100
 * upsampler.
101
 *
102
 * The above pictures describe the normal state of the pointer lists.
103
 * At top and bottom of the image, we diddle the pointer lists to duplicate
104
 * the first or last sample row as necessary (this is cheaper than copying
105
 * sample rows around).
106
 *
107
 * This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1.  In that
108
 * situation each iMCU row provides only one row group so the buffering logic
109
 * must be different (eg, we must read two iMCU rows before we can emit the
110
 * first row group).  For now, we simply do not support providing context
111
 * rows when min_DCT_scaled_size is 1.  That combination seems unlikely to
112
 * be worth providing --- if someone wants a 1/8th-size preview, they probably
113
 * want it quick and dirty, so a context-free upsampler is sufficient.
114
 */
115
116
117
/* Forward declarations */
118
METHODDEF(void) process_data_simple_main(j_decompress_ptr cinfo,
119
                                         _JSAMPARRAY output_buf,
120
                                         JDIMENSION *out_row_ctr,
121
                                         JDIMENSION out_rows_avail);
122
METHODDEF(void) process_data_context_main(j_decompress_ptr cinfo,
123
                                          _JSAMPARRAY output_buf,
124
                                          JDIMENSION *out_row_ctr,
125
                                          JDIMENSION out_rows_avail);
126
#ifdef QUANT_2PASS_SUPPORTED
127
METHODDEF(void) process_data_crank_post(j_decompress_ptr cinfo,
128
                                        _JSAMPARRAY output_buf,
129
                                        JDIMENSION *out_row_ctr,
130
                                        JDIMENSION out_rows_avail);
131
#endif
132
133
134
LOCAL(void)
135
alloc_funny_pointers(j_decompress_ptr cinfo)
136
/* Allocate space for the funny pointer lists.
137
 * This is done only once, not once per pass.
138
 */
139
562
{
140
562
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
141
562
  int ci, rgroup;
142
562
  int M = cinfo->_min_DCT_scaled_size;
143
562
  jpeg_component_info *compptr;
144
562
  _JSAMPARRAY xbuf;
145
146
  /* Get top-level space for component array pointers.
147
   * We alloc both arrays with one call to save a few cycles.
148
   */
149
562
  main_ptr->xbuffer[0] = (_JSAMPIMAGE)
150
562
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
151
562
                                cinfo->num_components * 2 *
152
562
                                sizeof(_JSAMPARRAY));
153
562
  main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
154
155
2.26k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
156
1.70k
       ci++, compptr++) {
157
1.70k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
158
1.70k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
159
    /* Get space for pointer lists --- M+4 row groups in each list.
160
     * We alloc both pointer lists with one call to save a few cycles.
161
     */
162
1.70k
    xbuf = (_JSAMPARRAY)
163
1.70k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
164
1.70k
                                  2 * (rgroup * (M + 4)) * sizeof(_JSAMPROW));
165
1.70k
    xbuf += rgroup;             /* want one row group at negative offsets */
166
1.70k
    main_ptr->xbuffer[0][ci] = xbuf;
167
1.70k
    xbuf += rgroup * (M + 4);
168
1.70k
    main_ptr->xbuffer[1][ci] = xbuf;
169
1.70k
  }
170
562
}
jdmainct-8.c:alloc_funny_pointers
Line
Count
Source
139
479
{
140
479
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
141
479
  int ci, rgroup;
142
479
  int M = cinfo->_min_DCT_scaled_size;
143
479
  jpeg_component_info *compptr;
144
479
  _JSAMPARRAY xbuf;
145
146
  /* Get top-level space for component array pointers.
147
   * We alloc both arrays with one call to save a few cycles.
148
   */
149
479
  main_ptr->xbuffer[0] = (_JSAMPIMAGE)
150
479
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
151
479
                                cinfo->num_components * 2 *
152
479
                                sizeof(_JSAMPARRAY));
153
479
  main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
154
155
1.91k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
156
1.43k
       ci++, compptr++) {
157
1.43k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
158
1.43k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
159
    /* Get space for pointer lists --- M+4 row groups in each list.
160
     * We alloc both pointer lists with one call to save a few cycles.
161
     */
162
1.43k
    xbuf = (_JSAMPARRAY)
163
1.43k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
164
1.43k
                                  2 * (rgroup * (M + 4)) * sizeof(_JSAMPROW));
165
1.43k
    xbuf += rgroup;             /* want one row group at negative offsets */
166
1.43k
    main_ptr->xbuffer[0][ci] = xbuf;
167
1.43k
    xbuf += rgroup * (M + 4);
168
1.43k
    main_ptr->xbuffer[1][ci] = xbuf;
169
1.43k
  }
170
479
}
jdmainct-12.c:alloc_funny_pointers
Line
Count
Source
139
83
{
140
83
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
141
83
  int ci, rgroup;
142
83
  int M = cinfo->_min_DCT_scaled_size;
143
83
  jpeg_component_info *compptr;
144
83
  _JSAMPARRAY xbuf;
145
146
  /* Get top-level space for component array pointers.
147
   * We alloc both arrays with one call to save a few cycles.
148
   */
149
83
  main_ptr->xbuffer[0] = (_JSAMPIMAGE)
150
83
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
151
83
                                cinfo->num_components * 2 *
152
83
                                sizeof(_JSAMPARRAY));
153
83
  main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
154
155
355
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
156
272
       ci++, compptr++) {
157
272
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
158
272
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
159
    /* Get space for pointer lists --- M+4 row groups in each list.
160
     * We alloc both pointer lists with one call to save a few cycles.
161
     */
162
272
    xbuf = (_JSAMPARRAY)
163
272
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
164
272
                                  2 * (rgroup * (M + 4)) * sizeof(_JSAMPROW));
165
272
    xbuf += rgroup;             /* want one row group at negative offsets */
166
272
    main_ptr->xbuffer[0][ci] = xbuf;
167
272
    xbuf += rgroup * (M + 4);
168
272
    main_ptr->xbuffer[1][ci] = xbuf;
169
272
  }
170
83
}
Unexecuted instantiation: jdmainct-16.c:alloc_funny_pointers
171
172
173
LOCAL(void)
174
make_funny_pointers(j_decompress_ptr cinfo)
175
/* Create the funny pointer lists discussed in the comments above.
176
 * The actual workspace is already allocated (in main_ptr->buffer),
177
 * and the space for the pointer lists is allocated too.
178
 * This routine just fills in the curiously ordered lists.
179
 * This will be repeated at the beginning of each pass.
180
 */
181
179
{
182
179
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
183
179
  int ci, i, rgroup;
184
179
  int M = cinfo->_min_DCT_scaled_size;
185
179
  jpeg_component_info *compptr;
186
179
  _JSAMPARRAY buf, xbuf0, xbuf1;
187
188
683
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
189
504
       ci++, compptr++) {
190
504
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
191
504
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
192
504
    xbuf0 = main_ptr->xbuffer[0][ci];
193
504
    xbuf1 = main_ptr->xbuffer[1][ci];
194
    /* First copy the workspace pointers as-is */
195
504
    buf = main_ptr->buffer[ci];
196
11.1k
    for (i = 0; i < rgroup * (M + 2); i++) {
197
10.6k
      xbuf0[i] = xbuf1[i] = buf[i];
198
10.6k
    }
199
    /* In the second list, put the last four row groups in swapped order */
200
2.62k
    for (i = 0; i < rgroup * 2; i++) {
201
2.12k
      xbuf1[rgroup * (M - 2) + i] = buf[rgroup * M + i];
202
2.12k
      xbuf1[rgroup * M + i] = buf[rgroup * (M - 2) + i];
203
2.12k
    }
204
    /* The wraparound pointers at top and bottom will be filled later
205
     * (see set_wraparound_pointers, below).  Initially we want the "above"
206
     * pointers to duplicate the first actual data line.  This only needs
207
     * to happen in xbuffer[0].
208
     */
209
1.56k
    for (i = 0; i < rgroup; i++) {
210
1.06k
      xbuf0[i - rgroup] = xbuf0[0];
211
1.06k
    }
212
504
  }
213
179
}
jdmainct-8.c:make_funny_pointers
Line
Count
Source
181
162
{
182
162
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
183
162
  int ci, i, rgroup;
184
162
  int M = cinfo->_min_DCT_scaled_size;
185
162
  jpeg_component_info *compptr;
186
162
  _JSAMPARRAY buf, xbuf0, xbuf1;
187
188
617
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
189
455
       ci++, compptr++) {
190
455
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
191
455
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
192
455
    xbuf0 = main_ptr->xbuffer[0][ci];
193
455
    xbuf1 = main_ptr->xbuffer[1][ci];
194
    /* First copy the workspace pointers as-is */
195
455
    buf = main_ptr->buffer[ci];
196
10.0k
    for (i = 0; i < rgroup * (M + 2); i++) {
197
9.59k
      xbuf0[i] = xbuf1[i] = buf[i];
198
9.59k
    }
199
    /* In the second list, put the last four row groups in swapped order */
200
2.37k
    for (i = 0; i < rgroup * 2; i++) {
201
1.91k
      xbuf1[rgroup * (M - 2) + i] = buf[rgroup * M + i];
202
1.91k
      xbuf1[rgroup * M + i] = buf[rgroup * (M - 2) + i];
203
1.91k
    }
204
    /* The wraparound pointers at top and bottom will be filled later
205
     * (see set_wraparound_pointers, below).  Initially we want the "above"
206
     * pointers to duplicate the first actual data line.  This only needs
207
     * to happen in xbuffer[0].
208
     */
209
1.41k
    for (i = 0; i < rgroup; i++) {
210
959
      xbuf0[i - rgroup] = xbuf0[0];
211
959
    }
212
455
  }
213
162
}
jdmainct-12.c:make_funny_pointers
Line
Count
Source
181
17
{
182
17
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
183
17
  int ci, i, rgroup;
184
17
  int M = cinfo->_min_DCT_scaled_size;
185
17
  jpeg_component_info *compptr;
186
17
  _JSAMPARRAY buf, xbuf0, xbuf1;
187
188
66
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
189
49
       ci++, compptr++) {
190
49
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
191
49
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
192
49
    xbuf0 = main_ptr->xbuffer[0][ci];
193
49
    xbuf1 = main_ptr->xbuffer[1][ci];
194
    /* First copy the workspace pointers as-is */
195
49
    buf = main_ptr->buffer[ci];
196
1.06k
    for (i = 0; i < rgroup * (M + 2); i++) {
197
1.02k
      xbuf0[i] = xbuf1[i] = buf[i];
198
1.02k
    }
199
    /* In the second list, put the last four row groups in swapped order */
200
253
    for (i = 0; i < rgroup * 2; i++) {
201
204
      xbuf1[rgroup * (M - 2) + i] = buf[rgroup * M + i];
202
204
      xbuf1[rgroup * M + i] = buf[rgroup * (M - 2) + i];
203
204
    }
204
    /* The wraparound pointers at top and bottom will be filled later
205
     * (see set_wraparound_pointers, below).  Initially we want the "above"
206
     * pointers to duplicate the first actual data line.  This only needs
207
     * to happen in xbuffer[0].
208
     */
209
151
    for (i = 0; i < rgroup; i++) {
210
102
      xbuf0[i - rgroup] = xbuf0[0];
211
102
    }
212
49
  }
213
17
}
Unexecuted instantiation: jdmainct-16.c:make_funny_pointers
214
215
216
LOCAL(void)
217
set_bottom_pointers(j_decompress_ptr cinfo)
218
/* Change the pointer lists to duplicate the last sample row at the bottom
219
 * of the image.  whichptr indicates which xbuffer holds the final iMCU row.
220
 * Also sets rowgroups_avail to indicate number of nondummy row groups in row.
221
 */
222
158
{
223
158
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
224
158
  int ci, i, rgroup, iMCUheight, rows_left;
225
158
  jpeg_component_info *compptr;
226
158
  _JSAMPARRAY xbuf;
227
228
601
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
229
443
       ci++, compptr++) {
230
    /* Count sample rows in one iMCU row and in one row group */
231
443
    iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size;
232
443
    rgroup = iMCUheight / cinfo->_min_DCT_scaled_size;
233
    /* Count nondummy sample rows remaining for this component */
234
443
    rows_left = (int)(compptr->downsampled_height % (JDIMENSION)iMCUheight);
235
443
    if (rows_left == 0) rows_left = iMCUheight;
236
    /* Count nondummy row groups.  Should get same answer for each component,
237
     * so we need only do it once.
238
     */
239
443
    if (ci == 0) {
240
158
      main_ptr->rowgroups_avail = (JDIMENSION)((rows_left - 1) / rgroup + 1);
241
158
    }
242
    /* Duplicate the last real sample row rgroup*2 times; this pads out the
243
     * last partial rowgroup and ensures at least one full rowgroup of context.
244
     */
245
443
    xbuf = main_ptr->xbuffer[main_ptr->whichptr][ci];
246
2.32k
    for (i = 0; i < rgroup * 2; i++) {
247
1.88k
      xbuf[rows_left + i] = xbuf[rows_left - 1];
248
1.88k
    }
249
443
  }
250
158
}
jdmainct-8.c:set_bottom_pointers
Line
Count
Source
222
158
{
223
158
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
224
158
  int ci, i, rgroup, iMCUheight, rows_left;
225
158
  jpeg_component_info *compptr;
226
158
  _JSAMPARRAY xbuf;
227
228
601
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
229
443
       ci++, compptr++) {
230
    /* Count sample rows in one iMCU row and in one row group */
231
443
    iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size;
232
443
    rgroup = iMCUheight / cinfo->_min_DCT_scaled_size;
233
    /* Count nondummy sample rows remaining for this component */
234
443
    rows_left = (int)(compptr->downsampled_height % (JDIMENSION)iMCUheight);
235
443
    if (rows_left == 0) rows_left = iMCUheight;
236
    /* Count nondummy row groups.  Should get same answer for each component,
237
     * so we need only do it once.
238
     */
239
443
    if (ci == 0) {
240
158
      main_ptr->rowgroups_avail = (JDIMENSION)((rows_left - 1) / rgroup + 1);
241
158
    }
242
    /* Duplicate the last real sample row rgroup*2 times; this pads out the
243
     * last partial rowgroup and ensures at least one full rowgroup of context.
244
     */
245
443
    xbuf = main_ptr->xbuffer[main_ptr->whichptr][ci];
246
2.32k
    for (i = 0; i < rgroup * 2; i++) {
247
1.88k
      xbuf[rows_left + i] = xbuf[rows_left - 1];
248
1.88k
    }
249
443
  }
250
158
}
Unexecuted instantiation: jdmainct-12.c:set_bottom_pointers
Unexecuted instantiation: jdmainct-16.c:set_bottom_pointers
251
252
253
/*
254
 * Initialize for a processing pass.
255
 */
256
257
METHODDEF(void)
258
start_pass_main(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
259
2.86k
{
260
2.86k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
261
262
2.86k
  switch (pass_mode) {
263
2.86k
  case JBUF_PASS_THRU:
264
2.86k
    if (cinfo->upsample->need_context_rows) {
265
179
      main_ptr->pub._process_data = process_data_context_main;
266
179
      make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
267
179
      main_ptr->whichptr = 0;   /* Read first iMCU row into xbuffer[0] */
268
179
      main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
269
179
      main_ptr->iMCU_row_ctr = 0;
270
2.68k
    } else {
271
      /* Simple case with no context needed */
272
2.68k
      main_ptr->pub._process_data = process_data_simple_main;
273
2.68k
    }
274
2.86k
    main_ptr->buffer_full = FALSE;      /* Mark buffer empty */
275
2.86k
    main_ptr->rowgroup_ctr = 0;
276
2.86k
    break;
277
0
#ifdef QUANT_2PASS_SUPPORTED
278
0
  case JBUF_CRANK_DEST:
279
    /* For last pass of 2-pass quantization, just crank the postprocessor */
280
0
    main_ptr->pub._process_data = process_data_crank_post;
281
0
    break;
282
0
#endif
283
0
  default:
284
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
285
0
    break;
286
2.86k
  }
287
2.86k
}
jdmainct-8.c:start_pass_main
Line
Count
Source
259
2.71k
{
260
2.71k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
261
262
2.71k
  switch (pass_mode) {
263
2.71k
  case JBUF_PASS_THRU:
264
2.71k
    if (cinfo->upsample->need_context_rows) {
265
162
      main_ptr->pub._process_data = process_data_context_main;
266
162
      make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
267
162
      main_ptr->whichptr = 0;   /* Read first iMCU row into xbuffer[0] */
268
162
      main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
269
162
      main_ptr->iMCU_row_ctr = 0;
270
2.54k
    } else {
271
      /* Simple case with no context needed */
272
2.54k
      main_ptr->pub._process_data = process_data_simple_main;
273
2.54k
    }
274
2.71k
    main_ptr->buffer_full = FALSE;      /* Mark buffer empty */
275
2.71k
    main_ptr->rowgroup_ctr = 0;
276
2.71k
    break;
277
0
#ifdef QUANT_2PASS_SUPPORTED
278
0
  case JBUF_CRANK_DEST:
279
    /* For last pass of 2-pass quantization, just crank the postprocessor */
280
0
    main_ptr->pub._process_data = process_data_crank_post;
281
0
    break;
282
0
#endif
283
0
  default:
284
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
285
0
    break;
286
2.71k
  }
287
2.71k
}
jdmainct-12.c:start_pass_main
Line
Count
Source
259
122
{
260
122
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
261
262
122
  switch (pass_mode) {
263
122
  case JBUF_PASS_THRU:
264
122
    if (cinfo->upsample->need_context_rows) {
265
17
      main_ptr->pub._process_data = process_data_context_main;
266
17
      make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
267
17
      main_ptr->whichptr = 0;   /* Read first iMCU row into xbuffer[0] */
268
17
      main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
269
17
      main_ptr->iMCU_row_ctr = 0;
270
105
    } else {
271
      /* Simple case with no context needed */
272
105
      main_ptr->pub._process_data = process_data_simple_main;
273
105
    }
274
122
    main_ptr->buffer_full = FALSE;      /* Mark buffer empty */
275
122
    main_ptr->rowgroup_ctr = 0;
276
122
    break;
277
0
#ifdef QUANT_2PASS_SUPPORTED
278
0
  case JBUF_CRANK_DEST:
279
    /* For last pass of 2-pass quantization, just crank the postprocessor */
280
0
    main_ptr->pub._process_data = process_data_crank_post;
281
0
    break;
282
0
#endif
283
0
  default:
284
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
285
0
    break;
286
122
  }
287
122
}
jdmainct-16.c:start_pass_main
Line
Count
Source
259
35
{
260
35
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
261
262
35
  switch (pass_mode) {
263
35
  case JBUF_PASS_THRU:
264
35
    if (cinfo->upsample->need_context_rows) {
265
0
      main_ptr->pub._process_data = process_data_context_main;
266
0
      make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
267
0
      main_ptr->whichptr = 0;   /* Read first iMCU row into xbuffer[0] */
268
0
      main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
269
0
      main_ptr->iMCU_row_ctr = 0;
270
35
    } else {
271
      /* Simple case with no context needed */
272
35
      main_ptr->pub._process_data = process_data_simple_main;
273
35
    }
274
35
    main_ptr->buffer_full = FALSE;      /* Mark buffer empty */
275
35
    main_ptr->rowgroup_ctr = 0;
276
35
    break;
277
0
#ifdef QUANT_2PASS_SUPPORTED
278
0
  case JBUF_CRANK_DEST:
279
    /* For last pass of 2-pass quantization, just crank the postprocessor */
280
0
    main_ptr->pub._process_data = process_data_crank_post;
281
0
    break;
282
0
#endif
283
0
  default:
284
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
285
0
    break;
286
35
  }
287
35
}
288
289
290
/*
291
 * Process some data.
292
 * This handles the simple case where no context is required.
293
 */
294
295
METHODDEF(void)
296
process_data_simple_main(j_decompress_ptr cinfo, _JSAMPARRAY output_buf,
297
                         JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
298
8.30M
{
299
8.30M
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
300
8.30M
  JDIMENSION rowgroups_avail;
301
302
  /* Read input data if we haven't filled the main buffer yet */
303
8.30M
  if (!main_ptr->buffer_full) {
304
568k
    if (!(*cinfo->coef->_decompress_data) (cinfo, main_ptr->buffer))
305
0
      return;                   /* suspension forced, can do nothing more */
306
568k
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
307
568k
  }
308
309
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
310
8.30M
  rowgroups_avail = (JDIMENSION)cinfo->_min_DCT_scaled_size;
311
  /* Note: at the bottom of the image, we may pass extra garbage row groups
312
   * to the postprocessor.  The postprocessor has to check for bottom
313
   * of image anyway (at row resolution), so no point in us doing it too.
314
   */
315
316
  /* Feed the postprocessor */
317
8.30M
  (*cinfo->post->_post_process_data) (cinfo, main_ptr->buffer,
318
8.30M
                                      &main_ptr->rowgroup_ctr, rowgroups_avail,
319
8.30M
                                      output_buf, out_row_ctr, out_rows_avail);
320
321
  /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
322
8.30M
  if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
323
566k
    main_ptr->buffer_full = FALSE;
324
566k
    main_ptr->rowgroup_ctr = 0;
325
566k
  }
326
8.30M
}
jdmainct-8.c:process_data_simple_main
Line
Count
Source
298
8.30M
{
299
8.30M
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
300
8.30M
  JDIMENSION rowgroups_avail;
301
302
  /* Read input data if we haven't filled the main buffer yet */
303
8.30M
  if (!main_ptr->buffer_full) {
304
568k
    if (!(*cinfo->coef->_decompress_data) (cinfo, main_ptr->buffer))
305
0
      return;                   /* suspension forced, can do nothing more */
306
568k
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
307
568k
  }
308
309
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
310
8.30M
  rowgroups_avail = (JDIMENSION)cinfo->_min_DCT_scaled_size;
311
  /* Note: at the bottom of the image, we may pass extra garbage row groups
312
   * to the postprocessor.  The postprocessor has to check for bottom
313
   * of image anyway (at row resolution), so no point in us doing it too.
314
   */
315
316
  /* Feed the postprocessor */
317
8.30M
  (*cinfo->post->_post_process_data) (cinfo, main_ptr->buffer,
318
8.30M
                                      &main_ptr->rowgroup_ctr, rowgroups_avail,
319
8.30M
                                      output_buf, out_row_ctr, out_rows_avail);
320
321
  /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
322
8.30M
  if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
323
566k
    main_ptr->buffer_full = FALSE;
324
566k
    main_ptr->rowgroup_ctr = 0;
325
566k
  }
326
8.30M
}
Unexecuted instantiation: jdmainct-12.c:process_data_simple_main
Unexecuted instantiation: jdmainct-16.c:process_data_simple_main
327
328
329
/*
330
 * Process some data.
331
 * This handles the case where context rows must be provided.
332
 */
333
334
METHODDEF(void)
335
process_data_context_main(j_decompress_ptr cinfo, _JSAMPARRAY output_buf,
336
                          JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
337
1.58M
{
338
1.58M
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
339
340
  /* Read input data if we haven't filled the main buffer yet */
341
1.58M
  if (!main_ptr->buffer_full) {
342
83.8k
    if (!(*cinfo->coef->_decompress_data) (cinfo,
343
83.8k
                                           main_ptr->xbuffer[main_ptr->whichptr]))
344
0
      return;                   /* suspension forced, can do nothing more */
345
83.8k
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
346
83.8k
    main_ptr->iMCU_row_ctr++;   /* count rows received */
347
83.8k
  }
348
349
  /* Postprocessor typically will not swallow all the input data it is handed
350
   * in one call (due to filling the output buffer first).  Must be prepared
351
   * to exit and restart.  This switch lets us keep track of how far we got.
352
   * Note that each case falls through to the next on successful completion.
353
   */
354
1.58M
  switch (main_ptr->context_state) {
355
197k
  case CTX_POSTPONED_ROW:
356
    /* Call postprocessor using previously set pointers for postponed row */
357
197k
    (*cinfo->post->_post_process_data) (cinfo,
358
197k
                                        main_ptr->xbuffer[main_ptr->whichptr],
359
197k
                                        &main_ptr->rowgroup_ctr,
360
197k
                                        main_ptr->rowgroups_avail, output_buf,
361
197k
                                        out_row_ctr, out_rows_avail);
362
197k
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
363
113k
      return;                   /* Need to suspend */
364
83.6k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
365
83.6k
    if (*out_row_ctr >= out_rows_avail)
366
83.6k
      return;                   /* Postprocessor exactly filled output buf */
367
0
    FALLTHROUGH                 /*FALLTHROUGH*/
368
83.8k
  case CTX_PREPARE_FOR_IMCU:
369
    /* Prepare to process first M-1 row groups of this iMCU row */
370
83.8k
    main_ptr->rowgroup_ctr = 0;
371
83.8k
    main_ptr->rowgroups_avail = (JDIMENSION)(cinfo->_min_DCT_scaled_size - 1);
372
    /* Check for bottom of image: if so, tweak pointers to "duplicate"
373
     * the last sample row, and adjust rowgroups_avail to ignore padding rows.
374
     */
375
83.8k
    if (main_ptr->iMCU_row_ctr == cinfo->total_iMCU_rows)
376
158
      set_bottom_pointers(cinfo);
377
83.8k
    main_ptr->context_state = CTX_PROCESS_IMCU;
378
83.8k
    FALLTHROUGH                 /*FALLTHROUGH*/
379
1.38M
  case CTX_PROCESS_IMCU:
380
    /* Call postprocessor using previously set pointers */
381
1.38M
    (*cinfo->post->_post_process_data) (cinfo,
382
1.38M
                                        main_ptr->xbuffer[main_ptr->whichptr],
383
1.38M
                                        &main_ptr->rowgroup_ctr,
384
1.38M
                                        main_ptr->rowgroups_avail, output_buf,
385
1.38M
                                        out_row_ctr, out_rows_avail);
386
1.38M
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
387
1.30M
      return;                   /* Need to suspend */
388
    /* After the first iMCU, change wraparound pointers to normal state */
389
83.7k
    if (main_ptr->iMCU_row_ctr == 1)
390
123
      set_wraparound_pointers(cinfo);
391
    /* Prepare to load new iMCU row using other xbuffer list */
392
83.7k
    main_ptr->whichptr ^= 1;    /* 0=>1 or 1=>0 */
393
83.7k
    main_ptr->buffer_full = FALSE;
394
    /* Still need to process last row group of this iMCU row, */
395
    /* which is saved at index M+1 of the other xbuffer */
396
83.7k
    main_ptr->rowgroup_ctr = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 1);
397
83.7k
    main_ptr->rowgroups_avail = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 2);
398
83.7k
    main_ptr->context_state = CTX_POSTPONED_ROW;
399
1.58M
  }
400
1.58M
}
jdmainct-8.c:process_data_context_main
Line
Count
Source
337
1.58M
{
338
1.58M
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
339
340
  /* Read input data if we haven't filled the main buffer yet */
341
1.58M
  if (!main_ptr->buffer_full) {
342
83.8k
    if (!(*cinfo->coef->_decompress_data) (cinfo,
343
83.8k
                                           main_ptr->xbuffer[main_ptr->whichptr]))
344
0
      return;                   /* suspension forced, can do nothing more */
345
83.8k
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
346
83.8k
    main_ptr->iMCU_row_ctr++;   /* count rows received */
347
83.8k
  }
348
349
  /* Postprocessor typically will not swallow all the input data it is handed
350
   * in one call (due to filling the output buffer first).  Must be prepared
351
   * to exit and restart.  This switch lets us keep track of how far we got.
352
   * Note that each case falls through to the next on successful completion.
353
   */
354
1.58M
  switch (main_ptr->context_state) {
355
197k
  case CTX_POSTPONED_ROW:
356
    /* Call postprocessor using previously set pointers for postponed row */
357
197k
    (*cinfo->post->_post_process_data) (cinfo,
358
197k
                                        main_ptr->xbuffer[main_ptr->whichptr],
359
197k
                                        &main_ptr->rowgroup_ctr,
360
197k
                                        main_ptr->rowgroups_avail, output_buf,
361
197k
                                        out_row_ctr, out_rows_avail);
362
197k
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
363
113k
      return;                   /* Need to suspend */
364
83.6k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
365
83.6k
    if (*out_row_ctr >= out_rows_avail)
366
83.6k
      return;                   /* Postprocessor exactly filled output buf */
367
0
    FALLTHROUGH                 /*FALLTHROUGH*/
368
83.8k
  case CTX_PREPARE_FOR_IMCU:
369
    /* Prepare to process first M-1 row groups of this iMCU row */
370
83.8k
    main_ptr->rowgroup_ctr = 0;
371
83.8k
    main_ptr->rowgroups_avail = (JDIMENSION)(cinfo->_min_DCT_scaled_size - 1);
372
    /* Check for bottom of image: if so, tweak pointers to "duplicate"
373
     * the last sample row, and adjust rowgroups_avail to ignore padding rows.
374
     */
375
83.8k
    if (main_ptr->iMCU_row_ctr == cinfo->total_iMCU_rows)
376
158
      set_bottom_pointers(cinfo);
377
83.8k
    main_ptr->context_state = CTX_PROCESS_IMCU;
378
83.8k
    FALLTHROUGH                 /*FALLTHROUGH*/
379
1.38M
  case CTX_PROCESS_IMCU:
380
    /* Call postprocessor using previously set pointers */
381
1.38M
    (*cinfo->post->_post_process_data) (cinfo,
382
1.38M
                                        main_ptr->xbuffer[main_ptr->whichptr],
383
1.38M
                                        &main_ptr->rowgroup_ctr,
384
1.38M
                                        main_ptr->rowgroups_avail, output_buf,
385
1.38M
                                        out_row_ctr, out_rows_avail);
386
1.38M
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
387
1.30M
      return;                   /* Need to suspend */
388
    /* After the first iMCU, change wraparound pointers to normal state */
389
83.7k
    if (main_ptr->iMCU_row_ctr == 1)
390
123
      set_wraparound_pointers(cinfo);
391
    /* Prepare to load new iMCU row using other xbuffer list */
392
83.7k
    main_ptr->whichptr ^= 1;    /* 0=>1 or 1=>0 */
393
83.7k
    main_ptr->buffer_full = FALSE;
394
    /* Still need to process last row group of this iMCU row, */
395
    /* which is saved at index M+1 of the other xbuffer */
396
83.7k
    main_ptr->rowgroup_ctr = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 1);
397
83.7k
    main_ptr->rowgroups_avail = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 2);
398
83.7k
    main_ptr->context_state = CTX_POSTPONED_ROW;
399
1.58M
  }
400
1.58M
}
Unexecuted instantiation: jdmainct-12.c:process_data_context_main
Unexecuted instantiation: jdmainct-16.c:process_data_context_main
401
402
403
/*
404
 * Process some data.
405
 * Final pass of two-pass quantization: just call the postprocessor.
406
 * Source data will be the postprocessor controller's internal buffer.
407
 */
408
409
#ifdef QUANT_2PASS_SUPPORTED
410
411
METHODDEF(void)
412
process_data_crank_post(j_decompress_ptr cinfo, _JSAMPARRAY output_buf,
413
                        JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
414
0
{
415
0
  (*cinfo->post->_post_process_data) (cinfo, (_JSAMPIMAGE)NULL,
416
0
                                      (JDIMENSION *)NULL, (JDIMENSION)0,
417
0
                                      output_buf, out_row_ctr, out_rows_avail);
418
0
}
Unexecuted instantiation: jdmainct-8.c:process_data_crank_post
Unexecuted instantiation: jdmainct-12.c:process_data_crank_post
Unexecuted instantiation: jdmainct-16.c:process_data_crank_post
419
420
#endif /* QUANT_2PASS_SUPPORTED */
421
422
423
/*
424
 * Initialize main buffer controller.
425
 */
426
427
GLOBAL(void)
428
_jinit_d_main_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
429
6.35k
{
430
6.35k
  my_main_ptr main_ptr;
431
6.35k
  int ci, rgroup, ngroups;
432
6.35k
  jpeg_component_info *compptr;
433
434
6.35k
#ifdef D_LOSSLESS_SUPPORTED
435
6.35k
  if (cinfo->master->lossless) {
436
#if BITS_IN_JSAMPLE == 8
437
1.34k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
438
#else
439
1.76k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
440
1.76k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
441
0
#endif
442
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
443
3.10k
  } else
444
3.24k
#endif
445
3.24k
  {
446
3.24k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
447
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
448
3.24k
  }
449
450
6.35k
  main_ptr = (my_main_ptr)
451
6.35k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
452
6.35k
                                sizeof(my_main_controller));
453
6.35k
  memset(main_ptr, 0, sizeof(my_main_controller));
454
6.35k
  cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
455
6.35k
  main_ptr->pub.start_pass = start_pass_main;
456
457
6.35k
  if (need_full_buffer)         /* shouldn't happen */
458
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
459
460
  /* Allocate the workspace.
461
   * ngroups is the number of row groups we need.
462
   */
463
6.35k
  if (cinfo->upsample->need_context_rows) {
464
562
    if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */
465
0
      ERREXIT(cinfo, JERR_NOTIMPL);
466
562
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
467
562
    ngroups = cinfo->_min_DCT_scaled_size + 2;
468
5.79k
  } else {
469
5.79k
    ngroups = cinfo->_min_DCT_scaled_size;
470
5.79k
  }
471
472
19.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
473
12.6k
       ci++, compptr++) {
474
12.6k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
475
12.6k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
476
12.6k
    main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
477
12.6k
                        ((j_common_ptr)cinfo, JPOOL_IMAGE,
478
12.6k
                         compptr->width_in_blocks * compptr->_DCT_scaled_size,
479
12.6k
                         (JDIMENSION)(rgroup * ngroups));
480
12.6k
  }
481
6.35k
}
jinit_d_main_controller
Line
Count
Source
429
4.19k
{
430
4.19k
  my_main_ptr main_ptr;
431
4.19k
  int ci, rgroup, ngroups;
432
4.19k
  jpeg_component_info *compptr;
433
434
4.19k
#ifdef D_LOSSLESS_SUPPORTED
435
4.19k
  if (cinfo->master->lossless) {
436
1.34k
#if BITS_IN_JSAMPLE == 8
437
1.34k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
438
#else
439
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
440
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
441
#endif
442
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
443
1.34k
  } else
444
2.84k
#endif
445
2.84k
  {
446
2.84k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
447
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
448
2.84k
  }
449
450
4.19k
  main_ptr = (my_main_ptr)
451
4.19k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
452
4.19k
                                sizeof(my_main_controller));
453
4.19k
  memset(main_ptr, 0, sizeof(my_main_controller));
454
4.19k
  cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
455
4.19k
  main_ptr->pub.start_pass = start_pass_main;
456
457
4.19k
  if (need_full_buffer)         /* shouldn't happen */
458
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
459
460
  /* Allocate the workspace.
461
   * ngroups is the number of row groups we need.
462
   */
463
4.19k
  if (cinfo->upsample->need_context_rows) {
464
479
    if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */
465
0
      ERREXIT(cinfo, JERR_NOTIMPL);
466
479
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
467
479
    ngroups = cinfo->_min_DCT_scaled_size + 2;
468
3.71k
  } else {
469
3.71k
    ngroups = cinfo->_min_DCT_scaled_size;
470
3.71k
  }
471
472
10.8k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
473
6.60k
       ci++, compptr++) {
474
6.60k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
475
6.60k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
476
6.60k
    main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
477
6.60k
                        ((j_common_ptr)cinfo, JPOOL_IMAGE,
478
6.60k
                         compptr->width_in_blocks * compptr->_DCT_scaled_size,
479
6.60k
                         (JDIMENSION)(rgroup * ngroups));
480
6.60k
  }
481
4.19k
}
j12init_d_main_controller
Line
Count
Source
429
1.25k
{
430
1.25k
  my_main_ptr main_ptr;
431
1.25k
  int ci, rgroup, ngroups;
432
1.25k
  jpeg_component_info *compptr;
433
434
1.25k
#ifdef D_LOSSLESS_SUPPORTED
435
1.25k
  if (cinfo->master->lossless) {
436
#if BITS_IN_JSAMPLE == 8
437
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
438
#else
439
859
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
440
859
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
441
0
#endif
442
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
443
859
  } else
444
396
#endif
445
396
  {
446
396
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
447
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
448
396
  }
449
450
1.25k
  main_ptr = (my_main_ptr)
451
1.25k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
452
1.25k
                                sizeof(my_main_controller));
453
1.25k
  memset(main_ptr, 0, sizeof(my_main_controller));
454
1.25k
  cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
455
1.25k
  main_ptr->pub.start_pass = start_pass_main;
456
457
1.25k
  if (need_full_buffer)         /* shouldn't happen */
458
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
459
460
  /* Allocate the workspace.
461
   * ngroups is the number of row groups we need.
462
   */
463
1.25k
  if (cinfo->upsample->need_context_rows) {
464
83
    if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */
465
0
      ERREXIT(cinfo, JERR_NOTIMPL);
466
83
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
467
83
    ngroups = cinfo->_min_DCT_scaled_size + 2;
468
1.17k
  } else {
469
1.17k
    ngroups = cinfo->_min_DCT_scaled_size;
470
1.17k
  }
471
472
4.63k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
473
3.38k
       ci++, compptr++) {
474
3.38k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
475
3.38k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
476
3.38k
    main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
477
3.38k
                        ((j_common_ptr)cinfo, JPOOL_IMAGE,
478
3.38k
                         compptr->width_in_blocks * compptr->_DCT_scaled_size,
479
3.38k
                         (JDIMENSION)(rgroup * ngroups));
480
3.38k
  }
481
1.25k
}
j16init_d_main_controller
Line
Count
Source
429
902
{
430
902
  my_main_ptr main_ptr;
431
902
  int ci, rgroup, ngroups;
432
902
  jpeg_component_info *compptr;
433
434
902
#ifdef D_LOSSLESS_SUPPORTED
435
902
  if (cinfo->master->lossless) {
436
#if BITS_IN_JSAMPLE == 8
437
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
438
#else
439
902
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
440
902
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
441
0
#endif
442
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
443
902
  } else
444
0
#endif
445
0
  {
446
0
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
447
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
448
0
  }
449
450
902
  main_ptr = (my_main_ptr)
451
902
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
452
902
                                sizeof(my_main_controller));
453
902
  memset(main_ptr, 0, sizeof(my_main_controller));
454
902
  cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
455
902
  main_ptr->pub.start_pass = start_pass_main;
456
457
902
  if (need_full_buffer)         /* shouldn't happen */
458
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
459
460
  /* Allocate the workspace.
461
   * ngroups is the number of row groups we need.
462
   */
463
902
  if (cinfo->upsample->need_context_rows) {
464
0
    if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */
465
0
      ERREXIT(cinfo, JERR_NOTIMPL);
466
0
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
467
0
    ngroups = cinfo->_min_DCT_scaled_size + 2;
468
902
  } else {
469
902
    ngroups = cinfo->_min_DCT_scaled_size;
470
902
  }
471
472
3.59k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
473
2.69k
       ci++, compptr++) {
474
2.69k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
475
2.69k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
476
2.69k
    main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
477
2.69k
                        ((j_common_ptr)cinfo, JPOOL_IMAGE,
478
2.69k
                         compptr->width_in_blocks * compptr->_DCT_scaled_size,
479
2.69k
                         (JDIMENSION)(rgroup * ngroups));
480
2.69k
  }
481
902
}
482
483
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */