2 {$N+}
3 { This file contains application interface code for the compression half
4 of the JPEG library. These are the "minimum" API routines that may be
5 needed in either the normal full-compression case or the transcoding-only
6 case.
8 Most of the routines intended to be called directly by an application
9 are in this file or in jcapistd.c. But also see jcparam.c for
10 parameter-setup helper routines, jcomapi.c for routines shared by
11 compression and decompression, and jctrans.c for the transcoding case. }
13 { jcapimin.c ; Copyright (C) 1994-1998, Thomas G. Lane. }
16 interface
18 {$I imjconfig.inc}
20 uses
21 imjmorecfg,
22 imjinclude,
23 imjdeferr,
24 imjerror,
25 imjpeglib,
26 imjcomapi,
27 imjmemmgr,
28 imjcmarker;
30 { Initialization of JPEG compression objects.
31 Nomssi: This is a macro in the original code.
33 jpeg_create_compress() and jpeg_create_decompress() are the exported
34 names that applications should call. These expand to calls on
35 jpeg_CreateCompress and jpeg_CreateDecompress with additional information
36 passed for version mismatch checking.
37 NB: you must set up the error-manager BEFORE calling jpeg_create_xxx. }
42 { Initialization of a JPEG compression object.
43 The error manager must already be set up (in case memory manager fails). }
45 {GLOBAL}
50 { Destruction of a JPEG compression object }
52 {GLOBAL}
56 { Abort processing of a JPEG compression operation,
57 but don't destroy the object itself. }
59 {GLOBAL}
63 { Forcibly suppress or un-suppress all quantization and Huffman tables.
64 Marks all currently defined tables as already written (if suppress)
65 or not written (if !suppress). This will control whether they get emitted
66 by a subsequent jpeg_start_compress call.
68 This routine is exported for use by applications that want to produce
69 abbreviated JPEG datastreams. It logically belongs in jcparam.c, but
70 since it is called by jpeg_start_compress, we put it here --- otherwise
71 jcparam.o would be linked whether the application used it or not. }
73 {GLOBAL}
78 { Finish JPEG compression.
80 If a multipass operating mode was selected, this may do a great deal of
81 work including most of the actual output. }
83 {GLOBAL}
86 { Write a special marker.
87 This is only recommended for writing COM or APPn markers.
88 Must be called after jpeg_start_compress() and before
89 first call to jpeg_write_scanlines() or jpeg_write_raw_data(). }
91 {GLOBAL}
97 {GLOBAL}
101 {GLOBAL}
104 { Alternate compression function: just write an abbreviated table file.
105 Before calling this, all parameters and a data destination must be set up.
107 To produce a pair of files containing abbreviated tables and abbreviated
108 image data, one would proceed as follows:
110 initialize JPEG object
111 set JPEG parameters
112 set destination to table file
113 jpeg_write_tables(cinfo);
114 set destination to image file
115 jpeg_start_compress(cinfo, FALSE);
116 write data...
117 jpeg_finish_compress(cinfo);
119 jpeg_write_tables has the side effect of marking all tables written
120 (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress
121 will not re-emit the tables unless it is passed write_all_tables=TRUE. }
125 {GLOBAL}
128 implementation
131 begin
136 { Initialization of a JPEG compression object.
137 The error manager must already be set up (in case memory manager fails). }
139 {GLOBAL}
143 var
145 var
148 begin
150 { Guard against version mismatches between library and caller. }
158 { For debugging purposes, we zero the whole master structure.
159 But the application has already set the err pointer, and may have set
160 client_data, so we have to save and restore those fields.
161 Note: if application hasn't set client_data, tools like Purify may
162 complain here. }
170 { Initialize a memory manager instance for this object }
173 { Zero out pointers to permanent structures. }
183 begin
192 { OK, I'm ready }
197 { Destruction of a JPEG compression object }
199 {GLOBAL}
201 begin
206 { Abort processing of a JPEG compression operation,
207 but don't destroy the object itself. }
209 {GLOBAL}
211 begin
216 { Forcibly suppress or un-suppress all quantization and Huffman tables.
217 Marks all currently defined tables as already written (if suppress)
218 or not written (if !suppress). This will control whether they get emitted
219 by a subsequent jpeg_start_compress call.
221 This routine is exported for use by applications that want to produce
222 abbreviated JPEG datastreams. It logically belongs in jcparam.c, but
223 since it is called by jpeg_start_compress, we put it here --- otherwise
224 jcparam.o would be linked whether the application used it or not. }
226 {GLOBAL}
229 var
233 begin
235 begin
242 begin
253 { Finish JPEG compression.
255 If a multipass operating mode was selected, this may do a great deal of
256 work including most of the actual output. }
258 {GLOBAL}
260 var
262 begin
265 begin
266 { Terminate first pass }
270 end
271 else
274 { Perform any remaining passes }
276 begin
279 begin
281 begin
286 { We bypass the main controller and invoke coef controller directly;
287 all work is being done from the coefficient buffer. }
294 { Write EOI, do final cleanup }
297 { We can use jpeg_abort to release memory and reset global_state }
302 { Write a special marker.
303 This is only recommended for writing COM or APPn markers.
304 Must be called after jpeg_start_compress() and before
305 first call to jpeg_write_scanlines() or jpeg_write_raw_data(). }
307 {GLOBAL}
312 var
314 begin
324 begin
331 { Same, but piecemeal. }
333 {GLOBAL}
337 begin
347 {GLOBAL}
349 begin
354 { Alternate compression function: just write an abbreviated table file.
355 Before calling this, all parameters and a data destination must be set up.
357 To produce a pair of files containing abbreviated tables and abbreviated
358 image data, one would proceed as follows:
360 initialize JPEG object
361 set JPEG parameters
362 set destination to table file
363 jpeg_write_tables(cinfo);
364 set destination to image file
365 jpeg_start_compress(cinfo, FALSE);
366 write data...
367 jpeg_finish_compress(cinfo);
369 jpeg_write_tables has the side effect of marking all tables written
370 (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress
371 will not re-emit the tables unless it is passed write_all_tables=TRUE. }
373 {GLOBAL}
375 begin
379 { (Re)initialize error mgr and destination modules }
382 { Initialize the marker writer ... bit of a crock to do it here. }
384 { Write them tables! }
386 { And clean up. }
389 { In library releases up through v6a, we called jpeg_abort() here to free
390 any working memory allocated by the destination manager and marker
391 writer. Some applications had a problem with that: they allocated space
392 of their own from the library memory manager, and didn't want it to go
393 away during write_tables. So now we do nothing. This will cause a
394 memory leak if an app calls write_tables repeatedly without doing a full
395 compression cycle or otherwise resetting the JPEG object. However, that
396 seems less bad than unexpectedly freeing memory in the normal case.
397 An app that prefers the old behavior can call jpeg_abort for itself after
398 each call to jpeg_write_tables(). }