/[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 19 by matty, Sun Oct 8 01:59:25 2000 UTC revision 30 by matty, Fri Sep 14 13:51:38 2001 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 23  Line 23 
23  #define CVAL(p)   (*(p++))  #define CVAL(p)   (*(p++))
24  #define SVAL(p)   ((*((p++) + 1) << 8) | CVAL(p))  #define SVAL(p)   ((*((p++) + 1) << 8) | CVAL(p))
25    
26  #define REPEAT(statement) { while ((count > 0) && (x < width)) { statement; count--; x++; } }  #define UNROLL8(exp) { exp exp exp exp exp exp exp exp }
 #define MASK_UPDATE() { mixmask <<= 1; if (mixmask == 0) { mask = CVAL(input); mixmask = 1; } }  
27    
28  BOOL bitmap_decompress(unsigned char *output, int width, int height,  #define REPEAT(statement) \
29                         unsigned char *input, int size)  { \
30            while((count & ~0x7) && ((x+8) < width)) \
31                    UNROLL8( statement; count--; x++; ); \
32            \
33            while((count > 0) && (x < width)) { statement; count--; x++; } \
34    }
35    
36    #define MASK_UPDATE() \
37    { \
38            mixmask <<= 1; \
39            if (mixmask == 0) \
40            { \
41                    mask = fom_mask ? fom_mask : CVAL(input); \
42                    mixmask = 1; \
43            } \
44    }
45    
46    BOOL
47    bitmap_decompress(unsigned char *output, int width, int height,
48                      unsigned char *input, int size)
49  {  {
50          unsigned char *end = input + size;          unsigned char *end = input + size;
51          unsigned char *prevline = NULL, *line = NULL;          unsigned char *prevline = NULL, *line = NULL;
# Line 35  BOOL bitmap_decompress(unsigned char *ou Line 53  BOOL bitmap_decompress(unsigned char *ou
53          int lastopcode = -1, insertmix = False, bicolour = False;          int lastopcode = -1, insertmix = False, bicolour = False;
54          uint8 code, colour1 = 0, colour2 = 0;          uint8 code, colour1 = 0, colour2 = 0;
55          uint8 mixmask, mask = 0, mix = 0xff;          uint8 mixmask, mask = 0, mix = 0xff;
56            int fom_mask = 0;
57    
58          while (input < end)          while (input < end)
59          {          {
60                    fom_mask = 0;
61                  code = CVAL(input);                  code = CVAL(input);
62                  opcode = code >> 4;                  opcode = code >> 4;
63    
# Line 54  BOOL bitmap_decompress(unsigned char *ou Line 74  BOOL bitmap_decompress(unsigned char *ou
74    
75                          case 0xf:                          case 0xf:
76                                  opcode = code & 0xf;                                  opcode = code & 0xf;
77                                  count = (opcode < 13) ? SVAL(input) : 1;                                  if (opcode < 9)
78                                            count = SVAL(input);
79                                    else
80                                            count = (opcode < 0xb) ? 8 : 1;
81                                  offset = 0;                                  offset = 0;
82                                  break;                                  break;
83    
# Line 84  BOOL bitmap_decompress(unsigned char *ou Line 107  BOOL bitmap_decompress(unsigned char *ou
107                  }                  }
108    
109                  /* Read preliminary data */                  /* Read preliminary data */
                 mixmask = 0;  
110                  switch (opcode)                  switch (opcode)
111                  {                  {
112                          case 0: /* Fill */                          case 0: /* Fill */
113                                  if ((lastopcode == opcode)                                  if ((lastopcode == opcode)
114                                      && !((x == width) && (prevline == NULL)))                                      && !((x == width) && (prevline == NULL)))
115                                          insertmix = True;                                          insertmix = True;
116                                  break;                                  break;
117                          case 8: /* Bicolour */                          case 8: /* Bicolour */
118                                  colour1 = CVAL(input);                                  colour1 = CVAL(input);
119                          case 3: /* Colour */                          case 3: /* Colour */
120                                  colour2 = CVAL(input);                                  colour2 = CVAL(input);
121                                  break;                                  break;
122                          case 6: /* SetMix/Mix */                          case 6: /* SetMix/Mix */
123                          case 7: /* SetMix/FillOrMix */                          case 7: /* SetMix/FillOrMix */
124                                  mix = CVAL(input);                                  mix = CVAL(input);
125                                  opcode -= 5;                                  opcode -= 5;
126                                  break;                                  break;
127                            case 9: /* FillOrMix_1 */
128                                    mask = 0x03;
129                                    opcode = 0x02;
130                                    fom_mask = 3;
131                                    break;
132                            case 0x0a:      /* FillOrMix_2 */
133                                    mask = 0x05;
134                                    opcode = 0x02;
135                                    fom_mask = 5;
136                                    break;
137    
138                  }                  }
139    
140                  lastopcode = opcode;                  lastopcode = opcode;
141                    mixmask = 0;
142    
143                  /* Output body */                  /* Output body */
144                  while (count > 0)                  while (count > 0)
# Line 122  BOOL bitmap_decompress(unsigned char *ou Line 157  BOOL bitmap_decompress(unsigned char *ou
157    
158                          switch (opcode)                          switch (opcode)
159                          {                          {
160                                  case 0: /* Fill */                                  case 0: /* Fill */
161                                          if (insertmix)                                          if (insertmix)
162                                          {                                          {
163                                                  if (prevline == NULL)                                                  if (prevline == NULL)
164                                                          line[x] = mix;                                                          line[x] = mix;
165                                                  else                                                  else
166                                                          line[x] = prevline[x] ^ mix;                                                          line[x] =
167                                                                    prevline[x] ^
168                                                                    mix;
169    
170                                                  insertmix = False;                                                  insertmix = False;
171                                                  count--;                                                  count--;
# Line 136  BOOL bitmap_decompress(unsigned char *ou Line 173  BOOL bitmap_decompress(unsigned char *ou
173                                          }                                          }
174    
175                                          if (prevline == NULL)                                          if (prevline == NULL)
176                                                  REPEAT(line[x] = 0)                                          {
177                                                    REPEAT(line[x] = 0);
178                                            }
179                                          else                                          else
180                                                  REPEAT(line[x] = prevline[x])                                          {
181                                                    REPEAT(line[x] = prevline[x]);
182                                            }
183                                          break;                                          break;
184    
185                                  case 1: /* Mix */                                  case 1: /* Mix */
186                                          if (prevline == NULL)                                          if (prevline == NULL)
187                                                  REPEAT(line[x] = mix)                                          {
188                                                    REPEAT(line[x] = mix);
189                                            }
190                                          else                                          else
191                                                  REPEAT(line[x] = prevline[x] ^ mix)                                          {
192                                                    REPEAT(line[x] =
193                                                           prevline[x] ^ mix);
194                                            }
195                                          break;                                          break;
196    
197                                  case 2: /* Fill or Mix */                                  case 2: /* Fill or Mix */
198                                          if (prevline == NULL)                                          if (prevline == NULL)
199                                              REPEAT(                                          {
200                                                     MASK_UPDATE();                                                  REPEAT(MASK_UPDATE();
201                                                           if (mask & mixmask)
202                                                     if (mask & mixmask)                                                         line[x] = mix;
203                                                          line[x] = mix;                                                         else
204                                                     else                                                         line[x] = 0;);
205                                                          line[x] = 0;                                          }
                                             )  
206                                          else                                          else
207                                              REPEAT(                                          {
208                                                     MASK_UPDATE();                                                  REPEAT(MASK_UPDATE();
209                                                           if (mask & mixmask)
210                                                     if (mask & mixmask)                                                         line[x] =
211                                                          line[x] = prevline[x] ^ mix;                                                         prevline[x] ^ mix;
212                                                     else                                                         else
213                                                          line[x] = prevline[x];                                                         line[x] =
214                                              )                                                         prevline[x];);
215                                            }
216                                          break;                                          break;
217    
218                                  case 3: /* Colour */                                  case 3: /* Colour */
219                                          REPEAT(line[x] = colour2)                                          REPEAT(line[x] = colour2);
220                                          break;                                          break;
221    
222                                  case 4: /* Copy */                                  case 4: /* Copy */
223                                          REPEAT(line[x] = CVAL(input))                                          REPEAT(line[x] = CVAL(input));
224                                          break;                                          break;
225    
226                                  case 8: /* Bicolour */                                  case 8: /* Bicolour */
227                                          REPEAT(                                          REPEAT(if (bicolour)
228                                                  if (bicolour)                                                 {
229                                                  {                                                 line[x] = colour2;
230                                                          line[x] = colour2;                                                 bicolour = False;}
231                                                          bicolour = False;                                                 else
232                                                  }                                                 {
233                                                  else                                                 line[x] = colour1;
234                                                  {                                                 bicolour = True; count++;}
235                                                          line[x] = colour1;                                          );
                                                         bicolour = True;  
                                                         count++;  
                                                 }  
                                         )  
236                                          break;                                          break;
237    
238                                  case 13: /* White */                                  case 0xd:       /* White */
239                                          REPEAT(line[x] = 0xff)                                          REPEAT(line[x] = 0xff);
240                                          break;                                          break;
241    
242                                  case 14: /* Black */                                  case 0xe:       /* Black */
243                                          REPEAT(line[x] = 0x00)                                          REPEAT(line[x] = 0x00);
244                                          break;                                          break;
245    
246                                  default:                                  default:
247                                          NOTIMP("bitmap opcode 0x%x\n", opcode);                                          unimpl("bitmap opcode 0x%x\n",
248                                                   opcode);
249                                          return False;                                          return False;
250                          }                          }
251                  }                  }

Legend:
Removed from v.19  
changed lines
  Added in v.30

  ViewVC Help
Powered by ViewVC 1.1.26