2001-10-04 23:12:57 +08:00
|
|
|
//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.
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
// -*-c++-*-
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_IMAGE
|
|
|
|
#define OSG_IMAGE 1
|
|
|
|
|
|
|
|
#include <osg/Object>
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
#include <string>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +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();
|
|
|
|
|
|
|
|
virtual Object* clone() const { return new Image(); }
|
2001-09-20 05:08:56 +08:00
|
|
|
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"; }
|
|
|
|
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const std::string& getFileName() const { return _fileName; }
|
|
|
|
void setFileName(const std::string& fileName);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** set the image data and format.
|
2001-09-20 05:08:56 +08:00
|
|
|
* 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,
|
2001-09-29 04:10:41 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
void setImage(const int s,const int t,const int r,
|
|
|
|
const int internalFormat,
|
|
|
|
const unsigned int pixelFormat,
|
|
|
|
const unsigned int dataType,
|
2001-01-11 00:32:10 +08:00
|
|
|
unsigned char *data,
|
2001-09-20 05:08:56 +08:00
|
|
|
const int packing=-1);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Width of image.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const int s() const { return _s; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Height of image.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const int t() const { return _t; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Depth of image.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const int r() const { return _r; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const int internalFormat() const { return _internalFormat; }
|
|
|
|
inline const unsigned int pixelFormat() const { return _pixelFormat; }
|
|
|
|
inline const unsigned int dataType() const { return _dataType; }
|
|
|
|
inline const unsigned int packing() const { return _packing; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** raw image data.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline unsigned char *data() { return _data; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** raw const image data.*/
|
|
|
|
inline const unsigned char *data() const { return _data; }
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Scale image to specified size. */
|
2001-09-20 05:08:56 +08:00
|
|
|
void scaleImage(const int s,const int t,const int r);
|
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.
|
|
|
|
*/
|
|
|
|
void ensureDimensionsArePowerOfTwo();
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-11-19 05:31:16 +08:00
|
|
|
/** Dirty the image, which increments the modified flag, to force osg::Texture to reload the image.*/
|
2001-12-05 04:38:27 +08:00
|
|
|
inline void dirty() { ++_modifiedTag; }
|
2001-11-19 05:31:16 +08:00
|
|
|
|
|
|
|
/** 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. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const unsigned int getModifiedTag() const { return _modifiedTag; }
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~Image();
|
|
|
|
|
|
|
|
// Image(const Image&) {}
|
|
|
|
// Image& operator = (const Image& image) {}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
std::string _fileName;
|
2001-01-11 00:32:10 +08:00
|
|
|
int _s, _t, _r;
|
|
|
|
int _internalFormat;
|
|
|
|
unsigned int _pixelFormat;
|
|
|
|
unsigned int _dataType;
|
|
|
|
unsigned int _packing;
|
|
|
|
unsigned char *_data;
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
unsigned int _modifiedTag;
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class Geode;
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** 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);
|
2001-09-20 05:08:56 +08:00
|
|
|
/** 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
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __SG_IMAGE_H
|