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