пересаживаемся на новые колеса

This commit is contained in:
potassium5703 2024-08-14 00:34:01 +03:00
parent 2fbba1eed0
commit 19a89b5988
4 changed files with 2 additions and 174 deletions

View File

@ -8,7 +8,7 @@ import (
"io"
"time"
"git.niplace.ru/XoxJlopeZ_1488/clock/imageutils"
"github.com/potassium5703/imageutils"
"git.niplace.ru/XoxJlopeZ_1488/clock/letter"
)

View File

@ -1,126 +0,0 @@
package imageutils
import (
"image"
"image/color"
"image/draw"
)
type Side int
const (
Left Side = iota
Right
Up
Down
)
type pair struct {
first, second image.Image
side Side
}
// Takes color.Model of the first 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()
)
point := image.Point{}
switch p.side {
case Left:
fallthrough
case Right:
point = image.Point{
X: b1.Dx() + b2.Dx(),
Y: max(b1.Dy(), b2.Dy()),
}
case Up:
fallthrough
case Down:
point = image.Point{
X: max(b1.Dx(), b2.Dx()),
Y: b1.Dy() + b2.Dy(),
}
}
return image.Rectangle{
image.ZP,
point,
}
}
func (p pair) At(x, y int) color.Color {
img := image.NewRGBA(p.Bounds())
point := image.Point{}
switch p.side {
case Left:
p.first, p.second = p.second, p.first
fallthrough
case Right:
point = image.Point{-p.first.Bounds().Dx(), 0}
case Up:
p.first, p.second = p.second, p.first
fallthrough
case Down:
point = image.Point{0, -p.first.Bounds().Dy()}
}
// draw main
draw.Draw(
img, img.Bounds(),
p.first,
image.ZP, draw.Src,
)
// draw second
draw.Draw(
img, p.Bounds(),
p.second,
point,
draw.Src,
)
return img.At(x, y)
}
func render(p pair) image.Image {
img := image.NewRGBA(p.Bounds())
point := image.Point{}
switch p.side {
case Left:
p.first, p.second = p.second, p.first
fallthrough
case Right:
point = image.Point{-p.first.Bounds().Dx(), 0}
case Up:
p.first, p.second = p.second, p.first
fallthrough
case Down:
point = image.Point{0, -p.first.Bounds().Dy()}
}
// draw main
draw.Draw(
img, img.Bounds(),
p.first,
image.ZP, draw.Src,
)
// draw second
draw.Draw(
img, p.Bounds(),
p.second,
point,
draw.Src,
)
return img
}
// Concat concatenates second image on a given side.
func Concat(i1, i2 image.Image, s Side) image.Image {
return render(pair{i1, i2, s})
}

View File

@ -1,46 +0,0 @@
package imageutils
import (
"image"
"image/color"
)
type rescaled struct {
src image.Image
scale int
}
// ColorModel implements image.Image interface
func (r rescaled) ColorModel() color.Model {
return r.src.ColorModel()
}
// Bounds implements image.Image interface
func (r rescaled) Bounds() image.Rectangle {
b := r.src.Bounds()
return image.Rectangle{
Min: image.Point{
X: b.Min.X,
Y: b.Min.Y,
},
Max: image.Point{
X: b.Max.X * r.scale,
Y: b.Max.Y * r.scale,
},
}
}
// At implements image.Image interface
func (r rescaled) At(x, y int) color.Color {
return r.src.At(x/r.scale, y/r.scale)
}
// Scale scales image.Image to a given scale
// and then returns image.Image.
// For now it will work only with positive integers.
func Scale(img image.Image, scale int) image.Image {
if scale < 1 {
scale = 1
}
return rescaled{img, scale}
}

View File

@ -1,7 +1,7 @@
package letter
import (
"git.niplace.ru/XoxJlopeZ_1488/clock/imageutils"
"github.com/potassium5703/imageutils"
"image"
"image/color"
"image/draw"