libfreerdp-core: fix decompression of color brushes

This commit is contained in:
Marc-André Moreau 2011-12-30 14:23:47 -05:00
parent 2d34a62ce8
commit e95dcc4c5e
5 changed files with 42 additions and 26 deletions

View File

@ -494,7 +494,7 @@ uint8* freerdp_image_convert_16bpp(uint8* srcData, uint8* dstData, int width, in
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 2);
if(clrconv->rgb555)
if (clrconv->rgb555)
{
int i;
uint8 red, green, blue;
@ -527,8 +527,9 @@ uint8* freerdp_image_convert_16bpp(uint8* srcData, uint8* dstData, int width, in
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 3);
dst8 = (uint8 *) dstData;
src16 = (uint16 *) srcData;
dst8 = (uint8*) dstData;
src16 = (uint16*) srcData;
for (i = width * height; i > 0; i--)
{
GetBGR16(red, green, blue, *src16);
@ -553,15 +554,16 @@ uint8* freerdp_image_convert_16bpp(uint8* srcData, uint8* dstData, int width, in
{
int i;
uint32 pixel;
uint16 *src16;
uint32 *dst32;
uint16* src16;
uint32* dst32;
uint8 red, green, blue;
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 4);
src16 = (uint16 *) srcData;
dst32 = (uint32 *) dstData;
src16 = (uint16*) srcData;
dst32 = (uint32*) dstData;
for (i = width * height; i > 0; i--)
{
pixel = *src16;
@ -882,23 +884,26 @@ uint8* freerdp_mono_image_convert(uint8* srcData, int width, int height, int src
greenFg = clrconv->palette->entries[fgcolor].green;
blueFg = clrconv->palette->entries[fgcolor].blue;
break;
case 16:
GetRGB16(redBg, greenBg, blueBg, bgcolor);
GetRGB16(redFg, greenFg, blueFg, fgcolor);
break;
case 15:
GetRGB15(redBg, greenBg, blueBg, bgcolor);
GetRGB15(redFg, greenFg, blueFg, fgcolor);
break;
default:
GetRGB32(redBg, greenBg, blueBg, bgcolor);
GetRGB32(redFg, greenFg, blueFg, fgcolor);
break;
}
if(dstBpp == 16)
if (dstBpp == 16)
{
if(clrconv->rgb555)
if (clrconv->rgb555)
{
if(srcBpp == 16)
{
@ -919,13 +924,14 @@ uint8* freerdp_mono_image_convert(uint8* srcData, int width, int height, int src
dstData = (uint8*) malloc(width * height * 2);
dst16 = (uint16*) dstData;
for(index = height; index > 0; index--)
{
/* each bit encodes a pixel */
bitMask = *srcData;
for(bitIndex = 7; bitIndex >= 0; bitIndex--)
for (bitIndex = 7; bitIndex >= 0; bitIndex--)
{
if((bitMask >> bitIndex) & 0x01)
if ((bitMask >> bitIndex) & 0x01)
{
*dst16 = bgcolor;
}
@ -939,15 +945,17 @@ uint8* freerdp_mono_image_convert(uint8* srcData, int width, int height, int src
}
return dstData;
}
else if(dstBpp == 32)
else if (dstBpp == 32)
{
dstData = (uint8*) malloc(width * height * 4);
dst32 = (uint32*) dstData;
for(index = height; index > 0; index--)
for (index = height; index > 0; index--)
{
/* each bit encodes a pixel */
bitMask = *srcData;
for(bitIndex = 7; bitIndex >= 0; bitIndex--)
for (bitIndex = 7; bitIndex >= 0; bitIndex--)
{
if((bitMask >> bitIndex) & 0x01)
{

View File

@ -1387,21 +1387,23 @@ void update_decompress_brush(STREAM* s, uint8* output, uint8 bpp)
int x, y, k;
uint8 byte = 0;
uint8* palette;
int bytesPerPixel;
palette = s->p + 16;
bytesPerPixel = ((bpp + 1) / 8);
for (y = 7; y >= 0; y--)
{
for (x = 0; x < 8; x++)
{
if (x % 4 == 0)
if ((x % 4) == 0)
stream_read_uint8(s, byte);
index = (byte >> ((3 - (x % 4)) * 2));
index = ((byte >> ((3 - (x % 4)) * 2)) & 0x03);
for (k = 0; k < bpp; k++)
for (k = 0; k < bytesPerPixel; k++)
{
output[(y * 8 + x) * (bpp / 8) + k] = palette[index * (bpp / 8) + k];
output[((y * 8 + x) * bytesPerPixel) + k] = palette[(index * bytesPerPixel) + k];
}
}
}
@ -1412,6 +1414,7 @@ void update_read_cache_brush_order(STREAM* s, CACHE_BRUSH_ORDER* cache_brush_ord
int i;
int size;
uint8 iBitmapFormat;
boolean compressed = false;
stream_read_uint8(s, cache_brush_order->index); /* cacheEntry (1 byte) */
@ -1446,7 +1449,14 @@ void update_read_cache_brush_order(STREAM* s, CACHE_BRUSH_ORDER* cache_brush_ord
}
else
{
if (cache_brush_order->length == COMPRESSED_BRUSH_LENGTH * cache_brush_order->bpp)
if ((iBitmapFormat == BMF_8BPP) && (cache_brush_order->length == 20))
compressed = true;
else if ((iBitmapFormat == BMF_16BPP) && (cache_brush_order->length == 24))
compressed = true;
else if ((iBitmapFormat == BMF_32BPP) && (cache_brush_order->length == 32))
compressed = true;
if (compressed != false)
{
/* compressed brush */
update_decompress_brush(s, cache_brush_order->data, cache_brush_order->bpp);

View File

@ -84,8 +84,6 @@
#define CBR3_IGNORABLE_FLAG 0x08
#define CBR3_DO_NOT_CACHE 0x10
#define COMPRESSED_BRUSH_LENGTH 20
/* Primary Drawing Orders */
#define ORDER_TYPE_DSTBLT 0x00
#define ORDER_TYPE_PATBLT 0x01

View File

@ -40,7 +40,7 @@ uint16 gdi_get_color_16bpp(HGDI_DC hdc, GDI_COLOR color)
GetRGB32(r, g, b, color);
if(hdc->rgb555)
if (hdc->rgb555)
{
if (hdc->invert)
{
@ -544,7 +544,7 @@ static int BitBlt_PATCOPY_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
uint16* patp;
uint16 color16;
if(hdcDest->brush->style == GDI_BS_SOLID)
if (hdcDest->brush->style == GDI_BS_SOLID)
{
color16 = gdi_get_color_16bpp(hdcDest, hdcDest->brush->color);
@ -590,7 +590,7 @@ static int BitBlt_PATINVERT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int n
uint16* patp;
uint16 color16;
if(hdcDest->brush->style == GDI_BS_SOLID)
if (hdcDest->brush->style == GDI_BS_SOLID)
{
color16 = gdi_get_color_16bpp(hdcDest, hdcDest->brush->color);

View File

@ -572,7 +572,7 @@ static int BitBlt_PATCOPY_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
uint32* patp;
uint32 color32;
if(hdcDest->brush->style == GDI_BS_SOLID)
if (hdcDest->brush->style == GDI_BS_SOLID)
{
color32 = gdi_get_color_32bpp(hdcDest, hdcDest->brush->color);
@ -618,7 +618,7 @@ static int BitBlt_PATINVERT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int n
uint32* patp;
uint32 color32;
if(hdcDest->brush->style == GDI_BS_SOLID)
if (hdcDest->brush->style == GDI_BS_SOLID)
{
color32 = gdi_get_color_32bpp(hdcDest, hdcDest->brush->color);