enc_chroma_from_luma.h (2355B)
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_CHROMA_FROM_LUMA_H_ 7 #define LIB_JXL_ENC_CHROMA_FROM_LUMA_H_ 8 9 // Chroma-from-luma, computed using heuristics to determine the best linear 10 // model for the X and B channels from the Y channel. 11 12 #include <jxl/memory_manager.h> 13 14 #include <cstddef> 15 #include <cstdint> 16 17 #include "lib/jxl/ac_strategy.h" 18 #include "lib/jxl/base/rect.h" 19 #include "lib/jxl/base/status.h" 20 #include "lib/jxl/chroma_from_luma.h" 21 #include "lib/jxl/enc_bit_writer.h" 22 #include "lib/jxl/image.h" 23 #include "lib/jxl/memory_manager_internal.h" 24 #include "lib/jxl/quant_weights.h" 25 #include "lib/jxl/simd_util.h" 26 27 namespace jxl { 28 29 struct AuxOut; 30 enum class LayerType : uint8_t; 31 class Quantizer; 32 33 Status ColorCorrelationEncodeDC(const ColorCorrelation& color_correlation, 34 BitWriter* writer, LayerType layer, 35 AuxOut* aux_out); 36 37 struct CfLHeuristics { 38 explicit CfLHeuristics(JxlMemoryManager* memory_manager) 39 : memory_manager(memory_manager) {} 40 41 Status Init(const Rect& rect); 42 43 Status PrepareForThreads(size_t num_threads) { 44 size_t mem_bytes = num_threads * ItemsPerThread() * sizeof(float); 45 JXL_ASSIGN_OR_RETURN(mem, AlignedMemory::Create(memory_manager, mem_bytes)); 46 return true; 47 } 48 49 Status ComputeTile(const Rect& r, const Image3F& opsin, 50 const Rect& opsin_rect, const DequantMatrices& dequant, 51 const AcStrategyImage* ac_strategy, 52 const ImageI* raw_quant_field, const Quantizer* quantizer, 53 bool fast, size_t thread, ColorCorrelationMap* cmap); 54 55 JxlMemoryManager* memory_manager; 56 ImageF dc_values; 57 AlignedMemory mem; 58 59 // Working set is too large for stack; allocate dynamically. 60 static size_t ItemsPerThread() { 61 const size_t dct_scratch_size = 62 3 * (MaxVectorSize() / sizeof(float)) * AcStrategy::kMaxBlockDim; 63 return AcStrategy::kMaxCoeffArea * 3 // Blocks 64 + kColorTileDim * kColorTileDim * 4 // AC coeff storage 65 + AcStrategy::kMaxCoeffArea * 2 // Scratch space 66 + dct_scratch_size; 67 } 68 }; 69 70 } // namespace jxl 71 72 #endif // LIB_JXL_ENC_CHROMA_FROM_LUMA_H_