/src/libjpeg-turbo.3.1.x/src/jddiffct.c
Line | Count | Source |
1 | | /* |
2 | | * jddiffct.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 [un]difference buffer controller for decompression. |
14 | | * This controller is the top level of the lossless JPEG decompressor proper. |
15 | | * The difference buffer lies between the entropy decoding and |
16 | | * prediction/undifferencing steps. The undifference buffer lies between the |
17 | | * prediction/undifferencing and scaling steps. |
18 | | * |
19 | | * In buffered-image mode, this controller is the interface between |
20 | | * input-oriented processing and output-oriented processing. |
21 | | */ |
22 | | |
23 | | #define JPEG_INTERNALS |
24 | | #include "jinclude.h" |
25 | | #include "jpeglib.h" |
26 | | #include "jlossls.h" /* Private declarations for lossless codec */ |
27 | | |
28 | | |
29 | | #ifdef D_LOSSLESS_SUPPORTED |
30 | | |
31 | | /* Private buffer controller object */ |
32 | | |
33 | | typedef struct { |
34 | | struct jpeg_d_coef_controller pub; /* public fields */ |
35 | | |
36 | | /* These variables keep track of the current location of the input side. */ |
37 | | /* cinfo->input_iMCU_row is also used for this. */ |
38 | | JDIMENSION MCU_ctr; /* counts MCUs processed in current row */ |
39 | | unsigned int restart_rows_to_go; /* MCU rows left in this restart |
40 | | interval */ |
41 | | unsigned int MCU_vert_offset; /* counts MCU rows within iMCU row */ |
42 | | unsigned int MCU_rows_per_iMCU_row; /* number of such rows needed */ |
43 | | |
44 | | /* The output side's location is represented by cinfo->output_iMCU_row. */ |
45 | | |
46 | | JDIFFARRAY diff_buf[MAX_COMPONENTS]; /* iMCU row of differences */ |
47 | | JDIFFARRAY undiff_buf[MAX_COMPONENTS]; /* iMCU row of undiff'd samples */ |
48 | | |
49 | | #ifdef D_MULTISCAN_FILES_SUPPORTED |
50 | | /* In multi-pass modes, we need a virtual sample array for each component. */ |
51 | | jvirt_sarray_ptr whole_image[MAX_COMPONENTS]; |
52 | | #endif |
53 | | } my_diff_controller; |
54 | | |
55 | | typedef my_diff_controller *my_diff_ptr; |
56 | | |
57 | | /* Forward declarations */ |
58 | | METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf); |
59 | | #ifdef D_MULTISCAN_FILES_SUPPORTED |
60 | | METHODDEF(int) output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf); |
61 | | #endif |
62 | | |
63 | | |
64 | | LOCAL(void) |
65 | | start_iMCU_row(j_decompress_ptr cinfo) |
66 | | /* Reset within-iMCU-row counters for a new row (input side) */ |
67 | 199M | { |
68 | 199M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; |
69 | | |
70 | | /* In an interleaved scan, an MCU row is the same as an iMCU row. |
71 | | * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. |
72 | | * But at the bottom of the image, process only what's left. |
73 | | */ |
74 | 199M | if (cinfo->comps_in_scan > 1) { |
75 | 44.3M | diff->MCU_rows_per_iMCU_row = 1; |
76 | 155M | } else { |
77 | 155M | if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1)) |
78 | 155M | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; |
79 | 28.8k | else |
80 | 28.8k | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; |
81 | 155M | } |
82 | | |
83 | 199M | diff->MCU_ctr = 0; |
84 | 199M | diff->MCU_vert_offset = 0; |
85 | 199M | } jddiffct-8.c:start_iMCU_row Line | Count | Source | 67 | 46.5M | { | 68 | 46.5M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 69 | | | 70 | | /* In an interleaved scan, an MCU row is the same as an iMCU row. | 71 | | * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. | 72 | | * But at the bottom of the image, process only what's left. | 73 | | */ | 74 | 46.5M | if (cinfo->comps_in_scan > 1) { | 75 | 14.5M | diff->MCU_rows_per_iMCU_row = 1; | 76 | 31.9M | } else { | 77 | 31.9M | if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1)) | 78 | 31.9M | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; | 79 | 9.31k | else | 80 | 9.31k | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; | 81 | 31.9M | } | 82 | | | 83 | 46.5M | diff->MCU_ctr = 0; | 84 | 46.5M | diff->MCU_vert_offset = 0; | 85 | 46.5M | } |
jddiffct-12.c:start_iMCU_row Line | Count | Source | 67 | 59.8M | { | 68 | 59.8M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 69 | | | 70 | | /* In an interleaved scan, an MCU row is the same as an iMCU row. | 71 | | * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. | 72 | | * But at the bottom of the image, process only what's left. | 73 | | */ | 74 | 59.8M | if (cinfo->comps_in_scan > 1) { | 75 | 8.56M | diff->MCU_rows_per_iMCU_row = 1; | 76 | 51.2M | } else { | 77 | 51.2M | if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1)) | 78 | 51.2M | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; | 79 | 8.20k | else | 80 | 8.20k | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; | 81 | 51.2M | } | 82 | | | 83 | 59.8M | diff->MCU_ctr = 0; | 84 | 59.8M | diff->MCU_vert_offset = 0; | 85 | 59.8M | } |
jddiffct-16.c:start_iMCU_row Line | Count | Source | 67 | 93.3M | { | 68 | 93.3M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 69 | | | 70 | | /* In an interleaved scan, an MCU row is the same as an iMCU row. | 71 | | * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. | 72 | | * But at the bottom of the image, process only what's left. | 73 | | */ | 74 | 93.3M | if (cinfo->comps_in_scan > 1) { | 75 | 21.2M | diff->MCU_rows_per_iMCU_row = 1; | 76 | 72.0M | } else { | 77 | 72.0M | if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1)) | 78 | 72.0M | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; | 79 | 11.3k | else | 80 | 11.3k | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; | 81 | 72.0M | } | 82 | | | 83 | 93.3M | diff->MCU_ctr = 0; | 84 | 93.3M | diff->MCU_vert_offset = 0; | 85 | 93.3M | } |
|
86 | | |
87 | | |
88 | | /* |
89 | | * Initialize for an input processing pass. |
90 | | */ |
91 | | |
92 | | METHODDEF(void) |
93 | | start_input_pass(j_decompress_ptr cinfo) |
94 | 39.8k | { |
95 | 39.8k | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; |
96 | | |
97 | | /* Because it is hitching a ride on the jpeg_inverse_dct struct, |
98 | | * start_pass_lossless() will be called at the start of the output pass. |
99 | | * This ensures that it will be called at the start of the input pass as |
100 | | * well. |
101 | | */ |
102 | 39.8k | (*cinfo->idct->start_pass) (cinfo); |
103 | | |
104 | | /* Check that the restart interval is an integer multiple of the number |
105 | | * of MCUs in an MCU row. |
106 | | */ |
107 | 39.8k | if (cinfo->restart_interval % cinfo->MCUs_per_row != 0) |
108 | 401 | ERREXIT2(cinfo, JERR_BAD_RESTART, |
109 | 39.8k | cinfo->restart_interval, cinfo->MCUs_per_row); |
110 | | |
111 | | /* Initialize restart counter */ |
112 | 39.8k | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; |
113 | | |
114 | 39.8k | cinfo->input_iMCU_row = 0; |
115 | 39.8k | start_iMCU_row(cinfo); |
116 | 39.8k | } jddiffct-8.c:start_input_pass Line | Count | Source | 94 | 13.2k | { | 95 | 13.2k | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 96 | | | 97 | | /* Because it is hitching a ride on the jpeg_inverse_dct struct, | 98 | | * start_pass_lossless() will be called at the start of the output pass. | 99 | | * This ensures that it will be called at the start of the input pass as | 100 | | * well. | 101 | | */ | 102 | 13.2k | (*cinfo->idct->start_pass) (cinfo); | 103 | | | 104 | | /* Check that the restart interval is an integer multiple of the number | 105 | | * of MCUs in an MCU row. | 106 | | */ | 107 | 13.2k | if (cinfo->restart_interval % cinfo->MCUs_per_row != 0) | 108 | 102 | ERREXIT2(cinfo, JERR_BAD_RESTART, | 109 | 13.2k | cinfo->restart_interval, cinfo->MCUs_per_row); | 110 | | | 111 | | /* Initialize restart counter */ | 112 | 13.2k | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; | 113 | | | 114 | 13.2k | cinfo->input_iMCU_row = 0; | 115 | 13.2k | start_iMCU_row(cinfo); | 116 | 13.2k | } |
jddiffct-12.c:start_input_pass Line | Count | Source | 94 | 11.3k | { | 95 | 11.3k | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 96 | | | 97 | | /* Because it is hitching a ride on the jpeg_inverse_dct struct, | 98 | | * start_pass_lossless() will be called at the start of the output pass. | 99 | | * This ensures that it will be called at the start of the input pass as | 100 | | * well. | 101 | | */ | 102 | 11.3k | (*cinfo->idct->start_pass) (cinfo); | 103 | | | 104 | | /* Check that the restart interval is an integer multiple of the number | 105 | | * of MCUs in an MCU row. | 106 | | */ | 107 | 11.3k | if (cinfo->restart_interval % cinfo->MCUs_per_row != 0) | 108 | 123 | ERREXIT2(cinfo, JERR_BAD_RESTART, | 109 | 11.3k | cinfo->restart_interval, cinfo->MCUs_per_row); | 110 | | | 111 | | /* Initialize restart counter */ | 112 | 11.3k | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; | 113 | | | 114 | 11.3k | cinfo->input_iMCU_row = 0; | 115 | 11.3k | start_iMCU_row(cinfo); | 116 | 11.3k | } |
jddiffct-16.c:start_input_pass Line | Count | Source | 94 | 15.1k | { | 95 | 15.1k | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 96 | | | 97 | | /* Because it is hitching a ride on the jpeg_inverse_dct struct, | 98 | | * start_pass_lossless() will be called at the start of the output pass. | 99 | | * This ensures that it will be called at the start of the input pass as | 100 | | * well. | 101 | | */ | 102 | 15.1k | (*cinfo->idct->start_pass) (cinfo); | 103 | | | 104 | | /* Check that the restart interval is an integer multiple of the number | 105 | | * of MCUs in an MCU row. | 106 | | */ | 107 | 15.1k | if (cinfo->restart_interval % cinfo->MCUs_per_row != 0) | 108 | 176 | ERREXIT2(cinfo, JERR_BAD_RESTART, | 109 | 15.1k | cinfo->restart_interval, cinfo->MCUs_per_row); | 110 | | | 111 | | /* Initialize restart counter */ | 112 | 15.1k | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; | 113 | | | 114 | 15.1k | cinfo->input_iMCU_row = 0; | 115 | 15.1k | start_iMCU_row(cinfo); | 116 | 15.1k | } |
|
117 | | |
118 | | |
119 | | /* |
120 | | * Check for a restart marker & resynchronize decoder, undifferencer. |
121 | | * Returns FALSE if must suspend. |
122 | | */ |
123 | | |
124 | | METHODDEF(boolean) |
125 | | process_restart(j_decompress_ptr cinfo) |
126 | 69.9M | { |
127 | 69.9M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; |
128 | | |
129 | 69.9M | if (!(*cinfo->entropy->process_restart) (cinfo)) |
130 | 0 | return FALSE; |
131 | | |
132 | 69.9M | (*cinfo->idct->start_pass) (cinfo); |
133 | | |
134 | | /* Reset restart counter */ |
135 | 69.9M | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; |
136 | | |
137 | 69.9M | return TRUE; |
138 | 69.9M | } jddiffct-8.c:process_restart Line | Count | Source | 126 | 14.8M | { | 127 | 14.8M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 128 | | | 129 | 14.8M | if (!(*cinfo->entropy->process_restart) (cinfo)) | 130 | 0 | return FALSE; | 131 | | | 132 | 14.8M | (*cinfo->idct->start_pass) (cinfo); | 133 | | | 134 | | /* Reset restart counter */ | 135 | 14.8M | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; | 136 | | | 137 | 14.8M | return TRUE; | 138 | 14.8M | } |
jddiffct-12.c:process_restart Line | Count | Source | 126 | 1.32M | { | 127 | 1.32M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 128 | | | 129 | 1.32M | if (!(*cinfo->entropy->process_restart) (cinfo)) | 130 | 0 | return FALSE; | 131 | | | 132 | 1.32M | (*cinfo->idct->start_pass) (cinfo); | 133 | | | 134 | | /* Reset restart counter */ | 135 | 1.32M | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; | 136 | | | 137 | 1.32M | return TRUE; | 138 | 1.32M | } |
jddiffct-16.c:process_restart Line | Count | Source | 126 | 53.7M | { | 127 | 53.7M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 128 | | | 129 | 53.7M | if (!(*cinfo->entropy->process_restart) (cinfo)) | 130 | 0 | return FALSE; | 131 | | | 132 | 53.7M | (*cinfo->idct->start_pass) (cinfo); | 133 | | | 134 | | /* Reset restart counter */ | 135 | 53.7M | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; | 136 | | | 137 | 53.7M | return TRUE; | 138 | 53.7M | } |
|
139 | | |
140 | | |
141 | | /* |
142 | | * Initialize for an output processing pass. |
143 | | */ |
144 | | |
145 | | METHODDEF(void) |
146 | | start_output_pass(j_decompress_ptr cinfo) |
147 | 10.7k | { |
148 | 10.7k | cinfo->output_iMCU_row = 0; |
149 | 10.7k | } jddiffct-8.c:start_output_pass Line | Count | Source | 147 | 4.33k | { | 148 | 4.33k | cinfo->output_iMCU_row = 0; | 149 | 4.33k | } |
jddiffct-12.c:start_output_pass Line | Count | Source | 147 | 3.17k | { | 148 | 3.17k | cinfo->output_iMCU_row = 0; | 149 | 3.17k | } |
jddiffct-16.c:start_output_pass Line | Count | Source | 147 | 3.22k | { | 148 | 3.22k | cinfo->output_iMCU_row = 0; | 149 | 3.22k | } |
|
150 | | |
151 | | |
152 | | /* |
153 | | * Decompress and return some data in the supplied buffer. |
154 | | * Always attempts to emit one fully interleaved MCU row ("iMCU" row). |
155 | | * Input and output must run in lockstep since we have only a one-MCU buffer. |
156 | | * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
157 | | * |
158 | | * NB: output_buf contains a plane for each component in image, |
159 | | * which we index according to the component's SOF position. |
160 | | */ |
161 | | |
162 | | METHODDEF(int) |
163 | | decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf) |
164 | 199M | { |
165 | 199M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; |
166 | 199M | lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct; |
167 | 199M | JDIMENSION MCU_col_num; /* index of current MCU within row */ |
168 | 199M | JDIMENSION MCU_count; /* number of MCUs decoded */ |
169 | 199M | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
170 | 199M | int ci, compi, row, prev_row; |
171 | 199M | unsigned int yoffset; |
172 | 199M | jpeg_component_info *compptr; |
173 | | |
174 | | /* Loop to process as much as one whole iMCU row */ |
175 | 508M | for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row; |
176 | 308M | yoffset++) { |
177 | | |
178 | | /* Process restart marker if needed; may have to suspend */ |
179 | 308M | if (cinfo->restart_interval) { |
180 | 110M | if (diff->restart_rows_to_go == 0) |
181 | 69.9M | if (!process_restart(cinfo)) |
182 | 0 | return JPEG_SUSPENDED; |
183 | 110M | } |
184 | | |
185 | 308M | MCU_col_num = diff->MCU_ctr; |
186 | | /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */ |
187 | 308M | MCU_count = |
188 | 308M | (*cinfo->entropy->decode_mcus) (cinfo, |
189 | 308M | diff->diff_buf, yoffset, MCU_col_num, |
190 | 308M | cinfo->MCUs_per_row - MCU_col_num); |
191 | 308M | if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) { |
192 | | /* Suspension forced; update state counters and exit */ |
193 | 0 | diff->MCU_vert_offset = yoffset; |
194 | 0 | diff->MCU_ctr += MCU_count; |
195 | 0 | return JPEG_SUSPENDED; |
196 | 0 | } |
197 | | |
198 | | /* Account for restart interval (no-op if not using restarts) */ |
199 | 308M | if (cinfo->restart_interval) |
200 | 110M | diff->restart_rows_to_go--; |
201 | | |
202 | | /* Completed an MCU row, but perhaps not an iMCU row */ |
203 | 308M | diff->MCU_ctr = 0; |
204 | 308M | } |
205 | | |
206 | | /* |
207 | | * Undifference and scale each scanline of the disassembled MCU row |
208 | | * separately. We do not process dummy samples at the end of a scanline |
209 | | * or dummy rows at the end of the image. |
210 | | */ |
211 | 457M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
212 | 258M | compptr = cinfo->cur_comp_info[ci]; |
213 | 258M | compi = compptr->component_index; |
214 | 258M | for (row = 0, prev_row = compptr->v_samp_factor - 1; |
215 | 673M | row < (cinfo->input_iMCU_row == last_iMCU_row ? |
216 | 673M | compptr->last_row_height : compptr->v_samp_factor); |
217 | 415M | prev_row = row, row++) { |
218 | 415M | (*losslessd->predict_undifference[compi]) |
219 | 415M | (cinfo, compi, diff->diff_buf[compi][row], |
220 | 415M | diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row], |
221 | 415M | compptr->width_in_blocks); |
222 | 415M | (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row], |
223 | 415M | output_buf[compi][row], |
224 | 415M | compptr->width_in_blocks); |
225 | 415M | } |
226 | 258M | } |
227 | | |
228 | | /* Completed the iMCU row, advance counters for next one. |
229 | | * |
230 | | * NB: output_data will increment output_iMCU_row. |
231 | | * This counter is not needed for the single-pass case |
232 | | * or the input side of the multi-pass case. |
233 | | */ |
234 | 199M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { |
235 | 199M | start_iMCU_row(cinfo); |
236 | 199M | return JPEG_ROW_COMPLETED; |
237 | 199M | } |
238 | | /* Completed the scan */ |
239 | 37.8k | (*cinfo->inputctl->finish_input_pass) (cinfo); |
240 | 37.8k | return JPEG_SCAN_COMPLETED; |
241 | 199M | } jddiffct-8.c:decompress_data Line | Count | Source | 164 | 46.5M | { | 165 | 46.5M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 166 | 46.5M | lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct; | 167 | 46.5M | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 168 | 46.5M | JDIMENSION MCU_count; /* number of MCUs decoded */ | 169 | 46.5M | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 170 | 46.5M | int ci, compi, row, prev_row; | 171 | 46.5M | unsigned int yoffset; | 172 | 46.5M | jpeg_component_info *compptr; | 173 | | | 174 | | /* Loop to process as much as one whole iMCU row */ | 175 | 124M | for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row; | 176 | 77.6M | yoffset++) { | 177 | | | 178 | | /* Process restart marker if needed; may have to suspend */ | 179 | 77.6M | if (cinfo->restart_interval) { | 180 | 25.7M | if (diff->restart_rows_to_go == 0) | 181 | 14.8M | if (!process_restart(cinfo)) | 182 | 0 | return JPEG_SUSPENDED; | 183 | 25.7M | } | 184 | | | 185 | 77.6M | MCU_col_num = diff->MCU_ctr; | 186 | | /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */ | 187 | 77.6M | MCU_count = | 188 | 77.6M | (*cinfo->entropy->decode_mcus) (cinfo, | 189 | 77.6M | diff->diff_buf, yoffset, MCU_col_num, | 190 | 77.6M | cinfo->MCUs_per_row - MCU_col_num); | 191 | 77.6M | if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) { | 192 | | /* Suspension forced; update state counters and exit */ | 193 | 0 | diff->MCU_vert_offset = yoffset; | 194 | 0 | diff->MCU_ctr += MCU_count; | 195 | 0 | return JPEG_SUSPENDED; | 196 | 0 | } | 197 | | | 198 | | /* Account for restart interval (no-op if not using restarts) */ | 199 | 77.6M | if (cinfo->restart_interval) | 200 | 25.7M | diff->restart_rows_to_go--; | 201 | | | 202 | | /* Completed an MCU row, but perhaps not an iMCU row */ | 203 | 77.6M | diff->MCU_ctr = 0; | 204 | 77.6M | } | 205 | | | 206 | | /* | 207 | | * Undifference and scale each scanline of the disassembled MCU row | 208 | | * separately. We do not process dummy samples at the end of a scanline | 209 | | * or dummy rows at the end of the image. | 210 | | */ | 211 | 114M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 212 | 67.9M | compptr = cinfo->cur_comp_info[ci]; | 213 | 67.9M | compi = compptr->component_index; | 214 | 67.9M | for (row = 0, prev_row = compptr->v_samp_factor - 1; | 215 | 187M | row < (cinfo->input_iMCU_row == last_iMCU_row ? | 216 | 187M | compptr->last_row_height : compptr->v_samp_factor); | 217 | 119M | prev_row = row, row++) { | 218 | 119M | (*losslessd->predict_undifference[compi]) | 219 | 119M | (cinfo, compi, diff->diff_buf[compi][row], | 220 | 119M | diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row], | 221 | 119M | compptr->width_in_blocks); | 222 | 119M | (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row], | 223 | 119M | output_buf[compi][row], | 224 | 119M | compptr->width_in_blocks); | 225 | 119M | } | 226 | 67.9M | } | 227 | | | 228 | | /* Completed the iMCU row, advance counters for next one. | 229 | | * | 230 | | * NB: output_data will increment output_iMCU_row. | 231 | | * This counter is not needed for the single-pass case | 232 | | * or the input side of the multi-pass case. | 233 | | */ | 234 | 46.5M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 235 | 46.4M | start_iMCU_row(cinfo); | 236 | 46.4M | return JPEG_ROW_COMPLETED; | 237 | 46.4M | } | 238 | | /* Completed the scan */ | 239 | 12.6k | (*cinfo->inputctl->finish_input_pass) (cinfo); | 240 | 12.6k | return JPEG_SCAN_COMPLETED; | 241 | 46.5M | } |
jddiffct-12.c:decompress_data Line | Count | Source | 164 | 59.8M | { | 165 | 59.8M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 166 | 59.8M | lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct; | 167 | 59.8M | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 168 | 59.8M | JDIMENSION MCU_count; /* number of MCUs decoded */ | 169 | 59.8M | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 170 | 59.8M | int ci, compi, row, prev_row; | 171 | 59.8M | unsigned int yoffset; | 172 | 59.8M | jpeg_component_info *compptr; | 173 | | | 174 | | /* Loop to process as much as one whole iMCU row */ | 175 | 164M | for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row; | 176 | 104M | yoffset++) { | 177 | | | 178 | | /* Process restart marker if needed; may have to suspend */ | 179 | 104M | if (cinfo->restart_interval) { | 180 | 19.4M | if (diff->restart_rows_to_go == 0) | 181 | 1.32M | if (!process_restart(cinfo)) | 182 | 0 | return JPEG_SUSPENDED; | 183 | 19.4M | } | 184 | | | 185 | 104M | MCU_col_num = diff->MCU_ctr; | 186 | | /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */ | 187 | 104M | MCU_count = | 188 | 104M | (*cinfo->entropy->decode_mcus) (cinfo, | 189 | 104M | diff->diff_buf, yoffset, MCU_col_num, | 190 | 104M | cinfo->MCUs_per_row - MCU_col_num); | 191 | 104M | if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) { | 192 | | /* Suspension forced; update state counters and exit */ | 193 | 0 | diff->MCU_vert_offset = yoffset; | 194 | 0 | diff->MCU_ctr += MCU_count; | 195 | 0 | return JPEG_SUSPENDED; | 196 | 0 | } | 197 | | | 198 | | /* Account for restart interval (no-op if not using restarts) */ | 199 | 104M | if (cinfo->restart_interval) | 200 | 19.4M | diff->restart_rows_to_go--; | 201 | | | 202 | | /* Completed an MCU row, but perhaps not an iMCU row */ | 203 | 104M | diff->MCU_ctr = 0; | 204 | 104M | } | 205 | | | 206 | | /* | 207 | | * Undifference and scale each scanline of the disassembled MCU row | 208 | | * separately. We do not process dummy samples at the end of a scanline | 209 | | * or dummy rows at the end of the image. | 210 | | */ | 211 | 129M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 212 | 69.7M | compptr = cinfo->cur_comp_info[ci]; | 213 | 69.7M | compi = compptr->component_index; | 214 | 69.7M | for (row = 0, prev_row = compptr->v_samp_factor - 1; | 215 | 190M | row < (cinfo->input_iMCU_row == last_iMCU_row ? | 216 | 190M | compptr->last_row_height : compptr->v_samp_factor); | 217 | 120M | prev_row = row, row++) { | 218 | 120M | (*losslessd->predict_undifference[compi]) | 219 | 120M | (cinfo, compi, diff->diff_buf[compi][row], | 220 | 120M | diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row], | 221 | 120M | compptr->width_in_blocks); | 222 | 120M | (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row], | 223 | 120M | output_buf[compi][row], | 224 | 120M | compptr->width_in_blocks); | 225 | 120M | } | 226 | 69.7M | } | 227 | | | 228 | | /* Completed the iMCU row, advance counters for next one. | 229 | | * | 230 | | * NB: output_data will increment output_iMCU_row. | 231 | | * This counter is not needed for the single-pass case | 232 | | * or the input side of the multi-pass case. | 233 | | */ | 234 | 59.8M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 235 | 59.8M | start_iMCU_row(cinfo); | 236 | 59.8M | return JPEG_ROW_COMPLETED; | 237 | 59.8M | } | 238 | | /* Completed the scan */ | 239 | 10.7k | (*cinfo->inputctl->finish_input_pass) (cinfo); | 240 | 10.7k | return JPEG_SCAN_COMPLETED; | 241 | 59.8M | } |
jddiffct-16.c:decompress_data Line | Count | Source | 164 | 93.3M | { | 165 | 93.3M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 166 | 93.3M | lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct; | 167 | 93.3M | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 168 | 93.3M | JDIMENSION MCU_count; /* number of MCUs decoded */ | 169 | 93.3M | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 170 | 93.3M | int ci, compi, row, prev_row; | 171 | 93.3M | unsigned int yoffset; | 172 | 93.3M | jpeg_component_info *compptr; | 173 | | | 174 | | /* Loop to process as much as one whole iMCU row */ | 175 | 219M | for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row; | 176 | 126M | yoffset++) { | 177 | | | 178 | | /* Process restart marker if needed; may have to suspend */ | 179 | 126M | if (cinfo->restart_interval) { | 180 | 65.0M | if (diff->restart_rows_to_go == 0) | 181 | 53.7M | if (!process_restart(cinfo)) | 182 | 0 | return JPEG_SUSPENDED; | 183 | 65.0M | } | 184 | | | 185 | 126M | MCU_col_num = diff->MCU_ctr; | 186 | | /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */ | 187 | 126M | MCU_count = | 188 | 126M | (*cinfo->entropy->decode_mcus) (cinfo, | 189 | 126M | diff->diff_buf, yoffset, MCU_col_num, | 190 | 126M | cinfo->MCUs_per_row - MCU_col_num); | 191 | 126M | if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) { | 192 | | /* Suspension forced; update state counters and exit */ | 193 | 0 | diff->MCU_vert_offset = yoffset; | 194 | 0 | diff->MCU_ctr += MCU_count; | 195 | 0 | return JPEG_SUSPENDED; | 196 | 0 | } | 197 | | | 198 | | /* Account for restart interval (no-op if not using restarts) */ | 199 | 126M | if (cinfo->restart_interval) | 200 | 65.0M | diff->restart_rows_to_go--; | 201 | | | 202 | | /* Completed an MCU row, but perhaps not an iMCU row */ | 203 | 126M | diff->MCU_ctr = 0; | 204 | 126M | } | 205 | | | 206 | | /* | 207 | | * Undifference and scale each scanline of the disassembled MCU row | 208 | | * separately. We do not process dummy samples at the end of a scanline | 209 | | * or dummy rows at the end of the image. | 210 | | */ | 211 | 213M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 212 | 120M | compptr = cinfo->cur_comp_info[ci]; | 213 | 120M | compi = compptr->component_index; | 214 | 120M | for (row = 0, prev_row = compptr->v_samp_factor - 1; | 215 | 296M | row < (cinfo->input_iMCU_row == last_iMCU_row ? | 216 | 296M | compptr->last_row_height : compptr->v_samp_factor); | 217 | 175M | prev_row = row, row++) { | 218 | 175M | (*losslessd->predict_undifference[compi]) | 219 | 175M | (cinfo, compi, diff->diff_buf[compi][row], | 220 | 175M | diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row], | 221 | 175M | compptr->width_in_blocks); | 222 | 175M | (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row], | 223 | 175M | output_buf[compi][row], | 224 | 175M | compptr->width_in_blocks); | 225 | 175M | } | 226 | 120M | } | 227 | | | 228 | | /* Completed the iMCU row, advance counters for next one. | 229 | | * | 230 | | * NB: output_data will increment output_iMCU_row. | 231 | | * This counter is not needed for the single-pass case | 232 | | * or the input side of the multi-pass case. | 233 | | */ | 234 | 93.3M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 235 | 93.3M | start_iMCU_row(cinfo); | 236 | 93.3M | return JPEG_ROW_COMPLETED; | 237 | 93.3M | } | 238 | | /* Completed the scan */ | 239 | 14.4k | (*cinfo->inputctl->finish_input_pass) (cinfo); | 240 | 14.4k | return JPEG_SCAN_COMPLETED; | 241 | 93.3M | } |
|
242 | | |
243 | | |
244 | | /* |
245 | | * Dummy consume-input routine for single-pass operation. |
246 | | */ |
247 | | |
248 | | METHODDEF(int) |
249 | | dummy_consume_data(j_decompress_ptr cinfo) |
250 | 0 | { |
251 | 0 | return JPEG_SUSPENDED; /* Always indicate nothing was done */ |
252 | 0 | } Unexecuted instantiation: jddiffct-8.c:dummy_consume_data Unexecuted instantiation: jddiffct-12.c:dummy_consume_data Unexecuted instantiation: jddiffct-16.c:dummy_consume_data |
253 | | |
254 | | |
255 | | #ifdef D_MULTISCAN_FILES_SUPPORTED |
256 | | |
257 | | /* |
258 | | * Consume input data and store it in the full-image sample buffer. |
259 | | * We read as much as one fully interleaved MCU row ("iMCU" row) per call, |
260 | | * ie, v_samp_factor rows for each component in the scan. |
261 | | * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
262 | | */ |
263 | | |
264 | | METHODDEF(int) |
265 | | consume_data(j_decompress_ptr cinfo) |
266 | 188M | { |
267 | 188M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; |
268 | 188M | int ci, compi; |
269 | 188M | _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN]; |
270 | 188M | jpeg_component_info *compptr; |
271 | | |
272 | | /* Align the virtual buffers for the components used in this scan. */ |
273 | 431M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
274 | 242M | compptr = cinfo->cur_comp_info[ci]; |
275 | 242M | compi = compptr->component_index; |
276 | 242M | buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) |
277 | 242M | ((j_common_ptr)cinfo, diff->whole_image[compi], |
278 | 242M | cinfo->input_iMCU_row * compptr->v_samp_factor, |
279 | 242M | (JDIMENSION)compptr->v_samp_factor, TRUE); |
280 | 242M | } |
281 | | |
282 | 188M | return decompress_data(cinfo, buffer); |
283 | 188M | } jddiffct-8.c:consume_data Line | Count | Source | 266 | 42.6M | { | 267 | 42.6M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 268 | 42.6M | int ci, compi; | 269 | 42.6M | _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN]; | 270 | 42.6M | jpeg_component_info *compptr; | 271 | | | 272 | | /* Align the virtual buffers for the components used in this scan. */ | 273 | 104M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 274 | 61.7M | compptr = cinfo->cur_comp_info[ci]; | 275 | 61.7M | compi = compptr->component_index; | 276 | 61.7M | buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 277 | 61.7M | ((j_common_ptr)cinfo, diff->whole_image[compi], | 278 | 61.7M | cinfo->input_iMCU_row * compptr->v_samp_factor, | 279 | 61.7M | (JDIMENSION)compptr->v_samp_factor, TRUE); | 280 | 61.7M | } | 281 | | | 282 | 42.6M | return decompress_data(cinfo, buffer); | 283 | 42.6M | } |
jddiffct-12.c:consume_data Line | Count | Source | 266 | 56.5M | { | 267 | 56.5M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 268 | 56.5M | int ci, compi; | 269 | 56.5M | _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN]; | 270 | 56.5M | jpeg_component_info *compptr; | 271 | | | 272 | | /* Align the virtual buffers for the components used in this scan. */ | 273 | 122M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 274 | 65.6M | compptr = cinfo->cur_comp_info[ci]; | 275 | 65.6M | compi = compptr->component_index; | 276 | 65.6M | buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 277 | 65.6M | ((j_common_ptr)cinfo, diff->whole_image[compi], | 278 | 65.6M | cinfo->input_iMCU_row * compptr->v_samp_factor, | 279 | 65.6M | (JDIMENSION)compptr->v_samp_factor, TRUE); | 280 | 65.6M | } | 281 | | | 282 | 56.5M | return decompress_data(cinfo, buffer); | 283 | 56.5M | } |
jddiffct-16.c:consume_data Line | Count | Source | 266 | 89.7M | { | 267 | 89.7M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 268 | 89.7M | int ci, compi; | 269 | 89.7M | _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN]; | 270 | 89.7M | jpeg_component_info *compptr; | 271 | | | 272 | | /* Align the virtual buffers for the components used in this scan. */ | 273 | 204M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 274 | 115M | compptr = cinfo->cur_comp_info[ci]; | 275 | 115M | compi = compptr->component_index; | 276 | 115M | buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 277 | 115M | ((j_common_ptr)cinfo, diff->whole_image[compi], | 278 | 115M | cinfo->input_iMCU_row * compptr->v_samp_factor, | 279 | 115M | (JDIMENSION)compptr->v_samp_factor, TRUE); | 280 | 115M | } | 281 | | | 282 | 89.7M | return decompress_data(cinfo, buffer); | 283 | 89.7M | } |
|
284 | | |
285 | | |
286 | | /* |
287 | | * Output some data from the full-image sample buffer in the multi-pass case. |
288 | | * Always attempts to emit one fully interleaved MCU row ("iMCU" row). |
289 | | * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
290 | | * |
291 | | * NB: output_buf contains a plane for each component in image. |
292 | | */ |
293 | | |
294 | | METHODDEF(int) |
295 | | output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf) |
296 | 3.59M | { |
297 | 3.59M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; |
298 | 3.59M | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
299 | 3.59M | int ci, samp_rows, row; |
300 | 3.59M | _JSAMPARRAY buffer; |
301 | 3.59M | jpeg_component_info *compptr; |
302 | | |
303 | | /* Force some input to be done if we are getting ahead of the input. */ |
304 | 6.16M | while (cinfo->input_scan_number < cinfo->output_scan_number || |
305 | 6.16M | (cinfo->input_scan_number == cinfo->output_scan_number && |
306 | 6.16M | cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { |
307 | 2.56M | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) |
308 | 0 | return JPEG_SUSPENDED; |
309 | 2.56M | } |
310 | | |
311 | | /* OK, output from the virtual arrays. */ |
312 | 15.0M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
313 | 11.4M | ci++, compptr++) { |
314 | | /* Align the virtual buffer for this component. */ |
315 | 11.4M | buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) |
316 | 11.4M | ((j_common_ptr)cinfo, diff->whole_image[ci], |
317 | 11.4M | cinfo->output_iMCU_row * compptr->v_samp_factor, |
318 | 11.4M | (JDIMENSION)compptr->v_samp_factor, FALSE); |
319 | | |
320 | 11.4M | if (cinfo->output_iMCU_row < last_iMCU_row) |
321 | 11.4M | samp_rows = compptr->v_samp_factor; |
322 | 6.02k | else { |
323 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ |
324 | 6.02k | samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); |
325 | 6.02k | if (samp_rows == 0) samp_rows = compptr->v_samp_factor; |
326 | 6.02k | } |
327 | | |
328 | 33.0M | for (row = 0; row < samp_rows; row++) { |
329 | 21.6M | memcpy(output_buf[ci][row], buffer[row], |
330 | 21.6M | compptr->width_in_blocks * sizeof(_JSAMPLE)); |
331 | 21.6M | } |
332 | 11.4M | } |
333 | | |
334 | 3.59M | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) |
335 | 3.59M | return JPEG_ROW_COMPLETED; |
336 | 2.66k | return JPEG_SCAN_COMPLETED; |
337 | 3.59M | } Line | Count | Source | 296 | 2.94M | { | 297 | 2.94M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 298 | 2.94M | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 299 | 2.94M | int ci, samp_rows, row; | 300 | 2.94M | _JSAMPARRAY buffer; | 301 | 2.94M | jpeg_component_info *compptr; | 302 | | | 303 | | /* Force some input to be done if we are getting ahead of the input. */ | 304 | 5.50M | while (cinfo->input_scan_number < cinfo->output_scan_number || | 305 | 5.50M | (cinfo->input_scan_number == cinfo->output_scan_number && | 306 | 5.50M | cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { | 307 | 2.56M | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) | 308 | 0 | return JPEG_SUSPENDED; | 309 | 2.56M | } | 310 | | | 311 | | /* OK, output from the virtual arrays. */ | 312 | 12.2M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 313 | 9.29M | ci++, compptr++) { | 314 | | /* Align the virtual buffer for this component. */ | 315 | 9.29M | buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 316 | 9.29M | ((j_common_ptr)cinfo, diff->whole_image[ci], | 317 | 9.29M | cinfo->output_iMCU_row * compptr->v_samp_factor, | 318 | 9.29M | (JDIMENSION)compptr->v_samp_factor, FALSE); | 319 | | | 320 | 9.29M | if (cinfo->output_iMCU_row < last_iMCU_row) | 321 | 9.28M | samp_rows = compptr->v_samp_factor; | 322 | 4.42k | else { | 323 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ | 324 | 4.42k | samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); | 325 | 4.42k | if (samp_rows == 0) samp_rows = compptr->v_samp_factor; | 326 | 4.42k | } | 327 | | | 328 | 27.8M | for (row = 0; row < samp_rows; row++) { | 329 | 18.5M | memcpy(output_buf[ci][row], buffer[row], | 330 | 18.5M | compptr->width_in_blocks * sizeof(_JSAMPLE)); | 331 | 18.5M | } | 332 | 9.29M | } | 333 | | | 334 | 2.94M | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) | 335 | 2.93M | return JPEG_ROW_COMPLETED; | 336 | 1.67k | return JPEG_SCAN_COMPLETED; | 337 | 2.94M | } |
jddiffct-12.c:output_data Line | Count | Source | 296 | 217k | { | 297 | 217k | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 298 | 217k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 299 | 217k | int ci, samp_rows, row; | 300 | 217k | _JSAMPARRAY buffer; | 301 | 217k | jpeg_component_info *compptr; | 302 | | | 303 | | /* Force some input to be done if we are getting ahead of the input. */ | 304 | 217k | while (cinfo->input_scan_number < cinfo->output_scan_number || | 305 | 217k | (cinfo->input_scan_number == cinfo->output_scan_number && | 306 | 217k | cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { | 307 | 0 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) | 308 | 0 | return JPEG_SUSPENDED; | 309 | 0 | } | 310 | | | 311 | | /* OK, output from the virtual arrays. */ | 312 | 965k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 313 | 747k | ci++, compptr++) { | 314 | | /* Align the virtual buffer for this component. */ | 315 | 747k | buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 316 | 747k | ((j_common_ptr)cinfo, diff->whole_image[ci], | 317 | 747k | cinfo->output_iMCU_row * compptr->v_samp_factor, | 318 | 747k | (JDIMENSION)compptr->v_samp_factor, FALSE); | 319 | | | 320 | 747k | if (cinfo->output_iMCU_row < last_iMCU_row) | 321 | 746k | samp_rows = compptr->v_samp_factor; | 322 | 727 | else { | 323 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ | 324 | 727 | samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); | 325 | 727 | if (samp_rows == 0) samp_rows = compptr->v_samp_factor; | 326 | 727 | } | 327 | | | 328 | 1.67M | for (row = 0; row < samp_rows; row++) { | 329 | 931k | memcpy(output_buf[ci][row], buffer[row], | 330 | 931k | compptr->width_in_blocks * sizeof(_JSAMPLE)); | 331 | 931k | } | 332 | 747k | } | 333 | | | 334 | 217k | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) | 335 | 217k | return JPEG_ROW_COMPLETED; | 336 | 400 | return JPEG_SCAN_COMPLETED; | 337 | 217k | } |
jddiffct-16.c:output_data Line | Count | Source | 296 | 434k | { | 297 | 434k | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 298 | 434k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 299 | 434k | int ci, samp_rows, row; | 300 | 434k | _JSAMPARRAY buffer; | 301 | 434k | jpeg_component_info *compptr; | 302 | | | 303 | | /* Force some input to be done if we are getting ahead of the input. */ | 304 | 434k | while (cinfo->input_scan_number < cinfo->output_scan_number || | 305 | 434k | (cinfo->input_scan_number == cinfo->output_scan_number && | 306 | 434k | cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { | 307 | 0 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) | 308 | 0 | return JPEG_SUSPENDED; | 309 | 0 | } | 310 | | | 311 | | /* OK, output from the virtual arrays. */ | 312 | 1.81M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 313 | 1.37M | ci++, compptr++) { | 314 | | /* Align the virtual buffer for this component. */ | 315 | 1.37M | buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 316 | 1.37M | ((j_common_ptr)cinfo, diff->whole_image[ci], | 317 | 1.37M | cinfo->output_iMCU_row * compptr->v_samp_factor, | 318 | 1.37M | (JDIMENSION)compptr->v_samp_factor, FALSE); | 319 | | | 320 | 1.37M | if (cinfo->output_iMCU_row < last_iMCU_row) | 321 | 1.37M | samp_rows = compptr->v_samp_factor; | 322 | 874 | else { | 323 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ | 324 | 874 | samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); | 325 | 874 | if (samp_rows == 0) samp_rows = compptr->v_samp_factor; | 326 | 874 | } | 327 | | | 328 | 3.52M | for (row = 0; row < samp_rows; row++) { | 329 | 2.14M | memcpy(output_buf[ci][row], buffer[row], | 330 | 2.14M | compptr->width_in_blocks * sizeof(_JSAMPLE)); | 331 | 2.14M | } | 332 | 1.37M | } | 333 | | | 334 | 434k | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) | 335 | 434k | return JPEG_ROW_COMPLETED; | 336 | 593 | return JPEG_SCAN_COMPLETED; | 337 | 434k | } |
|
338 | | |
339 | | #endif /* D_MULTISCAN_FILES_SUPPORTED */ |
340 | | |
341 | | |
342 | | /* |
343 | | * Initialize difference buffer controller. |
344 | | */ |
345 | | |
346 | | GLOBAL(void) |
347 | | _jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer) |
348 | 18.3k | { |
349 | 18.3k | my_diff_ptr diff; |
350 | 18.3k | int ci; |
351 | 18.3k | jpeg_component_info *compptr; |
352 | | |
353 | | #if BITS_IN_JSAMPLE == 8 |
354 | 6.13k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
355 | | #else |
356 | 12.2k | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
357 | 12.2k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) |
358 | 0 | #endif |
359 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
360 | | |
361 | 18.3k | diff = (my_diff_ptr) |
362 | 18.3k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
363 | 18.3k | sizeof(my_diff_controller)); |
364 | 18.3k | cinfo->coef = (struct jpeg_d_coef_controller *)diff; |
365 | 18.3k | diff->pub.start_input_pass = start_input_pass; |
366 | 18.3k | diff->pub.start_output_pass = start_output_pass; |
367 | | |
368 | | /* Create the [un]difference buffers. */ |
369 | 67.2k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
370 | 48.8k | ci++, compptr++) { |
371 | 48.8k | diff->diff_buf[ci] = |
372 | 48.8k | ALLOC_DARRAY(JPOOL_IMAGE, |
373 | 48.8k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, |
374 | 48.8k | (long)compptr->h_samp_factor), |
375 | 48.8k | (JDIMENSION)compptr->v_samp_factor); |
376 | 48.8k | diff->undiff_buf[ci] = |
377 | 48.8k | ALLOC_DARRAY(JPOOL_IMAGE, |
378 | 48.8k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, |
379 | 48.8k | (long)compptr->h_samp_factor), |
380 | 48.8k | (JDIMENSION)compptr->v_samp_factor); |
381 | 48.8k | } |
382 | | |
383 | 18.3k | if (need_full_buffer) { |
384 | 14.1k | #ifdef D_MULTISCAN_FILES_SUPPORTED |
385 | | /* Allocate a full-image virtual array for each component. */ |
386 | 14.1k | int access_rows; |
387 | | |
388 | 55.8k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
389 | 41.7k | ci++, compptr++) { |
390 | 41.7k | access_rows = compptr->v_samp_factor; |
391 | 41.7k | diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray) |
392 | 41.7k | ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, |
393 | 41.7k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, |
394 | 41.7k | (long)compptr->h_samp_factor), |
395 | 41.7k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, |
396 | 41.7k | (long)compptr->v_samp_factor), |
397 | 41.7k | (JDIMENSION)access_rows); |
398 | 41.7k | } |
399 | 14.1k | diff->pub.consume_data = consume_data; |
400 | 14.1k | diff->pub._decompress_data = output_data; |
401 | | #else |
402 | | ERREXIT(cinfo, JERR_NOT_COMPILED); |
403 | | #endif |
404 | 14.1k | } else { |
405 | 4.25k | diff->pub.consume_data = dummy_consume_data; |
406 | 4.25k | diff->pub._decompress_data = decompress_data; |
407 | | diff->whole_image[0] = NULL; /* flag for no virtual arrays */ |
408 | 4.25k | } |
409 | 18.3k | } Line | Count | Source | 348 | 6.13k | { | 349 | 6.13k | my_diff_ptr diff; | 350 | 6.13k | int ci; | 351 | 6.13k | jpeg_component_info *compptr; | 352 | | | 353 | 6.13k | #if BITS_IN_JSAMPLE == 8 | 354 | 6.13k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 355 | | #else | 356 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 357 | | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 358 | | #endif | 359 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 360 | | | 361 | 6.13k | diff = (my_diff_ptr) | 362 | 6.13k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 363 | 6.13k | sizeof(my_diff_controller)); | 364 | 6.13k | cinfo->coef = (struct jpeg_d_coef_controller *)diff; | 365 | 6.13k | diff->pub.start_input_pass = start_input_pass; | 366 | 6.13k | diff->pub.start_output_pass = start_output_pass; | 367 | | | 368 | | /* Create the [un]difference buffers. */ | 369 | 22.5k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 370 | 16.4k | ci++, compptr++) { | 371 | 16.4k | diff->diff_buf[ci] = | 372 | 16.4k | ALLOC_DARRAY(JPOOL_IMAGE, | 373 | 16.4k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 374 | 16.4k | (long)compptr->h_samp_factor), | 375 | 16.4k | (JDIMENSION)compptr->v_samp_factor); | 376 | 16.4k | diff->undiff_buf[ci] = | 377 | 16.4k | ALLOC_DARRAY(JPOOL_IMAGE, | 378 | 16.4k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 379 | 16.4k | (long)compptr->h_samp_factor), | 380 | 16.4k | (JDIMENSION)compptr->v_samp_factor); | 381 | 16.4k | } | 382 | | | 383 | 6.13k | if (need_full_buffer) { | 384 | 4.86k | #ifdef D_MULTISCAN_FILES_SUPPORTED | 385 | | /* Allocate a full-image virtual array for each component. */ | 386 | 4.86k | int access_rows; | 387 | | | 388 | 19.2k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 389 | 14.3k | ci++, compptr++) { | 390 | 14.3k | access_rows = compptr->v_samp_factor; | 391 | 14.3k | diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray) | 392 | 14.3k | ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, | 393 | 14.3k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 394 | 14.3k | (long)compptr->h_samp_factor), | 395 | 14.3k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, | 396 | 14.3k | (long)compptr->v_samp_factor), | 397 | 14.3k | (JDIMENSION)access_rows); | 398 | 14.3k | } | 399 | 4.86k | diff->pub.consume_data = consume_data; | 400 | 4.86k | diff->pub._decompress_data = output_data; | 401 | | #else | 402 | | ERREXIT(cinfo, JERR_NOT_COMPILED); | 403 | | #endif | 404 | 4.86k | } else { | 405 | 1.27k | diff->pub.consume_data = dummy_consume_data; | 406 | 1.27k | diff->pub._decompress_data = decompress_data; | 407 | | diff->whole_image[0] = NULL; /* flag for no virtual arrays */ | 408 | 1.27k | } | 409 | 6.13k | } |
j12init_d_diff_controller Line | Count | Source | 348 | 5.91k | { | 349 | 5.91k | my_diff_ptr diff; | 350 | 5.91k | int ci; | 351 | 5.91k | jpeg_component_info *compptr; | 352 | | | 353 | | #if BITS_IN_JSAMPLE == 8 | 354 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 355 | | #else | 356 | 5.91k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 357 | 5.91k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 358 | 0 | #endif | 359 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 360 | | | 361 | 5.91k | diff = (my_diff_ptr) | 362 | 5.91k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 363 | 5.91k | sizeof(my_diff_controller)); | 364 | 5.91k | cinfo->coef = (struct jpeg_d_coef_controller *)diff; | 365 | 5.91k | diff->pub.start_input_pass = start_input_pass; | 366 | 5.91k | diff->pub.start_output_pass = start_output_pass; | 367 | | | 368 | | /* Create the [un]difference buffers. */ | 369 | 21.4k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 370 | 15.4k | ci++, compptr++) { | 371 | 15.4k | diff->diff_buf[ci] = | 372 | 15.4k | ALLOC_DARRAY(JPOOL_IMAGE, | 373 | 15.4k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 374 | 15.4k | (long)compptr->h_samp_factor), | 375 | 15.4k | (JDIMENSION)compptr->v_samp_factor); | 376 | 15.4k | diff->undiff_buf[ci] = | 377 | 15.4k | ALLOC_DARRAY(JPOOL_IMAGE, | 378 | 15.4k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 379 | 15.4k | (long)compptr->h_samp_factor), | 380 | 15.4k | (JDIMENSION)compptr->v_samp_factor); | 381 | 15.4k | } | 382 | | | 383 | 5.91k | if (need_full_buffer) { | 384 | 4.36k | #ifdef D_MULTISCAN_FILES_SUPPORTED | 385 | | /* Allocate a full-image virtual array for each component. */ | 386 | 4.36k | int access_rows; | 387 | | | 388 | 17.2k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 389 | 12.9k | ci++, compptr++) { | 390 | 12.9k | access_rows = compptr->v_samp_factor; | 391 | 12.9k | diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray) | 392 | 12.9k | ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, | 393 | 12.9k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 394 | 12.9k | (long)compptr->h_samp_factor), | 395 | 12.9k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, | 396 | 12.9k | (long)compptr->v_samp_factor), | 397 | 12.9k | (JDIMENSION)access_rows); | 398 | 12.9k | } | 399 | 4.36k | diff->pub.consume_data = consume_data; | 400 | 4.36k | diff->pub._decompress_data = output_data; | 401 | | #else | 402 | | ERREXIT(cinfo, JERR_NOT_COMPILED); | 403 | | #endif | 404 | 4.36k | } else { | 405 | 1.55k | diff->pub.consume_data = dummy_consume_data; | 406 | 1.55k | diff->pub._decompress_data = decompress_data; | 407 | | diff->whole_image[0] = NULL; /* flag for no virtual arrays */ | 408 | 1.55k | } | 409 | 5.91k | } |
j16init_d_diff_controller Line | Count | Source | 348 | 6.33k | { | 349 | 6.33k | my_diff_ptr diff; | 350 | 6.33k | int ci; | 351 | 6.33k | jpeg_component_info *compptr; | 352 | | | 353 | | #if BITS_IN_JSAMPLE == 8 | 354 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 355 | | #else | 356 | 6.33k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 357 | 6.33k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 358 | 0 | #endif | 359 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 360 | | | 361 | 6.33k | diff = (my_diff_ptr) | 362 | 6.33k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 363 | 6.33k | sizeof(my_diff_controller)); | 364 | 6.33k | cinfo->coef = (struct jpeg_d_coef_controller *)diff; | 365 | 6.33k | diff->pub.start_input_pass = start_input_pass; | 366 | 6.33k | diff->pub.start_output_pass = start_output_pass; | 367 | | | 368 | | /* Create the [un]difference buffers. */ | 369 | 23.2k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 370 | 16.9k | ci++, compptr++) { | 371 | 16.9k | diff->diff_buf[ci] = | 372 | 16.9k | ALLOC_DARRAY(JPOOL_IMAGE, | 373 | 16.9k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 374 | 16.9k | (long)compptr->h_samp_factor), | 375 | 16.9k | (JDIMENSION)compptr->v_samp_factor); | 376 | 16.9k | diff->undiff_buf[ci] = | 377 | 16.9k | ALLOC_DARRAY(JPOOL_IMAGE, | 378 | 16.9k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 379 | 16.9k | (long)compptr->h_samp_factor), | 380 | 16.9k | (JDIMENSION)compptr->v_samp_factor); | 381 | 16.9k | } | 382 | | | 383 | 6.33k | if (need_full_buffer) { | 384 | 4.91k | #ifdef D_MULTISCAN_FILES_SUPPORTED | 385 | | /* Allocate a full-image virtual array for each component. */ | 386 | 4.91k | int access_rows; | 387 | | | 388 | 19.3k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 389 | 14.4k | ci++, compptr++) { | 390 | 14.4k | access_rows = compptr->v_samp_factor; | 391 | 14.4k | diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray) | 392 | 14.4k | ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, | 393 | 14.4k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 394 | 14.4k | (long)compptr->h_samp_factor), | 395 | 14.4k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, | 396 | 14.4k | (long)compptr->v_samp_factor), | 397 | 14.4k | (JDIMENSION)access_rows); | 398 | 14.4k | } | 399 | 4.91k | diff->pub.consume_data = consume_data; | 400 | 4.91k | diff->pub._decompress_data = output_data; | 401 | | #else | 402 | | ERREXIT(cinfo, JERR_NOT_COMPILED); | 403 | | #endif | 404 | 4.91k | } else { | 405 | 1.42k | diff->pub.consume_data = dummy_consume_data; | 406 | 1.42k | diff->pub._decompress_data = decompress_data; | 407 | | diff->whole_image[0] = NULL; /* flag for no virtual arrays */ | 408 | 1.42k | } | 409 | 6.33k | } |
|
410 | | |
411 | | #endif /* D_LOSSLESS_SUPPORTED */ |