freetype: update for image.Pix changes (again).
R=r CC=golang-dev http://codereview.appspot.com/4702041
This commit is contained in:
parent
43d4d89685
commit
006c241eaa
|
@ -62,9 +62,8 @@ func (r AlphaOverPainter) Paint(ss []Span, done bool) {
|
||||||
p := r.Image.Pix[base+s.X0 : base+s.X1]
|
p := r.Image.Pix[base+s.X0 : base+s.X1]
|
||||||
a := int(s.A >> 24)
|
a := int(s.A >> 24)
|
||||||
for i, c := range p {
|
for i, c := range p {
|
||||||
v := int(c.A)
|
v := int(c)
|
||||||
v = (v*255 + (255-v)*a) / 255
|
p[i] = uint8((v*255 + (255-v)*a) / 255)
|
||||||
p[i] = image.AlphaColor{uint8(v)}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +100,7 @@ func (r AlphaSrcPainter) Paint(ss []Span, done bool) {
|
||||||
}
|
}
|
||||||
base := (s.Y-r.Image.Rect.Min.Y)*r.Image.Stride - r.Image.Rect.Min.X
|
base := (s.Y-r.Image.Rect.Min.Y)*r.Image.Stride - r.Image.Rect.Min.X
|
||||||
p := r.Image.Pix[base+s.X0 : base+s.X1]
|
p := r.Image.Pix[base+s.X0 : base+s.X1]
|
||||||
color := image.AlphaColor{uint8(s.A >> 24)}
|
color := uint8(s.A >> 24)
|
||||||
for i := range p {
|
for i := range p {
|
||||||
p[i] = color
|
p[i] = color
|
||||||
}
|
}
|
||||||
|
@ -141,32 +140,29 @@ func (r *RGBAPainter) Paint(ss []Span, done bool) {
|
||||||
if s.X0 >= s.X1 {
|
if s.X0 >= s.X1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
base := (s.Y-r.Image.Rect.Min.Y)*r.Image.Stride - r.Image.Rect.Min.X
|
// This code is similar to drawGlyphOver in $GOROOT/src/pkg/image/draw/draw.go.
|
||||||
p := r.Image.Pix[base+s.X0 : base+s.X1]
|
|
||||||
for i, rgba := range p {
|
|
||||||
// This code is duplicated from drawGlyphOver in $GOROOT/src/pkg/exp/draw/draw.go.
|
|
||||||
// TODO(nigeltao): Factor out common code into a utility function, once the compiler
|
|
||||||
// can inline such function calls.
|
|
||||||
ma := s.A >> 16
|
ma := s.A >> 16
|
||||||
const M = 1<<16 - 1
|
const m = 1<<16 - 1
|
||||||
|
i0 := (s.Y-r.Image.Rect.Min.Y)*r.Image.Stride + (s.X0-r.Image.Rect.Min.X)*4
|
||||||
|
i1 := i0 + (s.X1-s.X0)*4
|
||||||
if r.Op == draw.Over {
|
if r.Op == draw.Over {
|
||||||
dr := uint32(rgba.R)
|
for i := i0; i < i1; i += 4 {
|
||||||
dg := uint32(rgba.G)
|
dr := uint32(r.Image.Pix[i+0])
|
||||||
db := uint32(rgba.B)
|
dg := uint32(r.Image.Pix[i+1])
|
||||||
da := uint32(rgba.A)
|
db := uint32(r.Image.Pix[i+2])
|
||||||
a := M - (r.ca * ma / M)
|
da := uint32(r.Image.Pix[i+3])
|
||||||
a *= 0x101
|
a := (m - (r.ca * ma / m)) * 0x101
|
||||||
dr = (dr*a + r.cr*ma) / M
|
r.Image.Pix[i+0] = uint8((dr*a + r.cr*ma) / m >> 8)
|
||||||
dg = (dg*a + r.cg*ma) / M
|
r.Image.Pix[i+1] = uint8((dg*a + r.cg*ma) / m >> 8)
|
||||||
db = (db*a + r.cb*ma) / M
|
r.Image.Pix[i+2] = uint8((db*a + r.cb*ma) / m >> 8)
|
||||||
da = (da*a + r.ca*ma) / M
|
r.Image.Pix[i+3] = uint8((da*a + r.ca*ma) / m >> 8)
|
||||||
p[i] = image.RGBAColor{uint8(dr >> 8), uint8(dg >> 8), uint8(db >> 8), uint8(da >> 8)}
|
}
|
||||||
} else {
|
} else {
|
||||||
dr := r.cr * ma / M
|
for i := i0; i < i1; i += 4 {
|
||||||
dg := r.cg * ma / M
|
r.Image.Pix[i+0] = uint8(r.cr * ma / m >> 8)
|
||||||
db := r.cb * ma / M
|
r.Image.Pix[i+1] = uint8(r.cg * ma / m >> 8)
|
||||||
da := r.ca * ma / M
|
r.Image.Pix[i+2] = uint8(r.cb * ma / m >> 8)
|
||||||
p[i] = image.RGBAColor{uint8(dr >> 8), uint8(dg >> 8), uint8(db >> 8), uint8(da >> 8)}
|
r.Image.Pix[i+3] = uint8(r.ca * ma / m >> 8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue