Added --flip and --no-flip command line options to enable/disable a vertical flip of the captured image before writing out to disk.

This commit is contained in:
Robert Osfield 2012-12-08 16:11:00 +00:00
parent 22868bce4f
commit 8d999a07cf
3 changed files with 18 additions and 4 deletions

View File

@ -5,6 +5,7 @@ using namespace gsc;
CaptureSettings::CaptureSettings():
_stereoMode(OFF),
_offscreen(false),
_outputImageFlip(false),
_width(1024),
_height(512),
_screenWidth(0.0),
@ -26,6 +27,7 @@ CaptureSettings::CaptureSettings(const CaptureSettings& cs, const osg::CopyOp& c
_outputExtension(cs._outputExtension),
_stereoMode(cs._stereoMode),
_offscreen(cs._offscreen),
_outputImageFlip(cs._outputImageFlip),
_width(cs._width),
_height(cs._height),
_screenWidth(cs._screenWidth),
@ -158,6 +160,7 @@ REGISTER_OBJECT_WRAPPER( gsc_CaptureSettings,
END_ENUM_SERIALIZER(); // _renderTargetImplementation
ADD_BOOL_SERIALIZER( Offscreen, false );
ADD_BOOL_SERIALIZER( OutputImageFlip, false );
ADD_UINT_SERIALIZER( Width, 1024 );
ADD_UINT_SERIALIZER( Height, 512 );

View File

@ -42,6 +42,9 @@ public:
void setOffscreen(bool o) { _offscreen = o; }
bool getOffscreen() const { return _offscreen; }
void setOutputImageFlip(bool flip) { _outputImageFlip = flip; }
bool getOutputImageFlip() const { return _outputImageFlip; }
void setWidth(unsigned int width) { _width = width; }
unsigned int getWidth() const { return _width; }
@ -109,6 +112,7 @@ protected:
StereoMode _stereoMode;
bool _offscreen;
bool _outputImageFlip;
unsigned int _width;
unsigned int _height;

View File

@ -17,7 +17,8 @@
struct ScreenShot : public osg::Camera::DrawCallback
{
ScreenShot() {}
ScreenShot(bool flip):
_flip(flip) {}
virtual void operator () (osg::RenderInfo& renderInfo) const
{
@ -48,6 +49,8 @@ struct ScreenShot : public osg::Camera::DrawCallback
image->readPixels(viewport->x(),viewport->y(),viewport->width(),viewport->height(),
GL_RGB, GL_UNSIGNED_BYTE, 1);
if (_flip) image->flipVertical();
osgDB::writeImageFile(*image, outputFileName);
}
@ -55,8 +58,9 @@ struct ScreenShot : public osg::Camera::DrawCallback
typedef std::map<const osg::Camera*, unsigned int> CameraNumMap;
osg::ref_ptr<gsc::CaptureSettings> _frameCapture;
CameraNumMap _cameraNumMap;
bool _flip;
osg::ref_ptr<gsc::CaptureSettings> _frameCapture;
CameraNumMap _cameraNumMap;
};
int main( int argc, char **argv )
@ -226,6 +230,9 @@ int main( int argc, char **argv )
if (arguments.read("--offscreen")) fc->setOffscreen(true);
if (arguments.read("--screen")) fc->setOffscreen(false);
if (arguments.read("--flip")) fc->setOutputImageFlip(true);
if (arguments.read("--no-flip")) fc->setOutputImageFlip(false);
unsigned int width = 1024;
if (arguments.read("--width",width)) fc->setWidth(width);
@ -468,7 +475,7 @@ int main( int argc, char **argv )
viewer.realize();
// set up screen shot
osg::ref_ptr<ScreenShot> screenShot = new ScreenShot;
osg::ref_ptr<ScreenShot> screenShot = new ScreenShot(fc->getOutputImageFlip());;
{
osgViewer::Viewer::Cameras cameras;