diff --git a/uirdesktop/bitmap.c b/uirdesktop/bitmap.c deleted file mode 100644 index 1dc384e7..00000000 --- a/uirdesktop/bitmap.c +++ /dev/null @@ -1,1253 +0,0 @@ -/* -*- c-basic-offset: 8 -*- - rdesktop: A Remote Desktop Protocol client. - Bitmap decompression routines - Copyright (C) Matthew Chapman 1999-2005 - - 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. -*/ - -/* three seperate function for speed when decompressing the bitmaps */ -/* when modifing one function make the change in the others */ -/* comment out #define BITMAP_SPEED_OVER_SIZE below for one slower function */ -/* j@american-data.com */ - -/* indent is confused by this file */ -/* *INDENT-OFF* */ - -#include "rdesktop.h" -#include "uimain.h" - -#define CVAL(p) (*(p++)) -#ifdef NEED_ALIGN -#ifdef L_ENDIAN -#define CVAL2(p, v) { v = (*(p++)); v |= (*(p++)) << 8; } -#else -#define CVAL2(p, v) { v = (*(p++)) << 8; v |= (*(p++)); } -#endif /* L_ENDIAN */ -#else -#define CVAL2(p, v) { v = (*((uint16*)p)); p += 2; } -#endif /* NEED_ALIGN */ - -#define UNROLL8(exp) { exp exp exp exp exp exp exp exp } - -#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; \ - } \ -} - -/* 1 byte bitmap decompress */ -static BOOL -bitmap_decompress1(uint8 * output, int width, int height, uint8 * input, int size) -{ - uint8 *end = input + size; - uint8 *prevline = NULL, *line = NULL; - int opcode, count, offset, isfillormix, x = width; - int lastopcode = -1, insertmix = False, bicolour = False; - uint8 code; - uint8 colour1 = 0, colour2 = 0; - uint8 mixmask, mask = 0; - uint8 mix = 0xff; - int fom_mask; - - while (input < end) - { - fom_mask = 0; - code = CVAL(input); - opcode = code >> 4; - /* Handle different opcode forms */ - switch (opcode) - { - case 0xc: - case 0xd: - case 0xe: - opcode -= 6; - count = code & 0xf; - offset = 16; - break; - case 0xf: - opcode = code & 0xf; - if (opcode < 9) - { - count = CVAL(input); - count |= CVAL(input) << 8; - } - else - { - count = (opcode < 0xb) ? 8 : 1; - } - offset = 0; - break; - default: - opcode >>= 1; - count = code & 0x1f; - offset = 32; - break; - } - /* Handle strange cases for counts */ - if (offset != 0) - { - isfillormix = ((opcode == 2) || (opcode == 7)); - if (count == 0) - { - if (isfillormix) - count = CVAL(input) + 1; - else - count = CVAL(input) + offset; - } - else if (isfillormix) - { - count <<= 3; - } - } - /* Read preliminary data */ - switch (opcode) - { - case 0: /* Fill */ - if ((lastopcode == opcode) && !((x == width) && (prevline == NULL))) - insertmix = True; - break; - case 8: /* Bicolour */ - colour1 = CVAL(input); - case 3: /* Colour */ - colour2 = CVAL(input); - break; - case 6: /* SetMix/Mix */ - case 7: /* SetMix/FillOrMix */ - 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) - { - if (x >= width) - { - if (height <= 0) - return False; - x = 0; - height--; - prevline = line; - line = output + height * width; - } - switch (opcode) - { - case 0: /* Fill */ - if (insertmix) - { - if (prevline == NULL) - line[x] = mix; - else - line[x] = prevline[x] ^ mix; - insertmix = False; - count--; - x++; - } - if (prevline == NULL) - { - REPEAT(line[x] = 0) - } - else - { - REPEAT(line[x] = prevline[x]) - } - break; - case 1: /* Mix */ - if (prevline == NULL) - { - REPEAT(line[x] = mix) - } - else - { - REPEAT(line[x] = prevline[x] ^ mix) - } - break; - case 2: /* Fill or Mix */ - if (prevline == NULL) - { - REPEAT - ( - MASK_UPDATE(); - if (mask & mixmask) - line[x] = mix; - else - line[x] = 0; - ) - } - else - { - REPEAT - ( - MASK_UPDATE(); - if (mask & mixmask) - line[x] = prevline[x] ^ mix; - else - line[x] = prevline[x]; - ) - } - break; - case 3: /* Colour */ - REPEAT(line[x] = colour2) - break; - case 4: /* Copy */ - REPEAT(line[x] = CVAL(input)) - break; - case 8: /* Bicolour */ - REPEAT - ( - if (bicolour) - { - line[x] = colour2; - bicolour = False; - } - else - { - line[x] = colour1; - bicolour = True; count++; - } - ) - break; - case 0xd: /* White */ - REPEAT(line[x] = 0xff) - break; - case 0xe: /* Black */ - REPEAT(line[x] = 0) - break; - default: - unimpl("bitmap opcode 0x%x\n", opcode); - return False; - } - } - } - return True; -} - -/* 2 byte bitmap decompress */ -static BOOL -bitmap_decompress2(uint8 * output, int width, int height, uint8 * input, int size) -{ - uint8 *end = input + size; - uint16 *prevline = NULL, *line = NULL; - int opcode, count, offset, isfillormix, x = width; - int lastopcode = -1, insertmix = False, bicolour = False; - uint8 code; - uint16 colour1 = 0, colour2 = 0; - uint8 mixmask, mask = 0; - uint16 mix = 0xffff; - int fom_mask; - - while (input < end) - { - fom_mask = 0; - code = CVAL(input); - opcode = code >> 4; - /* Handle different opcode forms */ - switch (opcode) - { - case 0xc: - case 0xd: - case 0xe: - opcode -= 6; - count = code & 0xf; - offset = 16; - break; - case 0xf: - opcode = code & 0xf; - if (opcode < 9) - { - count = CVAL(input); - count |= CVAL(input) << 8; - } - else - { - count = (opcode < 0xb) ? 8 : 1; - } - offset = 0; - break; - default: - opcode >>= 1; - count = code & 0x1f; - offset = 32; - break; - } - /* Handle strange cases for counts */ - if (offset != 0) - { - isfillormix = ((opcode == 2) || (opcode == 7)); - if (count == 0) - { - if (isfillormix) - count = CVAL(input) + 1; - else - count = CVAL(input) + offset; - } - else if (isfillormix) - { - count <<= 3; - } - } - /* Read preliminary data */ - switch (opcode) - { - case 0: /* Fill */ - if ((lastopcode == opcode) && !((x == width) && (prevline == NULL))) - insertmix = True; - break; - case 8: /* Bicolour */ - CVAL2(input, colour1); - case 3: /* Colour */ - CVAL2(input, colour2); - break; - case 6: /* SetMix/Mix */ - case 7: /* SetMix/FillOrMix */ - CVAL2(input, mix); - 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) - { - if (x >= width) - { - if (height <= 0) - return False; - x = 0; - height--; - prevline = line; - line = ((uint16 *) output) + height * width; - } - switch (opcode) - { - case 0: /* Fill */ - if (insertmix) - { - if (prevline == NULL) - line[x] = mix; - else - line[x] = prevline[x] ^ mix; - insertmix = False; - count--; - x++; - } - if (prevline == NULL) - { - REPEAT(line[x] = 0) - } - else - { - REPEAT(line[x] = prevline[x]) - } - break; - case 1: /* Mix */ - if (prevline == NULL) - { - REPEAT(line[x] = mix) - } - else - { - REPEAT(line[x] = prevline[x] ^ mix) - } - break; - case 2: /* Fill or Mix */ - if (prevline == NULL) - { - REPEAT - ( - MASK_UPDATE(); - if (mask & mixmask) - line[x] = mix; - else - line[x] = 0; - ) - } - else - { - REPEAT - ( - MASK_UPDATE(); - if (mask & mixmask) - line[x] = prevline[x] ^ mix; - else - line[x] = prevline[x]; - ) - } - break; - case 3: /* Colour */ - REPEAT(line[x] = colour2) - break; - case 4: /* Copy */ - REPEAT(CVAL2(input, line[x])) - break; - case 8: /* Bicolour */ - REPEAT - ( - if (bicolour) - { - line[x] = colour2; - bicolour = False; - } - else - { - line[x] = colour1; - bicolour = True; - count++; - } - ) - break; - case 0xd: /* White */ - REPEAT(line[x] = 0xffff) - break; - case 0xe: /* Black */ - REPEAT(line[x] = 0) - break; - default: - unimpl("bitmap opcode 0x%x\n", opcode); - return False; - } - } - } - return True; -} - -/* 3 byte bitmap decompress */ -static BOOL -bitmap_decompress3(uint8 * output, int width, int height, uint8 * input, int size) -{ - uint8 *end = input + size; - uint8 *prevline = NULL, *line = NULL; - int opcode, count, offset, isfillormix, x = width; - int lastopcode = -1, insertmix = False, bicolour = False; - uint8 code; - uint8 colour1[3] = {0, 0, 0}, colour2[3] = {0, 0, 0}; - uint8 mixmask, mask = 0; - uint8 mix[3] = {0xff, 0xff, 0xff}; - int fom_mask; - - while (input < end) - { - fom_mask = 0; - code = CVAL(input); - opcode = code >> 4; - /* Handle different opcode forms */ - switch (opcode) - { - case 0xc: - case 0xd: - case 0xe: - opcode -= 6; - count = code & 0xf; - offset = 16; - break; - case 0xf: - opcode = code & 0xf; - if (opcode < 9) - { - count = CVAL(input); - count |= CVAL(input) << 8; - } - else - { - count = (opcode < - 0xb) ? 8 : 1; - } - offset = 0; - break; - default: - opcode >>= 1; - count = code & 0x1f; - offset = 32; - break; - } - /* Handle strange cases for counts */ - if (offset != 0) - { - isfillormix = ((opcode == 2) || (opcode == 7)); - if (count == 0) - { - if (isfillormix) - count = CVAL(input) + 1; - else - count = CVAL(input) + offset; - } - else if (isfillormix) - { - count <<= 3; - } - } - /* Read preliminary data */ - switch (opcode) - { - case 0: /* Fill */ - if ((lastopcode == opcode) && !((x == width) && (prevline == NULL))) - insertmix = True; - break; - case 8: /* Bicolour */ - colour1[0] = CVAL(input); - colour1[1] = CVAL(input); - colour1[2] = CVAL(input); - case 3: /* Colour */ - colour2[0] = CVAL(input); - colour2[1] = CVAL(input); - colour2[2] = CVAL(input); - break; - case 6: /* SetMix/Mix */ - case 7: /* SetMix/FillOrMix */ - mix[0] = CVAL(input); - mix[1] = CVAL(input); - mix[2] = 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) - { - if (x >= width) - { - if (height <= 0) - return False; - x = 0; - height--; - prevline = line; - line = output + height * (width * 3); - } - switch (opcode) - { - case 0: /* Fill */ - if (insertmix) - { - if (prevline == NULL) - { - line[x * 3] = mix[0]; - line[x * 3 + 1] = mix[1]; - line[x * 3 + 2] = mix[2]; - } - else - { - line[x * 3] = - prevline[x * 3] ^ mix[0]; - line[x * 3 + 1] = - prevline[x * 3 + 1] ^ mix[1]; - line[x * 3 + 2] = - prevline[x * 3 + 2] ^ mix[2]; - } - insertmix = False; - count--; - x++; - } - if (prevline == NULL) - { - REPEAT - ( - line[x * 3] = 0; - line[x * 3 + 1] = 0; - line[x * 3 + 2] = 0; - ) - } - else - { - REPEAT - ( - line[x * 3] = prevline[x * 3]; - line[x * 3 + 1] = prevline[x * 3 + 1]; - line[x * 3 + 2] = prevline[x * 3 + 2]; - ) - } - break; - case 1: /* Mix */ - if (prevline == NULL) - { - REPEAT - ( - line[x * 3] = mix[0]; - line[x * 3 + 1] = mix[1]; - line[x * 3 + 2] = mix[2]; - ) - } - else - { - REPEAT - ( - line[x * 3] = - prevline[x * 3] ^ mix[0]; - line[x * 3 + 1] = - prevline[x * 3 + 1] ^ mix[1]; - line[x * 3 + 2] = - prevline[x * 3 + 2] ^ mix[2]; - ) - } - break; - case 2: /* Fill or Mix */ - if (prevline == NULL) - { - REPEAT - ( - MASK_UPDATE(); - if (mask & mixmask) - { - line[x * 3] = mix[0]; - line[x * 3 + 1] = mix[1]; - line[x * 3 + 2] = mix[2]; - } - else - { - line[x * 3] = 0; - line[x * 3 + 1] = 0; - line[x * 3 + 2] = 0; - } - ) - } - else - { - REPEAT - ( - MASK_UPDATE(); - if (mask & mixmask) - { - line[x * 3] = - prevline[x * 3] ^ mix [0]; - line[x * 3 + 1] = - prevline[x * 3 + 1] ^ mix [1]; - line[x * 3 + 2] = - prevline[x * 3 + 2] ^ mix [2]; - } - else - { - line[x * 3] = - prevline[x * 3]; - line[x * 3 + 1] = - prevline[x * 3 + 1]; - line[x * 3 + 2] = - prevline[x * 3 + 2]; - } - ) - } - break; - case 3: /* Colour */ - REPEAT - ( - line[x * 3] = colour2 [0]; - line[x * 3 + 1] = colour2 [1]; - line[x * 3 + 2] = colour2 [2]; - ) - break; - case 4: /* Copy */ - REPEAT - ( - line[x * 3] = CVAL(input); - line[x * 3 + 1] = CVAL(input); - line[x * 3 + 2] = CVAL(input); - ) - break; - case 8: /* Bicolour */ - REPEAT - ( - if (bicolour) - { - line[x * 3] = colour2[0]; - line[x * 3 + 1] = colour2[1]; - line[x * 3 + 2] = colour2[2]; - bicolour = False; - } - else - { - line[x * 3] = colour1[0]; - line[x * 3 + 1] = colour1[1]; - line[x * 3 + 2] = colour1[2]; - bicolour = True; - count++; - } - ) - break; - case 0xd: /* White */ - REPEAT - ( - line[x * 3] = 0xff; - line[x * 3 + 1] = 0xff; - line[x * 3 + 2] = 0xff; - ) - break; - case 0xe: /* Black */ - REPEAT - ( - line[x * 3] = 0; - line[x * 3 + 1] = 0; - line[x * 3 + 2] = 0; - ) - break; - default: - unimpl("bitmap opcode 0x%x\n", opcode); - return False; - } - } - } - return True; -} - -/* main decompress function */ -BOOL -bitmap_decompress(uint8 * output, int width, int height, uint8 * input, int size, int Bpp) -{ - BOOL rv = False; - switch (Bpp) - { - case 1: - rv = bitmap_decompress1(output, width, height, input, size); - break; - case 2: - rv = bitmap_decompress2(output, width, height, input, size); - break; - case 3: - rv = bitmap_decompress3(output, width, height, input, size); - break; - } - return rv; -} - -/* 2 byte bitmap decompress */ -static BOOL -bitmap_decompress_ex_16_to_32(uint8 * output, int width, int height, uint8 * input, int size) -{ - uint8 * end = input + size; - int * prevline = NULL, * line = NULL; - int opcode, count, offset, isfillormix, x = width; - int lastopcode = -1, insertmix = False, bicolour = False; - uint8 code; - int colour1 = 0, colour2 = 0; - uint8 mixmask, mask = 0; - int mix = 0xffffff; - int fom_mask; - int p, r, g, b; - - while (input < end) - { - fom_mask = 0; - code = CVAL(input); - opcode = code >> 4; - /* Handle different opcode forms */ - switch (opcode) - { - case 0xc: - case 0xd: - case 0xe: - opcode -= 6; - count = code & 0xf; - offset = 16; - break; - case 0xf: - opcode = code & 0xf; - if (opcode < 9) - { - count = CVAL(input); - count |= CVAL(input) << 8; - } - else - { - count = (opcode < 0xb) ? 8 : 1; - } - offset = 0; - break; - default: - opcode >>= 1; - count = code & 0x1f; - offset = 32; - break; - } - /* Handle strange cases for counts */ - if (offset != 0) - { - isfillormix = ((opcode == 2) || (opcode == 7)); - if (count == 0) - { - if (isfillormix) - { - count = CVAL(input) + 1; - } - else - { - count = CVAL(input) + offset; - } - } - else if (isfillormix) - { - count <<= 3; - } - } - /* Read preliminary data */ - switch (opcode) - { - case 0: /* Fill */ - if ((lastopcode == opcode) && !((x == width) && (prevline == NULL))) - { - insertmix = True; - } - break; - case 8: /* Bicolour */ - CVAL2(input, p); - SPLIT_COLOUR16(p, r, g, b); - MAKE_COLOUR32(p, r, g, b); - colour1 = p; - case 3: /* Colour */ - CVAL2(input, p); - SPLIT_COLOUR16(p, r, g, b); - MAKE_COLOUR32(p, r, g, b); - colour2 = p; - break; - case 6: /* SetMix/Mix */ - case 7: /* SetMix/FillOrMix */ - CVAL2(input, p); - SPLIT_COLOUR16(p, r, g, b); - MAKE_COLOUR32(p, r, g, b); - mix = p; - 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) - { - if (x >= width) - { - if (height <= 0) - { - return False; - } - x = 0; - height--; - prevline = line; - line = ((int *) output) + height * width; - } - switch (opcode) - { - case 0: /* Fill */ - if (insertmix) - { - if (prevline == NULL) - { - line[x] = mix; - } - else - { - line[x] = prevline[x] ^ mix; - } - insertmix = False; - count--; - x++; - } - if (prevline == NULL) - { - REPEAT(line[x] = 0) - } - else - { - REPEAT(line[x] = prevline[x]) - } - break; - case 1: /* Mix */ - if (prevline == NULL) - { - REPEAT(line[x] = mix) - } - else - { - REPEAT(line[x] = prevline[x] ^ mix) - } - break; - case 2: /* Fill or Mix */ - if (prevline == NULL) - { - REPEAT - ( - MASK_UPDATE(); - if (mask & mixmask) - { - line[x] = mix; - } - else - { - line[x] = 0; - } - ) - } - else - { - REPEAT - ( - MASK_UPDATE(); - if (mask & mixmask) - { - line[x] = prevline[x] ^ mix; - } - else - { - line[x] = prevline[x]; - } - ) - } - break; - case 3: /* Colour */ - REPEAT(line[x] = colour2) - break; - case 4: /* Copy */ - REPEAT - ( - CVAL2(input, p); - SPLIT_COLOUR16(p, r, g, b); - MAKE_COLOUR32(p, r, g, b); - line[x] = p; - ) - break; - case 8: /* Bicolour */ - REPEAT - ( - if (bicolour) - { - line[x] = colour2; - bicolour = False; - } - else - { - line[x] = colour1; - bicolour = True; - count++; - } - ) - break; - case 0xd: /* White */ - REPEAT(line[x] = 0xffffff) - break; - case 0xe: /* Black */ - REPEAT(line[x] = 0) - break; - default: - unimpl("bitmap opcode 0x%x\n", opcode); - return False; - } - } - } - return True; -} - -/* 3 byte bitmap decompress */ -static BOOL -bitmap_decompress_ex_24_to_32(uint8 * output, int width, int height, uint8 * input, int size) -{ - uint8 * end = input + size; - int * prevline = NULL, * line = NULL; - int opcode, count, offset, isfillormix, x = width; - int lastopcode = -1, insertmix = False, bicolour = False; - uint8 code; - int colour1 = 0, colour2 = 0; - uint8 mixmask, mask = 0; - int mix = 0xffffff; - int fom_mask; - int p, r, g, b; - - while (input < end) - { - fom_mask = 0; - code = CVAL(input); - opcode = code >> 4; - /* Handle different opcode forms */ - switch (opcode) - { - case 0xc: - case 0xd: - case 0xe: - opcode -= 6; - count = code & 0xf; - offset = 16; - break; - case 0xf: - opcode = code & 0xf; - if (opcode < 9) - { - count = CVAL(input); - count |= CVAL(input) << 8; - } - else - { - count = (opcode < - 0xb) ? 8 : 1; - } - offset = 0; - break; - default: - opcode >>= 1; - count = code & 0x1f; - offset = 32; - break; - } - /* Handle strange cases for counts */ - if (offset != 0) - { - isfillormix = ((opcode == 2) || (opcode == 7)); - if (count == 0) - { - if (isfillormix) - count = CVAL(input) + 1; - else - count = CVAL(input) + offset; - } - else if (isfillormix) - { - count <<= 3; - } - } - /* Read preliminary data */ - switch (opcode) - { - case 0: /* Fill */ - if ((lastopcode == opcode) && !((x == width) && (prevline == NULL))) - insertmix = True; - break; - case 8: /* Bicolour */ - b = CVAL(input); - g = CVAL(input); - r = CVAL(input); - MAKE_COLOUR32(p, r, g, b); - colour1 = p; - case 3: /* Colour */ - b = CVAL(input); - g = CVAL(input); - r = CVAL(input); - MAKE_COLOUR32(p, r, g, b); - colour2 = p; - break; - case 6: /* SetMix/Mix */ - case 7: /* SetMix/FillOrMix */ - b = CVAL(input); - g = CVAL(input); - r = CVAL(input); - MAKE_COLOUR32(p, r, g, b); - mix = p; - 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) - { - if (x >= width) - { - if (height <= 0) - return False; - x = 0; - height--; - prevline = line; - line = ((int *) output) + height * width; - } - switch (opcode) - { - case 0: /* Fill */ - if (insertmix) - { - if (prevline == NULL) - { - line[x] = mix; - } - else - { - line[x] = prevline[x] ^ mix; - } - insertmix = False; - count--; - x++; - } - if (prevline == NULL) - { - REPEAT(line[x] = 0) - } - else - { - REPEAT(line[x] = prevline[x]) - } - break; - case 1: /* Mix */ - if (prevline == NULL) - { - REPEAT(line[x] = mix) - } - else - { - REPEAT(line[x] = prevline[x] ^ mix) - } - break; - case 2: /* Fill or Mix */ - if (prevline == NULL) - { - REPEAT - ( - MASK_UPDATE(); - if (mask & mixmask) - { - line[x] = mix; - } - else - { - line[x] = 0; - } - ) - } - else - { - REPEAT - ( - MASK_UPDATE(); - if (mask & mixmask) - { - line[x] = prevline[x] ^ mix; - } - else - { - line[x] = prevline[x]; - } - ) - } - break; - case 3: /* Colour */ - REPEAT(line[x] = colour2) - break; - case 4: /* Copy */ - REPEAT - ( - b = CVAL(input); - g = CVAL(input); - r = CVAL(input); - MAKE_COLOUR32(p, r, g, b); - line[x] = p; - ) - break; - case 8: /* Bicolour */ - REPEAT - ( - if (bicolour) - { - line[x] = colour2; - bicolour = False; - } - else - { - line[x] = colour1; - bicolour = True; - count++; - } - ) - break; - case 0xd: /* White */ - REPEAT(line[x] = 0xffffff); - break; - case 0xe: /* Black */ - REPEAT(line[x] = 0); - break; - default: - unimpl("bitmap opcode 0x%x\n", opcode); - return False; - } - } - } - return True; -} - -BOOL -bitmap_decompress_ex(uint8 * output, int width, int height, uint8 * input, int size, - int in_bpp, int out_bpp) -{ - if (in_bpp == 16 && out_bpp == 32) - { - return bitmap_decompress_ex_16_to_32(output, width, height, input, size); - } - else if (in_bpp == 24 && out_bpp == 32) - { - return bitmap_decompress_ex_24_to_32(output, width, height, input, size); - } - return False; -} - -/* *INDENT-ON* */ diff --git a/uirdesktop/bsops.c b/uirdesktop/bsops.c deleted file mode 100755 index 310c9211..00000000 --- a/uirdesktop/bsops.c +++ /dev/null @@ -1,833 +0,0 @@ -/* -*- c-basic-offset: 8 -*- - rdesktop: A Remote Desktop Protocol client. - Generics backingstore operations - Copyright (C) Jay Sorg 2005-2006 - - 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. -*/ - -#include -#include -#include "bsops.h" - -/* externals */ -extern int g_width; -extern int g_height; -extern int g_bs_bpp; -extern int g_bs_Bpp; -extern char * g_bs; - -/* globals */ -static int g_clip_left = 0; -static int g_clip_top = 0; -static int g_clip_right = 800; -static int g_clip_bottom = 600; - -/* for bs_patblt */ -static unsigned char g_hatch_patterns[] = -{ - 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, /* 0 - bsHorizontal */ - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, /* 1 - bsVertical */ - 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, /* 2 - bsFDiagonal */ - 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, /* 3 - bsBDiagonal */ - 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08, /* 4 - bsCross */ - 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 /* 5 - bsDiagCross */ -}; - - -/*****************************************************************************/ -/* do a raster op */ -int -bs_do_rop(int rop, int src, int dst) -{ - switch (rop) - { - case 0x0: return 0; - case 0x1: return ~(src | dst); - case 0x2: return (~src) & dst; - case 0x3: return ~src; - case 0x4: return src & (~dst); - case 0x5: return ~(dst); - case 0x6: return src ^ dst; - case 0x7: return ~(src & dst); - case 0x8: return src & dst; - case 0x9: return ~(src) ^ dst; - case 0xa: return dst; - case 0xb: return (~src) | dst; - case 0xc: return src; - case 0xd: return src | (~dst); - case 0xe: return src | dst; - case 0xf: return ~0; - } - return dst; -} - -/*****************************************************************************/ -/* get a pixel from the in memory copy of whats on the screen */ -int -bs_get_pixel(int x, int y) -{ - char * p; - - if (x >= 0 && x < g_width && y >= 0 && y < g_height) - { - p = g_bs + (y * g_width * g_bs_Bpp) + (x * g_bs_Bpp); - if (g_bs_Bpp == 1) - { - return *((unsigned char *) p); - } - else if (g_bs_Bpp == 2) - { - return *((unsigned short *) p); - } - else - { - return *((unsigned int *) p); - } - } - else - { - return 0; - } -} - -/*****************************************************************************/ -/* set a pixel on the screen using the clip */ -void -bs_set_pixel(int x, int y, int pixel, int rop, int use_clip) -{ - char * p; - - if (!use_clip || - (x >= g_clip_left && x < g_clip_right && - y >= g_clip_top && y < g_clip_bottom)) - { - if (x >= 0 && x < g_width && y >= 0 && y < g_height) - { - p = g_bs + (y * g_width * g_bs_Bpp) + (x * g_bs_Bpp); - if (rop != 12) - { - pixel = bs_do_rop(rop, pixel, bs_get_pixel(x, y)); - } - if (g_bs_Bpp == 1) - { - *((unsigned char *) p) = pixel; - } - else if (g_bs_Bpp == 2) - { - *((unsigned short *) p) = pixel; - } - else - { - *((unsigned int *) p) = pixel; - } - } - } -} - -/*****************************************************************************/ -static char * -get_bs_ptr(int x, int y) -{ - char * p; - - if (x >= 0 && x < g_width && y >= 0 && y < g_height) - { - p = g_bs + (y * g_width * g_bs_Bpp) + (x * g_bs_Bpp); - return p; - } - else - { - return 0; - } -} - -/*****************************************************************************/ -void -bs_init(void) -{ - g_clip_left = 0; - g_clip_top = 0; - g_clip_right = g_width; - g_clip_bottom = g_height; -} - -/*****************************************************************************/ -void -bs_exit(void) -{ -} - -/*****************************************************************************/ -void -bs_set_clip(int x, int y, int cx, int cy) -{ - g_clip_left = x; - g_clip_top = y; - g_clip_right = x + cx; - g_clip_bottom = y + cy; -} - -/*****************************************************************************/ -void -bs_reset_clip(void) -{ - g_clip_left = 0; - g_clip_top = 0; - g_clip_right = g_width; - g_clip_bottom = g_height; -} - -/*****************************************************************************/ -/* check if a certain pixel is set in a bitmap */ -int -bs_is_pixel_on(char * data, int x, int y, int width, int bpp) -{ - int start; - int shift; - - if (bpp == 1) - { - width = (width + 7) / 8; - start = (y * width) + x / 8; - shift = x % 8; - return (data[start] & (0x80 >> shift)) != 0; - } - else if (bpp == 8) - { - return data[y * width + x] != 0; - } - else if (bpp == 24) - { - return data[(y * 3) * width + (x * 3)] != 0 && - data[(y * 3) * width + (x * 3) + 1] != 0 && - data[(y * 3) * width + (x * 3) + 2] != 0; - } - else - { - return 0; - } -} - -/*****************************************************************************/ -void -bs_set_pixel_on(char * data, int x, int y, int width, int bpp, - int pixel) -{ - int start; - int shift; - - if (bpp == 1) - { - width = (width + 7) / 8; - start = (y * width) + x / 8; - shift = x % 8; - if (pixel != 0) - { - data[start] = data[start] | (0x80 >> shift); - } - else - { - data[start] = data[start] & ~(0x80 >> shift); - } - } - else if (bpp == 8) - { - data[y * width + x] = pixel; - } - else if (bpp == 15 || bpp == 16) - { - ((unsigned short *) data)[y * width + x] = pixel; - } -} - -/*****************************************************************************/ -void -bs_copy_mem(char * d, char * s, int n) -{ - while (n & (~7)) - { - *(d++) = *(s++); - *(d++) = *(s++); - *(d++) = *(s++); - *(d++) = *(s++); - *(d++) = *(s++); - *(d++) = *(s++); - *(d++) = *(s++); - *(d++) = *(s++); - n = n - 8; - } - while (n > 0) - { - *(d++) = *(s++); - n--; - } -} - -/*****************************************************************************/ -void -bs_copy_memb(char * d, char * s, int n) -{ - d = (d + n) - 1; - s = (s + n) - 1; - while (n & (~7)) - { - *(d--) = *(s--); - *(d--) = *(s--); - *(d--) = *(s--); - *(d--) = *(s--); - *(d--) = *(s--); - *(d--) = *(s--); - *(d--) = *(s--); - *(d--) = *(s--); - n = n - 8; - } - while (n > 0) - { - *(d--) = *(s--); - n--; - } -} - -/*****************************************************************************/ -/* return true is the is something to draw */ -int -bs_warp_coords(int * x, int * y, int * cx, int * cy, - int * srcx, int * srcy) -{ - int dx; - int dy; - - if (g_clip_left > *x) - { - dx = g_clip_left - *x; - } - else - { - dx = 0; - } - if (g_clip_top > *y) - { - dy = g_clip_top - *y; - } - else - { - dy = 0; - } - if (*x + *cx > g_clip_right) - { - *cx = (*cx - ((*x + *cx) - g_clip_right)); - } - if (*y + *cy > g_clip_bottom) - { - *cy = (*cy - ((*y + *cy) - g_clip_bottom)); - } - *cx = *cx - dx; - *cy = *cy - dy; - if (*cx <= 0) - { - return 0; - } - if (*cy <= 0) - { - return 0; - } - *x = *x + dx; - *y = *y + dy; - if (srcx != 0) - { - *srcx = *srcx + dx; - } - if (srcy != 0) - { - *srcy = *srcy + dy; - } - return 1; -} - -/*****************************************************************************/ -void -bs_rect(int x, int y, int cx, int cy, int colour, int rop) -{ - int i; - int j; - unsigned char * p8; - unsigned short * p16; - unsigned int * p32; - - if (bs_warp_coords(&x, &y, &cx, &cy, 0, 0)) - { - if (rop == 0) /* black */ - { - rop = 12; - colour = 0; - } - else if (rop == 15) /* white */ - { - rop = 12; - colour = 0xffffff; - } - if (rop == 12) /* copy */ - { - if (g_bs_Bpp == 1) - { - for (i = 0; i < cy; i++) - { - p8 = (unsigned char *) get_bs_ptr(x, y + i); - if (p8 != 0) - { - for (j = 0; j < cx; j++) - { - *p8 = colour; - p8++; - } - } - } - } - else if (g_bs_Bpp == 2) - { - for (i = 0; i < cy; i++) - { - p16 = (unsigned short *) get_bs_ptr(x, y + i); - if (p16 != 0) - { - for (j = 0; j < cx; j++) - { - *p16 = colour; - p16++; - } - } - } - } - else - { - for (i = 0; i < cy; i++) - { - p32 = (unsigned int *) get_bs_ptr(x, y + i); - if (p32 != 0) - { - for (j = 0; j < cx; j++) - { - *p32 = colour; - p32++; - } - } - } - } - } - else /* slow */ - { - for (i = 0; i < cy; i++) - { - for (j = 0; j < cx; j++) - { - bs_set_pixel(j + x, i + y, colour, rop, 0); - } - } - } - } -} - -/*****************************************************************************/ -void -bs_screenblt(int rop, int x, int y, int cx, int cy, - int srcx, int srcy) -{ - int p; - int i; - int j; - char * src; - char * dst; - - if (bs_warp_coords(&x, &y, &cx, &cy, &srcx, &srcy)) - { - if (rop == 12) /* copy */ - { - if (srcy < y) /* copy down - bottom to top */ - { - for (i = cy - 1; i >= 0; i--) - { - src = get_bs_ptr(srcx, srcy + i); - dst = get_bs_ptr(x, y + i); - if (src != 0 && dst != 0) - { - bs_copy_mem(dst, src, cx * g_bs_Bpp); - } - } - } - else if (srcy > y || srcx > x) /* copy up or left - top to bottom */ - { - for (i = 0; i < cy; i++) - { - src = get_bs_ptr(srcx, srcy + i); - dst = get_bs_ptr(x, y + i); - if (src != 0 && dst != 0) - { - bs_copy_mem(dst, src, cx * g_bs_Bpp); - } - } - } - else /* copy straight right */ - { - for (i = 0; i < cy; i++) - { - src = get_bs_ptr(srcx, srcy + i); - dst = get_bs_ptr(x, y + i); - if (src != 0 && dst != 0) - { - bs_copy_memb(dst, src, cx * g_bs_Bpp); - } - } - } - } - else /* slow */ - { - if (srcy < y) /* copy down - bottom to top */ - { - for (i = cy - 1; i >= 0; i--) - { - for (j = 0; j < cx; j++) - { - p = bs_get_pixel(srcx + j, srcy + i); - bs_set_pixel(x + j, y + i, p, rop, 0); - } - } - } - else if (srcy > y || srcx > x) /* copy up or left - top to bottom */ - { - for (i = 0; i < cy; i++) - { - for (j = 0; j < cx; j++) - { - p = bs_get_pixel(srcx + j, srcy + i); - bs_set_pixel(x + j, y + i, p, rop, 0); - } - } - } - else /* copy straight right */ - { - for (i = 0; i < cy; i++) - { - for (j = cx - 1; j >= 0; j--) - { - p = bs_get_pixel(srcx + j, srcy + i); - bs_set_pixel(x + j, y + i, p, rop, 0); - } - } - } - } - } -} - -/*****************************************************************************/ -int -bs_memblt(int opcode, int x, int y, int cx, int cy, - void * srcdata, int srcwidth, int srcheight, - int srcx, int srcy) -{ - int i; - int j; - int p; - int rv; - char * dst; - char * src; - - rv = 1; - if (bs_warp_coords(&x, &y, &cx, &cy, &srcx, &srcy)) - { - if (opcode == 12) /* copy */ - { - rv = 0; - if (g_bs_Bpp == 1) - { - src = (char *) (((unsigned char *) srcdata) + srcy * srcwidth + srcx); - } - else if (g_bs_Bpp == 2) - { - src = (char *) (((unsigned short *) srcdata) + srcy * srcwidth + srcx); - } - else - { - src = (char *) (((unsigned int *) srcdata) + srcy * srcwidth + srcx); - } - for (i = 0; i < cy; i++) - { - dst = get_bs_ptr(x, y + i); - if (dst != 0) - { - if (!rv) - { - if (memcmp(dst, src, cx * g_bs_Bpp) != 0) - { - rv = 1; - } - } - bs_copy_mem(dst, src, cx * g_bs_Bpp); - src += srcwidth * g_bs_Bpp; - } - } - } - else /* slow */ - { - if (g_bs_Bpp == 1) - { - for (i = 0; i < cy; i++) - { - for (j = 0; j < cx; j++) - { - p = *(((unsigned char *) srcdata) + - ((i + srcy) * srcwidth + (j + srcx))); - bs_set_pixel(x + j, y + i, p, opcode, 0); - } - } - } - else if (g_bs_Bpp == 2) - { - for (i = 0; i < cy; i++) - { - for (j = 0; j < cx; j++) - { - p = *(((unsigned short *) srcdata) + - ((i + srcy) * srcwidth + (j + srcx))); - bs_set_pixel(x + j, y + i, p, opcode, 0); - } - } - } - else - { - for (i = 0; i < cy; i++) - { - for (j = 0; j < cx; j++) - { - p = *(((unsigned int *) srcdata) + - ((i + srcy) * srcwidth + (j + srcx))); - bs_set_pixel(x + j, y + i, p, opcode, 0); - } - } - } - } - } - return rv; -} - -/*****************************************************************************/ -void -bs_draw_glyph(int x, int y, char * glyph_data, int glyph_width, - int glyph_height, int fgcolour) -{ - int i; - int j; - - for (i = 0; i < glyph_height; i++) - { - for (j = 0; j < glyph_width; j++) - { - if (bs_is_pixel_on(glyph_data, j, i, glyph_width, 8)) - { - bs_set_pixel(x + j, y + i, fgcolour, 12, 1); - } - } - } -} - -/*****************************************************************************/ -/* Bresenham's line drawing algorithm */ -void -bs_line(int opcode, int startx, int starty, int endx, int endy, - int pen_width, int pen_style, int pen_colour) -{ - int dx; - int dy; - int incx; - int incy; - int dpr; - int dpru; - int p; - - if (startx > endx) - { - dx = startx - endx; - incx = -1; - } - else - { - dx = endx - startx; - incx = 1; - } - if (starty > endy) - { - dy = starty - endy; - incy = -1; - } - else - { - dy = endy - starty; - incy = 1; - } - if (dx >= dy) - { - dpr = dy << 1; - dpru = dpr - (dx << 1); - p = dpr - dx; - for (; dx >= 0; dx--) - { - if (startx != endx || starty != endy) - { - bs_set_pixel(startx, starty, pen_colour, opcode, 1); - } - if (p > 0) - { - startx += incx; - starty += incy; - p += dpru; - } - else - { - startx += incx; - p += dpr; - } - } - } - else - { - dpr = dx << 1; - dpru = dpr - (dy << 1); - p = dpr - dy; - for (; dy >= 0; dy--) - { - if (startx != endx || starty != endy) - { - bs_set_pixel(startx, starty, pen_colour, opcode, 1); - } - if (p > 0) - { - startx += incx; - starty += incy; - p += dpru; - } - else - { - starty += incy; - p += dpr; - } - } - } -} - -/*****************************************************************************/ -void -bs_patblt(int opcode, int x, int y, int cx, int cy, - int brush_style, char * brush_pattern, - int brush_x_org, int brush_y_org, - int bgcolour, int fgcolour) -{ - int i; - int j; - char ipattern[8]; - char * b; - - b = 0; - switch (brush_style) - { - case 0: - bs_rect(x, y, cx, cy, fgcolour, opcode); - break; - case 2: /* Hatch */ - b = g_hatch_patterns + brush_pattern[0] * 8; - break; - case 3: - for (i = 0; i < 8; i++) - { - ipattern[i] = ~brush_pattern[7 - i]; - } - b = ipattern; - break; - } - if (b != 0) - { - for (i = 0; i < cy; i++) - { - for (j = 0; j < cx; j++) - { - if (bs_is_pixel_on(b, (x + j + brush_x_org) % 8, - (y + i + brush_y_org) % 8, 8, 1)) - { - bs_set_pixel(x + j, y + i, fgcolour, opcode, 1); - } - else - { - bs_set_pixel(x + j, y + i, bgcolour, opcode, 1); - } - } - } - } -} - -/*****************************************************************************/ -void -bs_copy_box(char * dst, int x, int y, int cx, int cy, int line_size) -{ - char * src; - int i; - - /* shouldn't happen */ - if (cx < 1 || cy < 1) - { - return; - } - /* nothing to draw, memset and leave */ - if (x + cx < 0 || y + cy < 0 || x >= g_width || y >= g_height) - { - memset(dst, 0, cx * cy * g_bs_Bpp); - return; - } - /* check if it goes over an edge */ - if (x < 0 || y < 0 || x + cx > g_width || y + cy > g_height) - { - memset(dst, 0, cx * cy * g_bs_Bpp); - if (x < 0) - { - cx += x; - dst += -x * g_bs_Bpp; - x = 0; - } - if (x + cx > g_width) - { - cx = g_width - x; - } - for (i = 0; i < cy; i++) - { - src = get_bs_ptr(x, y + i); - if (src != 0) - { - bs_copy_mem(dst, src, cx * g_bs_Bpp); - } - dst += line_size; - } - } - else /* whole box is within */ - { - for (i = 0; i < cy; i++) - { - src = get_bs_ptr(x, y + i); - if (src != 0) - { - bs_copy_mem(dst, src, cx * g_bs_Bpp); - } - dst += line_size; - } - } -} - diff --git a/uirdesktop/bsops.h b/uirdesktop/bsops.h deleted file mode 100755 index 8fdf5132..00000000 --- a/uirdesktop/bsops.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- c-basic-offset: 8 -*- - rdesktop: A Remote Desktop Protocol client. - Generics backingstore operations - Copyright (C) Jay Sorg 2005-2006 - - 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. -*/ - -int bs_get_pixel(int x, int y); -void bs_set_pixel(int x, int y, int pixel, int rop, int use_clip); -int bs_do_rop(int rop, int src, int dst); -void bs_init(void); -void bs_exit(void); -void bs_set_clip(int x, int y, int cx, int cy); -void bs_reset_clip(void); -void bs_set_pixel_on(char * data, int x, int y, int width, int bpp, - int pixel); -int bs_is_pixel_on(char * data, int x, int y, int width, int bpp); -void bs_copy_mem(char * d, char * s, int n); -void bs_copy_memb(char * d, char * s, int n); -int bs_warp_coords(int * x, int * y, int * cx, int * cy, - int * srcx, int * srcy); -void bs_rect(int x, int y, int cx, int cy, int colour, int rop); -void bs_screenblt(int opcode, int x, int y, int cx, int cy, - int srcx, int srcy); -int bs_memblt(int opcode, int x, int y, int cx, int cy, - void * srcdata, int srcwidth, int srcheight, - int srcx, int srcy); -void bs_copy_box(char * dst, int x, int y, int cx, int cy, int line_size); -void bs_draw_glyph(int x, int y, char * glyph_data, int glyph_width, - int glyph_height, int fgcolour); -void bs_line(int opcode, int startx, int starty, int endx, int endy, - int pen_width, int pen_style, int pen_colour); -void bs_patblt(int opcode, int x, int y, int cx, int cy, - int brush_style, char * brush_pattern, - int brush_x_org, int brush_y_org, - int bgcolour, int fgcolour); diff --git a/uirdesktop/cache.c b/uirdesktop/cache.c deleted file mode 100644 index 54636379..00000000 --- a/uirdesktop/cache.c +++ /dev/null @@ -1,432 +0,0 @@ -/* -*- c-basic-offset: 8 -*- - rdesktop: A Remote Desktop Protocol client. - Cache routines - Copyright (C) Matthew Chapman 1999-2005 - Copyright (C) Jeroen Meijer 2005 - - 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. -*/ - -#include "rdesktop.h" - -/* BITMAP CACHE */ -extern int g_pstcache_fd[]; - -#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0])) -#define IS_PERSISTENT(id) (g_pstcache_fd[id] > 0) -#define TO_TOP -1 -#define NOT_SET -1 -#define IS_SET(idx) (idx >= 0) - -/* - * TODO: Test for optimal value of BUMP_COUNT. TO_TOP gives lowest cpu utilisation but using - * a positive value will hopefully result in less frequently used bitmaps having a greater chance - * of being evicted from the cache, and therby reducing the need to load bitmaps from disk. - * (Jeroen) - */ -#define BUMP_COUNT 40 - -struct bmpcache_entry -{ - RD_HBITMAP bitmap; - sint16 previous; - sint16 next; -}; - -static struct bmpcache_entry g_bmpcache[3][0xa00]; -static RD_HBITMAP g_volatile_bc[3]; - -static int g_bmpcache_lru[3] = { NOT_SET, NOT_SET, NOT_SET }; -static int g_bmpcache_mru[3] = { NOT_SET, NOT_SET, NOT_SET }; -static int g_bmpcache_count[3]; - -/* Setup the bitmap cache lru/mru linked list */ -void -cache_rebuild_bmpcache_linked_list(uint8 id, sint16 * idx, int count) -{ - int n = count, c = 0; - sint16 n_idx; - - /* find top, skip evicted bitmaps */ - while (--n >= 0 && g_bmpcache[id][idx[n]].bitmap == NULL); - if (n < 0) - { - g_bmpcache_mru[id] = g_bmpcache_lru[id] = NOT_SET; - return; - } - - g_bmpcache_mru[id] = idx[n]; - g_bmpcache[id][idx[n]].next = NOT_SET; - n_idx = idx[n]; - c++; - - /* link list */ - while (n >= 0) - { - /* skip evicted bitmaps */ - while (--n >= 0 && g_bmpcache[id][idx[n]].bitmap == NULL); - - if (n < 0) - break; - - g_bmpcache[id][n_idx].previous = idx[n]; - g_bmpcache[id][idx[n]].next = n_idx; - n_idx = idx[n]; - c++; - } - - g_bmpcache[id][n_idx].previous = NOT_SET; - g_bmpcache_lru[id] = n_idx; - - if (c != g_bmpcache_count[id]) - { - error("Oops. %d in bitmap cache linked list, %d in ui cache...\n", c, - g_bmpcache_count[id]); - exit(1); - } -} - -/* Move a bitmap to a new position in the linked list. */ -void -cache_bump_bitmap(uint8 id, uint16 idx, int bump) -{ - int p_idx, n_idx, n; - - if (!IS_PERSISTENT(id)) - return; - - if (g_bmpcache_mru[id] == idx) - return; - - DEBUG_RDP5(("bump bitmap: id=%d, idx=%d, bump=%d\n", id, idx, bump)); - - n_idx = g_bmpcache[id][idx].next; - p_idx = g_bmpcache[id][idx].previous; - - if (IS_SET(n_idx)) - { - /* remove */ - --g_bmpcache_count[id]; - if (IS_SET(p_idx)) - g_bmpcache[id][p_idx].next = n_idx; - else - g_bmpcache_lru[id] = n_idx; - if (IS_SET(n_idx)) - g_bmpcache[id][n_idx].previous = p_idx; - else - g_bmpcache_mru[id] = p_idx; - } - else - { - p_idx = NOT_SET; - n_idx = g_bmpcache_lru[id]; - } - - if (bump >= 0) - { - for (n = 0; n < bump && IS_SET(n_idx); n++) - { - p_idx = n_idx; - n_idx = g_bmpcache[id][p_idx].next; - } - } - else - { - p_idx = g_bmpcache_mru[id]; - n_idx = NOT_SET; - } - - /* insert */ - ++g_bmpcache_count[id]; - g_bmpcache[id][idx].previous = p_idx; - g_bmpcache[id][idx].next = n_idx; - - if (p_idx >= 0) - g_bmpcache[id][p_idx].next = idx; - else - g_bmpcache_lru[id] = idx; - - if (n_idx >= 0) - g_bmpcache[id][n_idx].previous = idx; - else - g_bmpcache_mru[id] = idx; -} - -/* Evict the least-recently used bitmap from the cache */ -void -cache_evict_bitmap(uint8 id) -{ - uint16 idx; - int n_idx; - - if (!IS_PERSISTENT(id)) - return; - - idx = g_bmpcache_lru[id]; - n_idx = g_bmpcache[id][idx].next; - DEBUG_RDP5(("evict bitmap: id=%d idx=%d n_idx=%d bmp=0x%x\n", id, idx, n_idx, - g_bmpcache[id][idx].bitmap)); - - ui_destroy_bitmap(g_bmpcache[id][idx].bitmap); - --g_bmpcache_count[id]; - g_bmpcache[id][idx].bitmap = 0; - - g_bmpcache_lru[id] = n_idx; - g_bmpcache[id][n_idx].previous = NOT_SET; - - pstcache_touch_bitmap(id, idx, 0); -} - -/* Retrieve a bitmap from the cache */ -RD_HBITMAP -cache_get_bitmap(uint8 id, uint16 idx) -{ - if ((id < NUM_ELEMENTS(g_bmpcache)) && (idx < NUM_ELEMENTS(g_bmpcache[0]))) - { - if (g_bmpcache[id][idx].bitmap || pstcache_load_bitmap(id, idx)) - { - if (IS_PERSISTENT(id)) - cache_bump_bitmap(id, idx, BUMP_COUNT); - - return g_bmpcache[id][idx].bitmap; - } - } - else if ((id < NUM_ELEMENTS(g_volatile_bc)) && (idx == 0x7fff)) - { - return g_volatile_bc[id]; - } - - error("get bitmap %d:%d\n", id, idx); - return NULL; -} - -/* Store a bitmap in the cache */ -void -cache_put_bitmap(uint8 id, uint16 idx, RD_HBITMAP bitmap) -{ - RD_HBITMAP old; - - if ((id < NUM_ELEMENTS(g_bmpcache)) && (idx < NUM_ELEMENTS(g_bmpcache[0]))) - { - old = g_bmpcache[id][idx].bitmap; - if (old != NULL) - ui_destroy_bitmap(old); - g_bmpcache[id][idx].bitmap = bitmap; - - if (IS_PERSISTENT(id)) - { - if (old == NULL) - g_bmpcache[id][idx].previous = g_bmpcache[id][idx].next = NOT_SET; - - cache_bump_bitmap(id, idx, TO_TOP); - if (g_bmpcache_count[id] > BMPCACHE2_C2_CELLS) - cache_evict_bitmap(id); - } - } - else if ((id < NUM_ELEMENTS(g_volatile_bc)) && (idx == 0x7fff)) - { - old = g_volatile_bc[id]; - if (old != NULL) - ui_destroy_bitmap(old); - g_volatile_bc[id] = bitmap; - } - else - { - error("put bitmap %d:%d\n", id, idx); - } -} - -/* Updates the persistent bitmap cache MRU information on exit */ -void -cache_save_state(void) -{ - uint32 id = 0, t = 0; - int idx; - - for (id = 0; id < NUM_ELEMENTS(g_bmpcache); id++) - if (IS_PERSISTENT(id)) - { - DEBUG_RDP5(("Saving cache state for bitmap cache %d...", id)); - idx = g_bmpcache_lru[id]; - while (idx >= 0) - { - pstcache_touch_bitmap((uint8) id, (uint16) idx, ++t); - idx = g_bmpcache[id][idx].next; - } - DEBUG_RDP5((" %d stamps written.\n", t)); - } -} - - -/* FONT CACHE */ -static FONTGLYPH g_fontcache[12][256]; - -/* Retrieve a glyph from the font cache */ -FONTGLYPH * -cache_get_font(uint8 font, uint16 character) -{ - FONTGLYPH *glyph; - - if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0]))) - { - glyph = &g_fontcache[font][character]; - if (glyph->pixmap != NULL) - return glyph; - } - - error("get font %d:%d\n", font, character); - return NULL; -} - -/* Store a glyph in the font cache */ -void -cache_put_font(uint8 font, uint16 character, uint16 offset, - uint16 baseline, uint16 width, uint16 height, RD_HGLYPH pixmap) -{ - FONTGLYPH *glyph; - - if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0]))) - { - glyph = &g_fontcache[font][character]; - if (glyph->pixmap != NULL) - ui_destroy_glyph(glyph->pixmap); - - glyph->offset = offset; - glyph->baseline = baseline; - glyph->width = width; - glyph->height = height; - glyph->pixmap = pixmap; - } - else - { - error("put font %d:%d\n", font, character); - } -} - - -/* TEXT CACHE */ -static DATABLOB g_textcache[256]; - -/* Retrieve a text item from the cache */ -DATABLOB * -cache_get_text(uint8 cache_id) -{ - DATABLOB *text; - - text = &g_textcache[cache_id]; - return text; -} - -/* Store a text item in the cache */ -void -cache_put_text(uint8 cache_id, void *data, int length) -{ - DATABLOB *text; - - text = &g_textcache[cache_id]; - if (text->data != NULL) - xfree(text->data); - text->data = xmalloc(length); - text->size = length; - memcpy(text->data, data, length); -} - - -/* DESKTOP CACHE */ -static uint8 g_deskcache[0x38400 * 4]; - -/* Retrieve desktop data from the cache */ -uint8 * -cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel) -{ - int length = cx * cy * bytes_per_pixel; - - if (offset > sizeof(g_deskcache)) - offset = 0; - - if ((offset + length) <= sizeof(g_deskcache)) - { - return &g_deskcache[offset]; - } - - error("get desktop %d:%d\n", offset, length); - return NULL; -} - -/* Store desktop data in the cache */ -void -cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 * data) -{ - int length = cx * cy * bytes_per_pixel; - - if (offset > sizeof(g_deskcache)) - offset = 0; - - if ((offset + length) <= sizeof(g_deskcache)) - { - cx *= bytes_per_pixel; - while (cy--) - { - memcpy(&g_deskcache[offset], data, cx); - data += scanline; - offset += cx; - } - } - else - { - error("put desktop %d:%d\n", offset, length); - } -} - - -/* CURSOR CACHE */ -static RD_HCURSOR g_cursorcache[0x20]; - -/* Retrieve cursor from cache */ -RD_HCURSOR -cache_get_cursor(uint16 cache_idx) -{ - RD_HCURSOR cursor; - - if (cache_idx < NUM_ELEMENTS(g_cursorcache)) - { - cursor = g_cursorcache[cache_idx]; - if (cursor != NULL) - return cursor; - } - - error("get cursor %d\n", cache_idx); - return NULL; -} - -/* Store cursor in cache */ -void -cache_put_cursor(uint16 cache_idx, RD_HCURSOR cursor) -{ - RD_HCURSOR old; - - if (cache_idx < NUM_ELEMENTS(g_cursorcache)) - { - old = g_cursorcache[cache_idx]; - if (old != NULL) - ui_destroy_cursor(old); - - g_cursorcache[cache_idx] = cursor; - } - else - { - error("put cursor %d\n", cache_idx); - } -}