diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2010-04-10 16:07:24 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2010-04-10 16:07:24 +0000 |
commit | 7d714381d1af9f51ae0094df79e1fe8d28c46b84 (patch) | |
tree | cf576cb526aa84b025b3bb599062e1849a55a3b0 /lib/libppm1.c | |
parent | 73225706f044df73549d0982e782b41ff94e117f (diff) | |
download | netpbm-mirror-7d714381d1af9f51ae0094df79e1fe8d28c46b84.tar.gz netpbm-mirror-7d714381d1af9f51ae0094df79e1fe8d28c46b84.tar.xz netpbm-mirror-7d714381d1af9f51ae0094df79e1fe8d28c46b84.zip |
Fix compiler warnings
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1185 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libppm1.c')
-rw-r--r-- | lib/libppm1.c | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/lib/libppm1.c b/lib/libppm1.c index ea929908..7b92d3ee 100644 --- a/lib/libppm1.c +++ b/lib/libppm1.c @@ -184,6 +184,46 @@ readPpmRow(FILE * const fileP, static void +interpRasterRowRaw(const unsigned char * const rowBuffer, + pixel * const pixelrow, + unsigned int const cols, + unsigned int const bytesPerSample) { + + unsigned int bufferCursor; + + bufferCursor = 0; /* start at beginning of rowBuffer[] */ + + if (bytesPerSample == 1) { + unsigned int col; + for (col = 0; col < cols; ++col) { + pixval const r = rowBuffer[bufferCursor++]; + pixval const g = rowBuffer[bufferCursor++]; + pixval const b = rowBuffer[bufferCursor++]; + PPM_ASSIGN(pixelrow[col], r, g, b); + } + } else { + /* two byte samples */ + unsigned int col; + for (col = 0; col < cols; ++col) { + pixval r, g, b; + + r = rowBuffer[bufferCursor++] << 8; + r |= rowBuffer[bufferCursor++]; + + g = rowBuffer[bufferCursor++] << 8; + g |= rowBuffer[bufferCursor++]; + + b = rowBuffer[bufferCursor++] << 8; + b |= rowBuffer[bufferCursor++]; + + PPM_ASSIGN(pixelrow[col], r, g, b); + } + } +} + + + +static void readRppmRow(FILE * const fileP, pixel * const pixelrow, unsigned int const cols, @@ -211,41 +251,14 @@ readRppmRow(FILE * const fileP, else if (ferror(fileP)) asprintfN(&error, "Error reading row. fread() errno=%d (%s)", errno, strerror(errno)); - else if (rc != bytesPerRow) - asprintfN(&error, "Error reading row. Short read of %u bytes " - "instead of %u", rc, bytesPerRow); else { - unsigned int bufferCursor; - - error = NULL; - - bufferCursor = 0; /* start at beginning of rowBuffer[] */ - - if (bytesPerSample == 1) { - unsigned int col; - for (col = 0; col < cols; ++col) { - pixval const r = rowBuffer[bufferCursor++]; - pixval const g = rowBuffer[bufferCursor++]; - pixval const b = rowBuffer[bufferCursor++]; - PPM_ASSIGN(pixelrow[col], r, g, b); - } - } else { - /* two byte samples */ - unsigned int col; - for (col = 0; col < cols; ++col) { - pixval r, g, b; - - r = rowBuffer[bufferCursor++] << 8; - r |= rowBuffer[bufferCursor++]; - - g = rowBuffer[bufferCursor++] << 8; - g |= rowBuffer[bufferCursor++]; - - b = rowBuffer[bufferCursor++] << 8; - b |= rowBuffer[bufferCursor++]; - - PPM_ASSIGN(pixelrow[col], r, g, b); - } + size_t const bytesRead = rc; + if (bytesRead != bytesPerRow) + asprintfN(&error, "Error reading row. Short read of %u bytes " + "instead of %u", (unsigned)bytesRead, bytesPerRow); + else { + interpRasterRowRaw(rowBuffer, pixelrow, cols, bytesPerSample); + error = NULL; } } free(rowBuffer); |