OLD | NEW |
1 /* | 1 /* |
2 * rdppm.c | 2 * rdppm.c |
3 * | 3 * |
4 * Copyright (C) 1991-1997, Thomas G. Lane. | 4 * Copyright (C) 1991-1997, Thomas G. Lane. |
| 5 * Modified 2009 by Bill Allombert, Guido Vollbeding. |
5 * This file is part of the Independent JPEG Group's software. | 6 * This file is part of the Independent JPEG Group's software. |
6 * For conditions of distribution and use, see the accompanying README file. | 7 * For conditions of distribution and use, see the accompanying README file. |
7 * | 8 * |
8 * This file contains routines to read input images in PPM/PGM format. | 9 * This file contains routines to read input images in PPM/PGM format. |
9 * The extended 2-byte-per-sample raw PPM/PGM formats are supported. | 10 * The extended 2-byte-per-sample raw PPM/PGM formats are supported. |
10 * The PBMPLUS library is NOT required to compile this software | 11 * The PBMPLUS library is NOT required to compile this software |
11 * (but it is highly useful as a set of PPM image manipulation programs). | 12 * (but it is highly useful as a set of PPM image manipulation programs). |
12 * | 13 * |
13 * These routines may need modification for non-Unix environments or | 14 * These routines may need modification for non-Unix environments or |
14 * specialized applications. As they stand, they assume input from | 15 * specialized applications. As they stand, they assume input from |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 register U_CHAR * bufferptr; | 244 register U_CHAR * bufferptr; |
244 register JSAMPLE *rescale = source->rescale; | 245 register JSAMPLE *rescale = source->rescale; |
245 JDIMENSION col; | 246 JDIMENSION col; |
246 | 247 |
247 if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 248 if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
248 ERREXIT(cinfo, JERR_INPUT_EOF); | 249 ERREXIT(cinfo, JERR_INPUT_EOF); |
249 ptr = source->pub.buffer[0]; | 250 ptr = source->pub.buffer[0]; |
250 bufferptr = source->iobuffer; | 251 bufferptr = source->iobuffer; |
251 for (col = cinfo->image_width; col > 0; col--) { | 252 for (col = cinfo->image_width; col > 0; col--) { |
252 register int temp; | 253 register int temp; |
253 temp = UCH(*bufferptr++); | 254 temp = UCH(*bufferptr++) << 8; |
254 temp |= UCH(*bufferptr++) << 8; | 255 temp |= UCH(*bufferptr++); |
255 *ptr++ = rescale[temp]; | 256 *ptr++ = rescale[temp]; |
256 } | 257 } |
257 return 1; | 258 return 1; |
258 } | 259 } |
259 | 260 |
260 | 261 |
261 METHODDEF(JDIMENSION) | 262 METHODDEF(JDIMENSION) |
262 get_word_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) | 263 get_word_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
263 /* This version is for reading raw-word-format PPM files with any maxval */ | 264 /* This version is for reading raw-word-format PPM files with any maxval */ |
264 { | 265 { |
265 ppm_source_ptr source = (ppm_source_ptr) sinfo; | 266 ppm_source_ptr source = (ppm_source_ptr) sinfo; |
266 register JSAMPROW ptr; | 267 register JSAMPROW ptr; |
267 register U_CHAR * bufferptr; | 268 register U_CHAR * bufferptr; |
268 register JSAMPLE *rescale = source->rescale; | 269 register JSAMPLE *rescale = source->rescale; |
269 JDIMENSION col; | 270 JDIMENSION col; |
270 | 271 |
271 if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 272 if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
272 ERREXIT(cinfo, JERR_INPUT_EOF); | 273 ERREXIT(cinfo, JERR_INPUT_EOF); |
273 ptr = source->pub.buffer[0]; | 274 ptr = source->pub.buffer[0]; |
274 bufferptr = source->iobuffer; | 275 bufferptr = source->iobuffer; |
275 for (col = cinfo->image_width; col > 0; col--) { | 276 for (col = cinfo->image_width; col > 0; col--) { |
276 register int temp; | 277 register int temp; |
277 temp = UCH(*bufferptr++); | 278 temp = UCH(*bufferptr++) << 8; |
278 temp |= UCH(*bufferptr++) << 8; | 279 temp |= UCH(*bufferptr++); |
279 *ptr++ = rescale[temp]; | 280 *ptr++ = rescale[temp]; |
280 temp = UCH(*bufferptr++); | 281 temp = UCH(*bufferptr++) << 8; |
281 temp |= UCH(*bufferptr++) << 8; | 282 temp |= UCH(*bufferptr++); |
282 *ptr++ = rescale[temp]; | 283 *ptr++ = rescale[temp]; |
283 temp = UCH(*bufferptr++); | 284 temp = UCH(*bufferptr++) << 8; |
284 temp |= UCH(*bufferptr++) << 8; | 285 temp |= UCH(*bufferptr++); |
285 *ptr++ = rescale[temp]; | 286 *ptr++ = rescale[temp]; |
286 } | 287 } |
287 return 1; | 288 return 1; |
288 } | 289 } |
289 | 290 |
290 | 291 |
291 /* | 292 /* |
292 * Read the file header; return image size and component count. | 293 * Read the file header; return image size and component count. |
293 */ | 294 */ |
294 | 295 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 450 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
450 SIZEOF(ppm_source_struct)); | 451 SIZEOF(ppm_source_struct)); |
451 /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 452 /* Fill in method ptrs, except get_pixel_rows which start_input sets */ |
452 source->pub.start_input = start_input_ppm; | 453 source->pub.start_input = start_input_ppm; |
453 source->pub.finish_input = finish_input_ppm; | 454 source->pub.finish_input = finish_input_ppm; |
454 | 455 |
455 return (cjpeg_source_ptr) source; | 456 return (cjpeg_source_ptr) source; |
456 } | 457 } |
457 | 458 |
458 #endif /* PPM_SUPPORTED */ | 459 #endif /* PPM_SUPPORTED */ |
OLD | NEW |