jcomapi.cpp 2.9 KB

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