summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-10-01 22:10:07 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-10-08 16:30:13 +0800
commit33bb133620177883b63f045444a471e4a4d56413 (patch)
tree5ae8ce0a5ac7c51c3c0dc50f59cf14f5a0507cd9 /src
parentdee01bdf755f43be15508b42a6e7bdff67a848b9 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/image.rs39
1 files changed, 17 insertions, 22 deletions
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<String> {
.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<HDirection, HDirection>) {
+fn draw_process(txt: &str, config: ComponentConfig<HDirection, HDirection>) {
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<HDire
.checked_sub(h)
.unwrap_or(0);
}
- ext(img, &mut (*c, *curh), &mut (w, h));
+ ext(&mut (*c, *curh), &mut (w, h));
+ let img = &mut *get_image();
let cw = c
.checked_sub(w / 2)
.unwrap_or(0);
@@ -194,7 +196,7 @@ fn draw_process(img: &mut DynamicImage, txt: &str, config: ComponentConfig<HDire
*curh += 2 * COMPONENT_TEXT_PADDING;
}
-fn draw_direction(img: &mut DynamicImage, dst: Option<&NCOffset>) {
+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();
}