enc_adaptive_quantization.h (2502B)
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_ADAPTIVE_QUANTIZATION_H_ 7 #define LIB_JXL_ENC_ADAPTIVE_QUANTIZATION_H_ 8 9 #include <jxl/cms_interface.h> 10 #include <stddef.h> 11 12 #include "lib/jxl/ac_strategy.h" 13 #include "lib/jxl/base/data_parallel.h" 14 #include "lib/jxl/enc_cache.h" 15 #include "lib/jxl/frame_header.h" 16 #include "lib/jxl/image.h" 17 18 // Heuristics to find a good quantizer for a given image. InitialQuantField 19 // produces a quantization field (i.e. relative quantization amounts for each 20 // block) out of an opsin-space image. `InitialQuantField` uses heuristics, 21 // `FindBestQuantizer` (in non-fast mode) will run multiple encoding-decoding 22 // steps and try to improve the given quant field. 23 24 namespace jxl { 25 26 struct AuxOut; 27 28 // Returns an image subsampled by kBlockDim in each direction. If the value 29 // at pixel (x,y) in the returned image is greater than 1.0, it means that 30 // more fine-grained quantization should be used in the corresponding block 31 // of the input image, while a value less than 1.0 indicates that less 32 // fine-grained quantization should be enough. Returns a mask, too, which 33 // can later be used to make better decisions about ac strategy. 34 StatusOr<ImageF> InitialQuantField(float butteraugli_target, 35 const Image3F& opsin, const Rect& rect, 36 ThreadPool* pool, float rescale, 37 ImageF* initial_quant_mask, 38 ImageF* initial_quant_mask1x1); 39 40 float InitialQuantDC(float butteraugli_target); 41 42 void AdjustQuantField(const AcStrategyImage& ac_strategy, const Rect& rect, 43 float butteraugli_target, ImageF* quant_field); 44 45 // Returns a quantizer that uses an adjusted version of the provided 46 // quant_field. Also computes the dequant_map corresponding to the given 47 // dequant_float_map and chosen quantization levels. 48 // `linear` is only used in Kitten mode or slower. 49 Status FindBestQuantizer(const FrameHeader& frame_header, const Image3F* linear, 50 const Image3F& opsin, ImageF& quant_field, 51 PassesEncoderState* enc_state, 52 const JxlCmsInterface& cms, ThreadPool* pool, 53 AuxOut* aux_out, double rescale = 1.0); 54 55 } // namespace jxl 56 57 #endif // LIB_JXL_ENC_ADAPTIVE_QUANTIZATION_H_