aboutsummaryrefslogtreecommitdiff
path: root/prototypes/xgb-window.go
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-08-21 20:45:25 +0200
committerPřemysl Janouch <p@janouch.name>2018-09-02 18:25:28 +0200
commit44b01ccb177bf188efc416609e95892dd7d77977 (patch)
tree0e8fe60b7ae83046a955093bca2e4aebc32d7135 /prototypes/xgb-window.go
parent0f7fcca7cea7682f0d1db65a277c43be2ab9dcc3 (diff)
downloadhaven-44b01ccb177bf188efc416609e95892dd7d77977.tar.gz
haven-44b01ccb177bf188efc416609e95892dd7d77977.tar.xz
haven-44b01ccb177bf188efc416609e95892dd7d77977.zip
xgb-window: add comparison with correct blending
Diffstat (limited to 'prototypes/xgb-window.go')
-rw-r--r--prototypes/xgb-window.go31
1 files changed, 27 insertions, 4 deletions
diff --git a/prototypes/xgb-window.go b/prototypes/xgb-window.go
index 2519fe9..3944fa4 100644
--- a/prototypes/xgb-window.go
+++ b/prototypes/xgb-window.go
@@ -4,6 +4,7 @@ import (
"github.com/BurntSushi/xgb"
"github.com/BurntSushi/xgb/xproto"
"log"
+ "math"
"math/rand"
)
@@ -73,6 +74,17 @@ func main() {
_ = xproto.CreateGC(X, cid, xproto.Drawable(wid),
xproto.GcGraphicsExposures, []uint32{0})
+ blend := func(a, b uint32, ratio, gamma float64) uint32 {
+ iratio := 1 - ratio
+
+ fa := math.Pow(float64(a)/255, gamma)
+ fb := math.Pow(float64(b)/255, gamma)
+
+ return uint32(math.Pow(ratio*fa+iratio*fb, 1/gamma)*255) & 0xff
+ }
+
+ // TODO: We could show some text just like we intend to with xgb-xrender.go.
+
var w, h uint16
var start, end uint32 = 0xabcdef, 0x32ab54
gradient := func() {
@@ -86,17 +98,28 @@ func main() {
for y := low; y < high; y++ {
ratio := float64(y-low) / (float64(high) - float64(low))
- iratio := 1 - ratio
- rR := uint32(ratio*float64(ra)+iratio*float64(rb)) & 0xff
- gG := uint32(ratio*float64(ga)+iratio*float64(gb)) & 0xff
- bB := uint32(ratio*float64(ba)+iratio*float64(bb)) & 0xff
+ rR := blend(ra, rb, ratio, 2.2)
+ gG := blend(ga, gb, ratio, 2.2)
+ bB := blend(ba, bb, ratio, 2.2)
_ = xproto.ChangeGC(X, cid, xproto.GcForeground,
[]uint32{0xff000000 | rR<<16 | gG<<8 | bB})
_ = xproto.PolyLine(X, xproto.CoordModeOrigin, xproto.Drawable(wid),
cid, []xproto.Point{
{X: 50, Y: int16(y)},
+ {X: int16(w / 2), Y: int16(y)},
+ })
+
+ rR = blend(ra, rb, ratio, 1)
+ gG = blend(ga, gb, ratio, 1)
+ bB = blend(ba, bb, ratio, 1)
+
+ _ = xproto.ChangeGC(X, cid, xproto.GcForeground,
+ []uint32{0xff000000 | rR<<16 | gG<<8 | bB})
+ _ = xproto.PolyLine(X, xproto.CoordModeOrigin, xproto.Drawable(wid),
+ cid, []xproto.Point{
+ {X: int16(w / 2), Y: int16(y)},
{X: int16(w - 50), Y: int16(y)},
})
}