Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge pull request #827 from pravdomil/claude/import-exif-orientation

Brandon Thomasc11740f461d2
diff --cc crates/media/src/pool.rs
index 4ccd24639,ce4be9c2e..90e191715
--- a/crates/media/src/pool.rs
+++ b/crates/media/src/pool.rs
@@@ -6,11 -6,12 +6,12 @@@ use std::sync::{Arc, Condvar, Mutex, On
use effectcraft_project::{AlphaMode, Footage, FootageKind, ItemId};
use effectcraft_raster::{Image, Px};
-use effectcraft_render::FootageSource;
+use effectcraft_render::{FloatCurve, FootageSource};
use effectcraft_time::{FrameRate, TICKS_PER_SECOND, Tick};
use filmcraft_media::{FrameRequest, SharedSource};
+ use image::metadata::Orientation;
- use crate::convert::{AlphaOp, dynamic_to_image, frame_to_image_in, frame_to_image_scaled};
+ use crate::convert::{AlphaOp, dynamic_to_image, frame_to_image_in, frame_to_image_scaled, turned};
use crate::gif_anim::{self, Anim};
use crate::{MediaError, Result};
@@@ -579,15 -582,10 +586,16 @@@ impl Inner
let slot = lock(&self.sources).entry(path.clone()).or_default().clone();
slot.get_or_init(|| {
self.opened.fetch_add(1, Ordering::Relaxed);
- let opened = self.read(path).and_then(|bytes| {
- let name = std::path::Path::new(&**path).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
- let turn = crate::probe::video_turn(&bytes);
+ // Files on disk are read in place (the index, then samples on demand) rather than
+ // whole; in-memory files (`add_bytes`) and wasm32 builds open from bytes.
+ let in_memory = lock(&self.files).contains_key(&**path);
+ let in_place = if in_memory { None } else { crate::stream::open_source(std::path::Path::new(&**path)) };
+ let opened = in_place.unwrap_or_else(|| {
+ self.read(path).and_then(|bytes| {
+ let name = std::path::Path::new(&**path).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
- filmcraft_codecs::open_bytes(&name, bytes).map_err(MediaError::from)
++ let turn = crate::probe::video_turn(&bytes);
+ filmcraft_codecs::open_bytes(&name, bytes).map(|src| (src, turn)).map_err(MediaError::from)
+ })
});
match opened {
Ok(s) => Some(s),
@@@ -757,11 -746,7 +765,11 @@@
{
return Err(MediaError::Decode(format!("{path}: {why}")));
}
- let img = match crate::probe::load_oriented(&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),
++ None => crate::probe::load_oriented(&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}")))?,