Add MemoizeImpure node and cache image base64 in graph (#1595)

* Cache base64 representation of images when converting to graphic group

* Fix build

* Fix build again

* Actually fix it this time

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Dennis Kobert
2024-02-03 23:16:03 +01:00
co-authored by Keavon Chambers
parent 8fa46ba63a
commit 349ec5da72
12 changed files with 127 additions and 13 deletions
+13 -1
View File
@@ -159,7 +159,19 @@ async fn construct_artboard<Fut: Future<Output = GraphicGroup>>(
}
impl From<ImageFrame<Color>> for GraphicElement {
fn from(image_frame: ImageFrame<Color>) -> Self {
fn from(mut image_frame: ImageFrame<Color>) -> Self {
use base64::Engine;
let image = &image_frame.image;
if !image.data.is_empty() {
let output = image.to_png();
let preamble = "data:image/png;base64,";
let mut base64_string = String::with_capacity(preamble.len() + output.len() * 4);
base64_string.push_str(preamble);
base64::engine::general_purpose::STANDARD.encode_string(output, &mut base64_string);
image_frame.image.base64_string = Some(base64_string);
}
GraphicElement::ImageFrame(image_frame)
}
}