/[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 25 - (hide annotations)
Sat Jan 6 03:47:04 2001 UTC (23 years, 5 months ago) by matty
File MIME type: text/plain
File size: 4542 byte(s)
Changed indentation style (-psl).

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 25 BOOL
30     bitmap_decompress(unsigned char *output, int width, int height,
31     unsigned char *input, int size)
32 matty 3 {
33     unsigned char *end = input + size;
34 matty 10 unsigned char *prevline = NULL, *line = NULL;
35 matty 7 int opcode, count, offset, isfillormix, x = width;
36 matty 19 int lastopcode = -1, insertmix = False, bicolour = False;
37 matty 10 uint8 code, colour1 = 0, colour2 = 0;
38     uint8 mixmask, mask = 0, mix = 0xff;
39 matty 3
40     while (input < end)
41     {
42 matty 7 code = CVAL(input);
43     opcode = code >> 4;
44    
45     /* Handle different opcode forms */
46     switch (opcode)
47 matty 3 {
48 matty 7 case 0xc:
49     case 0xd:
50     case 0xe:
51     opcode -= 6;
52     count = code & 0xf;
53     offset = 16;
54     break;
55 matty 3
56 matty 7 case 0xf:
57     opcode = code & 0xf;
58     count = (opcode < 13) ? SVAL(input) : 1;
59     offset = 0;
60     break;
61    
62     default:
63     opcode >>= 1;
64     count = code & 0x1f;
65     offset = 32;
66     break;
67     }
68    
69     /* Handle strange cases for counts */
70     if (offset != 0)
71     {
72     isfillormix = ((opcode == 2) || (opcode == 7));
73    
74     if (count == 0)
75 matty 3 {
76 matty 7 if (isfillormix)
77     count = CVAL(input) + 1;
78     else
79     count = CVAL(input) + offset;
80 matty 3 }
81 matty 7 else if (isfillormix)
82     {
83     count <<= 3;
84     }
85     }
86 matty 3
87 matty 7 /* Read preliminary data */
88 matty 9 mixmask = 0;
89 matty 7 switch (opcode)
90     {
91 matty 24 case 0: /* Fill */
92 matty 18 if ((lastopcode == opcode)
93     && !((x == width) && (prevline == NULL)))
94 matty 9 insertmix = True;
95 matty 3 break;
96 matty 24 case 8: /* Bicolour */
97 matty 9 colour1 = CVAL(input);
98 matty 24 case 3: /* Colour */
99 matty 9 colour2 = CVAL(input);
100     break;
101 matty 24 case 6: /* SetMix/Mix */
102     case 7: /* SetMix/FillOrMix */
103 matty 7 mix = CVAL(input);
104     opcode -= 5;
105 matty 3 break;
106 matty 7 }
107 matty 9 lastopcode = opcode;
108 matty 3
109 matty 7 /* Output body */
110     while (count > 0)
111     {
112     if (x >= width)
113     {
114     if (height <= 0)
115 matty 9 return False;
116 matty 7
117     x = 0;
118     height--;
119    
120     prevline = line;
121     line = output + height * width;
122     }
123    
124     switch (opcode)
125     {
126 matty 24 case 0: /* Fill */
127 matty 9 if (insertmix)
128     {
129     if (prevline == NULL)
130     line[x] = mix;
131     else
132 matty 24 line[x] =
133     prevline[x] ^
134     mix;
135 matty 9
136     insertmix = False;
137     count--;
138     x++;
139     }
140    
141 matty 7 if (prevline == NULL)
142 matty 24 {
143     REPEAT(line[x] = 0);
144     }
145 matty 7 else
146 matty 24 {
147     REPEAT(line[x] = prevline[x]);
148     }
149 matty 3 break;
150 matty 7
151 matty 24 case 1: /* Mix */
152 matty 7 if (prevline == NULL)
153 matty 24 {
154     REPEAT(line[x] = mix);
155     }
156 matty 7 else
157 matty 24 {
158     REPEAT(line[x] =
159     prevline[x] ^ mix);
160     }
161 matty 3 break;
162 matty 7
163 matty 24 case 2: /* Fill or Mix */
164 matty 7 if (prevline == NULL)
165 matty 24 {
166     REPEAT(MASK_UPDATE();
167     if (mask & mixmask)
168     line[x] = mix;
169     else
170     line[x] = 0;);
171     }
172 matty 7 else
173 matty 24 {
174     REPEAT(MASK_UPDATE();
175     if (mask & mixmask)
176     line[x] =
177     prevline[x] ^ mix;
178     else
179     line[x] =
180     prevline[x];);
181     }
182 matty 7 break;
183 matty 3
184 matty 24 case 3: /* Colour */
185     REPEAT(line[x] = colour2);
186 matty 7 break;
187 matty 3
188 matty 24 case 4: /* Copy */
189     REPEAT(line[x] = CVAL(input));
190 matty 7 break;
191 matty 3
192 matty 24 case 8: /* Bicolour */
193     REPEAT(if (bicolour)
194     {
195     line[x] = colour2;
196     bicolour = False;}
197     else
198     {
199     line[x] = colour1;
200     bicolour = True; count++;}
201     );
202 matty 7 break;
203 matty 3
204 matty 24 case 13: /* White */
205     REPEAT(line[x] = 0xff);
206 matty 7 break;
207 matty 3
208 matty 24 case 14: /* Black */
209     REPEAT(line[x] = 0x00);
210 matty 7 break;
211 matty 3
212 matty 7 default:
213 matty 24 NOTIMP("bitmap opcode 0x%x\n",
214     opcode);
215 matty 7 return False;
216     }
217     }
218 matty 3 }
219    
220 matty 7 return True;
221 matty 3 }

  ViewVC Help
Powered by ViewVC 1.1.26