From 6f34ef29f84a1e721dd40f518525bf319eca4fd9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 9 May 2004 07:06:32 +0000 Subject: [PATCH] From Joran Jessurun, "I needed to be able to set the quality of the saved jpeg images. I could not find a way to do this in OSG. Therefore I implemented this by adding an option called: JPEG_QUALITY to the JPEG reader/writer. To parse the options string I use the same method as used in the LWO reader/writer. " --- src/osgPlugins/jpeg/ReaderWriterJPEG.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp b/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp index b5b82e677..ef2534f6a 100644 --- a/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp +++ b/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp @@ -7,6 +7,8 @@ #include #include +#include + /**************************************************************************** * * Follows is code extracted from the simage library. Original Authors: @@ -410,6 +412,21 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter /* And we're done! */ return WriteResult::FILE_SAVED; } + int getQuality(const osgDB::ReaderWriter::Options *options) { + if(options) { + std::istringstream iss(options->getOptionString()); + std::string opt; + while (iss >> opt) { + if(opt=="JPEG_QUALITY") { + int quality; + iss >> quality; + return quality; + } + } + } + + return 100; + } public: virtual const char* className() { return "JPEG Image Reader/Writer"; } virtual bool acceptsExtension(const std::string& extension) @@ -459,13 +476,13 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter return pOsgImage; } - virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options *options) { std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; osg::ref_ptr tmp_img = new osg::Image(img); tmp_img->flipVertical(); - WriteResult::WriteStatus ws = write_JPEG_file(fileName.c_str(),img.s(),img.t(),(JSAMPLE*)(tmp_img->data())); + WriteResult::WriteStatus ws = write_JPEG_file(fileName.c_str(),img.s(),img.t(),(JSAMPLE*)(tmp_img->data()),getQuality(options)); return ws; } };