Store sequential array of colors in palette.

This commit is contained in:
Michael Jumper 2012-04-01 22:06:34 -07:00
parent 314e8c9222
commit 1489ae902d
3 changed files with 8 additions and 4 deletions

View File

@ -51,7 +51,8 @@ typedef struct guac_palette_entry {
typedef struct guac_palette {
guac_palette_entry entries[0xFFF];
int colors;
int colors[256];
int size;
} guac_palette;

View File

@ -80,13 +80,14 @@ guac_palette* guac_palette_alloc(cairo_surface_t* surface) {
if (entry->index == 0) {
/* Stop if already at capacity */
if (palette->colors == 256) {
if (palette->size == 256) {
guac_palette_free(palette);
return NULL;
}
/* Add color to map, done */
entry->index = ++palette->colors;
palette->colors[palette->size] = color;
entry->index = ++palette->size;
entry->color = color;
break;

View File

@ -230,9 +230,11 @@ int __guac_socket_write_length_png(guac_socket* socket, cairo_surface_t* surface
guac_palette* palette = guac_palette_alloc(surface);
if (palette != NULL) {
fprintf(stderr,
"Created palette with %i entries.\n",
palette->colors);
palette->size);
guac_palette_free(palette);
}