[1] | 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-2006 Torus Knot Software Ltd |
---|
| 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 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | #include <OgreStableHeaders.h> |
---|
| 30 | |
---|
| 31 | #include <OgreImage.h> |
---|
| 32 | #include <OgreCodec.h> |
---|
| 33 | #include <OgreException.h> |
---|
| 34 | #include <OgreLogManager.h> |
---|
| 35 | #include <OgreStringConverter.h> |
---|
| 36 | #include "OgreILImageCodec.h" |
---|
| 37 | #include "OgreILCodecs.h" |
---|
| 38 | |
---|
| 39 | #include <IL/il.h> |
---|
| 40 | #include <IL/ilu.h> |
---|
| 41 | |
---|
| 42 | namespace Ogre { |
---|
| 43 | std::list<ILImageCodec*> ILCodecs::codeclist; |
---|
| 44 | |
---|
| 45 | // Return IL type for a certain extension |
---|
| 46 | ILenum ogreIlTypeFromExt(const String &ext) |
---|
| 47 | { |
---|
| 48 | #ifdef IL_TGA |
---|
| 49 | if (ext=="tga" || ext=="vda" || |
---|
| 50 | ext=="icb" || ext=="vst") |
---|
| 51 | return IL_TGA; |
---|
| 52 | #endif |
---|
| 53 | #ifdef IL_JPG |
---|
| 54 | if (ext=="jpg" || ext=="jpe" || ext=="jpeg") |
---|
| 55 | return IL_JPG; |
---|
| 56 | #endif |
---|
| 57 | /*#ifdef IL_DDS |
---|
| 58 | if (ext=="dds") |
---|
| 59 | return IL_DDS; |
---|
| 60 | #endif*/ |
---|
| 61 | #ifdef IL_PNG |
---|
| 62 | if (ext=="png") |
---|
| 63 | return IL_PNG; |
---|
| 64 | #endif |
---|
| 65 | #ifdef IL_BMP |
---|
| 66 | if (ext=="bmp" || ext=="dib") |
---|
| 67 | return IL_BMP; |
---|
| 68 | #endif |
---|
| 69 | #ifdef IL_GIF |
---|
| 70 | if (ext=="gif") |
---|
| 71 | return IL_GIF; |
---|
| 72 | #endif |
---|
| 73 | #ifdef IL_CUT |
---|
| 74 | if (ext=="cut") |
---|
| 75 | return IL_CUT; |
---|
| 76 | #endif |
---|
| 77 | #ifdef IL_HDR |
---|
| 78 | if (ext=="hdr") |
---|
| 79 | return IL_HDR; |
---|
| 80 | #endif |
---|
| 81 | #ifdef IL_ICO |
---|
| 82 | if (ext=="ico" || ext=="cur") |
---|
| 83 | return IL_ICO; |
---|
| 84 | #endif |
---|
| 85 | #ifdef IL_JNG |
---|
| 86 | if (ext=="jng") |
---|
| 87 | return IL_JNG; |
---|
| 88 | #endif |
---|
| 89 | #ifdef IL_LIF |
---|
| 90 | if (ext=="lif") |
---|
| 91 | return IL_LIF; |
---|
| 92 | #endif |
---|
| 93 | #ifdef IL_MDL |
---|
| 94 | if (ext=="mdl") |
---|
| 95 | return IL_MDL; |
---|
| 96 | #endif |
---|
| 97 | #ifdef IL_MNG |
---|
| 98 | if (ext=="mng" || ext=="jng") |
---|
| 99 | return IL_MNG; |
---|
| 100 | #endif |
---|
| 101 | #ifdef IL_PCD |
---|
| 102 | if (ext=="pcd") |
---|
| 103 | return IL_PCD; |
---|
| 104 | #endif |
---|
| 105 | #ifdef IL_PCX |
---|
| 106 | if (ext=="pcx") |
---|
| 107 | return IL_PCX; |
---|
| 108 | #endif |
---|
| 109 | #ifdef IL_PIC |
---|
| 110 | if (ext=="pic") |
---|
| 111 | return IL_PIC; |
---|
| 112 | #endif |
---|
| 113 | #ifdef IL_PIX |
---|
| 114 | if (ext=="pix") |
---|
| 115 | return IL_PIX; |
---|
| 116 | #endif |
---|
| 117 | #ifdef IL_PNM |
---|
| 118 | if (ext=="pbm" || ext=="pgm" || |
---|
| 119 | ext=="pnm" || ext=="ppm") |
---|
| 120 | return IL_PNM; |
---|
| 121 | #endif |
---|
| 122 | #ifdef IL_PSD |
---|
| 123 | if (ext=="psd" || ext=="pdd") |
---|
| 124 | return IL_PSD; |
---|
| 125 | #endif |
---|
| 126 | #ifdef IL_PSP |
---|
| 127 | if (ext=="psp") |
---|
| 128 | return IL_PSP; |
---|
| 129 | #endif |
---|
| 130 | #ifdef IL_PXR |
---|
| 131 | if (ext=="pxr") |
---|
| 132 | return IL_PXR; |
---|
| 133 | #endif |
---|
| 134 | #ifdef IL_SGI |
---|
| 135 | if (ext=="sgi" || ext=="bw" || |
---|
| 136 | ext=="rgb" || ext=="rgba") |
---|
| 137 | return IL_SGI; |
---|
| 138 | #endif |
---|
| 139 | #ifdef IL_TIF |
---|
| 140 | if (ext=="tif" || ext=="tiff") |
---|
| 141 | return IL_TIF; |
---|
| 142 | #endif |
---|
| 143 | #ifdef IL_WAL |
---|
| 144 | if (ext=="wal") |
---|
| 145 | return IL_WAL; |
---|
| 146 | #endif |
---|
| 147 | #ifdef IL_XPM |
---|
| 148 | if (ext=="xpm") |
---|
| 149 | return IL_XPM; |
---|
| 150 | #endif |
---|
| 151 | |
---|
| 152 | return IL_TYPE_UNKNOWN; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | void ILCodecs::registerCodecs(void) { |
---|
| 157 | const char *il_version = ilGetString ( IL_VERSION_NUM ); |
---|
| 158 | if( ilGetError() != IL_NO_ERROR ) |
---|
| 159 | { |
---|
| 160 | // IL defined the version number as IL_VERSION in older versions, so we have to scan for it |
---|
| 161 | for(int ver=150; ver<170; ver++) |
---|
| 162 | { |
---|
| 163 | il_version = ilGetString ( ver ); |
---|
| 164 | if(ilGetError() == IL_NO_ERROR) |
---|
| 165 | break; |
---|
| 166 | else |
---|
| 167 | il_version = "Unknown"; |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | LogManager::getSingleton().logMessage( |
---|
| 171 | LML_NORMAL, |
---|
| 172 | "DevIL version: " + String(il_version)); |
---|
| 173 | const char *il_extensions = ilGetString ( IL_LOAD_EXT ); |
---|
| 174 | if( ilGetError() != IL_NO_ERROR ) |
---|
| 175 | il_extensions = ""; |
---|
| 176 | |
---|
| 177 | std::stringstream ext; |
---|
| 178 | String str, all; |
---|
| 179 | ext << il_extensions; |
---|
| 180 | while(ext >> str) |
---|
| 181 | { |
---|
| 182 | #if 0 |
---|
| 183 | String fileName = "dummy." + str; |
---|
| 184 | // DevIL doesn't export this under windows -- how weird |
---|
| 185 | int ilType = ilTypeFromext(const_cast<char*>(fileName.c_str())); |
---|
| 186 | #endif |
---|
| 187 | int ilType = ogreIlTypeFromExt(str); |
---|
| 188 | ILImageCodec *codec = new ILImageCodec(str, ilType); |
---|
| 189 | Codec::registerCodec(codec); |
---|
| 190 | codeclist.push_back(codec); |
---|
| 191 | //all += str+String("(")+StringConverter::toString(ilType)+String(") "); |
---|
| 192 | all += str+String(" "); |
---|
| 193 | } |
---|
| 194 | // Raw format, missing in image formats string |
---|
| 195 | ILImageCodec *cod = new ILImageCodec("raw", IL_RAW); |
---|
| 196 | Codec::registerCodec(cod); |
---|
| 197 | codeclist.push_back(cod); |
---|
| 198 | //all += String("raw")+"("+StringConverter::toString(IL_RAW)+String(") "); |
---|
| 199 | all += String("raw "); |
---|
| 200 | LogManager::getSingleton().logMessage( |
---|
| 201 | LML_NORMAL, |
---|
| 202 | "DevIL image formats: " + all); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | void ILCodecs::deleteCodecs(void) { |
---|
| 206 | for(std::list<ILImageCodec*>::const_iterator i = codeclist.begin(); i != codeclist.end(); ++i) |
---|
| 207 | { |
---|
| 208 | Codec::unRegisterCodec(*i); |
---|
| 209 | delete *i; |
---|
| 210 | } |
---|
| 211 | codeclist.clear(); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | } |
---|
| 215 | |
---|