Changeset 43842cb in libguac


Ignore:
Timestamp:
04/02/12 00:57:19 (14 months ago)
Author:
zhangmaike
Branches:
master, debian, rpm, unstable
Children:
eaf5489
Parents:
502f990
git-author:
Michael Jumper <zhangmaike@…> (04/02/12 00:57:19)
git-committer:
Michael Jumper <zhangmaike@…> (04/02/12 00:57:19)
Message:

Add palette find function.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/palette.h

    r502f990 r43842cb  
    5757 
    5858guac_palette* guac_palette_alloc(cairo_surface_t* surface); 
     59int guac_palette_find(guac_palette* palette, int color); 
    5960void guac_palette_free(guac_palette* palette); 
    6061 
  • src/palette.c

    r502f990 r43842cb  
    112112} 
    113113 
     114int guac_palette_find(guac_palette* palette, int color) { 
     115 
     116    /* Calculate hash code */ 
     117    int hash = ((color & 0xFFF000) >> 12) ^ (color & 0xFFF); 
     118 
     119    guac_palette_entry* entry; 
     120 
     121    /* Search for palette entry */ 
     122    for (;;) { 
     123         
     124        entry = &(palette->entries[hash]); 
     125 
     126        /* If we've found a free space, color not stored. */ 
     127        if (entry->index == 0) 
     128            return -1; 
     129 
     130        /* Otherwise, if color indeed stored here, done */ 
     131        if (entry->color == color) 
     132            return entry->index; 
     133 
     134        /* Otherwise, collision. Move on to another bucket */ 
     135        hash = (hash+1) & 0xFFF; 
     136 
     137    } 
     138 
     139} 
     140 
    114141void guac_palette_free(guac_palette* palette) { 
    115142    free(palette); 
Note: See TracChangeset for help on using the changeset viewer.