// 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.
// Defines the different kinds of transforms, and heuristics to choose between // them. // `AcStrategy` represents what transform should be used, and which sub-block of // that transform we are currently in. Note that DCT4x4 is applied on all four // 4x4 sub-blocks of an 8x8 block. // `AcStrategyImage` defines which strategy should be used for each 8x8 block // of the image. The highest 4 bits represent the strategy to be used, the // lowest 4 represent the index of the block inside that strategy.
namespace jxl {
// Raw strategy types. enumclass AcStrategyType : uint32_t { // Regular block size DCT
DCT = 0, // Encode pixels without transforming
IDENTITY = 1, // Use 2-by-2 DCT
DCT2X2 = 2, // Use 4-by-4 DCT
DCT4X4 = 3, // Use 16-by-16 DCT
DCT16X16 = 4, // Use 32-by-32 DCT
DCT32X32 = 5, // Use 16-by-8 DCT
DCT16X8 = 6, // Use 8-by-16 DCT
DCT8X16 = 7, // Use 32-by-8 DCT
DCT32X8 = 8, // Use 8-by-32 DCT
DCT8X32 = 9, // Use 32-by-16 DCT
DCT32X16 = 10, // Use 16-by-32 DCT
DCT16X32 = 11, // 4x8 and 8x4 DCT
DCT4X8 = 12,
DCT8X4 = 13, // Corner-DCT.
AFV0 = 14,
AFV1 = 15,
AFV2 = 16,
AFV3 = 17, // Larger DCTs
DCT64X64 = 18,
DCT64X32 = 19,
DCT32X64 = 20, // No transforms smaller than 64x64 are allowed below.
DCT128X128 = 21,
DCT128X64 = 22,
DCT64X128 = 23,
DCT256X256 = 24,
DCT256X128 = 25,
DCT128X256 = 26
};
class AcStrategy { public: // Extremal values for the number of blocks/coefficients of a single strategy. static constexpr size_t kMaxCoeffBlocks = 32; static constexpr size_t kMaxBlockDim = kBlockDim * kMaxCoeffBlocks; // Maximum number of coefficients in a block. Guaranteed to be a multiple of // the vector size. static constexpr size_t kMaxCoeffArea = kMaxBlockDim * kMaxBlockDim;
static_assert((kMaxCoeffArea * sizeof(float)) % hwy::kMaxVectorSize == 0, "Coefficient area is not a multiple of vector size");
// Returns true if this block is the first 8x8 block (i.e. top-left) of a // possibly multi-block strategy.
JXL_INLINE bool IsFirstBlock() const { return is_first_; }
// Returns the raw strategy value. Should only be used for tokenization.
JXL_INLINE uint8_t RawStrategy() const { returnstatic_cast<uint8_t>(strategy_);
}
// "Natural order" means the order of increasing of "anisotropic" frequency of // continuous version of DCT basis. // Round-trip, for any given strategy s: // X = NaturalCoeffOrder(s)[NaturalCoeffOrderLutN(s)[X]] // X = NaturalCoeffOrderLut(s)[NaturalCoeffOrderN(s)[X]] void ComputeNaturalCoeffOrder(coeff_order_t* order) const; void ComputeNaturalCoeffOrderLut(coeff_order_t* lut) const;
// Number of 8x8 blocks that this strategy will cover. 0 for non-top-left // blocks inside a multi-block transform.
JXL_INLINE size_t covered_blocks_x() const { static constexpr uint8_t kLut[] = {1, 1, 1, 1, 2, 4, 1, 2, 1,
4, 2, 4, 1, 1, 1, 1, 1, 1,
8, 4, 8, 16, 8, 16, 32, 16, 32};
static_assert(sizeof(kLut) / sizeof(*kLut) == kNumValidStrategies, "Update LUT"); return kLut[static_cast<size_t>(strategy_)];
}
// Class to use a certain row of the AC strategy. class AcStrategyRow { public: explicit AcStrategyRow(const uint8_t* row) : row_(row) {}
AcStrategy operator[](size_t x) const {
AcStrategyType strategy = static_cast<AcStrategyType>(row_[x] >> 1); bool is_first = static_cast<bool>(row_[x] & 1); return AcStrategy(strategy, is_first);
}
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.