/[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 7 by matty, Fri Jul 7 09:40:03 2000 UTC revision 24 by matty, Sat Jan 6 03:12:10 2001 UTC
# Line 18  Line 18 
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */  */
20    
21  #include "includes.h"  #include "rdesktop.h"
22    
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 REPEAT(statement) { while ((count > 0) && (x < width)) { statement; count--; x++; } }
27  #define MASK_UPDATE() { maskpix <<= 1; if (maskpix == 0) { mask = CVAL(input); maskpix = 1; } }  #define MASK_UPDATE() { mixmask <<= 1; if (mixmask == 0) { mask = CVAL(input); mixmask = 1; } }
28    
29  BOOL bitmap_decompress(unsigned char *output, int width, int height,  BOOL bitmap_decompress(unsigned char *output, int width, int height,
30                         unsigned char *input, int size)                         unsigned char *input, int size)
31  {  {
32          unsigned char *end = input + size;          unsigned char *end = input + size;
33          unsigned char *prevline, *line = NULL;          unsigned char *prevline = NULL, *line = NULL;
34          int opcode, count, offset, isfillormix, x = width;          int opcode, count, offset, isfillormix, x = width;
35          uint8 code, mask, maskpix, color1, color2;          int lastopcode = -1, insertmix = False, bicolour = False;
36          uint8 mix = 0xff;          uint8 code, colour1 = 0, colour2 = 0;
37            uint8 mixmask, mask = 0, mix = 0xff;
38    
         dump_data(input, end-input);  
39          while (input < end)          while (input < end)
40          {          {
                 fprintf(stderr, "Offset %d from end\n", end-input);  
41                  code = CVAL(input);                  code = CVAL(input);
42                  opcode = code >> 4;                  opcode = code >> 4;
43    
# Line 85  BOOL bitmap_decompress(unsigned char *ou Line 84  BOOL bitmap_decompress(unsigned char *ou
84                  }                  }
85    
86                  /* Read preliminary data */                  /* Read preliminary data */
87                  maskpix = 0;                  mixmask = 0;
88                  switch (opcode)                  switch (opcode)
89                  {                  {
90                          case 3: /* Color */                          case 0: /* Fill */
91                                  color1 = CVAL(input);                                  if ((lastopcode == opcode)
92                          case 8: /* Bicolor */                                      && !((x == width) && (prevline == NULL)))
93                                  color2 = CVAL(input);                                          insertmix = True;
94                                  break;                                  break;
95                          case 6: /* SetMix/Mix */                          case 8: /* Bicolour */
96                          case 7: /* SetMix/FillOrMix */                                  colour1 = CVAL(input);
97                            case 3: /* Colour */
98                                    colour2 = CVAL(input);
99                                    break;
100                            case 6: /* SetMix/Mix */
101                            case 7: /* SetMix/FillOrMix */
102                                  mix = CVAL(input);                                  mix = CVAL(input);
103                                  opcode -= 5;                                  opcode -= 5;
104                                  break;                                  break;
105                  }                  }
106                    lastopcode = opcode;
107    
108                  /* Output body */                  /* Output body */
109                  while (count > 0)                  while (count > 0)
# Line 106  BOOL bitmap_decompress(unsigned char *ou Line 111  BOOL bitmap_decompress(unsigned char *ou
111                          if (x >= width)                          if (x >= width)
112                          {                          {
113                                  if (height <= 0)                                  if (height <= 0)
114                                          return True;                                          return False;
115    
116                                  x = 0;                                  x = 0;
117                                  height--;                                  height--;
# Line 117  BOOL bitmap_decompress(unsigned char *ou Line 122  BOOL bitmap_decompress(unsigned char *ou
122    
123                          switch (opcode)                          switch (opcode)
124                          {                          {
125                                  case 0: /* Fill */                                  case 0: /* Fill */
126                                          fprintf(stderr, "Fill %d\n", count);                                          if (insertmix)
127                                            {
128                                                    if (prevline == NULL)
129                                                            line[x] = mix;
130                                                    else
131                                                            line[x] =
132                                                                    prevline[x] ^
133                                                                    mix;
134    
135                                                    insertmix = False;
136                                                    count--;
137                                                    x++;
138                                            }
139    
140                                          if (prevline == NULL)                                          if (prevline == NULL)
141                                                  REPEAT(line[x] = 0)                                          {
142                                                    REPEAT(line[x] = 0);
143                                            }
144                                          else                                          else
145                                                  REPEAT(line[x] = prevline[x])                                          {
146                                                    REPEAT(line[x] = prevline[x]);
147                                            }
148                                          break;                                          break;
149    
150                                  case 1: /* Mix */                                  case 1: /* Mix */
                                         fprintf(stderr, "Mix %d\n", count);  
151                                          if (prevline == NULL)                                          if (prevline == NULL)
152                                                  REPEAT(line[x] = mix)                                          {
153                                                    REPEAT(line[x] = mix);
154                                            }
155                                          else                                          else
156                                                  REPEAT(line[x] = prevline[x] ^ mix)                                          {
157                                                    REPEAT(line[x] =
158                                                           prevline[x] ^ mix);
159                                            }
160                                          break;                                          break;
161    
162  #if 0                                  case 2: /* Fill or Mix */
                                 case 2: /* Fill or Mix */  
                                         REPEAT(line[x] = 0);  
                                         break;  
163                                          if (prevline == NULL)                                          if (prevline == NULL)
164                                              REPEAT(                                          {
165                                                     MASK_UPDATE();                                                  REPEAT(MASK_UPDATE();
166                                                           if (mask & mixmask)
167                                                     if (mask & maskpix)                                                         line[x] = mix;
168                                                          line[x] = mix;                                                         else
169                                                     else                                                         line[x] = 0;);
170                                                          line[x] = 0;                                          }
                                             )  
171                                          else                                          else
172                                              REPEAT(                                          {
173                                                     MASK_UPDATE();                                                  REPEAT(MASK_UPDATE();
174                                                           if (mask & mixmask)
175                                                     if (mask & maskpix)                                                         line[x] =
176                                                          line[x] = prevline[x] ^ mix;                                                         prevline[x] ^ mix;
177                                                     else                                                         else
178                                                          line[x] = prevline[x];                                                         line[x] =
179                                              )                                                         prevline[x];);
180                                            }
181                                          break;                                          break;
 #endif  
182    
183                                  case 3: /* Colour */                                  case 3: /* Colour */
184                                          fprintf(stderr, "Colour %d\n", count);                                          REPEAT(line[x] = colour2);
                                         REPEAT(line[x] = color2)  
185                                          break;                                          break;
186    
187                                  case 4: /* Copy */                                  case 4: /* Copy */
188                                          fprintf(stderr, "Copy %d\n", count);                                          REPEAT(line[x] = CVAL(input));
                                         REPEAT(line[x] = CVAL(input))  
189                                          break;                                          break;
190    
191  #if 0                                  case 8: /* Bicolour */
192                                  case 8: /* Bicolor */                                          REPEAT(if (bicolour)
193                                          REPEAT(line[x] = color1; line[++x] = color2)                                                 {
194                                                   line[x] = colour2;
195                                                   bicolour = False;}
196                                                   else
197                                                   {
198                                                   line[x] = colour1;
199                                                   bicolour = True; count++;}
200                                            );
201                                          break;                                          break;
202    
203                                  case 13: /* White */                                  case 13:        /* White */
204                                          REPEAT(line[x] = 0xff)                                          REPEAT(line[x] = 0xff);
205                                          break;                                          break;
206    
207                                  case 14: /* Black */                                  case 14:        /* Black */
208                                          REPEAT(line[x] = 0x00)                                          REPEAT(line[x] = 0x00);
209                                          break;                                          break;
 #endif  
210    
211                                  default:                                  default:
212                                          fprintf(stderr, "Unknown bitmap opcode 0x%x\n", opcode);                                          NOTIMP("bitmap opcode 0x%x\n",
213                                                   opcode);
214                                          return False;                                          return False;
215                          }                          }
216                  }                  }

Legend:
Removed from v.7  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC 1.1.26