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

139 lines
5.2 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/// Generate a systematic set of inner glow PSDs for ground-truth MAE tuning.
///
/// Each PSD: 256×256 black rectangle (25% margin) on transparent background
/// + inner glow effect.
/// Output: `_tmp/inner_glow_psd_set/`
use hcie_protocol::{Layer, LayerType, LayerData, BlendMode, effects::LayerEffect};
use std::sync::atomic::{AtomicBool};
use std::sync::Mutex;
fn main() {
let out_dir = std::path::Path::new("_tmp/inner_glow_psd_set");
std::fs::create_dir_all(out_dir).expect("create output dir");
let canvas: u32 = 256;
let margin: u32 = 64;
let chokes: &[f32] = &[0.0, 20.0];
let sizes: &[f32] = &[10.0, 30.0];
let fx_opacities: &[f32] = &[0.75, 1.0];
let noises: &[f32] = &[0.0, 15.0];
let fx_blend_modes: &[(BlendMode, &str)] = &[
(BlendMode::Normal, "normal"),
(BlendMode::Screen, "screen"),
(BlendMode::LinearDodge, "linear_dodge"),
];
let glow_colors: &[([u8; 4], &str)] = &[
([220, 30, 30, 255], "red"),
([30, 180, 30, 255], "green"),
([30, 60, 220, 255], "blue"),
([255, 220, 30, 255], "yellow"),
([30, 220, 220, 255], "cyan"),
([255, 30, 180, 255], "magenta"),
([220, 220, 220, 255], "white"),
];
let total = chokes.len() * sizes.len() * fx_opacities.len()
* fx_blend_modes.len() * glow_colors.len() * noises.len();
println!("Generating {} inner glow PSDs...", total);
let mut count = 0usize;
let mut errors = 0usize;
for &choke in chokes {
for &size in sizes {
for &opacity in fx_opacities {
for &(_bm, bm_name) in fx_blend_modes {
for &(color, color_name) in glow_colors {
for &noise in noises {
count += 1;
let filename = format!(
"ig_c{}_s{}_op{}_n{}_{}_{}.psd",
choke as u32, size as u32,
(opacity * 100.0) as u32, noise as u32,
bm_name, color_name
);
let path = out_dir.join(&filename);
if path.exists() {
continue;
}
let mut pixels = vec![0u8; (canvas * canvas * 4) as usize];
for y in 0..canvas {
for x in 0..canvas {
let i = (y * canvas + x) as usize * 4;
if x >= margin && x < canvas - margin
&& y >= margin && y < canvas - margin
{
pixels[i] = 0;
pixels[i + 1] = 0;
pixels[i + 2] = 0;
pixels[i + 3] = 255;
}
}
}
let effect = LayerEffect::InnerGlow {
enabled: true,
blend_mode: bm_name.to_string(),
color,
opacity,
choke,
size,
noise,
contour: None,
source: 0, // edge
};
let layer = Layer {
name: "shape".to_string(),
layer_type: LayerType::Raster,
data: LayerData::Raster,
pixels: pixels.clone(),
width: canvas,
height: canvas,
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![effect],
effects_dirty: AtomicBool::new(false),
effects_cache: Mutex::new(None),
adjustment_raw: None,
is_section_divider: false,
image_resources_raw: None,
};
match hcie_psd::save_psd(&[layer], canvas, canvas, &pixels, &path) {
Ok(()) => {}
Err(e) => {
eprintln!(" ERROR {}: {}", filename, e);
errors += 1;
}
}
if count % 20 == 0 {
println!(" [{}/{}] errors={}", count, total, errors);
}
}
}
}
}
}
}
println!("Done. {} PSDs generated, {} errors.", count - errors, errors);
}