Coverage Report

Created: 2025-06-16 07:00

/src/libjxl/lib/jxl/enc_chroma_from_luma.h
Line
Count
Source
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
186
      : memory_manager(memory_manager) {}
40
41
  Status Init(const Rect& rect);
42
43
186
  Status PrepareForThreads(size_t num_threads) {
44
186
    size_t mem_bytes = num_threads * ItemsPerThread() * sizeof(float);
45
186
    JXL_ASSIGN_OR_RETURN(mem, AlignedMemory::Create(memory_manager, mem_bytes));
46
186
    return true;
47
186
  }
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
29.0k
  static size_t ItemsPerThread() {
61
29.0k
    const size_t dct_scratch_size =
62
29.0k
        3 * (MaxVectorSize() / sizeof(float)) * AcStrategy::kMaxBlockDim;
63
29.0k
    const size_t dc_scratch_size =
64
29.0k
        3 * AcStrategy::kMaxCoeffBlocks * AcStrategy::kMaxCoeffBlocks;
65
29.0k
    return AcStrategy::kMaxCoeffArea * 3        // Blocks
66
29.0k
           + kColorTileDim * kColorTileDim * 4  // AC coeff storage
67
29.0k
           + AcStrategy::kMaxCoeffArea * 2      // Scratch space
68
29.0k
           + dct_scratch_size + dc_scratch_size;
69
29.0k
  }
70
};
71
72
}  // namespace jxl
73
74
#endif  // LIB_JXL_ENC_CHROMA_FROM_LUMA_H_