2011-11-11 02:07:53 -05:00
|
|
|
/**
|
2012-10-08 23:02:04 -04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-11-11 02:07:53 -05:00
|
|
|
* Palette (Color Table) Cache
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-02-16 11:20:38 +01:00
|
|
|
#include <freerdp/config.h>
|
2012-08-14 17:09:01 -04:00
|
|
|
|
2012-09-23 18:41:07 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2012-11-19 23:49:08 -05:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
|
2014-09-12 14:36:29 +02:00
|
|
|
#include <freerdp/log.h>
|
2011-11-11 02:07:53 -05:00
|
|
|
|
2018-03-30 10:43:20 +02:00
|
|
|
#include "palette.h"
|
2023-02-07 15:42:52 +01:00
|
|
|
#include "cache.h"
|
2018-03-30 10:43:20 +02:00
|
|
|
|
2014-09-12 14:36:29 +02:00
|
|
|
#define TAG FREERDP_TAG("cache.palette")
|
|
|
|
|
|
2016-04-05 17:07:45 +02:00
|
|
|
static void palette_cache_put(rdpPaletteCache* palette, UINT32 index, void* entry);
|
|
|
|
|
|
|
|
|
|
static BOOL update_gdi_cache_color_table(rdpContext* context,
|
2019-11-06 15:24:51 +01:00
|
|
|
const CACHE_COLOR_TABLE_ORDER* cacheColorTable)
|
2011-11-11 02:07:53 -05:00
|
|
|
{
|
2026-02-26 15:06:27 +01:00
|
|
|
UINT32* colorTable = nullptr;
|
2011-11-21 19:41:49 -05:00
|
|
|
rdpCache* cache = context->cache;
|
2019-11-06 15:24:51 +01:00
|
|
|
colorTable = (UINT32*)malloc(sizeof(UINT32) * 256);
|
2018-03-30 10:43:20 +02:00
|
|
|
|
2015-04-14 10:14:23 +02:00
|
|
|
if (!colorTable)
|
|
|
|
|
return FALSE;
|
2013-02-03 16:19:25 -05:00
|
|
|
|
2018-03-30 10:43:20 +02:00
|
|
|
CopyMemory(colorTable, cacheColorTable->colorTable, sizeof(UINT32) * 256);
|
2019-11-06 15:24:51 +01:00
|
|
|
palette_cache_put(cache->palette, cacheColorTable->cacheIndex, (void*)colorTable);
|
2015-04-14 10:14:23 +02:00
|
|
|
return TRUE;
|
2011-11-11 02:07:53 -05:00
|
|
|
}
|
|
|
|
|
|
2013-11-03 13:51:41 -05:00
|
|
|
void palette_cache_put(rdpPaletteCache* paletteCache, UINT32 index, void* entry)
|
2011-11-11 02:07:53 -05:00
|
|
|
{
|
2013-11-03 13:51:41 -05:00
|
|
|
if (index >= paletteCache->maxEntries)
|
2011-11-11 02:07:53 -05:00
|
|
|
{
|
2019-11-06 15:24:51 +01:00
|
|
|
WLog_ERR(TAG, "invalid color table index: 0x%08" PRIX32 "", index);
|
2015-05-11 09:07:39 +02:00
|
|
|
free(entry);
|
2011-11-11 02:07:53 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 09:07:39 +02:00
|
|
|
free(paletteCache->entries[index].entry);
|
2013-11-03 13:51:41 -05:00
|
|
|
paletteCache->entries[index].entry = entry;
|
2011-11-11 02:07:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void palette_cache_register_callbacks(rdpUpdate* update)
|
|
|
|
|
{
|
2025-02-27 10:43:01 +01:00
|
|
|
WINPR_ASSERT(update);
|
|
|
|
|
WINPR_ASSERT(update->secondary);
|
2011-11-21 19:41:49 -05:00
|
|
|
update->secondary->CacheColorTable = update_gdi_cache_color_table;
|
2011-11-11 02:07:53 -05:00
|
|
|
}
|
|
|
|
|
|
2021-09-06 14:00:12 +02:00
|
|
|
rdpPaletteCache* palette_cache_new(rdpContext* context)
|
2011-11-11 02:07:53 -05:00
|
|
|
{
|
2026-02-26 15:06:27 +01:00
|
|
|
rdpPaletteCache* paletteCache = nullptr;
|
2021-09-06 14:00:12 +02:00
|
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
2019-11-06 15:24:51 +01:00
|
|
|
paletteCache = (rdpPaletteCache*)calloc(1, sizeof(rdpPaletteCache));
|
2011-11-11 02:07:53 -05:00
|
|
|
|
2013-11-03 13:51:41 -05:00
|
|
|
if (paletteCache)
|
2011-11-11 02:07:53 -05:00
|
|
|
{
|
2021-09-06 14:00:12 +02:00
|
|
|
paletteCache->context = context;
|
2013-11-03 13:51:41 -05:00
|
|
|
paletteCache->maxEntries = 6;
|
2019-11-06 15:24:51 +01:00
|
|
|
paletteCache->entries =
|
|
|
|
|
(PALETTE_TABLE_ENTRY*)calloc(paletteCache->maxEntries, sizeof(PALETTE_TABLE_ENTRY));
|
2011-11-11 02:07:53 -05:00
|
|
|
}
|
|
|
|
|
|
2013-11-03 13:51:41 -05:00
|
|
|
return paletteCache;
|
2011-11-11 02:07:53 -05:00
|
|
|
}
|
|
|
|
|
|
2013-11-03 13:51:41 -05:00
|
|
|
void palette_cache_free(rdpPaletteCache* paletteCache)
|
2011-11-11 02:07:53 -05:00
|
|
|
{
|
2013-11-03 13:51:41 -05:00
|
|
|
if (paletteCache)
|
2011-11-11 02:07:53 -05:00
|
|
|
{
|
2024-01-30 10:25:38 +01:00
|
|
|
for (UINT32 i = 0; i < paletteCache->maxEntries; i++)
|
2015-05-11 09:07:39 +02:00
|
|
|
free(paletteCache->entries[i].entry);
|
2013-11-03 13:51:41 -05:00
|
|
|
|
|
|
|
|
free(paletteCache->entries);
|
|
|
|
|
free(paletteCache);
|
2011-11-11 02:07:53 -05:00
|
|
|
}
|
|
|
|
|
}
|
2018-03-30 10:43:20 +02:00
|
|
|
|
2025-02-13 15:29:10 +01:00
|
|
|
void free_palette_update(WINPR_ATTR_UNUSED rdpContext* context, PALETTE_UPDATE* pointer)
|
2018-03-30 10:43:20 +02:00
|
|
|
{
|
|
|
|
|
free(pointer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PALETTE_UPDATE* copy_palette_update(rdpContext* context, const PALETTE_UPDATE* pointer)
|
|
|
|
|
{
|
|
|
|
|
PALETTE_UPDATE* dst = calloc(1, sizeof(PALETTE_UPDATE));
|
|
|
|
|
|
|
|
|
|
if (!dst || !pointer)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
*dst = *pointer;
|
|
|
|
|
return dst;
|
|
|
|
|
fail:
|
2024-02-04 11:11:29 +01:00
|
|
|
WINPR_PRAGMA_DIAG_PUSH
|
|
|
|
|
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
2018-03-30 10:43:20 +02:00
|
|
|
free_palette_update(context, dst);
|
2024-02-04 11:11:29 +01:00
|
|
|
WINPR_PRAGMA_DIAG_POP
|
2026-02-26 15:06:27 +01:00
|
|
|
return nullptr;
|
2018-03-30 10:43:20 +02:00
|
|
|
}
|