FreeImageLoader.h

Go to the documentation of this file.
00001 
00003 //    Copyright 2004, SenseGraphics AB
00004 //
00005 //    This file is part of H3D API.
00006 //
00007 //    H3D API is free software; you can redistribute it and/or modify
00008 //    it under the terms of the GNU General Public License as published by
00009 //    the Free Software Foundation; either version 2 of the License, or
00010 //    (at your option) any later version.
00011 //
00012 //    H3D API is distributed in the hope that it will be useful,
00013 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //    GNU General Public License for more details.
00016 //
00017 //    You should have received a copy of the GNU General Public License
00018 //    along with H3D API; if not, write to the Free Software
00019 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 //    A commercial license is also available. Please contact us at 
00022 //    www.sensegraphics.com for more information.
00023 //
00024 //
00029 //
00031 #ifndef __FREEIMAGELOADER_H__
00032 #define __FREEIMAGELOADER_H__
00033 
00034 #include "H3DImageLoaderNode.h"
00035 
00036 #ifdef HAVE_FREEIMAGE
00037 
00038 #include "FreeImageImage.h"
00039 
00040 namespace H3D {
00047   class H3DAPI_API FreeImageLoader : public H3DImageLoaderNode {
00048   public:
00050     FreeImageLoader() {
00051       type_name = "FreeImageLoader";
00052     }
00053 
00056     virtual Image *loadImage( const string &url ) {
00057         
00058       FREE_IMAGE_FORMAT format = FreeImage_GetFileType( url.c_str() );
00059       if( format == FIF_UNKNOWN ) {
00060         format = FreeImage_GetFIFFromFilename( url.c_str() );
00061       }
00062 
00063       if( format != FIF_UNKNOWN && FreeImage_FIFSupportsReading( format ) ) { 
00064         FIBITMAP *bm = FreeImage_Load( format, url.c_str() );
00065         
00066         if( bm ) {
00067           // Take care of the case of 32 bit RGB images( alpha ignored ) that seems to
00068           // happen once in a while with png images
00069           if( FreeImage_GetColorType( bm ) == FIC_RGB && FreeImage_GetBPP( bm ) == 32 ) {
00070             FIBITMAP *old = bm;
00071             bm = FreeImage_ConvertTo24Bits( bm );
00072             FreeImage_Unload( old );
00073           }
00074           return new FreeImageImage( bm );
00075         } 
00076       }
00077       return NULL;
00078     }
00079     
00082     
00085     static bool supportsFileType( const string &url );
00086 
00087     static H3DNodeDatabase database;    
00088 
00090     static FileReaderRegistration reader_registration;
00091   };
00092 }
00093 
00094 #endif // HAVE_FREEIMAGE
00095 #endif

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