wfreerdp: fix compilation on windows
[platform/upstream/freerdp.git] / libfreerdp-cache / color_table.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * Color Table Cache
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 #include <freerdp/utils/stream.h>
21 #include <freerdp/utils/memory.h>
22
23 #include <freerdp/cache/color_table.h>
24
25 void* color_table_get(rdpColorTableCache* color_table, uint8 index)
26 {
27         void* entry;
28
29         if (index > color_table->maxEntries)
30         {
31                 printf("invalid color table index: 0x%04X\n", index);
32                 return NULL;
33         }
34
35         entry = color_table->entries[index].entry;
36
37         if (entry == NULL)
38         {
39                 printf("invalid color table at index: 0x%04X\n", index);
40                 return NULL;
41         }
42
43         return entry;
44 }
45
46 void color_table_put(rdpColorTableCache* color_table, uint8 index, void* entry)
47 {
48         if (index > color_table->maxEntries)
49         {
50                 printf("invalid color table index: 0x%04X\n", index);
51                 return;
52         }
53
54         color_table->entries[index].entry = entry;
55 }
56
57 rdpColorTableCache* color_table_cache_new(rdpSettings* settings)
58 {
59         rdpColorTableCache* color_table;
60
61         color_table = (rdpColorTableCache*) xzalloc(sizeof(rdpColorTableCache));
62
63         if (color_table != NULL)
64         {
65                 color_table->settings = settings;
66
67                 color_table->maxEntries = 6;
68
69                 color_table->entries = (COLOR_TABLE_ENTRY*) xzalloc(sizeof(COLOR_TABLE_ENTRY) * color_table->maxEntries);
70         }
71
72         return color_table;
73 }
74
75 void color_table_cache_free(rdpColorTableCache* color_table)
76 {
77         if (color_table != NULL)
78         {
79                 xfree(color_table->entries);
80                 xfree(color_table);
81         }
82 }
83