Skip to content

Commit 7a9e847

Browse files
committed
chore: Make OPPTYPE_OPTIONS and MPPTYPE_OPTIONS as bit flag and remove lazy_static
1 parent b3f9055 commit 7a9e847

File tree

6 files changed

+170
-50
lines changed

6 files changed

+170
-50
lines changed

Cargo.lock

Lines changed: 144 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

h263/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ license = "MIT OR Apache-2.0"
99
bitflags = "2.4.0"
1010
thiserror = "2.0.3"
1111
num-traits = "0.2.16"
12-
lazy_static = "1.4.0"

h263/src/decoder/state.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::error::{Error, Result};
77
use crate::parser::{decode_block, decode_gob, decode_macroblock, decode_picture, H263Reader};
88
use crate::types::{
99
DecodedDctBlock, GroupOfBlocks, Macroblock, MacroblockType, MotionVector, Picture,
10-
PictureOption, PictureTypeCode, MPPTYPE_OPTIONS, OPPTYPE_OPTIONS,
10+
PictureOption, PictureTypeCode,
1111
};
1212
use std::collections::HashMap;
1313
use std::io::Read;
@@ -147,11 +147,14 @@ impl H263State {
147147
let next_running_options = if next_picture.has_plusptype && next_picture.has_opptype {
148148
next_picture.options
149149
} else if next_picture.has_plusptype {
150-
(next_picture.options & !*OPPTYPE_OPTIONS)
151-
| (self.running_options & *OPPTYPE_OPTIONS)
150+
(next_picture.options & !PictureOption::OPPTYPE_OPTIONS)
151+
| (self.running_options & PictureOption::OPPTYPE_OPTIONS)
152152
} else {
153-
(next_picture.options & !*OPPTYPE_OPTIONS & !*MPPTYPE_OPTIONS)
154-
| (self.running_options & (*OPPTYPE_OPTIONS | *MPPTYPE_OPTIONS))
153+
(next_picture.options
154+
& !PictureOption::OPPTYPE_OPTIONS
155+
& !PictureOption::MPPTYPE_OPTIONS)
156+
| (self.running_options
157+
& (PictureOption::OPPTYPE_OPTIONS | PictureOption::MPPTYPE_OPTIONS))
155158
};
156159

157160
let format = if let Some(format) = next_picture.format {

h263/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
#[macro_use]
44
extern crate bitflags;
55

6-
#[macro_use]
7-
extern crate lazy_static;
8-
96
mod decoder;
107
mod error;
118
pub mod parser;

h263/src/parser/picture.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,6 @@ pub type PlusPType = (
114114
bool,
115115
);
116116

117-
lazy_static! {
118-
/// The set of picture options defined by an `OPPTYPE` record.
119-
///
120-
/// If a picture does not contain an `OPPTYPE`, then all of these options
121-
/// will be carried forward from the previous picture's options.
122-
static ref OPPTYPE_OPTIONS: PictureOption = PictureOption::UNRESTRICTED_MOTION_VECTORS
123-
| PictureOption::SYNTAX_BASED_ARITHMETIC_CODING
124-
| PictureOption::ADVANCED_PREDICTION
125-
| PictureOption::ADVANCED_INTRA_CODING
126-
| PictureOption::DEBLOCKING_FILTER
127-
| PictureOption::SLICE_STRUCTURED
128-
| PictureOption::REFERENCE_PICTURE_SELECTION
129-
| PictureOption::INDEPENDENT_SEGMENT_DECODING
130-
| PictureOption::ALTERNATIVE_INTER_VLC
131-
| PictureOption::MODIFIED_QUANTIZATION;
132-
}
133-
134117
/// Attempts to read a `PLUSPTYPE` record from the bitstream.
135118
///
136119
/// The set of previous picture options are used to carry forward previously-
@@ -229,7 +212,7 @@ where
229212
followers |= PlusPTypeFollower::HAS_REFERENCE_LAYER_NUMBER;
230213
}
231214
} else {
232-
options |= previous_picture_options & *OPPTYPE_OPTIONS;
215+
options |= previous_picture_options & PictureOption::OPPTYPE_OPTIONS;
233216
}
234217

235218
let mpptype: u16 = reader.read_bits(9)?;

h263/src/types.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -214,30 +214,24 @@ bitflags! {
214214
///
215215
/// This flag is only set by Sorenson Spark bitstreams.
216216
const USE_DEBLOCKER = 0b10000000000000000;
217-
}
218-
}
219217

220-
lazy_static! {
221-
/// The set of options only present in the `OPPTYPE` portion of the picture
222-
/// header.
223-
pub static ref OPPTYPE_OPTIONS: PictureOption =
224-
PictureOption::UNRESTRICTED_MOTION_VECTORS
225-
| PictureOption::SYNTAX_BASED_ARITHMETIC_CODING
226-
| PictureOption::ADVANCED_PREDICTION
227-
| PictureOption::ADVANCED_INTRA_CODING
228-
| PictureOption::DEBLOCKING_FILTER
229-
| PictureOption::SLICE_STRUCTURED
230-
| PictureOption::REFERENCE_PICTURE_SELECTION
231-
| PictureOption::INDEPENDENT_SEGMENT_DECODING
232-
| PictureOption::ALTERNATIVE_INTER_VLC
233-
| PictureOption::MODIFIED_QUANTIZATION;
234-
235-
/// The set of options only present in the `MPPTYPE` portion of the picture
236-
/// header.
237-
pub static ref MPPTYPE_OPTIONS: PictureOption =
238-
PictureOption::REFERENCE_PICTURE_RESAMPLING
239-
| PictureOption::REDUCED_RESOLUTION_UPDATE
240-
| PictureOption::ROUNDING_TYPE_ONE;
218+
const OPPTYPE_OPTIONS =
219+
Self::UNRESTRICTED_MOTION_VECTORS.bits()
220+
| Self::SYNTAX_BASED_ARITHMETIC_CODING.bits()
221+
| Self::ADVANCED_PREDICTION.bits()
222+
| Self::ADVANCED_INTRA_CODING.bits()
223+
| Self::DEBLOCKING_FILTER.bits()
224+
| Self::SLICE_STRUCTURED.bits()
225+
| Self::REFERENCE_PICTURE_SELECTION.bits()
226+
| Self::INDEPENDENT_SEGMENT_DECODING.bits()
227+
| Self::ALTERNATIVE_INTER_VLC.bits()
228+
| Self::MODIFIED_QUANTIZATION.bits();
229+
230+
const MPPTYPE_OPTIONS =
231+
Self::REFERENCE_PICTURE_RESAMPLING.bits()
232+
| Self::REDUCED_RESOLUTION_UPDATE.bits()
233+
| Self::ROUNDING_TYPE_ONE.bits();
234+
}
241235
}
242236

243237
/// All available picture types in H.263.

0 commit comments

Comments
 (0)