freetype: image/color gofix.

R=r, rsc
CC=golang-dev
http://codereview.appspot.com/5166052
This commit is contained in:
Nigel Tao 2011-10-06 13:55:02 +11:00
parent 4188558878
commit 7b867fea2e
4 changed files with 14 additions and 10 deletions

View file

@ -11,6 +11,7 @@ import (
"fmt"
"freetype-go.googlecode.com/hg/freetype"
"image"
"image/color"
"image/draw"
"image/png"
"io/ioutil"
@ -80,10 +81,10 @@ func main() {
// Initialize the context.
fg, bg := image.Black, image.White
ruler := image.RGBAColor{0xdd, 0xdd, 0xdd, 0xff}
ruler := color.RGBA{0xdd, 0xdd, 0xdd, 0xff}
if *wonb {
fg, bg = image.White, image.Black
ruler = image.RGBAColor{0x22, 0x22, 0x22, 0xff}
ruler = color.RGBA{0x22, 0x22, 0x22, 0xff}
}
rgba := image.NewRGBA(image.Rect(0, 0, 640, 480))
draw.Draw(rgba, rgba.Bounds(), bg, image.ZP, draw.Src)

View file

@ -9,6 +9,7 @@ import (
"bufio"
"fmt"
"image"
"image/color"
"image/draw"
"image/png"
"log"
@ -116,14 +117,14 @@ func showNodes(m *image.RGBA, ns []node) {
if !(image.Point{x, y}).In(m.Bounds()) {
continue
}
var c image.Color
var c color.Color
switch n.degree {
case 0:
c = image.RGBAColor{0, 255, 255, 255}
c = color.RGBA{0, 255, 255, 255}
case 1:
c = image.RGBAColor{255, 0, 0, 255}
c = color.RGBA{255, 0, 0, 255}
case 2:
c = image.RGBAColor{255, 0, 0, 255}
c = color.RGBA{255, 0, 0, 255}
}
if c != nil {
m.Set(x, y, c)
@ -146,7 +147,7 @@ func main() {
// Draw the mask image (in gray) onto an RGBA image.
rgba := image.NewRGBA(image.Rect(0, 0, w, h))
gray := image.NewColorImage(image.AlphaColor{0x1f})
gray := image.NewUniform(color.Alpha{0x1f})
draw.Draw(rgba, rgba.Bounds(), image.Black, image.ZP, draw.Src)
draw.DrawMask(rgba, rgba.Bounds(), gray, image.ZP, mask, image.ZP, draw.Over)
showNodes(rgba, outside)

View file

@ -14,6 +14,7 @@ import (
"bufio"
"fmt"
"image"
"image/color"
"image/draw"
"image/png"
"log"
@ -32,7 +33,7 @@ func main() {
t := raster.Fix32(r * math.Tan(math.Pi/8))
m := image.NewRGBA(image.Rect(0, 0, 800, 600))
draw.Draw(m, m.Bounds(), &image.ColorImage{image.RGBAColor{63, 63, 63, 255}}, image.ZP, draw.Src)
draw.Draw(m, m.Bounds(), &image.Uniform{color.RGBA{63, 63, 63, 255}}, image.ZP, draw.Src)
mp := raster.NewRGBAPainter(m)
mp.SetColor(image.Black)
z := raster.NewRasterizer(800, 600)
@ -69,7 +70,7 @@ func main() {
theta := math.Pi * float64(j) / (n - 1)
dx := raster.Fix32(r * math.Cos(theta))
dy := raster.Fix32(r * math.Sin(theta))
m.Set(int((cx+dx)/256), int((cy+dy)/256), image.RGBAColor{255, 255, 0, 255})
m.Set(int((cx+dx)/256), int((cy+dy)/256), color.RGBA{255, 255, 0, 255})
}
}

View file

@ -7,6 +7,7 @@ package raster
import (
"image"
"image/color"
"image/draw"
"math"
)
@ -169,7 +170,7 @@ func (r *RGBAPainter) Paint(ss []Span, done bool) {
}
// SetColor sets the color to paint the spans.
func (r *RGBAPainter) SetColor(c image.Color) {
func (r *RGBAPainter) SetColor(c color.Color) {
r.cr, r.cg, r.cb, r.ca = c.RGBA()
}