ImageOptions 4.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 
 *
 * This library is open source and may be redistributed and/or modified under  
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * OpenSceneGraph Public License for more details.
*/

#ifndef OSGDB_IMAGEOPTIONS
#define OSGDB_IMAGEOPTIONS 1

#include <osgDB/Options>

namespace osgDB {

class OSGDB_EXPORT ImageOptions : public osgDB::Options
{
    public:
    
        ImageOptions();
        
        ImageOptions(const std::string& str);
            
        ImageOptions(const ImageOptions& options,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
            osgDB::Options(options,copyop),
            _sourceImageSamplingMode(options._sourceImageSamplingMode),
            _sourceImageWindowMode(options._sourceImageWindowMode),
            _sourceRatioWindow(options._sourceRatioWindow),
            _sourcePixelWindow(options._sourcePixelWindow),
            _destinationImage(options._destinationImage),
            _destinationImageWindowMode(options._destinationImageWindowMode),
            _destinationRatioWindow(options._destinationRatioWindow),
            _destinationPixelWindow(options._destinationPixelWindow),
            _destinationDataType(options._destinationDataType),
            _destinationPixelFormat(options._destinationPixelFormat) {}
          

        META_Object(osgDB,ImageOptions);

        /** RatioWindow stores the window (as ratios of 0.0 to 1.0) from the overall imagery from which to extract the osg::Image*/
        struct RatioWindow
        {
            RatioWindow():
                windowX(0.0),
                windowY(0.0),
                windowWidth(1.0),
                windowHeight(1.0) {}

            void set(double x, double y, double w, double h)
            {
                windowX = x;
                windowY = y;
                windowWidth = w;
                windowHeight = h;
            }
            
            double windowX;
            double windowY;
            double windowWidth;
            double windowHeight;
        };
        
        /** PixelWindow stores the window (in exact pixels) from the overall imagery from which to extract the osg::Image*/
        struct PixelWindow
        {
            PixelWindow():
                windowX(0),
                windowY(0),
                windowWidth(0),
                windowHeight(0) {}
        
            void set(unsigned int x, unsigned int y, unsigned int w, unsigned int h)
            {
                windowX = x;
                windowY = y;
                windowWidth = w;
                windowHeight = h;
            }
            
            unsigned int windowX;
            unsigned int windowY;
            unsigned int windowWidth;
            unsigned int windowHeight;
        };
        
        enum ImageWindowMode
        {
            ALL_IMAGE,
            RATIO_WINDOW,
            PIXEL_WINDOW
        };
        
        enum ImageSamplingMode
        {
            NEAREST,
            LINEAR,
            CUBIC
        };

        /** Used as UserData attached to generated osg::Image's*/
        struct TexCoordRange : public osg::Referenced
        {
            TexCoordRange():
                _x(0.0),
                _y(0.0),
                _w(1.0),
                _h(1.0) {}
        
            void set(double x,double y, double w, double h)
            {
                _x = x;
                _y = y;
                _w = w;
                _h = h;
            }
        
            double _x,_y,_w,_h;
        };


        // source        
        ImageSamplingMode   _sourceImageSamplingMode;
        ImageWindowMode     _sourceImageWindowMode;
        RatioWindow         _sourceRatioWindow;
        PixelWindow         _sourcePixelWindow;

        // destination
        osg::ref_ptr<osg::Image> _destinationImage;
       
        ImageWindowMode     _destinationImageWindowMode;
        RatioWindow         _destinationRatioWindow;
        PixelWindow         _destinationPixelWindow;

        GLenum              _destinationDataType;
        GLenum              _destinationPixelFormat;

        void init();
        
};


}

#endif // OSGDB_IMAGEOPTIONS