summaryrefslogtreecommitdiffstats
path: root/thirdparty/libwebp/utils/color_cache.c
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2016-10-11 23:35:58 +0200
committerRémi Verschelde <rverschelde@gmail.com>2016-10-15 11:50:39 +0200
commitee3cf211c6fd4d1e30617467cdbbe945798a68b3 (patch)
treed770150c48c806df4daca66770cde8d5b665a3ff /thirdparty/libwebp/utils/color_cache.c
parentb1e8889d969f5f88539c47c2afac6c9ea2a2dc11 (diff)
downloadredot-engine-ee3cf211c6fd4d1e30617467cdbbe945798a68b3.tar.gz
webp: Make it a module and unbundle libwebp thirdparty files
Note that there are two Godot-specific changes made to libwebp for the javascript/HTML5 platform. They are documented in the README.md.
Diffstat (limited to 'thirdparty/libwebp/utils/color_cache.c')
-rw-r--r--thirdparty/libwebp/utils/color_cache.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/thirdparty/libwebp/utils/color_cache.c b/thirdparty/libwebp/utils/color_cache.c
new file mode 100644
index 0000000000..c34b2e7f1a
--- /dev/null
+++ b/thirdparty/libwebp/utils/color_cache.c
@@ -0,0 +1,49 @@
+// Copyright 2012 Google Inc. All Rights Reserved.
+//
+// Use of this source code is governed by a BSD-style license
+// that can be found in the COPYING file in the root of the source
+// tree. An additional intellectual property rights grant can be found
+// in the file PATENTS. All contributing project authors may
+// be found in the AUTHORS file in the root of the source tree.
+// -----------------------------------------------------------------------------
+//
+// Color Cache for WebP Lossless
+//
+// Author: Jyrki Alakuijala (jyrki@google.com)
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include "./color_cache.h"
+#include "./utils.h"
+
+//------------------------------------------------------------------------------
+// VP8LColorCache.
+
+int VP8LColorCacheInit(VP8LColorCache* const cc, int hash_bits) {
+ const int hash_size = 1 << hash_bits;
+ assert(cc != NULL);
+ assert(hash_bits > 0);
+ cc->colors_ = (uint32_t*)WebPSafeCalloc((uint64_t)hash_size,
+ sizeof(*cc->colors_));
+ if (cc->colors_ == NULL) return 0;
+ cc->hash_shift_ = 32 - hash_bits;
+ cc->hash_bits_ = hash_bits;
+ return 1;
+}
+
+void VP8LColorCacheClear(VP8LColorCache* const cc) {
+ if (cc != NULL) {
+ WebPSafeFree(cc->colors_);
+ cc->colors_ = NULL;
+ }
+}
+
+void VP8LColorCacheCopy(const VP8LColorCache* const src,
+ VP8LColorCache* const dst) {
+ assert(src != NULL);
+ assert(dst != NULL);
+ assert(src->hash_bits_ == dst->hash_bits_);
+ memcpy(dst->colors_, src->colors_,
+ ((size_t)1u << dst->hash_bits_) * sizeof(*dst->colors_));
+}