diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-02-03 14:02:24 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-02-03 14:02:24 +0100 |
commit | 1e1fb5ea2504e548bc17521bdb273c9e59b9cf01 (patch) | |
tree | 6bdc1701a04e4eefb2d0b985ca78f6c53cb845b5 /media/libwebp/utils/color_cache_utils.c | |
parent | fcfa07318b5b25d0bb650aa820d99a8c5c14e61b (diff) | |
parent | 4662aad03a28a6fa049f2c34ab58069718a229fe (diff) | |
download | UXP-1e1fb5ea2504e548bc17521bdb273c9e59b9cf01.tar UXP-1e1fb5ea2504e548bc17521bdb273c9e59b9cf01.tar.gz UXP-1e1fb5ea2504e548bc17521bdb273c9e59b9cf01.tar.lz UXP-1e1fb5ea2504e548bc17521bdb273c9e59b9cf01.tar.xz UXP-1e1fb5ea2504e548bc17521bdb273c9e59b9cf01.zip |
Merge branch 'goanna-gfx'
Diffstat (limited to 'media/libwebp/utils/color_cache_utils.c')
-rw-r--r-- | media/libwebp/utils/color_cache_utils.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/media/libwebp/utils/color_cache_utils.c b/media/libwebp/utils/color_cache_utils.c new file mode 100644 index 000000000..0172590c4 --- /dev/null +++ b/media/libwebp/utils/color_cache_utils.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_utils.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_)); +} |