OpenSceneGraph/include/osg/Image

169 lines
6.3 KiB
Plaintext
Raw Normal View History

//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
// -*-c++-*-
2001-01-11 00:32:10 +08:00
#ifndef OSG_IMAGE
#define OSG_IMAGE 1
#include <osg/Object>
#include <osg/GL>
2001-01-11 00:32:10 +08:00
#include <string>
2001-01-11 00:32:10 +08:00
namespace osg {
2001-01-11 00:32:10 +08:00
/** Image class for encapsulating the storage texture image data.*/
class SG_EXPORT Image : public Object
{
public :
Image();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
Image(const Image& image,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
2001-01-11 00:32:10 +08:00
virtual Object* cloneType() const { return osgNew Image(); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew Image(*this,copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Image*>(obj)!=0; }
2001-01-11 00:32:10 +08:00
virtual const char* className() const { return "Image"; }
void setFileName(const std::string& fileName);
inline const std::string& getFileName() const { return _fileName; }
2001-01-11 00:32:10 +08:00
/* allocated a pixel block of specified size and type.*/
void createImage(int s,int t,int r,
GLenum format,GLenum type,
int packing=1);
2001-01-11 00:32:10 +08:00
/** set the image data and format.
* note, when the packing value is negative (the default is -1) this method assumes
2001-01-11 00:32:10 +08:00
* a _packing width of 1 if the width is not a multiple of 4,
* otherwise automatically sets to _packing to 4. If a positive
2001-01-11 00:32:10 +08:00
* value of packing is supplied than _packing is simply set to that value.
*/
void setImage(int s,int t,int r,
GLint internalTextureformat,
GLenum format,GLenum type,
unsigned char *data,
int packing=1);
/** readPixels from screen at specified position and size, using glReadPixels.
* Create memory for storage if required, reuse existing pixel coords if possible.
* if pixelFormat or dataType*/
void readPixels(int x,int y,int width,int height,
GLenum format,GLenum type);
2001-01-11 00:32:10 +08:00
/** Scale image to specified size. */
void scaleImage(const int s,const int t,const int r);
2001-01-11 00:32:10 +08:00
/** Width of image.*/
inline const int s() const { return _s; }
2001-01-11 00:32:10 +08:00
/** Height of image.*/
inline const int t() const { return _t; }
2001-01-11 00:32:10 +08:00
/** Depth of image.*/
inline const int r() const { return _r; }
2001-01-11 00:32:10 +08:00
void setInternalTextureFormat(GLint internalFormat);
inline const GLint getInternalTextureFormat() const { return _internalTextureFormat; }
void setPixelFormat(const GLenum format);
inline const GLenum getPixelFormat() const { return _pixelFormat; }
inline const GLenum getDataType() const { return _dataType; }
inline const unsigned int getPacking() const { return _packing; }
2001-01-11 00:32:10 +08:00
/** return the numbers of bits required for each pixel.*/
inline const unsigned int getPixelSizeInBits() const { return computePixelSizeInBits(_pixelFormat,_dataType); }
/** return the numbers of bytes each row of pixels occupies once it has been packed.*/
inline const unsigned int getRowSizeInBytes() const { return computeRowWidthInBytes(_s,_pixelFormat,_dataType,_packing); }
/** return the numbers of bytes each image (_s*_t) of pixels occupies..*/
inline const unsigned int getImageSizeInBytes() const { return getRowSizeInBytes()*_t; }
/** return the numbers of bytes the whole row/image/volume of pixels occupies.*/
inline const unsigned int getTotalSizeInBytes() const { return getImageSizeInBytes()*_r; }
2001-01-11 00:32:10 +08:00
/** raw image data.*/
inline unsigned char *data() { return _data; }
2001-01-11 00:32:10 +08:00
/** raw const image data.*/
inline const unsigned char *data() const { return _data; }
unsigned char* data(int column, int row=0,int image=0)
{
if (!_data) return NULL;
return _data+(column*getPixelSizeInBits())/8+row*getRowSizeInBytes()+image*getImageSizeInBytes();
}
2001-01-11 00:32:10 +08:00
/** Ensure image dimensions are a power of two.
* Mip Mapped texture require the image dimensions to be
* power of two and are within the maxiumum texture size for
* the host machine.*/
void ensureValidSizeForTexturing();
/** Dirty the image, which increments the modified flag, to force osg::Texture to reload the image.*/
inline void dirty() { ++_modifiedTag; }
/** Set the modified tag value, only used by osg::Texture when using texture subloading. */
inline void setModifiedTag(const unsigned int value) { _modifiedTag=value; }
/** Get modified tag value, only used by osg::Texture when using texture subloading. */
inline const unsigned int getModifiedTag() const { return _modifiedTag; }
static const bool isPackedType(GLenum type);
static const unsigned int computeNumComponents(GLenum format);
static const unsigned int computePixelSizeInBits(GLenum format,GLenum type);
static const unsigned int computeRowWidthInBytes(int width,GLenum format,GLenum type,int packing);
2001-01-11 00:32:10 +08:00
protected :
virtual ~Image();
2002-01-31 00:24:24 +08:00
Image& operator = (const Image&) { return *this; }
2001-01-11 00:32:10 +08:00
std::string _fileName;
2001-01-11 00:32:10 +08:00
int _s, _t, _r;
GLint _internalTextureFormat;
GLenum _pixelFormat;
GLenum _dataType;
2001-01-11 00:32:10 +08:00
unsigned int _packing;
unsigned char *_data;
unsigned int _modifiedTag;
2001-01-11 00:32:10 +08:00
};
class Geode;
/** Convenience function to be used by images loaders to generate a valid geode
* to return for readNode().
* Use the images s and t values scale the dimensions of the image.
*/
2001-01-11 00:32:10 +08:00
SG_EXPORT extern Geode* createGeodeForImage(Image* image);
/** Convenience function to be used by images loaders to generate a valid geode
* to return for readNode().
* Use the specified s and t values scale the dimensions of the image.
*/
SG_EXPORT extern Geode* createGeodeForImage(Image* image,const float s,const float t);
2001-01-11 00:32:10 +08:00
}
2001-01-11 00:32:10 +08:00
#endif // __SG_IMAGE_H