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