mirror of
https://github.com/status-im/nimPNG.git
synced 2025-01-27 04:44:52 +00:00
compile with Nim 1.0.0
This commit is contained in:
parent
77cbfc3405
commit
149fffe4e7
16
nimPNG.nim
16
nimPNG.nim
@ -2682,35 +2682,35 @@ proc filterScanLine(output: var DataBuf, scanLine, prevLine: DataBuf, len, byteW
|
||||
of FLT_SUB:
|
||||
for i in 0..byteWidth-1: output[i] = scanLine[i]
|
||||
for i in byteWidth..len-1:
|
||||
output[i] = chr(scanLine[i].uint - scanLine[i - byteWidth].uint)
|
||||
output[i] = chr((scanLine[i].uint - scanLine[i - byteWidth].uint) and 0xFF)
|
||||
of FLT_UP:
|
||||
if not prevLine.isNil:
|
||||
for i in 0..len-1:
|
||||
output[i] = chr(scanLine[i].uint - prevLine[i].uint)
|
||||
output[i] = chr((scanLine[i].uint - prevLine[i].uint) and 0xFF)
|
||||
else:
|
||||
for i in 0..len-1: output[i] = scanLine[i]
|
||||
of FLT_AVERAGE:
|
||||
if not prevLine.isNil:
|
||||
for i in 0..byteWidth-1:
|
||||
output[i] = chr(scanLine[i].uint - (prevLine[i].uint div 2))
|
||||
output[i] = chr((scanLine[i].uint - (prevLine[i].uint div 2)) and 0xFF)
|
||||
for i in byteWidth..len-1:
|
||||
output[i] = chr(scanLine[i].uint - ((scanLine[i - byteWidth].uint + prevLine[i].uint) div 2))
|
||||
output[i] = chr((scanLine[i].uint - ((scanLine[i - byteWidth].uint + prevLine[i].uint) div 2)) and 0xFF)
|
||||
else:
|
||||
for i in 0..byteWidth-1: output[i] = scanLine[i]
|
||||
for i in byteWidth..len-1:
|
||||
output[i] = chr(scanLine[i].uint - (scanLine[i - byteWidth].uint div 2))
|
||||
output[i] = chr((scanLine[i].uint - (scanLine[i - byteWidth].uint div 2)) and 0xFF)
|
||||
of FLT_PAETH:
|
||||
if not prevLine.isNil:
|
||||
#paethPredictor(0, prevLine[i], 0) is always prevLine[i]
|
||||
for i in 0..byteWidth-1:
|
||||
output[i] = chr(scanLine[i].uint - prevLine[i].uint)
|
||||
output[i] = chr((scanLine[i].uint - prevLine[i].uint) and 0xFF)
|
||||
for i in byteWidth..len-1:
|
||||
output[i] = chr(scanLine[i].uint - paethPredictor(ord(scanLine[i - byteWidth]), ord(prevLine[i]), ord(prevLine[i - byteWidth])).uint)
|
||||
output[i] = chr((scanLine[i].uint - paethPredictor(ord(scanLine[i - byteWidth]), ord(prevLine[i]), ord(prevLine[i - byteWidth])).uint) and 0xFF)
|
||||
else:
|
||||
for i in 0..byteWidth-1: output[i] = scanLine[i]
|
||||
#paethPredictor(scanLine[i - byteWidth], 0, 0) is always scanLine[i - byteWidth]
|
||||
for i in byteWidth..len-1:
|
||||
output[i] = chr(scanLine[i].uint - scanLine[i - byteWidth].uint)
|
||||
output[i] = chr((scanLine[i].uint - scanLine[i - byteWidth].uint) and 0xFF)
|
||||
|
||||
proc filterZero(output: var DataBuf, input: DataBuf, w, h, bpp: int) =
|
||||
#the width of a scanline in bytes, not including the filter type
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Package
|
||||
version = "0.2.4"
|
||||
version = "0.2.5"
|
||||
author = "Andri Lim"
|
||||
description = "PNG encoder and decoder"
|
||||
license = "MIT"
|
||||
|
@ -1,51 +1,51 @@
|
||||
import sequtils
|
||||
|
||||
type
|
||||
Buffer*[T] = object ## Uses T as internal data buffer
|
||||
data*: T
|
||||
offset*: int
|
||||
SeqBuffer*[T] = Buffer[seq[T]] ## Uses seq[T] as internal data buffer
|
||||
Buffer*[T] = object ## Uses T as internal data buffer
|
||||
data*: T
|
||||
offset*: int
|
||||
SeqBuffer*[T] = Buffer[seq[T]] ## Uses seq[T] as internal data buffer
|
||||
|
||||
template `[]`*[T](b: Buffer[T], i: int): auto = b.data[b.offset + i]
|
||||
template `[]=`*[S, T](b: var Buffer[S], i: int, v: T) = b.data[b.offset + i] = v
|
||||
|
||||
proc init*[T](b: var Buffer[T], d: T) =
|
||||
shallowCopy(b.data, d)
|
||||
b.offset = 0
|
||||
shallowCopy(b.data, d)
|
||||
b.offset = 0
|
||||
|
||||
proc initBuffer*[T](d: T): Buffer[T] =
|
||||
shallowCopy(result.data, d)
|
||||
shallowCopy(result.data, d)
|
||||
|
||||
proc subbuffer*[T](b: Buffer[T], offset: int): Buffer[T] =
|
||||
shallowCopy(result.data, b.data)
|
||||
result.offset = b.offset + offset
|
||||
shallowCopy(result.data, b.data)
|
||||
result.offset = b.offset + offset
|
||||
|
||||
template isNil*[T](b: Buffer[T]): bool =
|
||||
when T is (string or seq):
|
||||
b.data.len == 0
|
||||
else:
|
||||
b.data.isNil
|
||||
when T is (string or seq):
|
||||
b.data.len == 0
|
||||
else:
|
||||
b.data.isNil
|
||||
|
||||
template copyElements*[T](dst: var Buffer[T], src: Buffer[T], count: int) =
|
||||
when defined(js):
|
||||
for i in 0 ..< count: dst[i] = src[i]
|
||||
else:
|
||||
copyMem(addr dst[dst.offset], unsafeAddr src[src.offset], count * sizeof(dst[0]))
|
||||
when defined(js):
|
||||
for i in 0 ..< count: dst[i] = src[i]
|
||||
else:
|
||||
copyMem(addr dst[dst.offset], unsafeAddr src[src.offset], count * sizeof(dst[0]))
|
||||
|
||||
template zeroMem*[T](dst: var Buffer[T]) =
|
||||
when defined(js):
|
||||
applyIt(dst.data, type(dst[0])(0))
|
||||
else:
|
||||
zeroMem(addr dst.data[dst.offset], sizeof(dst[0]) * (dst.data.len - dst.offset))
|
||||
when defined(js):
|
||||
applyIt(dst.data, type(dst[0])(0))
|
||||
else:
|
||||
zeroMem(addr dst.data[dst.offset], sizeof(dst[0]) * (dst.data.len - dst.offset))
|
||||
|
||||
when isMainModule:
|
||||
var buf: SeqBuffer[uint8]
|
||||
buf.init(newSeq[uint8](1024))
|
||||
buf[1] = 5
|
||||
buf.offset = 1
|
||||
echo buf[0].int
|
||||
var buf: SeqBuffer[uint8]
|
||||
buf.init(newSeq[uint8](1024))
|
||||
buf[1] = 5
|
||||
buf.offset = 1
|
||||
echo buf[0].int
|
||||
|
||||
var strBuf = initBuffer(newString(20))
|
||||
strBuf[1] = 'A'
|
||||
let subBuf = strBuf.subbuffer(1)
|
||||
echo subBuf[0] # Should print A
|
||||
var strBuf = initBuffer(newString(20))
|
||||
strBuf[1] = 'A'
|
||||
let subBuf = strBuf.subbuffer(1)
|
||||
echo subBuf[0] # Should print A
|
||||
|
@ -20,9 +20,9 @@ proc toBMP(png: PNGResult, fileName: string) =
|
||||
bmp.data[px + 2] = chr(0xFF)
|
||||
else:
|
||||
let alpha = uint(x.data[px4 + 3])
|
||||
bmp.data[px] = chr(uint8(255) + uint8(((x.data[px4 + 2].uint - 255'u) * alpha) shr 8))
|
||||
bmp.data[px + 1] = chr(uint8(255) + uint8(((x.data[px4 + 1].uint - 255'u) * alpha) shr 8))
|
||||
bmp.data[px + 2] = chr(uint8(255) + uint8(((x.data[px4 + 0].uint - 255'u) * alpha) shr 8))
|
||||
bmp.data[px] = chr(uint8(255) + uint8((((x.data[px4 + 2].uint - 255'u) * alpha) shr 8) and 0xFF))
|
||||
bmp.data[px + 1] = chr(uint8(255) + uint8((((x.data[px4 + 1].uint - 255'u) * alpha) shr 8) and 0xFF))
|
||||
bmp.data[px + 2] = chr(uint8(255) + uint8((((x.data[px4 + 0].uint - 255'u) * alpha) shr 8) and 0xFF))
|
||||
|
||||
let bmpName = fileName & "_" & $frame & ".bmp"
|
||||
#var s = newFileStream(bmpName, fmWrite)
|
||||
|
Loading…
x
Reference in New Issue
Block a user