Coverage Report

Created: 2025-09-08 07:52

/src/libjxl/lib/jxl/chroma_from_luma.cc
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
#include "lib/jxl/chroma_from_luma.h"
7
8
#include <jxl/memory_manager.h>
9
10
#include <cstddef>
11
#include <cstdlib>  // abs
12
#include <limits>
13
14
#include "lib/jxl/base/common.h"
15
#include "lib/jxl/fields.h"
16
#include "lib/jxl/image_ops.h"
17
18
namespace jxl {
19
20
5.88k
Status ColorCorrelation::DecodeDC(BitReader* br) {
21
5.88k
  if (br->ReadFixedBits<1>() == 1) {
22
    // All default.
23
23
    return true;
24
23
  }
25
5.86k
  SetColorFactor(U32Coder::Read(kColorFactorDist, br));
26
5.86k
  JXL_RETURN_IF_ERROR(F16Coder::Read(br, &base_correlation_x_));
27
5.86k
  if (std::abs(base_correlation_x_) > 4.0f) {
28
0
    return JXL_FAILURE("Base X correlation is out of range");
29
0
  }
30
5.86k
  JXL_RETURN_IF_ERROR(F16Coder::Read(br, &base_correlation_b_));
31
5.86k
  if (std::abs(base_correlation_b_) > 4.0f) {
32
1
    return JXL_FAILURE("Base B correlation is out of range");
33
1
  }
34
5.86k
  ytox_dc_ = static_cast<int>(br->ReadFixedBits<kBitsPerByte>()) +
35
5.86k
             std::numeric_limits<int8_t>::min();
36
5.86k
  ytob_dc_ = static_cast<int>(br->ReadFixedBits<kBitsPerByte>()) +
37
5.86k
             std::numeric_limits<int8_t>::min();
38
5.86k
  RecomputeDCFactors();
39
5.86k
  return true;
40
5.86k
}
41
42
StatusOr<ColorCorrelationMap> ColorCorrelationMap::Create(
43
10.6k
    JxlMemoryManager* memory_manager, size_t xsize, size_t ysize, bool XYB) {
44
10.6k
  ColorCorrelationMap result;
45
10.6k
  size_t xblocks = DivCeil(xsize, kColorTileDim);
46
10.6k
  size_t yblocks = DivCeil(ysize, kColorTileDim);
47
10.6k
  JXL_ASSIGN_OR_RETURN(result.ytox_map,
48
10.6k
                       ImageSB::Create(memory_manager, xblocks, yblocks));
49
10.6k
  JXL_ASSIGN_OR_RETURN(result.ytob_map,
50
10.6k
                       ImageSB::Create(memory_manager, xblocks, yblocks));
51
10.6k
  ZeroFillImage(&result.ytox_map);
52
10.6k
  ZeroFillImage(&result.ytob_map);
53
10.6k
  if (!XYB) {
54
0
    result.base_.base_correlation_b_ = 0;
55
0
  }
56
10.6k
  result.base_.RecomputeDCFactors();
57
10.6k
  return result;
58
10.6k
}
59
60
}  // namespace jxl