Files
hcie-rust-v3.05/hcie-io/examples/test_psd_simple.rs
2026-07-09 02:59:53 +03:00

63 lines
1.8 KiB
Rust

/// Minimal PSD test: generates a 256x256 canvas with a single red rectangle layer.
/// No effects. Used to validate that the PSD writer produces files Photoshop can open.
use hcie_protocol::{Layer, LayerType, LayerData, BlendMode};
use std::sync::atomic::AtomicBool;
use std::sync::Mutex;
fn main() {
let w = 256u32;
let h = 256u32;
let margin = 64u32;
let mut pixels = vec![0u8; (w * h * 4) as usize];
for y in 0..h {
for x in 0..w {
let i = (y * w + x) as usize * 4;
if x >= margin && x < w - margin && y >= margin && y < h - margin {
pixels[i] = 255;
pixels[i + 1] = 0;
pixels[i + 2] = 0;
pixels[i + 3] = 255;
}
}
}
let layer = Layer {
name: "Red Rectangle".to_string(),
layer_type: LayerType::Raster,
data: LayerData::Raster,
pixels,
width: w,
height: h,
visible: true,
opacity: 1.0,
blend_mode: BlendMode::Normal,
locked: false,
dirty: false,
id: 1,
parent_id: None,
styles: vec![],
clipping_mask: false,
collapsed: false,
adjustment: None,
mask_pixels: None,
mask_bounds: None,
mask_default_color: 0,
curve_points: vec![],
fill_opacity: 1.0,
effects: vec![],
effects_dirty: AtomicBool::new(false),
effects_cache: Mutex::new(None),
adjustment_raw: None,
is_section_divider: false,
image_resources_raw: None,
};
let composited: Vec<u8> = layer.pixels.clone();
let path = std::path::Path::new("_tmp/simple_test.psd");
std::fs::create_dir_all("_tmp").ok();
hcie_psd::save_psd(&[layer], w, h, &composited, path).expect("save_psd failed");
println!("Saved {}", path.display());
}