2021-02-27 00:42:40 +00:00
|
|
|
import benchy, chroma, pixie, pixie/internal
|
2020-12-03 20:21:58 +00:00
|
|
|
|
2021-02-08 20:31:20 +00:00
|
|
|
let image = newImage(2560, 1440)
|
|
|
|
|
|
|
|
proc reset() =
|
|
|
|
image.fill(rgba(63, 127, 191, 191))
|
|
|
|
|
|
|
|
reset()
|
2020-12-03 20:21:58 +00:00
|
|
|
|
|
|
|
timeIt "fill":
|
2021-02-08 20:31:20 +00:00
|
|
|
image.fill(rgba(255, 255, 255, 255))
|
|
|
|
doAssert image[0, 0] == rgba(255, 255, 255, 255)
|
|
|
|
|
|
|
|
reset()
|
2020-12-03 20:21:58 +00:00
|
|
|
|
2020-12-09 00:10:20 +00:00
|
|
|
timeIt "fill_rgba":
|
2021-02-08 20:31:20 +00:00
|
|
|
image.fill(rgba(63, 127, 191, 191))
|
|
|
|
doAssert image[0, 0] == rgba(63, 127, 191, 191)
|
|
|
|
|
2021-08-17 21:14:31 +00:00
|
|
|
image.fill(rgba(100, 0, 100, 100))
|
|
|
|
timeIt "isOneColor":
|
|
|
|
doAssert image.isOneColor()
|
|
|
|
|
|
|
|
image.fill(rgba(0, 0, 0, 0))
|
|
|
|
timeIt "isTransparent":
|
|
|
|
doAssert image.isTransparent()
|
|
|
|
|
2021-12-13 03:48:02 +00:00
|
|
|
image.fill(rgba(255, 255, 255, 255))
|
|
|
|
timeIt "isOpaque":
|
|
|
|
doAssert image.isOpaque()
|
|
|
|
|
2021-02-08 20:31:20 +00:00
|
|
|
reset()
|
2020-12-09 00:10:20 +00:00
|
|
|
|
2021-01-23 20:17:28 +00:00
|
|
|
timeIt "subImage":
|
2021-02-08 20:31:20 +00:00
|
|
|
keep image.subImage(0, 0, 256, 256)
|
|
|
|
|
|
|
|
reset()
|
2021-01-23 20:17:28 +00:00
|
|
|
|
2021-03-03 06:23:44 +00:00
|
|
|
timeIt "superImage":
|
|
|
|
keep image.superImage(-10, -10, 2580, 1460)
|
2021-02-08 02:41:12 +00:00
|
|
|
|
2021-02-08 20:31:20 +00:00
|
|
|
reset()
|
|
|
|
|
2021-02-08 02:41:12 +00:00
|
|
|
timeIt "minifyBy2":
|
2021-02-08 20:31:20 +00:00
|
|
|
let minified = image.minifyBy2()
|
2021-06-18 02:25:54 +00:00
|
|
|
doAssert minified[0, 0] == rgba(63, 127, 191, 191)
|
|
|
|
|
2021-06-18 02:40:07 +00:00
|
|
|
reset()
|
|
|
|
|
2021-06-18 02:25:54 +00:00
|
|
|
timeIt "magnifyBy2":
|
|
|
|
let minified = image.magnifyBy2()
|
2021-02-08 02:41:12 +00:00
|
|
|
doAssert minified[0, 0] == rgba(63, 127, 191, 191)
|
|
|
|
|
2021-02-08 20:31:20 +00:00
|
|
|
reset()
|
|
|
|
|
2021-10-25 02:36:41 +00:00
|
|
|
timeIt "flipHorizontal":
|
|
|
|
image.flipHorizontal()
|
|
|
|
|
|
|
|
reset()
|
|
|
|
|
|
|
|
timeIt "flipVertical":
|
|
|
|
image.flipVertical()
|
|
|
|
|
|
|
|
reset()
|
|
|
|
|
2022-05-25 23:54:13 +00:00
|
|
|
timeIt "rotate90":
|
|
|
|
image.rotate90()
|
|
|
|
|
|
|
|
reset()
|
|
|
|
|
2020-12-03 20:21:58 +00:00
|
|
|
timeIt "invert":
|
2021-02-08 20:31:20 +00:00
|
|
|
image.invert()
|
|
|
|
|
|
|
|
reset()
|
2020-12-03 20:32:50 +00:00
|
|
|
|
|
|
|
timeIt "applyOpacity":
|
2022-07-23 03:49:51 +00:00
|
|
|
reset()
|
2021-02-08 20:31:20 +00:00
|
|
|
image.applyOpacity(0.5)
|
|
|
|
|
|
|
|
reset()
|
2020-12-03 20:32:50 +00:00
|
|
|
|
2021-01-25 17:49:29 +00:00
|
|
|
timeIt "toPremultipliedAlpha":
|
2021-02-27 00:42:40 +00:00
|
|
|
image.data.toPremultipliedAlpha()
|
2021-02-08 20:31:20 +00:00
|
|
|
|
|
|
|
reset()
|
2021-01-24 22:03:35 +00:00
|
|
|
|
2021-01-25 17:49:29 +00:00
|
|
|
timeIt "toStraightAlpha":
|
2021-02-27 00:42:40 +00:00
|
|
|
image.data.toStraightAlpha()
|
2021-02-08 20:31:20 +00:00
|
|
|
|
|
|
|
reset()
|
|
|
|
|
|
|
|
block:
|
2021-10-03 22:49:21 +00:00
|
|
|
let path = newPath()
|
2021-02-08 20:31:20 +00:00
|
|
|
path.ellipse(image.width / 2, image.height / 2, 300, 300)
|
|
|
|
|
|
|
|
let mask = newMask(image.width, image.height)
|
|
|
|
mask.fillPath(path)
|
|
|
|
|
|
|
|
timeIt "mask":
|
2021-02-08 23:26:48 +00:00
|
|
|
image.draw(mask)
|
2021-02-08 20:31:20 +00:00
|
|
|
|
|
|
|
reset()
|
2021-01-25 00:20:46 +00:00
|
|
|
|
2021-06-25 00:09:54 +00:00
|
|
|
timeIt "newMask(image)":
|
2021-02-09 22:08:08 +00:00
|
|
|
let mask = image.newMask()
|
|
|
|
doAssert mask[0, 0] == image[0, 0].a
|
|
|
|
|
|
|
|
reset()
|
|
|
|
|
2021-06-25 00:09:54 +00:00
|
|
|
block:
|
|
|
|
let mask = image.newMask()
|
|
|
|
|
|
|
|
timeIt "newImage(mask)":
|
|
|
|
let image = newImage(mask)
|
|
|
|
doAssert mask[0, 0] == image[0, 0].a
|
|
|
|
|
|
|
|
reset()
|
|
|
|
|
2022-07-24 16:54:40 +00:00
|
|
|
block:
|
|
|
|
let image = newImage(200, 200)
|
|
|
|
image.fill(rgbx(255, 0, 0, 255))
|
|
|
|
|
|
|
|
timeIt "blur":
|
|
|
|
image.blur(20)
|
2021-02-10 03:13:23 +00:00
|
|
|
|
|
|
|
reset()
|
|
|
|
|
2021-10-12 00:20:43 +00:00
|
|
|
timeIt "mix integers":
|
2021-01-25 00:20:46 +00:00
|
|
|
for i in 0 ..< 100000:
|
2021-02-08 20:31:20 +00:00
|
|
|
let c = image[0, 0]
|
2021-01-25 00:20:46 +00:00
|
|
|
var z: int
|
|
|
|
for t in 0 .. 100:
|
2021-10-12 00:20:43 +00:00
|
|
|
z += mix(c, c, t.float32 / 100).a.int
|
2021-01-25 00:20:46 +00:00
|
|
|
doAssert z > 0
|
|
|
|
|
2021-10-12 00:20:43 +00:00
|
|
|
timeIt "mix floats":
|
2021-01-25 00:20:46 +00:00
|
|
|
for i in 0 ..< 100000:
|
2021-02-08 20:31:20 +00:00
|
|
|
let c = image[0, 0]
|
2021-01-25 00:20:46 +00:00
|
|
|
var z: int
|
|
|
|
for t in 0 .. 100:
|
2021-10-12 00:20:43 +00:00
|
|
|
z += mix(c.color, c.color, t.float32 / 100).rgba().a.int
|
2021-01-25 00:20:46 +00:00
|
|
|
doAssert z > 0
|