Path: blob/master/thirdparty/libwebp/src/enc/cost_enc.h
9913 views
// Copyright 2011 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// Cost tables for level and modes.10//11// Author: Skal ([email protected])1213#ifndef WEBP_ENC_COST_ENC_H_14#define WEBP_ENC_COST_ENC_H_1516#include <assert.h>17#include <stdlib.h>18#include "src/enc/vp8i_enc.h"1920#ifdef __cplusplus21extern "C" {22#endif2324// On-the-fly info about the current set of residuals. Handy to avoid25// passing zillions of params.26typedef struct VP8Residual VP8Residual;27struct VP8Residual {28int first;29int last;30const int16_t* coeffs;3132int coeff_type;33ProbaArray* prob;34StatsArray* stats;35CostArrayPtr costs;36};3738void VP8InitResidual(int first, int coeff_type,39VP8Encoder* const enc, VP8Residual* const res);4041int VP8RecordCoeffs(int ctx, const VP8Residual* const res);4243// Record proba context used.44static WEBP_INLINE int VP8RecordStats(int bit, proba_t* const stats) {45proba_t p = *stats;46// An overflow is inbound. Note we handle this at 0xfffe0000u instead of47// 0xffff0000u to make sure p + 1u does not overflow.48if (p >= 0xfffe0000u) {49p = ((p + 1u) >> 1) & 0x7fff7fffu; // -> divide the stats by 2.50}51// record bit count (lower 16 bits) and increment total count (upper 16 bits).52p += 0x00010000u + bit;53*stats = p;54return bit;55}5657// Cost of coding one event with probability 'proba'.58static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {59return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];60}6162// Level cost calculations63void VP8CalculateLevelCosts(VP8EncProba* const proba);64static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) {65return VP8LevelFixedCosts[level]66+ table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level];67}6869// Mode costs70extern const uint16_t VP8FixedCostsUV[4];71extern const uint16_t VP8FixedCostsI16[4];72extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES];7374//------------------------------------------------------------------------------7576#ifdef __cplusplus77} // extern "C"78#endif7980#endif // WEBP_ENC_COST_ENC_H_818283