enc_chroma_from_luma.h (1959B)
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 <cstddef> 13 #include <hwy/aligned_allocator.h> 14 15 #include "lib/jxl/ac_strategy.h" 16 #include "lib/jxl/chroma_from_luma.h" 17 #include "lib/jxl/enc_bit_writer.h" 18 #include "lib/jxl/image.h" 19 #include "lib/jxl/quant_weights.h" 20 #include "lib/jxl/simd_util.h" 21 22 namespace jxl { 23 24 struct AuxOut; 25 class Quantizer; 26 27 void ColorCorrelationMapEncodeDC(const ColorCorrelationMap& map, 28 BitWriter* writer, size_t layer, 29 AuxOut* aux_out); 30 31 struct CfLHeuristics { 32 Status Init(const Rect& rect); 33 34 void PrepareForThreads(size_t num_threads) { 35 mem = hwy::AllocateAligned<float>(num_threads * ItemsPerThread()); 36 } 37 38 void ComputeTile(const Rect& r, const Image3F& opsin, const Rect& opsin_rect, 39 const DequantMatrices& dequant, 40 const AcStrategyImage* ac_strategy, 41 const ImageI* raw_quant_field, const Quantizer* quantizer, 42 bool fast, size_t thread, ColorCorrelationMap* cmap); 43 44 ImageF dc_values; 45 hwy::AlignedFreeUniquePtr<float[]> mem; 46 47 // Working set is too large for stack; allocate dynamically. 48 static size_t ItemsPerThread() { 49 const size_t dct_scratch_size = 50 3 * (MaxVectorSize() / sizeof(float)) * AcStrategy::kMaxBlockDim; 51 return AcStrategy::kMaxCoeffArea * 3 // Blocks 52 + kColorTileDim * kColorTileDim * 4 // AC coeff storage 53 + AcStrategy::kMaxCoeffArea * 2 // Scratch space 54 + dct_scratch_size; 55 } 56 }; 57 58 } // namespace jxl 59 60 #endif // LIB_JXL_ENC_CHROMA_FROM_LUMA_H_