home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / pmvnc100.zip / rect8.c < prev    next >
C/C++ Source or Header  |  1999-08-02  |  30KB  |  885 lines

  1. /*
  2.  * rect8.c - PM VNC Viewer, Pixel Handling for bgr233 8bit static color
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. #define INCL_PM
  9. #include <os2.h>
  10.  
  11. #include "pmvncdef.h"
  12.  
  13. /*
  14.  * rbuff is used to parse CoRRE, it requires buffer of
  15.  * 255 * 255 * 32 bits (nearly 64KB * 4).
  16.  */
  17.  
  18. #define RBUFSIZ     (1024 * 256)
  19.  
  20. static  PUCHAR  rbuff = NULL ;          /* as recv buffer   */
  21.  
  22. /*
  23.  * buffer for bitmap scan conversion
  24.  */
  25.  
  26. #define MAXSCAN     (4096 * 8)
  27.  
  28. static  PUCHAR  ibuff = NULL ;          /* as scan buffer   */
  29.  
  30. /*
  31.  * minimum I/O unit min(MAXSCAN, RBUFSIZ)
  32.  */
  33.  
  34. #define MINBUF  MAXSCAN
  35.  
  36. /*
  37.  * Remote Frame Buffer
  38.  */
  39.  
  40. static  int     cxBitmap = 0 ;
  41. static  int     cyBitmap = 0 ;
  42.  
  43. static  HDC     hdcBitmap = NULLHANDLE ;
  44. static  HPS     hpsBitmap = NULLHANDLE ;
  45. static  HBITMAP hbmBitmap = NULLHANDLE ;
  46.  
  47. static  PBITMAPINFO2    pbmiBitmap = NULL ;
  48.  
  49. /*
  50.  * ColorMap for BGR233
  51.  */
  52.  
  53. static  PULONG  bgrMap ;
  54.  
  55. /*
  56.  * rectDone - finialize rectangle operation
  57.  */
  58.  
  59. static  void    rectDone(void)
  60. {
  61.     if (hbmBitmap != NULLHANDLE) {
  62.         GpiDeleteBitmap(hbmBitmap) ;
  63.     hbmBitmap = NULLHANDLE ;
  64.     }
  65.     if (hpsBitmap != NULLHANDLE) {
  66.         GpiDestroyPS(hpsBitmap) ;
  67.     hpsBitmap = NULLHANDLE ;
  68.     }
  69.     if (hdcBitmap != NULLHANDLE) {
  70.         DevCloseDC(hdcBitmap) ;
  71.     hdcBitmap = NULLHANDLE ;
  72.     }
  73.     if (rbuff != NULL) {
  74.         free(rbuff) ;
  75.     rbuff = NULL ;
  76.     }
  77.     if (ibuff != NULL) {
  78.         free(ibuff) ;
  79.     ibuff = NULL ;
  80.     }
  81.     if (pbmiBitmap != NULL) {
  82.         free(pbmiBitmap) ;
  83.     pbmiBitmap = NULL ;
  84.     }
  85. }
  86.  
  87. /*
  88.  * rectInit - create bitmap for Remote Frame Buffer
  89.  */
  90.  
  91. static  BOOL    rectInit(int cx, int cy)
  92. {
  93.     SIZEL   siz ;
  94.     POINTL  pt  ;
  95.     BITMAPINFOHEADER2   bmi ;
  96.     int     i   ;
  97.     PUCHAR  pc  ;
  98.     PULONG  pl  ;
  99.     
  100.     /*
  101.      * prepare buffer for drawing
  102.      */
  103.      
  104.     rbuff = malloc(RBUFSIZ) ;
  105.     ibuff = malloc(MAXSCAN) ;
  106.     pbmiBitmap = malloc(16 + sizeof(RGB2) * 256) ;
  107.     
  108.     if (rbuff == NULL || ibuff == NULL || pbmiBitmap == NULL) {
  109.         rectDone() ;
  110.     return FALSE ;
  111.     }
  112.     
  113.     /*
  114.      * create bitmap for Remote Frame Buffer
  115.      */
  116.      
  117.     siz.cx = siz.cy = 0 ;
  118.     hdcBitmap = DevOpenDC(habNetwork, OD_MEMORY, "*", 0, NULL, NULLHANDLE) ;
  119.     hpsBitmap = GpiCreatePS(habNetwork, hdcBitmap, &siz,
  120.                     PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC) ;
  121.  
  122.     if (hdcBitmap == NULLHANDLE || hpsBitmap == NULLHANDLE) {
  123.         TRACE("rectInit - failed to create HDC/HPS\n") ;
  124.         rectDone() ;
  125.     return FALSE ;
  126.     }
  127.  
  128.     memset(&bmi, 0, sizeof(bmi)) ;
  129.     bmi.cbFix = sizeof(bmi) ;
  130.     bmi.cx = cxBitmap = cx ;
  131.     bmi.cy = cyBitmap = cy ;
  132.     bmi.cPlanes       = 1  ;
  133.     bmi.cBitCount     = 8  ;
  134.     bmi.ulCompression = 0  ;
  135.     bmi.cclrUsed      = 0  ;
  136.     bmi.cclrImportant = 0  ;   
  137.  
  138.     hbmBitmap = GpiCreateBitmap(hpsBitmap, &bmi, 0, NULL, NULL) ;
  139.  
  140.     if (hbmBitmap == NULLHANDLE) {
  141.         TRACE("rectInit - failed to create bitmap\n") ;
  142.     rectDone() ;
  143.     return FALSE ;
  144.     }
  145.     
  146.     GpiSetBitmap(hpsBitmap, hbmBitmap) ;
  147.  
  148.     /*
  149.      * put initial message on it
  150.      */
  151.  
  152.     pt.x = 32 ;
  153.     pt.y = cyBitmap - 64 ;
  154.     GpiErase(hpsBitmap) ;
  155.     GpiCharStringAt(hpsBitmap, &pt, strlen(VncGreeting), VncGreeting) ;
  156.     
  157.     if (GpiCreateLogColorTable(hpsBitmap, 0, LCOLF_CONSECRGB, 0, 256, bgrMap) != TRUE) {
  158.         TRACE("rectInit - failed to set color mode INDEX\n") ;
  159.     rectDone() ;
  160.         return FALSE ;
  161.     }
  162.  
  163.     /*
  164.      * prepare bitmap info. header for later operation
  165.      */
  166.  
  167.     memset(pbmiBitmap, 0, (16 + sizeof(RGB2) * 256)) ;
  168.     pbmiBitmap->cbFix     = 16 ;
  169.     pbmiBitmap->cPlanes   =  1 ;
  170.     pbmiBitmap->cBitCount =  8 ;
  171.     pc = (PUCHAR) pbmiBitmap ;
  172.     pl = (PULONG) (pc + 16)  ;
  173.     
  174.     for (i = 0 ; i < 256 ; i++) {
  175.         *pl++ = bgrMap[i] ;
  176.     }
  177.  
  178.     return TRUE ;
  179. }
  180.  
  181. /*
  182.  * rectDraw - draw bitmap to targte PS
  183.  */
  184.  
  185. static  BOOL    rectDraw(HPS hps, PPOINTL apt)
  186. {
  187.     if (hpsBitmap == NULLHANDLE) {
  188.         return FALSE ;
  189.     }
  190.     GpiBitBlt(hps, hpsBitmap, 4, apt, ROP_SRCCOPY, BBO_IGNORE) ;
  191.     return TRUE ;
  192. }
  193.  
  194. /*
  195.  * rectRaw - raw rectangle encoding
  196.  *      read RawRect data from Server and convert to PM Bitmap
  197.  */
  198.  
  199. static  void    rawConv(rfbRectangle *r, int lines, PUCHAR buff)
  200. {
  201.     PUCHAR  sp, dp ;
  202.     int     i, j   ;
  203.     int     bytesPerLine ;
  204.     POINTL  apt[4] ;
  205.     
  206.     /*
  207.      * convert to PM bitmap, reverse vertical order and align to ULONG
  208.      */
  209.      
  210.     bytesPerLine = (r->w + 3) & ~0x03 ;
  211.     
  212.     for (i = 0, sp = buff ; i < lines ; i++) {
  213.     dp = &ibuff[bytesPerLine * (lines - i - 1)] ;
  214.     for (j = 0 ; j < r->w ; j++) {
  215.         *dp++ = *sp++ ;
  216.         }
  217.     }
  218.  
  219.     pbmiBitmap->cx = r->w  ;
  220.     pbmiBitmap->cy = lines ;
  221.     
  222.     apt[0].x = r->x ;
  223.     apt[0].y = (cyBitmap - r->y - lines) ;
  224.     apt[1].x = apt[0].x + r->w  - 1 ;
  225.     apt[1].y = apt[0].y + lines - 1 ;
  226.     apt[2].x = 0 ;
  227.     apt[2].y = 0 ;
  228.     apt[3].x = r->w  ;
  229.     apt[3].y = lines ;
  230.  
  231.     GpiDrawBits(hpsBitmap, ibuff, pbmiBitmap, 4, apt, ROP_SRCCOPY, 0) ;
  232. }
  233.  
  234. static  BOOL    rectRaw(rfbRectangle *r)
  235. {
  236.     int     bytesPerLine, linesToRead ;
  237.     
  238.     bytesPerLine  = r->w ;          /* for bgr233 specific  */
  239.     linesToRead   = MINBUF / ((r->w + 3) & ~0x03) ;
  240.     
  241.     if (linesToRead == 0) {
  242.         netFail("rectRaw - scanline too large, recompile!!") ;
  243.     return FALSE ;
  244.     }
  245.  
  246.     while (r->h > 0) {
  247.         if (linesToRead > r->h) {
  248.             linesToRead = r->h ;
  249.         }
  250.         if (netRecv(rbuff, bytesPerLine * linesToRead) != TRUE) {
  251.         netFail("failed to recv Raw Scanline") ;
  252.         return FALSE ;
  253.     }
  254.         rawConv(r, linesToRead, rbuff) ;
  255.     r->h -= linesToRead ;
  256.     r->y += linesToRead ;
  257.     }
  258.     return TRUE ;
  259. }
  260.  
  261. /*
  262.  * rectCopy - copy rect encoding
  263.  */
  264.  
  265. static  BOOL    rectCopy(rfbRectangle *r)
  266. {
  267.     rfbCopyRect cr  ;
  268.     POINTL  apt[3]  ;
  269.     
  270.     if (netRecv((PUCHAR) &cr, sz_rfbCopyRect) != TRUE) {
  271.         netFail("failed to recv CopyRect") ;
  272.     return FALSE ;
  273.     }
  274.  
  275.     cr.srcX = swap16(cr.srcX) ;
  276.     cr.srcY = swap16(cr.srcY) ;
  277.     
  278.     apt[0].x = r->x                      ;
  279.     apt[0].y = cyBitmap - r->y - r->h    ;
  280.     apt[1].x = r->x + r->w               ;
  281.     apt[1].y = cyBitmap - r->y           ;
  282.     apt[2].x = cr.srcX                   ;
  283.     apt[2].y = cyBitmap - cr.srcY - r->h ;
  284.     
  285.     GpiBitBlt(hpsBitmap, hpsBitmap, 3, apt, ROP_SRCCOPY, 0) ;
  286.  
  287.     return TRUE ;
  288. }
  289.  
  290. /*
  291.  * Fill Rectangle with Solid Color
  292.  */
  293.  
  294. #define     fillRect(mx, my, mw, mh, color)         \
  295. {                                                   \
  296.     POLYGON pg ;                                    \
  297.     POINTL  apt[8] ;                                \
  298.     int     n, i ;                                  \
  299.     GpiSetColor(hpsBitmap, (LONG) (color)) ;        \
  300.     if ((mw) == 1 && (mh) == 1) {                   \
  301.         apt[0].x = (mx)                   ;         \
  302.         apt[0].y = cyBitmap - (my) - (mh) ;         \
  303.         GpiSetPel(hpsBitmap, &apt[0])     ;         \
  304.     } else if ((mw) <  4) {                         \
  305.         for (i = 0, n = 0 ; i < (mw) ; i++) {       \
  306.         apt[n].x = (mx) + i               ;     \
  307.         apt[n].y = cyBitmap - (my) - (mh) ;     \
  308.         n += 1                            ;     \
  309.         apt[n].x = (mx) + i               ;     \
  310.         apt[n].y = cyBitmap - (my) - 1    ;     \
  311.             n += 1                            ;     \
  312.     }                                           \
  313.     GpiPolyLineDisjoint(hpsBitmap, n, apt) ;    \
  314.     } else {                                        \
  315.         pg.ulPoints = 4  ;                              \
  316.     pg.aPointl = apt ;                              \
  317.         apt[2].x = apt[3].x = (mx)                   ;  \
  318.     apt[0].x = apt[1].x = (mx) + (mw) - 1        ;  \
  319.     apt[0].y = apt[3].y = cyBitmap - (my) - (mh) ;  \
  320.     apt[1].y = apt[2].y = cyBitmap - (my) - 1    ;  \
  321.         GpiMove(hpsBitmap, &apt[3])          ;          \
  322.         GpiPolygons(hpsBitmap, 1, &pg, 0, 0) ;          \
  323.     }                                                   \
  324. }
  325.  
  326. /*
  327.  * rectRRE - RRE encoding
  328.  */
  329.  
  330. static  BOOL    rectRRE(rfbRectangle *r)
  331. {
  332.     rfbRREHeader    hdr ;
  333.     rfbRectangle    subrect ;
  334.     CARD8   color    ;
  335.     int     i        ;
  336.  
  337.     if (netRecv((PUCHAR) &hdr, sz_rfbRREHeader) != TRUE) {
  338.         netFail("failed to recv RREHeader") ;
  339.     return FALSE ;
  340.     }
  341.     hdr.nSubrects = swap32(hdr.nSubrects) ;
  342.  
  343.     if (netRecv((PUCHAR) &color, sizeof(CARD8)) != TRUE) {
  344.         netFail("failed to recv BG color") ;
  345.     return FALSE ;
  346.     }
  347.  
  348.     fillRect(r->x, r->y, r->w, r->h, color) ;
  349.  
  350.     for (i = 0 ; i < hdr.nSubrects ; i++) {
  351.         if (netRecv((PUCHAR) &color, sizeof(CARD8)) != TRUE) {
  352.         netFail("failed to recv sub color") ;
  353.         return FALSE ;
  354.     }
  355.     if (netRecv((PUCHAR) &subrect, sz_rfbRectangle) != TRUE) {
  356.         netFail("failed to recv subrect") ;
  357.         return FALSE ;
  358.     }
  359.  
  360.     subrect.x = r->x + swap16(subrect.x) ;
  361.     subrect.y = r->y + swap16(subrect.y) ;
  362.     subrect.w = swap16(subrect.w) ;
  363.     subrect.h = swap16(subrect.h) ;
  364.  
  365.         fillRect(subrect.x, subrect.y, subrect.w, subrect.h, color) ;
  366.     }
  367.     return TRUE ;
  368. }
  369.  
  370. /*
  371.  * rectCoRRE - CoRRE encoding
  372.  */
  373.  
  374. static  BOOL    rectCoRRE(rfbRectangle *r)
  375. {
  376.     rfbRREHeader    hdr ;
  377.     rfbRectangle    subrect ;
  378.     PUCHAR  sp       ;
  379.     CARD8   color    ;
  380.     int     i        ;
  381.  
  382.     if (netRecv((PUCHAR) &hdr, sz_rfbRREHeader) != TRUE) {
  383.         netFail("failed to recv RREHeader") ;
  384.     return FALSE ;
  385.     }
  386.     hdr.nSubrects = swap32(hdr.nSubrects) ;
  387.  
  388.     if (netRecv((PUCHAR) &color, sizeof(CARD8)) != TRUE) {
  389.         netFail("failed to recv BG color") ;
  390.     return FALSE ;
  391.     }
  392.  
  393.     fillRect(r->x, r->y, r->w, r->h, color) ;
  394.  
  395.     if (netRecv(rbuff, hdr.nSubrects * 5) != TRUE) {
  396.         netFail("failed to recv subrects") ;
  397.     return FALSE ;
  398.     }
  399.  
  400.     for (i = 0, sp = rbuff ; i < hdr.nSubrects ; i++, sp += 5) {
  401.         color = *(CARD8 *) sp ;
  402.     subrect.x = r->x + sp[1] ;
  403.     subrect.y = r->y + sp[2] ;
  404.     subrect.w = sp[3] ;
  405.     subrect.h = sp[4] ;
  406.  
  407.         fillRect(subrect.x, subrect.y, subrect.w, subrect.h, color) ;
  408.     }
  409.     return TRUE ;
  410. }
  411.  
  412. /*
  413.  * rectTile - Hextile encoding
  414.  */
  415.  
  416. static  CARD8   tileFg = 0xff ;
  417. static  CARD8   tileBg = 0x00 ;
  418.  
  419. static  PUCHAR  tileScan[16] ;
  420. static  POINTL  tileBlit[4]  ;
  421.  
  422. static  void    hextileInit(int x, int y, int w, int h, CARD8 bg)
  423. {
  424.     int     i, bytesPerLine ;
  425.     
  426.     /*
  427.      * fill tile with background color
  428.      */
  429.      
  430.     bytesPerLine = (w + 3) & ~0x03 ;
  431.     memset(ibuff, bg, (bytesPerLine * h)) ;
  432.  
  433.     for (i = 0 ; i < h  ; i++) {
  434.         tileScan[i] = &ibuff[bytesPerLine * (h - i - 1)] ;
  435.     }
  436.  
  437.     /*
  438.      * prepare for final bitblt
  439.      */
  440.      
  441.     pbmiBitmap->cx = w ;
  442.     pbmiBitmap->cy = h ;
  443.  
  444.     tileBlit[0].x = x ;
  445.     tileBlit[0].y = (cyBitmap - y - h) ;
  446.     tileBlit[1].x = tileBlit[0].x + w  - 1 ;
  447.     tileBlit[1].y = tileBlit[0].y + h - 1 ;
  448.     tileBlit[2].x = 0 ;
  449.     tileBlit[2].y = 0 ;
  450.     tileBlit[3].x = w ;
  451.     tileBlit[3].y = h ;
  452. }
  453.  
  454. #define hextileDraw()   \
  455.     GpiDrawBits(hpsBitmap, ibuff, pbmiBitmap, 4, tileBlit, ROP_SRCCOPY, 0)
  456.  
  457. #define hextileFill(x, y, w, h, color)      \
  458. {                                           \
  459.     int     i ;                             \
  460.     PUCHAR  p ;                             \
  461.     if ((w) == 1) {                         \
  462.         for (i = 0 ; i < (h) ; i++) {       \
  463.             p = tileScan[(y) + i] + (x) ;   \
  464.         *p = (color) ;                  \
  465.         }                                   \
  466.     } else {                                \
  467.         for (i = 0 ; i < (h) ; i++) {       \
  468.             p = tileScan[(y) + i] + (x) ;   \
  469.             memset(p, (color), (w)) ;       \
  470.         }                                   \
  471.     }                                       \
  472. }
  473.  
  474. static  BOOL    rectTile(rfbRectangle *r)
  475. {
  476.     CARD8   subencoding, nSubrects ;
  477.     int     x, y, w, h ;
  478.     int     i, j, bytesPerLine ;
  479.     int     sn, sx, sy, sw, sh ;
  480.     PUCHAR  sp, dp ;
  481.     POINTL  apt[4] ;
  482.     
  483.     for (y = r->y ; y < (r->y + r->h) ; y += 16) {
  484.         for (x = r->x ; x < (r->x + r->w) ; x += 16) {
  485.             w = h = 16 ;
  486.         if ((r->x + r->w - x) < 16) {
  487.             w = r->x + r->w - x ;
  488.         }
  489.         if ((r->y + r->h - y) < 16) {
  490.             h = r->y + r->h - y ;
  491.         }
  492.         if (netRecv((PUCHAR) &subencoding, 1) != TRUE) {
  493.             netFail("failed to recv sub encoding") ;
  494.         return FALSE ;
  495.         }
  496.         if (subencoding & rfbHextileRaw) {
  497.  
  498.             bytesPerLine = (w + 3) & ~0x03 ;
  499.  
  500.         if (netRecv(rbuff, w * h) != TRUE) {
  501.             netFail("failed on hextile raw") ;
  502.             return FALSE ;
  503.         }
  504.         for (i = 0, sp = rbuff ; i < h ; i++) {
  505.                     dp = &ibuff[bytesPerLine * (h - i - 1)] ;
  506.             for (j = 0 ; j < w ; j++) {
  507.                 *dp++ = *sp++ ;
  508.             }
  509.         }
  510.         
  511.         pbmiBitmap->cx = w ;
  512.         pbmiBitmap->cy = h ;
  513.         
  514.                 apt[0].x = x ;
  515.                 apt[0].y = (cyBitmap - y - h) ;
  516.                 apt[1].x = apt[0].x + w  - 1 ;
  517.                 apt[1].y = apt[0].y + h - 1 ;
  518.                 apt[2].x = 0 ;
  519.                 apt[2].y = 0 ;
  520.                 apt[3].x = w ;
  521.                 apt[3].y = h ;
  522.  
  523.                 GpiDrawBits(hpsBitmap, ibuff, 
  524.                             pbmiBitmap, 4, apt, ROP_SRCCOPY, 0) ;
  525.         continue ;
  526.         }
  527.         if (subencoding & rfbHextileBackgroundSpecified) {
  528.             if (netRecv((PUCHAR) &tileBg, sizeof(CARD8)) != TRUE) {
  529.             netFail("failed to recv BG color") ;
  530.             return FALSE ;
  531.         }
  532.         }
  533.         if (subencoding & rfbHextileForegroundSpecified) {
  534.             if (netRecv((PUCHAR) &tileFg, sizeof(CARD8)) != TRUE) {
  535.             netFail("failed to recv FG color") ;
  536.             return FALSE ;
  537.         }
  538.         }
  539.         if ((subencoding & rfbHextileAnySubrects) == 0) {
  540.                 hextileInit(x, y, w, h, tileBg) ;
  541.         hextileDraw() ;
  542.             } else if (subencoding & rfbHextileSubrectsColoured) {
  543.                 hextileInit(x, y, w, h, tileBg) ;
  544.                 if (netRecv((PUCHAR) &nSubrects, 1) != TRUE) {
  545.                     netFail("failed to recv hextile nSubrects") ;
  546.                     return FALSE ;
  547.                 }
  548.                 if (netRecv((PUCHAR) rbuff, nSubrects * 3) != TRUE) {
  549.                     netFail("failed to recv hextile Subrects") ;
  550.                     return FALSE ;
  551.                 }
  552.  
  553.                 for (sn = 0, sp = rbuff ; sn < nSubrects ; sn++, sp += 3) {
  554.                     sx = rfbHextileExtractX(sp[1]) ;
  555.                     sy = rfbHextileExtractY(sp[1]) ;
  556.                     sw = rfbHextileExtractW(sp[2]) ;
  557.                     sh = rfbHextileExtractH(sp[2]) ;
  558.             hextileFill(sx, sy, sw, sh, sp[0]) ;
  559.         }
  560.         hextileDraw() ;
  561.         } else {
  562.                 hextileInit(x, y, w, h, tileBg) ;
  563.                 if (netRecv((PUCHAR) &nSubrects, 1) != TRUE) {
  564.                     netFail("failed to recv hextile nSubrects") ;
  565.                     return FALSE ;
  566.                 }
  567.                 if (netRecv((PUCHAR) rbuff, nSubrects * 2) != TRUE) {
  568.                     netFail("failed to recv hextile Subrects") ;
  569.                     return FALSE ;
  570.                 }
  571.  
  572.                 for (sn = 0, sp = rbuff ; sn < nSubrects ; sn++, sp += 2) {
  573.                     sx = rfbHextileExtractX(sp[0]) ;
  574.                     sy = rfbHextileExtractY(sp[0]) ;
  575.                     sw = rfbHextileExtractW(sp[1]) ;
  576.                     sh = rfbHextileExtractH(sp[1]) ;
  577.             hextileFill(sx, sy, sw, sh, tileFg) ;
  578.         }
  579.         hextileDraw() ;
  580.         }
  581.         }
  582.     }
  583.     return TRUE ;
  584. }
  585.  
  586. /*
  587.  * VncPix8 - Drawing Context for bgr233 8bit static color
  588.  */
  589.  
  590. static ULONG normMap[] = {
  591.     0x00000000, 0x00240000, 0x00480000, 0x006d0000, 
  592.     0x00910000, 0x00b60000, 0x00da0000, 0x00ff0000, 
  593.     0x00002400, 0x00242400, 0x00482400, 0x006d2400, 
  594.     0x00912400, 0x00b62400, 0x00da2400, 0x00ff2400, 
  595.     0x00004800, 0x00244800, 0x00484800, 0x006d4800, 
  596.     0x00914800, 0x00b64800, 0x00da4800, 0x00ff4800, 
  597.     0x00006d00, 0x00246d00, 0x00486d00, 0x006d6d00, 
  598.     0x00916d00, 0x00b66d00, 0x00da6d00, 0x00ff6d00, 
  599.     0x00009100, 0x00249100, 0x00489100, 0x006d9100, 
  600.     0x00919100, 0x00b69100, 0x00da9100, 0x00ff9100, 
  601.     0x0000b600, 0x0024b600, 0x0048b600, 0x006db600, 
  602.     0x0091b600, 0x00b6b600, 0x00dab600, 0x00ffb600, 
  603.     0x0000da00, 0x0024da00, 0x0048da00, 0x006dda00, 
  604.     0x0091da00, 0x00b6da00, 0x00dada00, 0x00ffda00, 
  605.     0x0000ff00, 0x0024ff00, 0x0048ff00, 0x006dff00, 
  606.     0x0091ff00, 0x00b6ff00, 0x00daff00, 0x00ffff00, 
  607.     0x00000055, 0x00240055, 0x00480055, 0x006d0055, 
  608.     0x00910055, 0x00b60055, 0x00da0055, 0x00ff0055, 
  609.     0x00002455, 0x00242455, 0x00482455, 0x006d2455, 
  610.     0x00912455, 0x00b62455, 0x00da2455, 0x00ff2455, 
  611.     0x00004855, 0x00244855, 0x00484855, 0x006d4855, 
  612.     0x00914855, 0x00b64855, 0x00da4855, 0x00ff4855, 
  613.     0x00006d55, 0x00246d55, 0x00486d55, 0x006d6d55, 
  614.     0x00916d55, 0x00b66d55, 0x00da6d55, 0x00ff6d55, 
  615.     0x00009155, 0x00249155, 0x00489155, 0x006d9155, 
  616.     0x00919155, 0x00b69155, 0x00da9155, 0x00ff9155, 
  617.     0x0000b655, 0x0024b655, 0x0048b655, 0x006db655, 
  618.     0x0091b655, 0x00b6b655, 0x00dab655, 0x00ffb655, 
  619.     0x0000da55, 0x0024da55, 0x0048da55, 0x006dda55, 
  620.     0x0091da55, 0x00b6da55, 0x00dada55, 0x00ffda55, 
  621.     0x0000ff55, 0x0024ff55, 0x0048ff55, 0x006dff55, 
  622.     0x0091ff55, 0x00b6ff55, 0x00daff55, 0x00ffff55, 
  623.     0x000000aa, 0x002400aa, 0x004800aa, 0x006d00aa, 
  624.     0x009100aa, 0x00b600aa, 0x00da00aa, 0x00ff00aa, 
  625.     0x000024aa, 0x002424aa, 0x004824aa, 0x006d24aa, 
  626.     0x009124aa, 0x00b624aa, 0x00da24aa, 0x00ff24aa, 
  627.     0x000048aa, 0x002448aa, 0x004848aa, 0x006d48aa, 
  628.     0x009148aa, 0x00b648aa, 0x00da48aa, 0x00ff48aa, 
  629.     0x00006daa, 0x00246daa, 0x00486daa, 0x006d6daa, 
  630.     0x00916daa, 0x00b66daa, 0x00da6daa, 0x00ff6daa, 
  631.     0x000091aa, 0x002491aa, 0x004891aa, 0x006d91aa, 
  632.     0x009191aa, 0x00b691aa, 0x00da91aa, 0x00ff91aa, 
  633.     0x0000b6aa, 0x0024b6aa, 0x0048b6aa, 0x006db6aa, 
  634.     0x0091b6aa, 0x00b6b6aa, 0x00dab6aa, 0x00ffb6aa, 
  635.     0x0000daaa, 0x0024daaa, 0x0048daaa, 0x006ddaaa, 
  636.     0x0091daaa, 0x00b6daaa, 0x00dadaaa, 0x00ffdaaa, 
  637.     0x0000ffaa, 0x0024ffaa, 0x0048ffaa, 0x006dffaa, 
  638.     0x0091ffaa, 0x00b6ffaa, 0x00daffaa, 0x00ffffaa, 
  639.     0x000000ff, 0x002400ff, 0x004800ff, 0x006d00ff, 
  640.     0x009100ff, 0x00b600ff, 0x00da00ff, 0x00ff00ff, 
  641.     0x000024ff, 0x002424ff, 0x004824ff, 0x006d24ff, 
  642.     0x009124ff, 0x00b624ff, 0x00da24ff, 0x00ff24ff, 
  643.     0x000048ff, 0x002448ff, 0x004848ff, 0x006d48ff, 
  644.     0x009148ff, 0x00b648ff, 0x00da48ff, 0x00ff48ff, 
  645.     0x00006dff, 0x00246dff, 0x00486dff, 0x006d6dff, 
  646.     0x00916dff, 0x00b66dff, 0x00da6dff, 0x00ff6dff, 
  647.     0x000091ff, 0x002491ff, 0x004891ff, 0x006d91ff, 
  648.     0x009191ff, 0x00b691ff, 0x00da91ff, 0x00ff91ff, 
  649.     0x0000b6ff, 0x0024b6ff, 0x0048b6ff, 0x006db6ff, 
  650.     0x0091b6ff, 0x00b6b6ff, 0x00dab6ff, 0x00ffb6ff, 
  651.     0x0000daff, 0x0024daff, 0x0048daff, 0x006ddaff, 
  652.     0x0091daff, 0x00b6daff, 0x00dadaff, 0x00ffdaff, 
  653.     0x0000ffff, 0x0024ffff, 0x0048ffff, 0x006dffff, 
  654.     0x0091ffff, 0x00b6ffff, 0x00daffff, 0x00ffffff
  655. } ;
  656.  
  657. static  BOOL    rectInitNorm(int cx, int cy)
  658. {
  659.     bgrMap = normMap ;
  660.  
  661.     return rectInit(cx, cy) ;
  662. }
  663.  
  664. VNCREC      VncCtx8 = {
  665.     /* bitsPerPixel */  8,          /* Current pixel format will fit    */
  666.     /* depth        */  8,          /* to PM's RGB structure with no    */
  667.     /* bigEndian    */  0,          /* conversions.                     */
  668.     /* trueColour   */  1,          /* It reduces client side load.     */
  669.     /* redMax       */  0x0007,     /* But for reduce network traffic,  */
  670.     /* greenMax     */  0x0007,     /* 8 bits BGR233 will be nice.      */
  671.     /* blureMax     */  0x0003,
  672.     /* redShift     */  0,
  673.     /* greenShift   */  3,
  674.     /* blueShift    */  6,
  675.     /* pad1, pad2   */  0, 0,
  676.     /* rectDone     */  rectDone,
  677.     /* rectInit     */  rectInitNorm,
  678.     /* rectDraw     */  rectDraw,
  679.     /* rectRaw      */  rectRaw,
  680.     /* rectCopy     */  rectCopy,
  681.     /* rectRRE      */  rectRRE,
  682.     /* rectCoRRE    */  rectCoRRE,
  683.     /* rectTile     */  rectTile
  684. } ;
  685.  
  686. /*
  687.  * VncPix8Tiny - Drawing Context for bgr233 mapped to default 16 colors
  688.  */
  689.  
  690. static ULONG tinyMap[] = {
  691.     0x00000000, 0x00800000, 0x00800000, 0x00800000, 
  692.     0x00800000, 0x00800000, 0x00ff0000, 0x00ff0000, 
  693.     0x00008000, 0x00800080, 0x00800000, 0x00800000, 
  694.     0x00800000, 0x00800000, 0x00ff0000, 0x00ff0000, 
  695.     0x00008000, 0x00008000, 0x00808000, 0x00800080, 
  696.     0x00800000, 0x00800000, 0x00ff0000, 0x00ff0000, 
  697.     0x00008000, 0x00008000, 0x00008000, 0x00808000, 
  698.     0x00808000, 0x00808000, 0x00ff0000, 0x00ff0000, 
  699.     0x00008000, 0x00008000, 0x00008000, 0x00808000, 
  700.     0x00808000, 0x00808000, 0x00ff00ff, 0x00ff00ff, 
  701.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  702.     0x00808080, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  703.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  704.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  705.     0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 
  706.     0x0000ff00, 0x0000ffff, 0x00ffff00, 0x00ffff00, 
  707.     0x00000080, 0x00000080, 0x00800080, 0x00800080, 
  708.     0x00800000, 0x00800000, 0x00ff0000, 0x00ff0000, 
  709.     0x00000080, 0x00000080, 0x00800080, 0x00800080, 
  710.     0x00800000, 0x00800000, 0x00ff0000, 0x00ff0000, 
  711.     0x00008080, 0x00008080, 0x00800080, 0x00800080, 
  712.     0x00800080, 0x00ff0000, 0x00ff0000, 0x00ff0000, 
  713.     0x00008080, 0x00008080, 0x00008080, 0x00808000, 
  714.     0x00808000, 0x00808000, 0x00ff0000, 0x00ff00ff, 
  715.     0x00008000, 0x00008000, 0x00008080, 0x00808080, 
  716.     0x00808080, 0x00808080, 0x00ff00ff, 0x00ff00ff, 
  717.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  718.     0x00ff00ff, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  719.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  720.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  721.     0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 
  722.     0x0000ffff, 0x0000ffff, 0x00ffff00, 0x00ffff00, 
  723.     0x00000080, 0x00000080, 0x00000080, 0x00800080, 
  724.     0x00800080, 0x00800080, 0x00ff0000, 0x00ff0000, 
  725.     0x00000080, 0x00000080, 0x00000080, 0x00800080, 
  726.     0x00800080, 0x00800080, 0x00ff0000, 0x00ff0000, 
  727.     0x000000ff, 0x000000ff, 0x000000ff, 0x00800080, 
  728.     0x00800080, 0x00800080, 0x00ff00ff, 0x00ff00ff, 
  729.     0x00008080, 0x00008080, 0x00008080, 0x00808080, 
  730.     0x00808080, 0x00808080, 0x00ff00ff, 0x00ff00ff, 
  731.     0x00008080, 0x00008080, 0x00008080, 0x00808080, 
  732.     0x00808080, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 
  733.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  734.     0x00ff00ff, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  735.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  736.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x0000ff00, 
  737.     0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ffff, 
  738.     0x0000ffff, 0x0000ffff, 0x00ffff00, 0x00ffff00, 
  739.     0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 
  740.     0x000000ff, 0x00808080, 0x00ff00ff, 0x00ff00ff, 
  741.     0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 
  742.     0x000000ff, 0x00808080, 0x00ff00ff, 0x00ff00ff, 
  743.     0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 
  744.     0x00808080, 0x00808080, 0x00ff00ff, 0x00ff00ff, 
  745.     0x000000ff, 0x000000ff, 0x000000ff, 0x00808080, 
  746.     0x00808080, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 
  747.     0x00008080, 0x00008080, 0x00808080, 0x00808080, 
  748.     0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00cccccc, 
  749.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  750.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  751.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  752.     0x00cccccc, 0x00cccccc, 0x0000ffff, 0x0000ffff, 
  753.     0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff, 
  754.     0x0000ffff, 0x00ffff00, 0x00ffff00, 0x00ffffff
  755. } ;
  756.  
  757. static  BOOL    rectInitTiny(int cx, int cy)
  758. {
  759.     bgrMap = tinyMap ;
  760.  
  761.     return rectInit(cx, cy) ;
  762. }
  763.  
  764. VNCREC      VncCtx8Tiny = {
  765.     /* bitsPerPixel */  8,          /* Current pixel format will fit    */
  766.     /* depth        */  8,          /* to PM's RGB structure with no    */
  767.     /* bigEndian    */  0,          /* conversions.                     */
  768.     /* trueColour   */  1,          /* It reduces client side load.     */
  769.     /* redMax       */  0x0007,     /* But for reduce network traffic,  */
  770.     /* greenMax     */  0x0007,     /* 8 bits BGR233 will be nice.      */
  771.     /* blureMax     */  0x0003,
  772.     /* redShift     */  0,
  773.     /* greenShift   */  3,
  774.     /* blueShift    */  6,
  775.     /* pad1, pad2   */  0, 0,
  776.     /* rectDone     */  rectDone,
  777.     /* rectInit     */  rectInitTiny,
  778.     /* rectDraw     */  rectDraw,
  779.     /* rectRaw      */  rectRaw,
  780.     /* rectCopy     */  rectCopy,
  781.     /* rectRRE      */  rectRRE,
  782.     /* rectCoRRE    */  rectCoRRE,
  783.     /* rectTile     */  rectTile
  784. } ;
  785.  
  786. /*
  787.  * VncPix8Gray - Drawing Context for bgr233 mapped to 4 level gray scale
  788.  */
  789.  
  790. static ULONG grayMap[] = {
  791.     0x00000000, 0x00000000, 0x00000000, 0x00000000, 
  792.     0x00000000, 0x00808080, 0x00808080, 0x00808080, 
  793.     0x00000000, 0x00000000, 0x00000000, 0x00000000, 
  794.     0x00000000, 0x00808080, 0x00808080, 0x00808080, 
  795.     0x00000000, 0x00000000, 0x00000000, 0x00000000, 
  796.     0x00000000, 0x00808080, 0x00808080, 0x00808080, 
  797.     0x00000000, 0x00000000, 0x00808080, 0x00808080, 
  798.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  799.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  800.     0x00808080, 0x00808080, 0x00808080, 0x00cccccc, 
  801.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  802.     0x00808080, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  803.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  804.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  805.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  806.     0x00cccccc, 0x00ffffff, 0x00ffffff, 0x00ffffff, 
  807.     0x00000000, 0x00000000, 0x00000000, 0x00000000, 
  808.     0x00000000, 0x00808080, 0x00808080, 0x00808080, 
  809.     0x00000000, 0x00000000, 0x00000000, 0x00000000, 
  810.     0x00000000, 0x00808080, 0x00808080, 0x00808080, 
  811.     0x00000000, 0x00000000, 0x00000000, 0x00000000, 
  812.     0x00000000, 0x00808080, 0x00808080, 0x00808080, 
  813.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  814.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  815.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  816.     0x00808080, 0x00808080, 0x00808080, 0x00cccccc, 
  817.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  818.     0x00808080, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  819.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  820.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  821.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  822.     0x00cccccc, 0x00ffffff, 0x00ffffff, 0x00ffffff, 
  823.     0x00000000, 0x00000000, 0x00000000, 0x00000000, 
  824.     0x00000000, 0x00808080, 0x00808080, 0x00808080, 
  825.     0x00000000, 0x00000000, 0x00000000, 0x00000000, 
  826.     0x00000000, 0x00808080, 0x00808080, 0x00808080, 
  827.     0x00000000, 0x00000000, 0x00000000, 0x00000000, 
  828.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  829.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  830.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  831.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  832.     0x00808080, 0x00808080, 0x00808080, 0x00cccccc, 
  833.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  834.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  835.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  836.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  837.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  838.     0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff, 
  839.     0x00000000, 0x00000000, 0x00000000, 0x00808080, 
  840.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  841.     0x00000000, 0x00000000, 0x00000000, 0x00808080, 
  842.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  843.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  844.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  845.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  846.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  847.     0x00808080, 0x00808080, 0x00808080, 0x00808080, 
  848.     0x00808080, 0x00808080, 0x00cccccc, 0x00cccccc, 
  849.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  850.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  851.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  852.     0x00cccccc, 0x00cccccc, 0x00cccccc, 0x00cccccc, 
  853.     0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff, 
  854.     0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff
  855. } ;
  856.  
  857. static  BOOL    rectInitGray(int cx, int cy)
  858. {
  859.     bgrMap = grayMap ;
  860.  
  861.     return rectInit(cx, cy) ;
  862. }
  863.  
  864. VNCREC      VncCtx8Gray = {
  865.     /* bitsPerPixel */  8,          /* Current pixel format will fit    */
  866.     /* depth        */  8,          /* to PM's RGB structure with no    */
  867.     /* bigEndian    */  0,          /* conversions.                     */
  868.     /* trueColour   */  1,          /* It reduces client side load.     */
  869.     /* redMax       */  0x0007,     /* But for reduce network traffic,  */
  870.     /* greenMax     */  0x0007,     /* 8 bits BGR233 will be nice.      */
  871.     /* blureMax     */  0x0003,
  872.     /* redShift     */  0,
  873.     /* greenShift   */  3,
  874.     /* blueShift    */  6,
  875.     /* pad1, pad2   */  0, 0,
  876.     /* rectDone     */  rectDone,
  877.     /* rectInit     */  rectInitGray,
  878.     /* rectDraw     */  rectDraw,
  879.     /* rectRaw      */  rectRaw,
  880.     /* rectCopy     */  rectCopy,
  881.     /* rectRRE      */  rectRRE,
  882.     /* rectCoRRE    */  rectCoRRE,
  883.     /* rectTile     */  rectTile
  884. } ;
  885.