Coverage Report

Created: 2026-07-30 07:40

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
78.8k
{
91
78.8k
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
92
93
78.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
78.8k
  prep->rows_to_go = cinfo->image_height;
98
  /* Mark the conversion buffer empty */
99
78.8k
  prep->next_buf_row = 0;
100
78.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
78.8k
  prep->this_row_group = 0;
105
  /* Set next_buf_stop to stop after two row groups have been read in. */
106
78.8k
  prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
107
78.8k
#endif
108
78.8k
}
jcprepct-12.c:start_pass_prep
Line
Count
Source
90
58.8k
{
91
58.8k
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
92
93
58.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
58.8k
  prep->rows_to_go = cinfo->image_height;
98
  /* Mark the conversion buffer empty */
99
58.8k
  prep->next_buf_row = 0;
100
58.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
58.8k
  prep->this_row_group = 0;
105
  /* Set next_buf_stop to stop after two row groups have been read in. */
106
58.8k
  prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
107
58.8k
#endif
108
58.8k
}
jcprepct-16.c:start_pass_prep
Line
Count
Source
90
20.9k
{
91
20.9k
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
92
93
20.9k
  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
20.9k
  prep->rows_to_go = cinfo->image_height;
98
  /* Mark the conversion buffer empty */
99
20.9k
  prep->next_buf_row = 0;
100
20.9k
#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
20.9k
  prep->this_row_group = 0;
105
  /* Set next_buf_stop to stop after two row groups have been read in. */
106
20.9k
  prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
107
20.9k
#endif
108
20.9k
}
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
197k
{
120
197k
  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
197k
}
jcprepct-8.c:expand_bottom_edge
Line
Count
Source
119
111k
{
120
111k
  register int row;
121
122
674k
  for (row = input_rows; row < output_rows; row++) {
123
562k
    _jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1,
124
562k
                       num_cols);
125
562k
  }
126
111k
}
jcprepct-12.c:expand_bottom_edge
Line
Count
Source
119
86.1k
{
120
86.1k
  register int row;
121
122
543k
  for (row = input_rows; row < output_rows; row++) {
123
456k
    _jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1,
124
456k
                       num_cols);
125
456k
  }
126
86.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
109M
{
144
109M
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
145
109M
  int numrows, ci;
146
109M
  JDIMENSION inrows;
147
109M
  jpeg_component_info *compptr;
148
109M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
149
150
317M
  while (*in_row_ctr < in_rows_avail &&
151
313M
         *out_row_group_ctr < out_row_groups_avail) {
152
    /* Do color conversion to fill the conversion buffer. */
153
208M
    inrows = in_rows_avail - *in_row_ctr;
154
208M
    numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
155
208M
    numrows = (int)MIN((JDIMENSION)numrows, inrows);
156
#ifdef WITH_PROFILE
157
    cinfo->master->start = getTime();
158
#endif
159
208M
    (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
160
208M
                                        prep->color_buf,
161
208M
                                        (JDIMENSION)prep->next_buf_row,
162
208M
                                        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
208M
    *in_row_ctr += numrows;
169
208M
    prep->next_buf_row += numrows;
170
208M
    prep->rows_to_go -= numrows;
171
    /* If at bottom of image, pad to fill the conversion buffer. */
172
208M
    if (prep->rows_to_go == 0 &&
173
152k
        prep->next_buf_row < cinfo->max_v_samp_factor) {
174
39.7k
      for (ci = 0; ci < cinfo->num_components; ci++) {
175
30.8k
        expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
176
30.8k
                           prep->next_buf_row, cinfo->max_v_samp_factor);
177
30.8k
      }
178
8.85k
      prep->next_buf_row = cinfo->max_v_samp_factor;
179
8.85k
    }
180
    /* If we've filled the conversion buffer, empty it. */
181
208M
    if (prep->next_buf_row == cinfo->max_v_samp_factor) {
182
#ifdef WITH_PROFILE
183
      cinfo->master->start = getTime();
184
#endif
185
206M
      (*cinfo->downsample->_downsample) (cinfo,
186
206M
                                         prep->color_buf, (JDIMENSION)0,
187
206M
                                         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
206M
      prep->next_buf_row = 0;
194
206M
      (*out_row_group_ctr)++;
195
206M
    }
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
208M
    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
155k
           ci++, compptr++) {
202
155k
        expand_bottom_edge(output_buf[ci],
203
155k
                           compptr->width_in_blocks * data_unit,
204
155k
                           (int)(*out_row_group_ctr * compptr->v_samp_factor),
205
155k
                           (int)(out_row_groups_avail * compptr->v_samp_factor));
206
155k
      }
207
57.8k
      *out_row_group_ctr = out_row_groups_avail;
208
57.8k
      break;                    /* can exit outer loop without test */
209
57.8k
    }
210
208M
  }
211
109M
}
jcprepct-8.c:pre_process_data
Line
Count
Source
143
38.5M
{
144
38.5M
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
145
38.5M
  int numrows, ci;
146
38.5M
  JDIMENSION inrows;
147
38.5M
  jpeg_component_info *compptr;
148
38.5M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
149
150
119M
  while (*in_row_ctr < in_rows_avail &&
151
115M
         *out_row_group_ctr < out_row_groups_avail) {
152
    /* Do color conversion to fill the conversion buffer. */
153
81.4M
    inrows = in_rows_avail - *in_row_ctr;
154
81.4M
    numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
155
81.4M
    numrows = (int)MIN((JDIMENSION)numrows, inrows);
156
#ifdef WITH_PROFILE
157
    cinfo->master->start = getTime();
158
#endif
159
81.4M
    (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
160
81.4M
                                        prep->color_buf,
161
81.4M
                                        (JDIMENSION)prep->next_buf_row,
162
81.4M
                                        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
81.4M
    *in_row_ctr += numrows;
169
81.4M
    prep->next_buf_row += numrows;
170
81.4M
    prep->rows_to_go -= numrows;
171
    /* If at bottom of image, pad to fill the conversion buffer. */
172
81.4M
    if (prep->rows_to_go == 0 &&
173
72.5k
        prep->next_buf_row < cinfo->max_v_samp_factor) {
174
20.4k
      for (ci = 0; ci < cinfo->num_components; ci++) {
175
15.8k
        expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
176
15.8k
                           prep->next_buf_row, cinfo->max_v_samp_factor);
177
15.8k
      }
178
4.56k
      prep->next_buf_row = cinfo->max_v_samp_factor;
179
4.56k
    }
180
    /* If we've filled the conversion buffer, empty it. */
181
81.4M
    if (prep->next_buf_row == cinfo->max_v_samp_factor) {
182
#ifdef WITH_PROFILE
183
      cinfo->master->start = getTime();
184
#endif
185
79.5M
      (*cinfo->downsample->_downsample) (cinfo,
186
79.5M
                                         prep->color_buf, (JDIMENSION)0,
187
79.5M
                                         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
79.5M
      prep->next_buf_row = 0;
194
79.5M
      (*out_row_group_ctr)++;
195
79.5M
    }
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
81.4M
    if (prep->rows_to_go == 0 && *out_row_group_ctr < out_row_groups_avail) {
200
115k
      for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
201
84.0k
           ci++, compptr++) {
202
84.0k
        expand_bottom_edge(output_buf[ci],
203
84.0k
                           compptr->width_in_blocks * data_unit,
204
84.0k
                           (int)(*out_row_group_ctr * compptr->v_samp_factor),
205
84.0k
                           (int)(out_row_groups_avail * compptr->v_samp_factor));
206
84.0k
      }
207
31.3k
      *out_row_group_ctr = out_row_groups_avail;
208
31.3k
      break;                    /* can exit outer loop without test */
209
31.3k
    }
210
81.4M
  }
211
38.5M
}
jcprepct-12.c:pre_process_data
Line
Count
Source
143
38.8M
{
144
38.8M
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
145
38.8M
  int numrows, ci;
146
38.8M
  JDIMENSION inrows;
147
38.8M
  jpeg_component_info *compptr;
148
38.8M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
149
150
133M
  while (*in_row_ctr < in_rows_avail &&
151
133M
         *out_row_group_ctr < out_row_groups_avail) {
152
    /* Do color conversion to fill the conversion buffer. */
153
95.0M
    inrows = in_rows_avail - *in_row_ctr;
154
95.0M
    numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
155
95.0M
    numrows = (int)MIN((JDIMENSION)numrows, inrows);
156
#ifdef WITH_PROFILE
157
    cinfo->master->start = getTime();
158
#endif
159
95.0M
    (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
160
95.0M
                                        prep->color_buf,
161
95.0M
                                        (JDIMENSION)prep->next_buf_row,
162
95.0M
                                        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
95.0M
    *in_row_ctr += numrows;
169
95.0M
    prep->next_buf_row += numrows;
170
95.0M
    prep->rows_to_go -= numrows;
171
    /* If at bottom of image, pad to fill the conversion buffer. */
172
95.0M
    if (prep->rows_to_go == 0 &&
173
58.8k
        prep->next_buf_row < cinfo->max_v_samp_factor) {
174
19.3k
      for (ci = 0; ci < cinfo->num_components; ci++) {
175
15.0k
        expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
176
15.0k
                           prep->next_buf_row, cinfo->max_v_samp_factor);
177
15.0k
      }
178
4.29k
      prep->next_buf_row = cinfo->max_v_samp_factor;
179
4.29k
    }
180
    /* If we've filled the conversion buffer, empty it. */
181
95.0M
    if (prep->next_buf_row == cinfo->max_v_samp_factor) {
182
#ifdef WITH_PROFILE
183
      cinfo->master->start = getTime();
184
#endif
185
95.0M
      (*cinfo->downsample->_downsample) (cinfo,
186
95.0M
                                         prep->color_buf, (JDIMENSION)0,
187
95.0M
                                         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
95.0M
      prep->next_buf_row = 0;
194
95.0M
      (*out_row_group_ctr)++;
195
95.0M
    }
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
95.0M
    if (prep->rows_to_go == 0 && *out_row_group_ctr < out_row_groups_avail) {
200
97.6k
      for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
201
71.1k
           ci++, compptr++) {
202
71.1k
        expand_bottom_edge(output_buf[ci],
203
71.1k
                           compptr->width_in_blocks * data_unit,
204
71.1k
                           (int)(*out_row_group_ctr * compptr->v_samp_factor),
205
71.1k
                           (int)(out_row_groups_avail * compptr->v_samp_factor));
206
71.1k
      }
207
26.5k
      *out_row_group_ctr = out_row_groups_avail;
208
26.5k
      break;                    /* can exit outer loop without test */
209
26.5k
    }
210
95.0M
  }
211
38.8M
}
jcprepct-16.c:pre_process_data
Line
Count
Source
143
32.0M
{
144
32.0M
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
145
32.0M
  int numrows, ci;
146
32.0M
  JDIMENSION inrows;
147
32.0M
  jpeg_component_info *compptr;
148
32.0M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
149
150
64.0M
  while (*in_row_ctr < in_rows_avail &&
151
64.0M
         *out_row_group_ctr < out_row_groups_avail) {
152
    /* Do color conversion to fill the conversion buffer. */
153
32.0M
    inrows = in_rows_avail - *in_row_ctr;
154
32.0M
    numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
155
32.0M
    numrows = (int)MIN((JDIMENSION)numrows, inrows);
156
#ifdef WITH_PROFILE
157
    cinfo->master->start = getTime();
158
#endif
159
32.0M
    (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
160
32.0M
                                        prep->color_buf,
161
32.0M
                                        (JDIMENSION)prep->next_buf_row,
162
32.0M
                                        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
32.0M
    *in_row_ctr += numrows;
169
32.0M
    prep->next_buf_row += numrows;
170
32.0M
    prep->rows_to_go -= numrows;
171
    /* If at bottom of image, pad to fill the conversion buffer. */
172
32.0M
    if (prep->rows_to_go == 0 &&
173
20.9k
        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
32.0M
    if (prep->next_buf_row == cinfo->max_v_samp_factor) {
182
#ifdef WITH_PROFILE
183
      cinfo->master->start = getTime();
184
#endif
185
32.0M
      (*cinfo->downsample->_downsample) (cinfo,
186
32.0M
                                         prep->color_buf, (JDIMENSION)0,
187
32.0M
                                         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
32.0M
      prep->next_buf_row = 0;
194
32.0M
      (*out_row_group_ctr)++;
195
32.0M
    }
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
32.0M
    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
32.0M
  }
211
32.0M
}
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.42M
{
226
4.42M
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
227
4.42M
  int numrows, ci;
228
4.42M
  int buf_height = cinfo->max_v_samp_factor * 3;
229
4.42M
  JDIMENSION inrows;
230
231
8.58M
  while (*out_row_group_ctr < out_row_groups_avail) {
232
8.31M
    if (*in_row_ctr < in_rows_avail) {
233
      /* Do color conversion to fill the conversion buffer. */
234
4.15M
      inrows = in_rows_avail - *in_row_ctr;
235
4.15M
      numrows = prep->next_buf_stop - prep->next_buf_row;
236
4.15M
      numrows = (int)MIN((JDIMENSION)numrows, inrows);
237
#ifdef WITH_PROFILE
238
      cinfo->master->start = getTime();
239
#endif
240
4.15M
      (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
241
4.15M
                                          prep->color_buf,
242
4.15M
                                          (JDIMENSION)prep->next_buf_row,
243
4.15M
                                          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.15M
      if (prep->rows_to_go == cinfo->image_height) {
251
5.25k
        for (ci = 0; ci < cinfo->num_components; ci++) {
252
3.48k
          int row;
253
9.51k
          for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
254
6.03k
            _jcopy_sample_rows(prep->color_buf[ci], 0, prep->color_buf[ci],
255
6.03k
                               -row, 1, cinfo->image_width);
256
6.03k
          }
257
3.48k
        }
258
1.77k
      }
259
4.15M
      *in_row_ctr += numrows;
260
4.15M
      prep->next_buf_row += numrows;
261
4.15M
      prep->rows_to_go -= numrows;
262
4.15M
    } else {
263
      /* Return for more data, unless we are at the bottom of the image. */
264
4.15M
      if (prep->rows_to_go != 0)
265
4.15M
        break;
266
      /* When at bottom of image, pad to fill the conversion buffer. */
267
5.97k
      if (prep->next_buf_row < prep->next_buf_stop) {
268
17.3k
        for (ci = 0; ci < cinfo->num_components; ci++) {
269
11.3k
          expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
270
11.3k
                             prep->next_buf_row, prep->next_buf_stop);
271
11.3k
        }
272
5.97k
        prep->next_buf_row = prep->next_buf_stop;
273
5.97k
      }
274
5.97k
    }
275
    /* If we've gotten enough data, downsample a row group. */
276
4.16M
    if (prep->next_buf_row == prep->next_buf_stop) {
277
#ifdef WITH_PROFILE
278
      cinfo->master->start = getTime();
279
#endif
280
2.19M
      (*cinfo->downsample->_downsample) (cinfo, prep->color_buf,
281
2.19M
                                         (JDIMENSION)prep->this_row_group,
282
2.19M
                                         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.19M
      (*out_row_group_ctr)++;
289
      /* Advance pointers with wraparound as necessary. */
290
2.19M
      prep->this_row_group += cinfo->max_v_samp_factor;
291
2.19M
      if (prep->this_row_group >= buf_height)
292
729k
        prep->this_row_group = 0;
293
2.19M
      if (prep->next_buf_row >= buf_height)
294
730k
        prep->next_buf_row = 0;
295
2.19M
      prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
296
2.19M
    }
297
4.16M
  }
298
4.42M
}
jcprepct-8.c:pre_process_context
Line
Count
Source
225
4.42M
{
226
4.42M
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
227
4.42M
  int numrows, ci;
228
4.42M
  int buf_height = cinfo->max_v_samp_factor * 3;
229
4.42M
  JDIMENSION inrows;
230
231
8.58M
  while (*out_row_group_ctr < out_row_groups_avail) {
232
8.31M
    if (*in_row_ctr < in_rows_avail) {
233
      /* Do color conversion to fill the conversion buffer. */
234
4.15M
      inrows = in_rows_avail - *in_row_ctr;
235
4.15M
      numrows = prep->next_buf_stop - prep->next_buf_row;
236
4.15M
      numrows = (int)MIN((JDIMENSION)numrows, inrows);
237
#ifdef WITH_PROFILE
238
      cinfo->master->start = getTime();
239
#endif
240
4.15M
      (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
241
4.15M
                                          prep->color_buf,
242
4.15M
                                          (JDIMENSION)prep->next_buf_row,
243
4.15M
                                          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.15M
      if (prep->rows_to_go == cinfo->image_height) {
251
5.25k
        for (ci = 0; ci < cinfo->num_components; ci++) {
252
3.48k
          int row;
253
9.51k
          for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
254
6.03k
            _jcopy_sample_rows(prep->color_buf[ci], 0, prep->color_buf[ci],
255
6.03k
                               -row, 1, cinfo->image_width);
256
6.03k
          }
257
3.48k
        }
258
1.77k
      }
259
4.15M
      *in_row_ctr += numrows;
260
4.15M
      prep->next_buf_row += numrows;
261
4.15M
      prep->rows_to_go -= numrows;
262
4.15M
    } else {
263
      /* Return for more data, unless we are at the bottom of the image. */
264
4.15M
      if (prep->rows_to_go != 0)
265
4.15M
        break;
266
      /* When at bottom of image, pad to fill the conversion buffer. */
267
5.97k
      if (prep->next_buf_row < prep->next_buf_stop) {
268
17.3k
        for (ci = 0; ci < cinfo->num_components; ci++) {
269
11.3k
          expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
270
11.3k
                             prep->next_buf_row, prep->next_buf_stop);
271
11.3k
        }
272
5.97k
        prep->next_buf_row = prep->next_buf_stop;
273
5.97k
      }
274
5.97k
    }
275
    /* If we've gotten enough data, downsample a row group. */
276
4.16M
    if (prep->next_buf_row == prep->next_buf_stop) {
277
#ifdef WITH_PROFILE
278
      cinfo->master->start = getTime();
279
#endif
280
2.19M
      (*cinfo->downsample->_downsample) (cinfo, prep->color_buf,
281
2.19M
                                         (JDIMENSION)prep->this_row_group,
282
2.19M
                                         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.19M
      (*out_row_group_ctr)++;
289
      /* Advance pointers with wraparound as necessary. */
290
2.19M
      prep->this_row_group += cinfo->max_v_samp_factor;
291
2.19M
      if (prep->this_row_group >= buf_height)
292
729k
        prep->this_row_group = 0;
293
2.19M
      if (prep->next_buf_row >= buf_height)
294
730k
        prep->next_buf_row = 0;
295
2.19M
      prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
296
2.19M
    }
297
4.16M
  }
298
4.42M
}
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.59k
{
308
3.59k
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
309
3.59k
  int rgroup_height = cinfo->max_v_samp_factor;
310
3.59k
  int ci, i;
311
3.59k
  jpeg_component_info *compptr;
312
3.59k
  _JSAMPARRAY true_buffer, fake_buffer;
313
3.59k
  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.59k
  fake_buffer = (_JSAMPARRAY)
319
3.59k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
320
3.59k
                                (cinfo->num_components * 5 * rgroup_height) *
321
3.59k
                                sizeof(_JSAMPROW));
322
323
11.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
324
7.67k
       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.67k
    true_buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
330
7.67k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
331
7.67k
       (JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
332
7.67k
                     cinfo->max_h_samp_factor) / compptr->h_samp_factor),
333
7.67k
       (JDIMENSION)(3 * rgroup_height));
334
    /* Copy true buffer row pointers into the middle of the fake row array */
335
7.67k
    memcpy(fake_buffer + rgroup_height, true_buffer,
336
7.67k
           3 * rgroup_height * sizeof(_JSAMPROW));
337
    /* Fill in the above and below wraparound pointers */
338
21.4k
    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.67k
    prep->color_buf[ci] = fake_buffer + rgroup_height;
343
7.67k
    fake_buffer += 5 * rgroup_height; /* point to space for next component */
344
7.67k
  }
345
3.59k
}
jcprepct-8.c:create_context_buffer
Line
Count
Source
307
3.59k
{
308
3.59k
  my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
309
3.59k
  int rgroup_height = cinfo->max_v_samp_factor;
310
3.59k
  int ci, i;
311
3.59k
  jpeg_component_info *compptr;
312
3.59k
  _JSAMPARRAY true_buffer, fake_buffer;
313
3.59k
  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.59k
  fake_buffer = (_JSAMPARRAY)
319
3.59k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
320
3.59k
                                (cinfo->num_components * 5 * rgroup_height) *
321
3.59k
                                sizeof(_JSAMPROW));
322
323
11.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
324
7.67k
       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.67k
    true_buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
330
7.67k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
331
7.67k
       (JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
332
7.67k
                     cinfo->max_h_samp_factor) / compptr->h_samp_factor),
333
7.67k
       (JDIMENSION)(3 * rgroup_height));
334
    /* Copy true buffer row pointers into the middle of the fake row array */
335
7.67k
    memcpy(fake_buffer + rgroup_height, true_buffer,
336
7.67k
           3 * rgroup_height * sizeof(_JSAMPROW));
337
    /* Fill in the above and below wraparound pointers */
338
21.4k
    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.67k
    prep->color_buf[ci] = fake_buffer + rgroup_height;
343
7.67k
    fake_buffer += 5 * rgroup_height; /* point to space for next component */
344
7.67k
  }
345
3.59k
}
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
28.9k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
366
#else
367
43.3k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
368
43.3k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
369
0
#endif
370
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
371
72.3k
  } 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.59k
#ifdef CONTEXT_ROWS_SUPPORTED
394
3.59k
    prep->pub._pre_process_data = pre_process_context;
395
3.59k
    create_context_buffer(cinfo);
396
#else
397
    ERREXIT(cinfo, JERR_NOT_COMPILED);
398
#endif
399
155k
  } else {
400
    /* No context, just make it tall enough for one row group */
401
155k
    prep->pub._pre_process_data = pre_process_data;
402
564k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
409k
         ci++, compptr++) {
404
409k
      prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
405
409k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
406
409k
         (JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
407
409k
                       cinfo->max_h_samp_factor) / compptr->h_samp_factor),
408
409k
         (JDIMENSION)cinfo->max_v_samp_factor);
409
409k
    }
410
155k
  }
411
158k
}
jinit_c_prep_controller
Line
Count
Source
356
78.8k
{
357
78.8k
  my_prep_ptr prep;
358
78.8k
  int ci;
359
78.8k
  jpeg_component_info *compptr;
360
78.8k
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
361
362
78.8k
#ifdef C_LOSSLESS_SUPPORTED
363
78.8k
  if (cinfo->master->lossless) {
364
28.9k
#if BITS_IN_JSAMPLE == 8
365
28.9k
    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
28.9k
  } else
372
49.8k
#endif
373
49.8k
  {
374
49.8k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
375
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
376
49.8k
  }
377
378
78.8k
  if (need_full_buffer)         /* safety check */
379
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
380
381
78.8k
  prep = (my_prep_ptr)
382
78.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
383
78.8k
                                sizeof(my_prep_controller));
384
78.8k
  cinfo->prep = (struct jpeg_c_prep_controller *)prep;
385
78.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
78.8k
  if (cinfo->downsample->need_context_rows) {
392
    /* Set up to provide context rows */
393
3.59k
#ifdef CONTEXT_ROWS_SUPPORTED
394
3.59k
    prep->pub._pre_process_data = pre_process_context;
395
3.59k
    create_context_buffer(cinfo);
396
#else
397
    ERREXIT(cinfo, JERR_NOT_COMPILED);
398
#endif
399
75.2k
  } else {
400
    /* No context, just make it tall enough for one row group */
401
75.2k
    prep->pub._pre_process_data = pre_process_data;
402
270k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
195k
         ci++, compptr++) {
404
195k
      prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
405
195k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
406
195k
         (JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
407
195k
                       cinfo->max_h_samp_factor) / compptr->h_samp_factor),
408
195k
         (JDIMENSION)cinfo->max_v_samp_factor);
409
195k
    }
410
75.2k
  }
411
78.8k
}
j12init_c_prep_controller
Line
Count
Source
356
58.8k
{
357
58.8k
  my_prep_ptr prep;
358
58.8k
  int ci;
359
58.8k
  jpeg_component_info *compptr;
360
58.8k
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
361
362
58.8k
#ifdef C_LOSSLESS_SUPPORTED
363
58.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
22.4k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
368
22.4k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
369
0
#endif
370
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
371
22.4k
  } else
372
36.4k
#endif
373
36.4k
  {
374
36.4k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
375
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
376
36.4k
  }
377
378
58.8k
  if (need_full_buffer)         /* safety check */
379
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
380
381
58.8k
  prep = (my_prep_ptr)
382
58.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
383
58.8k
                                sizeof(my_prep_controller));
384
58.8k
  cinfo->prep = (struct jpeg_c_prep_controller *)prep;
385
58.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
58.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
58.8k
  } else {
400
    /* No context, just make it tall enough for one row group */
401
58.8k
    prep->pub._pre_process_data = pre_process_data;
402
214k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
155k
         ci++, compptr++) {
404
155k
      prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
405
155k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
406
155k
         (JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
407
155k
                       cinfo->max_h_samp_factor) / compptr->h_samp_factor),
408
155k
         (JDIMENSION)cinfo->max_v_samp_factor);
409
155k
    }
410
58.8k
  }
411
58.8k
}
j16init_c_prep_controller
Line
Count
Source
356
20.9k
{
357
20.9k
  my_prep_ptr prep;
358
20.9k
  int ci;
359
20.9k
  jpeg_component_info *compptr;
360
20.9k
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
361
362
20.9k
#ifdef C_LOSSLESS_SUPPORTED
363
20.9k
  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
20.9k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
368
20.9k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
369
0
#endif
370
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
371
20.9k
  } 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
20.9k
  if (need_full_buffer)         /* safety check */
379
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
380
381
20.9k
  prep = (my_prep_ptr)
382
20.9k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
383
20.9k
                                sizeof(my_prep_controller));
384
20.9k
  cinfo->prep = (struct jpeg_c_prep_controller *)prep;
385
20.9k
  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
20.9k
  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
20.9k
  } else {
400
    /* No context, just make it tall enough for one row group */
401
20.9k
    prep->pub._pre_process_data = pre_process_data;
402
79.5k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
58.5k
         ci++, compptr++) {
404
58.5k
      prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
405
58.5k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
406
58.5k
         (JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
407
58.5k
                       cinfo->max_h_samp_factor) / compptr->h_samp_factor),
408
58.5k
         (JDIMENSION)cinfo->max_v_samp_factor);
409
58.5k
    }
410
20.9k
  }
411
20.9k
}
412
413
#endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */