20 #include <freerdp/config.h>
24 #include <winpr/crt.h>
26 #include <freerdp/log.h>
31 #define TAG FREERDP_TAG("cache.palette")
33 static void* palette_cache_get(rdpPaletteCache* palette, UINT32 index);
35 static void palette_cache_put(rdpPaletteCache* palette, UINT32 index,
void* entry);
37 static BOOL update_gdi_cache_color_table(rdpContext* context,
40 UINT32* colorTable = NULL;
41 rdpCache* cache = context->cache;
42 colorTable = (UINT32*)malloc(
sizeof(UINT32) * 256);
47 CopyMemory(colorTable, cacheColorTable->colorTable,
sizeof(UINT32) * 256);
48 palette_cache_put(cache->palette, cacheColorTable->cacheIndex, (
void*)colorTable);
52 void* palette_cache_get(rdpPaletteCache* paletteCache, UINT32 index)
56 if (index >= paletteCache->maxEntries)
58 WLog_ERR(TAG,
"invalid color table index: 0x%08" PRIX32
"", index);
62 entry = paletteCache->entries[index].entry;
66 WLog_ERR(TAG,
"invalid color table at index: 0x%08" PRIX32
"", index);
73 void palette_cache_put(rdpPaletteCache* paletteCache, UINT32 index,
void* entry)
75 if (index >= paletteCache->maxEntries)
77 WLog_ERR(TAG,
"invalid color table index: 0x%08" PRIX32
"", index);
82 free(paletteCache->entries[index].entry);
83 paletteCache->entries[index].entry = entry;
86 void palette_cache_register_callbacks(rdpUpdate* update)
88 update->secondary->CacheColorTable = update_gdi_cache_color_table;
91 rdpPaletteCache* palette_cache_new(rdpContext* context)
93 rdpPaletteCache* paletteCache = NULL;
95 WINPR_ASSERT(context);
97 paletteCache = (rdpPaletteCache*)calloc(1,
sizeof(rdpPaletteCache));
101 paletteCache->context = context;
102 paletteCache->maxEntries = 6;
103 paletteCache->entries =
110 void palette_cache_free(rdpPaletteCache* paletteCache)
114 for (UINT32 i = 0; i < paletteCache->maxEntries; i++)
115 free(paletteCache->entries[i].entry);
117 free(paletteCache->entries);
122 void free_palette_update(rdpContext* context,
PALETTE_UPDATE* pointer)
131 if (!dst || !pointer)
137 WINPR_PRAGMA_DIAG_PUSH
138 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
139 free_palette_update(context, dst);
140 WINPR_PRAGMA_DIAG_POP