aspect ratio: unify video placement + add export fit modes

A) Imported video had a different aspect ratio depending on how it was placed:
direct import used a uniform scale + center (preserve aspect), while the
asset-library timeline drag used an independent scale_x/scale_y (stretch to fill).
Add Transform::fit_centered (uniform scale, centered, aspect-preserving) and route
both paths through it, so a clip looks identical however it's added.

B) Exported video was stretched when the export resolution's aspect differed from
the document's (base_transform was always scale_non_uniform). Add
ExportFitMode {Stretch, Letterbox (default), Crop} on VideoExportSettings + a "Fit"
dropdown in advanced export settings, and a shared export_base_transform() helper:
Letterbox = uniform fit centered (black bars), Crop = uniform fill centered (trim),
Stretch = the old distort-to-fill. Threaded through the software, HDR, and
zero-copy export render paths (image export is doc-sized → identity).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Skyler Lehmkuhl
2026-06-26 06:54:49 -04:00
co-authored by Claude Opus 4.8
parent 02566d571b
commit fffcf0679c
7 changed files with 103 additions and 50 deletions
@@ -320,6 +320,29 @@ impl HdrExportMode {
}
}
/// How the document is fit into the export frame when the export resolution's aspect ratio differs
/// from the document's. Applied as the export `base_transform` (document space → export pixels).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum ExportFitMode {
/// Scale each axis independently to fill the frame — distorts when aspects differ.
Stretch,
/// Scale uniformly to fit, centered, with black bars (letterbox/pillarbox). Preserves aspect.
#[default]
Letterbox,
/// Scale uniformly to fill, centered, cropping the overflow. Preserves aspect, no bars.
Crop,
}
impl ExportFitMode {
pub fn name(&self) -> &'static str {
match self {
ExportFitMode::Stretch => "Stretch (distort to fill)",
ExportFitMode::Letterbox => "Letterbox (fit, black bars)",
ExportFitMode::Crop => "Crop (fill, trim edges)",
}
}
}
/// Video quality presets
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum VideoQuality {
@@ -385,6 +408,10 @@ pub struct VideoExportSettings {
#[serde(default)]
pub hdr: HdrExportMode,
/// How the document is fit into the export frame when aspect ratios differ (default Letterbox).
#[serde(default)]
pub fit: ExportFitMode,
/// Audio settings (None = no audio)
pub audio: Option<AudioExportSettings>,
@@ -405,6 +432,7 @@ impl Default for VideoExportSettings {
quality: VideoQuality::High,
color_range: ColorRange::Limited,
hdr: HdrExportMode::Sdr,
fit: ExportFitMode::Letterbox,
audio: Some(AudioExportSettings::high_quality_aac()),
start_time: 0.0,
end_time: 60.0,
@@ -47,6 +47,21 @@ impl Transform {
Self::default()
}
/// Set scale + position so `content_w × content_h` is fit **uniformly and centered** within
/// `doc_w × doc_h`, preserving aspect ratio (letterbox/pillarbox). The single shared way to
/// place a media clip (video/image) on the document — both import paths use this so a clip
/// looks identical however it was added. No-op for non-positive content dimensions.
pub fn fit_centered(&mut self, content_w: f64, content_h: f64, doc_w: f64, doc_h: f64) {
if content_w <= 0.0 || content_h <= 0.0 {
return;
}
let scale = (doc_w / content_w).min(doc_h / content_h);
self.scale_x = scale;
self.scale_y = scale;
self.x = (doc_w - content_w * scale) / 2.0;
self.y = (doc_h - content_h * scale) / 2.0;
}
/// Create a transform with position
pub fn with_position(x: f64, y: f64) -> Self {
Self {