2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
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 void LoadM8( const char *name, unsigned char **pic, int *width, int *height ){
29 m8_header_t *m8_header;
31 int i, num_pixels, size;
32 char text_buf[255] = { 0 };
35 unsigned char *palette_ent, *buf_temp;
36 unsigned char *buffer, *m8_file_buffer;
38 strcpy( text_buf, name );
39 text_dot_pos = strchr( text_buf, '.' );
43 // Fix for .pcx.m8 extention
44 strcat( text_buf, ".pcx.m8" );
47 if ( ( length = vfsLoadFile( (char *) text_buf, (void **) &m8_file_buffer, 0 ) ) == (unsigned int) -1 ) {
48 strcpy( text_buf, name );
49 for ( i = ( strlen( text_buf ) - 1 ); i > 0; i-- )
51 if ( text_buf[i] == '.' ) {
56 strcat( text_buf, ".m8" );
57 if ( length = vfsLoadFile( (char *) text_buf, (void **) &m8_file_buffer, 0 ) == (unsigned int) -1 ) {
58 Sys_Printf( "Unable to open file %s\n",name );
63 m8_header = (m8_header_t *)m8_file_buffer;
65 // make sure we have a valid M8 file
66 if ( m8_header->version != M8_VERSION ) {
67 vfsFreeFile( m8_file_buffer );
68 Sys_Printf( "Invalid M8 file %s\n", name );
73 *width = m8_header->width[0]; // Only interested in 1st MIP
74 *height = m8_header->height[0];
75 num_pixels = ( *width ) * ( *height );
76 size = num_pixels * 4;
79 buf_temp = (unsigned char *)( g_malloc( size ) );
83 palette = m8_header->palette;
86 buffer = m8_file_buffer + m8_header->offsets[0];
89 // Load texture into buffer
91 for ( i = 0; i < num_pixels; i++ )
93 *buf_temp++ = palette[*palette_ent].r;
94 *buf_temp++ = palette[*palette_ent].g;
95 *buf_temp++ = palette[*palette_ent].b;
96 *buf_temp++ = 255; // No alpha
100 Sys_Printf( "Loaded file %s\n",text_buf );
102 vfsFreeFile( m8_file_buffer );