35 #if BITS_IN_JSAMPLE != 8 36 Sorry,
this code only copes with 8-bit JSAMPLEs.
52 { GRAYSCALE, MAPPEDGRAY, PSEUDOCOLOR, TRUECOLOR, DIRECTCOLOR } rle_kind;
62 typedef struct _rle_source_struct * rle_source_ptr;
64 typedef struct _rle_source_struct {
83 rle_source_ptr source = (rle_source_ptr) sinfo;
85 #ifdef PROGRESS_REPORT 90 source->header = *rle_hdr_init(NULL);
91 source->header.rle_file = source->
pub.input_file;
92 switch (rle_get_setup(&(source->header))) {
103 ERREXIT(cinfo, JERR_RLE_EMPTY);
109 ERREXIT(cinfo, JERR_RLE_BADERROR);
115 width = source->header.xmax - source->header.xmin + 1;
116 height = source->header.ymax - source->header.ymin + 1;
117 source->header.xmin = 0;
118 source->header.xmax = width-1;
120 cinfo->image_width =
width;
121 cinfo->image_height =
height;
122 cinfo->data_precision = 8;
124 if (source->header.ncolors == 1 && source->header.ncmap == 0) {
125 source->visual = GRAYSCALE;
126 TRACEMS2(cinfo, 1, JTRC_RLE_GRAY, width, height);
127 }
else if (source->header.ncolors == 1 && source->header.ncmap == 1) {
128 source->visual = MAPPEDGRAY;
129 TRACEMS3(cinfo, 1, JTRC_RLE_MAPGRAY, width, height,
130 1 << source->header.cmaplen);
131 }
else if (source->header.ncolors == 1 && source->header.ncmap == 3) {
132 source->visual = PSEUDOCOLOR;
133 TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height,
134 1 << source->header.cmaplen);
135 }
else if (source->header.ncolors == 3 && source->header.ncmap == 3) {
136 source->visual = TRUECOLOR;
137 TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height,
138 1 << source->header.cmaplen);
139 }
else if (source->header.ncolors == 3 && source->header.ncmap == 0) {
140 source->visual = DIRECTCOLOR;
141 TRACEMS2(cinfo, 1, JTRC_RLE, width, height);
143 ERREXIT(cinfo, JERR_RLE_UNSUPPORTED);
145 if (source->visual == GRAYSCALE || source->visual == MAPPEDGRAY) {
147 cinfo->input_components = 1;
149 cinfo->in_color_space =
JCS_RGB;
150 cinfo->input_components = 3;
157 if (source->visual != GRAYSCALE) {
158 source->rle_row = (rle_pixel**) (*cinfo->mem->alloc_sarray)
164 source->image = (*cinfo->mem->request_virt_sarray)
166 (
JDIMENSION) (width * source->header.ncolors),
169 #ifdef PROGRESS_REPORT 170 if (progress != NULL) {
176 source->pub.buffer_height = 1;
189 rle_source_ptr source = (rle_source_ptr) sinfo;
192 source->pub.buffer = (*cinfo->mem->access_virt_sarray)
207 rle_source_ptr source = (rle_source_ptr) sinfo;
213 colormap = source->header.cmap;
214 dest_row = source->pub.buffer[0];
216 src_row = * (*cinfo->mem->access_virt_sarray)
219 for (col = cinfo->image_width; col > 0; col--) {
221 *dest_row++ = (
JSAMPLE) (colormap[val ] >> 8);
222 *dest_row++ = (
JSAMPLE) (colormap[val + 256] >> 8);
223 *dest_row++ = (
JSAMPLE) (colormap[val + 512] >> 8);
243 rle_source_ptr source = (rle_source_ptr) sinfo;
245 JSAMPROW scanline, red_ptr, green_ptr, blue_ptr;
249 #ifdef PROGRESS_REPORT 253 colormap = source->header.cmap;
254 rle_row = source->rle_row;
260 RLE_CLR_BIT(source->header, RLE_ALPHA);
262 #ifdef PROGRESS_REPORT 263 if (progress != NULL) {
270 switch (source->visual) {
274 for (row = 0; row < cinfo->image_height; row++) {
275 rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray)
277 rle_getrow(&source->header, rle_row);
278 #ifdef PROGRESS_REPORT 279 if (progress != NULL) {
289 for (row = 0; row < cinfo->image_height; row++) {
290 scanline = * (*cinfo->mem->access_virt_sarray)
292 rle_row = source->rle_row;
293 rle_getrow(&source->header, rle_row);
295 for (col = 0; col < cinfo->image_width; col++) {
296 for (channel = 0; channel < source->header.ncolors; channel++) {
298 (colormap[
GETJSAMPLE(rle_row[channel][col]) + 256 * channel] >> 8);
302 #ifdef PROGRESS_REPORT 303 if (progress != NULL) {
312 for (row = 0; row < cinfo->image_height; row++) {
313 scanline = * (*cinfo->mem->access_virt_sarray)
315 rle_getrow(&source->header, rle_row);
317 red_ptr = rle_row[0];
318 green_ptr = rle_row[1];
319 blue_ptr = rle_row[2];
321 for (col = cinfo->image_width; col > 0; col--) {
322 *scanline++ = *red_ptr++;
323 *scanline++ = *green_ptr++;
324 *scanline++ = *blue_ptr++;
327 #ifdef PROGRESS_REPORT 328 if (progress != NULL) {
336 #ifdef PROGRESS_REPORT 337 if (progress != NULL)
342 if (source->visual == PSEUDOCOLOR) {
343 source->pub.buffer = source->rle_row;
344 source->pub.get_pixel_rows = get_pseudocolor_row;
346 source->pub.get_pixel_rows = get_rle_row;
348 source->row = cinfo->image_height;
351 return (*source->pub.get_pixel_rows) (cinfo, sinfo);
373 rle_source_ptr source;
376 source = (rle_source_ptr)
377 (*cinfo->mem->alloc_small) ((
j_common_ptr) cinfo, JPOOL_IMAGE,
378 SIZEOF(rle_source_struct));
380 source->pub.start_input = start_input_rle;
381 source->pub.finish_input = finish_input_rle;
382 source->pub.get_pixel_rows = load_image;
struct jpeg_common_struct * j_common_ptr
#define GETJSAMPLE(value)
#define ERREXIT(cinfo, code)
#define TRACEMS2(cinfo, lvl, code, p1, p2)
png_infop png_uint_32 * width
int JSAMPARRAY int dest_row
png_infop png_uint_32 png_uint_32 * height
struct jpeg_progress_mgr pub
int completed_extra_passes
#define TRACEMS3(cinfo, lvl, code, p1, p2, p3)
struct cdjpeg_progress_mgr * cd_progress_ptr