2 * $Logfile: /Freespace2/code/Anim/PackUnpack.h $
7 * Code for handling packing and unpacking in Hoffoss's RLE format, used for
8 * Anim files. Also handles Anim loading, creating Anim instances (for
9 * utilizing an Anim), and getting getting frames of the Anim.
12 * Revision 1.1 2002/05/03 03:28:11 root
16 * 7 7/16/99 1:49p Dave
17 * 8 bit aabitmaps. yay.
19 * 6 1/14/99 12:48a Dave
20 * Todo list bug fixes. Made a pass at putting briefing icons back into
21 * FRED. Sort of works :(
23 * 5 11/30/98 1:07p Dave
24 * 16 bit conversion, first run.
26 * 4 10/22/98 6:14p Dave
27 * Optimized some #includes in Anim folder. Put in the beginnings of
28 * parse/localization support for externalized strings and tstrings.tbl
30 * 3 10/16/98 3:42p Andsager
31 * increase MAX_WEAPONS and MAX_SHIPS and som header files
33 * 2 10/07/98 10:52a Dave
36 * 1 10/07/98 10:48a Dave
38 * 32 5/18/98 5:59p Hoffoss
39 * Made command briefing advanced now once the speech stops and animation
40 * has fully played once, whichever is longer.
42 * 31 5/07/98 3:11a Lawrance
43 * Implement custom streaming code
45 * 30 1/14/98 6:43p Lawrance
46 * Add ref_count to anim struct, so we don't free multiple times
48 * 29 11/19/97 8:28p Dave
49 * Hooked in Main Hall screen. Put in Anim support for ping ponging
50 * animations as well as general reversal of anim direction.
52 * 28 8/30/97 2:11p Lawrance
53 * allow animations to loop
55 * 27 8/25/97 11:13p Lawrance
56 * support framerate independent playback with the option of now advancing
57 * more than one frame at a time
59 * 26 8/21/97 5:11p Lawrance
60 * frame numbering for ANI's now is from 0 -> total_frames-1.
62 * 25 7/28/97 10:42p Lawrance
63 * re-did interface to unpack_frame() to make more general
65 * 24 7/21/97 11:41a Lawrance
66 * make playback time of .ani files keyed of frametime
68 * 23 7/20/97 6:57p Lawrance
69 * supporting new RLE format
71 * 22 6/27/97 4:36p Lawrance
72 * update pal translation table when gr_screen.signature changes
74 * 21 6/26/97 12:12a Lawrance
75 * supporting anti-aliased bitmap animations
77 * 20 6/25/97 3:03p Lawrance
78 * fix palette translation problem with anti-alised bitmaps
80 * 19 5/27/97 3:48p Lawrance
81 * don't re-create a bitmap if using the same frame of animation
83 * 18 5/21/97 11:06a Lawrance
84 * enabling a user-defined transparent value
86 * 17 5/19/97 3:21p Lawrance
87 * add fps parm, version num to anim header
89 * 16 5/19/97 2:28p Lawrance
90 * changes some variables to flags
92 * 15 5/15/97 4:42p Lawrance
93 * supporting animations in-game
95 * 14 3/01/97 2:08p Lawrance
96 * not using windows.h, since memory mapping details moved to cfile
98 * 13 2/28/97 12:17p Lawrance
99 * supporting mapping file to memory
101 * 12 2/25/97 11:06a Lawrance
102 * moved some higher level functions to from PackUnpack to AnimPlay
104 * 11 2/19/97 9:51p Lawrance
105 * made keyframe decompression more effecient, moved
106 * default anim FPS to header file
108 * 10 2/19/97 4:01p Lawrance
109 * load_anim returns int, not void
111 * 9 2/17/97 4:19p Lawrance
112 * changed stop and start to be actual frame numbers, not percentages
114 * 8 2/17/97 4:17p Hoffoss
115 * modified packing internal format and added random access function to an
118 * 7 2/17/97 2:59p Lawrance
119 * integrating into game
121 * 6 2/14/97 11:09p Hoffoss
122 * Made optimizations.
124 * 5 2/14/97 10:48p Hoffoss
127 * 4 2/14/97 10:38p Lawrance
130 * 3 2/14/97 3:29p Hoffoss
131 * Added header for MSDEV to fill in.
136 #ifndef __PACKUNPACK_H__
137 #define __PACKUNPACK_H__
143 #define ANI_STREAM_CACHE_SIZE 4096
145 #define PACKER_CODE 0xEE // Use'd by PACKING_METHOD_RLE
146 #define PACKING_METHOD_RLE 0 // Hoffoss's RLE format
147 #define PACKING_METHOD_RLE_KEY 1 // Hoffoss's key frame RLE format
148 #define PACKING_METHOD_STD_RLE 2 // Standard RLE format (high bit is count)
149 #define PACKING_METHOD_STD_RLE_KEY 3 // Standard RLE format key frame
151 #define STD_RLE_CODE 0x80
153 typedef struct key_frame {
154 int frame_num; // which frame number this key frame is
155 int offset; // offset from the start of data block
158 #define ANF_MEM_MAPPED (1<<0) // animation is memory-mapped file
159 #define ANF_STREAMED (1<<1)
160 #define ANF_XPARENT (1<<2) // animation has transparency
161 #define ANF_ALL_KEYFRAMES (1<<3) // all the frames are keyframes (this is necessary if we want to play the file backwards)
163 typedef struct anim {
165 char name[MAX_PATH_LEN];
170 int instance_count; // number of instances that are currently playing
171 int ref_count; // number of times this anim has been loaded
172 float time; // playback time in seconds
176 ubyte palette_translation[256];
177 ubyte *data; // points to compressed data
181 ubyte xparent_r; // red component for the transparent color in source image
182 ubyte xparent_g; // green component for the transparent color in source image
183 ubyte xparent_b; // blue component for the transparent color in source image
186 int file_offset; // file offset to start of frame data
187 int cache_file_offset;
191 // the direction to play the anim (forwards or backwards)
192 #define ANIM_DIRECT_FORWARD 0
193 #define ANIM_DIRECT_REVERSE 1
195 typedef struct anim_instance {
196 anim_instance *next, *prev;
197 int x,y; // coordinates anim is played at (top left corner of anim)
198 vector *world_pos; // world (x,y,z) position of explosion
199 float radius; // radius of image, needed for scaling
200 int frame_num; // current frame, or last frame if between frames (first frame is 0)
201 int last_frame_num;// last frame rendered
202 anim *parent; // pointer to anim structure, which holds compressed data
203 ubyte *data; // pointer to next frame's compressed data
204 ubyte *frame; // uncompressed frame
205 float time_elapsed; // how long the anim has played for (in seconds)
206 int start_at; // frame anim playing should start
207 int stop_at; // frame anim playing should stop
208 int framerate_independent; // animation should play back in same amount of time, regardless
209 int skip_frames; // should anim skip frames during framerate independent playback
210 int looped; // should anim keep playing over and over...
211 int stop_now; // flag to indicate time to stop the animation
212 int last_bitmap; // id of last bitmap that was rendered out from animation
213 int screen_id; // 0 means all screens should render, otherwise screen specific
214 void *aa_color; // anti-aliased bitmap color
216 int direction; // playing forwards or backwards ?
217 int ping_pong; // should be played ping-pong style
218 int paused; // pause the anim
219 int file_offset; // current offset into frame (like data, put offset into file)
220 int loop_count; // starts at 0, and is incremented each time it loops
223 extern int packer_code;
225 int pack_key_frame(ubyte *frame, ubyte *save, long size, long max, int compress_type);
226 int pack_frame(ubyte *frame, ubyte *frame2, ubyte *save, long size, long max, int compress_type);
228 ubyte *unpack_frame(anim_instance *ai, ubyte *ptr, ubyte *frame, int size, ubyte *pal_translate, int aabitmap, int bpp);
229 int unpack_frame_from_file(anim_instance *ai, ubyte *frame, int size, ubyte *pal_translate, int aabitmap, int bpp);
232 anim_instance *init_anim_instance(anim *ptr, int bpp);
233 void free_anim_instance(anim_instance *inst);
234 int anim_get_next_frame(anim_instance *inst);
235 int anim_get_frame(anim_instance *inst, int frame_num, int xlate_pal=1);
236 ubyte *anim_get_next_raw_buffer(anim_instance *inst, int xlate_pal, int aabitmap, int bpp);
237 void anim_set_palette(anim *a);
238 void anim_check_for_palette_change(anim_instance *inst);
241 #endif /* __PACKUNPACK_H__ */