⭐ Moe-Counter Compatible Website Hit Counter Written in Gleam mayu.due.moe
hit-counter svg moe
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(image): use purely bit array syntax

Fuwn e828ac94 4de61ce9

+9 -20
+1 -1
gleam.toml
··· 2 2 # https://gleam.run/writing-gleam/gleam-toml/. 3 3 4 4 name = "mayu" 5 - version = "0.1.1" 5 + version = "0.1.4" 6 6 gleam = ">= 1.1.0" 7 7 description = "Moe-Counter Compatible Website Hit Counter" 8 8 licenses = ["GPL-3.0-only"]
+8 -19
src/image.gleam
··· 1 - import gleam/int 2 - 3 1 pub type ImageInformation { 4 2 ImageInformation(width: Int, height: Int, extension: String) 5 3 } 6 4 7 5 pub fn get_image_information(image) { 8 6 case image { 9 - <<0x89, "PNG\r\n":utf8, 0x1A, 0x0A, _:bits>> -> parse_png_chunks(image, 8) 7 + <<0x89, "PNG\r\n":utf8, 0x1A, "\n":utf8, _rest:bits>> -> 8 + parse_png_chunks(image, 8) 10 9 << 11 10 "GIF":utf8, 12 - _:16, 13 - _:unsigned, 14 - width_0:8, 15 - width_1:8, 16 - height_0:8, 17 - height_1:8, 11 + _version:unsigned-24, 12 + width:little-16, 13 + height:little-16, 18 14 _rest:bits, 19 - >> -> 20 - Ok(ImageInformation( 21 - int.bitwise_or(width_0, int.bitwise_shift_left(width_1, 8)), 22 - int.bitwise_or(height_0, int.bitwise_shift_left(height_1, 8)), 23 - "gif", 24 - )) 15 + >> -> Ok(ImageInformation(width, height, "gif")) 25 16 _ -> Error("Unsupported image format") 26 17 } 27 18 } 28 19 29 20 fn parse_png_chunks(image, offset) { 30 - let offset_bits = offset * 8 31 - 32 21 case image { 33 22 << 34 - _:size(offset_bits), 23 + _:unit(8)-size(offset), 35 24 _length:32, 36 25 "IHDR":utf8, 37 26 width:32, 38 27 height:32, 39 - _:bits, 28 + _rest:bits, 40 29 >> -> Ok(ImageInformation(width, height, "png")) 41 30 <<_:size(offset), length:32, _:4, _:bits>> -> 42 31 parse_png_chunks(image, offset + length + 12)