Coverage Report

Created: 2025-06-16 07:00

/src/libjxl/lib/jxl/enc_ac_strategy.h
Line
Count
Source (jump to first uncovered line)
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_AC_STRATEGY_H_
7
#define LIB_JXL_ENC_AC_STRATEGY_H_
8
9
#include <jxl/memory_manager.h>
10
11
#include <cstddef>
12
13
#include "lib/jxl/base/compiler_specific.h"
14
#include "lib/jxl/base/rect.h"
15
#include "lib/jxl/base/status.h"
16
#include "lib/jxl/chroma_from_luma.h"
17
#include "lib/jxl/enc_cache.h"
18
#include "lib/jxl/enc_params.h"
19
#include "lib/jxl/frame_dimensions.h"
20
#include "lib/jxl/image.h"
21
#include "lib/jxl/memory_manager_internal.h"
22
#include "lib/jxl/quant_weights.h"
23
24
// `FindBestAcStrategy` uses heuristics to choose which AC strategy should be
25
// used in each block, as well as the initial quantization field.
26
27
namespace jxl {
28
29
struct AuxOut;
30
class AcStrategyImage;
31
32
// AC strategy selection: utility struct.
33
34
struct ACSConfig {
35
  const DequantMatrices* JXL_RESTRICT dequant;
36
  const float* JXL_RESTRICT quant_field_row;
37
  size_t quant_field_stride;
38
  const float* JXL_RESTRICT masking_field_row;
39
  size_t masking_field_stride;
40
  const float* JXL_RESTRICT masking1x1_field_row;
41
  size_t masking1x1_field_stride;
42
  size_t mask1x1_xsize;
43
  const float* JXL_RESTRICT src_rows[3];
44
  size_t src_stride;
45
  float info_loss_multiplier;
46
  float cost_delta;
47
  float zeros_mul;
48
15.1M
  const float& Pixel(size_t c, size_t x, size_t y) const {
49
15.1M
    return src_rows[c][y * src_stride + x];
50
15.1M
  }
51
0
  float Masking(size_t bx, size_t by) const {
52
0
    JXL_DASSERT(masking_field_row[by * masking_field_stride + bx] > 0);
53
0
    return masking_field_row[by * masking_field_stride + bx];
54
0
  }
55
223M
  const float* MaskingPtr1x1(size_t bx, size_t by) const {
56
223M
    JXL_DASSERT(masking1x1_field_row[by * masking1x1_field_stride + bx] > 0);
57
223M
    return &masking1x1_field_row[by * masking1x1_field_stride + bx];
58
223M
  }
59
9.30M
  float Quant(size_t bx, size_t by) const {
60
9.30M
    JXL_DASSERT(quant_field_row[by * quant_field_stride + bx] > 0);
61
9.30M
    return quant_field_row[by * quant_field_stride + bx];
62
9.30M
  }
63
};
64
65
struct AcStrategyHeuristics {
66
  explicit AcStrategyHeuristics(JxlMemoryManager* memory_manager,
67
                                const CompressParams& cparams)
68
186
      : memory_manager(memory_manager),
69
186
        cparams(cparams),
70
186
        mem_per_thread(0),
71
186
        qmem_per_thread(0) {}
72
  Status Init(const Image3F& src, const Rect& rect_in,
73
              const ImageF& quant_field, const ImageF& mask,
74
              const ImageF& mask1x1, DequantMatrices* matrices);
75
  Status PrepareForThreads(std::size_t num_threads);
76
  Status ProcessRect(const Rect& rect, const ColorCorrelationMap& cmap,
77
                     AcStrategyImage* ac_strategy, size_t thread);
78
  Status Finalize(const FrameDimensions& frame_dim,
79
                  const AcStrategyImage& ac_strategy, AuxOut* aux_out);
80
  JxlMemoryManager* memory_manager;
81
  const CompressParams& cparams;
82
  ACSConfig config = {};
83
  size_t mem_per_thread;
84
  AlignedMemory mem;
85
  size_t qmem_per_thread;
86
  AlignedMemory qmem;
87
};
88
89
}  // namespace jxl
90
91
#endif  // LIB_JXL_ENC_AC_STRATEGY_H_