/[rdesktop]/sourceforge.net/trunk/rdesktop/bitmap.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/bitmap.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 25 by matty, Sat Jan 6 03:47:04 2001 UTC revision 82 by astrand, Tue Jul 30 07:18:48 2002 UTC
# Line 1  Line 1 
1  /*  /*
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Bitmap decompression routines     Bitmap decompression routines
4     Copyright (C) Matthew Chapman 1999-2000     Copyright (C) Matthew Chapman 1999-2001
5        
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 21  Line 21 
21  #include "rdesktop.h"  #include "rdesktop.h"
22    
23  #define CVAL(p)   (*(p++))  #define CVAL(p)   (*(p++))
 #define SVAL(p)   ((*((p++) + 1) << 8) | CVAL(p))  
24    
25  #define REPEAT(statement) { while ((count > 0) && (x < width)) { statement; count--; x++; } }  #define UNROLL8(exp) { exp exp exp exp exp exp exp exp }
26  #define MASK_UPDATE() { mixmask <<= 1; if (mixmask == 0) { mask = CVAL(input); mixmask = 1; } }  
27    #define REPEAT(statement) \
28    { \
29            while((count & ~0x7) && ((x+8) < width)) \
30                    UNROLL8( statement; count--; x++; ); \
31            \
32            while((count > 0) && (x < width)) { statement; count--; x++; } \
33    }
34    
35    #define MASK_UPDATE() \
36    { \
37            mixmask <<= 1; \
38            if (mixmask == 0) \
39            { \
40                    mask = fom_mask ? fom_mask : CVAL(input); \
41                    mixmask = 1; \
42            } \
43    }
44    
45  BOOL  BOOL
46  bitmap_decompress(unsigned char *output, int width, int height,  bitmap_decompress(unsigned char *output, int width, int height, unsigned char *input, int size)
                   unsigned char *input, int size)  
47  {  {
48          unsigned char *end = input + size;          unsigned char *end = input + size;
49          unsigned char *prevline = NULL, *line = NULL;          unsigned char *prevline = NULL, *line = NULL;
# Line 36  bitmap_decompress(unsigned char *output, Line 51  bitmap_decompress(unsigned char *output,
51          int lastopcode = -1, insertmix = False, bicolour = False;          int lastopcode = -1, insertmix = False, bicolour = False;
52          uint8 code, colour1 = 0, colour2 = 0;          uint8 code, colour1 = 0, colour2 = 0;
53          uint8 mixmask, mask = 0, mix = 0xff;          uint8 mixmask, mask = 0, mix = 0xff;
54            int fom_mask = 0;
55    
56          while (input < end)          while (input < end)
57          {          {
58                    fom_mask = 0;
59                  code = CVAL(input);                  code = CVAL(input);
60                  opcode = code >> 4;                  opcode = code >> 4;
61    
# Line 55  bitmap_decompress(unsigned char *output, Line 72  bitmap_decompress(unsigned char *output,
72    
73                          case 0xf:                          case 0xf:
74                                  opcode = code & 0xf;                                  opcode = code & 0xf;
75                                  count = (opcode < 13) ? SVAL(input) : 1;                                  if (opcode < 9)
76                                    {
77                                            count = CVAL(input);
78                                            count |= CVAL(input) << 8;
79                                    }
80                                    else
81                                    {
82                                            count = (opcode < 0xb) ? 8 : 1;
83                                    }
84                                  offset = 0;                                  offset = 0;
85                                  break;                                  break;
86    
# Line 85  bitmap_decompress(unsigned char *output, Line 110  bitmap_decompress(unsigned char *output,
110                  }                  }
111    
112                  /* Read preliminary data */                  /* Read preliminary data */
                 mixmask = 0;  
113                  switch (opcode)                  switch (opcode)
114                  {                  {
115                          case 0: /* Fill */                          case 0: /* Fill */
116                                  if ((lastopcode == opcode)                                  if ((lastopcode == opcode) && !((x == width) && (prevline == NULL)))
                                     && !((x == width) && (prevline == NULL)))  
117                                          insertmix = True;                                          insertmix = True;
118                                  break;                                  break;
119                          case 8: /* Bicolour */                          case 8: /* Bicolour */
# Line 103  bitmap_decompress(unsigned char *output, Line 126  bitmap_decompress(unsigned char *output,
126                                  mix = CVAL(input);                                  mix = CVAL(input);
127                                  opcode -= 5;                                  opcode -= 5;
128                                  break;                                  break;
129                            case 9: /* FillOrMix_1 */
130                                    mask = 0x03;
131                                    opcode = 0x02;
132                                    fom_mask = 3;
133                                    break;
134                            case 0x0a:      /* FillOrMix_2 */
135                                    mask = 0x05;
136                                    opcode = 0x02;
137                                    fom_mask = 5;
138                                    break;
139    
140                  }                  }
141    
142                  lastopcode = opcode;                  lastopcode = opcode;
143                    mixmask = 0;
144    
145                  /* Output body */                  /* Output body */
146                  while (count > 0)                  while (count > 0)
# Line 129  bitmap_decompress(unsigned char *output, Line 165  bitmap_decompress(unsigned char *output,
165                                                  if (prevline == NULL)                                                  if (prevline == NULL)
166                                                          line[x] = mix;                                                          line[x] = mix;
167                                                  else                                                  else
168                                                          line[x] =                                                          line[x] = prevline[x] ^ mix;
                                                                 prevline[x] ^  
                                                                 mix;  
169    
170                                                  insertmix = False;                                                  insertmix = False;
171                                                  count--;                                                  count--;
# Line 155  bitmap_decompress(unsigned char *output, Line 189  bitmap_decompress(unsigned char *output,
189                                          }                                          }
190                                          else                                          else
191                                          {                                          {
192                                                  REPEAT(line[x] =                                                  REPEAT(line[x] = prevline[x] ^ mix);
                                                        prevline[x] ^ mix);  
193                                          }                                          }
194                                          break;                                          break;
195    
# Line 164  bitmap_decompress(unsigned char *output, Line 197  bitmap_decompress(unsigned char *output,
197                                          if (prevline == NULL)                                          if (prevline == NULL)
198                                          {                                          {
199                                                  REPEAT(MASK_UPDATE();                                                  REPEAT(MASK_UPDATE();
200                                                         if (mask & mixmask)                                                         if (mask & mixmask) line[x] = mix;
                                                        line[x] = mix;  
201                                                         else                                                         else
202                                                         line[x] = 0;);                                                         line[x] = 0;);
203                                          }                                          }
# Line 173  bitmap_decompress(unsigned char *output, Line 205  bitmap_decompress(unsigned char *output,
205                                          {                                          {
206                                                  REPEAT(MASK_UPDATE();                                                  REPEAT(MASK_UPDATE();
207                                                         if (mask & mixmask)                                                         if (mask & mixmask)
208                                                         line[x] =                                                         line[x] = prevline[x] ^ mix;
                                                        prevline[x] ^ mix;  
209                                                         else                                                         else
210                                                         line[x] =                                                         line[x] = prevline[x];);
                                                        prevline[x];);  
211                                          }                                          }
212                                          break;                                          break;
213    
# Line 192  bitmap_decompress(unsigned char *output, Line 222  bitmap_decompress(unsigned char *output,
222                                  case 8: /* Bicolour */                                  case 8: /* Bicolour */
223                                          REPEAT(if (bicolour)                                          REPEAT(if (bicolour)
224                                                 {                                                 {
225                                                 line[x] = colour2;                                                 line[x] = colour2; bicolour = False;}
                                                bicolour = False;}  
226                                                 else                                                 else
227                                                 {                                                 {
228                                                 line[x] = colour1;                                                 line[x] = colour1; bicolour = True; count++;}
                                                bicolour = True; count++;}  
229                                          );                                          );
230                                          break;                                          break;
231    
232                                  case 13:        /* White */                                  case 0xd:       /* White */
233                                          REPEAT(line[x] = 0xff);                                          REPEAT(line[x] = 0xff);
234                                          break;                                          break;
235    
236                                  case 14:        /* Black */                                  case 0xe:       /* Black */
237                                          REPEAT(line[x] = 0x00);                                          REPEAT(line[x] = 0x00);
238                                          break;                                          break;
239    
240                                  default:                                  default:
241                                          NOTIMP("bitmap opcode 0x%x\n",                                          unimpl("bitmap opcode 0x%x\n", opcode);
                                                opcode);  
242                                          return False;                                          return False;
243                          }                          }
244                  }                  }

Legend:
Removed from v.25  
changed lines
  Added in v.82

  ViewVC Help
Powered by ViewVC 1.1.26