From Per Fahlberg, added support for writing 16-bit rgb images
This commit is contained in:
parent
b7b4fd5928
commit
f2b2f00ea1
@ -547,7 +547,10 @@ class ReaderWriterRGB : public osgDB::ReaderWriter
|
|||||||
|
|
||||||
GLenum pixelFormat = img.getPixelFormat();
|
GLenum pixelFormat = img.getPixelFormat();
|
||||||
|
|
||||||
raw.dim =
|
raw.dim = 3;
|
||||||
|
raw.sizeX = img.s();
|
||||||
|
raw.sizeY = img.t();
|
||||||
|
raw.sizeZ =
|
||||||
pixelFormat == GL_COLOR_INDEX? 1 :
|
pixelFormat == GL_COLOR_INDEX? 1 :
|
||||||
pixelFormat == GL_RED? 1 :
|
pixelFormat == GL_RED? 1 :
|
||||||
pixelFormat == GL_GREEN? 1 :
|
pixelFormat == GL_GREEN? 1 :
|
||||||
@ -559,30 +562,47 @@ class ReaderWriterRGB : public osgDB::ReaderWriter
|
|||||||
pixelFormat == GL_BGRA? 4 :
|
pixelFormat == GL_BGRA? 4 :
|
||||||
pixelFormat == GL_LUMINANCE? 1 :
|
pixelFormat == GL_LUMINANCE? 1 :
|
||||||
pixelFormat == GL_LUMINANCE_ALPHA ? 2 : 1;
|
pixelFormat == GL_LUMINANCE_ALPHA ? 2 : 1;
|
||||||
|
|
||||||
raw.sizeX = img.s();
|
|
||||||
raw.sizeY = img.t();
|
|
||||||
raw.sizeZ = raw.dim;
|
|
||||||
raw.min = 0;
|
raw.min = 0;
|
||||||
raw.max = 0xFF;
|
raw.max = 0xFF;
|
||||||
raw.wasteBytes = 0;
|
raw.wasteBytes = 0;
|
||||||
strncpy( raw.name, name.c_str(), 80);
|
strncpy( raw.name, name.c_str(), 80);
|
||||||
raw.colorMap = 0;
|
raw.colorMap = 0;
|
||||||
|
raw.bpc = (img.getPixelSizeInBits()/raw.sizeZ)/8;
|
||||||
|
|
||||||
int isize = img.getImageSizeInBytes();
|
int isize = img.getImageSizeInBytes();
|
||||||
unsigned char *buffer = new unsigned char[isize];
|
unsigned char *buffer = new unsigned char[isize];
|
||||||
unsigned char *dptr = buffer;
|
if(raw.bpc == 1)
|
||||||
int i, j;
|
|
||||||
for( i = 0; i < raw.sizeZ; i++ )
|
|
||||||
{
|
{
|
||||||
const unsigned char *ptr = img.data();
|
unsigned char *dptr = buffer;
|
||||||
ptr += i;
|
int i, j;
|
||||||
for( j = 0; j < isize/raw.sizeZ; j++ )
|
for( i = 0; i < raw.sizeZ; ++i )
|
||||||
{
|
{
|
||||||
*(dptr++) = *ptr;
|
const unsigned char *ptr = img.data();
|
||||||
ptr += raw.sizeZ;
|
ptr += i;
|
||||||
|
for( j = 0; j < isize/raw.sizeZ; ++j )
|
||||||
|
{
|
||||||
|
*(dptr++) = *ptr;
|
||||||
|
ptr += raw.sizeZ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{ // bpc == 2
|
||||||
|
unsigned short *dptr = reinterpret_cast<unsigned short*>(buffer);
|
||||||
|
int i, j;
|
||||||
|
for( i = 0; i < raw.sizeZ; ++i )
|
||||||
|
{
|
||||||
|
const unsigned short *ptr = reinterpret_cast<const unsigned short*>(img.data());
|
||||||
|
ptr += i;
|
||||||
|
for( j = 0; j < isize/(raw.sizeZ*2); ++j )
|
||||||
|
{
|
||||||
|
*dptr = *ptr;
|
||||||
|
ConvertShort(dptr++, 1);
|
||||||
|
ptr += raw.sizeZ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if( raw.needsBytesSwapped() )
|
if( raw.needsBytesSwapped() )
|
||||||
raw.swapBytes();
|
raw.swapBytes();
|
||||||
|
Loading…
Reference in New Issue
Block a user