ClientConnectionHextile.cpp
上传用户:sbftbdw
上传日期:2007-01-03
资源大小:379k
文件大小:8k
源码类别:

远程控制编程

开发平台:

Visual C++

  1. //  Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory
  2. //
  3. //  This file is part of the VNC system.
  4. //
  5. //  The VNC system is free software; you can redistribute it and/or modify
  6. //  it under the terms of the GNU General Public License as published by
  7. //  the Free Software Foundation; either version 2 of the License, or
  8. //  (at your option) any later version.
  9. //
  10. //  This program is distributed in the hope that it will be useful,
  11. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. //  GNU General Public License for more details.
  14. //
  15. //  You should have received a copy of the GNU General Public License
  16. //  along with this program; if not, write to the Free Software
  17. //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  18. //  USA.
  19. //
  20. // If the source code for the VNC system is not available from the place 
  21. // whence you received this file, check http://www.orl.co.uk/vnc or contact
  22. // the authors on vnc@orl.co.uk for information on obtaining it.
  23. // Hextile Encoding
  24. //
  25. // The bits of the ClientConnection object to do with Hextile.
  26. #include "stdhdrs.h"
  27. #include "vncviewer.h"
  28. #include "ClientConnection.h"
  29. void ClientConnection::ReadHextileRect(rfbFramebufferUpdateRectHeader *pfburh)
  30. {
  31. switch (m_myFormat.bitsPerPixel) {
  32. case 8:
  33. HandleHextileEncoding8(pfburh->r.x, pfburh->r.y, pfburh->r.w, pfburh->r.h);
  34. break;
  35. case 16:
  36. HandleHextileEncoding16(pfburh->r.x, pfburh->r.y, pfburh->r.w, pfburh->r.h);
  37. break;
  38. case 32:
  39. HandleHextileEncoding32(pfburh->r.x, pfburh->r.y, pfburh->r.w, pfburh->r.h);
  40. break;
  41. }
  42. }
  43. #define DEFINE_HEXTILE(bpp)                                                   
  44. void ClientConnection::HandleHextileEncoding##bpp(int rx, int ry, int rw, int rh)                    
  45. {                                                                             
  46.     CARD##bpp bg, fg;                                                         
  47. COLORREF bgcolor, fgcolor;   
  48.     int i;                                                                    
  49.     CARD8 *ptr;                                                               
  50.     int x, y, w, h;                                                           
  51.     int sx, sy, sw, sh;                                                       
  52.     CARD8 subencoding;                                                        
  53.     CARD8 nSubrects;                                                          
  54.   
  55.     CheckBufferSize( 16 * 16 * bpp );   
  56. SETUP_COLOR_SHORTCUTS;                                                    
  57.                                                                               
  58.     for (y = ry; y < ry+rh; y += 16) {                                        
  59.         for (x = rx; x < rx+rw; x += 16) {                                    
  60.             w = h = 16;                                                       
  61.             if (rx+rw - x < 16)                                               
  62.                 w = rx+rw - x;                                                
  63.             if (ry+rh - y < 16)                                               
  64.                 h = ry+rh - y;                                                
  65.                                                                               
  66.             ReadExact((char *)&subencoding, 1);                               
  67.                                                                               
  68.             if (subencoding & rfbHextileRaw) {                                
  69.                 ReadExact(m_netbuf, w * h * (bpp / 8));                       
  70.                 SETPIXELS(bpp, x,y,w,h)                                       
  71.                 continue;                                                     
  72.             }                                                                 
  73.                                                                               
  74.     if (subencoding & rfbHextileBackgroundSpecified) {                
  75.                 ReadExact((char *)&bg, (bpp/8));                              
  76. bgcolor = COLOR_FROM_PIXEL##bpp##_ADDRESS(&bg);     
  77. }   
  78.             FillSolidRect(x,y,w,h,bgcolor);                                   
  79.                                                                               
  80.             if (subencoding & rfbHextileForegroundSpecified)  {               
  81.                 ReadExact((char *)&fg, (bpp/8));                              
  82. fgcolor = COLOR_FROM_PIXEL##bpp##_ADDRESS(&fg);   
  83. }                                                                 
  84.                                                                               
  85.             if (!(subencoding & rfbHextileAnySubrects)) {                     
  86.                 continue;                                                     
  87.             }                                                                 
  88.                                                                               
  89.             ReadExact( (char *)&nSubrects, 1) ;                               
  90.                                                                               
  91.             ptr = (CARD8 *)m_netbuf;                                          
  92.                                                                               
  93.             if (subencoding & rfbHextileSubrectsColoured) {                   
  94.                                                               
  95.                 ReadExact( m_netbuf, nSubrects * (2 + (bpp / 8)));              
  96.                                                                               
  97.                 for (i = 0; i < nSubrects; i++) {                             
  98.                     fgcolor = COLOR_FROM_PIXEL##bpp##_ADDRESS(ptr);           
  99. ptr += (bpp/8);                                           
  100.                     sx = *ptr >> 4;                                           
  101.                     sy = *ptr++ & 0x0f;                                       
  102.                     sw = (*ptr >> 4) + 1;                                     
  103.                     sh = (*ptr++ & 0x0f) + 1;                                 
  104.                     FillSolidRect(x+sx, y+sy, sw, sh, fgcolor);               
  105.                 }                                                             
  106.                                                                               
  107.             } else {                                                          
  108.                 ReadExact(m_netbuf, nSubrects * 2);                    
  109.                                                                               
  110.                 for (i = 0; i < nSubrects; i++) {                             
  111.                     sx = *ptr >> 4;                                           
  112.                     sy = *ptr++ & 0x0f;                                       
  113.                     sw = (*ptr >> 4) + 1;                                     
  114.                     sh = (*ptr++ & 0x0f) + 1;                                 
  115.                     FillSolidRect(x+sx, y+sy, sw, sh, fgcolor);               
  116.                 }                                                             
  117.             }                                                                 
  118.         }                                                                     
  119.     }                                                                         
  120.                                                                               
  121. }
  122. DEFINE_HEXTILE(8)
  123. DEFINE_HEXTILE(16)
  124. DEFINE_HEXTILE(32)