]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/jpeg6/jcomapi.cpp
ABToSVK commit
[xonotic/netradiant.git] / libs / jpeg6 / jcomapi.cpp
1 /*
2
3  * jcomapi.c
4
5  *
6
7  * Copyright (C) 1994, Thomas G. Lane.
8
9  * This file is part of the Independent JPEG Group's software.
10
11  * For conditions of distribution and use, see the accompanying README file.
12
13  *
14
15  * This file contains application interface routines that are used for both
16
17  * compression and decompression.
18
19  */
20
21
22
23 #define JPEG_INTERNALS
24
25 #include "jinclude.h"
26
27 #include "radiant_jpeglib.h"
28
29
30
31
32
33 /*
34
35  * Abort processing of a JPEG compression or decompression operation,
36
37  * but don't destroy the object itself.
38
39  *
40
41  * For this, we merely clean up all the nonpermanent memory pools.
42
43  * Note that temp files (virtual arrays) are not allowed to belong to
44
45  * the permanent pool, so we will be able to close all temp files here.
46
47  * Closing a data source or destination, if necessary, is the application's
48
49  * responsibility.
50
51  */
52
53
54
55 GLOBAL void
56
57 jpeg_abort (j_common_ptr cinfo)
58
59 {
60
61   int pool;
62
63
64
65   /* Releasing pools in reverse order might help avoid fragmentation
66
67    * with some (brain-damaged) malloc libraries.
68
69    */
70
71   for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
72
73     (*cinfo->mem->free_pool) (cinfo, pool);
74
75   }
76
77
78
79   /* Reset overall state for possible reuse of object */
80
81   cinfo->global_state = (cinfo->is_decompressor ? DSTATE_START : CSTATE_START);
82
83 }
84
85
86
87
88
89 /*
90
91  * Destruction of a JPEG object.
92
93  *
94
95  * Everything gets deallocated except the master jpeg_compress_struct itself
96
97  * and the error manager struct.  Both of these are supplied by the application
98
99  * and must be freed, if necessary, by the application.  (Often they are on
100
101  * the stack and so don't need to be freed anyway.)
102
103  * Closing a data source or destination, if necessary, is the application's
104
105  * responsibility.
106
107  */
108
109
110
111 GLOBAL void
112
113 jpeg_destroy (j_common_ptr cinfo)
114
115 {
116
117   /* We need only tell the memory manager to release everything. */
118
119   /* NB: mem pointer is NULL if memory mgr failed to initialize. */
120
121   if (cinfo->mem != NULL)
122
123     (*cinfo->mem->self_destruct) (cinfo);
124
125   cinfo->mem = NULL;            /* be safe if jpeg_destroy is called twice */
126
127   cinfo->global_state = 0;      /* mark it destroyed */
128
129 }
130
131
132
133
134
135 /*
136
137  * Convenience routines for allocating quantization and Huffman tables.
138
139  * (Would jutils.c be a more reasonable place to put these?)
140
141  */
142
143
144
145 GLOBAL JQUANT_TBL *
146
147 jpeg_alloc_quant_table (j_common_ptr cinfo)
148
149 {
150
151   JQUANT_TBL *tbl;
152
153
154
155   tbl = (JQUANT_TBL *)
156
157     (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
158
159   tbl->sent_table = FALSE;      /* make sure this is false in any new table */
160
161   return tbl;
162
163 }
164
165
166
167
168
169 GLOBAL JHUFF_TBL *
170
171 jpeg_alloc_huff_table (j_common_ptr cinfo)
172
173 {
174
175   JHUFF_TBL *tbl;
176
177
178
179   tbl = (JHUFF_TBL *)
180
181     (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
182
183   tbl->sent_table = FALSE;      /* make sure this is false in any new table */
184
185   return tbl;
186
187 }
188