fix compile errors except for ffmpeg

This commit is contained in:
l1npengtul
2025-09-13 22:53:49 +09:00
parent 6db4a46e60
commit 5319e517d9
13 changed files with 279 additions and 410 deletions
+42 -9
View File
@@ -8,7 +8,7 @@ use bytemuck::try_cast_slice_mut;
use crate::pixel_destination::PixelDestination;
pub trait Decoder {
type Config: Clone + Debug;
type Config: Clone + Debug + ConfigHasResolution;
type OutputMeta: Clone + Debug;
const SUPPORTED_DESTINATIONS: &'static [PixelDestination];
@@ -27,10 +27,7 @@ pub trait Decoder {
where
<P as Pixel>::Subpixel: NonFloatScalarWidth
{
let destination = match PixelDestination::get_by_pixel::<P>() {
Some(dest) => dest,
None => return Err(NokhwaError::DecoderUnknownDestinationPixelFormat(P::COLOR_MODEL, P::Subpixel::WIDTH_BYTES))
};
let Some(destination) = PixelDestination::get_by_pixel::<P>() else { return Err(NokhwaError::DecoderUnknownDestinationPixelFormat(P::COLOR_MODEL, P::Subpixel::WIDTH_BYTES)) };
if !Self::supports_destination(destination) {
return Err(NokhwaError::DecoderUnsupportedDestinationPixelFormat(destination))
@@ -43,13 +40,29 @@ pub trait Decoder {
self.decode_to_buffer(to_decode, cast_slice, destination)
}
fn decode<P: Pixel>(
&mut self,
to_decode: FrameBuffer,
to_decode: FrameBuffer<'_>,
) -> Result<DecodedImage<P, Self::OutputMeta>, NokhwaError>
where
<P as Pixel>::Subpixel: NonFloatScalarWidth;
<P as Pixel>::Subpixel: NonFloatScalarWidth,
{
let resolution = self.config().resolution();
let min_size_alloc = self.output_decoder_min_size_pixel::<P>(resolution)?;
let mut out_buffer: Vec<P::Subpixel> = vec![P::Subpixel::DEFAULT_MIN_VALUE; min_size_alloc];
let meta = self.decode_to_pixel_buffer::<P>(to_decode, &mut out_buffer)?;
Ok(DecodedImage::new(
ImageBuffer::from_vec(
resolution.width(),
resolution.height(),
out_buffer,
)
.ok_or(NokhwaError::Decoder(
"failed to convert into an image buffer".to_string(),
))?,
meta,
))
}
fn output_decoder_min_size_pixel<P>(&self, resolution: Resolution) -> Result<usize, NokhwaError> where
P: Pixel,
@@ -58,9 +71,29 @@ pub trait Decoder {
}
fn output_decoder_min_size(&self, resolution: Resolution, destination_format: PixelDestination) -> Result<usize, NokhwaError>;
fn output_decoder_min_size(&self, resolution: Resolution, destination_format: PixelDestination) -> Result<usize, NokhwaError> {
if !Self::supports_destination(destination_format) {
return Err(NokhwaError::DecoderUnsupportedDestinationPixelFormat(destination_format))
}
let px_size = match destination_format {
PixelDestination::Rgb8 | PixelDestination::Bgr8 => 3_u32,
PixelDestination::Rgba8 | PixelDestination::Bgra8 | PixelDestination::LumaA16 => 4_u32,
PixelDestination::Rgb16 | PixelDestination::Bgr16 => 3_u32 * 2_u32,
PixelDestination::Rgba16 | PixelDestination::Bgra16 => 4_u32 * 2_u32,
PixelDestination::Luma8 => 1_u32,
PixelDestination::LumaA8 | PixelDestination::Luma16 => 2_u32,
};
let reso = resolution.width() * resolution.height();
Ok((reso as usize) * (px_size as usize))
}
#[must_use]
fn supports_destination(pixel_destination: PixelDestination) -> bool {
Self::SUPPORTED_DESTINATIONS.contains(&pixel_destination)
}
}
pub trait ConfigHasResolution {
fn resolution(&self) -> Resolution;
}
+1
View File
@@ -206,6 +206,7 @@ define_frame_format_with_groups! {
}
impl FrameFormat {
#[must_use]
pub fn is_custom(&self) -> bool {
if let FrameFormat::Custom(_) = self {
return true
+1
View File
@@ -19,6 +19,7 @@ pub enum PixelDestination {
}
impl PixelDestination {
#[must_use]
pub fn get_by_pixel<P>() -> Option<Self>
where
P: Pixel,
+1 -1
View File
@@ -165,7 +165,7 @@ impl<'a> StreamHandle<'a> {
return Err(NokhwaError::ReadFrameError(why));
}
}
Event::Error(e) => return Err(NokhwaError::ReadFrameError(e.to_string())),
Event::Error(e) => return Err(NokhwaError::ReadFrameError(e.clone())),
_ => {}
}
}
+1 -1
View File
@@ -43,7 +43,7 @@ impl CameraIndex {
pub fn as_string(&self) -> String {
match self {
CameraIndex::Index(i) => i.to_string(),
CameraIndex::String(s) | CameraIndex::Stable(s) => s.to_string(),
CameraIndex::String(s) | CameraIndex::Stable(s) => s.clone(),
}
}