3 { This file contains the main buffer controller for compression.
4 The main buffer lies between the pre-processor and the JPEG
5 compressor proper; it holds downsampled data in the JPEG colorspace. }
7 { Original : jcmainct.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
9 interface
11 {$I imjconfig.inc}
13 { Note: currently, there is no operating mode in which a full-image buffer
14 is needed at this step. If there were, that mode could not be used with
15 "raw data" input, since this module is bypassed in that case. However,
16 we've left the code here for possible use in special applications. }
18 {$undef FULL_MAIN_BUFFER_SUPPORTED}
20 uses
21 imjmorecfg,
22 imjinclude,
23 imjdeferr,
24 imjerror,
25 {$ifdef FULL_MAIN_BUFFER_SUPPORTED}
26 imjutils,
27 {$endif}
28 imjpeglib;
30 { Initialize main buffer controller. }
32 {GLOBAL}
36 implementation
39 { Private buffer controller object }
41 type
51 { If using just a strip buffer, this points to the entire set of buffers
52 (we allocate one for each component). In the full-image case, this
53 points to the currently accessible strips of the virtual arrays. }
57 {$ifdef FULL_MAIN_BUFFER_SUPPORTED}
58 { If using full-image storage, this array holds pointers to virtual-array
59 control blocks for each component. Unused if not full-image storage. }
62 {$endif}
66 { Forward declarations }
67 {METHODDEF}
73 {$ifdef FULL_MAIN_BUFFER_SUPPORTED}
74 {METHODDEF}
79 {$endif}
82 { Initialize for a processing pass. }
84 {METHODDEF}
87 var
89 begin
92 { Do nothing in raw-data mode. }
94 exit;
102 JBUF_PASS_THRU:
103 begin
104 {$ifdef FULL_MAIN_BUFFER_SUPPORTED}
107 {$endif}
110 {$ifdef FULL_MAIN_BUFFER_SUPPORTED}
111 JBUF_SAVE_SOURCE,
112 JBUF_CRANK_DEST,
113 JBUF_SAVE_AND_PASS:
114 begin
119 {$endif}
120 else
126 { Process some data.
127 This routine handles the simple pass-through mode,
128 where we have only a strip buffer. }
130 {METHODDEF}
135 var
137 begin
141 begin
142 { Read input data if we haven't filled the main buffer yet }
145 input_buf,
146 in_row_ctr,
147 in_rows_avail,
152 { If we don't have a full iMCU row buffered, return to application for
153 more data. Note that preprocessor will always pad to fill the iMCU row
154 at the bottom of the image. }
156 exit;
158 { Send the completed row to the compressor }
160 begin
161 { If compressor did not consume the whole row, then we must need to
162 suspend processing and return to the application. In this situation
163 we pretend we didn't yet consume the last input row; otherwise, if
164 it happened to be the last row of the image, the application would
165 think we were done. }
168 begin
172 exit;
174 { We did finish the row. Undo our little suspension hack if a previous
175 call suspended; then mark the main buffer empty. }
178 begin
188 {$ifdef FULL_MAIN_BUFFER_SUPPORTED}
190 { Process some data.
191 This routine handles all of the modes that use a full-size buffer. }
193 {METHODDEF}
198 var
203 begin
208 begin
209 { Realign the virtual buffers if at the start of an iMCU row. }
211 begin
214 begin
221 { In a read pass, pretend we just read some source data. }
223 begin
229 { If a write pass, read input data until the current iMCU row is full. }
230 { Note: preprocessor will pad if necessary to fill the last iMCU row. }
232 begin
239 { Return to application if we need more data to fill the iMCU row. }
241 exit;
244 { Emit data, unless this is a sink-only pass. }
246 begin
249 begin
250 { If compressor did not consume the whole row, then we must need to
251 suspend processing and return to the application. In this situation
252 we pretend we didn't yet consume the last input row; otherwise, if
253 it happened to be the last row of the image, the application would
254 think we were done. }
257 begin
261 exit;
263 { We did finish the row. Undo our little suspension hack if a previous
264 call suspended; then mark the main buffer empty. }
267 begin
273 { If get here, we are done with this iMCU row. Mark buffer empty. }
282 { Initialize main buffer controller. }
284 {GLOBAL}
287 var
291 begin
298 { We don't need to create a buffer in raw-data mode. }
300 exit;
302 { Create the buffer. It holds downsampled data, so each component
303 may be of a different size. }
306 begin
307 {$ifdef FULL_MAIN_BUFFER_SUPPORTED}
308 { Allocate a full-image virtual array for each component }
309 { Note we pad the bottom to a multiple of the iMCU height }
312 begin
321 {$else}
323 {$endif}
324 end
325 else
326 begin
327 {$ifdef FULL_MAIN_BUFFER_SUPPORTED}
329 {$endif}
330 { Allocate a strip buffer for each component }
333 begin