Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lazy_static #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion h263/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ license = "MIT OR Apache-2.0"
bitflags = "2.4.0"
thiserror = "2.0.3"
num-traits = "0.2.16"
lazy_static = "1.4.0"
38 changes: 19 additions & 19 deletions h263/src/decoder/cpu/idct.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
//! Inverse discrete cosine transform

// TODO: Restore this when f32::cos is a const fn.
/*
use lazy_static::lazy_static;
use std::f32::consts::{FRAC_1_SQRT_2, PI};

/// The 1D basis function of the H.263 IDCT.
///
/// `freq` is the frequency of the component
/// `x` is the point at which the cosine is to be computed
fn basis(freq: f32, x: f32) -> f32 {
const fn basis(freq: f32, x: f32) -> f32 {
f32::cos(PI * ((x as f32 + 0.5) / 8.0) * freq as f32)
}

lazy_static! {
/// Lookup table for `basis`.
///
/// The outer parameter represents all valid `spatial` inputs, while the
/// inner represents all valid `freq` inputs.
/// Already includes the former CUV_TABLE factors.
static ref BASIS_TABLE : [[f32; 8]; 8] = [
[basis(0.0, 0.0) * FRAC_1_SQRT_2, basis(0.0, 1.0) * FRAC_1_SQRT_2, basis(0.0, 2.0) * FRAC_1_SQRT_2, basis(0.0, 3.0) * FRAC_1_SQRT_2, basis(0.0, 4.0) * FRAC_1_SQRT_2, basis(0.0, 5.0) * FRAC_1_SQRT_2, basis(0.0, 6.0) * FRAC_1_SQRT_2, basis(0.0, 7.0) * FRAC_1_SQRT_2],
[basis(1.0, 0.0), basis(1.0, 1.0), basis(1.0, 2.0), basis(1.0, 3.0),basis(1.0, 4.0),basis(1.0, 5.0),basis(1.0, 6.0),basis(1.0, 7.0)],
[basis(2.0, 0.0), basis(2.0, 1.0), basis(2.0, 2.0), basis(2.0, 3.0),basis(2.0, 4.0),basis(2.0, 5.0),basis(2.0, 6.0),basis(2.0, 7.0)],
[basis(3.0, 0.0), basis(3.0, 1.0), basis(3.0, 2.0), basis(3.0, 3.0),basis(3.0, 4.0),basis(3.0, 5.0),basis(3.0, 6.0),basis(3.0, 7.0)],
[basis(4.0, 0.0), basis(4.0, 1.0), basis(4.0, 2.0), basis(4.0, 3.0),basis(4.0, 4.0),basis(4.0, 5.0),basis(4.0, 6.0),basis(4.0, 7.0)],
[basis(5.0, 0.0), basis(5.0, 1.0), basis(5.0, 2.0), basis(5.0, 3.0),basis(5.0, 4.0),basis(5.0, 5.0),basis(5.0, 6.0),basis(5.0, 7.0)],
[basis(6.0, 0.0), basis(6.0, 1.0), basis(6.0, 2.0), basis(6.0, 3.0),basis(6.0, 4.0),basis(6.0, 5.0),basis(6.0, 6.0),basis(6.0, 7.0)],
[basis(7.0, 0.0), basis(7.0, 1.0), basis(7.0, 2.0), basis(7.0, 3.0),basis(7.0, 4.0),basis(7.0, 5.0),basis(7.0, 6.0),basis(7.0, 7.0)],
];
}

/// Lookup table for `basis`.
///
/// The outer parameter represents all valid `spatial` inputs, while the
/// inner represents all valid `freq` inputs.
/// Already includes the former CUV_TABLE factors.
static BASIS_TABLE: [[f32; 8]; 8] = [
[basis(0.0, 0.0) * FRAC_1_SQRT_2, basis(0.0, 1.0) * FRAC_1_SQRT_2, basis(0.0, 2.0) * FRAC_1_SQRT_2, basis(0.0, 3.0) * FRAC_1_SQRT_2, basis(0.0, 4.0) * FRAC_1_SQRT_2, basis(0.0, 5.0) * FRAC_1_SQRT_2, basis(0.0, 6.0) * FRAC_1_SQRT_2, basis(0.0, 7.0) * FRAC_1_SQRT_2],
[basis(1.0, 0.0), basis(1.0, 1.0), basis(1.0, 2.0), basis(1.0, 3.0),basis(1.0, 4.0),basis(1.0, 5.0),basis(1.0, 6.0),basis(1.0, 7.0)],
[basis(2.0, 0.0), basis(2.0, 1.0), basis(2.0, 2.0), basis(2.0, 3.0),basis(2.0, 4.0),basis(2.0, 5.0),basis(2.0, 6.0),basis(2.0, 7.0)],
[basis(3.0, 0.0), basis(3.0, 1.0), basis(3.0, 2.0), basis(3.0, 3.0),basis(3.0, 4.0),basis(3.0, 5.0),basis(3.0, 6.0),basis(3.0, 7.0)],
[basis(4.0, 0.0), basis(4.0, 1.0), basis(4.0, 2.0), basis(4.0, 3.0),basis(4.0, 4.0),basis(4.0, 5.0),basis(4.0, 6.0),basis(4.0, 7.0)],
[basis(5.0, 0.0), basis(5.0, 1.0), basis(5.0, 2.0), basis(5.0, 3.0),basis(5.0, 4.0),basis(5.0, 5.0),basis(5.0, 6.0),basis(5.0, 7.0)],
[basis(6.0, 0.0), basis(6.0, 1.0), basis(6.0, 2.0), basis(6.0, 3.0),basis(6.0, 4.0),basis(6.0, 5.0),basis(6.0, 6.0),basis(6.0, 7.0)],
[basis(7.0, 0.0), basis(7.0, 1.0), basis(7.0, 2.0), basis(7.0, 3.0),basis(7.0, 4.0),basis(7.0, 5.0),basis(7.0, 6.0),basis(7.0, 7.0)],
];

*/

use crate::types::DecodedDctBlock;
Expand Down
13 changes: 8 additions & 5 deletions h263/src/decoder/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::error::{Error, Result};
use crate::parser::{decode_block, decode_gob, decode_macroblock, decode_picture, H263Reader};
use crate::types::{
DecodedDctBlock, GroupOfBlocks, Macroblock, MacroblockType, MotionVector, Picture,
PictureOption, PictureTypeCode, MPPTYPE_OPTIONS, OPPTYPE_OPTIONS,
PictureOption, PictureTypeCode,
};
use std::collections::HashMap;
use std::io::Read;
Expand Down Expand Up @@ -147,11 +147,14 @@ impl H263State {
let next_running_options = if next_picture.has_plusptype && next_picture.has_opptype {
next_picture.options
} else if next_picture.has_plusptype {
(next_picture.options & !*OPPTYPE_OPTIONS)
| (self.running_options & *OPPTYPE_OPTIONS)
(next_picture.options & !PictureOption::OPPTYPE_OPTIONS)
| (self.running_options & PictureOption::OPPTYPE_OPTIONS)
} else {
(next_picture.options & !*OPPTYPE_OPTIONS & !*MPPTYPE_OPTIONS)
| (self.running_options & (*OPPTYPE_OPTIONS | *MPPTYPE_OPTIONS))
(next_picture.options
& !PictureOption::OPPTYPE_OPTIONS
& !PictureOption::MPPTYPE_OPTIONS)
| (self.running_options
& (PictureOption::OPPTYPE_OPTIONS | PictureOption::MPPTYPE_OPTIONS))
};

let format = if let Some(format) = next_picture.format {
Expand Down
3 changes: 0 additions & 3 deletions h263/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#[macro_use]
extern crate bitflags;

#[macro_use]
extern crate lazy_static;

mod decoder;
mod error;
pub mod parser;
Expand Down
19 changes: 1 addition & 18 deletions h263/src/parser/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,6 @@ pub type PlusPType = (
bool,
);

lazy_static! {
/// The set of picture options defined by an `OPPTYPE` record.
///
/// If a picture does not contain an `OPPTYPE`, then all of these options
/// will be carried forward from the previous picture's options.
static ref OPPTYPE_OPTIONS: PictureOption = PictureOption::UNRESTRICTED_MOTION_VECTORS
| PictureOption::SYNTAX_BASED_ARITHMETIC_CODING
| PictureOption::ADVANCED_PREDICTION
| PictureOption::ADVANCED_INTRA_CODING
| PictureOption::DEBLOCKING_FILTER
| PictureOption::SLICE_STRUCTURED
| PictureOption::REFERENCE_PICTURE_SELECTION
| PictureOption::INDEPENDENT_SEGMENT_DECODING
| PictureOption::ALTERNATIVE_INTER_VLC
| PictureOption::MODIFIED_QUANTIZATION;
}

/// Attempts to read a `PLUSPTYPE` record from the bitstream.
///
/// The set of previous picture options are used to carry forward previously-
Expand Down Expand Up @@ -229,7 +212,7 @@ where
followers |= PlusPTypeFollower::HAS_REFERENCE_LAYER_NUMBER;
}
} else {
options |= previous_picture_options & *OPPTYPE_OPTIONS;
options |= previous_picture_options & PictureOption::OPPTYPE_OPTIONS;
}

let mpptype: u16 = reader.read_bits(9)?;
Expand Down
40 changes: 17 additions & 23 deletions h263/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,30 +214,24 @@ bitflags! {
///
/// This flag is only set by Sorenson Spark bitstreams.
const USE_DEBLOCKER = 0b10000000000000000;
}
}

lazy_static! {
/// The set of options only present in the `OPPTYPE` portion of the picture
/// header.
pub static ref OPPTYPE_OPTIONS: PictureOption =
PictureOption::UNRESTRICTED_MOTION_VECTORS
| PictureOption::SYNTAX_BASED_ARITHMETIC_CODING
| PictureOption::ADVANCED_PREDICTION
| PictureOption::ADVANCED_INTRA_CODING
| PictureOption::DEBLOCKING_FILTER
| PictureOption::SLICE_STRUCTURED
| PictureOption::REFERENCE_PICTURE_SELECTION
| PictureOption::INDEPENDENT_SEGMENT_DECODING
| PictureOption::ALTERNATIVE_INTER_VLC
| PictureOption::MODIFIED_QUANTIZATION;

/// The set of options only present in the `MPPTYPE` portion of the picture
/// header.
pub static ref MPPTYPE_OPTIONS: PictureOption =
PictureOption::REFERENCE_PICTURE_RESAMPLING
| PictureOption::REDUCED_RESOLUTION_UPDATE
| PictureOption::ROUNDING_TYPE_ONE;
const OPPTYPE_OPTIONS =
Self::UNRESTRICTED_MOTION_VECTORS.bits()
| Self::SYNTAX_BASED_ARITHMETIC_CODING.bits()
| Self::ADVANCED_PREDICTION.bits()
| Self::ADVANCED_INTRA_CODING.bits()
| Self::DEBLOCKING_FILTER.bits()
| Self::SLICE_STRUCTURED.bits()
| Self::REFERENCE_PICTURE_SELECTION.bits()
| Self::INDEPENDENT_SEGMENT_DECODING.bits()
| Self::ALTERNATIVE_INTER_VLC.bits()
| Self::MODIFIED_QUANTIZATION.bits();

const MPPTYPE_OPTIONS =
Self::REFERENCE_PICTURE_RESAMPLING.bits()
| Self::REDUCED_RESOLUTION_UPDATE.bits()
| Self::ROUNDING_TYPE_ONE.bits();
}
}

/// All available picture types in H.263.
Expand Down