diff options
author | Nigel Tao <nigeltao@golang.org> | 2010-02-04 20:25:37 +1100 |
---|---|---|
committer | Nigel Tao <nigeltao@golang.org> | 2010-02-04 20:25:37 +1100 |
commit | ea344e123ac19916bbac0e323ff4bbcd4d16b36e (patch) | |
tree | 74ad83014492c7e441cd9f1d8d28d713c1e0b44e | |
parent | 15da069a3755d45847dbf9567c75c0165d6ac373 (diff) | |
download | go-ea344e123ac19916bbac0e323ff4bbcd4d16b36e.tar.gz go-ea344e123ac19916bbac0e323ff4bbcd4d16b36e.zip |
Add named colors (e.g. image.Blue), suitable for exp/draw.
R=r, rsc
CC=golang-dev
https://golang.org/cl/198066
-rw-r--r-- | src/pkg/image/Makefile | 1 | ||||
-rw-r--r-- | src/pkg/image/names.go | 50 |
2 files changed, 51 insertions, 0 deletions
diff --git a/src/pkg/image/Makefile b/src/pkg/image/Makefile index f1ba374dba..9c886f9f9f 100644 --- a/src/pkg/image/Makefile +++ b/src/pkg/image/Makefile @@ -8,5 +8,6 @@ TARG=image GOFILES=\ color.go\ image.go\ + names.go\ include ../../Make.pkg diff --git a/src/pkg/image/names.go b/src/pkg/image/names.go new file mode 100644 index 0000000000..8defb0f055 --- /dev/null +++ b/src/pkg/image/names.go @@ -0,0 +1,50 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package image + +// Colors from the HTML 4.01 specification: http://www.w3.org/TR/REC-html40/types.html#h-6.5 +// These names do not necessarily match those from other lists, such as the X11 color names. +var ( + Aqua = ColorImage{RGBAColor{0x00, 0xff, 0xff, 0xff}} + Black = ColorImage{RGBAColor{0x00, 0x00, 0x00, 0xff}} + Blue = ColorImage{RGBAColor{0x00, 0x00, 0xff, 0xff}} + Fuchsia = ColorImage{RGBAColor{0xff, 0x00, 0xff, 0xff}} + Gray = ColorImage{RGBAColor{0x80, 0x80, 0x80, 0xff}} + Green = ColorImage{RGBAColor{0x00, 0x80, 0x00, 0xff}} + Lime = ColorImage{RGBAColor{0x00, 0xff, 0x00, 0xff}} + Maroon = ColorImage{RGBAColor{0x80, 0x00, 0x00, 0xff}} + Navy = ColorImage{RGBAColor{0x00, 0x00, 0x80, 0xff}} + Olive = ColorImage{RGBAColor{0x80, 0x80, 0x00, 0xff}} + Red = ColorImage{RGBAColor{0xff, 0x00, 0x00, 0xff}} + Purple = ColorImage{RGBAColor{0x80, 0x00, 0x80, 0xff}} + Silver = ColorImage{RGBAColor{0xc0, 0xc0, 0xc0, 0xff}} + Teal = ColorImage{RGBAColor{0x00, 0x80, 0x80, 0xff}} + White = ColorImage{RGBAColor{0xff, 0xff, 0xff, 0xff}} + Yellow = ColorImage{RGBAColor{0xff, 0xff, 0x00, 0xff}} + + // These synonyms are not in HTML 4.01. + Cyan = Aqua + Magenta = Fuchsia +) + +// A ColorImage is a practically infinite-sized Image of uniform Color. +// It implements both the Color and Image interfaces. +type ColorImage struct { + C Color +} + +func (c ColorImage) RGBA() (r, g, b, a uint32) { + return c.C.RGBA() +} + +func (c ColorImage) ColorModel() ColorModel { + return ColorModelFunc(func(Color) Color { return c.C }) +} + +func (c ColorImage) Width() int { return 1e9 } + +func (c ColorImage) Height() int { return 1e9 } + +func (c ColorImage) At(x, y int) Color { return c.C } |