1 
2 /*
3  * xa_act.c
4  *
5  * Copyright (C) 1990-1998,1999 by Mark Podlipec.
6  * All rights reserved.
7  *
8  * This software may be freely used, copied and redistributed without
9  * fee for non-commerical purposes provided that this copyright
10  * notice is preserved intact on all copies.
11  *
12  * There is no warranty or other guarantee of fitness of this software.
13  * It is provided solely "as is". The author disclaims all
14  * responsibility and liability with respect to this software's usage
15  * or its effect upon hardware or computer systems.
16  *
17  * 17Mar98:  Fixed bug in Make_Images with some types of Clips and TrueColor
18  *	     clip_mask would get mapped to common color. Need to generate
19  *	     clip masks prior to mapping.
20  */
21 #include "xanim.h"
22 #include <Intrinsic.h>
23 #include <StringDefs.h>
24 #include <Shell.h>
25 #include <sys/signal.h>
26 #ifndef VMS
27 #include <sys/times.h>
28 #endif
29 #include <ctype.h>
30 
31 #ifdef XSHM
32 #include <sys/ipc.h>
33 #include <sys/shm.h>
34 #include <X11/extensions/XShm.h>
35 #endif /*XSHM*/
36 
37 #include "xa_x11.h"
38 extern xaULONG shm;
39 extern Visual     *theVisual;
40 
41 extern xaLONG xa_pixmap_flag;
42 extern xaUSHORT xa_gamma_adj[];
43 
44 XA_ACTION *ACT_Get_Action();
45 void ACT_Setup_Mapped();
46 void ACT_Setup_Packed();
47 void ACT_Setup_Loop();
48 void ACT_Make_Images();
49 void ACT_Add_CHDR_To_Action();
50 void ACT_Del_CHDR_From_Action();
51 void ACT_Get_CCMAP();
52 XA_CHDR *ACT_Get_CMAP();
53 void ACT_Free_Act();
54 void ACT_Setup_Delta();
55 
56 void UTIL_Mapped_To_Bitmap();
57 void UTIL_Mapped_To_Mapped();
58 void UTIL_Mapped_To_Floyd();
59 void UTIL_Pack_Image();
60 xaUBYTE *UTIL_Alloc_Scaled();
61 xaUBYTE *UTIL_Scale_Mapped();
62 xaUBYTE *UTIL_Scale_Bitmap();
63 xaULONG UTIL_Get_Buffer_Scale();
64 void UTIL_Create_Clip();
65 void UTIL_Sub_Image();
66 xaUBYTE *UTIL_RGB_To_FS_Map();
67 xaUBYTE *UTIL_RGB_To_Map();
68 
69 extern xaULONG XA_Get_Image_Type();
70 
71 XA_CHDR *CMAP_Create_CHDR_From_True();
72 XA_CHDR *CMAP_Create_332();
73 XA_CHDR *CMAP_Create_Gray();
74 
75 XA_ACTION *act_first_cmap = 0;
76 XA_ACTION *act_cur_cmap = 0;
77 
78 
79 /*
80  * Allocate, Add to Anim_Hdr and Return an Action.
81  */
ACT_Get_Action(anim_hdr,type)82 XA_ACTION *ACT_Get_Action(anim_hdr,type)
83 XA_ANIM_HDR *anim_hdr;
84 xaLONG type;
85 {
86   XA_ACTION *act;
87 
88   act = (XA_ACTION *)malloc(sizeof(XA_ACTION));
89   if (act == 0) TheEnd1("ACT_Get_Action: malloc err\n");
90 
91   act->type = type;
92   act->cmap_rev = 0;
93   act->data = 0;
94   act->chdr = 0;
95   act->h_cmap = 0;
96   act->map = 0;
97   act->next_same_chdr = 0;
98 
99   act->next = anim_hdr->acts;  /* insert at front of list */
100   anim_hdr->acts = act;
101   return(act);
102 }
103 
104 /*
105  *
106  */
107 void
ACT_Setup_Mapped(act,ipic,chdr,xpos,ypos,xsize,ysize,width,height,clip_flag,clip_mask,free_ipic_flag,full_ipic_flag,already_disp_flag)108 ACT_Setup_Mapped(act,ipic,chdr,xpos,ypos,xsize,ysize,width,height,
109 		clip_flag,clip_mask,
110 		free_ipic_flag,full_ipic_flag,already_disp_flag)
111 XA_ACTION *act;
112 xaUBYTE *ipic;
113 XA_CHDR *chdr;
114 xaLONG xpos,ypos,xsize,ysize;	/* image/sub-image dimensions */
115 xaLONG width,height;		/* screen dimensions */
116 xaULONG clip_flag;		/* if xaTRUE then create clip with clip_mask */
117 xaULONG clip_mask;		/* transparent pixel value of clip  */
118 xaULONG free_ipic_flag;		/* free ipic before returning */
119 xaULONG full_ipic_flag;		/* full screen given, not just image */
120 xaULONG already_disp_flag;	/* ipic already in display form */
121 {
122   xaULONG line_size,buff_x,buff_y,need_to_scale;
123   xaULONG in_x_size,in_y_size,inline_size,inpix_size,resize_flag;
124   xaLONG map_size;
125   xaUBYTE *t_pic,*clip_ptr;
126   ACT_MAPPED_HDR *act_map_hdr;
127 
128 	/* Figure out buffer scaling */
129   need_to_scale = UTIL_Get_Buffer_Scale(width,height,&buff_x,&buff_y);
130 
131 	/* get correct input buffer size */
132   inpix_size = (already_disp_flag==xaTRUE)?x11_bytes_pixel:1;
133   in_x_size = (full_ipic_flag==xaTRUE)?width:xsize;
134   in_y_size = (full_ipic_flag==xaTRUE)?height:ysize;
135   inline_size = in_x_size * inpix_size;
136   if ( (full_ipic_flag == xaTRUE) && ((xsize != width) || (ysize != height)) )
137 	resize_flag = xaTRUE;
138   else  resize_flag = xaFALSE;
139 
140   DEBUG_LEVEL2 fprintf(stderr,"Setup_Mapped:\n");
141   DEBUG_LEVEL2 fprintf(stderr,"  <%d,%d> <%d,%d>\n",
142                 xpos,  ypos, xsize, ysize  );
143 
144   t_pic = clip_ptr = 0;
145   act_map_hdr = (ACT_MAPPED_HDR *) malloc( sizeof(ACT_MAPPED_HDR) );
146   if (act_map_hdr == 0) TheEnd1("ACT_Setup_Mapped: malloc err\n");
147 
148   map_size = (chdr)?(chdr->csize): 0 ;
149   line_size = X11_Get_Line_Size(xsize);
150 
151 /*******
152  * t_pic should hold image data
153  * i_pic should be left unchanged
154  * xpos,ypos,xsize,ysize can change and should be correct at break;
155  */
156   switch (x11_display_type)
157   {
158     case XA_MONOCHROME:
159           /* POD NOTE: Currently assumes ipic always get converted */
160 	if (need_to_scale == xaTRUE)
161         {
162 	  xaULONG xpos_o,ypos_o,xsize_o,ysize_o;
163 
164 	  xpos_o = xpos; ypos_o = ypos;
165 	  if (full_ipic_flag == xaFALSE) xpos = ypos = 0;
166 	  t_pic = UTIL_Alloc_Scaled(xsize,ysize,width,height,
167 		  buff_x,buff_y,1,xpos_o,ypos_o,xaTRUE);
168 	  if (t_pic)
169 	  {
170 	    xaUBYTE *p_pic;
171 	    p_pic = UTIL_Alloc_Scaled(xsize,ysize,width,height,
172 		  buff_x,buff_y,1,xpos_o,ypos_o,xaFALSE);
173 	    UTIL_Scale_Mapped(p_pic,ipic,xpos,ypos,xsize,ysize,
174 			inline_size,width,height,buff_x,buff_y,
175 			inpix_size,&xpos_o,&ypos_o,&xsize_o,&ysize_o,0);
176             xpos = xpos_o; ypos = ypos_o; xsize = xsize_o; ysize = ysize_o;
177 	    UTIL_Mapped_To_Bitmap(t_pic,p_pic,chdr, xpos,ypos,
178 			xsize,ysize,buff_x,buff_y, X11_Get_Line_Size(xsize));
179 	    act->type = ACT_DISP; act_map_hdr->psize = 0;
180 	    if (clip_flag == xaTRUE)
181 	    {
182 	      clip_ptr = (xaUBYTE *)
183 			malloc(ysize * (X11_Get_Bitmap_Width(xsize)/8) );
184 	      if (clip_ptr==0) TheEnd1("Setup_Mapped: clip malloc err\n");
185 	      UTIL_Create_Clip(clip_ptr,p_pic,clip_mask,xsize,ysize,
186 			inpix_size,X11_Get_Bitmap_Width(xsize),XA_LSBIT_1ST);
187 	    }
188 	    if (p_pic) { FREE(p_pic,0x106); p_pic = 0; }
189           }
190 	  else /* scale to zero size */
191 	  {
192 	    act->type = ACT_NOP;	clip_flag = xaFALSE;
193 	    FREE(act_map_hdr,0x107);	act_map_hdr = 0;
194 	  }
195         } /* end of need to scale */
196 	else
197 	{
198 	  t_pic = (xaUBYTE *) malloc(ysize * line_size);
199 	  if (t_pic == 0) TheEnd1("X11_Get_Image: t_pic malloc failed.\n");
200 	  UTIL_Mapped_To_Bitmap(t_pic,ipic,chdr,
201 			xpos,ypos,xsize,ysize,in_x_size,in_y_size,line_size);
202 	  if (clip_flag == xaTRUE)
203 	  {
204 	    clip_ptr = (xaUBYTE *)
205 			malloc(ysize * (X11_Get_Bitmap_Width(xsize)/8) );
206 	    if (clip_ptr==0) TheEnd1("Setup_Mapped: clip malloc err\n");
207 	    UTIL_Create_Clip(clip_ptr,ipic,clip_mask,xsize,ysize,
208 			inpix_size,X11_Get_Bitmap_Width(xsize),XA_LSBIT_1ST);
209           }
210 	  act->type = ACT_DISP; act_map_hdr->psize = 0;
211 	}
212 	break;
213     case XA_DIRECTCOLOR:
214     case XA_TRUECOLOR:
215         inpix_size = x11_bytes_pixel;
216 
217 
218 	/* Create Bitmap based on Original GIF Image */
219   if ( (clip_ptr==0) && (clip_flag==xaTRUE) )
220   {
221     clip_ptr = (xaUBYTE *) malloc(ysize * (X11_Get_Bitmap_Width(xsize)/8) );
222     if (clip_ptr==0) TheEnd1("Setup_Mapped: clip malloc err\n");
223     UTIL_Create_Clip(clip_ptr,ipic,clip_mask,xsize,ysize,
224 			1,X11_Get_Bitmap_Width(xsize),XA_LSBIT_1ST);
225   }
226 
227 	if (need_to_scale == xaTRUE)
228         {
229 	  xaULONG xpos_o,ypos_o,xsize_o,ysize_o;
230 
231 	  xpos_o = xpos; ypos_o = ypos;
232 	  if (full_ipic_flag == xaFALSE) xpos = ypos = 0;
233 	  t_pic = UTIL_Alloc_Scaled(xsize,ysize,width,height,
234 			buff_x,buff_y,x11_bytes_pixel,xpos_o,ypos_o,xaFALSE);
235 	  if (t_pic)
236 	  {
237 
238 	    if ((clip_ptr) && (clip_flag==xaTRUE))
239 	    { xaULONG cxpos, cypos, cxsize, cysize;
240 	      xaUBYTE *new_clip = UTIL_Scale_Bitmap(0,clip_ptr,
241 			xsize,ysize,(X11_Get_Bitmap_Width(xsize/8)),
242 			width, height,
243 			buff_x, buff_y,
244 			&cxpos, &cypos, &cxsize, &cysize,
245 			XA_LSBIT_1ST, XA_LSBIT_1ST);
246 	      if (new_clip) { free(clip_ptr); clip_ptr = new_clip; }
247 	      else { free(clip_ptr); clip_ptr = 0; clip_flag = xaFALSE; }
248 	    }
249 
250 	    if (already_disp_flag==xaTRUE) chdr=0;
251 	    UTIL_Scale_Mapped(t_pic,ipic,xpos,ypos,xsize,ysize,
252 		inline_size,width,height,buff_x,buff_y,x11_bytes_pixel,
253 		&xpos_o,&ypos_o,&xsize_o,&ysize_o,chdr);
254             xpos = xpos_o; ypos = ypos_o; xsize = xsize_o; ysize = ysize_o;
255 	    act->type = ACT_DISP;	act_map_hdr->psize = 8;
256 
257 	  }
258 	  else /* scale to zero size */
259 	  {
260 	    act->type = ACT_NOP;
261 	    FREE(act_map_hdr,0x101);	act_map_hdr = 0;
262 	    clip_flag = xaFALSE;
263 	    if (clip_ptr) { free(clip_ptr); clip_ptr = 0; }
264 	  }
265 	}
266 	else
267         {
268 	  if (   (already_disp_flag == xaFALSE) || (free_ipic_flag == xaFALSE)
269 	      || (resize_flag == xaTRUE) )
270 	  { xaULONG t_xpos,t_ypos;
271 	    if (resize_flag == xaFALSE) { t_xpos = t_ypos = 0; }
272 	    else { t_xpos = xpos; t_ypos = ypos; }
273 	    t_pic = (xaUBYTE *) malloc(ysize * line_size);
274 	    if (t_pic == 0) TheEnd1("X11_Get_Image: t_pic malloc failed.\n");
275 	    if (already_disp_flag == xaFALSE)
276 	    {
277 	      UTIL_Mapped_To_Mapped(t_pic,ipic,chdr,
278 			t_xpos,t_ypos,xsize,ysize,in_x_size,in_y_size);
279 	    }
280 	    else  /* either not_full or can't-free, either way copy */
281 	    {
282 	      UTIL_Sub_Image(t_pic,ipic,xsize,ysize,t_xpos,t_ypos,
283 						in_x_size,x11_bytes_pixel);
284 	    }
285 	  }
286 	  else t_pic = ipic;
287 	  act->type = ACT_DISP;	act_map_hdr->psize = 0;
288         }
289 	break;
290     case XA_STATICGRAY:
291     case XA_STATICCOLOR:
292     case XA_GRAYSCALE:
293     case XA_PSEUDOCOLOR:
294 
295 	/* Create Bitmap based on Original GIF Image */
296   if ( (clip_ptr==0) && (clip_flag==xaTRUE) )
297   {
298     clip_ptr = (xaUBYTE *) malloc(ysize * (X11_Get_Bitmap_Width(xsize)/8) );
299     if (clip_ptr==0) TheEnd1("Setup_Mapped: clip malloc err\n");
300     UTIL_Create_Clip(clip_ptr,ipic,clip_mask,xsize,ysize,
301 			1,X11_Get_Bitmap_Width(xsize),XA_LSBIT_1ST);
302   }
303 
304 	if (need_to_scale == xaTRUE)
305         {
306 	  xaULONG xpos_o,ypos_o,xsize_o,ysize_o;
307 
308 	  xpos_o = xpos; ypos_o = ypos;
309 	  if (full_ipic_flag == xaFALSE) xpos = ypos = 0;
310 	  t_pic = UTIL_Alloc_Scaled(xsize,ysize,width,height,
311 		buff_x,buff_y,x11_bytes_pixel,xpos_o,ypos_o,xaFALSE);
312 	  if (t_pic)
313 	  {
314 	    if ((clip_ptr) && (clip_flag==xaTRUE))
315 	    { xaULONG cxpos, cypos, cxsize, cysize;
316 	      xaUBYTE *new_clip = UTIL_Scale_Bitmap(0,clip_ptr,
317 			xsize,ysize,(X11_Get_Bitmap_Width(xsize/8)),
318 			width, height,
319 			buff_x, buff_y,
320 			&cxpos, &cypos, &cxsize, &cysize,
321 			XA_LSBIT_1ST, XA_LSBIT_1ST);
322 	      if (new_clip) { free(clip_ptr); clip_ptr = new_clip; }
323 	      else { free(clip_ptr); clip_ptr = 0; clip_flag = xaFALSE; }
324 	    }
325 
326 	    UTIL_Scale_Mapped(t_pic,ipic,xpos,ypos,xsize,ysize,
327 			inline_size,width,height,buff_x,buff_y,
328 			inpix_size,&xpos_o,&ypos_o,&xsize_o,&ysize_o,0);
329             xpos = xpos_o; ypos = ypos_o; xsize = xsize_o; ysize = ysize_o;
330 	    act->type = ACT_MAPPED;	act_map_hdr->psize = 8;
331 	  }
332 	  else /* scale to zero size */
333 	  {
334 	    act->type = ACT_NOP;	clip_flag = xaFALSE;
335 	    FREE(act_map_hdr,0x102);	act_map_hdr = 0;
336 	  }
337         } /* end of need to scale */
338         else
339         {
340 	  if ( (free_ipic_flag == xaFALSE) || (full_ipic_flag == xaFALSE)
341 	      || (resize_flag == xaTRUE) )
342 	  { xaULONG t_xpos,t_ypos;
343 	    if (resize_flag == xaFALSE) { t_xpos = t_ypos = 0; }
344 	    else { t_xpos = xpos; t_ypos = ypos; }
345 	    t_pic = (xaUBYTE *) malloc(ysize * line_size);
346 	    if (t_pic == 0) TheEnd1("Setup_Mapped: malloc err 3\n");
347             UTIL_Sub_Image(t_pic,ipic,xsize,ysize,t_xpos,t_ypos,
348 							in_x_size,inpix_size);
349 	  }
350 	  else t_pic = ipic;
351 	  act->type = ACT_MAPPED;
352           act_map_hdr->psize = 8;
353         }
354 	break;
355      default:
356 	act->type = ACT_NOP;
357 	fprintf(stderr,"invalid X11 display ?? %x\n",x11_display_type);
358 	TheEnd();
359   }
360 
361   if ( (clip_ptr==0) && (clip_flag==xaTRUE) )
362   {
363     clip_ptr = (xaUBYTE *) malloc(ysize * (X11_Get_Bitmap_Width(xsize)/8) );
364     if (clip_ptr==0) TheEnd1("Setup_Mapped: clip malloc err\n");
365     UTIL_Create_Clip(clip_ptr,t_pic,clip_mask,xsize,ysize,
366 			inpix_size,X11_Get_Bitmap_Width(xsize),XA_LSBIT_1ST);
367   }
368 
369   act->data = (xaUBYTE *) act_map_hdr;
370   if (act_map_hdr)
371   {
372     act_map_hdr->xpos = xpos;
373     act_map_hdr->ypos = ypos;
374     act_map_hdr->xsize = xsize;
375     act_map_hdr->ysize = ysize;
376     act_map_hdr->data = t_pic;
377     act_map_hdr->clip = clip_ptr;
378   }
379   if ((free_ipic_flag==xaTRUE) && (t_pic != ipic))
380 				{ FREE(ipic,0x103); ipic = 0; }
381 }
382 
ACT_Get_CHDR(rev,csize,coff,msize,moff,cmap_flag,map_flag)383 XA_CHDR *ACT_Get_CHDR(rev,csize,coff,msize,moff,cmap_flag,map_flag)
384 xaULONG rev,csize,coff,msize,moff;
385 xaULONG cmap_flag,map_flag;
386 {
387   XA_CHDR *chdr;
388 
389   chdr = (XA_CHDR *)malloc(sizeof(XA_CHDR));
390   if (chdr == 0) TheEnd1("ACT_Get_CHDR: malloc err\n");
391 
392   DEBUG_LEVEL2 fprintf(stderr,"ACT_Get_CHDR %x\n",(xaULONG)chdr);
393 
394   chdr->rev    = rev;
395   chdr->csize  = csize;
396   chdr->coff   = coff;
397   chdr->msize  = msize;
398   chdr->moff   = moff;
399   chdr->next   = 0;
400   chdr->acts   = 0;
401   chdr->new_chdr = 0;
402 
403   if ( (csize) && (cmap_flag) )
404   {
405     chdr->cmap = (ColorReg *)malloc(csize * sizeof(ColorReg));
406     if (chdr->cmap == 0) TheEnd1("ACT_Get_CHDR: cmap malloc err\n");
407   }
408   else
409   {
410     chdr->cmap = 0;
411     if ( (csize==0) && (cmap_flag) )
412 	 fprintf(stderr,"ACT_Get_CHDR: csize 0 err\n");
413   }
414   if ( (msize) && (map_flag) )
415   {
416     chdr->map = (xaULONG *)malloc(msize * sizeof(xaULONG));
417     if (chdr->map == 0) TheEnd1("ACT_Get_CHDR: map malloc err\n");
418   }
419   else
420   {
421     chdr->map = 0;
422     if ( (msize==0) && (map_flag) )
423 	 fprintf(stderr,"ACT_Get_CHDR: msize 0 err\n");
424   }
425 
426   if (xa_chdr_start == 0) xa_chdr_start = chdr;
427   else xa_chdr_cur->next = chdr;
428   xa_chdr_cur = chdr;
429   return(chdr);
430 }
431 
432 /*
433  * Allocate CMAP and put at end of list
434  */
ACT_Get_CMAP(new_map,csize,coff,msize,moff,rbits,gbits,bbits)435 XA_CHDR *ACT_Get_CMAP(new_map,csize,coff,msize,moff,rbits,gbits,bbits)
436 ColorReg *new_map;
437 xaULONG csize,coff,msize,moff;
438 xaULONG rbits,gbits,bbits;
439 {
440   xaULONG i;
441   XA_CHDR *chdr;
442   xaULONG rscale,gscale,bscale;
443 
444   if (   (msize > csize) || (moff < coff)
445       || ( (msize+moff) > (csize+coff) )  )
446 	TheEnd1("ACT_Get_CMAP: map not in cmap err\n");
447 
448   chdr = ACT_Get_CHDR(0,csize,coff,msize,moff,xaTRUE,xaTRUE);
449 
450   rscale = cmap_scale[rbits];
451   gscale = cmap_scale[gbits];
452   bscale = cmap_scale[bbits];
453 
454   DEBUG_LEVEL2 fprintf(stderr,"c scales %x %x %x\n",rscale,gscale,bscale);
455   for(i = 0; i < csize; i++)
456   {
457     chdr->cmap[i].red   = xa_gamma_adj[ ((rscale * new_map[i].red  ) >> 8) ];
458     chdr->cmap[i].green = xa_gamma_adj[ ((gscale * new_map[i].green) >> 8) ];
459     chdr->cmap[i].blue  = xa_gamma_adj[ ((bscale * new_map[i].blue ) >> 8) ];
460 
461     DEBUG_LEVEL3 fprintf(stderr,"%d) %x %x %x\n",i,
462 	chdr->cmap[i].red,chdr->cmap[i].green,chdr->cmap[i].blue);
463   }
464   rscale *= 11;
465   gscale *= 16;
466   bscale *=  5;
467   for(i = 0; i < csize; i++)
468   {
469     register xaULONG d = ( (   rscale * new_map[i].red
470 			   + gscale * new_map[i].green
471 			   + bscale * new_map[i].blue) >> 13 );
472     chdr->cmap[i].gray = xa_gamma_adj[ d ];
473   }
474   if (x11_display_type & XA_X11_TRUE)
475   {
476     for(i = 0; i < msize; i++)
477     {
478       register xaULONG j;
479       j = i + moff - coff;
480       chdr->map[i] = X11_Get_True_Color(chdr->cmap[j].red,
481 			chdr->cmap[j].green,chdr->cmap[j].blue,16);
482     }
483   }
484   else for(i = 0; i < csize; i++) chdr->map[i] = i + moff;
485   return(chdr);
486 }
487 
488 /*
489  * Allocate CCMAP and put at end of list
490  */
ACT_Get_CCMAP(act,new_map,csize,coff,rbits,gbits,bbits)491 void ACT_Get_CCMAP(act,new_map,csize,coff,rbits,gbits,bbits)
492 XA_ACTION *act;
493 ColorReg *new_map;
494 xaULONG csize,coff;
495 xaULONG rbits,gbits,bbits;
496 {
497   xaULONG i;
498   ACT_CMAP_HDR *act_cmap_hdr;
499   ColorReg *act_cmap;
500   xaULONG rscale,gscale,bscale;
501 
502   act_cmap_hdr = (ACT_CMAP_HDR *)malloc(sizeof(ACT_CMAP_HDR) +
503 					(csize * sizeof(ColorReg)) );
504   if (act_cmap_hdr == 0) TheEnd1("ACT_Get_CCMAP: malloc err");
505 
506   act->type = ACT_CMAP;
507   act->data = (xaUBYTE *) act_cmap_hdr;
508 
509   act_cmap_hdr->csize = csize;
510   act_cmap_hdr->coff  = coff;
511   act_cmap = (ColorReg *)act_cmap_hdr->data;
512 
513   rscale = cmap_scale[rbits];
514   gscale = cmap_scale[gbits];
515   bscale = cmap_scale[bbits];
516 
517   DEBUG_LEVEL2 fprintf(stderr,"c scales %x %x %x\n",rscale,gscale,bscale);
518   for(i = 0; i < csize; i++)
519   {
520     act_cmap[i].red   = xa_gamma_adj[ ((rscale * new_map[i].red  ) >> 8) ];
521     act_cmap[i].green = xa_gamma_adj[ ((gscale * new_map[i].green) >> 8) ];
522     act_cmap[i].blue  = xa_gamma_adj[ ((bscale * new_map[i].blue ) >> 8) ];
523     DEBUG_LEVEL3 fprintf(stderr,"%d) %x %x %x\n",i,
524 	act_cmap[i].red,act_cmap[i].green, act_cmap[i].blue);
525   }
526 
527   rscale *= 11;
528   gscale *= 16;
529   bscale *=  5;
530   for(i = 0; i < csize; i++)
531   {
532     register xaULONG d = ( (   rscale * new_map[i].red
533 			   + gscale * new_map[i].green
534 			   + bscale * new_map[i].blue) >> 13 );
535     act_cmap[i].gray = xa_gamma_adj[ d ];
536   }
537 }
538 
539 
ACT_Add_CHDR_To_Action(act,chdr)540 void ACT_Add_CHDR_To_Action(act,chdr)
541 XA_ACTION  *act;
542 XA_CHDR *chdr;
543 {
544   if ((act) && (chdr))
545   {
546     /* have act use chdr and map */
547     act->chdr = chdr;
548     act->map  = chdr->map;
549     /* add action to chdr's action list */
550     act->next_same_chdr = chdr->acts;
551     chdr->acts = act;
552   } else fprintf(stderr,"ACT_Add_CHDR_To_Action: Err %x %x\n",
553 						(xaULONG)act,(xaULONG)chdr);
554 }
555 
ACT_Del_CHDR_From_Action(act,chdr)556 void ACT_Del_CHDR_From_Action(act,chdr)
557 XA_ACTION  *act;
558 XA_CHDR *chdr;
559 {
560   XA_ACTION *t_act;
561   t_act = chdr->acts;
562   if (t_act)
563   {
564     if (t_act == act) chdr->acts = act->next_same_chdr;
565     else
566     {
567       while (t_act->next_same_chdr)
568       {
569         if (t_act->next_same_chdr == act)
570 		t_act->next_same_chdr = act->next_same_chdr;
571         else t_act = t_act->next_same_chdr;
572       }
573     }
574   }
575   act->chdr = 0;
576   act->map  = 0;
577 }
578 
579 
ACT_Make_Images(act)580 void ACT_Make_Images(act)
581 XA_ACTION *act;
582 {
583   xaULONG line_size,pixmap_type;
584   XImage *image;
585   ACT_MAPPED_HDR *act_map_hdr;
586 
587 
588   DEBUG_LEVEL1 fprintf(stderr,"ACT_Make_Images: ");
589   while(act)
590   {
591     DEBUG_LEVEL2 fprintf(stderr,"act %x \n",act->type);
592     switch(act->type)
593     {
594       case ACT_SETTER:
595 	if (xa_pixmap_flag == xaFALSE) act->type = ACT_IMAGES;
596 	else act->type = ACT_PIXMAPS;
597 	if (act->chdr)
598 	{
599 	  if (act->chdr->new_chdr)
600 	  {
601 	    act->chdr = act->chdr->new_chdr;
602 	    act->cmap_rev = act->chdr->rev;
603 	  }
604 	}
605 	break;
606 
607       case ACT_CYCLE:
608 	if (act->chdr)
609 	{
610 	  if (act->chdr->new_chdr)
611 	  {
612 	    ACT_CYCLE_HDR *act_cycle;
613 	    xaULONG i,size,*i_ptr,moff,*map;
614 
615 	    act_cycle = (ACT_CYCLE_HDR *)act->data;
616 	    size = act_cycle->size;
617 	    i_ptr = (xaULONG *)(act_cycle->data);
618 	    map    = act->chdr->map;
619 	    moff   = act->chdr->moff;
620 	    for(i=0; i<size; i++)
621 	      i_ptr[i] = map[ (i_ptr[i] - moff) ];
622 	    act->chdr = act->chdr->new_chdr;
623 	    act->cmap_rev = act->chdr->rev;
624 	  }
625 	}
626 	break;
627 
628       case ACT_CMAP:
629 	if (act->chdr)
630 	{
631 	  XA_CHDR *new_chdr;
632 	  new_chdr = act->chdr->new_chdr;
633 	  if (new_chdr)
634 	  {
635 	    ACT_CMAP_HDR *old_cmap_hdr,*new_cmap_hdr;
636 	    ColorReg *old_cmap,*new_cmap;
637 	    xaULONG i,new_csize,old_csize,old_coff;
638 
639             DEBUG_LEVEL2
640 		fprintf(stderr,"ACT_Make_Images remapping CMAP %x %x\n",
641 			(xaULONG)act->chdr, (xaULONG)new_chdr);
642 
643 	    old_cmap_hdr = (ACT_CMAP_HDR *) act->data;
644 	    old_cmap = (ColorReg *)old_cmap_hdr->data;
645 	    old_csize = old_cmap_hdr->csize;
646 	    old_coff  = old_cmap_hdr->coff;
647 	    new_csize = new_chdr->csize;
648 		/* allocate new cmap_hdr */
649 	    new_cmap_hdr = (ACT_CMAP_HDR *)malloc(sizeof(ACT_CMAP_HDR) +
650 					(new_csize * sizeof(ColorReg)) );
651 	    if (new_cmap_hdr == 0)
652 		TheEnd1("ACT_Make_Images: cmap malloc err");
653 	    new_cmap_hdr->csize = new_csize;
654 	    new_cmap_hdr->coff  = new_chdr->coff;
655 	    new_cmap = (ColorReg *)new_cmap_hdr->data;
656 		/* remap cmap change based on chdr map */
657 	    memcpy((char*)new_cmap,(char*)new_chdr->cmap,
658 					(new_csize * sizeof(ColorReg)));
659 	    for(i=0; i<old_csize; i++)
660 	    {
661 	      register xaULONG d;
662 	      d = act->chdr->map[ i + old_coff - act->chdr->coff ];
663 	      new_cmap[d].red   = old_cmap[i].red;
664 	      new_cmap[d].green = old_cmap[i].green;
665 	      new_cmap[d].blue  = old_cmap[i].blue;
666 	      new_cmap[d].gray  = old_cmap[i].gray;
667 	    }
668 	    FREE(old_cmap_hdr,0x104); old_cmap_hdr = 0;
669 	    act->data = (xaUBYTE *)new_cmap_hdr;
670 	    act->chdr = new_chdr;
671 	    act->cmap_rev = act->chdr->rev;
672           } /* end of new chdr */
673         } /* end of chdr */
674 	break;
675       case ACT_MAPPED:
676 	if (act->chdr)
677 	{
678 	  if (act->chdr->new_chdr)
679 	  {
680             DEBUG_LEVEL2
681 		fprintf(stderr,"ACT_Make_Images remapping MAPPED %x %x\n",
682 			(xaULONG)act->chdr, (xaULONG)act->chdr->new_chdr);
683 
684 	    act_map_hdr = (ACT_MAPPED_HDR *) act->data;
685 	    /* POD TEMP currently assumes same size mapping */
686             if (cmap_dither_type == CMAP_DITHER_FLOYD)
687             {
688 	      UTIL_Mapped_To_Floyd(act_map_hdr->data,act_map_hdr->data,
689 		  act->chdr->new_chdr,act->chdr,
690 		  0,0,act_map_hdr->xsize,act_map_hdr->ysize,
691 		  act_map_hdr->xsize,act_map_hdr->ysize);
692             }
693             else
694             {
695 	      UTIL_Mapped_To_Mapped(act_map_hdr->data,act_map_hdr->data,
696 		  act->chdr,
697 		  0,0,act_map_hdr->xsize,act_map_hdr->ysize,
698 		  act_map_hdr->xsize,act_map_hdr->ysize);
699 	    }
700 	    /* update chdr ptrs and revs */
701 	    act->chdr = act->chdr->new_chdr;
702 	    act->cmap_rev = act->chdr->rev;
703 	  }
704 	  else if (x11_bytes_pixel > 1) /* need to map anyways */
705 	  {
706 DEBUG_LEVEL2 fprintf(stderr,"ACT_Make_Images kludge remapping MAPPED\n");
707 
708 	    act_map_hdr = (ACT_MAPPED_HDR *) act->data;
709 	    UTIL_Mapped_To_Mapped(act_map_hdr->data,act_map_hdr->data,
710 		  act->chdr,
711 		  0,0,act_map_hdr->xsize,act_map_hdr->ysize,
712 		  act_map_hdr->xsize,act_map_hdr->ysize);
713 	  }
714 	}
715 	/* fall through */
716       case ACT_DISP:
717       {
718         ACT_IMAGE_HDR *act_im_hdr;
719 
720 	act_im_hdr = (ACT_IMAGE_HDR *) malloc( sizeof(ACT_IMAGE_HDR) );
721 	if (act_im_hdr == 0) TheEnd1("ACT_Make_Images: malloc err 1\n");
722 	act_map_hdr = (ACT_MAPPED_HDR *) act->data;
723 	line_size = X11_Get_Line_Size(act_map_hdr->xsize);
724 	if (x11_display_type == XA_MONOCHROME) pixmap_type = XYPixmap;
725 	else pixmap_type = ZPixmap;
726 
727 	if (x11_pack_flag == xaTRUE) /* PACK */
728 	{
729           UTIL_Pack_Image(act_map_hdr->data,act_map_hdr->data,
730 			  act_map_hdr->xsize,act_map_hdr->ysize);
731 	  if (x11_bits_per_pixel==2) line_size = (line_size + 3) / 4;
732           else if (x11_bits_per_pixel==4) line_size = (line_size + 1) / 2;
733 	}
734 
735 	{
736 	  image = XCreateImage(theDisp, theVisual,
737 		x11_depth,pixmap_type,0,NULL,
738 		act_map_hdr->xsize, act_map_hdr->ysize,
739 		x11_bitmap_pad, line_size);
740 	  if (image == 0) TheEnd1("ACT_Make_Images: XCreateImage err\n");
741 	  image->data = (char *)act_map_hdr->data;
742 	}
743 	act->type = ACT_IMAGE;
744 	act->data = (xaUBYTE *) act_im_hdr;
745 	act_im_hdr->flag = ACT_BUFF_VALID;
746 	act_im_hdr->xpos = act_map_hdr->xpos;
747 	act_im_hdr->ypos = act_map_hdr->ypos;
748 	act_im_hdr->xsize = act_map_hdr->xsize;
749 	act_im_hdr->ysize = act_map_hdr->ysize;
750 	act_im_hdr->image = image;
751 	act_im_hdr->clip  = act_map_hdr->clip;
752       }
753       FREE(act_map_hdr,0x105); act_map_hdr = 0;
754       break;
755     } /* end of switch */
756     act = act->next;
757   } /* end of while act */
758 }
759 
ACT_Setup_Loop(begin_act,end_act,count,begin_frame,end_frame)760 void ACT_Setup_Loop(begin_act,end_act,count,begin_frame,end_frame)
761 XA_ACTION *begin_act,*end_act;
762 xaULONG count,begin_frame,end_frame;
763 {
764   ACT_BEG_LP_HDR *beg_loop;
765   ACT_END_LP_HDR *end_loop;
766 
767   begin_act->type = ACT_BEG_LP;
768   beg_loop = (ACT_BEG_LP_HDR *)malloc(sizeof(ACT_BEG_LP_HDR));
769   if (beg_loop == 0) TheEnd1("ACT_Setup_Loop: malloc err0");
770   begin_act->data = (xaUBYTE *)beg_loop;
771   beg_loop->count = count;
772   beg_loop->cnt_var = 0;
773   beg_loop->end_frame = end_frame;
774 
775   end_act->type = ACT_END_LP;
776   end_loop = (ACT_END_LP_HDR *)malloc(sizeof(ACT_END_LP_HDR));
777   if (end_loop == 0) TheEnd1("ACT_Setup_Loop: malloc err1");
778   end_act->data = (xaUBYTE *)end_loop;
779   end_loop->count = &(beg_loop->count);
780   end_loop->cnt_var = &(beg_loop->cnt_var);
781   end_loop->begin_frame = begin_frame;
782   end_loop->end_frame = &(beg_loop->end_frame);
783   end_loop->prev_end_act = 0;
784 }
785 
ACT_Free_Act(act)786 void ACT_Free_Act(act)
787 XA_ACTION *act;
788 {
789   if (act)
790   {
791     switch(act->type)
792     {
793       case ACT_IMAGE:
794         { ACT_IMAGE_HDR *act_im_hdr;
795           act_im_hdr = (ACT_IMAGE_HDR *)(act->data);
796           if (act_im_hdr->flag & ACT_BUFF_VALID)
797 	  {
798             if (act_im_hdr->image)
799 		{ XDestroyImage(act_im_hdr->image); act_im_hdr->image = 0; }
800             if (act_im_hdr->clip)
801 		{ FREE(act_im_hdr->clip,0x199); act_im_hdr->clip = 0; }
802             XSync(theDisp,False);
803 	  }
804           FREE(act->data,0x108); act->data = 0;
805         }
806         break;
807 
808       case ACT_PIXMAP:
809         { ACT_PIXMAP_HDR *act_pm_hdr;
810           act_pm_hdr = (ACT_PIXMAP_HDR *)(act->data);
811           if (act_pm_hdr->flag & ACT_BUFF_VALID)
812 	  {
813             if (act_pm_hdr->pixmap) XFreePixmap(theDisp,act_pm_hdr->pixmap);
814             if (act_pm_hdr->clip)   XFreePixmap(theDisp,act_pm_hdr->clip);
815             XSync(theDisp,False);
816 	  }
817           FREE(act->data,0x109); act->data = 0;
818           DEBUG_LEVEL2 fprintf(stderr,"  freed ACT_PIXMAP\n");
819         }
820         break;
821 
822       /*POD NOTE: merge this to default case. Used to be separate for a reason,
823         but no longer. */
824       case ACT_SETTER:
825       case ACT_IMAGES:
826       case ACT_PIXMAPS:
827         { ACT_SETTER_HDR *act_pms_hdr;
828           act_pms_hdr = (ACT_SETTER_HDR *)(act->data);
829           FREE(act_pms_hdr,0x10a);
830         }
831         break;
832       default:
833         if (act->data != 0) { FREE(act->data,0x10b); act->data = 0; }
834         break;
835     } /* end of switch */
836     act->data = 0;
837     act->type = ACT_NOP;
838   }
839 }
840 
841 /****************************
842  *
843  *
844  *  xin is an open XA_INPUT handle to the animation file. It MUST be
845  *  returned in the same file position it was passed in as.
846  ********/
ACT_Setup_Delta(anim,act,dlta_hdr,xin)847 void ACT_Setup_Delta(anim,act,dlta_hdr,xin)
848 XA_ANIM_SETUP *anim;
849 XA_ACTION *act;
850 ACT_DLTA_HDR *dlta_hdr;
851 XA_INPUT *xin;
852 { XA_DEC_INFO dec_info;
853   XA_DEC2_INFO dec2_info;
854   dec2_info.imagex    = dec_info.imagex    = anim->imagex;
855   dec2_info.imagey    = dec_info.imagey    = anim->imagey;
856   dec2_info.imaged    = dec_info.imaged    = anim->depth;
857   dec2_info.chdr      = dec_info.chdr      = 0;
858   dec2_info.map_flag  = dec_info.map_flag  = xaFALSE;
859   dec2_info.map       = dec_info.map       = 0;
860   dec2_info.special   = dec_info.special   = 0;
861   dec2_info.extra     = dec_info.extra     = dlta_hdr->extra;
862   dec2_info.skip_flag = dec_info.skip_flag = 0;
863   dec2_info.bytes_pixel = x11_bytes_pixel;
864 
865   if (act->type == ACT_NOP)
866   {
867     return;
868   }
869   else if (xa_buffer_flag == xaTRUE)
870   { xaULONG xpos,ypos,xsize,ysize,dlta_flag,free_pic_flag;
871     xaUBYTE *the_pic = anim->pic;
872 
873     if (the_pic) free_pic_flag = xaFALSE;
874     else
875     { xaULONG psize = anim->imagex * anim->imagey;
876       if ((cmap_true_map_flag == xaTRUE) && (anim->depth > 8))
877 		the_pic = (xaUBYTE *) malloc( 3 * psize );
878       else	the_pic = (xaUBYTE *) malloc(XA_PIC_SIZE(psize));
879       if (the_pic == 0) TheEnd1("ACT_Setup_Delta: malloc err.");
880       free_pic_flag = xaTRUE;
881     }
882     if ( (cmap_true_map_flag==xaFALSE) || (anim->depth <= 8) )
883     {
884 
885       dec2_info.map_flag = dec_info.map_flag
886 			= (x11_display_type & XA_X11_TRUE)?(xaTRUE):(xaFALSE);
887       dec2_info.map = dec_info.map	= anim->chdr->map;
888 
889       if (dlta_hdr->xapi_rev == 0x0002)
890       {
891 
892         dec2_info.image_type = XA_Get_Image_Type( dlta_hdr->special,
893 				0,dec2_info.map_flag);
894 
895         dlta_flag = dlta_hdr->delta(the_pic,dlta_hdr->data,
896 			dlta_hdr->fsize,&dec2_info);
897         if (!(dlta_flag & ACT_DLTA_MAPD)) dec2_info.map_flag = xaFALSE;
898         xpos  = dec2_info.xs;	ypos  = dec2_info.ys;
899         xsize = dec2_info.xe;	ysize = dec2_info.ye;
900       }
901       else /* if (dlta_hdr->xapi_rev == 0x0001) */
902       {
903         dlta_flag = dlta_hdr->delta(the_pic,dlta_hdr->data,
904 			dlta_hdr->fsize,&dec_info);
905         if (!(dlta_flag & ACT_DLTA_MAPD)) dec_info.map_flag = xaFALSE;
906         xpos  = dec_info.xs;	ypos  = dec_info.ys;
907         xsize = dec_info.xe;	ysize = dec_info.ye;
908       }
909 
910 
911       xsize -= xpos; ysize -= ypos;
912       FREE(dlta_hdr,0xA001); act->data = 0; dlta_hdr = 0;
913       if (dlta_flag & ACT_DLTA_NOP)
914       { act->type = ACT_NOP;
915         if ((free_pic_flag==xaTRUE) && the_pic) {free(the_pic); the_pic = 0;}
916       }
917       else ACT_Setup_Mapped(act,the_pic,anim->chdr,
918 			xpos,ypos,xsize,ysize,anim->imagex,anim->imagey,
919 			xaFALSE,0,free_pic_flag,xaTRUE,dec_info.map_flag);
920       ACT_Add_CHDR_To_Action(act,anim->chdr);
921     }
922     else /* decode as RGB triplets and then convert to mapped image */
923     { xaUBYTE *tpic = 0;
924       dec2_info.special = dec_info.special = 1;
925       if (dlta_hdr->xapi_rev == 0x0002)
926       { dec2_info.image_type = XA_Get_Image_Type( dlta_hdr->special,
927                                            0,dec2_info.map_flag);
928         dlta_flag = dlta_hdr->delta(the_pic,dlta_hdr->data,
929 			dlta_hdr->fsize,&dec2_info);
930       }
931       else /* if (dlta_hdr->xapi_rev == 0x0001) */
932       { dlta_flag = dlta_hdr->delta(the_pic,dlta_hdr->data,
933 			dlta_hdr->fsize,&dec_info);
934       }
935       /*POD NOTE: need to add subimage support to RGB conversion utils */
936       /* until then ignore optimization and force full image */
937       /* xsize -= xpos; ysize -= ypos; */
938       xpos = ypos = 0; xsize = anim->imagex; ysize = anim->imagey;
939       FREE(dlta_hdr,0xA002); act->data = 0; dlta_hdr = 0;
940       if (dlta_flag & ACT_DLTA_NOP)
941       { act->type = ACT_NOP;
942         if ((free_pic_flag==xaTRUE) && the_pic) {free(the_pic); the_pic = 0;}
943       }
944       else
945       {
946 	if (    (cmap_true_to_all == xaTRUE)
947 	     || ((cmap_true_to_1st == xaTRUE) && (anim->chdr == 0) )
948 	   )  anim->chdr = CMAP_Create_CHDR_From_True(the_pic,8,8,8,
949 		anim->imagex,anim->imagey,anim->cmap,&(anim->imagec));
950 	else if ( (cmap_true_to_332 == xaTRUE) && (anim->chdr == 0) )
951 		anim->chdr = CMAP_Create_332(anim->cmap,&(anim->imagec));
952 	else if ( (cmap_true_to_gray == xaTRUE) && (anim->chdr == 0) )
953 		anim->chdr = CMAP_Create_Gray(anim->cmap,&(anim->imagec));
954 
955 	if (cmap_dither_type == CMAP_DITHER_FLOYD)
956 			tpic = UTIL_RGB_To_FS_Map(0,the_pic,anim->chdr,
957 				anim->imagex,anim->imagey,free_pic_flag);
958 	else tpic = UTIL_RGB_To_Map(0,the_pic,anim->chdr,
959 				anim->imagex,anim->imagey,free_pic_flag);
960 	ACT_Setup_Mapped(act,tpic,anim->chdr,xpos,ypos,xsize,ysize,
961 			anim->imagex,anim->imagey,xaFALSE,0,xaTRUE,xaTRUE,xaFALSE);
962 	if (anim->chdr) ACT_Add_CHDR_To_Action(act,anim->chdr);
963       } /* end of not NOP */
964     } /* end of true_map */
965   } /* end of buffer */
966   else /* not buffered */
967   {
968     /* Also make sure not xaTRUE, is 332 and special case file_flag */
969     if  ( (cmap_color_func != 0)
970             && (anim->depth > 8) && (anim->depth <= 32) /* QT gray depths */
971 	    && (!(x11_display_type & XA_X11_TRUE))
972 	)
973     {
974       if (anim->cmap_flag==0)
975       { xaULONG dlta_flag,psize;
976 	xaUBYTE *cbuf,*data;
977 
978 	psize = anim->imagex * anim->imagey;
979 	cbuf = (xaUBYTE *) malloc(3 * psize);
980 	if (cbuf == 0) TheEnd1("colorfunc1 malloc err0\n");
981 	memset((char *)(cbuf),0x00,(3 * psize) );
982 
983 	if ((xa_file_flag == xaTRUE) && (dlta_hdr->fsize != 0))
984 	{ xaULONG pos;
985 	  data = (xaUBYTE *)malloc(dlta_hdr->fsize);
986 	  if (data==0) TheEnd1("colorfunc1 malloc err1\n");
987 	  pos = xin->Get_FPos(xin);
988 	  xin->Seek_FPos(xin,dlta_hdr->fpos,0); /* save file pos */
989 	  xin->Read_Block(xin,data,dlta_hdr->fsize); /* read data*/
990 	  xin->Seek_FPos(xin,pos,0); /* restore file pos */
991 	} else data = dlta_hdr->data;
992 	dec2_info.special = dec_info.special   = 1;
993 	if (dlta_hdr->xapi_rev == 0x0002)
994         { dec2_info.image_type = XA_Get_Image_Type(dlta_hdr->special,
995                                            0,dec2_info.map_flag);
996 	  dlta_flag = dlta_hdr->delta(cbuf,data,dlta_hdr->fsize,&dec2_info);
997         }
998         else /* if (dlta_hdr->xapi_rev == 0x0001) */
999 	  dlta_flag = dlta_hdr->delta(cbuf,data,dlta_hdr->fsize,&dec_info);
1000 	if ((xa_file_flag == xaTRUE) && (dlta_hdr->fsize != 0))
1001 					{ FREE(data,0xA004); data = 0; }
1002 	switch(cmap_color_func)
1003 	{
1004 	  case 4:
1005 	  {
1006 	    anim->chdr = CMAP_Create_CHDR_From_True(cbuf,8,8,8,
1007 			 anim->imagex,anim->imagey,anim->cmap,&(anim->imagec));
1008 	    DEBUG_LEVEL1 fprintf(stderr,"CF4: csize = %d\n",anim->chdr->csize);
1009 	    anim->color_cnt += anim->chdr->csize;
1010 
1011 DEBUG_LEVEL1 fprintf(stderr,"Attempt: color_cnt %d retries %d \n",
1012 					anim->color_cnt, anim->color_retries);
1013 
1014 	    if (anim->color_cnt > 64)
1015 			{ anim->cmap_flag = 1; anim->color_cnt = 0;
1016 			  anim->color_retries = 0; }
1017             else
1018 	    {  anim->color_retries++;
1019 	       if (anim->color_retries > 3)
1020 			{ anim->cmap_flag = 1; anim->color_cnt = 0;
1021 			  anim->color_retries = 0; }
1022 	    }
1023 	    if (cbuf) FREE(cbuf,0xA005); cbuf = 0;
1024 	  }
1025 	  break;
1026 	} /* end switch */
1027       } /* first time through */
1028       else  /* else cnt til next time */
1029       {
1030 DEBUG_LEVEL1 fprintf(stderr,"Attempt: cmap_cnt %d fm_num %d sam_cnt %d\n",
1031 			anim->cmap_cnt, anim->cmap_frame_num, cmap_sample_cnt);
1032 	anim->cmap_cnt++;
1033 	if (cmap_sample_cnt && (anim->cmap_cnt >= anim->cmap_frame_num))
1034 		{ anim->cmap_flag = 0; anim->cmap_cnt = anim->color_cnt = 0; }
1035       }
1036     } /*color func, true color anim and not TrueDisplay  */
1037     if (anim->chdr) ACT_Add_CHDR_To_Action(act,anim->chdr);
1038   } /* not bufferd */
1039 }
1040 
1041