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