2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Anim/PackUnpack.h $
15 * Code for handling packing and unpacking in Hoffoss's RLE format, used for
16 * Anim files. Also handles Anim loading, creating Anim instances (for
17 * utilizing an Anim), and getting getting frames of the Anim.
20 * Revision 1.2 2002/06/09 04:41:14 relnev
21 * added copyright header
23 * Revision 1.1.1.1 2002/05/03 03:28:11 root
27 * 7 7/16/99 1:49p Dave
28 * 8 bit aabitmaps. yay.
30 * 6 1/14/99 12:48a Dave
31 * Todo list bug fixes. Made a pass at putting briefing icons back into
32 * FRED. Sort of works :(
34 * 5 11/30/98 1:07p Dave
35 * 16 bit conversion, first run.
37 * 4 10/22/98 6:14p Dave
38 * Optimized some #includes in Anim folder. Put in the beginnings of
39 * parse/localization support for externalized strings and tstrings.tbl
41 * 3 10/16/98 3:42p Andsager
42 * increase MAX_WEAPONS and MAX_SHIPS and som header files
44 * 2 10/07/98 10:52a Dave
47 * 1 10/07/98 10:48a Dave
49 * 32 5/18/98 5:59p Hoffoss
50 * Made command briefing advanced now once the speech stops and animation
51 * has fully played once, whichever is longer.
53 * 31 5/07/98 3:11a Lawrance
54 * Implement custom streaming code
56 * 30 1/14/98 6:43p Lawrance
57 * Add ref_count to anim struct, so we don't free multiple times
59 * 29 11/19/97 8:28p Dave
60 * Hooked in Main Hall screen. Put in Anim support for ping ponging
61 * animations as well as general reversal of anim direction.
63 * 28 8/30/97 2:11p Lawrance
64 * allow animations to loop
66 * 27 8/25/97 11:13p Lawrance
67 * support framerate independent playback with the option of now advancing
68 * more than one frame at a time
70 * 26 8/21/97 5:11p Lawrance
71 * frame numbering for ANI's now is from 0 -> total_frames-1.
73 * 25 7/28/97 10:42p Lawrance
74 * re-did interface to unpack_frame() to make more general
76 * 24 7/21/97 11:41a Lawrance
77 * make playback time of .ani files keyed of frametime
79 * 23 7/20/97 6:57p Lawrance
80 * supporting new RLE format
82 * 22 6/27/97 4:36p Lawrance
83 * update pal translation table when gr_screen.signature changes
85 * 21 6/26/97 12:12a Lawrance
86 * supporting anti-aliased bitmap animations
88 * 20 6/25/97 3:03p Lawrance
89 * fix palette translation problem with anti-alised bitmaps
91 * 19 5/27/97 3:48p Lawrance
92 * don't re-create a bitmap if using the same frame of animation
94 * 18 5/21/97 11:06a Lawrance
95 * enabling a user-defined transparent value
97 * 17 5/19/97 3:21p Lawrance
98 * add fps parm, version num to anim header
100 * 16 5/19/97 2:28p Lawrance
101 * changes some variables to flags
103 * 15 5/15/97 4:42p Lawrance
104 * supporting animations in-game
106 * 14 3/01/97 2:08p Lawrance
107 * not using windows.h, since memory mapping details moved to cfile
109 * 13 2/28/97 12:17p Lawrance
110 * supporting mapping file to memory
112 * 12 2/25/97 11:06a Lawrance
113 * moved some higher level functions to from PackUnpack to AnimPlay
115 * 11 2/19/97 9:51p Lawrance
116 * made keyframe decompression more effecient, moved
117 * default anim FPS to header file
119 * 10 2/19/97 4:01p Lawrance
120 * load_anim returns int, not void
122 * 9 2/17/97 4:19p Lawrance
123 * changed stop and start to be actual frame numbers, not percentages
125 * 8 2/17/97 4:17p Hoffoss
126 * modified packing internal format and added random access function to an
129 * 7 2/17/97 2:59p Lawrance
130 * integrating into game
132 * 6 2/14/97 11:09p Hoffoss
133 * Made optimizations.
135 * 5 2/14/97 10:48p Hoffoss
138 * 4 2/14/97 10:38p Lawrance
141 * 3 2/14/97 3:29p Hoffoss
142 * Added header for MSDEV to fill in.
147 #ifndef __PACKUNPACK_H__
148 #define __PACKUNPACK_H__
154 #define ANI_STREAM_CACHE_SIZE 4096
156 #define PACKER_CODE 0xEE // Use'd by PACKING_METHOD_RLE
157 #define PACKING_METHOD_RLE 0 // Hoffoss's RLE format
158 #define PACKING_METHOD_RLE_KEY 1 // Hoffoss's key frame RLE format
159 #define PACKING_METHOD_STD_RLE 2 // Standard RLE format (high bit is count)
160 #define PACKING_METHOD_STD_RLE_KEY 3 // Standard RLE format key frame
162 #define STD_RLE_CODE 0x80
164 typedef struct key_frame {
165 int frame_num; // which frame number this key frame is
166 int offset; // offset from the start of data block
169 #define ANF_MEM_MAPPED (1<<0) // animation is memory-mapped file
170 #define ANF_STREAMED (1<<1)
171 #define ANF_XPARENT (1<<2) // animation has transparency
172 #define ANF_ALL_KEYFRAMES (1<<3) // all the frames are keyframes (this is necessary if we want to play the file backwards)
174 typedef struct anim {
176 char name[MAX_PATH_LEN];
181 int instance_count; // number of instances that are currently playing
182 int ref_count; // number of times this anim has been loaded
183 float time; // playback time in seconds
187 ubyte palette_translation[256];
188 ubyte *data; // points to compressed data
192 ubyte xparent_r; // red component for the transparent color in source image
193 ubyte xparent_g; // green component for the transparent color in source image
194 ubyte xparent_b; // blue component for the transparent color in source image
197 int file_offset; // file offset to start of frame data
198 int cache_file_offset;
202 // the direction to play the anim (forwards or backwards)
203 #define ANIM_DIRECT_FORWARD 0
204 #define ANIM_DIRECT_REVERSE 1
206 typedef struct anim_instance {
207 anim_instance *next, *prev;
208 int x,y; // coordinates anim is played at (top left corner of anim)
209 vector *world_pos; // world (x,y,z) position of explosion
210 float radius; // radius of image, needed for scaling
211 int frame_num; // current frame, or last frame if between frames (first frame is 0)
212 int last_frame_num;// last frame rendered
213 anim *parent; // pointer to anim structure, which holds compressed data
214 ubyte *data; // pointer to next frame's compressed data
215 ubyte *frame; // uncompressed frame
216 float time_elapsed; // how long the anim has played for (in seconds)
217 int start_at; // frame anim playing should start
218 int stop_at; // frame anim playing should stop
219 int framerate_independent; // animation should play back in same amount of time, regardless
220 int skip_frames; // should anim skip frames during framerate independent playback
221 int looped; // should anim keep playing over and over...
222 int stop_now; // flag to indicate time to stop the animation
223 int last_bitmap; // id of last bitmap that was rendered out from animation
224 int screen_id; // 0 means all screens should render, otherwise screen specific
225 void *aa_color; // anti-aliased bitmap color
227 int direction; // playing forwards or backwards ?
228 int ping_pong; // should be played ping-pong style
229 int paused; // pause the anim
230 int file_offset; // current offset into frame (like data, put offset into file)
231 int loop_count; // starts at 0, and is incremented each time it loops
234 extern int packer_code;
236 int pack_key_frame(ubyte *frame, ubyte *save, long size, long max, int compress_type);
237 int pack_frame(ubyte *frame, ubyte *frame2, ubyte *save, long size, long max, int compress_type);
239 ubyte *unpack_frame(anim_instance *ai, ubyte *ptr, ubyte *frame, int size, ubyte *pal_translate, int aabitmap, int bpp);
240 int unpack_frame_from_file(anim_instance *ai, ubyte *frame, int size, ubyte *pal_translate, int aabitmap, int bpp);
243 anim_instance *init_anim_instance(anim *ptr, int bpp);
244 void free_anim_instance(anim_instance *inst);
245 int anim_get_next_frame(anim_instance *inst);
246 int anim_get_frame(anim_instance *inst, int frame_num, int xlate_pal=1);
247 ubyte *anim_get_next_raw_buffer(anim_instance *inst, int xlate_pal, int aabitmap, int bpp);
248 void anim_set_palette(anim *a);
249 void anim_check_for_palette_change(anim_instance *inst);
252 #endif /* __PACKUNPACK_H__ */