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
24 #include "ifilesystem.h"
26 #include "bytestreamutils.h"
29 typedef unsigned char byte;
31 const int M32_NAME_LENGTH = 128;
32 const int M32_MIPMAP_COUNT = 16;
34 typedef struct m32_header_t
37 char name[M32_NAME_LENGTH];
38 char altname[M32_NAME_LENGTH]; // texture substitution
39 char animname[M32_NAME_LENGTH]; // next frame in animation chain
40 char damagename[M32_NAME_LENGTH]; // image that should be shown when damaged
41 unsigned width[M32_MIPMAP_COUNT], height[M32_MIPMAP_COUNT];
42 unsigned offsets[M32_MIPMAP_COUNT];
46 float scale_x, scale_y;
49 // detail texturing info
50 char dt_name[M32_NAME_LENGTH]; // detailed texture name
51 float dt_scale_x, dt_scale_y;
54 int dt_src_blend_mode, dt_dst_blend_mode;
56 int unused[20]; // future expansion to maintain compatibility with h2
60 Image* LoadM32Buff( byte* buffer ){
61 PointerInputStream inputStream( buffer );
63 inputStream.seek( 4 // version
64 + M32_NAME_LENGTH // name
65 + M32_NAME_LENGTH // altname
66 + M32_NAME_LENGTH // animname
67 + M32_NAME_LENGTH ); // damagename
68 int w = istream_read_uint32_le( inputStream );
69 inputStream.seek( 4 * ( M32_MIPMAP_COUNT - 1 ) ); // remaining widths
70 int h = istream_read_uint32_le( inputStream );
71 inputStream.seek( 4 * ( M32_MIPMAP_COUNT - 1 ) ); // remaining heights
72 int offset = istream_read_uint32_le( inputStream );
73 inputStream.seek( 4 * ( M32_MIPMAP_COUNT - 1 ) ); // remaining offsets
74 int flags = istream_read_uint32_le( inputStream );
75 int contents = istream_read_uint32_le( inputStream );
76 int value = istream_read_uint32_le( inputStream );
78 RGBAImageFlags* image = new RGBAImageFlags( w, h, flags, contents, value );
80 const byte* source = buffer + offset;
81 std::copy( source, source + ( w * h * 4 ), image->getRGBAPixels() );
86 Image* LoadM32( ArchiveFile& file ){
87 ScopedArchiveBuffer buffer( file );
88 return LoadM32Buff( buffer.buffer );