00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 00026 #include "OgreStableHeaders.h" 00027 00028 #include "OgreILImageCodec.h" 00029 #include "OgreImage.h" 00030 #include "OgreException.h" 00031 00032 #include <IL/il.h> 00033 #include <IL/ilu.h> 00034 00035 namespace Ogre { 00036 00037 bool ILImageCodec::_is_initialised = false; 00038 //--------------------------------------------------------------------- 00039 void ILImageCodec::codeToFile( const DataChunk& input, 00040 const String& outFileName, Codec::CodecData* pData) const 00041 { 00042 OgreGuard( "ILImageCodec::codeToFile" ); 00043 00044 ILuint ImageName; 00045 00046 ilGenImages( 1, &ImageName ); 00047 ilBindImage( ImageName ); 00048 00049 ImageData* pImgData = static_cast< ImageData * >( pData ); 00050 std::pair< int, int > fmt_bpp = OgreFormat2ilFormat( pImgData->format ); 00051 ilTexImage( 00052 pImgData->width, pImgData->height, 1, fmt_bpp.second, fmt_bpp.first, IL_UNSIGNED_BYTE, 00053 static_cast< void * >( const_cast< uchar * >( ( input.getPtr() ) ) ) ); 00054 iluFlipImage(); 00055 00056 // Implicitly pick DevIL codec 00057 ilSaveImage(const_cast< char * >( outFileName.c_str() ) ); 00058 00059 ilDeleteImages(1, &ImageName); 00060 00061 OgreUnguard(); 00062 } 00063 //--------------------------------------------------------------------- 00064 Codec::CodecData * ILImageCodec::decode( const DataChunk& input, DataChunk* output, ... ) const 00065 { 00066 OgreGuard( "ILImageCodec::decode" ); 00067 00068 // DevIL variables 00069 ILuint ImageName; 00070 ILint Imagformat, BytesPerPixel; 00071 ImageData * ret_data = new ImageData; 00072 00073 // Load the image 00074 ilGenImages( 1, &ImageName ); 00075 ilBindImage( ImageName ); 00076 00077 ilLoadL( 00078 getILType(), 00079 ( void * )const_cast< uchar * >( input.getPtr() ), 00080 static_cast< ILuint >( input.getSize() ) ); 00081 00082 // Check if everything was ok 00083 ILenum PossibleError = ilGetError() ; 00084 if( PossibleError != IL_NO_ERROR ) 00085 { 00086 Except( Exception::UNIMPLEMENTED_FEATURE, 00087 "IL Error", 00088 iluErrorString(PossibleError) ) ; 00089 } 00090 00091 // Now sets some variables 00092 Imagformat = ilGetInteger( IL_IMAGE_FORMAT ); 00093 BytesPerPixel = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL ); 00094 00095 uint ImageSize = ilGetInteger( IL_IMAGE_WIDTH ) * ilGetInteger( IL_IMAGE_HEIGHT ) * ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL ); 00096 00097 ret_data->format = ilFormat2OgreFormat( Imagformat, BytesPerPixel ); 00098 ret_data->width = ilGetInteger( IL_IMAGE_WIDTH ); 00099 ret_data->height = ilGetInteger( IL_IMAGE_HEIGHT ); 00100 ret_data->depth = ilGetInteger( IL_IMAGE_DEPTH ); 00101 ret_data->num_mipmaps = ilGetInteger ( IL_NUM_MIPMAPS ); 00102 ret_data->flags = 0; 00103 ret_data->size = ImageSize; 00104 00105 // Move the image data to the output buffer 00106 output->allocate( ImageSize ); 00107 memcpy( output->getPtr(), ilGetData(), ImageSize ); 00108 00109 ilDeleteImages( 1, &ImageName ); 00110 00111 OgreUnguardRet( ret_data ); 00112 } 00113 //--------------------------------------------------------------------- 00114 void ILImageCodec::initialiseIL(void) 00115 { 00116 if( !_is_initialised ) 00117 { 00118 ilInit(); 00119 ilEnable( IL_FILE_OVERWRITE ); 00120 _is_initialised = true; 00121 } 00122 } 00123 }
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:17 2004