/src/libjxl/lib/jxl/passes_state.h
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 | | #ifndef LIB_JXL_PASSES_STATE_H_ |
7 | | #define LIB_JXL_PASSES_STATE_H_ |
8 | | |
9 | | #include "lib/jxl/ac_context.h" |
10 | | #include "lib/jxl/ac_strategy.h" |
11 | | #include "lib/jxl/chroma_from_luma.h" |
12 | | #include "lib/jxl/common.h" |
13 | | #include "lib/jxl/dec_patch_dictionary.h" |
14 | | #include "lib/jxl/frame_header.h" |
15 | | #include "lib/jxl/image.h" |
16 | | #include "lib/jxl/image_bundle.h" |
17 | | #include "lib/jxl/loop_filter.h" |
18 | | #include "lib/jxl/noise.h" |
19 | | #include "lib/jxl/quant_weights.h" |
20 | | #include "lib/jxl/quantizer.h" |
21 | | #include "lib/jxl/splines.h" |
22 | | |
23 | | // Structures that hold the (en/de)coder state for a JPEG XL kVarDCT |
24 | | // (en/de)coder. |
25 | | |
26 | | namespace jxl { |
27 | | |
28 | | struct ImageFeatures { |
29 | | NoiseParams noise_params; |
30 | | PatchDictionary patches; |
31 | | Splines splines; |
32 | | }; |
33 | | |
34 | | // State common to both encoder and decoder. |
35 | | // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding) |
36 | | struct PassesSharedState { |
37 | 92 | PassesSharedState() : frame_header(nullptr) {} |
38 | | |
39 | | // Headers and metadata. |
40 | | const CodecMetadata* metadata; |
41 | | FrameHeader frame_header; |
42 | | |
43 | | FrameDimensions frame_dim; |
44 | | |
45 | | // Control fields and parameters. |
46 | | AcStrategyImage ac_strategy; |
47 | | |
48 | | // Dequant matrices + quantizer. |
49 | | DequantMatrices matrices; |
50 | | Quantizer quantizer{&matrices}; |
51 | | ImageI raw_quant_field; |
52 | | |
53 | | // Per-block side information for EPF detail preservation. |
54 | | ImageB epf_sharpness; |
55 | | |
56 | | ColorCorrelationMap cmap; |
57 | | |
58 | | ImageFeatures image_features; |
59 | | |
60 | | // Memory area for storing coefficient orders. |
61 | | // `coeff_order_size` is the size used by *one* set of coefficient orders (at |
62 | | // most kMaxCoeffOrderSize). A set of coefficient orders is present for each |
63 | | // pass. |
64 | | size_t coeff_order_size = 0; |
65 | | std::vector<coeff_order_t> coeff_orders; |
66 | | |
67 | | // Decoder-side DC and quantized DC. |
68 | | ImageB quant_dc; |
69 | | Image3F dc_storage; |
70 | | const Image3F* JXL_RESTRICT dc = &dc_storage; |
71 | | |
72 | | BlockCtxMap block_ctx_map; |
73 | | |
74 | | Image3F dc_frames[4]; |
75 | | |
76 | | struct { |
77 | | ImageBundle storage; |
78 | | // Can either point to `storage`, if this is a frame that is not stored in |
79 | | // the CodecInOut, or can point to an existing ImageBundle. |
80 | | // TODO(veluca): pointing to ImageBundles in CodecInOut is not possible for |
81 | | // now, as they are stored in a vector and thus may be moved. Fix this. |
82 | | ImageBundle* JXL_RESTRICT frame = &storage; |
83 | | // ImageBundle doesn't yet have a simple way to state it is in XYB. |
84 | | bool ib_is_in_xyb = false; |
85 | | } reference_frames[4] = {}; |
86 | | |
87 | | // Number of pre-clustered set of histograms (with the same ctx map), per |
88 | | // pass. Encoded as num_histograms_ - 1. |
89 | | size_t num_histograms = 0; |
90 | | |
91 | 0 | bool IsGrayscale() const { return metadata->m.color_encoding.IsGray(); } |
92 | | |
93 | 92 | Rect GroupRect(size_t group_index) const { |
94 | 92 | const size_t gx = group_index % frame_dim.xsize_groups; |
95 | 92 | const size_t gy = group_index / frame_dim.xsize_groups; |
96 | 92 | const Rect rect(gx * frame_dim.group_dim, gy * frame_dim.group_dim, |
97 | 92 | frame_dim.group_dim, frame_dim.group_dim, frame_dim.xsize, |
98 | 92 | frame_dim.ysize); |
99 | 92 | return rect; |
100 | 92 | } |
101 | | |
102 | 0 | Rect PaddedGroupRect(size_t group_index) const { |
103 | 0 | const size_t gx = group_index % frame_dim.xsize_groups; |
104 | 0 | const size_t gy = group_index / frame_dim.xsize_groups; |
105 | 0 | const Rect rect(gx * frame_dim.group_dim, gy * frame_dim.group_dim, |
106 | 0 | frame_dim.group_dim, frame_dim.group_dim, |
107 | 0 | frame_dim.xsize_padded, frame_dim.ysize_padded); |
108 | 0 | return rect; |
109 | 0 | } |
110 | | |
111 | 184 | Rect BlockGroupRect(size_t group_index) const { |
112 | 184 | const size_t gx = group_index % frame_dim.xsize_groups; |
113 | 184 | const size_t gy = group_index / frame_dim.xsize_groups; |
114 | 184 | const Rect rect(gx * (frame_dim.group_dim >> 3), |
115 | 184 | gy * (frame_dim.group_dim >> 3), frame_dim.group_dim >> 3, |
116 | 184 | frame_dim.group_dim >> 3, frame_dim.xsize_blocks, |
117 | 184 | frame_dim.ysize_blocks); |
118 | 184 | return rect; |
119 | 184 | } |
120 | | |
121 | 276 | Rect DCGroupRect(size_t group_index) const { |
122 | 276 | const size_t gx = group_index % frame_dim.xsize_dc_groups; |
123 | 276 | const size_t gy = group_index / frame_dim.xsize_dc_groups; |
124 | 276 | const Rect rect(gx * frame_dim.group_dim, gy * frame_dim.group_dim, |
125 | 276 | frame_dim.group_dim, frame_dim.group_dim, |
126 | 276 | frame_dim.xsize_blocks, frame_dim.ysize_blocks); |
127 | 276 | return rect; |
128 | 276 | } |
129 | | }; |
130 | | |
131 | | // Initialized the state information that is shared between encoder and decoder. |
132 | | Status InitializePassesSharedState(const FrameHeader& frame_header, |
133 | | PassesSharedState* JXL_RESTRICT shared, |
134 | | bool encoder = false); |
135 | | |
136 | | } // namespace jxl |
137 | | |
138 | | #endif // LIB_JXL_PASSES_STATE_H_ |