more image pattern fixes

This commit is contained in:
Thomas Friedel 2019-05-02 12:42:23 +02:00
parent 23a92d2221
commit aa059cfcf3
3 changed files with 14 additions and 14 deletions

View file

@ -260,6 +260,7 @@ func (cv *Canvas) backendFillStyle(s *drawStyle, alpha float64) backendbase.Fill
if ip.ip == nil {
stl.Color = color.RGBA{}
} else {
ip.ip.Replace(ip.data(cv.state.transform))
stl.ImagePattern = ip.ip
}
} else {

View file

@ -189,7 +189,7 @@ func (cv *Canvas) PutImageData(img *image.RGBA, x, y int) {
type ImagePattern struct {
cv *Canvas
img *Image
tf [9]float64
tf mat
rep imagePatternRepeat
ip backendbase.ImagePattern
}
@ -204,10 +204,15 @@ const (
NoRepeat = imagePatternRepeat(backendbase.NoRepeat)
)
func (ip *ImagePattern) data() backendbase.ImagePatternData {
func (ip *ImagePattern) data(tf mat) backendbase.ImagePatternData {
m := tf.invert().mul(ip.tf.invert())
return backendbase.ImagePatternData{
Image: ip.img.img,
Transform: ip.tf,
Transform: [9]float64{
m[0], m[2], m[4],
m[1], m[3], m[5],
0, 0, 1,
},
Repeat: backendbase.ImagePatternRepeat(ip.rep),
}
}
@ -216,13 +221,7 @@ func (ip *ImagePattern) data() backendbase.ImagePatternData {
// to the given matrix. The matrix is a 3x3 matrix, but three
// of the values are always identity values
func (ip *ImagePattern) SetTransform(tf [6]float64) {
m := mat(tf).invert()
ip.tf = [9]float64{
m[0], m[2], m[4],
m[1], m[3], m[5],
0, 0, 1,
}
ip.ip.Replace(ip.data())
ip.tf = mat(tf)
}
// CreatePattern creates a new image pattern with the specified
@ -232,10 +231,10 @@ func (cv *Canvas) CreatePattern(src interface{}, repeat imagePatternRepeat) *Ima
cv: cv,
img: cv.getImage(src),
rep: repeat,
tf: [9]float64{1, 0, 0, 0, 1, 0, 0, 0, 1},
tf: mat{1, 0, 0, 1, 0, 0},
}
if ip.img != nil {
ip.ip = cv.b.LoadImagePattern(ip.data())
ip.ip = cv.b.LoadImagePattern(ip.data(cv.state.transform))
}
return ip
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 13 KiB