aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNigel Tao <nigeltao@golang.org>2021-06-29 16:53:44 +1000
committerNigel Tao <nigeltao@golang.org>2021-06-30 02:00:49 +0000
commitd19a53338fa6272b4fe9c39d66812a79e1464cd2 (patch)
tree70d80b3fac7e91d728c25b54afb95af95eb3e28f
parentc45e800e0cb237fcedc9a3e4fd243e3a7f47334c (diff)
downloadgo-d19a53338fa6272b4fe9c39d66812a79e1464cd2.tar.gz
go-d19a53338fa6272b4fe9c39d66812a79e1464cd2.zip
image: add Uniform.RGBA64At and Rectangle.RGBA64At
These types already implemented the Image interface. They should also implement the RGBA64Image interface (new in Go 1.17) Updates #44808 Change-Id: I9a2b13e305997088ae874efb95ad9e1648f94812 Reviewed-on: https://go-review.googlesource.com/c/go/+/331570 Trust: Nigel Tao <nigeltao@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
-rw-r--r--api/go1.17.txt2
-rw-r--r--doc/go1.17.html4
-rw-r--r--src/image/geom.go8
-rw-r--r--src/image/image_test.go12
-rw-r--r--src/image/names.go5
5 files changed, 29 insertions, 2 deletions
diff --git a/api/go1.17.txt b/api/go1.17.txt
index c5eb381708..8e4c0f5624 100644
--- a/api/go1.17.txt
+++ b/api/go1.17.txt
@@ -47,7 +47,9 @@ pkg image, method (*Paletted) RGBA64At(int, int) color.RGBA64
pkg image, method (*Paletted) SetRGBA64(int, int, color.RGBA64)
pkg image, method (*RGBA) RGBA64At(int, int) color.RGBA64
pkg image, method (*RGBA) SetRGBA64(int, int, color.RGBA64)
+pkg image, method (*Uniform) RGBA64At(int, int) color.RGBA64
pkg image, method (*YCbCr) RGBA64At(int, int) color.RGBA64
+pkg image, method (Rectangle) RGBA64At(int, int) color.RGBA64
pkg image, type RGBA64Image interface { At, Bounds, ColorModel, RGBA64At }
pkg image, type RGBA64Image interface, At(int, int) color.Color
pkg image, type RGBA64Image interface, Bounds() Rectangle
diff --git a/doc/go1.17.html b/doc/go1.17.html
index 3551ba46c8..b72752d77d 100644
--- a/doc/go1.17.html
+++ b/doc/go1.17.html
@@ -811,8 +811,8 @@ func Foo() bool {
<p><!-- CL 311129 -->
The concrete image types (<code>RGBA</code>, <code>Gray16</code> and so on)
now implement a new <a href="/pkg/image/#RGBA64Image"><code>RGBA64Image</code></a>
- interface. Those concrete types, other than the chroma-subsampling
- related <code>YCbCr</code> and <code>NYCbCrA</code>, also now implement
+ interface. The concrete types that previously implemented
+ <a href="/pkg/image/draw/#Image"><code>draw.Image</code></a> now also implement
<a href="/pkg/image/draw/#RGBA64Image"><code>draw.RGBA64Image</code></a>, a
new interface in the <code>image/draw</code> package.
</p>
diff --git a/src/image/geom.go b/src/image/geom.go
index 78e9e49d4f..e71aa61187 100644
--- a/src/image/geom.go
+++ b/src/image/geom.go
@@ -246,6 +246,14 @@ func (r Rectangle) At(x, y int) color.Color {
return color.Transparent
}
+// RGBA64At implements the RGBA64Image interface.
+func (r Rectangle) RGBA64At(x, y int) color.RGBA64 {
+ if (Point{x, y}).In(r) {
+ return color.RGBA64{0xffff, 0xffff, 0xffff, 0xffff}
+ }
+ return color.RGBA64{}
+}
+
// Bounds implements the Image interface.
func (r Rectangle) Bounds() Rectangle {
return r
diff --git a/src/image/image_test.go b/src/image/image_test.go
index c64b6107b7..7f41bcb6c7 100644
--- a/src/image/image_test.go
+++ b/src/image/image_test.go
@@ -213,7 +213,9 @@ func TestRGBA64Image(t *testing.T) {
NewPaletted(r, palette.Plan9),
NewRGBA(r),
NewRGBA64(r),
+ NewUniform(color.RGBA64{}),
NewYCbCr(r, YCbCrSubsampleRatio444),
+ r,
}
for _, tc := range testCases {
switch tc := tc.(type) {
@@ -226,6 +228,9 @@ func TestRGBA64Image(t *testing.T) {
// means that setting one pixel can modify neighboring pixels. They
// don't have Set or SetRGBA64 methods because that side effect could
// be surprising. Here, we just memset the channel buffers instead.
+ //
+ // The Uniform and Rectangle types are also special-cased, as they
+ // don't have a Set or SetRGBA64 method.
case interface {
SetRGBA64(x, y int, c color.RGBA64)
}:
@@ -237,11 +242,18 @@ func TestRGBA64Image(t *testing.T) {
memset(tc.YCbCr.Cr, 0x99)
memset(tc.A, 0xAA)
+ case *Uniform:
+ tc.C = color.RGBA64{0x7FFF, 0x3FFF, 0x0000, 0x7FFF}
+
case *YCbCr:
memset(tc.Y, 0x77)
memset(tc.Cb, 0x88)
memset(tc.Cr, 0x99)
+ case Rectangle:
+ // No-op. Rectangle pixels' colors are immutable. They're always
+ // color.Opaque.
+
default:
t.Errorf("could not initialize pixels for %T", tc)
continue
diff --git a/src/image/names.go b/src/image/names.go
index 8595a35014..17b06588ac 100644
--- a/src/image/names.go
+++ b/src/image/names.go
@@ -41,6 +41,11 @@ func (c *Uniform) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point
func (c *Uniform) At(x, y int) color.Color { return c.C }
+func (c *Uniform) RGBA64At(x, y int) color.RGBA64 {
+ r, g, b, a := c.C.RGBA()
+ return color.RGBA64{uint16(r), uint16(g), uint16(b), uint16(a)}
+}
+
// Opaque scans the entire image and reports whether it is fully opaque.
func (c *Uniform) Opaque() bool {
_, _, _, a := c.C.RGBA()