2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "ifilesystem.h"
28 #include "bytestreamutils.h"
30 #include "stream/textstream.h"
33 #include "mdlformat.h"
37 unsigned char mdl_palette[768];
43 void Texture_InitPalette (byte *pal)
51 gamma = 1.0;//g_qeglobals.d_savedinfo.fGamma;
55 for (i=0 ; i<256 ; i++)
59 for (i=0 ; i<256 ; i++)
61 inf = (int)(255 * pow ( (i+0.5)/255.5 , gamma ) + 0.5);
70 for (i=0 ; i<256 ; i++)
72 r = gammatable[pal[0]];
73 g = gammatable[pal[1]];
74 b = gammatable[pal[2]];
77 //v = (r<<24) + (g<<16) + (b<<8) + 255;
81 mdl_palette[i*3+0] = r;
82 mdl_palette[i*3+1] = g;
83 mdl_palette[i*3+2] = b;
89 unsigned char* buffer;
91 vfsLoadFile ("gfx/palette.lmp", (void **) &buffer);
95 Texture_InitPalette(buffer);
102 Image* LoadMDLImageBuff(byte* buffer)
109 if(!ident_equal(buffer, MDL_IDENT))
111 globalErrorStream() << "LoadMDLImage: data has wrong ident\n";
115 PointerInputStream inputStream(buffer);
116 inputStream.seek(4 + 4 + 12 + 12 + 4 + 12);
118 istream_read_int32_le(inputStream);
119 int skinwidth = istream_read_int32_le(inputStream);
120 int skinheight = istream_read_int32_le(inputStream);
121 inputStream.seek(4 + 4 + 4 + 4 + 4 + 4);
123 switch(istream_read_int32_le(inputStream))
125 case MDL_SKIN_SINGLE:
128 int numskins = istream_read_int32_le(inputStream);
129 inputStream.seek(numskins * 4);
133 RGBAImage* image = new RGBAImage(skinwidth, skinheight);
134 unsigned char* pRGBA = image->getRGBAPixels();
136 for(int i=0; i<(skinheight); i++)
138 for(int j=0; j<(skinwidth); j++)
140 byte index = istream_read_byte(inputStream);
141 *pRGBA++ = mdl_palette[index * 3 + 0];
142 *pRGBA++ = mdl_palette[index * 3 + 1];
143 *pRGBA++ = mdl_palette[index * 3 + 2];
151 Image* LoadMDLImage(ArchiveFile& file)
153 ScopedArchiveBuffer buffer(file);
154 return LoadMDLImageBuff( buffer.buffer );
157 void MDLImage_Destroy(byte* pic)