00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00027
00029 #ifndef __IMAGE_H__
00030 #define __IMAGE_H__
00031
00032 #include "H3DApi.h"
00033 #include "H3DTypes.h"
00034 #include "RefCountedClass.h"
00035 #include <assert.h>
00036
00038 namespace H3D {
00042 class H3DAPI_API Image: public RefCountedClass {
00043 public:
00046 typedef enum {
00047 LUMINANCE,
00048 LUMINANCE_ALPHA,
00049 RGB,
00050 RGBA,
00051 BGR,
00052 BGRA,
00053 VEC3
00054
00055 } PixelType;
00056
00058 typedef enum {
00059 SIGNED,
00060 UNSIGNED,
00061 RATIONAL
00062 } PixelComponentType;
00063
00065 virtual unsigned int width() = 0;
00067 virtual unsigned int height() = 0;
00069 virtual unsigned int depth() = 0;
00071 virtual unsigned int bitsPerPixel() = 0;
00073 virtual PixelType pixelType() = 0;
00075 virtual PixelComponentType pixelComponentType() = 0;
00078 virtual Vec3f pixelSize() {
00079 return Vec3f( 1, 1, 1 );
00080 }
00081
00086 virtual void *getImageData() = 0;
00087
00088
00089 virtual void getElement( void *value, int x = 0, int y = 0, int z = 0 ) {
00090 unsigned int byte_rem = bitsPerPixel() % 8;
00091 unsigned int bytes_per_pixel = bitsPerPixel() / 8;
00092 assert( byte_rem == 0 );
00093
00094 if( byte_rem != 0 ) {
00095 bytes_per_pixel++;
00096 }
00097
00098 unsigned char *data = (unsigned char *) getImageData();
00099
00100 memcpy( value,
00101 &data[ ( ( z * height() + y ) * width() + x ) * bytes_per_pixel ],
00102 bytes_per_pixel );
00103 }
00104
00105 virtual void setElement( void *value, int x = 0, int y = 0, int z = 0 ) {
00106 unsigned int byte_rem = bitsPerPixel() % 8;
00107 unsigned int bytes_per_pixel = bitsPerPixel() / 8;
00108 assert( byte_rem == 0 );
00109 if( byte_rem != 0 )
00110 bytes_per_pixel++;
00111
00112 unsigned char *data = (unsigned char *)getImageData();
00113 memcpy( &data[ ( ( z * height() + y ) * width() + x ) * bytes_per_pixel ],
00114 value,
00115 bytes_per_pixel );
00116 }
00117 };
00118 }
00119
00120 #endif
00121
00122