mirror of https://github.com/status-im/nimPNG.git
add missing openArray API
This commit is contained in:
parent
e91cfff314
commit
0bd20601a3
20
nimPNG.nim
20
nimPNG.nim
|
@ -2962,11 +2962,17 @@ proc encodePNG*[T](input: T, colorType: PNGColorType, bitDepth, w, h: int, setti
|
||||||
state.modeIn.bitDepth = bitDepth
|
state.modeIn.bitDepth = bitDepth
|
||||||
result = encodePNG(input, w, h, state)
|
result = encodePNG(input, w, h, state)
|
||||||
|
|
||||||
proc encodePNG32*[T](input: T, w, h: int): PNG[T] =
|
template encodePNG32*[T](input: T, w, h: int): auto =
|
||||||
result = encodePNG(input, LCT_RGBA, 8, w, h)
|
when T is openArray:
|
||||||
|
encodePNG(@(input), LCT_RGBA, 8, w, h)
|
||||||
|
else:
|
||||||
|
encodePNG(input, LCT_RGBA, 8, w, h)
|
||||||
|
|
||||||
proc encodePNG24*[T](input: T, w, h: int): PNG[T] =
|
template encodePNG24*[T](input: T, w, h: int): auto =
|
||||||
result = encodePNG(input, LCT_RGB, 8, w, h)
|
when T is openArray:
|
||||||
|
encodePNG(@(input), LCT_RGB, 8, w, h)
|
||||||
|
else:
|
||||||
|
encodePNG(input, LCT_RGB, 8, w, h)
|
||||||
|
|
||||||
proc writeChunks*[T](png: PNG[T], s: Stream) =
|
proc writeChunks*[T](png: PNG[T], s: Stream) =
|
||||||
s.write PNGSignature
|
s.write PNGSignature
|
||||||
|
@ -3115,18 +3121,24 @@ when not defined(js):
|
||||||
template savePNG*[T](fileName: string, input: T, colorType: PNGColorType, bitDepth, w, h: int): untyped =
|
template savePNG*[T](fileName: string, input: T, colorType: PNGColorType, bitDepth, w, h: int): untyped =
|
||||||
when T is string:
|
when T is string:
|
||||||
savePNGLegacy(fileName, input, colorType, bitDepth, w , h)
|
savePNGLegacy(fileName, input, colorType, bitDepth, w , h)
|
||||||
|
elif T is openArray:
|
||||||
|
savePNGImpl(fileName, @(input), colorType, bitDepth, w , h)
|
||||||
else:
|
else:
|
||||||
savePNGImpl(fileName, input, colorType, bitDepth, w , h)
|
savePNGImpl(fileName, input, colorType, bitDepth, w , h)
|
||||||
|
|
||||||
template savePNG32*[T](fileName: string, input: T, w, h: int): untyped =
|
template savePNG32*[T](fileName: string, input: T, w, h: int): untyped =
|
||||||
when T is string:
|
when T is string:
|
||||||
savePNG32Legacy(fileName, input, w, h)
|
savePNG32Legacy(fileName, input, w, h)
|
||||||
|
elif T is openArray:
|
||||||
|
savePNG32Impl(fileName, @(input), w, h)
|
||||||
else:
|
else:
|
||||||
savePNG32Impl(fileName, input, w, h)
|
savePNG32Impl(fileName, input, w, h)
|
||||||
|
|
||||||
template savePNG24*[T](fileName: string, input: T, w, h: int): untyped =
|
template savePNG24*[T](fileName: string, input: T, w, h: int): untyped =
|
||||||
when T is string:
|
when T is string:
|
||||||
savePNG24Legacy(fileName, input, w, h)
|
savePNG24Legacy(fileName, input, w, h)
|
||||||
|
elif T is openArray:
|
||||||
|
savePNG24Impl(fileName, @(input), w, h)
|
||||||
else:
|
else:
|
||||||
savePNG24Impl(fileName, input, w, h)
|
savePNG24Impl(fileName, input, w, h)
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,17 @@ proc main() =
|
||||||
check savePNG32(subject32, png2.data, png2.width, png2.height).isOk() == true
|
check savePNG32(subject32, png2.data, png2.width, png2.height).isOk() == true
|
||||||
|
|
||||||
test "decodePNG openArray[uint8]":
|
test "decodePNG openArray[uint8]":
|
||||||
let png1 = decodePNG24(data.toOpenArrayByte(0, data.len-1))
|
let res1 = decodePNG24(data.toOpenArrayByte(0, data.len-1))
|
||||||
let png2 = decodePNG32(data.toOpenArrayByte(0, data.len-1))
|
let res2 = decodePNG32(data.toOpenArrayByte(0, data.len-1))
|
||||||
|
|
||||||
|
check res1.isOk() == true
|
||||||
|
check res2.isOk() == true
|
||||||
|
|
||||||
|
let png1 = res1.get()
|
||||||
|
let png2 = res2.get()
|
||||||
|
|
||||||
|
let im1 = encodePNG24(png1.data.toOpenArray(0, png1.data.len-1), png1.width, png1.height)
|
||||||
|
let im2 = encodePNG32(png2.data.toOpenArray(0, png2.data.len-1), png2.width, png2.height)
|
||||||
|
|
||||||
test "loadPNG string":
|
test "loadPNG string":
|
||||||
let png1 = loadPNG32(string, subject)
|
let png1 = loadPNG32(string, subject)
|
||||||
|
|
Loading…
Reference in New Issue