mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 08:15:29 +00:00
Merge main preserving aligned ZIP and Lottie provenance
This commit is contained in:
commit
51673a8fea
5 files changed
+56
-2
No files matched your search
@@ -122,6 +122,9 @@ The XML reader in `crates/plist/src/xml.rs` and its base64 compatibility helper
|
||||
## Aligned stored ZIP entries
|
||||
|
||||
The USDZ alignment requirement and compatibility fixture for `Writer::add_stored_aligned` come from TextureCraft `crates/formats/src/mesh_export/usd.rs`, introduced by bflatastic in `bdbb52c9` and maintained through `9eb20086` (MIT OR Apache-2.0). The shared API and alignment validation are subsequent Dylan M. Taylor work. Scene/material mapping remains in TextureCraft.
|
||||
The raw gradient wire ordering in `craft-lottie::Gradient::flat_values` follows
|
||||
AniCraft's Lottie exporter by Tanish Manku (`63b39355`, `b9258b7b`), MIT OR Apache-2.0.
|
||||
Sanitization, animation fitting and numeric output policy remain caller-owned.
|
||||
## Screen Video key frames
|
||||
|
||||
`crates/video/src/screen_video.rs` extracts AniCraft `crates/xfl/src/video.rs` codec-3 decoding and its synthetic partial-block fixture, introduced by Tanish Manku in `1f3e603b7ff53a3da364e41ec4da8d43dc83aab0` with pixel-loop cleanup `2b7571363b4b647266df758f95b6e397021cfd4d` (MIT OR Apache-2.0). Import commits preserve Tanish as primary author. Caller-owned bounds and neutral RGBA output separate codec work from the consuming app's FLV first-frame/report policy. Boundary tests and integration are subsequent Dylan M. Taylor changes.
|
||||
@@ -212,7 +212,8 @@ fn title_left(c: &Chart, cat_on: bool, val_on: bool, area_w: f32) -> f32 {
|
||||
fn flat_title_lines(c: &Chart, area_w: f32) -> Option<Vec<String>> {
|
||||
let left = if c.horizontal { &c.cat } else { &c.val };
|
||||
let r = left.title_rot?.rem_euclid(360.0);
|
||||
if !(r < 1.0 || r > 359.0) {
|
||||
// Only near-zero rotations fit the horizontal strip; non-finite rotations do not.
|
||||
if !r.is_finite() || (1.0..=359.0).contains(&r) {
|
||||
return None;
|
||||
}
|
||||
let width = if area_w.is_finite() { (area_w * 0.18).max(1.0) } else { 1.0 };
|
||||
|
||||
@@ -745,6 +745,11 @@ fn value_axis_title_turns_counter_clockwise_like_word() {
|
||||
assert_eq!(angle(&line_with("", &title(r#"<a:bodyPr rot="5400000" vert="horz"/>"#))), Some(90.0));
|
||||
// A horizontal title (`rot="0"`) stays horizontal: the plot makes room for it (see below).
|
||||
assert_eq!(angle(&line_with("", &title(r#"<a:bodyPr rot="0" vert="horz"/>"#))), Some(0.0));
|
||||
// The horizontal tolerance excludes both boundary angles and keeps equivalent full turns.
|
||||
for (rot, expected) in [(30000, 0.0), (-30000, 0.0), (60000, -90.0), (-60000, -90.0), (10800000, -90.0), (21600000, 0.0)] {
|
||||
let body = format!(r#"<a:bodyPr rot="{rot}" vert="horz"/>"#);
|
||||
assert_eq!(angle(&line_with("", &title(&body))), Some(expected), "rotation {rot}");
|
||||
}
|
||||
// Hostile values stay finite.
|
||||
let odd = angle(&line_with("", &title(r#"<a:bodyPr rot="99999999999999999999"/>"#)));
|
||||
assert!(odd.is_some_and(f32::is_finite));
|
||||
|
||||
@@ -4,6 +4,18 @@ use serde_json::json;
|
||||
|
||||
use crate::{Json, nums, round6};
|
||||
|
||||
/// Raw gradient wire values from borrowed or mapped stops, without intermediate allocation.
|
||||
///
|
||||
/// Yields color groups (`position, r, g, b`) then every opacity pair (`position, alpha`).
|
||||
/// Input order and all values, including non-finite values and opaque alpha, are preserved.
|
||||
/// Sanitization, rounding, and input/output size budgets remain the caller's responsibility.
|
||||
pub fn flat_gradient_values(
|
||||
colors: impl IntoIterator<Item = (f64, [f64; 3])>,
|
||||
opacities: impl IntoIterator<Item = (f64, f64)>,
|
||||
) -> impl Iterator<Item = f64> {
|
||||
colors.into_iter().flat_map(|(p, [r, g, b])| [p, r, g, b]).chain(opacities.into_iter().flat_map(|(p, a)| [p, a]))
|
||||
}
|
||||
|
||||
/// A gradient: colour stops and opacity stops, each at a position in 0..=1.
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
pub struct Gradient {
|
||||
@@ -29,6 +41,17 @@ impl Gradient {
|
||||
Some(Self { colors, opacities })
|
||||
}
|
||||
|
||||
/// Raw color groups (`position, r, g, b`), followed by all opacity pairs
|
||||
/// (`position, alpha`), in input order. No rounding, clamping, or opacity elision.
|
||||
///
|
||||
/// This allocation-free view lets callers fit or interpolate equal-sized animated
|
||||
/// values before applying their own numeric policy. In particular, opaque alpha
|
||||
/// stops remain present so an opaque frame can interpolate to a translucent one.
|
||||
/// Non-finite values are preserved; callers must sanitize them before JSON output.
|
||||
pub fn flat_values(&self) -> impl Iterator<Item = f64> + '_ {
|
||||
flat_gradient_values(self.colors.iter().copied(), self.opacities.iter().copied())
|
||||
}
|
||||
|
||||
/// The flat list, rounded to six decimals. The alpha pairs are left out when every stop is
|
||||
/// opaque.
|
||||
pub fn to_flat(&self) -> Json {
|
||||
@@ -44,3 +67,25 @@ impl Gradient {
|
||||
json!(out)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod raw_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn raw_values_keep_order_precision_and_opaque_alpha() {
|
||||
let g = Gradient { colors: vec![(0.123456789, [0.2, 0.3, 0.4]), (1.0, [0.5, 0.6, 0.7])], opacities: vec![(0.0, 1.0), (1.0, 1.0)] };
|
||||
assert_eq!(g.flat_values().collect::<Vec<_>>(), vec![0.123456789, 0.2, 0.3, 0.4, 1.0, 0.5, 0.6, 0.7, 0.0, 1.0, 1.0, 1.0]);
|
||||
assert_eq!(g.to_flat(), json!([0.123457, 0.2, 0.3, 0.4, 1.0, 0.5, 0.6, 0.7]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_values_keep_nonfinite_signed_zero_and_unpaired_lists() {
|
||||
let g = Gradient { colors: vec![], opacities: vec![(-0.0, f64::NAN), (f64::INFINITY, f64::NEG_INFINITY)] };
|
||||
let bits: Vec<_> = g.flat_values().map(f64::to_bits).collect();
|
||||
assert_eq!(bits, [-0.0, f64::NAN, f64::INFINITY, f64::NEG_INFINITY].map(f64::to_bits));
|
||||
assert_eq!(Gradient::default().flat_values().count(), 0);
|
||||
let g = Gradient { colors: vec![(1e303, [1.0, 0.0, 0.0])], opacities: vec![] };
|
||||
assert_eq!(g.flat_values().collect::<Vec<_>>(), [1e303, 1.0, 0.0, 0.0]);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ mod prop;
|
||||
mod value;
|
||||
pub mod zip;
|
||||
|
||||
pub use gradient::Gradient;
|
||||
pub use gradient::{Gradient, flat_gradient_values};
|
||||
pub use model::{Animated, Animation, Layer, LayerContent, Limits, Shape, ShapeKind};
|
||||
pub use path::Bezier;
|
||||
pub use prop::{Ease, Key, KeyOut, Prop, PropValue, Tangents, is_animated, read_prop, tangent, write_keys, write_prop};
|
||||
|
||||
Reference in new issue
Block a user