diff options
author | bptato <nincsnevem662@gmail.com> | 2024-06-21 00:05:25 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-06-21 00:17:03 +0200 |
commit | b8a21c2407a9898a538852098eca5658de5afd37 (patch) | |
tree | e41ad69d5473a4775537ed61707d6d31cce5c104 /src/js | |
parent | 7f66b5ebc88936db974e3320d77c7ec9d4ab85e6 (diff) | |
download | chawan-b8a21c2407a9898a538852098eca5658de5afd37.tar.gz |
img, term: try to detect unknown images, improve kitty encoder
* preserve alpha in kitty + simplify encoder * pass unknown image types to stbi (as image/x-unknown) and let it detect the type
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/base64.nim | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/js/base64.nim b/src/js/base64.nim index 85844e09..b6941ef6 100644 --- a/src/js/base64.nim +++ b/src/js/base64.nim @@ -1,7 +1,7 @@ -import monoucha/quickjs import js/domexception import monoucha/javascript import monoucha/jstypes +import monoucha/quickjs import types/opt import utils/twtstr @@ -9,6 +9,7 @@ import utils/twtstr # anything above latin-1.) proc atob*(data: string): DOMResult[NarrowString] = + # Note: the actual atob implementation (atob0) is in twtstr. let r = atob0(data) if r.isNone: return err(newDOMException(r.error, "InvalidCharacterError")) @@ -16,13 +17,7 @@ proc atob*(data: string): DOMResult[NarrowString] = const AMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" -func btoa*(data: openArray[uint8]): string = - if data.len == 0: - return "" - var L = data.len div 3 * 4 - if (let rem = data.len mod 3; rem) > 0: - L += 3 - rem - var s = newStringOfCap(L) +func btoa*(s: var string; data: openArray[uint8]) = var i = 0 let endw = data.len - 2 while i < endw: @@ -47,6 +42,15 @@ func btoa*(data: openArray[uint8]): string = s &= AMap[b1 shl 4 and 0x3F] # 2 bits of b1 s &= '=' s &= '=' + +func btoa*(data: openArray[uint8]): string = + if data.len == 0: + return "" + var L = data.len div 3 * 4 + if (let rem = data.len mod 3; rem) > 0: + L += 3 - rem + var s = newStringOfCap(L) + s.btoa(data) return s func btoa*(data: string): string = |