FreeRDP/libfreerdp/core/graphics.c

237 lines
5.0 KiB
C
Raw Normal View History

/**
2012-10-09 07:02:04 +04:00
* FreeRDP: A Remote Desktop Protocol Implementation
* Graphical Objects
*
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <winpr/crt.h>
#include <freerdp/graphics.h>
2016-10-10 11:38:54 +03:00
#include "graphics.h"
2011-10-21 02:18:45 +04:00
/* Bitmap Class */
rdpBitmap* Bitmap_Alloc(rdpContext* context)
{
rdpBitmap* bitmap;
rdpGraphics* graphics;
graphics = context->graphics;
2019-11-06 17:24:51 +03:00
bitmap = (rdpBitmap*)calloc(1, graphics->Bitmap_Prototype->size);
if (bitmap)
{
CopyMemory(bitmap, graphics->Bitmap_Prototype, sizeof(rdpBitmap));
bitmap->data = NULL;
}
return bitmap;
}
2016-07-18 15:42:55 +03:00
static BOOL Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
{
2016-07-18 15:42:55 +03:00
if (!bitmap || !context)
return FALSE;
*bitmap = *context->graphics->Bitmap_Prototype;
return TRUE;
}
2016-10-10 11:38:54 +03:00
void Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
{
if (bitmap)
bitmap->Free(context, bitmap);
}
2019-11-06 17:24:51 +03:00
BOOL Bitmap_SetRectangle(rdpBitmap* bitmap, UINT16 left, UINT16 top, UINT16 right, UINT16 bottom)
{
2016-07-18 15:42:55 +03:00
if (!bitmap)
return FALSE;
bitmap->left = left;
bitmap->top = top;
bitmap->right = right;
bitmap->bottom = bottom;
2016-07-18 15:42:55 +03:00
return TRUE;
}
2019-11-06 17:24:51 +03:00
BOOL Bitmap_SetDimensions(rdpBitmap* bitmap, UINT16 width, UINT16 height)
{
2016-07-18 15:42:55 +03:00
if (!bitmap)
return FALSE;
2016-07-20 16:34:06 +03:00
bitmap->right = bitmap->left + width - 1;
bitmap->bottom = bitmap->top + height - 1;
bitmap->width = width;
bitmap->height = height;
2016-07-18 15:42:55 +03:00
return TRUE;
}
void graphics_register_bitmap(rdpGraphics* graphics, rdpBitmap* bitmap)
{
CopyMemory(graphics->Bitmap_Prototype, bitmap, sizeof(rdpBitmap));
}
2011-10-21 02:18:45 +04:00
/* Pointer Class */
rdpPointer* Pointer_Alloc(rdpContext* context)
{
rdpPointer* pointer;
rdpGraphics* graphics;
graphics = context->graphics;
2019-11-06 17:24:51 +03:00
pointer = (rdpPointer*)calloc(1, graphics->Pointer_Prototype->size);
2011-10-21 02:18:45 +04:00
if (pointer)
2011-10-21 02:18:45 +04:00
{
CopyMemory(pointer, graphics->Pointer_Prototype, sizeof(rdpPointer));
2011-10-21 02:18:45 +04:00
}
return pointer;
}
2016-07-18 15:16:13 +03:00
static BOOL Pointer_New(rdpContext* context, rdpPointer* pointer)
2011-10-21 02:18:45 +04:00
{
2016-07-18 15:16:13 +03:00
rdpPointer* proto;
if (!context || !context->graphics || !context->graphics->Pointer_Prototype)
return FALSE;
proto = context->graphics->Pointer_Prototype;
*pointer = *proto;
return TRUE;
2011-10-21 02:18:45 +04:00
}
/* static method */
void graphics_register_pointer(rdpGraphics* graphics, rdpPointer* pointer)
{
CopyMemory(graphics->Pointer_Prototype, pointer, sizeof(rdpPointer));
2011-10-21 02:18:45 +04:00
}
/* Glyph Class */
2019-11-06 17:24:51 +03:00
rdpGlyph* Glyph_Alloc(rdpContext* context, INT32 x, INT32 y, UINT32 cx, UINT32 cy, UINT32 cb,
const BYTE* aj)
{
rdpGlyph* glyph;
rdpGraphics* graphics;
2016-07-18 18:45:30 +03:00
if (!context || !context->graphics)
return NULL;
graphics = context->graphics;
2016-07-18 18:45:30 +03:00
if (!graphics->Glyph_Prototype)
return NULL;
2019-11-06 17:24:51 +03:00
glyph = (rdpGlyph*)calloc(1, graphics->Glyph_Prototype->size);
2016-07-18 18:45:30 +03:00
if (!glyph)
return NULL;
2016-07-18 18:45:30 +03:00
*glyph = *graphics->Glyph_Prototype;
2016-07-20 11:06:45 +03:00
glyph->cb = cb;
glyph->cx = cx;
glyph->cy = cy;
glyph->x = x;
glyph->y = y;
glyph->aj = malloc(glyph->cb);
if (!glyph->aj)
{
free(glyph);
return NULL;
}
CopyMemory(glyph->aj, aj, cb);
if (!glyph->New(context, glyph))
{
free(glyph->aj);
free(glyph);
return NULL;
}
return glyph;
}
void graphics_register_glyph(rdpGraphics* graphics, rdpGlyph* glyph)
{
CopyMemory(graphics->Glyph_Prototype, glyph, sizeof(rdpGlyph));
}
2011-10-21 02:18:45 +04:00
/* Graphics Module */
rdpGraphics* graphics_new(rdpContext* context)
{
rdpGraphics* graphics;
2019-11-06 17:24:51 +03:00
graphics = (rdpGraphics*)calloc(1, sizeof(rdpGraphics));
if (graphics)
{
graphics->context = context;
2019-11-06 17:24:51 +03:00
graphics->Bitmap_Prototype = (rdpBitmap*)calloc(1, sizeof(rdpBitmap));
if (!graphics->Bitmap_Prototype)
2014-11-17 02:41:06 +03:00
{
free(graphics);
return NULL;
2014-11-17 02:41:06 +03:00
}
graphics->Bitmap_Prototype->size = sizeof(rdpBitmap);
graphics->Bitmap_Prototype->New = Bitmap_New;
2016-10-10 11:38:54 +03:00
graphics->Bitmap_Prototype->Free = NULL;
2019-11-06 17:24:51 +03:00
graphics->Pointer_Prototype = (rdpPointer*)calloc(1, sizeof(rdpPointer));
if (!graphics->Pointer_Prototype)
2014-11-17 02:41:06 +03:00
{
free(graphics->Bitmap_Prototype);
free(graphics);
return NULL;
2014-11-17 02:41:06 +03:00
}
2011-10-21 02:18:45 +04:00
graphics->Pointer_Prototype->size = sizeof(rdpPointer);
graphics->Pointer_Prototype->New = Pointer_New;
2016-10-10 11:26:54 +03:00
graphics->Pointer_Prototype->Free = NULL;
2019-11-06 17:24:51 +03:00
graphics->Glyph_Prototype = (rdpGlyph*)calloc(1, sizeof(rdpGlyph));
if (!graphics->Glyph_Prototype)
2014-11-17 02:41:06 +03:00
{
free(graphics->Pointer_Prototype);
free(graphics->Bitmap_Prototype);
free(graphics);
return NULL;
2014-11-17 02:41:06 +03:00
}
graphics->Glyph_Prototype->size = sizeof(rdpGlyph);
}
return graphics;
}
void graphics_free(rdpGraphics* graphics)
{
if (graphics)
{
free(graphics->Bitmap_Prototype);
free(graphics->Pointer_Prototype);
free(graphics->Glyph_Prototype);
free(graphics);
}
}