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_MODULAR_ENCODING_DEC_MA_H_
7 #define LIB_JXL_MODULAR_ENCODING_DEC_MA_H_
8 
9 #include <stddef.h>
10 #include <stdint.h>
11 
12 #include <vector>
13 
14 #include "lib/jxl/base/status.h"
15 #include "lib/jxl/dec_bit_reader.h"
16 #include "lib/jxl/modular/options.h"
17 
18 namespace jxl {
19 
20 // inner nodes
21 struct PropertyDecisionNode {
22   PropertyVal splitval;
23   int16_t property;  // -1: leaf node, lchild points to leaf node
24   uint32_t lchild;
25   uint32_t rchild;
26   Predictor predictor;
27   int64_t predictor_offset;
28   uint32_t multiplier;
29 
PropertyDecisionNodePropertyDecisionNode30   PropertyDecisionNode(int p, int split_val, int lchild, int rchild,
31                        Predictor predictor, int64_t predictor_offset,
32                        uint32_t multiplier)
33       : splitval(split_val),
34         property(p),
35         lchild(lchild),
36         rchild(rchild),
37         predictor(predictor),
38         predictor_offset(predictor_offset),
39         multiplier(multiplier) {}
PropertyDecisionNodePropertyDecisionNode40   PropertyDecisionNode()
41       : splitval(0),
42         property(-1),
43         lchild(0),
44         rchild(0),
45         predictor(Predictor::Zero),
46         predictor_offset(0),
47         multiplier(1) {}
48   static PropertyDecisionNode Leaf(Predictor predictor, int64_t offset = 0,
49                                    uint32_t multiplier = 1) {
50     return PropertyDecisionNode(-1, 0, 0, 0, predictor, offset, multiplier);
51   }
52   static PropertyDecisionNode Split(int p, int split_val, int lchild,
53                                     int rchild = -1) {
54     if (rchild == -1) rchild = lchild + 1;
55     return PropertyDecisionNode(p, split_val, lchild, rchild, Predictor::Zero,
56                                 0, 1);
57   }
58 };
59 
60 using Tree = std::vector<PropertyDecisionNode>;
61 
62 Status DecodeTree(BitReader *br, Tree *tree, size_t tree_size_limit);
63 
64 }  // namespace jxl
65 
66 #endif  // LIB_JXL_MODULAR_ENCODING_DEC_MA_H_
67