2 Copyright (C) 1999-2006 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
22 // by Hydra - hydra@hydras-world.com
30 typedef unsigned char byte;
32 #include "ifilesystem.h"
37 ============================================================================
39 IDSP IMAGE (.spr files)
41 Some code copied straight from the Q1 source, also used the HalfLife SDK as
44 ============================================================================
47 typedef enum {ST_SYNC = 0, ST_RAND } synctype_t;
48 typedef enum { SPR_SINGLE = 0, SPR_GROUP } spriteframetype_t;
50 typedef struct dspriteheader_s {
94 #define IDSPRITEHEADER ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'D' << 8 ) + 'I' )
95 // little-endian "IDSP"
103 Image* LoadIDSPBuff( byte *buffer ){
105 int columns, rows, numPixels;
110 unsigned char red, green, blue, alphabyte;
112 dspriteheader_t *header;
115 dspriteframetype_t *pframetype;
118 dspriteframe_t *spriteframe;
120 header = (dspriteheader_t *)buffer;
122 if ( header->ident != IDSPRITEHEADER ) {
123 globalErrorStream() << "WARNING: IDSP file has wrong header\n";
127 version = header->version;
128 if ( version != 1 && version != 2 ) {
129 globalErrorStream() << "WARNING: IDSP file has wrong version number "
130 "(" << version << " should be 1 or 2)\n";
134 // initialise variables depending on the sprite version.
138 pinv1 = (dspritev1_t *)( header + 1 );
139 numframes = pinv1->numframes;
140 columns = pinv1->width;
141 rows = pinv1->height;
142 pframetype = (dspriteframetype_t *)( pinv1 + 1 );
145 pinv2 = (dspritev2_t *)( header + 1 );
146 numframes = pinv2->numframes;
147 columns = pinv2->width;
148 rows = pinv2->height;
149 pframetype = (dspriteframetype_t *)( pinv2 + 1 );
152 globalErrorStream() << "WARNING: IDSP file has unsupported version\n";
155 if ( numframes > 1 ) {
156 globalErrorStream() << "WARNING: IDSP file has multiple frames, only the first frame will be used.\n";
159 // palette = buffer+mipdatasize+2;
160 // buf_p = buffer+lpMip->offsets[0];
162 numPixels = columns * rows;
164 RGBAImage* image = new RGBAImage( columns, rows );
167 frametype = spriteframetype_t( pframetype->type );
168 if ( frametype == SPR_SINGLE ) {
169 globalOutputStream() << "Single Frame\n";
171 else if ( frametype == SPR_GROUP ) {
172 globalOutputStream() << "Group of Frames\n";
176 globalOutputStream() << "Bleh!\n"; // <-- we always get this, wtf!
180 palette = (byte *)( pframetype + 1 );
181 spriteframe = (dspriteframe_t *)( palette + ( 256 * 3 ) + 4 ); // what are those 4 extra bytes ? what's missing ?
182 buf_p = (byte *)( spriteframe + 1 );
184 for ( row = 0; row < rows; row++ )
186 pixbuf = image->getRGBAPixels() + row * columns * 4;
188 for ( column = 0; column < columns; column++ )
194 red = *( palette + ( palIndex * 3 ) );
195 green = *( palette + ( palIndex * 3 ) + 1 );
196 blue = *( palette + ( palIndex * 3 ) + 2 );
198 // HalfLife engine makes pixels that are BLUE transparent. (RGB = 0x0000FF)
199 // So show them that way in the editor.
200 if ( blue == 0xff && red == 0x00 && green == 0x00 ) {
201 alphabyte = 0xff; //FIXME: backwards? (so sprite models to render correctly)
202 blue = 0x00; // don't set the resulting pixel to blue
206 alphabyte = 0x00; //FIXME: backwards? (so sprite models to render correctly)
213 *pixbuf++ = alphabyte;
220 Image* LoadIDSP( ArchiveFile& file ){
221 ScopedArchiveBuffer buffer( file );
222 return LoadIDSPBuff( buffer.buffer );