tor-browser

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

enc_cache.h (2691B)


      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_CACHE_H_
      7 #define LIB_JXL_ENC_CACHE_H_
      8 
      9 #include <jxl/cms_interface.h>
     10 #include <jxl/memory_manager.h>
     11 
     12 #include <cstddef>
     13 #include <cstdint>
     14 #include <memory>
     15 #include <vector>
     16 
     17 #include "lib/jxl/base/data_parallel.h"
     18 #include "lib/jxl/base/rect.h"
     19 #include "lib/jxl/base/status.h"
     20 #include "lib/jxl/dct_util.h"
     21 #include "lib/jxl/enc_ans.h"
     22 #include "lib/jxl/enc_bit_writer.h"
     23 #include "lib/jxl/enc_params.h"
     24 #include "lib/jxl/enc_progressive_split.h"
     25 #include "lib/jxl/frame_header.h"
     26 #include "lib/jxl/image.h"
     27 #include "lib/jxl/passes_state.h"
     28 #include "lib/jxl/quant_weights.h"
     29 
     30 namespace jxl {
     31 
     32 struct AuxOut;
     33 
     34 // Contains encoder state.
     35 struct PassesEncoderState {
     36  explicit PassesEncoderState(JxlMemoryManager* memory_manager)
     37      : shared(memory_manager) {}
     38 
     39  PassesSharedState shared;
     40 
     41  bool streaming_mode = false;
     42  bool initialize_global_state = true;
     43  size_t dc_group_index = 0;
     44 
     45  // Per-pass DCT coefficients for the image. One row per group.
     46  std::vector<std::unique_ptr<ACImage>> coeffs;
     47 
     48  // Raw data for special (reference+DC) frames.
     49  std::vector<std::unique_ptr<BitWriter>> special_frames;
     50 
     51  // For splitting into passes.
     52  ProgressiveSplitter progressive_splitter;
     53 
     54  CompressParams cparams;
     55 
     56  struct PassData {
     57    std::vector<std::vector<Token>> ac_tokens;
     58    std::vector<uint8_t> context_map;
     59    EntropyEncodingData codes;
     60  };
     61 
     62  std::vector<PassData> passes;
     63  std::vector<size_t> histogram_idx;
     64 
     65  // Block sizes seen so far.
     66  uint32_t used_acs = 0;
     67  // Coefficient orders that are non-default.
     68  std::vector<uint32_t> used_orders;
     69 
     70  // Multiplier to be applied to the quant matrices of the x channel.
     71  float x_qm_multiplier = 1.0f;
     72  float b_qm_multiplier = 1.0f;
     73 
     74  ImageF initial_quant_masking1x1;
     75 
     76  JxlMemoryManager* memory_manager() const { return shared.memory_manager; }
     77 };
     78 
     79 // Initialize per-frame information.
     80 class ModularFrameEncoder;
     81 Status InitializePassesEncoder(const FrameHeader& frame_header,
     82                               const Image3F& opsin, const Rect& rect,
     83                               const JxlCmsInterface& cms, ThreadPool* pool,
     84                               PassesEncoderState* passes_enc_state,
     85                               ModularFrameEncoder* modular_frame_encoder,
     86                               AuxOut* aux_out);
     87 
     88 Status ComputeACMetadata(ThreadPool* pool, PassesEncoderState* enc_state,
     89                         ModularFrameEncoder* modular_frame_encoder);
     90 
     91 }  // namespace jxl
     92 
     93 #endif  // LIB_JXL_ENC_CACHE_H_