Fix signedness, fix hash size.

This commit is contained in:
Michael Jumper 2012-08-19 21:10:19 -07:00
parent 97ac78c1e5
commit b35947daea
2 changed files with 8 additions and 8 deletions

View File

@ -51,7 +51,7 @@
* @return An arbitrary 24-bit unsigned integer value intended to be well
* distributed across different images.
*/
int guac_hash_surface(cairo_surface_t* surface);
unsigned int guac_hash_surface(cairo_surface_t* surface);
#endif

View File

@ -44,10 +44,10 @@
* evenly, while guaranteeing that all 24-bit numbers are mapped onto
* themselves.
*/
int _guac_hash_32to24(int value) {
unsigned int _guac_hash_32to24(unsigned int value) {
/* Grab highest-order byte */
int upper = value & 0xFF000000;
unsigned int upper = value & 0xFF000000;
/* XOR upper with lower three bytes, truncate to 24-bit */
return
@ -73,10 +73,10 @@ unsigned int _guac_rotate(unsigned int value, int amount) {
}
int guac_hash_surface(cairo_surface_t* surface) {
unsigned int guac_hash_surface(cairo_surface_t* surface) {
/* Init to zero */
int hash_value = 0;
unsigned int hash_value = 0;
int x, y;
@ -95,19 +95,19 @@ int guac_hash_surface(cairo_surface_t* surface) {
for (x=0; x<width; x++) {
/* Get color at current pixel */
int color = *row;
unsigned int color = *row;
row++;
/* Compute next hash */
hash_value =
_guac_rotate(hash_value, 1) ^ _guac_hash_32to24(color);
_guac_rotate(hash_value, 1) ^ color;
}
} /* end for each row */
/* Done */
return hash_value;
return _guac_hash_32to24(hash_value);
}