From 37941e4a4197858bef8cddc0a0d38fa93e2b6571 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Wed, 1 Oct 2025 22:10:07 +0800 Subject: fix(image): mutex dead locks TODO: find better way to do this, maybe atomic? or somehow aquire and drop mutex when using it via macro or something --- src/image.rs | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/image.rs b/src/image.rs index 477ce91..4cd18fc 100644 --- a/src/image.rs +++ b/src/image.rs @@ -149,7 +149,8 @@ fn wrap_str(s: &str) -> Vec { .collect() } -fn ext(img: &mut DynamicImage, (curw, curh): &mut NCOffset, (extw, exth): &mut NCOffset) { +fn ext((curw, curh): &mut NCOffset, (extw, exth): &mut NCOffset) { + let img = &mut *get_image(); let (w, h) = img.dimensions(); let extedw = *extw + *curw; let extedh = *exth + *curh; @@ -163,7 +164,7 @@ fn ext(img: &mut DynamicImage, (curw, curh): &mut NCOffset, (extw, exth): &mut N // TODO: make draw_rect func // TODO: Accept all directions -fn draw_process(img: &mut DynamicImage, txt: &str, config: ComponentConfig) { +fn draw_process(txt: &str, config: ComponentConfig) { let (curw, curh, c) = &mut *get_offset(); let wrapped = wrap_str(txt); @@ -178,7 +179,8 @@ fn draw_process(img: &mut DynamicImage, txt: &str, config: ComponentConfig) { +fn draw_direction(dst: Option<&NCOffset>) { let (_, orih, c) = &mut *get_offset(); let srcx = *c as i32; @@ -256,7 +258,8 @@ fn draw_direction(img: &mut DynamicImage, dst: Option<&NCOffset>) { maxy = p.y; } } - ext(img, &mut (*c, *orih), &mut (((maxx - *c as i32).max(0) as u32), ((maxy - *orih as i32).max(0) as u32))); + ext(&mut (*c, *orih), &mut (((maxx - *c as i32).max(0) as u32), ((maxy - *orih as i32).max(0) as u32))); + let img = &mut *get_image(); draw_polygon_mut(img, &line, colors::DIRECT); draw_polygon_mut( @@ -278,28 +281,24 @@ fn draw_direction(img: &mut DynamicImage, dst: Option<&NCOffset>) { *orih = dsty as u32; } -fn build(ast: &[DepthExpr]) -> DynamicImage { - let mut img = DynamicImage::new(0, 0, ColorType::Rgba8); +fn build(ast: &[DepthExpr]) { draw_process( - &mut img, - "abcdefghijklmnop", + "abcdefghijklmnospa", ComponentConfig { ori_direction: HDirection::Down, dst_direction: HDirection::Down, }, ); - draw_direction(&mut img, None); + draw_direction(None); draw_process( - &mut img, "a", ComponentConfig { ori_direction: HDirection::Down, dst_direction: HDirection::Down, }, ); - draw_direction(&mut img, None); + draw_direction(None); draw_process( - &mut img, "a", ComponentConfig { ori_direction: HDirection::Down, @@ -307,39 +306,35 @@ fn build(ast: &[DepthExpr]) -> DynamicImage { }, ); let (a, b, c) = *get_offset(); - draw_direction(&mut img, None); + draw_direction(None); draw_process( - &mut img, "a", ComponentConfig { ori_direction: HDirection::Down, dst_direction: HDirection::Down, }, ); - draw_direction(&mut img, None); + draw_direction(None); draw_process( - &mut img, "a", ComponentConfig { ori_direction: HDirection::Down, dst_direction: HDirection::Down, }, ); - draw_direction(&mut img, Some(&(a + 100, b))); + draw_direction(Some(&(a + 100, b))); draw_process( - &mut img, "a", ComponentConfig { ori_direction: HDirection::Down, dst_direction: HDirection::Up, }, ); - - img } pub fn create(ast: &[DepthExpr], path: &Path) { - build(ast) + build(ast); + get_image() .save(path) .unwrap(); } -- cgit v1.2.3