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
25 #define MAX_SPRFRAMES MAX_MD2SKINS
28 dsprframe_t frames[MAX_SPRFRAMES];
30 byte *byteimage, *lbmpalette;
31 int byteimagewidth, byteimageheight;
33 char spritename[1024];
36 void FinishSprite (void);
37 void Cmd_Spritename (void);
46 void FinishSprite (void)
48 FILE *spriteouthandle;
53 if (sprite.numframes == 0)
56 if (!strlen(spritename))
57 Error ("Didn't name sprite file");
59 sprintf (savename, "%s%s.sp2", gamedir, spritename);
65 sprintf (name, "%s.sp2", spritename);
67 spritename[0] = 0; // clear for a new sprite
73 printf ("saving in %s\n", savename);
74 CreatePath (savename);
75 spriteouthandle = SafeOpenWrite (savename);
79 // write out the sprite header
81 spritetemp.ident = LittleLong (IDSPRITEHEADER);
82 spritetemp.version = LittleLong (SPRITE_VERSION);
83 spritetemp.numframes = LittleLong (sprite.numframes);
85 SafeWrite (spriteouthandle, &spritetemp, 12);
88 // write out the frames
92 for (i=0 ; i<sprite.numframes ; i++)
94 frames[i].width = LittleLong(frames[i].width);
95 frames[i].height = LittleLong(frames[i].height);
96 frames[i].origin_x = LittleLong(frames[i].origin_x);
97 frames[i].origin_y = LittleLong(frames[i].origin_y);
99 SafeWrite (spriteouthandle, frames, sizeof(frames[0])*sprite.numframes);
101 fclose (spriteouthandle);
103 spritename[0] = 0; // clear for a new sprite
104 sprite.numframes = 0;
122 name = ExpandPathAndArchive(token);
125 printf ("loading %s\n", name);
126 Load256Image (name, &byteimage, &lbmpalette,
127 &byteimagewidth, &byteimageheight);
128 RemapZero (byteimage, lbmpalette,
129 byteimagewidth, byteimageheight);
138 void Cmd_SpriteFrame (void)
140 int y,xl,yl,xh,yh,w,h;
155 // origin offset is optional
156 if (TokenAvailable ())
169 if ((xl & 0x07) || (yl & 0x07) || (w & 0x07) || (h & 0x07))
170 Error ("Sprite dimensions not multiples of 8\n");
172 if ((w > 256) || (h > 256))
173 Error ("Sprite has a dimension longer than 256");
178 if (sprite.numframes >= MAX_SPRFRAMES)
179 Error ("Too many frames; increase MAX_SPRFRAMES\n");
181 pframe = &frames[sprite.numframes];
184 pframe->origin_x = ox;
185 pframe->origin_y = oy;
186 sprintf (pframe->name, "%s_%i.pcx", spritename, sprite.numframes);
187 sprintf (savename, "%s%s_%i.pcx", gamedir, spritename, sprite.numframes);
192 ReleaseFile (pframe->name);
196 // crop it to the proper size
197 cropped = malloc (w*h);
198 for (y=0 ; y<h ; y++)
200 memcpy (cropped+y*w, byteimage+(y+yl)*byteimagewidth+xl, w);
203 // save off the new image
204 printf ("saving %s\n", savename);
205 CreatePath (savename);
206 WritePCXfile (savename, cropped, w, h, lbmpalette);
218 void Cmd_SpriteName (void)
220 if (sprite.numframes)
224 strcpy (spritename, token);
225 memset (&sprite, 0, sizeof(sprite));
226 memset (&frames, 0, sizeof(frames));