DEADSOFTWARE

hopefully no more windows
[d2df-editor.git] / src / lib / vampimg / JpegLib / imjcomapi.pas
1 unit imjcomapi;
3 { This file contains application interface routines that are used for both
4 compression and decompression. }
6 { Original: jcomapi.c; Copyright (C) 1994-1997, Thomas G. Lane. }
8 interface
10 {$I imjconfig.inc}
12 uses
13 imjmorecfg,
14 imjinclude,
15 imjpeglib;
17 { Abort processing of a JPEG compression or decompression operation,
18 but don't destroy the object itself. }
20 {GLOBAL}
21 procedure jpeg_abort (cinfo : j_common_ptr);
24 { Destruction of a JPEG object. }
26 {GLOBAL}
27 procedure jpeg_destroy (cinfo : j_common_ptr);
29 {GLOBAL}
30 function jpeg_alloc_quant_table (cinfo : j_common_ptr) : JQUANT_TBL_PTR;
32 {GLOBAL}
33 function jpeg_alloc_huff_table (cinfo : j_common_ptr) : JHUFF_TBL_PTR;
35 implementation
37 { Abort processing of a JPEG compression or decompression operation,
38 but don't destroy the object itself.
40 For this, we merely clean up all the nonpermanent memory pools.
41 Note that temp files (virtual arrays) are not allowed to belong to
42 the permanent pool, so we will be able to close all temp files here.
43 Closing a data source or destination, if necessary, is the application's
44 responsibility. }
47 {GLOBAL}
48 procedure jpeg_abort (cinfo : j_common_ptr);
49 var
50 pool : int;
51 begin
52 { Do nothing if called on a not-initialized or destroyed JPEG object. }
53 if (cinfo^.mem = NIL) then
54 exit;
56 { Releasing pools in reverse order might help avoid fragmentation
57 with some (brain-damaged) malloc libraries. }
59 for pool := JPOOL_NUMPOOLS-1 downto JPOOL_PERMANENT+1 do
60 begin
61 cinfo^.mem^.free_pool (cinfo, pool);
62 end;
64 { Reset overall state for possible reuse of object }
65 if (cinfo^.is_decompressor) then
66 begin
67 cinfo^.global_state := DSTATE_START;
68 { Try to keep application from accessing now-deleted marker list.
69 A bit kludgy to do it here, but this is the most central place. }
70 j_decompress_ptr(cinfo)^.marker_list := NIL;
71 end
72 else
73 begin
74 cinfo^.global_state := CSTATE_START;
75 end;
76 end;
79 { Destruction of a JPEG object.
81 Everything gets deallocated except the master jpeg_compress_struct itself
82 and the error manager struct. Both of these are supplied by the application
83 and must be freed, if necessary, by the application. (Often they are on
84 the stack and so don't need to be freed anyway.)
85 Closing a data source or destination, if necessary, is the application's
86 responsibility. }
89 {GLOBAL}
90 procedure jpeg_destroy (cinfo : j_common_ptr);
91 begin
92 { We need only tell the memory manager to release everything. }
93 { NB: mem pointer is NIL if memory mgr failed to initialize. }
94 if (cinfo^.mem <> NIL) then
95 cinfo^.mem^.self_destruct (cinfo);
96 cinfo^.mem := NIL; { be safe if jpeg_destroy is called twice }
97 cinfo^.global_state := 0; { mark it destroyed }
98 end;
101 { Convenience routines for allocating quantization and Huffman tables.
102 (Would jutils.c be a more reasonable place to put these?) }
105 {GLOBAL}
106 function jpeg_alloc_quant_table (cinfo : j_common_ptr) : JQUANT_TBL_PTR;
107 var
108 tbl : JQUANT_TBL_PTR;
109 begin
110 tbl := JQUANT_TBL_PTR(
111 cinfo^.mem^.alloc_small (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL))
112 );
113 tbl^.sent_table := FALSE; { make sure this is false in any new table }
114 jpeg_alloc_quant_table := tbl;
115 end;
118 {GLOBAL}
119 function jpeg_alloc_huff_table (cinfo : j_common_ptr) : JHUFF_TBL_PTR;
120 var
121 tbl : JHUFF_TBL_PTR;
122 begin
123 tbl := JHUFF_TBL_PTR(
124 cinfo^.mem^.alloc_small (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL))
125 );
126 tbl^.sent_table := FALSE; { make sure this is false in any new table }
127 jpeg_alloc_huff_table := tbl;
128 end;
130 end.