e980a81e75144a1704d747b9ff5e03b0c6f89370
[oweals/cde.git] / cde / lib / DtHelp / jpeg / jcomapi.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: jcomapi.c /main/2 1996/05/09 03:45:45 drk $ */
24 /*
25  * jcomapi.c
26  *
27  * Copyright (C) 1994-1996, Thomas G. Lane.
28  * This file is part of the Independent JPEG Group's software.
29  * For conditions of distribution and use, see the accompanying README file.
30  *
31  * This file contains application interface routines that are used for both
32  * compression and decompression.
33  */
34
35 #define JPEG_INTERNALS
36 #include "jinclude.h"
37 #include "jpeglib.h"
38
39
40 /*
41  * Abort processing of a JPEG compression or decompression operation,
42  * but don't destroy the object itself.
43  *
44  * For this, we merely clean up all the nonpermanent memory pools.
45  * Note that temp files (virtual arrays) are not allowed to belong to
46  * the permanent pool, so we will be able to close all temp files here.
47  * Closing a data source or destination, if necessary, is the application's
48  * responsibility.
49  */
50
51 GLOBAL(void)
52 jpeg_abort (j_common_ptr cinfo)
53 {
54   int pool;
55
56   /* Releasing pools in reverse order might help avoid fragmentation
57    * with some (brain-damaged) malloc libraries.
58    */
59   for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
60     (*cinfo->mem->free_pool) (cinfo, pool);
61   }
62
63   /* Reset overall state for possible reuse of object */
64   cinfo->global_state = (cinfo->is_decompressor ? DSTATE_START : CSTATE_START);
65 }
66
67
68 /*
69  * Destruction of a JPEG object.
70  *
71  * Everything gets deallocated except the master jpeg_compress_struct itself
72  * and the error manager struct.  Both of these are supplied by the application
73  * and must be freed, if necessary, by the application.  (Often they are on
74  * the stack and so don't need to be freed anyway.)
75  * Closing a data source or destination, if necessary, is the application's
76  * responsibility.
77  */
78
79 GLOBAL(void)
80 jpeg_destroy (j_common_ptr cinfo)
81 {
82   /* We need only tell the memory manager to release everything. */
83   /* NB: mem pointer is NULL if memory mgr failed to initialize. */
84   if (cinfo->mem != NULL)
85     (*cinfo->mem->self_destruct) (cinfo);
86   cinfo->mem = NULL;            /* be safe if jpeg_destroy is called twice */
87   cinfo->global_state = 0;      /* mark it destroyed */
88 }
89
90
91 /*
92  * Convenience routines for allocating quantization and Huffman tables.
93  * (Would jutils.c be a more reasonable place to put these?)
94  */
95
96 GLOBAL(JQUANT_TBL *)
97 jpeg_alloc_quant_table (j_common_ptr cinfo)
98 {
99   JQUANT_TBL *tbl;
100
101   tbl = (JQUANT_TBL *)
102     (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
103   tbl->sent_table = FALSE;      /* make sure this is false in any new table */
104   return tbl;
105 }
106
107
108 GLOBAL(JHUFF_TBL *)
109 jpeg_alloc_huff_table (j_common_ptr cinfo)
110 {
111   JHUFF_TBL *tbl;
112
113   tbl = (JHUFF_TBL *)
114     (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
115   tbl->sent_table = FALSE;      /* make sure this is false in any new table */
116   return tbl;
117 }