doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
jcomapi.c
Go to the documentation of this file.
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 
12 #define JPEG_INTERNALS
13 #include "jinclude.h"
14 #include "jpeglib.h"
15 
16 
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 
28 GLOBAL void
30 {
31  int pool;
32 
33  /* Releasing pools in reverse order might help avoid fragmentation
34  * with some (brain-damaged) malloc libraries.
35  */
36  for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
37  (*cinfo->mem->free_pool) (cinfo, pool);
38  }
39 
40  /* Reset overall state for possible reuse of object */
41  cinfo->global_state = (cinfo->is_decompressor ? DSTATE_START : CSTATE_START);
42 }
43 
44 
45 /*
46  * Destruction of a JPEG object.
47  *
48  * Everything gets deallocated except the master jpeg_compress_struct itself
49  * and the error manager struct. Both of these are supplied by the application
50  * and must be freed, if necessary, by the application. (Often they are on
51  * the stack and so don't need to be freed anyway.)
52  * Closing a data source or destination, if necessary, is the application's
53  * responsibility.
54  */
55 
56 GLOBAL void
58 {
59  /* We need only tell the memory manager to release everything. */
60  /* NB: mem pointer is NULL if memory mgr failed to initialize. */
61  if (cinfo->mem != NULL)
62  (*cinfo->mem->self_destruct) (cinfo);
63  cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
64  cinfo->global_state = 0; /* mark it destroyed */
65 }
66 
67 
68 /*
69  * Convenience routines for allocating quantization and Huffman tables.
70  * (Would jutils.c be a more reasonable place to put these?)
71  */
72 
75 {
76  JQUANT_TBL *tbl;
77 
78  tbl = (JQUANT_TBL *)
79  (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
80  tbl->sent_table = FALSE; /* make sure this is false in any new table */
81  return tbl;
82 }
83 
84 
87 {
88  JHUFF_TBL *tbl;
89 
90  tbl = (JHUFF_TBL *)
91  (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
92  tbl->sent_table = FALSE; /* make sure this is false in any new table */
93  return tbl;
94 }
#define CSTATE_START
Definition: jpegint.h:25
boolean sent_table
Definition: jpeglib.h:106
GLOBAL JHUFF_TBL * jpeg_alloc_huff_table(j_common_ptr cinfo)
Definition: jcomapi.c:86
#define SIZEOF(object)
Definition: jinclude.h:80
GLOBAL void jpeg_destroy(j_common_ptr cinfo)
Definition: jcomapi.c:57
#define NULL
Definition: Lib.h:88
#define DSTATE_START
Definition: jpegint.h:29
#define GLOBAL
Definition: jmorecfg.h:190
boolean sent_table
Definition: jpeglib.h:122
#define JPOOL_NUMPOOLS
Definition: jpeglib.h:737
GLOBAL void jpeg_abort(j_common_ptr cinfo)
Definition: jcomapi.c:29
#define FALSE
Definition: mprintf.c:70
GLOBAL JQUANT_TBL * jpeg_alloc_quant_table(j_common_ptr cinfo)
Definition: jcomapi.c:74
#define JPOOL_PERMANENT
Definition: jpeglib.h:735