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//------------------------------------------------------------------------------ 20a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// VP8LColorCache. 21a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 22a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraint VP8LColorCacheInit(VP8LColorCache* const cc, int hash_bits) { 23a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora const int hash_size = 1 << hash_bits; 24a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora assert(cc != NULL); 25a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora assert(hash_bits > 0); 26a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora cc->colors_ = (uint32_t*)WebPSafeCalloc((uint64_t)hash_size, 27a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora sizeof(*cc->colors_)); 28a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora if (cc->colors_ == NULL) return 0; 29a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora cc->hash_shift_ = 32 - hash_bits; 30a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora return 1; 31a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora} 32a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 33a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroravoid VP8LColorCacheClear(VP8LColorCache* const cc) { 34a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora if (cc != NULL) { 3533f74dabbc7920a65ed435d7417987589febdc16Vikas Arora WebPSafeFree(cc->colors_); 36a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora cc->colors_ = NULL; 37a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora } 38a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora} 39a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 40