Image.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
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       // Color table bitmap??
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 

Generated on Thu Aug 24 12:38:33 2006 for H3D API by  doxygen 1.4.5