Coverage Report

Created: 2026-08-13 07:24

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
184M
{
76
184M
  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
184M
  if (cinfo->comps_in_scan > 1) {
83
160M
    diff->MCU_rows_per_iMCU_row = 1;
84
160M
  } else {
85
24.0M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
24.0M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
52.1k
    else
88
52.1k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
24.0M
  }
90
91
184M
  diff->mcu_ctr = 0;
92
184M
  diff->MCU_vert_offset = 0;
93
184M
}
jcdiffct-8.c:start_iMCU_row
Line
Count
Source
75
55.8M
{
76
55.8M
  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
55.8M
  if (cinfo->comps_in_scan > 1) {
83
50.0M
    diff->MCU_rows_per_iMCU_row = 1;
84
50.0M
  } else {
85
5.75M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
5.73M
      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
5.75M
  }
90
91
55.8M
  diff->mcu_ctr = 0;
92
55.8M
  diff->MCU_vert_offset = 0;
93
55.8M
}
jcdiffct-12.c:start_iMCU_row
Line
Count
Source
75
61.0M
{
76
61.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
61.0M
  if (cinfo->comps_in_scan > 1) {
83
52.2M
    diff->MCU_rows_per_iMCU_row = 1;
84
52.2M
  } else {
85
8.71M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
8.69M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
16.0k
    else
88
16.0k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
8.71M
  }
90
91
61.0M
  diff->mcu_ctr = 0;
92
61.0M
  diff->MCU_vert_offset = 0;
93
61.0M
}
jcdiffct-16.c:start_iMCU_row
Line
Count
Source
75
67.5M
{
76
67.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
67.5M
  if (cinfo->comps_in_scan > 1) {
83
57.9M
    diff->MCU_rows_per_iMCU_row = 1;
84
57.9M
  } else {
85
9.59M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
9.58M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
14.6k
    else
88
14.6k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
9.59M
  }
90
91
67.5M
  diff->mcu_ctr = 0;
92
67.5M
  diff->MCU_vert_offset = 0;
93
67.5M
}
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.7k
    (*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.7k
  case JBUF_SAVE_AND_PASS:
124
72.7k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
72.7k
    diff->pub._compress_data = compress_first_pass;
127
72.7k
    break;
128
72.7k
  case JBUF_CRANK_DEST:
129
72.7k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
72.7k
    diff->pub._compress_data = compress_output;
132
72.7k
    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.8k
{
103
57.8k
  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.8k
  if (pass_mode == JBUF_CRANK_DEST)
111
28.9k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
57.8k
  diff->iMCU_row_num = 0;
114
57.8k
  start_iMCU_row(cinfo);
115
116
57.8k
  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.8k
  }
138
57.8k
}
jcdiffct-12.c:start_pass_diff
Line
Count
Source
102
45.2k
{
103
45.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
45.2k
  if (pass_mode == JBUF_CRANK_DEST)
111
22.6k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
45.2k
  diff->iMCU_row_num = 0;
114
45.2k
  start_iMCU_row(cinfo);
115
116
45.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
22.6k
  case JBUF_SAVE_AND_PASS:
124
22.6k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
22.6k
    diff->pub._compress_data = compress_first_pass;
127
22.6k
    break;
128
22.6k
  case JBUF_CRANK_DEST:
129
22.6k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
22.6k
    diff->pub._compress_data = compress_output;
132
22.6k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
45.2k
  }
138
45.2k
}
jcdiffct-16.c:start_pass_diff
Line
Count
Source
102
42.3k
{
103
42.3k
  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.3k
  if (pass_mode == JBUF_CRANK_DEST)
111
21.1k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
42.3k
  diff->iMCU_row_num = 0;
114
42.3k
  start_iMCU_row(cinfo);
115
116
42.3k
  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.3k
  }
138
42.3k
}
139
140
141
531M
#define SWAP_ROWS(rowa, rowb) { \
142
531M
  _JSAMPROW temp = rowa; \
143
531M
  rowa = rowb;  rowb = temp; \
144
531M
}
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
184M
{
159
184M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
184M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
184M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
184M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
184M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
184M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
184M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
368M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
184M
       yoffset++) {
170
171
184M
    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
184M
    if (MCU_col_num == 0) {
179
715M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
531M
        compptr = cinfo->cur_comp_info[ci];
181
531M
        compi = compptr->component_index;
182
531M
        if (diff->iMCU_row_num < last_iMCU_row)
183
531M
          samp_rows = compptr->v_samp_factor;
184
403k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
403k
          samp_rows =
187
403k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
403k
          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
403k
        }
200
531M
        samps_across = compptr->width_in_blocks;
201
202
1.06G
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
531M
          (*losslessc->scaler_scale) (cinfo,
204
531M
                                      input_buf[compi][samp_row],
205
531M
                                      diff->cur_row[compi],
206
531M
                                      samps_across);
207
531M
          (*losslessc->predict_difference[compi])
208
531M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
531M
             diff->diff_buf[compi][samp_row], samps_across);
210
531M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
531M
        }
212
531M
      }
213
184M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
184M
    MCU_count =
216
184M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
184M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
184M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
184M
    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
184M
    diff->mcu_ctr = 0;
227
184M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
184M
  diff->iMCU_row_num++;
230
184M
  start_iMCU_row(cinfo);
231
184M
  return TRUE;
232
184M
}
jcdiffct-8.c:compress_data
Line
Count
Source
158
55.7M
{
159
55.7M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
55.7M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
55.7M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
55.7M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
55.7M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
55.7M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
55.7M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
111M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
55.7M
       yoffset++) {
170
171
55.7M
    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
55.7M
    if (MCU_col_num == 0) {
179
219M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
164M
        compptr = cinfo->cur_comp_info[ci];
181
164M
        compi = compptr->component_index;
182
164M
        if (diff->iMCU_row_num < last_iMCU_row)
183
164M
          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
164M
        samps_across = compptr->width_in_blocks;
201
202
328M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
164M
          (*losslessc->scaler_scale) (cinfo,
204
164M
                                      input_buf[compi][samp_row],
205
164M
                                      diff->cur_row[compi],
206
164M
                                      samps_across);
207
164M
          (*losslessc->predict_difference[compi])
208
164M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
164M
             diff->diff_buf[compi][samp_row], samps_across);
210
164M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
164M
        }
212
164M
      }
213
55.7M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
55.7M
    MCU_count =
216
55.7M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
55.7M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
55.7M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
55.7M
    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
55.7M
    diff->mcu_ctr = 0;
227
55.7M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
55.7M
  diff->iMCU_row_num++;
230
55.7M
  start_iMCU_row(cinfo);
231
55.7M
  return TRUE;
232
55.7M
}
jcdiffct-12.c:compress_data
Line
Count
Source
158
60.9M
{
159
60.9M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
60.9M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
60.9M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
60.9M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
60.9M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
60.9M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
60.9M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
121M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
60.9M
       yoffset++) {
170
171
60.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
60.9M
    if (MCU_col_num == 0) {
179
235M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
174M
        compptr = cinfo->cur_comp_info[ci];
181
174M
        compi = compptr->component_index;
182
174M
        if (diff->iMCU_row_num < last_iMCU_row)
183
174M
          samp_rows = compptr->v_samp_factor;
184
125k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
125k
          samp_rows =
187
125k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
125k
          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
125k
        }
200
174M
        samps_across = compptr->width_in_blocks;
201
202
348M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
174M
          (*losslessc->scaler_scale) (cinfo,
204
174M
                                      input_buf[compi][samp_row],
205
174M
                                      diff->cur_row[compi],
206
174M
                                      samps_across);
207
174M
          (*losslessc->predict_difference[compi])
208
174M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
174M
             diff->diff_buf[compi][samp_row], samps_across);
210
174M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
174M
        }
212
174M
      }
213
60.9M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
60.9M
    MCU_count =
216
60.9M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
60.9M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
60.9M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
60.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
60.9M
    diff->mcu_ctr = 0;
227
60.9M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
60.9M
  diff->iMCU_row_num++;
230
60.9M
  start_iMCU_row(cinfo);
231
60.9M
  return TRUE;
232
60.9M
}
jcdiffct-16.c:compress_data
Line
Count
Source
158
67.5M
{
159
67.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
67.5M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
67.5M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
67.5M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
67.5M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
67.5M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
67.5M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
135M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
67.5M
       yoffset++) {
170
171
67.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
67.5M
    if (MCU_col_num == 0) {
179
260M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
193M
        compptr = cinfo->cur_comp_info[ci];
181
193M
        compi = compptr->component_index;
182
193M
        if (diff->iMCU_row_num < last_iMCU_row)
183
193M
          samp_rows = compptr->v_samp_factor;
184
118k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
118k
          samp_rows =
187
118k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
118k
          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
118k
        }
200
193M
        samps_across = compptr->width_in_blocks;
201
202
386M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
193M
          (*losslessc->scaler_scale) (cinfo,
204
193M
                                      input_buf[compi][samp_row],
205
193M
                                      diff->cur_row[compi],
206
193M
                                      samps_across);
207
193M
          (*losslessc->predict_difference[compi])
208
193M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
193M
             diff->diff_buf[compi][samp_row], samps_across);
210
193M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
193M
        }
212
193M
      }
213
67.5M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
67.5M
    MCU_count =
216
67.5M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
67.5M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
67.5M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
67.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
67.5M
    diff->mcu_ctr = 0;
227
67.5M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
67.5M
  diff->iMCU_row_num++;
230
67.5M
  start_iMCU_row(cinfo);
231
67.5M
  return TRUE;
232
67.5M
}
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
92.1M
{
258
92.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
92.1M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
92.1M
  JDIMENSION samps_across;
261
92.1M
  int ci, samp_row, samp_rows;
262
92.1M
  _JSAMPARRAY buffer;
263
92.1M
  jpeg_component_info *compptr;
264
265
357M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
265M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
265M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
265M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
265M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
265M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
265M
    if (diff->iMCU_row_num < last_iMCU_row)
275
265M
      samp_rows = compptr->v_samp_factor;
276
201k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
201k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
201k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
201k
    }
281
265M
    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
531M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
265M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
265M
             samps_across * sizeof(_JSAMPLE));
290
265M
    }
291
265M
  }
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
92.1M
  return compress_output(cinfo, input_buf);
298
92.1M
}
jcdiffct-8.c:compress_first_pass
Line
Count
Source
257
27.8M
{
258
27.8M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
27.8M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
27.8M
  JDIMENSION samps_across;
261
27.8M
  int ci, samp_row, samp_rows;
262
27.8M
  _JSAMPARRAY buffer;
263
27.8M
  jpeg_component_info *compptr;
264
265
109M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
82.1M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
82.1M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
82.1M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
82.1M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
82.1M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
82.1M
    if (diff->iMCU_row_num < last_iMCU_row)
275
82.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
82.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
164M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
82.1M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
82.1M
             samps_across * sizeof(_JSAMPLE));
290
82.1M
    }
291
82.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
27.8M
  return compress_output(cinfo, input_buf);
298
27.8M
}
jcdiffct-12.c:compress_first_pass
Line
Count
Source
257
30.4M
{
258
30.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
30.4M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
30.4M
  JDIMENSION samps_across;
261
30.4M
  int ci, samp_row, samp_rows;
262
30.4M
  _JSAMPARRAY buffer;
263
30.4M
  jpeg_component_info *compptr;
264
265
117M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
87.0M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
87.0M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
87.0M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
87.0M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
87.0M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
87.0M
    if (diff->iMCU_row_num < last_iMCU_row)
275
87.0M
      samp_rows = compptr->v_samp_factor;
276
62.9k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
62.9k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
62.9k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
62.9k
    }
281
87.0M
    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
174M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
87.0M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
87.0M
             samps_across * sizeof(_JSAMPLE));
290
87.0M
    }
291
87.0M
  }
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.4M
  return compress_output(cinfo, input_buf);
298
30.4M
}
jcdiffct-16.c:compress_first_pass
Line
Count
Source
257
33.7M
{
258
33.7M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
33.7M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
33.7M
  JDIMENSION samps_across;
261
33.7M
  int ci, samp_row, samp_rows;
262
33.7M
  _JSAMPARRAY buffer;
263
33.7M
  jpeg_component_info *compptr;
264
265
130M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
96.5M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
96.5M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
96.5M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
96.5M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
96.5M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
96.5M
    if (diff->iMCU_row_num < last_iMCU_row)
275
96.5M
      samp_rows = compptr->v_samp_factor;
276
59.1k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
59.1k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
59.1k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
59.1k
    }
281
96.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
193M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
96.5M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
96.5M
             samps_across * sizeof(_JSAMPLE));
290
96.5M
    }
291
96.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
33.7M
  return compress_output(cinfo, input_buf);
298
33.7M
}
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
184M
{
314
184M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
184M
  int ci, compi;
316
184M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
184M
  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
715M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
531M
    compptr = cinfo->cur_comp_info[ci];
325
531M
    compi = compptr->component_index;
326
531M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
531M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
531M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
531M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
531M
  }
331
332
184M
  return compress_data(cinfo, buffer);
333
184M
}
jcdiffct-8.c:compress_output
Line
Count
Source
313
55.7M
{
314
55.7M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
55.7M
  int ci, compi;
316
55.7M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
55.7M
  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
219M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
164M
    compptr = cinfo->cur_comp_info[ci];
325
164M
    compi = compptr->component_index;
326
164M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
164M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
164M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
164M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
164M
  }
331
332
55.7M
  return compress_data(cinfo, buffer);
333
55.7M
}
jcdiffct-12.c:compress_output
Line
Count
Source
313
60.9M
{
314
60.9M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
60.9M
  int ci, compi;
316
60.9M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
60.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
235M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
174M
    compptr = cinfo->cur_comp_info[ci];
325
174M
    compi = compptr->component_index;
326
174M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
174M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
174M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
174M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
174M
  }
331
332
60.9M
  return compress_data(cinfo, buffer);
333
60.9M
}
jcdiffct-16.c:compress_output
Line
Count
Source
313
67.5M
{
314
67.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
67.5M
  int ci, compi;
316
67.5M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
67.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
260M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
193M
    compptr = cinfo->cur_comp_info[ci];
325
193M
    compi = compptr->component_index;
326
193M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
193M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
193M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
193M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
193M
  }
331
332
67.5M
  return compress_data(cinfo, buffer);
333
67.5M
}
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.7k
{
345
72.7k
  my_diff_ptr diff;
346
72.7k
  int ci, row;
347
72.7k
  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.8k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
43.8k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
72.7k
  diff = (my_diff_ptr)
358
72.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
72.7k
                                sizeof(my_diff_controller));
360
72.7k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
72.7k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
274k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
201k
       ci++, compptr++) {
366
201k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
201k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
201k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
201k
                             (long)compptr->h_samp_factor),
370
201k
       (JDIMENSION)1);
371
201k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
201k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
201k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
201k
                             (long)compptr->h_samp_factor),
375
201k
       (JDIMENSION)1);
376
201k
  }
377
378
  /* Create the difference buffer. */
379
274k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
201k
       ci++, compptr++) {
381
201k
    diff->diff_buf[ci] =
382
201k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
201k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
201k
                                         (long)compptr->h_samp_factor),
385
201k
                   (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
403k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
201k
      memset(diff->diff_buf[ci][row], 0,
393
201k
             jround_up((long)compptr->width_in_blocks,
394
201k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
201k
  }
396
397
  /* Create the sample buffer. */
398
72.7k
  if (need_full_buffer) {
399
72.7k
#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
274k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
201k
         ci++, compptr++) {
404
201k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
201k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
201k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
201k
                               (long)compptr->h_samp_factor),
408
201k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
201k
                               (long)compptr->v_samp_factor),
410
201k
         (JDIMENSION)compptr->v_samp_factor);
411
201k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
72.7k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
72.7k
}
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.6k
{
345
22.6k
  my_diff_ptr diff;
346
22.6k
  int ci, row;
347
22.6k
  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.6k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
22.6k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
22.6k
  diff = (my_diff_ptr)
358
22.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
22.6k
                                sizeof(my_diff_controller));
360
22.6k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
22.6k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
85.5k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
62.9k
       ci++, compptr++) {
366
62.9k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
62.9k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
62.9k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
62.9k
                             (long)compptr->h_samp_factor),
370
62.9k
       (JDIMENSION)1);
371
62.9k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
62.9k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
62.9k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
62.9k
                             (long)compptr->h_samp_factor),
375
62.9k
       (JDIMENSION)1);
376
62.9k
  }
377
378
  /* Create the difference buffer. */
379
85.5k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
62.9k
       ci++, compptr++) {
381
62.9k
    diff->diff_buf[ci] =
382
62.9k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
62.9k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
62.9k
                                         (long)compptr->h_samp_factor),
385
62.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
125k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
62.9k
      memset(diff->diff_buf[ci][row], 0,
393
62.9k
             jround_up((long)compptr->width_in_blocks,
394
62.9k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
62.9k
  }
396
397
  /* Create the sample buffer. */
398
22.6k
  if (need_full_buffer) {
399
22.6k
#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
85.5k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
62.9k
         ci++, compptr++) {
404
62.9k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
62.9k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
62.9k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
62.9k
                               (long)compptr->h_samp_factor),
408
62.9k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
62.9k
                               (long)compptr->v_samp_factor),
410
62.9k
         (JDIMENSION)compptr->v_samp_factor);
411
62.9k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
22.6k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
22.6k
}
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.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
59.1k
       ci++, compptr++) {
366
59.1k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
59.1k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
59.1k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
59.1k
                             (long)compptr->h_samp_factor),
370
59.1k
       (JDIMENSION)1);
371
59.1k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
59.1k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
59.1k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
59.1k
                             (long)compptr->h_samp_factor),
375
59.1k
       (JDIMENSION)1);
376
59.1k
  }
377
378
  /* Create the difference buffer. */
379
80.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
59.1k
       ci++, compptr++) {
381
59.1k
    diff->diff_buf[ci] =
382
59.1k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
59.1k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
59.1k
                                         (long)compptr->h_samp_factor),
385
59.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
118k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
59.1k
      memset(diff->diff_buf[ci][row], 0,
393
59.1k
             jround_up((long)compptr->width_in_blocks,
394
59.1k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
59.1k
  }
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.2k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
59.1k
         ci++, compptr++) {
404
59.1k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
59.1k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
59.1k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
59.1k
                               (long)compptr->h_samp_factor),
408
59.1k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
59.1k
                               (long)compptr->v_samp_factor),
410
59.1k
         (JDIMENSION)compptr->v_samp_factor);
411
59.1k
    }
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 */