Final 350 project
Dependencies: uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed
includes/wrrle.c@0:791a779d6220, 2017-07-31 (annotated)
- Committer:
- shoaib_ahmed
- Date:
- Mon Jul 31 09:16:35 2017 +0000
- Revision:
- 0:791a779d6220
final project;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shoaib_ahmed | 0:791a779d6220 | 1 | /* |
shoaib_ahmed | 0:791a779d6220 | 2 | * wrrle.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 write output images in 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 output to |
shoaib_ahmed | 0:791a779d6220 | 13 | * an ordinary stdio stream. |
shoaib_ahmed | 0:791a779d6220 | 14 | * |
shoaib_ahmed | 0:791a779d6220 | 15 | * Based on code contributed by Mike Lijewski, |
shoaib_ahmed | 0:791a779d6220 | 16 | * with updates from Robert Hutchinson. |
shoaib_ahmed | 0:791a779d6220 | 17 | */ |
shoaib_ahmed | 0:791a779d6220 | 18 | |
shoaib_ahmed | 0:791a779d6220 | 19 | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ |
shoaib_ahmed | 0:791a779d6220 | 20 | |
shoaib_ahmed | 0:791a779d6220 | 21 | #ifdef RLE_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 22 | |
shoaib_ahmed | 0:791a779d6220 | 23 | /* rle.h is provided by the Utah Raster Toolkit. */ |
shoaib_ahmed | 0:791a779d6220 | 24 | |
shoaib_ahmed | 0:791a779d6220 | 25 | #include <rle.h> |
shoaib_ahmed | 0:791a779d6220 | 26 | |
shoaib_ahmed | 0:791a779d6220 | 27 | /* |
shoaib_ahmed | 0:791a779d6220 | 28 | * We assume that JSAMPLE has the same representation as rle_pixel, |
shoaib_ahmed | 0:791a779d6220 | 29 | * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples. |
shoaib_ahmed | 0:791a779d6220 | 30 | */ |
shoaib_ahmed | 0:791a779d6220 | 31 | |
shoaib_ahmed | 0:791a779d6220 | 32 | #if BITS_IN_JSAMPLE != 8 |
shoaib_ahmed | 0:791a779d6220 | 33 | Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ |
shoaib_ahmed | 0:791a779d6220 | 34 | #endif |
shoaib_ahmed | 0:791a779d6220 | 35 | |
shoaib_ahmed | 0:791a779d6220 | 36 | |
shoaib_ahmed | 0:791a779d6220 | 37 | /* |
shoaib_ahmed | 0:791a779d6220 | 38 | * Since RLE stores scanlines bottom-to-top, we have to invert the image |
shoaib_ahmed | 0:791a779d6220 | 39 | * from JPEG's top-to-bottom order. To do this, we save the outgoing data |
shoaib_ahmed | 0:791a779d6220 | 40 | * in a virtual array during put_pixel_row calls, then actually emit the |
shoaib_ahmed | 0:791a779d6220 | 41 | * RLE file during finish_output. |
shoaib_ahmed | 0:791a779d6220 | 42 | */ |
shoaib_ahmed | 0:791a779d6220 | 43 | |
shoaib_ahmed | 0:791a779d6220 | 44 | |
shoaib_ahmed | 0:791a779d6220 | 45 | /* |
shoaib_ahmed | 0:791a779d6220 | 46 | * For now, if we emit an RLE color map then it is always 256 entries long, |
shoaib_ahmed | 0:791a779d6220 | 47 | * though not all of the entries need be used. |
shoaib_ahmed | 0:791a779d6220 | 48 | */ |
shoaib_ahmed | 0:791a779d6220 | 49 | |
shoaib_ahmed | 0:791a779d6220 | 50 | #define CMAPBITS 8 |
shoaib_ahmed | 0:791a779d6220 | 51 | #define CMAPLENGTH (1<<(CMAPBITS)) |
shoaib_ahmed | 0:791a779d6220 | 52 | |
shoaib_ahmed | 0:791a779d6220 | 53 | typedef struct { |
shoaib_ahmed | 0:791a779d6220 | 54 | struct djpeg_dest_struct pub; /* public fields */ |
shoaib_ahmed | 0:791a779d6220 | 55 | |
shoaib_ahmed | 0:791a779d6220 | 56 | jvirt_sarray_ptr image; /* virtual array to store the output image */ |
shoaib_ahmed | 0:791a779d6220 | 57 | rle_map *colormap; /* RLE-style color map, or NULL if none */ |
shoaib_ahmed | 0:791a779d6220 | 58 | rle_pixel **rle_row; /* To pass rows to rle_putrow() */ |
shoaib_ahmed | 0:791a779d6220 | 59 | |
shoaib_ahmed | 0:791a779d6220 | 60 | } rle_dest_struct; |
shoaib_ahmed | 0:791a779d6220 | 61 | |
shoaib_ahmed | 0:791a779d6220 | 62 | typedef rle_dest_struct * rle_dest_ptr; |
shoaib_ahmed | 0:791a779d6220 | 63 | |
shoaib_ahmed | 0:791a779d6220 | 64 | /* Forward declarations */ |
shoaib_ahmed | 0:791a779d6220 | 65 | METHODDEF(void) rle_put_pixel_rows |
shoaib_ahmed | 0:791a779d6220 | 66 | JPP((j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, |
shoaib_ahmed | 0:791a779d6220 | 67 | JDIMENSION rows_supplied)); |
shoaib_ahmed | 0:791a779d6220 | 68 | |
shoaib_ahmed | 0:791a779d6220 | 69 | |
shoaib_ahmed | 0:791a779d6220 | 70 | /* |
shoaib_ahmed | 0:791a779d6220 | 71 | * Write the file header. |
shoaib_ahmed | 0:791a779d6220 | 72 | * |
shoaib_ahmed | 0:791a779d6220 | 73 | * In this module it's easier to wait till finish_output to write anything. |
shoaib_ahmed | 0:791a779d6220 | 74 | */ |
shoaib_ahmed | 0:791a779d6220 | 75 | |
shoaib_ahmed | 0:791a779d6220 | 76 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 77 | start_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) |
shoaib_ahmed | 0:791a779d6220 | 78 | { |
shoaib_ahmed | 0:791a779d6220 | 79 | rle_dest_ptr dest = (rle_dest_ptr) dinfo; |
shoaib_ahmed | 0:791a779d6220 | 80 | size_t cmapsize; |
shoaib_ahmed | 0:791a779d6220 | 81 | int i, ci; |
shoaib_ahmed | 0:791a779d6220 | 82 | #ifdef PROGRESS_REPORT |
shoaib_ahmed | 0:791a779d6220 | 83 | cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; |
shoaib_ahmed | 0:791a779d6220 | 84 | #endif |
shoaib_ahmed | 0:791a779d6220 | 85 | |
shoaib_ahmed | 0:791a779d6220 | 86 | /* |
shoaib_ahmed | 0:791a779d6220 | 87 | * Make sure the image can be stored in RLE format. |
shoaib_ahmed | 0:791a779d6220 | 88 | * |
shoaib_ahmed | 0:791a779d6220 | 89 | * - RLE stores image dimensions as *signed* 16 bit integers. JPEG |
shoaib_ahmed | 0:791a779d6220 | 90 | * uses unsigned, so we have to check the width. |
shoaib_ahmed | 0:791a779d6220 | 91 | * |
shoaib_ahmed | 0:791a779d6220 | 92 | * - Colorspace is expected to be grayscale or RGB. |
shoaib_ahmed | 0:791a779d6220 | 93 | * |
shoaib_ahmed | 0:791a779d6220 | 94 | * - The number of channels (components) is expected to be 1 (grayscale/ |
shoaib_ahmed | 0:791a779d6220 | 95 | * pseudocolor) or 3 (truecolor/directcolor). |
shoaib_ahmed | 0:791a779d6220 | 96 | * (could be 2 or 4 if using an alpha channel, but we aren't) |
shoaib_ahmed | 0:791a779d6220 | 97 | */ |
shoaib_ahmed | 0:791a779d6220 | 98 | |
shoaib_ahmed | 0:791a779d6220 | 99 | if (cinfo->output_width > 32767 || cinfo->output_height > 32767) |
shoaib_ahmed | 0:791a779d6220 | 100 | ERREXIT2(cinfo, JERR_RLE_DIMENSIONS, cinfo->output_width, |
shoaib_ahmed | 0:791a779d6220 | 101 | cinfo->output_height); |
shoaib_ahmed | 0:791a779d6220 | 102 | |
shoaib_ahmed | 0:791a779d6220 | 103 | if (cinfo->out_color_space != JCS_GRAYSCALE && |
shoaib_ahmed | 0:791a779d6220 | 104 | cinfo->out_color_space != JCS_RGB) |
shoaib_ahmed | 0:791a779d6220 | 105 | ERREXIT(cinfo, JERR_RLE_COLORSPACE); |
shoaib_ahmed | 0:791a779d6220 | 106 | |
shoaib_ahmed | 0:791a779d6220 | 107 | if (cinfo->output_components != 1 && cinfo->output_components != 3) |
shoaib_ahmed | 0:791a779d6220 | 108 | ERREXIT1(cinfo, JERR_RLE_TOOMANYCHANNELS, cinfo->num_components); |
shoaib_ahmed | 0:791a779d6220 | 109 | |
shoaib_ahmed | 0:791a779d6220 | 110 | /* Convert colormap, if any, to RLE format. */ |
shoaib_ahmed | 0:791a779d6220 | 111 | |
shoaib_ahmed | 0:791a779d6220 | 112 | dest->colormap = NULL; |
shoaib_ahmed | 0:791a779d6220 | 113 | |
shoaib_ahmed | 0:791a779d6220 | 114 | if (cinfo->quantize_colors) { |
shoaib_ahmed | 0:791a779d6220 | 115 | /* Allocate storage for RLE-style cmap, zero any extra entries */ |
shoaib_ahmed | 0:791a779d6220 | 116 | cmapsize = cinfo->out_color_components * CMAPLENGTH * SIZEOF(rle_map); |
shoaib_ahmed | 0:791a779d6220 | 117 | dest->colormap = (rle_map *) (*cinfo->mem->alloc_small) |
shoaib_ahmed | 0:791a779d6220 | 118 | ((j_common_ptr) cinfo, JPOOL_IMAGE, cmapsize); |
shoaib_ahmed | 0:791a779d6220 | 119 | MEMZERO(dest->colormap, cmapsize); |
shoaib_ahmed | 0:791a779d6220 | 120 | |
shoaib_ahmed | 0:791a779d6220 | 121 | /* Save away data in RLE format --- note 8-bit left shift! */ |
shoaib_ahmed | 0:791a779d6220 | 122 | /* Shifting would need adjustment for JSAMPLEs wider than 8 bits. */ |
shoaib_ahmed | 0:791a779d6220 | 123 | for (ci = 0; ci < cinfo->out_color_components; ci++) { |
shoaib_ahmed | 0:791a779d6220 | 124 | for (i = 0; i < cinfo->actual_number_of_colors; i++) { |
shoaib_ahmed | 0:791a779d6220 | 125 | dest->colormap[ci * CMAPLENGTH + i] = |
shoaib_ahmed | 0:791a779d6220 | 126 | GETJSAMPLE(cinfo->colormap[ci][i]) << 8; |
shoaib_ahmed | 0:791a779d6220 | 127 | } |
shoaib_ahmed | 0:791a779d6220 | 128 | } |
shoaib_ahmed | 0:791a779d6220 | 129 | } |
shoaib_ahmed | 0:791a779d6220 | 130 | |
shoaib_ahmed | 0:791a779d6220 | 131 | /* Set the output buffer to the first row */ |
shoaib_ahmed | 0:791a779d6220 | 132 | dest->pub.buffer = (*cinfo->mem->access_virt_sarray) |
shoaib_ahmed | 0:791a779d6220 | 133 | ((j_common_ptr) cinfo, dest->image, (JDIMENSION) 0, (JDIMENSION) 1, TRUE); |
shoaib_ahmed | 0:791a779d6220 | 134 | dest->pub.buffer_height = 1; |
shoaib_ahmed | 0:791a779d6220 | 135 | |
shoaib_ahmed | 0:791a779d6220 | 136 | dest->pub.put_pixel_rows = rle_put_pixel_rows; |
shoaib_ahmed | 0:791a779d6220 | 137 | |
shoaib_ahmed | 0:791a779d6220 | 138 | #ifdef PROGRESS_REPORT |
shoaib_ahmed | 0:791a779d6220 | 139 | if (progress != NULL) { |
shoaib_ahmed | 0:791a779d6220 | 140 | progress->total_extra_passes++; /* count file writing as separate pass */ |
shoaib_ahmed | 0:791a779d6220 | 141 | } |
shoaib_ahmed | 0:791a779d6220 | 142 | #endif |
shoaib_ahmed | 0:791a779d6220 | 143 | } |
shoaib_ahmed | 0:791a779d6220 | 144 | |
shoaib_ahmed | 0:791a779d6220 | 145 | |
shoaib_ahmed | 0:791a779d6220 | 146 | /* |
shoaib_ahmed | 0:791a779d6220 | 147 | * Write some pixel data. |
shoaib_ahmed | 0:791a779d6220 | 148 | * |
shoaib_ahmed | 0:791a779d6220 | 149 | * This routine just saves the data away in a virtual array. |
shoaib_ahmed | 0:791a779d6220 | 150 | */ |
shoaib_ahmed | 0:791a779d6220 | 151 | |
shoaib_ahmed | 0:791a779d6220 | 152 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 153 | rle_put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, |
shoaib_ahmed | 0:791a779d6220 | 154 | JDIMENSION rows_supplied) |
shoaib_ahmed | 0:791a779d6220 | 155 | { |
shoaib_ahmed | 0:791a779d6220 | 156 | rle_dest_ptr dest = (rle_dest_ptr) dinfo; |
shoaib_ahmed | 0:791a779d6220 | 157 | |
shoaib_ahmed | 0:791a779d6220 | 158 | if (cinfo->output_scanline < cinfo->output_height) { |
shoaib_ahmed | 0:791a779d6220 | 159 | dest->pub.buffer = (*cinfo->mem->access_virt_sarray) |
shoaib_ahmed | 0:791a779d6220 | 160 | ((j_common_ptr) cinfo, dest->image, |
shoaib_ahmed | 0:791a779d6220 | 161 | cinfo->output_scanline, (JDIMENSION) 1, TRUE); |
shoaib_ahmed | 0:791a779d6220 | 162 | } |
shoaib_ahmed | 0:791a779d6220 | 163 | } |
shoaib_ahmed | 0:791a779d6220 | 164 | |
shoaib_ahmed | 0:791a779d6220 | 165 | /* |
shoaib_ahmed | 0:791a779d6220 | 166 | * Finish up at the end of the file. |
shoaib_ahmed | 0:791a779d6220 | 167 | * |
shoaib_ahmed | 0:791a779d6220 | 168 | * Here is where we really output the RLE file. |
shoaib_ahmed | 0:791a779d6220 | 169 | */ |
shoaib_ahmed | 0:791a779d6220 | 170 | |
shoaib_ahmed | 0:791a779d6220 | 171 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 172 | finish_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) |
shoaib_ahmed | 0:791a779d6220 | 173 | { |
shoaib_ahmed | 0:791a779d6220 | 174 | rle_dest_ptr dest = (rle_dest_ptr) dinfo; |
shoaib_ahmed | 0:791a779d6220 | 175 | rle_hdr header; /* Output file information */ |
shoaib_ahmed | 0:791a779d6220 | 176 | rle_pixel **rle_row, *red, *green, *blue; |
shoaib_ahmed | 0:791a779d6220 | 177 | JSAMPROW output_row; |
shoaib_ahmed | 0:791a779d6220 | 178 | char cmapcomment[80]; |
shoaib_ahmed | 0:791a779d6220 | 179 | int row, col; |
shoaib_ahmed | 0:791a779d6220 | 180 | int ci; |
shoaib_ahmed | 0:791a779d6220 | 181 | #ifdef PROGRESS_REPORT |
shoaib_ahmed | 0:791a779d6220 | 182 | cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; |
shoaib_ahmed | 0:791a779d6220 | 183 | #endif |
shoaib_ahmed | 0:791a779d6220 | 184 | |
shoaib_ahmed | 0:791a779d6220 | 185 | /* Initialize the header info */ |
shoaib_ahmed | 0:791a779d6220 | 186 | header = *rle_hdr_init(NULL); |
shoaib_ahmed | 0:791a779d6220 | 187 | header.rle_file = dest->pub.output_file; |
shoaib_ahmed | 0:791a779d6220 | 188 | header.xmin = 0; |
shoaib_ahmed | 0:791a779d6220 | 189 | header.xmax = cinfo->output_width - 1; |
shoaib_ahmed | 0:791a779d6220 | 190 | header.ymin = 0; |
shoaib_ahmed | 0:791a779d6220 | 191 | header.ymax = cinfo->output_height - 1; |
shoaib_ahmed | 0:791a779d6220 | 192 | header.alpha = 0; |
shoaib_ahmed | 0:791a779d6220 | 193 | header.ncolors = cinfo->output_components; |
shoaib_ahmed | 0:791a779d6220 | 194 | for (ci = 0; ci < cinfo->output_components; ci++) { |
shoaib_ahmed | 0:791a779d6220 | 195 | RLE_SET_BIT(header, ci); |
shoaib_ahmed | 0:791a779d6220 | 196 | } |
shoaib_ahmed | 0:791a779d6220 | 197 | if (cinfo->quantize_colors) { |
shoaib_ahmed | 0:791a779d6220 | 198 | header.ncmap = cinfo->out_color_components; |
shoaib_ahmed | 0:791a779d6220 | 199 | header.cmaplen = CMAPBITS; |
shoaib_ahmed | 0:791a779d6220 | 200 | header.cmap = dest->colormap; |
shoaib_ahmed | 0:791a779d6220 | 201 | /* Add a comment to the output image with the true colormap length. */ |
shoaib_ahmed | 0:791a779d6220 | 202 | sprintf(cmapcomment, "color_map_length=%d", cinfo->actual_number_of_colors); |
shoaib_ahmed | 0:791a779d6220 | 203 | rle_putcom(cmapcomment, &header); |
shoaib_ahmed | 0:791a779d6220 | 204 | } |
shoaib_ahmed | 0:791a779d6220 | 205 | |
shoaib_ahmed | 0:791a779d6220 | 206 | /* Emit the RLE header and color map (if any) */ |
shoaib_ahmed | 0:791a779d6220 | 207 | rle_put_setup(&header); |
shoaib_ahmed | 0:791a779d6220 | 208 | |
shoaib_ahmed | 0:791a779d6220 | 209 | /* Now output the RLE data from our virtual array. |
shoaib_ahmed | 0:791a779d6220 | 210 | * We assume here that (a) rle_pixel is represented the same as JSAMPLE, |
shoaib_ahmed | 0:791a779d6220 | 211 | * and (b) we are not on a machine where FAR pointers differ from regular. |
shoaib_ahmed | 0:791a779d6220 | 212 | */ |
shoaib_ahmed | 0:791a779d6220 | 213 | |
shoaib_ahmed | 0:791a779d6220 | 214 | #ifdef PROGRESS_REPORT |
shoaib_ahmed | 0:791a779d6220 | 215 | if (progress != NULL) { |
shoaib_ahmed | 0:791a779d6220 | 216 | progress->pub.pass_limit = cinfo->output_height; |
shoaib_ahmed | 0:791a779d6220 | 217 | progress->pub.pass_counter = 0; |
shoaib_ahmed | 0:791a779d6220 | 218 | (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); |
shoaib_ahmed | 0:791a779d6220 | 219 | } |
shoaib_ahmed | 0:791a779d6220 | 220 | #endif |
shoaib_ahmed | 0:791a779d6220 | 221 | |
shoaib_ahmed | 0:791a779d6220 | 222 | if (cinfo->output_components == 1) { |
shoaib_ahmed | 0:791a779d6220 | 223 | for (row = cinfo->output_height-1; row >= 0; row--) { |
shoaib_ahmed | 0:791a779d6220 | 224 | rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray) |
shoaib_ahmed | 0:791a779d6220 | 225 | ((j_common_ptr) cinfo, dest->image, |
shoaib_ahmed | 0:791a779d6220 | 226 | (JDIMENSION) row, (JDIMENSION) 1, FALSE); |
shoaib_ahmed | 0:791a779d6220 | 227 | rle_putrow(rle_row, (int) cinfo->output_width, &header); |
shoaib_ahmed | 0:791a779d6220 | 228 | #ifdef PROGRESS_REPORT |
shoaib_ahmed | 0:791a779d6220 | 229 | if (progress != NULL) { |
shoaib_ahmed | 0:791a779d6220 | 230 | progress->pub.pass_counter++; |
shoaib_ahmed | 0:791a779d6220 | 231 | (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); |
shoaib_ahmed | 0:791a779d6220 | 232 | } |
shoaib_ahmed | 0:791a779d6220 | 233 | #endif |
shoaib_ahmed | 0:791a779d6220 | 234 | } |
shoaib_ahmed | 0:791a779d6220 | 235 | } else { |
shoaib_ahmed | 0:791a779d6220 | 236 | for (row = cinfo->output_height-1; row >= 0; row--) { |
shoaib_ahmed | 0:791a779d6220 | 237 | rle_row = (rle_pixel **) dest->rle_row; |
shoaib_ahmed | 0:791a779d6220 | 238 | output_row = * (*cinfo->mem->access_virt_sarray) |
shoaib_ahmed | 0:791a779d6220 | 239 | ((j_common_ptr) cinfo, dest->image, |
shoaib_ahmed | 0:791a779d6220 | 240 | (JDIMENSION) row, (JDIMENSION) 1, FALSE); |
shoaib_ahmed | 0:791a779d6220 | 241 | red = rle_row[0]; |
shoaib_ahmed | 0:791a779d6220 | 242 | green = rle_row[1]; |
shoaib_ahmed | 0:791a779d6220 | 243 | blue = rle_row[2]; |
shoaib_ahmed | 0:791a779d6220 | 244 | for (col = cinfo->output_width; col > 0; col--) { |
shoaib_ahmed | 0:791a779d6220 | 245 | *red++ = GETJSAMPLE(*output_row++); |
shoaib_ahmed | 0:791a779d6220 | 246 | *green++ = GETJSAMPLE(*output_row++); |
shoaib_ahmed | 0:791a779d6220 | 247 | *blue++ = GETJSAMPLE(*output_row++); |
shoaib_ahmed | 0:791a779d6220 | 248 | } |
shoaib_ahmed | 0:791a779d6220 | 249 | rle_putrow(rle_row, (int) cinfo->output_width, &header); |
shoaib_ahmed | 0:791a779d6220 | 250 | #ifdef PROGRESS_REPORT |
shoaib_ahmed | 0:791a779d6220 | 251 | if (progress != NULL) { |
shoaib_ahmed | 0:791a779d6220 | 252 | progress->pub.pass_counter++; |
shoaib_ahmed | 0:791a779d6220 | 253 | (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); |
shoaib_ahmed | 0:791a779d6220 | 254 | } |
shoaib_ahmed | 0:791a779d6220 | 255 | #endif |
shoaib_ahmed | 0:791a779d6220 | 256 | } |
shoaib_ahmed | 0:791a779d6220 | 257 | } |
shoaib_ahmed | 0:791a779d6220 | 258 | |
shoaib_ahmed | 0:791a779d6220 | 259 | #ifdef PROGRESS_REPORT |
shoaib_ahmed | 0:791a779d6220 | 260 | if (progress != NULL) |
shoaib_ahmed | 0:791a779d6220 | 261 | progress->completed_extra_passes++; |
shoaib_ahmed | 0:791a779d6220 | 262 | #endif |
shoaib_ahmed | 0:791a779d6220 | 263 | |
shoaib_ahmed | 0:791a779d6220 | 264 | /* Emit file trailer */ |
shoaib_ahmed | 0:791a779d6220 | 265 | rle_puteof(&header); |
shoaib_ahmed | 0:791a779d6220 | 266 | fflush(dest->pub.output_file); |
shoaib_ahmed | 0:791a779d6220 | 267 | if (ferror(dest->pub.output_file)) |
shoaib_ahmed | 0:791a779d6220 | 268 | ERREXIT(cinfo, JERR_FILE_WRITE); |
shoaib_ahmed | 0:791a779d6220 | 269 | } |
shoaib_ahmed | 0:791a779d6220 | 270 | |
shoaib_ahmed | 0:791a779d6220 | 271 | |
shoaib_ahmed | 0:791a779d6220 | 272 | /* |
shoaib_ahmed | 0:791a779d6220 | 273 | * The module selection routine for RLE format output. |
shoaib_ahmed | 0:791a779d6220 | 274 | */ |
shoaib_ahmed | 0:791a779d6220 | 275 | |
shoaib_ahmed | 0:791a779d6220 | 276 | GLOBAL(djpeg_dest_ptr) |
shoaib_ahmed | 0:791a779d6220 | 277 | jinit_write_rle (j_decompress_ptr cinfo) |
shoaib_ahmed | 0:791a779d6220 | 278 | { |
shoaib_ahmed | 0:791a779d6220 | 279 | rle_dest_ptr dest; |
shoaib_ahmed | 0:791a779d6220 | 280 | |
shoaib_ahmed | 0:791a779d6220 | 281 | /* Create module interface object, fill in method pointers */ |
shoaib_ahmed | 0:791a779d6220 | 282 | dest = (rle_dest_ptr) |
shoaib_ahmed | 0:791a779d6220 | 283 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
shoaib_ahmed | 0:791a779d6220 | 284 | SIZEOF(rle_dest_struct)); |
shoaib_ahmed | 0:791a779d6220 | 285 | dest->pub.start_output = start_output_rle; |
shoaib_ahmed | 0:791a779d6220 | 286 | dest->pub.finish_output = finish_output_rle; |
shoaib_ahmed | 0:791a779d6220 | 287 | |
shoaib_ahmed | 0:791a779d6220 | 288 | /* Calculate output image dimensions so we can allocate space */ |
shoaib_ahmed | 0:791a779d6220 | 289 | jpeg_calc_output_dimensions(cinfo); |
shoaib_ahmed | 0:791a779d6220 | 290 | |
shoaib_ahmed | 0:791a779d6220 | 291 | /* Allocate a work array for output to the RLE library. */ |
shoaib_ahmed | 0:791a779d6220 | 292 | dest->rle_row = (*cinfo->mem->alloc_sarray) |
shoaib_ahmed | 0:791a779d6220 | 293 | ((j_common_ptr) cinfo, JPOOL_IMAGE, |
shoaib_ahmed | 0:791a779d6220 | 294 | cinfo->output_width, (JDIMENSION) cinfo->output_components); |
shoaib_ahmed | 0:791a779d6220 | 295 | |
shoaib_ahmed | 0:791a779d6220 | 296 | /* Allocate a virtual array to hold the image. */ |
shoaib_ahmed | 0:791a779d6220 | 297 | dest->image = (*cinfo->mem->request_virt_sarray) |
shoaib_ahmed | 0:791a779d6220 | 298 | ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, |
shoaib_ahmed | 0:791a779d6220 | 299 | (JDIMENSION) (cinfo->output_width * cinfo->output_components), |
shoaib_ahmed | 0:791a779d6220 | 300 | cinfo->output_height, (JDIMENSION) 1); |
shoaib_ahmed | 0:791a779d6220 | 301 | |
shoaib_ahmed | 0:791a779d6220 | 302 | return (djpeg_dest_ptr) dest; |
shoaib_ahmed | 0:791a779d6220 | 303 | } |
shoaib_ahmed | 0:791a779d6220 | 304 | |
shoaib_ahmed | 0:791a779d6220 | 305 | #endif /* RLE_SUPPORTED */ |