// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
// Quantizes DC and AC coefficients, with separate quantization tables according // to the quant_kind (which is currently computed from the AC strategy and the // block index inside that strategy).
namespace jxl {
enumclass AcStrategyType : uint32_t;
static constexpr int kGlobalScaleDenom = 1 << 16; static constexpr int kGlobalScaleNumerator = 4096;
// zero-biases for quantizing channels X, Y, B static constexpr float kZeroBiasDefault[3] = {0.5f, 0.5f, 0.5f};
// Returns adjusted version of a quantized integer, such that its value is // closer to the expected value of the original. // The residuals of AC coefficients that we quantize are not uniformly // distributed. Numerical experiments show that they have a distribution with // the "shape" of 1/(1+x^2) [up to some coefficients]. This means that the // expected value of a coefficient that gets quantized to x will not be x // itself, but (at least with reasonable approximation): // - 0 if x is 0 // - x * biases[c] if x is 1 or -1 // - x - biases[3]/x otherwise // This follows from computing the distribution of the quantization bias, which // can be approximated fairly well by <constant>/x when |x| is at least two. static constexpr float kBiasNumerator = 0.145f;
class Quantizer { public: explicit Quantizer(const DequantMatrices& dequant);
Quantizer(const DequantMatrices& dequant, int quant_dc, int global_scale);
// Recomputes other derived fields after global_scale_ has changed. void RecomputeFromGlobalScale() {
global_scale_float_ = global_scale_ * (1.0 / kGlobalScaleDenom);
inv_global_scale_ = 1.0 * kGlobalScaleDenom / global_scale_;
inv_quant_dc_ = inv_global_scale_ / quant_dc_; for (size_t c = 0; c < 3; c++) {
mul_dc_[c] = GetDcStep(c);
inv_mul_dc_[c] = GetInvDcStep(c);
}
}
// Returns scaling factor such that Scale() * (RawDC() or RawQuantField()) // pixels yields the same float values returned by GetQuantField.
JXL_INLINE float Scale() const { return global_scale_float_; }
// Returns the DC quantization base value, which is currently global (not // adaptive). The actual scale factor used to dequantize pixels in channel c // is: inv_quant_dc() * dequant_->DCQuant(c). float inv_quant_dc() const { return inv_quant_dc_; }
// Dequantize by multiplying with this times dequant_matrix. float inv_quant_ac(int32_t quant) const { return inv_global_scale_ / quant; }
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.