/
draw.go
70 lines (63 loc) · 2.05 KB
/
draw.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package bench
import (
"github.com/BurntSushi/xgbutil/xgraphics"
"github.com/skelterjohn/go.wde/win"
"image"
)
// This. This seems to be the solution. 0.72ns/op. RGBA -> RGBA is 0.02ns/op. Draw is 180ns/op.
// from https://github.com/BurntSushi/xgbutil/blob/master/xgraphics/convert.go
func convertRGBAtoXgb(dest *xgraphics.Image, src *image.RGBA) {
var x, y, i, si int
for x = dest.Rect.Min.X; x < dest.Rect.Max.X; x++ {
for y = dest.Rect.Min.Y; y < dest.Rect.Max.Y; y++ {
si = src.PixOffset(x, y)
i = dest.PixOffset(x, y)
dest.Pix[i+0] = src.Pix[si+2]
dest.Pix[i+1] = src.Pix[si+1]
dest.Pix[i+2] = src.Pix[si+0]
dest.Pix[i+3] = src.Pix[si+3]
}
}
}
func convertRGBAtoWin(dest *win.DIB, src *image.RGBA) {
var x, y, i, si int
for x = dest.Rect.Min.X; x < dest.Rect.Max.X; x++ {
for y = dest.Rect.Min.Y; y < dest.Rect.Max.Y; y++ {
si = src.PixOffset(x, y)
i = dest.PixOffset(x, y)
dest.Pix[i+0] = src.Pix[si+2]
dest.Pix[i+1] = src.Pix[si+1]
dest.Pix[i+2] = src.Pix[si+0]
}
}
}
/*
// based on https://github.com/skelterjohn/go.wde/blob/master/win/dib_windows.go
func convertRGBAtoWinWithAlpha(dest *win.DIB, src *image.RGBA) {
var x, y, i, si int
for x = dest.Rect.Min.X; x < dest.Rect.Max.X; x++ {
for y = dest.Rect.Min.Y; y < dest.Rect.Max.Y; y++ {
si = src.PixOffset(x, y)
i = dest.PixOffset(x, y)
if src.Pix[si+3] == 0 {
dest.Pix[i+0] = 0
dest.Pix[i+1] = 0
dest.Pix[i+2] = 0
continue
} else if src.Pix[si+3] == 255 {
dest.Pix[i+0] = src.Pix[si+2] //B
dest.Pix[i+1] = src.Pix[si+1] //G
dest.Pix[i+2] = src.Pix[si+0] //R
continue
}
// B*a G*a R*a
//dest.Pix[i+0] = (src.Pix[si+2] / 0xff) * src.Pix[si+3]
//dest.Pix[i+1] = (src.Pix[si+1] / 0xff) * src.Pix[si+3]
//dest.Pix[i+2] = (src.Pix[si+0] / 0xff) * src.Pix[si+3]
dest.Pix[i+0] = uint8((float64(src.Pix[si+2]) / 0xff) * float64(src.Pix[si+3]))
dest.Pix[i+1] = uint8((float64(src.Pix[si+1]) / 0xff) * float64(src.Pix[si+3]))
dest.Pix[i+2] = uint8((float64(src.Pix[si+0]) / 0xff) * float64(src.Pix[si+3]))
}
}
}
*/