Coverage Report

Created: 2026-06-30 07:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo/src/jdmainct.c
Line
Count
Source
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, 2026, 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 rows of each component
40
 * from each 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
19.2k
{
140
19.2k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
141
19.2k
  int ci, rgroup;
142
19.2k
  int M = cinfo->_min_DCT_scaled_size;
143
19.2k
  jpeg_component_info *compptr;
144
19.2k
  _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
19.2k
  main_ptr->xbuffer[0] = (_JSAMPIMAGE)
150
19.2k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
151
19.2k
                                cinfo->num_components * 2 *
152
19.2k
                                sizeof(_JSAMPARRAY));
153
19.2k
  main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
154
155
90.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
156
70.8k
       ci++, compptr++) {
157
70.8k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
158
70.8k
      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
70.8k
    xbuf = (_JSAMPARRAY)
163
70.8k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
164
70.8k
                                  2 * (rgroup * (M + 4)) * sizeof(_JSAMPROW));
165
70.8k
    xbuf += rgroup;             /* want one row group at negative offsets */
166
70.8k
    main_ptr->xbuffer[0][ci] = xbuf;
167
70.8k
    xbuf += rgroup * (M + 4);
168
70.8k
    main_ptr->xbuffer[1][ci] = xbuf;
169
70.8k
  }
170
19.2k
}
jdmainct-8.c:alloc_funny_pointers
Line
Count
Source
139
10.5k
{
140
10.5k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
141
10.5k
  int ci, rgroup;
142
10.5k
  int M = cinfo->_min_DCT_scaled_size;
143
10.5k
  jpeg_component_info *compptr;
144
10.5k
  _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
10.5k
  main_ptr->xbuffer[0] = (_JSAMPIMAGE)
150
10.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
151
10.5k
                                cinfo->num_components * 2 *
152
10.5k
                                sizeof(_JSAMPARRAY));
153
10.5k
  main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
154
155
49.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
156
38.5k
       ci++, compptr++) {
157
38.5k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
158
38.5k
      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
38.5k
    xbuf = (_JSAMPARRAY)
163
38.5k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
164
38.5k
                                  2 * (rgroup * (M + 4)) * sizeof(_JSAMPROW));
165
38.5k
    xbuf += rgroup;             /* want one row group at negative offsets */
166
38.5k
    main_ptr->xbuffer[0][ci] = xbuf;
167
38.5k
    xbuf += rgroup * (M + 4);
168
38.5k
    main_ptr->xbuffer[1][ci] = xbuf;
169
38.5k
  }
170
10.5k
}
jdmainct-12.c:alloc_funny_pointers
Line
Count
Source
139
8.64k
{
140
8.64k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
141
8.64k
  int ci, rgroup;
142
8.64k
  int M = cinfo->_min_DCT_scaled_size;
143
8.64k
  jpeg_component_info *compptr;
144
8.64k
  _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
8.64k
  main_ptr->xbuffer[0] = (_JSAMPIMAGE)
150
8.64k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
151
8.64k
                                cinfo->num_components * 2 *
152
8.64k
                                sizeof(_JSAMPARRAY));
153
8.64k
  main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
154
155
40.8k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
156
32.2k
       ci++, compptr++) {
157
32.2k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
158
32.2k
      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
32.2k
    xbuf = (_JSAMPARRAY)
163
32.2k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
164
32.2k
                                  2 * (rgroup * (M + 4)) * sizeof(_JSAMPROW));
165
32.2k
    xbuf += rgroup;             /* want one row group at negative offsets */
166
32.2k
    main_ptr->xbuffer[0][ci] = xbuf;
167
32.2k
    xbuf += rgroup * (M + 4);
168
32.2k
    main_ptr->xbuffer[1][ci] = xbuf;
169
32.2k
  }
170
8.64k
}
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
16.3k
{
182
16.3k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
183
16.3k
  int ci, i, rgroup;
184
16.3k
  int M = cinfo->_min_DCT_scaled_size;
185
16.3k
  jpeg_component_info *compptr;
186
16.3k
  _JSAMPARRAY buf, xbuf0, xbuf1;
187
188
74.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
189
57.9k
       ci++, compptr++) {
190
57.9k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
191
57.9k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
192
57.9k
    xbuf0 = main_ptr->xbuffer[0][ci];
193
57.9k
    xbuf1 = main_ptr->xbuffer[1][ci];
194
    /* First copy the workspace pointers as-is */
195
57.9k
    buf = main_ptr->buffer[ci];
196
1.10M
    for (i = 0; i < rgroup * (M + 2); i++) {
197
1.04M
      xbuf0[i] = xbuf1[i] = buf[i];
198
1.04M
    }
199
    /* In the second list, put the last four row groups in swapped order */
200
266k
    for (i = 0; i < rgroup * 2; i++) {
201
208k
      xbuf1[rgroup * (M - 2) + i] = buf[rgroup * M + i];
202
208k
      xbuf1[rgroup * M + i] = buf[rgroup * (M - 2) + i];
203
208k
    }
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
162k
    for (i = 0; i < rgroup; i++) {
210
104k
      xbuf0[i - rgroup] = xbuf0[0];
211
104k
    }
212
57.9k
  }
213
16.3k
}
jdmainct-8.c:make_funny_pointers
Line
Count
Source
181
8.81k
{
182
8.81k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
183
8.81k
  int ci, i, rgroup;
184
8.81k
  int M = cinfo->_min_DCT_scaled_size;
185
8.81k
  jpeg_component_info *compptr;
186
8.81k
  _JSAMPARRAY buf, xbuf0, xbuf1;
187
188
40.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
189
31.4k
       ci++, compptr++) {
190
31.4k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
191
31.4k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
192
31.4k
    xbuf0 = main_ptr->xbuffer[0][ci];
193
31.4k
    xbuf1 = main_ptr->xbuffer[1][ci];
194
    /* First copy the workspace pointers as-is */
195
31.4k
    buf = main_ptr->buffer[ci];
196
613k
    for (i = 0; i < rgroup * (M + 2); i++) {
197
582k
      xbuf0[i] = xbuf1[i] = buf[i];
198
582k
    }
199
    /* In the second list, put the last four row groups in swapped order */
200
147k
    for (i = 0; i < rgroup * 2; i++) {
201
116k
      xbuf1[rgroup * (M - 2) + i] = buf[rgroup * M + i];
202
116k
      xbuf1[rgroup * M + i] = buf[rgroup * (M - 2) + i];
203
116k
    }
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
89.6k
    for (i = 0; i < rgroup; i++) {
210
58.2k
      xbuf0[i - rgroup] = xbuf0[0];
211
58.2k
    }
212
31.4k
  }
213
8.81k
}
jdmainct-12.c:make_funny_pointers
Line
Count
Source
181
7.48k
{
182
7.48k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
183
7.48k
  int ci, i, rgroup;
184
7.48k
  int M = cinfo->_min_DCT_scaled_size;
185
7.48k
  jpeg_component_info *compptr;
186
7.48k
  _JSAMPARRAY buf, xbuf0, xbuf1;
187
188
33.9k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
189
26.4k
       ci++, compptr++) {
190
26.4k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
191
26.4k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
192
26.4k
    xbuf0 = main_ptr->xbuffer[0][ci];
193
26.4k
    xbuf1 = main_ptr->xbuffer[1][ci];
194
    /* First copy the workspace pointers as-is */
195
26.4k
    buf = main_ptr->buffer[ci];
196
486k
    for (i = 0; i < rgroup * (M + 2); i++) {
197
460k
      xbuf0[i] = xbuf1[i] = buf[i];
198
460k
    }
199
    /* In the second list, put the last four row groups in swapped order */
200
118k
    for (i = 0; i < rgroup * 2; i++) {
201
92.0k
      xbuf1[rgroup * (M - 2) + i] = buf[rgroup * M + i];
202
92.0k
      xbuf1[rgroup * M + i] = buf[rgroup * (M - 2) + i];
203
92.0k
    }
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
72.5k
    for (i = 0; i < rgroup; i++) {
210
46.0k
      xbuf0[i - rgroup] = xbuf0[0];
211
46.0k
    }
212
26.4k
  }
213
7.48k
}
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
15.2k
{
223
15.2k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
224
15.2k
  int ci, i, rgroup, iMCUheight, rows_left;
225
15.2k
  jpeg_component_info *compptr;
226
15.2k
  _JSAMPARRAY xbuf;
227
228
65.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
229
50.5k
       ci++, compptr++) {
230
    /* Count sample rows in one iMCU row and in one row group */
231
50.5k
    iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size;
232
50.5k
    rgroup = iMCUheight / cinfo->_min_DCT_scaled_size;
233
    /* Count nondummy sample rows remaining for this component */
234
50.5k
    rows_left = (int)(compptr->downsampled_height % (JDIMENSION)iMCUheight);
235
50.5k
    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
50.5k
    if (ci == 0) {
240
15.2k
      main_ptr->rowgroups_avail = (JDIMENSION)((rows_left - 1) / rgroup + 1);
241
15.2k
    }
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
50.5k
    xbuf = main_ptr->xbuffer[main_ptr->whichptr][ci];
246
229k
    for (i = 0; i < rgroup * 2; i++) {
247
179k
      xbuf[rows_left + i] = xbuf[rows_left - 1];
248
179k
    }
249
50.5k
  }
250
15.2k
}
jdmainct-8.c:set_bottom_pointers
Line
Count
Source
222
8.22k
{
223
8.22k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
224
8.22k
  int ci, i, rgroup, iMCUheight, rows_left;
225
8.22k
  jpeg_component_info *compptr;
226
8.22k
  _JSAMPARRAY xbuf;
227
228
35.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
229
27.5k
       ci++, compptr++) {
230
    /* Count sample rows in one iMCU row and in one row group */
231
27.5k
    iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size;
232
27.5k
    rgroup = iMCUheight / cinfo->_min_DCT_scaled_size;
233
    /* Count nondummy sample rows remaining for this component */
234
27.5k
    rows_left = (int)(compptr->downsampled_height % (JDIMENSION)iMCUheight);
235
27.5k
    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
27.5k
    if (ci == 0) {
240
8.22k
      main_ptr->rowgroups_avail = (JDIMENSION)((rows_left - 1) / rgroup + 1);
241
8.22k
    }
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
27.5k
    xbuf = main_ptr->xbuffer[main_ptr->whichptr][ci];
246
128k
    for (i = 0; i < rgroup * 2; i++) {
247
100k
      xbuf[rows_left + i] = xbuf[rows_left - 1];
248
100k
    }
249
27.5k
  }
250
8.22k
}
jdmainct-12.c:set_bottom_pointers
Line
Count
Source
222
7.01k
{
223
7.01k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
224
7.01k
  int ci, i, rgroup, iMCUheight, rows_left;
225
7.01k
  jpeg_component_info *compptr;
226
7.01k
  _JSAMPARRAY xbuf;
227
228
30.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
229
23.0k
       ci++, compptr++) {
230
    /* Count sample rows in one iMCU row and in one row group */
231
23.0k
    iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size;
232
23.0k
    rgroup = iMCUheight / cinfo->_min_DCT_scaled_size;
233
    /* Count nondummy sample rows remaining for this component */
234
23.0k
    rows_left = (int)(compptr->downsampled_height % (JDIMENSION)iMCUheight);
235
23.0k
    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
23.0k
    if (ci == 0) {
240
7.01k
      main_ptr->rowgroups_avail = (JDIMENSION)((rows_left - 1) / rgroup + 1);
241
7.01k
    }
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
23.0k
    xbuf = main_ptr->xbuffer[main_ptr->whichptr][ci];
246
101k
    for (i = 0; i < rgroup * 2; i++) {
247
78.2k
      xbuf[rows_left + i] = xbuf[rows_left - 1];
248
78.2k
    }
249
23.0k
  }
250
7.01k
}
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
100k
{
260
100k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
261
262
100k
  switch (pass_mode) {
263
100k
  case JBUF_PASS_THRU:
264
100k
    if (cinfo->upsample->need_context_rows) {
265
16.3k
      main_ptr->pub._process_data = process_data_context_main;
266
16.3k
      make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
267
16.3k
      main_ptr->whichptr = 0;   /* Read first iMCU row into xbuffer[0] */
268
16.3k
      main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
269
16.3k
      main_ptr->iMCU_row_ctr = 0;
270
83.7k
    } else {
271
      /* Simple case with no context needed */
272
83.7k
      main_ptr->pub._process_data = process_data_simple_main;
273
83.7k
    }
274
100k
    main_ptr->buffer_full = FALSE;      /* Mark buffer empty */
275
100k
    main_ptr->rowgroup_ctr = 0;
276
100k
    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
100k
  }
287
100k
}
jdmainct-8.c:start_pass_main
Line
Count
Source
259
68.7k
{
260
68.7k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
261
262
68.7k
  switch (pass_mode) {
263
68.7k
  case JBUF_PASS_THRU:
264
68.7k
    if (cinfo->upsample->need_context_rows) {
265
8.81k
      main_ptr->pub._process_data = process_data_context_main;
266
8.81k
      make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
267
8.81k
      main_ptr->whichptr = 0;   /* Read first iMCU row into xbuffer[0] */
268
8.81k
      main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
269
8.81k
      main_ptr->iMCU_row_ctr = 0;
270
59.9k
    } else {
271
      /* Simple case with no context needed */
272
59.9k
      main_ptr->pub._process_data = process_data_simple_main;
273
59.9k
    }
274
68.7k
    main_ptr->buffer_full = FALSE;      /* Mark buffer empty */
275
68.7k
    main_ptr->rowgroup_ctr = 0;
276
68.7k
    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
68.7k
  }
287
68.7k
}
jdmainct-12.c:start_pass_main
Line
Count
Source
259
25.4k
{
260
25.4k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
261
262
25.4k
  switch (pass_mode) {
263
25.4k
  case JBUF_PASS_THRU:
264
25.4k
    if (cinfo->upsample->need_context_rows) {
265
7.48k
      main_ptr->pub._process_data = process_data_context_main;
266
7.48k
      make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
267
7.48k
      main_ptr->whichptr = 0;   /* Read first iMCU row into xbuffer[0] */
268
7.48k
      main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
269
7.48k
      main_ptr->iMCU_row_ctr = 0;
270
17.9k
    } else {
271
      /* Simple case with no context needed */
272
17.9k
      main_ptr->pub._process_data = process_data_simple_main;
273
17.9k
    }
274
25.4k
    main_ptr->buffer_full = FALSE;      /* Mark buffer empty */
275
25.4k
    main_ptr->rowgroup_ctr = 0;
276
25.4k
    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
25.4k
  }
287
25.4k
}
jdmainct-16.c:start_pass_main
Line
Count
Source
259
5.87k
{
260
5.87k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
261
262
5.87k
  switch (pass_mode) {
263
5.87k
  case JBUF_PASS_THRU:
264
5.87k
    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
5.87k
    } else {
271
      /* Simple case with no context needed */
272
5.87k
      main_ptr->pub._process_data = process_data_simple_main;
273
5.87k
    }
274
5.87k
    main_ptr->buffer_full = FALSE;      /* Mark buffer empty */
275
5.87k
    main_ptr->rowgroup_ctr = 0;
276
5.87k
    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
5.87k
  }
287
5.87k
}
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
26.5M
{
299
26.5M
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
300
26.5M
  JDIMENSION rowgroups_avail;
301
302
  /* Read input data if we haven't filled the main buffer yet */
303
26.5M
  if (!main_ptr->buffer_full) {
304
3.21M
    if (!(*cinfo->coef->_decompress_data) (cinfo, main_ptr->buffer))
305
0
      return;                   /* suspension forced, can do nothing more */
306
3.21M
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
307
3.21M
  }
308
309
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
310
26.5M
  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
26.5M
  (*cinfo->post->_post_process_data) (cinfo, main_ptr->buffer,
318
26.5M
                                      &main_ptr->rowgroup_ctr, rowgroups_avail,
319
26.5M
                                      output_buf, out_row_ctr, out_rows_avail);
320
321
  /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
322
26.5M
  if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
323
3.14M
    main_ptr->buffer_full = FALSE;
324
3.14M
    main_ptr->rowgroup_ctr = 0;
325
3.14M
  }
326
26.5M
}
jdmainct-8.c:process_data_simple_main
Line
Count
Source
298
18.3M
{
299
18.3M
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
300
18.3M
  JDIMENSION rowgroups_avail;
301
302
  /* Read input data if we haven't filled the main buffer yet */
303
18.3M
  if (!main_ptr->buffer_full) {
304
1.91M
    if (!(*cinfo->coef->_decompress_data) (cinfo, main_ptr->buffer))
305
0
      return;                   /* suspension forced, can do nothing more */
306
1.91M
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
307
1.91M
  }
308
309
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
310
18.3M
  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
18.3M
  (*cinfo->post->_post_process_data) (cinfo, main_ptr->buffer,
318
18.3M
                                      &main_ptr->rowgroup_ctr, rowgroups_avail,
319
18.3M
                                      output_buf, out_row_ctr, out_rows_avail);
320
321
  /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
322
18.3M
  if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
323
1.86M
    main_ptr->buffer_full = FALSE;
324
1.86M
    main_ptr->rowgroup_ctr = 0;
325
1.86M
  }
326
18.3M
}
jdmainct-12.c:process_data_simple_main
Line
Count
Source
298
7.42M
{
299
7.42M
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
300
7.42M
  JDIMENSION rowgroups_avail;
301
302
  /* Read input data if we haven't filled the main buffer yet */
303
7.42M
  if (!main_ptr->buffer_full) {
304
926k
    if (!(*cinfo->coef->_decompress_data) (cinfo, main_ptr->buffer))
305
0
      return;                   /* suspension forced, can do nothing more */
306
926k
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
307
926k
  }
308
309
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
310
7.42M
  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
7.42M
  (*cinfo->post->_post_process_data) (cinfo, main_ptr->buffer,
318
7.42M
                                      &main_ptr->rowgroup_ctr, rowgroups_avail,
319
7.42M
                                      output_buf, out_row_ctr, out_rows_avail);
320
321
  /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
322
7.42M
  if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
323
910k
    main_ptr->buffer_full = FALSE;
324
910k
    main_ptr->rowgroup_ctr = 0;
325
910k
  }
326
7.42M
}
jdmainct-16.c:process_data_simple_main
Line
Count
Source
298
791k
{
299
791k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
300
791k
  JDIMENSION rowgroups_avail;
301
302
  /* Read input data if we haven't filled the main buffer yet */
303
791k
  if (!main_ptr->buffer_full) {
304
373k
    if (!(*cinfo->coef->_decompress_data) (cinfo, main_ptr->buffer))
305
0
      return;                   /* suspension forced, can do nothing more */
306
373k
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
307
373k
  }
308
309
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
310
791k
  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
791k
  (*cinfo->post->_post_process_data) (cinfo, main_ptr->buffer,
318
791k
                                      &main_ptr->rowgroup_ctr, rowgroups_avail,
319
791k
                                      output_buf, out_row_ctr, out_rows_avail);
320
321
  /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
322
791k
  if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
323
369k
    main_ptr->buffer_full = FALSE;
324
369k
    main_ptr->rowgroup_ctr = 0;
325
369k
  }
326
791k
}
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
6.21M
{
338
6.21M
  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
6.21M
  if (!main_ptr->buffer_full) {
342
314k
    if (!(*cinfo->coef->_decompress_data) (cinfo,
343
314k
                                           main_ptr->xbuffer[main_ptr->whichptr]))
344
0
      return;                   /* suspension forced, can do nothing more */
345
314k
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
346
314k
    main_ptr->iMCU_row_ctr++;   /* count rows received */
347
314k
  }
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
6.21M
  switch (main_ptr->context_state) {
355
756k
  case CTX_POSTPONED_ROW:
356
    /* Call postprocessor using previously set pointers for postponed row */
357
756k
    (*cinfo->post->_post_process_data) (cinfo,
358
756k
                                        main_ptr->xbuffer[main_ptr->whichptr],
359
756k
                                        &main_ptr->rowgroup_ctr,
360
756k
                                        main_ptr->rowgroups_avail, output_buf,
361
756k
                                        out_row_ctr, out_rows_avail);
362
756k
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
363
457k
      return;                   /* Need to suspend */
364
298k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
365
298k
    if (*out_row_ctr >= out_rows_avail)
366
298k
      return;                   /* Postprocessor exactly filled output buf */
367
0
    FALLTHROUGH                 /*FALLTHROUGH*/
368
314k
  case CTX_PREPARE_FOR_IMCU:
369
    /* Prepare to process first M-1 row groups of this iMCU row */
370
314k
    main_ptr->rowgroup_ctr = 0;
371
314k
    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
314k
    if (main_ptr->iMCU_row_ctr == cinfo->total_iMCU_rows)
376
15.2k
      set_bottom_pointers(cinfo);
377
314k
    main_ptr->context_state = CTX_PROCESS_IMCU;
378
314k
    FALLTHROUGH                 /*FALLTHROUGH*/
379
5.46M
  case CTX_PROCESS_IMCU:
380
    /* Call postprocessor using previously set pointers */
381
5.46M
    (*cinfo->post->_post_process_data) (cinfo,
382
5.46M
                                        main_ptr->xbuffer[main_ptr->whichptr],
383
5.46M
                                        &main_ptr->rowgroup_ctr,
384
5.46M
                                        main_ptr->rowgroups_avail, output_buf,
385
5.46M
                                        out_row_ctr, out_rows_avail);
386
5.46M
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
387
5.15M
      return;                   /* Need to suspend */
388
    /* After the first iMCU, change wraparound pointers to normal state */
389
306k
    if (main_ptr->iMCU_row_ctr == 1)
390
13.5k
      set_wraparound_pointers(cinfo);
391
    /* Prepare to load new iMCU row using other xbuffer list */
392
306k
    main_ptr->whichptr ^= 1;    /* 0=>1 or 1=>0 */
393
306k
    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
306k
    main_ptr->rowgroup_ctr = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 1);
397
306k
    main_ptr->rowgroups_avail = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 2);
398
306k
    main_ptr->context_state = CTX_POSTPONED_ROW;
399
6.21M
  }
400
6.21M
}
jdmainct-8.c:process_data_context_main
Line
Count
Source
337
4.09M
{
338
4.09M
  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
4.09M
  if (!main_ptr->buffer_full) {
342
195k
    if (!(*cinfo->coef->_decompress_data) (cinfo,
343
195k
                                           main_ptr->xbuffer[main_ptr->whichptr]))
344
0
      return;                   /* suspension forced, can do nothing more */
345
195k
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
346
195k
    main_ptr->iMCU_row_ctr++;   /* count rows received */
347
195k
  }
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
4.09M
  switch (main_ptr->context_state) {
355
500k
  case CTX_POSTPONED_ROW:
356
    /* Call postprocessor using previously set pointers for postponed row */
357
500k
    (*cinfo->post->_post_process_data) (cinfo,
358
500k
                                        main_ptr->xbuffer[main_ptr->whichptr],
359
500k
                                        &main_ptr->rowgroup_ctr,
360
500k
                                        main_ptr->rowgroups_avail, output_buf,
361
500k
                                        out_row_ctr, out_rows_avail);
362
500k
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
363
313k
      return;                   /* Need to suspend */
364
187k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
365
187k
    if (*out_row_ctr >= out_rows_avail)
366
187k
      return;                   /* Postprocessor exactly filled output buf */
367
0
    FALLTHROUGH                 /*FALLTHROUGH*/
368
195k
  case CTX_PREPARE_FOR_IMCU:
369
    /* Prepare to process first M-1 row groups of this iMCU row */
370
195k
    main_ptr->rowgroup_ctr = 0;
371
195k
    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
195k
    if (main_ptr->iMCU_row_ctr == cinfo->total_iMCU_rows)
376
8.22k
      set_bottom_pointers(cinfo);
377
195k
    main_ptr->context_state = CTX_PROCESS_IMCU;
378
195k
    FALLTHROUGH                 /*FALLTHROUGH*/
379
3.59M
  case CTX_PROCESS_IMCU:
380
    /* Call postprocessor using previously set pointers */
381
3.59M
    (*cinfo->post->_post_process_data) (cinfo,
382
3.59M
                                        main_ptr->xbuffer[main_ptr->whichptr],
383
3.59M
                                        &main_ptr->rowgroup_ctr,
384
3.59M
                                        main_ptr->rowgroups_avail, output_buf,
385
3.59M
                                        out_row_ctr, out_rows_avail);
386
3.59M
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
387
3.40M
      return;                   /* Need to suspend */
388
    /* After the first iMCU, change wraparound pointers to normal state */
389
191k
    if (main_ptr->iMCU_row_ctr == 1)
390
7.12k
      set_wraparound_pointers(cinfo);
391
    /* Prepare to load new iMCU row using other xbuffer list */
392
191k
    main_ptr->whichptr ^= 1;    /* 0=>1 or 1=>0 */
393
191k
    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
191k
    main_ptr->rowgroup_ctr = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 1);
397
191k
    main_ptr->rowgroups_avail = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 2);
398
191k
    main_ptr->context_state = CTX_POSTPONED_ROW;
399
4.09M
  }
400
4.09M
}
jdmainct-12.c:process_data_context_main
Line
Count
Source
337
2.12M
{
338
2.12M
  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
2.12M
  if (!main_ptr->buffer_full) {
342
118k
    if (!(*cinfo->coef->_decompress_data) (cinfo,
343
118k
                                           main_ptr->xbuffer[main_ptr->whichptr]))
344
0
      return;                   /* suspension forced, can do nothing more */
345
118k
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
346
118k
    main_ptr->iMCU_row_ctr++;   /* count rows received */
347
118k
  }
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
2.12M
  switch (main_ptr->context_state) {
355
256k
  case CTX_POSTPONED_ROW:
356
    /* Call postprocessor using previously set pointers for postponed row */
357
256k
    (*cinfo->post->_post_process_data) (cinfo,
358
256k
                                        main_ptr->xbuffer[main_ptr->whichptr],
359
256k
                                        &main_ptr->rowgroup_ctr,
360
256k
                                        main_ptr->rowgroups_avail, output_buf,
361
256k
                                        out_row_ctr, out_rows_avail);
362
256k
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
363
144k
      return;                   /* Need to suspend */
364
111k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
365
111k
    if (*out_row_ctr >= out_rows_avail)
366
111k
      return;                   /* Postprocessor exactly filled output buf */
367
0
    FALLTHROUGH                 /*FALLTHROUGH*/
368
118k
  case CTX_PREPARE_FOR_IMCU:
369
    /* Prepare to process first M-1 row groups of this iMCU row */
370
118k
    main_ptr->rowgroup_ctr = 0;
371
118k
    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
118k
    if (main_ptr->iMCU_row_ctr == cinfo->total_iMCU_rows)
376
7.01k
      set_bottom_pointers(cinfo);
377
118k
    main_ptr->context_state = CTX_PROCESS_IMCU;
378
118k
    FALLTHROUGH                 /*FALLTHROUGH*/
379
1.86M
  case CTX_PROCESS_IMCU:
380
    /* Call postprocessor using previously set pointers */
381
1.86M
    (*cinfo->post->_post_process_data) (cinfo,
382
1.86M
                                        main_ptr->xbuffer[main_ptr->whichptr],
383
1.86M
                                        &main_ptr->rowgroup_ctr,
384
1.86M
                                        main_ptr->rowgroups_avail, output_buf,
385
1.86M
                                        out_row_ctr, out_rows_avail);
386
1.86M
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
387
1.75M
      return;                   /* Need to suspend */
388
    /* After the first iMCU, change wraparound pointers to normal state */
389
115k
    if (main_ptr->iMCU_row_ctr == 1)
390
6.45k
      set_wraparound_pointers(cinfo);
391
    /* Prepare to load new iMCU row using other xbuffer list */
392
115k
    main_ptr->whichptr ^= 1;    /* 0=>1 or 1=>0 */
393
115k
    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
115k
    main_ptr->rowgroup_ctr = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 1);
397
115k
    main_ptr->rowgroups_avail = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 2);
398
115k
    main_ptr->context_state = CTX_POSTPONED_ROW;
399
2.12M
  }
400
2.12M
}
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
116k
{
430
116k
  my_main_ptr main_ptr;
431
116k
  int ci, rgroup, ngroups;
432
116k
  jpeg_component_info *compptr;
433
434
116k
#ifdef D_LOSSLESS_SUPPORTED
435
116k
  if (cinfo->master->lossless) {
436
#if BITS_IN_JSAMPLE == 8
437
8.33k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
438
#else
439
15.4k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
440
15.4k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
441
0
#endif
442
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
443
23.7k
  } else
444
92.6k
#endif
445
92.6k
  {
446
92.6k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
447
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
448
92.6k
  }
449
450
116k
  main_ptr = (my_main_ptr)
451
116k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
452
116k
                                sizeof(my_main_controller));
453
116k
  memset(main_ptr, 0, sizeof(my_main_controller));
454
116k
  cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
455
116k
  main_ptr->pub.start_pass = start_pass_main;
456
457
116k
  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
116k
  if (cinfo->upsample->need_context_rows) {
464
19.2k
    if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */
465
0
      ERREXIT(cinfo, JERR_NOTIMPL);
466
19.2k
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
467
19.2k
    ngroups = cinfo->_min_DCT_scaled_size + 2;
468
97.1k
  } else {
469
97.1k
    ngroups = cinfo->_min_DCT_scaled_size;
470
97.1k
  }
471
472
395k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
473
278k
       ci++, compptr++) {
474
278k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
475
278k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
476
278k
    main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
477
278k
                        ((j_common_ptr)cinfo, JPOOL_IMAGE,
478
278k
                         compptr->width_in_blocks * compptr->_DCT_scaled_size,
479
278k
                         (JDIMENSION)(rgroup * ngroups));
480
278k
  }
481
116k
}
jinit_d_main_controller
Line
Count
Source
429
78.0k
{
430
78.0k
  my_main_ptr main_ptr;
431
78.0k
  int ci, rgroup, ngroups;
432
78.0k
  jpeg_component_info *compptr;
433
434
78.0k
#ifdef D_LOSSLESS_SUPPORTED
435
78.0k
  if (cinfo->master->lossless) {
436
8.33k
#if BITS_IN_JSAMPLE == 8
437
8.33k
    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
8.33k
  } else
444
69.7k
#endif
445
69.7k
  {
446
69.7k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
447
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
448
69.7k
  }
449
450
78.0k
  main_ptr = (my_main_ptr)
451
78.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
452
78.0k
                                sizeof(my_main_controller));
453
78.0k
  memset(main_ptr, 0, sizeof(my_main_controller));
454
78.0k
  cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
455
78.0k
  main_ptr->pub.start_pass = start_pass_main;
456
457
78.0k
  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
78.0k
  if (cinfo->upsample->need_context_rows) {
464
10.5k
    if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */
465
0
      ERREXIT(cinfo, JERR_NOTIMPL);
466
10.5k
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
467
10.5k
    ngroups = cinfo->_min_DCT_scaled_size + 2;
468
67.4k
  } else {
469
67.4k
    ngroups = cinfo->_min_DCT_scaled_size;
470
67.4k
  }
471
472
236k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
473
158k
       ci++, compptr++) {
474
158k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
475
158k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
476
158k
    main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
477
158k
                        ((j_common_ptr)cinfo, JPOOL_IMAGE,
478
158k
                         compptr->width_in_blocks * compptr->_DCT_scaled_size,
479
158k
                         (JDIMENSION)(rgroup * ngroups));
480
158k
  }
481
78.0k
}
j12init_d_main_controller
Line
Count
Source
429
30.2k
{
430
30.2k
  my_main_ptr main_ptr;
431
30.2k
  int ci, rgroup, ngroups;
432
30.2k
  jpeg_component_info *compptr;
433
434
30.2k
#ifdef D_LOSSLESS_SUPPORTED
435
30.2k
  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
7.37k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
440
7.37k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
441
0
#endif
442
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
443
7.37k
  } else
444
22.8k
#endif
445
22.8k
  {
446
22.8k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
447
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
448
22.8k
  }
449
450
30.2k
  main_ptr = (my_main_ptr)
451
30.2k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
452
30.2k
                                sizeof(my_main_controller));
453
30.2k
  memset(main_ptr, 0, sizeof(my_main_controller));
454
30.2k
  cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
455
30.2k
  main_ptr->pub.start_pass = start_pass_main;
456
457
30.2k
  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
30.2k
  if (cinfo->upsample->need_context_rows) {
464
8.64k
    if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */
465
0
      ERREXIT(cinfo, JERR_NOTIMPL);
466
8.64k
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
467
8.64k
    ngroups = cinfo->_min_DCT_scaled_size + 2;
468
21.6k
  } else {
469
21.6k
    ngroups = cinfo->_min_DCT_scaled_size;
470
21.6k
  }
471
472
118k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
473
88.0k
       ci++, compptr++) {
474
88.0k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
475
88.0k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
476
88.0k
    main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
477
88.0k
                        ((j_common_ptr)cinfo, JPOOL_IMAGE,
478
88.0k
                         compptr->width_in_blocks * compptr->_DCT_scaled_size,
479
88.0k
                         (JDIMENSION)(rgroup * ngroups));
480
88.0k
  }
481
30.2k
}
j16init_d_main_controller
Line
Count
Source
429
8.06k
{
430
8.06k
  my_main_ptr main_ptr;
431
8.06k
  int ci, rgroup, ngroups;
432
8.06k
  jpeg_component_info *compptr;
433
434
8.06k
#ifdef D_LOSSLESS_SUPPORTED
435
8.06k
  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
8.06k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
440
8.06k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
441
0
#endif
442
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
443
8.06k
  } 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
8.06k
  main_ptr = (my_main_ptr)
451
8.06k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
452
8.06k
                                sizeof(my_main_controller));
453
8.06k
  memset(main_ptr, 0, sizeof(my_main_controller));
454
8.06k
  cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
455
8.06k
  main_ptr->pub.start_pass = start_pass_main;
456
457
8.06k
  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
8.06k
  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
8.06k
  } else {
469
8.06k
    ngroups = cinfo->_min_DCT_scaled_size;
470
8.06k
  }
471
472
39.8k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
473
31.7k
       ci++, compptr++) {
474
31.7k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
475
31.7k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
476
31.7k
    main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
477
31.7k
                        ((j_common_ptr)cinfo, JPOOL_IMAGE,
478
31.7k
                         compptr->width_in_blocks * compptr->_DCT_scaled_size,
479
31.7k
                         (JDIMENSION)(rgroup * ngroups));
480
31.7k
  }
481
8.06k
}
482
483
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */