From bd3cdc925edf0aacfc841f784d23f4eb1c7fb048 Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 23 Dec 2023 21:44:11 -0600 Subject: [PATCH] Remove special-case for animated avif --- src/discover/magick.rs | 99 +----------------------------------------- 1 file changed, 1 insertion(+), 98 deletions(-) diff --git a/src/discover/magick.rs b/src/discover/magick.rs index 46a229e..2421eec 100644 --- a/src/discover/magick.rs +++ b/src/discover/magick.rs @@ -39,40 +39,7 @@ pub(super) async fn confirm_bytes( ) -> Result { match discovery { Some(Discovery { - input: InputFile::Animation(AnimationFormat::Avif), - width, - height, - .. - }) => { - let frames = count_avif_frames(tmp_dir, timeout, move |mut file| async move { - file.write_from_bytes(bytes) - .await - .map_err(MagickError::Write)?; - Ok(file) - }) - .await?; - - if frames == 1 { - return Ok(Discovery { - input: InputFile::Image(ImageInput { - format: ImageFormat::Avif, - needs_reorient: false, - }), - width, - height, - frames: None, - }); - } - - return Ok(Discovery { - input: InputFile::Animation(AnimationFormat::Avif), - width, - height, - frames: Some(frames), - }); - } - Some(Discovery { - input: InputFile::Animation(AnimationFormat::Webp), + input: InputFile::Animation(AnimationFormat::Webp | AnimationFormat::Avif), .. }) => { // continue @@ -93,70 +60,6 @@ pub(super) async fn confirm_bytes( .await } -#[tracing::instrument(level = "debug", skip_all)] -async fn count_avif_frames(tmp_dir: &TmpDir, timeout: u64, f: F) -> Result -where - F: FnOnce(crate::file::File) -> Fut, - Fut: std::future::Future>, -{ - let temporary_path = tmp_dir - .tmp_folder() - .await - .map_err(MagickError::CreateTemporaryDirectory)?; - - let input_file = tmp_dir.tmp_file(None); - crate::store::file_store::safe_create_parent(&input_file) - .await - .map_err(MagickError::CreateDir)?; - - let tmp_one = crate::file::File::create(&input_file) - .await - .map_err(MagickError::CreateFile)?; - let tmp_one = (f)(tmp_one).await?; - tmp_one.close().await.map_err(MagickError::CloseFile)?; - - let envs = [(MAGICK_TEMPORARY_PATH, temporary_path.as_os_str())]; - - let res = Process::run( - "magick", - &[ - "convert".as_ref(), - "-ping".as_ref(), - input_file.as_os_str(), - "INFO:".as_ref(), - ], - &envs, - timeout, - )? - .read() - .into_string() - .await; - - input_file.cleanup().await.map_err(MagickError::Cleanup)?; - temporary_path - .cleanup() - .await - .map_err(MagickError::Cleanup)?; - - let output = res?; - - if output.is_empty() { - return Err(MagickError::Empty); - } - - let lines: u32 = output - .lines() - .count() - .try_into() - .expect("Reasonable frame count"); - - if lines == 0 { - return Err(MagickError::Empty); - } - - Ok(lines) -} - #[tracing::instrument(level = "debug", skip_all)] async fn discover_file( tmp_dir: &TmpDir,