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