2020-11-21 04:08:57 +00:00
|
|
|
import pixie, chroma, vmath, fidget/opengl/perf, pixie/fileformats/bmp
|
|
|
|
|
2020-11-22 00:51:29 +00:00
|
|
|
proc inPlaceDraw*(destImage: Image, srcImage: Image, mat: Mat3, blendMode = bmNormal) =
|
2020-11-21 05:50:13 +00:00
|
|
|
## Draws one image onto another using matrix with color blending.
|
|
|
|
for y in 0 ..< destImage.width:
|
|
|
|
for x in 0 ..< destImage.height:
|
|
|
|
let srcPos = mat * vec2(x.float32, y.float32)
|
|
|
|
let destRgba = destImage.getRgbaUnsafe(x, y)
|
|
|
|
var rgba = destRgba
|
|
|
|
var srcRgba = rgba(0, 0, 0, 0)
|
|
|
|
if srcImage.inside(srcPos.x.floor.int, srcPos.y.floor.int):
|
|
|
|
srcRgba = srcImage.getRgbaSmooth(srcPos.x - 0.5, srcPos.y - 0.5)
|
|
|
|
if blendMode.hasEffect(srcRgba):
|
|
|
|
rgba = blendMode.mix(destRgba, srcRgba)
|
|
|
|
destImage.setRgbaUnsafe(x, y, rgba)
|
|
|
|
|
2020-11-22 00:51:29 +00:00
|
|
|
proc inPlaceDraw*(destImage: Image, srcImage: Image, pos = vec2(0, 0), blendMode = bmNormal) =
|
2020-11-21 05:50:13 +00:00
|
|
|
destImage.inPlaceDraw(srcImage, translate(-pos), blendMode)
|
|
|
|
|
2020-11-21 04:08:57 +00:00
|
|
|
block:
|
|
|
|
var a = newImage(100, 100)
|
|
|
|
a.fill(rgba(255, 0, 0, 255))
|
|
|
|
var b = newImage(100, 100)
|
|
|
|
b.fill(rgba(0, 255, 0, 255))
|
2020-11-21 05:50:13 +00:00
|
|
|
a.inPlaceDraw(b, pos=vec2(25, 25))
|
|
|
|
writeFile("tests/images/inPlaceDraw.bmp", a.encodeBmp())
|
2020-11-21 04:08:57 +00:00
|
|
|
|
|
|
|
block:
|
|
|
|
var a = newImage(100, 100)
|
|
|
|
a.fill(rgba(255, 0, 0, 255))
|
|
|
|
var b = newImage(100, 100)
|
|
|
|
b.fill(rgba(0, 255, 0, 255))
|
2020-11-22 00:51:29 +00:00
|
|
|
var c = a.drawFast3(b, translate(vec2(25, 25)), bmNormal)
|
2020-11-21 04:08:57 +00:00
|
|
|
writeFile("tests/images/copyDraw.bmp", c.encodeBmp())
|
|
|
|
|
2020-11-21 05:50:13 +00:00
|
|
|
timeIt "inPlaceDraw":
|
2020-11-21 04:08:57 +00:00
|
|
|
var tmp = 0
|
2020-11-21 05:50:13 +00:00
|
|
|
for i in 0 ..< 1000:
|
2020-11-21 04:08:57 +00:00
|
|
|
var a = newImage(100, 100)
|
|
|
|
a.fill(rgba(255, 0, 0, 255))
|
|
|
|
var b = newImage(100, 100)
|
|
|
|
b.fill(rgba(0, 255, 0, 255))
|
2020-11-21 05:50:13 +00:00
|
|
|
a.inPlaceDraw(b, pos=vec2(25, 25))
|
2020-11-21 04:08:57 +00:00
|
|
|
tmp += a.width * a.height
|
|
|
|
echo tmp
|
|
|
|
|
|
|
|
timeIt "copyDraw":
|
|
|
|
var tmp = 0
|
2020-11-21 05:50:13 +00:00
|
|
|
for i in 0 ..< 1000:
|
2020-11-21 04:08:57 +00:00
|
|
|
var a = newImage(100, 100)
|
|
|
|
a.fill(rgba(255, 0, 0, 255))
|
|
|
|
var b = newImage(100, 100)
|
|
|
|
b.fill(rgba(0, 255, 0, 255))
|
2020-11-22 00:51:29 +00:00
|
|
|
var c = a.drawFast3(b, translate(vec2(25, 25)), bmNormal)
|
2020-11-21 04:08:57 +00:00
|
|
|
tmp += c.width * c.height
|
|
|
|
echo tmp
|