Coverage Report

Created: 2025-11-24 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/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
174M
{
76
174M
  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
174M
  if (cinfo->comps_in_scan > 1) {
83
150M
    diff->MCU_rows_per_iMCU_row = 1;
84
150M
  } else {
85
23.4M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
23.4M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
12.5k
    else
88
12.5k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
23.4M
  }
90
91
174M
  diff->mcu_ctr = 0;
92
174M
  diff->MCU_vert_offset = 0;
93
174M
}
jcdiffct-8.c:start_iMCU_row
Line
Count
Source
75
55.1M
{
76
55.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
77
78
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
79
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
80
   * But at the bottom of the image, process only what's left.
81
   */
82
55.1M
  if (cinfo->comps_in_scan > 1) {
83
48.5M
    diff->MCU_rows_per_iMCU_row = 1;
84
48.5M
  } else {
85
6.64M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
6.64M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
4.11k
    else
88
4.11k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
6.64M
  }
90
91
55.1M
  diff->mcu_ctr = 0;
92
55.1M
  diff->MCU_vert_offset = 0;
93
55.1M
}
jcdiffct-12.c:start_iMCU_row
Line
Count
Source
75
52.5M
{
76
52.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
52.5M
  if (cinfo->comps_in_scan > 1) {
83
45.1M
    diff->MCU_rows_per_iMCU_row = 1;
84
45.1M
  } else {
85
7.37M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
7.37M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
3.97k
    else
88
3.97k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
7.37M
  }
90
91
52.5M
  diff->mcu_ctr = 0;
92
52.5M
  diff->MCU_vert_offset = 0;
93
52.5M
}
jcdiffct-16.c:start_iMCU_row
Line
Count
Source
75
66.3M
{
76
66.3M
  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
66.3M
  if (cinfo->comps_in_scan > 1) {
83
56.8M
    diff->MCU_rows_per_iMCU_row = 1;
84
56.8M
  } else {
85
9.45M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
9.44M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
4.44k
    else
88
4.44k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
9.45M
  }
90
91
66.3M
  diff->mcu_ctr = 0;
92
66.3M
  diff->MCU_vert_offset = 0;
93
66.3M
}
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
50.8k
{
103
50.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
50.8k
  if (pass_mode == JBUF_CRANK_DEST)
111
25.4k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
50.8k
  diff->iMCU_row_num = 0;
114
50.8k
  start_iMCU_row(cinfo);
115
116
50.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
25.4k
  case JBUF_SAVE_AND_PASS:
124
25.4k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
25.4k
    diff->pub._compress_data = compress_first_pass;
127
25.4k
    break;
128
25.4k
  case JBUF_CRANK_DEST:
129
25.4k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
25.4k
    diff->pub._compress_data = compress_output;
132
25.4k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
50.8k
  }
138
50.8k
}
jcdiffct-8.c:start_pass_diff
Line
Count
Source
102
17.5k
{
103
17.5k
  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
17.5k
  if (pass_mode == JBUF_CRANK_DEST)
111
8.75k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
17.5k
  diff->iMCU_row_num = 0;
114
17.5k
  start_iMCU_row(cinfo);
115
116
17.5k
  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
8.75k
  case JBUF_SAVE_AND_PASS:
124
8.75k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
8.75k
    diff->pub._compress_data = compress_first_pass;
127
8.75k
    break;
128
8.75k
  case JBUF_CRANK_DEST:
129
8.75k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
8.75k
    diff->pub._compress_data = compress_output;
132
8.75k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
17.5k
  }
138
17.5k
}
jcdiffct-12.c:start_pass_diff
Line
Count
Source
102
16.2k
{
103
16.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
16.2k
  if (pass_mode == JBUF_CRANK_DEST)
111
8.14k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
16.2k
  diff->iMCU_row_num = 0;
114
16.2k
  start_iMCU_row(cinfo);
115
116
16.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
8.14k
  case JBUF_SAVE_AND_PASS:
124
8.14k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
8.14k
    diff->pub._compress_data = compress_first_pass;
127
8.14k
    break;
128
8.14k
  case JBUF_CRANK_DEST:
129
8.14k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
8.14k
    diff->pub._compress_data = compress_output;
132
8.14k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
16.2k
  }
138
16.2k
}
jcdiffct-16.c:start_pass_diff
Line
Count
Source
102
17.0k
{
103
17.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
17.0k
  if (pass_mode == JBUF_CRANK_DEST)
111
8.52k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
17.0k
  diff->iMCU_row_num = 0;
114
17.0k
  start_iMCU_row(cinfo);
115
116
17.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
8.52k
  case JBUF_SAVE_AND_PASS:
124
8.52k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
8.52k
    diff->pub._compress_data = compress_first_pass;
127
8.52k
    break;
128
8.52k
  case JBUF_CRANK_DEST:
129
8.52k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
8.52k
    diff->pub._compress_data = compress_output;
132
8.52k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
17.0k
  }
138
17.0k
}
139
140
141
500M
#define SWAP_ROWS(rowa, rowb) { \
142
500M
  _JSAMPROW temp = rowa; \
143
500M
  rowa = rowb;  rowb = temp; \
144
500M
}
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
173M
{
159
173M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
173M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
173M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
173M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
173M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
173M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
173M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
347M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
173M
       yoffset++) {
170
171
173M
    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
173M
    if (MCU_col_num == 0) {
179
674M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
500M
        compptr = cinfo->cur_comp_info[ci];
181
500M
        compi = compptr->component_index;
182
500M
        if (diff->iMCU_row_num < last_iMCU_row)
183
499M
          samp_rows = compptr->v_samp_factor;
184
147k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
147k
          samp_rows =
187
147k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
147k
          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
147k
        }
200
500M
        samps_across = compptr->width_in_blocks;
201
202
1.00G
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
500M
          (*losslessc->scaler_scale) (cinfo,
204
500M
                                      input_buf[compi][samp_row],
205
500M
                                      diff->cur_row[compi],
206
500M
                                      samps_across);
207
500M
          (*losslessc->predict_difference[compi])
208
500M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
500M
             diff->diff_buf[compi][samp_row], samps_across);
210
500M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
500M
        }
212
500M
      }
213
173M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
173M
    MCU_count =
216
173M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
173M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
173M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
173M
    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
173M
    diff->mcu_ctr = 0;
227
173M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
173M
  diff->iMCU_row_num++;
230
173M
  start_iMCU_row(cinfo);
231
173M
  return TRUE;
232
173M
}
jcdiffct-8.c:compress_data
Line
Count
Source
158
55.1M
{
159
55.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
55.1M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
55.1M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
55.1M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
55.1M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
55.1M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
55.1M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
110M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
55.1M
       yoffset++) {
170
171
55.1M
    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.1M
    if (MCU_col_num == 0) {
179
215M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
160M
        compptr = cinfo->cur_comp_info[ci];
181
160M
        compi = compptr->component_index;
182
160M
        if (diff->iMCU_row_num < last_iMCU_row)
183
160M
          samp_rows = compptr->v_samp_factor;
184
50.9k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
50.9k
          samp_rows =
187
50.9k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
50.9k
          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
50.9k
        }
200
160M
        samps_across = compptr->width_in_blocks;
201
202
320M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
160M
          (*losslessc->scaler_scale) (cinfo,
204
160M
                                      input_buf[compi][samp_row],
205
160M
                                      diff->cur_row[compi],
206
160M
                                      samps_across);
207
160M
          (*losslessc->predict_difference[compi])
208
160M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
160M
             diff->diff_buf[compi][samp_row], samps_across);
210
160M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
160M
        }
212
160M
      }
213
55.1M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
55.1M
    MCU_count =
216
55.1M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
55.1M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
55.1M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
55.1M
    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.1M
    diff->mcu_ctr = 0;
227
55.1M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
55.1M
  diff->iMCU_row_num++;
230
55.1M
  start_iMCU_row(cinfo);
231
55.1M
  return TRUE;
232
55.1M
}
jcdiffct-12.c:compress_data
Line
Count
Source
158
52.5M
{
159
52.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
52.5M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
52.5M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
52.5M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
52.5M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
52.5M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
52.5M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
105M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
52.5M
       yoffset++) {
170
171
52.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
52.5M
    if (MCU_col_num == 0) {
179
202M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
150M
        compptr = cinfo->cur_comp_info[ci];
181
150M
        compi = compptr->component_index;
182
150M
        if (diff->iMCU_row_num < last_iMCU_row)
183
150M
          samp_rows = compptr->v_samp_factor;
184
47.1k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
47.1k
          samp_rows =
187
47.1k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
47.1k
          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
47.1k
        }
200
150M
        samps_across = compptr->width_in_blocks;
201
202
300M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
150M
          (*losslessc->scaler_scale) (cinfo,
204
150M
                                      input_buf[compi][samp_row],
205
150M
                                      diff->cur_row[compi],
206
150M
                                      samps_across);
207
150M
          (*losslessc->predict_difference[compi])
208
150M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
150M
             diff->diff_buf[compi][samp_row], samps_across);
210
150M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
150M
        }
212
150M
      }
213
52.5M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
52.5M
    MCU_count =
216
52.5M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
52.5M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
52.5M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
52.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
52.5M
    diff->mcu_ctr = 0;
227
52.5M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
52.5M
  diff->iMCU_row_num++;
230
52.5M
  start_iMCU_row(cinfo);
231
52.5M
  return TRUE;
232
52.5M
}
jcdiffct-16.c:compress_data
Line
Count
Source
158
66.3M
{
159
66.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
66.3M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
66.3M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
66.3M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
66.3M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
66.3M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
66.3M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
132M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
66.3M
       yoffset++) {
170
171
66.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
66.3M
    if (MCU_col_num == 0) {
179
255M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
189M
        compptr = cinfo->cur_comp_info[ci];
181
189M
        compi = compptr->component_index;
182
189M
        if (diff->iMCU_row_num < last_iMCU_row)
183
189M
          samp_rows = compptr->v_samp_factor;
184
48.9k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
48.9k
          samp_rows =
187
48.9k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
48.9k
          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
48.9k
        }
200
189M
        samps_across = compptr->width_in_blocks;
201
202
379M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
189M
          (*losslessc->scaler_scale) (cinfo,
204
189M
                                      input_buf[compi][samp_row],
205
189M
                                      diff->cur_row[compi],
206
189M
                                      samps_across);
207
189M
          (*losslessc->predict_difference[compi])
208
189M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
189M
             diff->diff_buf[compi][samp_row], samps_across);
210
189M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
189M
        }
212
189M
      }
213
66.3M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
66.3M
    MCU_count =
216
66.3M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
66.3M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
66.3M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
66.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
66.3M
    diff->mcu_ctr = 0;
227
66.3M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
66.3M
  diff->iMCU_row_num++;
230
66.3M
  start_iMCU_row(cinfo);
231
66.3M
  return TRUE;
232
66.3M
}
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
86.9M
{
258
86.9M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
86.9M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
86.9M
  JDIMENSION samps_across;
261
86.9M
  int ci, samp_row, samp_rows;
262
86.9M
  _JSAMPARRAY buffer;
263
86.9M
  jpeg_component_info *compptr;
264
265
337M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
250M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
250M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
250M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
250M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
250M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
250M
    if (diff->iMCU_row_num < last_iMCU_row)
275
249M
      samp_rows = compptr->v_samp_factor;
276
73.6k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
73.6k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
73.6k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
73.6k
    }
281
250M
    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
500M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
250M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
250M
             samps_across * sizeof(_JSAMPLE));
290
250M
    }
291
250M
  }
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
86.9M
  return compress_output(cinfo, input_buf);
298
86.9M
}
jcdiffct-8.c:compress_first_pass
Line
Count
Source
257
27.5M
{
258
27.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
27.5M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
27.5M
  JDIMENSION samps_across;
261
27.5M
  int ci, samp_row, samp_rows;
262
27.5M
  _JSAMPARRAY buffer;
263
27.5M
  jpeg_component_info *compptr;
264
265
107M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
80.1M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
80.1M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
80.1M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
80.1M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
80.1M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
80.1M
    if (diff->iMCU_row_num < last_iMCU_row)
275
80.0M
      samp_rows = compptr->v_samp_factor;
276
25.4k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
25.4k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
25.4k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
25.4k
    }
281
80.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
160M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
80.1M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
80.1M
             samps_across * sizeof(_JSAMPLE));
290
80.1M
    }
291
80.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.5M
  return compress_output(cinfo, input_buf);
298
27.5M
}
jcdiffct-12.c:compress_first_pass
Line
Count
Source
257
26.2M
{
258
26.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
26.2M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
26.2M
  JDIMENSION samps_across;
261
26.2M
  int ci, samp_row, samp_rows;
262
26.2M
  _JSAMPARRAY buffer;
263
26.2M
  jpeg_component_info *compptr;
264
265
101M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
75.1M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
75.1M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
75.1M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
75.1M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
75.1M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
75.1M
    if (diff->iMCU_row_num < last_iMCU_row)
275
75.1M
      samp_rows = compptr->v_samp_factor;
276
23.6k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
23.6k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
23.6k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
23.6k
    }
281
75.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
150M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
75.1M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
75.1M
             samps_across * sizeof(_JSAMPLE));
290
75.1M
    }
291
75.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
26.2M
  return compress_output(cinfo, input_buf);
298
26.2M
}
jcdiffct-16.c:compress_first_pass
Line
Count
Source
257
33.1M
{
258
33.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
33.1M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
33.1M
  JDIMENSION samps_across;
261
33.1M
  int ci, samp_row, samp_rows;
262
33.1M
  _JSAMPARRAY buffer;
263
33.1M
  jpeg_component_info *compptr;
264
265
127M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
94.7M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
94.7M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
94.7M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
94.7M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
94.7M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
94.7M
    if (diff->iMCU_row_num < last_iMCU_row)
275
94.7M
      samp_rows = compptr->v_samp_factor;
276
24.5k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
24.5k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
24.5k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
24.5k
    }
281
94.7M
    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
189M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
94.7M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
94.7M
             samps_across * sizeof(_JSAMPLE));
290
94.7M
    }
291
94.7M
  }
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.1M
  return compress_output(cinfo, input_buf);
298
33.1M
}
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
173M
{
314
173M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
173M
  int ci, compi;
316
173M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
173M
  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
674M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
500M
    compptr = cinfo->cur_comp_info[ci];
325
500M
    compi = compptr->component_index;
326
500M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
500M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
500M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
500M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
500M
  }
331
332
173M
  return compress_data(cinfo, buffer);
333
173M
}
jcdiffct-8.c:compress_output
Line
Count
Source
313
55.1M
{
314
55.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
55.1M
  int ci, compi;
316
55.1M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
55.1M
  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
215M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
160M
    compptr = cinfo->cur_comp_info[ci];
325
160M
    compi = compptr->component_index;
326
160M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
160M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
160M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
160M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
160M
  }
331
332
55.1M
  return compress_data(cinfo, buffer);
333
55.1M
}
jcdiffct-12.c:compress_output
Line
Count
Source
313
52.5M
{
314
52.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
52.5M
  int ci, compi;
316
52.5M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
52.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
202M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
150M
    compptr = cinfo->cur_comp_info[ci];
325
150M
    compi = compptr->component_index;
326
150M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
150M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
150M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
150M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
150M
  }
331
332
52.5M
  return compress_data(cinfo, buffer);
333
52.5M
}
jcdiffct-16.c:compress_output
Line
Count
Source
313
66.3M
{
314
66.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
66.3M
  int ci, compi;
316
66.3M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
66.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
255M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
189M
    compptr = cinfo->cur_comp_info[ci];
325
189M
    compi = compptr->component_index;
326
189M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
189M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
189M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
189M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
189M
  }
331
332
66.3M
  return compress_data(cinfo, buffer);
333
66.3M
}
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
25.4k
{
345
25.4k
  my_diff_ptr diff;
346
25.4k
  int ci, row;
347
25.4k
  jpeg_component_info *compptr;
348
349
#if BITS_IN_JSAMPLE == 8
350
8.75k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
351
#else
352
16.6k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
16.6k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
25.4k
  diff = (my_diff_ptr)
358
25.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
25.4k
                                sizeof(my_diff_controller));
360
25.4k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
25.4k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
99.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
73.6k
       ci++, compptr++) {
366
73.6k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
73.6k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
73.6k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
73.6k
                             (long)compptr->h_samp_factor),
370
73.6k
       (JDIMENSION)1);
371
73.6k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
73.6k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
73.6k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
73.6k
                             (long)compptr->h_samp_factor),
375
73.6k
       (JDIMENSION)1);
376
73.6k
  }
377
378
  /* Create the difference buffer. */
379
99.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
73.6k
       ci++, compptr++) {
381
73.6k
    diff->diff_buf[ci] =
382
73.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
73.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
73.6k
                                         (long)compptr->h_samp_factor),
385
73.6k
                   (JDIMENSION)compptr->v_samp_factor);
386
    /* Prefill difference rows with zeros.  We do this because only actual
387
     * data is placed in the buffers during prediction/differencing, leaving
388
     * any dummy differences at the right edge as zeros, which will encode
389
     * to the smallest amount of data.
390
     */
391
147k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
73.6k
      memset(diff->diff_buf[ci][row], 0,
393
73.6k
             jround_up((long)compptr->width_in_blocks,
394
73.6k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
73.6k
  }
396
397
  /* Create the sample buffer. */
398
25.4k
  if (need_full_buffer) {
399
25.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
99.0k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
73.6k
         ci++, compptr++) {
404
73.6k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
73.6k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
73.6k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
73.6k
                               (long)compptr->h_samp_factor),
408
73.6k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
73.6k
                               (long)compptr->v_samp_factor),
410
73.6k
         (JDIMENSION)compptr->v_samp_factor);
411
73.6k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
25.4k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
25.4k
}
jinit_c_diff_controller
Line
Count
Source
344
8.75k
{
345
8.75k
  my_diff_ptr diff;
346
8.75k
  int ci, row;
347
8.75k
  jpeg_component_info *compptr;
348
349
8.75k
#if BITS_IN_JSAMPLE == 8
350
8.75k
  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
8.75k
  diff = (my_diff_ptr)
358
8.75k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
8.75k
                                sizeof(my_diff_controller));
360
8.75k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
8.75k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
34.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
25.4k
       ci++, compptr++) {
366
25.4k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
25.4k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
25.4k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
25.4k
                             (long)compptr->h_samp_factor),
370
25.4k
       (JDIMENSION)1);
371
25.4k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
25.4k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
25.4k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
25.4k
                             (long)compptr->h_samp_factor),
375
25.4k
       (JDIMENSION)1);
376
25.4k
  }
377
378
  /* Create the difference buffer. */
379
34.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
25.4k
       ci++, compptr++) {
381
25.4k
    diff->diff_buf[ci] =
382
25.4k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
25.4k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
25.4k
                                         (long)compptr->h_samp_factor),
385
25.4k
                   (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
50.9k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
25.4k
      memset(diff->diff_buf[ci][row], 0,
393
25.4k
             jround_up((long)compptr->width_in_blocks,
394
25.4k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
25.4k
  }
396
397
  /* Create the sample buffer. */
398
8.75k
  if (need_full_buffer) {
399
8.75k
#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
34.2k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
25.4k
         ci++, compptr++) {
404
25.4k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
25.4k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
25.4k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
25.4k
                               (long)compptr->h_samp_factor),
408
25.4k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
25.4k
                               (long)compptr->v_samp_factor),
410
25.4k
         (JDIMENSION)compptr->v_samp_factor);
411
25.4k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
8.75k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
8.75k
}
j12init_c_diff_controller
Line
Count
Source
344
8.14k
{
345
8.14k
  my_diff_ptr diff;
346
8.14k
  int ci, row;
347
8.14k
  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
8.14k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
8.14k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
8.14k
  diff = (my_diff_ptr)
358
8.14k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
8.14k
                                sizeof(my_diff_controller));
360
8.14k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
8.14k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
31.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
23.6k
       ci++, compptr++) {
366
23.6k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
23.6k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
23.6k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
23.6k
                             (long)compptr->h_samp_factor),
370
23.6k
       (JDIMENSION)1);
371
23.6k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
23.6k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
23.6k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
23.6k
                             (long)compptr->h_samp_factor),
375
23.6k
       (JDIMENSION)1);
376
23.6k
  }
377
378
  /* Create the difference buffer. */
379
31.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
23.6k
       ci++, compptr++) {
381
23.6k
    diff->diff_buf[ci] =
382
23.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
23.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
23.6k
                                         (long)compptr->h_samp_factor),
385
23.6k
                   (JDIMENSION)compptr->v_samp_factor);
386
    /* Prefill difference rows with zeros.  We do this because only actual
387
     * data is placed in the buffers during prediction/differencing, leaving
388
     * any dummy differences at the right edge as zeros, which will encode
389
     * to the smallest amount of data.
390
     */
391
47.2k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
23.6k
      memset(diff->diff_buf[ci][row], 0,
393
23.6k
             jround_up((long)compptr->width_in_blocks,
394
23.6k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
23.6k
  }
396
397
  /* Create the sample buffer. */
398
8.14k
  if (need_full_buffer) {
399
8.14k
#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
31.7k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
23.6k
         ci++, compptr++) {
404
23.6k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
23.6k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
23.6k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
23.6k
                               (long)compptr->h_samp_factor),
408
23.6k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
23.6k
                               (long)compptr->v_samp_factor),
410
23.6k
         (JDIMENSION)compptr->v_samp_factor);
411
23.6k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
8.14k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
8.14k
}
j16init_c_diff_controller
Line
Count
Source
344
8.52k
{
345
8.52k
  my_diff_ptr diff;
346
8.52k
  int ci, row;
347
8.52k
  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
8.52k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
8.52k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
8.52k
  diff = (my_diff_ptr)
358
8.52k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
8.52k
                                sizeof(my_diff_controller));
360
8.52k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
8.52k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
33.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
24.5k
       ci++, compptr++) {
366
24.5k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
24.5k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
24.5k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
24.5k
                             (long)compptr->h_samp_factor),
370
24.5k
       (JDIMENSION)1);
371
24.5k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
24.5k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
24.5k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
24.5k
                             (long)compptr->h_samp_factor),
375
24.5k
       (JDIMENSION)1);
376
24.5k
  }
377
378
  /* Create the difference buffer. */
379
33.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
24.5k
       ci++, compptr++) {
381
24.5k
    diff->diff_buf[ci] =
382
24.5k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
24.5k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
24.5k
                                         (long)compptr->h_samp_factor),
385
24.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
49.1k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
24.5k
      memset(diff->diff_buf[ci][row], 0,
393
24.5k
             jround_up((long)compptr->width_in_blocks,
394
24.5k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
24.5k
  }
396
397
  /* Create the sample buffer. */
398
8.52k
  if (need_full_buffer) {
399
8.52k
#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
33.0k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
24.5k
         ci++, compptr++) {
404
24.5k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
24.5k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
24.5k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
24.5k
                               (long)compptr->h_samp_factor),
408
24.5k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
24.5k
                               (long)compptr->v_samp_factor),
410
24.5k
         (JDIMENSION)compptr->v_samp_factor);
411
24.5k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
8.52k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
8.52k
}
418
419
#endif /* C_LOSSLESS_SUPPORTED */