treeform / pixie

Full-featured 2d graphics library for Nim.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

something wrong a.draw(b) with alpha?

nomissbowling opened this issue · comments

import pixie

block:
let
a = newImage(80, 80)
y = newImage(64, 64)
b = newImage(32, 32)
g = newImage(32, 32)
r = newImage(32, 32)
k = newImage(32, 32)

a.fill(rgba(255, 255, 255, 255))
y.fill(rgba(255, 255, 0, 255))
b.fill(rgba(0, 0, 255, 255))
g.fill(rgba(0, 255, 0, 255))
r.fill(rgba(255, 0, 0, 255))
k.fill(rgbx(255, 0, 255, 0)) # Premultiplied alpha (not rgba())
y.draw(b)
y.flipVertical()
y.draw(g)
y.flipHorizontal()
y.draw(r)
y.draw(k, translate(vec2(16, 16))) # something wrong on the width
y.writeFile("tests/images/planes_flip_yellow.png")
a.draw(y, translate(vec2(8, 8)))
a.writeFile("tests/images/planes_flip_all.png") # something wrong on the width

but that is correct width when change one line k.fill(rgbx(255, 0, 255, 255))

I've not tried but I can see that rgbx(255, 0, 255, 0) does not make sense. No color channel value can be greater than the alpha value in a premultiplied alpha color, thus if alpha is 0 the only valid rgbx color is (0, 0, 0, 0). My guess is that is involved here at first glance.

Thank you, I understand it.
k.fill(rgbx(255, 0, 255, 0)) is invalid use.
y.draw(k) is nonsense and draw nothing to y when with k.fill(rgba(255, 0, 255, 0)) .
And must call toPremultipliedAlpha after change alpha directly 'y.data[i].a = anyvalue'.