Coverage Report

Created: 2026-09-01 07:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/src/jcprepct.c
Line
Count
Source
1
/*
2
 * jcprepct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1996, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 2024-2026, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the compression preprocessing controller.
14
 * This controller manages the color conversion, downsampling,
15
 * and edge expansion steps.
16
 *
17
 * Most of the complexity here is associated with buffering input rows
18
 * as required by the downsampler.  See the comments at the head of
19
 * jcsample.c for the downsampler's needs.
20
 */
21
22
#define JPEG_INTERNALS
23
#include "jinclude.h"
24
#include "jpeglib.h"
25
#include "jsamplecomp.h"
26
#ifdef WITH_PROFILE
27
#include "tjutil.h"
28
#endif
29
30
31
#if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)
32
33
/* At present, jcsample.c can request context rows only for smoothing.
34
 * In the future, we might also need context rows for CCIR601 sampling
35
 * or other more-complex downsampling procedures.  The code to support
36
 * context rows should be compiled only if needed.
37
 */
38
#ifdef INPUT_SMOOTHING_SUPPORTED
39
#define CONTEXT_ROWS_SUPPORTED
40
#endif
41
42
43
/*
44
 * For the simple (no-context-row) case, we just need to buffer one row group's
45
 * worth of components for the downsampling step.  At the bottom of the image,
46
 * we pad to a full row group by replicating the last component row(s).  The
47
 * downsampler's last output row is then replicated if needed to pad out to a
48
 * full iMCU row.
49
 *
50
 * When providing context rows, we must buffer three row groups' worth of
51
 * components.  Three row groups are physically allocated, but the row pointer
52
 * arrays are made five row groups high, with the extra pointers above and
53
 * below "wrapping around" to point to the last and first real row groups.
54
 * This allows the downsampler to access the proper context rows.  At the top
55
 * and bottom of the image, we create dummy context rows by copying the first
56
 * or last real component row(s).  This copying could be avoided by pointer
57
 * hacking, as is done in jdmainct.c, but it doesn't seem worth the trouble on
58
 * the compression side.
59
 */
60
61
62
/* Private buffer controller object */
63
64
typedef struct {
65
  struct jpeg_c_prep_controller pub; /* public fields */
66
67
  /* Downsampling input buffer.  This buffer holds color-converted data
68
   * until we have enough to do a downsample step.
69
   */
70
  _JSAMPARRAY color_buf[MAX_COMPONENTS];
71
72
  JDIMENSION rows_to_go;        /* counts rows remaining in source image */
73
  int next_buf_row;             /* index of next row to store in color_buf */
74
75
#ifdef CONTEXT_ROWS_SUPPORTED   /* only needed for context case */
76
  int this_row_group;           /* starting row index of group to process */
77
  int next_buf_stop;            /* downsample when we reach this index */
78
#endif
79
} my_prep_controller;
80
81
typedef my_prep_controller *my_prep_ptr;
82
83
84
/*
85
 * Initialize for a processing pass.
86
 */
87
88
METHODDEF(void)
89
start_pass_prep(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
90
158k
{
91
158k
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
92
93
158k
  if (pass_mode != JBUF_PASS_THRU)
94
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
95
96
  /* Initialize total-height counter for detecting bottom of image */
97
158k
  prep->rows_to_go = cinfo->image_height;
98
  /* Mark the conversion buffer empty */
99
158k
  prep->next_buf_row = 0;
100
158k
#ifdef CONTEXT_ROWS_SUPPORTED
101
  /* Preset additional state variables for context mode.
102
   * These aren't used in non-context mode, so we needn't test which mode.
103
   */
104
158k
  prep->this_row_group = 0;
105
  /* Set next_buf_stop to stop after two row groups have been read in. */
106
158k
  prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
107
158k
#endif
108
158k
}
jcprepct-8.c:start_pass_prep
Line
Count
Source
90
79.3k
{
91
79.3k
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
92
93
79.3k
  if (pass_mode != JBUF_PASS_THRU)
94
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
95
96
  /* Initialize total-height counter for detecting bottom of image */
97
79.3k
  prep->rows_to_go = cinfo->image_height;
98
  /* Mark the conversion buffer empty */
99
79.3k
  prep->next_buf_row = 0;
100
79.3k
#ifdef CONTEXT_ROWS_SUPPORTED
101
  /* Preset additional state variables for context mode.
102
   * These aren't used in non-context mode, so we needn't test which mode.
103
   */
104
79.3k
  prep->this_row_group = 0;
105
  /* Set next_buf_stop to stop after two row groups have been read in. */
106
79.3k
  prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
107
79.3k
#endif
108
79.3k
}
jcprepct-12.c:start_pass_prep
Line
Count
Source
90
57.8k
{
91
57.8k
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
92
93
57.8k
  if (pass_mode != JBUF_PASS_THRU)
94
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
95
96
  /* Initialize total-height counter for detecting bottom of image */
97
57.8k
  prep->rows_to_go = cinfo->image_height;
98
  /* Mark the conversion buffer empty */
99
57.8k
  prep->next_buf_row = 0;
100
57.8k
#ifdef CONTEXT_ROWS_SUPPORTED
101
  /* Preset additional state variables for context mode.
102
   * These aren't used in non-context mode, so we needn't test which mode.
103
   */
104
57.8k
  prep->this_row_group = 0;
105
  /* Set next_buf_stop to stop after two row groups have been read in. */
106
57.8k
  prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
107
57.8k
#endif
108
57.8k
}
jcprepct-16.c:start_pass_prep
Line
Count
Source
90
21.1k
{
91
21.1k
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
92
93
21.1k
  if (pass_mode != JBUF_PASS_THRU)
94
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
95
96
  /* Initialize total-height counter for detecting bottom of image */
97
21.1k
  prep->rows_to_go = cinfo->image_height;
98
  /* Mark the conversion buffer empty */
99
21.1k
  prep->next_buf_row = 0;
100
21.1k
#ifdef CONTEXT_ROWS_SUPPORTED
101
  /* Preset additional state variables for context mode.
102
   * These aren't used in non-context mode, so we needn't test which mode.
103
   */
104
21.1k
  prep->this_row_group = 0;
105
  /* Set next_buf_stop to stop after two row groups have been read in. */
106
21.1k
  prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
107
21.1k
#endif
108
21.1k
}
109
110
111
/*
112
 * Expand an image vertically from height input_rows to height output_rows,
113
 * by duplicating the bottom row.
114
 */
115
116
LOCAL(void)
117
expand_bottom_edge(_JSAMPARRAY image_data, JDIMENSION num_cols, int input_rows,
118
                   int output_rows)
119
196k
{
120
196k
  register int row;
121
122
1.21M
  for (row = input_rows; row < output_rows; row++) {
123
1.01M
    _jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1,
124
1.01M
                       num_cols);
125
1.01M
  }
126
196k
}
jcprepct-8.c:expand_bottom_edge
Line
Count
Source
119
111k
{
120
111k
  register int row;
121
122
678k
  for (row = input_rows; row < output_rows; row++) {
123
566k
    _jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1,
124
566k
                       num_cols);
125
566k
  }
126
111k
}
jcprepct-12.c:expand_bottom_edge
Line
Count
Source
119
84.1k
{
120
84.1k
  register int row;
121
122
536k
  for (row = input_rows; row < output_rows; row++) {
123
452k
    _jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1,
124
452k
                       num_cols);
125
452k
  }
126
84.1k
}
Unexecuted instantiation: jcprepct-16.c:expand_bottom_edge
127
128
129
/*
130
 * Process some data in the simple no-context case.
131
 *
132
 * Preprocessor output data is counted in "row groups".  A row group
133
 * is defined to be v_samp_factor sample rows of each component.
134
 * Downsampling will produce this much data from each max_v_samp_factor
135
 * input rows.
136
 */
137
138
METHODDEF(void)
139
pre_process_data(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
140
                 JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail,
141
                 _JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
142
                 JDIMENSION out_row_groups_avail)
143
111M
{
144
111M
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
145
111M
  int numrows, ci;
146
111M
  JDIMENSION inrows;
147
111M
  jpeg_component_info *compptr;
148
111M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
149
150
320M
  while (*in_row_ctr < in_rows_avail &&
151
316M
         *out_row_group_ctr < out_row_groups_avail) {
152
    /* Do color conversion to fill the conversion buffer. */
153
209M
    inrows = in_rows_avail - *in_row_ctr;
154
209M
    numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
155
209M
    numrows = (int)MIN((JDIMENSION)numrows, inrows);
156
#ifdef WITH_PROFILE
157
    cinfo->master->start = getTime();
158
#endif
159
209M
    (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
160
209M
                                        prep->color_buf,
161
209M
                                        (JDIMENSION)prep->next_buf_row,
162
209M
                                        numrows);
163
#ifdef WITH_PROFILE
164
    cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
165
    cinfo->master->cconvert_mpixels +=
166
      (double)cinfo->image_width * numrows / 1000000.;
167
#endif
168
209M
    *in_row_ctr += numrows;
169
209M
    prep->next_buf_row += numrows;
170
209M
    prep->rows_to_go -= numrows;
171
    /* If at bottom of image, pad to fill the conversion buffer. */
172
209M
    if (prep->rows_to_go == 0 &&
173
152k
        prep->next_buf_row < cinfo->max_v_samp_factor) {
174
38.9k
      for (ci = 0; ci < cinfo->num_components; ci++) {
175
30.2k
        expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
176
30.2k
                           prep->next_buf_row, cinfo->max_v_samp_factor);
177
30.2k
      }
178
8.68k
      prep->next_buf_row = cinfo->max_v_samp_factor;
179
8.68k
    }
180
    /* If we've filled the conversion buffer, empty it. */
181
209M
    if (prep->next_buf_row == cinfo->max_v_samp_factor) {
182
#ifdef WITH_PROFILE
183
      cinfo->master->start = getTime();
184
#endif
185
207M
      (*cinfo->downsample->_downsample) (cinfo,
186
207M
                                         prep->color_buf, (JDIMENSION)0,
187
207M
                                         output_buf, *out_row_group_ctr);
188
#ifdef WITH_PROFILE
189
      cinfo->master->downsample_elapsed += getTime() - cinfo->master->start;
190
      cinfo->master->downsample_msamples +=
191
        (double)cinfo->image_width * cinfo->max_v_samp_factor / 1000000.;
192
#endif
193
207M
      prep->next_buf_row = 0;
194
207M
      (*out_row_group_ctr)++;
195
207M
    }
196
    /* If at bottom of image, pad the output to a full iMCU height.
197
     * Note we assume the caller is providing a one-iMCU-height output buffer!
198
     */
199
209M
    if (prep->rows_to_go == 0 && *out_row_group_ctr < out_row_groups_avail) {
200
212k
      for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
201
154k
           ci++, compptr++) {
202
154k
        expand_bottom_edge(output_buf[ci],
203
154k
                           compptr->width_in_blocks * data_unit,
204
154k
                           (int)(*out_row_group_ctr * compptr->v_samp_factor),
205
154k
                           (int)(out_row_groups_avail * compptr->v_samp_factor));
206
154k
      }
207
57.7k
      *out_row_group_ctr = out_row_groups_avail;
208
57.7k
      break;                    /* can exit outer loop without test */
209
57.7k
    }
210
209M
  }
211
111M
}
jcprepct-8.c:pre_process_data
Line
Count
Source
143
39.9M
{
144
39.9M
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
145
39.9M
  int numrows, ci;
146
39.9M
  JDIMENSION inrows;
147
39.9M
  jpeg_component_info *compptr;
148
39.9M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
149
150
124M
  while (*in_row_ctr < in_rows_avail &&
151
120M
         *out_row_group_ctr < out_row_groups_avail) {
152
    /* Do color conversion to fill the conversion buffer. */
153
84.6M
    inrows = in_rows_avail - *in_row_ctr;
154
84.6M
    numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
155
84.6M
    numrows = (int)MIN((JDIMENSION)numrows, inrows);
156
#ifdef WITH_PROFILE
157
    cinfo->master->start = getTime();
158
#endif
159
84.6M
    (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
160
84.6M
                                        prep->color_buf,
161
84.6M
                                        (JDIMENSION)prep->next_buf_row,
162
84.6M
                                        numrows);
163
#ifdef WITH_PROFILE
164
    cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
165
    cinfo->master->cconvert_mpixels +=
166
      (double)cinfo->image_width * numrows / 1000000.;
167
#endif
168
84.6M
    *in_row_ctr += numrows;
169
84.6M
    prep->next_buf_row += numrows;
170
84.6M
    prep->rows_to_go -= numrows;
171
    /* If at bottom of image, pad to fill the conversion buffer. */
172
84.6M
    if (prep->rows_to_go == 0 &&
173
73.0k
        prep->next_buf_row < cinfo->max_v_samp_factor) {
174
20.5k
      for (ci = 0; ci < cinfo->num_components; ci++) {
175
15.9k
        expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
176
15.9k
                           prep->next_buf_row, cinfo->max_v_samp_factor);
177
15.9k
      }
178
4.60k
      prep->next_buf_row = cinfo->max_v_samp_factor;
179
4.60k
    }
180
    /* If we've filled the conversion buffer, empty it. */
181
84.6M
    if (prep->next_buf_row == cinfo->max_v_samp_factor) {
182
#ifdef WITH_PROFILE
183
      cinfo->master->start = getTime();
184
#endif
185
82.7M
      (*cinfo->downsample->_downsample) (cinfo,
186
82.7M
                                         prep->color_buf, (JDIMENSION)0,
187
82.7M
                                         output_buf, *out_row_group_ctr);
188
#ifdef WITH_PROFILE
189
      cinfo->master->downsample_elapsed += getTime() - cinfo->master->start;
190
      cinfo->master->downsample_msamples +=
191
        (double)cinfo->image_width * cinfo->max_v_samp_factor / 1000000.;
192
#endif
193
82.7M
      prep->next_buf_row = 0;
194
82.7M
      (*out_row_group_ctr)++;
195
82.7M
    }
196
    /* If at bottom of image, pad the output to a full iMCU height.
197
     * Note we assume the caller is providing a one-iMCU-height output buffer!
198
     */
199
84.6M
    if (prep->rows_to_go == 0 && *out_row_group_ctr < out_row_groups_avail) {
200
116k
      for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
201
84.9k
           ci++, compptr++) {
202
84.9k
        expand_bottom_edge(output_buf[ci],
203
84.9k
                           compptr->width_in_blocks * data_unit,
204
84.9k
                           (int)(*out_row_group_ctr * compptr->v_samp_factor),
205
84.9k
                           (int)(out_row_groups_avail * compptr->v_samp_factor));
206
84.9k
      }
207
31.6k
      *out_row_group_ctr = out_row_groups_avail;
208
31.6k
      break;                    /* can exit outer loop without test */
209
31.6k
    }
210
84.6M
  }
211
39.9M
}
jcprepct-12.c:pre_process_data
Line
Count
Source
143
36.2M
{
144
36.2M
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
145
36.2M
  int numrows, ci;
146
36.2M
  JDIMENSION inrows;
147
36.2M
  jpeg_component_info *compptr;
148
36.2M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
149
150
126M
  while (*in_row_ctr < in_rows_avail &&
151
125M
         *out_row_group_ctr < out_row_groups_avail) {
152
    /* Do color conversion to fill the conversion buffer. */
153
89.7M
    inrows = in_rows_avail - *in_row_ctr;
154
89.7M
    numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
155
89.7M
    numrows = (int)MIN((JDIMENSION)numrows, inrows);
156
#ifdef WITH_PROFILE
157
    cinfo->master->start = getTime();
158
#endif
159
89.7M
    (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
160
89.7M
                                        prep->color_buf,
161
89.7M
                                        (JDIMENSION)prep->next_buf_row,
162
89.7M
                                        numrows);
163
#ifdef WITH_PROFILE
164
    cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
165
    cinfo->master->cconvert_mpixels +=
166
      (double)cinfo->image_width * numrows / 1000000.;
167
#endif
168
89.7M
    *in_row_ctr += numrows;
169
89.7M
    prep->next_buf_row += numrows;
170
89.7M
    prep->rows_to_go -= numrows;
171
    /* If at bottom of image, pad to fill the conversion buffer. */
172
89.7M
    if (prep->rows_to_go == 0 &&
173
57.8k
        prep->next_buf_row < cinfo->max_v_samp_factor) {
174
18.3k
      for (ci = 0; ci < cinfo->num_components; ci++) {
175
14.2k
        expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
176
14.2k
                           prep->next_buf_row, cinfo->max_v_samp_factor);
177
14.2k
      }
178
4.08k
      prep->next_buf_row = cinfo->max_v_samp_factor;
179
4.08k
    }
180
    /* If we've filled the conversion buffer, empty it. */
181
89.7M
    if (prep->next_buf_row == cinfo->max_v_samp_factor) {
182
#ifdef WITH_PROFILE
183
      cinfo->master->start = getTime();
184
#endif
185
89.7M
      (*cinfo->downsample->_downsample) (cinfo,
186
89.7M
                                         prep->color_buf, (JDIMENSION)0,
187
89.7M
                                         output_buf, *out_row_group_ctr);
188
#ifdef WITH_PROFILE
189
      cinfo->master->downsample_elapsed += getTime() - cinfo->master->start;
190
      cinfo->master->downsample_msamples +=
191
        (double)cinfo->image_width * cinfo->max_v_samp_factor / 1000000.;
192
#endif
193
89.7M
      prep->next_buf_row = 0;
194
89.7M
      (*out_row_group_ctr)++;
195
89.7M
    }
196
    /* If at bottom of image, pad the output to a full iMCU height.
197
     * Note we assume the caller is providing a one-iMCU-height output buffer!
198
     */
199
89.7M
    if (prep->rows_to_go == 0 && *out_row_group_ctr < out_row_groups_avail) {
200
95.9k
      for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
201
69.8k
           ci++, compptr++) {
202
69.8k
        expand_bottom_edge(output_buf[ci],
203
69.8k
                           compptr->width_in_blocks * data_unit,
204
69.8k
                           (int)(*out_row_group_ctr * compptr->v_samp_factor),
205
69.8k
                           (int)(out_row_groups_avail * compptr->v_samp_factor));
206
69.8k
      }
207
26.0k
      *out_row_group_ctr = out_row_groups_avail;
208
26.0k
      break;                    /* can exit outer loop without test */
209
26.0k
    }
210
89.7M
  }
211
36.2M
}
jcprepct-16.c:pre_process_data
Line
Count
Source
143
35.1M
{
144
35.1M
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
145
35.1M
  int numrows, ci;
146
35.1M
  JDIMENSION inrows;
147
35.1M
  jpeg_component_info *compptr;
148
35.1M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
149
150
70.3M
  while (*in_row_ctr < in_rows_avail &&
151
70.3M
         *out_row_group_ctr < out_row_groups_avail) {
152
    /* Do color conversion to fill the conversion buffer. */
153
35.1M
    inrows = in_rows_avail - *in_row_ctr;
154
35.1M
    numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
155
35.1M
    numrows = (int)MIN((JDIMENSION)numrows, inrows);
156
#ifdef WITH_PROFILE
157
    cinfo->master->start = getTime();
158
#endif
159
35.1M
    (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
160
35.1M
                                        prep->color_buf,
161
35.1M
                                        (JDIMENSION)prep->next_buf_row,
162
35.1M
                                        numrows);
163
#ifdef WITH_PROFILE
164
    cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
165
    cinfo->master->cconvert_mpixels +=
166
      (double)cinfo->image_width * numrows / 1000000.;
167
#endif
168
35.1M
    *in_row_ctr += numrows;
169
35.1M
    prep->next_buf_row += numrows;
170
35.1M
    prep->rows_to_go -= numrows;
171
    /* If at bottom of image, pad to fill the conversion buffer. */
172
35.1M
    if (prep->rows_to_go == 0 &&
173
21.1k
        prep->next_buf_row < cinfo->max_v_samp_factor) {
174
0
      for (ci = 0; ci < cinfo->num_components; ci++) {
175
0
        expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
176
0
                           prep->next_buf_row, cinfo->max_v_samp_factor);
177
0
      }
178
0
      prep->next_buf_row = cinfo->max_v_samp_factor;
179
0
    }
180
    /* If we've filled the conversion buffer, empty it. */
181
35.1M
    if (prep->next_buf_row == cinfo->max_v_samp_factor) {
182
#ifdef WITH_PROFILE
183
      cinfo->master->start = getTime();
184
#endif
185
35.1M
      (*cinfo->downsample->_downsample) (cinfo,
186
35.1M
                                         prep->color_buf, (JDIMENSION)0,
187
35.1M
                                         output_buf, *out_row_group_ctr);
188
#ifdef WITH_PROFILE
189
      cinfo->master->downsample_elapsed += getTime() - cinfo->master->start;
190
      cinfo->master->downsample_msamples +=
191
        (double)cinfo->image_width * cinfo->max_v_samp_factor / 1000000.;
192
#endif
193
35.1M
      prep->next_buf_row = 0;
194
35.1M
      (*out_row_group_ctr)++;
195
35.1M
    }
196
    /* If at bottom of image, pad the output to a full iMCU height.
197
     * Note we assume the caller is providing a one-iMCU-height output buffer!
198
     */
199
35.1M
    if (prep->rows_to_go == 0 && *out_row_group_ctr < out_row_groups_avail) {
200
0
      for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
201
0
           ci++, compptr++) {
202
0
        expand_bottom_edge(output_buf[ci],
203
0
                           compptr->width_in_blocks * data_unit,
204
0
                           (int)(*out_row_group_ctr * compptr->v_samp_factor),
205
0
                           (int)(out_row_groups_avail * compptr->v_samp_factor));
206
0
      }
207
0
      *out_row_group_ctr = out_row_groups_avail;
208
0
      break;                    /* can exit outer loop without test */
209
0
    }
210
35.1M
  }
211
35.1M
}
212
213
214
#ifdef CONTEXT_ROWS_SUPPORTED
215
216
/*
217
 * Process some data in the context case.
218
 */
219
220
METHODDEF(void)
221
pre_process_context(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
222
                    JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail,
223
                    _JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
224
                    JDIMENSION out_row_groups_avail)
225
4.29M
{
226
4.29M
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
227
4.29M
  int numrows, ci;
228
4.29M
  int buf_height = cinfo->max_v_samp_factor * 3;
229
4.29M
  JDIMENSION inrows;
230
231
8.32M
  while (*out_row_group_ctr < out_row_groups_avail) {
232
8.06M
    if (*in_row_ctr < in_rows_avail) {
233
      /* Do color conversion to fill the conversion buffer. */
234
4.02M
      inrows = in_rows_avail - *in_row_ctr;
235
4.02M
      numrows = prep->next_buf_stop - prep->next_buf_row;
236
4.02M
      numrows = (int)MIN((JDIMENSION)numrows, inrows);
237
#ifdef WITH_PROFILE
238
      cinfo->master->start = getTime();
239
#endif
240
4.02M
      (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
241
4.02M
                                          prep->color_buf,
242
4.02M
                                          (JDIMENSION)prep->next_buf_row,
243
4.02M
                                          numrows);
244
#ifdef WITH_PROFILE
245
      cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
246
      cinfo->master->cconvert_mpixels +=
247
        (double)cinfo->image_width * numrows / 1000000.;
248
#endif
249
      /* Pad at top of image, if first time through */
250
4.02M
      if (prep->rows_to_go == cinfo->image_height) {
251
5.23k
        for (ci = 0; ci < cinfo->num_components; ci++) {
252
3.46k
          int row;
253
9.45k
          for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
254
5.99k
            _jcopy_sample_rows(prep->color_buf[ci], 0, prep->color_buf[ci],
255
5.99k
                               -row, 1, cinfo->image_width);
256
5.99k
          }
257
3.46k
        }
258
1.77k
      }
259
4.02M
      *in_row_ctr += numrows;
260
4.02M
      prep->next_buf_row += numrows;
261
4.02M
      prep->rows_to_go -= numrows;
262
4.03M
    } else {
263
      /* Return for more data, unless we are at the bottom of the image. */
264
4.03M
      if (prep->rows_to_go != 0)
265
4.02M
        break;
266
      /* When at bottom of image, pad to fill the conversion buffer. */
267
5.88k
      if (prep->next_buf_row < prep->next_buf_stop) {
268
16.9k
        for (ci = 0; ci < cinfo->num_components; ci++) {
269
11.0k
          expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
270
11.0k
                             prep->next_buf_row, prep->next_buf_stop);
271
11.0k
        }
272
5.88k
        prep->next_buf_row = prep->next_buf_stop;
273
5.88k
      }
274
5.88k
    }
275
    /* If we've gotten enough data, downsample a row group. */
276
4.03M
    if (prep->next_buf_row == prep->next_buf_stop) {
277
#ifdef WITH_PROFILE
278
      cinfo->master->start = getTime();
279
#endif
280
2.10M
      (*cinfo->downsample->_downsample) (cinfo, prep->color_buf,
281
2.10M
                                         (JDIMENSION)prep->this_row_group,
282
2.10M
                                         output_buf, *out_row_group_ctr);
283
#ifdef WITH_PROFILE
284
      cinfo->master->downsample_elapsed += getTime() - cinfo->master->start;
285
      cinfo->master->downsample_msamples +=
286
        (double)cinfo->image_width * cinfo->max_v_samp_factor / 1000000.;
287
#endif
288
2.10M
      (*out_row_group_ctr)++;
289
      /* Advance pointers with wraparound as necessary. */
290
2.10M
      prep->this_row_group += cinfo->max_v_samp_factor;
291
2.10M
      if (prep->this_row_group >= buf_height)
292
701k
        prep->this_row_group = 0;
293
2.10M
      if (prep->next_buf_row >= buf_height)
294
702k
        prep->next_buf_row = 0;
295
2.10M
      prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
296
2.10M
    }
297
4.03M
  }
298
4.29M
}
jcprepct-8.c:pre_process_context
Line
Count
Source
225
4.29M
{
226
4.29M
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
227
4.29M
  int numrows, ci;
228
4.29M
  int buf_height = cinfo->max_v_samp_factor * 3;
229
4.29M
  JDIMENSION inrows;
230
231
8.32M
  while (*out_row_group_ctr < out_row_groups_avail) {
232
8.06M
    if (*in_row_ctr < in_rows_avail) {
233
      /* Do color conversion to fill the conversion buffer. */
234
4.02M
      inrows = in_rows_avail - *in_row_ctr;
235
4.02M
      numrows = prep->next_buf_stop - prep->next_buf_row;
236
4.02M
      numrows = (int)MIN((JDIMENSION)numrows, inrows);
237
#ifdef WITH_PROFILE
238
      cinfo->master->start = getTime();
239
#endif
240
4.02M
      (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
241
4.02M
                                          prep->color_buf,
242
4.02M
                                          (JDIMENSION)prep->next_buf_row,
243
4.02M
                                          numrows);
244
#ifdef WITH_PROFILE
245
      cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
246
      cinfo->master->cconvert_mpixels +=
247
        (double)cinfo->image_width * numrows / 1000000.;
248
#endif
249
      /* Pad at top of image, if first time through */
250
4.02M
      if (prep->rows_to_go == cinfo->image_height) {
251
5.23k
        for (ci = 0; ci < cinfo->num_components; ci++) {
252
3.46k
          int row;
253
9.45k
          for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
254
5.99k
            _jcopy_sample_rows(prep->color_buf[ci], 0, prep->color_buf[ci],
255
5.99k
                               -row, 1, cinfo->image_width);
256
5.99k
          }
257
3.46k
        }
258
1.77k
      }
259
4.02M
      *in_row_ctr += numrows;
260
4.02M
      prep->next_buf_row += numrows;
261
4.02M
      prep->rows_to_go -= numrows;
262
4.03M
    } else {
263
      /* Return for more data, unless we are at the bottom of the image. */
264
4.03M
      if (prep->rows_to_go != 0)
265
4.02M
        break;
266
      /* When at bottom of image, pad to fill the conversion buffer. */
267
5.88k
      if (prep->next_buf_row < prep->next_buf_stop) {
268
16.9k
        for (ci = 0; ci < cinfo->num_components; ci++) {
269
11.0k
          expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
270
11.0k
                             prep->next_buf_row, prep->next_buf_stop);
271
11.0k
        }
272
5.88k
        prep->next_buf_row = prep->next_buf_stop;
273
5.88k
      }
274
5.88k
    }
275
    /* If we've gotten enough data, downsample a row group. */
276
4.03M
    if (prep->next_buf_row == prep->next_buf_stop) {
277
#ifdef WITH_PROFILE
278
      cinfo->master->start = getTime();
279
#endif
280
2.10M
      (*cinfo->downsample->_downsample) (cinfo, prep->color_buf,
281
2.10M
                                         (JDIMENSION)prep->this_row_group,
282
2.10M
                                         output_buf, *out_row_group_ctr);
283
#ifdef WITH_PROFILE
284
      cinfo->master->downsample_elapsed += getTime() - cinfo->master->start;
285
      cinfo->master->downsample_msamples +=
286
        (double)cinfo->image_width * cinfo->max_v_samp_factor / 1000000.;
287
#endif
288
2.10M
      (*out_row_group_ctr)++;
289
      /* Advance pointers with wraparound as necessary. */
290
2.10M
      prep->this_row_group += cinfo->max_v_samp_factor;
291
2.10M
      if (prep->this_row_group >= buf_height)
292
701k
        prep->this_row_group = 0;
293
2.10M
      if (prep->next_buf_row >= buf_height)
294
702k
        prep->next_buf_row = 0;
295
2.10M
      prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
296
2.10M
    }
297
4.03M
  }
298
4.29M
}
Unexecuted instantiation: jcprepct-12.c:pre_process_context
Unexecuted instantiation: jcprepct-16.c:pre_process_context
299
300
301
/*
302
 * Create the wrapped-around downsampling input buffer needed for context mode.
303
 */
304
305
LOCAL(void)
306
create_context_buffer(j_compress_ptr cinfo)
307
3.60k
{
308
3.60k
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
309
3.60k
  int rgroup_height = cinfo->max_v_samp_factor;
310
3.60k
  int ci, i;
311
3.60k
  jpeg_component_info *compptr;
312
3.60k
  _JSAMPARRAY true_buffer, fake_buffer;
313
3.60k
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
314
315
  /* Grab enough space for fake row pointers for all the components;
316
   * we need five row groups' worth of pointers for each component.
317
   */
318
3.60k
  fake_buffer = (_JSAMPARRAY)
319
3.60k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
320
3.60k
                                (cinfo->num_components * 5 * rgroup_height) *
321
3.60k
                                sizeof(_JSAMPROW));
322
323
11.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
324
7.65k
       ci++, compptr++) {
325
    /* Allocate the actual buffer space (3 row groups) for this component.
326
     * We make the buffer wide enough to allow the downsampler to edge-expand
327
     * horizontally within the buffer, if it so chooses.
328
     */
329
7.65k
    true_buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
330
7.65k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
331
7.65k
       (JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
332
7.65k
                     cinfo->max_h_samp_factor) / compptr->h_samp_factor),
333
7.65k
       (JDIMENSION)(3 * rgroup_height));
334
    /* Copy true buffer row pointers into the middle of the fake row array */
335
7.65k
    memcpy(fake_buffer + rgroup_height, true_buffer,
336
7.65k
           3 * rgroup_height * sizeof(_JSAMPROW));
337
    /* Fill in the above and below wraparound pointers */
338
21.3k
    for (i = 0; i < rgroup_height; i++) {
339
13.7k
      fake_buffer[i] = true_buffer[2 * rgroup_height + i];
340
13.7k
      fake_buffer[4 * rgroup_height + i] = true_buffer[i];
341
13.7k
    }
342
7.65k
    prep->color_buf[ci] = fake_buffer + rgroup_height;
343
7.65k
    fake_buffer += 5 * rgroup_height; /* point to space for next component */
344
7.65k
  }
345
3.60k
}
jcprepct-8.c:create_context_buffer
Line
Count
Source
307
3.60k
{
308
3.60k
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
309
3.60k
  int rgroup_height = cinfo->max_v_samp_factor;
310
3.60k
  int ci, i;
311
3.60k
  jpeg_component_info *compptr;
312
3.60k
  _JSAMPARRAY true_buffer, fake_buffer;
313
3.60k
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
314
315
  /* Grab enough space for fake row pointers for all the components;
316
   * we need five row groups' worth of pointers for each component.
317
   */
318
3.60k
  fake_buffer = (_JSAMPARRAY)
319
3.60k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
320
3.60k
                                (cinfo->num_components * 5 * rgroup_height) *
321
3.60k
                                sizeof(_JSAMPROW));
322
323
11.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
324
7.65k
       ci++, compptr++) {
325
    /* Allocate the actual buffer space (3 row groups) for this component.
326
     * We make the buffer wide enough to allow the downsampler to edge-expand
327
     * horizontally within the buffer, if it so chooses.
328
     */
329
7.65k
    true_buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
330
7.65k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
331
7.65k
       (JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
332
7.65k
                     cinfo->max_h_samp_factor) / compptr->h_samp_factor),
333
7.65k
       (JDIMENSION)(3 * rgroup_height));
334
    /* Copy true buffer row pointers into the middle of the fake row array */
335
7.65k
    memcpy(fake_buffer + rgroup_height, true_buffer,
336
7.65k
           3 * rgroup_height * sizeof(_JSAMPROW));
337
    /* Fill in the above and below wraparound pointers */
338
21.3k
    for (i = 0; i < rgroup_height; i++) {
339
13.7k
      fake_buffer[i] = true_buffer[2 * rgroup_height + i];
340
13.7k
      fake_buffer[4 * rgroup_height + i] = true_buffer[i];
341
13.7k
    }
342
7.65k
    prep->color_buf[ci] = fake_buffer + rgroup_height;
343
7.65k
    fake_buffer += 5 * rgroup_height; /* point to space for next component */
344
7.65k
  }
345
3.60k
}
Unexecuted instantiation: jcprepct-12.c:create_context_buffer
Unexecuted instantiation: jcprepct-16.c:create_context_buffer
346
347
#endif /* CONTEXT_ROWS_SUPPORTED */
348
349
350
/*
351
 * Initialize preprocessing controller.
352
 */
353
354
GLOBAL(void)
355
_jinit_c_prep_controller(j_compress_ptr cinfo, boolean need_full_buffer)
356
158k
{
357
158k
  my_prep_ptr prep;
358
158k
  int ci;
359
158k
  jpeg_component_info *compptr;
360
158k
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
361
362
158k
#ifdef C_LOSSLESS_SUPPORTED
363
158k
  if (cinfo->master->lossless) {
364
#if BITS_IN_JSAMPLE == 8
365
29.1k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
366
#else
367
42.9k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
368
42.9k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
369
0
#endif
370
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
371
72.0k
  } else
372
86.3k
#endif
373
86.3k
  {
374
86.3k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
375
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
376
86.3k
  }
377
378
158k
  if (need_full_buffer)         /* safety check */
379
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
380
381
158k
  prep = (my_prep_ptr)
382
158k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
383
158k
                                sizeof(my_prep_controller));
384
158k
  cinfo->prep = (struct jpeg_c_prep_controller *)prep;
385
158k
  prep->pub.start_pass = start_pass_prep;
386
387
  /* Allocate the color conversion buffer.
388
   * We make the buffer wide enough to allow the downsampler to edge-expand
389
   * horizontally within the buffer, if it so chooses.
390
   */
391
158k
  if (cinfo->downsample->need_context_rows) {
392
    /* Set up to provide context rows */
393
3.60k
#ifdef CONTEXT_ROWS_SUPPORTED
394
3.60k
    prep->pub._pre_process_data = pre_process_context;
395
3.60k
    create_context_buffer(cinfo);
396
#else
397
    ERREXIT(cinfo, JERR_NOT_COMPILED);
398
#endif
399
154k
  } else {
400
    /* No context, just make it tall enough for one row group */
401
154k
    prep->pub._pre_process_data = pre_process_data;
402
563k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
408k
         ci++, compptr++) {
404
408k
      prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
405
408k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
406
408k
         (JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
407
408k
                       cinfo->max_h_samp_factor) / compptr->h_samp_factor),
408
408k
         (JDIMENSION)cinfo->max_v_samp_factor);
409
408k
    }
410
154k
  }
411
158k
}
jinit_c_prep_controller
Line
Count
Source
356
79.3k
{
357
79.3k
  my_prep_ptr prep;
358
79.3k
  int ci;
359
79.3k
  jpeg_component_info *compptr;
360
79.3k
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
361
362
79.3k
#ifdef C_LOSSLESS_SUPPORTED
363
79.3k
  if (cinfo->master->lossless) {
364
29.1k
#if BITS_IN_JSAMPLE == 8
365
29.1k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
366
#else
367
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
368
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
369
#endif
370
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
371
29.1k
  } else
372
50.2k
#endif
373
50.2k
  {
374
50.2k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
375
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
376
50.2k
  }
377
378
79.3k
  if (need_full_buffer)         /* safety check */
379
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
380
381
79.3k
  prep = (my_prep_ptr)
382
79.3k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
383
79.3k
                                sizeof(my_prep_controller));
384
79.3k
  cinfo->prep = (struct jpeg_c_prep_controller *)prep;
385
79.3k
  prep->pub.start_pass = start_pass_prep;
386
387
  /* Allocate the color conversion buffer.
388
   * We make the buffer wide enough to allow the downsampler to edge-expand
389
   * horizontally within the buffer, if it so chooses.
390
   */
391
79.3k
  if (cinfo->downsample->need_context_rows) {
392
    /* Set up to provide context rows */
393
3.60k
#ifdef CONTEXT_ROWS_SUPPORTED
394
3.60k
    prep->pub._pre_process_data = pre_process_context;
395
3.60k
    create_context_buffer(cinfo);
396
#else
397
    ERREXIT(cinfo, JERR_NOT_COMPILED);
398
#endif
399
75.7k
  } else {
400
    /* No context, just make it tall enough for one row group */
401
75.7k
    prep->pub._pre_process_data = pre_process_data;
402
272k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
196k
         ci++, compptr++) {
404
196k
      prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
405
196k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
406
196k
         (JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
407
196k
                       cinfo->max_h_samp_factor) / compptr->h_samp_factor),
408
196k
         (JDIMENSION)cinfo->max_v_samp_factor);
409
196k
    }
410
75.7k
  }
411
79.3k
}
j12init_c_prep_controller
Line
Count
Source
356
57.8k
{
357
57.8k
  my_prep_ptr prep;
358
57.8k
  int ci;
359
57.8k
  jpeg_component_info *compptr;
360
57.8k
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
361
362
57.8k
#ifdef C_LOSSLESS_SUPPORTED
363
57.8k
  if (cinfo->master->lossless) {
364
#if BITS_IN_JSAMPLE == 8
365
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
366
#else
367
21.7k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
368
21.7k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
369
0
#endif
370
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
371
21.7k
  } else
372
36.0k
#endif
373
36.0k
  {
374
36.0k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
375
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
376
36.0k
  }
377
378
57.8k
  if (need_full_buffer)         /* safety check */
379
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
380
381
57.8k
  prep = (my_prep_ptr)
382
57.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
383
57.8k
                                sizeof(my_prep_controller));
384
57.8k
  cinfo->prep = (struct jpeg_c_prep_controller *)prep;
385
57.8k
  prep->pub.start_pass = start_pass_prep;
386
387
  /* Allocate the color conversion buffer.
388
   * We make the buffer wide enough to allow the downsampler to edge-expand
389
   * horizontally within the buffer, if it so chooses.
390
   */
391
57.8k
  if (cinfo->downsample->need_context_rows) {
392
    /* Set up to provide context rows */
393
0
#ifdef CONTEXT_ROWS_SUPPORTED
394
0
    prep->pub._pre_process_data = pre_process_context;
395
0
    create_context_buffer(cinfo);
396
#else
397
    ERREXIT(cinfo, JERR_NOT_COMPILED);
398
#endif
399
57.8k
  } else {
400
    /* No context, just make it tall enough for one row group */
401
57.8k
    prep->pub._pre_process_data = pre_process_data;
402
210k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
152k
         ci++, compptr++) {
404
152k
      prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
405
152k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
406
152k
         (JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
407
152k
                       cinfo->max_h_samp_factor) / compptr->h_samp_factor),
408
152k
         (JDIMENSION)cinfo->max_v_samp_factor);
409
152k
    }
410
57.8k
  }
411
57.8k
}
j16init_c_prep_controller
Line
Count
Source
356
21.1k
{
357
21.1k
  my_prep_ptr prep;
358
21.1k
  int ci;
359
21.1k
  jpeg_component_info *compptr;
360
21.1k
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
361
362
21.1k
#ifdef C_LOSSLESS_SUPPORTED
363
21.1k
  if (cinfo->master->lossless) {
364
#if BITS_IN_JSAMPLE == 8
365
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
366
#else
367
21.1k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
368
21.1k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
369
0
#endif
370
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
371
21.1k
  } else
372
0
#endif
373
0
  {
374
0
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
375
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
376
0
  }
377
378
21.1k
  if (need_full_buffer)         /* safety check */
379
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
380
381
21.1k
  prep = (my_prep_ptr)
382
21.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
383
21.1k
                                sizeof(my_prep_controller));
384
21.1k
  cinfo->prep = (struct jpeg_c_prep_controller *)prep;
385
21.1k
  prep->pub.start_pass = start_pass_prep;
386
387
  /* Allocate the color conversion buffer.
388
   * We make the buffer wide enough to allow the downsampler to edge-expand
389
   * horizontally within the buffer, if it so chooses.
390
   */
391
21.1k
  if (cinfo->downsample->need_context_rows) {
392
    /* Set up to provide context rows */
393
0
#ifdef CONTEXT_ROWS_SUPPORTED
394
0
    prep->pub._pre_process_data = pre_process_context;
395
0
    create_context_buffer(cinfo);
396
#else
397
    ERREXIT(cinfo, JERR_NOT_COMPILED);
398
#endif
399
21.1k
  } else {
400
    /* No context, just make it tall enough for one row group */
401
21.1k
    prep->pub._pre_process_data = pre_process_data;
402
80.3k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
59.1k
         ci++, compptr++) {
404
59.1k
      prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
405
59.1k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
406
59.1k
         (JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
407
59.1k
                       cinfo->max_h_samp_factor) / compptr->h_samp_factor),
408
59.1k
         (JDIMENSION)cinfo->max_v_samp_factor);
409
59.1k
    }
410
21.1k
  }
411
21.1k
}
412
413
#endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */