#[cfg(any(feature = "serde", test))]
use serde::{Deserialize, Serialize};
#[cfg(doc)]
use crate::TextureFormat;
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum ExternalTextureFormat {
Rgba,
Nv12,
Yu12,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Zeroable, bytemuck::Pod)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(missing_docs)]
pub struct ExternalTextureTransferFunction {
pub a: f32,
pub b: f32,
pub g: f32,
pub k: f32,
}
impl Default for ExternalTextureTransferFunction {
fn default() -> Self {
Self {
a: 1.0,
b: 1.0,
g: 1.0,
k: 1.0,
}
}
}
#[repr(C)]
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ExternalTextureDescriptor<L> {
pub label: L,
pub width: u32,
pub height: u32,
pub format: ExternalTextureFormat,
pub yuv_conversion_matrix: [f32; 16],
pub gamut_conversion_matrix: [f32; 9],
pub src_transfer_function: ExternalTextureTransferFunction,
pub dst_transfer_function: ExternalTextureTransferFunction,
pub sample_transform: [f32; 6],
pub load_transform: [f32; 6],
}
impl<L> ExternalTextureDescriptor<L> {
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> ExternalTextureDescriptor<K> {
ExternalTextureDescriptor {
label: fun(&self.label),
width: self.width,
height: self.height,
format: self.format,
yuv_conversion_matrix: self.yuv_conversion_matrix,
sample_transform: self.sample_transform,
load_transform: self.load_transform,
gamut_conversion_matrix: self.gamut_conversion_matrix,
src_transfer_function: self.src_transfer_function,
dst_transfer_function: self.dst_transfer_function,
}
}
pub fn num_planes(&self) -> usize {
match self.format {
ExternalTextureFormat::Rgba => 1,
ExternalTextureFormat::Nv12 => 2,
ExternalTextureFormat::Yu12 => 3,
}
}
}