Changeset abeefe6 in libguac


Ignore:
Timestamp:
04/02/12 00:49:15 (14 months ago)
Author:
zhangmaike
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)
Message:

Move palette functions into own files.

Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    re833178 rabeefe6  
    4141 
    4242libguacincdir = $(includedir)/guacamole 
    43 libguacinc_HEADERS = include/client.h include/socket.h include/protocol.h include/client-handlers.h include/error.h 
     43libguacinc_HEADERS = include/client.h include/socket.h include/protocol.h include/client-handlers.h include/error.h include/palette.h 
    4444 
    4545lib_LTLIBRARIES = libguac.la 
    4646 
    47 libguac_la_SOURCES = src/client.c src/socket.c src/protocol.c src/client-handlers.c src/error.c 
     47libguac_la_SOURCES = src/client.c src/socket.c src/protocol.c src/client-handlers.c src/error.c src/palette.c 
    4848 
    4949libguac_la_LDFLAGS = -version-info 3:0:0 
    5050 
     51noinst_HEADERS = include/palette.h 
     52 
    5153EXTRA_DIST = LICENSE doc/Doxyfile 
    5254 
  • src/protocol.c

    r1546de2 rabeefe6  
    7070#include "protocol.h" 
    7171#include "error.h" 
     72#include "palette.h" 
    7273 
    7374/* Output formatting functions */ 
     
    150151void __guac_socket_flush_png(png_structp png) { 
    151152    /* 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  
    223153} 
    224154 
Note: See TracChangeset for help on using the changeset viewer.