Main MRPT website > C++ reference for MRPT 1.9.9
jdtrans.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 /* Forward declarations */
16 
17 /*
18  * Read the coefficient arrays from a JPEG file.
19  * jpeg_read_header must be completed before calling this.
20  *
21  * The entire image is read into a set of virtual coefficient-block arrays,
22  * one per component. The return value is a pointer to the array of
23  * virtual-array descriptors. These can be manipulated directly via the
24  * JPEG memory manager, or handed off to jpeg_write_coefficients().
25  * To release the memory occupied by the virtual arrays, call
26  * jpeg_finish_decompress() when done with the data.
27  *
28  * An alternative usage is to simply obtain access to the coefficient arrays
29  * during a buffered-image-mode decompression operation. This is allowed
30  * after any jpeg_finish_output() call. The arrays can be accessed until
31  * jpeg_finish_decompress() is called. (Note that any call to the library
32  * may reposition the arrays, so don't rely on access_virt_barray() results
33  * to stay valid across library calls.)
34  *
35  * Returns nullptr if suspended. This case need be checked only if
36  * a suspending data source is used.
37  */
38 
41 {
42  if (cinfo->global_state == DSTATE_READY)
43  {
44  /* First call: initialize active modules */
46  cinfo->global_state = DSTATE_RDCOEFS;
47  }
48  if (cinfo->global_state == DSTATE_RDCOEFS)
49  {
50  /* Absorb whole file into the coef buffer */
51  for (;;)
52  {
53  int retcode;
54  /* Call progress monitor hook if present */
55  if (cinfo->progress != nullptr)
56  (*cinfo->progress->progress_monitor)((j_common_ptr)cinfo);
57  /* Absorb some more input */
58  retcode = (*cinfo->inputctl->consume_input)(cinfo);
59  if (retcode == JPEG_SUSPENDED) return nullptr;
60  if (retcode == JPEG_REACHED_EOI) break;
61  /* Advance progress counter if appropriate */
62  if (cinfo->progress != nullptr &&
63  (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS))
64  {
65  if (++cinfo->progress->pass_counter >=
66  cinfo->progress->pass_limit)
67  {
68  /* startup underestimated number of scans; ratchet up one
69  * scan */
70  cinfo->progress->pass_limit += (long)cinfo->total_iMCU_rows;
71  }
72  }
73  }
74  /* Set state so that jpeg_finish_decompress does the right thing */
75  cinfo->global_state = DSTATE_STOPPING;
76  }
77  /* At this point we should be in state DSTATE_STOPPING if being used
78  * standalone, or in state DSTATE_BUFIMAGE if being invoked to get access
79  * to the coefficients during a full buffered-image-mode decompression.
80  */
81  if ((cinfo->global_state == DSTATE_STOPPING ||
82  cinfo->global_state == DSTATE_BUFIMAGE) &&
83  cinfo->buffered_image)
84  {
85  return cinfo->coef->coef_arrays;
86  }
87  /* Oops, improper usage */
88  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
89  return nullptr; /* keep compiler happy */
90 }
91 
92 /*
93  * Master selection of decompression modules for transcoding.
94  * This substitutes for jdmaster.c's initialization of the full decompressor.
95  */
96 
97 LOCAL(void)
99 {
100  /* This is effectively a buffered-image operation. */
101  cinfo->buffered_image = TRUE;
102 
103  /* Entropy decoding: either Huffman or arithmetic coding. */
104  if (cinfo->arith_code)
105  {
106  ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
107  }
108  else
109  {
110  if (cinfo->progressive_mode)
111  {
112 #ifdef D_PROGRESSIVE_SUPPORTED
113  jinit_phuff_decoder(cinfo);
114 #else
115  ERREXIT(cinfo, JERR_NOT_COMPILED);
116 #endif
117  }
118  else
119  jinit_huff_decoder(cinfo);
120  }
121 
122  /* Always get a full-image coefficient buffer. */
124 
125  /* We can now tell the memory manager to allocate virtual arrays. */
126  (*cinfo->mem->realize_virt_arrays)((j_common_ptr)cinfo);
127 
128  /* Initialize input side of decompressor to consume first scan. */
129  (*cinfo->inputctl->start_input_pass)(cinfo);
130 
131  /* Initialize progress monitoring. */
132  if (cinfo->progress != nullptr)
133  {
134  int nscans;
135  /* Estimate number of scans to set pass_limit. */
136  if (cinfo->progressive_mode)
137  {
138  /* Arbitrarily estimate 2 interleaved DC scans + 3 AC
139  * scans/component. */
140  nscans = 2 + 3 * cinfo->num_components;
141  }
142  else if (cinfo->inputctl->has_multiple_scans)
143  {
144  /* For a nonprogressive multiscan file, estimate 1 scan per
145  * component. */
146  nscans = cinfo->num_components;
147  }
148  else
149  {
150  nscans = 1;
151  }
152  cinfo->progress->pass_counter = 0L;
153  cinfo->progress->pass_limit = (long)cinfo->total_iMCU_rows * nscans;
154  cinfo->progress->completed_passes = 0;
155  cinfo->progress->total_passes = 1;
156  }
157 }
#define JPEG_ROW_COMPLETED
Definition: mrpt_jpeglib.h:999
transdecode_master_selection(j_decompress_ptr cinfo)
Definition: jdtrans.cpp:98
#define DSTATE_RDCOEFS
Definition: jpegint.h:35
#define DSTATE_BUFIMAGE
Definition: jpegint.h:33
#define ERREXIT(cinfo, code)
Definition: jerror.h:451
#define DSTATE_STOPPING
Definition: jpegint.h:36
LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo))
jpeg_read_coefficients(j_decompress_ptr cinfo)
Definition: jdtrans.cpp:40
jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
Definition: jdcoefct.cpp:723
jinit_huff_decoder(j_decompress_ptr cinfo)
Definition: jdhuff.cpp:669
#define JPEG_REACHED_EOI
Definition: mrpt_jpeglib.h:998
#define DSTATE_READY
Definition: jpegint.h:28
#define JPEG_SUSPENDED
Definition: mrpt_jpeglib.h:964
jinit_phuff_decoder(j_decompress_ptr cinfo)
Definition: jdphuff.cpp:674
#define JPP(arglist)
Definition: mrpt_jpeglib.h:815
#define TRUE
Definition: jmorecfg.h:219
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:454
#define GLOBAL(type)
Definition: jmorecfg.h:177
#define JPEG_REACHED_SOS
Definition: mrpt_jpeglib.h:997



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