Blame src/enc/cost_enc.h

Packit 9c6abc
// Copyright 2011 Google Inc. All Rights Reserved.
Packit 9c6abc
//
Packit 9c6abc
// Use of this source code is governed by a BSD-style license
Packit 9c6abc
// that can be found in the COPYING file in the root of the source
Packit 9c6abc
// tree. An additional intellectual property rights grant can be found
Packit 9c6abc
// in the file PATENTS. All contributing project authors may
Packit 9c6abc
// be found in the AUTHORS file in the root of the source tree.
Packit 9c6abc
// -----------------------------------------------------------------------------
Packit 9c6abc
//
Packit 9c6abc
// Cost tables for level and modes.
Packit 9c6abc
//
Packit 9c6abc
// Author: Skal (pascal.massimino@gmail.com)
Packit 9c6abc
Packit 9c6abc
#ifndef WEBP_ENC_COST_ENC_H_
Packit 9c6abc
#define WEBP_ENC_COST_ENC_H_
Packit 9c6abc
Packit 9c6abc
#include <assert.h>
Packit 9c6abc
#include <stdlib.h>
Packit 9c6abc
#include "src/enc/vp8i_enc.h"
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
extern "C" {
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
// On-the-fly info about the current set of residuals. Handy to avoid
Packit 9c6abc
// passing zillions of params.
Packit 9c6abc
typedef struct VP8Residual VP8Residual;
Packit 9c6abc
struct VP8Residual {
Packit 9c6abc
  int first;
Packit 9c6abc
  int last;
Packit 9c6abc
  const int16_t* coeffs;
Packit 9c6abc
Packit 9c6abc
  int coeff_type;
Packit 9c6abc
  ProbaArray*   prob;
Packit 9c6abc
  StatsArray*   stats;
Packit 9c6abc
  CostArrayPtr  costs;
Packit 9c6abc
};
Packit 9c6abc
Packit 9c6abc
void VP8InitResidual(int first, int coeff_type,
Packit 9c6abc
                     VP8Encoder* const enc, VP8Residual* const res);
Packit 9c6abc
Packit 9c6abc
int VP8RecordCoeffs(int ctx, const VP8Residual* const res);
Packit 9c6abc
Packit 9c6abc
// Record proba context used.
Packit 9c6abc
static WEBP_INLINE int VP8RecordStats(int bit, proba_t* const stats) {
Packit 9c6abc
  proba_t p = *stats;
Packit 9c6abc
  // An overflow is inbound. Note we handle this at 0xfffe0000u instead of
Packit 9c6abc
  // 0xffff0000u to make sure p + 1u does not overflow.
Packit 9c6abc
  if (p >= 0xfffe0000u) {
Packit 9c6abc
    p = ((p + 1u) >> 1) & 0x7fff7fffu;  // -> divide the stats by 2.
Packit 9c6abc
  }
Packit 9c6abc
  // record bit count (lower 16 bits) and increment total count (upper 16 bits).
Packit 9c6abc
  p += 0x00010000u + bit;
Packit 9c6abc
  *stats = p;
Packit 9c6abc
  return bit;
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
// Cost of coding one event with probability 'proba'.
Packit 9c6abc
static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
Packit 9c6abc
  return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
// Level cost calculations
Packit 9c6abc
extern const uint16_t VP8LevelCodes[MAX_VARIABLE_LEVEL][2];
Packit 9c6abc
void VP8CalculateLevelCosts(VP8EncProba* const proba);
Packit 9c6abc
static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) {
Packit 9c6abc
  return VP8LevelFixedCosts[level]
Packit 9c6abc
       + table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level];
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
// Mode costs
Packit 9c6abc
extern const uint16_t VP8FixedCostsUV[4];
Packit 9c6abc
extern const uint16_t VP8FixedCostsI16[4];
Packit 9c6abc
extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES];
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
}    // extern "C"
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
#endif  /* WEBP_ENC_COST_ENC_H_ */