diff options
| author | Fuwn <[email protected]> | 2026-04-17 17:13:51 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-04-17 17:13:51 +0000 |
| commit | 6089ff1b9fc921d6aa85287ee52abae951b1bfe0 (patch) | |
| tree | 8184df13e7707fe8469f47f2645a6ea42797d243 /src/image.gleam | |
| parent | chore(gleam.toml): Bump version (diff) | |
| download | mayu-6089ff1b9fc921d6aa85287ee52abae951b1bfe0.tar.xz mayu-6089ff1b9fc921d6aa85287ee52abae951b1bfe0.zip | |
perf: Reduce per-request work and I/O in render pipeline
Diffstat (limited to 'src/image.gleam')
| -rw-r--r-- | src/image.gleam | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/image.gleam b/src/image.gleam index 93fe300..0ce82ea 100644 --- a/src/image.gleam +++ b/src/image.gleam @@ -4,8 +4,17 @@ pub type ImageInformation { pub fn get_image_information(image) { case image { - <<0x89, "PNG\r\n":utf8, 0x1A, "\n":utf8, _rest:bits>> -> - parse_png_chunks(image, 8) + << + 0x89, + "PNG\r\n":utf8, + 0x1A, + "\n":utf8, + _length:32, + "IHDR":utf8, + width:32, + height:32, + _rest:bits, + >> -> Ok(ImageInformation(width, height, "png")) << "GIF":utf8, _version:bytes-3, @@ -16,19 +25,3 @@ pub fn get_image_information(image) { _ -> Error("Unsupported image format") } } - -fn parse_png_chunks(image, offset) { - case image { - << - _:unit(8)-size(offset), - _length:32, - "IHDR":utf8, - width:32, - height:32, - _rest:bits, - >> -> Ok(ImageInformation(width, height, "png")) - <<_:size(offset), length:32, _:4, _:bits>> -> - parse_png_chunks(image, offset + length + 12) - _ -> Error("Invalid PNG chunk") - } -} |