use std::sync::Arc;
use jxr_core::{
BackendRequest, CoefficientArena, OutputFormatRequest, PreparedPlan, SurfaceLayout,
};
#[derive(Debug, Clone)]
pub struct PreparedAlphaReconstruction {
plan: PreparedPlan,
coefficients: Arc<CoefficientArena>,
}
impl PreparedAlphaReconstruction {
#[must_use]
pub const fn plan(&self) -> &PreparedPlan {
&self.plan
}
#[must_use]
pub const fn coefficients(&self) -> &Arc<CoefficientArena> {
&self.coefficients
}
}
#[derive(Debug, Clone)]
pub struct PreparedReconstruction {
plan: PreparedPlan,
coefficients: Arc<CoefficientArena>,
separate_alpha: Option<PreparedAlphaReconstruction>,
coded_origin: [u32; 2],
output_policy: OutputFormatRequest,
output_layout: SurfaceLayout,
requested_backend: BackendRequest,
}
impl PreparedReconstruction {
pub(crate) fn new(
plan: PreparedPlan,
coefficients: jxr_native::AcceleratorCoefficients,
coded_origin: [u32; 2],
output_policy: OutputFormatRequest,
output_layout: SurfaceLayout,
requested_backend: BackendRequest,
) -> Self {
let separate_alpha = coefficients
.separate_alpha
.map(|alpha| PreparedAlphaReconstruction {
plan: alpha.plan,
coefficients: Arc::new(alpha.coefficients),
});
Self {
plan,
coefficients: Arc::new(coefficients.primary),
separate_alpha,
coded_origin,
output_policy,
output_layout,
requested_backend,
}
}
#[must_use]
pub const fn plan(&self) -> &PreparedPlan {
&self.plan
}
#[must_use]
pub const fn coefficients(&self) -> &Arc<CoefficientArena> {
&self.coefficients
}
#[must_use]
pub const fn coded_origin(&self) -> [u32; 2] {
self.coded_origin
}
#[must_use]
pub const fn separate_alpha(&self) -> Option<&PreparedAlphaReconstruction> {
self.separate_alpha.as_ref()
}
#[must_use]
pub const fn output_policy(&self) -> OutputFormatRequest {
self.output_policy
}
#[must_use]
pub const fn output_layout(&self) -> &SurfaceLayout {
&self.output_layout
}
#[must_use]
pub const fn requested_backend(&self) -> BackendRequest {
self.requested_backend
}
#[cfg(feature = "metal")]
pub fn metal_plan(&self) -> Result<jxr_metal::MetalDecodePlan, jxr_metal::MetalError> {
self.metal_plan_with_layout(self.output_layout.clone())
}
#[cfg(feature = "metal")]
pub fn metal_plan_with_layout(
&self,
output: SurfaceLayout,
) -> Result<jxr_metal::MetalDecodePlan, jxr_metal::MetalError> {
jxr_metal::MetalDecodePlan::from_prepared(
self.coefficients.clone(),
self.separate_alpha
.as_ref()
.map(|alpha| (alpha.coefficients.clone(), alpha.plan.clone())),
&self.plan,
self.output_policy,
output,
self.coded_origin,
self.requested_backend,
)
}
#[cfg(feature = "cuda")]
pub fn cuda_plan(&self) -> Result<jxr_cuda::CudaDecodePlan, jxr_cuda::CudaError> {
self.cuda_plan_with_layout(self.output_layout.clone())
}
#[cfg(feature = "cuda")]
pub fn cuda_plan_with_layout(
&self,
output: SurfaceLayout,
) -> Result<jxr_cuda::CudaDecodePlan, jxr_cuda::CudaError> {
jxr_cuda::CudaDecodePlan::from_prepared(
self.coefficients.clone(),
self.separate_alpha
.as_ref()
.map(|alpha| (alpha.coefficients.clone(), alpha.plan.clone())),
&self.plan,
self.output_policy,
output,
self.coded_origin,
self.requested_backend,
)
}
}