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 <stddef.h> 10 #include <stdint.h> 11 12 #include <vector> 13 14 #include "lib/jxl/ac_strategy.h" 15 #include "lib/jxl/aux_out.h" 16 #include "lib/jxl/base/data_parallel.h" 17 #include "lib/jxl/chroma_from_luma.h" 18 #include "lib/jxl/coeff_order.h" 19 #include "lib/jxl/coeff_order_fwd.h" 20 #include "lib/jxl/common.h" 21 #include "lib/jxl/dct_util.h" 22 #include "lib/jxl/enc_ans.h" 23 #include "lib/jxl/enc_heuristics.h" 24 #include "lib/jxl/enc_params.h" 25 #include "lib/jxl/frame_header.h" 26 #include "lib/jxl/image.h" 27 #include "lib/jxl/image_bundle.h" 28 #include "lib/jxl/passes_state.h" 29 #include "lib/jxl/progressive_split.h" 30 #include "lib/jxl/quant_weights.h" 31 #include "lib/jxl/quantizer.h" 32 33 namespace jxl { 34 35 // Contains encoder state. 36 struct PassesEncoderState { 37 PassesSharedState shared; 38 39 ImageF initial_quant_field; // Invalid in Falcon mode. 40 ImageF initial_quant_masking; // Invalid in Falcon mode. 41 42 // Per-pass DCT coefficients for the image. One row per group. 43 std::vector<std::unique_ptr<ACImage>> coeffs; 44 45 // Raw data for special (reference+DC) frames. 46 std::vector<std::unique_ptr<BitWriter>> special_frames; 47 48 // For splitting into passes. 49 ProgressiveSplitter progressive_splitter; 50 51 CompressParams cparams; 52 53 struct PassData { 54 std::vector<std::vector<Token>> ac_tokens; 55 std::vector<uint8_t> context_map; 56 EntropyEncodingData codes; 57 }; 58 59 std::vector<PassData> passes; 60 std::vector<uint8_t> histogram_idx; 61 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 // Heuristics to be used by the encoder. 70 std::unique_ptr<EncoderHeuristics> heuristics = 71 make_unique<DefaultEncoderHeuristics>(); 72 }; 73 74 // Initialize per-frame information. 75 class ModularFrameEncoder; 76 void InitializePassesEncoder(const Image3F& opsin, ThreadPool* pool, 77 PassesEncoderState* passes_enc_state, 78 ModularFrameEncoder* modular_frame_encoder, 79 AuxOut* aux_out); 80 81 // Working area for ComputeCoefficients (per-group!) 82 struct EncCache { 83 // Allocates memory when first called, shrinks images to current group size. 84 void InitOnce(); 85 86 // TokenizeCoefficients 87 Image3I num_nzeroes; 88 }; 89 90 } // namespace jxl 91 92 #endif // LIB_JXL_ENC_CACHE_H_ 93