Changeset abeefe6 in libguac
- Timestamp:
- 04/02/12 00:49:15 (14 months ago)
- Branches:
- master, debian, rpm, unstable
- Children:
- 502f990
- Parents:
- 1546de2
- git-author:
- Michael Jumper <zhangmaike@…> (04/02/12 00:49:15)
- git-committer:
- Michael Jumper <zhangmaike@…> (04/02/12 00:49:15)
- Files:
-
- 2 added
- 2 edited
-
Makefile.am (modified) (1 diff)
-
include/palette.h (added)
-
src/palette.c (added)
-
src/protocol.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Makefile.am
re833178 rabeefe6 41 41 42 42 libguacincdir = $(includedir)/guacamole 43 libguacinc_HEADERS = include/client.h include/socket.h include/protocol.h include/client-handlers.h include/error.h 43 libguacinc_HEADERS = include/client.h include/socket.h include/protocol.h include/client-handlers.h include/error.h include/palette.h 44 44 45 45 lib_LTLIBRARIES = libguac.la 46 46 47 libguac_la_SOURCES = src/client.c src/socket.c src/protocol.c src/client-handlers.c src/error.c 47 libguac_la_SOURCES = src/client.c src/socket.c src/protocol.c src/client-handlers.c src/error.c src/palette.c 48 48 49 49 libguac_la_LDFLAGS = -version-info 3:0:0 50 50 51 noinst_HEADERS = include/palette.h 52 51 53 EXTRA_DIST = LICENSE doc/Doxyfile 52 54 -
src/protocol.c
r1546de2 rabeefe6 70 70 #include "protocol.h" 71 71 #include "error.h" 72 #include "palette.h" 72 73 73 74 /* Output formatting functions */ … … 150 151 void __guac_socket_flush_png(png_structp png) { 151 152 /* Dummy function */ 152 }153 154 typedef struct __guac_palette {155 156 int index;157 int color;158 159 } __guac_palette;160 161 void __guac_create_palette(cairo_surface_t* surface) {162 163 int x, y;164 165 int width = cairo_image_surface_get_width(surface);166 int height = cairo_image_surface_get_height(surface);167 int stride = cairo_image_surface_get_stride(surface);168 unsigned char* data = cairo_image_surface_get_data(surface);169 170 /* Simple palette map */171 __guac_palette palette[0xFFF] = {{0}};172 int colors = 0;173 174 for (y=0; y<height; y++) {175 176 for (x=0; x<width; x++) {177 178 /* Get pixel color */179 int color = ((uint32_t*) data)[x] & 0xFFFFFF;180 181 /* Calculate hash code */182 int hash = ((color & 0xFFF000) >> 12) ^ (color & 0xFFF);183 184 __guac_palette* entry;185 186 /* Search for open palette entry */187 for (;;) {188 189 entry = &palette[hash];190 191 /* If we've found a free space, use it */192 if (entry->index == 0) {193 194 /* Stop if already at capacity */195 if (colors == 256)196 return;197 198 /* Add color to map, done */199 entry->index = ++colors;200 entry->color = color;201 break;202 203 }204 205 /* Otherwise, if already stored here, done */206 if (entry->color == color)207 break;208 209 /* Otherwise, collision. Move on to another bucket */210 hash = (hash+1) & 0xFFF;211 212 }213 214 }215 216 /* Advance to next data row */217 data += stride;218 219 }220 221 fprintf(stderr, "%i colors!\n", colors);222 223 153 } 224 154
Note: See TracChangeset
for help on using the changeset viewer.
