Coverage Report

Created: 2025-10-10 07:05

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
170M
{
76
170M
  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
170M
  if (cinfo->comps_in_scan > 1) {
83
147M
    diff->MCU_rows_per_iMCU_row = 1;
84
147M
  } else {
85
22.9M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
22.8M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
11.8k
    else
88
11.8k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
22.9M
  }
90
91
170M
  diff->mcu_ctr = 0;
92
170M
  diff->MCU_vert_offset = 0;
93
170M
}
jcdiffct-8.c:start_iMCU_row
Line
Count
Source
75
53.1M
{
76
53.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
53.1M
  if (cinfo->comps_in_scan > 1) {
83
46.8M
    diff->MCU_rows_per_iMCU_row = 1;
84
46.8M
  } else {
85
6.27M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
6.26M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
3.91k
    else
88
3.91k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
6.27M
  }
90
91
53.1M
  diff->mcu_ctr = 0;
92
53.1M
  diff->MCU_vert_offset = 0;
93
53.1M
}
jcdiffct-12.c:start_iMCU_row
Line
Count
Source
75
57.2M
{
76
57.2M
  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
57.2M
  if (cinfo->comps_in_scan > 1) {
83
49.1M
    diff->MCU_rows_per_iMCU_row = 1;
84
49.1M
  } else {
85
8.04M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
8.04M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
3.71k
    else
88
3.71k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
8.04M
  }
90
91
57.2M
  diff->mcu_ctr = 0;
92
57.2M
  diff->MCU_vert_offset = 0;
93
57.2M
}
jcdiffct-16.c:start_iMCU_row
Line
Count
Source
75
60.1M
{
76
60.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
60.1M
  if (cinfo->comps_in_scan > 1) {
83
51.5M
    diff->MCU_rows_per_iMCU_row = 1;
84
51.5M
  } else {
85
8.58M
    if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
86
8.57M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
87
4.24k
    else
88
4.24k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
89
8.58M
  }
90
91
60.1M
  diff->mcu_ctr = 0;
92
60.1M
  diff->MCU_vert_offset = 0;
93
60.1M
}
94
95
96
/*
97
 * Initialize for a processing pass.
98
 */
99
100
METHODDEF(void)
101
start_pass_diff(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
102
48.4k
{
103
48.4k
  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
48.4k
  if (pass_mode == JBUF_CRANK_DEST)
111
24.2k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
48.4k
  diff->iMCU_row_num = 0;
114
48.4k
  start_iMCU_row(cinfo);
115
116
48.4k
  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
24.2k
  case JBUF_SAVE_AND_PASS:
124
24.2k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
24.2k
    diff->pub._compress_data = compress_first_pass;
127
24.2k
    break;
128
24.2k
  case JBUF_CRANK_DEST:
129
24.2k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
24.2k
    diff->pub._compress_data = compress_output;
132
24.2k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
48.4k
  }
138
48.4k
}
jcdiffct-8.c:start_pass_diff
Line
Count
Source
102
16.7k
{
103
16.7k
  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.7k
  if (pass_mode == JBUF_CRANK_DEST)
111
8.38k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
16.7k
  diff->iMCU_row_num = 0;
114
16.7k
  start_iMCU_row(cinfo);
115
116
16.7k
  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.38k
  case JBUF_SAVE_AND_PASS:
124
8.38k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
8.38k
    diff->pub._compress_data = compress_first_pass;
127
8.38k
    break;
128
8.38k
  case JBUF_CRANK_DEST:
129
8.38k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
8.38k
    diff->pub._compress_data = compress_output;
132
8.38k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
16.7k
  }
138
16.7k
}
jcdiffct-12.c:start_pass_diff
Line
Count
Source
102
15.3k
{
103
15.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
15.3k
  if (pass_mode == JBUF_CRANK_DEST)
111
7.65k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
15.3k
  diff->iMCU_row_num = 0;
114
15.3k
  start_iMCU_row(cinfo);
115
116
15.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
7.65k
  case JBUF_SAVE_AND_PASS:
124
7.65k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
7.65k
    diff->pub._compress_data = compress_first_pass;
127
7.65k
    break;
128
7.65k
  case JBUF_CRANK_DEST:
129
7.65k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
7.65k
    diff->pub._compress_data = compress_output;
132
7.65k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
15.3k
  }
138
15.3k
}
jcdiffct-16.c:start_pass_diff
Line
Count
Source
102
16.3k
{
103
16.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
16.3k
  if (pass_mode == JBUF_CRANK_DEST)
111
8.19k
    (*cinfo->fdct->start_pass) (cinfo);
112
113
16.3k
  diff->iMCU_row_num = 0;
114
16.3k
  start_iMCU_row(cinfo);
115
116
16.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
8.19k
  case JBUF_SAVE_AND_PASS:
124
8.19k
    if (diff->whole_image[0] == NULL)
125
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
126
8.19k
    diff->pub._compress_data = compress_first_pass;
127
8.19k
    break;
128
8.19k
  case JBUF_CRANK_DEST:
129
8.19k
    if (diff->whole_image[0] == NULL)
130
0
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
131
8.19k
    diff->pub._compress_data = compress_output;
132
8.19k
    break;
133
0
#endif
134
0
  default:
135
0
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
136
0
    break;
137
16.3k
  }
138
16.3k
}
139
140
141
490M
#define SWAP_ROWS(rowa, rowb) { \
142
490M
  _JSAMPROW temp = rowa; \
143
490M
  rowa = rowb;  rowb = temp; \
144
490M
}
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
170M
{
159
170M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
170M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
170M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
170M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
170M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
170M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
170M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
340M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
170M
       yoffset++) {
170
171
170M
    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
170M
    if (MCU_col_num == 0) {
179
660M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
490M
        compptr = cinfo->cur_comp_info[ci];
181
490M
        compi = compptr->component_index;
182
490M
        if (diff->iMCU_row_num < last_iMCU_row)
183
489M
          samp_rows = compptr->v_samp_factor;
184
140k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
140k
          samp_rows =
187
140k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
140k
          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
140k
        }
200
490M
        samps_across = compptr->width_in_blocks;
201
202
980M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
490M
          (*losslessc->scaler_scale) (cinfo,
204
490M
                                      input_buf[compi][samp_row],
205
490M
                                      diff->cur_row[compi],
206
490M
                                      samps_across);
207
490M
          (*losslessc->predict_difference[compi])
208
490M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
490M
             diff->diff_buf[compi][samp_row], samps_across);
210
490M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
490M
        }
212
490M
      }
213
170M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
170M
    MCU_count =
216
170M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
170M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
170M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
170M
    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
170M
    diff->mcu_ctr = 0;
227
170M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
170M
  diff->iMCU_row_num++;
230
170M
  start_iMCU_row(cinfo);
231
170M
  return TRUE;
232
170M
}
jcdiffct-8.c:compress_data
Line
Count
Source
158
53.1M
{
159
53.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
53.1M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
53.1M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
53.1M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
53.1M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
53.1M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
53.1M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
106M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
53.1M
       yoffset++) {
170
171
53.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
53.1M
    if (MCU_col_num == 0) {
179
207M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
154M
        compptr = cinfo->cur_comp_info[ci];
181
154M
        compi = compptr->component_index;
182
154M
        if (diff->iMCU_row_num < last_iMCU_row)
183
154M
          samp_rows = compptr->v_samp_factor;
184
48.8k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
48.8k
          samp_rows =
187
48.8k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
48.8k
          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.8k
        }
200
154M
        samps_across = compptr->width_in_blocks;
201
202
309M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
154M
          (*losslessc->scaler_scale) (cinfo,
204
154M
                                      input_buf[compi][samp_row],
205
154M
                                      diff->cur_row[compi],
206
154M
                                      samps_across);
207
154M
          (*losslessc->predict_difference[compi])
208
154M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
154M
             diff->diff_buf[compi][samp_row], samps_across);
210
154M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
154M
        }
212
154M
      }
213
53.1M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
53.1M
    MCU_count =
216
53.1M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
53.1M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
53.1M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
53.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
53.1M
    diff->mcu_ctr = 0;
227
53.1M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
53.1M
  diff->iMCU_row_num++;
230
53.1M
  start_iMCU_row(cinfo);
231
53.1M
  return TRUE;
232
53.1M
}
jcdiffct-12.c:compress_data
Line
Count
Source
158
57.1M
{
159
57.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
57.1M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
57.1M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
57.1M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
57.1M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
57.1M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
57.1M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
114M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
57.1M
       yoffset++) {
170
171
57.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
57.1M
    if (MCU_col_num == 0) {
179
220M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
163M
        compptr = cinfo->cur_comp_info[ci];
181
163M
        compi = compptr->component_index;
182
163M
        if (diff->iMCU_row_num < last_iMCU_row)
183
163M
          samp_rows = compptr->v_samp_factor;
184
44.3k
        else {
185
          /* NB: can't use last_row_height here, since may not be set! */
186
44.3k
          samp_rows =
187
44.3k
            (int)(compptr->height_in_blocks % compptr->v_samp_factor);
188
44.3k
          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
44.3k
        }
200
163M
        samps_across = compptr->width_in_blocks;
201
202
327M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
163M
          (*losslessc->scaler_scale) (cinfo,
204
163M
                                      input_buf[compi][samp_row],
205
163M
                                      diff->cur_row[compi],
206
163M
                                      samps_across);
207
163M
          (*losslessc->predict_difference[compi])
208
163M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
163M
             diff->diff_buf[compi][samp_row], samps_across);
210
163M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
163M
        }
212
163M
      }
213
57.1M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
57.1M
    MCU_count =
216
57.1M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
57.1M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
57.1M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
57.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
57.1M
    diff->mcu_ctr = 0;
227
57.1M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
57.1M
  diff->iMCU_row_num++;
230
57.1M
  start_iMCU_row(cinfo);
231
57.1M
  return TRUE;
232
57.1M
}
jcdiffct-16.c:compress_data
Line
Count
Source
158
60.0M
{
159
60.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
160
60.0M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
161
60.0M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
162
60.0M
  JDIMENSION MCU_count;         /* number of MCUs encoded */
163
60.0M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
164
60.0M
  int ci, compi, yoffset, samp_row, samp_rows, samps_across;
165
60.0M
  jpeg_component_info *compptr;
166
167
  /* Loop to write as much as one whole iMCU row */
168
120M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
169
60.0M
       yoffset++) {
170
171
60.0M
    MCU_col_num = diff->mcu_ctr;
172
173
    /* Scale and predict each scanline of the MCU row separately.
174
     *
175
     * Note: We only do this if we are at the start of an MCU row, ie,
176
     * we don't want to reprocess a row suspended by the output.
177
     */
178
60.0M
    if (MCU_col_num == 0) {
179
231M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
180
171M
        compptr = cinfo->cur_comp_info[ci];
181
171M
        compi = compptr->component_index;
182
171M
        if (diff->iMCU_row_num < last_iMCU_row)
183
171M
          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
171M
        samps_across = compptr->width_in_blocks;
201
202
343M
        for (samp_row = 0; samp_row < samp_rows; samp_row++) {
203
171M
          (*losslessc->scaler_scale) (cinfo,
204
171M
                                      input_buf[compi][samp_row],
205
171M
                                      diff->cur_row[compi],
206
171M
                                      samps_across);
207
171M
          (*losslessc->predict_difference[compi])
208
171M
            (cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
209
171M
             diff->diff_buf[compi][samp_row], samps_across);
210
171M
          SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
211
171M
        }
212
171M
      }
213
60.0M
    }
214
    /* Try to write the MCU row (or remaining portion of suspended MCU row). */
215
60.0M
    MCU_count =
216
60.0M
      (*cinfo->entropy->encode_mcus) (cinfo,
217
60.0M
                                      diff->diff_buf, yoffset, MCU_col_num,
218
60.0M
                                      cinfo->MCUs_per_row - MCU_col_num);
219
60.0M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
220
      /* Suspension forced; update state counters and exit */
221
0
      diff->MCU_vert_offset = yoffset;
222
0
      diff->mcu_ctr += MCU_col_num;
223
0
      return FALSE;
224
0
    }
225
    /* Completed an MCU row, but perhaps not an iMCU row */
226
60.0M
    diff->mcu_ctr = 0;
227
60.0M
  }
228
  /* Completed the iMCU row, advance counters for next one */
229
60.0M
  diff->iMCU_row_num++;
230
60.0M
  start_iMCU_row(cinfo);
231
60.0M
  return TRUE;
232
60.0M
}
233
234
235
#ifdef FULL_SAMP_BUFFER_SUPPORTED
236
237
/*
238
 * Process some data in the first pass of a multi-pass case.
239
 * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
240
 * per call, ie, v_samp_factor rows for each component in the image.
241
 * This amount of data is read from the source buffer and saved into the
242
 * virtual arrays.
243
 *
244
 * We must also emit the data to the compressor.  This is conveniently
245
 * done by calling compress_output() after we've loaded the current strip
246
 * of the virtual arrays.
247
 *
248
 * NB: input_buf contains a plane for each component in image.  All components
249
 * are loaded into the virtual arrays in this pass.  However, it may be that
250
 * only a subset of the components are emitted to the compressor during
251
 * this first pass; be careful about looking at the scan-dependent variables
252
 * (MCU dimensions, etc).
253
 */
254
255
METHODDEF(boolean)
256
compress_first_pass(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
257
85.2M
{
258
85.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
85.2M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
85.2M
  JDIMENSION samps_across;
261
85.2M
  int ci, samp_row, samp_rows;
262
85.2M
  _JSAMPARRAY buffer;
263
85.2M
  jpeg_component_info *compptr;
264
265
330M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
245M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
245M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
245M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
245M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
245M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
245M
    if (diff->iMCU_row_num < last_iMCU_row)
275
244M
      samp_rows = compptr->v_samp_factor;
276
70.3k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
70.3k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
70.3k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
70.3k
    }
281
245M
    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
490M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
245M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
245M
             samps_across * sizeof(_JSAMPLE));
290
245M
    }
291
245M
  }
292
  /* NB: compress_output will increment iMCU_row_num if successful.
293
   * A suspension return will result in redoing all the work above next time.
294
   */
295
296
  /* Emit data to the compressor, sharing code with subsequent passes */
297
85.2M
  return compress_output(cinfo, input_buf);
298
85.2M
}
jcdiffct-8.c:compress_first_pass
Line
Count
Source
257
26.5M
{
258
26.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
26.5M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
26.5M
  JDIMENSION samps_across;
261
26.5M
  int ci, samp_row, samp_rows;
262
26.5M
  _JSAMPARRAY buffer;
263
26.5M
  jpeg_component_info *compptr;
264
265
103M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
77.3M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
77.3M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
77.3M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
77.3M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
77.3M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
77.3M
    if (diff->iMCU_row_num < last_iMCU_row)
275
77.3M
      samp_rows = compptr->v_samp_factor;
276
24.4k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
24.4k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
24.4k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
24.4k
    }
281
77.3M
    samps_across = compptr->width_in_blocks;
282
283
    /* Perform point transform scaling and prediction/differencing for all
284
     * non-dummy rows in this iMCU row.  Each call on these functions
285
     * processes a complete row of samples.
286
     */
287
154M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
77.3M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
77.3M
             samps_across * sizeof(_JSAMPLE));
290
77.3M
    }
291
77.3M
  }
292
  /* NB: compress_output will increment iMCU_row_num if successful.
293
   * A suspension return will result in redoing all the work above next time.
294
   */
295
296
  /* Emit data to the compressor, sharing code with subsequent passes */
297
26.5M
  return compress_output(cinfo, input_buf);
298
26.5M
}
jcdiffct-12.c:compress_first_pass
Line
Count
Source
257
28.5M
{
258
28.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
28.5M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
28.5M
  JDIMENSION samps_across;
261
28.5M
  int ci, samp_row, samp_rows;
262
28.5M
  _JSAMPARRAY buffer;
263
28.5M
  jpeg_component_info *compptr;
264
265
110M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
81.8M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
81.8M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
81.8M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
81.8M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
81.8M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
81.8M
    if (diff->iMCU_row_num < last_iMCU_row)
275
81.8M
      samp_rows = compptr->v_samp_factor;
276
22.2k
    else {
277
      /* NB: can't use last_row_height here, since may not be set! */
278
22.2k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
279
22.2k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
280
22.2k
    }
281
81.8M
    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
163M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
81.8M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
81.8M
             samps_across * sizeof(_JSAMPLE));
290
81.8M
    }
291
81.8M
  }
292
  /* NB: compress_output will increment iMCU_row_num if successful.
293
   * A suspension return will result in redoing all the work above next time.
294
   */
295
296
  /* Emit data to the compressor, sharing code with subsequent passes */
297
28.5M
  return compress_output(cinfo, input_buf);
298
28.5M
}
jcdiffct-16.c:compress_first_pass
Line
Count
Source
257
30.0M
{
258
30.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
259
30.0M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
260
30.0M
  JDIMENSION samps_across;
261
30.0M
  int ci, samp_row, samp_rows;
262
30.0M
  _JSAMPARRAY buffer;
263
30.0M
  jpeg_component_info *compptr;
264
265
115M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
266
85.8M
       ci++, compptr++) {
267
    /* Align the virtual buffer for this component. */
268
85.8M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
269
85.8M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
270
85.8M
       diff->iMCU_row_num * compptr->v_samp_factor,
271
85.8M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
272
273
    /* Count non-dummy sample rows in this iMCU row. */
274
85.8M
    if (diff->iMCU_row_num < last_iMCU_row)
275
85.8M
      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
85.8M
    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
171M
    for (samp_row = 0; samp_row < samp_rows; samp_row++) {
288
85.8M
      memcpy(buffer[samp_row], input_buf[ci][samp_row],
289
85.8M
             samps_across * sizeof(_JSAMPLE));
290
85.8M
    }
291
85.8M
  }
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.0M
  return compress_output(cinfo, input_buf);
298
30.0M
}
299
300
301
/*
302
 * Process some data in subsequent passes of a multi-pass case.
303
 * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
304
 * per call, ie, v_samp_factor rows for each component in the scan.
305
 * The data is obtained from the virtual arrays and fed to the compressor.
306
 * Returns TRUE if the iMCU row is completed, FALSE if suspended.
307
 *
308
 * NB: input_buf is ignored; it is likely to be a NULL pointer.
309
 */
310
311
METHODDEF(boolean)
312
compress_output(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
313
170M
{
314
170M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
170M
  int ci, compi;
316
170M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
170M
  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
660M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
490M
    compptr = cinfo->cur_comp_info[ci];
325
490M
    compi = compptr->component_index;
326
490M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
490M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
490M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
490M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
490M
  }
331
332
170M
  return compress_data(cinfo, buffer);
333
170M
}
jcdiffct-8.c:compress_output
Line
Count
Source
313
53.1M
{
314
53.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
53.1M
  int ci, compi;
316
53.1M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
53.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
207M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
154M
    compptr = cinfo->cur_comp_info[ci];
325
154M
    compi = compptr->component_index;
326
154M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
154M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
154M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
154M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
154M
  }
331
332
53.1M
  return compress_data(cinfo, buffer);
333
53.1M
}
jcdiffct-12.c:compress_output
Line
Count
Source
313
57.1M
{
314
57.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
57.1M
  int ci, compi;
316
57.1M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
57.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
220M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
163M
    compptr = cinfo->cur_comp_info[ci];
325
163M
    compi = compptr->component_index;
326
163M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
163M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
163M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
163M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
163M
  }
331
332
57.1M
  return compress_data(cinfo, buffer);
333
57.1M
}
jcdiffct-16.c:compress_output
Line
Count
Source
313
60.0M
{
314
60.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
315
60.0M
  int ci, compi;
316
60.0M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
317
60.0M
  jpeg_component_info *compptr;
318
319
  /* Align the virtual buffers for the components used in this scan.
320
   * NB: during first pass, this is safe only because the buffers will
321
   * already be aligned properly, so jmemmgr.c won't need to do any I/O.
322
   */
323
231M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
324
171M
    compptr = cinfo->cur_comp_info[ci];
325
171M
    compi = compptr->component_index;
326
171M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
327
171M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
328
171M
       diff->iMCU_row_num * compptr->v_samp_factor,
329
171M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
330
171M
  }
331
332
60.0M
  return compress_data(cinfo, buffer);
333
60.0M
}
334
335
#endif /* FULL_SAMP_BUFFER_SUPPORTED */
336
337
338
/*
339
 * Initialize difference buffer controller.
340
 */
341
342
GLOBAL(void)
343
_jinit_c_diff_controller(j_compress_ptr cinfo, boolean need_full_buffer)
344
24.2k
{
345
24.2k
  my_diff_ptr diff;
346
24.2k
  int ci, row;
347
24.2k
  jpeg_component_info *compptr;
348
349
#if BITS_IN_JSAMPLE == 8
350
8.38k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
351
#else
352
15.8k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
15.8k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
24.2k
  diff = (my_diff_ptr)
358
24.2k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
24.2k
                                sizeof(my_diff_controller));
360
24.2k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
24.2k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
94.5k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
70.3k
       ci++, compptr++) {
366
70.3k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
70.3k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
70.3k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
70.3k
                             (long)compptr->h_samp_factor),
370
70.3k
       (JDIMENSION)1);
371
70.3k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
70.3k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
70.3k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
70.3k
                             (long)compptr->h_samp_factor),
375
70.3k
       (JDIMENSION)1);
376
70.3k
  }
377
378
  /* Create the difference buffer. */
379
94.5k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
70.3k
       ci++, compptr++) {
381
70.3k
    diff->diff_buf[ci] =
382
70.3k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
70.3k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
70.3k
                                         (long)compptr->h_samp_factor),
385
70.3k
                   (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
140k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
70.3k
      memset(diff->diff_buf[ci][row], 0,
393
70.3k
             jround_up((long)compptr->width_in_blocks,
394
70.3k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
70.3k
  }
396
397
  /* Create the sample buffer. */
398
24.2k
  if (need_full_buffer) {
399
24.2k
#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
94.5k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
70.3k
         ci++, compptr++) {
404
70.3k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
70.3k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
70.3k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
70.3k
                               (long)compptr->h_samp_factor),
408
70.3k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
70.3k
                               (long)compptr->v_samp_factor),
410
70.3k
         (JDIMENSION)compptr->v_samp_factor);
411
70.3k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
24.2k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
24.2k
}
jinit_c_diff_controller
Line
Count
Source
344
8.38k
{
345
8.38k
  my_diff_ptr diff;
346
8.38k
  int ci, row;
347
8.38k
  jpeg_component_info *compptr;
348
349
8.38k
#if BITS_IN_JSAMPLE == 8
350
8.38k
  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.38k
  diff = (my_diff_ptr)
358
8.38k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
8.38k
                                sizeof(my_diff_controller));
360
8.38k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
8.38k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
32.8k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
24.4k
       ci++, compptr++) {
366
24.4k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
24.4k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
24.4k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
24.4k
                             (long)compptr->h_samp_factor),
370
24.4k
       (JDIMENSION)1);
371
24.4k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
24.4k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
24.4k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
24.4k
                             (long)compptr->h_samp_factor),
375
24.4k
       (JDIMENSION)1);
376
24.4k
  }
377
378
  /* Create the difference buffer. */
379
32.8k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
24.4k
       ci++, compptr++) {
381
24.4k
    diff->diff_buf[ci] =
382
24.4k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
24.4k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
24.4k
                                         (long)compptr->h_samp_factor),
385
24.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
48.8k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
24.4k
      memset(diff->diff_buf[ci][row], 0,
393
24.4k
             jround_up((long)compptr->width_in_blocks,
394
24.4k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
24.4k
  }
396
397
  /* Create the sample buffer. */
398
8.38k
  if (need_full_buffer) {
399
8.38k
#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
32.8k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
24.4k
         ci++, compptr++) {
404
24.4k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
24.4k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
24.4k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
24.4k
                               (long)compptr->h_samp_factor),
408
24.4k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
24.4k
                               (long)compptr->v_samp_factor),
410
24.4k
         (JDIMENSION)compptr->v_samp_factor);
411
24.4k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
8.38k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
8.38k
}
j12init_c_diff_controller
Line
Count
Source
344
7.65k
{
345
7.65k
  my_diff_ptr diff;
346
7.65k
  int ci, row;
347
7.65k
  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
7.65k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
7.65k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
7.65k
  diff = (my_diff_ptr)
358
7.65k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
7.65k
                                sizeof(my_diff_controller));
360
7.65k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
7.65k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
29.8k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
365
22.2k
       ci++, compptr++) {
366
22.2k
    diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
367
22.2k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
368
22.2k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
369
22.2k
                             (long)compptr->h_samp_factor),
370
22.2k
       (JDIMENSION)1);
371
22.2k
    diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
372
22.2k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
373
22.2k
       (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
22.2k
                             (long)compptr->h_samp_factor),
375
22.2k
       (JDIMENSION)1);
376
22.2k
  }
377
378
  /* Create the difference buffer. */
379
29.8k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
380
22.2k
       ci++, compptr++) {
381
22.2k
    diff->diff_buf[ci] =
382
22.2k
      ALLOC_DARRAY(JPOOL_IMAGE,
383
22.2k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
384
22.2k
                                         (long)compptr->h_samp_factor),
385
22.2k
                   (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
44.4k
    for (row = 0; row < compptr->v_samp_factor; row++)
392
22.2k
      memset(diff->diff_buf[ci][row], 0,
393
22.2k
             jround_up((long)compptr->width_in_blocks,
394
22.2k
                       (long)compptr->h_samp_factor) * sizeof(JDIFF));
395
22.2k
  }
396
397
  /* Create the sample buffer. */
398
7.65k
  if (need_full_buffer) {
399
7.65k
#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
29.8k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
403
22.2k
         ci++, compptr++) {
404
22.2k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
405
22.2k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
406
22.2k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
407
22.2k
                               (long)compptr->h_samp_factor),
408
22.2k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
409
22.2k
                               (long)compptr->v_samp_factor),
410
22.2k
         (JDIMENSION)compptr->v_samp_factor);
411
22.2k
    }
412
#else
413
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
414
#endif
415
7.65k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
7.65k
}
j16init_c_diff_controller
Line
Count
Source
344
8.19k
{
345
8.19k
  my_diff_ptr diff;
346
8.19k
  int ci, row;
347
8.19k
  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.19k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
353
8.19k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
354
0
#endif
355
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
356
357
8.19k
  diff = (my_diff_ptr)
358
8.19k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
359
8.19k
                                sizeof(my_diff_controller));
360
8.19k
  cinfo->coef = (struct jpeg_c_coef_controller *)diff;
361
8.19k
  diff->pub.start_pass = start_pass_diff;
362
363
  /* Create the prediction row buffers. */
364
31.8k
  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.8k
  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.3k
    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.19k
  if (need_full_buffer) {
399
8.19k
#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.8k
    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.19k
  } else
416
0
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
417
8.19k
}
418
419
#endif /* C_LOSSLESS_SUPPORTED */