Coverage Report

Created: 2026-10-08 08:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/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
172M
{
76
172M
  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
172M
  if (cinfo->comps_in_scan > 1) {
83
149M
    diff->MCU_rows_per_iMCU_row = 1;
84
149M
  } else {
85
22.4M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
22.3M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
50.2k
    else
88
50.2k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
22.4M
  }
90
91
172M
  diff->mcu_ctr = 0;
92
172M
  diff->MCU_vert_offset = 0;
93
172M
}
jcdiffct-8.c:start_iMCU_row
Line
Count
Source
75
56.6M
{
76
56.6M
  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
56.6M
  if (cinfo->comps_in_scan > 1) {
83
50.6M
    diff->MCU_rows_per_iMCU_row = 1;
84
50.6M
  } else {
85
6.01M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
5.99M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
20.7k
    else
88
20.7k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
6.01M
  }
90
91
56.6M
  diff->mcu_ctr = 0;
92
56.6M
  diff->MCU_vert_offset = 0;
93
56.6M
}
jcdiffct-12.c:start_iMCU_row
Line
Count
Source
75
56.4M
{
76
56.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
56.4M
  if (cinfo->comps_in_scan > 1) {
83
48.4M
    diff->MCU_rows_per_iMCU_row = 1;
84
48.4M
  } else {
85
8.01M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
8.00M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
14.9k
    else
88
14.9k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
8.01M
  }
90
91
56.4M
  diff->mcu_ctr = 0;
92
56.4M
  diff->MCU_vert_offset = 0;
93
56.4M
}
jcdiffct-16.c:start_iMCU_row
Line
Count
Source
75
59.0M
{
76
59.0M
  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
59.0M
  if (cinfo->comps_in_scan > 1) {
83
50.6M
    diff->MCU_rows_per_iMCU_row = 1;
84
50.6M
  } else {
85
8.41M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
8.39M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
14.4k
    else
88
14.4k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
8.41M
  }
90
91
59.0M
  diff->mcu_ctr = 0;
92
59.0M
  diff->MCU_vert_offset = 0;
93
59.0M
}
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
140k
{
103
140k
  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
140k
  if (pass_mode == JBUF_CRANK_DEST)
111
70.1k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
140k
  diff->iMCU_row_num = 0;
114
140k
  start_iMCU_row(cinfo);
115
116
140k
  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
70.1k
  case JBUF_SAVE_AND_PASS:
124
70.1k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
70.1k
    diff->pub._compress_data = compress_first_pass;
127
70.1k
    break;
128
70.1k
  case JBUF_CRANK_DEST:
129
70.1k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
70.1k
    diff->pub._compress_data = compress_output;
132
70.1k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
140k
  }
138
140k
}
jcdiffct-8.c:start_pass_diff
Line
Count
Source
102
54.2k
{
103
54.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
54.2k
  if (pass_mode == JBUF_CRANK_DEST)
111
27.1k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
54.2k
  diff->iMCU_row_num = 0;
114
54.2k
  start_iMCU_row(cinfo);
115
116
54.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
27.1k
  case JBUF_SAVE_AND_PASS:
124
27.1k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
27.1k
    diff->pub._compress_data = compress_first_pass;
127
27.1k
    break;
128
27.1k
  case JBUF_CRANK_DEST:
129
27.1k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
27.1k
    diff->pub._compress_data = compress_output;
132
27.1k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
54.2k
  }
138
54.2k
}
jcdiffct-12.c:start_pass_diff
Line
Count
Source
102
43.0k
{
103
43.0k
  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
43.0k
  if (pass_mode == JBUF_CRANK_DEST)
111
21.5k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
43.0k
  diff->iMCU_row_num = 0;
114
43.0k
  start_iMCU_row(cinfo);
115
116
43.0k
  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.5k
  case JBUF_SAVE_AND_PASS:
124
21.5k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
21.5k
    diff->pub._compress_data = compress_first_pass;
127
21.5k
    break;
128
21.5k
  case JBUF_CRANK_DEST:
129
21.5k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
21.5k
    diff->pub._compress_data = compress_output;
132
21.5k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
43.0k
  }
138
43.0k
}
jcdiffct-16.c:start_pass_diff
Line
Count
Source
102
42.9k
{
103
42.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
42.9k
  if (pass_mode == JBUF_CRANK_DEST)
111
21.4k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
42.9k
  diff->iMCU_row_num = 0;
114
42.9k
  start_iMCU_row(cinfo);
115
116
42.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
21.4k
  case JBUF_SAVE_AND_PASS:
124
21.4k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
21.4k
    diff->pub._compress_data = compress_first_pass;
127
21.4k
    break;
128
21.4k
  case JBUF_CRANK_DEST:
129
21.4k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
21.4k
    diff->pub._compress_data = compress_output;
132
21.4k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
42.9k
  }
138
42.9k
}
139
140
141
496M
#define SWAP_ROWS(rowa, rowb) { \
142
496M
  _JSAMPROW temp = rowa; \
143
496M
  rowa = rowb;  rowb = temp; \
144
496M
}
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
171M
{
159
171M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
171M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
171M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
171M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
171M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
171M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
171M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
343M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
171M
       yoffset++) {
170
171
171M
    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
171M
    if (MCU_col_num == 0) {
179
668M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
496M
        compptr = cinfo->cur_comp_info[ci];
181
496M
        compi = compptr->component_index;
182
496M
        if (diff->iMCU_row_num < last_iMCU_row)
183
495M
          samp_rows = compptr->v_samp_factor;
184
389k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
389k
          samp_rows =
187
389k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
389k
          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
389k
        }
200
496M
        samps_across = compptr->width_in_blocks;
201
202
992M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
496M
          (*losslessc->scaler_scale) (cinfo,
204
496M
                                      input_buf[compi][samp_row],
205
496M
                                      diff->cur_row[compi],
206
496M
                                      samps_across);
207
496M
          (*losslessc->predict_difference[compi])
208
496M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
496M
             diff->diff_buf[compi][samp_row], samps_across);
210
496M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
496M
        }
212
496M
      }
213
171M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
171M
    MCU_count =
216
171M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
171M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
171M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
171M
    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
171M
    diff->mcu_ctr = 0;
227
171M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
171M
  diff->iMCU_row_num++;
230
171M
  start_iMCU_row(cinfo);
231
171M
  return TRUE;
232
171M
}
jcdiffct-8.c:compress_data
Line
Count
Source
158
56.6M
{
159
56.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
56.6M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
56.6M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
56.6M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
56.6M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
56.6M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
56.6M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
113M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
56.6M
       yoffset++) {
170
171
56.6M
    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
56.6M
    if (MCU_col_num == 0) {
179
222M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
166M
        compptr = cinfo->cur_comp_info[ci];
181
166M
        compi = compptr->component_index;
182
166M
        if (diff->iMCU_row_num < last_iMCU_row)
183
166M
          samp_rows = compptr->v_samp_factor;
184
149k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
149k
          samp_rows =
187
149k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
149k
          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
149k
        }
200
166M
        samps_across = compptr->width_in_blocks;
201
202
332M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
166M
          (*losslessc->scaler_scale) (cinfo,
204
166M
                                      input_buf[compi][samp_row],
205
166M
                                      diff->cur_row[compi],
206
166M
                                      samps_across);
207
166M
          (*losslessc->predict_difference[compi])
208
166M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
166M
             diff->diff_buf[compi][samp_row], samps_across);
210
166M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
166M
        }
212
166M
      }
213
56.6M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
56.6M
    MCU_count =
216
56.6M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
56.6M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
56.6M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
56.6M
    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
56.6M
    diff->mcu_ctr = 0;
227
56.6M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
56.6M
  diff->iMCU_row_num++;
230
56.6M
  start_iMCU_row(cinfo);
231
56.6M
  return TRUE;
232
56.6M
}
jcdiffct-12.c:compress_data
Line
Count
Source
158
56.3M
{
159
56.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
56.3M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
56.3M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
56.3M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
56.3M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
56.3M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
56.3M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
112M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
56.3M
       yoffset++) {
170
171
56.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
56.3M
    if (MCU_col_num == 0) {
179
217M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
161M
        compptr = cinfo->cur_comp_info[ci];
181
161M
        compi = compptr->component_index;
182
161M
        if (diff->iMCU_row_num < last_iMCU_row)
183
161M
          samp_rows = compptr->v_samp_factor;
184
120k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
120k
          samp_rows =
187
120k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
120k
          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
120k
        }
200
161M
        samps_across = compptr->width_in_blocks;
201
202
322M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
161M
          (*losslessc->scaler_scale) (cinfo,
204
161M
                                      input_buf[compi][samp_row],
205
161M
                                      diff->cur_row[compi],
206
161M
                                      samps_across);
207
161M
          (*losslessc->predict_difference[compi])
208
161M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
161M
             diff->diff_buf[compi][samp_row], samps_across);
210
161M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
161M
        }
212
161M
      }
213
56.3M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
56.3M
    MCU_count =
216
56.3M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
56.3M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
56.3M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
56.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
56.3M
    diff->mcu_ctr = 0;
227
56.3M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
56.3M
  diff->iMCU_row_num++;
230
56.3M
  start_iMCU_row(cinfo);
231
56.3M
  return TRUE;
232
56.3M
}
jcdiffct-16.c:compress_data
Line
Count
Source
158
58.9M
{
159
58.9M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
58.9M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
58.9M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
58.9M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
58.9M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
58.9M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
58.9M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
117M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
58.9M
       yoffset++) {
170
171
58.9M
    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
58.9M
    if (MCU_col_num == 0) {
179
227M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
168M
        compptr = cinfo->cur_comp_info[ci];
181
168M
        compi = compptr->component_index;
182
168M
        if (diff->iMCU_row_num < last_iMCU_row)
183
168M
          samp_rows = compptr->v_samp_factor;
184
120k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
120k
          samp_rows =
187
120k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
120k
          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
120k
        }
200
168M
        samps_across = compptr->width_in_blocks;
201
202
337M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
168M
          (*losslessc->scaler_scale) (cinfo,
204
168M
                                      input_buf[compi][samp_row],
205
168M
                                      diff->cur_row[compi],
206
168M
                                      samps_across);
207
168M
          (*losslessc->predict_difference[compi])
208
168M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
168M
             diff->diff_buf[compi][samp_row], samps_across);
210
168M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
168M
        }
212
168M
      }
213
58.9M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
58.9M
    MCU_count =
216
58.9M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
58.9M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
58.9M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
58.9M
    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
58.9M
    diff->mcu_ctr = 0;
227
58.9M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
58.9M
  diff->iMCU_row_num++;
230
58.9M
  start_iMCU_row(cinfo);
231
58.9M
  return TRUE;
232
58.9M
}
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
85.9M
{
258
85.9M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
85.9M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
85.9M
  JDIMENSION samps_across;
261
85.9M
  int ci, samp_row, samp_rows;
262
85.9M
  _JSAMPARRAY buffer;
263
85.9M
  jpeg_component_info *compptr;
264
265
334M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
248M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
248M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
248M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
248M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
248M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
248M
    if (diff->iMCU_row_num < last_iMCU_row)
275
247M
      samp_rows = compptr->v_samp_factor;
276
194k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
194k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
194k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
194k
    }
281
248M
    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
496M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
248M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
248M
             samps_across * sizeof(_JSAMPLE));
290
248M
    }
291
248M
  }
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
85.9M
  return compress_output(cinfo, input_buf);
298
85.9M
}
jcdiffct-8.c:compress_first_pass
Line
Count
Source
257
28.3M
{
258
28.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
28.3M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
28.3M
  JDIMENSION samps_across;
261
28.3M
  int ci, samp_row, samp_rows;
262
28.3M
  _JSAMPARRAY buffer;
263
28.3M
  jpeg_component_info *compptr;
264
265
111M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
83.1M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
83.1M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
83.1M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
83.1M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
83.1M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
83.1M
    if (diff->iMCU_row_num < last_iMCU_row)
275
83.0M
      samp_rows = compptr->v_samp_factor;
276
74.5k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
74.5k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
74.5k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
74.5k
    }
281
83.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
166M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
83.1M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
83.1M
             samps_across * sizeof(_JSAMPLE));
290
83.1M
    }
291
83.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
28.3M
  return compress_output(cinfo, input_buf);
298
28.3M
}
jcdiffct-12.c:compress_first_pass
Line
Count
Source
257
28.1M
{
258
28.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
28.1M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
28.1M
  JDIMENSION samps_across;
261
28.1M
  int ci, samp_row, samp_rows;
262
28.1M
  _JSAMPARRAY buffer;
263
28.1M
  jpeg_component_info *compptr;
264
265
108M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
80.5M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
80.5M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
80.5M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
80.5M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
80.5M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
80.5M
    if (diff->iMCU_row_num < last_iMCU_row)
275
80.5M
      samp_rows = compptr->v_samp_factor;
276
60.0k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
60.0k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
60.0k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
60.0k
    }
281
80.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
161M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
80.5M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
80.5M
             samps_across * sizeof(_JSAMPLE));
290
80.5M
    }
291
80.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
28.1M
  return compress_output(cinfo, input_buf);
298
28.1M
}
jcdiffct-16.c:compress_first_pass
Line
Count
Source
257
29.4M
{
258
29.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
29.4M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
29.4M
  JDIMENSION samps_across;
261
29.4M
  int ci, samp_row, samp_rows;
262
29.4M
  _JSAMPARRAY buffer;
263
29.4M
  jpeg_component_info *compptr;
264
265
113M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
84.3M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
84.3M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
84.3M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
84.3M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
84.3M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
84.3M
    if (diff->iMCU_row_num < last_iMCU_row)
275
84.2M
      samp_rows = compptr->v_samp_factor;
276
60.1k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
60.1k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
60.1k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
60.1k
    }
281
84.3M
    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
168M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
84.3M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
84.3M
             samps_across * sizeof(_JSAMPLE));
290
84.3M
    }
291
84.3M
  }
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
29.4M
  return compress_output(cinfo, input_buf);
298
29.4M
}
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
171M
{
314
171M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
171M
  int ci, compi;
316
171M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
171M
  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
668M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
496M
    compptr = cinfo->cur_comp_info[ci];
325
496M
    compi = compptr->component_index;
326
496M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
496M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
496M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
496M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
496M
  }
331
332
171M
  return compress_data(cinfo, buffer);
333
171M
}
jcdiffct-8.c:compress_output
Line
Count
Source
313
56.6M
{
314
56.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
56.6M
  int ci, compi;
316
56.6M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
56.6M
  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
222M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
166M
    compptr = cinfo->cur_comp_info[ci];
325
166M
    compi = compptr->component_index;
326
166M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
166M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
166M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
166M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
166M
  }
331
332
56.6M
  return compress_data(cinfo, buffer);
333
56.6M
}
jcdiffct-12.c:compress_output
Line
Count
Source
313
56.3M
{
314
56.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
56.3M
  int ci, compi;
316
56.3M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
56.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
217M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
161M
    compptr = cinfo->cur_comp_info[ci];
325
161M
    compi = compptr->component_index;
326
161M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
161M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
161M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
161M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
161M
  }
331
332
56.3M
  return compress_data(cinfo, buffer);
333
56.3M
}
jcdiffct-16.c:compress_output
Line
Count
Source
313
58.9M
{
314
58.9M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
58.9M
  int ci, compi;
316
58.9M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
58.9M
  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
227M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
168M
    compptr = cinfo->cur_comp_info[ci];
325
168M
    compi = compptr->component_index;
326
168M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
168M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
168M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
168M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
168M
  }
331
332
58.9M
  return compress_data(cinfo, buffer);
333
58.9M
}
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
70.1k
{
345
70.1k
  my_diff_ptr diff;
346
70.1k
  int ci, row;
347
70.1k
  jpeg_component_info *compptr;
348
349
#if BITS_IN_JSAMPLE == 8
350
27.1k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
351
#else
352
43.0k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
43.0k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
70.1k
  diff = (my_diff_ptr)
358
70.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
70.1k
                                sizeof(my_diff_controller));
360
70.1k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
70.1k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
264k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
194k
       ci++, compptr++) {
366
194k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
194k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
194k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
194k
                             (long)compptr->h_samp_factor),
370
194k
       (JDIMENSION)1);
371
194k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
194k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
194k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
194k
                             (long)compptr->h_samp_factor),
375
194k
       (JDIMENSION)1);
376
194k
  }
377
378
  /* Create the difference buffer. */
379
264k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
194k
       ci++, compptr++) {
381
194k
    diff->diff_buf[ci] =
382
194k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
194k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
194k
                                         (long)compptr->h_samp_factor),
385
194k
                   (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
389k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
194k
      memset(diff->diff_buf[ci][row], 0,
393
194k
             jround_up((long)compptr->width_in_blocks,
394
194k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
194k
  }
396
397
  /* Create the sample buffer. */
398
70.1k
  if (need_full_buffer) {
399
70.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
264k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
194k
         ci++, compptr++) {
404
194k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
194k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
194k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
194k
                               (long)compptr->h_samp_factor),
408
194k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
194k
                               (long)compptr->v_samp_factor),
410
194k
         (JDIMENSION)compptr->v_samp_factor);
411
194k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
70.1k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
70.1k
}
jinit_c_diff_controller
Line
Count
Source
344
27.1k
{
345
27.1k
  my_diff_ptr diff;
346
27.1k
  int ci, row;
347
27.1k
  jpeg_component_info *compptr;
348
349
27.1k
#if BITS_IN_JSAMPLE == 8
350
27.1k
  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
27.1k
  diff = (my_diff_ptr)
358
27.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
27.1k
                                sizeof(my_diff_controller));
360
27.1k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
27.1k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
101k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
74.5k
       ci++, compptr++) {
366
74.5k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
74.5k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
74.5k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
74.5k
                             (long)compptr->h_samp_factor),
370
74.5k
       (JDIMENSION)1);
371
74.5k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
74.5k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
74.5k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
74.5k
                             (long)compptr->h_samp_factor),
375
74.5k
       (JDIMENSION)1);
376
74.5k
  }
377
378
  /* Create the difference buffer. */
379
101k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
74.5k
       ci++, compptr++) {
381
74.5k
    diff->diff_buf[ci] =
382
74.5k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
74.5k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
74.5k
                                         (long)compptr->h_samp_factor),
385
74.5k
                   (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
149k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
74.5k
      memset(diff->diff_buf[ci][row], 0,
393
74.5k
             jround_up((long)compptr->width_in_blocks,
394
74.5k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
74.5k
  }
396
397
  /* Create the sample buffer. */
398
27.1k
  if (need_full_buffer) {
399
27.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
101k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
74.5k
         ci++, compptr++) {
404
74.5k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
74.5k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
74.5k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
74.5k
                               (long)compptr->h_samp_factor),
408
74.5k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
74.5k
                               (long)compptr->v_samp_factor),
410
74.5k
         (JDIMENSION)compptr->v_samp_factor);
411
74.5k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
27.1k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
27.1k
}
j12init_c_diff_controller
Line
Count
Source
344
21.5k
{
345
21.5k
  my_diff_ptr diff;
346
21.5k
  int ci, row;
347
21.5k
  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.5k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
21.5k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
21.5k
  diff = (my_diff_ptr)
358
21.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
21.5k
                                sizeof(my_diff_controller));
360
21.5k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
21.5k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
81.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
60.0k
       ci++, compptr++) {
366
60.0k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
60.0k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
60.0k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
60.0k
                             (long)compptr->h_samp_factor),
370
60.0k
       (JDIMENSION)1);
371
60.0k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
60.0k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
60.0k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
60.0k
                             (long)compptr->h_samp_factor),
375
60.0k
       (JDIMENSION)1);
376
60.0k
  }
377
378
  /* Create the difference buffer. */
379
81.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
60.0k
       ci++, compptr++) {
381
60.0k
    diff->diff_buf[ci] =
382
60.0k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
60.0k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
60.0k
                                         (long)compptr->h_samp_factor),
385
60.0k
                   (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
120k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
60.0k
      memset(diff->diff_buf[ci][row], 0,
393
60.0k
             jround_up((long)compptr->width_in_blocks,
394
60.0k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
60.0k
  }
396
397
  /* Create the sample buffer. */
398
21.5k
  if (need_full_buffer) {
399
21.5k
#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
81.6k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
60.0k
         ci++, compptr++) {
404
60.0k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
60.0k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
60.0k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
60.0k
                               (long)compptr->h_samp_factor),
408
60.0k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
60.0k
                               (long)compptr->v_samp_factor),
410
60.0k
         (JDIMENSION)compptr->v_samp_factor);
411
60.0k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
21.5k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
21.5k
}
j16init_c_diff_controller
Line
Count
Source
344
21.4k
{
345
21.4k
  my_diff_ptr diff;
346
21.4k
  int ci, row;
347
21.4k
  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.4k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
21.4k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
21.4k
  diff = (my_diff_ptr)
358
21.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
21.4k
                                sizeof(my_diff_controller));
360
21.4k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
21.4k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
81.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
60.1k
       ci++, compptr++) {
366
60.1k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
60.1k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
60.1k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
60.1k
                             (long)compptr->h_samp_factor),
370
60.1k
       (JDIMENSION)1);
371
60.1k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
60.1k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
60.1k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
60.1k
                             (long)compptr->h_samp_factor),
375
60.1k
       (JDIMENSION)1);
376
60.1k
  }
377
378
  /* Create the difference buffer. */
379
81.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
60.1k
       ci++, compptr++) {
381
60.1k
    diff->diff_buf[ci] =
382
60.1k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
60.1k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
60.1k
                                         (long)compptr->h_samp_factor),
385
60.1k
                   (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
120k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
60.1k
      memset(diff->diff_buf[ci][row], 0,
393
60.1k
             jround_up((long)compptr->width_in_blocks,
394
60.1k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
60.1k
  }
396
397
  /* Create the sample buffer. */
398
21.4k
  if (need_full_buffer) {
399
21.4k
#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
81.6k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
60.1k
         ci++, compptr++) {
404
60.1k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
60.1k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
60.1k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
60.1k
                               (long)compptr->h_samp_factor),
408
60.1k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
60.1k
                               (long)compptr->v_samp_factor),
410
60.1k
         (JDIMENSION)compptr->v_samp_factor);
411
60.1k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
21.4k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
21.4k
}
418
419
#endif /* C_LOSSLESS_SUPPORTED */