2 * FreeRDP: A Remote Desktop Protocol Client
3 * Palette (Color Table) Cache
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #include <freerdp/utils/stream.h>
21 #include <freerdp/utils/memory.h>
23 #include <freerdp/cache/palette.h>
25 void update_gdi_cache_color_table(rdpContext* context, CACHE_COLOR_TABLE_ORDER* cache_color_table)
27 rdpCache* cache = context->cache;
28 palette_cache_put(cache->palette, cache_color_table->cacheIndex, (void*) cache_color_table->colorTable);
31 void* palette_cache_get(rdpPaletteCache* palette_cache, uint32 index)
35 if (index > palette_cache->maxEntries)
37 printf("invalid color table index: 0x%04X\n", index);
41 entry = palette_cache->entries[index].entry;
45 printf("invalid color table at index: 0x%04X\n", index);
52 void palette_cache_put(rdpPaletteCache* palette_cache, uint32 index, void* entry)
54 if (index > palette_cache->maxEntries)
56 printf("invalid color table index: 0x%04X\n", index);
60 palette_cache->entries[index].entry = entry;
63 void palette_cache_register_callbacks(rdpUpdate* update)
65 update->secondary->CacheColorTable = update_gdi_cache_color_table;
68 rdpPaletteCache* palette_cache_new(rdpSettings* settings)
70 rdpPaletteCache* palette_cache;
72 palette_cache = (rdpPaletteCache*) xzalloc(sizeof(rdpPaletteCache));
74 if (palette_cache != NULL)
76 palette_cache->settings = settings;
77 palette_cache->maxEntries = 6;
78 palette_cache->entries = (PALETTE_TABLE_ENTRY*) xzalloc(sizeof(PALETTE_TABLE_ENTRY) * palette_cache->maxEntries);
84 void palette_cache_free(rdpPaletteCache* palette_cache)
86 if (palette_cache != NULL)
88 xfree(palette_cache->entries);