FreeRDP
Loading...
Searching...
No Matches
palette.c
1
20#include <freerdp/config.h>
21
22#include <stdio.h>
23
24#include <winpr/crt.h>
25
26#include <freerdp/log.h>
27
28#include "palette.h"
29#include "cache.h"
30
31#define TAG FREERDP_TAG("cache.palette")
32
33static void palette_cache_put(rdpPaletteCache* palette, UINT32 index, void* entry);
34
35static BOOL update_gdi_cache_color_table(rdpContext* context,
36 const CACHE_COLOR_TABLE_ORDER* cacheColorTable)
37{
38 UINT32* colorTable = NULL;
39 rdpCache* cache = context->cache;
40 colorTable = (UINT32*)malloc(sizeof(UINT32) * 256);
41
42 if (!colorTable)
43 return FALSE;
44
45 CopyMemory(colorTable, cacheColorTable->colorTable, sizeof(UINT32) * 256);
46 palette_cache_put(cache->palette, cacheColorTable->cacheIndex, (void*)colorTable);
47 return TRUE;
48}
49
50void palette_cache_put(rdpPaletteCache* paletteCache, UINT32 index, void* entry)
51{
52 if (index >= paletteCache->maxEntries)
53 {
54 WLog_ERR(TAG, "invalid color table index: 0x%08" PRIX32 "", index);
55 free(entry);
56 return;
57 }
58
59 free(paletteCache->entries[index].entry);
60 paletteCache->entries[index].entry = entry;
61}
62
63void palette_cache_register_callbacks(rdpUpdate* update)
64{
65 WINPR_ASSERT(update);
66 WINPR_ASSERT(update->secondary);
67 update->secondary->CacheColorTable = update_gdi_cache_color_table;
68}
69
70rdpPaletteCache* palette_cache_new(rdpContext* context)
71{
72 rdpPaletteCache* paletteCache = NULL;
73
74 WINPR_ASSERT(context);
75
76 paletteCache = (rdpPaletteCache*)calloc(1, sizeof(rdpPaletteCache));
77
78 if (paletteCache)
79 {
80 paletteCache->context = context;
81 paletteCache->maxEntries = 6;
82 paletteCache->entries =
83 (PALETTE_TABLE_ENTRY*)calloc(paletteCache->maxEntries, sizeof(PALETTE_TABLE_ENTRY));
84 }
85
86 return paletteCache;
87}
88
89void palette_cache_free(rdpPaletteCache* paletteCache)
90{
91 if (paletteCache)
92 {
93 for (UINT32 i = 0; i < paletteCache->maxEntries; i++)
94 free(paletteCache->entries[i].entry);
95
96 free(paletteCache->entries);
97 free(paletteCache);
98 }
99}
100
101void free_palette_update(WINPR_ATTR_UNUSED rdpContext* context, PALETTE_UPDATE* pointer)
102{
103 free(pointer);
104}
105
106PALETTE_UPDATE* copy_palette_update(rdpContext* context, const PALETTE_UPDATE* pointer)
107{
108 PALETTE_UPDATE* dst = calloc(1, sizeof(PALETTE_UPDATE));
109
110 if (!dst || !pointer)
111 goto fail;
112
113 *dst = *pointer;
114 return dst;
115fail:
116 WINPR_PRAGMA_DIAG_PUSH
117 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
118 free_palette_update(context, dst);
119 WINPR_PRAGMA_DIAG_POP
120 return NULL;
121}
Definition palette.h:29