Skip to content

Commit d19a533

Browse files
committed
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 <[email protected]> Run-TryBot: Nigel Tao <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent c45e800 commit d19a533

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

api/go1.17.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ pkg image, method (*Paletted) RGBA64At(int, int) color.RGBA64
4747
pkg image, method (*Paletted) SetRGBA64(int, int, color.RGBA64)
4848
pkg image, method (*RGBA) RGBA64At(int, int) color.RGBA64
4949
pkg image, method (*RGBA) SetRGBA64(int, int, color.RGBA64)
50+
pkg image, method (*Uniform) RGBA64At(int, int) color.RGBA64
5051
pkg image, method (*YCbCr) RGBA64At(int, int) color.RGBA64
52+
pkg image, method (Rectangle) RGBA64At(int, int) color.RGBA64
5153
pkg image, type RGBA64Image interface { At, Bounds, ColorModel, RGBA64At }
5254
pkg image, type RGBA64Image interface, At(int, int) color.Color
5355
pkg image, type RGBA64Image interface, Bounds() Rectangle

doc/go1.17.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,8 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
811811
<p><!-- CL 311129 -->
812812
The concrete image types (<code>RGBA</code>, <code>Gray16</code> and so on)
813813
now implement a new <a href="/pkg/image/#RGBA64Image"><code>RGBA64Image</code></a>
814-
interface. Those concrete types, other than the chroma-subsampling
815-
related <code>YCbCr</code> and <code>NYCbCrA</code>, also now implement
814+
interface. The concrete types that previously implemented
815+
<a href="/pkg/image/draw/#Image"><code>draw.Image</code></a> now also implement
816816
<a href="/pkg/image/draw/#RGBA64Image"><code>draw.RGBA64Image</code></a>, a
817817
new interface in the <code>image/draw</code> package.
818818
</p>

src/image/geom.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ func (r Rectangle) At(x, y int) color.Color {
246246
return color.Transparent
247247
}
248248

249+
// RGBA64At implements the RGBA64Image interface.
250+
func (r Rectangle) RGBA64At(x, y int) color.RGBA64 {
251+
if (Point{x, y}).In(r) {
252+
return color.RGBA64{0xffff, 0xffff, 0xffff, 0xffff}
253+
}
254+
return color.RGBA64{}
255+
}
256+
249257
// Bounds implements the Image interface.
250258
func (r Rectangle) Bounds() Rectangle {
251259
return r

src/image/image_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ func TestRGBA64Image(t *testing.T) {
213213
NewPaletted(r, palette.Plan9),
214214
NewRGBA(r),
215215
NewRGBA64(r),
216+
NewUniform(color.RGBA64{}),
216217
NewYCbCr(r, YCbCrSubsampleRatio444),
218+
r,
217219
}
218220
for _, tc := range testCases {
219221
switch tc := tc.(type) {
@@ -226,6 +228,9 @@ func TestRGBA64Image(t *testing.T) {
226228
// means that setting one pixel can modify neighboring pixels. They
227229
// don't have Set or SetRGBA64 methods because that side effect could
228230
// be surprising. Here, we just memset the channel buffers instead.
231+
//
232+
// The Uniform and Rectangle types are also special-cased, as they
233+
// don't have a Set or SetRGBA64 method.
229234
case interface {
230235
SetRGBA64(x, y int, c color.RGBA64)
231236
}:
@@ -237,11 +242,18 @@ func TestRGBA64Image(t *testing.T) {
237242
memset(tc.YCbCr.Cr, 0x99)
238243
memset(tc.A, 0xAA)
239244

245+
case *Uniform:
246+
tc.C = color.RGBA64{0x7FFF, 0x3FFF, 0x0000, 0x7FFF}
247+
240248
case *YCbCr:
241249
memset(tc.Y, 0x77)
242250
memset(tc.Cb, 0x88)
243251
memset(tc.Cr, 0x99)
244252

253+
case Rectangle:
254+
// No-op. Rectangle pixels' colors are immutable. They're always
255+
// color.Opaque.
256+
245257
default:
246258
t.Errorf("could not initialize pixels for %T", tc)
247259
continue

src/image/names.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ func (c *Uniform) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point
4141

4242
func (c *Uniform) At(x, y int) color.Color { return c.C }
4343

44+
func (c *Uniform) RGBA64At(x, y int) color.RGBA64 {
45+
r, g, b, a := c.C.RGBA()
46+
return color.RGBA64{uint16(r), uint16(g), uint16(b), uint16(a)}
47+
}
48+
4449
// Opaque scans the entire image and reports whether it is fully opaque.
4550
func (c *Uniform) Opaque() bool {
4651
_, _, _, a := c.C.RGBA()

0 commit comments

Comments
 (0)