jcomapi.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #define JPEG_INTERNALS
  35. #include "jinclude.h"
  36. #include "jpeglib.h"
  37. /*
  38. * Abort processing of a JPEG compression or decompression operation,
  39. * but don't destroy the object itself.
  40. *
  41. * For this, we merely clean up all the nonpermanent memory pools.
  42. * Note that temp files (virtual arrays) are not allowed to belong to
  43. * the permanent pool, so we will be able to close all temp files here.
  44. * Closing a data source or destination, if necessary, is the application's
  45. * responsibility.
  46. */
  47. GLOBAL(void)
  48. jpeg_abort (j_common_ptr cinfo)
  49. {
  50. int pool;
  51. /* Releasing pools in reverse order might help avoid fragmentation
  52. * with some (brain-damaged) malloc libraries.
  53. */
  54. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  55. (*cinfo->mem->free_pool) (cinfo, pool);
  56. }
  57. /* Reset overall state for possible reuse of object */
  58. cinfo->global_state = (cinfo->is_decompressor ? DSTATE_START : CSTATE_START);
  59. }
  60. /*
  61. * Destruction of a JPEG object.
  62. *
  63. * Everything gets deallocated except the master jpeg_compress_struct itself
  64. * and the error manager struct. Both of these are supplied by the application
  65. * and must be freed, if necessary, by the application. (Often they are on
  66. * the stack and so don't need to be freed anyway.)
  67. * Closing a data source or destination, if necessary, is the application's
  68. * responsibility.
  69. */
  70. GLOBAL(void)
  71. jpeg_destroy (j_common_ptr cinfo)
  72. {
  73. /* We need only tell the memory manager to release everything. */
  74. /* NB: mem pointer is NULL if memory mgr failed to initialize. */
  75. if (cinfo->mem != NULL)
  76. (*cinfo->mem->self_destruct) (cinfo);
  77. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  78. cinfo->global_state = 0; /* mark it destroyed */
  79. }
  80. /*
  81. * Convenience routines for allocating quantization and Huffman tables.
  82. * (Would jutils.c be a more reasonable place to put these?)
  83. */
  84. GLOBAL(JQUANT_TBL *)
  85. jpeg_alloc_quant_table (j_common_ptr cinfo)
  86. {
  87. JQUANT_TBL *tbl;
  88. tbl = (JQUANT_TBL *)
  89. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  90. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  91. return tbl;
  92. }
  93. GLOBAL(JHUFF_TBL *)
  94. jpeg_alloc_huff_table (j_common_ptr cinfo)
  95. {
  96. JHUFF_TBL *tbl;
  97. tbl = (JHUFF_TBL *)
  98. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  99. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  100. return tbl;
  101. }