add missing openArray API

This commit is contained in:
jangko 2020-06-11 21:11:45 +07:00
parent e91cfff314
commit 0bd20601a3
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 27 additions and 6 deletions

View File

@ -2962,11 +2962,17 @@ proc encodePNG*[T](input: T, colorType: PNGColorType, bitDepth, w, h: int, setti
state.modeIn.bitDepth = bitDepth
result = encodePNG(input, w, h, state)
proc encodePNG32*[T](input: T, w, h: int): PNG[T] =
result = encodePNG(input, LCT_RGBA, 8, w, h)
template encodePNG32*[T](input: T, w, h: int): auto =
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] =
result = encodePNG(input, LCT_RGB, 8, w, h)
template encodePNG24*[T](input: T, w, h: int): auto =
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) =
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 =
when T is string:
savePNGLegacy(fileName, input, colorType, bitDepth, w , h)
elif T is openArray:
savePNGImpl(fileName, @(input), colorType, bitDepth, w , h)
else:
savePNGImpl(fileName, input, colorType, bitDepth, w , h)
template savePNG32*[T](fileName: string, input: T, w, h: int): untyped =
when T is string:
savePNG32Legacy(fileName, input, w, h)
elif T is openArray:
savePNG32Impl(fileName, @(input), w, h)
else:
savePNG32Impl(fileName, input, w, h)
template savePNG24*[T](fileName: string, input: T, w, h: int): untyped =
when T is string:
savePNG24Legacy(fileName, input, w, h)
elif T is openArray:
savePNG24Impl(fileName, @(input), w, h)
else:
savePNG24Impl(fileName, input, w, h)

View File

@ -34,8 +34,17 @@ proc main() =
check savePNG32(subject32, png2.data, png2.width, png2.height).isOk() == true
test "decodePNG openArray[uint8]":
let png1 = decodePNG24(data.toOpenArrayByte(0, data.len-1))
let png2 = decodePNG32(data.toOpenArrayByte(0, data.len-1))
let res1 = decodePNG24(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":
let png1 = loadPNG32(string, subject)