2012-04-10 17:23:38 -07:00
|
|
|
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
|
|
//
|
2013-06-06 23:05:58 -07:00
|
|
|
// 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.
|
2012-04-10 17:23:38 -07:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Color Cache for WebP Lossless
|
|
|
|
//
|
2012-07-19 16:09:47 -07:00
|
|
|
// Author: Jyrki Alakuijala (jyrki@google.com)
|
2012-04-10 17:23:38 -07:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
2014-09-24 09:38:52 +02:00
|
|
|
#include <string.h>
|
2012-04-10 17:23:38 -07:00
|
|
|
#include "./color_cache.h"
|
2012-08-01 12:06:04 -07:00
|
|
|
#include "../utils/utils.h"
|
2012-04-10 17:23:38 -07:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// VP8LColorCache.
|
|
|
|
|
|
|
|
int VP8LColorCacheInit(VP8LColorCache* const cc, int hash_bits) {
|
2012-08-01 00:32:12 -07:00
|
|
|
const int hash_size = 1 << hash_bits;
|
2012-04-10 17:23:38 -07:00
|
|
|
assert(cc != NULL);
|
2012-08-01 00:32:12 -07:00
|
|
|
assert(hash_bits > 0);
|
2012-08-01 12:06:04 -07:00
|
|
|
cc->colors_ = (uint32_t*)WebPSafeCalloc((uint64_t)hash_size,
|
|
|
|
sizeof(*cc->colors_));
|
2012-04-10 17:23:38 -07:00
|
|
|
if (cc->colors_ == NULL) return 0;
|
|
|
|
cc->hash_shift_ = 32 - hash_bits;
|
2014-09-24 09:38:52 +02:00
|
|
|
cc->hash_bits_ = hash_bits;
|
2012-04-10 17:23:38 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-04-12 11:31:17 +00:00
|
|
|
void VP8LColorCacheClear(VP8LColorCache* const cc) {
|
2012-04-10 17:23:38 -07:00
|
|
|
if (cc != NULL) {
|
2014-03-27 23:27:32 +01:00
|
|
|
WebPSafeFree(cc->colors_);
|
2012-07-16 19:13:58 -07:00
|
|
|
cc->colors_ = NULL;
|
2012-04-10 17:23:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 09:38:52 +02:00
|
|
|
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_,
|
2015-01-16 17:46:38 -08:00
|
|
|
((size_t)1u << dst->hash_bits_) * sizeof(*dst->colors_));
|
2014-09-24 09:38:52 +02:00
|
|
|
}
|