blob: 3bd382f3b989b4be5e479aee0d54af0e36b53210 [file] [log] [blame]
// Copyright 2021 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
// -----------------------------------------------------------------------------
// WP2 encoder: trellis quantization.
// Author: Maryla (
#ifndef WP2_ENC_TRELLIS_H_
#define WP2_ENC_TRELLIS_H_
#include "src/common/lossy/block_size.h"
#include "src/common/lossy/quant_mtx.h"
#include "src/common/lossy/transforms.h"
#include "src/enc/symbols_enc.h"
namespace WP2 {
// Performs coeff optimization by dropping or lowering some coefficients if
// it improves the rd score. Assumes coeffs are stored using the "aom residuals"
// method.
// 'residuals' contains the original coeffs (in frequency space) before
// quantization.
// 'coeffs' contains the quantized version of 'residuals' and will be updated.
// 'dequantized_coeffs' contains the dequantized version of 'coeffs' and will be
// updated.
void Av1CoeffOptimization(Channel channel, TransformPair tx_type, TrfSize tdim,
const QuantMtx& quant, bool first_is_dc,
const int32_t* const residuals, int16_t* const coeffs,
uint32_t* const num_coeffs,
int16_t* const dequantized_coeffs,
SymbolCounter* const counter, float* const rate_cost);
// Removes small coeffs surrounded by many zeros. This is a faster/less accurate
// alternative to full trellis optimization. The number of zeroes required to
// drop a coefficient are deduced based on 'quality_factor' in [0; kQFactorMax].
void DropoutCoeffs(TrfSize tdim, int quality_factor, int16_t* coeffs,
uint32_t* num_coeffs, int16_t* dequantized_coeffs);
// Same as above except that the number of leading/trailing zeros required to
// drop a coeff are explicitly passed in.
void DropoutCoeffs(TrfSize tdim, const uint32_t dropout_num_before,
const uint32_t dropout_num_after, int16_t coeffs[],
uint32_t* num_coeffs, int16_t dequantized_coeffs[]);
} // namespace WP2
#endif // WP2_ENC_TRELLIS_H_