rustsynth 0.7.0

Safe VapourSynth wrapper
Documentation
//! Module for audio and video format definitions and related functionality.
mod audio;
mod enums;
mod errors;
mod presets;
mod video;

#[cfg(feature = "f16-pixel-type")]
use half::f16;

#[cfg(test)]
mod tests;

/// A trait for possible pixel components.
///
/// # Safety
/// Implementing this trait allows retrieving slices of pixel data from the frame for the target
/// type, so the target type must be valid for the given format.
pub unsafe trait Component {
    /// Returns whether this component is valid for this format.
    fn is_valid(format: VideoFormat) -> bool;
}

unsafe impl Component for u8 {
    #[inline]
    fn is_valid(format: VideoFormat) -> bool {
        format.sample_type == SampleType::Integer && format.bytes_per_sample == 1
    }
}

unsafe impl Component for u16 {
    #[inline]
    fn is_valid(format: VideoFormat) -> bool {
        format.sample_type == SampleType::Integer && format.bytes_per_sample == 2
    }
}

unsafe impl Component for u32 {
    #[inline]
    fn is_valid(format: VideoFormat) -> bool {
        format.sample_type == SampleType::Integer && format.bytes_per_sample == 4
    }
}

#[cfg(feature = "f16-pixel-type")]
unsafe impl Component for f16 {
    #[inline]
    fn is_valid(format: VideoFormat) -> bool {
        format.sample_type == SampleType::Float && format.bytes_per_sample == 2
    }
}

unsafe impl Component for f32 {
    #[inline]
    fn is_valid(format: VideoFormat) -> bool {
        format.sample_type == SampleType::Float && format.bytes_per_sample == 4
    }
}

pub use audio::{AudioFormat, AudioFormatBuilder, AudioInfo};
pub use enums::{ChannelLayout, ColorFamily, MediaType, SampleType};
pub use errors::FormatError;
pub use presets::PresetVideoFormat;
pub use video::{VideoFormat, VideoFormatBuilder, VideoInfo};