Fix byte order issue with 16bit PPM/PGM files

This commit is contained in:
DRC
2010-10-10 06:01:00 +00:00
parent 7a3ae15f7d
commit 3576a86dfb
2 changed files with 12 additions and 10 deletions

17
rdppm.c
View File

@@ -2,6 +2,7 @@
* rdppm.c * rdppm.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2009 by Bill Allombert, Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -250,8 +251,8 @@ get_word_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
bufferptr = source->iobuffer; bufferptr = source->iobuffer;
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
register int temp; register int temp;
temp = UCH(*bufferptr++); temp = UCH(*bufferptr++) << 8;
temp |= UCH(*bufferptr++) << 8; temp |= UCH(*bufferptr++);
*ptr++ = rescale[temp]; *ptr++ = rescale[temp];
} }
return 1; return 1;
@@ -274,14 +275,14 @@ get_word_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
bufferptr = source->iobuffer; bufferptr = source->iobuffer;
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
register int temp; register int temp;
temp = UCH(*bufferptr++); temp = UCH(*bufferptr++) << 8;
temp |= UCH(*bufferptr++) << 8; temp |= UCH(*bufferptr++);
*ptr++ = rescale[temp]; *ptr++ = rescale[temp];
temp = UCH(*bufferptr++); temp = UCH(*bufferptr++) << 8;
temp |= UCH(*bufferptr++) << 8; temp |= UCH(*bufferptr++);
*ptr++ = rescale[temp]; *ptr++ = rescale[temp];
temp = UCH(*bufferptr++); temp = UCH(*bufferptr++) << 8;
temp |= UCH(*bufferptr++) << 8; temp |= UCH(*bufferptr++);
*ptr++ = rescale[temp]; *ptr++ = rescale[temp];
} }
return 1; return 1;

View File

@@ -2,6 +2,7 @@
* wrppm.c * wrppm.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2009 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -40,11 +41,11 @@
#define BYTESPERSAMPLE 1 #define BYTESPERSAMPLE 1
#define PPM_MAXVAL 255 #define PPM_MAXVAL 255
#else #else
/* The word-per-sample format always puts the LSB first. */ /* The word-per-sample format always puts the MSB first. */
#define PUTPPMSAMPLE(ptr,v) \ #define PUTPPMSAMPLE(ptr,v) \
{ register int val_ = v; \ { register int val_ = v; \
*ptr++ = (char) (val_ & 0xFF); \
*ptr++ = (char) ((val_ >> 8) & 0xFF); \ *ptr++ = (char) ((val_ >> 8) & 0xFF); \
*ptr++ = (char) (val_ & 0xFF); \
} }
#define BYTESPERSAMPLE 2 #define BYTESPERSAMPLE 2
#define PPM_MAXVAL ((1<<BITS_IN_JSAMPLE)-1) #define PPM_MAXVAL ((1<<BITS_IN_JSAMPLE)-1)