diff options
author | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
commit | 959831f4ef5a3e797f576c3de08cd65032c997ad (patch) | |
tree | e7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jctrans.c | |
parent | Add info about changes to Irrlicht. (diff) | |
download | SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2 SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz |
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jctrans.c | 764 |
1 files changed, 382 insertions, 382 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jctrans.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jctrans.c index dc84214..f7d7b81 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jctrans.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jctrans.c | |||
@@ -1,382 +1,382 @@ | |||
1 | /* | 1 | /* |
2 | * jctrans.c | 2 | * jctrans.c |
3 | * | 3 | * |
4 | * Copyright (C) 1995-1998, Thomas G. Lane. | 4 | * Copyright (C) 1995-1998, Thomas G. Lane. |
5 | * Modified 2000-2011 by Guido Vollbeding. | 5 | * Modified 2000-2011 by Guido Vollbeding. |
6 | * This file is part of the Independent JPEG Group's software. | 6 | * This file is part of the Independent JPEG Group's software. |
7 | * For conditions of distribution and use, see the accompanying README file. | 7 | * For conditions of distribution and use, see the accompanying README file. |
8 | * | 8 | * |
9 | * This file contains library routines for transcoding compression, | 9 | * This file contains library routines for transcoding compression, |
10 | * that is, writing raw DCT coefficient arrays to an output JPEG file. | 10 | * that is, writing raw DCT coefficient arrays to an output JPEG file. |
11 | * The routines in jcapimin.c will also be needed by a transcoder. | 11 | * The routines in jcapimin.c will also be needed by a transcoder. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #define JPEG_INTERNALS | 14 | #define JPEG_INTERNALS |
15 | #include "jinclude.h" | 15 | #include "jinclude.h" |
16 | #include "jpeglib.h" | 16 | #include "jpeglib.h" |
17 | 17 | ||
18 | 18 | ||
19 | /* Forward declarations */ | 19 | /* Forward declarations */ |
20 | LOCAL(void) transencode_master_selection | 20 | LOCAL(void) transencode_master_selection |
21 | JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); | 21 | JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); |
22 | LOCAL(void) transencode_coef_controller | 22 | LOCAL(void) transencode_coef_controller |
23 | JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); | 23 | JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); |
24 | 24 | ||
25 | 25 | ||
26 | /* | 26 | /* |
27 | * Compression initialization for writing raw-coefficient data. | 27 | * Compression initialization for writing raw-coefficient data. |
28 | * Before calling this, all parameters and a data destination must be set up. | 28 | * Before calling this, all parameters and a data destination must be set up. |
29 | * Call jpeg_finish_compress() to actually write the data. | 29 | * Call jpeg_finish_compress() to actually write the data. |
30 | * | 30 | * |
31 | * The number of passed virtual arrays must match cinfo->num_components. | 31 | * The number of passed virtual arrays must match cinfo->num_components. |
32 | * Note that the virtual arrays need not be filled or even realized at | 32 | * Note that the virtual arrays need not be filled or even realized at |
33 | * the time write_coefficients is called; indeed, if the virtual arrays | 33 | * the time write_coefficients is called; indeed, if the virtual arrays |
34 | * were requested from this compression object's memory manager, they | 34 | * were requested from this compression object's memory manager, they |
35 | * typically will be realized during this routine and filled afterwards. | 35 | * typically will be realized during this routine and filled afterwards. |
36 | */ | 36 | */ |
37 | 37 | ||
38 | GLOBAL(void) | 38 | GLOBAL(void) |
39 | jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays) | 39 | jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays) |
40 | { | 40 | { |
41 | if (cinfo->global_state != CSTATE_START) | 41 | if (cinfo->global_state != CSTATE_START) |
42 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 42 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
43 | /* Mark all tables to be written */ | 43 | /* Mark all tables to be written */ |
44 | jpeg_suppress_tables(cinfo, FALSE); | 44 | jpeg_suppress_tables(cinfo, FALSE); |
45 | /* (Re)initialize error mgr and destination modules */ | 45 | /* (Re)initialize error mgr and destination modules */ |
46 | (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); | 46 | (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); |
47 | (*cinfo->dest->init_destination) (cinfo); | 47 | (*cinfo->dest->init_destination) (cinfo); |
48 | /* Perform master selection of active modules */ | 48 | /* Perform master selection of active modules */ |
49 | transencode_master_selection(cinfo, coef_arrays); | 49 | transencode_master_selection(cinfo, coef_arrays); |
50 | /* Wait for jpeg_finish_compress() call */ | 50 | /* Wait for jpeg_finish_compress() call */ |
51 | cinfo->next_scanline = 0; /* so jpeg_write_marker works */ | 51 | cinfo->next_scanline = 0; /* so jpeg_write_marker works */ |
52 | cinfo->global_state = CSTATE_WRCOEFS; | 52 | cinfo->global_state = CSTATE_WRCOEFS; |
53 | } | 53 | } |
54 | 54 | ||
55 | 55 | ||
56 | /* | 56 | /* |
57 | * Initialize the compression object with default parameters, | 57 | * Initialize the compression object with default parameters, |
58 | * then copy from the source object all parameters needed for lossless | 58 | * then copy from the source object all parameters needed for lossless |
59 | * transcoding. Parameters that can be varied without loss (such as | 59 | * transcoding. Parameters that can be varied without loss (such as |
60 | * scan script and Huffman optimization) are left in their default states. | 60 | * scan script and Huffman optimization) are left in their default states. |
61 | */ | 61 | */ |
62 | 62 | ||
63 | GLOBAL(void) | 63 | GLOBAL(void) |
64 | jpeg_copy_critical_parameters (j_decompress_ptr srcinfo, | 64 | jpeg_copy_critical_parameters (j_decompress_ptr srcinfo, |
65 | j_compress_ptr dstinfo) | 65 | j_compress_ptr dstinfo) |
66 | { | 66 | { |
67 | JQUANT_TBL ** qtblptr; | 67 | JQUANT_TBL ** qtblptr; |
68 | jpeg_component_info *incomp, *outcomp; | 68 | jpeg_component_info *incomp, *outcomp; |
69 | JQUANT_TBL *c_quant, *slot_quant; | 69 | JQUANT_TBL *c_quant, *slot_quant; |
70 | int tblno, ci, coefi; | 70 | int tblno, ci, coefi; |
71 | 71 | ||
72 | /* Safety check to ensure start_compress not called yet. */ | 72 | /* Safety check to ensure start_compress not called yet. */ |
73 | if (dstinfo->global_state != CSTATE_START) | 73 | if (dstinfo->global_state != CSTATE_START) |
74 | ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state); | 74 | ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state); |
75 | /* Copy fundamental image dimensions */ | 75 | /* Copy fundamental image dimensions */ |
76 | dstinfo->image_width = srcinfo->image_width; | 76 | dstinfo->image_width = srcinfo->image_width; |
77 | dstinfo->image_height = srcinfo->image_height; | 77 | dstinfo->image_height = srcinfo->image_height; |
78 | dstinfo->input_components = srcinfo->num_components; | 78 | dstinfo->input_components = srcinfo->num_components; |
79 | dstinfo->in_color_space = srcinfo->jpeg_color_space; | 79 | dstinfo->in_color_space = srcinfo->jpeg_color_space; |
80 | dstinfo->jpeg_width = srcinfo->output_width; | 80 | dstinfo->jpeg_width = srcinfo->output_width; |
81 | dstinfo->jpeg_height = srcinfo->output_height; | 81 | dstinfo->jpeg_height = srcinfo->output_height; |
82 | dstinfo->min_DCT_h_scaled_size = srcinfo->min_DCT_h_scaled_size; | 82 | dstinfo->min_DCT_h_scaled_size = srcinfo->min_DCT_h_scaled_size; |
83 | dstinfo->min_DCT_v_scaled_size = srcinfo->min_DCT_v_scaled_size; | 83 | dstinfo->min_DCT_v_scaled_size = srcinfo->min_DCT_v_scaled_size; |
84 | /* Initialize all parameters to default values */ | 84 | /* Initialize all parameters to default values */ |
85 | jpeg_set_defaults(dstinfo); | 85 | jpeg_set_defaults(dstinfo); |
86 | /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB. | 86 | /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB. |
87 | * Fix it to get the right header markers for the image colorspace. | 87 | * Fix it to get the right header markers for the image colorspace. |
88 | */ | 88 | */ |
89 | jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space); | 89 | jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space); |
90 | dstinfo->data_precision = srcinfo->data_precision; | 90 | dstinfo->data_precision = srcinfo->data_precision; |
91 | dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling; | 91 | dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling; |
92 | /* Copy the source's quantization tables. */ | 92 | /* Copy the source's quantization tables. */ |
93 | for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { | 93 | for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { |
94 | if (srcinfo->quant_tbl_ptrs[tblno] != NULL) { | 94 | if (srcinfo->quant_tbl_ptrs[tblno] != NULL) { |
95 | qtblptr = & dstinfo->quant_tbl_ptrs[tblno]; | 95 | qtblptr = & dstinfo->quant_tbl_ptrs[tblno]; |
96 | if (*qtblptr == NULL) | 96 | if (*qtblptr == NULL) |
97 | *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo); | 97 | *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo); |
98 | MEMCOPY((*qtblptr)->quantval, | 98 | MEMCOPY((*qtblptr)->quantval, |
99 | srcinfo->quant_tbl_ptrs[tblno]->quantval, | 99 | srcinfo->quant_tbl_ptrs[tblno]->quantval, |
100 | SIZEOF((*qtblptr)->quantval)); | 100 | SIZEOF((*qtblptr)->quantval)); |
101 | (*qtblptr)->sent_table = FALSE; | 101 | (*qtblptr)->sent_table = FALSE; |
102 | } | 102 | } |
103 | } | 103 | } |
104 | /* Copy the source's per-component info. | 104 | /* Copy the source's per-component info. |
105 | * Note we assume jpeg_set_defaults has allocated the dest comp_info array. | 105 | * Note we assume jpeg_set_defaults has allocated the dest comp_info array. |
106 | */ | 106 | */ |
107 | dstinfo->num_components = srcinfo->num_components; | 107 | dstinfo->num_components = srcinfo->num_components; |
108 | if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS) | 108 | if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS) |
109 | ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components, | 109 | ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components, |
110 | MAX_COMPONENTS); | 110 | MAX_COMPONENTS); |
111 | for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info; | 111 | for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info; |
112 | ci < dstinfo->num_components; ci++, incomp++, outcomp++) { | 112 | ci < dstinfo->num_components; ci++, incomp++, outcomp++) { |
113 | outcomp->component_id = incomp->component_id; | 113 | outcomp->component_id = incomp->component_id; |
114 | outcomp->h_samp_factor = incomp->h_samp_factor; | 114 | outcomp->h_samp_factor = incomp->h_samp_factor; |
115 | outcomp->v_samp_factor = incomp->v_samp_factor; | 115 | outcomp->v_samp_factor = incomp->v_samp_factor; |
116 | outcomp->quant_tbl_no = incomp->quant_tbl_no; | 116 | outcomp->quant_tbl_no = incomp->quant_tbl_no; |
117 | /* Make sure saved quantization table for component matches the qtable | 117 | /* Make sure saved quantization table for component matches the qtable |
118 | * slot. If not, the input file re-used this qtable slot. | 118 | * slot. If not, the input file re-used this qtable slot. |
119 | * IJG encoder currently cannot duplicate this. | 119 | * IJG encoder currently cannot duplicate this. |
120 | */ | 120 | */ |
121 | tblno = outcomp->quant_tbl_no; | 121 | tblno = outcomp->quant_tbl_no; |
122 | if (tblno < 0 || tblno >= NUM_QUANT_TBLS || | 122 | if (tblno < 0 || tblno >= NUM_QUANT_TBLS || |
123 | srcinfo->quant_tbl_ptrs[tblno] == NULL) | 123 | srcinfo->quant_tbl_ptrs[tblno] == NULL) |
124 | ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno); | 124 | ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno); |
125 | slot_quant = srcinfo->quant_tbl_ptrs[tblno]; | 125 | slot_quant = srcinfo->quant_tbl_ptrs[tblno]; |
126 | c_quant = incomp->quant_table; | 126 | c_quant = incomp->quant_table; |
127 | if (c_quant != NULL) { | 127 | if (c_quant != NULL) { |
128 | for (coefi = 0; coefi < DCTSIZE2; coefi++) { | 128 | for (coefi = 0; coefi < DCTSIZE2; coefi++) { |
129 | if (c_quant->quantval[coefi] != slot_quant->quantval[coefi]) | 129 | if (c_quant->quantval[coefi] != slot_quant->quantval[coefi]) |
130 | ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno); | 130 | ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno); |
131 | } | 131 | } |
132 | } | 132 | } |
133 | /* Note: we do not copy the source's Huffman table assignments; | 133 | /* Note: we do not copy the source's Huffman table assignments; |
134 | * instead we rely on jpeg_set_colorspace to have made a suitable choice. | 134 | * instead we rely on jpeg_set_colorspace to have made a suitable choice. |
135 | */ | 135 | */ |
136 | } | 136 | } |
137 | /* Also copy JFIF version and resolution information, if available. | 137 | /* Also copy JFIF version and resolution information, if available. |
138 | * Strictly speaking this isn't "critical" info, but it's nearly | 138 | * Strictly speaking this isn't "critical" info, but it's nearly |
139 | * always appropriate to copy it if available. In particular, | 139 | * always appropriate to copy it if available. In particular, |
140 | * if the application chooses to copy JFIF 1.02 extension markers from | 140 | * if the application chooses to copy JFIF 1.02 extension markers from |
141 | * the source file, we need to copy the version to make sure we don't | 141 | * the source file, we need to copy the version to make sure we don't |
142 | * emit a file that has 1.02 extensions but a claimed version of 1.01. | 142 | * emit a file that has 1.02 extensions but a claimed version of 1.01. |
143 | * We will *not*, however, copy version info from mislabeled "2.01" files. | 143 | * We will *not*, however, copy version info from mislabeled "2.01" files. |
144 | */ | 144 | */ |
145 | if (srcinfo->saw_JFIF_marker) { | 145 | if (srcinfo->saw_JFIF_marker) { |
146 | if (srcinfo->JFIF_major_version == 1) { | 146 | if (srcinfo->JFIF_major_version == 1) { |
147 | dstinfo->JFIF_major_version = srcinfo->JFIF_major_version; | 147 | dstinfo->JFIF_major_version = srcinfo->JFIF_major_version; |
148 | dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version; | 148 | dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version; |
149 | } | 149 | } |
150 | dstinfo->density_unit = srcinfo->density_unit; | 150 | dstinfo->density_unit = srcinfo->density_unit; |
151 | dstinfo->X_density = srcinfo->X_density; | 151 | dstinfo->X_density = srcinfo->X_density; |
152 | dstinfo->Y_density = srcinfo->Y_density; | 152 | dstinfo->Y_density = srcinfo->Y_density; |
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
157 | /* | 157 | /* |
158 | * Master selection of compression modules for transcoding. | 158 | * Master selection of compression modules for transcoding. |
159 | * This substitutes for jcinit.c's initialization of the full compressor. | 159 | * This substitutes for jcinit.c's initialization of the full compressor. |
160 | */ | 160 | */ |
161 | 161 | ||
162 | LOCAL(void) | 162 | LOCAL(void) |
163 | transencode_master_selection (j_compress_ptr cinfo, | 163 | transencode_master_selection (j_compress_ptr cinfo, |
164 | jvirt_barray_ptr * coef_arrays) | 164 | jvirt_barray_ptr * coef_arrays) |
165 | { | 165 | { |
166 | /* Initialize master control (includes parameter checking/processing) */ | 166 | /* Initialize master control (includes parameter checking/processing) */ |
167 | jinit_c_master_control(cinfo, TRUE /* transcode only */); | 167 | jinit_c_master_control(cinfo, TRUE /* transcode only */); |
168 | 168 | ||
169 | /* Entropy encoding: either Huffman or arithmetic coding. */ | 169 | /* Entropy encoding: either Huffman or arithmetic coding. */ |
170 | if (cinfo->arith_code) | 170 | if (cinfo->arith_code) |
171 | jinit_arith_encoder(cinfo); | 171 | jinit_arith_encoder(cinfo); |
172 | else { | 172 | else { |
173 | jinit_huff_encoder(cinfo); | 173 | jinit_huff_encoder(cinfo); |
174 | } | 174 | } |
175 | 175 | ||
176 | /* We need a special coefficient buffer controller. */ | 176 | /* We need a special coefficient buffer controller. */ |
177 | transencode_coef_controller(cinfo, coef_arrays); | 177 | transencode_coef_controller(cinfo, coef_arrays); |
178 | 178 | ||
179 | jinit_marker_writer(cinfo); | 179 | jinit_marker_writer(cinfo); |
180 | 180 | ||
181 | /* We can now tell the memory manager to allocate virtual arrays. */ | 181 | /* We can now tell the memory manager to allocate virtual arrays. */ |
182 | (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); | 182 | (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); |
183 | 183 | ||
184 | /* Write the datastream header (SOI, JFIF) immediately. | 184 | /* Write the datastream header (SOI, JFIF) immediately. |
185 | * Frame and scan headers are postponed till later. | 185 | * Frame and scan headers are postponed till later. |
186 | * This lets application insert special markers after the SOI. | 186 | * This lets application insert special markers after the SOI. |
187 | */ | 187 | */ |
188 | (*cinfo->marker->write_file_header) (cinfo); | 188 | (*cinfo->marker->write_file_header) (cinfo); |
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
192 | /* | 192 | /* |
193 | * The rest of this file is a special implementation of the coefficient | 193 | * The rest of this file is a special implementation of the coefficient |
194 | * buffer controller. This is similar to jccoefct.c, but it handles only | 194 | * buffer controller. This is similar to jccoefct.c, but it handles only |
195 | * output from presupplied virtual arrays. Furthermore, we generate any | 195 | * output from presupplied virtual arrays. Furthermore, we generate any |
196 | * dummy padding blocks on-the-fly rather than expecting them to be present | 196 | * dummy padding blocks on-the-fly rather than expecting them to be present |
197 | * in the arrays. | 197 | * in the arrays. |
198 | */ | 198 | */ |
199 | 199 | ||
200 | /* Private buffer controller object */ | 200 | /* Private buffer controller object */ |
201 | 201 | ||
202 | typedef struct { | 202 | typedef struct { |
203 | struct jpeg_c_coef_controller pub; /* public fields */ | 203 | struct jpeg_c_coef_controller pub; /* public fields */ |
204 | 204 | ||
205 | JDIMENSION iMCU_row_num; /* iMCU row # within image */ | 205 | JDIMENSION iMCU_row_num; /* iMCU row # within image */ |
206 | JDIMENSION mcu_ctr; /* counts MCUs processed in current row */ | 206 | JDIMENSION mcu_ctr; /* counts MCUs processed in current row */ |
207 | int MCU_vert_offset; /* counts MCU rows within iMCU row */ | 207 | int MCU_vert_offset; /* counts MCU rows within iMCU row */ |
208 | int MCU_rows_per_iMCU_row; /* number of such rows needed */ | 208 | int MCU_rows_per_iMCU_row; /* number of such rows needed */ |
209 | 209 | ||
210 | /* Virtual block array for each component. */ | 210 | /* Virtual block array for each component. */ |
211 | jvirt_barray_ptr * whole_image; | 211 | jvirt_barray_ptr * whole_image; |
212 | 212 | ||
213 | /* Workspace for constructing dummy blocks at right/bottom edges. */ | 213 | /* Workspace for constructing dummy blocks at right/bottom edges. */ |
214 | JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU]; | 214 | JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU]; |
215 | } my_coef_controller; | 215 | } my_coef_controller; |
216 | 216 | ||
217 | typedef my_coef_controller * my_coef_ptr; | 217 | typedef my_coef_controller * my_coef_ptr; |
218 | 218 | ||
219 | 219 | ||
220 | LOCAL(void) | 220 | LOCAL(void) |
221 | start_iMCU_row (j_compress_ptr cinfo) | 221 | start_iMCU_row (j_compress_ptr cinfo) |
222 | /* Reset within-iMCU-row counters for a new row */ | 222 | /* Reset within-iMCU-row counters for a new row */ |
223 | { | 223 | { |
224 | my_coef_ptr coef = (my_coef_ptr) cinfo->coef; | 224 | my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
225 | 225 | ||
226 | /* In an interleaved scan, an MCU row is the same as an iMCU row. | 226 | /* In an interleaved scan, an MCU row is the same as an iMCU row. |
227 | * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. | 227 | * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. |
228 | * But at the bottom of the image, process only what's left. | 228 | * But at the bottom of the image, process only what's left. |
229 | */ | 229 | */ |
230 | if (cinfo->comps_in_scan > 1) { | 230 | if (cinfo->comps_in_scan > 1) { |
231 | coef->MCU_rows_per_iMCU_row = 1; | 231 | coef->MCU_rows_per_iMCU_row = 1; |
232 | } else { | 232 | } else { |
233 | if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1)) | 233 | if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1)) |
234 | coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; | 234 | coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; |
235 | else | 235 | else |
236 | coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; | 236 | coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; |
237 | } | 237 | } |
238 | 238 | ||
239 | coef->mcu_ctr = 0; | 239 | coef->mcu_ctr = 0; |
240 | coef->MCU_vert_offset = 0; | 240 | coef->MCU_vert_offset = 0; |
241 | } | 241 | } |
242 | 242 | ||
243 | 243 | ||
244 | /* | 244 | /* |
245 | * Initialize for a processing pass. | 245 | * Initialize for a processing pass. |
246 | */ | 246 | */ |
247 | 247 | ||
248 | METHODDEF(void) | 248 | METHODDEF(void) |
249 | start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode) | 249 | start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode) |
250 | { | 250 | { |
251 | my_coef_ptr coef = (my_coef_ptr) cinfo->coef; | 251 | my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
252 | 252 | ||
253 | if (pass_mode != JBUF_CRANK_DEST) | 253 | if (pass_mode != JBUF_CRANK_DEST) |
254 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 254 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); |
255 | 255 | ||
256 | coef->iMCU_row_num = 0; | 256 | coef->iMCU_row_num = 0; |
257 | start_iMCU_row(cinfo); | 257 | start_iMCU_row(cinfo); |
258 | } | 258 | } |
259 | 259 | ||
260 | 260 | ||
261 | /* | 261 | /* |
262 | * Process some data. | 262 | * Process some data. |
263 | * We process the equivalent of one fully interleaved MCU row ("iMCU" row) | 263 | * We process the equivalent of one fully interleaved MCU row ("iMCU" row) |
264 | * per call, ie, v_samp_factor block rows for each component in the scan. | 264 | * per call, ie, v_samp_factor block rows for each component in the scan. |
265 | * The data is obtained from the virtual arrays and fed to the entropy coder. | 265 | * The data is obtained from the virtual arrays and fed to the entropy coder. |
266 | * Returns TRUE if the iMCU row is completed, FALSE if suspended. | 266 | * Returns TRUE if the iMCU row is completed, FALSE if suspended. |
267 | * | 267 | * |
268 | * NB: input_buf is ignored; it is likely to be a NULL pointer. | 268 | * NB: input_buf is ignored; it is likely to be a NULL pointer. |
269 | */ | 269 | */ |
270 | 270 | ||
271 | METHODDEF(boolean) | 271 | METHODDEF(boolean) |
272 | compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf) | 272 | compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf) |
273 | { | 273 | { |
274 | my_coef_ptr coef = (my_coef_ptr) cinfo->coef; | 274 | my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
275 | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 275 | JDIMENSION MCU_col_num; /* index of current MCU within row */ |
276 | JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; | 276 | JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; |
277 | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 277 | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
278 | int blkn, ci, xindex, yindex, yoffset, blockcnt; | 278 | int blkn, ci, xindex, yindex, yoffset, blockcnt; |
279 | JDIMENSION start_col; | 279 | JDIMENSION start_col; |
280 | JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; | 280 | JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; |
281 | JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU]; | 281 | JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU]; |
282 | JBLOCKROW buffer_ptr; | 282 | JBLOCKROW buffer_ptr; |
283 | jpeg_component_info *compptr; | 283 | jpeg_component_info *compptr; |
284 | 284 | ||
285 | /* Align the virtual buffers for the components used in this scan. */ | 285 | /* Align the virtual buffers for the components used in this scan. */ |
286 | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 286 | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
287 | compptr = cinfo->cur_comp_info[ci]; | 287 | compptr = cinfo->cur_comp_info[ci]; |
288 | buffer[ci] = (*cinfo->mem->access_virt_barray) | 288 | buffer[ci] = (*cinfo->mem->access_virt_barray) |
289 | ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], | 289 | ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], |
290 | coef->iMCU_row_num * compptr->v_samp_factor, | 290 | coef->iMCU_row_num * compptr->v_samp_factor, |
291 | (JDIMENSION) compptr->v_samp_factor, FALSE); | 291 | (JDIMENSION) compptr->v_samp_factor, FALSE); |
292 | } | 292 | } |
293 | 293 | ||
294 | /* Loop to process one whole iMCU row */ | 294 | /* Loop to process one whole iMCU row */ |
295 | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; | 295 | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; |
296 | yoffset++) { | 296 | yoffset++) { |
297 | for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row; | 297 | for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row; |
298 | MCU_col_num++) { | 298 | MCU_col_num++) { |
299 | /* Construct list of pointers to DCT blocks belonging to this MCU */ | 299 | /* Construct list of pointers to DCT blocks belonging to this MCU */ |
300 | blkn = 0; /* index of current DCT block within MCU */ | 300 | blkn = 0; /* index of current DCT block within MCU */ |
301 | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 301 | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
302 | compptr = cinfo->cur_comp_info[ci]; | 302 | compptr = cinfo->cur_comp_info[ci]; |
303 | start_col = MCU_col_num * compptr->MCU_width; | 303 | start_col = MCU_col_num * compptr->MCU_width; |
304 | blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width | 304 | blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width |
305 | : compptr->last_col_width; | 305 | : compptr->last_col_width; |
306 | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { | 306 | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { |
307 | if (coef->iMCU_row_num < last_iMCU_row || | 307 | if (coef->iMCU_row_num < last_iMCU_row || |
308 | yindex+yoffset < compptr->last_row_height) { | 308 | yindex+yoffset < compptr->last_row_height) { |
309 | /* Fill in pointers to real blocks in this row */ | 309 | /* Fill in pointers to real blocks in this row */ |
310 | buffer_ptr = buffer[ci][yindex+yoffset] + start_col; | 310 | buffer_ptr = buffer[ci][yindex+yoffset] + start_col; |
311 | for (xindex = 0; xindex < blockcnt; xindex++) | 311 | for (xindex = 0; xindex < blockcnt; xindex++) |
312 | MCU_buffer[blkn++] = buffer_ptr++; | 312 | MCU_buffer[blkn++] = buffer_ptr++; |
313 | } else { | 313 | } else { |
314 | /* At bottom of image, need a whole row of dummy blocks */ | 314 | /* At bottom of image, need a whole row of dummy blocks */ |
315 | xindex = 0; | 315 | xindex = 0; |
316 | } | 316 | } |
317 | /* Fill in any dummy blocks needed in this row. | 317 | /* Fill in any dummy blocks needed in this row. |
318 | * Dummy blocks are filled in the same way as in jccoefct.c: | 318 | * Dummy blocks are filled in the same way as in jccoefct.c: |
319 | * all zeroes in the AC entries, DC entries equal to previous | 319 | * all zeroes in the AC entries, DC entries equal to previous |
320 | * block's DC value. The init routine has already zeroed the | 320 | * block's DC value. The init routine has already zeroed the |
321 | * AC entries, so we need only set the DC entries correctly. | 321 | * AC entries, so we need only set the DC entries correctly. |
322 | */ | 322 | */ |
323 | for (; xindex < compptr->MCU_width; xindex++) { | 323 | for (; xindex < compptr->MCU_width; xindex++) { |
324 | MCU_buffer[blkn] = coef->dummy_buffer[blkn]; | 324 | MCU_buffer[blkn] = coef->dummy_buffer[blkn]; |
325 | MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0]; | 325 | MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0]; |
326 | blkn++; | 326 | blkn++; |
327 | } | 327 | } |
328 | } | 328 | } |
329 | } | 329 | } |
330 | /* Try to write the MCU. */ | 330 | /* Try to write the MCU. */ |
331 | if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) { | 331 | if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) { |
332 | /* Suspension forced; update state counters and exit */ | 332 | /* Suspension forced; update state counters and exit */ |
333 | coef->MCU_vert_offset = yoffset; | 333 | coef->MCU_vert_offset = yoffset; |
334 | coef->mcu_ctr = MCU_col_num; | 334 | coef->mcu_ctr = MCU_col_num; |
335 | return FALSE; | 335 | return FALSE; |
336 | } | 336 | } |
337 | } | 337 | } |
338 | /* Completed an MCU row, but perhaps not an iMCU row */ | 338 | /* Completed an MCU row, but perhaps not an iMCU row */ |
339 | coef->mcu_ctr = 0; | 339 | coef->mcu_ctr = 0; |
340 | } | 340 | } |
341 | /* Completed the iMCU row, advance counters for next one */ | 341 | /* Completed the iMCU row, advance counters for next one */ |
342 | coef->iMCU_row_num++; | 342 | coef->iMCU_row_num++; |
343 | start_iMCU_row(cinfo); | 343 | start_iMCU_row(cinfo); |
344 | return TRUE; | 344 | return TRUE; |
345 | } | 345 | } |
346 | 346 | ||
347 | 347 | ||
348 | /* | 348 | /* |
349 | * Initialize coefficient buffer controller. | 349 | * Initialize coefficient buffer controller. |
350 | * | 350 | * |
351 | * Each passed coefficient array must be the right size for that | 351 | * Each passed coefficient array must be the right size for that |
352 | * coefficient: width_in_blocks wide and height_in_blocks high, | 352 | * coefficient: width_in_blocks wide and height_in_blocks high, |
353 | * with unitheight at least v_samp_factor. | 353 | * with unitheight at least v_samp_factor. |
354 | */ | 354 | */ |
355 | 355 | ||
356 | LOCAL(void) | 356 | LOCAL(void) |
357 | transencode_coef_controller (j_compress_ptr cinfo, | 357 | transencode_coef_controller (j_compress_ptr cinfo, |
358 | jvirt_barray_ptr * coef_arrays) | 358 | jvirt_barray_ptr * coef_arrays) |
359 | { | 359 | { |
360 | my_coef_ptr coef; | 360 | my_coef_ptr coef; |
361 | JBLOCKROW buffer; | 361 | JBLOCKROW buffer; |
362 | int i; | 362 | int i; |
363 | 363 | ||
364 | coef = (my_coef_ptr) | 364 | coef = (my_coef_ptr) |
365 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 365 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
366 | SIZEOF(my_coef_controller)); | 366 | SIZEOF(my_coef_controller)); |
367 | cinfo->coef = (struct jpeg_c_coef_controller *) coef; | 367 | cinfo->coef = (struct jpeg_c_coef_controller *) coef; |
368 | coef->pub.start_pass = start_pass_coef; | 368 | coef->pub.start_pass = start_pass_coef; |
369 | coef->pub.compress_data = compress_output; | 369 | coef->pub.compress_data = compress_output; |
370 | 370 | ||
371 | /* Save pointer to virtual arrays */ | 371 | /* Save pointer to virtual arrays */ |
372 | coef->whole_image = coef_arrays; | 372 | coef->whole_image = coef_arrays; |
373 | 373 | ||
374 | /* Allocate and pre-zero space for dummy DCT blocks. */ | 374 | /* Allocate and pre-zero space for dummy DCT blocks. */ |
375 | buffer = (JBLOCKROW) | 375 | buffer = (JBLOCKROW) |
376 | (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 376 | (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
377 | C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); | 377 | C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); |
378 | FMEMZERO((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); | 378 | FMEMZERO((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); |
379 | for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) { | 379 | for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) { |
380 | coef->dummy_buffer[i] = buffer + i; | 380 | coef->dummy_buffer[i] = buffer + i; |
381 | } | 381 | } |
382 | } | 382 | } |