2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: jcomapi.c /main/2 1996/05/09 03:45:45 drk $ */
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.
31 * This file contains application interface routines that are used for both
32 * compression and decompression.
35 #define JPEG_INTERNALS
41 * Abort processing of a JPEG compression or decompression operation,
42 * but don't destroy the object itself.
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
52 jpeg_abort (j_common_ptr cinfo)
56 /* Releasing pools in reverse order might help avoid fragmentation
57 * with some (brain-damaged) malloc libraries.
59 for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
60 (*cinfo->mem->free_pool) (cinfo, pool);
63 /* Reset overall state for possible reuse of object */
64 cinfo->global_state = (cinfo->is_decompressor ? DSTATE_START : CSTATE_START);
69 * Destruction of a JPEG object.
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
80 jpeg_destroy (j_common_ptr cinfo)
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 */
92 * Convenience routines for allocating quantization and Huffman tables.
93 * (Would jutils.c be a more reasonable place to put these?)
97 jpeg_alloc_quant_table (j_common_ptr cinfo)
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 */
109 jpeg_alloc_huff_table (j_common_ptr cinfo)
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 */