Store palette in libpng format, add PLTE section.
This commit is contained in:
parent
969f96f1b7
commit
ec652af924
@ -38,6 +38,7 @@
|
||||
#ifndef __GUAC_PALETTE_H
|
||||
#define __GUAC_PALETTE_H
|
||||
|
||||
#include <png.h>
|
||||
#include <cairo/cairo.h>
|
||||
|
||||
typedef struct guac_palette_entry {
|
||||
@ -51,7 +52,7 @@ typedef struct guac_palette_entry {
|
||||
typedef struct guac_palette {
|
||||
|
||||
guac_palette_entry entries[0xFFF];
|
||||
int colors[256];
|
||||
png_color colors[256];
|
||||
int size;
|
||||
|
||||
} guac_palette;
|
||||
|
@ -79,16 +79,24 @@ guac_palette* guac_palette_alloc(cairo_surface_t* surface) {
|
||||
/* If we've found a free space, use it */
|
||||
if (entry->index == 0) {
|
||||
|
||||
png_color* c;
|
||||
|
||||
/* Stop if already at capacity */
|
||||
if (palette->size == 256) {
|
||||
guac_palette_free(palette);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Add color to map, done */
|
||||
palette->colors[palette->size] = color;
|
||||
/* Store in palette */
|
||||
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->color = color;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
@ -263,6 +263,9 @@ int __guac_socket_write_length_png(guac_socket* socket, cairo_surface_t* surface
|
||||
PNG_FILTER_TYPE_DEFAULT
|
||||
);
|
||||
|
||||
/* Write palette */
|
||||
png_set_PLTE(png, png_info, palette->colors, palette->size);
|
||||
|
||||
/* Write image */
|
||||
png_set_rows(png, png_info, png_rows);
|
||||
png_write_png(png, png_info, PNG_TRANSFORM_IDENTITY, NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user