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