tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

passes_state.h (3083B)


      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_PASSES_STATE_H_
      7 #define LIB_JXL_PASSES_STATE_H_
      8 
      9 #include <jxl/memory_manager.h>
     10 
     11 #include <array>
     12 #include <cstddef>
     13 #include <vector>
     14 
     15 #include "lib/jxl/ac_context.h"
     16 #include "lib/jxl/ac_strategy.h"
     17 #include "lib/jxl/base/common.h"
     18 #include "lib/jxl/base/compiler_specific.h"
     19 #include "lib/jxl/base/status.h"
     20 #include "lib/jxl/chroma_from_luma.h"
     21 #include "lib/jxl/coeff_order_fwd.h"
     22 #include "lib/jxl/dec_patch_dictionary.h"
     23 #include "lib/jxl/frame_dimensions.h"
     24 #include "lib/jxl/frame_header.h"
     25 #include "lib/jxl/image.h"
     26 #include "lib/jxl/image_bundle.h"
     27 #include "lib/jxl/image_metadata.h"
     28 #include "lib/jxl/noise.h"
     29 #include "lib/jxl/quant_weights.h"
     30 #include "lib/jxl/quantizer.h"
     31 #include "lib/jxl/splines.h"
     32 
     33 // Structures that hold the (en/de)coder state for a JPEG XL kVarDCT
     34 // (en/de)coder.
     35 
     36 namespace jxl {
     37 
     38 struct ImageFeatures {
     39  explicit ImageFeatures(JxlMemoryManager* memory_manager_)
     40      : patches(memory_manager_) {}
     41  NoiseParams noise_params;
     42  PatchDictionary patches;
     43  Splines splines;
     44 };
     45 
     46 // State common to both encoder and decoder.
     47 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
     48 struct PassesSharedState {
     49  explicit PassesSharedState(JxlMemoryManager* memory_manager_)
     50      : memory_manager(memory_manager_), image_features(memory_manager_) {
     51    for (auto& reference_frame : reference_frames) {
     52      reference_frame.frame = jxl::make_unique<ImageBundle>(memory_manager_);
     53    }
     54  }
     55 
     56  JxlMemoryManager* memory_manager;
     57  const CodecMetadata* metadata;
     58 
     59  FrameDimensions frame_dim;
     60 
     61  // Control fields and parameters.
     62  AcStrategyImage ac_strategy;
     63 
     64  // Dequant matrices + quantizer.
     65  DequantMatrices matrices;
     66  Quantizer quantizer{matrices};
     67  ImageI raw_quant_field;
     68 
     69  // Per-block side information for EPF detail preservation.
     70  ImageB epf_sharpness;
     71 
     72  ColorCorrelationMap cmap;
     73 
     74  ImageFeatures image_features;
     75 
     76  // Memory area for storing coefficient orders.
     77  // `coeff_order_size` is the size used by *one* set of coefficient orders (at
     78  // most kMaxCoeffOrderSize). A set of coefficient orders is present for each
     79  // pass.
     80  size_t coeff_order_size = 0;
     81  std::vector<coeff_order_t> coeff_orders;
     82 
     83  // Decoder-side DC and quantized DC.
     84  ImageB quant_dc;
     85  Image3F dc_storage;
     86  const Image3F* JXL_RESTRICT dc = &dc_storage;
     87 
     88  BlockCtxMap block_ctx_map;
     89 
     90  Image3F dc_frames[4];
     91 
     92  std::array<ReferceFrame, 4> reference_frames;
     93 
     94  // Number of pre-clustered set of histograms (with the same ctx map), per
     95  // pass. Encoded as num_histograms_ - 1.
     96  size_t num_histograms = 0;
     97 };
     98 
     99 // Initialized the state information that is shared between encoder and decoder.
    100 Status InitializePassesSharedState(const FrameHeader& frame_header,
    101                                   PassesSharedState* JXL_RESTRICT shared,
    102                                   bool encoder = false);
    103 
    104 }  // namespace jxl
    105 
    106 #endif  // LIB_JXL_PASSES_STATE_H_