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/enc/cost_enc.h | |
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/enc/cost_enc.h')
-rw-r--r-- | media/libwebp/enc/cost_enc.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/media/libwebp/enc/cost_enc.h b/media/libwebp/enc/cost_enc.h new file mode 100644 index 000000000..99e4b37aa --- /dev/null +++ b/media/libwebp/enc/cost_enc.h @@ -0,0 +1,82 @@ +// Copyright 2011 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. +// ----------------------------------------------------------------------------- +// +// Cost tables for level and modes. +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_ENC_COST_H_ +#define WEBP_ENC_COST_H_ + +#include <assert.h> +#include <stdlib.h> +#include "./vp8i_enc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// On-the-fly info about the current set of residuals. Handy to avoid +// passing zillions of params. +typedef struct VP8Residual VP8Residual; +struct VP8Residual { + int first; + int last; + const int16_t* coeffs; + + int coeff_type; + ProbaArray* prob; + StatsArray* stats; + CostArrayPtr costs; +}; + +void VP8InitResidual(int first, int coeff_type, + VP8Encoder* const enc, VP8Residual* const res); + +int VP8RecordCoeffs(int ctx, const VP8Residual* const res); + +// Record proba context used. +static WEBP_INLINE int VP8RecordStats(int bit, proba_t* const stats) { + proba_t p = *stats; + // An overflow is inbound. Note we handle this at 0xfffe0000u instead of + // 0xffff0000u to make sure p + 1u does not overflow. + if (p >= 0xfffe0000u) { + p = ((p + 1u) >> 1) & 0x7fff7fffu; // -> divide the stats by 2. + } + // record bit count (lower 16 bits) and increment total count (upper 16 bits). + p += 0x00010000u + bit; + *stats = p; + return bit; +} + +// Cost of coding one event with probability 'proba'. +static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) { + return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba]; +} + +// Level cost calculations +extern const uint16_t VP8LevelCodes[MAX_VARIABLE_LEVEL][2]; +void VP8CalculateLevelCosts(VP8EncProba* const proba); +static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) { + return VP8LevelFixedCosts[level] + + table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level]; +} + +// Mode costs +extern const uint16_t VP8FixedCostsUV[4]; +extern const uint16_t VP8FixedCostsI16[4]; +extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES]; + +//------------------------------------------------------------------------------ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_ENC_COST_H_ */ |