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