Coverage Report

Created: 2026-04-28 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/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
10.7k
{
140
10.7k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
141
10.7k
  int ci, rgroup;
142
10.7k
  int M = cinfo->_min_DCT_scaled_size;
143
10.7k
  jpeg_component_info *compptr;
144
10.7k
  _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.7k
  main_ptr->xbuffer[0] = (_JSAMPIMAGE)
150
10.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
151
10.7k
                                cinfo->num_components * 2 *
152
10.7k
                                sizeof(_JSAMPARRAY));
153
10.7k
  main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
154
155
43.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
156
32.9k
       ci++, compptr++) {
157
32.9k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
158
32.9k
      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.9k
    xbuf = (_JSAMPARRAY)
163
32.9k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
164
32.9k
                                  2 * (rgroup * (M + 4)) * sizeof(_JSAMPROW));
165
32.9k
    xbuf += rgroup;             /* want one row group at negative offsets */
166
32.9k
    main_ptr->xbuffer[0][ci] = xbuf;
167
32.9k
    xbuf += rgroup * (M + 4);
168
32.9k
    main_ptr->xbuffer[1][ci] = xbuf;
169
32.9k
  }
170
10.7k
}
jdmainct-8.c:alloc_funny_pointers
Line
Count
Source
139
9.45k
{
140
9.45k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
141
9.45k
  int ci, rgroup;
142
9.45k
  int M = cinfo->_min_DCT_scaled_size;
143
9.45k
  jpeg_component_info *compptr;
144
9.45k
  _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
9.45k
  main_ptr->xbuffer[0] = (_JSAMPIMAGE)
150
9.45k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
151
9.45k
                                cinfo->num_components * 2 *
152
9.45k
                                sizeof(_JSAMPARRAY));
153
9.45k
  main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
154
155
38.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
156
28.7k
       ci++, compptr++) {
157
28.7k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
158
28.7k
      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
28.7k
    xbuf = (_JSAMPARRAY)
163
28.7k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
164
28.7k
                                  2 * (rgroup * (M + 4)) * sizeof(_JSAMPROW));
165
28.7k
    xbuf += rgroup;             /* want one row group at negative offsets */
166
28.7k
    main_ptr->xbuffer[0][ci] = xbuf;
167
28.7k
    xbuf += rgroup * (M + 4);
168
28.7k
    main_ptr->xbuffer[1][ci] = xbuf;
169
28.7k
  }
170
9.45k
}
jdmainct-12.c:alloc_funny_pointers
Line
Count
Source
139
1.32k
{
140
1.32k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
141
1.32k
  int ci, rgroup;
142
1.32k
  int M = cinfo->_min_DCT_scaled_size;
143
1.32k
  jpeg_component_info *compptr;
144
1.32k
  _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
1.32k
  main_ptr->xbuffer[0] = (_JSAMPIMAGE)
150
1.32k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
151
1.32k
                                cinfo->num_components * 2 *
152
1.32k
                                sizeof(_JSAMPARRAY));
153
1.32k
  main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
154
155
5.56k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
156
4.23k
       ci++, compptr++) {
157
4.23k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
158
4.23k
      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
4.23k
    xbuf = (_JSAMPARRAY)
163
4.23k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
164
4.23k
                                  2 * (rgroup * (M + 4)) * sizeof(_JSAMPROW));
165
4.23k
    xbuf += rgroup;             /* want one row group at negative offsets */
166
4.23k
    main_ptr->xbuffer[0][ci] = xbuf;
167
4.23k
    xbuf += rgroup * (M + 4);
168
4.23k
    main_ptr->xbuffer[1][ci] = xbuf;
169
4.23k
  }
170
1.32k
}
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
27.3k
{
182
27.3k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
183
27.3k
  int ci, i, rgroup;
184
27.3k
  int M = cinfo->_min_DCT_scaled_size;
185
27.3k
  jpeg_component_info *compptr;
186
27.3k
  _JSAMPARRAY buf, xbuf0, xbuf1;
187
188
109k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
189
82.5k
       ci++, compptr++) {
190
82.5k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
191
82.5k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
192
82.5k
    xbuf0 = main_ptr->xbuffer[0][ci];
193
82.5k
    xbuf1 = main_ptr->xbuffer[1][ci];
194
    /* First copy the workspace pointers as-is */
195
82.5k
    buf = main_ptr->buffer[ci];
196
1.51M
    for (i = 0; i < rgroup * (M + 2); i++) {
197
1.42M
      xbuf0[i] = xbuf1[i] = buf[i];
198
1.42M
    }
199
    /* In the second list, put the last four row groups in swapped order */
200
371k
    for (i = 0; i < rgroup * 2; i++) {
201
288k
      xbuf1[rgroup * (M - 2) + i] = buf[rgroup * M + i];
202
288k
      xbuf1[rgroup * M + i] = buf[rgroup * (M - 2) + i];
203
288k
    }
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
227k
    for (i = 0; i < rgroup; i++) {
210
144k
      xbuf0[i - rgroup] = xbuf0[0];
211
144k
    }
212
82.5k
  }
213
27.3k
}
jdmainct-8.c:make_funny_pointers
Line
Count
Source
181
26.6k
{
182
26.6k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
183
26.6k
  int ci, i, rgroup;
184
26.6k
  int M = cinfo->_min_DCT_scaled_size;
185
26.6k
  jpeg_component_info *compptr;
186
26.6k
  _JSAMPARRAY buf, xbuf0, xbuf1;
187
188
107k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
189
80.3k
       ci++, compptr++) {
190
80.3k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
191
80.3k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
192
80.3k
    xbuf0 = main_ptr->xbuffer[0][ci];
193
80.3k
    xbuf1 = main_ptr->xbuffer[1][ci];
194
    /* First copy the workspace pointers as-is */
195
80.3k
    buf = main_ptr->buffer[ci];
196
1.47M
    for (i = 0; i < rgroup * (M + 2); i++) {
197
1.39M
      xbuf0[i] = xbuf1[i] = buf[i];
198
1.39M
    }
199
    /* In the second list, put the last four row groups in swapped order */
200
360k
    for (i = 0; i < rgroup * 2; i++) {
201
280k
      xbuf1[rgroup * (M - 2) + i] = buf[rgroup * M + i];
202
280k
      xbuf1[rgroup * M + i] = buf[rgroup * (M - 2) + i];
203
280k
    }
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
220k
    for (i = 0; i < rgroup; i++) {
210
140k
      xbuf0[i - rgroup] = xbuf0[0];
211
140k
    }
212
80.3k
  }
213
26.6k
}
jdmainct-12.c:make_funny_pointers
Line
Count
Source
181
696
{
182
696
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
183
696
  int ci, i, rgroup;
184
696
  int M = cinfo->_min_DCT_scaled_size;
185
696
  jpeg_component_info *compptr;
186
696
  _JSAMPARRAY buf, xbuf0, xbuf1;
187
188
2.93k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
189
2.23k
       ci++, compptr++) {
190
2.23k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
191
2.23k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
192
2.23k
    xbuf0 = main_ptr->xbuffer[0][ci];
193
2.23k
    xbuf1 = main_ptr->xbuffer[1][ci];
194
    /* First copy the workspace pointers as-is */
195
2.23k
    buf = main_ptr->buffer[ci];
196
37.3k
    for (i = 0; i < rgroup * (M + 2); i++) {
197
35.1k
      xbuf0[i] = xbuf1[i] = buf[i];
198
35.1k
    }
199
    /* In the second list, put the last four row groups in swapped order */
200
10.6k
    for (i = 0; i < rgroup * 2; i++) {
201
8.38k
      xbuf1[rgroup * (M - 2) + i] = buf[rgroup * M + i];
202
8.38k
      xbuf1[rgroup * M + i] = buf[rgroup * (M - 2) + i];
203
8.38k
    }
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
6.42k
    for (i = 0; i < rgroup; i++) {
210
4.19k
      xbuf0[i - rgroup] = xbuf0[0];
211
4.19k
    }
212
2.23k
  }
213
696
}
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
24.3k
{
223
24.3k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
224
24.3k
  int ci, i, rgroup, iMCUheight, rows_left;
225
24.3k
  jpeg_component_info *compptr;
226
24.3k
  _JSAMPARRAY xbuf;
227
228
97.5k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
229
73.2k
       ci++, compptr++) {
230
    /* Count sample rows in one iMCU row and in one row group */
231
73.2k
    iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size;
232
73.2k
    rgroup = iMCUheight / cinfo->_min_DCT_scaled_size;
233
    /* Count nondummy sample rows remaining for this component */
234
73.2k
    rows_left = (int)(compptr->downsampled_height % (JDIMENSION)iMCUheight);
235
73.2k
    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
73.2k
    if (ci == 0) {
240
24.3k
      main_ptr->rowgroups_avail = (JDIMENSION)((rows_left - 1) / rgroup + 1);
241
24.3k
    }
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
73.2k
    xbuf = main_ptr->xbuffer[main_ptr->whichptr][ci];
246
332k
    for (i = 0; i < rgroup * 2; i++) {
247
259k
      xbuf[rows_left + i] = xbuf[rows_left - 1];
248
259k
    }
249
73.2k
  }
250
24.3k
}
jdmainct-8.c:set_bottom_pointers
Line
Count
Source
222
23.7k
{
223
23.7k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
224
23.7k
  int ci, i, rgroup, iMCUheight, rows_left;
225
23.7k
  jpeg_component_info *compptr;
226
23.7k
  _JSAMPARRAY xbuf;
227
228
95.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
229
71.3k
       ci++, compptr++) {
230
    /* Count sample rows in one iMCU row and in one row group */
231
71.3k
    iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size;
232
71.3k
    rgroup = iMCUheight / cinfo->_min_DCT_scaled_size;
233
    /* Count nondummy sample rows remaining for this component */
234
71.3k
    rows_left = (int)(compptr->downsampled_height % (JDIMENSION)iMCUheight);
235
71.3k
    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
71.3k
    if (ci == 0) {
240
23.7k
      main_ptr->rowgroups_avail = (JDIMENSION)((rows_left - 1) / rgroup + 1);
241
23.7k
    }
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
71.3k
    xbuf = main_ptr->xbuffer[main_ptr->whichptr][ci];
246
323k
    for (i = 0; i < rgroup * 2; i++) {
247
251k
      xbuf[rows_left + i] = xbuf[rows_left - 1];
248
251k
    }
249
71.3k
  }
250
23.7k
}
jdmainct-12.c:set_bottom_pointers
Line
Count
Source
222
596
{
223
596
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
224
596
  int ci, i, rgroup, iMCUheight, rows_left;
225
596
  jpeg_component_info *compptr;
226
596
  _JSAMPARRAY xbuf;
227
228
2.46k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
229
1.86k
       ci++, compptr++) {
230
    /* Count sample rows in one iMCU row and in one row group */
231
1.86k
    iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size;
232
1.86k
    rgroup = iMCUheight / cinfo->_min_DCT_scaled_size;
233
    /* Count nondummy sample rows remaining for this component */
234
1.86k
    rows_left = (int)(compptr->downsampled_height % (JDIMENSION)iMCUheight);
235
1.86k
    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
1.86k
    if (ci == 0) {
240
596
      main_ptr->rowgroups_avail = (JDIMENSION)((rows_left - 1) / rgroup + 1);
241
596
    }
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
1.86k
    xbuf = main_ptr->xbuffer[main_ptr->whichptr][ci];
246
9.06k
    for (i = 0; i < rgroup * 2; i++) {
247
7.19k
      xbuf[rows_left + i] = xbuf[rows_left - 1];
248
7.19k
    }
249
1.86k
  }
250
596
}
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
107k
{
260
107k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
261
262
107k
  switch (pass_mode) {
263
103k
  case JBUF_PASS_THRU:
264
103k
    if (cinfo->upsample->need_context_rows) {
265
27.3k
      main_ptr->pub._process_data = process_data_context_main;
266
27.3k
      make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
267
27.3k
      main_ptr->whichptr = 0;   /* Read first iMCU row into xbuffer[0] */
268
27.3k
      main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
269
27.3k
      main_ptr->iMCU_row_ctr = 0;
270
75.7k
    } else {
271
      /* Simple case with no context needed */
272
75.7k
      main_ptr->pub._process_data = process_data_simple_main;
273
75.7k
    }
274
103k
    main_ptr->buffer_full = FALSE;      /* Mark buffer empty */
275
103k
    main_ptr->rowgroup_ctr = 0;
276
103k
    break;
277
0
#ifdef QUANT_2PASS_SUPPORTED
278
4.29k
  case JBUF_CRANK_DEST:
279
    /* For last pass of 2-pass quantization, just crank the postprocessor */
280
4.29k
    main_ptr->pub._process_data = process_data_crank_post;
281
4.29k
    break;
282
0
#endif
283
0
  default:
284
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
285
0
    break;
286
107k
  }
287
107k
}
jdmainct-8.c:start_pass_main
Line
Count
Source
259
88.8k
{
260
88.8k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
261
262
88.8k
  switch (pass_mode) {
263
84.5k
  case JBUF_PASS_THRU:
264
84.5k
    if (cinfo->upsample->need_context_rows) {
265
26.6k
      main_ptr->pub._process_data = process_data_context_main;
266
26.6k
      make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
267
26.6k
      main_ptr->whichptr = 0;   /* Read first iMCU row into xbuffer[0] */
268
26.6k
      main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
269
26.6k
      main_ptr->iMCU_row_ctr = 0;
270
57.8k
    } else {
271
      /* Simple case with no context needed */
272
57.8k
      main_ptr->pub._process_data = process_data_simple_main;
273
57.8k
    }
274
84.5k
    main_ptr->buffer_full = FALSE;      /* Mark buffer empty */
275
84.5k
    main_ptr->rowgroup_ctr = 0;
276
84.5k
    break;
277
0
#ifdef QUANT_2PASS_SUPPORTED
278
4.29k
  case JBUF_CRANK_DEST:
279
    /* For last pass of 2-pass quantization, just crank the postprocessor */
280
4.29k
    main_ptr->pub._process_data = process_data_crank_post;
281
4.29k
    break;
282
0
#endif
283
0
  default:
284
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
285
0
    break;
286
88.8k
  }
287
88.8k
}
jdmainct-12.c:start_pass_main
Line
Count
Source
259
15.3k
{
260
15.3k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
261
262
15.3k
  switch (pass_mode) {
263
15.3k
  case JBUF_PASS_THRU:
264
15.3k
    if (cinfo->upsample->need_context_rows) {
265
696
      main_ptr->pub._process_data = process_data_context_main;
266
696
      make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
267
696
      main_ptr->whichptr = 0;   /* Read first iMCU row into xbuffer[0] */
268
696
      main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
269
696
      main_ptr->iMCU_row_ctr = 0;
270
14.6k
    } else {
271
      /* Simple case with no context needed */
272
14.6k
      main_ptr->pub._process_data = process_data_simple_main;
273
14.6k
    }
274
15.3k
    main_ptr->buffer_full = FALSE;      /* Mark buffer empty */
275
15.3k
    main_ptr->rowgroup_ctr = 0;
276
15.3k
    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
15.3k
  }
287
15.3k
}
jdmainct-16.c:start_pass_main
Line
Count
Source
259
3.22k
{
260
3.22k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
261
262
3.22k
  switch (pass_mode) {
263
3.22k
  case JBUF_PASS_THRU:
264
3.22k
    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
3.22k
    } else {
271
      /* Simple case with no context needed */
272
3.22k
      main_ptr->pub._process_data = process_data_simple_main;
273
3.22k
    }
274
3.22k
    main_ptr->buffer_full = FALSE;      /* Mark buffer empty */
275
3.22k
    main_ptr->rowgroup_ctr = 0;
276
3.22k
    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
3.22k
  }
287
3.22k
}
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
259M
{
299
259M
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
300
259M
  JDIMENSION rowgroups_avail;
301
302
  /* Read input data if we haven't filled the main buffer yet */
303
259M
  if (!main_ptr->buffer_full) {
304
33.7M
    if (!(*cinfo->coef->_decompress_data) (cinfo, main_ptr->buffer))
305
2.03k
      return;                   /* suspension forced, can do nothing more */
306
33.7M
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
307
33.7M
  }
308
309
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
310
259M
  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
259M
  (*cinfo->post->_post_process_data) (cinfo, main_ptr->buffer,
318
259M
                                      &main_ptr->rowgroup_ctr, rowgroups_avail,
319
259M
                                      output_buf, out_row_ctr, out_rows_avail);
320
321
  /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
322
259M
  if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
323
33.7M
    main_ptr->buffer_full = FALSE;
324
33.7M
    main_ptr->rowgroup_ctr = 0;
325
33.7M
  }
326
259M
}
jdmainct-8.c:process_data_simple_main
Line
Count
Source
298
244M
{
299
244M
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
300
244M
  JDIMENSION rowgroups_avail;
301
302
  /* Read input data if we haven't filled the main buffer yet */
303
244M
  if (!main_ptr->buffer_full) {
304
27.9M
    if (!(*cinfo->coef->_decompress_data) (cinfo, main_ptr->buffer))
305
2.03k
      return;                   /* suspension forced, can do nothing more */
306
27.9M
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
307
27.9M
  }
308
309
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
310
244M
  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
244M
  (*cinfo->post->_post_process_data) (cinfo, main_ptr->buffer,
318
244M
                                      &main_ptr->rowgroup_ctr, rowgroups_avail,
319
244M
                                      output_buf, out_row_ctr, out_rows_avail);
320
321
  /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
322
244M
  if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
323
27.9M
    main_ptr->buffer_full = FALSE;
324
27.9M
    main_ptr->rowgroup_ctr = 0;
325
27.9M
  }
326
244M
}
jdmainct-12.c:process_data_simple_main
Line
Count
Source
298
13.1M
{
299
13.1M
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
300
13.1M
  JDIMENSION rowgroups_avail;
301
302
  /* Read input data if we haven't filled the main buffer yet */
303
13.1M
  if (!main_ptr->buffer_full) {
304
4.02M
    if (!(*cinfo->coef->_decompress_data) (cinfo, main_ptr->buffer))
305
0
      return;                   /* suspension forced, can do nothing more */
306
4.02M
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
307
4.02M
  }
308
309
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
310
13.1M
  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
13.1M
  (*cinfo->post->_post_process_data) (cinfo, main_ptr->buffer,
318
13.1M
                                      &main_ptr->rowgroup_ctr, rowgroups_avail,
319
13.1M
                                      output_buf, out_row_ctr, out_rows_avail);
320
321
  /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
322
13.1M
  if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
323
4.01M
    main_ptr->buffer_full = FALSE;
324
4.01M
    main_ptr->rowgroup_ctr = 0;
325
4.01M
  }
326
13.1M
}
jdmainct-16.c:process_data_simple_main
Line
Count
Source
298
1.76M
{
299
1.76M
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
300
1.76M
  JDIMENSION rowgroups_avail;
301
302
  /* Read input data if we haven't filled the main buffer yet */
303
1.76M
  if (!main_ptr->buffer_full) {
304
1.76M
    if (!(*cinfo->coef->_decompress_data) (cinfo, main_ptr->buffer))
305
0
      return;                   /* suspension forced, can do nothing more */
306
1.76M
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
307
1.76M
  }
308
309
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
310
1.76M
  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
1.76M
  (*cinfo->post->_post_process_data) (cinfo, main_ptr->buffer,
318
1.76M
                                      &main_ptr->rowgroup_ctr, rowgroups_avail,
319
1.76M
                                      output_buf, out_row_ctr, out_rows_avail);
320
321
  /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
322
1.76M
  if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
323
1.76M
    main_ptr->buffer_full = FALSE;
324
1.76M
    main_ptr->rowgroup_ctr = 0;
325
1.76M
  }
326
1.76M
}
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
33.3M
{
338
33.3M
  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
33.3M
  if (!main_ptr->buffer_full) {
342
2.16M
    if (!(*cinfo->coef->_decompress_data) (cinfo,
343
2.16M
                                           main_ptr->xbuffer[main_ptr->whichptr]))
344
17.2k
      return;                   /* suspension forced, can do nothing more */
345
2.14M
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
346
2.14M
    main_ptr->iMCU_row_ctr++;   /* count rows received */
347
2.14M
  }
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
33.3M
  switch (main_ptr->context_state) {
355
4.18M
  case CTX_POSTPONED_ROW:
356
    /* Call postprocessor using previously set pointers for postponed row */
357
4.18M
    (*cinfo->post->_post_process_data) (cinfo,
358
4.18M
                                        main_ptr->xbuffer[main_ptr->whichptr],
359
4.18M
                                        &main_ptr->rowgroup_ctr,
360
4.18M
                                        main_ptr->rowgroups_avail, output_buf,
361
4.18M
                                        out_row_ctr, out_rows_avail);
362
4.18M
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
363
2.06M
      return;                   /* Need to suspend */
364
2.12M
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
365
2.12M
    if (*out_row_ctr >= out_rows_avail)
366
1.95M
      return;                   /* Postprocessor exactly filled output buf */
367
167k
    FALLTHROUGH                 /*FALLTHROUGH*/
368
2.14M
  case CTX_PREPARE_FOR_IMCU:
369
    /* Prepare to process first M-1 row groups of this iMCU row */
370
2.14M
    main_ptr->rowgroup_ctr = 0;
371
2.14M
    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
2.14M
    if (main_ptr->iMCU_row_ctr == cinfo->total_iMCU_rows)
376
24.3k
      set_bottom_pointers(cinfo);
377
2.14M
    main_ptr->context_state = CTX_PROCESS_IMCU;
378
2.14M
    FALLTHROUGH                 /*FALLTHROUGH*/
379
29.3M
  case CTX_PROCESS_IMCU:
380
    /* Call postprocessor using previously set pointers */
381
29.3M
    (*cinfo->post->_post_process_data) (cinfo,
382
29.3M
                                        main_ptr->xbuffer[main_ptr->whichptr],
383
29.3M
                                        &main_ptr->rowgroup_ctr,
384
29.3M
                                        main_ptr->rowgroups_avail, output_buf,
385
29.3M
                                        out_row_ctr, out_rows_avail);
386
29.3M
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
387
27.1M
      return;                   /* Need to suspend */
388
    /* After the first iMCU, change wraparound pointers to normal state */
389
2.13M
    if (main_ptr->iMCU_row_ctr == 1)
390
20.8k
      set_wraparound_pointers(cinfo);
391
    /* Prepare to load new iMCU row using other xbuffer list */
392
2.13M
    main_ptr->whichptr ^= 1;    /* 0=>1 or 1=>0 */
393
2.13M
    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
2.13M
    main_ptr->rowgroup_ctr = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 1);
397
2.13M
    main_ptr->rowgroups_avail = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 2);
398
2.13M
    main_ptr->context_state = CTX_POSTPONED_ROW;
399
33.3M
  }
400
33.3M
}
jdmainct-8.c:process_data_context_main
Line
Count
Source
337
32.8M
{
338
32.8M
  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
32.8M
  if (!main_ptr->buffer_full) {
342
2.08M
    if (!(*cinfo->coef->_decompress_data) (cinfo,
343
2.08M
                                           main_ptr->xbuffer[main_ptr->whichptr]))
344
17.2k
      return;                   /* suspension forced, can do nothing more */
345
2.06M
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
346
2.06M
    main_ptr->iMCU_row_ctr++;   /* count rows received */
347
2.06M
  }
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
32.8M
  switch (main_ptr->context_state) {
355
4.11M
  case CTX_POSTPONED_ROW:
356
    /* Call postprocessor using previously set pointers for postponed row */
357
4.11M
    (*cinfo->post->_post_process_data) (cinfo,
358
4.11M
                                        main_ptr->xbuffer[main_ptr->whichptr],
359
4.11M
                                        &main_ptr->rowgroup_ctr,
360
4.11M
                                        main_ptr->rowgroups_avail, output_buf,
361
4.11M
                                        out_row_ctr, out_rows_avail);
362
4.11M
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
363
2.06M
      return;                   /* Need to suspend */
364
2.04M
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
365
2.04M
    if (*out_row_ctr >= out_rows_avail)
366
1.95M
      return;                   /* Postprocessor exactly filled output buf */
367
89.5k
    FALLTHROUGH                 /*FALLTHROUGH*/
368
2.06M
  case CTX_PREPARE_FOR_IMCU:
369
    /* Prepare to process first M-1 row groups of this iMCU row */
370
2.06M
    main_ptr->rowgroup_ctr = 0;
371
2.06M
    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
2.06M
    if (main_ptr->iMCU_row_ctr == cinfo->total_iMCU_rows)
376
23.7k
      set_bottom_pointers(cinfo);
377
2.06M
    main_ptr->context_state = CTX_PROCESS_IMCU;
378
2.06M
    FALLTHROUGH                 /*FALLTHROUGH*/
379
28.8M
  case CTX_PROCESS_IMCU:
380
    /* Call postprocessor using previously set pointers */
381
28.8M
    (*cinfo->post->_post_process_data) (cinfo,
382
28.8M
                                        main_ptr->xbuffer[main_ptr->whichptr],
383
28.8M
                                        &main_ptr->rowgroup_ctr,
384
28.8M
                                        main_ptr->rowgroups_avail, output_buf,
385
28.8M
                                        out_row_ctr, out_rows_avail);
386
28.8M
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
387
26.7M
      return;                   /* Need to suspend */
388
    /* After the first iMCU, change wraparound pointers to normal state */
389
2.05M
    if (main_ptr->iMCU_row_ctr == 1)
390
20.5k
      set_wraparound_pointers(cinfo);
391
    /* Prepare to load new iMCU row using other xbuffer list */
392
2.05M
    main_ptr->whichptr ^= 1;    /* 0=>1 or 1=>0 */
393
2.05M
    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
2.05M
    main_ptr->rowgroup_ctr = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 1);
397
2.05M
    main_ptr->rowgroups_avail = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 2);
398
2.05M
    main_ptr->context_state = CTX_POSTPONED_ROW;
399
32.8M
  }
400
32.8M
}
jdmainct-12.c:process_data_context_main
Line
Count
Source
337
446k
{
338
446k
  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
446k
  if (!main_ptr->buffer_full) {
342
78.2k
    if (!(*cinfo->coef->_decompress_data) (cinfo,
343
78.2k
                                           main_ptr->xbuffer[main_ptr->whichptr]))
344
0
      return;                   /* suspension forced, can do nothing more */
345
78.2k
    main_ptr->buffer_full = TRUE;       /* OK, we have an iMCU row to work with */
346
78.2k
    main_ptr->iMCU_row_ctr++;   /* count rows received */
347
78.2k
  }
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
446k
  switch (main_ptr->context_state) {
355
77.7k
  case CTX_POSTPONED_ROW:
356
    /* Call postprocessor using previously set pointers for postponed row */
357
77.7k
    (*cinfo->post->_post_process_data) (cinfo,
358
77.7k
                                        main_ptr->xbuffer[main_ptr->whichptr],
359
77.7k
                                        &main_ptr->rowgroup_ctr,
360
77.7k
                                        main_ptr->rowgroups_avail, output_buf,
361
77.7k
                                        out_row_ctr, out_rows_avail);
362
77.7k
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
363
74
      return;                   /* Need to suspend */
364
77.6k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
365
77.6k
    if (*out_row_ctr >= out_rows_avail)
366
72
      return;                   /* Postprocessor exactly filled output buf */
367
77.5k
    FALLTHROUGH                 /*FALLTHROUGH*/
368
78.2k
  case CTX_PREPARE_FOR_IMCU:
369
    /* Prepare to process first M-1 row groups of this iMCU row */
370
78.2k
    main_ptr->rowgroup_ctr = 0;
371
78.2k
    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
78.2k
    if (main_ptr->iMCU_row_ctr == cinfo->total_iMCU_rows)
376
596
      set_bottom_pointers(cinfo);
377
78.2k
    main_ptr->context_state = CTX_PROCESS_IMCU;
378
78.2k
    FALLTHROUGH                 /*FALLTHROUGH*/
379
446k
  case CTX_PROCESS_IMCU:
380
    /* Call postprocessor using previously set pointers */
381
446k
    (*cinfo->post->_post_process_data) (cinfo,
382
446k
                                        main_ptr->xbuffer[main_ptr->whichptr],
383
446k
                                        &main_ptr->rowgroup_ctr,
384
446k
                                        main_ptr->rowgroups_avail, output_buf,
385
446k
                                        out_row_ctr, out_rows_avail);
386
446k
    if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
387
368k
      return;                   /* Need to suspend */
388
    /* After the first iMCU, change wraparound pointers to normal state */
389
77.8k
    if (main_ptr->iMCU_row_ctr == 1)
390
388
      set_wraparound_pointers(cinfo);
391
    /* Prepare to load new iMCU row using other xbuffer list */
392
77.8k
    main_ptr->whichptr ^= 1;    /* 0=>1 or 1=>0 */
393
77.8k
    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
77.8k
    main_ptr->rowgroup_ctr = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 1);
397
77.8k
    main_ptr->rowgroups_avail = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 2);
398
77.8k
    main_ptr->context_state = CTX_POSTPONED_ROW;
399
446k
  }
400
446k
}
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
52.5M
{
415
52.5M
  (*cinfo->post->_post_process_data) (cinfo, (_JSAMPIMAGE)NULL,
416
52.5M
                                      (JDIMENSION *)NULL, (JDIMENSION)0,
417
52.5M
                                      output_buf, out_row_ctr, out_rows_avail);
418
52.5M
}
jdmainct-8.c:process_data_crank_post
Line
Count
Source
414
52.5M
{
415
52.5M
  (*cinfo->post->_post_process_data) (cinfo, (_JSAMPIMAGE)NULL,
416
                                      (JDIMENSION *)NULL, (JDIMENSION)0,
417
52.5M
                                      output_buf, out_row_ctr, out_rows_avail);
418
52.5M
}
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
83.6k
{
430
83.6k
  my_main_ptr main_ptr;
431
83.6k
  int ci, rgroup, ngroups;
432
83.6k
  jpeg_component_info *compptr;
433
434
83.6k
#ifdef D_LOSSLESS_SUPPORTED
435
83.6k
  if (cinfo->master->lossless) {
436
#if BITS_IN_JSAMPLE == 8
437
6.12k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
438
#else
439
11.6k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
440
11.6k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
441
0
#endif
442
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
443
17.7k
  } else
444
65.8k
#endif
445
65.8k
  {
446
65.8k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
447
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
448
65.8k
  }
449
450
83.6k
  main_ptr = (my_main_ptr)
451
83.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
452
83.6k
                                sizeof(my_main_controller));
453
83.6k
  memset(main_ptr, 0, sizeof(my_main_controller));
454
83.6k
  cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
455
83.6k
  main_ptr->pub.start_pass = start_pass_main;
456
457
83.6k
  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
83.6k
  if (cinfo->upsample->need_context_rows) {
464
10.7k
    if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */
465
0
      ERREXIT(cinfo, JERR_NOTIMPL);
466
10.7k
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
467
10.7k
    ngroups = cinfo->_min_DCT_scaled_size + 2;
468
72.8k
  } else {
469
72.8k
    ngroups = cinfo->_min_DCT_scaled_size;
470
72.8k
  }
471
472
277k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
473
194k
       ci++, compptr++) {
474
194k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
475
194k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
476
194k
    main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
477
194k
                        ((j_common_ptr)cinfo, JPOOL_IMAGE,
478
194k
                         compptr->width_in_blocks * compptr->_DCT_scaled_size,
479
194k
                         (JDIMENSION)(rgroup * ngroups));
480
194k
  }
481
83.6k
}
jinit_d_main_controller
Line
Count
Source
429
55.8k
{
430
55.8k
  my_main_ptr main_ptr;
431
55.8k
  int ci, rgroup, ngroups;
432
55.8k
  jpeg_component_info *compptr;
433
434
55.8k
#ifdef D_LOSSLESS_SUPPORTED
435
55.8k
  if (cinfo->master->lossless) {
436
6.12k
#if BITS_IN_JSAMPLE == 8
437
6.12k
    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
6.12k
  } else
444
49.7k
#endif
445
49.7k
  {
446
49.7k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
447
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
448
49.7k
  }
449
450
55.8k
  main_ptr = (my_main_ptr)
451
55.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
452
55.8k
                                sizeof(my_main_controller));
453
55.8k
  memset(main_ptr, 0, sizeof(my_main_controller));
454
55.8k
  cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
455
55.8k
  main_ptr->pub.start_pass = start_pass_main;
456
457
55.8k
  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
55.8k
  if (cinfo->upsample->need_context_rows) {
464
9.45k
    if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */
465
0
      ERREXIT(cinfo, JERR_NOTIMPL);
466
9.45k
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
467
9.45k
    ngroups = cinfo->_min_DCT_scaled_size + 2;
468
46.4k
  } else {
469
46.4k
    ngroups = cinfo->_min_DCT_scaled_size;
470
46.4k
  }
471
472
184k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
473
128k
       ci++, compptr++) {
474
128k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
475
128k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
476
128k
    main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
477
128k
                        ((j_common_ptr)cinfo, JPOOL_IMAGE,
478
128k
                         compptr->width_in_blocks * compptr->_DCT_scaled_size,
479
128k
                         (JDIMENSION)(rgroup * ngroups));
480
128k
  }
481
55.8k
}
j12init_d_main_controller
Line
Count
Source
429
21.8k
{
430
21.8k
  my_main_ptr main_ptr;
431
21.8k
  int ci, rgroup, ngroups;
432
21.8k
  jpeg_component_info *compptr;
433
434
21.8k
#ifdef D_LOSSLESS_SUPPORTED
435
21.8k
  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
5.78k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
440
5.78k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
441
0
#endif
442
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
443
5.78k
  } else
444
16.0k
#endif
445
16.0k
  {
446
16.0k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
447
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
448
16.0k
  }
449
450
21.8k
  main_ptr = (my_main_ptr)
451
21.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
452
21.8k
                                sizeof(my_main_controller));
453
21.8k
  memset(main_ptr, 0, sizeof(my_main_controller));
454
21.8k
  cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
455
21.8k
  main_ptr->pub.start_pass = start_pass_main;
456
457
21.8k
  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
21.8k
  if (cinfo->upsample->need_context_rows) {
464
1.32k
    if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */
465
0
      ERREXIT(cinfo, JERR_NOTIMPL);
466
1.32k
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
467
1.32k
    ngroups = cinfo->_min_DCT_scaled_size + 2;
468
20.5k
  } else {
469
20.5k
    ngroups = cinfo->_min_DCT_scaled_size;
470
20.5k
  }
471
472
69.9k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
473
48.0k
       ci++, compptr++) {
474
48.0k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
475
48.0k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
476
48.0k
    main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
477
48.0k
                        ((j_common_ptr)cinfo, JPOOL_IMAGE,
478
48.0k
                         compptr->width_in_blocks * compptr->_DCT_scaled_size,
479
48.0k
                         (JDIMENSION)(rgroup * ngroups));
480
48.0k
  }
481
21.8k
}
j16init_d_main_controller
Line
Count
Source
429
5.87k
{
430
5.87k
  my_main_ptr main_ptr;
431
5.87k
  int ci, rgroup, ngroups;
432
5.87k
  jpeg_component_info *compptr;
433
434
5.87k
#ifdef D_LOSSLESS_SUPPORTED
435
5.87k
  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
5.87k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
440
5.87k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
441
0
#endif
442
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
443
5.87k
  } 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
5.87k
  main_ptr = (my_main_ptr)
451
5.87k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
452
5.87k
                                sizeof(my_main_controller));
453
5.87k
  memset(main_ptr, 0, sizeof(my_main_controller));
454
5.87k
  cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
455
5.87k
  main_ptr->pub.start_pass = start_pass_main;
456
457
5.87k
  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
5.87k
  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
5.87k
  } else {
469
5.87k
    ngroups = cinfo->_min_DCT_scaled_size;
470
5.87k
  }
471
472
22.9k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
473
17.1k
       ci++, compptr++) {
474
17.1k
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
475
17.1k
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
476
17.1k
    main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
477
17.1k
                        ((j_common_ptr)cinfo, JPOOL_IMAGE,
478
17.1k
                         compptr->width_in_blocks * compptr->_DCT_scaled_size,
479
17.1k
                         (JDIMENSION)(rgroup * ngroups));
480
17.1k
  }
481
5.87k
}
482
483
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */