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.cpp $
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:15 relnev
21 * added copyright header
23 * Revision 1.1.1.1 2002/05/03 03:28:08 root
27 * 12 7/30/99 10:10p Dave
28 * Fixed loading bar in 32 bit mode.
30 * 11 7/18/99 1:59p Johnson
31 * Fixed potential anim locking problem.
33 * 10 7/16/99 1:49p Dave
34 * 8 bit aabitmaps. yay.
36 * 9 7/13/99 1:15p Dave
37 * 32 bit support. Whee!
39 * 8 4/09/99 2:21p Dave
40 * Multiplayer beta stuff. CD checking.
42 * 7 1/14/99 12:48a Dave
43 * Todo list bug fixes. Made a pass at putting briefing icons back into
44 * FRED. Sort of works :(
46 * 6 12/01/98 5:53p Dave
47 * Simplified the way pixel data is swizzled. Fixed tga bitmaps to work
48 * properly in D3D and Glide.
50 * 5 12/01/98 8:06a Dave
51 * Temporary checkin to fix some texture transparency problems in d3d.
53 * 4 11/30/98 1:07p Dave
54 * 16 bit conversion, first run.
56 * 3 10/22/98 6:14p Dave
57 * Optimized some #includes in Anim folder. Put in the beginnings of
58 * parse/localization support for externalized strings and tstrings.tbl
60 * 2 10/07/98 10:52a Dave
63 * 1 10/07/98 10:48a Dave
65 * 30 5/14/98 3:38p John
66 * Added in more non-darkening colors for Adam. Had to fix some bugs in
67 * BmpMan and Ani stuff to get this to work.
69 * 29 5/07/98 3:11a Lawrance
70 * Implement custom streaming code
72 * 28 11/19/97 8:28p Dave
73 * Hooked in Main Hall screen. Put in Anim support for ping ponging
74 * animations as well as general reversal of anim direction.
76 * 27 9/09/97 3:39p Sandeep
77 * warning level 4 bugs
79 * 26 8/22/97 8:21a Lawrance
80 * short circuit key frame check if keyframe matches frame we are
83 * 25 8/21/97 5:11p Lawrance
84 * frame numbering for ANI's now is from 0 -> total_frames-1.
86 * 24 8/19/97 10:59a Lawrance
87 * fix problem with accessing key frames
89 * 23 7/28/97 10:42p Lawrance
90 * re-did interface to unpack_frame() to make more general
92 * 22 7/28/97 10:52a Lawrance
93 * correctly set bitmap flags in anim_get_frame()
95 * 21 7/21/97 5:10p Lawrance
96 * fix problem that was causing infinite recursion
98 * 20 7/20/97 6:57p Lawrance
99 * supporting new RLE format
101 * 19 6/27/97 4:36p Lawrance
102 * update pal translation table when gr_screen.signature changes
104 * 18 6/26/97 12:12a Lawrance
105 * supporting anti-aliased bitmap animations
107 * 17 6/25/97 3:03p Lawrance
108 * fix palette translation problem with anti-alised bitmaps
110 * 16 5/19/97 2:28p Lawrance
111 * changes some variables to flags
113 * 15 5/15/97 4:42p Lawrance
114 * supporting animations in-game
116 * 14 2/25/97 11:06a Lawrance
117 * moved some higher level functions to from PackUnpack to AnimPlay
119 * 13 2/19/97 9:51p Lawrance
120 * made keyframe decompression more effecient, moved
121 * default anim FPS to header file
123 * 12 2/19/97 4:00p Lawrance
124 * don't assert when cannot find anim filename, return a NULL instead
126 * 11 2/17/97 4:17p Hoffoss
127 * modified packing internal format and added random access function to an
130 * 10 2/17/97 2:59p Lawrance
131 * integrating into game
133 * 9 2/14/97 11:27p Lawrance
134 * optimized unpacking some more (Jason)
136 * 8 2/14/97 11:09p Hoffoss
137 * Made optimizations.
139 * 7 2/14/97 10:48p Hoffoss
142 * 6 2/14/97 10:38p Lawrance
145 * 5 2/14/97 5:38p Hoffoss
146 * Changes to get AnimCoverter project to compile and link.
148 * 4 2/14/97 3:29p Hoffoss
149 * Added header for MSDEV to fill in.
154 #include "grinternal.h"
158 #include "animplay.h"
159 #include "packunpack.h"
161 int packer_code = PACKER_CODE;
162 int transparent_code = 254;
164 void anim_check_for_palette_change(anim_instance *instance) {
165 if ( instance->parent->screen_sig != gr_screen.signature ) {
166 instance->parent->screen_sig = gr_screen.signature;
167 anim_set_palette(instance->parent);
171 anim_instance *init_anim_instance(anim *ptr, int bpp)
180 if ( ptr->flags & ANF_STREAMED ) {
181 if ( ptr->file_offset < 0 ) {
192 ptr->instance_count++;
193 inst = (anim_instance *) malloc(sizeof(anim_instance));
195 inst->frame_num = -1;
196 inst->last_frame_num = -1;
198 inst->data = ptr->data;
199 inst->file_offset = ptr->file_offset;
200 inst->stop_now = FALSE;
201 inst->aa_color = NULL;
204 inst->frame = (ubyte *) malloc(inst->parent->width * inst->parent->height * 2);
206 inst->frame = (ubyte *) malloc(inst->parent->width * inst->parent->height);
211 void free_anim_instance(anim_instance *inst)
213 SDL_assert(inst->frame);
216 inst->parent->instance_count--;
219 inst->file_offset = -1;
224 int anim_get_next_frame(anim_instance *inst)
226 int bm, bitmap_flags;
230 if ( anim_instance_is_streamed(inst) ) {
231 if ( inst->file_offset <= 0 ) {
240 if (inst->frame_num >= inst->parent->total_frames) {
242 inst->file_offset = inst->parent->file_offset;
246 if (inst->parent->flags & ANF_XPARENT) {
247 // bitmap_flags = BMP_XPARENT;
254 if(inst->aa_color != NULL){
255 bitmap_flags |= BMP_AABITMAP;
260 anim_check_for_palette_change(inst);
262 // if we're using bitmap polys
264 BM_SELECT_TEX_FORMAT();
267 if ( anim_instance_is_streamed(inst) ) {
268 inst->file_offset = unpack_frame_from_file(inst, inst->frame, inst->parent->width*inst->parent->height, inst->parent->palette_translation, aabitmap, bpp);
270 inst->data = unpack_frame(inst, inst->data, inst->frame, inst->parent->width*inst->parent->height, inst->parent->palette_translation, aabitmap, bpp);
273 bm = bm_create(bpp, inst->parent->width, inst->parent->height, inst->frame, bitmap_flags);
278 ubyte *anim_get_next_raw_buffer(anim_instance *inst, int xlate_pal, int aabitmap, int bpp)
280 if ( anim_instance_is_streamed(inst) ) {
281 if ( inst->file_offset < 0 ) {
291 if (inst->frame_num >= inst->parent->total_frames) {
293 inst->file_offset = inst->parent->file_offset;
297 anim_check_for_palette_change(inst);
299 if ( anim_instance_is_streamed(inst) ) {
301 inst->file_offset = unpack_frame_from_file(inst, inst->frame, inst->parent->width*inst->parent->height, inst->parent->palette_translation, aabitmap, bpp);
303 inst->file_offset = unpack_frame_from_file(inst, inst->frame, inst->parent->width*inst->parent->height, NULL, aabitmap, bpp);
307 inst->data = unpack_frame(inst, inst->data, inst->frame, inst->parent->width*inst->parent->height, inst->parent->palette_translation, aabitmap, bpp);
309 inst->data = unpack_frame(inst, inst->data, inst->frame, inst->parent->width*inst->parent->height, NULL, aabitmap, bpp);
316 // --------------------------------------------------------------------
319 // Get a bitmap id from the anim_instance for the specified frame_num
321 // input: *inst => pointer to anim instance
322 // frame_num => frame number to get (first frame is 0)
323 // xlate_pal => DEFAULT PARM (value 1): whether to translate the palette
324 // to the current game palette
326 int anim_get_frame(anim_instance *inst, int frame_num, int xlate_pal)
329 int bm, bitmap_flags, key = 0, offset = 0;
332 if ((frame_num < 0) || (frame_num >= inst->parent->total_frames)) // illegal frame number
336 if ( anim_instance_is_streamed(inst) ) {
337 if ( inst->file_offset < 0 ) {
346 if (need_reset || (inst->frame_num >= inst->parent->total_frames)) { // reset to valid info
347 inst->data = inst->parent->data;
348 inst->file_offset = inst->parent->file_offset;
353 if (inst->parent->flags & ANF_XPARENT) {
354 // bitmap_flags = BMP_XPARENT;
358 if ( inst->frame_num == frame_num ) {
359 bm = bm_create(16, inst->parent->width, inst->parent->height, inst->frame, bitmap_flags);
364 if (inst->parent->flags & ANF_XPARENT){
365 // bitmap_flags = BMP_XPARENT;
373 while(idx < inst->parent->num_keys){
374 if (( (inst->parent->keys[idx].frame_num-1) <= frame_num) && ( (inst->parent->keys[idx].frame_num-1) > key)) { // find closest key
375 key = inst->parent->keys[idx].frame_num - 1;
376 offset = inst->parent->keys[idx].offset;
378 if ( key == frame_num )
384 if ( key == frame_num ) {
385 inst->frame_num = key;
387 if ( anim_instance_is_streamed(inst) ) {
388 inst->file_offset = inst->parent->file_offset + offset;
390 inst->data = inst->parent->data + offset;
393 anim_check_for_palette_change(inst);
395 if ( anim_instance_is_streamed(inst) ) {
397 inst->file_offset = unpack_frame_from_file(inst, inst->frame, inst->parent->width*inst->parent->height, inst->parent->palette_translation);
399 inst->file_offset = unpack_frame_from_file(inst, inst->frame, inst->parent->width*inst->parent->height, NULL);
403 inst->data = unpack_frame(inst, inst->data, inst->frame, inst->parent->width*inst->parent->height, inst->parent->palette_translation);
405 inst->data = unpack_frame(inst, inst->data, inst->frame, inst->parent->width*inst->parent->height, NULL);
412 if (key > inst->frame_num) // best key is closer than current position
414 inst->frame_num = key;
416 if ( anim_instance_is_streamed(inst) ) {
417 inst->file_offset = inst->parent->file_offset + offset;
419 inst->data = inst->parent->data + offset;
422 anim_check_for_palette_change(inst);
424 if ( anim_instance_is_streamed(inst) ) {
426 inst->file_offset = unpack_frame_from_file(inst, inst->frame, inst->parent->width*inst->parent->height, inst->parent->palette_translation);
428 inst->file_offset = unpack_frame_from_file(inst, inst->frame, inst->parent->width*inst->parent->height, NULL);
431 inst->data = unpack_frame(inst, inst->data, inst->frame, inst->parent->width*inst->parent->height, inst->parent->palette_translation);
433 inst->data = unpack_frame(inst, inst->data, inst->frame, inst->parent->width*inst->parent->height, NULL);
437 while (inst->frame_num != frame_num) {
438 anim_check_for_palette_change(inst);
440 if ( anim_instance_is_streamed(inst) ) {
442 inst->file_offset = unpack_frame_from_file(inst, inst->frame, inst->parent->width*inst->parent->height, inst->parent->palette_translation);
444 inst->file_offset = unpack_frame_from_file(inst, inst->frame, inst->parent->width*inst->parent->height, NULL);
447 inst->data = unpack_frame(inst, inst->data, inst->frame, inst->parent->width*inst->parent->height, inst->parent->palette_translation);
449 inst->data = unpack_frame(inst, inst->data, inst->frame, inst->parent->width*inst->parent->height, NULL);
456 bm = bm_create(16, inst->parent->width, inst->parent->height, inst->frame, bitmap_flags);
464 // frame = frame pixel data to pack
465 // save = memory to store packed data to
466 // size = number of bytes to pack
467 // max = maximum number of packed bytes (size of buffer)
468 // returns: actual number of bytes data packed to or -1 if error
469 int pack_key_frame(ubyte *frame, ubyte *save, long size, long max, int compress_type)
471 int last = -32768, count = 0;
472 long packed_size = 1;
474 switch ( compress_type ) {
475 case PACKING_METHOD_RLE_KEY:
476 *save++ = PACKING_METHOD_RLE_KEY;
478 if (*frame != last || count > 255) {
479 if (packed_size + 3 >= max)
483 if (last == packer_code) {
484 *save++ = (ubyte)packer_code;
485 *save++ = (ubyte)(count - 1);
490 *save++ = (ubyte)last;
495 *save++ = (ubyte)packer_code;
496 *save++ = (ubyte)(count - 1);
497 *save++ = (ubyte)last;
509 if (packed_size + 3 >= max)
513 if (last == packer_code) {
514 *save++ = (ubyte)packer_code;
515 *save++ = (ubyte)(count - 1);
520 *save++ = (ubyte)last;
525 *save++ = (ubyte)packer_code;
526 *save++ = (ubyte)(count - 1);
527 *save++ = (ubyte)last;
532 case PACKING_METHOD_STD_RLE_KEY: {
540 *save++ = PACKING_METHOD_STD_RLE_KEY;
541 for (i=1; i < size; i++ ) {
543 if ( *frame != last ) {
546 if (packed_size + 2 >= max)
549 if ( (count == 1) && !(last & STD_RLE_CODE) ) {
550 *save++ = (ubyte)last;
552 SDL_assert( last != STD_RLE_CODE );
553 // printf("Just packed %d 1 times, since pixel change, no count included\n",last);
556 count |= STD_RLE_CODE;
557 *save++ = (ubyte)count;
558 *save++ = (ubyte)last;
560 // printf("Just packed %d %d times, since pixel change\n",last,count);
571 if ( count == 127 ) {
572 count |= STD_RLE_CODE;
573 *save++ = (ubyte)count;
574 *save++ = (ubyte)last;
577 // printf("Just packed %d %d times, since count overflow\n",last,count);
584 if (packed_size + 2 >= max)
587 if ( (count == 1) && !(last & STD_RLE_CODE) ) {
588 *save++ = (ubyte)last;
590 // printf("Just packed %d 1 times, at end since single pixel, no count\n",last);
591 SDL_assert( last != STD_RLE_CODE );
594 count |= STD_RLE_CODE;
595 *save++ = (ubyte)count;
596 *save++ = (ubyte)last;
598 // printf("Just packed %d %d times, at end since pixel change\n",last,count);
602 SDL_assert(packed_size == (save-dest_start) );
616 // frame = frame pixel data to pack
617 // frame2 = previous frame's pixel data
618 // save = memory to store packed data to
619 // size = number of bytes to pack
620 // max = maximum number of packed bytes (size of buffer)
621 // returns: actual number of bytes data packed to or -1 if error
622 int pack_frame(ubyte *frame, ubyte *frame2, ubyte *save, long size, long max, int compress_type)
624 int pixel, last = -32768, count = 0, i;
625 long packed_size = 1;
627 switch ( compress_type ) {
628 case PACKING_METHOD_RLE: // Hoffoss RLE regular frame
629 *save++ = PACKING_METHOD_RLE;
631 if (*frame != *frame2++)
634 pixel = transparent_code;
636 if (pixel != last || count > 255) {
637 if (packed_size + 3 >= max)
641 if (last == packer_code) {
642 *save++ = (ubyte)packer_code;
643 *save++ = (ubyte)(count - 1);
648 *save++ = (ubyte)last;
653 *save++ = (ubyte)packer_code;
654 *save++ = (ubyte)(count - 1);
655 *save++ = (ubyte)last;
667 if (packed_size + 3 >= max)
671 if (last == packer_code) {
672 *save++ = (ubyte)packer_code;
673 *save++ = (ubyte)(count - 1);
678 *save++ = (ubyte)last;
683 *save++ = (ubyte)(packer_code);
684 *save++ = (ubyte)(count - 1);
685 *save++ = (ubyte)(last);
690 case PACKING_METHOD_STD_RLE: { // high bit count regular RLE frame
697 if (*frame++ != *frame2++)
700 last = transparent_code;
702 *save++ = PACKING_METHOD_STD_RLE;
703 for (i=1; i < size; i++ ) {
705 if (*frame != *frame2++)
708 pixel = transparent_code;
710 if ( pixel != last ) {
713 if (packed_size + 2 >= max)
716 if ( (count == 1) && !(last & STD_RLE_CODE) ) {
717 *save++ = (ubyte)last;
719 SDL_assert( last != STD_RLE_CODE );
722 count |= STD_RLE_CODE;
723 *save++ = (ubyte)count;
724 *save++ = (ubyte)last;
736 if ( count == 127 ) {
737 count |= STD_RLE_CODE;
738 *save++ = (ubyte)count;
739 *save++ = (ubyte)last;
747 if (packed_size + 2 >= max)
750 if ( (count == 1) && !(last & STD_RLE_CODE) ) {
751 *save++ = (ubyte)last;
753 SDL_assert( last != STD_RLE_CODE );
756 count |= STD_RLE_CODE;
757 *save++ = (ubyte)count;
758 *save++ = (ubyte)last;
763 SDL_assert(packed_size == (save-dest_start) );
777 // unpack a pixel given the passed index and the anim_instance's palette, return bytes stuffed
778 int unpack_pixel(anim_instance *ai, ubyte *data, ubyte pix, int aabitmap, int bpp)
785 anim *a = ai->parent;
788 // if this is an aabitmap, don't run through the palette
792 bit_16 = (ushort)pix;
801 // if the pixel value is 255, or is the xparent color, make it so
802 if(((a->palette[pix*3] == a->xparent_r) && (a->palette[pix*3+1] == a->xparent_g) && (a->palette[pix*3+2] == a->xparent_b)) ){
805 bm_set_components((ubyte*)&bit_16, &r, &g, &b, &al);
807 // stuff the 24 bit value
808 memcpy(&bit_24, &ai->parent->palette[pix * 3], 3);
811 bm_24_to_16(bit_24, &bit_16);
818 memcpy(data, &bit_16, sizeof(ushort));
819 return sizeof(ushort);
823 return sizeof(ubyte);
830 // unpack a pixel given the passed index and the anim_instance's palette, return bytes stuffed
831 int unpack_pixel_count(anim_instance *ai, ubyte *data, ubyte pix, int count, int aabitmap, int bpp)
838 anim *a = ai->parent;
842 // if this is an aabitmap, don't run through the palette
846 bit_16 = (ushort)pix;
855 // if the pixel value is 255, or is the xparent color, make it so
856 if(((a->palette[pix*3] == a->xparent_r) && (a->palette[pix*3+1] == a->xparent_g) && (a->palette[pix*3+2] == a->xparent_b)) ){
859 bm_set_components((ubyte*)&bit_16, &r, &g, &b, &al);
861 // stuff the 24 bit value
862 memcpy(&bit_24, &ai->parent->palette[pix * 3], 3);
865 bm_24_to_16(bit_24, &bit_16);
870 for(idx=0; idx<count; idx++){
873 memcpy(data + (idx*2), &bit_16, sizeof(ushort));
876 *(data + idx) = bit_8;
882 return sizeof(ushort) * count;
884 return sizeof(ubyte) * count;
887 // ptr = packed data to unpack
888 // frame = where to store unpacked data to
889 // size = total number of unpacked pixels requested
890 // pal_translate = color translation lookup table (NULL if no palette translation desired)
891 ubyte *unpack_frame(anim_instance *ai, ubyte *ptr, ubyte *frame, int size, ubyte *pal_translate, int aabitmap, int bpp)
893 int xlate_pal, value, count = 0;
895 int pixel_size = (bpp == 16) ? 2 : 1;
897 if ( pal_translate == NULL ) {
904 if (*ptr == PACKING_METHOD_RLE_KEY) { // key frame, Hoffoss's RLE format
908 if (value != packer_code) {
910 stuffed = unpack_pixel(ai, frame, pal_translate[value], aabitmap, bpp);
912 stuffed = unpack_pixel(ai, frame, (ubyte)value, aabitmap, bpp);
929 stuffed = unpack_pixel_count(ai, frame, pal_translate[value], count, aabitmap, bpp);
931 stuffed = unpack_pixel_count(ai, frame, (ubyte)value, count, aabitmap, bpp);
939 else if ( *ptr == PACKING_METHOD_STD_RLE_KEY) { // key frame, with high bit as count
943 if ( !(value & STD_RLE_CODE) ) {
945 stuffed = unpack_pixel(ai, frame, pal_translate[value], aabitmap, bpp);
947 stuffed = unpack_pixel(ai, frame, (ubyte)value, aabitmap, bpp);
953 count = value & (~STD_RLE_CODE);
957 SDL_assert(size >= 0);
960 stuffed = unpack_pixel_count(ai, frame, pal_translate[value], count, aabitmap, bpp);
962 stuffed = unpack_pixel_count(ai, frame, (ubyte)value, count, aabitmap, bpp);
969 else if (*ptr == PACKING_METHOD_RLE) { // normal frame, Hoffoss's RLE format
971 // test code, to show unused pixels
972 // memset(frame, 255, size);
977 if (value != packer_code) {
978 if (value != transparent_code) {
980 stuffed = unpack_pixel(ai, frame, pal_translate[value], aabitmap, bpp);
982 stuffed = unpack_pixel(ai, frame, (ubyte)value, aabitmap, bpp);
986 stuffed = pixel_size;
1004 SDL_assert(size >= 0);
1006 if (value != transparent_code ) {
1008 stuffed = unpack_pixel_count(ai, frame, pal_translate[value], count, aabitmap, bpp);
1010 stuffed = unpack_pixel_count(ai, frame, (ubyte)value, count, aabitmap, bpp);
1013 stuffed = count * pixel_size;
1021 else if ( *ptr == PACKING_METHOD_STD_RLE) { // normal frame, with high bit as count
1025 if ( !(value & STD_RLE_CODE) ) {
1026 if (value != transparent_code) {
1028 stuffed = unpack_pixel(ai, frame, pal_translate[value], aabitmap, bpp);
1030 stuffed = unpack_pixel(ai, frame, (ubyte)value, aabitmap, bpp);
1033 stuffed = pixel_size;
1039 count = value & (~STD_RLE_CODE);
1043 SDL_assert(size >= 0);
1045 if (value != transparent_code) {
1047 stuffed = unpack_pixel_count(ai, frame, pal_translate[value], count, aabitmap, bpp);
1049 stuffed = unpack_pixel_count(ai, frame, (ubyte)value, count, aabitmap, bpp);
1052 stuffed = pixel_size * count;
1060 SDL_assert(0); // unknown packing method
1066 // ptr = packed data to unpack
1067 // frame = where to store unpacked data to
1068 // size = total number of unpacked pixels requested
1069 // pal_translate = color translation lookup table (NULL if no palette translation desired)
1070 int unpack_frame_from_file(anim_instance *ai, ubyte *frame, int size, ubyte *pal_translate, int aabitmap, int bpp)
1072 int xlate_pal, value, count = 0;
1075 int pixel_size = (bpp == 16) ? 2 : 1;
1077 if ( pal_translate == NULL ) {
1084 if (anim_instance_get_byte(ai,offset) == PACKING_METHOD_RLE_KEY) { // key frame, Hoffoss's RLE format
1087 value = anim_instance_get_byte(ai,offset);
1089 if (value != packer_code) {
1091 stuffed = unpack_pixel(ai, frame, pal_translate[value], aabitmap, bpp);
1093 stuffed = unpack_pixel(ai, frame, (ubyte)value, aabitmap, bpp);
1099 count = anim_instance_get_byte(ai,offset);
1102 value = packer_code;
1104 value = anim_instance_get_byte(ai,offset);
1108 if (++count > size){
1113 stuffed = unpack_pixel_count(ai, frame, pal_translate[value], count, aabitmap, bpp);
1115 stuffed = unpack_pixel_count(ai, frame, (ubyte)value, count, aabitmap, bpp);
1123 else if ( anim_instance_get_byte(ai,offset) == PACKING_METHOD_STD_RLE_KEY) { // key frame, with high bit as count
1126 value = anim_instance_get_byte(ai,offset);
1128 if ( !(value & STD_RLE_CODE) ) {
1130 stuffed = unpack_pixel(ai, frame, pal_translate[value], aabitmap, bpp);
1132 stuffed = unpack_pixel(ai, frame, (ubyte)value, aabitmap, bpp);
1138 count = value & (~STD_RLE_CODE);
1139 value = anim_instance_get_byte(ai,offset);
1143 SDL_assert(size >= 0);
1146 stuffed = unpack_pixel_count(ai, frame, pal_translate[value], count, aabitmap, bpp);
1148 stuffed = unpack_pixel_count(ai, frame, (ubyte)value, count, aabitmap, bpp);
1155 else if (anim_instance_get_byte(ai,offset) == PACKING_METHOD_RLE) { // normal frame, Hoffoss's RLE format
1157 // test code, to show unused pixels
1158 // memset(frame, 255, size);
1162 value = anim_instance_get_byte(ai,offset);
1164 if (value != packer_code) {
1165 if (value != transparent_code) {
1167 stuffed = unpack_pixel(ai, frame, pal_translate[value], aabitmap, bpp);
1169 stuffed = unpack_pixel(ai, frame, (ubyte)value, aabitmap, bpp);
1172 stuffed = pixel_size;
1178 count = anim_instance_get_byte(ai,offset);
1182 value = packer_code;
1184 value = anim_instance_get_byte(ai,offset);
1187 if (++count > size){
1192 SDL_assert(size >= 0);
1194 if (value != transparent_code ) {
1196 stuffed = unpack_pixel_count(ai, frame, pal_translate[value], count, aabitmap, bpp);
1198 stuffed = unpack_pixel_count(ai, frame, (ubyte)value, count, aabitmap, bpp);
1201 stuffed = pixel_size * count;
1209 else if ( anim_instance_get_byte(ai,offset) ) { // normal frame, with high bit as count
1212 value = anim_instance_get_byte(ai,offset);
1214 if ( !(value & STD_RLE_CODE) ) {
1215 if (value != transparent_code) {
1217 stuffed = unpack_pixel(ai, frame, pal_translate[value], aabitmap, bpp);
1219 stuffed = unpack_pixel(ai, frame, (ubyte)value, aabitmap, bpp);
1222 stuffed = pixel_size;
1228 count = value & (~STD_RLE_CODE);
1229 value = anim_instance_get_byte(ai,offset);
1233 SDL_assert(size >= 0);
1235 if (value != transparent_code) {
1237 stuffed = unpack_pixel_count(ai, frame, pal_translate[value], count, aabitmap, bpp);
1239 stuffed = unpack_pixel_count(ai, frame, (ubyte)value, count, aabitmap, bpp);
1242 stuffed = pixel_size * count;
1250 Int3(); // unknown packing method
1253 return ai->file_offset + offset;
1257 // TODO: actually convert the frame data to correct palette at this point
1258 void anim_set_palette(anim *ptr)
1260 int i, xparent_found = 0;
1262 // create the palette translation look-up table
1263 for ( i = 0; i < 256; i++ ) {
1265 //if ( (ptr->palette[i*3] == ptr->xparent_r) && (ptr->palette[i*3+1] == ptr->xparent_g) && (ptr->palette[i*3+2] == ptr->xparent_b) ) {
1266 // ptr->palette_translation[i] = 255;
1267 // xparent_found = 1;
1269 // ptr->palette_translation[i] = (ubyte)palette_find( ptr->palette[i*3], ptr->palette[i*3+1], ptr->palette[i*3+2] );
1270 ptr->palette_translation[i] = (ubyte)i;
1274 if ( xparent_found ) {
1275 ptr->flags |= ANF_XPARENT;
1278 ptr->flags &= ~ANF_XPARENT;