--- sourceforge.net/trunk/rdesktop/bitmap.c 2002/07/30 07:18:48 82 +++ sourceforge.net/trunk/rdesktop/bitmap.c 2003/03/27 13:08:57 345 @@ -1,18 +1,18 @@ -/* +/* -*- c-basic-offset: 8 -*- rdesktop: A Remote Desktop Protocol client. Bitmap decompression routines - Copyright (C) Matthew Chapman 1999-2001 - + 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 the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. @@ -22,6 +22,31 @@ #define CVAL(p) (*(p++)) +static uint32 +cvalx(unsigned char **input, int Bpp) +{ + uint32 rv = 0; + memcpy(&rv, *input, Bpp); + *input += Bpp; + return rv; +} + +static void +setli(unsigned char *input, int offset, uint32 value, int Bpp) +{ + input += offset * Bpp; + memcpy(input, &value, Bpp); +} + +static uint32 +getli(unsigned char *input, int offset, int Bpp) +{ + uint32 rv = 0; + input += offset * Bpp; + memcpy(&rv, input, Bpp); + return rv; +} + #define UNROLL8(exp) { exp exp exp exp exp exp exp exp } #define REPEAT(statement) \ @@ -43,14 +68,17 @@ } BOOL -bitmap_decompress(unsigned char *output, int width, int height, unsigned char *input, int size) +bitmap_decompress(unsigned char *output, int width, int height, unsigned char *input, int size, + int Bpp) { unsigned char *end = input + size; unsigned char *prevline = NULL, *line = NULL; int opcode, count, offset, isfillormix, x = width; int lastopcode = -1, insertmix = False, bicolour = False; - uint8 code, colour1 = 0, colour2 = 0; - uint8 mixmask, mask = 0, mix = 0xff; + uint8 code; + uint32 colour1 = 0, colour2 = 0; + uint8 mixmask, mask = 0; + uint32 mix = 0xffffffff; int fom_mask = 0; while (input < end) @@ -117,13 +145,13 @@ insertmix = True; break; case 8: /* Bicolour */ - colour1 = CVAL(input); + colour1 = cvalx(&input, Bpp); case 3: /* Colour */ - colour2 = CVAL(input); + colour2 = cvalx(&input, Bpp); break; case 6: /* SetMix/Mix */ case 7: /* SetMix/FillOrMix */ - mix = CVAL(input); + mix = cvalx(&input, Bpp); opcode -= 5; break; case 9: /* FillOrMix_1 */ @@ -154,7 +182,7 @@ height--; prevline = line; - line = output + height * width; + line = output + height * width * Bpp; } switch (opcode) @@ -163,9 +191,10 @@ if (insertmix) { if (prevline == NULL) - line[x] = mix; + setli(line, x, mix, Bpp); else - line[x] = prevline[x] ^ mix; + setli(line, x, + getli(prevline, x, Bpp) ^ mix, Bpp); insertmix = False; count--; @@ -174,22 +203,24 @@ if (prevline == NULL) { - REPEAT(line[x] = 0); - } + REPEAT(setli(line, x, 0, Bpp))} else { - REPEAT(line[x] = prevline[x]); + REPEAT(setli + (line, x, getli(prevline, x, Bpp), Bpp)); } break; case 1: /* Mix */ if (prevline == NULL) { - REPEAT(line[x] = mix); + REPEAT(setli(line, x, mix, Bpp)); } else { - REPEAT(line[x] = prevline[x] ^ mix); + REPEAT(setli + (line, x, getli(prevline, x, Bpp) ^ mix, + Bpp)); } break; @@ -197,44 +228,47 @@ if (prevline == NULL) { REPEAT(MASK_UPDATE(); - if (mask & mixmask) line[x] = mix; + if (mask & mixmask) setli(line, x, mix, Bpp); else - line[x] = 0;); + setli(line, x, 0, Bpp);); } else { REPEAT(MASK_UPDATE(); if (mask & mixmask) - line[x] = prevline[x] ^ mix; + setli(line, x, getli(prevline, x, Bpp) ^ mix, + Bpp); else - line[x] = prevline[x];); + setli(line, x, getli(prevline, x, Bpp), + Bpp);); } break; case 3: /* Colour */ - REPEAT(line[x] = colour2); + REPEAT(setli(line, x, colour2, Bpp)); break; case 4: /* Copy */ - REPEAT(line[x] = CVAL(input)); + REPEAT(setli(line, x, cvalx(&input, Bpp), Bpp)); break; case 8: /* Bicolour */ REPEAT(if (bicolour) { - line[x] = colour2; bicolour = False;} + setli(line, x, colour2, Bpp); bicolour = False;} else { - line[x] = colour1; bicolour = True; count++;} + setli(line, x, colour1, Bpp); bicolour = True; + count++;} ); break; case 0xd: /* White */ - REPEAT(line[x] = 0xff); + REPEAT(setli(line, x, 0xffffffff, Bpp)); break; case 0xe: /* Black */ - REPEAT(line[x] = 0x00); + REPEAT(setli(line, x, 0, Bpp)); break; default: