This commit is contained in:
2026-06-21 01:18:50 +03:00
parent afd438930e
commit 3b32bfa85f
20 changed files with 70 additions and 73 deletions
+11 -9
View File
@@ -18,7 +18,7 @@ func (sub sub) At(x, y int) color.Color {
type GridDownscale struct {
image.Image
newBounds image.Rectangle
NewBounds image.Rectangle
}
func blend(c1, c2 color.Color) color.RGBA {
@@ -39,24 +39,25 @@ func blend(c1, c2 color.Color) color.RGBA {
}
func avgColor(img image.Image) (c color.Color) {
dx, dy := img.Bounds().Dx(), img.Bounds().Dy()
for y := 0; y < dy; y++ {
for x := 0; x < dx; x++ {
b := img.Bounds()
c = img.At(b.Min.X, b.Min.Y)
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X + 1; x < b.Max.X; x++ {
c = blend(c, img.At(x, y))
}
}
return
}
func (grid grid) ColorModel() color.Model { return grid.Image.ColorModel }
func (grid grid) Bounds() image.Rectangle { return grid.NewBounds }
func (grid grid) At(x, y int) color.Color {
func (grid GridDownscale) ColorModel() color.Model { return grid.Image.ColorModel() }
func (grid GridDownscale) Bounds() image.Rectangle { return grid.NewBounds }
func (grid GridDownscale) At(x, y int) color.Color {
b := grid.Image.Bounds()
dx, dy := b.Dx(), b.Dy()
cellBounds := image.Rect(
0, 0,
dx/grid.newBounds.Dx(),
dy/grid.newBounds.Dy(),
dx/grid.NewBounds.Dx(),
dy/grid.NewBounds.Dy(),
)
r := grid.Image.Bounds().Intersect(
@@ -68,6 +69,7 @@ func (grid grid) At(x, y int) color.Color {
},
),
)
println(r.Min.X, r.Min.Y)
return avgColor(sub{grid.Image, r})
}