concat.go

This commit is contained in:
potassium 2023-12-12 22:30:03 +03:00
parent 48074bb2cc
commit b646bef7b2
2 changed files with 57 additions and 1 deletions

56
concat.go Normal file
View File

@ -0,0 +1,56 @@
//go:build todo
package imageutils
import (
"image"
"image/color"
"image/draw"
)
type pair struct {
first, second image.Image
}
func (p pair) ColorModel() color.Model { return p.first.ColorModel() }
func (p pair) Bounds() image.Rectangle {
var (
b1 = p.first.Bounds()
b2 = p.second.Bounds()
)
return image.Rectangle{
image.ZP,
image.Point{
X: b1.Dx() + b2.Dx(),
Y: max(b1.Dy(), b2.Dy()),
},
}
}
func (p pair) At(x, y int) color.Color {
rgbaImg := image.NewRGBA(p.Bounds())
draw.Draw(
rgbaImg,
rgbaImg.Bounds(),
p.first,
image.ZP,
draw.Src,
)
draw.Draw(
rgbaImg,
p.Bounds(),
p.second,
image.Point{
p.first.Bounds().Dx(),
0,
},
draw.Src,
)
return rgbaImg
}
// Concat concatenates second image to the right side of first.
func Concat(i1, i2 image.Image) image.Image {
return pair{i1, i2}
}

View File

@ -42,5 +42,5 @@ func Scale(img image.Image, scale int) image.Image {
if scale < 1 { if scale < 1 {
scale = 1 scale = 1
} }
return rescaled{img, scale} return rescaled{img, scale}
} }