/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 | 200M | { |
68 | 200M | 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 | 200M | if (cinfo->comps_in_scan > 1) { |
75 | 51.7M | diff->MCU_rows_per_iMCU_row = 1; |
76 | 148M | } else { |
77 | 148M | if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1)) |
78 | 148M | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; |
79 | 28.3k | else |
80 | 28.3k | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; |
81 | 148M | } |
82 | | |
83 | 200M | diff->MCU_ctr = 0; |
84 | 200M | diff->MCU_vert_offset = 0; |
85 | 200M | } jddiffct-8.c:start_iMCU_row Line | Count | Source | 67 | 47.5M | { | 68 | 47.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 | 47.5M | if (cinfo->comps_in_scan > 1) { | 75 | 18.3M | diff->MCU_rows_per_iMCU_row = 1; | 76 | 29.2M | } else { | 77 | 29.2M | if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1)) | 78 | 29.2M | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; | 79 | 8.71k | else | 80 | 8.71k | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; | 81 | 29.2M | } | 82 | | | 83 | 47.5M | diff->MCU_ctr = 0; | 84 | 47.5M | diff->MCU_vert_offset = 0; | 85 | 47.5M | } |
jddiffct-12.c:start_iMCU_row Line | Count | Source | 67 | 65.2M | { | 68 | 65.2M | 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 | 65.2M | if (cinfo->comps_in_scan > 1) { | 75 | 9.26M | diff->MCU_rows_per_iMCU_row = 1; | 76 | 56.0M | } else { | 77 | 56.0M | if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1)) | 78 | 56.0M | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; | 79 | 8.26k | else | 80 | 8.26k | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; | 81 | 56.0M | } | 82 | | | 83 | 65.2M | diff->MCU_ctr = 0; | 84 | 65.2M | diff->MCU_vert_offset = 0; | 85 | 65.2M | } |
jddiffct-16.c:start_iMCU_row Line | Count | Source | 67 | 87.8M | { | 68 | 87.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 | 87.8M | if (cinfo->comps_in_scan > 1) { | 75 | 24.1M | diff->MCU_rows_per_iMCU_row = 1; | 76 | 63.6M | } else { | 77 | 63.6M | if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1)) | 78 | 63.6M | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; | 79 | 11.4k | else | 80 | 11.4k | diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; | 81 | 63.6M | } | 82 | | | 83 | 87.8M | diff->MCU_ctr = 0; | 84 | 87.8M | diff->MCU_vert_offset = 0; | 85 | 87.8M | } |
|
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.3k | { |
95 | 39.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 | 39.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 | 39.3k | if (cinfo->restart_interval % cinfo->MCUs_per_row != 0) |
108 | 236 | ERREXIT2(cinfo, JERR_BAD_RESTART, |
109 | 39.3k | cinfo->restart_interval, cinfo->MCUs_per_row); |
110 | | |
111 | | /* Initialize restart counter */ |
112 | 39.3k | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; |
113 | | |
114 | 39.3k | cinfo->input_iMCU_row = 0; |
115 | 39.3k | start_iMCU_row(cinfo); |
116 | 39.3k | } jddiffct-8.c:start_input_pass Line | Count | Source | 94 | 12.7k | { | 95 | 12.7k | 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 | 12.7k | (*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 | 12.7k | if (cinfo->restart_interval % cinfo->MCUs_per_row != 0) | 108 | 82 | ERREXIT2(cinfo, JERR_BAD_RESTART, | 109 | 12.7k | cinfo->restart_interval, cinfo->MCUs_per_row); | 110 | | | 111 | | /* Initialize restart counter */ | 112 | 12.7k | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; | 113 | | | 114 | 12.7k | cinfo->input_iMCU_row = 0; | 115 | 12.7k | start_iMCU_row(cinfo); | 116 | 12.7k | } |
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 | 77 | 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.2k | { | 95 | 15.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 | 15.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 | 15.2k | if (cinfo->restart_interval % cinfo->MCUs_per_row != 0) | 108 | 77 | ERREXIT2(cinfo, JERR_BAD_RESTART, | 109 | 15.2k | cinfo->restart_interval, cinfo->MCUs_per_row); | 110 | | | 111 | | /* Initialize restart counter */ | 112 | 15.2k | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; | 113 | | | 114 | 15.2k | cinfo->input_iMCU_row = 0; | 115 | 15.2k | start_iMCU_row(cinfo); | 116 | 15.2k | } |
|
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 | 64.3M | { |
127 | 64.3M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; |
128 | | |
129 | 64.3M | if (!(*cinfo->entropy->process_restart) (cinfo)) |
130 | 0 | return FALSE; |
131 | | |
132 | 64.3M | (*cinfo->idct->start_pass) (cinfo); |
133 | | |
134 | | /* Reset restart counter */ |
135 | 64.3M | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; |
136 | | |
137 | 64.3M | return TRUE; |
138 | 64.3M | } jddiffct-8.c:process_restart Line | Count | Source | 126 | 14.5M | { | 127 | 14.5M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 128 | | | 129 | 14.5M | if (!(*cinfo->entropy->process_restart) (cinfo)) | 130 | 0 | return FALSE; | 131 | | | 132 | 14.5M | (*cinfo->idct->start_pass) (cinfo); | 133 | | | 134 | | /* Reset restart counter */ | 135 | 14.5M | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; | 136 | | | 137 | 14.5M | return TRUE; | 138 | 14.5M | } |
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 | 48.4M | { | 127 | 48.4M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 128 | | | 129 | 48.4M | if (!(*cinfo->entropy->process_restart) (cinfo)) | 130 | 0 | return FALSE; | 131 | | | 132 | 48.4M | (*cinfo->idct->start_pass) (cinfo); | 133 | | | 134 | | /* Reset restart counter */ | 135 | 48.4M | diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row; | 136 | | | 137 | 48.4M | return TRUE; | 138 | 48.4M | } |
|
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.3k | { |
148 | 10.3k | cinfo->output_iMCU_row = 0; |
149 | 10.3k | } jddiffct-8.c:start_output_pass Line | Count | Source | 147 | 4.19k | { | 148 | 4.19k | cinfo->output_iMCU_row = 0; | 149 | 4.19k | } |
jddiffct-12.c:start_output_pass Line | Count | Source | 147 | 3.04k | { | 148 | 3.04k | cinfo->output_iMCU_row = 0; | 149 | 3.04k | } |
jddiffct-16.c:start_output_pass Line | Count | Source | 147 | 3.13k | { | 148 | 3.13k | cinfo->output_iMCU_row = 0; | 149 | 3.13k | } |
|
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 | 200M | { |
165 | 200M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; |
166 | 200M | lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct; |
167 | 200M | JDIMENSION MCU_col_num; /* index of current MCU within row */ |
168 | 200M | JDIMENSION MCU_count; /* number of MCUs decoded */ |
169 | 200M | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
170 | 200M | int ci, compi, row, prev_row; |
171 | 200M | unsigned int yoffset; |
172 | 200M | jpeg_component_info *compptr; |
173 | | |
174 | | /* Loop to process as much as one whole iMCU row */ |
175 | 510M | for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row; |
176 | 309M | yoffset++) { |
177 | | |
178 | | /* Process restart marker if needed; may have to suspend */ |
179 | 309M | if (cinfo->restart_interval) { |
180 | 102M | if (diff->restart_rows_to_go == 0) |
181 | 64.3M | if (!process_restart(cinfo)) |
182 | 0 | return JPEG_SUSPENDED; |
183 | 102M | } |
184 | | |
185 | 309M | MCU_col_num = diff->MCU_ctr; |
186 | | /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */ |
187 | 309M | MCU_count = |
188 | 309M | (*cinfo->entropy->decode_mcus) (cinfo, |
189 | 309M | diff->diff_buf, yoffset, MCU_col_num, |
190 | 309M | cinfo->MCUs_per_row - MCU_col_num); |
191 | 309M | 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 | 309M | if (cinfo->restart_interval) |
200 | 102M | diff->restart_rows_to_go--; |
201 | | |
202 | | /* Completed an MCU row, but perhaps not an iMCU row */ |
203 | 309M | diff->MCU_ctr = 0; |
204 | 309M | } |
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 | 472M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
212 | 271M | compptr = cinfo->cur_comp_info[ci]; |
213 | 271M | compi = compptr->component_index; |
214 | 271M | for (row = 0, prev_row = compptr->v_samp_factor - 1; |
215 | 710M | row < (cinfo->input_iMCU_row == last_iMCU_row ? |
216 | 710M | compptr->last_row_height : compptr->v_samp_factor); |
217 | 439M | prev_row = row, row++) { |
218 | 439M | (*losslessd->predict_undifference[compi]) |
219 | 439M | (cinfo, compi, diff->diff_buf[compi][row], |
220 | 439M | diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row], |
221 | 439M | compptr->width_in_blocks); |
222 | 439M | (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row], |
223 | 439M | output_buf[compi][row], |
224 | 439M | compptr->width_in_blocks); |
225 | 439M | } |
226 | 271M | } |
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 | 200M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { |
235 | 200M | start_iMCU_row(cinfo); |
236 | 200M | return JPEG_ROW_COMPLETED; |
237 | 200M | } |
238 | | /* Completed the scan */ |
239 | 37.5k | (*cinfo->inputctl->finish_input_pass) (cinfo); |
240 | 37.5k | return JPEG_SCAN_COMPLETED; |
241 | 200M | } jddiffct-8.c:decompress_data Line | Count | Source | 164 | 47.5M | { | 165 | 47.5M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 166 | 47.5M | lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct; | 167 | 47.5M | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 168 | 47.5M | JDIMENSION MCU_count; /* number of MCUs decoded */ | 169 | 47.5M | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 170 | 47.5M | int ci, compi, row, prev_row; | 171 | 47.5M | unsigned int yoffset; | 172 | 47.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.0M | yoffset++) { | 177 | | | 178 | | /* Process restart marker if needed; may have to suspend */ | 179 | 77.0M | if (cinfo->restart_interval) { | 180 | 24.4M | if (diff->restart_rows_to_go == 0) | 181 | 14.5M | if (!process_restart(cinfo)) | 182 | 0 | return JPEG_SUSPENDED; | 183 | 24.4M | } | 184 | | | 185 | 77.0M | MCU_col_num = diff->MCU_ctr; | 186 | | /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */ | 187 | 77.0M | MCU_count = | 188 | 77.0M | (*cinfo->entropy->decode_mcus) (cinfo, | 189 | 77.0M | diff->diff_buf, yoffset, MCU_col_num, | 190 | 77.0M | cinfo->MCUs_per_row - MCU_col_num); | 191 | 77.0M | 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.0M | if (cinfo->restart_interval) | 200 | 24.4M | diff->restart_rows_to_go--; | 201 | | | 202 | | /* Completed an MCU row, but perhaps not an iMCU row */ | 203 | 77.0M | diff->MCU_ctr = 0; | 204 | 77.0M | } | 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 | 125M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 212 | 77.7M | compptr = cinfo->cur_comp_info[ci]; | 213 | 77.7M | compi = compptr->component_index; | 214 | 77.7M | for (row = 0, prev_row = compptr->v_samp_factor - 1; | 215 | 210M | row < (cinfo->input_iMCU_row == last_iMCU_row ? | 216 | 210M | compptr->last_row_height : compptr->v_samp_factor); | 217 | 133M | prev_row = row, row++) { | 218 | 133M | (*losslessd->predict_undifference[compi]) | 219 | 133M | (cinfo, compi, diff->diff_buf[compi][row], | 220 | 133M | diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row], | 221 | 133M | compptr->width_in_blocks); | 222 | 133M | (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row], | 223 | 133M | output_buf[compi][row], | 224 | 133M | compptr->width_in_blocks); | 225 | 133M | } | 226 | 77.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 | 47.5M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 235 | 47.5M | start_iMCU_row(cinfo); | 236 | 47.5M | return JPEG_ROW_COMPLETED; | 237 | 47.5M | } | 238 | | /* Completed the scan */ | 239 | 12.1k | (*cinfo->inputctl->finish_input_pass) (cinfo); | 240 | 12.1k | return JPEG_SCAN_COMPLETED; | 241 | 47.5M | } |
jddiffct-12.c:decompress_data Line | Count | Source | 164 | 65.2M | { | 165 | 65.2M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 166 | 65.2M | lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct; | 167 | 65.2M | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 168 | 65.2M | JDIMENSION MCU_count; /* number of MCUs decoded */ | 169 | 65.2M | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 170 | 65.2M | int ci, compi, row, prev_row; | 171 | 65.2M | unsigned int yoffset; | 172 | 65.2M | jpeg_component_info *compptr; | 173 | | | 174 | | /* Loop to process as much as one whole iMCU row */ | 175 | 176M | for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row; | 176 | 111M | yoffset++) { | 177 | | | 178 | | /* Process restart marker if needed; may have to suspend */ | 179 | 111M | if (cinfo->restart_interval) { | 180 | 18.4M | if (diff->restart_rows_to_go == 0) | 181 | 1.32M | if (!process_restart(cinfo)) | 182 | 0 | return JPEG_SUSPENDED; | 183 | 18.4M | } | 184 | | | 185 | 111M | MCU_col_num = diff->MCU_ctr; | 186 | | /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */ | 187 | 111M | MCU_count = | 188 | 111M | (*cinfo->entropy->decode_mcus) (cinfo, | 189 | 111M | diff->diff_buf, yoffset, MCU_col_num, | 190 | 111M | cinfo->MCUs_per_row - MCU_col_num); | 191 | 111M | 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 | 111M | if (cinfo->restart_interval) | 200 | 18.4M | diff->restart_rows_to_go--; | 201 | | | 202 | | /* Completed an MCU row, but perhaps not an iMCU row */ | 203 | 111M | diff->MCU_ctr = 0; | 204 | 111M | } | 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 | 141M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 212 | 76.1M | compptr = cinfo->cur_comp_info[ci]; | 213 | 76.1M | compi = compptr->component_index; | 214 | 76.1M | for (row = 0, prev_row = compptr->v_samp_factor - 1; | 215 | 206M | row < (cinfo->input_iMCU_row == last_iMCU_row ? | 216 | 206M | compptr->last_row_height : compptr->v_samp_factor); | 217 | 129M | prev_row = row, row++) { | 218 | 129M | (*losslessd->predict_undifference[compi]) | 219 | 129M | (cinfo, compi, diff->diff_buf[compi][row], | 220 | 129M | diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row], | 221 | 129M | compptr->width_in_blocks); | 222 | 129M | (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row], | 223 | 129M | output_buf[compi][row], | 224 | 129M | compptr->width_in_blocks); | 225 | 129M | } | 226 | 76.1M | } | 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 | 65.2M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 235 | 65.2M | start_iMCU_row(cinfo); | 236 | 65.2M | return JPEG_ROW_COMPLETED; | 237 | 65.2M | } | 238 | | /* Completed the scan */ | 239 | 10.7k | (*cinfo->inputctl->finish_input_pass) (cinfo); | 240 | 10.7k | return JPEG_SCAN_COMPLETED; | 241 | 65.2M | } |
jddiffct-16.c:decompress_data Line | Count | Source | 164 | 87.8M | { | 165 | 87.8M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 166 | 87.8M | lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct; | 167 | 87.8M | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 168 | 87.8M | JDIMENSION MCU_count; /* number of MCUs decoded */ | 169 | 87.8M | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 170 | 87.8M | int ci, compi, row, prev_row; | 171 | 87.8M | unsigned int yoffset; | 172 | 87.8M | jpeg_component_info *compptr; | 173 | | | 174 | | /* Loop to process as much as one whole iMCU row */ | 175 | 209M | for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row; | 176 | 121M | yoffset++) { | 177 | | | 178 | | /* Process restart marker if needed; may have to suspend */ | 179 | 121M | if (cinfo->restart_interval) { | 180 | 59.7M | if (diff->restart_rows_to_go == 0) | 181 | 48.4M | if (!process_restart(cinfo)) | 182 | 0 | return JPEG_SUSPENDED; | 183 | 59.7M | } | 184 | | | 185 | 121M | MCU_col_num = diff->MCU_ctr; | 186 | | /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */ | 187 | 121M | MCU_count = | 188 | 121M | (*cinfo->entropy->decode_mcus) (cinfo, | 189 | 121M | diff->diff_buf, yoffset, MCU_col_num, | 190 | 121M | cinfo->MCUs_per_row - MCU_col_num); | 191 | 121M | 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 | 121M | if (cinfo->restart_interval) | 200 | 59.7M | diff->restart_rows_to_go--; | 201 | | | 202 | | /* Completed an MCU row, but perhaps not an iMCU row */ | 203 | 121M | diff->MCU_ctr = 0; | 204 | 121M | } | 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 | 205M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 212 | 117M | compptr = cinfo->cur_comp_info[ci]; | 213 | 117M | compi = compptr->component_index; | 214 | 117M | for (row = 0, prev_row = compptr->v_samp_factor - 1; | 215 | 293M | row < (cinfo->input_iMCU_row == last_iMCU_row ? | 216 | 293M | compptr->last_row_height : compptr->v_samp_factor); | 217 | 176M | prev_row = row, row++) { | 218 | 176M | (*losslessd->predict_undifference[compi]) | 219 | 176M | (cinfo, compi, diff->diff_buf[compi][row], | 220 | 176M | diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row], | 221 | 176M | compptr->width_in_blocks); | 222 | 176M | (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row], | 223 | 176M | output_buf[compi][row], | 224 | 176M | compptr->width_in_blocks); | 225 | 176M | } | 226 | 117M | } | 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 | 87.8M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 235 | 87.7M | start_iMCU_row(cinfo); | 236 | 87.7M | return JPEG_ROW_COMPLETED; | 237 | 87.7M | } | 238 | | /* Completed the scan */ | 239 | 14.5k | (*cinfo->inputctl->finish_input_pass) (cinfo); | 240 | 14.5k | return JPEG_SCAN_COMPLETED; | 241 | 87.8M | } |
|
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 | 190M | { |
267 | 190M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; |
268 | 190M | int ci, compi; |
269 | 190M | _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN]; |
270 | 190M | jpeg_component_info *compptr; |
271 | | |
272 | | /* Align the virtual buffers for the components used in this scan. */ |
273 | 446M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
274 | 255M | compptr = cinfo->cur_comp_info[ci]; |
275 | 255M | compi = compptr->component_index; |
276 | 255M | buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) |
277 | 255M | ((j_common_ptr)cinfo, diff->whole_image[compi], |
278 | 255M | cinfo->input_iMCU_row * compptr->v_samp_factor, |
279 | 255M | (JDIMENSION)compptr->v_samp_factor, TRUE); |
280 | 255M | } |
281 | | |
282 | 190M | return decompress_data(cinfo, buffer); |
283 | 190M | } jddiffct-8.c:consume_data Line | Count | Source | 266 | 44.0M | { | 267 | 44.0M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 268 | 44.0M | int ci, compi; | 269 | 44.0M | _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN]; | 270 | 44.0M | jpeg_component_info *compptr; | 271 | | | 272 | | /* Align the virtual buffers for the components used in this scan. */ | 273 | 115M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 274 | 71.4M | compptr = cinfo->cur_comp_info[ci]; | 275 | 71.4M | compi = compptr->component_index; | 276 | 71.4M | buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 277 | 71.4M | ((j_common_ptr)cinfo, diff->whole_image[compi], | 278 | 71.4M | cinfo->input_iMCU_row * compptr->v_samp_factor, | 279 | 71.4M | (JDIMENSION)compptr->v_samp_factor, TRUE); | 280 | 71.4M | } | 281 | | | 282 | 44.0M | return decompress_data(cinfo, buffer); | 283 | 44.0M | } |
jddiffct-12.c:consume_data Line | Count | Source | 266 | 61.9M | { | 267 | 61.9M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 268 | 61.9M | int ci, compi; | 269 | 61.9M | _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN]; | 270 | 61.9M | jpeg_component_info *compptr; | 271 | | | 272 | | /* Align the virtual buffers for the components used in this scan. */ | 273 | 133M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 274 | 71.8M | compptr = cinfo->cur_comp_info[ci]; | 275 | 71.8M | compi = compptr->component_index; | 276 | 71.8M | buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 277 | 71.8M | ((j_common_ptr)cinfo, diff->whole_image[compi], | 278 | 71.8M | cinfo->input_iMCU_row * compptr->v_samp_factor, | 279 | 71.8M | (JDIMENSION)compptr->v_samp_factor, TRUE); | 280 | 71.8M | } | 281 | | | 282 | 61.9M | return decompress_data(cinfo, buffer); | 283 | 61.9M | } |
jddiffct-16.c:consume_data Line | Count | Source | 266 | 84.3M | { | 267 | 84.3M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 268 | 84.3M | int ci, compi; | 269 | 84.3M | _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN]; | 270 | 84.3M | jpeg_component_info *compptr; | 271 | | | 272 | | /* Align the virtual buffers for the components used in this scan. */ | 273 | 196M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 274 | 112M | compptr = cinfo->cur_comp_info[ci]; | 275 | 112M | compi = compptr->component_index; | 276 | 112M | buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 277 | 112M | ((j_common_ptr)cinfo, diff->whole_image[compi], | 278 | 112M | cinfo->input_iMCU_row * compptr->v_samp_factor, | 279 | 112M | (JDIMENSION)compptr->v_samp_factor, TRUE); | 280 | 112M | } | 281 | | | 282 | 84.3M | return decompress_data(cinfo, buffer); | 283 | 84.3M | } |
|
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.44M | { |
297 | 3.44M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; |
298 | 3.44M | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
299 | 3.44M | int ci, samp_rows, row; |
300 | 3.44M | _JSAMPARRAY buffer; |
301 | 3.44M | jpeg_component_info *compptr; |
302 | | |
303 | | /* Force some input to be done if we are getting ahead of the input. */ |
304 | 5.81M | while (cinfo->input_scan_number < cinfo->output_scan_number || |
305 | 5.81M | (cinfo->input_scan_number == cinfo->output_scan_number && |
306 | 5.81M | cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { |
307 | 2.37M | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) |
308 | 0 | return JPEG_SUSPENDED; |
309 | 2.37M | } |
310 | | |
311 | | /* OK, output from the virtual arrays. */ |
312 | 15.1M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
313 | 11.7M | ci++, compptr++) { |
314 | | /* Align the virtual buffer for this component. */ |
315 | 11.7M | buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) |
316 | 11.7M | ((j_common_ptr)cinfo, diff->whole_image[ci], |
317 | 11.7M | cinfo->output_iMCU_row * compptr->v_samp_factor, |
318 | 11.7M | (JDIMENSION)compptr->v_samp_factor, FALSE); |
319 | | |
320 | 11.7M | if (cinfo->output_iMCU_row < last_iMCU_row) |
321 | 11.6M | samp_rows = compptr->v_samp_factor; |
322 | 6.20k | else { |
323 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ |
324 | 6.20k | samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); |
325 | 6.20k | if (samp_rows == 0) samp_rows = compptr->v_samp_factor; |
326 | 6.20k | } |
327 | | |
328 | 33.1M | for (row = 0; row < samp_rows; row++) { |
329 | 21.4M | memcpy(output_buf[ci][row], buffer[row], |
330 | 21.4M | compptr->width_in_blocks * sizeof(_JSAMPLE)); |
331 | 21.4M | } |
332 | 11.7M | } |
333 | | |
334 | 3.44M | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) |
335 | 3.43M | return JPEG_ROW_COMPLETED; |
336 | 2.63k | return JPEG_SCAN_COMPLETED; |
337 | 3.44M | } Line | Count | Source | 296 | 2.73M | { | 297 | 2.73M | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 298 | 2.73M | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 299 | 2.73M | int ci, samp_rows, row; | 300 | 2.73M | _JSAMPARRAY buffer; | 301 | 2.73M | jpeg_component_info *compptr; | 302 | | | 303 | | /* Force some input to be done if we are getting ahead of the input. */ | 304 | 5.10M | while (cinfo->input_scan_number < cinfo->output_scan_number || | 305 | 5.10M | (cinfo->input_scan_number == cinfo->output_scan_number && | 306 | 5.10M | cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { | 307 | 2.37M | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) | 308 | 0 | return JPEG_SUSPENDED; | 309 | 2.37M | } | 310 | | | 311 | | /* OK, output from the virtual arrays. */ | 312 | 12.1M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 313 | 9.41M | ci++, compptr++) { | 314 | | /* Align the virtual buffer for this component. */ | 315 | 9.41M | buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 316 | 9.41M | ((j_common_ptr)cinfo, diff->whole_image[ci], | 317 | 9.41M | cinfo->output_iMCU_row * compptr->v_samp_factor, | 318 | 9.41M | (JDIMENSION)compptr->v_samp_factor, FALSE); | 319 | | | 320 | 9.41M | if (cinfo->output_iMCU_row < last_iMCU_row) | 321 | 9.40M | samp_rows = compptr->v_samp_factor; | 322 | 4.70k | else { | 323 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ | 324 | 4.70k | samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); | 325 | 4.70k | if (samp_rows == 0) samp_rows = compptr->v_samp_factor; | 326 | 4.70k | } | 327 | | | 328 | 27.8M | for (row = 0; row < samp_rows; row++) { | 329 | 18.4M | memcpy(output_buf[ci][row], buffer[row], | 330 | 18.4M | compptr->width_in_blocks * sizeof(_JSAMPLE)); | 331 | 18.4M | } | 332 | 9.41M | } | 333 | | | 334 | 2.73M | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) | 335 | 2.73M | return JPEG_ROW_COMPLETED; | 336 | 1.71k | return JPEG_SCAN_COMPLETED; | 337 | 2.73M | } |
jddiffct-12.c:output_data Line | Count | Source | 296 | 220k | { | 297 | 220k | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 298 | 220k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 299 | 220k | int ci, samp_rows, row; | 300 | 220k | _JSAMPARRAY buffer; | 301 | 220k | jpeg_component_info *compptr; | 302 | | | 303 | | /* Force some input to be done if we are getting ahead of the input. */ | 304 | 220k | while (cinfo->input_scan_number < cinfo->output_scan_number || | 305 | 220k | (cinfo->input_scan_number == cinfo->output_scan_number && | 306 | 220k | 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 | 976k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 313 | 756k | ci++, compptr++) { | 314 | | /* Align the virtual buffer for this component. */ | 315 | 756k | buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 316 | 756k | ((j_common_ptr)cinfo, diff->whole_image[ci], | 317 | 756k | cinfo->output_iMCU_row * compptr->v_samp_factor, | 318 | 756k | (JDIMENSION)compptr->v_samp_factor, FALSE); | 319 | | | 320 | 756k | if (cinfo->output_iMCU_row < last_iMCU_row) | 321 | 755k | samp_rows = compptr->v_samp_factor; | 322 | 677 | else { | 323 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ | 324 | 677 | samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); | 325 | 677 | if (samp_rows == 0) samp_rows = compptr->v_samp_factor; | 326 | 677 | } | 327 | | | 328 | 1.70M | for (row = 0; row < samp_rows; row++) { | 329 | 952k | memcpy(output_buf[ci][row], buffer[row], | 330 | 952k | compptr->width_in_blocks * sizeof(_JSAMPLE)); | 331 | 952k | } | 332 | 756k | } | 333 | | | 334 | 220k | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) | 335 | 219k | return JPEG_ROW_COMPLETED; | 336 | 363 | return JPEG_SCAN_COMPLETED; | 337 | 220k | } |
jddiffct-16.c:output_data Line | Count | Source | 296 | 487k | { | 297 | 487k | my_diff_ptr diff = (my_diff_ptr)cinfo->coef; | 298 | 487k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 299 | 487k | int ci, samp_rows, row; | 300 | 487k | _JSAMPARRAY buffer; | 301 | 487k | jpeg_component_info *compptr; | 302 | | | 303 | | /* Force some input to be done if we are getting ahead of the input. */ | 304 | 487k | while (cinfo->input_scan_number < cinfo->output_scan_number || | 305 | 487k | (cinfo->input_scan_number == cinfo->output_scan_number && | 306 | 487k | 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 | 2.02M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 313 | 1.53M | ci++, compptr++) { | 314 | | /* Align the virtual buffer for this component. */ | 315 | 1.53M | buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 316 | 1.53M | ((j_common_ptr)cinfo, diff->whole_image[ci], | 317 | 1.53M | cinfo->output_iMCU_row * compptr->v_samp_factor, | 318 | 1.53M | (JDIMENSION)compptr->v_samp_factor, FALSE); | 319 | | | 320 | 1.53M | if (cinfo->output_iMCU_row < last_iMCU_row) | 321 | 1.53M | samp_rows = compptr->v_samp_factor; | 322 | 827 | else { | 323 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ | 324 | 827 | samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); | 325 | 827 | if (samp_rows == 0) samp_rows = compptr->v_samp_factor; | 326 | 827 | } | 327 | | | 328 | 3.59M | for (row = 0; row < samp_rows; row++) { | 329 | 2.06M | memcpy(output_buf[ci][row], buffer[row], | 330 | 2.06M | compptr->width_in_blocks * sizeof(_JSAMPLE)); | 331 | 2.06M | } | 332 | 1.53M | } | 333 | | | 334 | 487k | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) | 335 | 487k | return JPEG_ROW_COMPLETED; | 336 | 549 | return JPEG_SCAN_COMPLETED; | 337 | 487k | } |
|
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 | 17.6k | { |
349 | 17.6k | my_diff_ptr diff; |
350 | 17.6k | int ci; |
351 | 17.6k | jpeg_component_info *compptr; |
352 | | |
353 | | #if BITS_IN_JSAMPLE == 8 |
354 | 5.80k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
355 | | #else |
356 | 11.8k | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
357 | 11.8k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) |
358 | 0 | #endif |
359 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
360 | | |
361 | 17.6k | diff = (my_diff_ptr) |
362 | 17.6k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
363 | 17.6k | sizeof(my_diff_controller)); |
364 | 17.6k | cinfo->coef = (struct jpeg_d_coef_controller *)diff; |
365 | 17.6k | diff->pub.start_input_pass = start_input_pass; |
366 | 17.6k | diff->pub.start_output_pass = start_output_pass; |
367 | | |
368 | | /* Create the [un]difference buffers. */ |
369 | 64.5k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
370 | 46.8k | ci++, compptr++) { |
371 | 46.8k | diff->diff_buf[ci] = |
372 | 46.8k | ALLOC_DARRAY(JPOOL_IMAGE, |
373 | 46.8k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, |
374 | 46.8k | (long)compptr->h_samp_factor), |
375 | 46.8k | (JDIMENSION)compptr->v_samp_factor); |
376 | 46.8k | diff->undiff_buf[ci] = |
377 | 46.8k | ALLOC_DARRAY(JPOOL_IMAGE, |
378 | 46.8k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, |
379 | 46.8k | (long)compptr->h_samp_factor), |
380 | 46.8k | (JDIMENSION)compptr->v_samp_factor); |
381 | 46.8k | } |
382 | | |
383 | 17.6k | if (need_full_buffer) { |
384 | 13.6k | #ifdef D_MULTISCAN_FILES_SUPPORTED |
385 | | /* Allocate a full-image virtual array for each component. */ |
386 | 13.6k | int access_rows; |
387 | | |
388 | 53.7k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
389 | 40.1k | ci++, compptr++) { |
390 | 40.1k | access_rows = compptr->v_samp_factor; |
391 | 40.1k | diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray) |
392 | 40.1k | ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, |
393 | 40.1k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, |
394 | 40.1k | (long)compptr->h_samp_factor), |
395 | 40.1k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, |
396 | 40.1k | (long)compptr->v_samp_factor), |
397 | 40.1k | (JDIMENSION)access_rows); |
398 | 40.1k | } |
399 | 13.6k | diff->pub.consume_data = consume_data; |
400 | 13.6k | diff->pub._decompress_data = output_data; |
401 | | #else |
402 | | ERREXIT(cinfo, JERR_NOT_COMPILED); |
403 | | #endif |
404 | 13.6k | } else { |
405 | 4.03k | diff->pub.consume_data = dummy_consume_data; |
406 | 4.03k | diff->pub._decompress_data = decompress_data; |
407 | | diff->whole_image[0] = NULL; /* flag for no virtual arrays */ |
408 | 4.03k | } |
409 | 17.6k | } Line | Count | Source | 348 | 5.80k | { | 349 | 5.80k | my_diff_ptr diff; | 350 | 5.80k | int ci; | 351 | 5.80k | jpeg_component_info *compptr; | 352 | | | 353 | 5.80k | #if BITS_IN_JSAMPLE == 8 | 354 | 5.80k | 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 | 5.80k | diff = (my_diff_ptr) | 362 | 5.80k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 363 | 5.80k | sizeof(my_diff_controller)); | 364 | 5.80k | cinfo->coef = (struct jpeg_d_coef_controller *)diff; | 365 | 5.80k | diff->pub.start_input_pass = start_input_pass; | 366 | 5.80k | diff->pub.start_output_pass = start_output_pass; | 367 | | | 368 | | /* Create the [un]difference buffers. */ | 369 | 21.3k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 370 | 15.5k | ci++, compptr++) { | 371 | 15.5k | diff->diff_buf[ci] = | 372 | 15.5k | ALLOC_DARRAY(JPOOL_IMAGE, | 373 | 15.5k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 374 | 15.5k | (long)compptr->h_samp_factor), | 375 | 15.5k | (JDIMENSION)compptr->v_samp_factor); | 376 | 15.5k | diff->undiff_buf[ci] = | 377 | 15.5k | ALLOC_DARRAY(JPOOL_IMAGE, | 378 | 15.5k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 379 | 15.5k | (long)compptr->h_samp_factor), | 380 | 15.5k | (JDIMENSION)compptr->v_samp_factor); | 381 | 15.5k | } | 382 | | | 383 | 5.80k | if (need_full_buffer) { | 384 | 4.60k | #ifdef D_MULTISCAN_FILES_SUPPORTED | 385 | | /* Allocate a full-image virtual array for each component. */ | 386 | 4.60k | int access_rows; | 387 | | | 388 | 18.1k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 389 | 13.5k | ci++, compptr++) { | 390 | 13.5k | access_rows = compptr->v_samp_factor; | 391 | 13.5k | diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray) | 392 | 13.5k | ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, | 393 | 13.5k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 394 | 13.5k | (long)compptr->h_samp_factor), | 395 | 13.5k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, | 396 | 13.5k | (long)compptr->v_samp_factor), | 397 | 13.5k | (JDIMENSION)access_rows); | 398 | 13.5k | } | 399 | 4.60k | diff->pub.consume_data = consume_data; | 400 | 4.60k | diff->pub._decompress_data = output_data; | 401 | | #else | 402 | | ERREXIT(cinfo, JERR_NOT_COMPILED); | 403 | | #endif | 404 | 4.60k | } else { | 405 | 1.20k | diff->pub.consume_data = dummy_consume_data; | 406 | 1.20k | diff->pub._decompress_data = decompress_data; | 407 | | diff->whole_image[0] = NULL; /* flag for no virtual arrays */ | 408 | 1.20k | } | 409 | 5.80k | } |
j12init_d_diff_controller Line | Count | Source | 348 | 5.78k | { | 349 | 5.78k | my_diff_ptr diff; | 350 | 5.78k | int ci; | 351 | 5.78k | 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.78k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 357 | 5.78k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 358 | 0 | #endif | 359 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 360 | | | 361 | 5.78k | diff = (my_diff_ptr) | 362 | 5.78k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 363 | 5.78k | sizeof(my_diff_controller)); | 364 | 5.78k | cinfo->coef = (struct jpeg_d_coef_controller *)diff; | 365 | 5.78k | diff->pub.start_input_pass = start_input_pass; | 366 | 5.78k | diff->pub.start_output_pass = start_output_pass; | 367 | | | 368 | | /* Create the [un]difference buffers. */ | 369 | 20.9k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 370 | 15.1k | ci++, compptr++) { | 371 | 15.1k | diff->diff_buf[ci] = | 372 | 15.1k | ALLOC_DARRAY(JPOOL_IMAGE, | 373 | 15.1k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 374 | 15.1k | (long)compptr->h_samp_factor), | 375 | 15.1k | (JDIMENSION)compptr->v_samp_factor); | 376 | 15.1k | diff->undiff_buf[ci] = | 377 | 15.1k | ALLOC_DARRAY(JPOOL_IMAGE, | 378 | 15.1k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 379 | 15.1k | (long)compptr->h_samp_factor), | 380 | 15.1k | (JDIMENSION)compptr->v_samp_factor); | 381 | 15.1k | } | 382 | | | 383 | 5.78k | if (need_full_buffer) { | 384 | 4.33k | #ifdef D_MULTISCAN_FILES_SUPPORTED | 385 | | /* Allocate a full-image virtual array for each component. */ | 386 | 4.33k | int access_rows; | 387 | | | 388 | 17.1k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 389 | 12.7k | ci++, compptr++) { | 390 | 12.7k | access_rows = compptr->v_samp_factor; | 391 | 12.7k | diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray) | 392 | 12.7k | ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, | 393 | 12.7k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 394 | 12.7k | (long)compptr->h_samp_factor), | 395 | 12.7k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, | 396 | 12.7k | (long)compptr->v_samp_factor), | 397 | 12.7k | (JDIMENSION)access_rows); | 398 | 12.7k | } | 399 | 4.33k | diff->pub.consume_data = consume_data; | 400 | 4.33k | diff->pub._decompress_data = output_data; | 401 | | #else | 402 | | ERREXIT(cinfo, JERR_NOT_COMPILED); | 403 | | #endif | 404 | 4.33k | } else { | 405 | 1.45k | diff->pub.consume_data = dummy_consume_data; | 406 | 1.45k | diff->pub._decompress_data = decompress_data; | 407 | | diff->whole_image[0] = NULL; /* flag for no virtual arrays */ | 408 | 1.45k | } | 409 | 5.78k | } |
j16init_d_diff_controller Line | Count | Source | 348 | 6.05k | { | 349 | 6.05k | my_diff_ptr diff; | 350 | 6.05k | int ci; | 351 | 6.05k | 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.05k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 357 | 6.05k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 358 | 0 | #endif | 359 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 360 | | | 361 | 6.05k | diff = (my_diff_ptr) | 362 | 6.05k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 363 | 6.05k | sizeof(my_diff_controller)); | 364 | 6.05k | cinfo->coef = (struct jpeg_d_coef_controller *)diff; | 365 | 6.05k | diff->pub.start_input_pass = start_input_pass; | 366 | 6.05k | diff->pub.start_output_pass = start_output_pass; | 367 | | | 368 | | /* Create the [un]difference buffers. */ | 369 | 22.2k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 370 | 16.2k | ci++, compptr++) { | 371 | 16.2k | diff->diff_buf[ci] = | 372 | 16.2k | ALLOC_DARRAY(JPOOL_IMAGE, | 373 | 16.2k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 374 | 16.2k | (long)compptr->h_samp_factor), | 375 | 16.2k | (JDIMENSION)compptr->v_samp_factor); | 376 | 16.2k | diff->undiff_buf[ci] = | 377 | 16.2k | ALLOC_DARRAY(JPOOL_IMAGE, | 378 | 16.2k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 379 | 16.2k | (long)compptr->h_samp_factor), | 380 | 16.2k | (JDIMENSION)compptr->v_samp_factor); | 381 | 16.2k | } | 382 | | | 383 | 6.05k | if (need_full_buffer) { | 384 | 4.67k | #ifdef D_MULTISCAN_FILES_SUPPORTED | 385 | | /* Allocate a full-image virtual array for each component. */ | 386 | 4.67k | int access_rows; | 387 | | | 388 | 18.4k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 389 | 13.7k | ci++, compptr++) { | 390 | 13.7k | access_rows = compptr->v_samp_factor; | 391 | 13.7k | diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray) | 392 | 13.7k | ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, | 393 | 13.7k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 394 | 13.7k | (long)compptr->h_samp_factor), | 395 | 13.7k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, | 396 | 13.7k | (long)compptr->v_samp_factor), | 397 | 13.7k | (JDIMENSION)access_rows); | 398 | 13.7k | } | 399 | 4.67k | diff->pub.consume_data = consume_data; | 400 | 4.67k | diff->pub._decompress_data = output_data; | 401 | | #else | 402 | | ERREXIT(cinfo, JERR_NOT_COMPILED); | 403 | | #endif | 404 | 4.67k | } else { | 405 | 1.37k | diff->pub.consume_data = dummy_consume_data; | 406 | 1.37k | diff->pub._decompress_data = decompress_data; | 407 | | diff->whole_image[0] = NULL; /* flag for no virtual arrays */ | 408 | 1.37k | } | 409 | 6.05k | } |
|
410 | | |
411 | | #endif /* D_LOSSLESS_SUPPORTED */ |