color_cache.c revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright 2012 Google Inc. All Rights Reserved. 2// 3// This code is licensed under the same terms as WebM: 4// Software License Agreement: http://www.webmproject.org/license/software/ 5// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ 6// ----------------------------------------------------------------------------- 7// 8// Color Cache for WebP Lossless 9// 10// Author: Jyrki Alakuijala (jyrki@google.com) 11 12#include <assert.h> 13#include <stdlib.h> 14#include "./color_cache.h" 15#include "../utils/utils.h" 16 17#if defined(__cplusplus) || defined(c_plusplus) 18extern "C" { 19#endif 20 21//------------------------------------------------------------------------------ 22// VP8LColorCache. 23 24int VP8LColorCacheInit(VP8LColorCache* const cc, int hash_bits) { 25 const int hash_size = 1 << hash_bits; 26 assert(cc != NULL); 27 assert(hash_bits > 0); 28 cc->colors_ = (uint32_t*)WebPSafeCalloc((uint64_t)hash_size, 29 sizeof(*cc->colors_)); 30 if (cc->colors_ == NULL) return 0; 31 cc->hash_shift_ = 32 - hash_bits; 32 return 1; 33} 34 35void VP8LColorCacheClear(VP8LColorCache* const cc) { 36 if (cc != NULL) { 37 free(cc->colors_); 38 cc->colors_ = NULL; 39 } 40} 41 42#if defined(__cplusplus) || defined(c_plusplus) 43} 44#endif 45