/[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 7 - (hide annotations)
Fri Jul 7 09:40:03 2000 UTC (23 years, 11 months ago) by matty
File MIME type: text/plain
File size: 4137 byte(s)
Miscellaneous updates: implemented some more protocol features including
colour maps. Started on a new bitmap decompression engine which is not
completely working yet - however I am going back on the road so I am
committing now.

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     #include "includes.h"
22    
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     #define MASK_UPDATE() { maskpix <<= 1; if (maskpix == 0) { mask = CVAL(input); maskpix = 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 7 unsigned char *prevline, *line = NULL;
34     int opcode, count, offset, isfillormix, x = width;
35     uint8 code, mask, maskpix, color1, color2;
36     uint8 mix = 0xff;
37 matty 3
38 matty 7 dump_data(input, end-input);
39 matty 3 while (input < end)
40     {
41 matty 7 fprintf(stderr, "Offset %d from end\n", end-input);
42     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     maskpix = 0;
89     switch (opcode)
90     {
91     case 3: /* Color */
92     color1 = CVAL(input);
93     case 8: /* Bicolor */
94     color2 = CVAL(input);
95 matty 3 break;
96 matty 7 case 6: /* SetMix/Mix */
97     case 7: /* SetMix/FillOrMix */
98     mix = CVAL(input);
99     opcode -= 5;
100 matty 3 break;
101 matty 7 }
102 matty 3
103 matty 7 /* Output body */
104     while (count > 0)
105     {
106     if (x >= width)
107     {
108     if (height <= 0)
109     return True;
110    
111     x = 0;
112     height--;
113    
114     prevline = line;
115     line = output + height * width;
116     }
117    
118     switch (opcode)
119     {
120     case 0: /* Fill */
121     fprintf(stderr, "Fill %d\n", count);
122     if (prevline == NULL)
123     REPEAT(line[x] = 0)
124     else
125     REPEAT(line[x] = prevline[x])
126 matty 3 break;
127 matty 7
128     case 1: /* Mix */
129     fprintf(stderr, "Mix %d\n", count);
130     if (prevline == NULL)
131     REPEAT(line[x] = mix)
132     else
133     REPEAT(line[x] = prevline[x] ^ mix)
134 matty 3 break;
135 matty 7
136     #if 0
137     case 2: /* Fill or Mix */
138     REPEAT(line[x] = 0);
139 matty 3 break;
140 matty 7 if (prevline == NULL)
141     REPEAT(
142     MASK_UPDATE();
143 matty 3
144 matty 7 if (mask & maskpix)
145     line[x] = mix;
146     else
147     line[x] = 0;
148     )
149     else
150     REPEAT(
151     MASK_UPDATE();
152 matty 3
153 matty 7 if (mask & maskpix)
154     line[x] = prevline[x] ^ mix;
155     else
156     line[x] = prevline[x];
157     )
158     break;
159     #endif
160 matty 3
161 matty 7 case 3: /* Colour */
162     fprintf(stderr, "Colour %d\n", count);
163     REPEAT(line[x] = color2)
164     break;
165 matty 3
166 matty 7 case 4: /* Copy */
167     fprintf(stderr, "Copy %d\n", count);
168     REPEAT(line[x] = CVAL(input))
169     break;
170 matty 3
171 matty 7 #if 0
172     case 8: /* Bicolor */
173     REPEAT(line[x] = color1; line[++x] = color2)
174     break;
175 matty 3
176 matty 7 case 13: /* White */
177     REPEAT(line[x] = 0xff)
178     break;
179 matty 3
180 matty 7 case 14: /* Black */
181     REPEAT(line[x] = 0x00)
182     break;
183     #endif
184 matty 3
185 matty 7 default:
186     fprintf(stderr, "Unknown bitmap opcode 0x%x\n", opcode);
187     return False;
188     }
189     }
190 matty 3 }
191    
192 matty 7 return True;
193 matty 3 }

  ViewVC Help
Powered by ViewVC 1.1.26