Commit f096176c authored by Luca Barbato's avatar Luca Barbato Committed by Luca Barbato

Use a procedural macro instead a local copy of arg_enum

Make cargo doc happier and make crav1e not depend on compiler
unstable feature.
parent fbcea419
......@@ -17,6 +17,7 @@ nasm = ["nasm-rs"]
dump_ivf = ["ivf"]
[dependencies]
arg_enum_proc_macro = "0.1.1"
bitstream-io = "0.8"
clap = { version = "2", optional = true, default-features = false }
libc = "0.2"
......
......@@ -7,6 +7,7 @@
// Media Patent License 1.0 was not distributed with this source code in the
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
use arg_enum_proc_macro::ArgEnum;
use bitstream_io::*;
use crate::encoder::*;
use crate::metrics::calculate_frame_psnr;
......@@ -315,14 +316,12 @@ impl Default for ChromaSamplePosition {
}
}
arg_enum!{
#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub enum PixelRange {
Unspecified = 0,
Limited,
Full,
}
#[derive(ArgEnum, Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub enum PixelRange {
Unspecified = 0,
Limited,
Full,
}
impl Default for PixelRange {
......@@ -331,25 +330,23 @@ impl Default for PixelRange {
}
}
arg_enum!{
#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub enum MatrixCoefficients {
Identity = 0,
BT709,
Unspecified,
BT470M = 4,
BT470BG,
ST170M,
ST240M,
YCgCo,
BT2020NonConstantLuminance,
BT2020ConstantLuminance,
ST2085,
ChromaticityDerivedNonConstantLuminance,
ChromaticityDerivedConstantLuminance,
ICtCp,
}
#[derive(ArgEnum, Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub enum MatrixCoefficients {
Identity = 0,
BT709,
Unspecified,
BT470M = 4,
BT470BG,
ST170M,
ST240M,
YCgCo,
BT2020NonConstantLuminance,
BT2020ConstantLuminance,
ST2085,
ChromaticityDerivedNonConstantLuminance,
ChromaticityDerivedConstantLuminance,
ICtCp,
}
impl Default for MatrixCoefficients {
......@@ -358,23 +355,21 @@ impl Default for MatrixCoefficients {
}
}
arg_enum!{
#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub enum ColorPrimaries {
BT709 = 1,
Unspecified,
BT470M = 4,
BT470BG,
ST170M,
ST240M,
Film,
BT2020,
ST428,
P3DCI,
P3Display,
Tech3213 = 22,
}
#[derive(ArgEnum, Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub enum ColorPrimaries {
BT709 = 1,
Unspecified,
BT470M = 4,
BT470BG,
ST170M,
ST240M,
Film,
BT2020,
ST428,
P3DCI,
P3Display,
Tech3213 = 22,
}
impl Default for ColorPrimaries {
......@@ -383,28 +378,26 @@ impl Default for ColorPrimaries {
}
}
arg_enum!{
#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub enum TransferCharacteristics {
BT1886 = 1,
Unspecified,
BT470M = 4,
BT470BG,
ST170M,
ST240M,
Linear,
Logarithmic100,
Logarithmic316,
XVYCC,
BT1361E,
SRGB,
BT2020Ten,
BT2020Twelve,
PerceptualQuantizer,
ST428,
HybridLogGamma,
}
#[derive(ArgEnum, Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub enum TransferCharacteristics {
BT1886 = 1,
Unspecified,
BT470M = 4,
BT470BG,
ST170M,
ST240M,
Linear,
Logarithmic100,
Logarithmic316,
XVYCC,
BT1361E,
SRGB,
BT2020Ten,
BT2020Twelve,
PerceptualQuantizer,
ST428,
HybridLogGamma,
}
impl Default for TransferCharacteristics {
......
......@@ -28,6 +28,7 @@ use crate::util::*;
use crate::partition::PartitionType::*;
use crate::header::*;
use arg_enum_proc_macro::ArgEnum;
use bitstream_io::{BitWriter, BigEndian};
use bincode::{serialize, deserialize};
use std;
......@@ -177,13 +178,11 @@ const MAX_NUM_TEMPORAL_LAYERS: usize = 8;
const MAX_NUM_SPATIAL_LAYERS: usize = 4;
const MAX_NUM_OPERATING_POINTS: usize = MAX_NUM_TEMPORAL_LAYERS * MAX_NUM_SPATIAL_LAYERS;
arg_enum!{
#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(C)]
pub enum Tune {
Psnr,
Psychovisual
}
#[derive(ArgEnum, Copy, Clone, Debug, PartialEq)]
#[repr(C)]
pub enum Tune {
Psnr,
Psychovisual
}
impl Default for Tune {
......
......@@ -11,115 +11,6 @@ use num_traits::*;
use std::mem;
use std::mem::size_of;
use std::fmt::{Debug, Display};
#[allow(deprecated, unused_imports)]
use ::std::ascii::AsciiExt;
// Imported from clap, to avoid to depend directly to the crate
macro_rules! _clap_count_exprs {
() => { 0 };
($e:expr) => { 1 };
($e:expr, $($es:expr),+) => { 1 + _clap_count_exprs!($($es),*) };
}
macro_rules! arg_enum {
(@as_item $($i:item)*) => ($($i)*);
(@impls ( $($tts:tt)* ) -> ($e:ident, $($v:ident),+)) => {
arg_enum!(@as_item
$($tts)*
impl ::std::str::FromStr for $e {
type Err = String;
fn from_str(s: &str) -> ::std::result::Result<Self,Self::Err> {
match s {
$(stringify!($v) |
_ if s.eq_ignore_ascii_case(stringify!($v)) => Ok($e::$v)),+,
_ => Err({
let v = vec![
$(stringify!($v),)+
];
format!("valid values: {}",
v.join(" ,"))
}),
}
}
}
impl ::std::fmt::Display for $e {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
$($e::$v => write!(f, stringify!($v)),)+
}
}
}
impl $e {
#[allow(dead_code)]
pub fn variants() -> [&'static str; _clap_count_exprs!($(stringify!($v)),+)] {
[
$(stringify!($v),)+
]
}
});
};
($(#[$($m:meta),+])+ pub enum $e:ident { $($v:ident $(=$val:expr)*,)+ } ) => {
arg_enum!(@impls
($(#[$($m),+])+
pub enum $e {
$($v$(=$val)*),+
}) -> ($e, $($v),+)
);
};
($(#[$($m:meta),+])+ pub enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => {
arg_enum!(@impls
($(#[$($m),+])+
pub enum $e {
$($v$(=$val)*),+
}) -> ($e, $($v),+)
);
};
($(#[$($m:meta),+])+ enum $e:ident { $($v:ident $(=$val:expr)*,)+ } ) => {
arg_enum!(@impls
($(#[$($m),+])+
enum $e {
$($v$(=$val)*),+
}) -> ($e, $($v),+)
);
};
($(#[$($m:meta),+])+ enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => {
arg_enum!(@impls
($(#[$($m),+])+
enum $e {
$($v$(=$val)*),+
}) -> ($e, $($v),+)
);
};
(pub enum $e:ident { $($v:ident $(=$val:expr)*,)+ } ) => {
arg_enum!(@impls
(pub enum $e {
$($v$(=$val)*),+
}) -> ($e, $($v),+)
);
};
(pub enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => {
arg_enum!(@impls
(pub enum $e {
$($v$(=$val)*),+
}) -> ($e, $($v),+)
);
};
(enum $e:ident { $($v:ident $(=$val:expr)*,)+ } ) => {
arg_enum!(@impls
(enum $e {
$($v$(=$val)*),+
}) -> ($e, $($v),+)
);
};
(enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => {
arg_enum!(@impls
(enum $e {
$($v$(=$val)*),+
}) -> ($e, $($v),+)
);
};
}
//TODO: Nice to have (although I wasnt able to find a way to do it yet in rust): zero-fill arrays that are
// shorter than required. Need const fn (Rust Issue #24111) or const generics (Rust RFC #2000)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment