color_cache.c revision 0406ce1417f76f2034833414dcecc9f56253640c
1a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Copyright 2012 Google Inc. All Rights Reserved. 2a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// 30406ce1417f76f2034833414dcecc9f56253640cVikas Arora// Use of this source code is governed by a BSD-style license 40406ce1417f76f2034833414dcecc9f56253640cVikas Arora// that can be found in the COPYING file in the root of the source 50406ce1417f76f2034833414dcecc9f56253640cVikas Arora// tree. An additional intellectual property rights grant can be found 60406ce1417f76f2034833414dcecc9f56253640cVikas Arora// in the file PATENTS. All contributing project authors may 70406ce1417f76f2034833414dcecc9f56253640cVikas Arora// be found in the AUTHORS file in the root of the source tree. 8a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// ----------------------------------------------------------------------------- 9a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// 10a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Color Cache for WebP Lossless 11a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// 12a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Author: Jyrki Alakuijala (jyrki@google.com) 13a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 14a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#include <assert.h> 15a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#include <stdlib.h> 16a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#include "./color_cache.h" 17a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#include "../utils/utils.h" 18a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 19a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#if defined(__cplusplus) || defined(c_plusplus) 20a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern "C" { 21a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif 22a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 23a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 24a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// VP8LColorCache. 25a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 26a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraint VP8LColorCacheInit(VP8LColorCache* const cc, int hash_bits) { 27a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora const int hash_size = 1 << hash_bits; 28a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora assert(cc != NULL); 29a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora assert(hash_bits > 0); 30a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora cc->colors_ = (uint32_t*)WebPSafeCalloc((uint64_t)hash_size, 31a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora sizeof(*cc->colors_)); 32a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora if (cc->colors_ == NULL) return 0; 33a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora cc->hash_shift_ = 32 - hash_bits; 34a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora return 1; 35a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora} 36a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 37a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroravoid VP8LColorCacheClear(VP8LColorCache* const cc) { 38a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora if (cc != NULL) { 39a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora free(cc->colors_); 40a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora cc->colors_ = NULL; 41a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora } 42a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora} 43a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 44a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#if defined(__cplusplus) || defined(c_plusplus) 45a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora} 46a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif 47