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.

97 lines
2.7 KiB

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