mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-12 08:52:32 +00:00
PhotoCraft's `photocraft-psd` crate (crates/psd at storytold/photocraft 63b641b55e54bf8f5c83efd977fdb16a2c255431) as `craft-psd`: the lossless PSD/PSB model, reader, writer and builder, descriptors, the Photoshop resource files that share its primitives (.abr, .asl, .aco, .act, .ase, .grd, .pat, .atn, .csh, .shc) and the Photoshop blocks of a layered TIFF. The crate had no dependency on any other PhotoCraft crate. Code is unchanged apart from the crate name, craft-libs' rustfmt width, comments that named other PhotoCraft crates, issue references (now `photocraft#N`), and the corpus tests' directory (`CRAFT_PSD_CORPUS` or `corpus/` at the workspace root). Tests, proptests, fuzz targets and fixtures move with it. Part of #778, #786.
50 lines
1.8 KiB
Rust
50 lines
1.8 KiB
Rust
pub fn triangle_csh() -> Vec<u8> {
|
|
polygon_csh(&[&[(0.25, 0.25), (0.75, 0.25), (0.5, 0.75)]])
|
|
}
|
|
|
|
pub fn polygon_csh(polygons: &[&[(f64, f64)]]) -> Vec<u8> {
|
|
named_polygon_csh("Triangle", polygons)
|
|
}
|
|
|
|
pub fn named_polygon_csh(label: &str, polygons: &[&[(f64, f64)]]) -> Vec<u8> {
|
|
let mut out = b"cush".to_vec();
|
|
out.extend_from_slice(&2u32.to_be_bytes());
|
|
out.extend_from_slice(&1u32.to_be_bytes());
|
|
let name: Vec<u16> = label.encode_utf16().chain(std::iter::once(0)).collect();
|
|
out.extend_from_slice(&(name.len() as u32).to_be_bytes());
|
|
for unit in &name {
|
|
out.extend_from_slice(&unit.to_be_bytes());
|
|
}
|
|
if !name.len().is_multiple_of(2) {
|
|
out.extend_from_slice(&[0, 0]);
|
|
}
|
|
out.extend_from_slice(&1u32.to_be_bytes());
|
|
let mut body = vec![36];
|
|
body.extend_from_slice(b"00000000-0000-4000-8000-000000000001");
|
|
for bound in [0i32, 0, 100, 200] {
|
|
body.extend_from_slice(&bound.to_be_bytes());
|
|
}
|
|
for selector in [6u16, 8] {
|
|
body.extend_from_slice(&selector.to_be_bytes());
|
|
body.extend_from_slice(&[0; 24]);
|
|
}
|
|
for polygon in polygons {
|
|
body.extend_from_slice(&0u16.to_be_bytes());
|
|
body.extend_from_slice(&(polygon.len() as u16).to_be_bytes());
|
|
body.extend_from_slice(&[0; 22]);
|
|
for &(x, y) in *polygon {
|
|
body.extend_from_slice(&2u16.to_be_bytes());
|
|
for _ in 0..3 {
|
|
body.extend_from_slice(&((y * 16_777_216.0) as i32).to_be_bytes());
|
|
body.extend_from_slice(&((x * 16_777_216.0) as i32).to_be_bytes());
|
|
}
|
|
}
|
|
}
|
|
while !body.len().is_multiple_of(4) {
|
|
body.push(0);
|
|
}
|
|
out.extend_from_slice(&(body.len() as u32).to_be_bytes());
|
|
out.extend_from_slice(&body);
|
|
out
|
|
}
|