def png.palette
gralha-png-decode@0.1.0.1 · png.bend:92
import gralha-png-decode@0.1.0.1/png.bend as Png
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U
import gralha-bytes@0.1.0.1/bytes.bend as Bin
import gralha-image@0.1.0.1/image.bend as Img
92def png.palette(+palette: Bin.Bytes, +alpha: Bin.Bytes, +index: U32) -> Img.Color:
93 +at = (index * 3 : U32)
94 U.branch(Img.Color, U32.is_lt((at + 2 : U32), Bin.bytes.size(palette)),
95 _ => Img.rgba((U32.to_f32(Bin.bytes.get(palette, at)) / 255.0 : F32), (U32.to_f32(Bin.bytes.get(palette, U32.inc(at))) / 255.0 : F32), (U32.to_f32(Bin.bytes.get(palette, (at + 2 : U32))) / 255.0 : F32), (U32.to_f32(U.choose(U32, U32.is_lt(index, Bin.bytes.size(alpha)), Bin.bytes.get(alpha, index), 255)) / 255.0 : F32)), _ => Img.clear())