Merge pull request #755 from vangel76/gap-tga-hdr-import
#745: import Targa (.tga) and Radiance HDR (.hdr) stills and sequences # Conflicts: # crates/ui-egui/src/menus.rs
This commit is contained in:
+16
-2
@@ -10,7 +10,7 @@
|
||||
//! Video containers (MP4/MOV, Matroska/WebM) and codecs (H.264, HEVC, VP9, AV1, ProRes, DNxHD,
|
||||
//! MJPEG; AAC, Opus, PCM, MP3/FLAC/Vorbis) come from FilmCraft's pure-Rust crates (git dependency,
|
||||
//! pinned; `plan/adr/0001`). FilmCraft types never leave this crate. Stills use the `image` crate
|
||||
//! (PNG, JPEG, GIF, WebP, TIFF, BMP, OpenEXR); Photoshop documents (merged image or one layer) come
|
||||
//! (PNG, JPEG, GIF, WebP, TIFF, BMP, OpenEXR, Targa, Radiance HDR); Photoshop documents (merged image or one layer) come
|
||||
//! from `effectcraft-psd` and SVG from `effectcraft-svg` (rasterised at any scale).
|
||||
|
||||
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
||||
@@ -51,7 +51,8 @@ impl From<filmcraft_media::MediaError> for MediaError {
|
||||
}
|
||||
|
||||
/// File extensions recognised as stills.
|
||||
pub const STILL_EXTENSIONS: &[&str] = &["png", "jpg", "jpeg", "gif", "webp", "tif", "tiff", "bmp", "exr", "psd", "psb", "svg", "pdf", "ai", "eps"];
|
||||
pub const STILL_EXTENSIONS: &[&str] =
|
||||
&["png", "jpg", "jpeg", "gif", "webp", "tif", "tiff", "bmp", "exr", "tga", "hdr", "psd", "psb", "svg", "pdf", "ai", "eps"];
|
||||
/// File extensions recognised as audio-only files.
|
||||
pub const AUDIO_EXTENSIONS: &[&str] = filmcraft_media::AUDIO_EXTENSIONS;
|
||||
/// File extensions recognised as movies.
|
||||
@@ -73,6 +74,19 @@ pub(crate) fn ext_of(path: &std::path::Path) -> String {
|
||||
path.extension().and_then(|e| e.to_str()).unwrap_or("").to_ascii_lowercase()
|
||||
}
|
||||
|
||||
/// The `image` crate format of a still: from its signature, else from its extension (Targa has
|
||||
/// no signature; a `.hdr` without the Radiance one then fails with the decoder's own error).
|
||||
pub(crate) fn still_format(path: &str, bytes: &[u8]) -> Option<image::ImageFormat> {
|
||||
if let Ok(fmt) = image::guess_format(bytes) {
|
||||
return Some(fmt);
|
||||
}
|
||||
match ext_of(std::path::Path::new(path)).as_str() {
|
||||
"tga" => Some(image::ImageFormat::Tga),
|
||||
"hdr" => Some(image::ImageFormat::Hdr),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn rate_from_fc(r: filmcraft_time::FrameRate) -> effectcraft_time::FrameRate {
|
||||
if r.num > 0 && r.den > 0 { effectcraft_time::FrameRate::new(r.num, r.den) } else { effectcraft_time::FrameRate::FPS_30 }
|
||||
}
|
||||
|
||||
@@ -746,7 +746,11 @@ impl Inner {
|
||||
{
|
||||
return Err(MediaError::Decode(format!("{path}: {why}")));
|
||||
}
|
||||
let img = match image::load_from_memory(&bytes) {
|
||||
let loaded = match crate::still_format(path, &bytes) {
|
||||
Some(fmt) => image::load_from_memory_with_format(&bytes, fmt),
|
||||
None => image::load_from_memory(&bytes),
|
||||
};
|
||||
let img = match loaded {
|
||||
Ok(img) => img,
|
||||
// A multi-layer OpenEXR file without an unnamed RGB layer: its colour layer.
|
||||
Err(e) => crate::exr_channels::cached_layered_image(path, bytes).ok_or_else(|| MediaError::Decode(format!("{path}: {e}")))?,
|
||||
|
||||
@@ -66,7 +66,7 @@ pub fn probe_bytes(path: &str, bytes: Arc<[u8]>) -> Result<Footage> {
|
||||
if crate::MODEL_EXTENSIONS.contains(&ext_of(Path::new(path)).as_str()) {
|
||||
return probe_model(path, &bytes, &|_| None);
|
||||
}
|
||||
if let Ok(fmt) = image::guess_format(&bytes) {
|
||||
if let Some(fmt) = crate::still_format(path, &bytes) {
|
||||
// An animated GIF is a movie; one with a single frame is a still.
|
||||
if fmt == image::ImageFormat::Gif
|
||||
&& let Some(f) = crate::gif_anim::probe(path, &bytes)
|
||||
|
||||
Reference in New Issue
Block a user