Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: wrrle.c

Issue 1953443002: Update to libjpeg_turbo 1.4.90 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « wrppm.c ('k') | wrtarga.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * wrrle.c 2 * wrrle.c
3 * 3 *
4 * This file was part of the Independent JPEG Group's software:
4 * Copyright (C) 1991-1996, Thomas G. Lane. 5 * Copyright (C) 1991-1996, Thomas G. Lane.
5 * This file is part of the Independent JPEG Group's software. 6 * It was modified by The libjpeg-turbo Project to include only code and
6 * For conditions of distribution and use, see the accompanying README file. 7 * information relevant to libjpeg-turbo.
8 * For conditions of distribution and use, see the accompanying README.ijg
9 * file.
7 * 10 *
8 * This file contains routines to write output images in RLE format. 11 * This file contains routines to write output images in RLE format.
9 * The Utah Raster Toolkit library is required (version 3.1 or later). 12 * The Utah Raster Toolkit library is required (version 3.1 or later).
10 * 13 *
11 * These routines may need modification for non-Unix environments or 14 * These routines may need modification for non-Unix environments or
12 * specialized applications. As they stand, they assume output to 15 * specialized applications. As they stand, they assume output to
13 * an ordinary stdio stream. 16 * an ordinary stdio stream.
14 * 17 *
15 * Based on code contributed by Mike Lijewski, 18 * Based on code contributed by Mike Lijewski,
16 * with updates from Robert Hutchinson. 19 * with updates from Robert Hutchinson.
17 */ 20 */
18 21
19 #include "cdjpeg.h"» » /* Common decls for cjpeg/djpeg applications */ 22 #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
20 23
21 #ifdef RLE_SUPPORTED 24 #ifdef RLE_SUPPORTED
22 25
23 /* rle.h is provided by the Utah Raster Toolkit. */ 26 /* rle.h is provided by the Utah Raster Toolkit. */
24 27
25 #include <rle.h> 28 #include <rle.h>
26 29
27 /* 30 /*
28 * We assume that JSAMPLE has the same representation as rle_pixel, 31 * We assume that JSAMPLE has the same representation as rle_pixel,
29 * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples. 32 * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples.
(...skipping 10 matching lines...) Expand all
40 * in a virtual array during put_pixel_row calls, then actually emit the 43 * in a virtual array during put_pixel_row calls, then actually emit the
41 * RLE file during finish_output. 44 * RLE file during finish_output.
42 */ 45 */
43 46
44 47
45 /* 48 /*
46 * For now, if we emit an RLE color map then it is always 256 entries long, 49 * For now, if we emit an RLE color map then it is always 256 entries long,
47 * though not all of the entries need be used. 50 * though not all of the entries need be used.
48 */ 51 */
49 52
50 #define CMAPBITS» 8 53 #define CMAPBITS 8
51 #define CMAPLENGTH» (1<<(CMAPBITS)) 54 #define CMAPLENGTH (1<<(CMAPBITS))
52 55
53 typedef struct { 56 typedef struct {
54 struct djpeg_dest_struct pub; /* public fields */ 57 struct djpeg_dest_struct pub; /* public fields */
55 58
56 jvirt_sarray_ptr image;» /* virtual array to store the output image */ 59 jvirt_sarray_ptr image; /* virtual array to store the output image */
57 rle_map *colormap;» » /* RLE-style color map, or NULL if none */ 60 rle_map *colormap; /* RLE-style color map, or NULL if none */
58 rle_pixel **rle_row;» » /* To pass rows to rle_putrow() */ 61 rle_pixel **rle_row; /* To pass rows to rle_putrow() */
59 62
60 } rle_dest_struct; 63 } rle_dest_struct;
61 64
62 typedef rle_dest_struct * rle_dest_ptr; 65 typedef rle_dest_struct *rle_dest_ptr;
63 66
64 /* Forward declarations */ 67 /* Forward declarations */
65 METHODDEF(void) rle_put_pixel_rows 68 METHODDEF(void) rle_put_pixel_rows
66 JPP((j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, 69 (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
67 » JDIMENSION rows_supplied)); 70 JDIMENSION rows_supplied);
68 71
69 72
70 /* 73 /*
71 * Write the file header. 74 * Write the file header.
72 * 75 *
73 * In this module it's easier to wait till finish_output to write anything. 76 * In this module it's easier to wait till finish_output to write anything.
74 */ 77 */
75 78
76 METHODDEF(void) 79 METHODDEF(void)
77 start_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) 80 start_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
(...skipping 12 matching lines...) Expand all
90 * uses unsigned, so we have to check the width. 93 * uses unsigned, so we have to check the width.
91 * 94 *
92 * - Colorspace is expected to be grayscale or RGB. 95 * - Colorspace is expected to be grayscale or RGB.
93 * 96 *
94 * - The number of channels (components) is expected to be 1 (grayscale/ 97 * - The number of channels (components) is expected to be 1 (grayscale/
95 * pseudocolor) or 3 (truecolor/directcolor). 98 * pseudocolor) or 3 (truecolor/directcolor).
96 * (could be 2 or 4 if using an alpha channel, but we aren't) 99 * (could be 2 or 4 if using an alpha channel, but we aren't)
97 */ 100 */
98 101
99 if (cinfo->output_width > 32767 || cinfo->output_height > 32767) 102 if (cinfo->output_width > 32767 || cinfo->output_height > 32767)
100 ERREXIT2(cinfo, JERR_RLE_DIMENSIONS, cinfo->output_width, 103 ERREXIT2(cinfo, JERR_RLE_DIMENSIONS, cinfo->output_width,
101 » cinfo->output_height); 104 cinfo->output_height);
102 105
103 if (cinfo->out_color_space != JCS_GRAYSCALE && 106 if (cinfo->out_color_space != JCS_GRAYSCALE &&
104 cinfo->out_color_space != JCS_RGB) 107 cinfo->out_color_space != JCS_RGB)
105 ERREXIT(cinfo, JERR_RLE_COLORSPACE); 108 ERREXIT(cinfo, JERR_RLE_COLORSPACE);
106 109
107 if (cinfo->output_components != 1 && cinfo->output_components != 3) 110 if (cinfo->output_components != 1 && cinfo->output_components != 3)
108 ERREXIT1(cinfo, JERR_RLE_TOOMANYCHANNELS, cinfo->num_components); 111 ERREXIT1(cinfo, JERR_RLE_TOOMANYCHANNELS, cinfo->num_components);
109 112
110 /* Convert colormap, if any, to RLE format. */ 113 /* Convert colormap, if any, to RLE format. */
111 114
112 dest->colormap = NULL; 115 dest->colormap = NULL;
113 116
114 if (cinfo->quantize_colors) { 117 if (cinfo->quantize_colors) {
115 /* Allocate storage for RLE-style cmap, zero any extra entries */ 118 /* Allocate storage for RLE-style cmap, zero any extra entries */
116 cmapsize = cinfo->out_color_components * CMAPLENGTH * SIZEOF(rle_map); 119 cmapsize = cinfo->out_color_components * CMAPLENGTH * sizeof(rle_map);
117 dest->colormap = (rle_map *) (*cinfo->mem->alloc_small) 120 dest->colormap = (rle_map *) (*cinfo->mem->alloc_small)
118 ((j_common_ptr) cinfo, JPOOL_IMAGE, cmapsize); 121 ((j_common_ptr) cinfo, JPOOL_IMAGE, cmapsize);
119 MEMZERO(dest->colormap, cmapsize); 122 MEMZERO(dest->colormap, cmapsize);
120 123
121 /* Save away data in RLE format --- note 8-bit left shift! */ 124 /* Save away data in RLE format --- note 8-bit left shift! */
122 /* Shifting would need adjustment for JSAMPLEs wider than 8 bits. */ 125 /* Shifting would need adjustment for JSAMPLEs wider than 8 bits. */
123 for (ci = 0; ci < cinfo->out_color_components; ci++) { 126 for (ci = 0; ci < cinfo->out_color_components; ci++) {
124 for (i = 0; i < cinfo->actual_number_of_colors; i++) { 127 for (i = 0; i < cinfo->actual_number_of_colors; i++) {
125 dest->colormap[ci * CMAPLENGTH + i] = 128 dest->colormap[ci * CMAPLENGTH + i] =
126 GETJSAMPLE(cinfo->colormap[ci][i]) << 8; 129 GETJSAMPLE(cinfo->colormap[ci][i]) << 8;
(...skipping 17 matching lines...) Expand all
144 147
145 148
146 /* 149 /*
147 * Write some pixel data. 150 * Write some pixel data.
148 * 151 *
149 * This routine just saves the data away in a virtual array. 152 * This routine just saves the data away in a virtual array.
150 */ 153 */
151 154
152 METHODDEF(void) 155 METHODDEF(void)
153 rle_put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, 156 rle_put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
154 » » JDIMENSION rows_supplied) 157 JDIMENSION rows_supplied)
155 { 158 {
156 rle_dest_ptr dest = (rle_dest_ptr) dinfo; 159 rle_dest_ptr dest = (rle_dest_ptr) dinfo;
157 160
158 if (cinfo->output_scanline < cinfo->output_height) { 161 if (cinfo->output_scanline < cinfo->output_height) {
159 dest->pub.buffer = (*cinfo->mem->access_virt_sarray) 162 dest->pub.buffer = (*cinfo->mem->access_virt_sarray)
160 ((j_common_ptr) cinfo, dest->image, 163 ((j_common_ptr) cinfo, dest->image,
161 cinfo->output_scanline, (JDIMENSION) 1, TRUE); 164 cinfo->output_scanline, (JDIMENSION) 1, TRUE);
162 } 165 }
163 } 166 }
164 167
165 /* 168 /*
166 * Finish up at the end of the file. 169 * Finish up at the end of the file.
167 * 170 *
168 * Here is where we really output the RLE file. 171 * Here is where we really output the RLE file.
169 */ 172 */
170 173
171 METHODDEF(void) 174 METHODDEF(void)
172 finish_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) 175 finish_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
173 { 176 {
174 rle_dest_ptr dest = (rle_dest_ptr) dinfo; 177 rle_dest_ptr dest = (rle_dest_ptr) dinfo;
175 rle_hdr header;» » /* Output file information */ 178 rle_hdr header; /* Output file information */
176 rle_pixel **rle_row, *red, *green, *blue; 179 rle_pixel **rle_row, *red, *green, *blue;
177 JSAMPROW output_row; 180 JSAMPROW output_row;
178 char cmapcomment[80]; 181 char cmapcomment[80];
179 int row, col; 182 int row, col;
180 int ci; 183 int ci;
181 #ifdef PROGRESS_REPORT 184 #ifdef PROGRESS_REPORT
182 cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; 185 cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
183 #endif 186 #endif
184 187
185 /* Initialize the header info */ 188 /* Initialize the header info */
(...skipping 14 matching lines...) Expand all
200 header.cmap = dest->colormap; 203 header.cmap = dest->colormap;
201 /* Add a comment to the output image with the true colormap length. */ 204 /* Add a comment to the output image with the true colormap length. */
202 sprintf(cmapcomment, "color_map_length=%d", cinfo->actual_number_of_colors); 205 sprintf(cmapcomment, "color_map_length=%d", cinfo->actual_number_of_colors);
203 rle_putcom(cmapcomment, &header); 206 rle_putcom(cmapcomment, &header);
204 } 207 }
205 208
206 /* Emit the RLE header and color map (if any) */ 209 /* Emit the RLE header and color map (if any) */
207 rle_put_setup(&header); 210 rle_put_setup(&header);
208 211
209 /* Now output the RLE data from our virtual array. 212 /* Now output the RLE data from our virtual array.
210 * We assume here that (a) rle_pixel is represented the same as JSAMPLE, 213 * We assume here that rle_pixel is represented the same as JSAMPLE.
211 * and (b) we are not on a machine where FAR pointers differ from regular.
212 */ 214 */
213 215
214 #ifdef PROGRESS_REPORT 216 #ifdef PROGRESS_REPORT
215 if (progress != NULL) { 217 if (progress != NULL) {
216 progress->pub.pass_limit = cinfo->output_height; 218 progress->pub.pass_limit = cinfo->output_height;
217 progress->pub.pass_counter = 0; 219 progress->pub.pass_counter = 0;
218 (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); 220 (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
219 } 221 }
220 #endif 222 #endif
221 223
222 if (cinfo->output_components == 1) { 224 if (cinfo->output_components == 1) {
223 for (row = cinfo->output_height-1; row >= 0; row--) { 225 for (row = cinfo->output_height-1; row >= 0; row--) {
224 rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray) 226 rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray)
225 ((j_common_ptr) cinfo, dest->image, 227 ((j_common_ptr) cinfo, dest->image,
226 » (JDIMENSION) row, (JDIMENSION) 1, FALSE); 228 (JDIMENSION) row, (JDIMENSION) 1, FALSE);
227 rle_putrow(rle_row, (int) cinfo->output_width, &header); 229 rle_putrow(rle_row, (int) cinfo->output_width, &header);
228 #ifdef PROGRESS_REPORT 230 #ifdef PROGRESS_REPORT
229 if (progress != NULL) { 231 if (progress != NULL) {
230 progress->pub.pass_counter++; 232 progress->pub.pass_counter++;
231 (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); 233 (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
232 } 234 }
233 #endif 235 #endif
234 } 236 }
235 } else { 237 } else {
236 for (row = cinfo->output_height-1; row >= 0; row--) { 238 for (row = cinfo->output_height-1; row >= 0; row--) {
237 rle_row = (rle_pixel **) dest->rle_row; 239 rle_row = (rle_pixel **) dest->rle_row;
238 output_row = * (*cinfo->mem->access_virt_sarray) 240 output_row = *(*cinfo->mem->access_virt_sarray)
239 ((j_common_ptr) cinfo, dest->image, 241 ((j_common_ptr) cinfo, dest->image,
240 » (JDIMENSION) row, (JDIMENSION) 1, FALSE); 242 (JDIMENSION) row, (JDIMENSION) 1, FALSE);
241 red = rle_row[0]; 243 red = rle_row[0];
242 green = rle_row[1]; 244 green = rle_row[1];
243 blue = rle_row[2]; 245 blue = rle_row[2];
244 for (col = cinfo->output_width; col > 0; col--) { 246 for (col = cinfo->output_width; col > 0; col--) {
245 *red++ = GETJSAMPLE(*output_row++); 247 *red++ = GETJSAMPLE(*output_row++);
246 *green++ = GETJSAMPLE(*output_row++); 248 *green++ = GETJSAMPLE(*output_row++);
247 *blue++ = GETJSAMPLE(*output_row++); 249 *blue++ = GETJSAMPLE(*output_row++);
248 } 250 }
249 rle_putrow(rle_row, (int) cinfo->output_width, &header); 251 rle_putrow(rle_row, (int) cinfo->output_width, &header);
250 #ifdef PROGRESS_REPORT 252 #ifdef PROGRESS_REPORT
(...skipping 23 matching lines...) Expand all
274 */ 276 */
275 277
276 GLOBAL(djpeg_dest_ptr) 278 GLOBAL(djpeg_dest_ptr)
277 jinit_write_rle (j_decompress_ptr cinfo) 279 jinit_write_rle (j_decompress_ptr cinfo)
278 { 280 {
279 rle_dest_ptr dest; 281 rle_dest_ptr dest;
280 282
281 /* Create module interface object, fill in method pointers */ 283 /* Create module interface object, fill in method pointers */
282 dest = (rle_dest_ptr) 284 dest = (rle_dest_ptr)
283 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 285 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
284 SIZEOF(rle_dest_struct)); 286 sizeof(rle_dest_struct));
285 dest->pub.start_output = start_output_rle; 287 dest->pub.start_output = start_output_rle;
286 dest->pub.finish_output = finish_output_rle; 288 dest->pub.finish_output = finish_output_rle;
287 289
288 /* Calculate output image dimensions so we can allocate space */ 290 /* Calculate output image dimensions so we can allocate space */
289 jpeg_calc_output_dimensions(cinfo); 291 jpeg_calc_output_dimensions(cinfo);
290 292
291 /* Allocate a work array for output to the RLE library. */ 293 /* Allocate a work array for output to the RLE library. */
292 dest->rle_row = (*cinfo->mem->alloc_sarray) 294 dest->rle_row = (*cinfo->mem->alloc_sarray)
293 ((j_common_ptr) cinfo, JPOOL_IMAGE, 295 ((j_common_ptr) cinfo, JPOOL_IMAGE,
294 cinfo->output_width, (JDIMENSION) cinfo->output_components); 296 cinfo->output_width, (JDIMENSION) cinfo->output_components);
295 297
296 /* Allocate a virtual array to hold the image. */ 298 /* Allocate a virtual array to hold the image. */
297 dest->image = (*cinfo->mem->request_virt_sarray) 299 dest->image = (*cinfo->mem->request_virt_sarray)
298 ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, 300 ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
299 (JDIMENSION) (cinfo->output_width * cinfo->output_components), 301 (JDIMENSION) (cinfo->output_width * cinfo->output_components),
300 cinfo->output_height, (JDIMENSION) 1); 302 cinfo->output_height, (JDIMENSION) 1);
301 303
302 return (djpeg_dest_ptr) dest; 304 return (djpeg_dest_ptr) dest;
303 } 305 }
304 306
305 #endif /* RLE_SUPPORTED */ 307 #endif /* RLE_SUPPORTED */
OLDNEW
« no previous file with comments | « wrppm.c ('k') | wrtarga.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698