Skip to content

Commit e1a3964

Browse files
committed
Implement interface with comments
1 parent 3b6681b commit e1a3964

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

spectogram/image.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,29 @@ type Image128 struct {
1717
bounds image.Rectangle
1818
}
1919

20+
// ColorModel returns the Image's color model.
2021
func (img *Image128) ColorModel() color.Model {
2122
return color.RGBA64Model
2223
}
2324

25+
// Bounds returns the domain for which At can return non-zero color.
26+
// The bounds do not necessarily contain the point (0, 0).
2427
func (img *Image128) Bounds() image.Rectangle {
2528
return img.bounds
2629
}
2730

31+
// At returns the color of the pixel at (x, y).
32+
// At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid.
33+
// At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.
34+
func (img *Image128) At(x int, y int) color.Color {
35+
o := img.offset(x, y)
36+
if o < 0 {
37+
return color.RGBA{}
38+
}
39+
img.at++
40+
return img.pix[o]
41+
}
42+
2843
func (img *Image128) offset(x, y int) int {
2944
p := image.Point{x, y}
3045
if !p.In(img.bounds) {
@@ -38,15 +53,6 @@ func (img *Image128) offset(x, y int) int {
3853
return ny*stride + nx
3954
}
4055

41-
func (img *Image128) At(x int, y int) color.Color {
42-
o := img.offset(x, y)
43-
if o < 0 {
44-
return color.RGBA{}
45-
}
46-
img.at++
47-
return img.pix[o]
48-
}
49-
5056
func (img *Image128) Set(x int, y int, c color.Color) {
5157
o := img.offset(x, y)
5258
if o < 0 {

0 commit comments

Comments
 (0)