graphics: Refactoring: remove drawWithFittingScale

This commit is contained in:
Hajime Hoshi 2018-02-25 03:12:33 +09:00
parent 0cc456b534
commit c7a733fb16

View File

@ -41,21 +41,6 @@ func init() {
_ = emptyImage.ReplacePixels(pix) _ = emptyImage.ReplacePixels(pix)
} }
func drawWithFittingScale(dst *Image, src *Image, colorM *ColorM, filter Filter) {
wd, hd := dst.Size()
ws, hs := src.Size()
sw := float64(wd) / float64(ws)
sh := float64(hd) / float64(hs)
op := &DrawImageOptions{}
op.GeoM.Scale(sw, sh)
if colorM != nil {
op.ColorM = *colorM
}
op.CompositeMode = CompositeModeCopy
op.Filter = filter
_ = dst.DrawImage(src, op)
}
// Image represents a rectangle set of pixels. // Image represents a rectangle set of pixels.
// The pixel format is alpha-premultiplied RGBA. // The pixel format is alpha-premultiplied RGBA.
// Image implements image.Image. // Image implements image.Image.
@ -93,16 +78,22 @@ func (i *Image) Fill(clr color.Color) error {
} }
func (i *Image) fill(r, g, b, a uint8) { func (i *Image) fill(r, g, b, a uint8) {
var c *ColorM wd, hd := i.Size()
ws, hs := emptyImage.Size()
sw := float64(wd) / float64(ws)
sh := float64(hd) / float64(hs)
op := &DrawImageOptions{}
op.GeoM.Scale(sw, sh)
if a > 0 { if a > 0 {
c = &ColorM{}
rf := float64(r) / float64(a) rf := float64(r) / float64(a)
gf := float64(g) / float64(a) gf := float64(g) / float64(a)
bf := float64(b) / float64(a) bf := float64(b) / float64(a)
af := float64(a) / 0xff af := float64(a) / 0xff
c.Translate(rf, gf, bf, af) op.ColorM.Translate(rf, gf, bf, af)
} }
drawWithFittingScale(i, emptyImage, c, FilterNearest) op.CompositeMode = CompositeModeCopy
op.Filter = FilterNearest
_ = i.DrawImage(emptyImage, op)
} }
// DrawImage draws the given image on the image i. // DrawImage draws the given image on the image i.