Store palette in libpng format, add PLTE section.

This commit is contained in:
Michael Jumper 2012-04-01 22:36:55 -07:00
parent 969f96f1b7
commit ec652af924
3 changed files with 15 additions and 3 deletions

View File

@ -38,6 +38,7 @@
#ifndef __GUAC_PALETTE_H #ifndef __GUAC_PALETTE_H
#define __GUAC_PALETTE_H #define __GUAC_PALETTE_H
#include <png.h>
#include <cairo/cairo.h> #include <cairo/cairo.h>
typedef struct guac_palette_entry { typedef struct guac_palette_entry {
@ -51,7 +52,7 @@ typedef struct guac_palette_entry {
typedef struct guac_palette { typedef struct guac_palette {
guac_palette_entry entries[0xFFF]; guac_palette_entry entries[0xFFF];
int colors[256]; png_color colors[256];
int size; int size;
} guac_palette; } guac_palette;

View File

@ -79,16 +79,24 @@ guac_palette* guac_palette_alloc(cairo_surface_t* surface) {
/* If we've found a free space, use it */ /* If we've found a free space, use it */
if (entry->index == 0) { if (entry->index == 0) {
png_color* c;
/* Stop if already at capacity */ /* Stop if already at capacity */
if (palette->size == 256) { if (palette->size == 256) {
guac_palette_free(palette); guac_palette_free(palette);
return NULL; return NULL;
} }
/* Add color to map, done */ /* Store in palette */
palette->colors[palette->size] = color; c = &(palette->colors[palette->size]);
c->blue = (color & 0x0000FF);
c->green = (color & 0x00FF00) >> 8;
c->red = (color & 0xFF0000) >> 16;
/* Add color to map */
entry->index = ++palette->size; entry->index = ++palette->size;
entry->color = color; entry->color = color;
break; break;
} }

View File

@ -263,6 +263,9 @@ int __guac_socket_write_length_png(guac_socket* socket, cairo_surface_t* surface
PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_DEFAULT
); );
/* Write palette */
png_set_PLTE(png, png_info, palette->colors, palette->size);
/* Write image */ /* Write image */
png_set_rows(png, png_info, png_rows); png_set_rows(png, png_info, png_rows);
png_write_png(png, png_info, PNG_TRANSFORM_IDENTITY, NULL); png_write_png(png, png_info, PNG_TRANSFORM_IDENTITY, NULL);