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) |
32 |
unsigned char *end = input + size; |
unsigned char *end = input + size; |
33 |
unsigned char *prevline, *line = NULL; |
unsigned char *prevline, *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; |
36 |
|
uint8 code, colour1, colour2, mask, mixmask; |
37 |
uint8 mix = 0xff; |
uint8 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 |
|
|
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) && (x != width)) |
92 |
case 8: /* Bicolor */ |
insertmix = True; |
93 |
color2 = CVAL(input); |
break; |
94 |
|
case 8: /* Bicolour */ |
95 |
|
colour1 = CVAL(input); |
96 |
|
case 3: /* Colour */ |
97 |
|
colour2 = CVAL(input); |
98 |
break; |
break; |
99 |
case 6: /* SetMix/Mix */ |
case 6: /* SetMix/Mix */ |
100 |
case 7: /* SetMix/FillOrMix */ |
case 7: /* SetMix/FillOrMix */ |
102 |
opcode -= 5; |
opcode -= 5; |
103 |
break; |
break; |
104 |
} |
} |
105 |
|
lastopcode = opcode; |
106 |
|
|
107 |
/* Output body */ |
/* Output body */ |
108 |
while (count > 0) |
while (count > 0) |
110 |
if (x >= width) |
if (x >= width) |
111 |
{ |
{ |
112 |
if (height <= 0) |
if (height <= 0) |
113 |
return True; |
return False; |
114 |
|
|
115 |
x = 0; |
x = 0; |
116 |
height--; |
height--; |
122 |
switch (opcode) |
switch (opcode) |
123 |
{ |
{ |
124 |
case 0: /* Fill */ |
case 0: /* Fill */ |
125 |
fprintf(stderr, "Fill %d\n", count); |
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 |
if (prevline == NULL) |
if (prevline == NULL) |
138 |
REPEAT(line[x] = 0) |
REPEAT(line[x] = 0) |
139 |
else |
else |
141 |
break; |
break; |
142 |
|
|
143 |
case 1: /* Mix */ |
case 1: /* Mix */ |
|
fprintf(stderr, "Mix %d\n", count); |
|
144 |
if (prevline == NULL) |
if (prevline == NULL) |
145 |
REPEAT(line[x] = mix) |
REPEAT(line[x] = mix) |
146 |
else |
else |
147 |
REPEAT(line[x] = prevline[x] ^ mix) |
REPEAT(line[x] = prevline[x] ^ mix) |
148 |
break; |
break; |
149 |
|
|
|
#if 0 |
|
150 |
case 2: /* Fill or Mix */ |
case 2: /* Fill or Mix */ |
|
REPEAT(line[x] = 0); |
|
|
break; |
|
151 |
if (prevline == NULL) |
if (prevline == NULL) |
152 |
REPEAT( |
REPEAT( |
153 |
MASK_UPDATE(); |
MASK_UPDATE(); |
154 |
|
|
155 |
if (mask & maskpix) |
if (mask & mixmask) |
156 |
line[x] = mix; |
line[x] = mix; |
157 |
else |
else |
158 |
line[x] = 0; |
line[x] = 0; |
161 |
REPEAT( |
REPEAT( |
162 |
MASK_UPDATE(); |
MASK_UPDATE(); |
163 |
|
|
164 |
if (mask & maskpix) |
if (mask & mixmask) |
165 |
line[x] = prevline[x] ^ mix; |
line[x] = prevline[x] ^ mix; |
166 |
else |
else |
167 |
line[x] = prevline[x]; |
line[x] = prevline[x]; |
168 |
) |
) |
169 |
break; |
break; |
|
#endif |
|
170 |
|
|
171 |
case 3: /* Colour */ |
case 3: /* Colour */ |
172 |
fprintf(stderr, "Colour %d\n", count); |
REPEAT(line[x] = colour2) |
|
REPEAT(line[x] = color2) |
|
173 |
break; |
break; |
174 |
|
|
175 |
case 4: /* Copy */ |
case 4: /* Copy */ |
|
fprintf(stderr, "Copy %d\n", count); |
|
176 |
REPEAT(line[x] = CVAL(input)) |
REPEAT(line[x] = CVAL(input)) |
177 |
break; |
break; |
178 |
|
|
179 |
#if 0 |
case 8: /* Bicolour */ |
180 |
case 8: /* Bicolor */ |
REPEAT(line[x] = colour1; line[++x] = colour2) |
|
REPEAT(line[x] = color1; line[++x] = color2) |
|
181 |
break; |
break; |
182 |
|
|
183 |
case 13: /* White */ |
case 13: /* White */ |
187 |
case 14: /* Black */ |
case 14: /* Black */ |
188 |
REPEAT(line[x] = 0x00) |
REPEAT(line[x] = 0x00) |
189 |
break; |
break; |
|
#endif |
|
190 |
|
|
191 |
default: |
default: |
192 |
fprintf(stderr, "Unknown bitmap opcode 0x%x\n", opcode); |
NOTIMP("bitmap opcode 0x%x\n", opcode); |
193 |
return False; |
return False; |
194 |
} |
} |
195 |
} |
} |