Skip to content

Commit daa97c8

Browse files
committed
Const Formats
1 parent 15f9197 commit daa97c8

4 files changed

Lines changed: 66 additions & 42 deletions

File tree

rustsynth/src/format/audio.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,6 @@ impl AudioFormatBuilder {
5656
}
5757
}
5858

59-
impl AudioFormat {
60-
/// Convenience method to create common 16-bit stereo format
61-
pub fn stereo_16bit(core: &crate::core::CoreRef) -> Result<Self, FormatError> {
62-
AudioFormatBuilder::new(SampleType::Integer, 16, ChannelLayout::STEREO).build(core)
63-
}
64-
65-
/// Convenience method to create common 32-bit float stereo format
66-
pub fn stereo_32bit_float(core: &crate::core::CoreRef) -> Result<Self, FormatError> {
67-
AudioFormatBuilder::new(SampleType::Float, 32, ChannelLayout::STEREO).build(core)
68-
}
69-
70-
/// Convenience method to create common 16-bit mono format
71-
pub fn mono_16bit(core: &crate::core::CoreRef) -> Result<Self, FormatError> {
72-
AudioFormatBuilder::new(SampleType::Integer, 16, ChannelLayout::MONO).build(core)
73-
}
74-
}
75-
7659
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
7760
pub struct AudioInfo {
7861
pub format: AudioFormat,
@@ -186,4 +169,20 @@ impl AudioFormat {
186169
pub fn get_name(&self) -> Option<String> {
187170
unsafe { API::get_cached().get_audio_format_name(&self.as_ptr()) }
188171
}
172+
173+
pub const STEREO16: Self = Self {
174+
sample_type: SampleType::Integer,
175+
bits_per_sample: 16,
176+
bytes_per_sample: 2,
177+
num_channels: 2,
178+
channel_layout: ChannelLayout::STEREO,
179+
};
180+
181+
pub const MONO16: Self = Self {
182+
sample_type: SampleType::Integer,
183+
bits_per_sample: 16,
184+
bytes_per_sample: 2,
185+
num_channels: 1,
186+
channel_layout: ChannelLayout::MONO,
187+
};
189188
}

rustsynth/src/format/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub enum MediaType {
88
Audio,
99
}
1010

11-
/// Audio channel layout bitmask using VSAudioChannels constants
11+
/// Audio channel layout bitmask
1212
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1313
pub struct ChannelLayout(pub u64);
1414

rustsynth/src/format/presets.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::format::{ColorFamily, SampleType};
2-
/// Preset video formats as defined by VapourSynth.
1+
use crate::{core::CoreRef, format::{ColorFamily, SampleType, VideoFormat}};
2+
/// Preset video format IDs as defined by VapourSynth.
33
///
44
/// The presets suffixed with H and S have floating point sample type. The H and S suffixes stand
55
/// for half precision and single precision, respectively.
@@ -77,3 +77,10 @@ const fn make_video_id(
7777
| (sub_sampling_w << 8)
7878
| sub_sampling_h
7979
}
80+
81+
impl PresetVideoFormat {
82+
/// Consumes the PresetVideoFormatID and returns the corresponding VideoFormat from the core.
83+
pub fn into_format(self, core: &CoreRef) -> VideoFormat {
84+
core.get_video_format_by_id(self as u32).unwrap()
85+
}
86+
}

rustsynth/src/format/video.rs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,46 @@ impl VideoFormat {
106106
pub fn get_name(&self) -> Option<String> {
107107
unsafe { API::get_cached().get_video_format_name(&self.as_ptr()) }
108108
}
109+
110+
pub const YUV420P8: Self = Self {
111+
color_family: ColorFamily::YUV,
112+
sample_type: SampleType::Integer,
113+
bits_per_sample: 8,
114+
bytes_per_sample: 1,
115+
sub_sampling_w: 2,
116+
sub_sampling_h: 2,
117+
num_planes: 3,
118+
};
119+
120+
pub const YUV444P8: Self = Self {
121+
color_family: ColorFamily::YUV,
122+
sample_type: SampleType::Integer,
123+
bits_per_sample: 8,
124+
bytes_per_sample: 1,
125+
sub_sampling_w: 1,
126+
sub_sampling_h: 1,
127+
num_planes: 3,
128+
};
129+
130+
pub const RGB24: Self = Self {
131+
color_family: ColorFamily::RGB,
132+
sample_type: SampleType::Integer,
133+
bits_per_sample: 8,
134+
bytes_per_sample: 1,
135+
sub_sampling_w: 0,
136+
sub_sampling_h: 0,
137+
num_planes: 3,
138+
};
139+
140+
pub const GRAY8: Self = Self {
141+
color_family: ColorFamily::Gray,
142+
sample_type: SampleType::Integer,
143+
bits_per_sample: 8,
144+
bytes_per_sample: 1,
145+
sub_sampling_w: 0,
146+
sub_sampling_h: 0,
147+
num_planes: 1,
148+
};
109149
}
110150

111151
impl VideoInfo {
@@ -197,28 +237,6 @@ impl VideoFormatBuilder {
197237
}
198238
}
199239

200-
impl VideoFormat {
201-
/// Convenience method to create common YUV420P8 format
202-
pub fn yuv420p8(core: &crate::core::CoreRef) -> Result<Self, FormatError> {
203-
Self::query(ColorFamily::YUV, SampleType::Integer, 8, 1, 1, core)
204-
}
205-
206-
/// Convenience method to create common YUV444P8 format
207-
pub fn yuv444p8(core: &crate::core::CoreRef) -> Result<Self, FormatError> {
208-
Self::query(ColorFamily::YUV, SampleType::Integer, 8, 0, 0, core)
209-
}
210-
211-
/// Convenience method to create common RGB24 format
212-
pub fn rgb24(core: &crate::core::CoreRef) -> Result<Self, FormatError> {
213-
Self::query(ColorFamily::RGB, SampleType::Integer, 8, 0, 0, core)
214-
}
215-
216-
/// Convenience method to create common Gray8 format
217-
pub fn gray8(core: &crate::core::CoreRef) -> Result<Self, FormatError> {
218-
Self::query(ColorFamily::Gray, SampleType::Integer, 8, 0, 0, core)
219-
}
220-
}
221-
222240
/// Information about a video clip
223241
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
224242
pub struct VideoInfo {

0 commit comments

Comments
 (0)