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)
30 m8_header_t *m8_header;
32 int i, num_pixels, size;
33 char text_buf[255] = { 0 };
36 unsigned char *palette_ent, *buf_temp;
37 unsigned char *buffer, *m8_file_buffer;
39 strcpy(text_buf, name);
40 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)
49 strcpy(text_buf, name);
50 for(i=(strlen(text_buf)-1); i>0; i--)
58 strcat(text_buf, ".m8");
59 if ( length = vfsLoadFile ((char *) text_buf, (void **) &m8_file_buffer, 0) == (unsigned int) -1)
61 Sys_Printf("Unable to open file %s\n",name);
66 m8_header = (m8_header_t *)m8_file_buffer;
68 // make sure we have a valid M8 file
69 if ( m8_header->version != M8_VERSION)
71 vfsFreeFile(m8_file_buffer);
72 Sys_Printf("Invalid M8 file %s\n", name);
77 *width = m8_header->width[0]; // Only interested in 1st MIP
78 *height = m8_header->height[0];
79 num_pixels = (*width) * (*height);
83 buf_temp = (unsigned char *)(g_malloc(size));
87 palette = m8_header->palette;
90 buffer = m8_file_buffer + m8_header->offsets[0];
93 // Load texture into buffer
95 for(i=0; i<num_pixels; i++)
97 *buf_temp++ = palette[*palette_ent].r;
98 *buf_temp++ = palette[*palette_ent].g;
99 *buf_temp++ = palette[*palette_ent].b;
100 *buf_temp++ = 255; // No alpha
104 Sys_Printf("Loaded file %s\n",text_buf);
106 vfsFreeFile(m8_file_buffer);