ReactOS 0.4.15-dev-8219-ge8b88cf
jcapistd.c
Go to the documentation of this file.
1/*
2 * jcapistd.c
3 *
4 * Copyright (C) 1994-1996, Thomas G. Lane.
5 * Modified 2013 by Guido Vollbeding.
6 * This file is part of the Independent JPEG Group's software.
7 * For conditions of distribution and use, see the accompanying README file.
8 *
9 * This file contains application interface code for the compression half
10 * of the JPEG library. These are the "standard" API routines that are
11 * used in the normal full-compression case. They are not used by a
12 * transcoding-only application. Note that if an application links in
13 * jpeg_start_compress, it will end up linking in the entire compressor.
14 * We thus must separate this file from jcapimin.c to avoid linking the
15 * whole compression library into a transcoder.
16 */
17
18#define JPEG_INTERNALS
19#include "jinclude.h"
20#include "jpeglib.h"
21
22
23/*
24 * Compression initialization.
25 * Before calling this, all parameters and a data destination must be set up.
26 *
27 * We require a write_all_tables parameter as a failsafe check when writing
28 * multiple datastreams from the same compression object. Since prior runs
29 * will have left all the tables marked sent_table=TRUE, a subsequent run
30 * would emit an abbreviated stream (no tables) by default. This may be what
31 * is wanted, but for safety's sake it should not be the default behavior:
32 * programmers should have to make a deliberate choice to emit abbreviated
33 * images. Therefore the documentation and examples should encourage people
34 * to pass write_all_tables=TRUE; then it will take active thought to do the
35 * wrong thing.
36 */
37
38GLOBAL(void)
40{
41 if (cinfo->global_state != CSTATE_START)
42 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
43
45 jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
46
47 /* (Re)initialize error mgr and destination modules */
48 (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
49 (*cinfo->dest->init_destination) (cinfo);
50 /* Perform master selection of active modules */
52 /* Set up for the first pass */
53 (*cinfo->master->prepare_for_pass) (cinfo);
54 /* Ready for application to drive first pass through jpeg_write_scanlines
55 * or jpeg_write_raw_data.
56 */
57 cinfo->next_scanline = 0;
58 cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
59}
60
61
62/*
63 * Write some scanlines of data to the JPEG compressor.
64 *
65 * The return value will be the number of lines actually written.
66 * This should be less than the supplied num_lines only in case that
67 * the data destination module has requested suspension of the compressor,
68 * or if more than image_height scanlines are passed in.
69 *
70 * Note: we warn about excess calls to jpeg_write_scanlines() since
71 * this likely signals an application programmer error. However,
72 * excess scanlines passed in the last valid call are *silently* ignored,
73 * so that the application need not adjust num_lines for end-of-image
74 * when using a multiple-scanline buffer.
75 */
76
80{
81 JDIMENSION row_ctr, rows_left;
82
83 if (cinfo->global_state != CSTATE_SCANNING)
84 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
85 if (cinfo->next_scanline >= cinfo->image_height)
86 WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
87
88 /* Call progress monitor hook if present */
89 if (cinfo->progress != NULL) {
90 cinfo->progress->pass_counter = (long) cinfo->next_scanline;
91 cinfo->progress->pass_limit = (long) cinfo->image_height;
92 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
93 }
94
95 /* Give master control module another chance if this is first call to
96 * jpeg_write_scanlines. This lets output of the frame/scan headers be
97 * delayed so that application can write COM, etc, markers between
98 * jpeg_start_compress and jpeg_write_scanlines.
99 */
100 if (cinfo->master->call_pass_startup)
101 (*cinfo->master->pass_startup) (cinfo);
102
103 /* Ignore any extra scanlines at bottom of image. */
104 rows_left = cinfo->image_height - cinfo->next_scanline;
105 if (num_lines > rows_left)
106 num_lines = rows_left;
107
108 row_ctr = 0;
109 (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
110 cinfo->next_scanline += row_ctr;
111 return row_ctr;
112}
113
114
115/*
116 * Alternate entry point to write raw data.
117 * Processes exactly one iMCU row per call, unless suspended.
118 */
119
123{
124 JDIMENSION lines_per_iMCU_row;
125
126 if (cinfo->global_state != CSTATE_RAW_OK)
127 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
128 if (cinfo->next_scanline >= cinfo->image_height) {
129 WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
130 return 0;
131 }
132
133 /* Call progress monitor hook if present */
134 if (cinfo->progress != NULL) {
135 cinfo->progress->pass_counter = (long) cinfo->next_scanline;
136 cinfo->progress->pass_limit = (long) cinfo->image_height;
137 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
138 }
139
140 /* Give master control module another chance if this is first call to
141 * jpeg_write_raw_data. This lets output of the frame/scan headers be
142 * delayed so that application can write COM, etc, markers between
143 * jpeg_start_compress and jpeg_write_raw_data.
144 */
145 if (cinfo->master->call_pass_startup)
146 (*cinfo->master->pass_startup) (cinfo);
147
148 /* Verify that at least one iMCU row has been passed. */
149 lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size;
150 if (num_lines < lines_per_iMCU_row)
151 ERREXIT(cinfo, JERR_BUFFER_SIZE);
152
153 /* Directly compress the row. */
154 if (! (*cinfo->coef->compress_data) (cinfo, data)) {
155 /* If compressor did not consume the whole row, suspend processing. */
156 return 0;
157 }
158
159 /* OK, we processed one iMCU row. */
160 cinfo->next_scanline += lines_per_iMCU_row;
161 return lines_per_iMCU_row;
162}
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress)
Definition: jcapimin.c:127
jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data, JDIMENSION num_lines)
Definition: jcapistd.c:121
jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)
Definition: jcapistd.c:78
jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
Definition: jcapistd.c:39
jinit_compress_master(j_compress_ptr cinfo)
Definition: jcinit.c:193
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:212
#define WARNMS(cinfo, code)
Definition: jerror.h:251
unsigned int JDIMENSION
Definition: jmorecfg.h:229
#define GLOBAL(type)
Definition: jmorecfg.h:291
#define CSTATE_RAW_OK
Definition: jpegint.h:28
#define CSTATE_START
Definition: jpegint.h:26
#define CSTATE_SCANNING
Definition: jpegint.h:27
JSAMPARRAY scanlines
Definition: jpeglib.h:1016
JSAMPARRAY * JSAMPIMAGE
Definition: jpeglib.h:77
boolean write_all_tables
Definition: jpeglib.h:1014
JSAMPARRAY JDIMENSION num_lines
Definition: jpeglib.h:1017
JSAMPROW * JSAMPARRAY
Definition: jpeglib.h:76
#define long
Definition: qsort.c:33
#define ERREXIT(msg)
Definition: rdjpgcom.c:72