Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreBMPCodec.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 -----------------------------------------------------------------------------
00004 
00005 This source file is part of OGRE
00006 
00007 (Object-oriented Graphics Rendering Engine)
00008 
00009 For the latest info, see http://www.ogre3d.org/
00010 
00011 
00012 
00013 Copyright © 2000-2002 The OGRE Team
00014 
00015 Also see acknowledgements in Readme.html
00016 
00017 
00018 
00019 This program is free software; you can redistribute it and/or modify it under
00020 
00021 the terms of the GNU Lesser General Public License as published by the Free Software
00022 
00023 Foundation; either version 2 of the License, or (at your option) any later
00024 
00025 version.
00026 
00027 
00028 
00029 This program is distributed in the hope that it will be useful, but WITHOUT
00030 
00031 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00032 
00033 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00034 
00035 
00036 
00037 You should have received a copy of the GNU Lesser General Public License along with
00038 
00039 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00040 
00041 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00042 
00043 http://www.gnu.org/copyleft/lesser.txt.
00044 
00045 -----------------------------------------------------------------------------
00046 
00047 */
00048 
00049 #include "OgreStableHeaders.h"
00050 
00051 
00052 
00053 #include "OgreBMPCodec.h"
00054 
00055 #include "OgreImage.h"
00056 
00057 #include "OgreException.h"
00058 
00059 
00060 
00061 #include <IL/il.h>
00062 
00063 #include <IL/ilu.h>
00064 
00065 
00066 
00067 namespace Ogre {
00068 
00069 
00070 
00071 
00072 
00073     //---------------------------------------------------------------------
00074 
00075     void BMPCodec::code( const DataChunk& input, DataChunk* output, ... ) const
00076 
00077     {        
00078 
00079         OgreGuard( "BMPCodec::code" );
00080 
00081 
00082 
00083         Except(Exception::UNIMPLEMENTED_FEATURE, "code to memory not implemented",
00084 
00085             "BMPCodec::code");
00086 
00087 
00088 
00089         OgreUnguard();
00090 
00091 
00092 
00093     }
00094 
00095     //---------------------------------------------------------------------
00096 
00097     Codec::CodecData * BMPCodec::decode( const DataChunk& input, DataChunk* output, ... ) const
00098 
00099     {
00100 
00101         OgreGuard( "BMPCodec::decode" );
00102 
00103 
00104 
00105         // DevIL variables
00106 
00107         ILuint ImageName;
00108 
00109         ILint ImageFormat, BytesPerPixel;
00110 
00111         ImageData * ret_data = new ImageData;
00112 
00113 
00114 
00115         // Load the image 
00116 
00117         ilGenImages( 1, &ImageName );
00118 
00119         ilBindImage( ImageName );
00120 
00121 
00122 
00123         ilLoadL( 
00124 
00125             getILType(), 
00126 
00127             ( void * )const_cast< uchar * >( input.getPtr() ), 
00128 
00129             static_cast< ILuint >( input.getSize() ) );
00130 
00131 
00132 
00133         // Check if everything was ok
00134 
00135         ILenum PossibleError = ilGetError() ;
00136 
00137         if( PossibleError != IL_NO_ERROR )
00138 
00139         {
00140 
00141             Except( Exception::UNIMPLEMENTED_FEATURE, 
00142 
00143                     "IL Error", 
00144 
00145                     iluErrorString(PossibleError) ) ;
00146 
00147         }
00148 
00149 
00150 
00151         iluSwapColours();
00152 
00153 
00154 
00155         // Now sets some variables
00156 
00157         ImageFormat = ilGetInteger( IL_IMAGE_FORMAT );
00158 
00159         BytesPerPixel = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL ); 
00160 
00161 
00162 
00163         ret_data->format = ilFormat2OgreFormat( ImageFormat, BytesPerPixel );
00164 
00165         ret_data->width = ilGetInteger( IL_IMAGE_WIDTH );
00166 
00167         ret_data->height = ilGetInteger( IL_IMAGE_HEIGHT );
00168         ret_data->depth = ilGetInteger( IL_IMAGE_DEPTH );
00169         ret_data->num_mipmaps = ilGetInteger ( IL_NUM_MIPMAPS );
00170 
00171 
00172         uint ImageSize = ilGetInteger( IL_IMAGE_WIDTH ) * ilGetInteger( IL_IMAGE_HEIGHT ) * ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL );
00173 
00174 
00175         ret_data->size = ImageSize;
00176         ret_data->flags = 0;
00177 
00178         // Move the image data to the output buffer
00179 
00180         output->allocate( ImageSize );
00181 
00182         memcpy( output->getPtr(), ilGetData(), ImageSize );
00183 
00184 
00185 
00186         ilDeleteImages( 1, &ImageName );
00187 
00188 
00189 
00190         OgreUnguardRet( ret_data );
00191 
00192     }
00193 
00194     //---------------------------------------------------------------------
00195 
00196     unsigned int BMPCodec::getILType(void) const
00197 
00198     { 
00199 
00200         return IL_BMP;
00201 
00202     }
00203 
00204 
00205 
00206 }
00207 
00208 
00209 

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:21:53 2004