libfreerdp-gdi: migrate to _aligned_malloc/_aligned_free
This commit is contained in:
parent
c16000e67b
commit
ac7d23b9a3
@ -148,10 +148,10 @@ void wf_Bitmap_Decompress(wfContext* wfc, rdpBitmap* bitmap,
|
||||
|
||||
size = width * height * (bpp / 8);
|
||||
|
||||
if (bitmap->data == NULL)
|
||||
bitmap->data = (BYTE*) malloc(size);
|
||||
if (!bitmap->data)
|
||||
bitmap->data = (BYTE*) _aligned_malloc(size, 16);
|
||||
else
|
||||
bitmap->data = (BYTE*) realloc(bitmap->data, size);
|
||||
bitmap->data = (BYTE*) _aligned_realloc(bitmap->data, size, 16);
|
||||
|
||||
if (compressed)
|
||||
{
|
||||
|
@ -805,9 +805,9 @@ BOOL xf_pre_connect(freerdp *instance)
|
||||
BOOL xf_post_connect(freerdp *instance)
|
||||
{
|
||||
XGCValues gcv;
|
||||
rdpCache *cache;
|
||||
rdpChannels *channels;
|
||||
rdpSettings *settings;
|
||||
rdpCache* cache;
|
||||
rdpChannels* channels;
|
||||
rdpSettings* settings;
|
||||
ResizeWindowEventArgs e;
|
||||
xfContext* xfc = (xfContext*) instance->context;
|
||||
|
||||
@ -820,33 +820,34 @@ BOOL xf_post_connect(freerdp *instance)
|
||||
|
||||
xf_register_graphics(instance->context->graphics);
|
||||
|
||||
if (xfc->settings->SoftwareGdi)
|
||||
if (settings->SoftwareGdi)
|
||||
{
|
||||
rdpGdi *gdi;
|
||||
rdpGdi* gdi;
|
||||
UINT32 flags;
|
||||
flags = CLRCONV_ALPHA;
|
||||
|
||||
if(xfc->bpp > 16)
|
||||
flags |= CLRBUF_32BPP;
|
||||
else
|
||||
flags |= CLRBUF_16BPP;
|
||||
|
||||
gdi_init(instance, flags, NULL);
|
||||
|
||||
gdi = instance->context->gdi;
|
||||
xfc->primary_buffer = gdi->primary_buffer;
|
||||
|
||||
xfc->rfx = gdi->rfx_context;
|
||||
}
|
||||
else
|
||||
{
|
||||
xfc->srcBpp = instance->settings->ColorDepth;
|
||||
xfc->srcBpp = settings->ColorDepth;
|
||||
xf_gdi_register_update_callbacks(instance->update);
|
||||
xfc->hdc = gdi_CreateDC(xfc->clrconv, xfc->bpp);
|
||||
|
||||
if (instance->settings->RemoteFxCodec)
|
||||
if (settings->RemoteFxCodec)
|
||||
{
|
||||
xfc->rfx = rfx_context_new(FALSE);
|
||||
}
|
||||
|
||||
if (instance->settings->NSCodec)
|
||||
if (settings->NSCodec)
|
||||
{
|
||||
xfc->nsc = nsc_context_new();
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ void xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
|
||||
XSetFunction(xfc->display, xfc->gc, GXcopy);
|
||||
pixmap = XCreatePixmap(xfc->display, xfc->drawable, bitmap->width, bitmap->height, xfc->depth);
|
||||
|
||||
if (bitmap->data != NULL)
|
||||
if (bitmap->data)
|
||||
{
|
||||
data = freerdp_image_convert(bitmap->data, NULL,
|
||||
bitmap->width, bitmap->height, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);
|
||||
@ -64,12 +64,12 @@ void xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
|
||||
XFree(image);
|
||||
|
||||
if (data != bitmap->data)
|
||||
free(data);
|
||||
_aligned_free(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (data != bitmap->data)
|
||||
free(bitmap->data);
|
||||
_aligned_free(bitmap->data);
|
||||
|
||||
bitmap->data = data;
|
||||
}
|
||||
@ -133,10 +133,10 @@ void xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
|
||||
|
||||
size = width * height * ((bpp + 7) / 8);
|
||||
|
||||
if (bitmap->data == NULL)
|
||||
bitmap->data = (BYTE*) malloc(size);
|
||||
if (!bitmap->data)
|
||||
bitmap->data = (BYTE*) _aligned_malloc(size, 16);
|
||||
else
|
||||
bitmap->data = (BYTE*) realloc(bitmap->data, size);
|
||||
bitmap->data = (BYTE*) _aligned_realloc(bitmap->data, size, 16);
|
||||
|
||||
switch (codec_id)
|
||||
{
|
||||
@ -148,7 +148,7 @@ void xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
|
||||
rfx_context_set_pixel_format(xfc->rfx, RDP_PIXEL_FORMAT_B8G8R8A8);
|
||||
msg = rfx_process_message(xfc->rfx, data, length);
|
||||
|
||||
if (msg == NULL)
|
||||
if (!msg)
|
||||
{
|
||||
fprintf(stderr, "xf_Bitmap_Decompress: rfx Decompression Failed\n");
|
||||
}
|
||||
@ -231,8 +231,10 @@ void xf_Pointer_New(rdpContext* context, rdpPointer* pointer)
|
||||
ci.xhot = pointer->xPos;
|
||||
ci.yhot = pointer->yPos;
|
||||
|
||||
ci.pixels = (XcursorPixel*) malloc(ci.width * ci.height * 4);
|
||||
ZeroMemory(ci.pixels, ci.width * ci.height * 4);
|
||||
ci.pixels = (XcursorPixel*) calloc(1, ci.width * ci.height * 4);
|
||||
|
||||
if (!ci.pixels)
|
||||
return;
|
||||
|
||||
if ((pointer->andMaskData != 0) && (pointer->xorMaskData != 0))
|
||||
{
|
||||
@ -434,8 +436,10 @@ void xf_register_graphics(rdpGraphics* graphics)
|
||||
rdpPointer* pointer;
|
||||
rdpGlyph* glyph;
|
||||
|
||||
bitmap = (rdpBitmap*) malloc(sizeof(rdpBitmap));
|
||||
ZeroMemory(bitmap, sizeof(rdpBitmap));
|
||||
bitmap = (rdpBitmap*) calloc(1, sizeof(rdpBitmap));
|
||||
|
||||
if (!bitmap)
|
||||
return;
|
||||
|
||||
bitmap->size = sizeof(xfBitmap);
|
||||
|
||||
@ -448,8 +452,10 @@ void xf_register_graphics(rdpGraphics* graphics)
|
||||
graphics_register_bitmap(graphics, bitmap);
|
||||
free(bitmap);
|
||||
|
||||
pointer = (rdpPointer*) malloc(sizeof(rdpPointer));
|
||||
ZeroMemory(pointer, sizeof(rdpPointer));
|
||||
pointer = (rdpPointer*) calloc(1, sizeof(rdpPointer));
|
||||
|
||||
if (!pointer)
|
||||
return;
|
||||
|
||||
pointer->size = sizeof(xfPointer);
|
||||
|
||||
@ -462,8 +468,10 @@ void xf_register_graphics(rdpGraphics* graphics)
|
||||
graphics_register_pointer(graphics, pointer);
|
||||
free(pointer);
|
||||
|
||||
glyph = (rdpGlyph*) malloc(sizeof(rdpGlyph));
|
||||
ZeroMemory(glyph, sizeof(rdpGlyph));
|
||||
glyph = (rdpGlyph*) calloc(1, sizeof(rdpGlyph));
|
||||
|
||||
if (!glyph)
|
||||
return;
|
||||
|
||||
glyph->size = sizeof(xfGlyph);
|
||||
|
||||
|
19
libfreerdp/cache/bitmap.c
vendored
19
libfreerdp/cache/bitmap.c
vendored
@ -126,7 +126,7 @@ void update_gdi_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORDER* cach
|
||||
|
||||
prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmapV2->cacheId, cacheBitmapV2->cacheIndex);
|
||||
|
||||
if (prevBitmap != NULL)
|
||||
if (prevBitmap)
|
||||
Bitmap_Free(context, prevBitmap);
|
||||
|
||||
bitmap_cache_put(cache->bitmap, cacheBitmapV2->cacheId, cacheBitmapV2->cacheIndex, bitmap);
|
||||
@ -158,7 +158,7 @@ void update_gdi_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORDER* cach
|
||||
|
||||
prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmapV3->cacheId, cacheBitmapV3->cacheIndex);
|
||||
|
||||
if (prevBitmap != NULL)
|
||||
if (prevBitmap)
|
||||
Bitmap_Free(context, prevBitmap);
|
||||
|
||||
bitmap_cache_put(cache->bitmap, cacheBitmapV3->cacheId, cacheBitmapV3->cacheIndex, bitmap);
|
||||
@ -279,27 +279,26 @@ rdpBitmapCache* bitmap_cache_new(rdpSettings* settings)
|
||||
int i;
|
||||
rdpBitmapCache* bitmapCache;
|
||||
|
||||
bitmapCache = (rdpBitmapCache*) malloc(sizeof(rdpBitmapCache));
|
||||
bitmapCache = (rdpBitmapCache*) calloc(1, sizeof(rdpBitmapCache));
|
||||
|
||||
if (bitmapCache)
|
||||
{
|
||||
ZeroMemory(bitmapCache, sizeof(rdpBitmapCache));
|
||||
|
||||
bitmapCache->settings = settings;
|
||||
bitmapCache->update = ((freerdp*) settings->instance)->update;
|
||||
bitmapCache->context = bitmapCache->update->context;
|
||||
|
||||
bitmapCache->maxCells = settings->BitmapCacheV2NumCells;
|
||||
|
||||
bitmapCache->cells = (BITMAP_V2_CELL*) malloc(sizeof(BITMAP_V2_CELL) * bitmapCache->maxCells);
|
||||
ZeroMemory(bitmapCache->cells, sizeof(BITMAP_V2_CELL) * bitmapCache->maxCells);
|
||||
bitmapCache->cells = (BITMAP_V2_CELL*) calloc(bitmapCache->maxCells, sizeof(BITMAP_V2_CELL));
|
||||
|
||||
if (!bitmapCache->cells)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < (int) bitmapCache->maxCells; i++)
|
||||
{
|
||||
bitmapCache->cells[i].number = settings->BitmapCacheV2CellInfo[i].numEntries;
|
||||
/* allocate an extra entry for BITMAP_CACHE_WAITING_LIST_INDEX */
|
||||
bitmapCache->cells[i].entries = (rdpBitmap**) malloc(sizeof(rdpBitmap*) * (bitmapCache->cells[i].number + 1));
|
||||
ZeroMemory(bitmapCache->cells[i].entries, sizeof(rdpBitmap*) * (bitmapCache->cells[i].number + 1));
|
||||
bitmapCache->cells[i].entries = (rdpBitmap**) calloc((bitmapCache->cells[i].number + 1), sizeof(rdpBitmap*));
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,7 +310,7 @@ void bitmap_cache_free(rdpBitmapCache* bitmapCache)
|
||||
int i, j;
|
||||
rdpBitmap* bitmap;
|
||||
|
||||
if (bitmapCache != NULL)
|
||||
if (bitmapCache)
|
||||
{
|
||||
for (i = 0; i < (int) bitmapCache->maxCells; i++)
|
||||
{
|
||||
|
@ -253,10 +253,10 @@ BOOL bitmap_decompress(BYTE* srcData, BYTE* dstData, int width, int height, int
|
||||
|
||||
if (srcBpp == 16 && dstBpp == 16)
|
||||
{
|
||||
TmpBfr = (BYTE*) malloc(width * height * 2);
|
||||
RleDecompress16to16(srcData, size, TmpBfr, width * 2, width, height);
|
||||
freerdp_bitmap_flip(TmpBfr, dstData, width * 2, height);
|
||||
free(TmpBfr);
|
||||
TmpBfr = (BYTE*) _aligned_malloc(width * height * 2, 16);
|
||||
RleDecompress16to16(srcData, size, TmpBfr, width * 2, width, height);
|
||||
freerdp_bitmap_flip(TmpBfr, dstData, width * 2, height);
|
||||
_aligned_free(TmpBfr);
|
||||
}
|
||||
else if (srcBpp == 32 && dstBpp == 32)
|
||||
{
|
||||
@ -270,24 +270,24 @@ BOOL bitmap_decompress(BYTE* srcData, BYTE* dstData, int width, int height, int
|
||||
}
|
||||
else if (srcBpp == 15 && dstBpp == 15)
|
||||
{
|
||||
TmpBfr = (BYTE*) malloc(width * height * 2);
|
||||
RleDecompress16to16(srcData, size, TmpBfr, width * 2, width, height);
|
||||
freerdp_bitmap_flip(TmpBfr, dstData, width * 2, height);
|
||||
free(TmpBfr);
|
||||
TmpBfr = (BYTE*) _aligned_malloc(width * height * 2, 16);
|
||||
RleDecompress16to16(srcData, size, TmpBfr, width * 2, width, height);
|
||||
freerdp_bitmap_flip(TmpBfr, dstData, width * 2, height);
|
||||
_aligned_free(TmpBfr);
|
||||
}
|
||||
else if (srcBpp == 8 && dstBpp == 8)
|
||||
{
|
||||
TmpBfr = (BYTE*) malloc(width * height);
|
||||
RleDecompress8to8(srcData, size, TmpBfr, width, width, height);
|
||||
freerdp_bitmap_flip(TmpBfr, dstData, width, height);
|
||||
free(TmpBfr);
|
||||
TmpBfr = (BYTE*) _aligned_malloc(width * height, 16);
|
||||
RleDecompress8to8(srcData, size, TmpBfr, width, width, height);
|
||||
freerdp_bitmap_flip(TmpBfr, dstData, width, height);
|
||||
_aligned_free(TmpBfr);
|
||||
}
|
||||
else if (srcBpp == 24 && dstBpp == 24)
|
||||
{
|
||||
TmpBfr = (BYTE*) malloc(width * height * 3);
|
||||
RleDecompress24to24(srcData, size, TmpBfr, width * 3, width, height);
|
||||
freerdp_bitmap_flip(TmpBfr, dstData, width * 3, height);
|
||||
free(TmpBfr);
|
||||
TmpBfr = (BYTE*) _aligned_malloc(width * height * 3, 16);
|
||||
RleDecompress24to24(srcData, size, TmpBfr, width * 3, width, height);
|
||||
freerdp_bitmap_flip(TmpBfr, dstData, width * 3, height);
|
||||
_aligned_free(TmpBfr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -66,8 +66,8 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize,
|
||||
BYTE seqNumber;
|
||||
BYTE glyphFlags;
|
||||
BYTE* glyphData;
|
||||
UINT16 glyphIndex;
|
||||
UINT32 offset = 0;
|
||||
UINT16 glyphIndex = 0;
|
||||
BYTE* pDstData = NULL;
|
||||
UINT32 residualByteCount;
|
||||
UINT32 bandsByteCount;
|
||||
|
@ -392,18 +392,26 @@ BYTE* freerdp_image_convert_8bpp(BYTE* srcData, BYTE* dstData, int width, int he
|
||||
|
||||
if (dstBpp == 8)
|
||||
{
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height);
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
CopyMemory(dstData, srcData, width * height);
|
||||
|
||||
memcpy(dstData, srcData, width * height);
|
||||
return dstData;
|
||||
}
|
||||
else if (dstBpp == 15 || (dstBpp == 16 && clrconv->rgb555))
|
||||
{
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 2);
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 2, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
dst16 = (UINT16*) dstData;
|
||||
|
||||
dst16 = (UINT16 *) dstData;
|
||||
for (i = width * height; i > 0; i--)
|
||||
{
|
||||
pixel = *srcData;
|
||||
@ -415,14 +423,19 @@ BYTE* freerdp_image_convert_8bpp(BYTE* srcData, BYTE* dstData, int width, int he
|
||||
*dst16 = pixel;
|
||||
dst16++;
|
||||
}
|
||||
|
||||
return dstData;
|
||||
}
|
||||
else if (dstBpp == 16)
|
||||
{
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 2);
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 2, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
dst16 = (UINT16*) dstData;
|
||||
|
||||
dst16 = (UINT16 *) dstData;
|
||||
for (i = width * height; i > 0; i--)
|
||||
{
|
||||
pixel = *srcData;
|
||||
@ -434,15 +447,20 @@ BYTE* freerdp_image_convert_8bpp(BYTE* srcData, BYTE* dstData, int width, int he
|
||||
*dst16 = pixel;
|
||||
dst16++;
|
||||
}
|
||||
|
||||
return dstData;
|
||||
}
|
||||
else if (dstBpp == 32)
|
||||
{
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 4);
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 4, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
src8 = (BYTE*) srcData;
|
||||
dst32 = (UINT32*) dstData;
|
||||
|
||||
for (i = width * height; i > 0; i--)
|
||||
{
|
||||
pixel = *src8;
|
||||
@ -461,6 +479,7 @@ BYTE* freerdp_image_convert_8bpp(BYTE* srcData, BYTE* dstData, int width, int he
|
||||
*dst32 = pixel;
|
||||
dst32++;
|
||||
}
|
||||
|
||||
return dstData;
|
||||
}
|
||||
|
||||
@ -480,20 +499,27 @@ BYTE* freerdp_image_convert_15bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
|
||||
if (dstBpp == 15 || (dstBpp == 16 && clrconv->rgb555))
|
||||
{
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 2);
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 2, 16);
|
||||
|
||||
memcpy(dstData, srcData, width * height * 2);
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
CopyMemory(dstData, srcData, width * height * 2);
|
||||
|
||||
return dstData;
|
||||
}
|
||||
else if (dstBpp == 32)
|
||||
{
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 4);
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 4, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
src16 = (UINT16*) srcData;
|
||||
dst32 = (UINT32*) dstData;
|
||||
|
||||
src16 = (UINT16 *) srcData;
|
||||
dst32 = (UINT32 *) dstData;
|
||||
for (i = width * height; i > 0; i--)
|
||||
{
|
||||
pixel = *src16;
|
||||
@ -510,15 +536,20 @@ BYTE* freerdp_image_convert_15bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
*dst32 = pixel;
|
||||
dst32++;
|
||||
}
|
||||
|
||||
return dstData;
|
||||
}
|
||||
else if (dstBpp == 16)
|
||||
{
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 2);
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 2, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
src16 = (UINT16*) srcData;
|
||||
dst16 = (UINT16*) dstData;
|
||||
|
||||
src16 = (UINT16 *) srcData;
|
||||
dst16 = (UINT16 *) dstData;
|
||||
for (i = width * height; i > 0; i--)
|
||||
{
|
||||
pixel = *src16;
|
||||
@ -529,6 +560,7 @@ BYTE* freerdp_image_convert_15bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
*dst16 = pixel;
|
||||
dst16++;
|
||||
}
|
||||
|
||||
return dstData;
|
||||
}
|
||||
|
||||
@ -542,8 +574,11 @@ BYTE* freerdp_image_convert_16bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
|
||||
if (dstBpp == 16)
|
||||
{
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 2);
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 2, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
if (clrconv->rgb555)
|
||||
{
|
||||
@ -563,7 +598,7 @@ BYTE* freerdp_image_convert_16bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(dstData, srcData, width * height * 2);
|
||||
CopyMemory(dstData, srcData, width * height * 2);
|
||||
}
|
||||
|
||||
return dstData;
|
||||
@ -575,8 +610,11 @@ BYTE* freerdp_image_convert_16bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
UINT16 *src16;
|
||||
BYTE red, green, blue;
|
||||
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 3);
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 3, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
dst8 = (BYTE*) dstData;
|
||||
src16 = (UINT16*) srcData;
|
||||
@ -599,6 +637,7 @@ BYTE* freerdp_image_convert_16bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
*dst8++ = blue;
|
||||
}
|
||||
}
|
||||
|
||||
return dstData;
|
||||
}
|
||||
else if (dstBpp == 32)
|
||||
@ -606,12 +645,10 @@ BYTE* freerdp_image_convert_16bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
primitives_t* prims;
|
||||
|
||||
if (!dstData)
|
||||
{
|
||||
dstData = _aligned_malloc(width * height * sizeof(UINT32), 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
}
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
prims = primitives_get();
|
||||
prims->RGB565ToARGB_16u32u_C3C4(
|
||||
@ -631,11 +668,16 @@ BYTE* freerdp_image_convert_24bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
|
||||
if (dstBpp == 32)
|
||||
{
|
||||
BYTE *dstp;
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 4);
|
||||
BYTE* dstp;
|
||||
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 4, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
dstp = dstData;
|
||||
|
||||
for (i = width * height; i > 0; i--)
|
||||
{
|
||||
*(dstp++) = *(srcData++);
|
||||
@ -643,6 +685,7 @@ BYTE* freerdp_image_convert_24bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
*(dstp++) = *(srcData++);
|
||||
*(dstp++) = 0xFF;
|
||||
}
|
||||
|
||||
return dstData;
|
||||
}
|
||||
|
||||
@ -658,8 +701,11 @@ BYTE* freerdp_image_convert_32bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
UINT32 *src32;
|
||||
BYTE red, green, blue;
|
||||
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 2);
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 2, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
dst16 = (UINT16*) dstData;
|
||||
src32 = (UINT32*) srcData;
|
||||
@ -671,18 +717,23 @@ BYTE* freerdp_image_convert_32bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
src32++;
|
||||
dst16++;
|
||||
}
|
||||
|
||||
return dstData;
|
||||
}
|
||||
else if (dstBpp == 24)
|
||||
{
|
||||
BYTE *dstp;
|
||||
int index;
|
||||
BYTE* dstp;
|
||||
BYTE red, green, blue;
|
||||
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 3);
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 3, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
dstp = dstData;
|
||||
|
||||
for (index = 0; index < width * height; index++)
|
||||
{
|
||||
red = *(srcData++);
|
||||
@ -704,19 +755,23 @@ BYTE* freerdp_image_convert_32bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
|
||||
srcData++;
|
||||
}
|
||||
|
||||
return dstData;
|
||||
}
|
||||
else if (dstBpp == 32)
|
||||
{
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 4, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
if (clrconv->alpha)
|
||||
{
|
||||
int x, y;
|
||||
BYTE *dstp;
|
||||
BYTE* dstp;
|
||||
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 4);
|
||||
|
||||
memcpy(dstData, srcData, width * height * 4);
|
||||
CopyMemory(dstData, srcData, width * height * 4);
|
||||
|
||||
dstp = dstData;
|
||||
for (y = 0; y < height; y++)
|
||||
@ -731,10 +786,7 @@ BYTE* freerdp_image_convert_32bpp(BYTE* srcData, BYTE* dstData, int width, int h
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * 4);
|
||||
|
||||
memcpy(dstData, srcData, width * height * 4);
|
||||
CopyMemory(dstData, srcData, width * height * 4);
|
||||
}
|
||||
|
||||
return dstData;
|
||||
@ -778,7 +830,7 @@ void freerdp_bitmap_flip(BYTE * src, BYTE * dst, int scanLineSz, int height)
|
||||
* fixed size buffers (of max scanline size (or adaptative?) )
|
||||
* -- would be much faster).
|
||||
*/
|
||||
BYTE * tmpBfr = malloc(scanLineSz);
|
||||
BYTE* tmpBfr = _aligned_malloc(scanLineSz, 16);
|
||||
int half = height / 2;
|
||||
/* Flip buffer in place by line permutations through the temp
|
||||
* scan line buffer.
|
||||
@ -791,14 +843,14 @@ void freerdp_bitmap_flip(BYTE * src, BYTE * dst, int scanLineSz, int height)
|
||||
height--;
|
||||
for (i = 0; i < half ; i++)
|
||||
{
|
||||
memcpy(tmpBfr, topLine, scanLineSz);
|
||||
memcpy(topLine, bottomLine, scanLineSz);
|
||||
memcpy(bottomLine, tmpBfr, scanLineSz);
|
||||
CopyMemory(tmpBfr, topLine, scanLineSz);
|
||||
CopyMemory(topLine, bottomLine, scanLineSz);
|
||||
CopyMemory(bottomLine, tmpBfr, scanLineSz);
|
||||
topLine += scanLineSz;
|
||||
bottomLine -= scanLineSz;
|
||||
height--;
|
||||
}
|
||||
free(tmpBfr);
|
||||
_aligned_free(tmpBfr);
|
||||
}
|
||||
/* Flip from source buffer to destination buffer. */
|
||||
else
|
||||
@ -806,7 +858,7 @@ void freerdp_bitmap_flip(BYTE * src, BYTE * dst, int scanLineSz, int height)
|
||||
|
||||
for (i = 0; i < height; i++)
|
||||
{
|
||||
memcpy(bottomLine, topLine, scanLineSz);
|
||||
CopyMemory(bottomLine, topLine, scanLineSz);
|
||||
topLine += scanLineSz;
|
||||
bottomLine -= scanLineSz;
|
||||
}
|
||||
@ -820,10 +872,14 @@ BYTE* freerdp_image_flip(BYTE* srcData, BYTE* dstData, int width, int height, in
|
||||
|
||||
scanline = width * ((bpp + 7) / 8);
|
||||
|
||||
if (dstData == NULL)
|
||||
dstData = (BYTE*) malloc(width * height * ((bpp + 7) / 8));
|
||||
if (!dstData)
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * ((bpp + 7) / 8), 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
freerdp_bitmap_flip(srcData, dstData, scanline, height);
|
||||
|
||||
return dstData;
|
||||
}
|
||||
|
||||
@ -843,7 +899,7 @@ BYTE* freerdp_icon_convert(BYTE* srcData, BYTE* dstData, BYTE* mask, int width,
|
||||
|
||||
data = freerdp_image_flip(srcData, dstData, width, height, bpp);
|
||||
dstData = freerdp_image_convert(data, NULL, width, height, bpp, 32, clrconv);
|
||||
free(data);
|
||||
_aligned_free(data);
|
||||
|
||||
/* Read the AND alpha plane */
|
||||
if (bpp < 32)
|
||||
@ -891,9 +947,9 @@ BYTE* freerdp_icon_convert(BYTE* srcData, BYTE* dstData, BYTE* mask, int width,
|
||||
BYTE* freerdp_glyph_convert(int width, int height, BYTE* data)
|
||||
{
|
||||
int x, y;
|
||||
BYTE *srcp;
|
||||
BYTE *dstp;
|
||||
BYTE *dstData;
|
||||
BYTE* srcp;
|
||||
BYTE* dstp;
|
||||
BYTE* dstData;
|
||||
int scanline;
|
||||
|
||||
/*
|
||||
@ -903,8 +959,12 @@ BYTE* freerdp_glyph_convert(int width, int height, BYTE* data)
|
||||
*/
|
||||
|
||||
scanline = (width + 7) / 8;
|
||||
dstData = (BYTE*) malloc(width * height);
|
||||
memset(dstData, 0, width * height);
|
||||
dstData = (BYTE*) _aligned_malloc(width * height, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
ZeroMemory(dstData, width * height);
|
||||
dstp = dstData;
|
||||
|
||||
for (y = 0; y < height; y++)
|
||||
@ -987,7 +1047,11 @@ BYTE* freerdp_mono_image_convert(BYTE* srcData, int width, int height, int srcBp
|
||||
}
|
||||
}
|
||||
|
||||
dstData = (BYTE*) malloc(width * height * 2);
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 2, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
dst16 = (UINT16*) dstData;
|
||||
|
||||
for (index = height; index > 0; index--)
|
||||
@ -1012,7 +1076,11 @@ BYTE* freerdp_mono_image_convert(BYTE* srcData, int width, int height, int srcBp
|
||||
}
|
||||
else if (dstBpp == 32)
|
||||
{
|
||||
dstData = (BYTE*) malloc(width * height * 4);
|
||||
dstData = (BYTE*) _aligned_malloc(width * height * 4, 16);
|
||||
|
||||
if (!dstData)
|
||||
return NULL;
|
||||
|
||||
dst32 = (UINT32*) dstData;
|
||||
|
||||
for (index = height; index > 0; index--)
|
||||
@ -1098,24 +1166,28 @@ HCLRCONV freerdp_clrconv_new(UINT32 flags)
|
||||
{
|
||||
HCLRCONV clrconv;
|
||||
|
||||
clrconv = (CLRCONV*) malloc(sizeof(CLRCONV));
|
||||
ZeroMemory(clrconv, sizeof(CLRCONV));
|
||||
clrconv = (CLRCONV*) calloc(1, sizeof(CLRCONV));
|
||||
|
||||
if (!clrconv)
|
||||
return NULL;
|
||||
|
||||
clrconv->alpha = (flags & CLRCONV_ALPHA) ? TRUE : FALSE;
|
||||
clrconv->invert = (flags & CLRCONV_INVERT) ? TRUE : FALSE;
|
||||
clrconv->rgb555 = (flags & CLRCONV_RGB555) ? TRUE : FALSE;
|
||||
|
||||
clrconv->palette = (rdpPalette*) malloc(sizeof(rdpPalette));
|
||||
ZeroMemory(clrconv->palette, sizeof(rdpPalette));
|
||||
clrconv->palette = (rdpPalette*) calloc(1, sizeof(rdpPalette));
|
||||
|
||||
if (!clrconv->palette)
|
||||
return NULL;
|
||||
|
||||
return clrconv;
|
||||
}
|
||||
|
||||
void freerdp_clrconv_free(HCLRCONV clrconv)
|
||||
{
|
||||
if (clrconv != NULL)
|
||||
if (clrconv)
|
||||
{
|
||||
if (clrconv->palette != NULL)
|
||||
if (clrconv->palette)
|
||||
free(clrconv->palette);
|
||||
|
||||
free(clrconv);
|
||||
|
@ -1186,19 +1186,20 @@ BOOL setupWorkers(RFX_CONTEXT *context, int nbTiles)
|
||||
if (!context->priv->UseThreads)
|
||||
return TRUE;
|
||||
|
||||
priv->workObjects = (PTP_WORK *)realloc(priv->workObjects, sizeof(PTP_WORK) * nbTiles);
|
||||
if (!priv->workObjects)
|
||||
return FALSE;
|
||||
priv->workObjects = (PTP_WORK*) realloc(priv->workObjects, sizeof(PTP_WORK) * nbTiles);
|
||||
|
||||
priv->tileWorkParams = (RFX_TILE_COMPOSE_WORK_PARAM *)
|
||||
if (!priv->workObjects)
|
||||
return FALSE;
|
||||
|
||||
priv->tileWorkParams = (RFX_TILE_COMPOSE_WORK_PARAM*)
|
||||
realloc(priv->tileWorkParams, sizeof(RFX_TILE_COMPOSE_WORK_PARAM) * nbTiles);
|
||||
|
||||
if (!priv->tileWorkParams)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int numRects,
|
||||
BYTE* data, int width, int height, int scanline)
|
||||
{
|
||||
@ -1223,7 +1224,8 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int
|
||||
assert(height > 0);
|
||||
assert(scanline > 0);
|
||||
|
||||
message = (RFX_MESSAGE *)calloc(1, sizeof(RFX_MESSAGE));
|
||||
message = (RFX_MESSAGE*)calloc(1, sizeof(RFX_MESSAGE));
|
||||
|
||||
if (!message)
|
||||
return NULL;
|
||||
|
||||
@ -1231,6 +1233,7 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int
|
||||
rfx_update_context_properties(context);
|
||||
|
||||
message->frameIdx = context->frameIdx++;
|
||||
|
||||
if (!context->numQuant)
|
||||
{
|
||||
context->numQuant = 1;
|
||||
@ -1240,12 +1243,14 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int
|
||||
context->quantIdxCb = 0;
|
||||
context->quantIdxCr = 0;
|
||||
}
|
||||
|
||||
message->numQuant = context->numQuant;
|
||||
message->quantVals = context->quants;
|
||||
|
||||
bytesPerPixel = (context->bits_per_pixel / 8);
|
||||
|
||||
region16_init(&rectsRegion);
|
||||
|
||||
if (!computeRegion(rects, numRects, &rectsRegion, width, height))
|
||||
goto out_free_message;
|
||||
|
||||
@ -1258,6 +1263,7 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int
|
||||
maxNbTiles = maxTilesX * maxTilesY;
|
||||
|
||||
message->tiles = calloc(maxNbTiles, sizeof(RFX_TILE*));
|
||||
|
||||
if (!message->tiles)
|
||||
goto out_free_message;
|
||||
|
||||
@ -1272,8 +1278,10 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int
|
||||
|
||||
regionRect = region16_rects(&rectsRegion, ®ionNbRects);
|
||||
message->rects = rfxRect = calloc(regionNbRects, sizeof(RFX_RECT));
|
||||
|
||||
if (!message->rects)
|
||||
goto out_clean_tiles;
|
||||
|
||||
message->numRects = regionNbRects;
|
||||
|
||||
region16_init(&tilesRegion);
|
||||
@ -1295,6 +1303,7 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int
|
||||
for (yIdx = startTileY, gridRelY = startTileY * 64; yIdx <= endTileY; yIdx++, gridRelY += 64 )
|
||||
{
|
||||
int tileHeight = 64;
|
||||
|
||||
if ((yIdx == endTileY) && (gridRelY + 64 > height))
|
||||
tileHeight = height - gridRelY;
|
||||
|
||||
@ -1304,6 +1313,7 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int
|
||||
for (xIdx = startTileX, gridRelX = startTileX * 64; xIdx <= endTileX; xIdx++, gridRelX += 64)
|
||||
{
|
||||
int tileWidth = 64;
|
||||
|
||||
if ((xIdx == endTileX) && (gridRelX + 64 > width))
|
||||
tileWidth = width - gridRelX;
|
||||
|
||||
@ -1314,7 +1324,8 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int
|
||||
if (region16_intersects_rect(&tilesRegion, ¤tTileRect))
|
||||
continue;
|
||||
|
||||
tile = (RFX_TILE *)ObjectPool_Take(context->priv->TilePool);
|
||||
tile = (RFX_TILE*) ObjectPool_Take(context->priv->TilePool);
|
||||
|
||||
if (!tile)
|
||||
goto out_clean_rects;;
|
||||
|
||||
@ -1328,6 +1339,7 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int
|
||||
|
||||
ax = gridRelX;
|
||||
ay = gridRelY;
|
||||
|
||||
if (tile->data && tile->allocated)
|
||||
{
|
||||
free(tile->data);
|
||||
@ -1356,7 +1368,7 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int
|
||||
|
||||
*workObject = CreateThreadpoolWork(
|
||||
(PTP_WORK_CALLBACK)rfx_compose_message_tile_work_callback,
|
||||
(void *)workParam,
|
||||
(void*) workParam,
|
||||
&context->priv->ThreadPoolEnv
|
||||
);
|
||||
|
||||
@ -1381,7 +1393,8 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int
|
||||
|
||||
if (message->numTiles != maxNbTiles)
|
||||
{
|
||||
message->tiles = realloc(message->tiles, sizeof(RFX_TILE *) * message->numTiles);
|
||||
message->tiles = realloc(message->tiles, sizeof(RFX_TILE*) * message->numTiles);
|
||||
|
||||
if (!message->tiles)
|
||||
goto out_clean_rects;
|
||||
}
|
||||
@ -1391,6 +1404,7 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int
|
||||
/* when using threads ensure all computations are done */
|
||||
message->tilesDataSize = 0;
|
||||
workObject = context->priv->workObjects;
|
||||
|
||||
for (i = 0; i < message->numTiles; i++)
|
||||
{
|
||||
tile = message->tiles[i];
|
||||
@ -1431,8 +1445,10 @@ RFX_MESSAGE* rfx_split_message(RFX_CONTEXT* context, RFX_MESSAGE* message, int*
|
||||
|
||||
*numMessages = ((message->tilesDataSize + maxDataSize) / maxDataSize) * 4;
|
||||
|
||||
messages = (RFX_MESSAGE*) malloc(sizeof(RFX_MESSAGE) * (*numMessages));
|
||||
ZeroMemory(messages, sizeof(RFX_MESSAGE) * (*numMessages));
|
||||
messages = (RFX_MESSAGE*) calloc((*numMessages), sizeof(RFX_MESSAGE));
|
||||
|
||||
if (!messages)
|
||||
return NULL;
|
||||
|
||||
j = 0;
|
||||
|
||||
@ -1604,4 +1620,3 @@ void rfx_compose_message(RFX_CONTEXT* context, wStream* s,
|
||||
|
||||
rfx_message_free(context, message);
|
||||
}
|
||||
|
||||
|
@ -3388,7 +3388,7 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
|
||||
free(decompressedBitmap);
|
||||
|
||||
freerdp_clrconv_free(clrconv);
|
||||
free(srcBitmap32);
|
||||
_aligned_free(srcBitmap32);
|
||||
|
||||
freerdp_bitmap_planar_context_free(planar);
|
||||
|
||||
|
@ -35,9 +35,9 @@ rdpBitmap* Bitmap_Alloc(rdpContext* context)
|
||||
graphics = context->graphics;
|
||||
bitmap = (rdpBitmap*) malloc(graphics->Bitmap_Prototype->size);
|
||||
|
||||
if (bitmap != NULL)
|
||||
if (bitmap)
|
||||
{
|
||||
memcpy(bitmap, context->graphics->Bitmap_Prototype, sizeof(rdpBitmap));
|
||||
CopyMemory(bitmap, context->graphics->Bitmap_Prototype, sizeof(rdpBitmap));
|
||||
bitmap->data = NULL;
|
||||
}
|
||||
|
||||
@ -51,12 +51,12 @@ void Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
|
||||
|
||||
void Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
|
||||
{
|
||||
if (bitmap != NULL)
|
||||
if (bitmap)
|
||||
{
|
||||
bitmap->Free(context, bitmap);
|
||||
|
||||
if (bitmap->data != NULL)
|
||||
free(bitmap->data);
|
||||
if (bitmap->data)
|
||||
_aligned_free(bitmap->data);
|
||||
|
||||
free(bitmap);
|
||||
}
|
||||
@ -84,7 +84,7 @@ void Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary)
|
||||
|
||||
void graphics_register_bitmap(rdpGraphics* graphics, rdpBitmap* bitmap)
|
||||
{
|
||||
memcpy(graphics->Bitmap_Prototype, bitmap, sizeof(rdpBitmap));
|
||||
CopyMemory(graphics->Bitmap_Prototype, bitmap, sizeof(rdpBitmap));
|
||||
}
|
||||
|
||||
/* Pointer Class */
|
||||
@ -97,9 +97,9 @@ rdpPointer* Pointer_Alloc(rdpContext* context)
|
||||
graphics = context->graphics;
|
||||
pointer = (rdpPointer*) malloc(graphics->Pointer_Prototype->size);
|
||||
|
||||
if (pointer != NULL)
|
||||
if (pointer)
|
||||
{
|
||||
memcpy(pointer, context->graphics->Pointer_Prototype, sizeof(rdpPointer));
|
||||
CopyMemory(pointer, context->graphics->Pointer_Prototype, sizeof(rdpPointer));
|
||||
}
|
||||
|
||||
return pointer;
|
||||
@ -112,7 +112,7 @@ void Pointer_New(rdpContext* context, rdpPointer* pointer)
|
||||
|
||||
void Pointer_Free(rdpContext* context, rdpPointer* pointer)
|
||||
{
|
||||
if (pointer != NULL)
|
||||
if (pointer)
|
||||
{
|
||||
pointer->Free(context, pointer);
|
||||
|
||||
@ -150,7 +150,7 @@ void Pointer_SetDefault(rdpContext* context)
|
||||
|
||||
void graphics_register_pointer(rdpGraphics* graphics, rdpPointer* pointer)
|
||||
{
|
||||
memcpy(graphics->Pointer_Prototype, pointer, sizeof(rdpPointer));
|
||||
CopyMemory(graphics->Pointer_Prototype, pointer, sizeof(rdpPointer));
|
||||
}
|
||||
|
||||
/* Glyph Class */
|
||||
@ -163,9 +163,9 @@ rdpGlyph* Glyph_Alloc(rdpContext* context)
|
||||
graphics = context->graphics;
|
||||
glyph = (rdpGlyph*) malloc(graphics->Glyph_Prototype->size);
|
||||
|
||||
if (glyph != NULL)
|
||||
if (glyph)
|
||||
{
|
||||
memcpy(glyph, context->graphics->Glyph_Prototype, sizeof(rdpGlyph));
|
||||
CopyMemory(glyph, context->graphics->Glyph_Prototype, sizeof(rdpGlyph));
|
||||
}
|
||||
|
||||
return glyph;
|
||||
@ -198,7 +198,7 @@ void Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, UIN
|
||||
|
||||
void graphics_register_glyph(rdpGraphics* graphics, rdpGlyph* glyph)
|
||||
{
|
||||
memcpy(graphics->Glyph_Prototype, glyph, sizeof(rdpGlyph));
|
||||
CopyMemory(graphics->Glyph_Prototype, glyph, sizeof(rdpGlyph));
|
||||
}
|
||||
|
||||
/* Graphics Module */
|
||||
@ -207,28 +207,35 @@ rdpGraphics* graphics_new(rdpContext* context)
|
||||
{
|
||||
rdpGraphics* graphics;
|
||||
|
||||
graphics = (rdpGraphics*) malloc(sizeof(rdpGraphics));
|
||||
graphics = (rdpGraphics*) calloc(1, sizeof(rdpGraphics));
|
||||
|
||||
if (graphics != NULL)
|
||||
if (graphics)
|
||||
{
|
||||
ZeroMemory(graphics, sizeof(rdpGraphics));
|
||||
|
||||
graphics->context = context;
|
||||
|
||||
graphics->Bitmap_Prototype = (rdpBitmap*) malloc(sizeof(rdpBitmap));
|
||||
ZeroMemory(graphics->Bitmap_Prototype, sizeof(rdpBitmap));
|
||||
graphics->Bitmap_Prototype = (rdpBitmap*) calloc(1, sizeof(rdpBitmap));
|
||||
|
||||
if (!graphics->Bitmap_Prototype)
|
||||
return NULL;
|
||||
|
||||
graphics->Bitmap_Prototype->size = sizeof(rdpBitmap);
|
||||
graphics->Bitmap_Prototype->New = Bitmap_New;
|
||||
graphics->Bitmap_Prototype->Free = Bitmap_Free;
|
||||
|
||||
graphics->Pointer_Prototype = (rdpPointer*) malloc(sizeof(rdpPointer));
|
||||
ZeroMemory(graphics->Pointer_Prototype, sizeof(rdpPointer));
|
||||
graphics->Pointer_Prototype = (rdpPointer*) calloc(1, sizeof(rdpPointer));
|
||||
|
||||
if (!graphics->Pointer_Prototype)
|
||||
return NULL;
|
||||
|
||||
graphics->Pointer_Prototype->size = sizeof(rdpPointer);
|
||||
graphics->Pointer_Prototype->New = Pointer_New;
|
||||
graphics->Pointer_Prototype->Free = Pointer_Free;
|
||||
|
||||
graphics->Glyph_Prototype = (rdpGlyph*) malloc(sizeof(rdpGlyph));
|
||||
ZeroMemory(graphics->Glyph_Prototype, sizeof(rdpGlyph));
|
||||
graphics->Glyph_Prototype = (rdpGlyph*) calloc(1, sizeof(rdpGlyph));
|
||||
|
||||
if (!graphics->Glyph_Prototype)
|
||||
return NULL;
|
||||
|
||||
graphics->Glyph_Prototype->size = sizeof(rdpGlyph);
|
||||
graphics->Glyph_Prototype->New = Glyph_New;
|
||||
graphics->Glyph_Prototype->Free = Glyph_Free;
|
||||
@ -239,7 +246,7 @@ rdpGraphics* graphics_new(rdpContext* context)
|
||||
|
||||
void graphics_free(rdpGraphics* graphics)
|
||||
{
|
||||
if (graphics != NULL)
|
||||
if (graphics)
|
||||
{
|
||||
free(graphics->Bitmap_Prototype);
|
||||
free(graphics->Pointer_Prototype);
|
||||
|
@ -95,7 +95,7 @@ int update_recv_surfcmds(rdpUpdate* update, UINT32 size, wStream* s)
|
||||
{
|
||||
BYTE* mark;
|
||||
UINT16 cmdType;
|
||||
UINT32 cmdLength;
|
||||
UINT32 cmdLength = 0;
|
||||
|
||||
while (size > 2)
|
||||
{
|
||||
|
@ -158,12 +158,16 @@ HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, BYTE* d
|
||||
HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, int nWidth, int nHeight)
|
||||
{
|
||||
HGDI_BITMAP hBitmap = (HGDI_BITMAP) malloc(sizeof(GDI_BITMAP));
|
||||
|
||||
if (!hBitmap)
|
||||
return NULL;
|
||||
|
||||
hBitmap->objectType = GDIOBJECT_BITMAP;
|
||||
hBitmap->bytesPerPixel = hdc->bytesPerPixel;
|
||||
hBitmap->bitsPerPixel = hdc->bitsPerPixel;
|
||||
hBitmap->width = nWidth;
|
||||
hBitmap->height = nHeight;
|
||||
hBitmap->data = malloc(nWidth * nHeight * hBitmap->bytesPerPixel);
|
||||
hBitmap->data = _aligned_malloc(nWidth * nHeight * hBitmap->bytesPerPixel, 16);
|
||||
hBitmap->scanline = nWidth * hBitmap->bytesPerPixel;
|
||||
return hBitmap;
|
||||
}
|
||||
|
@ -163,15 +163,15 @@ HGDIOBJECT gdi_SelectObject(HGDI_DC hdc, HGDIOBJECT hgdiobject)
|
||||
|
||||
int gdi_DeleteObject(HGDIOBJECT hgdiobject)
|
||||
{
|
||||
if (hgdiobject == NULL)
|
||||
if (!hgdiobject)
|
||||
return 0;
|
||||
|
||||
if (hgdiobject->objectType == GDIOBJECT_BITMAP)
|
||||
{
|
||||
HGDI_BITMAP hBitmap = (HGDI_BITMAP) hgdiobject;
|
||||
|
||||
if (hBitmap->data != NULL)
|
||||
free(hBitmap->data);
|
||||
if (hBitmap->data)
|
||||
_aligned_free(hBitmap->data);
|
||||
|
||||
free(hBitmap);
|
||||
}
|
||||
|
@ -390,6 +390,9 @@ gdiBitmap* gdi_glyph_new(rdpGdi* gdi, GLYPH_DATA* glyph)
|
||||
|
||||
gdi_bmp = (gdiBitmap*) malloc(sizeof(gdiBitmap));
|
||||
|
||||
if (!gdi_bmp)
|
||||
return NULL;
|
||||
|
||||
gdi_bmp->hdc = gdi_GetDC();
|
||||
gdi_bmp->hdc->bytesPerPixel = 1;
|
||||
gdi_bmp->hdc->bitsPerPixel = 1;
|
||||
@ -405,9 +408,9 @@ gdiBitmap* gdi_glyph_new(rdpGdi* gdi, GLYPH_DATA* glyph)
|
||||
return gdi_bmp;
|
||||
}
|
||||
|
||||
void gdi_glyph_free(gdiBitmap *gdi_bmp)
|
||||
void gdi_glyph_free(gdiBitmap* gdi_bmp)
|
||||
{
|
||||
if (gdi_bmp != 0)
|
||||
if (gdi_bmp)
|
||||
{
|
||||
gdi_SelectObject(gdi_bmp->hdc, (HGDIOBJECT) gdi_bmp->org_bitmap);
|
||||
gdi_DeleteObject((HGDIOBJECT) gdi_bmp->bitmap);
|
||||
@ -421,11 +424,15 @@ gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE*
|
||||
gdiBitmap* bitmap;
|
||||
|
||||
bitmap = (gdiBitmap*) malloc(sizeof(gdiBitmap));
|
||||
|
||||
if (!bitmap)
|
||||
return NULL;
|
||||
|
||||
bitmap->hdc = gdi_CreateCompatibleDC(gdi->hdc);
|
||||
|
||||
DEBUG_GDI("gdi_bitmap_new: width:%d height:%d bpp:%d", width, height, bpp);
|
||||
|
||||
if (data == NULL)
|
||||
if (!data)
|
||||
bitmap->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, width, height);
|
||||
else
|
||||
bitmap->bitmap = gdi_create_bitmap(gdi, width, height, bpp, data);
|
||||
@ -795,8 +802,10 @@ void gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits_co
|
||||
surface_bits_command->width, surface_bits_command->height,
|
||||
surface_bits_command->bitmapDataLength);
|
||||
|
||||
tile_bitmap = (char*) malloc(32);
|
||||
ZeroMemory(tile_bitmap, 32);
|
||||
tile_bitmap = (char*) _aligned_malloc(32, 16);
|
||||
|
||||
if (!tile_bitmap)
|
||||
return;
|
||||
|
||||
if (surface_bits_command->codecID == RDP_CODEC_ID_REMOTEFX)
|
||||
{
|
||||
@ -841,7 +850,7 @@ void gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits_co
|
||||
gdi->image->bitmap->height = surface_bits_command->height;
|
||||
gdi->image->bitmap->bitsPerPixel = surface_bits_command->bpp;
|
||||
gdi->image->bitmap->bytesPerPixel = gdi->image->bitmap->bitsPerPixel / 8;
|
||||
gdi->image->bitmap->data = (BYTE*) realloc(gdi->image->bitmap->data, gdi->image->bitmap->width * gdi->image->bitmap->height * 4);
|
||||
gdi->image->bitmap->data = (BYTE*) _aligned_realloc(gdi->image->bitmap->data, gdi->image->bitmap->width * gdi->image->bitmap->height * 4, 16);
|
||||
freerdp_image_flip(nsc_context->BitmapData, gdi->image->bitmap->data, gdi->image->bitmap->width, gdi->image->bitmap->height, 32);
|
||||
gdi_BitBlt(gdi->primary->hdc, surface_bits_command->destLeft, surface_bits_command->destTop, surface_bits_command->width, surface_bits_command->height, gdi->image->hdc, 0, 0, GDI_SRCCOPY);
|
||||
}
|
||||
@ -852,8 +861,8 @@ void gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits_co
|
||||
gdi->image->bitmap->bitsPerPixel = surface_bits_command->bpp;
|
||||
gdi->image->bitmap->bytesPerPixel = gdi->image->bitmap->bitsPerPixel / 8;
|
||||
|
||||
gdi->image->bitmap->data = (BYTE*) realloc(gdi->image->bitmap->data,
|
||||
gdi->image->bitmap->width * gdi->image->bitmap->height * 4);
|
||||
gdi->image->bitmap->data = (BYTE*) _aligned_realloc(gdi->image->bitmap->data,
|
||||
gdi->image->bitmap->width * gdi->image->bitmap->height * 4, 16);
|
||||
|
||||
if ((surface_bits_command->bpp != 32) || (gdi->clrconv->alpha == TRUE))
|
||||
{
|
||||
@ -866,9 +875,9 @@ void gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits_co
|
||||
surface_bits_command->bpp = 32;
|
||||
surface_bits_command->bitmapData = gdi->image->bitmap->data;
|
||||
|
||||
temp_image = (BYTE*) malloc(gdi->image->bitmap->width * gdi->image->bitmap->height * 4);
|
||||
temp_image = (BYTE*) _aligned_malloc(gdi->image->bitmap->width * gdi->image->bitmap->height * 4, 16);
|
||||
freerdp_image_flip(gdi->image->bitmap->data, temp_image, gdi->image->bitmap->width, gdi->image->bitmap->height, 32);
|
||||
free(gdi->image->bitmap->data);
|
||||
_aligned_free(gdi->image->bitmap->data);
|
||||
gdi->image->bitmap->data = temp_image;
|
||||
}
|
||||
else
|
||||
@ -885,8 +894,8 @@ void gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits_co
|
||||
fprintf(stderr, "Unsupported codecID %d\n", surface_bits_command->codecID);
|
||||
}
|
||||
|
||||
if (tile_bitmap != NULL)
|
||||
free(tile_bitmap);
|
||||
if (tile_bitmap)
|
||||
_aligned_free(tile_bitmap);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -932,6 +941,10 @@ void gdi_register_update_callbacks(rdpUpdate* update)
|
||||
void gdi_init_primary(rdpGdi* gdi)
|
||||
{
|
||||
gdi->primary = (gdiBitmap*) malloc(sizeof(gdiBitmap));
|
||||
|
||||
if (!gdi->primary)
|
||||
return NULL;
|
||||
|
||||
gdi->primary->hdc = gdi_CreateCompatibleDC(gdi->hdc);
|
||||
|
||||
if (!gdi->primary_buffer)
|
||||
@ -984,8 +997,10 @@ int gdi_init(freerdp* instance, UINT32 flags, BYTE* buffer)
|
||||
rdpGdi* gdi;
|
||||
rdpCache* cache;
|
||||
|
||||
gdi = (rdpGdi*) malloc(sizeof(rdpGdi));
|
||||
ZeroMemory(gdi, sizeof(rdpGdi));
|
||||
gdi = (rdpGdi*) calloc(1, sizeof(rdpGdi));
|
||||
|
||||
if (!gdi)
|
||||
return -1;
|
||||
|
||||
instance->context->gdi = gdi;
|
||||
cache = instance->context->cache;
|
||||
@ -1036,11 +1051,18 @@ int gdi_init(freerdp* instance, UINT32 flags, BYTE* buffer)
|
||||
gdi->hdc->bytesPerPixel = gdi->bytesPerPixel;
|
||||
|
||||
gdi->clrconv = (HCLRCONV) malloc(sizeof(CLRCONV));
|
||||
|
||||
if (!gdi->clrconv)
|
||||
return -1;
|
||||
|
||||
gdi->clrconv->alpha = (flags & CLRCONV_ALPHA) ? 1 : 0;
|
||||
gdi->clrconv->invert = (flags & CLRCONV_INVERT) ? 1 : 0;
|
||||
gdi->clrconv->rgb555 = (flags & CLRCONV_RGB555) ? 1 : 0;
|
||||
gdi->clrconv->palette = (rdpPalette*) malloc(sizeof(rdpPalette));
|
||||
|
||||
if (!gdi->clrconv->palette)
|
||||
return -1;
|
||||
|
||||
gdi->hdc->alpha = gdi->clrconv->alpha;
|
||||
gdi->hdc->invert = gdi->clrconv->invert;
|
||||
gdi->hdc->rgb555 = gdi->clrconv->rgb555;
|
||||
|
@ -61,7 +61,7 @@ void gdi_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
|
||||
gdi_bitmap = (gdiBitmap*) bitmap;
|
||||
gdi_bitmap->hdc = gdi_CreateCompatibleDC(gdi->hdc);
|
||||
|
||||
if (bitmap->data == NULL)
|
||||
if (!bitmap->data)
|
||||
gdi_bitmap->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, bitmap->width, bitmap->height);
|
||||
else
|
||||
gdi_bitmap->bitmap = gdi_create_bitmap(gdi, bitmap->width, bitmap->height, gdi->dstBpp, bitmap->data);
|
||||
@ -74,7 +74,7 @@ void gdi_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
|
||||
{
|
||||
gdiBitmap* gdi_bitmap = (gdiBitmap*) bitmap;
|
||||
|
||||
if (gdi_bitmap != NULL)
|
||||
if (gdi_bitmap)
|
||||
{
|
||||
gdi_SelectObject(gdi_bitmap->hdc, (HGDIOBJECT) gdi_bitmap->org_bitmap);
|
||||
gdi_DeleteObject((HGDIOBJECT) gdi_bitmap->bitmap);
|
||||
@ -110,9 +110,9 @@ void gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
|
||||
size = width * height * ((bpp + 7) / 8);
|
||||
|
||||
if (!bitmap->data)
|
||||
bitmap->data = (BYTE*) malloc(size);
|
||||
bitmap->data = (BYTE*) _aligned_malloc(size, 16);
|
||||
else
|
||||
bitmap->data = (BYTE*) realloc(bitmap->data, size);
|
||||
bitmap->data = (BYTE*) _aligned_realloc(bitmap->data, size, 16);
|
||||
|
||||
switch (codecId)
|
||||
{
|
||||
@ -217,7 +217,7 @@ void gdi_Glyph_Free(rdpContext* context, rdpGlyph* glyph)
|
||||
|
||||
gdi_glyph = (gdiGlyph*) glyph;
|
||||
|
||||
if (gdi_glyph != 0)
|
||||
if (gdi_glyph)
|
||||
{
|
||||
gdi_SelectObject(gdi_glyph->hdc, (HGDIOBJECT) gdi_glyph->org_bitmap);
|
||||
gdi_DeleteObject((HGDIOBJECT) gdi_glyph->bitmap);
|
||||
|
@ -27,6 +27,8 @@
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#define WINPR_ALIGNED_MALLOC_SIGNATURE 0x0BA0BAB
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
@ -39,6 +41,7 @@
|
||||
|
||||
struct _aligned_meminfo
|
||||
{
|
||||
UINT32 sig;
|
||||
size_t size;
|
||||
void* base_addr;
|
||||
};
|
||||
@ -84,6 +87,7 @@ void* _aligned_offset_malloc(size_t size, size_t alignment, size_t offset)
|
||||
memptr = (void *)((((size_t)((PBYTE)tmpptr + alignment + offset + sizeof(struct _aligned_meminfo)) & ~(alignment - 1)) - offset));
|
||||
|
||||
ameminfo = (struct _aligned_meminfo*) (((size_t)((PBYTE)memptr - sizeof(struct _aligned_meminfo))));
|
||||
ameminfo->sig = WINPR_ALIGNED_MALLOC_SIGNATURE;
|
||||
ameminfo->base_addr = tmpptr;
|
||||
ameminfo->size = size;
|
||||
|
||||
@ -111,6 +115,13 @@ void* _aligned_offset_realloc(void* memblock, size_t size, size_t alignment, siz
|
||||
return NULL;
|
||||
|
||||
ameminfo = (struct _aligned_meminfo*) (((size_t)((PBYTE)memblock - sizeof(struct _aligned_meminfo))));
|
||||
|
||||
if (ameminfo->sig != WINPR_ALIGNED_MALLOC_SIGNATURE)
|
||||
{
|
||||
fprintf(stderr, "_aligned_offset_realloc: memory block was not allocated by _aligned_malloc!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CopyMemory(newmem, memblock, ameminfo->size);
|
||||
_aligned_free(memblock);
|
||||
|
||||
@ -136,6 +147,12 @@ void _aligned_free(void* memblock)
|
||||
|
||||
ameminfo = (struct _aligned_meminfo*) (((size_t)((PBYTE)memblock - sizeof(struct _aligned_meminfo))));
|
||||
|
||||
if (ameminfo->sig != WINPR_ALIGNED_MALLOC_SIGNATURE)
|
||||
{
|
||||
fprintf(stderr, "_aligned_free: memory block was not allocated by _aligned_malloc!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
free(ameminfo->base_addr);
|
||||
}
|
||||
|
||||
|
@ -116,12 +116,10 @@ wObjectPool* ObjectPool_New(BOOL synchronized)
|
||||
{
|
||||
wObjectPool* pool = NULL;
|
||||
|
||||
pool = (wObjectPool*) malloc(sizeof(wObjectPool));
|
||||
pool = (wObjectPool*) calloc(1, sizeof(wObjectPool));
|
||||
|
||||
if (pool)
|
||||
{
|
||||
ZeroMemory(pool, sizeof(wObjectPool));
|
||||
|
||||
pool->synchronized = synchronized;
|
||||
|
||||
if (pool->synchronized)
|
||||
|
Loading…
Reference in New Issue
Block a user