PixelImage.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 __PIXELIMAGE_H__
00030 #define __PIXELIMAGE_H__
00031 
00032 #include "Image.h"
00033 #include <vector>
00034 
00035 namespace H3D {
00036 
00037   class H3DAPI_API PixelImage: public Image {
00038   public:
00041     PixelImage( unsigned int _width,
00042                 unsigned int _height,
00043                 unsigned int _depth,
00044                 unsigned int _bits_per_pixel,
00045                 PixelType _pixel_type,
00046                 PixelComponentType _pixel_component_type,
00047                 unsigned char *data,
00048                 bool copy_data = false,
00049                 const Vec3f &_pixel_size = Vec3f( 0, 0, 0 ) ):
00050       w( _width ),
00051       h( _height ),
00052       d( _depth ),
00053       bits_per_pixel( _bits_per_pixel ),
00054       pixel_type( _pixel_type ),
00055       pixel_component_type( _pixel_component_type ),
00056       pixel_size( _pixel_size ){
00057       if( copy_data ) {
00058         unsigned int size = (w * h * d * bits_per_pixel)/8;
00059         image_data = new unsigned char[ size ];
00060         memcpy( image_data, data, size );
00061       }
00062       else 
00063         image_data = data;
00064     }
00065 
00066     ~PixelImage() {
00067       if( image_data )
00068         delete image_data;
00069     }
00070 
00072     virtual unsigned int width() {
00073       return w;
00074     }
00075 
00077     virtual unsigned int height() {
00078       return h;
00079     }
00080 
00082     virtual unsigned int depth() {
00083       return d;
00084     }
00085 
00087     virtual Vec3f pixelSize() {
00088       return pixel_size;
00089     }
00090 
00092     virtual unsigned int bitsPerPixel() {
00093       return bits_per_pixel;
00094     }
00095 
00097     virtual PixelType pixelType() {
00098       return pixel_type;
00099     }
00100         
00102     virtual PixelComponentType pixelComponentType() {
00103       return pixel_component_type;
00104     }
00105         
00107     virtual void *getImageData() {
00108       return image_data;
00109     }
00110 
00112     virtual void setHeight( unsigned int height ) {
00113       h = height;
00114     }
00115 
00117     virtual void setWidth( unsigned int width ) {
00118       w = width;
00119     }
00120 
00122     virtual void setDepth( unsigned int depth ) {
00123       d = depth;
00124     }
00125 
00126 
00128     virtual void setPixelSize( const Vec3f &s ) {
00129       pixel_size = s;
00130     }
00131 
00133     virtual void setbitsPerPixel( unsigned int b ) {
00134       bits_per_pixel = b;
00135     }
00136 
00138     virtual void setPixelType( const PixelType &pt) {
00139       pixel_type = pt;
00140     }
00141         
00143     virtual void setPixelComponentType( const PixelComponentType &pct ) {
00144       pixel_component_type = pct;
00145     }
00146         
00148     virtual void setImageData( unsigned char * data, bool copy_data = false ) {
00149       if( image_data ) delete image_data;
00150       if( copy_data ) {
00151         unsigned int size = (w * h * d * bits_per_pixel)/8;
00152         image_data = new unsigned char[ size ];
00153         memcpy( image_data, data, size );
00154       } else {
00155         image_data = data;
00156       }
00157     }
00158 
00159   protected:
00160     unsigned int w, h, d;
00161     unsigned int bits_per_pixel;
00162     PixelType pixel_type;
00163     PixelComponentType pixel_component_type;
00164     Vec3f pixel_size;
00165     unsigned char *image_data;
00166   };
00167 
00168     
00169 }
00170 
00171 #endif
00172 
00173 

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