2023-07-13 03:12:21 +00:00
|
|
|
use crate::{
|
2024-02-22 22:02:33 +00:00
|
|
|
bytes_stream::BytesStream,
|
2023-07-13 03:12:21 +00:00
|
|
|
exiftool::ExifError,
|
|
|
|
formats::{ImageInput, InputFile},
|
|
|
|
process::Process,
|
|
|
|
};
|
|
|
|
|
|
|
|
use super::Discovery;
|
|
|
|
|
2023-12-16 04:34:45 +00:00
|
|
|
#[tracing::instrument(level = "debug", skip_all)]
|
2023-07-13 03:12:21 +00:00
|
|
|
pub(super) async fn check_reorient(
|
|
|
|
Discovery {
|
|
|
|
input,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
frames,
|
|
|
|
}: Discovery,
|
2024-02-22 22:02:33 +00:00
|
|
|
bytes: BytesStream,
|
2024-02-04 00:18:13 +00:00
|
|
|
timeout: u64,
|
2023-07-13 03:12:21 +00:00
|
|
|
) -> Result<Discovery, ExifError> {
|
|
|
|
let input = match input {
|
|
|
|
InputFile::Image(ImageInput { format, .. }) => {
|
2023-08-05 17:41:06 +00:00
|
|
|
let needs_reorient = needs_reorienting(bytes, timeout).await?;
|
2023-07-13 03:12:21 +00:00
|
|
|
|
|
|
|
InputFile::Image(ImageInput {
|
|
|
|
format,
|
|
|
|
needs_reorient,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
otherwise => otherwise,
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(Discovery {
|
|
|
|
input,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
frames,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-12-16 04:34:45 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip_all)]
|
2024-02-22 22:02:33 +00:00
|
|
|
async fn needs_reorienting(input: BytesStream, timeout: u64) -> Result<bool, ExifError> {
|
2023-12-23 02:52:58 +00:00
|
|
|
let buf = Process::run("exiftool", &["-n", "-Orientation", "-"], &[], timeout)?
|
2024-02-24 20:02:41 +00:00
|
|
|
.drive_with_async_read(input.into_reader())
|
2023-12-23 17:58:20 +00:00
|
|
|
.into_string()
|
2023-12-23 02:52:58 +00:00
|
|
|
.await?;
|
2023-07-13 03:12:21 +00:00
|
|
|
|
|
|
|
Ok(!buf.is_empty())
|
|
|
|
}
|