nimPNG/tester/testSuite.nim

40 lines
1.1 KiB
Nim
Raw Normal View History

2017-11-24 03:42:14 +00:00
import streams, os, strutils, nimPNG, minibmp
2015-08-28 15:56:55 +00:00
proc loadPNG(fileName: string): BMP =
2015-09-03 04:56:22 +00:00
var settings = makePNGDecoder()
2015-08-28 15:56:55 +00:00
settings.readTextChunks = true
var png = loadPNG24(fileName, settings)
if png == nil: return nil
let size = png.width * png.height
result = newBMP(png.width, png.height)
for i in 0..size-1:
let px = i * 3
result.data[px] = png.data[px]
result.data[px + 1] = png.data[px + 1]
result.data[px + 2] = png.data[px + 2]
proc write(bmp: BMP): string =
var s = newStringStream()
s.write(bmp)
result = s.data
proc convert(dir: string) =
for fileName in walkDirRec(dir, {pcFile}):
let path = splitFile(fileName)
if path.ext.len() == 0: continue
2016-08-24 02:56:11 +00:00
let ext = toLowerAscii(path.ext)
2015-08-28 15:56:55 +00:00
if ext != ".png": continue
if path.name[0] == 'x': continue
2017-11-24 03:42:14 +00:00
2015-08-28 15:56:55 +00:00
let bmpName = path.dir & DirSep & path.name & ExtSep & "bmp"
2017-11-24 03:42:14 +00:00
2015-08-28 15:56:55 +00:00
echo fileName, " vs. ", bmpName
var bmp = loadPNG(fileName)
if bmp != nil:
let data1 = bmp.write()
let data2 = readFile(bmpName)
assert data1 == data2
2017-05-19 15:07:32 +00:00
convert(".." & DirSep & "suite")