mirror of https://github.com/status-im/nimPNG.git
close stream properly
This commit is contained in:
parent
ee66f3b58f
commit
316a345290
21
nimPNG.nim
21
nimPNG.nim
|
@ -26,10 +26,9 @@
|
|||
#-------------------------------------
|
||||
|
||||
import unsigned, streams, endians, tables, hashes, math, nimz
|
||||
import strutils
|
||||
|
||||
const
|
||||
NIM_PNG_VERSION = "0.1.0"
|
||||
NIM_PNG_VERSION = "0.1.1"
|
||||
|
||||
type
|
||||
PNGChunkType = distinct int32
|
||||
|
@ -193,17 +192,6 @@ type
|
|||
height*: int
|
||||
data*: string
|
||||
|
||||
proc toHex*(input: string) =
|
||||
var i = 0
|
||||
for x in 0..input.high:
|
||||
write(stdout, toHex(ord(input[x]), 2))
|
||||
inc i
|
||||
if i == 40:
|
||||
write(stdout, "\n")
|
||||
i = 0
|
||||
if i < 40:
|
||||
write(stdout, "\n")
|
||||
|
||||
proc makePNGDecoder*(): PNGDecoder =
|
||||
var s: PNGDecoder
|
||||
new(s)
|
||||
|
@ -1779,6 +1767,7 @@ proc loadPNG*(fileName: string, colorType: PNGcolorType, bitDepth: int, settings
|
|||
var s = newFileStream(fileName, fmRead)
|
||||
if s == nil: return nil
|
||||
result = s.PNGDecode(colorType, bitDepth, settings)
|
||||
s.close()
|
||||
except:
|
||||
debugEcho getCurrentExceptionMsg()
|
||||
result = nil
|
||||
|
@ -2832,10 +2821,6 @@ proc `$`(colorType: PNGColorType): string =
|
|||
of LCT_RGBA: result = "LCT_RGBA"
|
||||
else: result = "LCT_UNKNOWN"
|
||||
|
||||
proc show*(mode: PNGColorMode) =
|
||||
for k, v in fieldPairs(mode[]):
|
||||
echo k, " ", $v
|
||||
|
||||
proc PNGEncode*(input: string, w, h: int, settings = PNGEncoder(nil)): PNG =
|
||||
var png: PNG
|
||||
new(png)
|
||||
|
@ -2966,6 +2951,7 @@ proc savePNG32*(fileName, input: string, w, h: int): bool =
|
|||
var png = PNGEncode(input, LCT_RGBA, 8, w, h)
|
||||
var s = newFileStream(fileName, fmWrite)
|
||||
png.writeChunks s
|
||||
s.close()
|
||||
result = true
|
||||
except:
|
||||
debugEcho getCurrentExceptionMsg()
|
||||
|
@ -2976,6 +2962,7 @@ proc savePNG24*(fileName, input: string, w, h: int): bool =
|
|||
var png = PNGEncode(input, LCT_RGB, 8, w, h)
|
||||
var s = newFileStream(fileName, fmWrite)
|
||||
png.writeChunks s
|
||||
s.close()
|
||||
result = true
|
||||
except:
|
||||
debugEcho getCurrentExceptionMsg()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[Package]
|
||||
name = "nimPNG"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
author = "Andri Lim"
|
||||
description = "PNG encoder and decoder"
|
||||
license = "MIT"
|
||||
|
|
Loading…
Reference in New Issue