nuclear@2: /* nuclear@2: * jcomapi.c nuclear@2: * nuclear@2: * Copyright (C) 1994-1997, Thomas G. Lane. nuclear@2: * This file is part of the Independent JPEG Group's software. nuclear@2: * For conditions of distribution and use, see the accompanying README file. nuclear@2: * nuclear@2: * This file contains application interface routines that are used for both nuclear@2: * compression and decompression. nuclear@2: */ nuclear@2: nuclear@2: #define JPEG_INTERNALS nuclear@2: #include "jinclude.h" nuclear@2: #include "jpeglib.h" nuclear@2: nuclear@2: nuclear@2: /* nuclear@2: * Abort processing of a JPEG compression or decompression operation, nuclear@2: * but don't destroy the object itself. nuclear@2: * nuclear@2: * For this, we merely clean up all the nonpermanent memory pools. nuclear@2: * Note that temp files (virtual arrays) are not allowed to belong to nuclear@2: * the permanent pool, so we will be able to close all temp files here. nuclear@2: * Closing a data source or destination, if necessary, is the application's nuclear@2: * responsibility. nuclear@2: */ nuclear@2: nuclear@2: GLOBAL(void) nuclear@2: jpeg_abort (j_common_ptr cinfo) nuclear@2: { nuclear@2: int pool; nuclear@2: nuclear@2: /* Do nothing if called on a not-initialized or destroyed JPEG object. */ nuclear@2: if (cinfo->mem == NULL) nuclear@2: return; nuclear@2: nuclear@2: /* Releasing pools in reverse order might help avoid fragmentation nuclear@2: * with some (brain-damaged) malloc libraries. nuclear@2: */ nuclear@2: for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) { nuclear@2: (*cinfo->mem->free_pool) (cinfo, pool); nuclear@2: } nuclear@2: nuclear@2: /* Reset overall state for possible reuse of object */ nuclear@2: if (cinfo->is_decompressor) { nuclear@2: cinfo->global_state = DSTATE_START; nuclear@2: /* Try to keep application from accessing now-deleted marker list. nuclear@2: * A bit kludgy to do it here, but this is the most central place. nuclear@2: */ nuclear@2: ((j_decompress_ptr) cinfo)->marker_list = NULL; nuclear@2: } else { nuclear@2: cinfo->global_state = CSTATE_START; nuclear@2: } nuclear@2: } nuclear@2: nuclear@2: nuclear@2: /* nuclear@2: * Destruction of a JPEG object. nuclear@2: * nuclear@2: * Everything gets deallocated except the master jpeg_compress_struct itself nuclear@2: * and the error manager struct. Both of these are supplied by the application nuclear@2: * and must be freed, if necessary, by the application. (Often they are on nuclear@2: * the stack and so don't need to be freed anyway.) nuclear@2: * Closing a data source or destination, if necessary, is the application's nuclear@2: * responsibility. nuclear@2: */ nuclear@2: nuclear@2: GLOBAL(void) nuclear@2: jpeg_destroy (j_common_ptr cinfo) nuclear@2: { nuclear@2: /* We need only tell the memory manager to release everything. */ nuclear@2: /* NB: mem pointer is NULL if memory mgr failed to initialize. */ nuclear@2: if (cinfo->mem != NULL) nuclear@2: (*cinfo->mem->self_destruct) (cinfo); nuclear@2: cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */ nuclear@2: cinfo->global_state = 0; /* mark it destroyed */ nuclear@2: } nuclear@2: nuclear@2: nuclear@2: /* nuclear@2: * Convenience routines for allocating quantization and Huffman tables. nuclear@2: * (Would jutils.c be a more reasonable place to put these?) nuclear@2: */ nuclear@2: nuclear@2: GLOBAL(JQUANT_TBL *) nuclear@2: jpeg_alloc_quant_table (j_common_ptr cinfo) nuclear@2: { nuclear@2: JQUANT_TBL *tbl; nuclear@2: nuclear@2: tbl = (JQUANT_TBL *) nuclear@2: (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL)); nuclear@2: tbl->sent_table = FALSE; /* make sure this is false in any new table */ nuclear@2: return tbl; nuclear@2: } nuclear@2: nuclear@2: nuclear@2: GLOBAL(JHUFF_TBL *) nuclear@2: jpeg_alloc_huff_table (j_common_ptr cinfo) nuclear@2: { nuclear@2: JHUFF_TBL *tbl; nuclear@2: nuclear@2: tbl = (JHUFF_TBL *) nuclear@2: (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL)); nuclear@2: tbl->sent_table = FALSE; /* make sure this is false in any new table */ nuclear@2: return tbl; nuclear@2: }