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



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019