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



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020