1
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
12
register(imagecolorFix)
15
var imagecolorFix = fix{
19
`Adapt code to types moved from image to color.
21
http://codereview.appspot.com/5132048
25
var colorRenames = []struct{ in, out string }{
27
{"ColorModel", "Model"},
28
{"ColorModelFunc", "ModelFunc"},
29
{"PalettedColorModel", "Palette"},
31
{"RGBAColor", "RGBA"},
32
{"RGBA64Color", "RGBA64"},
33
{"NRGBAColor", "NRGBA"},
34
{"NRGBA64Color", "NRGBA64"},
35
{"AlphaColor", "Alpha"},
36
{"Alpha16Color", "Alpha16"},
37
{"GrayColor", "Gray"},
38
{"Gray16Color", "Gray16"},
40
{"RGBAColorModel", "RGBAModel"},
41
{"RGBA64ColorModel", "RGBA64Model"},
42
{"NRGBAColorModel", "NRGBAModel"},
43
{"NRGBA64ColorModel", "NRGBA64Model"},
44
{"AlphaColorModel", "AlphaModel"},
45
{"Alpha16ColorModel", "Alpha16Model"},
46
{"GrayColorModel", "GrayModel"},
47
{"Gray16ColorModel", "Gray16Model"},
50
func imagecolor(f *ast.File) (fixed bool) {
51
if !imports(f, "image") {
55
walk(f, func(n interface{}) {
56
s, ok := n.(*ast.SelectorExpr)
58
if !ok || !isTopName(s.X, "image") {
62
switch sel := s.Sel.String(); {
63
case sel == "ColorImage":
64
s.Sel = &ast.Ident{Name: "Uniform"}
66
case sel == "NewColorImage":
67
s.Sel = &ast.Ident{Name: "NewUniform"}
70
for _, rename := range colorRenames {
72
addImport(f, "image/color")
73
s.X.(*ast.Ident).Name = "color"
74
s.Sel.Name = rename.out
81
if fixed && !usesImport(f, "image") {
82
deleteImport(f, "image")