JCOMAPI.c
上传用户:qiutianh
上传日期:2022-08-08
资源大小:939k
文件大小:4k
源码类别:

图形图象

开发平台:

Visual C++

  1. ////////////////////////////////////////////////////////////////////////
  2. //
  3. // Note : this file is included as part of the Smaller Animals Software
  4. // JpegFile package. Though this file has not been modified from it's 
  5. // original IJG 6a form, it is not the responsibility on the Independent
  6. // JPEG Group to answer questions regarding this code.
  7. //
  8. // Any questions you have about this code should be addressed to :
  9. //
  10. // CHRISDL@PAGESZ.NET - the distributor of this package.
  11. //
  12. // Remember, by including this code in the JpegFile package, Smaller 
  13. // Animals Software assumes all responsibilities for answering questions
  14. // about it. If we (SA Software) can't answer your questions ourselves, we 
  15. // will direct you to people who can.
  16. //
  17. // Thanks, CDL.
  18. //
  19. ////////////////////////////////////////////////////////////////////////
  20. /*
  21.  * jcomapi.c
  22.  *
  23.  * Copyright (C) 1994-1996, Thomas G. Lane.
  24.  * This file is part of the Independent JPEG Group's software.
  25.  * For conditions of distribution and use, see the accompanying README file.
  26.  *
  27.  * This file contains application interface routines that are used for both
  28.  * compression and decompression.
  29.  */
  30. #define JPEG_INTERNALS
  31. #include "jinclude.h"
  32. #include "jpeglib.h"
  33. /*
  34.  * Abort processing of a JPEG compression or decompression operation,
  35.  * but don't destroy the object itself.
  36.  *
  37.  * For this, we merely clean up all the nonpermanent memory pools.
  38.  * Note that temp files (virtual arrays) are not allowed to belong to
  39.  * the permanent pool, so we will be able to close all temp files here.
  40.  * Closing a data source or destination, if necessary, is the application's
  41.  * responsibility.
  42.  */
  43. GLOBAL(void)
  44. jpeg_abort (j_common_ptr cinfo)
  45. {
  46.   int pool;
  47.   /* Releasing pools in reverse order might help avoid fragmentation
  48.    * with some (brain-damaged) malloc libraries.
  49.    */
  50.   for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  51.     (*cinfo->mem->free_pool) (cinfo, pool);
  52.   }
  53.   /* Reset overall state for possible reuse of object */
  54.   cinfo->global_state = (cinfo->is_decompressor ? DSTATE_START : CSTATE_START);
  55. }
  56. /*
  57.  * Destruction of a JPEG object.
  58.  *
  59.  * Everything gets deallocated except the master jpeg_compress_struct itself
  60.  * and the error manager struct.  Both of these are supplied by the application
  61.  * and must be freed, if necessary, by the application.  (Often they are on
  62.  * the stack and so don't need to be freed anyway.)
  63.  * Closing a data source or destination, if necessary, is the application's
  64.  * responsibility.
  65.  */
  66. GLOBAL(void)
  67. jpeg_destroy (j_common_ptr cinfo)
  68. {
  69.   /* We need only tell the memory manager to release everything. */
  70.   /* NB: mem pointer is NULL if memory mgr failed to initialize. */
  71.   if (cinfo->mem != NULL)
  72.     (*cinfo->mem->self_destruct) (cinfo);
  73.   cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  74.   cinfo->global_state = 0; /* mark it destroyed */
  75. }
  76. /*
  77.  * Convenience routines for allocating quantization and Huffman tables.
  78.  * (Would jutils.c be a more reasonable place to put these?)
  79.  */
  80. GLOBAL(JQUANT_TBL *)
  81. jpeg_alloc_quant_table (j_common_ptr cinfo)
  82. {
  83.   JQUANT_TBL *tbl;
  84.   tbl = (JQUANT_TBL *)
  85.     (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  86.   tbl->sent_table = FALSE; /* make sure this is false in any new table */
  87.   return tbl;
  88. }
  89. GLOBAL(JHUFF_TBL *)
  90. jpeg_alloc_huff_table (j_common_ptr cinfo)
  91. {
  92.   JHUFF_TBL *tbl;
  93.   tbl = (JHUFF_TBL *)
  94.     (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  95.   tbl->sent_table = FALSE; /* make sure this is false in any new table */
  96.   return tbl;
  97. }