simpler
This commit is contained in:
parent
0af140b047
commit
0600a59148
2 changed files with 13 additions and 19 deletions
|
@ -90,9 +90,7 @@ proc decodePalette(data: pointer, len: int): seq[ColorRGB] =
|
||||||
|
|
||||||
result.setLen(len div 3)
|
result.setLen(len div 3)
|
||||||
|
|
||||||
let data = cast[ptr UncheckedArray[uint8]](data)
|
copyMem(result[0].addr, data, len)
|
||||||
for i in 0 ..< len div 3:
|
|
||||||
copyMem(result[i].addr, data[i * 3].unsafeAddr, 3)
|
|
||||||
|
|
||||||
proc unfilter(
|
proc unfilter(
|
||||||
uncompressed: string, height, rowBytes, bpp: int
|
uncompressed: string, height, rowBytes, bpp: int
|
||||||
|
@ -275,12 +273,15 @@ proc decodeImageData(
|
||||||
result[i].a = 255
|
result[i].a = 255
|
||||||
|
|
||||||
let lastOffset = header.height * header.width - 1
|
let lastOffset = header.height * header.width - 1
|
||||||
var rgb: array[3, uint8]
|
var rgba = rgba(
|
||||||
copyMem(rgb.addr, unfiltered[lastOffset * 3].unsafeAddr, 3)
|
unfiltered[lastOffset * 3 + 0].uint8,
|
||||||
var rgba = ColorRGBA(r: rgb[0], g: rgb[1], b: rgb[2], a: 255)
|
unfiltered[lastOffset * 3 + 1].uint8,
|
||||||
|
unfiltered[lastOffset * 3 + 2].uint8,
|
||||||
|
255
|
||||||
|
)
|
||||||
if rgba == special:
|
if rgba == special:
|
||||||
rgba.a = 0
|
rgba.a = 0
|
||||||
result[header.height * header.width - 1] = cast[ColorRGBA](rgba)
|
result[header.height * header.width - 1] = rgba
|
||||||
of 3:
|
of 3:
|
||||||
var bytePos, bitPos: int
|
var bytePos, bitPos: int
|
||||||
for y in 0 ..< header.height:
|
for y in 0 ..< header.height:
|
||||||
|
|
|
@ -1,17 +1,10 @@
|
||||||
import pixie, pixie/fileformats/png, pngsuite, strformat
|
import pixie, pixie/fileformats/png, pngsuite, strformat
|
||||||
|
|
||||||
# for file in pngSuiteFiles:
|
for file in pngSuiteFiles:
|
||||||
# let
|
let
|
||||||
# original = cast[seq[uint8]](
|
original = readFile(&"tests/fileformats/png/pngsuite/{file}.png")
|
||||||
# readFile(&"tests/images/png/pngsuite/{file}.png")
|
decoded = decodePng(original)
|
||||||
# )
|
encoded = encodePng(decoded)
|
||||||
# decoded = decodePng(original)
|
|
||||||
# encoded = encodePng(decoded)
|
|
||||||
# decoded2 = decodePng(cast[seq[uint8]](encoded))
|
|
||||||
|
|
||||||
# doAssert decoded.height == decoded2.height
|
|
||||||
# doAssert decoded.width == decoded2.width
|
|
||||||
# doAssert decoded.data == decoded2.data
|
|
||||||
|
|
||||||
block:
|
block:
|
||||||
for channels in 1 .. 4:
|
for channels in 1 .. 4:
|
||||||
|
|
Loading…
Reference in a new issue