[692] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | #include "OgreStableHeaders.h"
|
---|
| 26 |
|
---|
| 27 | #include "OgreImage.h"
|
---|
| 28 | #include "OgreCodec.h"
|
---|
| 29 | #include "OgreException.h"
|
---|
| 30 | #include "OgreLogManager.h"
|
---|
| 31 | #include "OgreStringConverter.h"
|
---|
| 32 | #include "OgreILImageCodec.h"
|
---|
| 33 | #include "OgreILCodecs.h"
|
---|
| 34 |
|
---|
| 35 | #include <IL/il.h>
|
---|
| 36 | #include <IL/ilu.h>
|
---|
| 37 |
|
---|
| 38 | namespace Ogre {
|
---|
| 39 | std::list<ILImageCodec*> ILCodecs::codeclist;
|
---|
| 40 |
|
---|
| 41 | // Return IL type for a certain extension
|
---|
| 42 | ILenum ogreIlTypeFromExt(const String &ext)
|
---|
| 43 | {
|
---|
| 44 | #ifdef IL_TGA
|
---|
| 45 | if (ext=="tga" || ext=="vda" ||
|
---|
| 46 | ext=="icb" || ext=="vst")
|
---|
| 47 | return IL_TGA;
|
---|
| 48 | #endif
|
---|
| 49 | #ifdef IL_JPG
|
---|
| 50 | if (ext=="jpg" || ext=="jpe" || ext=="jpeg")
|
---|
| 51 | return IL_JPG;
|
---|
| 52 | #endif
|
---|
| 53 | #ifdef IL_DDS
|
---|
| 54 | if (ext=="dds")
|
---|
| 55 | return IL_DDS;
|
---|
| 56 | #endif
|
---|
| 57 | #ifdef IL_PNG
|
---|
| 58 | if (ext=="png")
|
---|
| 59 | return IL_PNG;
|
---|
| 60 | #endif
|
---|
| 61 | #ifdef IL_BMP
|
---|
| 62 | if (ext=="bmp" || ext=="dib")
|
---|
| 63 | return IL_BMP;
|
---|
| 64 | #endif
|
---|
| 65 | #ifdef IL_GIF
|
---|
| 66 | if (ext=="gif")
|
---|
| 67 | return IL_GIF;
|
---|
| 68 | #endif
|
---|
| 69 | #ifdef IL_CUT
|
---|
| 70 | if (ext=="cut")
|
---|
| 71 | return IL_CUT;
|
---|
| 72 | #endif
|
---|
| 73 | #ifdef IL_HDR
|
---|
| 74 | if (ext=="hdr")
|
---|
| 75 | return IL_HDR;
|
---|
| 76 | #endif
|
---|
| 77 | #ifdef IL_ICO
|
---|
| 78 | if (ext=="ico" || ext=="cur")
|
---|
| 79 | return IL_ICO;
|
---|
| 80 | #endif
|
---|
| 81 | #ifdef IL_JNG
|
---|
| 82 | if (ext=="jng")
|
---|
| 83 | return IL_JNG;
|
---|
| 84 | #endif
|
---|
| 85 | #ifdef IL_LIF
|
---|
| 86 | if (ext=="lif")
|
---|
| 87 | return IL_LIF;
|
---|
| 88 | #endif
|
---|
| 89 | #ifdef IL_MDL
|
---|
| 90 | if (ext=="mdl")
|
---|
| 91 | return IL_MDL;
|
---|
| 92 | #endif
|
---|
| 93 | #ifdef IL_MNG
|
---|
| 94 | if (ext=="mng" || ext=="jng")
|
---|
| 95 | return IL_MNG;
|
---|
| 96 | #endif
|
---|
| 97 | #ifdef IL_PCD
|
---|
| 98 | if (ext=="pcd")
|
---|
| 99 | return IL_PCD;
|
---|
| 100 | #endif
|
---|
| 101 | #ifdef IL_PCX
|
---|
| 102 | if (ext=="pcx")
|
---|
| 103 | return IL_PCX;
|
---|
| 104 | #endif
|
---|
| 105 | #ifdef IL_PIC
|
---|
| 106 | if (ext=="pic")
|
---|
| 107 | return IL_PIC;
|
---|
| 108 | #endif
|
---|
| 109 | #ifdef IL_PIX
|
---|
| 110 | if (ext=="pix")
|
---|
| 111 | return IL_PIX;
|
---|
| 112 | #endif
|
---|
| 113 | #ifdef IL_PNM
|
---|
| 114 | if (ext=="pbm" || ext=="pgm" ||
|
---|
| 115 | ext=="pnm" || ext=="ppm")
|
---|
| 116 | return IL_PNM;
|
---|
| 117 | #endif
|
---|
| 118 | #ifdef IL_PSD
|
---|
| 119 | if (ext=="psd" || ext=="pdd")
|
---|
| 120 | return IL_PSD;
|
---|
| 121 | #endif
|
---|
| 122 | #ifdef IL_PSP
|
---|
| 123 | if (ext=="psp")
|
---|
| 124 | return IL_PSP;
|
---|
| 125 | #endif
|
---|
| 126 | #ifdef IL_PXR
|
---|
| 127 | if (ext=="pxr")
|
---|
| 128 | return IL_PXR;
|
---|
| 129 | #endif
|
---|
| 130 | #ifdef IL_SGI
|
---|
| 131 | if (ext=="sgi" || ext=="bw" ||
|
---|
| 132 | ext=="rgb" || ext=="rgba")
|
---|
| 133 | return IL_SGI;
|
---|
| 134 | #endif
|
---|
| 135 | #ifdef IL_TIF
|
---|
| 136 | if (ext=="tif" || ext=="tiff")
|
---|
| 137 | return IL_TIF;
|
---|
| 138 | #endif
|
---|
| 139 | #ifdef IL_WAL
|
---|
| 140 | if (ext=="wal")
|
---|
| 141 | return IL_WAL;
|
---|
| 142 | #endif
|
---|
| 143 | #ifdef IL_XPM
|
---|
| 144 | if (ext=="xpm")
|
---|
| 145 | return IL_XPM;
|
---|
| 146 | #endif
|
---|
| 147 |
|
---|
| 148 | return IL_TYPE_UNKNOWN;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | void ILCodecs::registerCodecs(void) {
|
---|
| 153 | const char *il_version = ilGetString ( IL_VERSION_NUM );
|
---|
| 154 | if( ilGetError() != IL_NO_ERROR )
|
---|
| 155 | {
|
---|
| 156 | // IL defined the version number as IL_VERSION in older versions, so we have to scan for it
|
---|
| 157 | for(int ver=150; ver<170; ver++)
|
---|
| 158 | {
|
---|
| 159 | il_version = ilGetString ( ver );
|
---|
| 160 | if(ilGetError() == IL_NO_ERROR)
|
---|
| 161 | break;
|
---|
| 162 | else
|
---|
| 163 | il_version = "Unknown";
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | LogManager::getSingleton().logMessage(
|
---|
| 167 | LML_NORMAL,
|
---|
| 168 | "DevIL version: " + String(il_version));
|
---|
| 169 | const char *il_extensions = ilGetString ( IL_LOAD_EXT );
|
---|
| 170 | if( ilGetError() != IL_NO_ERROR )
|
---|
| 171 | il_extensions = "";
|
---|
| 172 |
|
---|
| 173 | std::stringstream ext;
|
---|
| 174 | String str, all;
|
---|
| 175 | ext << il_extensions;
|
---|
| 176 | while(ext >> str)
|
---|
| 177 | {
|
---|
| 178 | #if 0
|
---|
| 179 | String fileName = "dummy." + str;
|
---|
| 180 | // DevIL doesn't export this under windows -- how weird
|
---|
| 181 | int ilType = ilTypeFromext(const_cast<char*>(fileName.c_str()));
|
---|
| 182 | #endif
|
---|
| 183 | int ilType = ogreIlTypeFromExt(str);
|
---|
| 184 | ILImageCodec *codec = new ILImageCodec(str, ilType);
|
---|
| 185 | Codec::registerCodec(codec);
|
---|
| 186 | codeclist.push_back(codec);
|
---|
| 187 | //all += str+String("(")+StringConverter::toString(ilType)+String(") ");
|
---|
| 188 | all += str+String(" ");
|
---|
| 189 | }
|
---|
| 190 | // Raw format, missing in image formats string
|
---|
| 191 | ILImageCodec *cod = new ILImageCodec("raw", IL_RAW);
|
---|
| 192 | Codec::registerCodec(cod);
|
---|
| 193 | codeclist.push_back(cod);
|
---|
| 194 | //all += String("raw")+"("+StringConverter::toString(IL_RAW)+String(") ");
|
---|
| 195 | all += String("raw ");
|
---|
| 196 | LogManager::getSingleton().logMessage(
|
---|
| 197 | LML_NORMAL,
|
---|
| 198 | "DevIL image formats: " + all);
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | void ILCodecs::deleteCodecs(void) {
|
---|
| 202 | for(std::list<ILImageCodec*>::const_iterator i = codeclist.begin(); i != codeclist.end(); ++i)
|
---|
| 203 | {
|
---|
| 204 | Codec::unRegisterCodec(*i);
|
---|
| 205 | delete *i;
|
---|
| 206 | }
|
---|
| 207 | codeclist.clear();
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | }
|
---|
| 211 |
|
---|