/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (hide annotations)
Tue Aug 15 10:23:24 2000 UTC (23 years, 9 months ago) by matty
File MIME type: text/plain
File size: 4185 byte(s)
Major commit of work from laptop - done in various free moments.
Implemented encryption layer and some basic licensing negotiation.
Reorganised code somewhat. While this is not quite as clean, it is
a lot faster - our parser speed was becoming a bottle-neck.

1 matty 3 /*
2     rdesktop: A Remote Desktop Protocol client.
3     Bitmap decompression routines
4     Copyright (C) Matthew Chapman 1999-2000
5    
6     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
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10    
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     */
20    
21 matty 10 #include "rdesktop.h"
22 matty 3
23 matty 7 #define CVAL(p) (*(p++))
24     #define SVAL(p) ((*((p++) + 1) << 8) | CVAL(p))
25 matty 3
26 matty 7 #define REPEAT(statement) { while ((count > 0) && (x < width)) { statement; count--; x++; } }
27 matty 9 #define MASK_UPDATE() { mixmask <<= 1; if (mixmask == 0) { mask = CVAL(input); mixmask = 1; } }
28 matty 3
29 matty 7 BOOL bitmap_decompress(unsigned char *output, int width, int height,
30     unsigned char *input, int size)
31 matty 3 {
32     unsigned char *end = input + size;
33 matty 10 unsigned char *prevline = NULL, *line = NULL;
34 matty 7 int opcode, count, offset, isfillormix, x = width;
35 matty 9 int lastopcode = -1, insertmix = False;
36 matty 10 uint8 code, colour1 = 0, colour2 = 0;
37     uint8 mixmask, mask = 0, mix = 0xff;
38 matty 3
39     while (input < end)
40     {
41 matty 7 code = CVAL(input);
42     opcode = code >> 4;
43    
44     /* Handle different opcode forms */
45     switch (opcode)
46 matty 3 {
47 matty 7 case 0xc:
48     case 0xd:
49     case 0xe:
50     opcode -= 6;
51     count = code & 0xf;
52     offset = 16;
53     break;
54 matty 3
55 matty 7 case 0xf:
56     opcode = code & 0xf;
57     count = (opcode < 13) ? SVAL(input) : 1;
58     offset = 0;
59     break;
60    
61     default:
62     opcode >>= 1;
63     count = code & 0x1f;
64     offset = 32;
65     break;
66     }
67    
68     /* Handle strange cases for counts */
69     if (offset != 0)
70     {
71     isfillormix = ((opcode == 2) || (opcode == 7));
72    
73     if (count == 0)
74 matty 3 {
75 matty 7 if (isfillormix)
76     count = CVAL(input) + 1;
77     else
78     count = CVAL(input) + offset;
79 matty 3 }
80 matty 7 else if (isfillormix)
81     {
82     count <<= 3;
83     }
84     }
85 matty 3
86 matty 7 /* Read preliminary data */
87 matty 9 mixmask = 0;
88 matty 7 switch (opcode)
89     {
90 matty 9 case 0: /* Fill */
91     if ((lastopcode == opcode) && (x != width))
92     insertmix = True;
93 matty 3 break;
94 matty 9 case 8: /* Bicolour */
95     colour1 = CVAL(input);
96     case 3: /* Colour */
97     colour2 = CVAL(input);
98     break;
99 matty 7 case 6: /* SetMix/Mix */
100     case 7: /* SetMix/FillOrMix */
101     mix = CVAL(input);
102     opcode -= 5;
103 matty 3 break;
104 matty 7 }
105 matty 9 lastopcode = opcode;
106 matty 3
107 matty 7 /* Output body */
108     while (count > 0)
109     {
110     if (x >= width)
111     {
112     if (height <= 0)
113 matty 9 return False;
114 matty 7
115     x = 0;
116     height--;
117    
118     prevline = line;
119     line = output + height * width;
120     }
121    
122     switch (opcode)
123     {
124     case 0: /* Fill */
125 matty 9 if (insertmix)
126     {
127     if (prevline == NULL)
128     line[x] = mix;
129     else
130     line[x] = prevline[x] ^ mix;
131    
132     insertmix = False;
133     count--;
134     x++;
135     }
136    
137 matty 7 if (prevline == NULL)
138     REPEAT(line[x] = 0)
139     else
140     REPEAT(line[x] = prevline[x])
141 matty 3 break;
142 matty 7
143     case 1: /* Mix */
144     if (prevline == NULL)
145     REPEAT(line[x] = mix)
146     else
147     REPEAT(line[x] = prevline[x] ^ mix)
148 matty 3 break;
149 matty 7
150     case 2: /* Fill or Mix */
151     if (prevline == NULL)
152     REPEAT(
153     MASK_UPDATE();
154 matty 3
155 matty 9 if (mask & mixmask)
156 matty 7 line[x] = mix;
157     else
158     line[x] = 0;
159     )
160     else
161     REPEAT(
162     MASK_UPDATE();
163 matty 3
164 matty 9 if (mask & mixmask)
165 matty 7 line[x] = prevline[x] ^ mix;
166     else
167     line[x] = prevline[x];
168     )
169     break;
170 matty 3
171 matty 7 case 3: /* Colour */
172 matty 9 REPEAT(line[x] = colour2)
173 matty 7 break;
174 matty 3
175 matty 7 case 4: /* Copy */
176     REPEAT(line[x] = CVAL(input))
177     break;
178 matty 3
179 matty 9 case 8: /* Bicolour */
180     REPEAT(line[x] = colour1; line[++x] = colour2)
181 matty 7 break;
182 matty 3
183 matty 7 case 13: /* White */
184     REPEAT(line[x] = 0xff)
185     break;
186 matty 3
187 matty 7 case 14: /* Black */
188     REPEAT(line[x] = 0x00)
189     break;
190 matty 3
191 matty 7 default:
192 matty 9 NOTIMP("bitmap opcode 0x%x\n", opcode);
193 matty 7 return False;
194     }
195     }
196 matty 3 }
197    
198 matty 7 return True;
199 matty 3 }

  ViewVC Help
Powered by ViewVC 1.1.26