libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

coeff_order.h (2141B)


      1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
      2 //
      3 // Use of this source code is governed by a BSD-style
      4 // license that can be found in the LICENSE file.
      5 
      6 #ifndef LIB_JXL_COEFF_ORDER_H_
      7 #define LIB_JXL_COEFF_ORDER_H_
      8 
      9 #include <stddef.h>
     10 #include <stdint.h>
     11 
     12 #include "lib/jxl/ac_strategy.h"
     13 #include "lib/jxl/base/common.h"
     14 #include "lib/jxl/base/compiler_specific.h"
     15 #include "lib/jxl/base/status.h"
     16 #include "lib/jxl/coeff_order_fwd.h"
     17 #include "lib/jxl/frame_dimensions.h"
     18 
     19 namespace jxl {
     20 
     21 class BitReader;
     22 
     23 // Those offsets get multiplied by kDCTBlockSize.
     24 
     25 static constexpr size_t kCoeffOrderLimit = 6156;
     26 
     27 static constexpr std::array<size_t, 3 * kNumOrders + 1> kCoeffOrderOffset = {
     28     0,    1,    2,    3,    4,    5,    6,    10,   14,   18,
     29     34,   50,   66,   68,   70,   72,   76,   80,   84,   92,
     30     100,  108,  172,  236,  300,  332,  364,  396,  652,  908,
     31     1164, 1292, 1420, 1548, 2572, 3596, 4620, 5132, 5644, kCoeffOrderLimit};
     32 
     33 static JXL_MAYBE_UNUSED constexpr size_t CoeffOrderOffset(size_t order,
     34                                                           size_t c) {
     35   return kCoeffOrderOffset[3 * order + c] * kDCTBlockSize;
     36 }
     37 
     38 static JXL_MAYBE_UNUSED constexpr size_t kCoeffOrderMaxSize =
     39     kCoeffOrderLimit * kDCTBlockSize;
     40 
     41 // Mapping from AC strategy to order bucket. Strategies with different natural
     42 // orders must have different buckets.
     43 constexpr uint8_t kStrategyOrder[] = {
     44     0, 1, 1, 1, 2, 3, 4, 4, 5,  5,  6,  6,  1,  1,
     45     1, 1, 1, 1, 7, 8, 8, 9, 10, 10, 11, 12, 12,
     46 };
     47 
     48 static_assert(AcStrategy::kNumValidStrategies ==
     49                   sizeof(kStrategyOrder) / sizeof(*kStrategyOrder),
     50               "Update this array when adding or removing AC strategies.");
     51 
     52 constexpr JXL_MAYBE_UNUSED uint32_t kPermutationContexts = 8;
     53 
     54 uint32_t CoeffOrderContext(uint32_t val);
     55 
     56 Status DecodeCoeffOrders(uint16_t used_orders, uint32_t used_acs,
     57                          coeff_order_t* order, BitReader* br);
     58 
     59 Status DecodePermutation(size_t skip, size_t size, coeff_order_t* order,
     60                          BitReader* br);
     61 
     62 }  // namespace jxl
     63 
     64 #endif  // LIB_JXL_COEFF_ORDER_H_