libjxl

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

enc_ac_strategy.h (2816B)


      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_ENC_AC_STRATEGY_H_
      7 #define LIB_JXL_ENC_AC_STRATEGY_H_
      8 
      9 #include <cstddef>
     10 
     11 #include "lib/jxl/ac_strategy.h"
     12 #include "lib/jxl/base/compiler_specific.h"
     13 #include "lib/jxl/base/status.h"
     14 #include "lib/jxl/chroma_from_luma.h"
     15 #include "lib/jxl/enc_cache.h"
     16 #include "lib/jxl/enc_params.h"
     17 #include "lib/jxl/frame_dimensions.h"
     18 #include "lib/jxl/image.h"
     19 #include "lib/jxl/quant_weights.h"
     20 
     21 // `FindBestAcStrategy` uses heuristics to choose which AC strategy should be
     22 // used in each block, as well as the initial quantization field.
     23 
     24 namespace jxl {
     25 
     26 struct AuxOut;
     27 
     28 // AC strategy selection: utility struct.
     29 
     30 struct ACSConfig {
     31   const DequantMatrices* JXL_RESTRICT dequant;
     32   const float* JXL_RESTRICT quant_field_row;
     33   size_t quant_field_stride;
     34   const float* JXL_RESTRICT masking_field_row;
     35   size_t masking_field_stride;
     36   const float* JXL_RESTRICT masking1x1_field_row;
     37   size_t masking1x1_field_stride;
     38   const float* JXL_RESTRICT src_rows[3];
     39   size_t src_stride;
     40   float info_loss_multiplier;
     41   float cost_delta;
     42   float zeros_mul;
     43   const float& Pixel(size_t c, size_t x, size_t y) const {
     44     return src_rows[c][y * src_stride + x];
     45   }
     46   float Masking(size_t bx, size_t by) const {
     47     JXL_DASSERT(masking_field_row[by * masking_field_stride + bx] > 0);
     48     return masking_field_row[by * masking_field_stride + bx];
     49   }
     50   const float* MaskingPtr1x1(size_t bx, size_t by) const {
     51     JXL_DASSERT(masking1x1_field_row[by * masking1x1_field_stride + bx] > 0);
     52     return &masking1x1_field_row[by * masking1x1_field_stride + bx];
     53   }
     54   float Quant(size_t bx, size_t by) const {
     55     JXL_DASSERT(quant_field_row[by * quant_field_stride + bx] > 0);
     56     return quant_field_row[by * quant_field_stride + bx];
     57   }
     58 };
     59 
     60 struct AcStrategyHeuristics {
     61   explicit AcStrategyHeuristics(const CompressParams& cparams)
     62       : cparams(cparams), mem_per_thread(0), qmem_per_thread(0) {}
     63   void Init(const Image3F& src, const Rect& rect_in, const ImageF& quant_field,
     64             const ImageF& mask, const ImageF& mask1x1,
     65             DequantMatrices* matrices);
     66   void PrepareForThreads(std::size_t num_threads);
     67   void ProcessRect(const Rect& rect, const ColorCorrelationMap& cmap,
     68                    AcStrategyImage* ac_strategy, size_t thread);
     69   Status Finalize(const FrameDimensions& frame_dim,
     70                   const AcStrategyImage& ac_strategy, AuxOut* aux_out);
     71   const CompressParams& cparams;
     72   ACSConfig config = {};
     73   size_t mem_per_thread;
     74   hwy::AlignedFreeUniquePtr<float[]> mem;
     75   size_t qmem_per_thread;
     76   hwy::AlignedFreeUniquePtr<uint32_t[]> qmem;
     77 };
     78 
     79 }  // namespace jxl
     80 
     81 #endif  // LIB_JXL_ENC_AC_STRATEGY_H_