Coverage Report

Created: 2026-07-16 07:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.3.1.x/src/jcdiffct.c
Line
Count
Source
1
/*
2
 * jcdiffct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 2024, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the difference buffer controller for compression.
14
 * This controller is the top level of the lossless JPEG compressor proper.
15
 * The difference buffer lies between the prediction/differencing and entropy
16
 * encoding steps.
17
 */
18
19
#define JPEG_INTERNALS
20
#include "jinclude.h"
21
#include "jpeglib.h"
22
#include "jlossls.h"            /* Private declarations for lossless codec */
23
24
25
#ifdef C_LOSSLESS_SUPPORTED
26
27
/* We use a full-image sample buffer when doing Huffman optimization,
28
 * and also for writing multiple-scan JPEG files.  In all cases, the
29
 * full-image buffer is filled during the first pass, and the scaling,
30
 * prediction and differencing steps are run during subsequent passes.
31
 */
32
#ifdef ENTROPY_OPT_SUPPORTED
33
#define FULL_SAMP_BUFFER_SUPPORTED
34
#else
35
#ifdef C_MULTISCAN_FILES_SUPPORTED
36
#define FULL_SAMP_BUFFER_SUPPORTED
37
#endif
38
#endif
39
40
41
/* Private buffer controller object */
42
43
typedef struct {
44
  struct jpeg_c_coef_controller pub; /* public fields */
45
46
  JDIMENSION iMCU_row_num;      /* iMCU row # within image */
47
  JDIMENSION mcu_ctr;           /* counts MCUs processed in current row */
48
  int MCU_vert_offset;          /* counts MCU rows within iMCU row */
49
  int MCU_rows_per_iMCU_row;    /* number of such rows needed */
50
51
  _JSAMPROW cur_row[MAX_COMPONENTS];    /* row of point-transformed samples */
52
  _JSAMPROW prev_row[MAX_COMPONENTS];   /* previous row of Pt'd samples */
53
  JDIFFARRAY diff_buf[MAX_COMPONENTS];  /* iMCU row of differences */
54
55
  /* In multi-pass modes, we need a virtual sample array for each component. */
56
  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
57
} my_diff_controller;
58
59
typedef my_diff_controller *my_diff_ptr;
60
61
62
/* Forward declarations */
63
METHODDEF(boolean) compress_data(j_compress_ptr cinfo, _JSAMPIMAGE input_buf);
64
#ifdef FULL_SAMP_BUFFER_SUPPORTED
65
METHODDEF(boolean) compress_first_pass(j_compress_ptr cinfo,
66
                                       _JSAMPIMAGE input_buf);
67
METHODDEF(boolean) compress_output(j_compress_ptr cinfo,
68
                                   _JSAMPIMAGE input_buf);
69
#endif
70
71
72
LOCAL(void)
73
start_iMCU_row(j_compress_ptr cinfo)
74
/* Reset within-iMCU-row counters for a new row */
75
190M
{
76
190M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
77
78
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
79
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
80
   * But at the bottom of the image, process only what's left.
81
   */
82
190M
  if (cinfo->comps_in_scan > 1) {
83
165M
    diff->MCU_rows_per_iMCU_row = 1;
84
165M
  } else {
85
24.8M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
24.8M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
52.0k
    else
88
52.0k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
24.8M
  }
90
91
190M
  diff->mcu_ctr = 0;
92
190M
  diff->MCU_vert_offset = 0;
93
190M
}
jcdiffct-8.c:start_iMCU_row
Line
Count
Source
75
61.4M
{
76
61.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
77
78
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
79
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
80
   * But at the bottom of the image, process only what's left.
81
   */
82
61.4M
  if (cinfo->comps_in_scan > 1) {
83
54.9M
    diff->MCU_rows_per_iMCU_row = 1;
84
54.9M
  } else {
85
6.53M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
6.51M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
21.5k
    else
88
21.5k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
6.53M
  }
90
91
61.4M
  diff->mcu_ctr = 0;
92
61.4M
  diff->MCU_vert_offset = 0;
93
61.4M
}
jcdiffct-12.c:start_iMCU_row
Line
Count
Source
75
64.5M
{
76
64.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
77
78
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
79
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
80
   * But at the bottom of the image, process only what's left.
81
   */
82
64.5M
  if (cinfo->comps_in_scan > 1) {
83
55.3M
    diff->MCU_rows_per_iMCU_row = 1;
84
55.3M
  } else {
85
9.22M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
9.20M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
15.9k
    else
88
15.9k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
9.22M
  }
90
91
64.5M
  diff->mcu_ctr = 0;
92
64.5M
  diff->MCU_vert_offset = 0;
93
64.5M
}
jcdiffct-16.c:start_iMCU_row
Line
Count
Source
75
64.1M
{
76
64.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
77
78
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
79
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
80
   * But at the bottom of the image, process only what's left.
81
   */
82
64.1M
  if (cinfo->comps_in_scan > 1) {
83
55.0M
    diff->MCU_rows_per_iMCU_row = 1;
84
55.0M
  } else {
85
9.13M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
9.11M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
14.5k
    else
88
14.5k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
9.13M
  }
90
91
64.1M
  diff->mcu_ctr = 0;
92
64.1M
  diff->MCU_vert_offset = 0;
93
64.1M
}
94
95
96
/*
97
 * Initialize for a processing pass.
98
 */
99
100
METHODDEF(void)
101
start_pass_diff(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
102
145k
{
103
145k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
104
105
  /* Because it is hitching a ride on the jpeg_forward_dct struct,
106
   * start_pass_lossless() will be called at the start of the initial pass.
107
   * This ensures that it will be called at the start of the Huffman
108
   * optimization and output passes as well.
109
   */
110
145k
  if (pass_mode == JBUF_CRANK_DEST)
111
72.9k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
145k
  diff->iMCU_row_num = 0;
114
145k
  start_iMCU_row(cinfo);
115
116
145k
  switch (pass_mode) {
117
0
  case JBUF_PASS_THRU:
118
0
    if (diff->whole_image[0] != NULL)
119
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
120
0
    diff->pub._compress_data = compress_data;
121
0
    break;
122
0
#ifdef FULL_SAMP_BUFFER_SUPPORTED
123
72.9k
  case JBUF_SAVE_AND_PASS:
124
72.9k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
72.9k
    diff->pub._compress_data = compress_first_pass;
127
72.9k
    break;
128
72.9k
  case JBUF_CRANK_DEST:
129
72.9k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
72.9k
    diff->pub._compress_data = compress_output;
132
72.9k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
145k
  }
138
145k
}
jcdiffct-8.c:start_pass_diff
Line
Count
Source
102
57.9k
{
103
57.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
104
105
  /* Because it is hitching a ride on the jpeg_forward_dct struct,
106
   * start_pass_lossless() will be called at the start of the initial pass.
107
   * This ensures that it will be called at the start of the Huffman
108
   * optimization and output passes as well.
109
   */
110
57.9k
  if (pass_mode == JBUF_CRANK_DEST)
111
28.9k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
57.9k
  diff->iMCU_row_num = 0;
114
57.9k
  start_iMCU_row(cinfo);
115
116
57.9k
  switch (pass_mode) {
117
0
  case JBUF_PASS_THRU:
118
0
    if (diff->whole_image[0] != NULL)
119
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
120
0
    diff->pub._compress_data = compress_data;
121
0
    break;
122
0
#ifdef FULL_SAMP_BUFFER_SUPPORTED
123
28.9k
  case JBUF_SAVE_AND_PASS:
124
28.9k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
28.9k
    diff->pub._compress_data = compress_first_pass;
127
28.9k
    break;
128
28.9k
  case JBUF_CRANK_DEST:
129
28.9k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
28.9k
    diff->pub._compress_data = compress_output;
132
28.9k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
57.9k
  }
138
57.9k
}
jcdiffct-12.c:start_pass_diff
Line
Count
Source
102
45.6k
{
103
45.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
104
105
  /* Because it is hitching a ride on the jpeg_forward_dct struct,
106
   * start_pass_lossless() will be called at the start of the initial pass.
107
   * This ensures that it will be called at the start of the Huffman
108
   * optimization and output passes as well.
109
   */
110
45.6k
  if (pass_mode == JBUF_CRANK_DEST)
111
22.8k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
45.6k
  diff->iMCU_row_num = 0;
114
45.6k
  start_iMCU_row(cinfo);
115
116
45.6k
  switch (pass_mode) {
117
0
  case JBUF_PASS_THRU:
118
0
    if (diff->whole_image[0] != NULL)
119
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
120
0
    diff->pub._compress_data = compress_data;
121
0
    break;
122
0
#ifdef FULL_SAMP_BUFFER_SUPPORTED
123
22.8k
  case JBUF_SAVE_AND_PASS:
124
22.8k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
22.8k
    diff->pub._compress_data = compress_first_pass;
127
22.8k
    break;
128
22.8k
  case JBUF_CRANK_DEST:
129
22.8k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
22.8k
    diff->pub._compress_data = compress_output;
132
22.8k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
45.6k
  }
138
45.6k
}
jcdiffct-16.c:start_pass_diff
Line
Count
Source
102
42.2k
{
103
42.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
104
105
  /* Because it is hitching a ride on the jpeg_forward_dct struct,
106
   * start_pass_lossless() will be called at the start of the initial pass.
107
   * This ensures that it will be called at the start of the Huffman
108
   * optimization and output passes as well.
109
   */
110
42.2k
  if (pass_mode == JBUF_CRANK_DEST)
111
21.1k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
42.2k
  diff->iMCU_row_num = 0;
114
42.2k
  start_iMCU_row(cinfo);
115
116
42.2k
  switch (pass_mode) {
117
0
  case JBUF_PASS_THRU:
118
0
    if (diff->whole_image[0] != NULL)
119
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
120
0
    diff->pub._compress_data = compress_data;
121
0
    break;
122
0
#ifdef FULL_SAMP_BUFFER_SUPPORTED
123
21.1k
  case JBUF_SAVE_AND_PASS:
124
21.1k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
21.1k
    diff->pub._compress_data = compress_first_pass;
127
21.1k
    break;
128
21.1k
  case JBUF_CRANK_DEST:
129
21.1k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
21.1k
    diff->pub._compress_data = compress_output;
132
21.1k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
42.2k
  }
138
42.2k
}
139
140
141
547M
#define SWAP_ROWS(rowa, rowb) { \
142
547M
  _JSAMPROW temp = rowa; \
143
547M
  rowa = rowb;  rowb = temp; \
144
547M
}
145
146
/*
147
 * Process some data in the single-pass case.
148
 * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
149
 * per call, ie, v_samp_factor rows for each component in the image.
150
 * Returns TRUE if the iMCU row is completed, FALSE if suspended.
151
 *
152
 * NB: input_buf contains a plane for each component in image,
153
 * which we index according to the component's SOF position.
154
 */
155
156
METHODDEF(boolean)
157
compress_data(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
158
190M
{
159
190M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
190M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
190M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
190M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
190M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
190M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
190M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
380M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
190M
       yoffset++) {
170
171
190M
    MCU_col_num = diff->mcu_ctr;
172
173
    /* Scale and predict each scanline of the MCU row separately.
174
     *
175
     * Note: We only do this if we are at the start of an MCU row, ie,
176
     * we don't want to reprocess a row suspended by the output.
177
     */
178
190M
    if (MCU_col_num == 0) {
179
737M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
547M
        compptr = cinfo->cur_comp_info[ci];
181
547M
        compi = compptr->component_index;
182
547M
        if (diff->iMCU_row_num < last_iMCU_row)
183
547M
          samp_rows = compptr->v_samp_factor;
184
404k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
404k
          samp_rows =
187
404k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
404k
          if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
189
0
          else {
190
            /* Fill dummy difference rows at the bottom edge with zeros, which
191
             * will encode to the smallest amount of data.
192
             */
193
0
            for (samp_row = samp_rows; samp_row < compptr->v_samp_factor;
194
0
                 samp_row++)
195
0
              memset(diff->diff_buf[compi][samp_row], 0,
196
0
                     jround_up((long)compptr->width_in_blocks,
197
0
                               (long)compptr->h_samp_factor) * sizeof(JDIFF));
198
0
          }
199
404k
        }
200
547M
        samps_across = compptr->width_in_blocks;
201
202
1.09G
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
547M
          (*losslessc->scaler_scale) (cinfo,
204
547M
                                      input_buf[compi][samp_row],
205
547M
                                      diff->cur_row[compi],
206
547M
                                      samps_across);
207
547M
          (*losslessc->predict_difference[compi])
208
547M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
547M
             diff->diff_buf[compi][samp_row], samps_across);
210
547M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
547M
        }
212
547M
      }
213
190M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
190M
    MCU_count =
216
190M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
190M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
190M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
190M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
220
      /* Suspension forced; update state counters and exit */
221
0
      diff->MCU_vert_offset = yoffset;
222
0
      diff->mcu_ctr += MCU_col_num;
223
0
      return FALSE;
224
0
    }
225
    /* Completed an MCU row, but perhaps not an iMCU row */
226
190M
    diff->mcu_ctr = 0;
227
190M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
190M
  diff->iMCU_row_num++;
230
190M
  start_iMCU_row(cinfo);
231
190M
  return TRUE;
232
190M
}
jcdiffct-8.c:compress_data
Line
Count
Source
158
61.3M
{
159
61.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
61.3M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
61.3M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
61.3M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
61.3M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
61.3M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
61.3M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
122M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
61.3M
       yoffset++) {
170
171
61.3M
    MCU_col_num = diff->mcu_ctr;
172
173
    /* Scale and predict each scanline of the MCU row separately.
174
     *
175
     * Note: We only do this if we are at the start of an MCU row, ie,
176
     * we don't want to reprocess a row suspended by the output.
177
     */
178
61.3M
    if (MCU_col_num == 0) {
179
241M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
180M
        compptr = cinfo->cur_comp_info[ci];
181
180M
        compi = compptr->component_index;
182
180M
        if (diff->iMCU_row_num < last_iMCU_row)
183
180M
          samp_rows = compptr->v_samp_factor;
184
159k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
159k
          samp_rows =
187
159k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
159k
          if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
189
0
          else {
190
            /* Fill dummy difference rows at the bottom edge with zeros, which
191
             * will encode to the smallest amount of data.
192
             */
193
0
            for (samp_row = samp_rows; samp_row < compptr->v_samp_factor;
194
0
                 samp_row++)
195
0
              memset(diff->diff_buf[compi][samp_row], 0,
196
0
                     jround_up((long)compptr->width_in_blocks,
197
0
                               (long)compptr->h_samp_factor) * sizeof(JDIFF));
198
0
          }
199
159k
        }
200
180M
        samps_across = compptr->width_in_blocks;
201
202
360M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
180M
          (*losslessc->scaler_scale) (cinfo,
204
180M
                                      input_buf[compi][samp_row],
205
180M
                                      diff->cur_row[compi],
206
180M
                                      samps_across);
207
180M
          (*losslessc->predict_difference[compi])
208
180M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
180M
             diff->diff_buf[compi][samp_row], samps_across);
210
180M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
180M
        }
212
180M
      }
213
61.3M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
61.3M
    MCU_count =
216
61.3M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
61.3M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
61.3M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
61.3M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
220
      /* Suspension forced; update state counters and exit */
221
0
      diff->MCU_vert_offset = yoffset;
222
0
      diff->mcu_ctr += MCU_col_num;
223
0
      return FALSE;
224
0
    }
225
    /* Completed an MCU row, but perhaps not an iMCU row */
226
61.3M
    diff->mcu_ctr = 0;
227
61.3M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
61.3M
  diff->iMCU_row_num++;
230
61.3M
  start_iMCU_row(cinfo);
231
61.3M
  return TRUE;
232
61.3M
}
jcdiffct-12.c:compress_data
Line
Count
Source
158
64.5M
{
159
64.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
64.5M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
64.5M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
64.5M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
64.5M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
64.5M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
64.5M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
129M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
64.5M
       yoffset++) {
170
171
64.5M
    MCU_col_num = diff->mcu_ctr;
172
173
    /* Scale and predict each scanline of the MCU row separately.
174
     *
175
     * Note: We only do this if we are at the start of an MCU row, ie,
176
     * we don't want to reprocess a row suspended by the output.
177
     */
178
64.5M
    if (MCU_col_num == 0) {
179
248M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
184M
        compptr = cinfo->cur_comp_info[ci];
181
184M
        compi = compptr->component_index;
182
184M
        if (diff->iMCU_row_num < last_iMCU_row)
183
184M
          samp_rows = compptr->v_samp_factor;
184
127k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
127k
          samp_rows =
187
127k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
127k
          if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
189
0
          else {
190
            /* Fill dummy difference rows at the bottom edge with zeros, which
191
             * will encode to the smallest amount of data.
192
             */
193
0
            for (samp_row = samp_rows; samp_row < compptr->v_samp_factor;
194
0
                 samp_row++)
195
0
              memset(diff->diff_buf[compi][samp_row], 0,
196
0
                     jround_up((long)compptr->width_in_blocks,
197
0
                               (long)compptr->h_samp_factor) * sizeof(JDIFF));
198
0
          }
199
127k
        }
200
184M
        samps_across = compptr->width_in_blocks;
201
202
368M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
184M
          (*losslessc->scaler_scale) (cinfo,
204
184M
                                      input_buf[compi][samp_row],
205
184M
                                      diff->cur_row[compi],
206
184M
                                      samps_across);
207
184M
          (*losslessc->predict_difference[compi])
208
184M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
184M
             diff->diff_buf[compi][samp_row], samps_across);
210
184M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
184M
        }
212
184M
      }
213
64.5M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
64.5M
    MCU_count =
216
64.5M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
64.5M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
64.5M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
64.5M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
220
      /* Suspension forced; update state counters and exit */
221
0
      diff->MCU_vert_offset = yoffset;
222
0
      diff->mcu_ctr += MCU_col_num;
223
0
      return FALSE;
224
0
    }
225
    /* Completed an MCU row, but perhaps not an iMCU row */
226
64.5M
    diff->mcu_ctr = 0;
227
64.5M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
64.5M
  diff->iMCU_row_num++;
230
64.5M
  start_iMCU_row(cinfo);
231
64.5M
  return TRUE;
232
64.5M
}
jcdiffct-16.c:compress_data
Line
Count
Source
158
64.0M
{
159
64.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
64.0M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
64.0M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
64.0M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
64.0M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
64.0M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
64.0M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
128M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
64.0M
       yoffset++) {
170
171
64.0M
    MCU_col_num = diff->mcu_ctr;
172
173
    /* Scale and predict each scanline of the MCU row separately.
174
     *
175
     * Note: We only do this if we are at the start of an MCU row, ie,
176
     * we don't want to reprocess a row suspended by the output.
177
     */
178
64.0M
    if (MCU_col_num == 0) {
179
247M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
183M
        compptr = cinfo->cur_comp_info[ci];
181
183M
        compi = compptr->component_index;
182
183M
        if (diff->iMCU_row_num < last_iMCU_row)
183
183M
          samp_rows = compptr->v_samp_factor;
184
117k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
117k
          samp_rows =
187
117k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
117k
          if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
189
0
          else {
190
            /* Fill dummy difference rows at the bottom edge with zeros, which
191
             * will encode to the smallest amount of data.
192
             */
193
0
            for (samp_row = samp_rows; samp_row < compptr->v_samp_factor;
194
0
                 samp_row++)
195
0
              memset(diff->diff_buf[compi][samp_row], 0,
196
0
                     jround_up((long)compptr->width_in_blocks,
197
0
                               (long)compptr->h_samp_factor) * sizeof(JDIFF));
198
0
          }
199
117k
        }
200
183M
        samps_across = compptr->width_in_blocks;
201
202
366M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
183M
          (*losslessc->scaler_scale) (cinfo,
204
183M
                                      input_buf[compi][samp_row],
205
183M
                                      diff->cur_row[compi],
206
183M
                                      samps_across);
207
183M
          (*losslessc->predict_difference[compi])
208
183M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
183M
             diff->diff_buf[compi][samp_row], samps_across);
210
183M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
183M
        }
212
183M
      }
213
64.0M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
64.0M
    MCU_count =
216
64.0M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
64.0M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
64.0M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
64.0M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
220
      /* Suspension forced; update state counters and exit */
221
0
      diff->MCU_vert_offset = yoffset;
222
0
      diff->mcu_ctr += MCU_col_num;
223
0
      return FALSE;
224
0
    }
225
    /* Completed an MCU row, but perhaps not an iMCU row */
226
64.0M
    diff->mcu_ctr = 0;
227
64.0M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
64.0M
  diff->iMCU_row_num++;
230
64.0M
  start_iMCU_row(cinfo);
231
64.0M
  return TRUE;
232
64.0M
}
233
234
235
#ifdef FULL_SAMP_BUFFER_SUPPORTED
236
237
/*
238
 * Process some data in the first pass of a multi-pass case.
239
 * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
240
 * per call, ie, v_samp_factor rows for each component in the image.
241
 * This amount of data is read from the source buffer and saved into the
242
 * virtual arrays.
243
 *
244
 * We must also emit the data to the compressor.  This is conveniently
245
 * done by calling compress_output() after we've loaded the current strip
246
 * of the virtual arrays.
247
 *
248
 * NB: input_buf contains a plane for each component in image.  All components
249
 * are loaded into the virtual arrays in this pass.  However, it may be that
250
 * only a subset of the components are emitted to the compressor during
251
 * this first pass; be careful about looking at the scan-dependent variables
252
 * (MCU dimensions, etc).
253
 */
254
255
METHODDEF(boolean)
256
compress_first_pass(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
257
95.0M
{
258
95.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
95.0M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
95.0M
  JDIMENSION samps_across;
261
95.0M
  int ci, samp_row, samp_rows;
262
95.0M
  _JSAMPARRAY buffer;
263
95.0M
  jpeg_component_info *compptr;
264
265
368M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
273M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
273M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
273M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
273M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
273M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
273M
    if (diff->iMCU_row_num < last_iMCU_row)
275
273M
      samp_rows = compptr->v_samp_factor;
276
202k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
202k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
202k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
202k
    }
281
273M
    samps_across = compptr->width_in_blocks;
282
283
    /* Perform point transform scaling and prediction/differencing for all
284
     * non-dummy rows in this iMCU row.  Each call on these functions
285
     * processes a complete row of samples.
286
     */
287
547M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
273M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
273M
             samps_across * sizeof(_JSAMPLE));
290
273M
    }
291
273M
  }
292
  /* NB: compress_output will increment iMCU_row_num if successful.
293
   * A suspension return will result in redoing all the work above next time.
294
   */
295
296
  /* Emit data to the compressor, sharing code with subsequent passes */
297
95.0M
  return compress_output(cinfo, input_buf);
298
95.0M
}
jcdiffct-8.c:compress_first_pass
Line
Count
Source
257
30.6M
{
258
30.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
30.6M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
30.6M
  JDIMENSION samps_across;
261
30.6M
  int ci, samp_row, samp_rows;
262
30.6M
  _JSAMPARRAY buffer;
263
30.6M
  jpeg_component_info *compptr;
264
265
120M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
90.1M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
90.1M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
90.1M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
90.1M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
90.1M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
90.1M
    if (diff->iMCU_row_num < last_iMCU_row)
275
90.0M
      samp_rows = compptr->v_samp_factor;
276
79.9k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
79.9k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
79.9k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
79.9k
    }
281
90.1M
    samps_across = compptr->width_in_blocks;
282
283
    /* Perform point transform scaling and prediction/differencing for all
284
     * non-dummy rows in this iMCU row.  Each call on these functions
285
     * processes a complete row of samples.
286
     */
287
180M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
90.1M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
90.1M
             samps_across * sizeof(_JSAMPLE));
290
90.1M
    }
291
90.1M
  }
292
  /* NB: compress_output will increment iMCU_row_num if successful.
293
   * A suspension return will result in redoing all the work above next time.
294
   */
295
296
  /* Emit data to the compressor, sharing code with subsequent passes */
297
30.6M
  return compress_output(cinfo, input_buf);
298
30.6M
}
jcdiffct-12.c:compress_first_pass
Line
Count
Source
257
32.2M
{
258
32.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
32.2M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
32.2M
  JDIMENSION samps_across;
261
32.2M
  int ci, samp_row, samp_rows;
262
32.2M
  _JSAMPARRAY buffer;
263
32.2M
  jpeg_component_info *compptr;
264
265
124M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
92.2M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
92.2M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
92.2M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
92.2M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
92.2M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
92.2M
    if (diff->iMCU_row_num < last_iMCU_row)
275
92.1M
      samp_rows = compptr->v_samp_factor;
276
63.6k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
63.6k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
63.6k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
63.6k
    }
281
92.2M
    samps_across = compptr->width_in_blocks;
282
283
    /* Perform point transform scaling and prediction/differencing for all
284
     * non-dummy rows in this iMCU row.  Each call on these functions
285
     * processes a complete row of samples.
286
     */
287
184M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
92.2M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
92.2M
             samps_across * sizeof(_JSAMPLE));
290
92.2M
    }
291
92.2M
  }
292
  /* NB: compress_output will increment iMCU_row_num if successful.
293
   * A suspension return will result in redoing all the work above next time.
294
   */
295
296
  /* Emit data to the compressor, sharing code with subsequent passes */
297
32.2M
  return compress_output(cinfo, input_buf);
298
32.2M
}
jcdiffct-16.c:compress_first_pass
Line
Count
Source
257
32.0M
{
258
32.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
32.0M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
32.0M
  JDIMENSION samps_across;
261
32.0M
  int ci, samp_row, samp_rows;
262
32.0M
  _JSAMPARRAY buffer;
263
32.0M
  jpeg_component_info *compptr;
264
265
123M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
91.5M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
91.5M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
91.5M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
91.5M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
91.5M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
91.5M
    if (diff->iMCU_row_num < last_iMCU_row)
275
91.5M
      samp_rows = compptr->v_samp_factor;
276
58.9k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
58.9k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
58.9k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
58.9k
    }
281
91.5M
    samps_across = compptr->width_in_blocks;
282
283
    /* Perform point transform scaling and prediction/differencing for all
284
     * non-dummy rows in this iMCU row.  Each call on these functions
285
     * processes a complete row of samples.
286
     */
287
183M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
91.5M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
91.5M
             samps_across * sizeof(_JSAMPLE));
290
91.5M
    }
291
91.5M
  }
292
  /* NB: compress_output will increment iMCU_row_num if successful.
293
   * A suspension return will result in redoing all the work above next time.
294
   */
295
296
  /* Emit data to the compressor, sharing code with subsequent passes */
297
32.0M
  return compress_output(cinfo, input_buf);
298
32.0M
}
299
300
301
/*
302
 * Process some data in subsequent passes of a multi-pass case.
303
 * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
304
 * per call, ie, v_samp_factor rows for each component in the scan.
305
 * The data is obtained from the virtual arrays and fed to the compressor.
306
 * Returns TRUE if the iMCU row is completed, FALSE if suspended.
307
 *
308
 * NB: input_buf is ignored; it is likely to be a NULL pointer.
309
 */
310
311
METHODDEF(boolean)
312
compress_output(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
313
190M
{
314
190M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
190M
  int ci, compi;
316
190M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
190M
  jpeg_component_info *compptr;
318
319
  /* Align the virtual buffers for the components used in this scan.
320
   * NB: during first pass, this is safe only because the buffers will
321
   * already be aligned properly, so jmemmgr.c won't need to do any I/O.
322
   */
323
737M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
547M
    compptr = cinfo->cur_comp_info[ci];
325
547M
    compi = compptr->component_index;
326
547M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
547M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
547M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
547M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
547M
  }
331
332
190M
  return compress_data(cinfo, buffer);
333
190M
}
jcdiffct-8.c:compress_output
Line
Count
Source
313
61.3M
{
314
61.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
61.3M
  int ci, compi;
316
61.3M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
61.3M
  jpeg_component_info *compptr;
318
319
  /* Align the virtual buffers for the components used in this scan.
320
   * NB: during first pass, this is safe only because the buffers will
321
   * already be aligned properly, so jmemmgr.c won't need to do any I/O.
322
   */
323
241M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
180M
    compptr = cinfo->cur_comp_info[ci];
325
180M
    compi = compptr->component_index;
326
180M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
180M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
180M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
180M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
180M
  }
331
332
61.3M
  return compress_data(cinfo, buffer);
333
61.3M
}
jcdiffct-12.c:compress_output
Line
Count
Source
313
64.5M
{
314
64.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
64.5M
  int ci, compi;
316
64.5M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
64.5M
  jpeg_component_info *compptr;
318
319
  /* Align the virtual buffers for the components used in this scan.
320
   * NB: during first pass, this is safe only because the buffers will
321
   * already be aligned properly, so jmemmgr.c won't need to do any I/O.
322
   */
323
248M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
184M
    compptr = cinfo->cur_comp_info[ci];
325
184M
    compi = compptr->component_index;
326
184M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
184M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
184M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
184M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
184M
  }
331
332
64.5M
  return compress_data(cinfo, buffer);
333
64.5M
}
jcdiffct-16.c:compress_output
Line
Count
Source
313
64.0M
{
314
64.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
64.0M
  int ci, compi;
316
64.0M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
64.0M
  jpeg_component_info *compptr;
318
319
  /* Align the virtual buffers for the components used in this scan.
320
   * NB: during first pass, this is safe only because the buffers will
321
   * already be aligned properly, so jmemmgr.c won't need to do any I/O.
322
   */
323
247M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
183M
    compptr = cinfo->cur_comp_info[ci];
325
183M
    compi = compptr->component_index;
326
183M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
183M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
183M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
183M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
183M
  }
331
332
64.0M
  return compress_data(cinfo, buffer);
333
64.0M
}
334
335
#endif /* FULL_SAMP_BUFFER_SUPPORTED */
336
337
338
/*
339
 * Initialize difference buffer controller.
340
 */
341
342
GLOBAL(void)
343
_jinit_c_diff_controller(j_compress_ptr cinfo, boolean need_full_buffer)
344
72.9k
{
345
72.9k
  my_diff_ptr diff;
346
72.9k
  int ci, row;
347
72.9k
  jpeg_component_info *compptr;
348
349
#if BITS_IN_JSAMPLE == 8
350
28.9k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
351
#else
352
43.9k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
43.9k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
72.9k
  diff = (my_diff_ptr)
358
72.9k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
72.9k
                                sizeof(my_diff_controller));
360
72.9k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
72.9k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
275k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
202k
       ci++, compptr++) {
366
202k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
202k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
202k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
202k
                             (long)compptr->h_samp_factor),
370
202k
       (JDIMENSION)1);
371
202k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
202k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
202k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
202k
                             (long)compptr->h_samp_factor),
375
202k
       (JDIMENSION)1);
376
202k
  }
377
378
  /* Create the difference buffer. */
379
275k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
202k
       ci++, compptr++) {
381
202k
    diff->diff_buf[ci] =
382
202k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
202k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
202k
                                         (long)compptr->h_samp_factor),
385
202k
                   (JDIMENSION)compptr->v_samp_factor);
386
    /* Prefill difference rows with zeros.  We do this because only actual
387
     * data is placed in the buffers during prediction/differencing, leaving
388
     * any dummy differences at the right edge as zeros, which will encode
389
     * to the smallest amount of data.
390
     */
391
405k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
202k
      memset(diff->diff_buf[ci][row], 0,
393
202k
             jround_up((long)compptr->width_in_blocks,
394
202k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
202k
  }
396
397
  /* Create the sample buffer. */
398
72.9k
  if (need_full_buffer) {
399
72.9k
#ifdef FULL_SAMP_BUFFER_SUPPORTED
400
    /* Allocate a full-image virtual array for each component, */
401
    /* padded to a multiple of samp_factor differences in each direction. */
402
275k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
202k
         ci++, compptr++) {
404
202k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
202k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
202k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
202k
                               (long)compptr->h_samp_factor),
408
202k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
202k
                               (long)compptr->v_samp_factor),
410
202k
         (JDIMENSION)compptr->v_samp_factor);
411
202k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
72.9k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
72.9k
}
jinit_c_diff_controller
Line
Count
Source
344
28.9k
{
345
28.9k
  my_diff_ptr diff;
346
28.9k
  int ci, row;
347
28.9k
  jpeg_component_info *compptr;
348
349
28.9k
#if BITS_IN_JSAMPLE == 8
350
28.9k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
351
#else
352
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
28.9k
  diff = (my_diff_ptr)
358
28.9k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
28.9k
                                sizeof(my_diff_controller));
360
28.9k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
28.9k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
108k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
79.9k
       ci++, compptr++) {
366
79.9k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
79.9k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
79.9k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
79.9k
                             (long)compptr->h_samp_factor),
370
79.9k
       (JDIMENSION)1);
371
79.9k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
79.9k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
79.9k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
79.9k
                             (long)compptr->h_samp_factor),
375
79.9k
       (JDIMENSION)1);
376
79.9k
  }
377
378
  /* Create the difference buffer. */
379
108k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
79.9k
       ci++, compptr++) {
381
79.9k
    diff->diff_buf[ci] =
382
79.9k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
79.9k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
79.9k
                                         (long)compptr->h_samp_factor),
385
79.9k
                   (JDIMENSION)compptr->v_samp_factor);
386
    /* Prefill difference rows with zeros.  We do this because only actual
387
     * data is placed in the buffers during prediction/differencing, leaving
388
     * any dummy differences at the right edge as zeros, which will encode
389
     * to the smallest amount of data.
390
     */
391
159k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
79.9k
      memset(diff->diff_buf[ci][row], 0,
393
79.9k
             jround_up((long)compptr->width_in_blocks,
394
79.9k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
79.9k
  }
396
397
  /* Create the sample buffer. */
398
28.9k
  if (need_full_buffer) {
399
28.9k
#ifdef FULL_SAMP_BUFFER_SUPPORTED
400
    /* Allocate a full-image virtual array for each component, */
401
    /* padded to a multiple of samp_factor differences in each direction. */
402
108k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
79.9k
         ci++, compptr++) {
404
79.9k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
79.9k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
79.9k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
79.9k
                               (long)compptr->h_samp_factor),
408
79.9k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
79.9k
                               (long)compptr->v_samp_factor),
410
79.9k
         (JDIMENSION)compptr->v_samp_factor);
411
79.9k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
28.9k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
28.9k
}
j12init_c_diff_controller
Line
Count
Source
344
22.8k
{
345
22.8k
  my_diff_ptr diff;
346
22.8k
  int ci, row;
347
22.8k
  jpeg_component_info *compptr;
348
349
#if BITS_IN_JSAMPLE == 8
350
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
351
#else
352
22.8k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
22.8k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
22.8k
  diff = (my_diff_ptr)
358
22.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
22.8k
                                sizeof(my_diff_controller));
360
22.8k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
22.8k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
86.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
63.6k
       ci++, compptr++) {
366
63.6k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
63.6k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
63.6k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
63.6k
                             (long)compptr->h_samp_factor),
370
63.6k
       (JDIMENSION)1);
371
63.6k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
63.6k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
63.6k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
63.6k
                             (long)compptr->h_samp_factor),
375
63.6k
       (JDIMENSION)1);
376
63.6k
  }
377
378
  /* Create the difference buffer. */
379
86.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
63.6k
       ci++, compptr++) {
381
63.6k
    diff->diff_buf[ci] =
382
63.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
63.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
63.6k
                                         (long)compptr->h_samp_factor),
385
63.6k
                   (JDIMENSION)compptr->v_samp_factor);
386
    /* Prefill difference rows with zeros.  We do this because only actual
387
     * data is placed in the buffers during prediction/differencing, leaving
388
     * any dummy differences at the right edge as zeros, which will encode
389
     * to the smallest amount of data.
390
     */
391
127k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
63.6k
      memset(diff->diff_buf[ci][row], 0,
393
63.6k
             jround_up((long)compptr->width_in_blocks,
394
63.6k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
63.6k
  }
396
397
  /* Create the sample buffer. */
398
22.8k
  if (need_full_buffer) {
399
22.8k
#ifdef FULL_SAMP_BUFFER_SUPPORTED
400
    /* Allocate a full-image virtual array for each component, */
401
    /* padded to a multiple of samp_factor differences in each direction. */
402
86.4k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
63.6k
         ci++, compptr++) {
404
63.6k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
63.6k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
63.6k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
63.6k
                               (long)compptr->h_samp_factor),
408
63.6k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
63.6k
                               (long)compptr->v_samp_factor),
410
63.6k
         (JDIMENSION)compptr->v_samp_factor);
411
63.6k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
22.8k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
22.8k
}
j16init_c_diff_controller
Line
Count
Source
344
21.1k
{
345
21.1k
  my_diff_ptr diff;
346
21.1k
  int ci, row;
347
21.1k
  jpeg_component_info *compptr;
348
349
#if BITS_IN_JSAMPLE == 8
350
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
351
#else
352
21.1k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
21.1k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
21.1k
  diff = (my_diff_ptr)
358
21.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
21.1k
                                sizeof(my_diff_controller));
360
21.1k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
21.1k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
80.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
58.9k
       ci++, compptr++) {
366
58.9k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
58.9k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
58.9k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
58.9k
                             (long)compptr->h_samp_factor),
370
58.9k
       (JDIMENSION)1);
371
58.9k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
58.9k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
58.9k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
58.9k
                             (long)compptr->h_samp_factor),
375
58.9k
       (JDIMENSION)1);
376
58.9k
  }
377
378
  /* Create the difference buffer. */
379
80.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
58.9k
       ci++, compptr++) {
381
58.9k
    diff->diff_buf[ci] =
382
58.9k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
58.9k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
58.9k
                                         (long)compptr->h_samp_factor),
385
58.9k
                   (JDIMENSION)compptr->v_samp_factor);
386
    /* Prefill difference rows with zeros.  We do this because only actual
387
     * data is placed in the buffers during prediction/differencing, leaving
388
     * any dummy differences at the right edge as zeros, which will encode
389
     * to the smallest amount of data.
390
     */
391
117k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
58.9k
      memset(diff->diff_buf[ci][row], 0,
393
58.9k
             jround_up((long)compptr->width_in_blocks,
394
58.9k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
58.9k
  }
396
397
  /* Create the sample buffer. */
398
21.1k
  if (need_full_buffer) {
399
21.1k
#ifdef FULL_SAMP_BUFFER_SUPPORTED
400
    /* Allocate a full-image virtual array for each component, */
401
    /* padded to a multiple of samp_factor differences in each direction. */
402
80.1k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
58.9k
         ci++, compptr++) {
404
58.9k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
58.9k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
58.9k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
58.9k
                               (long)compptr->h_samp_factor),
408
58.9k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
58.9k
                               (long)compptr->v_samp_factor),
410
58.9k
         (JDIMENSION)compptr->v_samp_factor);
411
58.9k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
21.1k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
21.1k
}
418
419
#endif /* C_LOSSLESS_SUPPORTED */