Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.7 KiB

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