Final 350 project

Dependencies:   uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed

Committer:
shoaib_ahmed
Date:
Mon Jul 31 09:16:35 2017 +0000
Revision:
0:791a779d6220
final project;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shoaib_ahmed 0:791a779d6220 1 /*
shoaib_ahmed 0:791a779d6220 2 * rdrle.c
shoaib_ahmed 0:791a779d6220 3 *
shoaib_ahmed 0:791a779d6220 4 * Copyright (C) 1991-1996, Thomas G. Lane.
shoaib_ahmed 0:791a779d6220 5 * This file is part of the Independent JPEG Group's software.
shoaib_ahmed 0:791a779d6220 6 * For conditions of distribution and use, see the accompanying README file.
shoaib_ahmed 0:791a779d6220 7 *
shoaib_ahmed 0:791a779d6220 8 * This file contains routines to read input images in Utah RLE format.
shoaib_ahmed 0:791a779d6220 9 * The Utah Raster Toolkit library is required (version 3.1 or later).
shoaib_ahmed 0:791a779d6220 10 *
shoaib_ahmed 0:791a779d6220 11 * These routines may need modification for non-Unix environments or
shoaib_ahmed 0:791a779d6220 12 * specialized applications. As they stand, they assume input from
shoaib_ahmed 0:791a779d6220 13 * an ordinary stdio stream. They further assume that reading begins
shoaib_ahmed 0:791a779d6220 14 * at the start of the file; start_input may need work if the
shoaib_ahmed 0:791a779d6220 15 * user interface has already read some data (e.g., to determine that
shoaib_ahmed 0:791a779d6220 16 * the file is indeed RLE format).
shoaib_ahmed 0:791a779d6220 17 *
shoaib_ahmed 0:791a779d6220 18 * Based on code contributed by Mike Lijewski,
shoaib_ahmed 0:791a779d6220 19 * with updates from Robert Hutchinson.
shoaib_ahmed 0:791a779d6220 20 */
shoaib_ahmed 0:791a779d6220 21
shoaib_ahmed 0:791a779d6220 22 #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
shoaib_ahmed 0:791a779d6220 23
shoaib_ahmed 0:791a779d6220 24 #ifdef RLE_SUPPORTED
shoaib_ahmed 0:791a779d6220 25
shoaib_ahmed 0:791a779d6220 26 /* rle.h is provided by the Utah Raster Toolkit. */
shoaib_ahmed 0:791a779d6220 27
shoaib_ahmed 0:791a779d6220 28 #include <rle.h>
shoaib_ahmed 0:791a779d6220 29
shoaib_ahmed 0:791a779d6220 30 /*
shoaib_ahmed 0:791a779d6220 31 * We assume that JSAMPLE has the same representation as rle_pixel,
shoaib_ahmed 0:791a779d6220 32 * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples.
shoaib_ahmed 0:791a779d6220 33 */
shoaib_ahmed 0:791a779d6220 34
shoaib_ahmed 0:791a779d6220 35 #if BITS_IN_JSAMPLE != 8
shoaib_ahmed 0:791a779d6220 36 Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
shoaib_ahmed 0:791a779d6220 37 #endif
shoaib_ahmed 0:791a779d6220 38
shoaib_ahmed 0:791a779d6220 39 /*
shoaib_ahmed 0:791a779d6220 40 * We support the following types of RLE files:
shoaib_ahmed 0:791a779d6220 41 *
shoaib_ahmed 0:791a779d6220 42 * GRAYSCALE - 8 bits, no colormap
shoaib_ahmed 0:791a779d6220 43 * MAPPEDGRAY - 8 bits, 1 channel colomap
shoaib_ahmed 0:791a779d6220 44 * PSEUDOCOLOR - 8 bits, 3 channel colormap
shoaib_ahmed 0:791a779d6220 45 * TRUECOLOR - 24 bits, 3 channel colormap
shoaib_ahmed 0:791a779d6220 46 * DIRECTCOLOR - 24 bits, no colormap
shoaib_ahmed 0:791a779d6220 47 *
shoaib_ahmed 0:791a779d6220 48 * For now, we ignore any alpha channel in the image.
shoaib_ahmed 0:791a779d6220 49 */
shoaib_ahmed 0:791a779d6220 50
shoaib_ahmed 0:791a779d6220 51 typedef enum
shoaib_ahmed 0:791a779d6220 52 { GRAYSCALE, MAPPEDGRAY, PSEUDOCOLOR, TRUECOLOR, DIRECTCOLOR } rle_kind;
shoaib_ahmed 0:791a779d6220 53
shoaib_ahmed 0:791a779d6220 54
shoaib_ahmed 0:791a779d6220 55 /*
shoaib_ahmed 0:791a779d6220 56 * Since RLE stores scanlines bottom-to-top, we have to invert the image
shoaib_ahmed 0:791a779d6220 57 * to conform to JPEG's top-to-bottom order. To do this, we read the
shoaib_ahmed 0:791a779d6220 58 * incoming image into a virtual array on the first get_pixel_rows call,
shoaib_ahmed 0:791a779d6220 59 * then fetch the required row from the virtual array on subsequent calls.
shoaib_ahmed 0:791a779d6220 60 */
shoaib_ahmed 0:791a779d6220 61
shoaib_ahmed 0:791a779d6220 62 typedef struct _rle_source_struct * rle_source_ptr;
shoaib_ahmed 0:791a779d6220 63
shoaib_ahmed 0:791a779d6220 64 typedef struct _rle_source_struct {
shoaib_ahmed 0:791a779d6220 65 struct cjpeg_source_struct pub; /* public fields */
shoaib_ahmed 0:791a779d6220 66
shoaib_ahmed 0:791a779d6220 67 rle_kind visual; /* actual type of input file */
shoaib_ahmed 0:791a779d6220 68 jvirt_sarray_ptr image; /* virtual array to hold the image */
shoaib_ahmed 0:791a779d6220 69 JDIMENSION row; /* current row # in the virtual array */
shoaib_ahmed 0:791a779d6220 70 rle_hdr header; /* Input file information */
shoaib_ahmed 0:791a779d6220 71 rle_pixel** rle_row; /* holds a row returned by rle_getrow() */
shoaib_ahmed 0:791a779d6220 72
shoaib_ahmed 0:791a779d6220 73 } rle_source_struct;
shoaib_ahmed 0:791a779d6220 74
shoaib_ahmed 0:791a779d6220 75
shoaib_ahmed 0:791a779d6220 76 /*
shoaib_ahmed 0:791a779d6220 77 * Read the file header; return image size and component count.
shoaib_ahmed 0:791a779d6220 78 */
shoaib_ahmed 0:791a779d6220 79
shoaib_ahmed 0:791a779d6220 80 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 81 start_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
shoaib_ahmed 0:791a779d6220 82 {
shoaib_ahmed 0:791a779d6220 83 rle_source_ptr source = (rle_source_ptr) sinfo;
shoaib_ahmed 0:791a779d6220 84 JDIMENSION width, height;
shoaib_ahmed 0:791a779d6220 85 #ifdef PROGRESS_REPORT
shoaib_ahmed 0:791a779d6220 86 cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
shoaib_ahmed 0:791a779d6220 87 #endif
shoaib_ahmed 0:791a779d6220 88
shoaib_ahmed 0:791a779d6220 89 /* Use RLE library routine to get the header info */
shoaib_ahmed 0:791a779d6220 90 source->header = *rle_hdr_init(NULL);
shoaib_ahmed 0:791a779d6220 91 source->header.rle_file = source->pub.input_file;
shoaib_ahmed 0:791a779d6220 92 switch (rle_get_setup(&(source->header))) {
shoaib_ahmed 0:791a779d6220 93 case RLE_SUCCESS:
shoaib_ahmed 0:791a779d6220 94 /* A-OK */
shoaib_ahmed 0:791a779d6220 95 break;
shoaib_ahmed 0:791a779d6220 96 case RLE_NOT_RLE:
shoaib_ahmed 0:791a779d6220 97 ERREXIT(cinfo, JERR_RLE_NOT);
shoaib_ahmed 0:791a779d6220 98 break;
shoaib_ahmed 0:791a779d6220 99 case RLE_NO_SPACE:
shoaib_ahmed 0:791a779d6220 100 ERREXIT(cinfo, JERR_RLE_MEM);
shoaib_ahmed 0:791a779d6220 101 break;
shoaib_ahmed 0:791a779d6220 102 case RLE_EMPTY:
shoaib_ahmed 0:791a779d6220 103 ERREXIT(cinfo, JERR_RLE_EMPTY);
shoaib_ahmed 0:791a779d6220 104 break;
shoaib_ahmed 0:791a779d6220 105 case RLE_EOF:
shoaib_ahmed 0:791a779d6220 106 ERREXIT(cinfo, JERR_RLE_EOF);
shoaib_ahmed 0:791a779d6220 107 break;
shoaib_ahmed 0:791a779d6220 108 default:
shoaib_ahmed 0:791a779d6220 109 ERREXIT(cinfo, JERR_RLE_BADERROR);
shoaib_ahmed 0:791a779d6220 110 break;
shoaib_ahmed 0:791a779d6220 111 }
shoaib_ahmed 0:791a779d6220 112
shoaib_ahmed 0:791a779d6220 113 /* Figure out what we have, set private vars and return values accordingly */
shoaib_ahmed 0:791a779d6220 114
shoaib_ahmed 0:791a779d6220 115 width = source->header.xmax - source->header.xmin + 1;
shoaib_ahmed 0:791a779d6220 116 height = source->header.ymax - source->header.ymin + 1;
shoaib_ahmed 0:791a779d6220 117 source->header.xmin = 0; /* realign horizontally */
shoaib_ahmed 0:791a779d6220 118 source->header.xmax = width-1;
shoaib_ahmed 0:791a779d6220 119
shoaib_ahmed 0:791a779d6220 120 cinfo->image_width = width;
shoaib_ahmed 0:791a779d6220 121 cinfo->image_height = height;
shoaib_ahmed 0:791a779d6220 122 cinfo->data_precision = 8; /* we can only handle 8 bit data */
shoaib_ahmed 0:791a779d6220 123
shoaib_ahmed 0:791a779d6220 124 if (source->header.ncolors == 1 && source->header.ncmap == 0) {
shoaib_ahmed 0:791a779d6220 125 source->visual = GRAYSCALE;
shoaib_ahmed 0:791a779d6220 126 TRACEMS2(cinfo, 1, JTRC_RLE_GRAY, width, height);
shoaib_ahmed 0:791a779d6220 127 } else if (source->header.ncolors == 1 && source->header.ncmap == 1) {
shoaib_ahmed 0:791a779d6220 128 source->visual = MAPPEDGRAY;
shoaib_ahmed 0:791a779d6220 129 TRACEMS3(cinfo, 1, JTRC_RLE_MAPGRAY, width, height,
shoaib_ahmed 0:791a779d6220 130 1 << source->header.cmaplen);
shoaib_ahmed 0:791a779d6220 131 } else if (source->header.ncolors == 1 && source->header.ncmap == 3) {
shoaib_ahmed 0:791a779d6220 132 source->visual = PSEUDOCOLOR;
shoaib_ahmed 0:791a779d6220 133 TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height,
shoaib_ahmed 0:791a779d6220 134 1 << source->header.cmaplen);
shoaib_ahmed 0:791a779d6220 135 } else if (source->header.ncolors == 3 && source->header.ncmap == 3) {
shoaib_ahmed 0:791a779d6220 136 source->visual = TRUECOLOR;
shoaib_ahmed 0:791a779d6220 137 TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height,
shoaib_ahmed 0:791a779d6220 138 1 << source->header.cmaplen);
shoaib_ahmed 0:791a779d6220 139 } else if (source->header.ncolors == 3 && source->header.ncmap == 0) {
shoaib_ahmed 0:791a779d6220 140 source->visual = DIRECTCOLOR;
shoaib_ahmed 0:791a779d6220 141 TRACEMS2(cinfo, 1, JTRC_RLE, width, height);
shoaib_ahmed 0:791a779d6220 142 } else
shoaib_ahmed 0:791a779d6220 143 ERREXIT(cinfo, JERR_RLE_UNSUPPORTED);
shoaib_ahmed 0:791a779d6220 144
shoaib_ahmed 0:791a779d6220 145 if (source->visual == GRAYSCALE || source->visual == MAPPEDGRAY) {
shoaib_ahmed 0:791a779d6220 146 cinfo->in_color_space = JCS_GRAYSCALE;
shoaib_ahmed 0:791a779d6220 147 cinfo->input_components = 1;
shoaib_ahmed 0:791a779d6220 148 } else {
shoaib_ahmed 0:791a779d6220 149 cinfo->in_color_space = JCS_RGB;
shoaib_ahmed 0:791a779d6220 150 cinfo->input_components = 3;
shoaib_ahmed 0:791a779d6220 151 }
shoaib_ahmed 0:791a779d6220 152
shoaib_ahmed 0:791a779d6220 153 /*
shoaib_ahmed 0:791a779d6220 154 * A place to hold each scanline while it's converted.
shoaib_ahmed 0:791a779d6220 155 * (GRAYSCALE scanlines don't need converting)
shoaib_ahmed 0:791a779d6220 156 */
shoaib_ahmed 0:791a779d6220 157 if (source->visual != GRAYSCALE) {
shoaib_ahmed 0:791a779d6220 158 source->rle_row = (rle_pixel**) (*cinfo->mem->alloc_sarray)
shoaib_ahmed 0:791a779d6220 159 ((j_common_ptr) cinfo, JPOOL_IMAGE,
shoaib_ahmed 0:791a779d6220 160 (JDIMENSION) width, (JDIMENSION) cinfo->input_components);
shoaib_ahmed 0:791a779d6220 161 }
shoaib_ahmed 0:791a779d6220 162
shoaib_ahmed 0:791a779d6220 163 /* request a virtual array to hold the image */
shoaib_ahmed 0:791a779d6220 164 source->image = (*cinfo->mem->request_virt_sarray)
shoaib_ahmed 0:791a779d6220 165 ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
shoaib_ahmed 0:791a779d6220 166 (JDIMENSION) (width * source->header.ncolors),
shoaib_ahmed 0:791a779d6220 167 (JDIMENSION) height, (JDIMENSION) 1);
shoaib_ahmed 0:791a779d6220 168
shoaib_ahmed 0:791a779d6220 169 #ifdef PROGRESS_REPORT
shoaib_ahmed 0:791a779d6220 170 if (progress != NULL) {
shoaib_ahmed 0:791a779d6220 171 /* count file input as separate pass */
shoaib_ahmed 0:791a779d6220 172 progress->total_extra_passes++;
shoaib_ahmed 0:791a779d6220 173 }
shoaib_ahmed 0:791a779d6220 174 #endif
shoaib_ahmed 0:791a779d6220 175
shoaib_ahmed 0:791a779d6220 176 source->pub.buffer_height = 1;
shoaib_ahmed 0:791a779d6220 177 }
shoaib_ahmed 0:791a779d6220 178
shoaib_ahmed 0:791a779d6220 179
shoaib_ahmed 0:791a779d6220 180 /*
shoaib_ahmed 0:791a779d6220 181 * Read one row of pixels.
shoaib_ahmed 0:791a779d6220 182 * Called only after load_image has read the image into the virtual array.
shoaib_ahmed 0:791a779d6220 183 * Used for GRAYSCALE, MAPPEDGRAY, TRUECOLOR, and DIRECTCOLOR images.
shoaib_ahmed 0:791a779d6220 184 */
shoaib_ahmed 0:791a779d6220 185
shoaib_ahmed 0:791a779d6220 186 METHODDEF(JDIMENSION)
shoaib_ahmed 0:791a779d6220 187 get_rle_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
shoaib_ahmed 0:791a779d6220 188 {
shoaib_ahmed 0:791a779d6220 189 rle_source_ptr source = (rle_source_ptr) sinfo;
shoaib_ahmed 0:791a779d6220 190
shoaib_ahmed 0:791a779d6220 191 source->row--;
shoaib_ahmed 0:791a779d6220 192 source->pub.buffer = (*cinfo->mem->access_virt_sarray)
shoaib_ahmed 0:791a779d6220 193 ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE);
shoaib_ahmed 0:791a779d6220 194
shoaib_ahmed 0:791a779d6220 195 return 1;
shoaib_ahmed 0:791a779d6220 196 }
shoaib_ahmed 0:791a779d6220 197
shoaib_ahmed 0:791a779d6220 198 /*
shoaib_ahmed 0:791a779d6220 199 * Read one row of pixels.
shoaib_ahmed 0:791a779d6220 200 * Called only after load_image has read the image into the virtual array.
shoaib_ahmed 0:791a779d6220 201 * Used for PSEUDOCOLOR images.
shoaib_ahmed 0:791a779d6220 202 */
shoaib_ahmed 0:791a779d6220 203
shoaib_ahmed 0:791a779d6220 204 METHODDEF(JDIMENSION)
shoaib_ahmed 0:791a779d6220 205 get_pseudocolor_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
shoaib_ahmed 0:791a779d6220 206 {
shoaib_ahmed 0:791a779d6220 207 rle_source_ptr source = (rle_source_ptr) sinfo;
shoaib_ahmed 0:791a779d6220 208 JSAMPROW src_row, dest_row;
shoaib_ahmed 0:791a779d6220 209 JDIMENSION col;
shoaib_ahmed 0:791a779d6220 210 rle_map *colormap;
shoaib_ahmed 0:791a779d6220 211 int val;
shoaib_ahmed 0:791a779d6220 212
shoaib_ahmed 0:791a779d6220 213 colormap = source->header.cmap;
shoaib_ahmed 0:791a779d6220 214 dest_row = source->pub.buffer[0];
shoaib_ahmed 0:791a779d6220 215 source->row--;
shoaib_ahmed 0:791a779d6220 216 src_row = * (*cinfo->mem->access_virt_sarray)
shoaib_ahmed 0:791a779d6220 217 ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE);
shoaib_ahmed 0:791a779d6220 218
shoaib_ahmed 0:791a779d6220 219 for (col = cinfo->image_width; col > 0; col--) {
shoaib_ahmed 0:791a779d6220 220 val = GETJSAMPLE(*src_row++);
shoaib_ahmed 0:791a779d6220 221 *dest_row++ = (JSAMPLE) (colormap[val ] >> 8);
shoaib_ahmed 0:791a779d6220 222 *dest_row++ = (JSAMPLE) (colormap[val + 256] >> 8);
shoaib_ahmed 0:791a779d6220 223 *dest_row++ = (JSAMPLE) (colormap[val + 512] >> 8);
shoaib_ahmed 0:791a779d6220 224 }
shoaib_ahmed 0:791a779d6220 225
shoaib_ahmed 0:791a779d6220 226 return 1;
shoaib_ahmed 0:791a779d6220 227 }
shoaib_ahmed 0:791a779d6220 228
shoaib_ahmed 0:791a779d6220 229
shoaib_ahmed 0:791a779d6220 230 /*
shoaib_ahmed 0:791a779d6220 231 * Load the image into a virtual array. We have to do this because RLE
shoaib_ahmed 0:791a779d6220 232 * files start at the lower left while the JPEG standard has them starting
shoaib_ahmed 0:791a779d6220 233 * in the upper left. This is called the first time we want to get a row
shoaib_ahmed 0:791a779d6220 234 * of input. What we do is load the RLE data into the array and then call
shoaib_ahmed 0:791a779d6220 235 * the appropriate routine to read one row from the array. Before returning,
shoaib_ahmed 0:791a779d6220 236 * we set source->pub.get_pixel_rows so that subsequent calls go straight to
shoaib_ahmed 0:791a779d6220 237 * the appropriate row-reading routine.
shoaib_ahmed 0:791a779d6220 238 */
shoaib_ahmed 0:791a779d6220 239
shoaib_ahmed 0:791a779d6220 240 METHODDEF(JDIMENSION)
shoaib_ahmed 0:791a779d6220 241 load_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
shoaib_ahmed 0:791a779d6220 242 {
shoaib_ahmed 0:791a779d6220 243 rle_source_ptr source = (rle_source_ptr) sinfo;
shoaib_ahmed 0:791a779d6220 244 JDIMENSION row, col;
shoaib_ahmed 0:791a779d6220 245 JSAMPROW scanline, red_ptr, green_ptr, blue_ptr;
shoaib_ahmed 0:791a779d6220 246 rle_pixel **rle_row;
shoaib_ahmed 0:791a779d6220 247 rle_map *colormap;
shoaib_ahmed 0:791a779d6220 248 char channel;
shoaib_ahmed 0:791a779d6220 249 #ifdef PROGRESS_REPORT
shoaib_ahmed 0:791a779d6220 250 cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
shoaib_ahmed 0:791a779d6220 251 #endif
shoaib_ahmed 0:791a779d6220 252
shoaib_ahmed 0:791a779d6220 253 colormap = source->header.cmap;
shoaib_ahmed 0:791a779d6220 254 rle_row = source->rle_row;
shoaib_ahmed 0:791a779d6220 255
shoaib_ahmed 0:791a779d6220 256 /* Read the RLE data into our virtual array.
shoaib_ahmed 0:791a779d6220 257 * We assume here that (a) rle_pixel is represented the same as JSAMPLE,
shoaib_ahmed 0:791a779d6220 258 * and (b) we are not on a machine where FAR pointers differ from regular.
shoaib_ahmed 0:791a779d6220 259 */
shoaib_ahmed 0:791a779d6220 260 RLE_CLR_BIT(source->header, RLE_ALPHA); /* don't read the alpha channel */
shoaib_ahmed 0:791a779d6220 261
shoaib_ahmed 0:791a779d6220 262 #ifdef PROGRESS_REPORT
shoaib_ahmed 0:791a779d6220 263 if (progress != NULL) {
shoaib_ahmed 0:791a779d6220 264 progress->pub.pass_limit = cinfo->image_height;
shoaib_ahmed 0:791a779d6220 265 progress->pub.pass_counter = 0;
shoaib_ahmed 0:791a779d6220 266 (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
shoaib_ahmed 0:791a779d6220 267 }
shoaib_ahmed 0:791a779d6220 268 #endif
shoaib_ahmed 0:791a779d6220 269
shoaib_ahmed 0:791a779d6220 270 switch (source->visual) {
shoaib_ahmed 0:791a779d6220 271
shoaib_ahmed 0:791a779d6220 272 case GRAYSCALE:
shoaib_ahmed 0:791a779d6220 273 case PSEUDOCOLOR:
shoaib_ahmed 0:791a779d6220 274 for (row = 0; row < cinfo->image_height; row++) {
shoaib_ahmed 0:791a779d6220 275 rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray)
shoaib_ahmed 0:791a779d6220 276 ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);
shoaib_ahmed 0:791a779d6220 277 rle_getrow(&source->header, rle_row);
shoaib_ahmed 0:791a779d6220 278 #ifdef PROGRESS_REPORT
shoaib_ahmed 0:791a779d6220 279 if (progress != NULL) {
shoaib_ahmed 0:791a779d6220 280 progress->pub.pass_counter++;
shoaib_ahmed 0:791a779d6220 281 (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
shoaib_ahmed 0:791a779d6220 282 }
shoaib_ahmed 0:791a779d6220 283 #endif
shoaib_ahmed 0:791a779d6220 284 }
shoaib_ahmed 0:791a779d6220 285 break;
shoaib_ahmed 0:791a779d6220 286
shoaib_ahmed 0:791a779d6220 287 case MAPPEDGRAY:
shoaib_ahmed 0:791a779d6220 288 case TRUECOLOR:
shoaib_ahmed 0:791a779d6220 289 for (row = 0; row < cinfo->image_height; row++) {
shoaib_ahmed 0:791a779d6220 290 scanline = * (*cinfo->mem->access_virt_sarray)
shoaib_ahmed 0:791a779d6220 291 ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);
shoaib_ahmed 0:791a779d6220 292 rle_row = source->rle_row;
shoaib_ahmed 0:791a779d6220 293 rle_getrow(&source->header, rle_row);
shoaib_ahmed 0:791a779d6220 294
shoaib_ahmed 0:791a779d6220 295 for (col = 0; col < cinfo->image_width; col++) {
shoaib_ahmed 0:791a779d6220 296 for (channel = 0; channel < source->header.ncolors; channel++) {
shoaib_ahmed 0:791a779d6220 297 *scanline++ = (JSAMPLE)
shoaib_ahmed 0:791a779d6220 298 (colormap[GETJSAMPLE(rle_row[channel][col]) + 256 * channel] >> 8);
shoaib_ahmed 0:791a779d6220 299 }
shoaib_ahmed 0:791a779d6220 300 }
shoaib_ahmed 0:791a779d6220 301
shoaib_ahmed 0:791a779d6220 302 #ifdef PROGRESS_REPORT
shoaib_ahmed 0:791a779d6220 303 if (progress != NULL) {
shoaib_ahmed 0:791a779d6220 304 progress->pub.pass_counter++;
shoaib_ahmed 0:791a779d6220 305 (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
shoaib_ahmed 0:791a779d6220 306 }
shoaib_ahmed 0:791a779d6220 307 #endif
shoaib_ahmed 0:791a779d6220 308 }
shoaib_ahmed 0:791a779d6220 309 break;
shoaib_ahmed 0:791a779d6220 310
shoaib_ahmed 0:791a779d6220 311 case DIRECTCOLOR:
shoaib_ahmed 0:791a779d6220 312 for (row = 0; row < cinfo->image_height; row++) {
shoaib_ahmed 0:791a779d6220 313 scanline = * (*cinfo->mem->access_virt_sarray)
shoaib_ahmed 0:791a779d6220 314 ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);
shoaib_ahmed 0:791a779d6220 315 rle_getrow(&source->header, rle_row);
shoaib_ahmed 0:791a779d6220 316
shoaib_ahmed 0:791a779d6220 317 red_ptr = rle_row[0];
shoaib_ahmed 0:791a779d6220 318 green_ptr = rle_row[1];
shoaib_ahmed 0:791a779d6220 319 blue_ptr = rle_row[2];
shoaib_ahmed 0:791a779d6220 320
shoaib_ahmed 0:791a779d6220 321 for (col = cinfo->image_width; col > 0; col--) {
shoaib_ahmed 0:791a779d6220 322 *scanline++ = *red_ptr++;
shoaib_ahmed 0:791a779d6220 323 *scanline++ = *green_ptr++;
shoaib_ahmed 0:791a779d6220 324 *scanline++ = *blue_ptr++;
shoaib_ahmed 0:791a779d6220 325 }
shoaib_ahmed 0:791a779d6220 326
shoaib_ahmed 0:791a779d6220 327 #ifdef PROGRESS_REPORT
shoaib_ahmed 0:791a779d6220 328 if (progress != NULL) {
shoaib_ahmed 0:791a779d6220 329 progress->pub.pass_counter++;
shoaib_ahmed 0:791a779d6220 330 (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
shoaib_ahmed 0:791a779d6220 331 }
shoaib_ahmed 0:791a779d6220 332 #endif
shoaib_ahmed 0:791a779d6220 333 }
shoaib_ahmed 0:791a779d6220 334 }
shoaib_ahmed 0:791a779d6220 335
shoaib_ahmed 0:791a779d6220 336 #ifdef PROGRESS_REPORT
shoaib_ahmed 0:791a779d6220 337 if (progress != NULL)
shoaib_ahmed 0:791a779d6220 338 progress->completed_extra_passes++;
shoaib_ahmed 0:791a779d6220 339 #endif
shoaib_ahmed 0:791a779d6220 340
shoaib_ahmed 0:791a779d6220 341 /* Set up to call proper row-extraction routine in future */
shoaib_ahmed 0:791a779d6220 342 if (source->visual == PSEUDOCOLOR) {
shoaib_ahmed 0:791a779d6220 343 source->pub.buffer = source->rle_row;
shoaib_ahmed 0:791a779d6220 344 source->pub.get_pixel_rows = get_pseudocolor_row;
shoaib_ahmed 0:791a779d6220 345 } else {
shoaib_ahmed 0:791a779d6220 346 source->pub.get_pixel_rows = get_rle_row;
shoaib_ahmed 0:791a779d6220 347 }
shoaib_ahmed 0:791a779d6220 348 source->row = cinfo->image_height;
shoaib_ahmed 0:791a779d6220 349
shoaib_ahmed 0:791a779d6220 350 /* And fetch the topmost (bottommost) row */
shoaib_ahmed 0:791a779d6220 351 return (*source->pub.get_pixel_rows) (cinfo, sinfo);
shoaib_ahmed 0:791a779d6220 352 }
shoaib_ahmed 0:791a779d6220 353
shoaib_ahmed 0:791a779d6220 354
shoaib_ahmed 0:791a779d6220 355 /*
shoaib_ahmed 0:791a779d6220 356 * Finish up at the end of the file.
shoaib_ahmed 0:791a779d6220 357 */
shoaib_ahmed 0:791a779d6220 358
shoaib_ahmed 0:791a779d6220 359 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 360 finish_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
shoaib_ahmed 0:791a779d6220 361 {
shoaib_ahmed 0:791a779d6220 362 /* no work */
shoaib_ahmed 0:791a779d6220 363 }
shoaib_ahmed 0:791a779d6220 364
shoaib_ahmed 0:791a779d6220 365
shoaib_ahmed 0:791a779d6220 366 /*
shoaib_ahmed 0:791a779d6220 367 * The module selection routine for RLE format input.
shoaib_ahmed 0:791a779d6220 368 */
shoaib_ahmed 0:791a779d6220 369
shoaib_ahmed 0:791a779d6220 370 GLOBAL(cjpeg_source_ptr)
shoaib_ahmed 0:791a779d6220 371 jinit_read_rle (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 372 {
shoaib_ahmed 0:791a779d6220 373 rle_source_ptr source;
shoaib_ahmed 0:791a779d6220 374
shoaib_ahmed 0:791a779d6220 375 /* Create module interface object */
shoaib_ahmed 0:791a779d6220 376 source = (rle_source_ptr)
shoaib_ahmed 0:791a779d6220 377 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
shoaib_ahmed 0:791a779d6220 378 SIZEOF(rle_source_struct));
shoaib_ahmed 0:791a779d6220 379 /* Fill in method ptrs */
shoaib_ahmed 0:791a779d6220 380 source->pub.start_input = start_input_rle;
shoaib_ahmed 0:791a779d6220 381 source->pub.finish_input = finish_input_rle;
shoaib_ahmed 0:791a779d6220 382 source->pub.get_pixel_rows = load_image;
shoaib_ahmed 0:791a779d6220 383
shoaib_ahmed 0:791a779d6220 384 return (cjpeg_source_ptr) source;
shoaib_ahmed 0:791a779d6220 385 }
shoaib_ahmed 0:791a779d6220 386
shoaib_ahmed 0:791a779d6220 387 #endif /* RLE_SUPPORTED */