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-2003 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 "OgreDDSCodec.h" 00029 #include "OgreImage.h" 00030 #include "OgreException.h" 00031 #include "OgreRoot.h" 00032 #include "OgreRenderSystem.h" 00033 00034 #include <IL/il.h> 00035 #include <IL/ilu.h> 00036 00037 namespace Ogre { 00038 //--------------------------------------------------------------------- 00039 void DDSCodec::code( const DataChunk& input, DataChunk* output, ... ) const 00040 { 00041 OgreGuard( "DDSCodec::code" ); 00042 00043 Except(Exception::UNIMPLEMENTED_FEATURE, "code to memory not implemented", 00044 "DDSCodec::code"); 00045 00046 OgreUnguard(); 00047 } 00048 00049 //--------------------------------------------------------------------- 00050 Codec::CodecData *DDSCodec::decode( const DataChunk& input, DataChunk* output, ... ) const 00051 00052 { 00053 OgreGuard( "DDSCodec::decode" ); 00054 00055 // DevIL variables 00056 ILuint ImageName; 00057 ILint ImageFormat, BytesPerPixel; 00058 ImageData * ret_data = new ImageData; 00059 00060 // Load the image 00061 ilGenImages( 1, &ImageName ); 00062 ilBindImage( ImageName ); 00063 ilSetInteger(IL_KEEP_DXTC_DATA, IL_TRUE); 00064 00065 ilLoadL( 00066 getILType(), 00067 ( void * )const_cast< uchar * >( input.getPtr() ), 00068 static_cast< ILuint >( input.getSize() ) ); 00069 00070 // Check if everything was ok 00071 ILenum PossibleError = ilGetError() ; 00072 00073 if( PossibleError != IL_NO_ERROR ) 00074 { 00075 Except( Exception::UNIMPLEMENTED_FEATURE, 00076 "IL Error", 00077 iluErrorString(PossibleError) ) ; 00078 } 00079 00080 // Now sets some variables 00081 ImageFormat = ilGetInteger( IL_IMAGE_FORMAT ); 00082 BytesPerPixel = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL ); 00083 00084 ret_data->width = ilGetInteger( IL_IMAGE_WIDTH ); 00085 ret_data->height = ilGetInteger( IL_IMAGE_HEIGHT ); 00086 ret_data->depth = ilGetInteger( IL_IMAGE_DEPTH ); 00087 ret_data->num_mipmaps = ilGetInteger ( IL_NUM_MIPMAPS ); 00088 ret_data->flags = 0; 00089 00090 ILuint dxtFormat = ilGetInteger( IL_DXTC_DATA_FORMAT ); 00091 00092 ILuint cubeflags = ilGetInteger ( IL_IMAGE_CUBEFLAGS ); 00093 if(cubeflags) 00094 ret_data->flags |= IF_CUBEMAP; 00095 00096 if(dxtFormat != IL_DXT_NO_COMP && Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability( RSC_TEXTURE_COMPRESSION_DXT )) 00097 { 00098 ILuint dxtSize = ilGetDXTCData(NULL, 0, dxtFormat); 00099 output->allocate( dxtSize ); 00100 ilGetDXTCData(output->getPtr(), dxtSize, dxtFormat); 00101 00102 ret_data->size = dxtSize; 00103 ret_data->format = ilFormat2OgreFormat( dxtFormat, BytesPerPixel ); 00104 ret_data->flags |= IF_COMPRESSED; 00105 } 00106 else 00107 { 00108 uint numImagePasses = cubeflags ? 6 : 1; 00109 uint imageSize = ilGetInteger(IL_IMAGE_SIZE_OF_DATA); 00110 output->allocate( imageSize * numImagePasses ); 00111 00112 unsigned int i = 0, offset = 0; 00113 for(i = 0; i < numImagePasses; i++) 00114 { 00115 if(cubeflags) 00116 { 00117 ilBindImage(ImageName); 00118 ilActiveImage(i); 00119 } 00120 00121 // Move the image data to the output buffer 00122 memcpy( output->getPtr() + offset, ilGetData(), imageSize ); 00123 offset += imageSize; 00124 } 00125 00126 ret_data->size = imageSize * numImagePasses; 00127 ret_data->format = ilFormat2OgreFormat( ImageFormat, BytesPerPixel ); 00128 } 00129 00130 ilDeleteImages( 1, &ImageName ); 00131 OgreUnguardRet( ret_data ); 00132 } 00133 //--------------------------------------------------------------------- 00134 unsigned int DDSCodec::getILType(void) const 00135 { 00136 return IL_DDS; 00137 } 00138 }
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:06 2004