15136a052SCorentin Chary /* 25136a052SCorentin Chary * QEMU VNC display driver: palette hash table 35136a052SCorentin Chary * 45136a052SCorentin Chary * From libvncserver/libvncserver/tight.c 55136a052SCorentin Chary * Copyright (C) 2000, 2001 Const Kaplinsky. All Rights Reserved. 65136a052SCorentin Chary * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. 75136a052SCorentin Chary * 85136a052SCorentin Chary * Copyright (C) 2010 Corentin Chary <corentin.chary@gmail.com> 95136a052SCorentin Chary * 105136a052SCorentin Chary * Permission is hereby granted, free of charge, to any person obtaining a copy 115136a052SCorentin Chary * of this software and associated documentation files (the "Software"), to deal 125136a052SCorentin Chary * in the Software without restriction, including without limitation the rights 135136a052SCorentin Chary * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 145136a052SCorentin Chary * copies of the Software, and to permit persons to whom the Software is 155136a052SCorentin Chary * furnished to do so, subject to the following conditions: 165136a052SCorentin Chary * 175136a052SCorentin Chary * The above copyright notice and this permission notice shall be included in 185136a052SCorentin Chary * all copies or substantial portions of the Software. 195136a052SCorentin Chary * 205136a052SCorentin Chary * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 215136a052SCorentin Chary * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 225136a052SCorentin Chary * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 235136a052SCorentin Chary * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 245136a052SCorentin Chary * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 255136a052SCorentin Chary * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 265136a052SCorentin Chary * THE SOFTWARE. 275136a052SCorentin Chary */ 285136a052SCorentin Chary 295136a052SCorentin Chary #ifndef VNC_PALETTE_H 305136a052SCorentin Chary #define VNC_PALETTE_H 315136a052SCorentin Chary 32*1de7afc9SPaolo Bonzini #include "qemu/queue.h" 335136a052SCorentin Chary 345136a052SCorentin Chary #define VNC_PALETTE_HASH_SIZE 256 35e31e3694SCorentin Chary #define VNC_PALETTE_MAX_SIZE 256 365136a052SCorentin Chary 375136a052SCorentin Chary typedef struct VncPaletteEntry { 385136a052SCorentin Chary int idx; 395136a052SCorentin Chary uint32_t color; 405136a052SCorentin Chary QLIST_ENTRY(VncPaletteEntry) next; 415136a052SCorentin Chary } VncPaletteEntry; 425136a052SCorentin Chary 435136a052SCorentin Chary typedef struct VncPalette { 44e31e3694SCorentin Chary VncPaletteEntry pool[VNC_PALETTE_MAX_SIZE]; 455136a052SCorentin Chary size_t size; 465136a052SCorentin Chary size_t max; 475136a052SCorentin Chary int bpp; 485136a052SCorentin Chary QLIST_HEAD(,VncPaletteEntry) table[VNC_PALETTE_HASH_SIZE]; 495136a052SCorentin Chary } VncPalette; 505136a052SCorentin Chary 515136a052SCorentin Chary VncPalette *palette_new(size_t max, int bpp); 5272aefb76SCorentin Chary void palette_init(VncPalette *palette, size_t max, int bpp); 535136a052SCorentin Chary void palette_destroy(VncPalette *palette); 545136a052SCorentin Chary 555136a052SCorentin Chary int palette_put(VncPalette *palette, uint32_t color); 565136a052SCorentin Chary int palette_idx(const VncPalette *palette, uint32_t color); 575136a052SCorentin Chary size_t palette_size(const VncPalette *palette); 585136a052SCorentin Chary 595136a052SCorentin Chary void palette_iter(const VncPalette *palette, 605136a052SCorentin Chary void (*iter)(int idx, uint32_t color, void *opaque), 615136a052SCorentin Chary void *opaque); 62f8562e32SCorentin Chary uint32_t palette_color(const VncPalette *palette, int idx, bool *found); 63f8562e32SCorentin Chary size_t palette_fill(const VncPalette *palette, 64f8562e32SCorentin Chary uint32_t colors[VNC_PALETTE_MAX_SIZE]); 655136a052SCorentin Chary 665136a052SCorentin Chary #endif /* VNC_PALETTE_H */ 67