Fix crash of content_shell aura due to ime.
[chromium-blink-merge.git] / third_party / libwebp / utils / color_cache.c
blob749db6128fb148b7e2accdbda26f4fe7a6d4569a
1 // Copyright 2012 Google Inc. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 // -----------------------------------------------------------------------------
9 //
10 // Color Cache for WebP Lossless
12 // Author: Jyrki Alakuijala (jyrki@google.com)
14 #include <assert.h>
15 #include <stdlib.h>
16 #include "./color_cache.h"
17 #include "../utils/utils.h"
19 #if defined(__cplusplus) || defined(c_plusplus)
20 extern "C" {
21 #endif
23 //------------------------------------------------------------------------------
24 // VP8LColorCache.
26 int VP8LColorCacheInit(VP8LColorCache* const cc, int hash_bits) {
27 const int hash_size = 1 << hash_bits;
28 assert(cc != NULL);
29 assert(hash_bits > 0);
30 cc->colors_ = (uint32_t*)WebPSafeCalloc((uint64_t)hash_size,
31 sizeof(*cc->colors_));
32 if (cc->colors_ == NULL) return 0;
33 cc->hash_shift_ = 32 - hash_bits;
34 return 1;
37 void VP8LColorCacheClear(VP8LColorCache* const cc) {
38 if (cc != NULL) {
39 free(cc->colors_);
40 cc->colors_ = NULL;
44 #if defined(__cplusplus) || defined(c_plusplus)
46 #endif