/* * Copyright (C) 2013 Glyptodon LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "config.h" #include #include #include /* * Arbitrary hash function whhich maps ALL 32-bit numbers onto 24-bit numbers * evenly, while guaranteeing that all 24-bit numbers are mapped onto * themselves. */ unsigned int _guac_hash_32to24(unsigned int value) { /* Grab highest-order byte */ unsigned int upper = value & 0xFF000000; /* XOR upper with lower three bytes, truncate to 24-bit */ return (value & 0xFFFFFF) ^ (upper >> 8) ^ (upper >> 16) ^ (upper >> 24); } /** * Rotates a given 32-bit integer by N bits. * * NOTE: We probably should check for available bitops.h macros first. */ unsigned int _guac_rotate(unsigned int value, int amount) { /* amount = amount % 32 */ amount &= 0x1F; /* Return rotated amount */ return (value >> amount) | (value << (32 - amount)); } unsigned int guac_hash_surface(cairo_surface_t* surface) { /* Init to zero */ unsigned int hash_value = 0; int x, y; /* Get image data and metrics */ unsigned char* data = cairo_image_surface_get_data(surface); int width = cairo_image_surface_get_width(surface); int height = cairo_image_surface_get_height(surface); int stride = cairo_image_surface_get_stride(surface); for (y=0; y