From 6849bb8e3bcdc2e07a4a599cf517b80419509b06 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 16 Aug 2010 14:39:53 +0000 Subject: [PATCH] From Wang Rui, "Attachment is the implementation of the writing operation of the TGA format. I wrote it just for one of my client. At present it only outputs uncompressed RGBA images, but the OSG community can go deeper at any time." --- src/osgPlugins/tga/ReaderWriterTGA.cpp | 69 ++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/osgPlugins/tga/ReaderWriterTGA.cpp b/src/osgPlugins/tga/ReaderWriterTGA.cpp index e3e09bb05..e56995cad 100644 --- a/src/osgPlugins/tga/ReaderWriterTGA.cpp +++ b/src/osgPlugins/tga/ReaderWriterTGA.cpp @@ -542,6 +542,75 @@ class ReaderWriterTGA : public osgDB::ReaderWriter if(rr.validImage()) rr.getImage()->setFileName(file); return rr; } + + bool saveTGAStream(const osg::Image& image, std::ostream& fout) const + { + // At present, I will only save the image to unmapped RGB format + // Other data types can be added soon with different options + // The format description can be found at: + // http://local.wasp.uwa.edu.au/~pbourke/dataformats/tga/ + int width = image.s(), height = image.t(); + int numPerPixel = image.computeNumComponents(image.getPixelFormat()); + int pixelMultiplier = (image.getDataType()==GL_FLOAT ? 255 : 1); + const unsigned char* data = image.data(); + if ( !data ) return false; + + // Headers + fout.put(0); // Identification field size + fout.put(0); // Color map type + fout.put(2); // Image type + fout.put(0); fout.put(0); // Color map origin + fout.put(0); fout.put(0); // Color map length + fout.put(0); // Color map entry size + fout.put(0); fout.put(0); // X origin of image + fout.put(0); fout.put(0); // Y origin of image + fout.put(width&0xff); fout.put((width&0xff00)>>8); // Width of image + fout.put(height&0xff); fout.put((height&0xff00)>>8); // Height of image + fout.put(numPerPixel * 8); // Image pixel size + fout.put(0); // Image descriptor + + // Data + for (int y=0; y