faster
This commit is contained in:
parent
ad303de223
commit
ff45edf131
1 changed files with 26 additions and 14 deletions
|
@ -114,39 +114,51 @@ proc unfilter(
|
||||||
rowBytes
|
rowBytes
|
||||||
)
|
)
|
||||||
of 1: # Sub
|
of 1: # Sub
|
||||||
|
let
|
||||||
|
uncompressedStartIdx = uncompressedIdx(1, y)
|
||||||
|
unfilteredStartIx = unfiteredIdx(0, y)
|
||||||
for x in 0 ..< rowBytes:
|
for x in 0 ..< rowBytes:
|
||||||
var value = uncompressed.readUint8(uncompressedIdx(x + 1, y))
|
var value = uncompressed.readUint8(uncompressedStartIdx + x)
|
||||||
if x - bpp >= 0:
|
if x - bpp >= 0:
|
||||||
value += result.readUint8(unfiteredIdx(x - bpp, y))
|
value += result.readUint8(unfilteredStartIx + x - bpp)
|
||||||
result[unfiteredIdx(x, y)] = value.char
|
result[unfilteredStartIx + x] = value.char
|
||||||
of 2: # Up
|
of 2: # Up
|
||||||
|
let
|
||||||
|
uncompressedStartIdx = uncompressedIdx(1, y)
|
||||||
|
unfilteredStartIx = unfiteredIdx(0, y)
|
||||||
for x in 0 ..< rowBytes:
|
for x in 0 ..< rowBytes:
|
||||||
var value = uncompressed.readUint8(uncompressedIdx(x + 1, y))
|
var value = uncompressed.readUint8(uncompressedStartIdx + x)
|
||||||
if y - 1 >= 0:
|
if y - 1 >= 0:
|
||||||
value += result.readUint8(unfiteredIdx(x, y - 1))
|
value += result.readUint8(unfiteredIdx(x, y - 1))
|
||||||
result[unfiteredIdx(x, y)] = value.char
|
result[unfilteredStartIx + x] = value.char
|
||||||
of 3: # Average
|
of 3: # Average
|
||||||
|
let
|
||||||
|
uncompressedStartIdx = uncompressedIdx(1, y)
|
||||||
|
unfilteredStartIx = unfiteredIdx(0, y)
|
||||||
for x in 0 ..< rowBytes:
|
for x in 0 ..< rowBytes:
|
||||||
var
|
var
|
||||||
value = uncompressed.readUint8(uncompressedIdx(x + 1, y))
|
value = uncompressed.readUint8(uncompressedStartIdx + x)
|
||||||
left, up: int
|
left, up: int
|
||||||
if x - bpp >= 0:
|
if x - bpp >= 0:
|
||||||
left = result[unfiteredIdx(x - bpp, y)].int
|
left = result[unfilteredStartIx + x - bpp].int
|
||||||
if y - 1 >= 0:
|
if y - 1 >= 0:
|
||||||
up = result[unfiteredIdx(x, y - 1)].int
|
up = result[unfilteredStartIx + x - rowBytes].int
|
||||||
value += ((left + up) div 2).uint8
|
value += ((left + up) div 2).uint8
|
||||||
result[unfiteredIdx(x, y)] = value.char
|
result[unfilteredStartIx + x] = value.char
|
||||||
of 4: # Paeth
|
of 4: # Paeth
|
||||||
|
let
|
||||||
|
uncompressedStartIdx = uncompressedIdx(1, y)
|
||||||
|
unfilteredStartIx = unfiteredIdx(0, y)
|
||||||
for x in 0 ..< rowBytes:
|
for x in 0 ..< rowBytes:
|
||||||
var
|
var
|
||||||
value = uncompressed.readUint8(uncompressedIdx(x + 1, y))
|
value = uncompressed.readUint8(uncompressedStartIdx + x)
|
||||||
left, up, upLeft: int
|
left, up, upLeft: int
|
||||||
if x - bpp >= 0:
|
if x - bpp >= 0:
|
||||||
left = result[unfiteredIdx(x - bpp, y)].int
|
left = result[unfilteredStartIx + x - bpp].int
|
||||||
if y - 1 >= 0:
|
if y - 1 >= 0:
|
||||||
up = result[unfiteredIdx(x, y - 1)].int
|
up = result[unfilteredStartIx + x - rowBytes].int
|
||||||
if x - bpp >= 0 and y - 1 >= 0:
|
if x - bpp >= 0 and y - 1 >= 0:
|
||||||
upLeft = result[unfiteredIdx(x - bpp, y - 1)].int
|
upLeft = result[unfilteredStartIx + x - rowBytes - bpp].int
|
||||||
template paethPredictor(a, b, c: int): int =
|
template paethPredictor(a, b, c: int): int =
|
||||||
let
|
let
|
||||||
p = a + b - c
|
p = a + b - c
|
||||||
|
@ -160,7 +172,7 @@ proc unfilter(
|
||||||
else:
|
else:
|
||||||
c
|
c
|
||||||
value += paethPredictor(up, left, upLeft).uint8
|
value += paethPredictor(up, left, upLeft).uint8
|
||||||
result[unfiteredIdx(x, y)] = value.char
|
result[unfilteredStartIx + x] = value.char
|
||||||
else:
|
else:
|
||||||
discard # Not possible, parseHeader validates
|
discard # Not possible, parseHeader validates
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue