From ba2fd0316b6ac8fa7884ddffa93b557cb4eef7a8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 27 May 2011 08:55:37 +0000 Subject: [PATCH] From Eric Sokolowsky, "Attached is an updated PNM plugin for inclusion in both the trunk and for release version 2.8.5. The attached file fixes numerous bugs in reading 8-bit and 16-bit images, including loading the images upside-down. This file also incorporates trunk patch r12220 which updated the plugin for reading and writing images through streams instead of C-style FILE I/O." --- src/osgPlugins/pnm/ReaderWriterPNM.cpp | 65 -------------------------- 1 file changed, 65 deletions(-) diff --git a/src/osgPlugins/pnm/ReaderWriterPNM.cpp b/src/osgPlugins/pnm/ReaderWriterPNM.cpp index 85739d3ee..864be6f68 100644 --- a/src/osgPlugins/pnm/ReaderWriterPNM.cpp +++ b/src/osgPlugins/pnm/ReaderWriterPNM.cpp @@ -23,54 +23,27 @@ template { T* data = new T[width*height]; - T* dst = data; - T* end = data + width*height; - T value = 0; - unsigned long num; - while(dst < end) { - // read in characters looking for '0's and '1's, these - // values map to 255 and 0. Any other characters - // are silently ignored. - fin >> num; if (!fin.good()) { delete [] data; return NULL; } - if (num == 1) { - value = 0; - break; } - else if (num == 0) - { - value = 255; - break; - } - - // place value in the image - *(dst++) = value; } return reinterpret_cast(data); } template - unsigned char* read_grayscale_ascii(std::istream& fin, int width, int height) { T* data = new T[width*height]; - T* dst = data; - T* end = data + width*height; - T value = 0; - unsigned long num; - while(dst < end) { - fin >> num; if (!fin.good()) { delete [] data; @@ -78,25 +51,17 @@ template } // place value in the image - *(dst++) = value; } return reinterpret_cast(data); } template - unsigned char* read_color_ascii(std::istream& fin, int width, int height) { T* data = new T[3*width*height]; - T* dst = data; - T* end = data + 3*width*height; - T value = 0; - unsigned long num; - while(dst < end) { - fin >> num; if (!fin.good()) { delete [] data; @@ -104,7 +69,6 @@ template } // place value in the image - *(dst++) = value; } return reinterpret_cast(data); @@ -115,7 +79,6 @@ template { T* data = new T[width*height]; - for(int y = 0; y < height; y++) { T* dst = data + (y+0)*width; T* end = data + (y+1)*width; @@ -144,46 +107,31 @@ template template unsigned char* read_grayscale_binary(std::istream& fin, int width, int height) { - unsigned char* data = new unsigned char[sizeof(T)*width*height]; - fin.read((char*)data, sizeof(T)*width*height); - if (!fin.good()) { - delete [] data; - return NULL; } // if the machine is little endian swap the bytes around if (sizeof(T) == 2 && getCpuByteOrder() == osg::LittleEndian) { - for(int i = 0; i < width*height; i++) { - unsigned char* bs = (unsigned char*)(&data[i]); std::swap(bs[0], bs[1]); } } - return data; } template unsigned char* read_color_binary(std::istream& fin, int width, int height) { - unsigned char* data = new unsigned char[sizeof(T)*3*width*height]; - fin.read((char*)data, sizeof(T)*3*width*height); - if (!fin.good()) { - delete [] data; - return NULL; } // if the machine is little endian swap the bytes around if (sizeof(T) == 2 && getCpuByteOrder() == osg::LittleEndian) { - for(int i = 0; i < 3*width*height; i++) { - unsigned char* bs = (unsigned char*)(&data[i]); std::swap(bs[0], bs[1]); } } @@ -272,25 +220,14 @@ class ReaderWriterPNM : public osgDB::ReaderWriter if (max_value > 255) { - OSG_NOTICE<<"OpenSceneGraph PPM reader: width="<