summaryrefslogtreecommitdiff
path: root/image/png/paeth.ha
diff options
context:
space:
mode:
Diffstat (limited to 'image/png/paeth.ha')
-rw-r--r--image/png/paeth.ha30
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;
+ };
+ };
+};