From 7304e5e28c9cd5816aa4bb233322dbf8ffa8bc60 Mon Sep 17 00:00:00 2001 From: andri lim Date: Mon, 13 Apr 2020 21:28:55 +0700 Subject: [PATCH] gc:arc refactor add LFS_MINSUM, LFS_BRUTEFORCE and add tests --- nimPNG/filters.nim | 116 +++++++++++++++++++++++------------------ nimPNG/nimz.nim | 5 +- tests/test_filters.nim | 19 ++++++- 3 files changed, 87 insertions(+), 53 deletions(-) diff --git a/nimPNG/filters.nim b/nimPNG/filters.nim index e60d6aa..81107ed 100644 --- a/nimPNG/filters.nim +++ b/nimPNG/filters.nim @@ -1,4 +1,4 @@ -import math +import math, ../nimPNG/nimz type PNGFilter* = enum @@ -101,55 +101,64 @@ proc filterZero*(output: var openArray[byte], input: openArray[byte], w, h, bpp: input.toOpenArray(prevIndex, input.len-1), byteWidth, lineBytes, FLT_NONE) prevIndex = inIndex - -#[ + + proc filterMinsum*(output: var openArray[byte], input: openArray[byte], w, h, bpp: int) = let lineBytes = (w * bpp + 7) div 8 let byteWidth = (bpp + 7) div 8 #adaptive filtering - var sum = [0, 0, 0, 0, 0] - var smallest = 0 - - #five filtering attempts, one for each filter type - var attempt: array[0..4, string] - var bestType = 0 - var prevLine: DataBuf + var + sum = [0, 0, 0, 0, 0] + smallest = 0 + # five filtering attempts, one for each filter type + attempt: array[0..4, seq[byte]] + bestType = 0 + prevIndex = 0 for i in 0..attempt.high: - attempt[i] = newString(lineBytes) + attempt[i] = newSeq[byte](lineBytes) - for y in 0..h-1: - #try the 5 filter types + for y in 0..