-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrgb14.go
66 lines (56 loc) · 1.18 KB
/
rgb14.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
package arw
import (
"image"
"image/color"
)
// NewRGBA returns a new RGBA image with the given bounds.
func NewRGB14(r image.Rectangle) *RGB14 {
w, h := r.Dx(), r.Dy()
buf := make([]pixel16, w*h)
return &RGB14{buf, w, r}
}
// RGBA64 is an in-memory image whose At method returns pixel16 values.
type RGB14 struct {
Pix []pixel16
// Stride is the Pix stride between vertically adjacent pixels.
Stride int
// Rect is the image's bounds.
Rect image.Rectangle
}
func (r *RGB14) at(x, y int) pixel16 {
return r.Pix[(y*r.Stride)+x]
}
func (r *RGB14) At(x, y int) color.Color {
return r.at(x, y)
}
func (r *RGB14) Bounds() image.Rectangle {
return r.Rect.Bounds()
}
func (r *RGB14) ColorModel() color.Model {
return color.RGBA64Model
}
func (c pixel16) RGBA() (uint32, uint32, uint32, uint32) {
r := uint32(c.R) << 2
g := uint32(c.G) << 2
b := uint32(c.B) << 2
if r > 0xffff {
r = 0xffff
}
if g > 0xffff {
g = 0xffff
}
if b > 0xffff {
b = 0xffff
}
return r, g, b, 0xffff
//return uint32(c.R), uint32(c.G), uint32(c.B), 0xffff
}
func (r *RGB14) set(x, y int, pixel pixel16) {
r.Pix[y*r.Stride+x] = pixel
}
type pixel16 struct {
R uint16
G uint16
B uint16
_ uint16
}