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 #include "OgreStableHeaders.h" 00026 #include "OgreTGACodec.h" 00027 #include "OgreImage.h" 00028 #include "OgreException.h" 00029 00030 #include <IL/il.h> 00031 #include <IL/ilu.h> 00032 00033 namespace Ogre { 00034 //--------------------------------------------------------------------- 00035 void TGACodec::code( const DataChunk& input, DataChunk* output, ... ) const 00036 { 00037 OgreGuard( "TGACodec::code" ); 00038 Except(Exception::UNIMPLEMENTED_FEATURE, "code to memory not implemented", 00039 "TGACodec::code"); 00040 OgreUnguard(); 00041 } 00042 //--------------------------------------------------------------------- 00043 Codec::CodecData * TGACodec::decode( const DataChunk& input, DataChunk* output, ... ) const 00044 { 00045 OgreGuard( "TGACodec::decode" ); 00046 00047 // DevIL variables 00048 ILuint ImageName; 00049 ILint Imagformat, BytesPerPixel; 00050 ImageData * ret_data = new ImageData; 00051 00052 // Load the image 00053 ilGenImages( 1, &ImageName ); 00054 ilBindImage( ImageName ); 00055 00056 ilLoadL( 00057 getILType(), 00058 ( void * )const_cast< uchar * >( input.getPtr() ), 00059 static_cast< ILuint >( input.getSize() ) ); 00060 00061 // Check if everything was ok 00062 ILenum PossibleError = ilGetError(); 00063 if( PossibleError != IL_NO_ERROR ) 00064 { 00065 Except( Exception::UNIMPLEMENTED_FEATURE, 00066 "IL Error", 00067 iluErrorString(PossibleError) ); 00068 } 00069 00070 Imagformat = ilGetInteger( IL_IMAGE_FORMAT ); 00071 BytesPerPixel = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL ); 00072 00073 // Now sets some variables 00074 ret_data->width = ilGetInteger( IL_IMAGE_WIDTH ); 00075 ret_data->height = ilGetInteger( IL_IMAGE_HEIGHT ); 00076 ret_data->num_mipmaps = ilGetInteger ( IL_NUM_MIPMAPS ); 00077 ret_data->depth = ilGetInteger( IL_IMAGE_DEPTH ); 00078 ret_data->flags = 0; 00079 00080 uint ImageSize = ilGetInteger( IL_IMAGE_WIDTH ) * ilGetInteger( IL_IMAGE_HEIGHT ) * ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL ); 00081 00082 output->allocate( ImageSize ); 00083 00084 //check to see whether the image is upside down 00085 if(ilGetInteger(IL_ORIGIN_MODE) == IL_ORIGIN_LOWER_LEFT) 00086 { 00087 //if so (probably) put it right side up 00088 ilEnable(IL_ORIGIN_SET); 00089 ilSetInteger(IL_ORIGIN_MODE, IL_ORIGIN_UPPER_LEFT); 00090 } 00091 if( Imagformat==IL_BGR || Imagformat==IL_BGRA) 00092 { 00093 //if so (probably) reverse the b and the r, this is slower but at least it works 00094 ILint newIF = Imagformat==IL_BGR ? IL_RGB : IL_RGBA; 00095 ilCopyPixels(0, 0, 0, ret_data->width , ret_data->height, 1, newIF, IL_UNSIGNED_BYTE, output->getPtr()); 00096 Imagformat = newIF; 00097 } 00098 else 00099 { 00100 memcpy( output->getPtr(), ilGetData(), ImageSize ); 00101 } 00102 00103 ret_data->format = ilFormat2OgreFormat( Imagformat, BytesPerPixel ); 00104 ret_data->size = ImageSize; 00105 00106 ilDeleteImages( 1, &ImageName ); 00107 00108 OgreUnguardRet( ret_data ); 00109 } 00110 //--------------------------------------------------------------------- 00111 unsigned int TGACodec::getILType(void) const 00112 { 00113 return IL_TGA; 00114 } 00115 }
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:53 2004