summaryrefslogtreecommitdiffstats
path: root/xrdp/xrdp_bitmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'xrdp/xrdp_bitmap.c')
-rw-r--r--xrdp/xrdp_bitmap.c244
1 files changed, 152 insertions, 92 deletions
diff --git a/xrdp/xrdp_bitmap.c b/xrdp/xrdp_bitmap.c
index 46fb6401..49750221 100644
--- a/xrdp/xrdp_bitmap.c
+++ b/xrdp/xrdp_bitmap.c
@@ -23,9 +23,22 @@
#include "xrdp.h"
#include "log.h"
-
-static int g_crc_seed = 0xffffffff;
-static int g_crc_table[256] =
+#include "crc16.h"
+
+#define LLOG_LEVEL 1
+#define LLOGLN(_level, _args) \
+ do \
+ { \
+ if (_level < LLOG_LEVEL) \
+ { \
+ g_write("xrdp:xrdp_bitmap [%10.10u]: ", g_time3()); \
+ g_writeln _args ; \
+ } \
+ } \
+ while (0)
+
+
+static const int g_crc_table[256] =
{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@@ -72,10 +85,10 @@ static int g_crc_table[256] =
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
-#define CRC_START(in_crc) (in_crc) = g_crc_seed
+#define CRC_START(in_crc) (in_crc) = 0xFFFFFFFF
#define CRC_PASS(in_pixel, in_crc) \
(in_crc) = g_crc_table[((in_crc) ^ (in_pixel)) & 0xff] ^ ((in_crc) >> 8)
-#define CRC_END(in_crc) (in_crc) = ((in_crc) ^ g_crc_seed)
+#define CRC_END(in_crc) (in_crc) = ((in_crc) ^ 0xFFFFFFFF)
/*****************************************************************************/
struct xrdp_bitmap *APP_CC
@@ -716,11 +729,17 @@ xrdp_bitmap_copy_box(struct xrdp_bitmap *self,
struct xrdp_bitmap *dest,
int x, int y, int cx, int cy)
{
- int i = 0;
- int j = 0;
- int destx = 0;
- int desty = 0;
- int pixel = 0;
+ int i;
+ int destx;
+ int desty;
+ int incs;
+ int incd;
+ tui8 *s8;
+ tui8 *d8;
+ tui16 *s16;
+ tui16 *d16;
+ tui32 *s32;
+ tui32 *d32;
if (self == 0)
{
@@ -762,35 +781,54 @@ xrdp_bitmap_copy_box(struct xrdp_bitmap *self,
if (self->bpp == 24)
{
+ s32 = ((tui32 *)(self->data)) + (self->width * y + x);
+ d32 = ((tui32 *)(dest->data)) + (dest->width * desty + destx);
+ incs = self->width - cx;
+ incd = dest->width - cx;
+
for (i = 0; i < cy; i++)
{
- for (j = 0; j < cx; j++)
- {
- pixel = GETPIXEL32(self->data, j + x, i + y, self->width);
- SETPIXEL32(dest->data, j + destx, i + desty, dest->width, pixel);
- }
+ g_memcpy(d32, s32, cx * 4);
+ s32 += cx;
+ d32 += cx;
+
+ s32 += incs;
+ d32 += incd;
}
+
}
else if (self->bpp == 15 || self->bpp == 16)
{
+ s16 = ((tui16 *)(self->data)) + (self->width * y + x);
+ d16 = ((tui16 *)(dest->data)) + (dest->width * desty + destx);
+ incs = self->width - cx;
+ incd = dest->width - cx;
+
for (i = 0; i < cy; i++)
{
- for (j = 0; j < cx; j++)
- {
- pixel = GETPIXEL16(self->data, j + x, i + y, self->width);
- SETPIXEL16(dest->data, j + destx, i + desty, dest->width, pixel);
- }
+ g_memcpy(d16, s16, cx * 2);
+ s16 += cx;
+ d16 += cx;
+
+ s16 += incs;
+ d16 += incd;
}
}
else if (self->bpp == 8)
{
+ s8 = ((tui8 *)(self->data)) + (self->width * y + x);
+ d8 = ((tui8 *)(dest->data)) + (dest->width * desty + destx);
+ incs = self->width - cx;
+ incd = dest->width - cx;
+
for (i = 0; i < cy; i++)
{
- for (j = 0; j < cx; j++)
- {
- pixel = GETPIXEL8(self->data, j + x, i + y, self->width);
- SETPIXEL8(dest->data, j + destx, i + desty, dest->width, pixel);
- }
+ g_memcpy(d8, s8, cx);
+ s8 += cx;
+ d8 += cx;
+
+ s8 += incs;
+ d8 += incd;
}
}
else
@@ -802,6 +840,51 @@ xrdp_bitmap_copy_box(struct xrdp_bitmap *self,
}
/*****************************************************************************/
+int APP_CC
+xrdp_bitmap_hash_crc(struct xrdp_bitmap *self)
+{
+ void *hash;
+ int bytes;
+ int crc;
+ int index;
+ char hash_data[16];
+
+ if (self->bpp == 24)
+ {
+ bytes = self->width * self->height * 4;
+ }
+ else if (self->bpp == 15 || self->bpp == 16)
+ {
+ bytes = self->width * self->height * 2;
+ }
+ else if (self->bpp == 8)
+ {
+ bytes = self->width * self->height;
+ }
+ else
+ {
+ return 1;
+ }
+ hash = ssl_md5_info_create();
+ ssl_md5_transform(hash, self->data, bytes);
+ ssl_md5_complete(hash, hash_data);
+ ssl_md5_info_delete(hash);
+ CRC_START(crc);
+ CRC_PASS(self->width, crc);
+ CRC_PASS(self->width >> 8, crc);
+ CRC_PASS(self->height, crc);
+ CRC_PASS(self->height >> 8, crc);
+ for (index = 0; index < 16; index++)
+ {
+ CRC_PASS(hash_data[index], crc);
+ }
+ CRC_END(crc);
+ self->crc32 = crc;
+ self->crc16 = self->crc32 & 0xffff;
+ return 0;
+}
+
+/*****************************************************************************/
/* copy part of self at x, y to 0, 0 in dest */
/* returns error */
int APP_CC
@@ -809,20 +892,20 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
struct xrdp_bitmap *dest,
int x, int y, int cx, int cy)
{
- int i = 0;
- int j = 0;
- int destx = 0;
- int desty = 0;
- int pixel = 0;
- int crc = 0;
- int incs = 0;
- int incd = 0;
- unsigned char *s8 = (unsigned char *)NULL;
- unsigned char *d8 = (unsigned char *)NULL;
- unsigned short *s16 = (unsigned short *)NULL;
- unsigned short *d16 = (unsigned short *)NULL;
- unsigned int *s32;
- unsigned int *d32;
+ int i;
+ int j;
+ int destx;
+ int desty;
+ int pixel;
+ int crc;
+ int incs;
+ int incd;
+ tui8 *s8;
+ tui8 *d8;
+ tui16 *s16;
+ tui16 *d16;
+ tui32 *s32;
+ tui32 *d32;
if (self == 0)
{
@@ -864,47 +947,54 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
CRC_START(crc);
+ CRC_PASS(self->width, crc);
+ CRC_PASS(self->width >> 8, crc);
+
+ CRC_PASS(self->height, crc);
+ CRC_PASS(self->height >> 8, crc);
+
if (self->bpp == 24)
{
- s32 = ((unsigned int *)(self->data)) + (self->width * y + x);
- d32 = ((unsigned int *)(dest->data)) + (dest->width * desty + destx);
+ s32 = ((tui32 *)(self->data)) + (self->width * y + x);
+ d32 = ((tui32 *)(dest->data)) + (dest->width * desty + destx);
incs = self->width - cx;
incd = dest->width - cx;
for (i = 0; i < cy; i++)
{
j = 0;
+
while (j < cx - 4)
{
pixel = *s32;
+ *d32 = pixel;
CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc);
- *d32 = pixel;
s32++;
d32++;
pixel = *s32;
+ *d32 = pixel;
CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc);
- *d32 = pixel;
s32++;
d32++;
pixel = *s32;
+ *d32 = pixel;
CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc);
- *d32 = pixel;
s32++;
d32++;
pixel = *s32;
+ *d32 = pixel;
CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc);
- *d32 = pixel;
s32++;
d32++;
@@ -913,10 +1003,10 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
while (j < cx)
{
pixel = *s32;
+ *d32 = pixel;
CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc);
- *d32 = pixel;
s32++;
d32++;
@@ -929,8 +1019,8 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
}
else if (self->bpp == 15 || self->bpp == 16)
{
- s16 = ((unsigned short *)(self->data)) + (self->width * y + x);
- d16 = ((unsigned short *)(dest->data)) + (dest->width * desty + destx);
+ s16 = ((tui16 *)(self->data)) + (self->width * y + x);
+ d16 = ((tui16 *)(dest->data)) + (dest->width * desty + destx);
incs = self->width - cx;
incd = dest->width - cx;
@@ -939,9 +1029,9 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
for (j = 0; j < cx; j++)
{
pixel = *s16;
+ *d16 = pixel;
CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc);
- *d16 = pixel;
s16++;
d16++;
}
@@ -952,8 +1042,8 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
}
else if (self->bpp == 8)
{
- s8 = ((unsigned char *)(self->data)) + (self->width * y + x);
- d8 = ((unsigned char *)(dest->data)) + (dest->width * desty + destx);
+ s8 = ((tui8 *)(self->data)) + (self->width * y + x);
+ d8 = ((tui8 *)(dest->data)) + (dest->width * desty + destx);
incs = self->width - cx;
incd = dest->width - cx;
@@ -962,8 +1052,8 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
for (j = 0; j < cx; j++)
{
pixel = *s8;
- CRC_PASS(pixel, crc);
*d8 = pixel;
+ CRC_PASS(pixel, crc);
s8++;
d8++;
}
@@ -978,7 +1068,14 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
}
CRC_END(crc);
- dest->crc = crc;
+ dest->crc32 = crc;
+ dest->crc16 = dest->crc32 & 0xffff;
+
+ LLOGLN(10, ("xrdp_bitmap_copy_box_with_crc: crc16 0x%4.4x",
+ dest->crc16));
+ LLOGLN(10, ("xrdp_bitmap_copy_box_with_crc: width %d height %d",
+ dest->width, dest->height));
+
return 0;
}
@@ -988,45 +1085,8 @@ int APP_CC
xrdp_bitmap_compare(struct xrdp_bitmap *self,
struct xrdp_bitmap *b)
{
- if (self == 0)
- {
- return 0;
- }
-
- if (b == 0)
- {
- return 0;
- }
+ LLOGLN(10, ("xrdp_bitmap_compare:"));
- if (self->bpp != b->bpp)
- {
- return 0;
- }
-
- if (self->width != b->width)
- {
- return 0;
- }
-
- if (self->height != b->height)
- {
- return 0;
- }
-
- if (g_memcmp(self->data, b->data, b->height * b->line_size) == 0)
- {
- return 1;
- }
-
- return 0;
-}
-
-/*****************************************************************************/
-/* returns true if they are the same, else returns false */
-int APP_CC
-xrdp_bitmap_compare_with_crc(struct xrdp_bitmap *self,
- struct xrdp_bitmap *b)
-{
if (self == 0)
{
return 0;
@@ -1052,7 +1112,7 @@ xrdp_bitmap_compare_with_crc(struct xrdp_bitmap *self,
return 0;
}
- if (self->crc == b->crc)
+ if (g_memcmp(self->data, b->data, b->height * b->line_size) == 0)
{
return 1;
}