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

  1.  
  2. /*
  3.  * xa_qt_decs.c
  4.  *
  5.  * Copyright (C) 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. /* REVISIONS ***********
  19.  * 31Aug94  RPZA was using *iptr+=row_inc instead of iptr+=row_inc.
  20.  * 15Sep94  Added support for RAW32 format. straight RGB with 0x00 up front.
  21.  * 20Sep94  Added RAW4,RAW16,RAW24,RAW32,Gray CVID and Gray Other codecs.
  22.  * 07Nov94  Fixed bug in RLE,RLE16,RLE24,RLE32 and RLE1 code, where I
  23.  *          had improperly guessed what a header meant. Now it's a different
  24.  *        hopeful more correct guess.
  25.  * 29Dec94  Above bug wasn't fixed in RLE(8bit), now it is.
  26.  * 11Feb95  Fixed Bug with RLE depth 1 codec.
  27.  * 04Mar95  Added Dithering(+F option) to Cinepak Video Codec.
  28.  * 17Mar95  Fixed bug that was causing quicktime to erroneously send
  29.  *          back a FULL_IM flag allowing serious skipping to occur. This
  30.  *          causes on screen corruption if the Video Codec doesn't 
  31.  *          really support serious skipping.
  32.  * 11Apr95  Fixed bug in QT_Create_Gray_Cmap that caused last color of
  33.  *        colormap not to be generated correctly. Only affected
  34.  *        the Gray Quicktime codecs.
  35.  * 16Jun95  Removed Cinepak Codec per Radius request.
  36.  *  1Mar96  Separated Video Codecs from mainline qt code.
  37.  * 17Mar96  Added dithering to RPZA Codec(Apple Video).
  38.  */
  39. #include "xa_qt.h"
  40. #include "xa_codecs.h"
  41. #include "xa_color.h"
  42.  
  43. xaLONG QT_Codec_Query();
  44. xaLONG QT_UNK_Codec_Query();
  45.  
  46. xaULONG QT_Decode_RAW1();
  47. xaULONG QT_Decode_RAW4();
  48. xaULONG QT_Decode_RAW8();
  49. xaULONG QT_Decode_RAW16();
  50. xaULONG QT_Decode_RAW24();
  51. xaULONG QT_Decode_RAW32();
  52. xaULONG QT_Decode_RLE1();
  53. xaULONG QT_Decode_RLE4();
  54. xaULONG QT_Decode_RLE8();
  55. xaULONG QT_Decode_RLE16();
  56. xaULONG QT_Decode_RLE24();
  57. xaULONG QT_Decode_RLE32();
  58. xaULONG QT_Decode_RPZA();
  59. xaULONG QT_Decode_SMC();
  60. xaULONG QT_Decode_YUV2();
  61. extern xaULONG JFIF_Decode_JPEG();
  62. extern xaULONG AVI_Decode_CRAM();
  63. extern xaULONG AVI_Decode_CRAM16();
  64.  
  65. xaULONG QT_RPZA_Dither();
  66.  
  67. extern XA_Gen_YUV_Tabs();
  68. /* JPEG and other assist routines */
  69. extern void JPG_Alloc_MCU_Bufs();
  70. extern void JPG_Setup_Samp_Limit_Table();
  71.  
  72. extern void yuv_to_rgb();
  73. void    QT_Get_Dith1_Color24();
  74. void    QT_Get_Dith4_Color24();
  75. xaULONG    QT_Get_Color();
  76. void    QT_Get_RGBColor();
  77. void    QT_Get_RGBColorL();
  78. void    QT_Get_AV_Colors();
  79. void    QT_Get_AV_RGBColors();
  80. void    QT_Get_AV_DITH_RGB();
  81. xaULONG    QT_Get_DithColor24();
  82. extern    xaULONG XA_RGB24_To_CLR32();
  83. extern    xaUSHORT qt_gamma_adj[32];
  84.  
  85. void *XA_YUV211111_Func();
  86.  
  87. extern void CMAP_Cache_Clear();
  88. extern void CMAP_Cache_Init();
  89. extern xaULONG CMAP_Find_Closest();
  90.  
  91. extern xaLONG xa_dither_flag;
  92. extern xaUBYTE  *xa_byte_limit;
  93. extern YUVBufs jpg_YUVBufs;
  94. extern YUVTabs def_yuv_tabs;
  95.  
  96.  
  97. #define    SMC_MAX_CNT 256
  98. /* POD NOTE: eventually make these conditionally dynamic */
  99. static xaULONG smc_8cnt,smc_Acnt,smc_Ccnt;
  100. static xaULONG smc_8[ (2 * SMC_MAX_CNT) ];
  101. static xaULONG smc_A[ (4 * SMC_MAX_CNT) ];
  102. static xaULONG smc_C[ (8 * SMC_MAX_CNT) ];
  103.  
  104.  
  105. /*****************************************************************************
  106.  *
  107.  ****************/
  108. xaLONG QT_Codec_Query(codec)
  109. XA_CODEC_HDR *codec;
  110. { xaLONG ret = CODEC_UNKNOWN;   /* default */
  111.   codec->extra = 0;
  112.   codec->xapi_rev = 0x0001;
  113.   codec->decoder = 0;
  114.   codec->description = 0;
  115.   codec->avi_read_ext = 0;
  116.  
  117.   switch(codec->compression)
  118.   {
  119.     case QT_rle:
  120.         codec->compression      = QT_rle;
  121.         codec->description      = "Apple Animation(RLE)";
  122.         ret = CODEC_SUPPORTED;
  123.     switch(codec->depth)
  124.     {
  125.       case 40:
  126.       case 8:    codec->decoder = QT_Decode_RLE8;
  127.             codec->x = 4 * ((codec->x + 3)/4);
  128.             codec->depth = 8;
  129.             break;
  130.       case 16:    codec->decoder = QT_Decode_RLE16;
  131.             break;
  132.       case 24:    codec->decoder = QT_Decode_RLE24;
  133.             break;
  134.       case 32:    codec->decoder = QT_Decode_RLE32;
  135.             break;
  136.       case 33:
  137.       case  1:    codec->decoder = QT_Decode_RLE1;
  138.             codec->x = 16 * ((codec->x + 15)/16);
  139.             codec->depth = 1;
  140.             break;
  141.       case 36:
  142.       case  4:    codec->decoder = QT_Decode_RLE4;
  143.             codec->x = 8 * ((codec->x + 7)/8);
  144.             codec->depth = 4;
  145.             break;
  146.       default:    ret = CODEC_UNSUPPORTED;    break;
  147.     }
  148.     break;
  149.  
  150.     case QT_smc:
  151.         codec->compression      = QT_smc;
  152.         codec->description      = "Apple Graphics(SMC)";
  153.         ret = CODEC_SUPPORTED;
  154.     if ((codec->depth==8) || (codec->depth==40))
  155.     { codec->decoder = QT_Decode_SMC;
  156.       codec->x = 4 * ((codec->x + 3)/4);
  157.       codec->y = 4 * ((codec->y + 3)/4);
  158.       codec->depth = 8;
  159.     }
  160.     else ret = CODEC_UNSUPPORTED;
  161.     break;
  162.  
  163.     case QT_raw:
  164.         codec->compression      = QT_raw;
  165.         codec->description      = "Apple Uncompressed";
  166.         ret = CODEC_SUPPORTED;
  167.     switch(codec->depth)
  168.     {
  169.       case 33:
  170.       case 1:    codec->decoder = QT_Decode_RAW1;
  171.             codec->depth = 1;
  172.             break;
  173.       case 36:
  174.       case 4:    codec->decoder = QT_Decode_RAW4;
  175.             codec->depth = 4;
  176.             break;
  177.       case 40:
  178.       case 8:    codec->decoder = QT_Decode_RAW8;
  179.             codec->depth = 8;
  180.             break;
  181.       case 16:    codec->decoder = QT_Decode_RAW16;
  182.             break;
  183.       case 24:    codec->decoder = QT_Decode_RAW24;
  184.             break;
  185.       case 32:    codec->decoder = QT_Decode_RAW32;
  186.             break;
  187.       default:    ret = CODEC_UNSUPPORTED;    break;
  188.     }
  189.     break;
  190.  
  191.     case QT_azpr:
  192.     case QT_rpza:
  193.         codec->compression      = QT_rpza;
  194.         codec->description      = "Apple Video(RPZA)";
  195.         ret = CODEC_SUPPORTED;
  196.     if (codec->depth == 16)
  197.     { codec->decoder = QT_Decode_RPZA;
  198.       codec->x = 4 * ((codec->x + 3)/4);
  199.       codec->y = 4 * ((codec->y + 3)/4);
  200.       JPG_Setup_Samp_Limit_Table(codec->anim_hdr);
  201.     }
  202.     else ret = CODEC_UNSUPPORTED;
  203.     break;
  204.  
  205.     case QT_jpeg:
  206.         codec->compression      = QT_jpeg;
  207.         codec->description      = "JPEG";
  208.     codec->xapi_rev        = 0x0002;
  209.         ret = CODEC_SUPPORTED;
  210.     if ((codec->depth == 8) || (codec->depth == 24)
  211.         || (codec->depth == 40) )
  212.     { JPG_Alloc_MCU_Bufs(codec->anim_hdr,codec->x,0,xaFALSE);
  213.       JPG_Setup_Samp_Limit_Table(codec->anim_hdr);
  214.       codec->x = 4 * ((codec->x + 3)/4);
  215.       codec->y = 2 * ((codec->y + 1)/2);
  216.       codec->decoder = JFIF_Decode_JPEG;
  217.       XA_Gen_YUV_Tabs(codec->anim_hdr);
  218.       if (codec->depth == 40) codec->depth = 8;
  219.     }
  220.     else ret = CODEC_UNSUPPORTED;
  221.     break;
  222.  
  223.     case QT_yuv2:
  224.     codec->xapi_rev = 0x0002;
  225.         codec->compression      = QT_yuv2;
  226.         codec->description      = "Component Video(YUV2)";
  227.         ret = CODEC_SUPPORTED;
  228.     codec->decoder = QT_Decode_YUV2;
  229.     codec->x = 2 * ((codec->x + 1)/2);
  230.     codec->y = 2 * ((codec->y + 1)/2); /* POD ness? */
  231.     JPG_Alloc_MCU_Bufs(codec->anim_hdr,codec->x,0,xaFALSE);
  232.     JPG_Setup_Samp_Limit_Table(codec->anim_hdr);
  233.     XA_Gen_YUV_Tabs(codec->anim_hdr);
  234.     break;
  235.  
  236.     case QT_cram:
  237.     case QT_CRAM:
  238.     case QT_wham:
  239.     case QT_WHAM:
  240.     case QT_msvc:
  241.     case QT_MSVC:
  242.         codec->compression      = QT_cram;
  243.         codec->description      = "Microsoft Video 1";
  244.         ret = CODEC_SUPPORTED;
  245.     if (codec->depth == 8)        codec->decoder = AVI_Decode_CRAM;
  246.     else if (codec->depth == 16)    codec->decoder = AVI_Decode_CRAM16;
  247.     else ret = CODEC_UNSUPPORTED;
  248.     codec->x = 4 * ((codec->x + 3)/4);
  249.     codec->y = 4 * ((codec->y + 3)/4);
  250.     JPG_Setup_Samp_Limit_Table(codec->anim_hdr);
  251.     break;
  252.  
  253.  
  254.     
  255.     default:
  256.         ret = CODEC_UNKNOWN;
  257.         break;
  258.   }
  259.   return(ret);
  260. }
  261.  
  262. /*****************************************************************************
  263.  *
  264.  ****************/
  265. xaLONG QT_UNK_Codec_Query(codec)
  266. XA_CODEC_HDR *codec;
  267. { xaLONG ret = CODEC_UNKNOWN;   /* default */
  268.   codec->extra = 0;
  269.   codec->xapi_rev = 0x0001;
  270.   codec->decoder = 0;
  271.   codec->description = 0;
  272.   codec->avi_read_ext = 0;
  273.  
  274.   switch(codec->compression)
  275.   {
  276.     case QT_PGVV:
  277.         codec->compression      = QT_PGVV;
  278.         codec->description      = "Radius (PGVV)";
  279.         ret = CODEC_UNSUPPORTED;
  280.     break;
  281.  
  282.     case QT_cvid:
  283.     case QT_CVID:
  284.         codec->compression      = QT_CVID;
  285.         codec->description      = "Radius Cinepak";
  286.         ret = CODEC_UNSUPPORTED;
  287.     break;
  288.  
  289.     case QT_SPIG:
  290.         codec->compression      = QT_SPIG;
  291.         codec->description      = "Radius Spigot";
  292.         ret = CODEC_UNSUPPORTED;
  293.     break;
  294.  
  295.     case QT_rt21:
  296.     case QT_RT21:
  297.         codec->compression      = QT_RT21;
  298.         codec->description      = "Intel Indeo R2.1";
  299.         ret = CODEC_UNSUPPORTED;
  300.     break;
  301.  
  302.     case QT_iv31:
  303.     case QT_IV31:
  304.         codec->compression      = QT_IV31;
  305.         codec->description      = "Intel Indeo R3.1";
  306.         ret = CODEC_UNSUPPORTED;
  307.     break;
  308.  
  309.     case QT_iv32:
  310.     case QT_IV32:
  311.         codec->compression      = QT_IV32;
  312.         codec->description      = "Intel Indeo R3.2";
  313.         ret = CODEC_UNSUPPORTED;
  314.     break;
  315.  
  316.     case QT_iv41:
  317.     case QT_IV41:
  318.         codec->compression      = QT_IV41;
  319.         codec->description      = "Intel Indeo R4.1";
  320.         ret = CODEC_UNSUPPORTED;
  321.     break;
  322.  
  323.     case QT_YVU9:
  324.     case QT_YUV9:
  325.         codec->compression      = QT_YUV9;
  326.         codec->description      = "Intel Raw(YUV9)";
  327.         ret = CODEC_UNSUPPORTED;
  328.     break;
  329.  
  330.     case QT_kpcd:
  331.     case QT_KPCD:
  332.         codec->compression      = QT_KPCD;
  333.         codec->description      = "Kodak Photo CD";
  334.         ret = CODEC_UNSUPPORTED;
  335.     break;
  336.  
  337.     default:
  338.         ret = CODEC_UNKNOWN;
  339.         break;
  340.   }
  341.   return(ret);
  342. }
  343.  
  344.  
  345.  
  346. /********************* * * * *******************************************/
  347. xaULONG QT_Decode_RAW4(image,delta,dsize,dec_info)
  348. xaUBYTE *image;         /* Image Buffer. */
  349. xaUBYTE *delta;         /* delta data. */
  350. xaULONG dsize;          /* delta size */
  351. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  352. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  353.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  354.   xaUBYTE *dp = delta;
  355.   xaLONG i = (imagex * imagey) >> 1;
  356.  
  357.   dec_info->xs = dec_info->ys = 0;
  358.   dec_info->xe = imagex; dec_info->ye = imagey;
  359.  
  360.     /* Indicate we can drop these frames */
  361.   if (dec_info->skip_flag > 0) return(ACT_DLTA_DROP);
  362.  
  363. /* POD QUESTION: is imagex a multiple of 2??? */
  364.   if (map_flag==xaFALSE) { xaUBYTE *iptr = (xaUBYTE *)image; 
  365.     while(i--) { xaUBYTE d = *dp++; *iptr++ = (d>>4); *iptr++ = d & 0xf; }
  366.   }
  367.   else if (x11_bytes_pixel==1) { xaUBYTE *iptr = (xaUBYTE *)image; 
  368.     while(i--) { xaULONG d = (xaULONG)*dp++;
  369.                  *iptr++ = (xaUBYTE)map[d>>4]; *iptr++ = (xaUBYTE)map[d&15]; }
  370.   }
  371.   else if (x11_bytes_pixel==4) { xaULONG *iptr = (xaULONG *)image; 
  372.     while(i--) { xaULONG d = (xaULONG)*dp++;
  373.                  *iptr++ = (xaULONG)map[d>>4]; *iptr++ = (xaULONG)map[d&15]; }
  374.   }
  375.   else /*(x11_bytes_pixel==2)*/ { xaUSHORT *iptr = (xaUSHORT *)image; 
  376.     while(i--) { xaULONG d = (xaULONG)*dp++;
  377.                  *iptr++ = (xaUSHORT)map[d>>4]; *iptr++ = (xaUSHORT)map[d&15]; }
  378.   }
  379.   if (map_flag==xaTRUE) return(ACT_DLTA_MAPD);
  380.   else return(ACT_DLTA_NORM);
  381. }
  382.  
  383. /********************* * * * *******************************************/
  384. xaULONG QT_Decode_RAW1(image,delta,dsize,dec_info)
  385. xaUBYTE *image;         /* Image Buffer. */
  386. xaUBYTE *delta;         /* delta data. */
  387. xaULONG dsize;          /* delta size */
  388. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  389. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  390.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  391.   xaUBYTE *dp = delta;
  392.   xaLONG i = (imagex * imagey) >> 1;
  393.   xaULONG white,black;
  394.  
  395.   dec_info->xs = dec_info->ys = 0;
  396.   dec_info->xe = imagex; dec_info->ye = imagey;
  397.  
  398.   black = 0x00;
  399.   white = 0x01;
  400.  
  401.     /* Indicate we can drop these frames */
  402.   if (dec_info->skip_flag > 0) return(ACT_DLTA_DROP);
  403.  
  404. /* POD QUESTION: is imagex a multiple of 8??? */
  405.   if (map_flag==xaFALSE) { xaUBYTE *iptr = (xaUBYTE *)image; 
  406.     while(i--) { xaUBYTE d = *dp++; 
  407.        *iptr++ = (xaUBYTE)( (d & 0x80)?(white):(black) );
  408.        *iptr++ = (xaUBYTE)( (d & 0x40)?(white):(black) );
  409.        *iptr++ = (xaUBYTE)( (d & 0x20)?(white):(black) );
  410.        *iptr++ = (xaUBYTE)( (d & 0x10)?(white):(black) );
  411.        *iptr++ = (xaUBYTE)( (d & 0x08)?(white):(black) );
  412.        *iptr++ = (xaUBYTE)( (d & 0x04)?(white):(black) );
  413.        *iptr++ = (xaUBYTE)( (d & 0x02)?(white):(black) );
  414.        *iptr++ = (xaUBYTE)( (d & 0x01)?(white):(black) ); }
  415.   }
  416.   else if (x11_bytes_pixel==1) { xaUBYTE *iptr = (xaUBYTE *)image; 
  417.     while(i--) { xaUBYTE d = *dp++;
  418.        *iptr++ = (xaUBYTE)map[ (d & 0x80)?(white):(black) ];
  419.        *iptr++ = (xaUBYTE)map[ (d & 0x40)?(white):(black) ];
  420.        *iptr++ = (xaUBYTE)map[ (d & 0x20)?(white):(black) ];
  421.        *iptr++ = (xaUBYTE)map[ (d & 0x10)?(white):(black) ];
  422.        *iptr++ = (xaUBYTE)map[ (d & 0x08)?(white):(black) ];
  423.        *iptr++ = (xaUBYTE)map[ (d & 0x04)?(white):(black) ];
  424.        *iptr++ = (xaUBYTE)map[ (d & 0x02)?(white):(black) ];
  425.        *iptr++ = (xaUBYTE)map[ (d & 0x01)?(white):(black) ]; }
  426.   }
  427.   else if (x11_bytes_pixel==4) { xaULONG *iptr = (xaULONG *)image; 
  428.     while(i--) { xaUBYTE d = *dp++;
  429.        *iptr++ = (xaULONG)map[ (d & 0x80)?(white):(black) ];
  430.        *iptr++ = (xaULONG)map[ (d & 0x40)?(white):(black) ];
  431.        *iptr++ = (xaULONG)map[ (d & 0x20)?(white):(black) ];
  432.        *iptr++ = (xaULONG)map[ (d & 0x10)?(white):(black) ];
  433.        *iptr++ = (xaULONG)map[ (d & 0x08)?(white):(black) ];
  434.        *iptr++ = (xaULONG)map[ (d & 0x04)?(white):(black) ];
  435.        *iptr++ = (xaULONG)map[ (d & 0x02)?(white):(black) ];
  436.        *iptr++ = (xaULONG)map[ (d & 0x01)?(white):(black) ]; }
  437.   }
  438.   else /*(x11_bytes_pixel==2)*/ { xaUSHORT *iptr = (xaUSHORT *)image; 
  439.     while(i--) { xaUBYTE d = *dp++;
  440.        *iptr++ = (xaUSHORT)map[ (d & 0x80)?(white):(black) ];
  441.        *iptr++ = (xaUSHORT)map[ (d & 0x40)?(white):(black) ];
  442.        *iptr++ = (xaUSHORT)map[ (d & 0x20)?(white):(black) ];
  443.        *iptr++ = (xaUSHORT)map[ (d & 0x10)?(white):(black) ];
  444.        *iptr++ = (xaUSHORT)map[ (d & 0x08)?(white):(black) ];
  445.        *iptr++ = (xaUSHORT)map[ (d & 0x04)?(white):(black) ];
  446.        *iptr++ = (xaUSHORT)map[ (d & 0x02)?(white):(black) ];
  447.        *iptr++ = (xaUSHORT)map[ (d & 0x01)?(white):(black) ]; }
  448.   }
  449.   if (map_flag==xaTRUE) return(ACT_DLTA_MAPD);
  450.   else return(ACT_DLTA_NORM);
  451. }
  452.  
  453. /********************* * * * *******************************************/
  454. xaULONG QT_Decode_RAW8(image,delta,dsize,dec_info)
  455. xaUBYTE *image;         /* Image Buffer. */
  456. xaUBYTE *delta;         /* delta data. */
  457. xaULONG dsize;          /* delta size */
  458. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  459. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  460.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  461.   xaUBYTE *dptr = delta;
  462.   xaLONG i = imagex * imagey;
  463.  
  464.   dec_info->xs = dec_info->ys = 0;
  465.   dec_info->xe = imagex; dec_info->ye = imagey;
  466.     /* Indicate we can drop these frames */
  467.   if (dec_info->skip_flag > 0) return(ACT_DLTA_DROP);
  468.   
  469.   if (map_flag==xaFALSE) { xaUBYTE *iptr = (xaUBYTE *)image; 
  470.                 while(i--) *iptr++ = (xaUBYTE)*dptr++; }
  471.   else if (x11_bytes_pixel==1) { xaUBYTE *iptr = (xaUBYTE *)image; 
  472.                 while(i--) *iptr++ = (xaUBYTE)map[*dptr++]; }
  473.   else if (x11_bytes_pixel==2) { xaUSHORT *iptr = (xaUSHORT *)image; 
  474.                 while(i--) *iptr++ = (xaUSHORT)map[*dptr++]; }
  475.   else { xaULONG *iptr = (xaULONG *)image; 
  476.                 while(i--) *iptr++ = (xaULONG)map[*dptr++]; }
  477.  
  478.   if (map_flag==xaTRUE) return(ACT_DLTA_MAPD);
  479.   else return(ACT_DLTA_NORM);
  480. }
  481.  
  482. #define QT_RAW_READ16RGB(dp,r,g,b) { xaULONG _d = *dp++ << 8; _d |= *dp++; \
  483.   r = (_d >> 10) & 0x1f; g = (_d >> 5) & 0x1f; b = _d & 0x1f;    \
  484.   r = (r << 3) | (r >> 2); g = (g << 3) | (g >> 2); b = (b << 3) | (b >> 2); }
  485.  
  486. /****************** RAW CODEC DEPTH 16 *********************************
  487.  *  1 unused bit. 5 bits R, G, B
  488.  *
  489.  *********************************************************************/
  490. xaULONG QT_Decode_RAW16(image,delta,dsize,dec_info)
  491. xaUBYTE *image;         /* Image Buffer. */
  492. xaUBYTE *delta;         /* delta data. */
  493. xaULONG dsize;          /* delta size */
  494. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  495. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  496.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  497.   xaULONG special = dec_info->special;
  498.   XA_CHDR *chdr = dec_info->chdr;
  499.   xaUBYTE *dp = delta;
  500.   xaULONG special_flag = special & 0x0001;
  501.   xaLONG i = imagex * imagey;
  502.   
  503.   dec_info->xs = dec_info->ys = 0;
  504.   dec_info->xe = imagex; dec_info->ye = imagey;
  505.     /* Indicate we can drop these frames */
  506.   if (dec_info->skip_flag > 0) return(ACT_DLTA_DROP);
  507.  
  508.   if (chdr) { if (chdr->new_chdr) chdr = chdr->new_chdr; }
  509.  
  510.   if (special_flag)
  511.   { xaUBYTE *iptr = (xaUBYTE *)image; 
  512.     while(i--) 
  513.     { xaULONG r,g,b;  QT_RAW_READ16RGB(dp,r,g,b);
  514.       *iptr++ = r; *iptr++ = g; *iptr++ = b;}
  515.   }
  516.   else if ( (map_flag==xaFALSE) || (x11_bytes_pixel==1) )
  517.   { xaUBYTE *iptr = (xaUBYTE *)image; 
  518.     while(i--) 
  519.     { xaULONG r,g,b; QT_RAW_READ16RGB(dp,r,g,b);
  520.       *iptr++ = (xaUBYTE)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  521.     }
  522.   }
  523.   else if (x11_bytes_pixel==4)
  524.   { xaULONG *iptr = (xaULONG *)image; 
  525.     while(i--) 
  526.     { xaULONG r,g,b;  QT_RAW_READ16RGB(dp,r,g,b);
  527.       *iptr++ = (xaULONG)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  528.     }
  529.   }
  530.   else /* (x11_bytes_pixel==2) */
  531.   { xaUSHORT *iptr = (xaUSHORT *)image; 
  532.     while(i--) 
  533.     { xaULONG r,g,b;  QT_RAW_READ16RGB(dp,r,g,b);
  534.       *iptr++ = (xaUSHORT)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  535.     }
  536.   }
  537.   if (map_flag==xaTRUE) return(ACT_DLTA_MAPD);
  538.   else return(ACT_DLTA_NORM);
  539. }
  540.  
  541.  
  542. /****************** RAW CODEC DEPTH 24 *********************************
  543.  *  R G B
  544.  *********************************************************************/
  545. xaULONG QT_Decode_RAW24(image,delta,dsize,dec_info)
  546. xaUBYTE *image;         /* Image Buffer. */
  547. xaUBYTE *delta;         /* delta data. */
  548. xaULONG dsize;          /* delta size */
  549. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  550. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  551.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  552.   xaULONG special = dec_info->special;
  553.   XA_CHDR *chdr = dec_info->chdr;
  554.   xaUBYTE *dp = delta;
  555.   xaULONG special_flag = special & 0x0001;
  556.   xaLONG i = imagex * imagey;
  557.   
  558.   dec_info->xs = dec_info->ys = 0;
  559.   dec_info->xe = imagex; dec_info->ye = imagey;
  560.     /* Indicate we can drop these frames */
  561.   if (dec_info->skip_flag > 0) return(ACT_DLTA_DROP);
  562.  
  563.   if (chdr) { if (chdr->new_chdr) chdr = chdr->new_chdr; }
  564.  
  565.   if (special_flag)
  566.   { xaUBYTE *iptr = (xaUBYTE *)image; 
  567.     while(i--) { *iptr++ = *dp++; *iptr++ = *dp++; *iptr++ = *dp++;}
  568.   }
  569.   else if ( (map_flag==xaFALSE) || (x11_bytes_pixel==1) )
  570.   { xaUBYTE *iptr = (xaUBYTE *)image; 
  571.     while(i--) 
  572.     { xaULONG r,g,b;
  573.       r = (xaULONG)*dp++; g = (xaULONG)*dp++; b = (xaULONG)*dp++;
  574.       *iptr++ = (xaUBYTE)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  575.     }
  576.   }
  577.   else if (x11_bytes_pixel==4)
  578.   { xaULONG *iptr = (xaULONG *)image; 
  579.     while(i--) 
  580.     { xaULONG r,g,b; 
  581.       r = (xaULONG)*dp++; g = (xaULONG)*dp++; b = (xaULONG)*dp++;
  582.       *iptr++ = (xaULONG)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  583.     }
  584.   }
  585.   else /* (x11_bytes_pixel==2) */
  586.   { xaUSHORT *iptr = (xaUSHORT *)image; 
  587.     while(i--) 
  588.     { xaULONG r,g,b; 
  589.       r = (xaULONG)*dp++; g = (xaULONG)*dp++; b = (xaULONG)*dp++;
  590.       *iptr++ = (xaUSHORT)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  591.     }
  592.   }
  593.   if (map_flag==xaTRUE) return(ACT_DLTA_MAPD);
  594.   else return(ACT_DLTA_NORM);
  595. }
  596.  
  597.  
  598. /****************** RAW CODEC DEPTH 32 *********************************
  599.  *  0 R G B
  600.  *
  601.  *********************************************************************/
  602. xaULONG QT_Decode_RAW32(image,delta,dsize,dec_info)
  603. xaUBYTE *image;         /* Image Buffer. */
  604. xaUBYTE *delta;         /* delta data. */
  605. xaULONG dsize;          /* delta size */
  606. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  607. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  608.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  609.   xaULONG special = dec_info->special;
  610.   XA_CHDR *chdr = dec_info->chdr;
  611.   xaUBYTE *dp = delta;
  612.   xaULONG special_flag = special & 0x0001;
  613.   xaLONG i = imagex * imagey;
  614.   
  615.   dec_info->xs = dec_info->ys = 0;
  616.   dec_info->xe = imagex; dec_info->ye = imagey;
  617.     /* Indicate we can drop these frames */
  618.   if (dec_info->skip_flag > 0) return(ACT_DLTA_DROP);
  619.  
  620.   if (chdr) { if (chdr->new_chdr) chdr = chdr->new_chdr; }
  621.   if (special_flag)
  622.   { xaUBYTE *iptr = (xaUBYTE *)image; 
  623.     while(i--) {dp++; *iptr++ = *dp++; *iptr++ = *dp++; *iptr++ = *dp++;}
  624.   }
  625.   else if ( (map_flag==xaFALSE) || (x11_bytes_pixel==1) )
  626.   { xaUBYTE *iptr = (xaUBYTE *)image; 
  627.     while(i--) 
  628.     { xaULONG r,g,b;
  629.       dp++; r = (xaULONG)*dp++; g = (xaULONG)*dp++; b = (xaULONG)*dp++;
  630.       *iptr++ = (xaUBYTE)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  631.     }
  632.   }
  633.   else if (x11_bytes_pixel==4)
  634.   { xaULONG *iptr = (xaULONG *)image; 
  635.     while(i--) 
  636.     { xaULONG r,g,b; 
  637.       dp++; r = (xaULONG)*dp++; g = (xaULONG)*dp++; b = (xaULONG)*dp++;
  638.       *iptr++ = (xaULONG)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  639.     }
  640.   }
  641.   else /* (x11_bytes_pixel==2) */
  642.   { xaUSHORT *iptr = (xaUSHORT *)image; 
  643.     while(i--) 
  644.     { xaULONG r,g,b; 
  645.       dp++; r = (xaULONG)*dp++; g = (xaULONG)*dp++; b = (xaULONG)*dp++;
  646.       *iptr++ = (xaUSHORT)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  647.     }
  648.   }
  649.   if (map_flag==xaTRUE) return(ACT_DLTA_MAPD);
  650.   else return(ACT_DLTA_NORM);
  651. }
  652.  
  653.  
  654. /********************* * * * *******************************************/
  655. xaULONG QT_Decode_RLE1(image,delta,dsize,dec_info)
  656. xaUBYTE *image;         /* Image Buffer. */
  657. xaUBYTE *delta;         /* delta data. */
  658. xaULONG dsize;          /* delta size */
  659. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  660. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  661.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  662.   xaLONG x,y,d,lines; /* xaLONG min_x,max_x,min_y,max_y; */
  663.   xaUBYTE *dptr;
  664.  
  665.   dptr = delta;
  666.   dptr += 4;    /* skip codec size */
  667.   d = (*dptr++) << 8;  d |= *dptr++;   /* read code either 0008 or 0000 */
  668.   if (dsize < 8) /* NOP */
  669.   { 
  670.     dec_info->xs = dec_info->ys = dec_info->xe = dec_info->ye = 0;
  671.     return(ACT_DLTA_NOP);
  672.   }
  673.   if (d & 0x0008) /* Header present */
  674.   {
  675.     y = (*dptr++) << 8; y |= *dptr++;           /* start line */
  676.     dptr += 2;                                  /* unknown */
  677.     lines = (*dptr++) << 8; lines |= *dptr++;   /* number of lines */
  678.     dptr += 2;                                  /* unknown */
  679.   }
  680.   else { y = 0; lines = imagey; }
  681.   x = 0; y--; lines++;
  682.   while(lines)                /* loop thru lines */
  683.   {
  684.     xaULONG d,xskip,cnt;
  685.  
  686.     xskip = *dptr++;                /* skip x pixels */
  687.     cnt = *dptr++;                /* RLE code */
  688.     if (cnt == 0) break;             /* exit */
  689.     
  690. /* this can be removed */
  691.     if ((xskip == 0x80) && (cnt == 0x00))  /* end of codec */
  692.     {
  693.       lines = 0; y++; x = 0; 
  694.     }
  695.     else if ((xskip == 0x80) && (cnt == 0xff)) /* skip line */
  696.     {lines--; y++; x = 0; }
  697.     else
  698.     {
  699.       if (xskip & 0x80) {lines--; y++; x = xskip & 0x7f;}
  700.       else x += xskip;
  701.  
  702.       if (cnt < 0x80)                /* run of data */
  703.       { 
  704.         xaUBYTE *bptr; xaUSHORT *sptr; xaULONG *lptr;
  705.     if ((x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  706.         bptr = (xaUBYTE *)(image + (y * imagex) + (x << 4) );
  707.     else if (x11_bytes_pixel==2)
  708.         sptr = (xaUSHORT *)(image + 2*(y * imagex) + (x << 5) );
  709.         else lptr = (xaULONG *)(image + 4*(y * imagex) + (x << 6) );
  710.         x += cnt;
  711.         while(cnt--) 
  712.         { xaULONG i,mask;
  713.           d = (*dptr++ << 8); d |= *dptr++;
  714.           mask = 0x8000;
  715.           for(i=0;i<16;i++)
  716.           {
  717.             if (map_flag==xaFALSE) 
  718.         { if (d & mask) *bptr++ = 0;  else *bptr++ = 1; }
  719.             else if (x11_bytes_pixel==1) {if (d & mask) *bptr++=(xaUBYTE)map[0];
  720.                     else *bptr++=(xaUBYTE)map[1];}
  721.             else if (x11_bytes_pixel==2) {if (d & mask) *sptr++ =(xaUSHORT)map[0];
  722.                     else *sptr++ =(xaUSHORT)map[1]; }
  723.             else { if (d & mask) *lptr++ = (xaULONG)map[0]; 
  724.                     else *lptr++ = (xaULONG)map[1]; }
  725.             mask >>= 1;
  726.           }
  727.         }
  728.       } /* end run */ 
  729.       else                /* repeat data */
  730.       { 
  731.         xaUBYTE *bptr; xaUSHORT *sptr; xaULONG *lptr;
  732.     if ((x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  733.         bptr = (xaUBYTE *)(image + (y * imagex) + (x << 4) );
  734.     else if (x11_bytes_pixel==2)
  735.         sptr = (xaUSHORT *)(image + 2*(y * imagex) + (x << 5) );
  736.         else lptr = (xaULONG *)(image + 4*(y * imagex) + (x << 6) );
  737.         cnt = 0x100 - cnt;
  738.         x += cnt;
  739.         d = (*dptr++ << 8); d |= *dptr++;
  740.         while(cnt--) 
  741.         { xaULONG i,mask;
  742.           mask = 0x8000;
  743.           for(i=0;i<16;i++)
  744.           {
  745.             if (map_flag==xaFALSE) 
  746.         { if (d & mask) *bptr++ = 0;  else *bptr++ = 1; }
  747.             else if (x11_bytes_pixel==1) {if (d & mask) *bptr++=(xaUBYTE)map[0];
  748.                     else *bptr++=(xaUBYTE)map[1];}
  749.             else if (x11_bytes_pixel==2) {if (d & mask) *sptr++ =(xaUSHORT)map[0];
  750.                     else *sptr++ =(xaUSHORT)map[1]; }
  751.             else { if (d & mask) *lptr++ = (xaULONG)map[0]; 
  752.                     else *lptr++ = (xaULONG)map[1]; }
  753.             mask >>= 1;
  754.           }
  755.         }
  756.       } /* end repeat */
  757.     } /* end of code */
  758.   } /* end of lines */
  759.  dec_info->xs = dec_info->ys = 0; dec_info->xe = imagex; dec_info->ye = imagey;
  760.  if (map_flag==xaTRUE) return(ACT_DLTA_MAPD);
  761.  else return(ACT_DLTA_NORM);
  762. }
  763.  
  764.  
  765. /********************* * * * *******************************************/
  766. xaULONG QT_Decode_RLE4(image,delta,dsize,dec_info)
  767. xaUBYTE *image;         /* Image Buffer. */
  768. xaUBYTE *delta;         /* delta data. */
  769. xaULONG dsize;          /* delta size */
  770. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  771. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  772.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  773.   xaLONG x,y,lines; /* xaLONG min_x,max_x,min_y,max_y; */
  774.   xaULONG d;
  775.   xaUBYTE *dptr;
  776.  
  777.   dptr = delta;
  778.   dptr += 4;    /* skip codec size */
  779.   d = (*dptr++) << 8;  d |= *dptr++;   /* read code either 0008 or 0000 */
  780.   if (dsize < 8) /* NOP */
  781.   { 
  782.     dec_info->xs = dec_info->ys = dec_info->xe = dec_info->ye = 0;
  783. fprintf(stderr,"nop\n"); /* POD */
  784.     return(ACT_DLTA_NOP);
  785.   }
  786.   if (d & 0x0008) /* Header present */
  787.   {
  788.     y = (*dptr++) << 8; y |= *dptr++;           /* start line */
  789.     dptr += 2;                                  /* unknown */
  790.     lines = (*dptr++) << 8; lines |= *dptr++;   /* number of lines */
  791.     dptr += 2;                                  /* unknown */
  792.   }
  793.   else { y = 0; lines = imagey; }
  794.  
  795. fprintf(stderr,"d=%d y=%d lines %d\n",d,y,lines); /* POD */
  796.  
  797.   x = -1; lines++;
  798.   while(lines)                /* loop thru lines */
  799.   {
  800.     xaULONG xskip,cnt;
  801.  
  802.     if (x == -1) 
  803.     {  xskip = *dptr++;  /* skip x pixels */
  804.        if (xskip == 0) break;  /* end of codec */
  805.     }
  806.     else xskip = 0;
  807.  
  808.  
  809.     cnt = *dptr++;                /* RLE code */
  810.  
  811. DEBUG_LEVEL1 fprintf(stderr," xy <%d,%d> xskip %x cnt %x\n",x,y,xskip,cnt);
  812.  
  813.     if (cnt == 0) break;             /* exit */
  814.     
  815. /* this can be removed */
  816.     if (cnt == 0x00)  /* end of codec */
  817.     {
  818.       lines = 0; y++; x = -1; 
  819.     }
  820.     else if (cnt == 0xff) /* skip line */
  821.     { lines--; y++; x = -1; 
  822.  
  823.       DEBUG_LEVEL1 fprintf(stderr,"    skip line xy <%d,%d>\n",x,y);
  824.     }
  825.     else
  826.     {
  827.       if (xskip & 0x80) {lines--; y++; x = xskip & 0x7f;}
  828.       else x += xskip;
  829.  
  830.       DEBUG_LEVEL1 fprintf(stderr,"    cnt %x <%d,%d>\n",cnt,x,y);
  831.  
  832.       if (cnt < 0x80)                /* run of data */
  833.       { 
  834.         xaUBYTE *bptr; xaUSHORT *sptr; xaULONG *lptr;
  835.     if ((x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  836.         bptr = (xaUBYTE *)(image + (y * imagex) + (x << 3) );
  837.     else if (x11_bytes_pixel==2)
  838.         sptr = (xaUSHORT *)(image + 2*(y * imagex) + (x << 4) );
  839.         else lptr = (xaULONG *)(image + 4*(y * imagex) + (x << 5) );
  840.         x += cnt;
  841.         while(cnt--) 
  842.         { xaULONG i,shift,d0;
  843.           d0 = (*dptr++ << 24);  d0 |= (*dptr++ << 16); 
  844.                 d0 |= (*dptr++ << 8);  d0 |= *dptr++;
  845.           shift = 32;
  846.           for(i=0;i<8;i++)
  847.           { shift -= 4;
  848.             d = (d0 >> shift) & 0x0f;
  849.             if (map_flag==xaFALSE)     *bptr++ = (xaUBYTE)d;
  850.             else if (x11_bytes_pixel==1) *bptr++ = (xaUBYTE)map[d];
  851.             else if (x11_bytes_pixel==2) *sptr++ = (xaUSHORT)map[d];
  852.             else             *lptr++ = (xaULONG)map[d]; 
  853.           }
  854.         }
  855.       } /* end run */ 
  856.       else                /* repeat data */
  857.       { xaULONG d0;
  858.         xaUBYTE *bptr; xaUSHORT *sptr; xaULONG *lptr;
  859.     if ((x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  860.         bptr = (xaUBYTE *)(image + (y * imagex) + (x << 3) );
  861.     else if (x11_bytes_pixel==2)
  862.         sptr = (xaUSHORT *)(image + 2*(y * imagex) + (x << 4) );
  863.         else lptr = (xaULONG *)(image + 4*(y * imagex) + (x << 5) );
  864.         cnt = 0x100 - cnt;
  865.         x += cnt;
  866.         d0 = (*dptr++ << 24);  d0 |= (*dptr++ << 16); 
  867.                 d0 |= (*dptr++ << 8);  d0 |= *dptr++;
  868.         while(cnt--) 
  869.         { xaULONG i,shift;
  870.           shift = 32;
  871.           for(i=0;i<8;i++)
  872.           { shift -= 4;
  873.             d = (d0 >> shift) & 0x0f;
  874.             if (map_flag==xaFALSE)      *bptr++ = (xaUBYTE)d;
  875.             else if (x11_bytes_pixel==1) *bptr++ = (xaUBYTE)map[d];
  876.             else if (x11_bytes_pixel==2) *sptr++ = (xaUSHORT)map[d];
  877.             else             *lptr++ = (xaULONG)map[d]; 
  878.           }
  879.         }
  880.       } /* end repeat */
  881.     } /* end of code */
  882.   } /* end of lines */
  883.  dec_info->xs = dec_info->ys = 0; dec_info->xe = imagex; dec_info->ye = imagey;
  884.  if (map_flag==xaTRUE) return(ACT_DLTA_MAPD);
  885.  else return(ACT_DLTA_NORM);
  886. }
  887.  
  888.  
  889. /********************* * * * *******************************************/
  890. xaULONG QT_Decode_RLE8(image,delta,dsize,dec_info)
  891. xaUBYTE *image;         /* Image Buffer. */
  892. xaUBYTE *delta;         /* delta data. */
  893. xaULONG dsize;          /* delta size */
  894. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  895. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  896.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  897.   xaLONG y,lines,d; /* xaLONG min_x,max_x,min_y,max_y;  */
  898.   xaUBYTE *dptr;
  899.  
  900.   dptr = delta;
  901.   dptr += 4;    /* skip codec size */
  902.   d = (*dptr++) << 8;  d |= *dptr++;   /* read code either 0008 or 0000 */
  903.   if (dsize < 8) /* NOP */
  904.   { dec_info->xs = dec_info->ys = dec_info->xe = dec_info->ye = 0;
  905.     return(ACT_DLTA_NOP);
  906.   }
  907.   if (d & 0x0008) /* Header present */
  908.   {
  909.     y = (*dptr++) << 8; y |= *dptr++;           /* start line */
  910.     dptr += 2;                                  /* unknown */
  911.     lines = (*dptr++) << 8; lines |= *dptr++;   /* number of lines */
  912.     dptr += 2;                                  /* unknown */
  913.   }
  914.   else { y = 0; lines = imagey; }
  915.   while(lines--)
  916.   {
  917.     xaULONG xskip,cnt;
  918.     xskip = *dptr++;                /* skip x pixels */
  919.     if (xskip==0) break;            /* exit */
  920.     cnt = *dptr++;                /* RLE code */
  921.     if ( (x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  922.     { xaUBYTE *iptr = (xaUBYTE *)(image + (y * imagex) + (4 * (xskip-1)) );
  923.       while(cnt != 0xff)
  924.       {
  925.         if (cnt == 0x00) { xskip = *dptr++; iptr += 4 * (xskip-1); }
  926.         else if (cnt < 0x80)            /* run of data */
  927.         {
  928.           cnt *= 4; if (map_flag==xaFALSE) while(cnt--) *iptr++ = (xaUBYTE)*dptr++;
  929.           else while(cnt--) *iptr++ = (xaUBYTE)map[*dptr++];
  930.         } else                    /* repeat data */
  931.         { xaUBYTE d1,d2,d3,d4;    cnt = 0x100 - cnt;
  932.           if (map_flag==xaTRUE) { d1=(xaUBYTE)map[*dptr++]; d2=(xaUBYTE)map[*dptr++];
  933.                   d3=(xaUBYTE)map[*dptr++]; d4=(xaUBYTE)map[*dptr++]; }
  934.       else    { d1 = (xaUBYTE)*dptr++; d2 = (xaUBYTE)*dptr++;
  935.           d3 = (xaUBYTE)*dptr++; d4 = (xaUBYTE)*dptr++; }
  936.           while(cnt--) { *iptr++ =d1; *iptr++ =d2; *iptr++ =d3; *iptr++ =d4; }
  937.         } /* end of  >= 0x80 */
  938.         cnt = *dptr++;
  939.       } /* end while cnt */
  940.     } else if (x11_bytes_pixel==2)
  941.     { xaUSHORT *iptr = (xaUSHORT *)(image + 2 *((y * imagex) + (4 * (xskip-1))) );
  942.       while(cnt != 0xff)
  943.       {
  944.         if (cnt == 0x00) { xskip = *dptr++; iptr += 4 * (xskip-1); }
  945.         else if (cnt < 0x80)            /* run of data */
  946.         {
  947.           cnt *= 4; while(cnt--) *iptr++ = (xaUSHORT)map[*dptr++];
  948.         } else                    /* repeat data */
  949.         { xaUSHORT d1,d2,d3,d4;    cnt = 0x100 - cnt;
  950.       { d1 = (xaUSHORT)map[*dptr++]; d2 = (xaUSHORT)map[*dptr++];
  951.         d3 = (xaUSHORT)map[*dptr++]; d4 = (xaUSHORT)map[*dptr++]; }
  952.           while(cnt--) { *iptr++ =d1; *iptr++ =d2; *iptr++ =d3; *iptr++ =d4; }
  953.         } /* end of  >= 0x80 */
  954.         cnt = *dptr++;
  955.       } /* end while cnt */
  956.     } else /* bytes == 4 */
  957.     { xaULONG *iptr = (xaULONG *)(image + 4 * ((y * imagex) + (4 * (xskip-1))) );
  958.       while(cnt != 0xff)
  959.       {
  960.         if (cnt == 0x00) { xskip = *dptr++; iptr += 4 * (xskip-1); }
  961.         else if (cnt < 0x80)            /* run of data */
  962.         {
  963.           cnt *= 4; while(cnt--) *iptr++ = (xaULONG)map[*dptr++];
  964.         } else                    /* repeat data */
  965.         { xaULONG d1,d2,d3,d4; cnt = 0x100 - cnt;
  966.       { d1 = (xaULONG)map[*dptr++]; d2 = (xaULONG)map[*dptr++]; 
  967.         d3 = (xaULONG)map[*dptr++]; d4 = (xaULONG)map[*dptr++]; }
  968.           while(cnt--) { *iptr++ =d1; *iptr++ =d2; *iptr++ =d3; *iptr++ =d4; }
  969.         } /* end of  >= 0x80 */
  970.         cnt = *dptr++;
  971.       } /* end while cnt */
  972.     }
  973.     y++;
  974.   } /* end of lines */
  975.  /* one more zero byte */
  976.  dec_info->xs = dec_info->ys = 0; dec_info->xe = imagex; dec_info->ye = imagey;
  977.  if (map_flag==xaTRUE) return(ACT_DLTA_MAPD);
  978.  else return(ACT_DLTA_NORM);
  979. }
  980.  
  981. /********************* * * * *******************************************/
  982. xaULONG QT_Decode_RLE16(image,delta,dsize,dec_info)
  983. xaUBYTE *image;         /* Image Buffer. */
  984. xaUBYTE *delta;         /* delta data. */
  985. xaULONG dsize;          /* delta size */
  986. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  987. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  988.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  989.   xaULONG special = dec_info->special;
  990.   XA_CHDR *chdr = dec_info->chdr;
  991.   xaLONG y,d,lines; /* xaLONG min_x,max_x,min_y,max_y; */
  992.   xaULONG special_flag;
  993.   xaUBYTE r,g,b,*dptr;
  994.  
  995.   if (chdr) { if (chdr->new_chdr) chdr = chdr->new_chdr; }
  996.  
  997.   special_flag = special & 0x0001;
  998.  
  999.   dptr = delta;
  1000.   dptr += 4;    /* skip codec size */
  1001.   d = (*dptr++) << 8;  d |= *dptr++;   /* read code either 0008 or 0000 */
  1002.   if (dsize < 8) /* NOP */
  1003.   {
  1004.     dec_info->xs = dec_info->ys = dec_info->xe = dec_info->ye = 0;
  1005.     return(ACT_DLTA_NOP);
  1006.   }
  1007.   if (d & 0x0008) /* Header present */
  1008.   {
  1009.     y = (*dptr++) << 8; y |= *dptr++;           /* start line */
  1010.     dptr += 2;                                  /* unknown */
  1011.     lines = (*dptr++) << 8; lines |= *dptr++;   /* number of lines */
  1012.     dptr += 2;                                  /* unknown */
  1013.   }
  1014.   else { y = 0; lines = imagey; }
  1015.   while(lines--)                /* loop thru lines */
  1016.   {
  1017.     xaULONG d,xskip,cnt;
  1018.     xskip = *dptr++;                /* skip x pixels */
  1019.     if (xskip==0) break;            /* exit */
  1020.     cnt = *dptr++;                /* RLE code */
  1021.  
  1022.     if (special_flag)
  1023.     { xaUBYTE *iptr = (xaUBYTE *)(image + 3*((y * imagex) + (xskip-1)) );
  1024.       while(cnt != 0xff)                /* while not EOL */
  1025.       {
  1026.         if (cnt == 0x00) { xskip = *dptr++; iptr += 3*(xskip-1); }
  1027.         else if (cnt < 0x80)                /* run of data */
  1028.           while(cnt--) { d = (*dptr++ << 8); d |= *dptr++;
  1029.              QT_Get_RGBColor(&r,&g,&b,d);
  1030.             *iptr++ = r; *iptr++ = g; *iptr++ = b; }
  1031.         else                        /* repeat data */
  1032.         { cnt = 0x100 - cnt; d = (*dptr++ << 8); d |= *dptr++;
  1033.           QT_Get_RGBColor(&r,&g,&b,d);
  1034.           while(cnt--) { *iptr++ = r; *iptr++ = g; *iptr++ = b; }
  1035.         }
  1036.         cnt = *dptr++;                /* get new RLE code */
  1037.       } /* end of line */
  1038.     }
  1039.     else if ( (x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  1040.     { xaUBYTE *iptr = (xaUBYTE *)(image + (y * imagex) + (xskip-1) );
  1041.       while(cnt != 0xff)                /* while not EOL */
  1042.       {
  1043.         if (cnt == 0x00) { xskip = *dptr++; iptr += (xskip-1); }
  1044.         else if (cnt < 0x80)                /* run of data */
  1045.           while(cnt--) { d = (*dptr++ << 8); d |= *dptr++;
  1046.         *iptr++ = (xaUBYTE)QT_Get_Color(d,map_flag,map,chdr); }
  1047.         else                        /* repeat data */
  1048.         { cnt = 0x100 - cnt; d = (*dptr++ << 8); d |= *dptr++;
  1049.           d = QT_Get_Color(d,map_flag,map,chdr);
  1050.           while(cnt--) { *iptr++ = (xaUBYTE)d; }
  1051.         }
  1052.         cnt = *dptr++;                /* get new RLE code */
  1053.       } /* end of line */
  1054.     }
  1055.     else if (x11_bytes_pixel==4)
  1056.     { xaULONG *iptr = (xaULONG *)(image + 4*((y * imagex)+(xskip-1)) );
  1057.       while(cnt != 0xff)                /* while not EOL */
  1058.       {
  1059.         if (cnt == 0x00) { xskip = *dptr++; iptr += (xskip-1); }
  1060.         else if (cnt < 0x80)                /* run of data */
  1061.           while(cnt--) { d = (*dptr++ << 8); d |= *dptr++;
  1062.         *iptr++ = (xaULONG)QT_Get_Color(d,map_flag,map,chdr); }
  1063.         else                        /* repeat data */
  1064.         { cnt = 0x100 - cnt; d = (*dptr++ << 8); d |= *dptr++;
  1065.           d = QT_Get_Color(d,map_flag,map,chdr);
  1066.           while(cnt--) { *iptr++ = (xaULONG)d; }
  1067.         }
  1068.         cnt = *dptr++;                /* get new RLE code */
  1069.       } /* end of line */
  1070.     }
  1071.     else /* if (x11_bytes_pixel==2) */
  1072.     { xaUSHORT *iptr = (xaUSHORT *)(image + 2*((y * imagex)+(xskip-1)) );
  1073.       while(cnt != 0xff)                /* while not EOL */
  1074.       {
  1075.         if (cnt == 0x00) { xskip = *dptr++; iptr += (xskip-1); }
  1076.         else if (cnt < 0x80)                /* run of data */
  1077.           while(cnt--) { d = (*dptr++ << 8); d |= *dptr++;
  1078.         *iptr++ = (xaUSHORT)QT_Get_Color(d,map_flag,map,chdr); }
  1079.         else                        /* repeat data */
  1080.         { cnt = 0x100 - cnt; d = (*dptr++ << 8); d |= *dptr++;
  1081.           d = QT_Get_Color(d,map_flag,map,chdr);
  1082.           while(cnt--) { *iptr++ = (xaUSHORT)d; }
  1083.         }
  1084.         cnt = *dptr++;                /* get new RLE code */
  1085.       } /* end of line */
  1086.     }
  1087.     y++;
  1088.   } /* end of lines */
  1089.  /* one more zero byte */
  1090.  dec_info->xs = dec_info->ys = 0; dec_info->xe = imagex; dec_info->ye = imagey;
  1091.  if (map_flag==xaTRUE) return(ACT_DLTA_MAPD);
  1092.  else return(ACT_DLTA_NORM);
  1093. }
  1094.  
  1095. /********************* * * * *******************************************/
  1096. xaULONG QT_Decode_RLE24(image,delta,dsize,dec_info)
  1097. xaUBYTE *image;         /* Image Buffer. */
  1098. xaUBYTE *delta;         /* delta data. */
  1099. xaULONG dsize;          /* delta size */
  1100. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  1101. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  1102.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  1103.   xaULONG special = dec_info->special;
  1104.   XA_CHDR *chdr = dec_info->chdr;
  1105.   xaLONG y,d,lines; /* xaULONG min_x,max_x,min_y,max_y; */
  1106.   xaULONG special_flag,r,g,b;
  1107.   xaUBYTE *dptr;
  1108.  
  1109.   if (chdr) { if (chdr->new_chdr) chdr = chdr->new_chdr; }
  1110.  
  1111.   special_flag = special & 0x0001;
  1112.  
  1113.   dptr = delta;
  1114.   dptr += 4;    /* skip codec size */
  1115.   d = (*dptr++) << 8;  d |= *dptr++;   /* read code either 0008 or 0000 */
  1116.   if (dsize < 8) /* NOP */
  1117.   {  dec_info->xs = dec_info->ys = dec_info->xe = dec_info->ye = 0;
  1118.     return(ACT_DLTA_NOP);
  1119.   }
  1120.   if (d & 0x0008) /* Header present */
  1121.   { y = (*dptr++) << 8; y |= *dptr++;        /* start line */
  1122.     dptr += 2;                    /* unknown */
  1123.     lines = (*dptr++) << 8; lines |= *dptr++;    /* number of lines */
  1124.     dptr += 2;                    /* unknown */
  1125.   }
  1126.   else { y = 0; lines = imagey; }
  1127.  
  1128.   while(lines--)                /* loop thru lines */
  1129.   { xaULONG d,xskip,cnt;
  1130.     xskip = *dptr++;                /* skip x pixels */
  1131.     if (xskip == 0) break;             /* exit */
  1132.     cnt = *dptr++;                /* RLE code */
  1133.  
  1134.     if (special_flag)
  1135.     { xaUBYTE *iptr = (xaUBYTE *)(image + 3*((y * imagex) + (xskip-1)) );
  1136.       while(cnt != 0xff)                /* while not EOL */
  1137.       { if (cnt == 0x00) { xskip = *dptr++; iptr += 3*(xskip-1); }
  1138.         else if (cnt < 0x80)                /* run of data */
  1139.           while(cnt--) { r = *dptr++; g = *dptr++; b = *dptr++;
  1140.             *iptr++ = (xaUBYTE)r; *iptr++ = (xaUBYTE)g; 
  1141.                         *iptr++ = (xaUBYTE)b; }
  1142.         else                        /* repeat data */
  1143.         { cnt = 0x100 - cnt; r = *dptr++; g = *dptr++; b = *dptr++;
  1144.           while(cnt--) { *iptr++ = (xaUBYTE)r; *iptr++ = (xaUBYTE)g; 
  1145.                          *iptr++ = (xaUBYTE)b; }
  1146.         }
  1147.         cnt = *dptr++;                /* get new RLE code */
  1148.       } /* end of line */
  1149.     }
  1150.     else if ( (x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  1151.     { xaUBYTE *iptr = (xaUBYTE *)(image + (y * imagex) + (xskip-1) );
  1152.       while(cnt != 0xff)                /* while not EOL */
  1153.       { if (cnt == 0x00) { xskip = *dptr++; iptr += (xskip-1); }
  1154.         else if (cnt < 0x80)                /* run of data */
  1155.           while(cnt--) { r = *dptr++; g = *dptr++; b = *dptr++;
  1156.         *iptr++ = (xaUBYTE)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr); }
  1157.         else                        /* repeat data */
  1158.         { cnt = 0x100 - cnt; r = *dptr++; g = *dptr++; b = *dptr++;
  1159.           d = XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  1160.           while(cnt--) { *iptr++ = (xaUBYTE)d; }
  1161.         }
  1162.         cnt = *dptr++;                /* get new RLE code */
  1163.       } /* end of line */
  1164.     }
  1165.     else if (x11_bytes_pixel==4)
  1166.     { xaULONG *iptr = (xaULONG *)(image + 4*((y * imagex)+(xskip-1)) );
  1167.       while(cnt != 0xff)                /* while not EOL */
  1168.       { if (cnt == 0x00) { xskip = *dptr++; iptr += (xskip-1); }
  1169.         else if (cnt < 0x80)                /* run of data */
  1170.           while(cnt--) { r = *dptr++; g = *dptr++; b = *dptr++;
  1171.         *iptr++ = (xaULONG)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr); }
  1172.         else                        /* repeat data */
  1173.         { cnt = 0x100 - cnt; r = *dptr++; g = *dptr++; b = *dptr++;
  1174.           d = XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  1175.           while(cnt--) { *iptr++ = (xaULONG)d; }
  1176.         }
  1177.         cnt = *dptr++;                /* get new RLE code */
  1178.       } /* end of line */
  1179.     }
  1180.     else /* if (x11_bytes_pixel==2) */
  1181.     { xaUSHORT *iptr = (xaUSHORT *)(image + 2*((y * imagex)+(xskip-1)) );
  1182.       while(cnt != 0xff)                /* while not EOL */
  1183.       {
  1184.         if (cnt == 0x00) { xskip = *dptr++; iptr += (xskip-1); }
  1185.         else if (cnt < 0x80)                /* run of data */
  1186.           while(cnt--) { r = *dptr++; g = *dptr++; b = *dptr++;
  1187.            *iptr++ = (xaUSHORT)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr); }
  1188.         else                        /* repeat data */
  1189.         { cnt = 0x100 - cnt; r = *dptr++; g = *dptr++; b = *dptr++;
  1190.           d = XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  1191.           while(cnt--) { *iptr++ = (xaUSHORT)d; }
  1192.         }
  1193.         cnt = *dptr++;                /* get new RLE code */
  1194.       } /* end of line */
  1195.     }
  1196.     y++;
  1197.   } /* end of lines */
  1198.  /* one more zero byte */
  1199.   dec_info->xs = dec_info->ys = 0; dec_info->xe = imagex; dec_info->ye = imagey;
  1200.   if (map_flag==xaTRUE) return(ACT_DLTA_MAPD);
  1201.   else return(ACT_DLTA_NORM);
  1202. }
  1203.  
  1204. /********************* * * * *******************************************/
  1205. xaULONG QT_Decode_RLE32(image,delta,dsize,dec_info)
  1206. xaUBYTE *image;         /* Image Buffer. */
  1207. xaUBYTE *delta;         /* delta data. */
  1208. xaULONG dsize;          /* delta size */
  1209. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  1210. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  1211.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  1212.   xaULONG special = dec_info->special;
  1213.   XA_CHDR *chdr = dec_info->chdr;
  1214.   xaLONG y,d,lines; /* xaULONG min_x,max_x,min_y,max_y; */
  1215.   xaULONG special_flag,r,g,b;
  1216.   xaUBYTE *dp;
  1217.  
  1218.   if (chdr) { if (chdr->new_chdr) chdr = chdr->new_chdr; }
  1219.  
  1220.   special_flag = special & 0x0001;
  1221.  
  1222.   dp = delta;
  1223.   dp += 4;    /* skip codec size */
  1224.   d = (*dp++) << 8;  d |= *dp++;   /* read code either 0008 or 0000 */
  1225.   if (dsize < 8) /* NOP */
  1226.   {
  1227.     dec_info->xs = dec_info->ys = dec_info->xe = dec_info->ye = 0;
  1228.     return(ACT_DLTA_NOP);
  1229.   }
  1230.   if (d & 0x0008) /* Header present */
  1231.   {
  1232.     y = (*dp++) << 8; y |= *dp++;           /* start line */
  1233.     dp += 2;                                  /* unknown */
  1234.     lines = (*dp++) << 8; lines |= *dp++;   /* number of lines */
  1235.     dp += 2;                                  /* unknown */
  1236.   }
  1237.   else { y = 0; lines = imagey; }
  1238.   while(lines--)                /* loop thru lines */
  1239.   {
  1240.     xaULONG d,xskip,cnt;
  1241.     xskip = *dp++;                /* skip x pixels */
  1242.     if (xskip == 0) break;            /* exit */
  1243.     cnt = *dp++;                /* RLE code */
  1244.  
  1245.     if (special_flag)
  1246.     { xaUBYTE *iptr = (xaUBYTE *)(image + 3*((y * imagex) + (xskip-1)) );
  1247.       while(cnt != 0xff)                /* while not EOL */
  1248.       {
  1249.         if (cnt == 0x00) { xskip = *dp++; iptr += 3*(xskip-1); }
  1250.         else if (cnt < 0x80)                /* run of data */
  1251.           while(cnt--) { dp++; r = *dp++; g = *dp++; b = *dp++;
  1252.             *iptr++ = (xaUBYTE)r; *iptr++ = (xaUBYTE)g; 
  1253.                         *iptr++ = (xaUBYTE)b; }
  1254.         else                        /* repeat data */
  1255.         { cnt = 0x100 - cnt; dp++; r = *dp++; g = *dp++; b = *dp++;
  1256.           while(cnt--) { *iptr++ = (xaUBYTE)r; *iptr++ = (xaUBYTE)g; 
  1257.                          *iptr++ = (xaUBYTE)b; }
  1258.         }
  1259.         cnt = *dp++;                /* get new RLE code */
  1260.       } /* end of line */
  1261.     }
  1262.     else if ( (x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  1263.     { xaUBYTE *iptr = (xaUBYTE *)(image + (y * imagex) + (xskip-1) );
  1264.       while(cnt != 0xff)                /* while not EOL */
  1265.       {
  1266.         if (cnt == 0x00) { xskip = *dp++; iptr += (xskip-1); }
  1267.         else if (cnt < 0x80)                /* run of data */
  1268.           while(cnt--) { dp++; r = *dp++; g = *dp++; b = *dp++;
  1269.         *iptr++ = (xaUBYTE)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr); }
  1270.         else                        /* repeat data */
  1271.         { cnt = 0x100 - cnt; dp++; r = *dp++; g = *dp++; b = *dp++;
  1272.           d = XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  1273.           while(cnt--) { *iptr++ = (xaUBYTE)d; }
  1274.         }
  1275.         cnt = *dp++;                /* get new RLE code */
  1276.       } /* end of line */
  1277.     }
  1278.     else if (x11_bytes_pixel==4)
  1279.     { xaULONG *iptr = (xaULONG *)(image + 4*((y * imagex)+(xskip-1)) );
  1280.       while(cnt != 0xff)                /* while not EOL */
  1281.       {
  1282.         if (cnt == 0x00) { xskip = *dp++; iptr += (xskip-1); }
  1283.         else if (cnt < 0x80)                /* run of data */
  1284.           while(cnt--) { dp++; r = *dp++; g = *dp++; b = *dp++;
  1285.         *iptr++ = (xaULONG)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr); }
  1286.         else                        /* repeat data */
  1287.         { cnt = 0x100 - cnt; dp++; r = *dp++; g = *dp++; b = *dp++;
  1288.           d = XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  1289.           while(cnt--) { *iptr++ = (xaULONG)d; }
  1290.         }
  1291.         cnt = *dp++;                /* get new RLE code */
  1292.       } /* end of line */
  1293.     }
  1294.     else /* if (x11_bytes_pixel==2) */
  1295.     { xaUSHORT *iptr = (xaUSHORT *)(image + 2*((y * imagex)+(xskip-1)) );
  1296.       while(cnt != 0xff)                /* while not EOL */
  1297.       {
  1298.         if (cnt == 0x00) { xskip = *dp++; iptr += (xskip-1); }
  1299.         else if (cnt < 0x80)                /* run of data */
  1300.           while(cnt--) { dp++; r = *dp++; g = *dp++; b = *dp++;
  1301.         *iptr++ = (xaUSHORT)XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr); }
  1302.         else                        /* repeat data */
  1303.         { cnt = 0x100 - cnt; dp++; r = *dp++; g = *dp++; b = *dp++;
  1304.           d = XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
  1305.           while(cnt--) { *iptr++ = (xaUSHORT)d; }
  1306.         }
  1307.         cnt = *dp++;                /* get new RLE code */
  1308.       } /* end of line */
  1309.     }
  1310.     y++;
  1311.   } /* end of lines */
  1312.  /* one more zero byte */
  1313.   dec_info->xs = dec_info->ys = 0; dec_info->xe = imagex; dec_info->ye = imagey;
  1314.  if (map_flag==xaTRUE) return(ACT_DLTA_MAPD);
  1315.  else return(ACT_DLTA_NORM);
  1316. }
  1317.  
  1318. /********************* * * * *******************************************/
  1319. #define QT_BLOCK_INC(x,y,imagex) { x += 4; if (x>=imagex) { x=0; y += 4; }}
  1320.  
  1321. #define QT_RPZA_BLOCK_INC(x,y,imagex,im0,im1,im2,im3,binc,rinc) \
  1322. { x += 4; im0 += binc; im1 += binc; im2 += binc; im3 += binc;    \
  1323.   if (x>=imagex)                    \
  1324.   { x=0; y += 4; im0 += rinc; im1 += rinc; im2 += rinc; im3 += rinc; } }
  1325.  
  1326. #define QT_MIN_MAX_CHECK(x,y,min_x,min_y,max_x,max_y) {    \
  1327.   if (x > max_x) max_x=x; if (y > max_y) max_y=y;    \
  1328.   if (x < min_x) min_x=x; if (y < min_y) min_y=y;  }
  1329.  
  1330. #define QT_RPZA_C1(ip0,ip1,ip2,ip3,c,CAST) { \
  1331.  ip0[0] = ip0[1] = ip0[2] = ip0[3] = (CAST)c; \
  1332.  ip1[0] = ip1[1] = ip1[2] = ip1[3] = (CAST)c; \
  1333.  ip2[0] = ip2[1] = ip2[2] = ip2[3] = (CAST)c; \
  1334.  ip3[0] = ip3[1] = ip3[2] = ip3[3] = (CAST)c; }
  1335.  
  1336. #define QT_RPZA_C4(ip,c,mask,CAST); { \
  1337.  ip[0] =(CAST)(c[((mask>>6)&0x03)]); ip[1] =(CAST)(c[((mask>>4)&0x03)]); \
  1338.  ip[2] =(CAST)(c[((mask>>2)&0x03)]); ip[3] =(CAST)(c[ (mask & 0x03)]); }
  1339.  
  1340. #define QT_RPZA_C16(ip0,ip1,ip2,ip3,c,CAST) { \
  1341.  ip0[0] = (CAST)(*c++); ip0[1] = (CAST)(*c++); \
  1342.  ip0[2] = (CAST)(*c++); ip0[3] = (CAST)(*c++); \
  1343.  ip1[0] = (CAST)(*c++); ip1[1] = (CAST)(*c++); \
  1344.  ip1[2] = (CAST)(*c++); ip1[3] = (CAST)(*c++); \
  1345.  ip2[0] = (CAST)(*c++); ip2[1] = (CAST)(*c++); \
  1346.  ip2[2] = (CAST)(*c++); ip2[3] = (CAST)(*c++); \
  1347.  ip3[0] = (CAST)(*c++); ip3[1] = (CAST)(*c++); \
  1348.  ip3[2] = (CAST)(*c++); ip3[3] = (CAST)(*c  ); }
  1349.  
  1350. #define QT_RPZA_rgbC1(ip,r,g,b) { \
  1351.  ip[0] = ip[3] = ip[6] = ip[9]  = r; \
  1352.  ip[1] = ip[4] = ip[7] = ip[10] = g; \
  1353.  ip[2] = ip[5] = ip[8] = ip[11] = b; }
  1354.  
  1355. #define QT_RPZA_rgbC4(ip,r,g,b,mask); { xaULONG _idx; \
  1356.  _idx = (mask>>6)&0x03; ip[0] = r[_idx]; ip[1] = g[_idx]; ip[2] = b[_idx]; \
  1357.  _idx = (mask>>4)&0x03; ip[3] = r[_idx]; ip[4] = g[_idx]; ip[5] = b[_idx]; \
  1358.  _idx = (mask>>2)&0x03; ip[6] = r[_idx]; ip[7] = g[_idx]; ip[8] = b[_idx]; \
  1359.  _idx =  mask    &0x03; ip[9] = r[_idx]; ip[10] = g[_idx]; ip[11] = b[_idx]; }
  1360.  
  1361. #define QT_RPZA_rgbC16(ip,r,g,b) { \
  1362.  ip[0]= *r++; ip[1]= *g++; ip[2]= *b++; \
  1363.  ip[3]= *r++; ip[4]= *g++; ip[5]= *b++; \
  1364.  ip[6]= *r++; ip[7]= *g++; ip[8]= *b++; \
  1365.  ip[9]= *r++; ip[10]= *g++; ip[11]= *b++; }
  1366.  
  1367.  
  1368. #define RPZA_DITH_COL2RGB(_r,_g,_b,_col) { \
  1369. _r = (_col & 0x7c00); _g = (_col & 0x03e0); _b = (_col & 0x001f);    \
  1370. _r = _r | (_r >> 5);  _g = (_g << 5) | _g; _b = (_b << 10) | (_b << 5); }
  1371.  
  1372. #define RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col) { xaLONG r1,g1,b1; \
  1373.   r1 = (xaLONG)rnglimit[(r + re) >> 7];    \
  1374.   g1 = (xaLONG)rnglimit[(g + ge) >> 7];    \
  1375.   b1 = (xaLONG)rnglimit[(b + be) >> 7];    \
  1376.   col = (r1 & 0xe0) | ((g1 & 0xe0) >> 3) | ((b1 & 0xc0) >> 6); }
  1377.  
  1378. #define RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap) { \
  1379.   re =  ((xaLONG)(r) - (xaLONG)(cmap[col].red   >> 1)) >> 1; \
  1380.   ge =  ((xaLONG)(g) - (xaLONG)(cmap[col].green >> 1)) >> 1; \
  1381.   be =  ((xaLONG)(b) - (xaLONG)(cmap[col].blue  >> 1)) >> 1; }
  1382.  
  1383.  
  1384. /********************* * * * *******************************************/
  1385. xaULONG QT_Decode_RPZA(image,delta,dsize,dec_info)
  1386. xaUBYTE *image;         /* Image Buffer. */
  1387. xaUBYTE *delta;         /* delta data. */
  1388. xaULONG dsize;          /* delta size */
  1389. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  1390. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  1391.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  1392.   xaULONG special = dec_info->special;
  1393.   XA_CHDR *chdr = dec_info->chdr;
  1394.   xaLONG x,y,len,row_inc,blk_inc; 
  1395.   xaLONG min_x,max_x,min_y,max_y;
  1396.   xaUBYTE *dptr = delta;
  1397.   xaULONG code,changed;
  1398.   xaUBYTE *im0,*im1,*im2,*im3;
  1399.  
  1400.   dec_info->xs = dec_info->ys = 0; dec_info->xe = imagex; dec_info->ye = imagey;
  1401.  
  1402.   dptr++;            /* skip  0xe1 */
  1403.   len =(*dptr++)<<16; len |= (*dptr++)<< 8; len |= (*dptr++); /* Read Len */
  1404.   /* CHECK FOR CORRUPTION - FAIRLY COMMON */
  1405.   if (len != dsize)
  1406.   { if (xa_verbose==xaTRUE) 
  1407.     fprintf(stderr,"QT corruption-skipping this frame %x %x\n",dsize,len);
  1408.     return(ACT_DLTA_NOP);
  1409.   }
  1410.   len -= 4;                /* read 4 already */
  1411.  
  1412.   if (chdr) { if (chdr->new_chdr) chdr = chdr->new_chdr; }
  1413.  
  1414.    /* special case dither routine - fill out a bit */
  1415.   if (   (!special) && (x11_bytes_pixel==1) 
  1416.       && (chdr) && (x11_display_type == XA_PSEUDOCOLOR)
  1417.       && (cmap_color_func != 4)
  1418.       && (cmap_true_to_332 == xaTRUE) && (x11_cmap_size == 256)
  1419.       && (xa_dither_flag==xaTRUE)
  1420.      )
  1421.      return( QT_RPZA_Dither(image,dptr,len,dec_info) );
  1422.  
  1423.  
  1424.   max_x = max_y = 0; min_x = imagex; min_y = imagey; changed = 0;
  1425.   x = y = 0;
  1426.   if (special) blk_inc = 3;
  1427.   else if ( (x11_bytes_pixel==1) || (map_flag == xaFALSE) ) blk_inc = 1;
  1428.   else if (x11_bytes_pixel==2) blk_inc = 2;
  1429.   else blk_inc = 4;
  1430.   row_inc = blk_inc * imagex;
  1431.   blk_inc *= 4;
  1432.   im1 = im0 = image;    im1 += row_inc; 
  1433.   im2 = im1;        im2 += row_inc;
  1434.   im3 = im2;        im3 += row_inc;
  1435.   row_inc *= 3; /* skip 3 rows at a time */
  1436.  
  1437.   
  1438.   while(len > 0)
  1439.   { code = *dptr++; len--;
  1440.  
  1441.     if ( (code >= 0xa0) && (code <= 0xbf) )            /* SINGLE */
  1442.     {
  1443.       xaULONG color,skip;
  1444.       changed = 1;
  1445.       color = (*dptr++) << 8; color |= *dptr++; len -= 2;
  1446.       skip = (code-0x9f);
  1447.       if (special)
  1448.       { xaUBYTE r,g,b;
  1449.         QT_Get_RGBColor(&r,&g,&b,color); 
  1450.         while(skip--)
  1451.         { xaUBYTE *ip0=im0; xaUBYTE *ip1=im1; xaUBYTE *ip2=im2; xaUBYTE *ip3=im3;
  1452.       QT_RPZA_rgbC1(ip0,r,g,b);
  1453.       QT_RPZA_rgbC1(ip1,r,g,b);
  1454.       QT_RPZA_rgbC1(ip2,r,g,b);
  1455.       QT_RPZA_rgbC1(ip3,r,g,b);
  1456.       QT_MIN_MAX_CHECK(x,y,min_x,min_y,max_x,max_y);
  1457.       QT_RPZA_BLOCK_INC(x,y,imagex,im0,im1,im2,im3,blk_inc,row_inc);
  1458.     }
  1459.       }
  1460.       else /* not special */
  1461.       {
  1462.         color = QT_Get_Color(color,map_flag,map,chdr); 
  1463.         while(skip--)
  1464.         {
  1465.           if ( (x11_bytes_pixel==1) || (map_flag == xaFALSE) )
  1466.           { xaUBYTE *ip0=im0; xaUBYTE *ip1=im1; xaUBYTE *ip2=im2; xaUBYTE *ip3=im3;
  1467.         QT_RPZA_C1(ip0,ip1,ip2,ip3,color,xaUBYTE);
  1468.       }
  1469.           else if (x11_bytes_pixel==4)
  1470.           { xaULONG *ip0= (xaULONG *)im0; xaULONG *ip1= (xaULONG *)im1; 
  1471.         xaULONG *ip2= (xaULONG *)im2; xaULONG *ip3= (xaULONG *)im3;
  1472.         QT_RPZA_C1(ip0,ip1,ip2,ip3,color,xaULONG);
  1473.       }
  1474.           else /* if (x11_bytes_pixel==2) */
  1475.           { xaUSHORT *ip0= (xaUSHORT *)im0; xaUSHORT *ip1= (xaUSHORT *)im1; 
  1476.         xaUSHORT *ip2= (xaUSHORT *)im2; xaUSHORT *ip3= (xaUSHORT *)im3;
  1477.         QT_RPZA_C1(ip0,ip1,ip2,ip3,color,xaUSHORT);
  1478.       }
  1479.       QT_MIN_MAX_CHECK(x,y,min_x,min_y,max_x,max_y);
  1480.       QT_RPZA_BLOCK_INC(x,y,imagex,im0,im1,im2,im3,blk_inc,row_inc);
  1481.         } /* end of skip-- */
  1482.       } /* end not special */
  1483.     }
  1484.     else if ( (code >= 0x80) && (code <= 0x9f) )        /* SKIP */
  1485.     { xaULONG skip = (code-0x7f);
  1486.       while(skip--) 
  1487.         QT_RPZA_BLOCK_INC(x,y,imagex,im0,im1,im2,im3,blk_inc,row_inc);
  1488.     }
  1489.     else if ( (code < 0x80)                 /* FOUR/SIXTEEN */ 
  1490.          || ((code >= 0xc0) && (code <= 0xdf)) )
  1491.     { xaULONG cA,cB;
  1492.       changed = 1;
  1493.       /* Get 1st two colors */
  1494.       if (code >= 0xc0) { cA = (*dptr++) << 8; cA |= *dptr++; len -= 2; }
  1495.       else {cA = (code << 8) | *dptr++; len -= 1;}
  1496.       cB = (*dptr++) << 8; cB |= *dptr++; len -= 2;
  1497.  
  1498.       /****** SIXTEEN COLOR *******/
  1499.       if ( (code < 0x80) && ((cB & 0x8000)==0) ) /* 16 color */
  1500.       {
  1501.         xaULONG i,d,*clr,c[16];
  1502.         xaUBYTE r[16],g[16],b[16];
  1503.     if (special)
  1504.     { QT_Get_RGBColor(&r[0],&g[0],&b[0],cA);
  1505.           QT_Get_RGBColor(&r[1],&g[1],&b[1],cB);
  1506.           for(i=2; i<16; i++)
  1507.           {
  1508.             d = (*dptr++) << 8; d |= *dptr++; len -= 2;
  1509.             QT_Get_RGBColor(&r[i],&g[i],&b[i],d);
  1510.           }
  1511.     }
  1512.     else
  1513.     {
  1514.       clr = c;
  1515.           *clr++ = QT_Get_Color(cA,map_flag,map,chdr);
  1516.           *clr++ = QT_Get_Color(cB,map_flag,map,chdr);
  1517.           for(i=2; i<16; i++)
  1518.           {
  1519.             d = (*dptr++) << 8; d |= *dptr++; len -= 2;
  1520.             *clr++ = QT_Get_Color(d,map_flag,map,chdr);
  1521.           }
  1522.     }
  1523.     clr = c;
  1524.     if (special)
  1525.         { xaUBYTE *ip0=im0; xaUBYTE *ip1=im1; xaUBYTE *ip2=im2; xaUBYTE *ip3=im3;
  1526.       xaUBYTE *tr,*tg,*tb; tr=r; tg=g; tb=b;
  1527.       QT_RPZA_rgbC16(ip0,tr,tg,tb);
  1528.       QT_RPZA_rgbC16(ip1,tr,tg,tb);
  1529.       QT_RPZA_rgbC16(ip2,tr,tg,tb);
  1530.       QT_RPZA_rgbC16(ip3,tr,tg,tb);
  1531.     }
  1532.     else if ( (x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  1533.         { xaUBYTE *ip0=im0; xaUBYTE *ip1=im1; xaUBYTE *ip2=im2; xaUBYTE *ip3=im3;
  1534.       QT_RPZA_C16(ip0,ip1,ip2,ip3,clr,xaUBYTE);
  1535.     }
  1536.     else if (x11_bytes_pixel==4)
  1537.         { xaULONG *ip0= (xaULONG *)im0; xaULONG *ip1= (xaULONG *)im1; 
  1538.       xaULONG *ip2= (xaULONG *)im2; xaULONG *ip3= (xaULONG *)im3;
  1539.       QT_RPZA_C16(ip0,ip1,ip2,ip3,clr,xaULONG);
  1540.     }
  1541.     else /* if (x11_bytes_pixel==2) */
  1542.         { xaUSHORT *ip0= (xaUSHORT *)im0; xaUSHORT *ip1= (xaUSHORT *)im1; 
  1543.       xaUSHORT *ip2= (xaUSHORT *)im2; xaUSHORT *ip3= (xaUSHORT *)im3;
  1544.       QT_RPZA_C16(ip0,ip1,ip2,ip3,clr,xaUSHORT);
  1545.     }
  1546.     QT_MIN_MAX_CHECK(x,y,min_x,min_y,max_x,max_y);
  1547.     QT_RPZA_BLOCK_INC(x,y,imagex,im0,im1,im2,im3,blk_inc,row_inc);
  1548.       } /*** END of SIXTEEN COLOR */
  1549.       else                    /****** FOUR COLOR *******/
  1550.       { xaULONG m_cnt,msk0,msk1,msk2,msk3,c[4];
  1551.     xaUBYTE r[4],g[4],b[4];
  1552.  
  1553.         if (code < 0x80) m_cnt = 1; 
  1554.     else m_cnt = code - 0xbf; 
  1555.  
  1556.     if (special)        QT_Get_AV_RGBColors(c,r,g,b,cA,cB);
  1557.     else            QT_Get_AV_Colors(c,cA,cB,map_flag,map,chdr);
  1558.  
  1559.         while(m_cnt--)
  1560.         { msk0 = *dptr++; msk1 = *dptr++;
  1561.       msk2 = *dptr++; msk3 = *dptr++; len -= 4;
  1562.       if (special)
  1563.           { xaUBYTE *ip0=im0; xaUBYTE *ip1=im1; xaUBYTE *ip2=im2; xaUBYTE *ip3=im3;
  1564.         QT_RPZA_rgbC4(ip0,r,g,b,msk0);
  1565.         QT_RPZA_rgbC4(ip1,r,g,b,msk1);
  1566.         QT_RPZA_rgbC4(ip2,r,g,b,msk2);
  1567.         QT_RPZA_rgbC4(ip3,r,g,b,msk3);
  1568.       }
  1569.       else if ( (x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  1570.           { xaUBYTE *ip0=im0; xaUBYTE *ip1=im1; xaUBYTE *ip2=im2; xaUBYTE *ip3=im3;
  1571.         QT_RPZA_C4(ip0,c,msk0,xaUBYTE);
  1572.         QT_RPZA_C4(ip1,c,msk1,xaUBYTE);
  1573.         QT_RPZA_C4(ip2,c,msk2,xaUBYTE);
  1574.         QT_RPZA_C4(ip3,c,msk3,xaUBYTE);
  1575.       }
  1576.       else if (x11_bytes_pixel==4)
  1577.           { xaULONG *ip0= (xaULONG *)im0; xaULONG *ip1= (xaULONG *)im1; 
  1578.         xaULONG *ip2= (xaULONG *)im2; xaULONG *ip3= (xaULONG *)im3;
  1579.         QT_RPZA_C4(ip0,c,msk0,xaULONG);
  1580.         QT_RPZA_C4(ip1,c,msk1,xaULONG);
  1581.         QT_RPZA_C4(ip2,c,msk2,xaULONG);
  1582.         QT_RPZA_C4(ip3,c,msk3,xaULONG);
  1583.       }
  1584.       else /* if (x11_bytes_pixel==2) */
  1585.           { xaUSHORT *ip0= (xaUSHORT *)im0; xaUSHORT *ip1= (xaUSHORT *)im1; 
  1586.         xaUSHORT *ip2= (xaUSHORT *)im2; xaUSHORT *ip3= (xaUSHORT *)im3;
  1587.         QT_RPZA_C4(ip0,c,msk0,xaUSHORT);
  1588.         QT_RPZA_C4(ip1,c,msk1,xaUSHORT);
  1589.         QT_RPZA_C4(ip2,c,msk2,xaUSHORT);
  1590.         QT_RPZA_C4(ip3,c,msk3,xaUSHORT);
  1591.       }
  1592.       QT_MIN_MAX_CHECK(x,y,min_x,min_y,max_x,max_y);
  1593.       QT_RPZA_BLOCK_INC(x,y,imagex,im0,im1,im2,im3,blk_inc,row_inc);
  1594.         }  
  1595.       } /*** END of FOUR COLOR *******/
  1596.     } /*** END of 4/16 COLOR BLOCKS ****/
  1597.     else /* UNKNOWN */
  1598.     {
  1599.       fprintf(stderr,"QT RPZA: Unknown %x\n",code);
  1600.       return(ACT_DLTA_NOP);
  1601.     }
  1602.   }
  1603.   if (xa_optimize_flag == xaTRUE)
  1604.   {
  1605.     if (changed) { dec_info->xs=min_x; dec_info->ys=min_y;
  1606.            dec_info->xe=max_x + 4; dec_info->ye=max_y + 4; }
  1607.     else  { dec_info->xs = dec_info->ys = dec_info->xe = dec_info->ye = 0;
  1608.         return(ACT_DLTA_NOP); }
  1609.   }
  1610.   else { dec_info->xs = dec_info->ys = 0; 
  1611.      dec_info->xe = imagex; dec_info->ye = imagey; }
  1612.   if (map_flag) return(ACT_DLTA_MAPD);
  1613.   else return(ACT_DLTA_NORM);
  1614. }
  1615.  
  1616. void QT_Get_RGBColor(r,g,b,color)
  1617. xaUBYTE *r,*g,*b;
  1618. xaULONG color;
  1619. { xaULONG ra,ga,ba;
  1620.   ra = (color >> 10) & 0x1f;    ra = (ra << 3) | (ra >> 2);
  1621.   ga = (color >>  5) & 0x1f;    ga = (ga << 3) | (ga >> 2);
  1622.   ba =  color & 0x1f;        ba = (ba << 3) | (ba >> 2);
  1623.   *r = ra; *g = ga; *b = ba;
  1624. }
  1625.  
  1626. void QT_Get_RGBColorL(r,g,b,color)
  1627. xaLONG *r,*g,*b;
  1628. xaULONG color;
  1629. { xaULONG ra,ga,ba;
  1630.   ra = (color >> 10) & 0x1f;    ra = (ra << 3) | (ra >> 2);
  1631.   ga = (color >>  5) & 0x1f;    ga = (ga << 3) | (ga >> 2);
  1632.   ba =  color & 0x1f;        ba = (ba << 3) | (ba >> 2);
  1633.   *r = ra; *g = ga; *b = ba;
  1634. }
  1635.  
  1636. xaULONG QT_Get_Color(color,map_flag,map,chdr)
  1637. xaULONG color,map_flag,*map;
  1638. XA_CHDR *chdr;
  1639. {
  1640.   register xaULONG clr,ra,ga,ba,ra5,ga5,ba5;
  1641.  
  1642.   ra5 = (color >> 10) & 0x1f;
  1643.   ga5 = (color >>  5) & 0x1f;
  1644.   ba5 =  color & 0x1f;
  1645.   ra = qt_gamma_adj[ra5]; ga = qt_gamma_adj[ga5]; ba = qt_gamma_adj[ba5];
  1646.  
  1647.   if (x11_display_type & XA_X11_TRUE) clr = X11_Get_True_Color(ra,ga,ba,16);
  1648.   else 
  1649.   { 
  1650.     if ((cmap_color_func == 4) && (chdr))
  1651.     { register xaULONG cache_i = color & 0x7fff;
  1652.       if (cmap_cache == 0) CMAP_Cache_Init(0);
  1653.       if (chdr != cmap_cache_chdr)
  1654.       {
  1655.         CMAP_Cache_Clear();
  1656.         cmap_cache_chdr = chdr;
  1657.       }
  1658.       if (cmap_cache[cache_i] == 0xffff)
  1659.       {
  1660.         clr = chdr->coff +
  1661.            CMAP_Find_Closest(chdr->cmap,chdr->csize,ra,ga,ba,16,16,16,xaTRUE);
  1662.         cmap_cache[cache_i] = (xaUSHORT)clr;
  1663.       }
  1664.       else clr = (xaULONG)cmap_cache[cache_i];
  1665.     }
  1666.     else
  1667.     {
  1668.       if (cmap_true_to_332 == xaTRUE) clr = CMAP_GET_332(ra5,ga5,ba5,CMAP_SCALE5);
  1669.       else              clr = CMAP_GET_GRAY(ra5,ga5,ba5,CMAP_SCALE10);
  1670.       if (map_flag) clr = map[clr];
  1671.     }
  1672.   }
  1673.   return(clr);
  1674. }
  1675.  
  1676.  
  1677. void QT_Get_AV_RGBColors(c,r,g,b,cA,cB)
  1678. xaULONG *c;
  1679. xaUBYTE *r,*g,*b;
  1680. xaULONG cA,cB;
  1681. { xaULONG rA,gA,bA,rB,gB,bB,ra,ga,ba;
  1682. /**color 3 ***/
  1683.   rA = (cA >> 10) & 0x1f;    r[3] = (rA << 3) | (rA >> 2);
  1684.   gA = (cA >>  5) & 0x1f;    g[3] = (gA << 3) | (gA >> 2);
  1685.   bA =  cA & 0x1f;        b[3] = (bA << 3) | (bA >> 2);
  1686. /**color 0 ***/
  1687.   rB = (cB >> 10) & 0x1f;    r[0] = (rB << 3) | (rB >> 2);
  1688.   gB = (cB >>  5) & 0x1f;    g[0] = (gB << 3) | (gB >> 2);
  1689.   bB =  cB & 0x1f;        b[0] = (bB << 3) | (bB >> 2);
  1690. /**color 2 ***/
  1691.   ra = (21*rA + 11*rB) >> 5;    r[2] = (ra << 3) | (ra >> 2);
  1692.   ga = (21*gA + 11*gB) >> 5;    g[2] = (ga << 3) | (ga >> 2);
  1693.   ba = (21*bA + 11*bB) >> 5;    b[2] = (ba << 3) | (ba >> 2);
  1694. /**color 1 ***/
  1695.   ra = (11*rA + 21*rB) >> 5;    r[1] = (ra << 3) | (ra >> 2);
  1696.   ga = (11*gA + 21*gB) >> 5;    g[1] = (ga << 3) | (ga >> 2);
  1697.   ba = (11*bA + 21*bB) >> 5;    b[1] = (ba << 3) | (ba >> 2);
  1698. }
  1699.  
  1700. void QT_Get_AV_DITH_RGB(r,g,b,cA,cB)
  1701. xaLONG *r,*g,*b;
  1702. xaULONG cA,cB;
  1703. { xaULONG rA,gA,bA,rB,gB,bB,ra,ga,ba;
  1704. /**color 3 ***/
  1705.   rA = (cA >> 10) & 0x1f;    r[3] = (rA << 9) | (rA << 4);
  1706.   gA = (cA >>  5) & 0x1f;    g[3] = (gA << 9) | (gA << 4);
  1707.   bA =  cA & 0x1f;        b[3] = (bA << 9) | (bA << 4);
  1708. /**color 0 ***/
  1709.   rB = (cB >> 10) & 0x1f;    r[0] = (rB << 9) | (rB << 4);
  1710.   gB = (cB >>  5) & 0x1f;    g[0] = (gB << 9) | (gB << 4);
  1711.   bB =  cB & 0x1f;        b[0] = (bB << 9) | (bB << 4);
  1712. /**color 2 ***/
  1713.   ra = (21*rA + 11*rB) >> 5;    r[2] = (ra << 9) | (ra << 4);
  1714.   ga = (21*gA + 11*gB) >> 5;    g[2] = (ga << 9) | (ga << 4);
  1715.   ba = (21*bA + 11*bB) >> 5;    b[2] = (ba << 9) | (ba << 4);
  1716. /**color 1 ***/
  1717.   ra = (11*rA + 21*rB) >> 5;    r[1] = (ra << 9) | (ra << 4);
  1718.   ga = (11*gA + 21*gB) >> 5;    g[1] = (ga << 9) | (ga << 4);
  1719.   ba = (11*bA + 21*bB) >> 5;    b[1] = (ba << 9) | (ba << 4);
  1720. }
  1721.  
  1722. void QT_Get_AV_Colors(c,cA,cB,map_flag,map,chdr)
  1723. xaULONG *c;
  1724. xaULONG cA,cB,map_flag,*map;
  1725. XA_CHDR *chdr;
  1726. {
  1727.   xaULONG clr,rA,gA,bA,rB,gB,bB,r0,g0,b0,r1,g1,b1;
  1728.   xaULONG rA5,gA5,bA5,rB5,gB5,bB5;
  1729.   xaULONG r05,g05,b05,r15,g15,b15;
  1730.  
  1731. /*color 3*/
  1732.   rA5 = (cA >> 10) & 0x1f;
  1733.   gA5 = (cA >>  5) & 0x1f;
  1734.   bA5 =  cA & 0x1f;
  1735. /*color 0*/
  1736.   rB5 = (cB >> 10) & 0x1f;
  1737.   gB5 = (cB >>  5) & 0x1f;
  1738.   bB5 =  cB & 0x1f;
  1739. /*color 2*/
  1740.   r05 = (21*rA5 + 11*rB5) >> 5;
  1741.   g05 = (21*gA5 + 11*gB5) >> 5;
  1742.   b05 = (21*bA5 + 11*bB5) >> 5;
  1743. /*color 1*/
  1744.   r15 = (11*rA5 + 21*rB5) >> 5;
  1745.   g15 = (11*gA5 + 21*gB5) >> 5;
  1746.   b15 = (11*bA5 + 21*bB5) >> 5;
  1747. /*adj and scale to 16 bits */
  1748.   rA=qt_gamma_adj[rA5]; gA=qt_gamma_adj[gA5]; bA=qt_gamma_adj[bA5];
  1749.   rB=qt_gamma_adj[rB5]; gB=qt_gamma_adj[gB5]; bB=qt_gamma_adj[bB5];
  1750.   r0=qt_gamma_adj[r05]; g0=qt_gamma_adj[g05]; b0=qt_gamma_adj[b05];
  1751.   r1=qt_gamma_adj[r15]; g1=qt_gamma_adj[g15]; b1=qt_gamma_adj[b15];
  1752.  
  1753.   /*** 1st Color **/
  1754.   if (x11_display_type & XA_X11_TRUE) clr = X11_Get_True_Color(rA,gA,bA,16);
  1755.   else 
  1756.   { 
  1757.     if ((cmap_color_func == 4) && (chdr))
  1758.     { register xaULONG cache_i = cA & 0x7fff;
  1759.       if (cmap_cache == 0) CMAP_Cache_Init(0);
  1760.       if (chdr != cmap_cache_chdr)
  1761.       {
  1762.         CMAP_Cache_Clear();
  1763.         cmap_cache_chdr = chdr;
  1764.       }
  1765.       if (cmap_cache[cache_i] == 0xffff)
  1766.       {
  1767.         clr = chdr->coff +
  1768.            CMAP_Find_Closest(chdr->cmap,chdr->csize,rA,gA,bA,16,16,16,xaTRUE);
  1769.         cmap_cache[cache_i] = (xaUSHORT)clr;
  1770.       }
  1771.       else clr = (xaULONG)cmap_cache[cache_i];
  1772.     }
  1773.     else
  1774.     { if (cmap_true_to_332 == xaTRUE) clr = CMAP_GET_332(rA5,gA5,bA5,CMAP_SCALE5);
  1775.       else    clr = CMAP_GET_GRAY(rA5,gA5,bA5,CMAP_SCALE10);
  1776.       if (map_flag) clr = map[clr];
  1777.     }
  1778.   }
  1779.   c[3] = clr;
  1780.  
  1781.   /*** 2nd Color **/
  1782.   if (x11_display_type & XA_X11_TRUE) clr = X11_Get_True_Color(rB,gB,bB,16);
  1783.   else 
  1784.   { 
  1785.     if ((cmap_color_func == 4) && (chdr))
  1786.     { register xaULONG cache_i = cB & 0x7fff;
  1787.       if (cmap_cache[cache_i] == 0xffff)
  1788.       {
  1789.         clr = chdr->coff +
  1790.            CMAP_Find_Closest(chdr->cmap,chdr->csize,rB,gB,bB,16,16,16,xaTRUE);
  1791.         cmap_cache[cache_i] = (xaUSHORT)clr;
  1792.       }
  1793.       else clr = (xaULONG)cmap_cache[cache_i];
  1794.     }
  1795.     else
  1796.     { if (cmap_true_to_332 == xaTRUE) clr = CMAP_GET_332(rB5,gB5,bB5,CMAP_SCALE5);
  1797.       else    clr = CMAP_GET_GRAY(rB5,gB5,bB5,CMAP_SCALE10);
  1798.       if (map_flag) clr = map[clr];
  1799.     }
  1800.   }
  1801.   c[0] = clr;
  1802.  
  1803.   /*** 1st Av ****/
  1804.   if (x11_display_type & XA_X11_TRUE) clr = X11_Get_True_Color(r0,g0,b0,16);
  1805.   else 
  1806.   { 
  1807.     if ((cmap_color_func == 4) && (chdr))
  1808.     { register xaULONG cache_i;
  1809.       cache_i = (xaULONG)(r05 << 10) | (g05 << 5) | b05;
  1810.       if (cmap_cache[cache_i] == 0xffff)
  1811.       {
  1812.         clr = chdr->coff +
  1813.            CMAP_Find_Closest(chdr->cmap,chdr->csize,r0,g0,b0,16,16,16,xaTRUE);
  1814.         cmap_cache[cache_i] = (xaUSHORT)clr;
  1815.       }
  1816.       else clr = (xaULONG)cmap_cache[cache_i];
  1817.     }
  1818.     else
  1819.     { if (cmap_true_to_332 == xaTRUE) clr = CMAP_GET_332(r05,g05,b05,CMAP_SCALE5);
  1820.       else    clr = CMAP_GET_GRAY(r05,g05,b05,CMAP_SCALE10);
  1821.       if (map_flag) clr = map[clr];
  1822.     }
  1823.   }
  1824.   c[2] = clr;
  1825.  
  1826.   /*** 2nd Av ****/
  1827.   if (x11_display_type & XA_X11_TRUE) clr = X11_Get_True_Color(r1,g1,b1,16);
  1828.   else 
  1829.   { 
  1830.     if ((cmap_color_func == 4) && (chdr))
  1831.     { register xaULONG cache_i;
  1832.       cache_i = (xaULONG)(r15 << 10) | (g15 << 5) | b15;
  1833.       if (cmap_cache[cache_i] == 0xffff)
  1834.       {
  1835.         clr = chdr->coff +
  1836.            CMAP_Find_Closest(chdr->cmap,chdr->csize,r1,g1,b1,16,16,16,xaTRUE);
  1837.         cmap_cache[cache_i] = (xaUSHORT)clr;
  1838.       }
  1839.       else clr = (xaULONG)cmap_cache[cache_i];
  1840.     }
  1841.     else
  1842.     { if (cmap_true_to_332 == xaTRUE) clr = CMAP_GET_332(r15,g15,b15,CMAP_SCALE5);
  1843.       else    clr = CMAP_GET_GRAY(r15,g15,b15,CMAP_SCALE10);
  1844.       if (map_flag) clr = map[clr];
  1845.     }
  1846.   }
  1847.   c[1] = clr;
  1848. }
  1849.  
  1850.  
  1851.  
  1852. #define QT_SMC_O2I(i,o,rinc) { \
  1853. *i++ = *o++; *i++ = *o++; *i++ = *o++; *i++ = *o++; i += rinc; o += rinc; \
  1854. *i++ = *o++; *i++ = *o++; *i++ = *o++; *i++ = *o++; i += rinc; o += rinc; \
  1855. *i++ = *o++; *i++ = *o++; *i++ = *o++; *i++ = *o++; i += rinc; o += rinc; \
  1856. *i++ = *o++; *i++ = *o++; *i++ = *o++; *i++ = *o++;  } 
  1857.  
  1858. #define QT_SMC_C1(i,c,rinc) { \
  1859. *i++ = c; *i++ = c; *i++ = c; *i++ = c;  i += rinc; \
  1860. *i++ = c; *i++ = c; *i++ = c; *i++ = c;  i += rinc; \
  1861. *i++ = c; *i++ = c; *i++ = c; *i++ = c;  i += rinc; \
  1862. *i++ = c; *i++ = c; *i++ = c; *i++ = c;  i += rinc; }
  1863.  
  1864. #define QT_SMC_C2(i,c0,c1,msk,rinc) { \
  1865. *i++ =(msk&0x80)?c1:c0; *i++ =(msk&0x40)?c1:c0; \
  1866. *i++ =(msk&0x20)?c1:c0; *i++ =(msk&0x10)?c1:c0; i += rinc; \
  1867. *i++ =(msk&0x08)?c1:c0; *i++ =(msk&0x04)?c1:c0; \
  1868. *i++ =(msk&0x02)?c1:c0; *i++ =(msk&0x01)?c1:c0; }
  1869.  
  1870. #define QT_SMC_C4(i,CST,c,mska,mskb,rinc) { \
  1871. *i++ = (CST)(c[(mska>>6) & 0x03]); *i++ = (CST)(c[(mska>>4) & 0x03]); \
  1872. *i++ = (CST)(c[(mska>>2) & 0x03]); *i++ = (CST)(c[mska & 0x03]); i+=rinc; \
  1873. *i++ = (CST)(c[(mskb>>6) & 0x03]); *i++ = (CST)(c[(mskb>>4) & 0x03]); \
  1874. *i++ = (CST)(c[(mskb>>2) & 0x03]); *i++ = (CST)(c[mskb & 0x03]); }
  1875.  
  1876. #define QT_SMC_C8(i,CST,c,msk,rinc) { \
  1877. *i++ = (CST)(c[(msk>>21) & 0x07]); *i++ = (CST)(c[(msk>>18) & 0x07]); \
  1878. *i++ = (CST)(c[(msk>>15) & 0x07]); *i++ = (CST)(c[(msk>>12) & 0x07]); i+=rinc; \
  1879. *i++ = (CST)(c[(msk>> 9) & 0x07]); *i++ = (CST)(c[(msk>> 6) & 0x07]); \
  1880. *i++ = (CST)(c[(msk>> 3) & 0x07]); *i++ = (CST)(c[msk & 0x07]); }
  1881.  
  1882. #define QT_SMC_C16m(i,dp,CST,map,rinc) { \
  1883. *i++ =(CST)map[*dp++]; *i++ =(CST)map[*dp++]; \
  1884. *i++ =(CST)map[*dp++]; *i++ =(CST)map[*dp++]; i += rinc; \
  1885. *i++ =(CST)map[*dp++]; *i++ =(CST)map[*dp++]; \
  1886. *i++ =(CST)map[*dp++]; *i++ =(CST)map[*dp++]; }
  1887.  
  1888. #define QT_SMC_C16(i,dp,CST) { \
  1889. *i++ =(CST)(*dp++); *i++ =(CST)(*dp++); \
  1890. *i++ =(CST)(*dp++); *i++ =(CST)(*dp++); }
  1891.  
  1892. xaULONG
  1893. QT_Decode_SMC(image,delta,dsize,dec_info)
  1894. xaUBYTE *image;         /* Image Buffer. */
  1895. xaUBYTE *delta;         /* delta data. */
  1896. xaULONG dsize;          /* delta size */
  1897. XA_DEC_INFO *dec_info;  /* Decoder Info Header */
  1898. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  1899.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  1900.   xaLONG x,y,len,row_inc; /* xaLONG min_x,max_x,min_y,max_y; */
  1901.   xaUBYTE *dptr;
  1902.   xaULONG i,cnt,hicode,code;
  1903.   xaULONG *c;
  1904.  
  1905.   smc_8cnt = smc_Acnt = smc_Ccnt = 0;
  1906.  
  1907.   dec_info->xs = dec_info->ys = 0; dec_info->xe = imagex; dec_info->ye = imagey;
  1908.   dptr = delta;
  1909.   x = y = 0;
  1910.   row_inc = imagex - 4;
  1911.  
  1912.   dptr++;                /* skip over 0xe1 */
  1913.   len =(*dptr++)<<16; len |= (*dptr++)<< 8; len |= (*dptr++); /* Read Len */
  1914.   len -= 4;                /* read 4 already */
  1915.   while(len > 0)
  1916.   {
  1917.     code = *dptr++; len--; hicode = code & 0xf0;
  1918.     switch(hicode)
  1919.     {
  1920.       case 0x00: /* SKIPs */
  1921.       case 0x10:
  1922.     if (hicode == 0x10) {cnt = 1 + *dptr++; len -= 1;}
  1923.     else cnt = 1 + (code & 0x0f);
  1924.         while(cnt--) {x += 4; if (x >= imagex) { x = 0; y += 4; } }
  1925.     break;
  1926.       case 0x20: /* Repeat Last Block */
  1927.       case 0x30:
  1928.     { xaLONG tx,ty;
  1929.       if (hicode == 0x30) {cnt = 1 + *dptr++; len--;}
  1930.       else cnt = 1 + (code & 0x0f);
  1931.       if (x==0) {ty = y-4; tx = imagex-4;} else {ty=y; tx = x-4;}
  1932.  
  1933.       while(cnt--)
  1934.       { 
  1935.         if ( (x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  1936.         { xaUBYTE *i_ptr = (xaUBYTE *)(image + y * imagex + x);
  1937.           xaUBYTE *o_ptr = (xaUBYTE *)(image + ty * imagex + tx);
  1938.           QT_SMC_O2I(i_ptr,o_ptr,row_inc);
  1939.         } else if (x11_bytes_pixel==2)
  1940.         { xaUSHORT *i_ptr = (xaUSHORT *)(image + 2*(y * imagex + x) );
  1941.           xaUSHORT *o_ptr = (xaUSHORT *)(image + 2*(ty * imagex + tx) );
  1942.           QT_SMC_O2I(i_ptr,o_ptr,row_inc);
  1943.         } else /* if (x11_bytes_pixel==4) */
  1944.         { xaULONG *i_ptr = (xaULONG *)(image + 4*(y * imagex + x) );
  1945.           xaULONG *o_ptr = (xaULONG *)(image + 4*(ty * imagex + tx) );
  1946.           QT_SMC_O2I(i_ptr,o_ptr,row_inc);
  1947.         }
  1948.         x += 4; if (x >= imagex) { x = 0; y += 4; }
  1949.       }
  1950.     }
  1951.     break;
  1952.       case 0x40: /* */
  1953.       case 0x50:
  1954.     { xaULONG cnt,cnt1;
  1955.       xaULONG m_cnt,m_cnt1;
  1956.       xaLONG m_tx,m_ty;
  1957.           xaLONG tx,ty;
  1958.       if (hicode == 0x50) 
  1959.       {  
  1960.          m_cnt1 = 1 + *dptr++; len--; 
  1961.          m_cnt = 2;
  1962.       }
  1963.           else 
  1964.       {
  1965.         m_cnt1 = (1 + (code & 0x0f));
  1966.         m_cnt = 2;
  1967.       }
  1968.           m_tx = x-(xaLONG)(4 * m_cnt); m_ty = y; 
  1969.       if (m_tx < 0) {m_tx += imagex; m_ty -= 4;}
  1970.       cnt1 = m_cnt1;
  1971.       while(cnt1--)
  1972.       {
  1973.         cnt = m_cnt; tx = m_tx; ty = m_ty;
  1974.         while(cnt--)
  1975.         { 
  1976.           if ( (x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  1977.           { xaUBYTE *i_ptr = (xaUBYTE *)(image + y * imagex + x);
  1978.         xaUBYTE *o_ptr = (xaUBYTE *)(image + ty * imagex + tx);
  1979.         QT_SMC_O2I(i_ptr,o_ptr,row_inc);
  1980.           } else if (x11_bytes_pixel==2)
  1981.           { xaUSHORT *i_ptr = (xaUSHORT *)(image + 2*(y * imagex + x));
  1982.         xaUSHORT *o_ptr = (xaUSHORT *)(image + 2*(ty * imagex + tx));
  1983.         QT_SMC_O2I(i_ptr,o_ptr,row_inc);
  1984.           } else 
  1985.           { xaULONG *i_ptr = (xaULONG *)(image + 4*(y * imagex + x));
  1986.         xaULONG *o_ptr = (xaULONG *)(image + 4*(ty * imagex + tx));
  1987.         QT_SMC_O2I(i_ptr,o_ptr,row_inc);
  1988.           }
  1989.           x += 4; if (x >= imagex) { x = 0; y += 4; }
  1990.           tx += 4; if (tx >= imagex) { tx = 0; ty += 4; }
  1991.         } /* end of cnt */
  1992.       } /* end of cnt1 */
  1993.     }
  1994.     break;
  1995.  
  1996.       case 0x60: /* Repeat Data */
  1997.       case 0x70:
  1998.     { xaULONG ct,cnt;
  1999.       if (hicode == 0x70) {cnt = 1 + *dptr++; len--;}
  2000.       else cnt = 1 + (code & 0x0f);
  2001.       ct = (map_flag)?(map[*dptr++]):(xaULONG)(*dptr++); len--;
  2002.       while(cnt--)
  2003.       {
  2004.         if ( (x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  2005.         { xaUBYTE *i_ptr = (xaUBYTE *)(image + y * imagex + x);
  2006.           xaUBYTE d = (xaUBYTE)(ct);
  2007.           QT_SMC_C1(i_ptr,d,row_inc);
  2008.         } else if (x11_bytes_pixel==2)
  2009.         { xaUSHORT *i_ptr = (xaUSHORT *)(image + 2*(y * imagex + x));
  2010.           xaUSHORT d = (xaUBYTE)(ct);
  2011.           QT_SMC_C1(i_ptr,d,row_inc);
  2012.         } else
  2013.         { xaULONG *i_ptr = (xaULONG *)(image + 4*(y * imagex + x));
  2014.           QT_SMC_C1(i_ptr,ct,row_inc);
  2015.         }
  2016.         x += 4; if (x >= imagex) { x = 0; y += 4; }
  2017.       }
  2018.     }
  2019.     break;
  2020.  
  2021.       case 0x80: /* 2 colors plus 16 mbits per */
  2022.       case 0x90:
  2023.         { xaULONG cnt = 1 + (code & 0x0f);
  2024.       if (hicode == 0x80)
  2025.       {
  2026.             c = (xaULONG *)&smc_8[ (smc_8cnt * 2) ];  len -= 2;
  2027.         smc_8cnt++; if (smc_8cnt >= SMC_MAX_CNT) smc_8cnt -= SMC_MAX_CNT;
  2028.         for(i=0;i<2;i++) {c[i]=(map_flag)?map[*dptr++]:(xaULONG)(*dptr++);}
  2029.       }
  2030.           else { c = (xaULONG *)&smc_8[ ((xaULONG)(*dptr++) << 1) ]; len--; }
  2031.       while(cnt--)
  2032.       { xaULONG msk1,msk0;
  2033.         msk0 = *dptr++; msk1 = *dptr++;  len-= 2;
  2034.         if ( (x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  2035.         { xaUBYTE *i_ptr = (xaUBYTE *)(image + y * imagex + x);
  2036.           xaUBYTE c0=(xaUBYTE)c[0];    xaUBYTE c1=(xaUBYTE)c[1];
  2037.           QT_SMC_C2(i_ptr,c0,c1,msk0,row_inc); i_ptr += row_inc;
  2038.           QT_SMC_C2(i_ptr,c0,c1,msk1,row_inc);
  2039.         } else if (x11_bytes_pixel==2)
  2040.         { xaUSHORT *i_ptr = (xaUSHORT *)(image + 2*(y * imagex + x));
  2041.           xaUSHORT c0=(xaUSHORT)c[0];    xaUSHORT c1=(xaUSHORT)c[1];
  2042.           QT_SMC_C2(i_ptr,c0,c1,msk0,row_inc); i_ptr += row_inc;
  2043.           QT_SMC_C2(i_ptr,c0,c1,msk1,row_inc);
  2044.         } else
  2045.         { xaULONG *i_ptr = (xaULONG *)(image + 4*(y * imagex + x));
  2046.           xaULONG c0=(xaULONG)c[0];    xaULONG c1=(xaULONG)c[1];
  2047.           QT_SMC_C2(i_ptr,c0,c1,msk0,row_inc); i_ptr += row_inc;
  2048.           QT_SMC_C2(i_ptr,c0,c1,msk1,row_inc);
  2049.         }
  2050.         x += 4; if (x >= imagex) { x = 0; y += 4; }
  2051.           } 
  2052.         } 
  2053.     break;
  2054.  
  2055.       case 0xA0: /* 4 color + 32 mbits */
  2056.       case 0xB0:
  2057.         { xaULONG cnt = 1 + (code & 0xf);
  2058.           if (hicode == 0xA0)
  2059.           {
  2060.             c = (xaULONG *)&smc_A[ (smc_Acnt << 2) ]; len -= 4;
  2061.             smc_Acnt++; if (smc_Acnt >= SMC_MAX_CNT) smc_Acnt -= SMC_MAX_CNT;
  2062.             for(i=0;i<4;i++) {c[i]=(map_flag)?map[*dptr++]:(xaULONG)(*dptr++);}
  2063.           }
  2064.           else { c = (xaULONG *)&smc_A[ ((xaULONG)(*dptr++) << 2) ]; len--; }
  2065.       while(cnt--)
  2066.       { xaUBYTE msk0,msk1,msk2,msk3; 
  2067.         msk0 = *dptr++;    msk1 = *dptr++; 
  2068.         msk2 = *dptr++;    msk3 = *dptr++;        len -= 4;
  2069.         if ( (x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  2070.         { xaUBYTE *i_ptr = (xaUBYTE *)(image + y * imagex + x);
  2071.           QT_SMC_C4(i_ptr,xaUBYTE,c,msk0,msk1,row_inc); i_ptr += row_inc;
  2072.           QT_SMC_C4(i_ptr,xaUBYTE,c,msk2,msk3,row_inc);
  2073.         } else if (x11_bytes_pixel==2)
  2074.         { xaUSHORT *i_ptr = (xaUSHORT *)(image + 2*(y * imagex + x));
  2075.           QT_SMC_C4(i_ptr,xaUSHORT,c,msk0,msk1,row_inc); i_ptr += row_inc;
  2076.           QT_SMC_C4(i_ptr,xaUSHORT,c,msk2,msk3,row_inc);
  2077.         } else
  2078.         { xaULONG *i_ptr = (xaULONG *)(image + 4*(y * imagex + x));
  2079.           QT_SMC_C4(i_ptr,xaULONG,c,msk0,msk1,row_inc); i_ptr += row_inc;
  2080.           QT_SMC_C4(i_ptr,xaULONG,c,msk2,msk3,row_inc);
  2081.         }
  2082.         x += 4; if (x >= imagex) { x = 0; y += 4; }
  2083.           } 
  2084.         } 
  2085.     break;
  2086.  
  2087.       case 0xC0: /* 8 colors + 48 mbits */
  2088.       case 0xD0:
  2089.         { xaULONG cnt = 1 + (code & 0xf);
  2090.           if (hicode == 0xC0)
  2091.           {
  2092.             c = (xaULONG *)&smc_C[ (smc_Ccnt << 3) ];   len -= 8;
  2093.             smc_Ccnt++; if (smc_Ccnt >= SMC_MAX_CNT) smc_Ccnt -= SMC_MAX_CNT;
  2094.             for(i=0;i<8;i++) {c[i]=(map_flag)?map[*dptr++]:(xaULONG)(*dptr++);}
  2095.           }
  2096.           else { c = (xaULONG *)&smc_C[ ((xaULONG)(*dptr++) << 3) ]; len--; }
  2097.  
  2098.       while(cnt--)
  2099.       { xaULONG t,mbits0,mbits1;
  2100.         t = (*dptr++) << 8; t |= *dptr++;
  2101.         mbits0  = (t & 0xfff0) << 8;  mbits1  = (t & 0x000f) << 8;
  2102.         t = (*dptr++) << 8; t |= *dptr++;
  2103.         mbits0 |= (t & 0xfff0) >> 4;  mbits1 |= (t & 0x000f) << 4;
  2104.         t = (*dptr++) << 8; t |= *dptr++;
  2105.         mbits1 |= (t & 0xfff0) << 8;  mbits1 |= (t & 0x000f);
  2106.         len -= 6;
  2107.         if ( (x11_bytes_pixel==1) || (map_flag==xaFALSE) )
  2108.         { xaUBYTE *i_ptr = (xaUBYTE *)(image + y * imagex + x);
  2109.           QT_SMC_C8(i_ptr,xaUBYTE,c,mbits0,row_inc); i_ptr += row_inc;
  2110.           QT_SMC_C8(i_ptr,xaUBYTE,c,mbits1,row_inc);
  2111.         } else if (x11_bytes_pixel==2)
  2112.         { xaUSHORT *i_ptr = (xaUSHORT *)(image + 2*(y * imagex + x));
  2113.           QT_SMC_C8(i_ptr,xaUSHORT,c,mbits0,row_inc); i_ptr += row_inc;
  2114.           QT_SMC_C8(i_ptr,xaUSHORT,c,mbits1,row_inc);
  2115.         } else
  2116.         { xaULONG *i_ptr = (xaULONG *)(image + 4*(y * imagex + x));
  2117.           QT_SMC_C8(i_ptr,xaULONG,c,mbits0,row_inc); i_ptr += row_inc;
  2118.           QT_SMC_C8(i_ptr,xaULONG,c,mbits1,row_inc);
  2119.         }
  2120.         x += 4; if (x >= imagex) { x = 0; y += 4; }
  2121.           } 
  2122.         } 
  2123.     break;
  2124.  
  2125.       case 0xE0: /* 16 colors */
  2126.         { xaULONG cnt = 1 + (code & 0x0f);
  2127.       while(cnt--)
  2128.       { 
  2129.         if (map_flag==xaFALSE)
  2130.         { xaUBYTE *i_ptr = (xaUBYTE *)(image + y * imagex + x);
  2131.           QT_SMC_C16(i_ptr,dptr,xaUBYTE); i_ptr += row_inc;
  2132.           QT_SMC_C16(i_ptr,dptr,xaUBYTE); i_ptr += row_inc;
  2133.           QT_SMC_C16(i_ptr,dptr,xaUBYTE); i_ptr += row_inc;
  2134.           QT_SMC_C16(i_ptr,dptr,xaUBYTE);
  2135.         } else if (x11_bytes_pixel==1)
  2136.         { xaUBYTE *i_ptr = (xaUBYTE *)(image + y * imagex + x);
  2137.           QT_SMC_C16m(i_ptr,dptr,xaUBYTE,map,row_inc); i_ptr += row_inc;
  2138.           QT_SMC_C16m(i_ptr,dptr,xaUBYTE,map,row_inc);
  2139.         } else if (x11_bytes_pixel==2)
  2140.         { xaUSHORT *i_ptr = (xaUSHORT *)(image + 2*(y * imagex + x));
  2141.           QT_SMC_C16m(i_ptr,dptr,xaUSHORT,map,row_inc); i_ptr += row_inc;
  2142.           QT_SMC_C16m(i_ptr,dptr,xaUSHORT,map,row_inc);
  2143.         } else
  2144.         { xaULONG *i_ptr = (xaULONG *)(image + 4*(y * imagex + x));
  2145.           QT_SMC_C16m(i_ptr,dptr,xaULONG,map,row_inc); i_ptr += row_inc;
  2146.           QT_SMC_C16m(i_ptr,dptr,xaULONG,map,row_inc);
  2147.         }
  2148.         len -= 16; x += 4; if (x >= imagex) { x = 0; y += 4; }
  2149.       }
  2150.     }
  2151.     break;
  2152.  
  2153.       default:   /* 0xF0 */
  2154.     fprintf(stderr,"SMC opcode %x is unknown\n",code);
  2155.     break;
  2156.     }
  2157.   }
  2158.   if (map_flag) return(ACT_DLTA_MAPD);
  2159.   else return(ACT_DLTA_NORM);
  2160. }
  2161.  
  2162. xaULONG QT_Decode_YUV2(image,delta,dsize,dec_info)
  2163. xaUBYTE *image;         /* Image Buffer. */
  2164. xaUBYTE *delta;         /* delta data. */
  2165. xaULONG dsize;          /* delta size */
  2166. XA_DEC2_INFO *dec_info;  /* Decoder Info Header */
  2167. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  2168.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  2169.   XA_CHDR *chdr = dec_info->chdr;
  2170.   xaUBYTE *dptr = delta;
  2171.   xaULONG ycnt, row_inc = imagex << 1;
  2172.   xaULONG mx = imagex >> 1;
  2173.   void (*color_func)() = (void (*)())XA_YUV211111_Func(dec_info->image_type);
  2174.  
  2175.  
  2176.   dec_info->xs = dec_info->ys = 0;
  2177.   dec_info->xe = imagex; dec_info->ye = imagey;
  2178.   if (dec_info->skip_flag > 0) return(ACT_DLTA_DROP);
  2179.   if (chdr) { if (chdr->new_chdr) chdr = chdr->new_chdr; }
  2180.  
  2181.   row_inc *= dec_info->bytes_pixel;
  2182.  
  2183.   ycnt = 0;
  2184.   while( (imagey > 0) && (dsize > 0) )
  2185.   { xaUBYTE *yp,*up,*vp;
  2186.     xaULONG x = mx;
  2187.     if (ycnt == 0)
  2188.       { yp = jpg_YUVBufs.Ybuf; up = jpg_YUVBufs.Ubuf; vp = jpg_YUVBufs.Vbuf; }
  2189.     while(x--)
  2190.     { *yp++ = *dptr++; *up++ = (*dptr++) ^ 0x80;
  2191.       *yp++ = *dptr++; *vp++ = (*dptr++) ^ 0x80;  dsize -= 4;
  2192.     }
  2193.     ycnt++;
  2194.     imagey--;
  2195.     if ((ycnt >= 2) || (imagey == 0))
  2196.     { color_func(image,imagex,ycnt,imagex,ycnt,
  2197.                 &jpg_YUVBufs, &def_yuv_tabs, map_flag, map, chdr);
  2198.       ycnt = 0;
  2199.       image += row_inc;
  2200.     }
  2201.   } /*end of y */
  2202.  
  2203.   if (map_flag) return(ACT_DLTA_MAPD);
  2204.   else return(ACT_DLTA_NORM);
  2205. }
  2206.  
  2207. /*********
  2208.  *
  2209.  *******/
  2210.  
  2211. xaULONG QT_RPZA_Dither(image,delta,len,dec_info)
  2212. xaUBYTE *image;        /* Image Buffer. */
  2213. xaUBYTE *delta;        /* delta data. */
  2214. xaULONG len;        /* delta size */
  2215. XA_DEC_INFO *dec_info;    /* Decoder Info Header */
  2216.   xaULONG imagex = dec_info->imagex;
  2217.   xaULONG imagey = dec_info->imagey;
  2218.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  2219.   XA_CHDR *chdr = dec_info->chdr;
  2220.   xaLONG x,y,row_inc,blk_inc; 
  2221.   xaLONG min_x,max_x,min_y,max_y;
  2222.   xaUBYTE *dptr;
  2223.   xaULONG code,changed;
  2224.   xaUBYTE *im0,*im1,*im2,*im3;
  2225.   xaUBYTE *rnglimit = xa_byte_limit;
  2226.   ColorReg *cmap;
  2227.  
  2228.   if (chdr) { if (chdr->new_chdr) chdr = chdr->new_chdr; }
  2229.   cmap = chdr->cmap;
  2230.   dec_info->xs = dec_info->ys = 0; dec_info->xe = imagex; dec_info->ye = imagey;
  2231.   max_x = max_y = 0; min_x = imagex; min_y = imagey; changed = 0;
  2232.   dptr = delta;
  2233.   x = y = 0;
  2234.  
  2235.   blk_inc = 1; /* possible optimization */
  2236.   row_inc = blk_inc * imagex;
  2237.   blk_inc *= 4;
  2238.   im1 = im0 = image;    im1 += row_inc;
  2239.   im2 = im1;            im2 += row_inc;
  2240.   im3 = im2;            im3 += row_inc;
  2241.   row_inc *= 3; /* skip 3 rows at a time */
  2242.  
  2243.   while(len > 0) 
  2244.   { code = *dptr++; len--; 
  2245.     if ( (code >= 0xa0) && (code <= 0xbf) )        /* SINGLE */
  2246.     { xaULONG color,skip;
  2247.       xaLONG re,ge,be,r,g,b,col;    
  2248.  
  2249.       changed = 1;
  2250.       color = (*dptr++) << 8; color |= *dptr++; len -= 2;
  2251.       skip = (code - 0x9f);
  2252.  
  2253.       while(skip--)
  2254.       { xaUBYTE *ip0=im0; xaUBYTE *ip1=im1;
  2255.     xaUBYTE *ip2=im2; xaUBYTE *ip3=im3;
  2256.       /* get original r,g,b  and scale to 8 bits */
  2257.     RPZA_DITH_COL2RGB(r,g,b,color);
  2258.  
  2259.       /**---0 0*/
  2260.       RPZA_DITH_GET_RGB(r,g,b,0,0,0,col);
  2261.       if (map_flag) col = map[col];            ip0[0] = (xaUBYTE)col;
  2262.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2263.       /*----0 1*/
  2264.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2265.       if (map_flag) col = map[col];            ip0[1] = (xaUBYTE)col;
  2266.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2267.       /*----1 1*/
  2268.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2269.       if (map_flag) col = map[col];            ip1[1] = (xaUBYTE)col;
  2270.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2271.       /*----1 0*/
  2272.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2273.       if (map_flag) col = map[col];            ip1[0] = (xaUBYTE)col;
  2274.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2275.       /**---2 0*/
  2276.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2277.       if (map_flag) col = map[col];            ip2[0] = (xaUBYTE)col;
  2278.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2279.       /*----3 0*/
  2280.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2281.       if (map_flag) col = map[col];            ip3[0] = (xaUBYTE)col;
  2282.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2283.       /*----3 1*/
  2284.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2285.       if (map_flag) col = map[col];            ip3[1] = (xaUBYTE)col;
  2286.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2287.       /*----2 1*/
  2288.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2289.       if (map_flag) col = map[col];            ip2[1] = (xaUBYTE)col;
  2290.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2291.       /**---2 2*/
  2292.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2293.       if (map_flag) col = map[col];            ip2[2] = (xaUBYTE)col;
  2294.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2295.       /*----3 2*/
  2296.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2297.       if (map_flag) col = map[col];            ip3[2] = (xaUBYTE)col;
  2298.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2299.       /*----3 3*/
  2300.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2301.       if (map_flag) col = map[col];            ip3[3] = (xaUBYTE)col;
  2302.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2303.       /*----2 3*/
  2304.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2305.       if (map_flag) col = map[col];            ip2[3] = (xaUBYTE)col;
  2306.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2307.       /**---1 3*/
  2308.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2309.       if (map_flag) col = map[col];            ip1[3] = (xaUBYTE)col;
  2310.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2311.       /*----1 2*/
  2312.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2313.       if (map_flag) col = map[col];            ip1[2] = (xaUBYTE)col;
  2314.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2315.       /*----0 2*/
  2316.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2317.       if (map_flag) col = map[col];            ip0[2] = (xaUBYTE)col;
  2318.       RPZA_DITH_GET_ERR(r,g,b,re,ge,be,col,cmap);
  2319.       /*----0 3*/
  2320.       RPZA_DITH_GET_RGB(r,g,b,re,ge,be,col);
  2321.       if (map_flag) col = map[col];            ip0[3] = (xaUBYTE)col;
  2322.       
  2323.       QT_MIN_MAX_CHECK(x,y,min_x,min_y,max_x,max_y);
  2324.       QT_RPZA_BLOCK_INC(x,y,imagex,im0,im1,im2,im3,blk_inc,row_inc);
  2325.         } /* end while */
  2326.     }
  2327.     else if ( (code >= 0x80) && (code <= 0x9f) )        /* SKIP */
  2328.     { xaULONG skip = (code - 0x7f);
  2329.       while(skip--) 
  2330.         QT_RPZA_BLOCK_INC(x,y,imagex,im0,im1,im2,im3,blk_inc,row_inc);
  2331.     }
  2332.  
  2333.                  /* FOUR/SIXTEEN */ 
  2334.     else if ( (code < 0x80) || ((code >= 0xc0) && (code <= 0xdf)) )
  2335.     { xaULONG cA,cB;
  2336.       changed = 1;
  2337.       /* Get 1st two colors */
  2338.       if (code >= 0xc0) { cA = (*dptr++) << 8; cA |= *dptr++; len -= 2; }
  2339.       else {cA = (code << 8) | *dptr++; len -= 1;}
  2340.       cB = (*dptr++) << 8; cB |= *dptr++; len -= 2;
  2341.  
  2342.       /****** SIXTEEN COLOR *******/
  2343.       if ( (code < 0x80) && ((cB & 0x8000)==0) ) /* 16 color */
  2344.       { xaUBYTE *cptr = dptr;
  2345.         xaUBYTE *ip0=im0; xaUBYTE *ip1=im1;
  2346.     xaUBYTE *ip2=im2; xaUBYTE *ip3=im3;
  2347.         xaLONG re,ge,be,ra,ga,ba,col;    
  2348.     dptr += 28; len -= 28;  /* skip over colors */
  2349.  
  2350.     /**---0 0*/
  2351.      RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2352.      RPZA_DITH_GET_RGB(ra,ga,ba,0,0,0,col);
  2353.      if (map_flag) col = map[col];        ip0[0] = (xaUBYTE)col;
  2354.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2355.     /*----0 1*/
  2356.      RPZA_DITH_COL2RGB(ra,ga,ba,cB);
  2357.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2358.      if (map_flag) col = map[col];        ip0[1] = (xaUBYTE)col;
  2359.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2360.     /*----1 1*/
  2361.      cA = (cptr[ 6]) << 8; cA |= cptr[ 7]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2362.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2363.      if (map_flag) col = map[col];        ip1[1] = (xaUBYTE)col;
  2364.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2365.     /*----1 0*/
  2366.      cA = (cptr[ 4]) << 8; cA |= cptr[ 5]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2367.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2368.      if (map_flag) col = map[col];        ip1[0] = (xaUBYTE)col;
  2369.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2370.     /**---2 0*/
  2371.      cA = (cptr[12]) << 8; cA |= cptr[13]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2372.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2373.      if (map_flag) col = map[col];        ip2[0] = (xaUBYTE)col;
  2374.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2375.     /*----3 0*/
  2376.      cA = (cptr[20]) << 8; cA |= cptr[21]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2377.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2378.      if (map_flag) col = map[col];        ip3[0] = (xaUBYTE)col;
  2379.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2380.     /*----3 1*/
  2381.      cA = (cptr[22]) << 8; cA |= cptr[23]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2382.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2383.      if (map_flag) col = map[col];        ip3[1] = (xaUBYTE)col;
  2384.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2385.     /*----2 1*/
  2386.      cA = (cptr[14]) << 8; cA |= cptr[15]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2387.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2388.      if (map_flag) col = map[col];        ip2[1] = (xaUBYTE)col;
  2389.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2390.     /**---2 2*/
  2391.      cA = (cptr[16]) << 8; cA |= cptr[17]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2392.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2393.      if (map_flag) col = map[col];        ip2[2] = (xaUBYTE)col;
  2394.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2395.     /*----3 2*/
  2396.      cA = (cptr[24]) << 8; cA |= cptr[25]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2397.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2398.      if (map_flag) col = map[col];        ip3[2] = (xaUBYTE)col;
  2399.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2400.     /*----3 3*/
  2401.      cA = (cptr[26]) << 8; cA |= cptr[27]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2402.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2403.      if (map_flag) col = map[col];        ip3[3] = (xaUBYTE)col;
  2404.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2405.     /*----2 3*/
  2406.      cA = (cptr[18]) << 8; cA |= cptr[19]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2407.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2408.      if (map_flag) col = map[col];        ip2[3] = (xaUBYTE)col;
  2409.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2410.     /**---1 3*/
  2411.      cA = (cptr[10]) << 8; cA |= cptr[11]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2412.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2413.      if (map_flag) col = map[col];        ip1[3] = (xaUBYTE)col;
  2414.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2415.     /*----1 2*/
  2416.      cA = (cptr[ 8]) << 8; cA |= cptr[ 9]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2417.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2418.      if (map_flag) col = map[col];        ip1[2] = (xaUBYTE)col;
  2419.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2420.     /*----0 2*/
  2421.      cA = (cptr[ 0]) << 8; cA |= cptr[ 1]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2422.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2423.      if (map_flag) col = map[col];        ip0[2] = (xaUBYTE)col;
  2424.      RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2425.     /*----0 3*/
  2426.      cA = (cptr[ 2]) << 8; cA |= cptr[ 3]; RPZA_DITH_COL2RGB(ra,ga,ba,cA);
  2427.      RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2428.      if (map_flag) col = map[col];        ip0[3] = (xaUBYTE)col;
  2429.  
  2430.     QT_MIN_MAX_CHECK(x,y,min_x,min_y,max_x,max_y);
  2431.     QT_RPZA_BLOCK_INC(x,y,imagex,im0,im1,im2,im3,blk_inc,row_inc);
  2432.       } /*** END of SIXTEEN COLOR */
  2433.       else                    /****** FOUR COLOR *******/
  2434.       { xaULONG m_cnt,msk0,msk1,msk2,msk3;
  2435.     xaLONG r[4],g[4],b[4];
  2436.  
  2437.         if (code < 0x80) m_cnt = 1; 
  2438.     else m_cnt = code - 0xbf; 
  2439.  
  2440.     { xaULONG rA,gA,bA, rB,gB,bB;
  2441.       RPZA_DITH_COL2RGB(rA,gA,bA,cA);  r[3] = rA; g[3] = gA; b[3] = bA;
  2442.       RPZA_DITH_COL2RGB(rB,gB,bB,cB);  r[0] = rB; g[0] = gB; b[0] = bB;
  2443.           r[2] = (21*rA + 11*rB) >> 5;       r[1] = (11*rA + 21*rB) >> 5; 
  2444.       g[2] = (21*gA + 11*gB) >> 5;       g[1] = (11*gA + 21*gB) >> 5;
  2445.       b[2] = (21*bA + 11*bB) >> 5;       b[1] = (11*bA + 21*bB) >> 5;
  2446.     }
  2447.  
  2448.  
  2449.         while(m_cnt--)
  2450.         { msk0 = *dptr++; msk1 = *dptr++;
  2451.       msk2 = *dptr++; msk3 = *dptr++; len -= 4;
  2452.  
  2453.           { xaUBYTE *ip0=im0; xaUBYTE *ip1=im1;
  2454.         xaUBYTE *ip2=im2; xaUBYTE *ip3=im3;
  2455.             xaLONG idx,re,ge,be,ra,ga,ba,col;    
  2456.       /**---0 0*/
  2457.         idx = (msk0>>6)&0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2458.         RPZA_DITH_GET_RGB(ra,ga,ba,0,0,0,col);
  2459.         if (map_flag) col = map[col];        ip0[0] = (xaUBYTE)col;
  2460.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2461.       /*----0 1*/
  2462.         idx = (msk0>>4)&0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2463.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2464.         if (map_flag) col = map[col];        ip0[1] = (xaUBYTE)col;
  2465.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2466.       /*----1 1*/
  2467.         idx = (msk1>>4)&0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2468.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2469.         if (map_flag) col = map[col];        ip1[1] = (xaUBYTE)col;
  2470.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2471.       /*----1 0*/
  2472.         idx = (msk1>>6)&0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2473.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2474.         if (map_flag) col = map[col];        ip1[0] = (xaUBYTE)col;
  2475.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2476.       /**---2 0*/
  2477.         idx = (msk2>>6)&0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2478.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2479.         if (map_flag) col = map[col];        ip2[0] = (xaUBYTE)col;
  2480.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2481.       /*----3 0*/
  2482.         idx = (msk3>>6)&0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2483.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2484.         if (map_flag) col = map[col];        ip3[0] = (xaUBYTE)col;
  2485.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2486.       /*----3 1*/
  2487.         idx = (msk3>>4)&0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2488.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2489.         if (map_flag) col = map[col];        ip3[1] = (xaUBYTE)col;
  2490.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2491.       /*----2 1*/
  2492.         idx = (msk2>>4)&0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2493.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2494.         if (map_flag) col = map[col];        ip2[1] = (xaUBYTE)col;
  2495.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2496.       /**---2 2*/
  2497.         idx = (msk2>>2)&0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2498.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2499.         if (map_flag) col = map[col];        ip2[2] = (xaUBYTE)col;
  2500.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2501.       /*----3 2*/
  2502.         idx = (msk3>>2)&0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2503.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2504.         if (map_flag) col = map[col];        ip3[2] = (xaUBYTE)col;
  2505.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2506.       /*----3 3*/
  2507.         idx = msk3 & 0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2508.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2509.         if (map_flag) col = map[col];        ip3[3] = (xaUBYTE)col;
  2510.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2511.       /*----2 3*/
  2512.         idx = msk2 & 0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2513.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2514.         if (map_flag) col = map[col];        ip2[3] = (xaUBYTE)col;
  2515.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2516.       /**---1 3*/
  2517.         idx = msk1 & 0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2518.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2519.         if (map_flag) col = map[col];        ip1[3] = (xaUBYTE)col;
  2520.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2521.       /*----1 2*/
  2522.         idx = (msk1>>2)&0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2523.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2524.         if (map_flag) col = map[col];        ip1[2] = (xaUBYTE)col;
  2525.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2526.       /*----0 2*/
  2527.         idx = (msk0>>2)&0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2528.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2529.         if (map_flag) col = map[col];        ip0[2] = (xaUBYTE)col;
  2530.         RPZA_DITH_GET_ERR(ra,ga,ba,re,ge,be,col,cmap);
  2531.       /*----0 3*/
  2532.         idx = msk0 & 0x03; ra = r[idx]; ga = g[idx]; ba = b[idx];
  2533.         RPZA_DITH_GET_RGB(ra,ga,ba,re,ge,be,col);
  2534.         if (map_flag) col = map[col];        ip0[3] = (xaUBYTE)col;
  2535.       }
  2536.       QT_MIN_MAX_CHECK(x,y,min_x,min_y,max_x,max_y);
  2537.       QT_RPZA_BLOCK_INC(x,y,imagex,im0,im1,im2,im3,blk_inc,row_inc);
  2538.         }  
  2539.       } /*** END of FOUR COLOR *******/
  2540.     } /*** END of 4/16 COLOR BLOCKS ****/
  2541.     else /* UNKNOWN */
  2542.     {
  2543.       fprintf(stderr,"QT RPZA: Unknown %x\n",code);
  2544.       return(ACT_DLTA_NOP);
  2545.     }
  2546.   }
  2547.   if (xa_optimize_flag == xaTRUE)
  2548.   { if (changed) { dec_info->xs=min_x; dec_info->ys=min_y;
  2549.            dec_info->xe=max_x + 4; dec_info->ye=max_y + 4; }
  2550.     else  { dec_info->xs = dec_info->ys = dec_info->xe = dec_info->ye = 0;
  2551.         return(ACT_DLTA_NOP); }
  2552.   }
  2553.   else { dec_info->xs = dec_info->ys = 0; 
  2554.      dec_info->xe = imagex; dec_info->ye = imagey; }
  2555.   if (map_flag) return(ACT_DLTA_MAPD);
  2556.   else return(ACT_DLTA_NORM);
  2557. }
  2558.  
  2559.  
  2560.  
  2561.