Main MRPT website > C++ reference for MRPT 1.9.9
jcomapi.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #define JPEG_INTERNALS
11 #include "jinclude.h"
12 #include "mrpt_jpeglib.h"
13 
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 
25 GLOBAL(void)
27 {
28  int pool;
29 
30  /* Do nothing if called on a not-initialized or destroyed JPEG object. */
31  if (cinfo->mem == nullptr) return;
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  {
38  (*cinfo->mem->free_pool)(cinfo, pool);
39  }
40 
41  /* Reset overall state for possible reuse of object */
42  if (cinfo->is_decompressor)
43  {
44  cinfo->global_state = DSTATE_START;
45  /* Try to keep application from accessing now-deleted marker list.
46  * A bit kludgy to do it here, but this is the most central place.
47  */
48  ((j_decompress_ptr)cinfo)->marker_list = nullptr;
49  }
50  else
51  {
52  cinfo->global_state = CSTATE_START;
53  }
54 }
55 
56 /*
57  * Destruction of a JPEG object.
58  *
59  * Everything gets deallocated except the master jpeg_compress_struct itself
60  * and the error manager struct. Both of these are supplied by the application
61  * and must be freed, if necessary, by the application. (Often they are on
62  * the stack and so don't need to be freed anyway.)
63  * Closing a data source or destination, if necessary, is the application's
64  * responsibility.
65  */
66 
67 GLOBAL(void)
69 {
70  /* We need only tell the memory manager to release everything. */
71  /* NB: mem pointer is nullptr if memory mgr failed to initialize. */
72  if (cinfo->mem != nullptr) (*cinfo->mem->self_destruct)(cinfo);
73  cinfo->mem = nullptr; /* be safe if jpeg_destroy is called twice */
74  cinfo->global_state = 0; /* mark it destroyed */
75 }
76 
77 /*
78  * Convenience routines for allocating quantization and Huffman tables.
79  * (Would jutils.c be a more reasonable place to put these?)
80  */
81 
84 {
85  JQUANT_TBL* tbl;
86 
87  tbl = (JQUANT_TBL*)(*cinfo->mem->alloc_small)(
89  tbl->sent_table = FALSE; /* make sure this is false in any new table */
90  return tbl;
91 }
92 
95 {
96  JHUFF_TBL* tbl;
97 
98  tbl = (JHUFF_TBL*)(*cinfo->mem->alloc_small)(
100  tbl->sent_table = FALSE; /* make sure this is false in any new table */
101  return tbl;
102 }
#define CSTATE_START
Definition: jpegint.h:22
#define JPOOL_PERMANENT
Definition: mrpt_jpeglib.h:749
boolean sent_table
Definition: mrpt_jpeglib.h:87
jpeg_destroy(j_common_ptr cinfo)
Definition: jcomapi.cpp:68
#define SIZEOF(object)
Definition: jinclude.h:74
struct jpeg_decompress_struct * j_decompress_ptr
Definition: mrpt_jpeglib.h:260
jpeg_abort(j_common_ptr cinfo)
Definition: jcomapi.cpp:26
#define FALSE
Definition: jmorecfg.h:216
#define DSTATE_START
Definition: jpegint.h:26
jpeg_alloc_huff_table(j_common_ptr cinfo)
Definition: jcomapi.cpp:94
#define JPOOL_NUMPOOLS
Definition: mrpt_jpeglib.h:751
jpeg_alloc_quant_table(j_common_ptr cinfo)
Definition: jcomapi.cpp:83
boolean sent_table
Definition: mrpt_jpeglib.h:103
#define GLOBAL(type)
Definition: jmorecfg.h:177



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019