-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpixelfunctions.go
83 lines (68 loc) · 1.72 KB
/
pixelfunctions.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
71
72
73
74
75
76
77
78
79
80
81
82
83
package pf
// The uint32 is on the form ARGB
// Invert the colors
func Invert(v uint32) uint32 {
// Invert the colors, but set the alpha value to 0xff
return (0xffffffff - v) | 0xff000000
}
// Invert the colors, including the alpha value
func InvertEverything(v uint32) uint32 {
// Invert everything
return 0xffffffff - v
}
// Keep the red component
func OnlyRed(v uint32) uint32 {
// Keep alpha and the red value
return v & 0xffff0000
}
// Keep the green component
func OnlyGreen(v uint32) uint32 {
// Keep alpha and the green value
return v & 0xff00ff00
}
// Keep the blue component
func OnlyBlue(v uint32) uint32 {
// Keep alpha and the blue value
return v & 0xff0000ff
}
// Keep the alpha component
func OnlyAlpha(v uint32) uint32 {
// Keep only the alpha value
return v & 0xff000000
}
// Remove the red component
func RemoveRed(v uint32) uint32 {
// Keep everything but red
return v & 0xff00ffff
}
// Remove the green component
func RemoveGreen(v uint32) uint32 {
// Keep everything but green
return v & 0xffff00ff
}
// Remove the blue component
func RemoveBlue(v uint32) uint32 {
// Keep everything but blue
return v & 0xffffff00
}
// Remove the alpha component, making the pixels transparent
func RemoveAlpha(v uint32) uint32 {
// Keep everything but the alpha value
return v & 0x00ffffff
}
// Make the red component of every pixel 0xff
func SetRedBits(v uint32) uint32 {
return v | 0x00ff0000
}
// Make the green component of every pixel 0xff
func SetGreenBits(v uint32) uint32 {
return v | 0x0000ff00
}
// Make the blue component of every pixel 0xff
func SetBlueBits(v uint32) uint32 {
return v | 0x000000ff
}
// Make the alpha component of every pixel 0xff
func OrAlpha(v uint32) uint32 {
return v | 0xff000000
}