diff --git a/README.md b/README.md index 013d0bb..fe5474a 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,3 @@ BlurHash Implementation in Odin -### TODO -- [ ] Clean up memory leaks diff --git a/blurhash.odin b/blurhash.odin index 73ff962..d67b314 100644 --- a/blurhash.odin +++ b/blurhash.odin @@ -61,9 +61,7 @@ base83_decode_str :: proc(str: string) -> int { base83_decode :: proc{base83_decode_str, base83_decode_byte} @(private) -base83_encode :: proc(value, length: int, allocator := context.allocator) -> string { - b := strings.builder_make_none(allocator) - +base83_encode :: proc(b: ^strings.Builder, value, length: int, allocator := context.allocator) { pow :: proc(base, exp: int) -> int { base := base exp := exp @@ -80,10 +78,8 @@ base83_encode :: proc(value, length: int, allocator := context.allocator) -> str for i in 1..=length { digit := (value / pow(83, length - i)) % 83 - strings.write_byte(&b, ENC_TABLE[digit]) + strings.write_byte(b, ENC_TABLE[digit]) } - - return strings.to_string(b) } @(private) @@ -168,6 +164,7 @@ decode :: proc(blurhash: string, width, height: int, punch := 1.0, allocator := colors_size := num_x * num_y colors := make([][3]f32, colors_size) + defer delete(colors) for iter in 0..