Coverage Report

Created: 2025-07-16 07:53

/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
6.07k
Status ColorCorrelation::DecodeDC(BitReader* br) {
21
6.07k
  if (br->ReadFixedBits<1>() == 1) {
22
    // All default.
23
3
    return true;
24
3
  }
25
6.07k
  SetColorFactor(U32Coder::Read(kColorFactorDist, br));
26
6.07k
  JXL_RETURN_IF_ERROR(F16Coder::Read(br, &base_correlation_x_));
27
6.07k
  if (std::abs(base_correlation_x_) > 4.0f) {
28
0
    return JXL_FAILURE("Base X correlation is out of range");
29
0
  }
30
6.07k
  JXL_RETURN_IF_ERROR(F16Coder::Read(br, &base_correlation_b_));
31
6.07k
  if (std::abs(base_correlation_b_) > 4.0f) {
32
1
    return JXL_FAILURE("Base B correlation is out of range");
33
1
  }
34
6.07k
  ytox_dc_ = static_cast<int>(br->ReadFixedBits<kBitsPerByte>()) +
35
6.07k
             std::numeric_limits<int8_t>::min();
36
6.07k
  ytob_dc_ = static_cast<int>(br->ReadFixedBits<kBitsPerByte>()) +
37
6.07k
             std::numeric_limits<int8_t>::min();
38
6.07k
  RecomputeDCFactors();
39
6.07k
  return true;
40
6.07k
}
41
42
StatusOr<ColorCorrelationMap> ColorCorrelationMap::Create(
43
12.0k
    JxlMemoryManager* memory_manager, size_t xsize, size_t ysize, bool XYB) {
44
12.0k
  ColorCorrelationMap result;
45
12.0k
  size_t xblocks = DivCeil(xsize, kColorTileDim);
46
12.0k
  size_t yblocks = DivCeil(ysize, kColorTileDim);
47
12.0k
  JXL_ASSIGN_OR_RETURN(result.ytox_map,
48
12.0k
                       ImageSB::Create(memory_manager, xblocks, yblocks));
49
12.0k
  JXL_ASSIGN_OR_RETURN(result.ytob_map,
50
12.0k
                       ImageSB::Create(memory_manager, xblocks, yblocks));
51
12.0k
  ZeroFillImage(&result.ytox_map);
52
12.0k
  ZeroFillImage(&result.ytob_map);
53
12.0k
  if (!XYB) {
54
0
    result.base_.base_correlation_b_ = 0;
55
0
  }
56
12.0k
  result.base_.RecomputeDCFactors();
57
12.0k
  return result;
58
12.0k
}
59
60
}  // namespace jxl