home *** CD-ROM | disk | FTP | other *** search
/ Dream 44 / Amiga_Dream_44.iso / Linux / Apps / xanim.tgz / xanim / xanim27064 / xa_show.c < prev    next >
C/C++ Source or Header  |  1997-01-26  |  37KB  |  1,210 lines

  1.  
  2. /*
  3.  * xa_show.c
  4.  *
  5.  * Copyright (C) 1990,1991,1992,1993,1994,1995,1996,1997 by Mark Podlipec.
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified and redistributed without
  9.  * fee for non-commerical purposes provided that this copyright notice is
  10.  * preserved intact on all copies and modified copies.
  11.  *
  12.  * There is no warranty or other guarantee of fitness of this software.
  13.  * It is provided solely "as is". The author(s) disclaim(s) all
  14.  * responsibility and liability with respect to this software's usage
  15.  * or its effect upon hardware or computer systems.
  16.  *
  17.  */
  18.  
  19. /* Revisions:
  20.  * 13Nov94:  wasn't properly skipping video frames in certain instances.
  21.  */
  22.  
  23. #include "xanim.h"
  24. #include <Intrinsic.h>
  25. #include <StringDefs.h>
  26. #include <Shell.h>
  27.  
  28. #ifdef XSHM
  29. #include <sys/ipc.h>
  30. #include <sys/shm.h>
  31. #include <X11/extensions/XShm.h>
  32. extern Visual        *theVisual;  /* POD NOTE: needed for XMBUF?? */
  33. #endif /*XSHM*/
  34.  
  35. #ifdef XMBUF
  36. #include <X11/extensions/multibuf.h>
  37. #endif
  38.  
  39. #include "xa_x11.h"
  40.  
  41. #define AUD_SYNC_CHECK() { XSync(theDisp,False); }
  42.  
  43. void XA_SHOW_IMAGE();
  44. void XA_SHOW_PIXMAP();
  45. void XA_SHOW_IMAGES();
  46. void XA_SHOW_PIXMAPS();
  47. void XA_SHOW_DELTA();
  48.  
  49. xaUBYTE *UTIL_Scale_Bitmap();
  50. xaUBYTE *UTIL_Scale_Mapped();
  51. void UTIL_Pack_Image();
  52. void UTIL_Mapped_To_Mapped();
  53. void UTIL_Mapped_To_Bitmap();
  54. void UTIL_Mapped_To_Floyd();
  55. xaULONG XA_Image_To_Pixmap();
  56. xaULONG XA_Read_Delta();
  57. void X11_Init_Image_Struct();
  58. void XA_Install_CMAP();
  59. void IFF_Init_DLTA_HDR();
  60. void IFF_Update_DLTA_HDR();
  61. void IFF_Buffer_HAM6();
  62. void IFF_Buffer_HAM8();
  63. extern xaULONG XA_Get_Image_Type();
  64.  
  65.  
  66. extern xaLONG  xa_frames_skipd, xa_frames_Sskipd;
  67. extern xaULONG xa_need_to_scale_b;
  68. extern xaULONG xa_need_to_scale_u;
  69. extern xaULONG xa_buff_x, xa_buff_y;
  70. extern xaULONG xa_disp_x, xa_disp_y;
  71. extern char *im_buff0,*im_buff1,*im_buff2,*im_buff3;
  72. extern char *xa_pic,*xa_disp_buff,*xa_scale_buff;
  73. extern xaULONG xa_disp_buff_size,xa_scale_buff_size;
  74. extern xaLONG xa_skip_flag;
  75. extern xaLONG xa_skip_video;
  76. extern xaLONG xa_skip_cnt;
  77. #define XA_SKIP_MAX 10  /* don't skip more than 5 frames in a row */
  78. extern xaULONG xa_image_size;
  79. extern xaULONG xa_imagex;
  80. extern xaULONG xa_imagey;
  81. extern xaULONG xa_imaged;
  82. extern xaLONG xa_pixmap_flag;
  83. extern xaLONG xa_dither_flag;
  84. extern int xa_vid_fd;
  85. extern xaUBYTE *xa_vidcodec_buf;
  86. extern xaULONG x11_expose_flag;
  87. extern xaLONG xa_anim_flags;
  88. extern xaLONG xa_no_disp;
  89.  
  90. extern xaLONG xa_cycle_cnt;
  91. extern xaLONG xa_now_cycling;
  92. extern void XA_Cycle_It();
  93.  
  94. extern xaULONG shm;
  95. #ifdef XSHM
  96. extern XShmSegmentInfo im0_shminfo;
  97. extern XShmSegmentInfo im1_shminfo;
  98. extern XShmSegmentInfo im2_shminfo;
  99. extern XImage *im0_Image;
  100. extern XImage *im1_Image;
  101. extern XImage *im2_Image;
  102. extern XImage *sh_Image;
  103. #endif
  104.  
  105. extern xaULONG mbuf;
  106.  
  107. /* SMR 13 */
  108. extern xaLONG xa_window_x;
  109. extern xaLONG xa_window_y;
  110. extern xaLONG xa_window_center_flag;
  111. extern xaLONG xa_max_imagex;
  112. extern xaLONG xa_max_imagey;
  113. extern float xa_scalex;
  114. extern float xa_scaley;
  115.  
  116. /* override XPutImage call to support playing at a particular
  117.    position in a window.  Uses #define kludge to avoid changing
  118.    lots of code */
  119. void xa_putimage(Display *dpy, Drawable d, GC gc, XImage *im,
  120.                  int sx, int sy, int dx, int dy,
  121.                  unsigned int w, unsigned int h)
  122. {
  123.   if (d == mainW) {
  124.     dx += xa_window_x;
  125.     dy += xa_window_y;
  126.     if (xa_window_center_flag == xaTRUE)
  127.     {
  128.       dx -= (int)((double)xa_max_imagex * xa_scalex / 2.0);
  129.       dy -= (int)((double)xa_max_imagey * xa_scaley / 2.0);
  130.     }
  131.   }
  132.   XPutImage(dpy, d, gc, im, sx, sy, dx, dy, w, h);
  133. }
  134. #define XPutImage xa_putimage
  135.  
  136. #ifdef XSHM
  137. void xa_shmputimage(Display *dpy, Drawable d, GC gc, XImage *im,
  138.                     int sx, int sy, int dx, int dy,
  139.                     unsigned int w, unsigned int h, int event)
  140. {
  141.   if (d == mainW) {
  142.     dx += xa_window_x;
  143.     dy += xa_window_y;
  144.     if (xa_window_center_flag == xaTRUE)
  145.     {
  146.       dx -= (int)((double)xa_max_imagex * xa_scalex / 2.0);
  147.       dy -= (int)((double)xa_max_imagey * xa_scaley / 2.0);
  148.     }
  149.   }
  150.   XShmPutImage(dpy, d, gc, im, sx, sy, dx, dy, w, h, False);
  151. }
  152. #define XShmPutImage xa_shmputimage
  153. #endif
  154. /* end SMR 13 */
  155.  
  156.  
  157. XA_DEC_INFO  xa_dec_info;
  158. XA_DEC2_INFO xa_dec2_info;
  159.  
  160.  
  161. /*POD clean this up */
  162. void XA_Show_Action(act)
  163. XA_ACTION *act;
  164. {
  165.  switch(act->type)
  166.  {
  167.        /* 
  168.         * NOP and DELAY don't change anything but can have timing info
  169.         * that might prove useful. ie dramatic pauses :^)
  170.         */
  171.     case ACT_NOP:      
  172.     DEBUG_LEVEL2 fprintf(stderr,"ACT_NOP:\n");
  173.     break;
  174.     case ACT_DELAY:    
  175.     DEBUG_LEVEL2 fprintf(stderr,"ACT_DELAY:\n");
  176.     break;
  177.        /* 
  178.         * Change Color Map.
  179.         */
  180.      case ACT_CMAP:     
  181.     if (   (cmap_play_nice == xaFALSE) 
  182.         && (!(x11_display_type & XA_X11_STATIC)) )
  183.     { ColorReg *tcmap;
  184.       xaLONG j;
  185.       ACT_CMAP_HDR *cmap_hdr;
  186.  
  187.       cmap_hdr    = (ACT_CMAP_HDR *)act->data;
  188.       xa_cmap_size    = cmap_hdr->csize;
  189.       if (xa_cmap_size > x11_cmap_size) xa_cmap_size = x11_cmap_size;
  190.       xa_cmap_off    = cmap_hdr->coff;
  191.       tcmap        = (ColorReg *)cmap_hdr->data;
  192.           for(j=0; j<xa_cmap_size;j++)
  193.       {
  194.         xa_cmap[j].red   = tcmap[j].red;
  195.         xa_cmap[j].green = tcmap[j].green;
  196.         xa_cmap[j].blue  = tcmap[j].blue;
  197.         xa_cmap[j].gray  = tcmap[j].gray;
  198.       }
  199.         /* POD TEMP share routine whith CHDR install */
  200.       if (x11_cmap_flag == xaTRUE)
  201.       {
  202.         DEBUG_LEVEL2 fprintf(stderr,"CMAP: size=%d off=%d\n",
  203.                     xa_cmap_size,xa_cmap_off);
  204.         if (x11_display_type & XA_X11_GRAY)
  205.         {
  206.           for(j=0;j<xa_cmap_size;j++)
  207.           {
  208.             defs[j].pixel = xa_cmap_off + j;
  209.             defs[j].red   = xa_cmap[j].gray;
  210.             defs[j].green = xa_cmap[j].gray;
  211.             defs[j].blue  = xa_cmap[j].gray;
  212.             defs[j].flags = DoRed | DoGreen | DoBlue;
  213.           }
  214.         }
  215.         else
  216.         {
  217.           for(j=0; j<xa_cmap_size;j++)
  218.           {
  219.             defs[j].pixel = xa_cmap_off + j;
  220.             defs[j].red   = xa_cmap[j].red;
  221.             defs[j].green = xa_cmap[j].green;
  222.             defs[j].blue  = xa_cmap[j].blue;
  223.             defs[j].flags = DoRed | DoGreen | DoBlue;
  224.             DEBUG_LEVEL3 fprintf(stderr," %d) %x %x %x <%d>\n",
  225.                 j,xa_cmap[j].red,xa_cmap[j].green,
  226.                 xa_cmap[j].blue,xa_cmap[j].gray);
  227.           }
  228.         }
  229.         XStoreColors(theDisp,theCmap,defs,xa_cmap_size);
  230.       }
  231.     }
  232.     break;
  233.        /* 
  234.         * Lower Color Intensity by 1/16.
  235.         */
  236.      case ACT_FADE:     
  237.     { xaLONG j;
  238.       DEBUG_LEVEL2 fprintf(stderr,"ACT_FADE:\n");
  239.       if ( (x11_display_type & XA_X11_CMAP) && (x11_cmap_flag == xaTRUE) )
  240.       {
  241.         for(j=0;j<xa_cmap_size;j++)
  242.         {
  243.           if (xa_cmap[j].red   <= 16) xa_cmap[j].red   = 0;
  244.           else xa_cmap[j].red   -= 16;
  245.           if (xa_cmap[j].green <= 16) xa_cmap[j].green = 0;
  246.           else xa_cmap[j].green -= 16;
  247.           if (xa_cmap[j].blue  <= 16) xa_cmap[j].blue  = 0;
  248.           else xa_cmap[j].blue  -= 16;
  249.  
  250.           defs[j].pixel = j;
  251.           defs[j].red   = xa_cmap[j].red   << 8;
  252.           defs[j].green = xa_cmap[j].green << 8;
  253.           defs[j].blue  = xa_cmap[j].blue  << 8;
  254.           defs[j].flags = DoRed | DoGreen | DoBlue;
  255.         }
  256.         XStoreColors(theDisp,theCmap,defs,xa_cmap_size);
  257.         XFlush(theDisp);
  258.       }
  259.     }
  260.     break;
  261.  
  262.      case ACT_APTR:   
  263.     { ACT_APTR_HDR *aptr_hdr = (ACT_APTR_HDR *)act->data;
  264.           if (aptr_hdr->act->type == ACT_IMAGE)
  265.         XA_SHOW_IMAGE(aptr_hdr->act,aptr_hdr->xpos,aptr_hdr->ypos,
  266.                 aptr_hdr->xsize,aptr_hdr->ysize,1);
  267.           else if (aptr_hdr->act->type == ACT_PIXMAP)
  268.         XA_SHOW_PIXMAP(aptr_hdr->act,aptr_hdr->xpos,aptr_hdr->ypos,
  269.                 aptr_hdr->xsize,aptr_hdr->ysize,1);
  270.       else
  271.       {
  272.           fprintf(stderr,"ACT_APTR: error invalid action %x\n",act->type);
  273.       }
  274.     }
  275.     break;
  276.  
  277.      case ACT_IMAGE:   
  278.     XA_SHOW_IMAGE(act,0,0,0,0,0);
  279.     break;
  280.  
  281.      case ACT_PIXMAP:   
  282.     XA_SHOW_PIXMAP(act,0,0,0,0,0);
  283.     break;
  284.  
  285.      case ACT_IMAGES:
  286.     XA_SHOW_IMAGES(act);
  287.     break;
  288.  
  289.      case ACT_PIXMAPS:
  290.     XA_SHOW_PIXMAPS(act);
  291.     break;
  292.  
  293.        /* Act upon IFF Color Cycling chunk.  */
  294.      case ACT_CYCLE:
  295.     {
  296.       /* if there is a new_chdr, install it, not the old one */
  297.       /*
  298.         * XA_CHDR *the_chdr;
  299.        * if (act->chdr->new_chdr) the_chdr = act->chdr->new_chdr;
  300.        * else the_chdr = act->chdr;
  301.        */
  302.  
  303.       if (   (cmap_play_nice == xaFALSE) 
  304.          && (x11_display_type & XA_X11_CMAP)
  305.          && (xa_anim_flags & ANIM_CYCLE) )
  306.       {
  307.         ACT_CYCLE_HDR *act_cycle;
  308.         act_cycle = (ACT_CYCLE_HDR *)act->data;
  309.  
  310.         DEBUG_LEVEL2 fprintf(stderr,"ACT_CYCLE:\n");
  311.         if ( !(act_cycle->flags & ACT_CYCLE_STARTED) )
  312.         {
  313.           if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  314.             XA_Install_CMAP(act->chdr);
  315.           xa_cycle_cnt++;
  316.           act_cycle->flags |= ACT_CYCLE_STARTED;
  317.           xa_now_cycling = xaTRUE;
  318.           XtAppAddTimeOut(theContext,(int)(act_cycle->rate), 
  319.         (XtTimerCallbackProc)XA_Cycle_It, (XtPointer)(act_cycle));
  320.         }
  321.       }
  322.     } /*POD*/
  323.     break;
  324.  
  325.      case ACT_DELTA:        
  326.     XA_SHOW_DELTA(act);
  327.     break;
  328.  
  329.      default:    fprintf(stderr,"Unknown not supported %x\n",act->type);
  330.   } /* end of switch of action type */
  331. }
  332.  
  333.  
  334. /***************************************************** 
  335.  * XA_SHOW_IMAGE
  336.  *
  337.  *****************************************************/
  338. void XA_SHOW_IMAGE(act,im_xpos,im_ypos,im_xsize,im_ysize,flag)
  339. XA_ACTION *act;
  340. xaULONG im_xpos,im_ypos;
  341. xaULONG im_xsize,im_ysize;
  342. xaULONG flag;        /* override flag 0 normal 1 use pos/size */
  343. {
  344.   Pixmap pix_map = 0;
  345.   ACT_IMAGE_HDR *act_im_hdr;
  346.  
  347.   DEBUG_LEVEL2 fprintf(stderr,"ACT_IMAGE:\n");
  348.  
  349.   act_im_hdr = (ACT_IMAGE_HDR *)(act->data);
  350.   if (flag==0)
  351.   { im_xpos = act_im_hdr->xpos;
  352.     im_ypos = act_im_hdr->ypos;
  353.     im_xsize = act_im_hdr->xsize;
  354.     im_ysize = act_im_hdr->ysize;
  355.   }
  356.  
  357.   if (xa_need_to_scale_b)
  358.   { xaUBYTE *tmp_pic;
  359.     xaULONG xp,yp,xsize,ysize;
  360.  
  361.     if(act_im_hdr->clip)
  362.     {
  363.       xsize = im_xsize;    ysize = im_ysize;
  364.       xp = im_xpos;    yp = im_ypos;
  365.       tmp_pic = UTIL_Scale_Bitmap(0,act_im_hdr->clip,im_xsize,im_ysize,
  366.         (X11_Get_Bitmap_Width(xsize)/8),xa_buff_x,xa_buff_y,
  367.         xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,X11_LSB,X11_LSB);
  368.       if (tmp_pic)
  369.       {
  370.         pix_map = XCreatePixmapFromBitmapData(theDisp,mainW,(char *)tmp_pic,
  371.               X11_Get_Bitmap_Width(xsize),ysize,0x01,0x00,1);
  372.         XSetClipMask(theDisp,theGC,pix_map);
  373.         XSetClipOrigin(theDisp,theGC,xp,yp);
  374.       }
  375.       else pix_map = 0;
  376.     }
  377.  
  378.     xp = im_xpos;    yp = im_ypos;
  379.     if (x11_display_type == XA_MONOCHROME)
  380.       tmp_pic = UTIL_Scale_Bitmap(0,act_im_hdr->image->data,
  381.             im_xsize,im_ysize, act_im_hdr->image->bytes_per_line,
  382.             xa_buff_x,xa_buff_y, xa_disp_x,xa_disp_y,
  383.             &xp,&yp,&xsize,&ysize,x11_bit_order,x11_bit_order);
  384.     else    tmp_pic = UTIL_Scale_Mapped(0,act_im_hdr->image->data,
  385.            0,0, im_xsize, im_ysize, act_im_hdr->image->bytes_per_line,
  386.            xa_buff_x,xa_buff_y,xa_disp_x,xa_disp_y,
  387.            x11_bytes_pixel,&xp,&yp,&xsize,&ysize,0);
  388.     if (tmp_pic)
  389.     {
  390.       theImage->data = (char *)tmp_pic;
  391.         
  392.       X11_Init_Image_Struct(theImage,xsize,ysize);
  393.       if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  394.         XA_Install_CMAP(act->chdr);
  395.       XPutImage(theDisp,mainW,theGC,theImage,0,0,xp,yp,xsize,ysize);
  396.     }
  397.     if(act_im_hdr->clip) XSetClipMask(theDisp,theGC,None);
  398.   }
  399.   else /* Not scaling Image */
  400.   {
  401.     if(act_im_hdr->clip)
  402.     {
  403.       pix_map = XCreatePixmapFromBitmapData(theDisp,mainW,
  404.                 (char *)act_im_hdr->clip,
  405.                 X11_Get_Bitmap_Width(im_xsize),im_ysize,0x01,0x00,1);
  406.       XSetClipMask(theDisp,theGC,pix_map);
  407.       XSetClipOrigin(theDisp,theGC,im_xpos,im_ypos);
  408.     }
  409.     if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  410.         XA_Install_CMAP(act->chdr);
  411.     XPutImage(theDisp,mainW,theGC,act_im_hdr->image, 0, 0,
  412.         im_xpos,  im_ypos, im_xsize, im_ysize  );
  413.     if (act_im_hdr->clip)
  414.     {
  415.       XSetClipMask(theDisp,theGC,None);
  416.       XFreePixmap(theDisp,pix_map);
  417.     }
  418.   }
  419.   AUD_SYNC_CHECK();
  420. }
  421.  
  422.  
  423. /***************************************************** 
  424.  * XA_SHOW_PIXMAP
  425.  *
  426.  *****************************************************/
  427. void XA_SHOW_PIXMAP(act,pm_xpos,pm_ypos,pm_xsize,pm_ysize,flag)
  428. XA_ACTION *act;
  429. xaULONG pm_xpos,pm_ypos;
  430. xaULONG pm_xsize,pm_ysize;
  431. xaULONG flag;        /* 0 normal 1 use pos/size */
  432. {
  433.   ACT_PIXMAP_HDR *act_pm_hdr;
  434.  
  435.   DEBUG_LEVEL2 fprintf(stderr,"ACT_PIXMAP:\n");
  436.   act_pm_hdr = (ACT_PIXMAP_HDR *)(act->data);
  437.   if (flag==0)
  438.   { pm_xpos = act_pm_hdr->xpos;
  439.     pm_ypos = act_pm_hdr->ypos;
  440.     pm_xsize = act_pm_hdr->xsize;
  441.     pm_ysize = act_pm_hdr->ysize;
  442.   }
  443.   if (xa_need_to_scale_b)
  444.   {
  445.     Pixmap pix_map;
  446.     XImage *t_image,*p_image;
  447.     xaUBYTE *tmp_pic;
  448.     xaULONG xp,yp,xsize,ysize;
  449.  
  450.     if (act_pm_hdr->clip)
  451.     {
  452.       xp = pm_xpos;      yp = pm_ypos;
  453.       xsize = pm_xsize;  ysize = pm_ysize;
  454.       p_image = XGetImage(theDisp,act_pm_hdr->clip,0,0,xsize,ysize,1,XYPixmap);
  455.       tmp_pic = UTIL_Scale_Bitmap(0,p_image->data, xsize,ysize,
  456.         p_image->bytes_per_line,xa_buff_x,xa_buff_y,
  457.                 xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  458.                     x11_bit_order,X11_LSB);
  459.       if (tmp_pic)
  460.       {
  461.         pix_map = XCreatePixmapFromBitmapData(theDisp,mainW,
  462.                 (char *)tmp_pic, X11_Get_Bitmap_Width(xsize),
  463.                 ysize,0x01,0x00,1);
  464.         XSetClipMask(theDisp,theGC,pix_map);
  465.         XSetClipOrigin(theDisp,theGC,xp,yp);
  466.       } else pix_map = 0;
  467.     }
  468.  
  469.     xp = pm_xpos;    yp = pm_ypos;
  470.     xsize = pm_xsize;    ysize = pm_ysize;
  471.     t_image = XGetImage(theDisp,act_pm_hdr->pixmap,0,0,xsize,ysize,
  472.                 AllPlanes,ZPixmap);
  473.     if (x11_display_type == XA_MONOCHROME)
  474.     {
  475.       t_image = XGetImage(theDisp,act_pm_hdr->pixmap,0,0,xsize,ysize,
  476.                 1,XYPixmap);
  477.       tmp_pic = UTIL_Scale_Bitmap(0,t_image->data,
  478.                 xsize,ysize,t_image->bytes_per_line,xa_buff_x,xa_buff_y,
  479.                 xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  480.                     x11_bit_order,x11_bit_order);
  481.     }
  482.     else
  483.     {
  484.       t_image = XGetImage(theDisp,act_pm_hdr->pixmap,0,0,xsize,ysize,
  485.                 AllPlanes,ZPixmap);
  486.       tmp_pic = UTIL_Scale_Mapped(0,t_image->data,
  487.                    0,0, xsize, ysize, t_image->bytes_per_line,
  488.                    xa_buff_x,xa_buff_y,xa_disp_x,xa_disp_y,
  489.                    x11_bytes_pixel,&xp,&yp,&xsize,&ysize,0);
  490.     }
  491.     if (tmp_pic) /* if image to draw */
  492.     {
  493.       theImage->data = (char *)tmp_pic;
  494.       X11_Init_Image_Struct(theImage,xsize,ysize);
  495.       if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  496.           XA_Install_CMAP(act->chdr);
  497.       XPutImage(theDisp,mainW,theGC,theImage,0,0,xp,yp,xsize,ysize);
  498.     }
  499.     if (act_pm_hdr->clip) 
  500.     {
  501.       XSetClipMask(theDisp,theGC,None);
  502.       XDestroyImage(p_image);
  503.       if (pix_map) XFreePixmap(theDisp,pix_map);
  504.     }
  505.     XDestroyImage(t_image);
  506.     AUD_SYNC_CHECK();
  507.   }
  508.   else /* no rescale */
  509.   {
  510.     if (act_pm_hdr->clip)
  511.     {
  512.       XSetClipMask(theDisp,theGC,act_pm_hdr->clip);
  513.       XSetClipOrigin(theDisp,theGC,pm_xpos,pm_ypos);
  514.       XSetPlaneMask(theDisp,theGC,AllPlanes);
  515.     }
  516.     if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  517.         XA_Install_CMAP(act->chdr);
  518.     XCopyArea(theDisp,act_pm_hdr->pixmap,mainW,theGC, 0, 0, 
  519.         pm_xsize, pm_ysize, pm_xpos,  pm_ypos   );
  520.     AUD_SYNC_CHECK();
  521.     if (act_pm_hdr->clip) XSetClipMask(theDisp,theGC,None);
  522.   }
  523. }
  524.  
  525. /***************************************************** 
  526.  * XA_SHOW_IMAGES
  527.  *
  528.  *****************************************************/
  529. void XA_SHOW_IMAGES(act)
  530. XA_ACTION *act;
  531. {
  532.   ACT_SETTER_HDR *act_ims_hdr;
  533.   ACT_PIXMAP_HDR *work_pm_hdr;
  534.   Pixmap work;
  535.   ACT_IMAGE_HDR *back_im_hdr;
  536.   XImage *back;
  537.   xaLONG xpback,ypback;
  538.  
  539.   DEBUG_LEVEL2 fprintf(stderr,"ACT_SETTERS: im\n");
  540.   act_ims_hdr = (ACT_SETTER_HDR *)(act->data);
  541.  
  542.   /* work still needs to be PIXMAP */
  543.   if (act_ims_hdr->work->type != ACT_PIXMAP)
  544.         XA_Image_To_Pixmap(act_ims_hdr->work);
  545.   work_pm_hdr = (ACT_PIXMAP_HDR *)act_ims_hdr->work->data;
  546.   work = work_pm_hdr->pixmap;
  547.  
  548.   back_im_hdr = (ACT_IMAGE_HDR *)act_ims_hdr->back->data;
  549.   back = back_im_hdr->image;
  550.  
  551.   /* copy backgrnd into work area */
  552.   xpback = act_ims_hdr->xpback;
  553.   ypback = act_ims_hdr->ypback;
  554.   {
  555.     xaLONG xback,yback;
  556.     xaLONG xlen,ylen,xlen1,ylen1;
  557.  
  558.     xback = act_ims_hdr->xback;
  559.     yback = act_ims_hdr->yback;
  560.     xlen = xback - xpback;
  561.     ylen = yback - ypback;
  562.     if (xlen >= xa_buff_x) xlen1 = 0;
  563.     else xlen1 = xa_buff_x - xlen;
  564.     if (ylen >= xa_buff_y) ylen1 = 0;
  565.     else ylen1 = xa_buff_y - ylen;
  566.  
  567.     if (xlen1 == 0)
  568.     { 
  569.       if (ylen1 == 0)
  570.       {
  571.         XPutImage(theDisp, work, theGC, back,
  572.               xpback,ypback,0,0,xa_buff_x,xa_buff_y );
  573.       }
  574.       else
  575.       {
  576.         XPutImage(theDisp, work, theGC, back,
  577.                 xpback,ypback,0,   0, xa_buff_x,ylen);
  578.         XPutImage(theDisp, work, theGC, back,
  579.               xpback,    0, 0,ylen, xa_buff_x,ylen1);
  580.       }
  581.     }
  582.     else /* xlen1 != 0 */
  583.     { 
  584.       if (ylen1 == 0)
  585.       {
  586.         XPutImage(theDisp, work, theGC, back,
  587.               xpback,ypback,0,   0,xlen ,xa_buff_y);
  588.         XPutImage(theDisp, work, theGC, back,
  589.                   0,ypback,xlen, 0,xlen1,xa_buff_y);
  590.       }
  591.       else
  592.       {
  593.         XPutImage(theDisp, work, theGC, back,
  594.               xpback,ypback,    0,    0,  xlen,  ylen);
  595.         XPutImage(theDisp, work, theGC, back,
  596.                   0,    0, xlen, ylen, xlen1, ylen1);
  597.         XPutImage(theDisp, work, theGC, back,
  598.                   0,ypback, xlen,    0, xlen1,  ylen);
  599.         XPutImage(theDisp, work, theGC, back,
  600.               xpback,    0,    0, ylen,  xlen, ylen1);
  601.       }
  602.     }
  603.   }
  604.  
  605.   /* loop through face pixmaps */
  606.   while(act_ims_hdr != 0)
  607.   {
  608.     ACT_IMAGE_HDR *face_im_hdr;
  609.     Pixmap pix_map = 0;
  610.  
  611.     face_im_hdr = (ACT_IMAGE_HDR *)act_ims_hdr->face->data;
  612.     if (face_im_hdr->clip)
  613.     {
  614.       pix_map = XCreatePixmapFromBitmapData(theDisp,mainW,
  615.                 (char *)face_im_hdr->clip,
  616.                 X11_Get_Bitmap_Width(face_im_hdr->xsize),face_im_hdr->ysize,
  617.                 0x01,0x00,1);
  618.       XSetClipMask(theDisp,theGC,pix_map);
  619.       XSetClipOrigin(theDisp,theGC,
  620.         act_ims_hdr->xpface,act_ims_hdr->ypface);
  621.     }
  622.     XPutImage(theDisp, work, theGC,face_im_hdr->image,
  623.           0, 0, act_ims_hdr->xpface,  act_ims_hdr->ypface,
  624.                 act_ims_hdr->xface, act_ims_hdr->yface    );
  625.  
  626.     if(face_im_hdr->clip)
  627.     {
  628.       XSetClipMask(theDisp,theGC,None);
  629.       XFreePixmap(theDisp,pix_map);
  630.     }
  631.     act_ims_hdr = act_ims_hdr->next;
  632.   }
  633.  
  634.   if (xa_need_to_scale_b)
  635.   {
  636.     XImage *t_image;
  637.     xaULONG xp,yp,xsize,ysize;
  638.     xaUBYTE *tmp_pic;
  639.     xp = yp = 0; xsize = xa_buff_x; ysize = xa_buff_y;
  640.     if (x11_display_type == XA_MONOCHROME)
  641.     {
  642.       t_image=XGetImage(theDisp,work,0,0,xsize,ysize,1,XYPixmap);
  643.       tmp_pic = UTIL_Scale_Bitmap(0,t_image->data,
  644.                 xsize,ysize,t_image->bytes_per_line,xa_buff_x,xa_buff_y,
  645.                 xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  646.                     x11_bit_order,x11_bit_order);
  647.     }
  648.     else
  649.     {
  650.       t_image=XGetImage(theDisp,work,0,0,xsize,ysize,AllPlanes,ZPixmap);
  651.       tmp_pic = UTIL_Scale_Mapped(0,t_image->data,
  652.                    0,0, xsize, ysize, t_image->bytes_per_line,
  653.                    xa_buff_x,xa_buff_y,xa_disp_x,xa_disp_y,
  654.                    x11_bytes_pixel,&xp,&yp,&xsize,&ysize,0);
  655.     }
  656.     if (tmp_pic)
  657.     {
  658.       theImage->data = (char *)tmp_pic;
  659.       X11_Init_Image_Struct(theImage,xsize,ysize);
  660.       if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  661.                   XA_Install_CMAP(act->chdr);
  662.       XPutImage(theDisp,mainW,theGC,theImage,0,0,xp,yp,xsize,ysize);
  663.     }
  664.     XDestroyImage(t_image);
  665.   }
  666.   else /* not scaling */
  667.   {
  668.     if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  669.         XA_Install_CMAP(act->chdr);
  670.     XCopyArea(theDisp,work,mainW,theGC,0,0,xa_disp_x,xa_disp_y,0, 0);
  671.   }
  672.   AUD_SYNC_CHECK();
  673. }
  674.  
  675. /***************************************************** 
  676.  * XA_SHOW_PIXMAPS
  677.  *
  678.  *****************************************************/
  679. void XA_SHOW_PIXMAPS(act)
  680. XA_ACTION *act;
  681. {
  682.   ACT_SETTER_HDR *act_pms_hdr;
  683.   ACT_PIXMAP_HDR *back_pm_hdr,*work_pm_hdr;
  684.   Pixmap work,back;
  685.   xaLONG xpback,ypback;
  686.  
  687.   DEBUG_LEVEL2 fprintf(stderr,"ACT_SETTERS:\n");
  688.   act_pms_hdr = (ACT_SETTER_HDR *)(act->data);
  689.  
  690.   if (act_pms_hdr->back->type != ACT_PIXMAP)
  691.         XA_Image_To_Pixmap(act_pms_hdr->back);
  692.   if (act_pms_hdr->work->type != ACT_PIXMAP)
  693.         XA_Image_To_Pixmap(act_pms_hdr->work);
  694.   back_pm_hdr = (ACT_PIXMAP_HDR *)act_pms_hdr->back->data;
  695.   work_pm_hdr = (ACT_PIXMAP_HDR *)act_pms_hdr->work->data;
  696.   back = back_pm_hdr->pixmap;
  697.   work = work_pm_hdr->pixmap;
  698.  
  699.   /* copy backgrnd into work area */
  700.   xpback = act_pms_hdr->xpback;
  701.   ypback = act_pms_hdr->ypback;
  702.   {
  703.     xaLONG xback,yback;
  704.     xaLONG xlen,ylen,xlen1,ylen1;
  705.  
  706.     xback = act_pms_hdr->xback;
  707.     yback = act_pms_hdr->yback;
  708.     xlen = xback - xpback;
  709.     ylen = yback - ypback;
  710.     if (xlen >= xa_buff_x) xlen1 = 0;
  711.     else xlen1 = xa_buff_x - xlen;
  712.     if (ylen >= xa_buff_y) ylen1 = 0;
  713.     else ylen1 = xa_buff_y - ylen;
  714.  
  715.     if (xlen1 == 0)
  716.     { 
  717.       if (ylen1 == 0)
  718.       {
  719.         XCopyArea(theDisp, back, work, theGC,
  720.               xpback,ypback,xa_buff_x,xa_buff_y,0,0);
  721.       }
  722.       else
  723.       {
  724.         XCopyArea(theDisp, back, work, theGC,
  725.               xpback,ypback,xa_buff_x,ylen ,0,   0);
  726.         XCopyArea(theDisp, back, work, theGC,
  727.               xpback,    0,xa_buff_x,ylen1,0,ylen);
  728.       }
  729.     }
  730.     else /* xlen1 != 0 */
  731.     { 
  732.       if (ylen1 == 0)
  733.       {
  734.         XCopyArea(theDisp, back, work, theGC,
  735.               xpback,ypback,xlen ,xa_buff_y,0,   0);
  736.         XCopyArea(theDisp, back, work, theGC,
  737.                   0,ypback,xlen1,xa_buff_y,xlen,0);
  738.       }
  739.       else
  740.       {
  741.         XCopyArea(theDisp, back, work, theGC,
  742.               xpback,ypback,  xlen,  ylen,    0,    0);
  743.         XCopyArea(theDisp, back, work, theGC,
  744.                   0,    0, xlen1, ylen1, xlen, ylen);
  745.         XCopyArea(theDisp, back, work, theGC,
  746.                   0,ypback, xlen1,  ylen, xlen,    0);
  747.         XCopyArea(theDisp, back, work, theGC,
  748.               xpback,    0,  xlen, ylen1,    0, ylen);
  749.       }
  750.     }
  751.   }
  752.  
  753.     /* loop through face pixmaps */
  754.   while(act_pms_hdr != 0)
  755.   {
  756.     xaULONG ret;
  757.     ACT_PIXMAP_HDR *face_pm_hdr;
  758.  
  759.     if (act_pms_hdr->face->type != ACT_PIXMAP)
  760.                 ret = XA_Image_To_Pixmap(act_pms_hdr->face);
  761.     face_pm_hdr = (ACT_PIXMAP_HDR *)act_pms_hdr->face->data;
  762.     if (face_pm_hdr->clip)
  763.     {
  764.       XSetClipMask(theDisp,theGC,face_pm_hdr->clip);
  765.       XSetClipOrigin(theDisp,theGC,
  766.         act_pms_hdr->xpface,act_pms_hdr->ypface);
  767.     }
  768.  
  769.     XCopyArea(theDisp,
  770.           face_pm_hdr->pixmap, work, theGC,
  771.           0, 0, 
  772.           act_pms_hdr->xface, act_pms_hdr->yface,
  773.           act_pms_hdr->xpface,  act_pms_hdr->ypface   );
  774.     if (face_pm_hdr->clip) XSetClipMask(theDisp,theGC,None);
  775.     act_pms_hdr = act_pms_hdr->next;
  776.   }
  777.  
  778.   if (xa_need_to_scale_b)
  779.   {
  780.     XImage *t_image;
  781.     xaULONG xp,yp,xsize,ysize;
  782.     xaUBYTE *tmp_pic;
  783.     xp = yp = 0; xsize = xa_buff_x; ysize = xa_buff_y;
  784.     if (x11_display_type == XA_MONOCHROME)
  785.     {
  786.       t_image=XGetImage(theDisp,work,0,0,xsize,ysize,1,XYPixmap);
  787.       tmp_pic = UTIL_Scale_Bitmap(0,t_image->data,
  788.                 xsize,ysize,t_image->bytes_per_line,xa_buff_x,xa_buff_y,
  789.                 xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  790.                     x11_bit_order,x11_bit_order);
  791.     }
  792.     else
  793.     {
  794.       t_image=XGetImage(theDisp,work,0,0,xsize,ysize,AllPlanes,ZPixmap);
  795.       tmp_pic = UTIL_Scale_Mapped(0,t_image->data,
  796.                    0,0, xsize, ysize, t_image->bytes_per_line,
  797.                    xa_buff_x,xa_buff_y,xa_disp_x,xa_disp_y,
  798.                    x11_bytes_pixel,&xp,&yp,&xsize,&ysize,0);
  799.     }
  800.     if (tmp_pic)
  801.     {
  802.       theImage->data = (char *)tmp_pic;
  803.       X11_Init_Image_Struct(theImage,xsize,ysize);
  804.       if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  805.                   XA_Install_CMAP(act->chdr);
  806.       XPutImage(theDisp,mainW,theGC,theImage,0,0,xp,yp,xsize,ysize);
  807.     }
  808.     XDestroyImage(t_image);
  809.   }
  810.   else
  811.   {
  812.     if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  813.         XA_Install_CMAP(act->chdr);
  814.     XCopyArea(theDisp,work,mainW,theGC,0,0,xa_disp_x,xa_disp_y,0, 0);
  815.   }
  816.   AUD_SYNC_CHECK();
  817. }
  818.  
  819.  
  820. /***************************************************** 
  821.  * XA_SHOW_DELTA
  822.  *
  823.  *****************************************************/
  824. void XA_SHOW_DELTA(act)
  825. XA_ACTION *act;
  826.   ACT_DLTA_HDR *dlta_hdr = (ACT_DLTA_HDR *)act->data;
  827.   xaULONG xsrc,ysrc,xdst,ydst,xsize,ysize,*remap_map;
  828.   xaULONG xbuff,ybuff,map_flag,dith_flag,dlta_flag;
  829.   XA_CHDR *the_chdr;
  830.   char *the_pic;
  831.   xaULONG no_shared;
  832.   XA_DEC_INFO  *dec_info  = &xa_dec_info;
  833.   XA_DEC2_INFO *dec2_info = &xa_dec2_info;
  834.  
  835.   no_shared = 0;
  836.   if (cmap_dither_type == CMAP_DITHER_FLOYD) dith_flag = xaTRUE;
  837.   else dith_flag = xaFALSE; 
  838.  
  839.   if (act->chdr == 0)    /* NOP */ return;
  840.   /* if there is a new_chdr, install it, not the old one */
  841.   else if (act->chdr->new_chdr) 
  842.   {
  843.     if (   (x11_display_type & XA_X11_TRUE)
  844.     || (x11_kludge_1 == xaTRUE)
  845.     || (x11_bytes_pixel != 1)      ) map_flag = xaTRUE;
  846.     /* if dithering and new_chdr then don't remap while decoding */
  847.     else if (dith_flag)  map_flag = xaFALSE;
  848.     else map_flag = xaTRUE;
  849.     the_chdr = act->chdr->new_chdr;
  850.   }
  851.   else 
  852.   {
  853.     /* remap to larger pixel size NOTE: all anim are 1 byte */
  854.     if (   (x11_display_type & XA_X11_TRUE)
  855.     || (x11_kludge_1 == xaTRUE)
  856.     || (x11_bytes_pixel != 1)      ) map_flag = xaTRUE;
  857.     else map_flag = xaFALSE;
  858.     dith_flag = xaFALSE;
  859.     the_chdr = act->chdr;
  860.   }
  861.   remap_map = act->chdr->map;
  862.  
  863.   if (dlta_hdr->xapi_rev == 0x0001)
  864.   { dec_info->imagex    = xa_imagex;
  865.     dec_info->imagey    = xa_imagey;
  866.     dec_info->imaged    = xa_imaged;
  867.     dec_info->chdr    = act->chdr;
  868.     dec_info->map_flag    = map_flag;
  869.     dec_info->map    = remap_map;
  870.     dec_info->special    = dlta_hdr->special;
  871.     dec_info->extra    = dlta_hdr->extra;
  872.  
  873.     if (xa_skip_video == 0) { xa_skip_cnt = 0; dec_info->skip_flag = 0; }
  874.     else { if (xa_skip_cnt < XA_SKIP_MAX) dec_info->skip_flag= xa_skip_video;
  875.        else { xa_skip_cnt = 0; dec_info->skip_flag = 0; } }
  876.  
  877.     the_pic = xa_pic; xbuff = xa_imagex; ybuff = xa_imagey;
  878.     if ((xa_vid_fd >= 0) && (!(dlta_hdr->flags & DLTA_DATA)) )
  879.     { int ret = XA_Read_Delta(xa_vidcodec_buf, xa_vid_fd,
  880.                     dlta_hdr->fpos, dlta_hdr->fsize);
  881.       /* if read fails */
  882.       if (ret == xaFALSE) dlta_flag = ACT_DLTA_NOP;
  883.       else dlta_flag = dlta_hdr->delta(the_pic,xa_vidcodec_buf,
  884.                     dlta_hdr->fsize,dec_info);
  885.     }
  886.     else
  887.     { dlta_flag = dlta_hdr->delta(the_pic,dlta_hdr->data,
  888.                     dlta_hdr->fsize,dec_info);
  889.     }
  890.     if ( (dlta_flag == ACT_DLTA_DROP) || (dec_info->skip_flag > 0) )
  891.     { xa_skip_cnt++; xa_frames_skipd++; return; }
  892.   } /* End of XAPI_REV 0x0001 */
  893.   else if (dlta_hdr->xapi_rev == 0x0002)
  894.   { dec2_info->imagex    = xa_imagex;
  895.     dec2_info->imagey    = xa_imagey;
  896.     dec2_info->imaged    = xa_imaged;
  897.     dec2_info->chdr    = act->chdr;
  898.     dec2_info->map_flag    = map_flag;
  899.     dec2_info->map    = remap_map;
  900.     dec2_info->special    = dlta_hdr->special;
  901.     dec2_info->extra    = dlta_hdr->extra;
  902.     dec2_info->tmp1 = dec2_info->tmp2 = dec2_info->tmp3 = dec2_info->tmp4 = 0;
  903.     dec2_info->bytes_pixel    = x11_bytes_pixel;
  904.     dec2_info->image_type = XA_Get_Image_Type( dlta_hdr->special,
  905.                             act->chdr,map_flag);
  906. /* POD or in dither and cf4 into special */
  907.     if (xa_dither_flag)    dec2_info->special |= XA_DEC_SPEC_DITH;
  908. /* XA_DEC_SPEC_CF4 */
  909.  
  910.     if (xa_skip_video == 0) { xa_skip_cnt = 0; dec2_info->skip_flag = 0; }
  911.     else { if (xa_skip_cnt < XA_SKIP_MAX) dec2_info->skip_flag= xa_skip_video;
  912.        else { xa_skip_cnt = 0; dec2_info->skip_flag = 0; } }
  913.  
  914.     the_pic = xa_pic; xbuff = xa_imagex; ybuff = xa_imagey;
  915.     if ((xa_vid_fd >= 0) && (!(dlta_hdr->flags & DLTA_DATA)) )
  916.     { int ret = XA_Read_Delta(xa_vidcodec_buf, xa_vid_fd,
  917.                     dlta_hdr->fpos, dlta_hdr->fsize);
  918.       /* if read fails */
  919.       if (ret == xaFALSE) dlta_flag = ACT_DLTA_NOP;
  920.       else dlta_flag = dlta_hdr->delta(the_pic,xa_vidcodec_buf,
  921.                     dlta_hdr->fsize,dec2_info);
  922.     }
  923.     else
  924.     { dlta_flag = dlta_hdr->delta(the_pic,dlta_hdr->data,
  925.                     dlta_hdr->fsize,dec2_info);
  926.     }
  927.     if ( (dlta_flag == ACT_DLTA_DROP) || (dec2_info->skip_flag > 0) )
  928.     { xa_skip_cnt++; xa_frames_skipd++; return; }
  929.   } /* End of XAPI_REV 0x0001 */
  930.   else /* Start of XAPI_REV 0x0000 */
  931.   {
  932. fprintf(stderr,"WHO USES THIS???\n");
  933.      dlta_flag = ACT_DLTA_NOP;
  934.   } /* End of XAPI_REV 0x0000 */
  935.  
  936.  
  937.   if (x11_expose_flag == xaTRUE) { x11_expose_flag = xaFALSE;
  938.         xsrc = ysrc = 0; xsize = xbuff; ysize = ybuff; }
  939.   else if (dlta_flag & ACT_DLTA_NOP) { act->type = ACT_NOP; return; }
  940.   else if (dlta_hdr->xapi_rev == 0x0001)
  941.   { xsrc = dec_info->xs;    ysrc = dec_info->ys; 
  942.     xsize = dec_info->xe;    ysize = dec_info->ye;
  943.   }
  944.   else if (dlta_hdr->xapi_rev == 0x0002)
  945.   { xsrc = dec2_info->xs;    ysrc = dec2_info->ys; 
  946.     xsize = dec2_info->xe;    ysize = dec2_info->ye;
  947.   }
  948.  
  949.   if (dlta_flag & ACT_DLTA_BODY)
  950.   {
  951.     if (im_buff0 && (im_buff0 != the_pic) )
  952.         memcpy((char *)im_buff0, (char *)the_pic, xa_image_size);
  953.     if (im_buff1 && (im_buff1 != the_pic) )
  954.         memcpy((char *)im_buff1, (char *)the_pic, xa_image_size);
  955.     xsize = dlta_hdr->xsize; ysize = dlta_hdr->ysize;
  956.     xa_image_size = xa_imagex * xa_imagey;
  957.     IFF_Init_DLTA_HDR(xsize,ysize);
  958.   }
  959.   if (xa_anim_flags & ANIM_DBL_BUF)
  960.   {
  961.     IFF_Update_DLTA_HDR(&xsrc,&ysrc,&xsize,&ysize);
  962.     xa_pic = (xa_pic==im_buff0)?im_buff1:im_buff0;
  963.     /* With Double Buffering we don't want any NOP's generated */
  964.     if (xsize == xsrc) { xsrc = ysrc = 0; xsize = 8; ysize = 1; }
  965.   } 
  966.  
  967.   /* convert min/max to pos/size */
  968.   xsize -= xsrc;    ysize -= ysrc;
  969.   xdst = xsrc; ydst = ysrc;
  970.  
  971.   if (xa_anim_flags & ANIM_HAM)
  972.   {
  973.     xsize =  4*((xsize+3)/4); /* PODTEST */
  974.     if (xa_anim_flags & ANIM_HAM6) IFF_Buffer_HAM6(im_buff2,the_pic,
  975.         act->chdr,act->h_cmap,xsize,ysize,xsrc,ysrc,xbuff,xaTRUE);
  976.     else             IFF_Buffer_HAM8(im_buff2,the_pic,
  977.         act->chdr,act->h_cmap,xsize,ysize,xsrc,ysrc,xbuff,xaTRUE);
  978.     the_pic = im_buff2;
  979. #ifdef XSHM
  980.     if (shm) { sh_Image = im2_Image; }
  981. #endif
  982.     dlta_flag |= ACT_DLTA_MAPD;
  983.     xsrc = ysrc = 0; xbuff = xsize; ybuff = ysize;
  984.   }
  985.  
  986.   if (x11_display_type == XA_MONOCHROME)
  987.   { no_shared = 1;
  988.     if (xa_need_to_scale_u)
  989.     {
  990.       xaUBYTE *tmp_pic;
  991.       xaULONG line_size;
  992.       tmp_pic = UTIL_Scale_Mapped(0,the_pic,0,0,
  993.             xbuff,ybuff, xbuff,
  994.             xa_imagex,xa_imagey, xa_disp_x,xa_disp_y,
  995.             x11_bytes_pixel,&xdst,&ydst,&xsize,&ysize,0);
  996.       if (tmp_pic == 0) return; /* NOP */
  997.       line_size = X11_Get_Line_Size(xsize);
  998.       UTIL_Mapped_To_Bitmap(tmp_pic,tmp_pic,act->chdr,0,0,
  999.             xsize,ysize,xsize,ysize,line_size);
  1000.       xsrc = ysrc = 0;
  1001.       theImage->data = (char *)tmp_pic;
  1002.       X11_Init_Image_Struct(theImage,xsize,ysize);
  1003.     } /* end of scale */
  1004.     else
  1005.     {
  1006.       xaULONG line_size,tsize;
  1007.       tsize = ysize * X11_Get_Line_Size(xsize);
  1008.       XA_REALLOC(xa_disp_buff,xa_disp_buff_size,tsize);
  1009.       line_size = X11_Get_Line_Size(xbuff);
  1010.       UTIL_Mapped_To_Bitmap(xa_disp_buff,the_pic,act->chdr,
  1011.             xsrc,ysrc,xsize,ysize,xbuff,ybuff,line_size);
  1012.       xsrc = ysrc = 0;
  1013.       theImage->data = xa_disp_buff;
  1014.       X11_Init_Image_Struct(theImage,xsize,ysize);
  1015.     }
  1016.   } /* end of mono */
  1017.   else
  1018.   {
  1019.     if (dith_flag == xaTRUE) /* map here if dithering is on */
  1020.     {
  1021.       if (cmap_dither_type == CMAP_DITHER_FLOYD)
  1022.       {
  1023.         UTIL_Mapped_To_Floyd(im_buff2,the_pic,
  1024.                   act->chdr->new_chdr,act->chdr,xsrc,ysrc,
  1025.             xsize,ysize,xbuff,ybuff);
  1026.         xsrc = ysrc = 0; xbuff = xsize; ybuff = ysize;
  1027.         the_pic = im_buff2;    dlta_flag |= ACT_DLTA_MAPD;
  1028. #ifdef XSHM
  1029.         if (shm) 
  1030.         { sh_Image = im2_Image; 
  1031.           X11_Init_Image_Struct(im2_Image,xbuff,ybuff);
  1032.         }
  1033. #endif
  1034.       }
  1035.     } /* end of dither */
  1036.  
  1037.     if (xa_need_to_scale_u)
  1038.     {
  1039.       XA_CHDR *tmp_chdr;
  1040.       xaUBYTE *tmp_pic;
  1041.       no_shared = 1;
  1042.       if ((map_flag==xaTRUE) && (!(dlta_flag & ACT_DLTA_MAPD)) )
  1043.                 tmp_chdr = act->chdr;
  1044.       else tmp_chdr = 0;
  1045.       tmp_pic = UTIL_Scale_Mapped(0,the_pic,xsrc,ysrc,
  1046.               xsize,ysize,X11_Get_Line_Size(xbuff),
  1047.               xa_imagex,xa_imagey,xa_disp_x,xa_disp_y,
  1048.               x11_bytes_pixel,&xdst,&ydst,&xsize,&ysize,tmp_chdr);
  1049.       if (tmp_pic==0) return; /*NOP*/
  1050.       xsrc = ysrc = 0;
  1051.       theImage->data = (char *)tmp_pic;
  1052.       xbuff = xsize; ybuff = ysize;
  1053.     } /* end of scaling */
  1054.     else /* no scaling */
  1055.     {
  1056.       if (   ((x11_bytes_pixel > 1) && (!(dlta_flag & ACT_DLTA_MAPD)))
  1057.             || ((map_flag==xaTRUE) && (!(dlta_flag & ACT_DLTA_MAPD)))     )
  1058.       {
  1059.         xaULONG tsize = (xsize) * (ysize) * x11_bytes_pixel;
  1060.         XA_REALLOC(xa_disp_buff,xa_disp_buff_size,tsize);
  1061.         UTIL_Mapped_To_Mapped(xa_disp_buff,the_pic,act->chdr,
  1062.             xsrc,ysrc,xsize,ysize,xbuff,ybuff);
  1063.         xsrc = ysrc = 0;
  1064.         theImage->data = (char *)xa_disp_buff;
  1065.         xbuff = xsize; ybuff = ysize;
  1066.         no_shared = 1;
  1067.       } 
  1068.       else 
  1069.       { 
  1070. #ifdef XSHM
  1071.         if (shm) sh_Image->data = the_pic;
  1072. #endif
  1073.         theImage->data = the_pic;
  1074.       }
  1075.     } /* end of no scaling */
  1076.  
  1077.     if (x11_pack_flag == xaTRUE)
  1078.     { no_shared = 1;
  1079.       UTIL_Pack_Image(im_buff3,theImage->data,xbuff,ybuff);
  1080.       theImage->data = im_buff3;
  1081.     }
  1082. #ifdef XSHM
  1083.     if (sh_Image) X11_Init_Image_Struct(sh_Image,xbuff,ybuff);
  1084. #endif
  1085.     X11_Init_Image_Struct(theImage,xbuff,ybuff);
  1086.   } /* end of not mono */
  1087.  
  1088.   if (xa_no_disp == xaFALSE)
  1089.   {
  1090.     if ( (the_chdr != 0) && (the_chdr != xa_chdr_now) )
  1091.                         XA_Install_CMAP(the_chdr);
  1092. #ifdef XSHM
  1093.     if (shm && (no_shared==0) )
  1094.     {
  1095.       AUD_SYNC_CHECK();
  1096.       XShmPutImage(theDisp,mainW,theGC,sh_Image,
  1097.                 xsrc,ysrc,xdst,ydst,xsize,ysize,True );
  1098.     } else
  1099. #endif
  1100.     {
  1101.       XPutImage(theDisp,mainW,theGC,theImage,xsrc,ysrc,xdst,ydst,xsize,ysize);
  1102.     }
  1103. #ifdef XMBUF
  1104.     if (mbuf) {
  1105.       DEBUG_LEVEL1 fprintf(stderr, "Swapping buffers\n");
  1106.       XmbufDisplayBuffers(theDisp, 1, &mainW, 0, 0);
  1107.       mainW = mainWbuffers[mainWbufIndex = !mainWbufIndex];
  1108.     }
  1109. #endif
  1110.     AUD_SYNC_CHECK();
  1111.   }
  1112. #ifdef XSHM
  1113.   if ( (shm) && (xa_anim_flags & ANIM_DBL_BUF) ) 
  1114.         {sh_Image = (xa_pic==im_buff0)?im0_Image:im1_Image;}
  1115.     /* note: xa_pic already swapped */
  1116. #endif
  1117. } /* end of DELTA case */
  1118.  
  1119.  
  1120. /***************************************************** 
  1121.  * XA_Image_To_Pixmap
  1122.  *
  1123.  * Convert IMAGE action into PIXMAP action
  1124.  *****************************************************/
  1125. xaULONG XA_Image_To_Pixmap(act)
  1126. XA_ACTION *act;
  1127. {
  1128.   ACT_IMAGE_HDR *act_im_hdr;
  1129.   ACT_PIXMAP_HDR *act_pm_hdr;
  1130.   xaULONG line_size;
  1131.  
  1132.   if (act->type == ACT_NOP) return(0);
  1133.   if (act->type != ACT_IMAGE) 
  1134.   { 
  1135.     fprintf(stderr,"XA_Image_To_Pixmap: not Image err %x\n",act->type);
  1136.     TheEnd();
  1137.   }
  1138.   act_im_hdr = (ACT_IMAGE_HDR *)(act->data);
  1139.   if (!(act_im_hdr->flag & ACT_BUFF_VALID)) return(0);
  1140.   act_pm_hdr = (ACT_PIXMAP_HDR *) malloc( sizeof(ACT_PIXMAP_HDR) );
  1141.   if (act_pm_hdr == 0) TheEnd1("Image_to_Pixmap: malloc err\n");
  1142.  
  1143.   if (x11_display_type == XA_MONOCHROME)
  1144.     line_size = X11_Get_Bitmap_Width(act_im_hdr->xsize);
  1145.   else line_size = act_im_hdr->xsize;
  1146.  
  1147.   if(act_im_hdr->clip)
  1148.   {
  1149.     act_pm_hdr->clip = 
  1150.     XCreatePixmapFromBitmapData(theDisp,mainW,
  1151.                 (char *)act_im_hdr->clip,
  1152.                 X11_Get_Bitmap_Width(act_im_hdr->xsize),act_im_hdr->ysize,
  1153.                 0x01,0x00,1);
  1154.     XSync(theDisp,False);
  1155.   }
  1156.   else act_pm_hdr->clip = 0;
  1157.  
  1158.   act->type = ACT_PIXMAP;
  1159.   act->data = (xaUBYTE *) act_pm_hdr;
  1160.   act_pm_hdr->flag  = ACT_BUFF_VALID;
  1161.   act_pm_hdr->xpos  = act_im_hdr->xpos;
  1162.   act_pm_hdr->ypos  = act_im_hdr->ypos;
  1163.   act_pm_hdr->xsize = act_im_hdr->xsize;
  1164.   act_pm_hdr->ysize = act_im_hdr->ysize;
  1165.   act_pm_hdr->pixmap = XCreatePixmap(theDisp,mainW,
  1166.                 line_size, act_pm_hdr->ysize, x11_depth);
  1167.   XSync(theDisp,False);
  1168.   DEBUG_LEVEL2 fprintf(stderr,
  1169.     "XA_Image_To_Pixmap: pixmap = %x\n", (xaULONG)act_pm_hdr->pixmap);
  1170.   XSetClipMask(theDisp,theGC,None);
  1171.   XPutImage(theDisp, act_pm_hdr->pixmap, theGC, act_im_hdr->image,
  1172.       0,0,0,0,act_pm_hdr->xsize,act_pm_hdr->ysize);
  1173.   XSync(theDisp,False);
  1174.   if (act_im_hdr->clip) { FREE(act_im_hdr->clip,0x03); act_im_hdr->clip=0;}
  1175.   XDestroyImage(act_im_hdr->image);
  1176.   FREE(act_im_hdr,0x04);
  1177. /*POD NOTE: NEED TO SEARCH ACTIONS FOR IMAGES WITH non valid buffers to
  1178.  * to see if they just got converted to a pixmap by this as well. */
  1179.   return(1);
  1180. }
  1181.  
  1182. /***************************************************** 
  1183.  * XA_Read_Delta
  1184.  *
  1185.  * Read delta fromf ile for decompression.
  1186.  *****************************************************/
  1187. xaULONG XA_Read_Delta(dptr,fd,fpos,fsize)
  1188. char *dptr;    /* buffer to put delta into */
  1189. int fd;        /* file descript to read from */
  1190. xaULONG fpos;    /* pos within file */
  1191. xaULONG fsize;    /* size of delta */
  1192. {
  1193.   xaLONG ret;
  1194.   ret = lseek(fd,fpos,SEEK_SET);
  1195.   if (ret != fpos) 
  1196.   { fprintf(stderr,"XA_Read_Delta: Can't seek vid fpos");
  1197.     return(xaFALSE);
  1198.   }
  1199.   ret = read(fd,dptr,fsize);
  1200.   if (ret != fsize) 
  1201.   { fprintf(stderr,"XA_Read_Delta: Can't read vid data ret %08x fsz %08x\n",
  1202.                                 ret,fsize);
  1203.     return(xaFALSE);
  1204.   }
  1205.   return(xaTRUE);
  1206. }
  1207.  
  1208.  
  1209.