Main MRPT website > C++ reference for MRPT 1.9.9
jcapistd.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  * Compression initialization.
16  * Before calling this, all parameters and a data destination must be set up.
17  *
18  * We require a write_all_tables parameter as a failsafe check when writing
19  * multiple datastreams from the same compression object. Since prior runs
20  * will have left all the tables marked sent_table=TRUE, a subsequent run
21  * would emit an abbreviated stream (no tables) by default. This may be what
22  * is wanted, but for safety's sake it should not be the default behavior:
23  * programmers should have to make a deliberate choice to emit abbreviated
24  * images. Therefore the documentation and examples should encourage people
25  * to pass write_all_tables=TRUE; then it will take active thought to do the
26  * wrong thing.
27  */
28 
29 GLOBAL(void)
30 jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
31 {
32  if (cinfo->global_state != CSTATE_START)
33  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
34 
35  if (write_all_tables)
36  jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
37 
38  /* (Re)initialize error mgr and destination modules */
39  (*cinfo->err->reset_error_mgr)((j_common_ptr)cinfo);
40  (*cinfo->dest->init_destination)(cinfo);
41  /* Perform master selection of active modules */
42  jinit_compress_master(cinfo);
43  /* Set up for the first pass */
44  (*cinfo->master->prepare_for_pass)(cinfo);
45  /* Ready for application to drive first pass through jpeg_write_scanlines
46  * or jpeg_write_raw_data.
47  */
48  cinfo->next_scanline = 0;
49  cinfo->global_state =
50  (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
51 }
52 
53 /*
54  * Write some scanlines of data to the JPEG compressor.
55  *
56  * The return value will be the number of lines actually written.
57  * This should be less than the supplied num_lines only in case that
58  * the data destination module has requested suspension of the compressor,
59  * or if more than image_height scanlines are passed in.
60  *
61  * Note: we warn about excess calls to jpeg_write_scanlines() since
62  * this likely signals an application programmer error. However,
63  * excess scanlines passed in the last valid call are *silently* ignored,
64  * so that the application need not adjust num_lines for end-of-image
65  * when using a multiple-scanline buffer.
66  */
67 
70  j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)
71 {
72  JDIMENSION row_ctr, rows_left;
73 
74  if (cinfo->global_state != CSTATE_SCANNING)
75  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
76  if (cinfo->next_scanline >= cinfo->image_height)
77  WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
78 
79  /* Call progress monitor hook if present */
80  if (cinfo->progress != nullptr)
81  {
82  cinfo->progress->pass_counter = (long)cinfo->next_scanline;
83  cinfo->progress->pass_limit = (long)cinfo->image_height;
84  (*cinfo->progress->progress_monitor)((j_common_ptr)cinfo);
85  }
86 
87  /* Give master control module another chance if this is first call to
88  * jpeg_write_scanlines. This lets output of the frame/scan headers be
89  * delayed so that application can write COM, etc, markers between
90  * jpeg_start_compress and jpeg_write_scanlines.
91  */
92  if (cinfo->master->call_pass_startup) (*cinfo->master->pass_startup)(cinfo);
93 
94  /* Ignore any extra scanlines at bottom of image. */
95  rows_left = cinfo->image_height - cinfo->next_scanline;
96  if (num_lines > rows_left) num_lines = rows_left;
97 
98  row_ctr = 0;
99  (*cinfo->main->process_data)(cinfo, scanlines, &row_ctr, num_lines);
100  cinfo->next_scanline += row_ctr;
101  return row_ctr;
102 }
103 
104 /*
105  * Alternate entry point to write raw data.
106  * Processes exactly one iMCU row per call, unless suspended.
107  */
108 
111 {
112  JDIMENSION lines_per_iMCU_row;
113 
114  if (cinfo->global_state != CSTATE_RAW_OK)
115  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
116  if (cinfo->next_scanline >= cinfo->image_height)
117  {
118  WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
119  return 0;
120  }
121 
122  /* Call progress monitor hook if present */
123  if (cinfo->progress != nullptr)
124  {
125  cinfo->progress->pass_counter = (long)cinfo->next_scanline;
126  cinfo->progress->pass_limit = (long)cinfo->image_height;
127  (*cinfo->progress->progress_monitor)((j_common_ptr)cinfo);
128  }
129 
130  /* Give master control module another chance if this is first call to
131  * jpeg_write_raw_data. This lets output of the frame/scan headers be
132  * delayed so that application can write COM, etc, markers between
133  * jpeg_start_compress and jpeg_write_raw_data.
134  */
135  if (cinfo->master->call_pass_startup) (*cinfo->master->pass_startup)(cinfo);
136 
137  /* Verify that at least one iMCU row has been passed. */
138  lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
139  if (num_lines < lines_per_iMCU_row) ERREXIT(cinfo, JERR_BUFFER_SIZE);
140 
141  /* Directly compress the row. */
142  if (!(*cinfo->coef->compress_data)(cinfo, data))
143  {
144  /* If compressor did not consume the whole row, suspend processing. */
145  return 0;
146  }
147 
148  /* OK, we processed one iMCU row. */
149  cinfo->next_scanline += lines_per_iMCU_row;
150  return lines_per_iMCU_row;
151 }
#define CSTATE_START
Definition: jpegint.h:22
#define DCTSIZE
Definition: mrpt_jpeglib.h:36
#define ERREXIT(cinfo, code)
Definition: jerror.h:451
jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress)
Definition: jcapimin.cpp:108
#define CSTATE_RAW_OK
Definition: jpegint.h:24
#define CSTATE_SCANNING
Definition: jpegint.h:23
jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)
Definition: jcapistd.cpp:69
jinit_compress_master(j_compress_ptr cinfo)
Definition: jcinit.cpp:21
#define FALSE
Definition: jmorecfg.h:216
JSAMPROW * JSAMPARRAY
Definition: mrpt_jpeglib.h:61
#define WARNMS(cinfo, code)
Definition: jerror.h:482
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:454
JSAMPARRAY * JSAMPIMAGE
Definition: mrpt_jpeglib.h:62
#define GLOBAL(type)
Definition: jmorecfg.h:177
unsigned int JDIMENSION
Definition: jmorecfg.h:161
jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data, JDIMENSION num_lines)
Definition: jcapistd.cpp:110
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3546
jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
Definition: jcapistd.cpp:30



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