diff options
author | Lassi Pulkkinen <lassi@pulk.fi> | 2024-10-31 03:11:21 +0200 |
---|---|---|
committer | Lassi Pulkkinen <lassi@pulk.fi> | 2024-10-31 03:51:35 +0200 |
commit | ae44478b30d890fe0fb04022f44d474dcdcc3f9d (patch) | |
tree | 5f462459ae4b47d22114eed717d1382d08cf4dfe /image/png/paeth.ha |
Diffstat (limited to 'image/png/paeth.ha')
-rw-r--r-- | image/png/paeth.ha | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/image/png/paeth.ha b/image/png/paeth.ha new file mode 100644 index 0000000..4abc373 --- /dev/null +++ b/image/png/paeth.ha @@ -0,0 +1,30 @@ +// Based on Go's implementation; BSD license +use math; + +fn applypaeth(dec: *decoder) void = { + const bpp = dec.bpp; + let a = 0i32, b = 0i32, c = 0i32, pa = 0i32, pb = 0i32, pc = 0i32; + for (let i = 0z; i < bpp; i += 1) { + a = 0; + c = 0; + for (let j = i; j < len(dec.cr); j += bpp) { + b = dec.pr[j]: i32; + pa = b - c; + pb = a - c; + pc = math::absi32(pa + pb): i32; + pa = math::absi32(pa): i32; + pb = math::absi32(pb): i32; + if (pa <= pb && pa <= pc) { + void; // no-op + } else if (pb <= pc) { + a = b; + } else { + a = c; + }; + a += dec.cr[j]: i32; + a &= 0xff; + dec.cr[j] = a: u8; + c = b; + }; + }; +}; |