/src/libjpeg-turbo.main/src/jdcoefct.c
Line | Count | Source |
1 | | /* |
2 | | * jdcoefct.c |
3 | | * |
4 | | * This file was part of the Independent JPEG Group's software: |
5 | | * Copyright (C) 1994-1997, Thomas G. Lane. |
6 | | * libjpeg-turbo Modifications: |
7 | | * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
8 | | * Copyright (C) 2010, 2015-2016, 2019-2020, 2022-2024, D. R. Commander. |
9 | | * Copyright (C) 2015, 2020, Google, Inc. |
10 | | * For conditions of distribution and use, see the accompanying README.ijg |
11 | | * file. |
12 | | * |
13 | | * This file contains the coefficient buffer controller for decompression. |
14 | | * This controller is the top level of the lossy JPEG decompressor proper. |
15 | | * The coefficient buffer lies between entropy decoding and inverse-DCT steps. |
16 | | * |
17 | | * In buffered-image mode, this controller is the interface between |
18 | | * input-oriented processing and output-oriented processing. |
19 | | * Also, the input side (only) is used when reading a file for transcoding. |
20 | | */ |
21 | | |
22 | | #include "jinclude.h" |
23 | | #include "jdcoefct.h" |
24 | | #include "jpegapicomp.h" |
25 | | #include "jsamplecomp.h" |
26 | | |
27 | | |
28 | | /* Forward declarations */ |
29 | | METHODDEF(int) decompress_onepass(j_decompress_ptr cinfo, |
30 | | _JSAMPIMAGE output_buf); |
31 | | #ifdef D_MULTISCAN_FILES_SUPPORTED |
32 | | METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf); |
33 | | #endif |
34 | | #ifdef BLOCK_SMOOTHING_SUPPORTED |
35 | | LOCAL(boolean) smoothing_ok(j_decompress_ptr cinfo); |
36 | | METHODDEF(int) decompress_smooth_data(j_decompress_ptr cinfo, |
37 | | _JSAMPIMAGE output_buf); |
38 | | #endif |
39 | | |
40 | | |
41 | | /* |
42 | | * Initialize for an input processing pass. |
43 | | */ |
44 | | |
45 | | METHODDEF(void) |
46 | | start_input_pass(j_decompress_ptr cinfo) |
47 | 26.9k | { |
48 | 26.9k | cinfo->input_iMCU_row = 0; |
49 | 26.9k | start_iMCU_row(cinfo); |
50 | 26.9k | } jdcoefct-8.c:start_input_pass Line | Count | Source | 47 | 16.3k | { | 48 | 16.3k | cinfo->input_iMCU_row = 0; | 49 | 16.3k | start_iMCU_row(cinfo); | 50 | 16.3k | } |
jdcoefct-12.c:start_input_pass Line | Count | Source | 47 | 10.5k | { | 48 | 10.5k | cinfo->input_iMCU_row = 0; | 49 | 10.5k | start_iMCU_row(cinfo); | 50 | 10.5k | } |
|
51 | | |
52 | | |
53 | | /* |
54 | | * Initialize for an output processing pass. |
55 | | */ |
56 | | |
57 | | METHODDEF(void) |
58 | | start_output_pass(j_decompress_ptr cinfo) |
59 | 4.43k | { |
60 | 4.43k | #ifdef BLOCK_SMOOTHING_SUPPORTED |
61 | 4.43k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
62 | | |
63 | | /* If multipass, check to see whether to use block smoothing on this pass */ |
64 | 4.43k | if (coef->pub.coef_arrays != NULL) { |
65 | 3.61k | if (cinfo->do_block_smoothing && smoothing_ok(cinfo)) |
66 | 1.06k | coef->pub._decompress_data = decompress_smooth_data; |
67 | 2.54k | else |
68 | 2.54k | coef->pub._decompress_data = decompress_data; |
69 | 3.61k | } |
70 | 4.43k | #endif |
71 | 4.43k | cinfo->output_iMCU_row = 0; |
72 | 4.43k | } jdcoefct-8.c:start_output_pass Line | Count | Source | 59 | 1.92k | { | 60 | 1.92k | #ifdef BLOCK_SMOOTHING_SUPPORTED | 61 | 1.92k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 62 | | | 63 | | /* If multipass, check to see whether to use block smoothing on this pass */ | 64 | 1.92k | if (coef->pub.coef_arrays != NULL) { | 65 | 1.51k | if (cinfo->do_block_smoothing && smoothing_ok(cinfo)) | 66 | 492 | coef->pub._decompress_data = decompress_smooth_data; | 67 | 1.02k | else | 68 | 1.02k | coef->pub._decompress_data = decompress_data; | 69 | 1.51k | } | 70 | 1.92k | #endif | 71 | 1.92k | cinfo->output_iMCU_row = 0; | 72 | 1.92k | } |
jdcoefct-12.c:start_output_pass Line | Count | Source | 59 | 2.51k | { | 60 | 2.51k | #ifdef BLOCK_SMOOTHING_SUPPORTED | 61 | 2.51k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 62 | | | 63 | | /* If multipass, check to see whether to use block smoothing on this pass */ | 64 | 2.51k | if (coef->pub.coef_arrays != NULL) { | 65 | 2.10k | if (cinfo->do_block_smoothing && smoothing_ok(cinfo)) | 66 | 577 | coef->pub._decompress_data = decompress_smooth_data; | 67 | 1.52k | else | 68 | 1.52k | coef->pub._decompress_data = decompress_data; | 69 | 2.10k | } | 70 | 2.51k | #endif | 71 | 2.51k | cinfo->output_iMCU_row = 0; | 72 | 2.51k | } |
|
73 | | |
74 | | |
75 | | /* |
76 | | * Decompress and return some data in the single-pass case. |
77 | | * Always attempts to emit one fully interleaved MCU row ("iMCU" row). |
78 | | * Input and output must run in lockstep since we have only a one-MCU buffer. |
79 | | * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
80 | | * |
81 | | * NB: output_buf contains a plane for each component in image, |
82 | | * which we index according to the component's SOF position. |
83 | | */ |
84 | | |
85 | | METHODDEF(int) |
86 | | decompress_onepass(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf) |
87 | 373k | { |
88 | 373k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
89 | 373k | JDIMENSION MCU_col_num; /* index of current MCU within row */ |
90 | 373k | JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; |
91 | 373k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
92 | 373k | int blkn, ci, xindex, yindex, yoffset, useful_width; |
93 | 373k | _JSAMPARRAY output_ptr; |
94 | 373k | JDIMENSION start_col, output_col; |
95 | 373k | jpeg_component_info *compptr; |
96 | 373k | _inverse_DCT_method_ptr inverse_DCT; |
97 | | |
98 | | /* Loop to process as much as one whole iMCU row */ |
99 | 980k | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; |
100 | 607k | yoffset++) { |
101 | 5.41M | for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; |
102 | 4.80M | MCU_col_num++) { |
103 | | /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ |
104 | 4.80M | jzero_far((void *)coef->MCU_buffer[0], |
105 | 4.80M | (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK))); |
106 | 4.80M | if (!cinfo->entropy->insufficient_data) |
107 | 2.91M | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; |
108 | 4.80M | if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { |
109 | | /* Suspension forced; update state counters and exit */ |
110 | 0 | coef->MCU_vert_offset = yoffset; |
111 | 0 | coef->MCU_ctr = MCU_col_num; |
112 | 0 | return JPEG_SUSPENDED; |
113 | 0 | } |
114 | | |
115 | | /* Only perform the IDCT on blocks that are contained within the desired |
116 | | * cropping region. |
117 | | */ |
118 | 4.80M | if (MCU_col_num >= cinfo->master->first_iMCU_col && |
119 | 4.80M | MCU_col_num <= cinfo->master->last_iMCU_col) { |
120 | | /* Determine where data should go in output_buf and do the IDCT thing. |
121 | | * We skip dummy blocks at the right and bottom edges (but blkn gets |
122 | | * incremented past them!). Note the inner loop relies on having |
123 | | * allocated the MCU_buffer[] blocks sequentially. |
124 | | */ |
125 | 4.80M | blkn = 0; /* index of current DCT block within MCU */ |
126 | 9.77M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
127 | 4.96M | compptr = cinfo->cur_comp_info[ci]; |
128 | | /* Don't bother to IDCT an uninteresting component. */ |
129 | 4.96M | if (!compptr->component_needed) { |
130 | 12.6k | blkn += compptr->MCU_blocks; |
131 | 12.6k | continue; |
132 | 12.6k | } |
133 | 4.95M | inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index]; |
134 | 4.95M | useful_width = (MCU_col_num < last_MCU_col) ? |
135 | 4.32M | compptr->MCU_width : compptr->last_col_width; |
136 | 4.95M | output_ptr = output_buf[compptr->component_index] + |
137 | 4.95M | yoffset * compptr->_DCT_scaled_size; |
138 | 4.95M | start_col = (MCU_col_num - cinfo->master->first_iMCU_col) * |
139 | 4.95M | compptr->MCU_sample_width; |
140 | 10.0M | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { |
141 | 5.04M | if (cinfo->input_iMCU_row < last_iMCU_row || |
142 | 5.01M | yoffset + yindex < compptr->last_row_height) { |
143 | 5.01M | output_col = start_col; |
144 | 10.1M | for (xindex = 0; xindex < useful_width; xindex++) { |
145 | 5.17M | (*inverse_DCT) (cinfo, compptr, |
146 | 5.17M | (JCOEFPTR)coef->MCU_buffer[blkn + xindex], |
147 | 5.17M | output_ptr, output_col); |
148 | 5.17M | output_col += compptr->_DCT_scaled_size; |
149 | 5.17M | } |
150 | 5.01M | } |
151 | 5.04M | blkn += compptr->MCU_width; |
152 | 5.04M | output_ptr += compptr->_DCT_scaled_size; |
153 | 5.04M | } |
154 | 4.95M | } |
155 | 4.80M | } |
156 | 4.80M | } |
157 | | /* Completed an MCU row, but perhaps not an iMCU row */ |
158 | 607k | coef->MCU_ctr = 0; |
159 | 607k | } |
160 | | /* Completed the iMCU row, advance counters for next one */ |
161 | 373k | cinfo->output_iMCU_row++; |
162 | 373k | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { |
163 | 373k | start_iMCU_row(cinfo); |
164 | 373k | return JPEG_ROW_COMPLETED; |
165 | 373k | } |
166 | | /* Completed the scan */ |
167 | 818 | (*cinfo->inputctl->finish_input_pass) (cinfo); |
168 | 818 | return JPEG_SCAN_COMPLETED; |
169 | 373k | } jdcoefct-8.c:decompress_onepass Line | Count | Source | 87 | 166k | { | 88 | 166k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 89 | 166k | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 90 | 166k | JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; | 91 | 166k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 92 | 166k | int blkn, ci, xindex, yindex, yoffset, useful_width; | 93 | 166k | _JSAMPARRAY output_ptr; | 94 | 166k | JDIMENSION start_col, output_col; | 95 | 166k | jpeg_component_info *compptr; | 96 | 166k | _inverse_DCT_method_ptr inverse_DCT; | 97 | | | 98 | | /* Loop to process as much as one whole iMCU row */ | 99 | 413k | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; | 100 | 247k | yoffset++) { | 101 | 2.47M | for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; | 102 | 2.22M | MCU_col_num++) { | 103 | | /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ | 104 | 2.22M | jzero_far((void *)coef->MCU_buffer[0], | 105 | 2.22M | (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK))); | 106 | 2.22M | if (!cinfo->entropy->insufficient_data) | 107 | 519k | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; | 108 | 2.22M | if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { | 109 | | /* Suspension forced; update state counters and exit */ | 110 | 0 | coef->MCU_vert_offset = yoffset; | 111 | 0 | coef->MCU_ctr = MCU_col_num; | 112 | 0 | return JPEG_SUSPENDED; | 113 | 0 | } | 114 | | | 115 | | /* Only perform the IDCT on blocks that are contained within the desired | 116 | | * cropping region. | 117 | | */ | 118 | 2.22M | if (MCU_col_num >= cinfo->master->first_iMCU_col && | 119 | 2.22M | MCU_col_num <= cinfo->master->last_iMCU_col) { | 120 | | /* Determine where data should go in output_buf and do the IDCT thing. | 121 | | * We skip dummy blocks at the right and bottom edges (but blkn gets | 122 | | * incremented past them!). Note the inner loop relies on having | 123 | | * allocated the MCU_buffer[] blocks sequentially. | 124 | | */ | 125 | 2.22M | blkn = 0; /* index of current DCT block within MCU */ | 126 | 4.56M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 127 | 2.34M | compptr = cinfo->cur_comp_info[ci]; | 128 | | /* Don't bother to IDCT an uninteresting component. */ | 129 | 2.34M | if (!compptr->component_needed) { | 130 | 5.43k | blkn += compptr->MCU_blocks; | 131 | 5.43k | continue; | 132 | 5.43k | } | 133 | 2.33M | inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index]; | 134 | 2.33M | useful_width = (MCU_col_num < last_MCU_col) ? | 135 | 2.07M | compptr->MCU_width : compptr->last_col_width; | 136 | 2.33M | output_ptr = output_buf[compptr->component_index] + | 137 | 2.33M | yoffset * compptr->_DCT_scaled_size; | 138 | 2.33M | start_col = (MCU_col_num - cinfo->master->first_iMCU_col) * | 139 | 2.33M | compptr->MCU_sample_width; | 140 | 4.73M | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { | 141 | 2.39M | if (cinfo->input_iMCU_row < last_iMCU_row || | 142 | 2.38M | yoffset + yindex < compptr->last_row_height) { | 143 | 2.38M | output_col = start_col; | 144 | 4.86M | for (xindex = 0; xindex < useful_width; xindex++) { | 145 | 2.47M | (*inverse_DCT) (cinfo, compptr, | 146 | 2.47M | (JCOEFPTR)coef->MCU_buffer[blkn + xindex], | 147 | 2.47M | output_ptr, output_col); | 148 | 2.47M | output_col += compptr->_DCT_scaled_size; | 149 | 2.47M | } | 150 | 2.38M | } | 151 | 2.39M | blkn += compptr->MCU_width; | 152 | 2.39M | output_ptr += compptr->_DCT_scaled_size; | 153 | 2.39M | } | 154 | 2.33M | } | 155 | 2.22M | } | 156 | 2.22M | } | 157 | | /* Completed an MCU row, but perhaps not an iMCU row */ | 158 | 247k | coef->MCU_ctr = 0; | 159 | 247k | } | 160 | | /* Completed the iMCU row, advance counters for next one */ | 161 | 166k | cinfo->output_iMCU_row++; | 162 | 166k | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 163 | 165k | start_iMCU_row(cinfo); | 164 | 165k | return JPEG_ROW_COMPLETED; | 165 | 165k | } | 166 | | /* Completed the scan */ | 167 | 403 | (*cinfo->inputctl->finish_input_pass) (cinfo); | 168 | 403 | return JPEG_SCAN_COMPLETED; | 169 | 166k | } |
jdcoefct-12.c:decompress_onepass Line | Count | Source | 87 | 207k | { | 88 | 207k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 89 | 207k | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 90 | 207k | JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; | 91 | 207k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 92 | 207k | int blkn, ci, xindex, yindex, yoffset, useful_width; | 93 | 207k | _JSAMPARRAY output_ptr; | 94 | 207k | JDIMENSION start_col, output_col; | 95 | 207k | jpeg_component_info *compptr; | 96 | 207k | _inverse_DCT_method_ptr inverse_DCT; | 97 | | | 98 | | /* Loop to process as much as one whole iMCU row */ | 99 | 567k | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; | 100 | 360k | yoffset++) { | 101 | 2.94M | for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; | 102 | 2.58M | MCU_col_num++) { | 103 | | /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ | 104 | 2.58M | jzero_far((void *)coef->MCU_buffer[0], | 105 | 2.58M | (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK))); | 106 | 2.58M | if (!cinfo->entropy->insufficient_data) | 107 | 2.40M | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; | 108 | 2.58M | if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { | 109 | | /* Suspension forced; update state counters and exit */ | 110 | 0 | coef->MCU_vert_offset = yoffset; | 111 | 0 | coef->MCU_ctr = MCU_col_num; | 112 | 0 | return JPEG_SUSPENDED; | 113 | 0 | } | 114 | | | 115 | | /* Only perform the IDCT on blocks that are contained within the desired | 116 | | * cropping region. | 117 | | */ | 118 | 2.58M | if (MCU_col_num >= cinfo->master->first_iMCU_col && | 119 | 2.58M | MCU_col_num <= cinfo->master->last_iMCU_col) { | 120 | | /* Determine where data should go in output_buf and do the IDCT thing. | 121 | | * We skip dummy blocks at the right and bottom edges (but blkn gets | 122 | | * incremented past them!). Note the inner loop relies on having | 123 | | * allocated the MCU_buffer[] blocks sequentially. | 124 | | */ | 125 | 2.58M | blkn = 0; /* index of current DCT block within MCU */ | 126 | 5.21M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 127 | 2.62M | compptr = cinfo->cur_comp_info[ci]; | 128 | | /* Don't bother to IDCT an uninteresting component. */ | 129 | 2.62M | if (!compptr->component_needed) { | 130 | 7.20k | blkn += compptr->MCU_blocks; | 131 | 7.20k | continue; | 132 | 7.20k | } | 133 | 2.61M | inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index]; | 134 | 2.61M | useful_width = (MCU_col_num < last_MCU_col) ? | 135 | 2.25M | compptr->MCU_width : compptr->last_col_width; | 136 | 2.61M | output_ptr = output_buf[compptr->component_index] + | 137 | 2.61M | yoffset * compptr->_DCT_scaled_size; | 138 | 2.61M | start_col = (MCU_col_num - cinfo->master->first_iMCU_col) * | 139 | 2.61M | compptr->MCU_sample_width; | 140 | 5.26M | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { | 141 | 2.64M | if (cinfo->input_iMCU_row < last_iMCU_row || | 142 | 2.63M | yoffset + yindex < compptr->last_row_height) { | 143 | 2.63M | output_col = start_col; | 144 | 5.33M | for (xindex = 0; xindex < useful_width; xindex++) { | 145 | 2.69M | (*inverse_DCT) (cinfo, compptr, | 146 | 2.69M | (JCOEFPTR)coef->MCU_buffer[blkn + xindex], | 147 | 2.69M | output_ptr, output_col); | 148 | 2.69M | output_col += compptr->_DCT_scaled_size; | 149 | 2.69M | } | 150 | 2.63M | } | 151 | 2.64M | blkn += compptr->MCU_width; | 152 | 2.64M | output_ptr += compptr->_DCT_scaled_size; | 153 | 2.64M | } | 154 | 2.61M | } | 155 | 2.58M | } | 156 | 2.58M | } | 157 | | /* Completed an MCU row, but perhaps not an iMCU row */ | 158 | 360k | coef->MCU_ctr = 0; | 159 | 360k | } | 160 | | /* Completed the iMCU row, advance counters for next one */ | 161 | 207k | cinfo->output_iMCU_row++; | 162 | 207k | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 163 | 207k | start_iMCU_row(cinfo); | 164 | 207k | return JPEG_ROW_COMPLETED; | 165 | 207k | } | 166 | | /* Completed the scan */ | 167 | 415 | (*cinfo->inputctl->finish_input_pass) (cinfo); | 168 | 415 | return JPEG_SCAN_COMPLETED; | 169 | 207k | } |
|
170 | | |
171 | | |
172 | | /* |
173 | | * Dummy consume-input routine for single-pass operation. |
174 | | */ |
175 | | |
176 | | METHODDEF(int) |
177 | | dummy_consume_data(j_decompress_ptr cinfo) |
178 | 0 | { |
179 | 0 | return JPEG_SUSPENDED; /* Always indicate nothing was done */ |
180 | 0 | } Unexecuted instantiation: jdcoefct-8.c:dummy_consume_data Unexecuted instantiation: jdcoefct-12.c:dummy_consume_data |
181 | | |
182 | | |
183 | | #ifdef D_MULTISCAN_FILES_SUPPORTED |
184 | | |
185 | | /* |
186 | | * Consume input data and store it in the full-image coefficient buffer. |
187 | | * We read as much as one fully interleaved MCU row ("iMCU" row) per call, |
188 | | * ie, v_samp_factor block rows for each component in the scan. |
189 | | * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
190 | | */ |
191 | | |
192 | | METHODDEF(int) |
193 | | consume_data(j_decompress_ptr cinfo) |
194 | 4.42M | { |
195 | 4.42M | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
196 | 4.42M | JDIMENSION MCU_col_num; /* index of current MCU within row */ |
197 | 4.42M | int blkn, ci, xindex, yindex, yoffset; |
198 | 4.42M | JDIMENSION start_col; |
199 | 4.42M | JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; |
200 | 4.42M | JBLOCKROW buffer_ptr; |
201 | 4.42M | jpeg_component_info *compptr; |
202 | | |
203 | | /* Align the virtual buffers for the components used in this scan. */ |
204 | 10.1M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
205 | 5.70M | compptr = cinfo->cur_comp_info[ci]; |
206 | 5.70M | buffer[ci] = (*cinfo->mem->access_virt_barray) |
207 | 5.70M | ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index], |
208 | 5.70M | cinfo->input_iMCU_row * compptr->v_samp_factor, |
209 | 5.70M | (JDIMENSION)compptr->v_samp_factor, TRUE); |
210 | | /* Note: entropy decoder expects buffer to be zeroed, |
211 | | * but this is handled automatically by the memory manager |
212 | | * because we requested a pre-zeroed array. |
213 | | */ |
214 | 5.70M | } |
215 | | |
216 | | /* Loop to process one whole iMCU row */ |
217 | 9.72M | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; |
218 | 5.29M | yoffset++) { |
219 | 78.0M | for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; |
220 | 72.7M | MCU_col_num++) { |
221 | | /* Construct list of pointers to DCT blocks belonging to this MCU */ |
222 | 72.7M | blkn = 0; /* index of current DCT block within MCU */ |
223 | 156M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
224 | 84.0M | compptr = cinfo->cur_comp_info[ci]; |
225 | 84.0M | start_col = MCU_col_num * compptr->MCU_width; |
226 | 182M | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { |
227 | 97.9M | buffer_ptr = buffer[ci][yindex + yoffset] + start_col; |
228 | 207M | for (xindex = 0; xindex < compptr->MCU_width; xindex++) { |
229 | 109M | coef->MCU_buffer[blkn++] = buffer_ptr++; |
230 | 109M | } |
231 | 97.9M | } |
232 | 84.0M | } |
233 | 72.7M | if (!cinfo->entropy->insufficient_data) |
234 | 35.9M | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; |
235 | | /* Try to fetch the MCU. */ |
236 | 72.7M | if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { |
237 | | /* Suspension forced; update state counters and exit */ |
238 | 0 | coef->MCU_vert_offset = yoffset; |
239 | 0 | coef->MCU_ctr = MCU_col_num; |
240 | 0 | return JPEG_SUSPENDED; |
241 | 0 | } |
242 | 72.7M | } |
243 | | /* Completed an MCU row, but perhaps not an iMCU row */ |
244 | 5.29M | coef->MCU_ctr = 0; |
245 | 5.29M | } |
246 | | /* Completed the iMCU row, advance counters for next one */ |
247 | 4.42M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { |
248 | 4.40M | start_iMCU_row(cinfo); |
249 | 4.40M | return JPEG_ROW_COMPLETED; |
250 | 4.40M | } |
251 | | /* Completed the scan */ |
252 | 26.1k | (*cinfo->inputctl->finish_input_pass) (cinfo); |
253 | 26.1k | return JPEG_SCAN_COMPLETED; |
254 | 4.42M | } jdcoefct-8.c:consume_data Line | Count | Source | 194 | 1.99M | { | 195 | 1.99M | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 196 | 1.99M | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 197 | 1.99M | int blkn, ci, xindex, yindex, yoffset; | 198 | 1.99M | JDIMENSION start_col; | 199 | 1.99M | JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; | 200 | 1.99M | JBLOCKROW buffer_ptr; | 201 | 1.99M | jpeg_component_info *compptr; | 202 | | | 203 | | /* Align the virtual buffers for the components used in this scan. */ | 204 | 5.02M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 205 | 3.02M | compptr = cinfo->cur_comp_info[ci]; | 206 | 3.02M | buffer[ci] = (*cinfo->mem->access_virt_barray) | 207 | 3.02M | ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index], | 208 | 3.02M | cinfo->input_iMCU_row * compptr->v_samp_factor, | 209 | 3.02M | (JDIMENSION)compptr->v_samp_factor, TRUE); | 210 | | /* Note: entropy decoder expects buffer to be zeroed, | 211 | | * but this is handled automatically by the memory manager | 212 | | * because we requested a pre-zeroed array. | 213 | | */ | 214 | 3.02M | } | 215 | | | 216 | | /* Loop to process one whole iMCU row */ | 217 | 4.54M | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; | 218 | 2.55M | yoffset++) { | 219 | 58.8M | for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; | 220 | 56.2M | MCU_col_num++) { | 221 | | /* Construct list of pointers to DCT blocks belonging to this MCU */ | 222 | 56.2M | blkn = 0; /* index of current DCT block within MCU */ | 223 | 120M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 224 | 64.0M | compptr = cinfo->cur_comp_info[ci]; | 225 | 64.0M | start_col = MCU_col_num * compptr->MCU_width; | 226 | 136M | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { | 227 | 72.3M | buffer_ptr = buffer[ci][yindex + yoffset] + start_col; | 228 | 155M | for (xindex = 0; xindex < compptr->MCU_width; xindex++) { | 229 | 82.8M | coef->MCU_buffer[blkn++] = buffer_ptr++; | 230 | 82.8M | } | 231 | 72.3M | } | 232 | 64.0M | } | 233 | 56.2M | if (!cinfo->entropy->insufficient_data) | 234 | 23.1M | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; | 235 | | /* Try to fetch the MCU. */ | 236 | 56.2M | if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { | 237 | | /* Suspension forced; update state counters and exit */ | 238 | 0 | coef->MCU_vert_offset = yoffset; | 239 | 0 | coef->MCU_ctr = MCU_col_num; | 240 | 0 | return JPEG_SUSPENDED; | 241 | 0 | } | 242 | 56.2M | } | 243 | | /* Completed an MCU row, but perhaps not an iMCU row */ | 244 | 2.55M | coef->MCU_ctr = 0; | 245 | 2.55M | } | 246 | | /* Completed the iMCU row, advance counters for next one */ | 247 | 1.99M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 248 | 1.98M | start_iMCU_row(cinfo); | 249 | 1.98M | return JPEG_ROW_COMPLETED; | 250 | 1.98M | } | 251 | | /* Completed the scan */ | 252 | 15.9k | (*cinfo->inputctl->finish_input_pass) (cinfo); | 253 | 15.9k | return JPEG_SCAN_COMPLETED; | 254 | 1.99M | } |
jdcoefct-12.c:consume_data Line | Count | Source | 194 | 2.42M | { | 195 | 2.42M | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 196 | 2.42M | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 197 | 2.42M | int blkn, ci, xindex, yindex, yoffset; | 198 | 2.42M | JDIMENSION start_col; | 199 | 2.42M | JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; | 200 | 2.42M | JBLOCKROW buffer_ptr; | 201 | 2.42M | jpeg_component_info *compptr; | 202 | | | 203 | | /* Align the virtual buffers for the components used in this scan. */ | 204 | 5.11M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 205 | 2.68M | compptr = cinfo->cur_comp_info[ci]; | 206 | 2.68M | buffer[ci] = (*cinfo->mem->access_virt_barray) | 207 | 2.68M | ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index], | 208 | 2.68M | cinfo->input_iMCU_row * compptr->v_samp_factor, | 209 | 2.68M | (JDIMENSION)compptr->v_samp_factor, TRUE); | 210 | | /* Note: entropy decoder expects buffer to be zeroed, | 211 | | * but this is handled automatically by the memory manager | 212 | | * because we requested a pre-zeroed array. | 213 | | */ | 214 | 2.68M | } | 215 | | | 216 | | /* Loop to process one whole iMCU row */ | 217 | 5.17M | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; | 218 | 2.74M | yoffset++) { | 219 | 19.2M | for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; | 220 | 16.4M | MCU_col_num++) { | 221 | | /* Construct list of pointers to DCT blocks belonging to this MCU */ | 222 | 16.4M | blkn = 0; /* index of current DCT block within MCU */ | 223 | 36.4M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 224 | 20.0M | compptr = cinfo->cur_comp_info[ci]; | 225 | 20.0M | start_col = MCU_col_num * compptr->MCU_width; | 226 | 45.6M | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { | 227 | 25.5M | buffer_ptr = buffer[ci][yindex + yoffset] + start_col; | 228 | 52.0M | for (xindex = 0; xindex < compptr->MCU_width; xindex++) { | 229 | 26.4M | coef->MCU_buffer[blkn++] = buffer_ptr++; | 230 | 26.4M | } | 231 | 25.5M | } | 232 | 20.0M | } | 233 | 16.4M | if (!cinfo->entropy->insufficient_data) | 234 | 12.8M | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; | 235 | | /* Try to fetch the MCU. */ | 236 | 16.4M | if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { | 237 | | /* Suspension forced; update state counters and exit */ | 238 | 0 | coef->MCU_vert_offset = yoffset; | 239 | 0 | coef->MCU_ctr = MCU_col_num; | 240 | 0 | return JPEG_SUSPENDED; | 241 | 0 | } | 242 | 16.4M | } | 243 | | /* Completed an MCU row, but perhaps not an iMCU row */ | 244 | 2.74M | coef->MCU_ctr = 0; | 245 | 2.74M | } | 246 | | /* Completed the iMCU row, advance counters for next one */ | 247 | 2.42M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 248 | 2.41M | start_iMCU_row(cinfo); | 249 | 2.41M | return JPEG_ROW_COMPLETED; | 250 | 2.41M | } | 251 | | /* Completed the scan */ | 252 | 10.1k | (*cinfo->inputctl->finish_input_pass) (cinfo); | 253 | 10.1k | return JPEG_SCAN_COMPLETED; | 254 | 2.42M | } |
|
255 | | |
256 | | |
257 | | /* |
258 | | * Decompress and return some data in the multi-pass case. |
259 | | * Always attempts to emit one fully interleaved MCU row ("iMCU" row). |
260 | | * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
261 | | * |
262 | | * NB: output_buf contains a plane for each component in image. |
263 | | */ |
264 | | |
265 | | METHODDEF(int) |
266 | | decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf) |
267 | 578k | { |
268 | 578k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
269 | 578k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
270 | 578k | JDIMENSION block_num; |
271 | 578k | int ci, block_row, block_rows; |
272 | 578k | JBLOCKARRAY buffer; |
273 | 578k | JBLOCKROW buffer_ptr; |
274 | 578k | _JSAMPARRAY output_ptr; |
275 | 578k | JDIMENSION output_col; |
276 | 578k | jpeg_component_info *compptr; |
277 | 578k | _inverse_DCT_method_ptr inverse_DCT; |
278 | | |
279 | | /* Force some input to be done if we are getting ahead of the input. */ |
280 | 578k | while (cinfo->input_scan_number < cinfo->output_scan_number || |
281 | 578k | (cinfo->input_scan_number == cinfo->output_scan_number && |
282 | 578k | cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { |
283 | 0 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) |
284 | 0 | return JPEG_SUSPENDED; |
285 | 0 | } |
286 | | |
287 | | /* OK, output from the virtual arrays. */ |
288 | 1.70M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
289 | 1.12M | ci++, compptr++) { |
290 | | /* Don't bother to IDCT an uninteresting component. */ |
291 | 1.12M | if (!compptr->component_needed) |
292 | 93.3k | continue; |
293 | | /* Align the virtual buffer for this component. */ |
294 | 1.02M | buffer = (*cinfo->mem->access_virt_barray) |
295 | 1.02M | ((j_common_ptr)cinfo, coef->whole_image[ci], |
296 | 1.02M | cinfo->output_iMCU_row * compptr->v_samp_factor, |
297 | 1.02M | (JDIMENSION)compptr->v_samp_factor, FALSE); |
298 | | /* Count non-dummy DCT block rows in this iMCU row. */ |
299 | 1.02M | if (cinfo->output_iMCU_row < last_iMCU_row) |
300 | 1.02M | block_rows = compptr->v_samp_factor; |
301 | 5.16k | else { |
302 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ |
303 | 5.16k | block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); |
304 | 5.16k | if (block_rows == 0) block_rows = compptr->v_samp_factor; |
305 | 5.16k | } |
306 | 1.02M | inverse_DCT = cinfo->idct->_inverse_DCT[ci]; |
307 | 1.02M | output_ptr = output_buf[ci]; |
308 | | /* Loop over all DCT blocks to be processed. */ |
309 | 2.54M | for (block_row = 0; block_row < block_rows; block_row++) { |
310 | 1.51M | buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci]; |
311 | 1.51M | output_col = 0; |
312 | 1.51M | for (block_num = cinfo->master->first_MCU_col[ci]; |
313 | 15.2M | block_num <= cinfo->master->last_MCU_col[ci]; block_num++) { |
314 | 13.7M | (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr, |
315 | 13.7M | output_col); |
316 | 13.7M | buffer_ptr++; |
317 | 13.7M | output_col += compptr->_DCT_scaled_size; |
318 | 13.7M | } |
319 | 1.51M | output_ptr += compptr->_DCT_scaled_size; |
320 | 1.51M | } |
321 | 1.02M | } |
322 | | |
323 | 578k | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) |
324 | 575k | return JPEG_ROW_COMPLETED; |
325 | 2.54k | return JPEG_SCAN_COMPLETED; |
326 | 578k | } jdcoefct-8.c:decompress_data Line | Count | Source | 267 | 376k | { | 268 | 376k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 269 | 376k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 270 | 376k | JDIMENSION block_num; | 271 | 376k | int ci, block_row, block_rows; | 272 | 376k | JBLOCKARRAY buffer; | 273 | 376k | JBLOCKROW buffer_ptr; | 274 | 376k | _JSAMPARRAY output_ptr; | 275 | 376k | JDIMENSION output_col; | 276 | 376k | jpeg_component_info *compptr; | 277 | 376k | _inverse_DCT_method_ptr inverse_DCT; | 278 | | | 279 | | /* Force some input to be done if we are getting ahead of the input. */ | 280 | 376k | while (cinfo->input_scan_number < cinfo->output_scan_number || | 281 | 376k | (cinfo->input_scan_number == cinfo->output_scan_number && | 282 | 376k | cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { | 283 | 0 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) | 284 | 0 | return JPEG_SUSPENDED; | 285 | 0 | } | 286 | | | 287 | | /* OK, output from the virtual arrays. */ | 288 | 1.04M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 289 | 673k | ci++, compptr++) { | 290 | | /* Don't bother to IDCT an uninteresting component. */ | 291 | 673k | if (!compptr->component_needed) | 292 | 38.7k | continue; | 293 | | /* Align the virtual buffer for this component. */ | 294 | 634k | buffer = (*cinfo->mem->access_virt_barray) | 295 | 634k | ((j_common_ptr)cinfo, coef->whole_image[ci], | 296 | 634k | cinfo->output_iMCU_row * compptr->v_samp_factor, | 297 | 634k | (JDIMENSION)compptr->v_samp_factor, FALSE); | 298 | | /* Count non-dummy DCT block rows in this iMCU row. */ | 299 | 634k | if (cinfo->output_iMCU_row < last_iMCU_row) | 300 | 632k | block_rows = compptr->v_samp_factor; | 301 | 1.91k | else { | 302 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ | 303 | 1.91k | block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); | 304 | 1.91k | if (block_rows == 0) block_rows = compptr->v_samp_factor; | 305 | 1.91k | } | 306 | 634k | inverse_DCT = cinfo->idct->_inverse_DCT[ci]; | 307 | 634k | output_ptr = output_buf[ci]; | 308 | | /* Loop over all DCT blocks to be processed. */ | 309 | 1.56M | for (block_row = 0; block_row < block_rows; block_row++) { | 310 | 930k | buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci]; | 311 | 930k | output_col = 0; | 312 | 930k | for (block_num = cinfo->master->first_MCU_col[ci]; | 313 | 9.36M | block_num <= cinfo->master->last_MCU_col[ci]; block_num++) { | 314 | 8.43M | (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr, | 315 | 8.43M | output_col); | 316 | 8.43M | buffer_ptr++; | 317 | 8.43M | output_col += compptr->_DCT_scaled_size; | 318 | 8.43M | } | 319 | 930k | output_ptr += compptr->_DCT_scaled_size; | 320 | 930k | } | 321 | 634k | } | 322 | | | 323 | 376k | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) | 324 | 374k | return JPEG_ROW_COMPLETED; | 325 | 1.02k | return JPEG_SCAN_COMPLETED; | 326 | 376k | } |
jdcoefct-12.c:decompress_data Line | Count | Source | 267 | 202k | { | 268 | 202k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 269 | 202k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 270 | 202k | JDIMENSION block_num; | 271 | 202k | int ci, block_row, block_rows; | 272 | 202k | JBLOCKARRAY buffer; | 273 | 202k | JBLOCKROW buffer_ptr; | 274 | 202k | _JSAMPARRAY output_ptr; | 275 | 202k | JDIMENSION output_col; | 276 | 202k | jpeg_component_info *compptr; | 277 | 202k | _inverse_DCT_method_ptr inverse_DCT; | 278 | | | 279 | | /* Force some input to be done if we are getting ahead of the input. */ | 280 | 202k | while (cinfo->input_scan_number < cinfo->output_scan_number || | 281 | 202k | (cinfo->input_scan_number == cinfo->output_scan_number && | 282 | 202k | cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { | 283 | 0 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) | 284 | 0 | return JPEG_SUSPENDED; | 285 | 0 | } | 286 | | | 287 | | /* OK, output from the virtual arrays. */ | 288 | 651k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 289 | 449k | ci++, compptr++) { | 290 | | /* Don't bother to IDCT an uninteresting component. */ | 291 | 449k | if (!compptr->component_needed) | 292 | 54.6k | continue; | 293 | | /* Align the virtual buffer for this component. */ | 294 | 394k | buffer = (*cinfo->mem->access_virt_barray) | 295 | 394k | ((j_common_ptr)cinfo, coef->whole_image[ci], | 296 | 394k | cinfo->output_iMCU_row * compptr->v_samp_factor, | 297 | 394k | (JDIMENSION)compptr->v_samp_factor, FALSE); | 298 | | /* Count non-dummy DCT block rows in this iMCU row. */ | 299 | 394k | if (cinfo->output_iMCU_row < last_iMCU_row) | 300 | 391k | block_rows = compptr->v_samp_factor; | 301 | 3.25k | else { | 302 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ | 303 | 3.25k | block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); | 304 | 3.25k | if (block_rows == 0) block_rows = compptr->v_samp_factor; | 305 | 3.25k | } | 306 | 394k | inverse_DCT = cinfo->idct->_inverse_DCT[ci]; | 307 | 394k | output_ptr = output_buf[ci]; | 308 | | /* Loop over all DCT blocks to be processed. */ | 309 | 980k | for (block_row = 0; block_row < block_rows; block_row++) { | 310 | 585k | buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci]; | 311 | 585k | output_col = 0; | 312 | 585k | for (block_num = cinfo->master->first_MCU_col[ci]; | 313 | 5.87M | block_num <= cinfo->master->last_MCU_col[ci]; block_num++) { | 314 | 5.28M | (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr, | 315 | 5.28M | output_col); | 316 | 5.28M | buffer_ptr++; | 317 | 5.28M | output_col += compptr->_DCT_scaled_size; | 318 | 5.28M | } | 319 | 585k | output_ptr += compptr->_DCT_scaled_size; | 320 | 585k | } | 321 | 394k | } | 322 | | | 323 | 202k | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) | 324 | 200k | return JPEG_ROW_COMPLETED; | 325 | 1.52k | return JPEG_SCAN_COMPLETED; | 326 | 202k | } |
|
327 | | |
328 | | #endif /* D_MULTISCAN_FILES_SUPPORTED */ |
329 | | |
330 | | |
331 | | #ifdef BLOCK_SMOOTHING_SUPPORTED |
332 | | |
333 | | /* |
334 | | * This code applies interblock smoothing; the first 9 AC coefficients are |
335 | | * estimated from the DC values of a DCT block and its 24 neighboring blocks. |
336 | | * We apply smoothing only for progressive JPEG decoding, and only if |
337 | | * the coefficients it can estimate are not yet known to full precision. |
338 | | */ |
339 | | |
340 | | /* Natural-order array positions of the first 9 zigzag-order coefficients */ |
341 | 623k | #define Q01_POS 1 |
342 | 623k | #define Q10_POS 8 |
343 | 623k | #define Q20_POS 16 |
344 | 623k | #define Q11_POS 9 |
345 | 623k | #define Q02_POS 2 |
346 | 477k | #define Q03_POS 3 |
347 | 477k | #define Q12_POS 10 |
348 | 477k | #define Q21_POS 17 |
349 | 477k | #define Q30_POS 24 |
350 | | |
351 | | /* |
352 | | * Determine whether block smoothing is applicable and safe. |
353 | | * We also latch the current states of the coef_bits[] entries for the |
354 | | * AC coefficients; otherwise, if the input side of the decompressor |
355 | | * advances into a new scan, we might think the coefficients are known |
356 | | * more accurately than they really are. |
357 | | */ |
358 | | |
359 | | LOCAL(boolean) |
360 | | smoothing_ok(j_decompress_ptr cinfo) |
361 | 3.61k | { |
362 | 3.61k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
363 | 3.61k | boolean smoothing_useful = FALSE; |
364 | 3.61k | int ci, coefi; |
365 | 3.61k | jpeg_component_info *compptr; |
366 | 3.61k | JQUANT_TBL *qtable; |
367 | 3.61k | int *coef_bits, *prev_coef_bits; |
368 | 3.61k | int *coef_bits_latch, *prev_coef_bits_latch; |
369 | | |
370 | 3.61k | if (!cinfo->progressive_mode || cinfo->coef_bits == NULL) |
371 | 1.33k | return FALSE; |
372 | | |
373 | | /* Allocate latch area if not already done */ |
374 | 2.28k | if (coef->coef_bits_latch == NULL) |
375 | 2.28k | coef->coef_bits_latch = (int *) |
376 | 2.28k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
377 | 2.28k | cinfo->num_components * 2 * |
378 | 2.28k | (SAVED_COEFS * sizeof(int))); |
379 | 2.28k | coef_bits_latch = coef->coef_bits_latch; |
380 | 2.28k | prev_coef_bits_latch = |
381 | 2.28k | &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS]; |
382 | | |
383 | 3.74k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
384 | 2.65k | ci++, compptr++) { |
385 | | /* All components' quantization values must already be latched. */ |
386 | 2.65k | if ((qtable = compptr->quant_table) == NULL) |
387 | 229 | return FALSE; |
388 | | /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */ |
389 | 2.42k | if (qtable->quantval[0] == 0 || |
390 | 2.32k | qtable->quantval[Q01_POS] == 0 || |
391 | 2.17k | qtable->quantval[Q10_POS] == 0 || |
392 | 2.07k | qtable->quantval[Q20_POS] == 0 || |
393 | 1.98k | qtable->quantval[Q11_POS] == 0 || |
394 | 1.88k | qtable->quantval[Q02_POS] == 0 || |
395 | 1.82k | qtable->quantval[Q03_POS] == 0 || |
396 | 1.72k | qtable->quantval[Q12_POS] == 0 || |
397 | 1.64k | qtable->quantval[Q21_POS] == 0 || |
398 | 1.59k | qtable->quantval[Q30_POS] == 0) |
399 | 866 | return FALSE; |
400 | | /* DC values must be at least partly known for all components. */ |
401 | 1.55k | coef_bits = cinfo->coef_bits[ci]; |
402 | 1.55k | prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components]; |
403 | 1.55k | if (coef_bits[0] < 0) |
404 | 98 | return FALSE; |
405 | 1.45k | coef_bits_latch[0] = coef_bits[0]; |
406 | | /* Block smoothing is helpful if some AC coefficients remain inaccurate. */ |
407 | 14.5k | for (coefi = 1; coefi < SAVED_COEFS; coefi++) { |
408 | 13.1k | if (cinfo->input_scan_number > 1) |
409 | 6.15k | prev_coef_bits_latch[coefi] = prev_coef_bits[coefi]; |
410 | 6.96k | else |
411 | 6.96k | prev_coef_bits_latch[coefi] = -1; |
412 | 13.1k | coef_bits_latch[coefi] = coef_bits[coefi]; |
413 | 13.1k | if (coef_bits[coefi] != 0) |
414 | 12.2k | smoothing_useful = TRUE; |
415 | 13.1k | } |
416 | 1.45k | coef_bits_latch += SAVED_COEFS; |
417 | 1.45k | prev_coef_bits_latch += SAVED_COEFS; |
418 | 1.45k | } |
419 | | |
420 | 1.09k | return smoothing_useful; |
421 | 2.28k | } jdcoefct-8.c:smoothing_ok Line | Count | Source | 361 | 1.51k | { | 362 | 1.51k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 363 | 1.51k | boolean smoothing_useful = FALSE; | 364 | 1.51k | int ci, coefi; | 365 | 1.51k | jpeg_component_info *compptr; | 366 | 1.51k | JQUANT_TBL *qtable; | 367 | 1.51k | int *coef_bits, *prev_coef_bits; | 368 | 1.51k | int *coef_bits_latch, *prev_coef_bits_latch; | 369 | | | 370 | 1.51k | if (!cinfo->progressive_mode || cinfo->coef_bits == NULL) | 371 | 333 | return FALSE; | 372 | | | 373 | | /* Allocate latch area if not already done */ | 374 | 1.18k | if (coef->coef_bits_latch == NULL) | 375 | 1.18k | coef->coef_bits_latch = (int *) | 376 | 1.18k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 377 | 1.18k | cinfo->num_components * 2 * | 378 | 1.18k | (SAVED_COEFS * sizeof(int))); | 379 | 1.18k | coef_bits_latch = coef->coef_bits_latch; | 380 | 1.18k | prev_coef_bits_latch = | 381 | 1.18k | &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS]; | 382 | | | 383 | 1.87k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 384 | 1.37k | ci++, compptr++) { | 385 | | /* All components' quantization values must already be latched. */ | 386 | 1.37k | if ((qtable = compptr->quant_table) == NULL) | 387 | 120 | return FALSE; | 388 | | /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */ | 389 | 1.25k | if (qtable->quantval[0] == 0 || | 390 | 1.20k | qtable->quantval[Q01_POS] == 0 || | 391 | 1.11k | qtable->quantval[Q10_POS] == 0 || | 392 | 1.06k | qtable->quantval[Q20_POS] == 0 || | 393 | 1.00k | qtable->quantval[Q11_POS] == 0 || | 394 | 953 | qtable->quantval[Q02_POS] == 0 || | 395 | 906 | qtable->quantval[Q03_POS] == 0 || | 396 | 861 | qtable->quantval[Q12_POS] == 0 || | 397 | 795 | qtable->quantval[Q21_POS] == 0 || | 398 | 772 | qtable->quantval[Q30_POS] == 0) | 399 | 514 | return FALSE; | 400 | | /* DC values must be at least partly known for all components. */ | 401 | 744 | coef_bits = cinfo->coef_bits[ci]; | 402 | 744 | prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components]; | 403 | 744 | if (coef_bits[0] < 0) | 404 | 53 | return FALSE; | 405 | 691 | coef_bits_latch[0] = coef_bits[0]; | 406 | | /* Block smoothing is helpful if some AC coefficients remain inaccurate. */ | 407 | 6.91k | for (coefi = 1; coefi < SAVED_COEFS; coefi++) { | 408 | 6.21k | if (cinfo->input_scan_number > 1) | 409 | 2.94k | prev_coef_bits_latch[coefi] = prev_coef_bits[coefi]; | 410 | 3.27k | else | 411 | 3.27k | prev_coef_bits_latch[coefi] = -1; | 412 | 6.21k | coef_bits_latch[coefi] = coef_bits[coefi]; | 413 | 6.21k | if (coef_bits[coefi] != 0) | 414 | 5.88k | smoothing_useful = TRUE; | 415 | 6.21k | } | 416 | 691 | coef_bits_latch += SAVED_COEFS; | 417 | 691 | prev_coef_bits_latch += SAVED_COEFS; | 418 | 691 | } | 419 | | | 420 | 498 | return smoothing_useful; | 421 | 1.18k | } |
jdcoefct-12.c:smoothing_ok Line | Count | Source | 361 | 2.10k | { | 362 | 2.10k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 363 | 2.10k | boolean smoothing_useful = FALSE; | 364 | 2.10k | int ci, coefi; | 365 | 2.10k | jpeg_component_info *compptr; | 366 | 2.10k | JQUANT_TBL *qtable; | 367 | 2.10k | int *coef_bits, *prev_coef_bits; | 368 | 2.10k | int *coef_bits_latch, *prev_coef_bits_latch; | 369 | | | 370 | 2.10k | if (!cinfo->progressive_mode || cinfo->coef_bits == NULL) | 371 | 999 | return FALSE; | 372 | | | 373 | | /* Allocate latch area if not already done */ | 374 | 1.10k | if (coef->coef_bits_latch == NULL) | 375 | 1.10k | coef->coef_bits_latch = (int *) | 376 | 1.10k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 377 | 1.10k | cinfo->num_components * 2 * | 378 | 1.10k | (SAVED_COEFS * sizeof(int))); | 379 | 1.10k | coef_bits_latch = coef->coef_bits_latch; | 380 | 1.10k | prev_coef_bits_latch = | 381 | 1.10k | &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS]; | 382 | | | 383 | 1.86k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 384 | 1.27k | ci++, compptr++) { | 385 | | /* All components' quantization values must already be latched. */ | 386 | 1.27k | if ((qtable = compptr->quant_table) == NULL) | 387 | 109 | return FALSE; | 388 | | /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */ | 389 | 1.16k | if (qtable->quantval[0] == 0 || | 390 | 1.11k | qtable->quantval[Q01_POS] == 0 || | 391 | 1.05k | qtable->quantval[Q10_POS] == 0 || | 392 | 1.00k | qtable->quantval[Q20_POS] == 0 || | 393 | 977 | qtable->quantval[Q11_POS] == 0 || | 394 | 936 | qtable->quantval[Q02_POS] == 0 || | 395 | 917 | qtable->quantval[Q03_POS] == 0 || | 396 | 867 | qtable->quantval[Q12_POS] == 0 || | 397 | 846 | qtable->quantval[Q21_POS] == 0 || | 398 | 827 | qtable->quantval[Q30_POS] == 0) | 399 | 352 | return FALSE; | 400 | | /* DC values must be at least partly known for all components. */ | 401 | 812 | coef_bits = cinfo->coef_bits[ci]; | 402 | 812 | prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components]; | 403 | 812 | if (coef_bits[0] < 0) | 404 | 45 | return FALSE; | 405 | 767 | coef_bits_latch[0] = coef_bits[0]; | 406 | | /* Block smoothing is helpful if some AC coefficients remain inaccurate. */ | 407 | 7.67k | for (coefi = 1; coefi < SAVED_COEFS; coefi++) { | 408 | 6.90k | if (cinfo->input_scan_number > 1) | 409 | 3.21k | prev_coef_bits_latch[coefi] = prev_coef_bits[coefi]; | 410 | 3.69k | else | 411 | 3.69k | prev_coef_bits_latch[coefi] = -1; | 412 | 6.90k | coef_bits_latch[coefi] = coef_bits[coefi]; | 413 | 6.90k | if (coef_bits[coefi] != 0) | 414 | 6.37k | smoothing_useful = TRUE; | 415 | 6.90k | } | 416 | 767 | coef_bits_latch += SAVED_COEFS; | 417 | 767 | prev_coef_bits_latch += SAVED_COEFS; | 418 | 767 | } | 419 | | | 420 | 595 | return smoothing_useful; | 421 | 1.10k | } |
|
422 | | |
423 | | |
424 | | /* |
425 | | * Variant of decompress_data for use when doing block smoothing. |
426 | | */ |
427 | | |
428 | | METHODDEF(int) |
429 | | decompress_smooth_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf) |
430 | 415k | { |
431 | 415k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
432 | 415k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
433 | 415k | JDIMENSION block_num, last_block_column; |
434 | 415k | int ci, block_row, block_rows, access_rows, image_block_row, |
435 | 415k | image_block_rows; |
436 | 415k | JBLOCKARRAY buffer; |
437 | 415k | JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row; |
438 | 415k | JBLOCKROW next_block_row, next_next_block_row; |
439 | 415k | _JSAMPARRAY output_ptr; |
440 | 415k | JDIMENSION output_col; |
441 | 415k | jpeg_component_info *compptr; |
442 | 415k | _inverse_DCT_method_ptr inverse_DCT; |
443 | 415k | boolean change_dc; |
444 | 415k | JCOEF *workspace; |
445 | 415k | int *coef_bits; |
446 | 415k | JQUANT_TBL *quanttbl; |
447 | 415k | JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num; |
448 | 415k | int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12, |
449 | 415k | DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24, |
450 | 415k | DC25; |
451 | 415k | int Al, pred; |
452 | | |
453 | | /* Keep a local variable to avoid looking it up more than once */ |
454 | 415k | workspace = coef->workspace; |
455 | | |
456 | | /* Force some input to be done if we are getting ahead of the input. */ |
457 | 415k | while (cinfo->input_scan_number <= cinfo->output_scan_number && |
458 | 415k | !cinfo->inputctl->eoi_reached) { |
459 | 0 | if (cinfo->input_scan_number == cinfo->output_scan_number) { |
460 | | /* If input is working on current scan, we ordinarily want it to |
461 | | * have completed the current row. But if input scan is DC, |
462 | | * we want it to keep two rows ahead so that next two block rows' DC |
463 | | * values are up to date. |
464 | | */ |
465 | 0 | JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0; |
466 | 0 | if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta) |
467 | 0 | break; |
468 | 0 | } |
469 | 0 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) |
470 | 0 | return JPEG_SUSPENDED; |
471 | 0 | } |
472 | | |
473 | | /* OK, output from the virtual arrays. */ |
474 | 1.04M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
475 | 627k | ci++, compptr++) { |
476 | | /* Don't bother to IDCT an uninteresting component. */ |
477 | 627k | if (!compptr->component_needed) |
478 | 6.46k | continue; |
479 | | /* Count non-dummy DCT block rows in this iMCU row. */ |
480 | 621k | if (cinfo->output_iMCU_row + 1 < last_iMCU_row) { |
481 | 618k | block_rows = compptr->v_samp_factor; |
482 | 618k | access_rows = block_rows * 3; /* this and next two iMCU rows */ |
483 | 618k | } else if (cinfo->output_iMCU_row < last_iMCU_row) { |
484 | 1.19k | block_rows = compptr->v_samp_factor; |
485 | 1.19k | access_rows = block_rows * 2; /* this and next iMCU row */ |
486 | 1.35k | } else { |
487 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ |
488 | 1.35k | block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); |
489 | 1.35k | if (block_rows == 0) block_rows = compptr->v_samp_factor; |
490 | 1.35k | access_rows = block_rows; /* this iMCU row only */ |
491 | 1.35k | } |
492 | | /* Align the virtual buffer for this component. */ |
493 | 621k | if (cinfo->output_iMCU_row > 1) { |
494 | 618k | access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */ |
495 | 618k | buffer = (*cinfo->mem->access_virt_barray) |
496 | 618k | ((j_common_ptr)cinfo, coef->whole_image[ci], |
497 | 618k | (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor, |
498 | 618k | (JDIMENSION)access_rows, FALSE); |
499 | 618k | buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */ |
500 | 618k | } else if (cinfo->output_iMCU_row > 0) { |
501 | 1.19k | access_rows += compptr->v_samp_factor; /* prior iMCU row too */ |
502 | 1.19k | buffer = (*cinfo->mem->access_virt_barray) |
503 | 1.19k | ((j_common_ptr)cinfo, coef->whole_image[ci], |
504 | 1.19k | (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor, |
505 | 1.19k | (JDIMENSION)access_rows, FALSE); |
506 | 1.19k | buffer += compptr->v_samp_factor; /* point to current iMCU row */ |
507 | 1.35k | } else { |
508 | 1.35k | buffer = (*cinfo->mem->access_virt_barray) |
509 | 1.35k | ((j_common_ptr)cinfo, coef->whole_image[ci], |
510 | 1.35k | (JDIMENSION)0, (JDIMENSION)access_rows, FALSE); |
511 | 1.35k | } |
512 | | /* Fetch component-dependent info. |
513 | | * If the current scan is incomplete, then we use the component-dependent |
514 | | * info from the previous scan. |
515 | | */ |
516 | 621k | if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row) |
517 | 357k | coef_bits = |
518 | 357k | coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS); |
519 | 263k | else |
520 | 263k | coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS); |
521 | | |
522 | | /* We only do DC interpolation if no AC coefficient data is available. */ |
523 | 621k | change_dc = |
524 | 621k | coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 && |
525 | 505k | coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 && |
526 | 488k | coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1; |
527 | | |
528 | 621k | quanttbl = compptr->quant_table; |
529 | 621k | Q00 = quanttbl->quantval[0]; |
530 | 621k | Q01 = quanttbl->quantval[Q01_POS]; |
531 | 621k | Q10 = quanttbl->quantval[Q10_POS]; |
532 | 621k | Q20 = quanttbl->quantval[Q20_POS]; |
533 | 621k | Q11 = quanttbl->quantval[Q11_POS]; |
534 | 621k | Q02 = quanttbl->quantval[Q02_POS]; |
535 | 621k | if (change_dc) { |
536 | 475k | Q03 = quanttbl->quantval[Q03_POS]; |
537 | 475k | Q12 = quanttbl->quantval[Q12_POS]; |
538 | 475k | Q21 = quanttbl->quantval[Q21_POS]; |
539 | 475k | Q30 = quanttbl->quantval[Q30_POS]; |
540 | 475k | } |
541 | 621k | inverse_DCT = cinfo->idct->_inverse_DCT[ci]; |
542 | 621k | output_ptr = output_buf[ci]; |
543 | | /* Loop over all DCT blocks to be processed. */ |
544 | 621k | image_block_rows = block_rows * cinfo->total_iMCU_rows; |
545 | 1.55M | for (block_row = 0; block_row < block_rows; block_row++) { |
546 | 933k | image_block_row = cinfo->output_iMCU_row * block_rows + block_row; |
547 | 933k | buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci]; |
548 | | |
549 | 933k | if (image_block_row > 0) |
550 | 932k | prev_block_row = |
551 | 932k | buffer[block_row - 1] + cinfo->master->first_MCU_col[ci]; |
552 | 1.35k | else |
553 | 1.35k | prev_block_row = buffer_ptr; |
554 | | |
555 | 933k | if (image_block_row > 1) |
556 | 931k | prev_prev_block_row = |
557 | 931k | buffer[block_row - 2] + cinfo->master->first_MCU_col[ci]; |
558 | 2.63k | else |
559 | 2.63k | prev_prev_block_row = prev_block_row; |
560 | | |
561 | 933k | if (image_block_row < image_block_rows - 1) |
562 | 932k | next_block_row = |
563 | 932k | buffer[block_row + 1] + cinfo->master->first_MCU_col[ci]; |
564 | 1.35k | else |
565 | 1.35k | next_block_row = buffer_ptr; |
566 | | |
567 | 933k | if (image_block_row < image_block_rows - 2) |
568 | 931k | next_next_block_row = |
569 | 931k | buffer[block_row + 2] + cinfo->master->first_MCU_col[ci]; |
570 | 2.27k | else |
571 | 2.27k | next_next_block_row = next_block_row; |
572 | | |
573 | | /* We fetch the surrounding DC values using a sliding-register approach. |
574 | | * Initialize all 25 here so as to do the right thing on narrow pics. |
575 | | */ |
576 | 933k | DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0]; |
577 | 933k | DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0]; |
578 | 933k | DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0]; |
579 | 933k | DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0]; |
580 | 933k | DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0]; |
581 | 933k | output_col = 0; |
582 | 933k | last_block_column = compptr->width_in_blocks - 1; |
583 | 933k | for (block_num = cinfo->master->first_MCU_col[ci]; |
584 | 8.81M | block_num <= cinfo->master->last_MCU_col[ci]; block_num++) { |
585 | | /* Fetch current DCT block into workspace so we can modify it. */ |
586 | 7.88M | jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1); |
587 | | /* Update DC values */ |
588 | 7.88M | if (block_num == cinfo->master->first_MCU_col[ci] && |
589 | 933k | block_num < last_block_column) { |
590 | 476k | DC04 = DC05 = (int)prev_prev_block_row[1][0]; |
591 | 476k | DC09 = DC10 = (int)prev_block_row[1][0]; |
592 | 476k | DC14 = DC15 = (int)buffer_ptr[1][0]; |
593 | 476k | DC19 = DC20 = (int)next_block_row[1][0]; |
594 | 476k | DC24 = DC25 = (int)next_next_block_row[1][0]; |
595 | 476k | } |
596 | 7.88M | if (block_num + 1 < last_block_column) { |
597 | 6.47M | DC05 = (int)prev_prev_block_row[2][0]; |
598 | 6.47M | DC10 = (int)prev_block_row[2][0]; |
599 | 6.47M | DC15 = (int)buffer_ptr[2][0]; |
600 | 6.47M | DC20 = (int)next_block_row[2][0]; |
601 | 6.47M | DC25 = (int)next_next_block_row[2][0]; |
602 | 6.47M | } |
603 | | /* If DC interpolation is enabled, compute coefficient estimates using |
604 | | * a Gaussian-like kernel, keeping the averages of the DC values. |
605 | | * |
606 | | * If DC interpolation is disabled, compute coefficient estimates using |
607 | | * an algorithm similar to the one described in Section K.8 of the JPEG |
608 | | * standard, except applied to a 5x5 window rather than a 3x3 window. |
609 | | * |
610 | | * An estimate is applied only if the coefficient is still zero and is |
611 | | * not known to be fully accurate. |
612 | | */ |
613 | | /* AC01 */ |
614 | 7.88M | if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) { |
615 | 7.45M | num = Q00 * (change_dc ? |
616 | 5.24M | (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 - |
617 | 5.24M | 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 + |
618 | 5.24M | 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 - |
619 | 5.24M | DC21 - DC22 + DC24 + DC25) : |
620 | 7.45M | (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15)); |
621 | 7.45M | if (num >= 0) { |
622 | 5.67M | pred = (int)(((Q01 << 7) + num) / (Q01 << 8)); |
623 | 5.67M | if (Al > 0 && pred >= (1 << Al)) |
624 | 518k | pred = (1 << Al) - 1; |
625 | 5.67M | } else { |
626 | 1.77M | pred = (int)(((Q01 << 7) - num) / (Q01 << 8)); |
627 | 1.77M | if (Al > 0 && pred >= (1 << Al)) |
628 | 427k | pred = (1 << Al) - 1; |
629 | 1.77M | pred = -pred; |
630 | 1.77M | } |
631 | 7.45M | workspace[1] = (JCOEF)pred; |
632 | 7.45M | } |
633 | | /* AC10 */ |
634 | 7.88M | if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) { |
635 | 7.46M | num = Q00 * (change_dc ? |
636 | 5.24M | (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 + |
637 | 5.24M | 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 - |
638 | 5.24M | 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 + |
639 | 5.24M | 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) : |
640 | 7.46M | (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23)); |
641 | 7.46M | if (num >= 0) { |
642 | 5.33M | pred = (int)(((Q10 << 7) + num) / (Q10 << 8)); |
643 | 5.33M | if (Al > 0 && pred >= (1 << Al)) |
644 | 589k | pred = (1 << Al) - 1; |
645 | 5.33M | } else { |
646 | 2.12M | pred = (int)(((Q10 << 7) - num) / (Q10 << 8)); |
647 | 2.12M | if (Al > 0 && pred >= (1 << Al)) |
648 | 565k | pred = (1 << Al) - 1; |
649 | 2.12M | pred = -pred; |
650 | 2.12M | } |
651 | 7.46M | workspace[8] = (JCOEF)pred; |
652 | 7.46M | } |
653 | | /* AC20 */ |
654 | 7.88M | if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) { |
655 | 7.47M | num = Q00 * (change_dc ? |
656 | 5.24M | (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 - |
657 | 5.24M | 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) : |
658 | 7.47M | (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23)); |
659 | 7.47M | if (num >= 0) { |
660 | 4.70M | pred = (int)(((Q20 << 7) + num) / (Q20 << 8)); |
661 | 4.70M | if (Al > 0 && pred >= (1 << Al)) |
662 | 587k | pred = (1 << Al) - 1; |
663 | 4.70M | } else { |
664 | 2.77M | pred = (int)(((Q20 << 7) - num) / (Q20 << 8)); |
665 | 2.77M | if (Al > 0 && pred >= (1 << Al)) |
666 | 596k | pred = (1 << Al) - 1; |
667 | 2.77M | pred = -pred; |
668 | 2.77M | } |
669 | 7.47M | workspace[16] = (JCOEF)pred; |
670 | 7.47M | } |
671 | | /* AC11 */ |
672 | 7.88M | if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) { |
673 | 7.51M | num = Q00 * (change_dc ? |
674 | 5.24M | (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 + |
675 | 5.24M | 9 * DC19 + DC21 - DC25) : |
676 | 7.51M | (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 - |
677 | 2.26M | DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09)); |
678 | 7.51M | if (num >= 0) { |
679 | 5.99M | pred = (int)(((Q11 << 7) + num) / (Q11 << 8)); |
680 | 5.99M | if (Al > 0 && pred >= (1 << Al)) |
681 | 275k | pred = (1 << Al) - 1; |
682 | 5.99M | } else { |
683 | 1.51M | pred = (int)(((Q11 << 7) - num) / (Q11 << 8)); |
684 | 1.51M | if (Al > 0 && pred >= (1 << Al)) |
685 | 275k | pred = (1 << Al) - 1; |
686 | 1.51M | pred = -pred; |
687 | 1.51M | } |
688 | 7.51M | workspace[9] = (JCOEF)pred; |
689 | 7.51M | } |
690 | | /* AC02 */ |
691 | 7.88M | if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) { |
692 | 7.52M | num = Q00 * (change_dc ? |
693 | 5.24M | (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 + |
694 | 5.24M | 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) : |
695 | 7.52M | (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15)); |
696 | 7.52M | if (num >= 0) { |
697 | 4.75M | pred = (int)(((Q02 << 7) + num) / (Q02 << 8)); |
698 | 4.75M | if (Al > 0 && pred >= (1 << Al)) |
699 | 380k | pred = (1 << Al) - 1; |
700 | 4.75M | } else { |
701 | 2.76M | pred = (int)(((Q02 << 7) - num) / (Q02 << 8)); |
702 | 2.76M | if (Al > 0 && pred >= (1 << Al)) |
703 | 397k | pred = (1 << Al) - 1; |
704 | 2.76M | pred = -pred; |
705 | 2.76M | } |
706 | 7.52M | workspace[2] = (JCOEF)pred; |
707 | 7.52M | } |
708 | 7.88M | if (change_dc) { |
709 | | /* AC03 */ |
710 | 5.24M | if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) { |
711 | 5.24M | num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19); |
712 | 5.24M | if (num >= 0) { |
713 | 4.27M | pred = (int)(((Q03 << 7) + num) / (Q03 << 8)); |
714 | 4.27M | if (Al > 0 && pred >= (1 << Al)) |
715 | 0 | pred = (1 << Al) - 1; |
716 | 4.27M | } else { |
717 | 963k | pred = (int)(((Q03 << 7) - num) / (Q03 << 8)); |
718 | 963k | if (Al > 0 && pred >= (1 << Al)) |
719 | 0 | pred = (1 << Al) - 1; |
720 | 963k | pred = -pred; |
721 | 963k | } |
722 | 5.24M | workspace[3] = (JCOEF)pred; |
723 | 5.24M | } |
724 | | /* AC12 */ |
725 | 5.24M | if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) { |
726 | 5.24M | num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19); |
727 | 5.24M | if (num >= 0) { |
728 | 3.27M | pred = (int)(((Q12 << 7) + num) / (Q12 << 8)); |
729 | 3.27M | if (Al > 0 && pred >= (1 << Al)) |
730 | 0 | pred = (1 << Al) - 1; |
731 | 3.27M | } else { |
732 | 1.96M | pred = (int)(((Q12 << 7) - num) / (Q12 << 8)); |
733 | 1.96M | if (Al > 0 && pred >= (1 << Al)) |
734 | 0 | pred = (1 << Al) - 1; |
735 | 1.96M | pred = -pred; |
736 | 1.96M | } |
737 | 5.24M | workspace[10] = (JCOEF)pred; |
738 | 5.24M | } |
739 | | /* AC21 */ |
740 | 5.24M | if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) { |
741 | 5.24M | num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19); |
742 | 5.24M | if (num >= 0) { |
743 | 2.97M | pred = (int)(((Q21 << 7) + num) / (Q21 << 8)); |
744 | 2.97M | if (Al > 0 && pred >= (1 << Al)) |
745 | 0 | pred = (1 << Al) - 1; |
746 | 2.97M | } else { |
747 | 2.26M | pred = (int)(((Q21 << 7) - num) / (Q21 << 8)); |
748 | 2.26M | if (Al > 0 && pred >= (1 << Al)) |
749 | 0 | pred = (1 << Al) - 1; |
750 | 2.26M | pred = -pred; |
751 | 2.26M | } |
752 | 5.24M | workspace[17] = (JCOEF)pred; |
753 | 5.24M | } |
754 | | /* AC30 */ |
755 | 5.24M | if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) { |
756 | 5.24M | num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19); |
757 | 5.24M | if (num >= 0) { |
758 | 3.99M | pred = (int)(((Q30 << 7) + num) / (Q30 << 8)); |
759 | 3.99M | if (Al > 0 && pred >= (1 << Al)) |
760 | 0 | pred = (1 << Al) - 1; |
761 | 3.99M | } else { |
762 | 1.24M | pred = (int)(((Q30 << 7) - num) / (Q30 << 8)); |
763 | 1.24M | if (Al > 0 && pred >= (1 << Al)) |
764 | 0 | pred = (1 << Al) - 1; |
765 | 1.24M | pred = -pred; |
766 | 1.24M | } |
767 | 5.24M | workspace[24] = (JCOEF)pred; |
768 | 5.24M | } |
769 | | /* coef_bits[0] is non-negative. Otherwise this function would not |
770 | | * be called. |
771 | | */ |
772 | 5.24M | num = Q00 * |
773 | 5.24M | (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 - |
774 | 5.24M | 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 - |
775 | 5.24M | 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 - |
776 | 5.24M | 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 - |
777 | 5.24M | 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25); |
778 | 5.24M | if (num >= 0) { |
779 | 3.37M | pred = (int)(((Q00 << 7) + num) / (Q00 << 8)); |
780 | 3.37M | } else { |
781 | 1.87M | pred = (int)(((Q00 << 7) - num) / (Q00 << 8)); |
782 | 1.87M | pred = -pred; |
783 | 1.87M | } |
784 | 5.24M | workspace[0] = (JCOEF)pred; |
785 | 5.24M | } /* change_dc */ |
786 | | |
787 | | /* OK, do the IDCT */ |
788 | 7.88M | (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr, |
789 | 7.88M | output_col); |
790 | | /* Advance for next column */ |
791 | 7.88M | DC01 = DC02; DC02 = DC03; DC03 = DC04; DC04 = DC05; |
792 | 7.88M | DC06 = DC07; DC07 = DC08; DC08 = DC09; DC09 = DC10; |
793 | 7.88M | DC11 = DC12; DC12 = DC13; DC13 = DC14; DC14 = DC15; |
794 | 7.88M | DC16 = DC17; DC17 = DC18; DC18 = DC19; DC19 = DC20; |
795 | 7.88M | DC21 = DC22; DC22 = DC23; DC23 = DC24; DC24 = DC25; |
796 | 7.88M | buffer_ptr++, prev_block_row++, next_block_row++, |
797 | 7.88M | prev_prev_block_row++, next_next_block_row++; |
798 | 7.88M | output_col += compptr->_DCT_scaled_size; |
799 | 7.88M | } |
800 | 933k | output_ptr += compptr->_DCT_scaled_size; |
801 | 933k | } |
802 | 621k | } |
803 | | |
804 | 415k | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) |
805 | 414k | return JPEG_ROW_COMPLETED; |
806 | 1.06k | return JPEG_SCAN_COMPLETED; |
807 | 415k | } jdcoefct-8.c:decompress_smooth_data Line | Count | Source | 430 | 191k | { | 431 | 191k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 432 | 191k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 433 | 191k | JDIMENSION block_num, last_block_column; | 434 | 191k | int ci, block_row, block_rows, access_rows, image_block_row, | 435 | 191k | image_block_rows; | 436 | 191k | JBLOCKARRAY buffer; | 437 | 191k | JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row; | 438 | 191k | JBLOCKROW next_block_row, next_next_block_row; | 439 | 191k | _JSAMPARRAY output_ptr; | 440 | 191k | JDIMENSION output_col; | 441 | 191k | jpeg_component_info *compptr; | 442 | 191k | _inverse_DCT_method_ptr inverse_DCT; | 443 | 191k | boolean change_dc; | 444 | 191k | JCOEF *workspace; | 445 | 191k | int *coef_bits; | 446 | 191k | JQUANT_TBL *quanttbl; | 447 | 191k | JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num; | 448 | 191k | int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12, | 449 | 191k | DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24, | 450 | 191k | DC25; | 451 | 191k | int Al, pred; | 452 | | | 453 | | /* Keep a local variable to avoid looking it up more than once */ | 454 | 191k | workspace = coef->workspace; | 455 | | | 456 | | /* Force some input to be done if we are getting ahead of the input. */ | 457 | 191k | while (cinfo->input_scan_number <= cinfo->output_scan_number && | 458 | 191k | !cinfo->inputctl->eoi_reached) { | 459 | 0 | if (cinfo->input_scan_number == cinfo->output_scan_number) { | 460 | | /* If input is working on current scan, we ordinarily want it to | 461 | | * have completed the current row. But if input scan is DC, | 462 | | * we want it to keep two rows ahead so that next two block rows' DC | 463 | | * values are up to date. | 464 | | */ | 465 | 0 | JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0; | 466 | 0 | if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta) | 467 | 0 | break; | 468 | 0 | } | 469 | 0 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) | 470 | 0 | return JPEG_SUSPENDED; | 471 | 0 | } | 472 | | | 473 | | /* OK, output from the virtual arrays. */ | 474 | 492k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 475 | 300k | ci++, compptr++) { | 476 | | /* Don't bother to IDCT an uninteresting component. */ | 477 | 300k | if (!compptr->component_needed) | 478 | 3.60k | continue; | 479 | | /* Count non-dummy DCT block rows in this iMCU row. */ | 480 | 296k | if (cinfo->output_iMCU_row + 1 < last_iMCU_row) { | 481 | 295k | block_rows = compptr->v_samp_factor; | 482 | 295k | access_rows = block_rows * 3; /* this and next two iMCU rows */ | 483 | 295k | } else if (cinfo->output_iMCU_row < last_iMCU_row) { | 484 | 545 | block_rows = compptr->v_samp_factor; | 485 | 545 | access_rows = block_rows * 2; /* this and next iMCU row */ | 486 | 638 | } else { | 487 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ | 488 | 638 | block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); | 489 | 638 | if (block_rows == 0) block_rows = compptr->v_samp_factor; | 490 | 638 | access_rows = block_rows; /* this iMCU row only */ | 491 | 638 | } | 492 | | /* Align the virtual buffer for this component. */ | 493 | 296k | if (cinfo->output_iMCU_row > 1) { | 494 | 295k | access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */ | 495 | 295k | buffer = (*cinfo->mem->access_virt_barray) | 496 | 295k | ((j_common_ptr)cinfo, coef->whole_image[ci], | 497 | 295k | (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor, | 498 | 295k | (JDIMENSION)access_rows, FALSE); | 499 | 295k | buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */ | 500 | 295k | } else if (cinfo->output_iMCU_row > 0) { | 501 | 545 | access_rows += compptr->v_samp_factor; /* prior iMCU row too */ | 502 | 545 | buffer = (*cinfo->mem->access_virt_barray) | 503 | 545 | ((j_common_ptr)cinfo, coef->whole_image[ci], | 504 | 545 | (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor, | 505 | 545 | (JDIMENSION)access_rows, FALSE); | 506 | 545 | buffer += compptr->v_samp_factor; /* point to current iMCU row */ | 507 | 638 | } else { | 508 | 638 | buffer = (*cinfo->mem->access_virt_barray) | 509 | 638 | ((j_common_ptr)cinfo, coef->whole_image[ci], | 510 | 638 | (JDIMENSION)0, (JDIMENSION)access_rows, FALSE); | 511 | 638 | } | 512 | | /* Fetch component-dependent info. | 513 | | * If the current scan is incomplete, then we use the component-dependent | 514 | | * info from the previous scan. | 515 | | */ | 516 | 296k | if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row) | 517 | 174k | coef_bits = | 518 | 174k | coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS); | 519 | 122k | else | 520 | 122k | coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS); | 521 | | | 522 | | /* We only do DC interpolation if no AC coefficient data is available. */ | 523 | 296k | change_dc = | 524 | 296k | coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 && | 525 | 249k | coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 && | 526 | 243k | coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1; | 527 | | | 528 | 296k | quanttbl = compptr->quant_table; | 529 | 296k | Q00 = quanttbl->quantval[0]; | 530 | 296k | Q01 = quanttbl->quantval[Q01_POS]; | 531 | 296k | Q10 = quanttbl->quantval[Q10_POS]; | 532 | 296k | Q20 = quanttbl->quantval[Q20_POS]; | 533 | 296k | Q11 = quanttbl->quantval[Q11_POS]; | 534 | 296k | Q02 = quanttbl->quantval[Q02_POS]; | 535 | 296k | if (change_dc) { | 536 | 240k | Q03 = quanttbl->quantval[Q03_POS]; | 537 | 240k | Q12 = quanttbl->quantval[Q12_POS]; | 538 | 240k | Q21 = quanttbl->quantval[Q21_POS]; | 539 | 240k | Q30 = quanttbl->quantval[Q30_POS]; | 540 | 240k | } | 541 | 296k | inverse_DCT = cinfo->idct->_inverse_DCT[ci]; | 542 | 296k | output_ptr = output_buf[ci]; | 543 | | /* Loop over all DCT blocks to be processed. */ | 544 | 296k | image_block_rows = block_rows * cinfo->total_iMCU_rows; | 545 | 742k | for (block_row = 0; block_row < block_rows; block_row++) { | 546 | 445k | image_block_row = cinfo->output_iMCU_row * block_rows + block_row; | 547 | 445k | buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci]; | 548 | | | 549 | 445k | if (image_block_row > 0) | 550 | 445k | prev_block_row = | 551 | 445k | buffer[block_row - 1] + cinfo->master->first_MCU_col[ci]; | 552 | 638 | else | 553 | 638 | prev_block_row = buffer_ptr; | 554 | | | 555 | 445k | if (image_block_row > 1) | 556 | 444k | prev_prev_block_row = | 557 | 444k | buffer[block_row - 2] + cinfo->master->first_MCU_col[ci]; | 558 | 1.23k | else | 559 | 1.23k | prev_prev_block_row = prev_block_row; | 560 | | | 561 | 445k | if (image_block_row < image_block_rows - 1) | 562 | 445k | next_block_row = | 563 | 445k | buffer[block_row + 1] + cinfo->master->first_MCU_col[ci]; | 564 | 638 | else | 565 | 638 | next_block_row = buffer_ptr; | 566 | | | 567 | 445k | if (image_block_row < image_block_rows - 2) | 568 | 444k | next_next_block_row = | 569 | 444k | buffer[block_row + 2] + cinfo->master->first_MCU_col[ci]; | 570 | 1.09k | else | 571 | 1.09k | next_next_block_row = next_block_row; | 572 | | | 573 | | /* We fetch the surrounding DC values using a sliding-register approach. | 574 | | * Initialize all 25 here so as to do the right thing on narrow pics. | 575 | | */ | 576 | 445k | DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0]; | 577 | 445k | DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0]; | 578 | 445k | DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0]; | 579 | 445k | DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0]; | 580 | 445k | DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0]; | 581 | 445k | output_col = 0; | 582 | 445k | last_block_column = compptr->width_in_blocks - 1; | 583 | 445k | for (block_num = cinfo->master->first_MCU_col[ci]; | 584 | 4.39M | block_num <= cinfo->master->last_MCU_col[ci]; block_num++) { | 585 | | /* Fetch current DCT block into workspace so we can modify it. */ | 586 | 3.94M | jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1); | 587 | | /* Update DC values */ | 588 | 3.94M | if (block_num == cinfo->master->first_MCU_col[ci] && | 589 | 445k | block_num < last_block_column) { | 590 | 225k | DC04 = DC05 = (int)prev_prev_block_row[1][0]; | 591 | 225k | DC09 = DC10 = (int)prev_block_row[1][0]; | 592 | 225k | DC14 = DC15 = (int)buffer_ptr[1][0]; | 593 | 225k | DC19 = DC20 = (int)next_block_row[1][0]; | 594 | 225k | DC24 = DC25 = (int)next_next_block_row[1][0]; | 595 | 225k | } | 596 | 3.94M | if (block_num + 1 < last_block_column) { | 597 | 3.27M | DC05 = (int)prev_prev_block_row[2][0]; | 598 | 3.27M | DC10 = (int)prev_block_row[2][0]; | 599 | 3.27M | DC15 = (int)buffer_ptr[2][0]; | 600 | 3.27M | DC20 = (int)next_block_row[2][0]; | 601 | 3.27M | DC25 = (int)next_next_block_row[2][0]; | 602 | 3.27M | } | 603 | | /* If DC interpolation is enabled, compute coefficient estimates using | 604 | | * a Gaussian-like kernel, keeping the averages of the DC values. | 605 | | * | 606 | | * If DC interpolation is disabled, compute coefficient estimates using | 607 | | * an algorithm similar to the one described in Section K.8 of the JPEG | 608 | | * standard, except applied to a 5x5 window rather than a 3x3 window. | 609 | | * | 610 | | * An estimate is applied only if the coefficient is still zero and is | 611 | | * not known to be fully accurate. | 612 | | */ | 613 | | /* AC01 */ | 614 | 3.94M | if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) { | 615 | 3.79M | num = Q00 * (change_dc ? | 616 | 2.68M | (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 - | 617 | 2.68M | 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 + | 618 | 2.68M | 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 - | 619 | 2.68M | DC21 - DC22 + DC24 + DC25) : | 620 | 3.79M | (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15)); | 621 | 3.79M | if (num >= 0) { | 622 | 2.93M | pred = (int)(((Q01 << 7) + num) / (Q01 << 8)); | 623 | 2.93M | if (Al > 0 && pred >= (1 << Al)) | 624 | 307k | pred = (1 << Al) - 1; | 625 | 2.93M | } else { | 626 | 860k | pred = (int)(((Q01 << 7) - num) / (Q01 << 8)); | 627 | 860k | if (Al > 0 && pred >= (1 << Al)) | 628 | 197k | pred = (1 << Al) - 1; | 629 | 860k | pred = -pred; | 630 | 860k | } | 631 | 3.79M | workspace[1] = (JCOEF)pred; | 632 | 3.79M | } | 633 | | /* AC10 */ | 634 | 3.94M | if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) { | 635 | 3.77M | num = Q00 * (change_dc ? | 636 | 2.68M | (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 + | 637 | 2.68M | 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 - | 638 | 2.68M | 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 + | 639 | 2.68M | 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) : | 640 | 3.77M | (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23)); | 641 | 3.77M | if (num >= 0) { | 642 | 2.67M | pred = (int)(((Q10 << 7) + num) / (Q10 << 8)); | 643 | 2.67M | if (Al > 0 && pred >= (1 << Al)) | 644 | 296k | pred = (1 << Al) - 1; | 645 | 2.67M | } else { | 646 | 1.10M | pred = (int)(((Q10 << 7) - num) / (Q10 << 8)); | 647 | 1.10M | if (Al > 0 && pred >= (1 << Al)) | 648 | 281k | pred = (1 << Al) - 1; | 649 | 1.10M | pred = -pred; | 650 | 1.10M | } | 651 | 3.77M | workspace[8] = (JCOEF)pred; | 652 | 3.77M | } | 653 | | /* AC20 */ | 654 | 3.94M | if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) { | 655 | 3.76M | num = Q00 * (change_dc ? | 656 | 2.68M | (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 - | 657 | 2.68M | 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) : | 658 | 3.76M | (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23)); | 659 | 3.76M | if (num >= 0) { | 660 | 2.48M | pred = (int)(((Q20 << 7) + num) / (Q20 << 8)); | 661 | 2.48M | if (Al > 0 && pred >= (1 << Al)) | 662 | 260k | pred = (1 << Al) - 1; | 663 | 2.48M | } else { | 664 | 1.28M | pred = (int)(((Q20 << 7) - num) / (Q20 << 8)); | 665 | 1.28M | if (Al > 0 && pred >= (1 << Al)) | 666 | 259k | pred = (1 << Al) - 1; | 667 | 1.28M | pred = -pred; | 668 | 1.28M | } | 669 | 3.76M | workspace[16] = (JCOEF)pred; | 670 | 3.76M | } | 671 | | /* AC11 */ | 672 | 3.94M | if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) { | 673 | 3.77M | num = Q00 * (change_dc ? | 674 | 2.68M | (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 + | 675 | 2.68M | 9 * DC19 + DC21 - DC25) : | 676 | 3.77M | (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 - | 677 | 1.09M | DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09)); | 678 | 3.77M | if (num >= 0) { | 679 | 3.07M | pred = (int)(((Q11 << 7) + num) / (Q11 << 8)); | 680 | 3.07M | if (Al > 0 && pred >= (1 << Al)) | 681 | 145k | pred = (1 << Al) - 1; | 682 | 3.07M | } else { | 683 | 708k | pred = (int)(((Q11 << 7) - num) / (Q11 << 8)); | 684 | 708k | if (Al > 0 && pred >= (1 << Al)) | 685 | 148k | pred = (1 << Al) - 1; | 686 | 708k | pred = -pred; | 687 | 708k | } | 688 | 3.77M | workspace[9] = (JCOEF)pred; | 689 | 3.77M | } | 690 | | /* AC02 */ | 691 | 3.94M | if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) { | 692 | 3.79M | num = Q00 * (change_dc ? | 693 | 2.68M | (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 + | 694 | 2.68M | 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) : | 695 | 3.79M | (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15)); | 696 | 3.79M | if (num >= 0) { | 697 | 2.48M | pred = (int)(((Q02 << 7) + num) / (Q02 << 8)); | 698 | 2.48M | if (Al > 0 && pred >= (1 << Al)) | 699 | 178k | pred = (1 << Al) - 1; | 700 | 2.48M | } else { | 701 | 1.30M | pred = (int)(((Q02 << 7) - num) / (Q02 << 8)); | 702 | 1.30M | if (Al > 0 && pred >= (1 << Al)) | 703 | 191k | pred = (1 << Al) - 1; | 704 | 1.30M | pred = -pred; | 705 | 1.30M | } | 706 | 3.79M | workspace[2] = (JCOEF)pred; | 707 | 3.79M | } | 708 | 3.94M | if (change_dc) { | 709 | | /* AC03 */ | 710 | 2.68M | if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) { | 711 | 2.68M | num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19); | 712 | 2.68M | if (num >= 0) { | 713 | 2.21M | pred = (int)(((Q03 << 7) + num) / (Q03 << 8)); | 714 | 2.21M | if (Al > 0 && pred >= (1 << Al)) | 715 | 0 | pred = (1 << Al) - 1; | 716 | 2.21M | } else { | 717 | 479k | pred = (int)(((Q03 << 7) - num) / (Q03 << 8)); | 718 | 479k | if (Al > 0 && pred >= (1 << Al)) | 719 | 0 | pred = (1 << Al) - 1; | 720 | 479k | pred = -pred; | 721 | 479k | } | 722 | 2.68M | workspace[3] = (JCOEF)pred; | 723 | 2.68M | } | 724 | | /* AC12 */ | 725 | 2.68M | if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) { | 726 | 2.68M | num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19); | 727 | 2.68M | if (num >= 0) { | 728 | 1.87M | pred = (int)(((Q12 << 7) + num) / (Q12 << 8)); | 729 | 1.87M | if (Al > 0 && pred >= (1 << Al)) | 730 | 0 | pred = (1 << Al) - 1; | 731 | 1.87M | } else { | 732 | 816k | pred = (int)(((Q12 << 7) - num) / (Q12 << 8)); | 733 | 816k | if (Al > 0 && pred >= (1 << Al)) | 734 | 0 | pred = (1 << Al) - 1; | 735 | 816k | pred = -pred; | 736 | 816k | } | 737 | 2.68M | workspace[10] = (JCOEF)pred; | 738 | 2.68M | } | 739 | | /* AC21 */ | 740 | 2.68M | if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) { | 741 | 2.68M | num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19); | 742 | 2.68M | if (num >= 0) { | 743 | 1.68M | pred = (int)(((Q21 << 7) + num) / (Q21 << 8)); | 744 | 1.68M | if (Al > 0 && pred >= (1 << Al)) | 745 | 0 | pred = (1 << Al) - 1; | 746 | 1.68M | } else { | 747 | 1.00M | pred = (int)(((Q21 << 7) - num) / (Q21 << 8)); | 748 | 1.00M | if (Al > 0 && pred >= (1 << Al)) | 749 | 0 | pred = (1 << Al) - 1; | 750 | 1.00M | pred = -pred; | 751 | 1.00M | } | 752 | 2.68M | workspace[17] = (JCOEF)pred; | 753 | 2.68M | } | 754 | | /* AC30 */ | 755 | 2.68M | if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) { | 756 | 2.68M | num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19); | 757 | 2.68M | if (num >= 0) { | 758 | 2.00M | pred = (int)(((Q30 << 7) + num) / (Q30 << 8)); | 759 | 2.00M | if (Al > 0 && pred >= (1 << Al)) | 760 | 0 | pred = (1 << Al) - 1; | 761 | 2.00M | } else { | 762 | 682k | pred = (int)(((Q30 << 7) - num) / (Q30 << 8)); | 763 | 682k | if (Al > 0 && pred >= (1 << Al)) | 764 | 0 | pred = (1 << Al) - 1; | 765 | 682k | pred = -pred; | 766 | 682k | } | 767 | 2.68M | workspace[24] = (JCOEF)pred; | 768 | 2.68M | } | 769 | | /* coef_bits[0] is non-negative. Otherwise this function would not | 770 | | * be called. | 771 | | */ | 772 | 2.68M | num = Q00 * | 773 | 2.68M | (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 - | 774 | 2.68M | 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 - | 775 | 2.68M | 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 - | 776 | 2.68M | 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 - | 777 | 2.68M | 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25); | 778 | 2.68M | if (num >= 0) { | 779 | 1.95M | pred = (int)(((Q00 << 7) + num) / (Q00 << 8)); | 780 | 1.95M | } else { | 781 | 736k | pred = (int)(((Q00 << 7) - num) / (Q00 << 8)); | 782 | 736k | pred = -pred; | 783 | 736k | } | 784 | 2.68M | workspace[0] = (JCOEF)pred; | 785 | 2.68M | } /* change_dc */ | 786 | | | 787 | | /* OK, do the IDCT */ | 788 | 3.94M | (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr, | 789 | 3.94M | output_col); | 790 | | /* Advance for next column */ | 791 | 3.94M | DC01 = DC02; DC02 = DC03; DC03 = DC04; DC04 = DC05; | 792 | 3.94M | DC06 = DC07; DC07 = DC08; DC08 = DC09; DC09 = DC10; | 793 | 3.94M | DC11 = DC12; DC12 = DC13; DC13 = DC14; DC14 = DC15; | 794 | 3.94M | DC16 = DC17; DC17 = DC18; DC18 = DC19; DC19 = DC20; | 795 | 3.94M | DC21 = DC22; DC22 = DC23; DC23 = DC24; DC24 = DC25; | 796 | 3.94M | buffer_ptr++, prev_block_row++, next_block_row++, | 797 | 3.94M | prev_prev_block_row++, next_next_block_row++; | 798 | 3.94M | output_col += compptr->_DCT_scaled_size; | 799 | 3.94M | } | 800 | 445k | output_ptr += compptr->_DCT_scaled_size; | 801 | 445k | } | 802 | 296k | } | 803 | | | 804 | 191k | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) | 805 | 191k | return JPEG_ROW_COMPLETED; | 806 | 492 | return JPEG_SCAN_COMPLETED; | 807 | 191k | } |
jdcoefct-12.c:decompress_smooth_data Line | Count | Source | 430 | 223k | { | 431 | 223k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 432 | 223k | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 433 | 223k | JDIMENSION block_num, last_block_column; | 434 | 223k | int ci, block_row, block_rows, access_rows, image_block_row, | 435 | 223k | image_block_rows; | 436 | 223k | JBLOCKARRAY buffer; | 437 | 223k | JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row; | 438 | 223k | JBLOCKROW next_block_row, next_next_block_row; | 439 | 223k | _JSAMPARRAY output_ptr; | 440 | 223k | JDIMENSION output_col; | 441 | 223k | jpeg_component_info *compptr; | 442 | 223k | _inverse_DCT_method_ptr inverse_DCT; | 443 | 223k | boolean change_dc; | 444 | 223k | JCOEF *workspace; | 445 | 223k | int *coef_bits; | 446 | 223k | JQUANT_TBL *quanttbl; | 447 | 223k | JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num; | 448 | 223k | int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12, | 449 | 223k | DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24, | 450 | 223k | DC25; | 451 | 223k | int Al, pred; | 452 | | | 453 | | /* Keep a local variable to avoid looking it up more than once */ | 454 | 223k | workspace = coef->workspace; | 455 | | | 456 | | /* Force some input to be done if we are getting ahead of the input. */ | 457 | 223k | while (cinfo->input_scan_number <= cinfo->output_scan_number && | 458 | 223k | !cinfo->inputctl->eoi_reached) { | 459 | 0 | if (cinfo->input_scan_number == cinfo->output_scan_number) { | 460 | | /* If input is working on current scan, we ordinarily want it to | 461 | | * have completed the current row. But if input scan is DC, | 462 | | * we want it to keep two rows ahead so that next two block rows' DC | 463 | | * values are up to date. | 464 | | */ | 465 | 0 | JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0; | 466 | 0 | if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta) | 467 | 0 | break; | 468 | 0 | } | 469 | 0 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) | 470 | 0 | return JPEG_SUSPENDED; | 471 | 0 | } | 472 | | | 473 | | /* OK, output from the virtual arrays. */ | 474 | 550k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 475 | 327k | ci++, compptr++) { | 476 | | /* Don't bother to IDCT an uninteresting component. */ | 477 | 327k | if (!compptr->component_needed) | 478 | 2.86k | continue; | 479 | | /* Count non-dummy DCT block rows in this iMCU row. */ | 480 | 324k | if (cinfo->output_iMCU_row + 1 < last_iMCU_row) { | 481 | 322k | block_rows = compptr->v_samp_factor; | 482 | 322k | access_rows = block_rows * 3; /* this and next two iMCU rows */ | 483 | 322k | } else if (cinfo->output_iMCU_row < last_iMCU_row) { | 484 | 654 | block_rows = compptr->v_samp_factor; | 485 | 654 | access_rows = block_rows * 2; /* this and next iMCU row */ | 486 | 715 | } else { | 487 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ | 488 | 715 | block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); | 489 | 715 | if (block_rows == 0) block_rows = compptr->v_samp_factor; | 490 | 715 | access_rows = block_rows; /* this iMCU row only */ | 491 | 715 | } | 492 | | /* Align the virtual buffer for this component. */ | 493 | 324k | if (cinfo->output_iMCU_row > 1) { | 494 | 322k | access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */ | 495 | 322k | buffer = (*cinfo->mem->access_virt_barray) | 496 | 322k | ((j_common_ptr)cinfo, coef->whole_image[ci], | 497 | 322k | (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor, | 498 | 322k | (JDIMENSION)access_rows, FALSE); | 499 | 322k | buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */ | 500 | 322k | } else if (cinfo->output_iMCU_row > 0) { | 501 | 654 | access_rows += compptr->v_samp_factor; /* prior iMCU row too */ | 502 | 654 | buffer = (*cinfo->mem->access_virt_barray) | 503 | 654 | ((j_common_ptr)cinfo, coef->whole_image[ci], | 504 | 654 | (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor, | 505 | 654 | (JDIMENSION)access_rows, FALSE); | 506 | 654 | buffer += compptr->v_samp_factor; /* point to current iMCU row */ | 507 | 715 | } else { | 508 | 715 | buffer = (*cinfo->mem->access_virt_barray) | 509 | 715 | ((j_common_ptr)cinfo, coef->whole_image[ci], | 510 | 715 | (JDIMENSION)0, (JDIMENSION)access_rows, FALSE); | 511 | 715 | } | 512 | | /* Fetch component-dependent info. | 513 | | * If the current scan is incomplete, then we use the component-dependent | 514 | | * info from the previous scan. | 515 | | */ | 516 | 324k | if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row) | 517 | 183k | coef_bits = | 518 | 183k | coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS); | 519 | 141k | else | 520 | 141k | coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS); | 521 | | | 522 | | /* We only do DC interpolation if no AC coefficient data is available. */ | 523 | 324k | change_dc = | 524 | 324k | coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 && | 525 | 255k | coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 && | 526 | 244k | coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1; | 527 | | | 528 | 324k | quanttbl = compptr->quant_table; | 529 | 324k | Q00 = quanttbl->quantval[0]; | 530 | 324k | Q01 = quanttbl->quantval[Q01_POS]; | 531 | 324k | Q10 = quanttbl->quantval[Q10_POS]; | 532 | 324k | Q20 = quanttbl->quantval[Q20_POS]; | 533 | 324k | Q11 = quanttbl->quantval[Q11_POS]; | 534 | 324k | Q02 = quanttbl->quantval[Q02_POS]; | 535 | 324k | if (change_dc) { | 536 | 235k | Q03 = quanttbl->quantval[Q03_POS]; | 537 | 235k | Q12 = quanttbl->quantval[Q12_POS]; | 538 | 235k | Q21 = quanttbl->quantval[Q21_POS]; | 539 | 235k | Q30 = quanttbl->quantval[Q30_POS]; | 540 | 235k | } | 541 | 324k | inverse_DCT = cinfo->idct->_inverse_DCT[ci]; | 542 | 324k | output_ptr = output_buf[ci]; | 543 | | /* Loop over all DCT blocks to be processed. */ | 544 | 324k | image_block_rows = block_rows * cinfo->total_iMCU_rows; | 545 | 812k | for (block_row = 0; block_row < block_rows; block_row++) { | 546 | 488k | image_block_row = cinfo->output_iMCU_row * block_rows + block_row; | 547 | 488k | buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci]; | 548 | | | 549 | 488k | if (image_block_row > 0) | 550 | 487k | prev_block_row = | 551 | 487k | buffer[block_row - 1] + cinfo->master->first_MCU_col[ci]; | 552 | 715 | else | 553 | 715 | prev_block_row = buffer_ptr; | 554 | | | 555 | 488k | if (image_block_row > 1) | 556 | 486k | prev_prev_block_row = | 557 | 486k | buffer[block_row - 2] + cinfo->master->first_MCU_col[ci]; | 558 | 1.39k | else | 559 | 1.39k | prev_prev_block_row = prev_block_row; | 560 | | | 561 | 488k | if (image_block_row < image_block_rows - 1) | 562 | 487k | next_block_row = | 563 | 487k | buffer[block_row + 1] + cinfo->master->first_MCU_col[ci]; | 564 | 715 | else | 565 | 715 | next_block_row = buffer_ptr; | 566 | | | 567 | 488k | if (image_block_row < image_block_rows - 2) | 568 | 487k | next_next_block_row = | 569 | 487k | buffer[block_row + 2] + cinfo->master->first_MCU_col[ci]; | 570 | 1.18k | else | 571 | 1.18k | next_next_block_row = next_block_row; | 572 | | | 573 | | /* We fetch the surrounding DC values using a sliding-register approach. | 574 | | * Initialize all 25 here so as to do the right thing on narrow pics. | 575 | | */ | 576 | 488k | DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0]; | 577 | 488k | DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0]; | 578 | 488k | DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0]; | 579 | 488k | DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0]; | 580 | 488k | DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0]; | 581 | 488k | output_col = 0; | 582 | 488k | last_block_column = compptr->width_in_blocks - 1; | 583 | 488k | for (block_num = cinfo->master->first_MCU_col[ci]; | 584 | 4.42M | block_num <= cinfo->master->last_MCU_col[ci]; block_num++) { | 585 | | /* Fetch current DCT block into workspace so we can modify it. */ | 586 | 3.93M | jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1); | 587 | | /* Update DC values */ | 588 | 3.93M | if (block_num == cinfo->master->first_MCU_col[ci] && | 589 | 488k | block_num < last_block_column) { | 590 | 250k | DC04 = DC05 = (int)prev_prev_block_row[1][0]; | 591 | 250k | DC09 = DC10 = (int)prev_block_row[1][0]; | 592 | 250k | DC14 = DC15 = (int)buffer_ptr[1][0]; | 593 | 250k | DC19 = DC20 = (int)next_block_row[1][0]; | 594 | 250k | DC24 = DC25 = (int)next_next_block_row[1][0]; | 595 | 250k | } | 596 | 3.93M | if (block_num + 1 < last_block_column) { | 597 | 3.19M | DC05 = (int)prev_prev_block_row[2][0]; | 598 | 3.19M | DC10 = (int)prev_block_row[2][0]; | 599 | 3.19M | DC15 = (int)buffer_ptr[2][0]; | 600 | 3.19M | DC20 = (int)next_block_row[2][0]; | 601 | 3.19M | DC25 = (int)next_next_block_row[2][0]; | 602 | 3.19M | } | 603 | | /* If DC interpolation is enabled, compute coefficient estimates using | 604 | | * a Gaussian-like kernel, keeping the averages of the DC values. | 605 | | * | 606 | | * If DC interpolation is disabled, compute coefficient estimates using | 607 | | * an algorithm similar to the one described in Section K.8 of the JPEG | 608 | | * standard, except applied to a 5x5 window rather than a 3x3 window. | 609 | | * | 610 | | * An estimate is applied only if the coefficient is still zero and is | 611 | | * not known to be fully accurate. | 612 | | */ | 613 | | /* AC01 */ | 614 | 3.93M | if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) { | 615 | 3.66M | num = Q00 * (change_dc ? | 616 | 2.55M | (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 - | 617 | 2.55M | 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 + | 618 | 2.55M | 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 - | 619 | 2.55M | DC21 - DC22 + DC24 + DC25) : | 620 | 3.66M | (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15)); | 621 | 3.66M | if (num >= 0) { | 622 | 2.74M | pred = (int)(((Q01 << 7) + num) / (Q01 << 8)); | 623 | 2.74M | if (Al > 0 && pred >= (1 << Al)) | 624 | 211k | pred = (1 << Al) - 1; | 625 | 2.74M | } else { | 626 | 911k | pred = (int)(((Q01 << 7) - num) / (Q01 << 8)); | 627 | 911k | if (Al > 0 && pred >= (1 << Al)) | 628 | 230k | pred = (1 << Al) - 1; | 629 | 911k | pred = -pred; | 630 | 911k | } | 631 | 3.66M | workspace[1] = (JCOEF)pred; | 632 | 3.66M | } | 633 | | /* AC10 */ | 634 | 3.93M | if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) { | 635 | 3.68M | num = Q00 * (change_dc ? | 636 | 2.55M | (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 + | 637 | 2.55M | 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 - | 638 | 2.55M | 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 + | 639 | 2.55M | 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) : | 640 | 3.68M | (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23)); | 641 | 3.68M | if (num >= 0) { | 642 | 2.66M | pred = (int)(((Q10 << 7) + num) / (Q10 << 8)); | 643 | 2.66M | if (Al > 0 && pred >= (1 << Al)) | 644 | 293k | pred = (1 << Al) - 1; | 645 | 2.66M | } else { | 646 | 1.02M | pred = (int)(((Q10 << 7) - num) / (Q10 << 8)); | 647 | 1.02M | if (Al > 0 && pred >= (1 << Al)) | 648 | 284k | pred = (1 << Al) - 1; | 649 | 1.02M | pred = -pred; | 650 | 1.02M | } | 651 | 3.68M | workspace[8] = (JCOEF)pred; | 652 | 3.68M | } | 653 | | /* AC20 */ | 654 | 3.93M | if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) { | 655 | 3.70M | num = Q00 * (change_dc ? | 656 | 2.55M | (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 - | 657 | 2.55M | 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) : | 658 | 3.70M | (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23)); | 659 | 3.70M | if (num >= 0) { | 660 | 2.22M | pred = (int)(((Q20 << 7) + num) / (Q20 << 8)); | 661 | 2.22M | if (Al > 0 && pred >= (1 << Al)) | 662 | 326k | pred = (1 << Al) - 1; | 663 | 2.22M | } else { | 664 | 1.48M | pred = (int)(((Q20 << 7) - num) / (Q20 << 8)); | 665 | 1.48M | if (Al > 0 && pred >= (1 << Al)) | 666 | 336k | pred = (1 << Al) - 1; | 667 | 1.48M | pred = -pred; | 668 | 1.48M | } | 669 | 3.70M | workspace[16] = (JCOEF)pred; | 670 | 3.70M | } | 671 | | /* AC11 */ | 672 | 3.93M | if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) { | 673 | 3.73M | num = Q00 * (change_dc ? | 674 | 2.55M | (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 + | 675 | 2.55M | 9 * DC19 + DC21 - DC25) : | 676 | 3.73M | (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 - | 677 | 1.17M | DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09)); | 678 | 3.73M | if (num >= 0) { | 679 | 2.92M | pred = (int)(((Q11 << 7) + num) / (Q11 << 8)); | 680 | 2.92M | if (Al > 0 && pred >= (1 << Al)) | 681 | 130k | pred = (1 << Al) - 1; | 682 | 2.92M | } else { | 683 | 807k | pred = (int)(((Q11 << 7) - num) / (Q11 << 8)); | 684 | 807k | if (Al > 0 && pred >= (1 << Al)) | 685 | 127k | pred = (1 << Al) - 1; | 686 | 807k | pred = -pred; | 687 | 807k | } | 688 | 3.73M | workspace[9] = (JCOEF)pred; | 689 | 3.73M | } | 690 | | /* AC02 */ | 691 | 3.93M | if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) { | 692 | 3.72M | num = Q00 * (change_dc ? | 693 | 2.55M | (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 + | 694 | 2.55M | 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) : | 695 | 3.72M | (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15)); | 696 | 3.72M | if (num >= 0) { | 697 | 2.26M | pred = (int)(((Q02 << 7) + num) / (Q02 << 8)); | 698 | 2.26M | if (Al > 0 && pred >= (1 << Al)) | 699 | 201k | pred = (1 << Al) - 1; | 700 | 2.26M | } else { | 701 | 1.45M | pred = (int)(((Q02 << 7) - num) / (Q02 << 8)); | 702 | 1.45M | if (Al > 0 && pred >= (1 << Al)) | 703 | 205k | pred = (1 << Al) - 1; | 704 | 1.45M | pred = -pred; | 705 | 1.45M | } | 706 | 3.72M | workspace[2] = (JCOEF)pred; | 707 | 3.72M | } | 708 | 3.93M | if (change_dc) { | 709 | | /* AC03 */ | 710 | 2.55M | if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) { | 711 | 2.55M | num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19); | 712 | 2.55M | if (num >= 0) { | 713 | 2.06M | pred = (int)(((Q03 << 7) + num) / (Q03 << 8)); | 714 | 2.06M | if (Al > 0 && pred >= (1 << Al)) | 715 | 0 | pred = (1 << Al) - 1; | 716 | 2.06M | } else { | 717 | 484k | pred = (int)(((Q03 << 7) - num) / (Q03 << 8)); | 718 | 484k | if (Al > 0 && pred >= (1 << Al)) | 719 | 0 | pred = (1 << Al) - 1; | 720 | 484k | pred = -pred; | 721 | 484k | } | 722 | 2.55M | workspace[3] = (JCOEF)pred; | 723 | 2.55M | } | 724 | | /* AC12 */ | 725 | 2.55M | if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) { | 726 | 2.55M | num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19); | 727 | 2.55M | if (num >= 0) { | 728 | 1.40M | pred = (int)(((Q12 << 7) + num) / (Q12 << 8)); | 729 | 1.40M | if (Al > 0 && pred >= (1 << Al)) | 730 | 0 | pred = (1 << Al) - 1; | 731 | 1.40M | } else { | 732 | 1.14M | pred = (int)(((Q12 << 7) - num) / (Q12 << 8)); | 733 | 1.14M | if (Al > 0 && pred >= (1 << Al)) | 734 | 0 | pred = (1 << Al) - 1; | 735 | 1.14M | pred = -pred; | 736 | 1.14M | } | 737 | 2.55M | workspace[10] = (JCOEF)pred; | 738 | 2.55M | } | 739 | | /* AC21 */ | 740 | 2.55M | if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) { | 741 | 2.55M | num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19); | 742 | 2.55M | if (num >= 0) { | 743 | 1.29M | pred = (int)(((Q21 << 7) + num) / (Q21 << 8)); | 744 | 1.29M | if (Al > 0 && pred >= (1 << Al)) | 745 | 0 | pred = (1 << Al) - 1; | 746 | 1.29M | } else { | 747 | 1.26M | pred = (int)(((Q21 << 7) - num) / (Q21 << 8)); | 748 | 1.26M | if (Al > 0 && pred >= (1 << Al)) | 749 | 0 | pred = (1 << Al) - 1; | 750 | 1.26M | pred = -pred; | 751 | 1.26M | } | 752 | 2.55M | workspace[17] = (JCOEF)pred; | 753 | 2.55M | } | 754 | | /* AC30 */ | 755 | 2.55M | if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) { | 756 | 2.55M | num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19); | 757 | 2.55M | if (num >= 0) { | 758 | 1.99M | pred = (int)(((Q30 << 7) + num) / (Q30 << 8)); | 759 | 1.99M | if (Al > 0 && pred >= (1 << Al)) | 760 | 0 | pred = (1 << Al) - 1; | 761 | 1.99M | } else { | 762 | 562k | pred = (int)(((Q30 << 7) - num) / (Q30 << 8)); | 763 | 562k | if (Al > 0 && pred >= (1 << Al)) | 764 | 0 | pred = (1 << Al) - 1; | 765 | 562k | pred = -pred; | 766 | 562k | } | 767 | 2.55M | workspace[24] = (JCOEF)pred; | 768 | 2.55M | } | 769 | | /* coef_bits[0] is non-negative. Otherwise this function would not | 770 | | * be called. | 771 | | */ | 772 | 2.55M | num = Q00 * | 773 | 2.55M | (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 - | 774 | 2.55M | 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 - | 775 | 2.55M | 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 - | 776 | 2.55M | 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 - | 777 | 2.55M | 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25); | 778 | 2.55M | if (num >= 0) { | 779 | 1.41M | pred = (int)(((Q00 << 7) + num) / (Q00 << 8)); | 780 | 1.41M | } else { | 781 | 1.13M | pred = (int)(((Q00 << 7) - num) / (Q00 << 8)); | 782 | 1.13M | pred = -pred; | 783 | 1.13M | } | 784 | 2.55M | workspace[0] = (JCOEF)pred; | 785 | 2.55M | } /* change_dc */ | 786 | | | 787 | | /* OK, do the IDCT */ | 788 | 3.93M | (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr, | 789 | 3.93M | output_col); | 790 | | /* Advance for next column */ | 791 | 3.93M | DC01 = DC02; DC02 = DC03; DC03 = DC04; DC04 = DC05; | 792 | 3.93M | DC06 = DC07; DC07 = DC08; DC08 = DC09; DC09 = DC10; | 793 | 3.93M | DC11 = DC12; DC12 = DC13; DC13 = DC14; DC14 = DC15; | 794 | 3.93M | DC16 = DC17; DC17 = DC18; DC18 = DC19; DC19 = DC20; | 795 | 3.93M | DC21 = DC22; DC22 = DC23; DC23 = DC24; DC24 = DC25; | 796 | 3.93M | buffer_ptr++, prev_block_row++, next_block_row++, | 797 | 3.93M | prev_prev_block_row++, next_next_block_row++; | 798 | 3.93M | output_col += compptr->_DCT_scaled_size; | 799 | 3.93M | } | 800 | 488k | output_ptr += compptr->_DCT_scaled_size; | 801 | 488k | } | 802 | 324k | } | 803 | | | 804 | 223k | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) | 805 | 222k | return JPEG_ROW_COMPLETED; | 806 | 577 | return JPEG_SCAN_COMPLETED; | 807 | 223k | } |
|
808 | | |
809 | | #endif /* BLOCK_SMOOTHING_SUPPORTED */ |
810 | | |
811 | | |
812 | | /* |
813 | | * Initialize coefficient buffer controller. |
814 | | */ |
815 | | |
816 | | GLOBAL(void) |
817 | | _jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer) |
818 | 5.40k | { |
819 | 5.40k | my_coef_ptr coef; |
820 | | |
821 | 5.40k | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
822 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
823 | | |
824 | 5.40k | coef = (my_coef_ptr) |
825 | 5.40k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
826 | 5.40k | sizeof(my_coef_controller)); |
827 | 5.40k | memset(coef, 0, sizeof(my_coef_controller)); |
828 | 5.40k | cinfo->coef = (struct jpeg_d_coef_controller *)coef; |
829 | 5.40k | coef->pub.start_input_pass = start_input_pass; |
830 | 5.40k | coef->pub.start_output_pass = start_output_pass; |
831 | 5.40k | #ifdef BLOCK_SMOOTHING_SUPPORTED |
832 | 5.40k | coef->coef_bits_latch = NULL; |
833 | 5.40k | #endif |
834 | | |
835 | | /* Create the coefficient buffer. */ |
836 | 5.40k | if (need_full_buffer) { |
837 | 4.51k | #ifdef D_MULTISCAN_FILES_SUPPORTED |
838 | | /* Allocate a full-image virtual array for each component, */ |
839 | | /* padded to a multiple of samp_factor DCT blocks in each direction. */ |
840 | | /* Note we ask for a pre-zeroed array. */ |
841 | 4.51k | int ci, access_rows; |
842 | 4.51k | jpeg_component_info *compptr; |
843 | | |
844 | 13.2k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
845 | 8.78k | ci++, compptr++) { |
846 | 8.78k | access_rows = compptr->v_samp_factor; |
847 | 8.78k | #ifdef BLOCK_SMOOTHING_SUPPORTED |
848 | | /* If block smoothing could be used, need a bigger window */ |
849 | 8.78k | if (cinfo->progressive_mode) |
850 | 4.12k | access_rows *= 5; |
851 | 8.78k | #endif |
852 | 8.78k | coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) |
853 | 8.78k | ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE, |
854 | 8.78k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, |
855 | 8.78k | (long)compptr->h_samp_factor), |
856 | 8.78k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, |
857 | 8.78k | (long)compptr->v_samp_factor), |
858 | 8.78k | (JDIMENSION)access_rows); |
859 | 8.78k | } |
860 | 4.51k | coef->pub.consume_data = consume_data; |
861 | 4.51k | coef->pub._decompress_data = decompress_data; |
862 | 4.51k | coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */ |
863 | | #else |
864 | | ERREXIT(cinfo, JERR_NOT_COMPILED); |
865 | | #endif |
866 | 4.51k | } else { |
867 | | /* We only need a single-MCU buffer. */ |
868 | 892 | JBLOCKROW buffer; |
869 | 892 | int i; |
870 | | |
871 | 892 | buffer = (JBLOCKROW) |
872 | 892 | (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
873 | 892 | D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK)); |
874 | 9.81k | for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { |
875 | 8.92k | coef->MCU_buffer[i] = buffer + i; |
876 | 8.92k | } |
877 | 892 | coef->pub.consume_data = dummy_consume_data; |
878 | 892 | coef->pub._decompress_data = decompress_onepass; |
879 | 892 | coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */ |
880 | 892 | } |
881 | | |
882 | | /* Allocate the workspace buffer */ |
883 | 5.40k | coef->workspace = (JCOEF *) |
884 | 5.40k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
885 | 5.40k | sizeof(JCOEF) * DCTSIZE2); |
886 | 5.40k | } Line | Count | Source | 818 | 2.72k | { | 819 | 2.72k | my_coef_ptr coef; | 820 | | | 821 | 2.72k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 822 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 823 | | | 824 | 2.72k | coef = (my_coef_ptr) | 825 | 2.72k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 826 | 2.72k | sizeof(my_coef_controller)); | 827 | 2.72k | memset(coef, 0, sizeof(my_coef_controller)); | 828 | 2.72k | cinfo->coef = (struct jpeg_d_coef_controller *)coef; | 829 | 2.72k | coef->pub.start_input_pass = start_input_pass; | 830 | 2.72k | coef->pub.start_output_pass = start_output_pass; | 831 | 2.72k | #ifdef BLOCK_SMOOTHING_SUPPORTED | 832 | 2.72k | coef->coef_bits_latch = NULL; | 833 | 2.72k | #endif | 834 | | | 835 | | /* Create the coefficient buffer. */ | 836 | 2.72k | if (need_full_buffer) { | 837 | 2.26k | #ifdef D_MULTISCAN_FILES_SUPPORTED | 838 | | /* Allocate a full-image virtual array for each component, */ | 839 | | /* padded to a multiple of samp_factor DCT blocks in each direction. */ | 840 | | /* Note we ask for a pre-zeroed array. */ | 841 | 2.26k | int ci, access_rows; | 842 | 2.26k | jpeg_component_info *compptr; | 843 | | | 844 | 6.13k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 845 | 3.87k | ci++, compptr++) { | 846 | 3.87k | access_rows = compptr->v_samp_factor; | 847 | 3.87k | #ifdef BLOCK_SMOOTHING_SUPPORTED | 848 | | /* If block smoothing could be used, need a bigger window */ | 849 | 3.87k | if (cinfo->progressive_mode) | 850 | 2.37k | access_rows *= 5; | 851 | 3.87k | #endif | 852 | 3.87k | coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) | 853 | 3.87k | ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE, | 854 | 3.87k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 855 | 3.87k | (long)compptr->h_samp_factor), | 856 | 3.87k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, | 857 | 3.87k | (long)compptr->v_samp_factor), | 858 | 3.87k | (JDIMENSION)access_rows); | 859 | 3.87k | } | 860 | 2.26k | coef->pub.consume_data = consume_data; | 861 | 2.26k | coef->pub._decompress_data = decompress_data; | 862 | 2.26k | coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */ | 863 | | #else | 864 | | ERREXIT(cinfo, JERR_NOT_COMPILED); | 865 | | #endif | 866 | 2.26k | } else { | 867 | | /* We only need a single-MCU buffer. */ | 868 | 461 | JBLOCKROW buffer; | 869 | 461 | int i; | 870 | | | 871 | 461 | buffer = (JBLOCKROW) | 872 | 461 | (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 873 | 461 | D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK)); | 874 | 5.07k | for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { | 875 | 4.61k | coef->MCU_buffer[i] = buffer + i; | 876 | 4.61k | } | 877 | 461 | coef->pub.consume_data = dummy_consume_data; | 878 | 461 | coef->pub._decompress_data = decompress_onepass; | 879 | 461 | coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */ | 880 | 461 | } | 881 | | | 882 | | /* Allocate the workspace buffer */ | 883 | 2.72k | coef->workspace = (JCOEF *) | 884 | 2.72k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 885 | 2.72k | sizeof(JCOEF) * DCTSIZE2); | 886 | 2.72k | } |
j12init_d_coef_controller Line | Count | Source | 818 | 2.68k | { | 819 | 2.68k | my_coef_ptr coef; | 820 | | | 821 | 2.68k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 822 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 823 | | | 824 | 2.68k | coef = (my_coef_ptr) | 825 | 2.68k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 826 | 2.68k | sizeof(my_coef_controller)); | 827 | 2.68k | memset(coef, 0, sizeof(my_coef_controller)); | 828 | 2.68k | cinfo->coef = (struct jpeg_d_coef_controller *)coef; | 829 | 2.68k | coef->pub.start_input_pass = start_input_pass; | 830 | 2.68k | coef->pub.start_output_pass = start_output_pass; | 831 | 2.68k | #ifdef BLOCK_SMOOTHING_SUPPORTED | 832 | 2.68k | coef->coef_bits_latch = NULL; | 833 | 2.68k | #endif | 834 | | | 835 | | /* Create the coefficient buffer. */ | 836 | 2.68k | if (need_full_buffer) { | 837 | 2.24k | #ifdef D_MULTISCAN_FILES_SUPPORTED | 838 | | /* Allocate a full-image virtual array for each component, */ | 839 | | /* padded to a multiple of samp_factor DCT blocks in each direction. */ | 840 | | /* Note we ask for a pre-zeroed array. */ | 841 | 2.24k | int ci, access_rows; | 842 | 2.24k | jpeg_component_info *compptr; | 843 | | | 844 | 7.16k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 845 | 4.91k | ci++, compptr++) { | 846 | 4.91k | access_rows = compptr->v_samp_factor; | 847 | 4.91k | #ifdef BLOCK_SMOOTHING_SUPPORTED | 848 | | /* If block smoothing could be used, need a bigger window */ | 849 | 4.91k | if (cinfo->progressive_mode) | 850 | 1.75k | access_rows *= 5; | 851 | 4.91k | #endif | 852 | 4.91k | coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) | 853 | 4.91k | ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE, | 854 | 4.91k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 855 | 4.91k | (long)compptr->h_samp_factor), | 856 | 4.91k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, | 857 | 4.91k | (long)compptr->v_samp_factor), | 858 | 4.91k | (JDIMENSION)access_rows); | 859 | 4.91k | } | 860 | 2.24k | coef->pub.consume_data = consume_data; | 861 | 2.24k | coef->pub._decompress_data = decompress_data; | 862 | 2.24k | coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */ | 863 | | #else | 864 | | ERREXIT(cinfo, JERR_NOT_COMPILED); | 865 | | #endif | 866 | 2.24k | } else { | 867 | | /* We only need a single-MCU buffer. */ | 868 | 431 | JBLOCKROW buffer; | 869 | 431 | int i; | 870 | | | 871 | 431 | buffer = (JBLOCKROW) | 872 | 431 | (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 873 | 431 | D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK)); | 874 | 4.74k | for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { | 875 | 4.31k | coef->MCU_buffer[i] = buffer + i; | 876 | 4.31k | } | 877 | 431 | coef->pub.consume_data = dummy_consume_data; | 878 | 431 | coef->pub._decompress_data = decompress_onepass; | 879 | 431 | coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */ | 880 | 431 | } | 881 | | | 882 | | /* Allocate the workspace buffer */ | 883 | 2.68k | coef->workspace = (JCOEF *) | 884 | 2.68k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 885 | 2.68k | sizeof(JCOEF) * DCTSIZE2); | 886 | 2.68k | } |
|