1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use std::io;
use scuffle_bytes_util::{BitReader, range_check};
use scuffle_expgolomb::BitReaderExpGolombExt;
/// Sequence parameter set 3D extension.
///
/// `sps_3d_extension()`
///
/// - ISO/IEC 23008-2 - I.7.3.2.2.5
/// - ISO/IEC 23008-2 - I.7.4.3.2.5
#[derive(Debug, Clone, PartialEq)]
pub struct Sps3dExtension {
/// All values for `d=0`
pub d0: Sps3dExtensionD0,
/// All values for `d=1`
pub d1: Sps3dExtensionD1,
}
/// Directly part of [SPS 3D extension](Sps3dExtension).
#[derive(Debug, Clone, PartialEq)]
pub struct Sps3dExtensionD0 {
/// Equal to `true` specifies that the derivation process for inter-view predicted
/// merging candidates and the derivation process for disparity information merging candidates may be used
/// in the decoding process of layers with `DepthFlag` equal to **0**.
///
/// Equal to `false` specifies
/// that derivation process for inter-view predicted merging candidates and the derivation process for
/// disparity information merging candidates is not used in the decoding process of layers with `DepthFlag`
/// equal to **0**.
pub iv_di_mc_enabled_flag: bool,
/// Equal to `true` specifies that motion vectors used for inter-view prediction may
/// be scaled based on `view_id_val` values in the decoding process of layers with `DepthFlag` equal to **0**.
///
/// Equal to `false` specifies that motion vectors used for inter-view prediction are
/// not scaled based on `view_id_val` values in the decoding process of layers with `DepthFlag` equal to **0**.
pub iv_mv_scal_enabled_flag: bool,
/// When [`iv_di_mc_enabled_flag`](Sps3dExtensionD0::iv_di_mc_enabled_flag) is equal to `true`, is
/// used to derive the minimum size of sub-block partitions used in the derivation process for sub-block
/// partition motion vectors for an inter-layer predicted merging candidate in the decoding process of layers
/// with `DepthFlag` equal to 0.
///
/// The value is in range
/// \[[`MinCbLog2SizeY`](crate::SpsRbsp::min_cb_log2_size_y) - 3, [`CtbLog2SizeY`](crate::SpsRbsp::ctb_log2_size_y) - 3\].
pub log2_ivmc_sub_pb_size_minus3: u64,
/// Equal to `true` specifies that the `iv_res_pred_weight_idx` syntax element may
/// be present in coding units of layers with `DepthFlag` equal to 0.
///
/// Equal to 0 specifies that the `iv_res_pred_weight_idx` syntax element is not present coding units of layers with
/// `DepthFlag` equal to 0.
pub iv_res_pred_enabled_flag: bool,
/// Equal to `true` specifies that the derivation process for a depth or disparity
/// sample array from a depth picture may be used in the derivation process for a disparity vector for texture
/// layers in the decoding process of layers with `DepthFlag` equal to 0.
///
/// Equal to `false` specifies that derivation process for a depth or disparity sample array from
/// a depth picture is not used in the derivation process for a disparity vector for texture layers in
/// the decoding process of layers with `DepthFlag` equal to 0.
pub depth_ref_enabled_flag: bool,
/// Equal to `true` specifies that the derivation process for a view synthesis prediction
/// merging candidate may be used in the decoding process of layers with `DepthFlag` equal to 0.
///
/// Equal to `false` specifies that the derivation process for a view synthesis prediction
/// merging candidate is not used in the decoding process of layers with `DepthFlag` equal to 0.
pub vsp_mc_enabled_flag: bool,
/// Equal to `true` specifies that the `dbbp_flag` syntax element may be present in coding
/// units of layers with `DepthFlag` equal to 0.
///
/// Equal to `false` specifies that the `dbbp_flag`
/// syntax element is not present in coding units of layers with `DepthFlag` equal to 0.
pub dbbp_enabled_flag: bool,
}
/// Directly part of [SPS 3D extension](Sps3dExtension).
#[derive(Debug, Clone, PartialEq)]
pub struct Sps3dExtensionD1 {
/// Equal to `true` specifies that the derivation process for inter-view predicted
/// merging candidates and the derivation process for disparity information merging candidates may be used
/// in the decoding process of layers with `DepthFlag` equal to **1**.
///
/// Equal to `false` specifies
/// that derivation process for inter-view predicted merging candidates and the derivation process for
/// disparity information merging candidates is not used in the decoding process of layers with `DepthFlag`
/// equal to **1**.
pub iv_di_mc_enabled_flag: bool,
/// Equal to `true` specifies that motion vectors used for inter-view prediction may
/// be scaled based on `view_id_val` values in the decoding process of layers with `DepthFlag` equal to **1**.
///
/// Equal to `false` specifies that motion vectors used for inter-view prediction are
/// not scaled based on `view_id_val` values in the decoding process of layers with `DepthFlag` equal to **1**.
pub iv_mv_scal_enabled_flag: bool,
/// Equal to `true` specifies that the derivation process for motion vectors for the
/// texture merge candidate may be used in the decoding process of layers with `DepthFlag` equal to 1.
///
/// Equal to `false` specifies that the derivation process for motion vectors for the texture
/// merge candidate is not used in the decoding process of layers with `DepthFlag` equal to 1.
pub tex_mc_enabled_flag: bool,
/// When this value is equal to `true`, is used to derive the
/// minimum size of sub-block partitions used in the derivation process for sub-block partition motion
/// vectors for an inter-layer predicted merging candidate in the decoding process of layers with `DepthFlag`
/// equal to 1.
///
/// The value is in range
/// \[[`MinCbLog2SizeY`](crate::SpsRbsp::min_cb_log2_size_y) - 3, [`CtbLog2SizeY`](crate::SpsRbsp::ctb_log2_size_y) - 3\].
pub log2_texmc_sub_pb_size_minus3: u64,
/// Equal to `true` specifies that the intra prediction mode `INTRA_CONTOUR`
/// using depth intra contour prediction may be used in the decoding process of layers with `DepthFlag` equal
/// to 1.
///
/// Equal to `false` specifies that the intra prediction mode `INTRA_CONTOUR`
/// using depth intra contour prediction is not used in the decoding process of layers with `DepthFlag` equal
/// to 1.
pub intra_contour_enabled_flag: bool,
/// Equal to `true` specifies that the `dc_only_flag` syntax element may be
/// present in coding units coded in an intra prediction mode of layers with `DepthFlag` equal to 1, and that
/// the intra prediction mode `INTRA_WEDGE` may be used in the decoding process of layers with `DepthFlag`
/// equal to 1.
///
/// Equal to `false` specifies that the `dc_only_flag` syntax element
/// is not present in coding units coded in an intra prediction mode of layers with `DepthFlag` equal to 1 and
/// that the intra prediction mode `INTRA_WEDGE` is not used in the decoding process of layers with
/// `DepthFlag` equal to 1.
pub intra_dc_only_wedge_enabled_flag: bool,
/// Equal to `true` specifies that coding quadtree and coding unit
/// partitioning information may be inter-component predicted in the decoding process of layers with
/// `DepthFlag` equal to 1.
///
/// Equal to `false` specifies that coding quadtree and
/// coding unit partitioning information are not inter-component predicted in the decoding process of layers
/// with `DepthFlag` equal to 1.
pub cqt_cu_part_pred_enabled_flag: bool,
/// Equal to `true` specifies that the dc_only_flag syntax element may be present
/// in coding units coded an in inter prediction mode of layers with `DepthFlag` equal to 1.
///
/// Equal to `false` specifies that the dc_only_flag syntax element is not present in
/// coding units coded in an inter prediction mode of layers with `DepthFlag` equal to 1.
pub inter_dc_only_enabled_flag: bool,
/// Equal to `true` specifies that the `skip_intra_flag` syntax element may be present
/// in coding units of layers with `DepthFlag` equal to 1.
///
/// Equal to `false` specifies that
/// the `skip_intra_flag` syntax element is not present in coding units of layers with `DepthFlag` equal to 1.
pub skip_intra_enabled_flag: bool,
}
impl Sps3dExtension {
pub(crate) fn parse<R: io::Read>(
bit_reader: &mut BitReader<R>,
min_cb_log2_size_y: u64,
ctb_log2_size_y: u64,
) -> io::Result<Self> {
let iv_di_mc_enabled_flag = bit_reader.read_bit()?;
let iv_mv_scal_enabled_flag = bit_reader.read_bit()?;
let log2_ivmc_sub_pb_size_minus3 = bit_reader.read_exp_golomb()?;
range_check!(
log2_ivmc_sub_pb_size_minus3,
min_cb_log2_size_y.saturating_sub(3),
ctb_log2_size_y.saturating_sub(3)
)?;
let d0 = Sps3dExtensionD0 {
iv_di_mc_enabled_flag,
iv_mv_scal_enabled_flag,
log2_ivmc_sub_pb_size_minus3,
iv_res_pred_enabled_flag: bit_reader.read_bit()?,
depth_ref_enabled_flag: bit_reader.read_bit()?,
vsp_mc_enabled_flag: bit_reader.read_bit()?,
dbbp_enabled_flag: bit_reader.read_bit()?,
};
let tex_mc_enabled_flag = bit_reader.read_bit()?;
let log2_texmc_sub_pb_size_minus3 = bit_reader.read_exp_golomb()?;
range_check!(
log2_texmc_sub_pb_size_minus3,
min_cb_log2_size_y.saturating_sub(3),
ctb_log2_size_y.saturating_sub(3)
)?;
let d1 = Sps3dExtensionD1 {
iv_di_mc_enabled_flag: d0.iv_di_mc_enabled_flag,
iv_mv_scal_enabled_flag: d0.iv_mv_scal_enabled_flag,
tex_mc_enabled_flag,
log2_texmc_sub_pb_size_minus3,
intra_contour_enabled_flag: bit_reader.read_bit()?,
intra_dc_only_wedge_enabled_flag: bit_reader.read_bit()?,
cqt_cu_part_pred_enabled_flag: bit_reader.read_bit()?,
inter_dc_only_enabled_flag: bit_reader.read_bit()?,
skip_intra_enabled_flag: bit_reader.read_bit()?,
};
Ok(Sps3dExtension { d0, d1 })
}
}