jcomapi.c
Go to the documentation of this file.
00001 /*
00002  * jcomapi.c
00003  *
00004  * Copyright (C) 1994-1997, Thomas G. Lane.
00005  * This file is part of the Independent JPEG Group's software.
00006  * For conditions of distribution and use, see the accompanying README file.
00007  *
00008  * This file contains application interface routines that are used for both
00009  * compression and decompression.
00010  */
00011 
00012 #define JPEG_INTERNALS
00013 #include "jinclude.h"
00014 #include "jpeglib.h"
00015 
00016 
00017 /*
00018  * Abort processing of a JPEG compression or decompression operation,
00019  * but don't destroy the object itself.
00020  *
00021  * For this, we merely clean up all the nonpermanent memory pools.
00022  * Note that temp files (virtual arrays) are not allowed to belong to
00023  * the permanent pool, so we will be able to close all temp files here.
00024  * Closing a data source or destination, if necessary, is the application's
00025  * responsibility.
00026  */
00027 
00028 GLOBAL(void)
00029 jpeg_abort (j_common_ptr cinfo)
00030 {
00031   int pool;
00032 
00033   /* Do nothing if called on a not-initialized or destroyed JPEG object. */
00034   if (cinfo->mem == NULL)
00035     return;
00036 
00037   /* Releasing pools in reverse order might help avoid fragmentation
00038    * with some (brain-damaged) malloc libraries.
00039    */
00040   for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
00041     (*cinfo->mem->free_pool) (cinfo, pool);
00042   }
00043 
00044   /* Reset overall state for possible reuse of object */
00045   if (cinfo->is_decompressor) {
00046     cinfo->global_state = DSTATE_START;
00047     /* Try to keep application from accessing now-deleted marker list.
00048      * A bit kludgy to do it here, but this is the most central place.
00049      */
00050     ((j_decompress_ptr) cinfo)->marker_list = NULL;
00051   } else {
00052     cinfo->global_state = CSTATE_START;
00053   }
00054 }
00055 
00056 
00057 /*
00058  * Destruction of a JPEG object.
00059  *
00060  * Everything gets deallocated except the master jpeg_compress_struct itself
00061  * and the error manager struct.  Both of these are supplied by the application
00062  * and must be freed, if necessary, by the application.  (Often they are on
00063  * the stack and so don't need to be freed anyway.)
00064  * Closing a data source or destination, if necessary, is the application's
00065  * responsibility.
00066  */
00067 
00068 GLOBAL(void)
00069 jpeg_destroy (j_common_ptr cinfo)
00070 {
00071   /* We need only tell the memory manager to release everything. */
00072   /* NB: mem pointer is NULL if memory mgr failed to initialize. */
00073   if (cinfo->mem != NULL)
00074     (*cinfo->mem->self_destruct) (cinfo);
00075   cinfo->mem = NULL;            /* be safe if jpeg_destroy is called twice */
00076   cinfo->global_state = 0;      /* mark it destroyed */
00077 }
00078 
00079 
00080 /*
00081  * Convenience routines for allocating quantization and Huffman tables.
00082  * (Would jutils.c be a more reasonable place to put these?)
00083  */
00084 
00085 GLOBAL(JQUANT_TBL *)
00086 jpeg_alloc_quant_table (j_common_ptr cinfo)
00087 {
00088   JQUANT_TBL *tbl;
00089 
00090   tbl = (JQUANT_TBL *)
00091     (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
00092   tbl->sent_table = FALSE;      /* make sure this is false in any new table */
00093   return tbl;
00094 }
00095 
00096 
00097 GLOBAL(JHUFF_TBL *)
00098 jpeg_alloc_huff_table (j_common_ptr cinfo)
00099 {
00100   JHUFF_TBL *tbl;
00101 
00102   tbl = (JHUFF_TBL *)
00103     (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
00104   tbl->sent_table = FALSE;      /* make sure this is false in any new table */
00105   return tbl;
00106 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:17