FreeImageImage.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 __FREEIMAGEIMAGE_H__
00030 #define __FREEIMAGEIMAGE_H__
00031 
00032 #include "H3DApi.h"
00033 #include "Image.h"
00034 #include "Exception.h"
00035 
00036 #ifdef HAVE_FREEIMAGE
00037 #ifdef _MSC_VER
00038 #pragma comment( lib, "FreeImage.lib" )
00039 #endif
00040 
00041 #include <FreeImage.h>
00042 
00043 namespace H3D {
00046   H3D_VALUE_EXCEPTION( FREE_IMAGE_COLOR_TYPE, 
00047                        UnsupportedFreeImageColorType ); 
00050   H3D_VALUE_EXCEPTION( FREE_IMAGE_TYPE, UnsupportedFreeImageImageType ); 
00051 
00055   class H3DAPI_API FreeImageImage: public Image {
00056   public:
00060     FreeImageImage( FIBITMAP *_bitmap ):
00061       bitmap( _bitmap ){}
00062 
00064     virtual unsigned int width() {
00065       return FreeImage_GetWidth( bitmap );
00066     }
00067 
00069     virtual unsigned int height() {
00070       return FreeImage_GetHeight( bitmap );
00071     }
00072 
00074     virtual unsigned int depth() {
00075       return 1;
00076     }
00077 
00079     virtual unsigned int bitsPerPixel() {
00080       return FreeImage_GetBPP( bitmap );
00081     }
00082 
00084     virtual PixelType pixelType() {
00085       FREE_IMAGE_COLOR_TYPE t = FreeImage_GetColorType( bitmap );
00086       switch( t ) {
00087       case FIC_MINISBLACK: 
00088       case FIC_MINISWHITE: return LUMINANCE;
00089 #ifdef FREEIMAGE_BIGENDIAN
00090       case FIC_RGB: return RGB;
00091       case FIC_RGBALPHA: return RGBA;
00092 #else
00093       case FIC_RGB: return BGR;
00094       case FIC_RGBALPHA: return BGRA;
00095 #endif
00096       default: 
00097         throw UnsupportedFreeImageColorType( t, "", H3D_FULL_LOCATION );
00098       }
00099     }
00100         
00102     virtual PixelComponentType pixelComponentType() {
00103       FREE_IMAGE_TYPE t = FreeImage_GetImageType( bitmap );
00104       switch( t ) {
00105       case FIT_BITMAP:
00106       case FIT_UINT16: 
00107       case FIT_UINT32: return UNSIGNED;
00108       case FIT_INT16: 
00109       case FIT_INT32: return SIGNED;
00110       case FIT_DOUBLE:
00111       case FIT_FLOAT: return RATIONAL;
00112       default: 
00113         throw UnsupportedFreeImageImageType( t, "", H3D_FULL_LOCATION );
00114       }
00115     }
00116         
00118     virtual void *getImageData() {
00119       return FreeImage_GetBits( bitmap );
00120     }
00121 
00122   protected:
00123     FIBITMAP *bitmap;
00124   };
00125 
00126     
00127 }
00128 
00129 #endif // HAVE_FREEIMAGE
00130 #endif
00131 
00132 

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