image_intensities 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/image_intensities/Makefile +73 -4
- data/ext/image_intensities/turbojpeg/cderror.h +137 -0
- data/ext/image_intensities/turbojpeg/cdjpeg.h +157 -0
- data/ext/image_intensities/turbojpeg/cmyk.h +61 -0
- data/ext/image_intensities/turbojpeg/jaricom.c +157 -0
- data/ext/image_intensities/turbojpeg/jcapimin.c +295 -0
- data/ext/image_intensities/turbojpeg/jcapistd.c +162 -0
- data/ext/image_intensities/turbojpeg/jcarith.c +932 -0
- data/ext/image_intensities/turbojpeg/jccoefct.c +449 -0
- data/ext/image_intensities/turbojpeg/jccolext.c +144 -0
- data/ext/image_intensities/turbojpeg/jccolor.c +710 -0
- data/ext/image_intensities/turbojpeg/jcdctmgr.c +721 -0
- data/ext/image_intensities/turbojpeg/jchuff.c +1096 -0
- data/ext/image_intensities/turbojpeg/jchuff.h +42 -0
- data/ext/image_intensities/turbojpeg/jcicc.c +105 -0
- data/ext/image_intensities/turbojpeg/jcinit.c +77 -0
- data/ext/image_intensities/turbojpeg/jcmainct.c +162 -0
- data/ext/image_intensities/turbojpeg/jcmarker.c +664 -0
- data/ext/image_intensities/turbojpeg/jcmaster.c +640 -0
- data/ext/image_intensities/turbojpeg/jcomapi.c +109 -0
- data/ext/image_intensities/turbojpeg/jconfig.h +73 -0
- data/ext/image_intensities/turbojpeg/jconfigint.h +31 -0
- data/ext/image_intensities/turbojpeg/jcparam.c +541 -0
- data/ext/image_intensities/turbojpeg/jcphuff.c +1105 -0
- data/ext/image_intensities/turbojpeg/jcprepct.c +351 -0
- data/ext/image_intensities/turbojpeg/jcsample.c +539 -0
- data/ext/image_intensities/turbojpeg/jctrans.c +400 -0
- data/ext/image_intensities/turbojpeg/jdapimin.c +407 -0
- data/ext/image_intensities/turbojpeg/jdapistd.c +639 -0
- data/ext/image_intensities/turbojpeg/jdarith.c +773 -0
- data/ext/image_intensities/turbojpeg/jdatadst-tj.c +203 -0
- data/ext/image_intensities/turbojpeg/jdatadst.c +293 -0
- data/ext/image_intensities/turbojpeg/jdatasrc-tj.c +194 -0
- data/ext/image_intensities/turbojpeg/jdatasrc.c +295 -0
- data/ext/image_intensities/turbojpeg/jdcoefct.c +692 -0
- data/ext/image_intensities/turbojpeg/jdcoefct.h +82 -0
- data/ext/image_intensities/turbojpeg/jdcol565.c +384 -0
- data/ext/image_intensities/turbojpeg/jdcolext.c +143 -0
- data/ext/image_intensities/turbojpeg/jdcolor.c +883 -0
- data/ext/image_intensities/turbojpeg/jdct.h +208 -0
- data/ext/image_intensities/turbojpeg/jddctmgr.c +352 -0
- data/ext/image_intensities/turbojpeg/jdhuff.c +831 -0
- data/ext/image_intensities/turbojpeg/jdhuff.h +238 -0
- data/ext/image_intensities/turbojpeg/jdicc.c +171 -0
- data/ext/image_intensities/turbojpeg/jdinput.c +408 -0
- data/ext/image_intensities/turbojpeg/jdmainct.c +460 -0
- data/ext/image_intensities/turbojpeg/jdmainct.h +71 -0
- data/ext/image_intensities/turbojpeg/jdmarker.c +1377 -0
- data/ext/image_intensities/turbojpeg/jdmaster.c +737 -0
- data/ext/image_intensities/turbojpeg/jdmaster.h +28 -0
- data/ext/image_intensities/turbojpeg/jdmerge.c +617 -0
- data/ext/image_intensities/turbojpeg/jdmrg565.c +354 -0
- data/ext/image_intensities/turbojpeg/jdmrgext.c +184 -0
- data/ext/image_intensities/turbojpeg/jdphuff.c +687 -0
- data/ext/image_intensities/turbojpeg/jdpostct.c +294 -0
- data/ext/image_intensities/turbojpeg/jdsample.c +518 -0
- data/ext/image_intensities/turbojpeg/jdsample.h +50 -0
- data/ext/image_intensities/turbojpeg/jdtrans.c +155 -0
- data/ext/image_intensities/turbojpeg/jerror.c +251 -0
- data/ext/image_intensities/turbojpeg/jfdctflt.c +169 -0
- data/ext/image_intensities/turbojpeg/jfdctfst.c +227 -0
- data/ext/image_intensities/turbojpeg/jfdctint.c +288 -0
- data/ext/image_intensities/turbojpeg/jidctflt.c +240 -0
- data/ext/image_intensities/turbojpeg/jidctfst.c +371 -0
- data/ext/image_intensities/turbojpeg/jidctint.c +2627 -0
- data/ext/image_intensities/turbojpeg/jidctred.c +409 -0
- data/ext/image_intensities/turbojpeg/jinclude.h +88 -0
- data/ext/image_intensities/turbojpeg/jmemmgr.c +1179 -0
- data/ext/image_intensities/turbojpeg/jmemnobs.c +115 -0
- data/ext/image_intensities/turbojpeg/jmemsys.h +178 -0
- data/ext/image_intensities/turbojpeg/jpeg_nbits_table.h +4098 -0
- data/ext/image_intensities/turbojpeg/jpegcomp.h +31 -0
- data/ext/image_intensities/turbojpeg/jquant1.c +859 -0
- data/ext/image_intensities/turbojpeg/jquant2.c +1285 -0
- data/ext/image_intensities/turbojpeg/jsimd.h +117 -0
- data/ext/image_intensities/turbojpeg/jsimd_none.c +418 -0
- data/ext/image_intensities/turbojpeg/jsimddct.h +70 -0
- data/ext/image_intensities/turbojpeg/jstdhuff.c +143 -0
- data/ext/image_intensities/turbojpeg/jutils.c +133 -0
- data/ext/image_intensities/turbojpeg/jversion.h +52 -0
- data/ext/image_intensities/turbojpeg/libturbojpeg.a +0 -0
- data/ext/image_intensities/turbojpeg/rdbmp.c +689 -0
- data/ext/image_intensities/turbojpeg/rdppm.c +766 -0
- data/ext/image_intensities/turbojpeg/tjutil.h +47 -0
- data/ext/image_intensities/turbojpeg/transupp.c +1628 -0
- data/ext/image_intensities/turbojpeg/transupp.h +210 -0
- data/ext/image_intensities/turbojpeg/turbojpeg.c +2150 -0
- data/ext/image_intensities/turbojpeg/wrbmp.c +558 -0
- data/ext/image_intensities/turbojpeg/wrppm.c +365 -0
- data/image_intensities.gemspec +1 -1
- data/lib/image_intensities/version.rb +1 -1
- metadata +91 -3
@@ -0,0 +1,295 @@
|
|
1
|
+
/*
|
2
|
+
* jcapimin.c
|
3
|
+
*
|
4
|
+
* This file was part of the Independent JPEG Group's software:
|
5
|
+
* Copyright (C) 1994-1998, Thomas G. Lane.
|
6
|
+
* Modified 2003-2010 by Guido Vollbeding.
|
7
|
+
* It was modified by The libjpeg-turbo Project to include only code relevant
|
8
|
+
* to libjpeg-turbo.
|
9
|
+
* For conditions of distribution and use, see the accompanying README.ijg
|
10
|
+
* file.
|
11
|
+
*
|
12
|
+
* This file contains application interface code for the compression half
|
13
|
+
* of the JPEG library. These are the "minimum" API routines that may be
|
14
|
+
* needed in either the normal full-compression case or the transcoding-only
|
15
|
+
* case.
|
16
|
+
*
|
17
|
+
* Most of the routines intended to be called directly by an application
|
18
|
+
* are in this file or in jcapistd.c. But also see jcparam.c for
|
19
|
+
* parameter-setup helper routines, jcomapi.c for routines shared by
|
20
|
+
* compression and decompression, and jctrans.c for the transcoding case.
|
21
|
+
*/
|
22
|
+
|
23
|
+
#define JPEG_INTERNALS
|
24
|
+
#include "jinclude.h"
|
25
|
+
#include "jpeglib.h"
|
26
|
+
|
27
|
+
|
28
|
+
/*
|
29
|
+
* Initialization of a JPEG compression object.
|
30
|
+
* The error manager must already be set up (in case memory manager fails).
|
31
|
+
*/
|
32
|
+
|
33
|
+
GLOBAL(void)
|
34
|
+
jpeg_CreateCompress(j_compress_ptr cinfo, int version, size_t structsize)
|
35
|
+
{
|
36
|
+
int i;
|
37
|
+
|
38
|
+
/* Guard against version mismatches between library and caller. */
|
39
|
+
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
|
40
|
+
if (version != JPEG_LIB_VERSION)
|
41
|
+
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
|
42
|
+
if (structsize != sizeof(struct jpeg_compress_struct))
|
43
|
+
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
|
44
|
+
(int)sizeof(struct jpeg_compress_struct), (int)structsize);
|
45
|
+
|
46
|
+
/* For debugging purposes, we zero the whole master structure.
|
47
|
+
* But the application has already set the err pointer, and may have set
|
48
|
+
* client_data, so we have to save and restore those fields.
|
49
|
+
* Note: if application hasn't set client_data, tools like Purify may
|
50
|
+
* complain here.
|
51
|
+
*/
|
52
|
+
{
|
53
|
+
struct jpeg_error_mgr *err = cinfo->err;
|
54
|
+
void *client_data = cinfo->client_data; /* ignore Purify complaint here */
|
55
|
+
MEMZERO(cinfo, sizeof(struct jpeg_compress_struct));
|
56
|
+
cinfo->err = err;
|
57
|
+
cinfo->client_data = client_data;
|
58
|
+
}
|
59
|
+
cinfo->is_decompressor = FALSE;
|
60
|
+
|
61
|
+
/* Initialize a memory manager instance for this object */
|
62
|
+
jinit_memory_mgr((j_common_ptr)cinfo);
|
63
|
+
|
64
|
+
/* Zero out pointers to permanent structures. */
|
65
|
+
cinfo->progress = NULL;
|
66
|
+
cinfo->dest = NULL;
|
67
|
+
|
68
|
+
cinfo->comp_info = NULL;
|
69
|
+
|
70
|
+
for (i = 0; i < NUM_QUANT_TBLS; i++) {
|
71
|
+
cinfo->quant_tbl_ptrs[i] = NULL;
|
72
|
+
#if JPEG_LIB_VERSION >= 70
|
73
|
+
cinfo->q_scale_factor[i] = 100;
|
74
|
+
#endif
|
75
|
+
}
|
76
|
+
|
77
|
+
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
78
|
+
cinfo->dc_huff_tbl_ptrs[i] = NULL;
|
79
|
+
cinfo->ac_huff_tbl_ptrs[i] = NULL;
|
80
|
+
}
|
81
|
+
|
82
|
+
#if JPEG_LIB_VERSION >= 80
|
83
|
+
/* Must do it here for emit_dqt in case jpeg_write_tables is used */
|
84
|
+
cinfo->block_size = DCTSIZE;
|
85
|
+
cinfo->natural_order = jpeg_natural_order;
|
86
|
+
cinfo->lim_Se = DCTSIZE2 - 1;
|
87
|
+
#endif
|
88
|
+
|
89
|
+
cinfo->script_space = NULL;
|
90
|
+
|
91
|
+
cinfo->input_gamma = 1.0; /* in case application forgets */
|
92
|
+
|
93
|
+
/* OK, I'm ready */
|
94
|
+
cinfo->global_state = CSTATE_START;
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
/*
|
99
|
+
* Destruction of a JPEG compression object
|
100
|
+
*/
|
101
|
+
|
102
|
+
GLOBAL(void)
|
103
|
+
jpeg_destroy_compress(j_compress_ptr cinfo)
|
104
|
+
{
|
105
|
+
jpeg_destroy((j_common_ptr)cinfo); /* use common routine */
|
106
|
+
}
|
107
|
+
|
108
|
+
|
109
|
+
/*
|
110
|
+
* Abort processing of a JPEG compression operation,
|
111
|
+
* but don't destroy the object itself.
|
112
|
+
*/
|
113
|
+
|
114
|
+
GLOBAL(void)
|
115
|
+
jpeg_abort_compress(j_compress_ptr cinfo)
|
116
|
+
{
|
117
|
+
jpeg_abort((j_common_ptr)cinfo); /* use common routine */
|
118
|
+
}
|
119
|
+
|
120
|
+
|
121
|
+
/*
|
122
|
+
* Forcibly suppress or un-suppress all quantization and Huffman tables.
|
123
|
+
* Marks all currently defined tables as already written (if suppress)
|
124
|
+
* or not written (if !suppress). This will control whether they get emitted
|
125
|
+
* by a subsequent jpeg_start_compress call.
|
126
|
+
*
|
127
|
+
* This routine is exported for use by applications that want to produce
|
128
|
+
* abbreviated JPEG datastreams. It logically belongs in jcparam.c, but
|
129
|
+
* since it is called by jpeg_start_compress, we put it here --- otherwise
|
130
|
+
* jcparam.o would be linked whether the application used it or not.
|
131
|
+
*/
|
132
|
+
|
133
|
+
GLOBAL(void)
|
134
|
+
jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress)
|
135
|
+
{
|
136
|
+
int i;
|
137
|
+
JQUANT_TBL *qtbl;
|
138
|
+
JHUFF_TBL *htbl;
|
139
|
+
|
140
|
+
for (i = 0; i < NUM_QUANT_TBLS; i++) {
|
141
|
+
if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
|
142
|
+
qtbl->sent_table = suppress;
|
143
|
+
}
|
144
|
+
|
145
|
+
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
146
|
+
if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
|
147
|
+
htbl->sent_table = suppress;
|
148
|
+
if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
|
149
|
+
htbl->sent_table = suppress;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
/*
|
155
|
+
* Finish JPEG compression.
|
156
|
+
*
|
157
|
+
* If a multipass operating mode was selected, this may do a great deal of
|
158
|
+
* work including most of the actual output.
|
159
|
+
*/
|
160
|
+
|
161
|
+
GLOBAL(void)
|
162
|
+
jpeg_finish_compress(j_compress_ptr cinfo)
|
163
|
+
{
|
164
|
+
JDIMENSION iMCU_row;
|
165
|
+
|
166
|
+
if (cinfo->global_state == CSTATE_SCANNING ||
|
167
|
+
cinfo->global_state == CSTATE_RAW_OK) {
|
168
|
+
/* Terminate first pass */
|
169
|
+
if (cinfo->next_scanline < cinfo->image_height)
|
170
|
+
ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
|
171
|
+
(*cinfo->master->finish_pass) (cinfo);
|
172
|
+
} else if (cinfo->global_state != CSTATE_WRCOEFS)
|
173
|
+
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
174
|
+
/* Perform any remaining passes */
|
175
|
+
while (!cinfo->master->is_last_pass) {
|
176
|
+
(*cinfo->master->prepare_for_pass) (cinfo);
|
177
|
+
for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
|
178
|
+
if (cinfo->progress != NULL) {
|
179
|
+
cinfo->progress->pass_counter = (long)iMCU_row;
|
180
|
+
cinfo->progress->pass_limit = (long)cinfo->total_iMCU_rows;
|
181
|
+
(*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
|
182
|
+
}
|
183
|
+
/* We bypass the main controller and invoke coef controller directly;
|
184
|
+
* all work is being done from the coefficient buffer.
|
185
|
+
*/
|
186
|
+
if (!(*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE)NULL))
|
187
|
+
ERREXIT(cinfo, JERR_CANT_SUSPEND);
|
188
|
+
}
|
189
|
+
(*cinfo->master->finish_pass) (cinfo);
|
190
|
+
}
|
191
|
+
/* Write EOI, do final cleanup */
|
192
|
+
(*cinfo->marker->write_file_trailer) (cinfo);
|
193
|
+
(*cinfo->dest->term_destination) (cinfo);
|
194
|
+
/* We can use jpeg_abort to release memory and reset global_state */
|
195
|
+
jpeg_abort((j_common_ptr)cinfo);
|
196
|
+
}
|
197
|
+
|
198
|
+
|
199
|
+
/*
|
200
|
+
* Write a special marker.
|
201
|
+
* This is only recommended for writing COM or APPn markers.
|
202
|
+
* Must be called after jpeg_start_compress() and before
|
203
|
+
* first call to jpeg_write_scanlines() or jpeg_write_raw_data().
|
204
|
+
*/
|
205
|
+
|
206
|
+
GLOBAL(void)
|
207
|
+
jpeg_write_marker(j_compress_ptr cinfo, int marker, const JOCTET *dataptr,
|
208
|
+
unsigned int datalen)
|
209
|
+
{
|
210
|
+
void (*write_marker_byte) (j_compress_ptr info, int val);
|
211
|
+
|
212
|
+
if (cinfo->next_scanline != 0 ||
|
213
|
+
(cinfo->global_state != CSTATE_SCANNING &&
|
214
|
+
cinfo->global_state != CSTATE_RAW_OK &&
|
215
|
+
cinfo->global_state != CSTATE_WRCOEFS))
|
216
|
+
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
217
|
+
|
218
|
+
(*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
|
219
|
+
write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
|
220
|
+
while (datalen--) {
|
221
|
+
(*write_marker_byte) (cinfo, *dataptr);
|
222
|
+
dataptr++;
|
223
|
+
}
|
224
|
+
}
|
225
|
+
|
226
|
+
/* Same, but piecemeal. */
|
227
|
+
|
228
|
+
GLOBAL(void)
|
229
|
+
jpeg_write_m_header(j_compress_ptr cinfo, int marker, unsigned int datalen)
|
230
|
+
{
|
231
|
+
if (cinfo->next_scanline != 0 ||
|
232
|
+
(cinfo->global_state != CSTATE_SCANNING &&
|
233
|
+
cinfo->global_state != CSTATE_RAW_OK &&
|
234
|
+
cinfo->global_state != CSTATE_WRCOEFS))
|
235
|
+
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
236
|
+
|
237
|
+
(*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
|
238
|
+
}
|
239
|
+
|
240
|
+
GLOBAL(void)
|
241
|
+
jpeg_write_m_byte(j_compress_ptr cinfo, int val)
|
242
|
+
{
|
243
|
+
(*cinfo->marker->write_marker_byte) (cinfo, val);
|
244
|
+
}
|
245
|
+
|
246
|
+
|
247
|
+
/*
|
248
|
+
* Alternate compression function: just write an abbreviated table file.
|
249
|
+
* Before calling this, all parameters and a data destination must be set up.
|
250
|
+
*
|
251
|
+
* To produce a pair of files containing abbreviated tables and abbreviated
|
252
|
+
* image data, one would proceed as follows:
|
253
|
+
*
|
254
|
+
* initialize JPEG object
|
255
|
+
* set JPEG parameters
|
256
|
+
* set destination to table file
|
257
|
+
* jpeg_write_tables(cinfo);
|
258
|
+
* set destination to image file
|
259
|
+
* jpeg_start_compress(cinfo, FALSE);
|
260
|
+
* write data...
|
261
|
+
* jpeg_finish_compress(cinfo);
|
262
|
+
*
|
263
|
+
* jpeg_write_tables has the side effect of marking all tables written
|
264
|
+
* (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress
|
265
|
+
* will not re-emit the tables unless it is passed write_all_tables=TRUE.
|
266
|
+
*/
|
267
|
+
|
268
|
+
GLOBAL(void)
|
269
|
+
jpeg_write_tables(j_compress_ptr cinfo)
|
270
|
+
{
|
271
|
+
if (cinfo->global_state != CSTATE_START)
|
272
|
+
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
273
|
+
|
274
|
+
/* (Re)initialize error mgr and destination modules */
|
275
|
+
(*cinfo->err->reset_error_mgr) ((j_common_ptr)cinfo);
|
276
|
+
(*cinfo->dest->init_destination) (cinfo);
|
277
|
+
/* Initialize the marker writer ... bit of a crock to do it here. */
|
278
|
+
jinit_marker_writer(cinfo);
|
279
|
+
/* Write them tables! */
|
280
|
+
(*cinfo->marker->write_tables_only) (cinfo);
|
281
|
+
/* And clean up. */
|
282
|
+
(*cinfo->dest->term_destination) (cinfo);
|
283
|
+
/*
|
284
|
+
* In library releases up through v6a, we called jpeg_abort() here to free
|
285
|
+
* any working memory allocated by the destination manager and marker
|
286
|
+
* writer. Some applications had a problem with that: they allocated space
|
287
|
+
* of their own from the library memory manager, and didn't want it to go
|
288
|
+
* away during write_tables. So now we do nothing. This will cause a
|
289
|
+
* memory leak if an app calls write_tables repeatedly without doing a full
|
290
|
+
* compression cycle or otherwise resetting the JPEG object. However, that
|
291
|
+
* seems less bad than unexpectedly freeing memory in the normal case.
|
292
|
+
* An app that prefers the old behavior can call jpeg_abort for itself after
|
293
|
+
* each call to jpeg_write_tables().
|
294
|
+
*/
|
295
|
+
}
|
@@ -0,0 +1,162 @@
|
|
1
|
+
/*
|
2
|
+
* jcapistd.c
|
3
|
+
*
|
4
|
+
* Copyright (C) 1994-1996, Thomas G. Lane.
|
5
|
+
* This file is part of the Independent JPEG Group's software.
|
6
|
+
* For conditions of distribution and use, see the accompanying README.ijg
|
7
|
+
* 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
|
+
|
38
|
+
GLOBAL(void)
|
39
|
+
jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
|
40
|
+
{
|
41
|
+
if (cinfo->global_state != CSTATE_START)
|
42
|
+
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
43
|
+
|
44
|
+
if (write_all_tables)
|
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 */
|
51
|
+
jinit_compress_master(cinfo);
|
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
|
+
|
77
|
+
GLOBAL(JDIMENSION)
|
78
|
+
jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines,
|
79
|
+
JDIMENSION num_lines)
|
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
|
+
|
120
|
+
GLOBAL(JDIMENSION)
|
121
|
+
jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
|
122
|
+
JDIMENSION num_lines)
|
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 * DCTSIZE;
|
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
|
+
}
|