From 0123cdbe8f6f66683e41af5d5cccc57f101179c7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 25 Mar 2005 11:17:33 +0000 Subject: [PATCH] From Waltice (don't have full name at time of submission), added support for 16bit tiff files --- src/osgPlugins/tiff/ReaderWriterTIFF.cpp | 31 ++++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/osgPlugins/tiff/ReaderWriterTIFF.cpp b/src/osgPlugins/tiff/ReaderWriterTIFF.cpp index d638d8175..4ef5556c0 100644 --- a/src/osgPlugins/tiff/ReaderWriterTIFF.cpp +++ b/src/osgPlugins/tiff/ReaderWriterTIFF.cpp @@ -105,12 +105,26 @@ checkcmap(int n, uint16* r, uint16* g, uint16* b) static void -invert_row(unsigned char *ptr, unsigned char *data, int n, int invert) +invert_row(unsigned char *ptr, unsigned char *data, int n, int invert, uint16 bitspersample) { - while (n--) + if (bitspersample == 8) { - if (invert) *ptr++ = 255 - *data++; - else *ptr++ = *data++; + while (n--) + { + if (invert) *ptr++ = 255 - *data++; + else *ptr++ = *data++; + } + } + else + { + unsigned short *ptr1 = (unsigned short *)ptr; + unsigned short *data1 = (unsigned short *)data; + + while (n--) + { + if (invert) *ptr1++ = 65535 - *data1++; + else *ptr1++ = *data1++; + } } } @@ -250,9 +264,9 @@ int *numComponents_ret) if (TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample) == 1) { - if (bitspersample != 8) + if (bitspersample != 8 && bitspersample != 16) { - /* can only handle 8-bit samples. */ + /* can only handle 8 and 16 bit samples. */ TIFFClose(in); tifferror = ERR_UNSUPPORTED; return NULL; @@ -281,7 +295,7 @@ int *numComponents_ret) else format = 3; */ - format = samplesperpixel; + format = samplesperpixel * bitspersample / 8; buffer = new unsigned char [w*h*format]; for(unsigned char* ptr=buffer;ptr