Path: blob/master/thirdparty/libwebp/src/enc/cost_enc.h
21733 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>1819#include "src/dec/common_dec.h"20#include "src/dsp/dsp.h"21#include "src/enc/vp8i_enc.h"22#include "src/webp/types.h"2324#ifdef __cplusplus25extern "C" {26#endif2728// On-the-fly info about the current set of residuals. Handy to avoid29// passing zillions of params.30typedef struct VP8Residual VP8Residual;31struct VP8Residual {32int first;33int last;34const int16_t* coeffs;3536int coeff_type;37ProbaArray* prob;38StatsArray* stats;39CostArrayPtr costs;40};4142void VP8InitResidual(int first, int coeff_type,43VP8Encoder* const enc, VP8Residual* const res);4445int VP8RecordCoeffs(int ctx, const VP8Residual* const res);4647// Record proba context used.48static WEBP_INLINE int VP8RecordStats(int bit, proba_t* const stats) {49proba_t p = *stats;50// An overflow is inbound. Note we handle this at 0xfffe0000u instead of51// 0xffff0000u to make sure p + 1u does not overflow.52if (p >= 0xfffe0000u) {53p = ((p + 1u) >> 1) & 0x7fff7fffu; // -> divide the stats by 2.54}55// record bit count (lower 16 bits) and increment total count (upper 16 bits).56p += 0x00010000u + bit;57*stats = p;58return bit;59}6061// Cost of coding one event with probability 'proba'.62static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {63return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];64}6566// Level cost calculations67void VP8CalculateLevelCosts(VP8EncProba* const proba);68static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) {69return VP8LevelFixedCosts[level]70+ table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level];71}7273// Mode costs74extern const uint16_t VP8FixedCostsUV[4];75extern const uint16_t VP8FixedCostsI16[4];76extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES];7778//------------------------------------------------------------------------------7980#ifdef __cplusplus81} // extern "C"82#endif8384#endif // WEBP_ENC_COST_ENC_H_858687