scuffle_h265/sps/
sps_3d_extension.rs

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