--- sourceforge.net/trunk/rdesktop/bitmap.c 2001/01/06 03:12:10 24 +++ sourceforge.net/trunk/rdesktop/bitmap.c 2002/09/26 14:26:46 207 @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. Bitmap decompression routines - Copyright (C) Matthew Chapman 1999-2000 + Copyright (C) Matthew Chapman 1999-2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,13 +21,29 @@ #include "rdesktop.h" #define CVAL(p) (*(p++)) -#define SVAL(p) ((*((p++) + 1) << 8) | CVAL(p)) -#define REPEAT(statement) { while ((count > 0) && (x < width)) { statement; count--; x++; } } -#define MASK_UPDATE() { mixmask <<= 1; if (mixmask == 0) { mask = CVAL(input); mixmask = 1; } } +#define UNROLL8(exp) { exp exp exp exp exp exp exp exp } -BOOL bitmap_decompress(unsigned char *output, int width, int height, - unsigned char *input, int size) +#define REPEAT(statement) \ +{ \ + while((count & ~0x7) && ((x+8) < width)) \ + UNROLL8( statement; count--; x++; ); \ + \ + while((count > 0) && (x < width)) { statement; count--; x++; } \ +} + +#define MASK_UPDATE() \ +{ \ + mixmask <<= 1; \ + if (mixmask == 0) \ + { \ + mask = fom_mask ? fom_mask : CVAL(input); \ + mixmask = 1; \ + } \ +} + +BOOL +bitmap_decompress(unsigned char *output, int width, int height, unsigned char *input, int size) { unsigned char *end = input + size; unsigned char *prevline = NULL, *line = NULL; @@ -35,9 +51,11 @@ int lastopcode = -1, insertmix = False, bicolour = False; uint8 code, colour1 = 0, colour2 = 0; uint8 mixmask, mask = 0, mix = 0xff; + int fom_mask = 0; while (input < end) { + fom_mask = 0; code = CVAL(input); opcode = code >> 4; @@ -54,7 +72,15 @@ case 0xf: opcode = code & 0xf; - count = (opcode < 13) ? SVAL(input) : 1; + if (opcode < 9) + { + count = CVAL(input); + count |= CVAL(input) << 8; + } + else + { + count = (opcode < 0xb) ? 8 : 1; + } offset = 0; break; @@ -84,12 +110,10 @@ } /* Read preliminary data */ - mixmask = 0; switch (opcode) { case 0: /* Fill */ - if ((lastopcode == opcode) - && !((x == width) && (prevline == NULL))) + if ((lastopcode == opcode) && !((x == width) && (prevline == NULL))) insertmix = True; break; case 8: /* Bicolour */ @@ -102,8 +126,21 @@ mix = CVAL(input); opcode -= 5; break; + case 9: /* FillOrMix_1 */ + mask = 0x03; + opcode = 0x02; + fom_mask = 3; + break; + case 0x0a: /* FillOrMix_2 */ + mask = 0x05; + opcode = 0x02; + fom_mask = 5; + break; + } + lastopcode = opcode; + mixmask = 0; /* Output body */ while (count > 0) @@ -128,9 +165,7 @@ if (prevline == NULL) line[x] = mix; else - line[x] = - prevline[x] ^ - mix; + line[x] = prevline[x] ^ mix; insertmix = False; count--; @@ -154,8 +189,7 @@ } else { - REPEAT(line[x] = - prevline[x] ^ mix); + REPEAT(line[x] = prevline[x] ^ mix); } break; @@ -163,8 +197,7 @@ if (prevline == NULL) { REPEAT(MASK_UPDATE(); - if (mask & mixmask) - line[x] = mix; + if (mask & mixmask) line[x] = mix; else line[x] = 0;); } @@ -172,11 +205,9 @@ { REPEAT(MASK_UPDATE(); if (mask & mixmask) - line[x] = - prevline[x] ^ mix; + line[x] = prevline[x] ^ mix; else - line[x] = - prevline[x];); + line[x] = prevline[x];); } break; @@ -191,26 +222,23 @@ case 8: /* Bicolour */ REPEAT(if (bicolour) { - line[x] = colour2; - bicolour = False;} + line[x] = colour2; bicolour = False;} else { - line[x] = colour1; - bicolour = True; count++;} + line[x] = colour1; bicolour = True; count++;} ); break; - case 13: /* White */ + case 0xd: /* White */ REPEAT(line[x] = 0xff); break; - case 14: /* Black */ + case 0xe: /* Black */ REPEAT(line[x] = 0x00); break; default: - NOTIMP("bitmap opcode 0x%x\n", - opcode); + unimpl("bitmap opcode 0x%x\n", opcode); return False; } }