more new ideas
This commit is contained in:
@@ -11,7 +11,7 @@ type Circle struct {
|
|||||||
R int
|
R int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Circle) ColorModel() color.Model { return color.AlphaModel }
|
func (c Circle) ColorModel() color.Model { return color.Alpha16Model }
|
||||||
func (c Circle) Bounds() image.Rectangle {
|
func (c Circle) Bounds() image.Rectangle {
|
||||||
return image.Rect(c.Point.X-c.R, c.Point.Y-c.R, c.Point.X+c.R, c.Point.Y+c.R)
|
return image.Rect(c.Point.X-c.R, c.Point.Y-c.R, c.Point.X+c.R, c.Point.Y+c.R)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,24 +27,6 @@ func Circles(b image.Rectangle, radius int) chan iu.Circle {
|
|||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
var Opaque, Transparent = color.Alpha{0xff}, color.Alpha{0}
|
|
||||||
|
|
||||||
type xor struct{ dst, src image.Image }
|
|
||||||
|
|
||||||
func (t xor) ColorModel() color.Model { return t.dst.ColorModel() }
|
|
||||||
func (t xor) Bounds() image.Rectangle { return t.src.Bounds() }
|
|
||||||
func (t xor) At(x, y int) color.Color {
|
|
||||||
dstColor := t.ColorModel().Convert(t.dst.At(x, y))
|
|
||||||
srcColor := t.ColorModel().Convert(t.src.At(x, y))
|
|
||||||
|
|
||||||
|
|
||||||
if ((dstColor == color.Opaque) || (srcColor == color.Opaque)) &&
|
|
||||||
!((dstColor == color.Opaque) && (srcColor == color.Opaque)) {
|
|
||||||
return color.Opaque
|
|
||||||
}
|
|
||||||
return color.Transparent
|
|
||||||
}
|
|
||||||
|
|
||||||
var exchange = color.ModelFunc(
|
var exchange = color.ModelFunc(
|
||||||
func(c color.Color) color.Color {
|
func(c color.Color) color.Color {
|
||||||
if color.Alpha16Model.Convert(c) == color.Transparent{
|
if color.Alpha16Model.Convert(c) == color.Transparent{
|
||||||
@@ -63,29 +45,21 @@ func (e Exchange) At(x, y int) color.Color {
|
|||||||
return exchange.Convert(c)
|
return exchange.Convert(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
var blackAndWhite = color.ModelFunc(
|
||||||
canvas := image.NewAlpha16(square(1024))
|
func(c color.Color) color.Color {
|
||||||
circles := Circles(canvas.Bounds(), 1024/7)
|
if color.Alpha16Model.Convert(c) == color.Transparent{
|
||||||
|
return color.Black
|
||||||
// draw n circles
|
|
||||||
for i := 0; i < 500; i++ {
|
|
||||||
c := <-circles
|
|
||||||
|
|
||||||
draw.Draw(canvas, c.Bounds(), xor{c, canvas}, c.Bounds().Min, draw.Src)
|
|
||||||
/*
|
|
||||||
draw.DrawMask(
|
|
||||||
canvas, canvas.Bounds(), &image.Uniform{color.White},
|
|
||||||
image.Point{}, xor{c, canvas}, image.Point{}, draw.Src,
|
|
||||||
)
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
newCanvas := image.NewRGBA(canvas.Bounds())
|
|
||||||
draw.Draw(newCanvas, newCanvas.Bounds(), &image.Uniform{color.RGBA{255, 255, 0, 255}}, image.ZP, draw.Over)
|
|
||||||
draw.Draw(newCanvas, newCanvas.Bounds(), canvas, image.ZP, draw.Over)
|
|
||||||
*/
|
|
||||||
err := png.Encode(os.Stdout, canvas)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
return color.White
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// Black and white's alpha image.
|
||||||
|
type BlackAndWhite struct { image.Image }
|
||||||
|
|
||||||
|
func (b BlackAndWhite) ColorModel() color.Model { return color.GrayModel }
|
||||||
|
func (b BlackAndWhite) Bounds() image.Rectangle { return b.Image.Bounds() }
|
||||||
|
func (b BlackAndWhite) At(x, y int) color.Color {
|
||||||
|
c := b.Image.At(x, y)
|
||||||
|
return blackAndWhite.Convert(c)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
//go:build colored
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
/*
|
||||||
|
const (
|
||||||
|
red = iota
|
||||||
|
green
|
||||||
|
blue
|
||||||
|
)
|
||||||
|
*/
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
canvas := image.NewRGBA(image.Rect(0, 0, 3840, 2160))
|
||||||
|
circles := Circles(canvas.Bounds(), 2160/6)
|
||||||
|
|
||||||
|
palette := []color.Color{
|
||||||
|
color.RGBA{R:255, A:255},
|
||||||
|
color.RGBA{G:255, A:255},
|
||||||
|
color.RGBA{B:255, A:255},
|
||||||
|
}
|
||||||
|
c := palette[rand.Int()%2]
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
canvas := image.NewRGBA(image.Rect(0, 0, 3840, 2160))
|
||||||
|
circles := Circles(canvas.Bounds(), 2160/6)
|
||||||
|
|
||||||
|
// draw n circles
|
||||||
|
for i := 0; i < 24; i++ {
|
||||||
|
c := <-circles
|
||||||
|
|
||||||
|
draw.Draw(canvas, c.Bounds(), xor{c, canvas}, c.Bounds().Min, draw.Src)
|
||||||
|
/*
|
||||||
|
draw.DrawMask(
|
||||||
|
canvas, canvas.Bounds(), &image.Uniform{color.White},
|
||||||
|
image.Point{}, xor{c, canvas}, image.Point{}, draw.Src,
|
||||||
|
)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
newCanvas := image.NewRGBA(canvas.Bounds())
|
||||||
|
draw.Draw(newCanvas, newCanvas.Bounds(), &image.Uniform{color.RGBA{255, 255, 0, 255}}, image.ZP, draw.Over)
|
||||||
|
draw.Draw(newCanvas, newCanvas.Bounds(), canvas, image.ZP, draw.Over)
|
||||||
|
*/
|
||||||
|
err := png.Encode(os.Stdout, BlackAndWhite{canvas})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
var Opaque, Transparent = color.Alpha{0xff}, color.Alpha{0}
|
||||||
|
|
||||||
|
type xor struct{ dst, src image.Image }
|
||||||
|
|
||||||
|
func (t xor) ColorModel() color.Model { return t.dst.ColorModel() }
|
||||||
|
func (t xor) Bounds() image.Rectangle { return t.src.Bounds() }
|
||||||
|
func (t xor) At(x, y int) color.Color {
|
||||||
|
dstColor := t.ColorModel().Convert(t.dst.At(x, y))
|
||||||
|
srcColor := t.ColorModel().Convert(t.src.At(x, y))
|
||||||
|
|
||||||
|
// xor operation (a || b) && !(a && b)
|
||||||
|
if ((dstColor == color.Opaque) || (srcColor == color.Opaque)) &&
|
||||||
|
!((dstColor == color.Opaque) && (srcColor == color.Opaque)) {
|
||||||
|
return color.Opaque
|
||||||
|
}
|
||||||
|
return color.Transparent
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"math/rand"
|
||||||
|
|
||||||
|
iu "git.nkpl.cc/twocookedfaggots/imageutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func square(side int) image.Rectangle { return image.Rect(0, 0, side, side) }
|
||||||
|
|
||||||
|
func Circles(b image.Rectangle, radius int) chan iu.Circle {
|
||||||
|
ch := make(chan iu.Circle)
|
||||||
|
go func() {
|
||||||
|
defer close(ch)
|
||||||
|
for {
|
||||||
|
x, y := rand.Int()%b.Dx(), rand.Int()%b.Dy()
|
||||||
|
dxdy := b.Dx() * b.Dy()
|
||||||
|
r := rand.Int() % (dxdy / (dxdy / radius))
|
||||||
|
ch <- iu.Circle{image.Point{x, y}, r}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
||||||
|
var Opaque, Transparent = color.Alpha{0xff}, color.Alpha{0}
|
||||||
|
|
||||||
|
type xor struct{ dst, src image.Image }
|
||||||
|
|
||||||
|
func (t xor) ColorModel() color.Model { return t.dst.ColorModel() }
|
||||||
|
func (t xor) Bounds() image.Rectangle { return t.src.Bounds() }
|
||||||
|
func (t xor) At(x, y int) color.Color {
|
||||||
|
dstColor := t.ColorModel().Convert(t.dst.At(x, y))
|
||||||
|
srcColor := t.ColorModel().Convert(t.src.At(x, y))
|
||||||
|
|
||||||
|
// xor operation (a || b) && !(a && b)
|
||||||
|
if ((dstColor == color.Opaque) || (srcColor == color.Opaque)) &&
|
||||||
|
!((dstColor == color.Opaque) && (srcColor == color.Opaque)) {
|
||||||
|
return color.Opaque
|
||||||
|
}
|
||||||
|
return color.Transparent
|
||||||
|
}
|
||||||
|
|
||||||
|
var exchange = color.ModelFunc(
|
||||||
|
func(c color.Color) color.Color {
|
||||||
|
if color.Alpha16Model.Convert(c) == color.Transparent {
|
||||||
|
return color.Opaque
|
||||||
|
}
|
||||||
|
return color.Transparent
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
type Exchange struct{ image.Image }
|
||||||
|
|
||||||
|
func (e Exchange) ColorModel() color.Model { return color.Alpha16Model }
|
||||||
|
func (e Exchange) Bounds() image.Rectangle { return e.Image.Bounds() }
|
||||||
|
func (e Exchange) At(x, y int) color.Color {
|
||||||
|
c := e.ColorModel().Convert(e.Image.At(x, y))
|
||||||
|
return exchange.Convert(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
var blackAndWhite = color.ModelFunc(
|
||||||
|
func(c color.Color) color.Color {
|
||||||
|
if color.Alpha16Model.Convert(c) == color.Transparent {
|
||||||
|
return color.Black
|
||||||
|
}
|
||||||
|
return color.White
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// Black and white's alpha image.
|
||||||
|
type BlackAndWhite struct{ image.Image }
|
||||||
|
|
||||||
|
func (b BlackAndWhite) ColorModel() color.Model { return color.Gray16Model }
|
||||||
|
func (b BlackAndWhite) Bounds() image.Rectangle { return b.Image.Bounds() }
|
||||||
|
func (b BlackAndWhite) At(x, y int) color.Color {
|
||||||
|
c := b.Image.At(x, y)
|
||||||
|
return blackAndWhite.Convert(c)
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"image/draw"
|
||||||
|
"image/png"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type XORMask struct {
|
||||||
|
dst, src image.Image
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m XORMask) ColorModel() color.Model { return color.Gray16Model }
|
||||||
|
func (m XORMask) Bounds() image.Rectangle { return m.dst.Bounds() }
|
||||||
|
func (m XORMask) At(x, y int) color.Color {
|
||||||
|
srcColor := m.src.At(x, y)
|
||||||
|
dstColor := m.dst.At(x, y)
|
||||||
|
|
||||||
|
if ((dstColor == color.Black) || (srcColor == color.Black)) &&
|
||||||
|
!((dstColor == color.Black) && (srcColor == color.Black)) {
|
||||||
|
return color.Black
|
||||||
|
}
|
||||||
|
return color.White
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
img, err := png.Decode(os.Stdin)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
grayImg := image.NewGray16(img.Bounds())
|
||||||
|
for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
|
||||||
|
for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ {
|
||||||
|
c := img.At(x, y)
|
||||||
|
grayImg.Set(x, y, color.Gray16Model.Convert(c))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
canvas := image.NewRGBA(img.Bounds())
|
||||||
|
circle := Circles(canvas.Bounds(), canvas.Bounds().Dy()/6)
|
||||||
|
for i := 0; i < 24; i++ {
|
||||||
|
c := <-circle
|
||||||
|
draw.Draw(canvas, c.Bounds(), xor{c, canvas}, c.Bounds().Min, draw.Src)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = png.Encode(
|
||||||
|
os.Stdout, XORMask{
|
||||||
|
grayImg,
|
||||||
|
BlackAndWhite{
|
||||||
|
Exchange{
|
||||||
|
canvas,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build upsampling
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"image"
|
||||||
|
|
||||||
|
"git.nkpl.cc/twocookedfaggots/imageutils/downscale"
|
||||||
|
"git.nkpl.cc/twocookedfaggots/imageutils/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
var x = flag.Int("x", 256, "dx value of new bounds")
|
||||||
|
var y = flag.Int("y", 256, "dy value of new bounds")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
if err := util.ProcessStdio(func(img image.Image) image.Image {
|
||||||
|
return downscale.GridDownscale{
|
||||||
|
Image: img,
|
||||||
|
Rectangle: image.Rect(0,0,x,y),
|
||||||
|
}
|
||||||
|
}); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
var (
|
||||||
|
x = flag.Int("x", 0, "")
|
||||||
|
y = flag.Int("y", 0, "")
|
||||||
|
size = flag.Int("size", 24, "size of font")
|
||||||
|
// img = flag.String("path", "", "path to image")
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
f, err := truetype.Parse(gomono.TTF)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
face := truetype.NewFace(f, &truetype.Options{
|
||||||
|
Size: float64(img.Bounds().Dx() / size),
|
||||||
|
DPI: 72,
|
||||||
|
Hinting: font.HintingNone,
|
||||||
|
})
|
||||||
|
|
||||||
|
d := &font.Drawer{
|
||||||
|
Dst: dst,
|
||||||
|
Src: image.NewUniform(color.Black),
|
||||||
|
Face: face,
|
||||||
|
Dot: fixed.Point26_6{fixed.Int26_6(img.Bounds().Dx() /
|
||||||
|
x,
|
||||||
|
),
|
||||||
|
fixed.Int26_6(img.Bounds().Dy() /
|
||||||
|
y,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
d.DrawString(time.Now().Format(time.Kitchen))
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "image/color"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
c1, c2 := color.Black,
|
||||||
|
color.Gray16Model.Convert(color.RGBA{})
|
||||||
|
|
||||||
|
println(c1.RGBA())
|
||||||
|
println(c2.RGBA())
|
||||||
|
println(c1 == c2)
|
||||||
|
}
|
||||||
@@ -4,5 +4,10 @@ go 1.25.5
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
||||||
golang.org/x/image v0.36.0
|
golang.org/x/image v0.43.0
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/dbriemann/pixel v0.5.1 // indirect
|
||||||
|
github.com/go-gl/mathgl v1.2.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
|
github.com/dbriemann/pixel v0.5.1 h1:9iPqkfolOW2VRu8IzEbUBii9/S5ubMwPTQP7xBGkNX8=
|
||||||
|
github.com/dbriemann/pixel v0.5.1/go.mod h1:iWjzS4T3euA4FW04ULyz3SCkZB5LyK7pwTR1vyZFv0E=
|
||||||
|
github.com/go-gl/mathgl v1.2.0 h1:v2eOj/y1B2afDxF6URV1qCYmo1KW08lAMtTbOn3KXCY=
|
||||||
|
github.com/go-gl/mathgl v1.2.0/go.mod h1:pf9+b5J3LFP7iZ4XXaVzZrCle0Q/vNpB/vDe5+3ulRE=
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||||
golang.org/x/image v0.36.0 h1:Iknbfm1afbgtwPTmHnS2gTM/6PPZfH+z2EFuOkSbqwc=
|
golang.org/x/image v0.36.0 h1:Iknbfm1afbgtwPTmHnS2gTM/6PPZfH+z2EFuOkSbqwc=
|
||||||
golang.org/x/image v0.36.0/go.mod h1:YsWD2TyyGKiIX1kZlu9QfKIsQ4nAAK9bdgdrIsE7xy4=
|
golang.org/x/image v0.36.0/go.mod h1:YsWD2TyyGKiIX1kZlu9QfKIsQ4nAAK9bdgdrIsE7xy4=
|
||||||
|
golang.org/x/image v0.43.0 h1:FLxcP4ec2350nTfOC8ysKtqYSIFbk/QGjw1ZHNP4tsY=
|
||||||
|
golang.org/x/image v0.43.0/go.mod h1:rrpelvGFt+kLPAjPM4HeWPgrl0FtafueU//e5N0qk/Q=
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
const side = 16
|
const side = 16
|
||||||
|
|
||||||
|
// tile
|
||||||
type grid struct {
|
type grid struct {
|
||||||
color.Gray
|
color.Gray
|
||||||
Factor float64
|
Factor float64
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package downscale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package downscale
|
||||||
|
|
||||||
|
type sub struct {
|
||||||
|
image.Image
|
||||||
|
image.Rectangle
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sub sub) ColorModel() color.Model { return sub.Image.ColorModel() }
|
||||||
|
func (sub sub) Bounds() image.Rectangle { return sub.Rectangle }
|
||||||
|
func (sub sub) At(x, y int) color.Color {
|
||||||
|
return sub.Image.At(x, y)
|
||||||
|
}
|
||||||
|
|
||||||
|
type GridDownscale struct {
|
||||||
|
image.Image
|
||||||
|
newBounds image.Rectangle
|
||||||
|
}
|
||||||
|
|
||||||
|
func blend(c1, c2 color.Color) color.RGBA {
|
||||||
|
r1, g1, b1, a1 := c1.RGBA()
|
||||||
|
r2, g2, b2, a2 := c2.RGBA()
|
||||||
|
|
||||||
|
r := r1/2 + r2/2
|
||||||
|
g := g1/2 + g2/2
|
||||||
|
b := b1/2 + b2/2
|
||||||
|
a := a1/2 + a2/2
|
||||||
|
|
||||||
|
return color.RGBA{
|
||||||
|
R: uint8(r >> 8),
|
||||||
|
G: uint8(g >> 8),
|
||||||
|
B: uint8(b >> 8),
|
||||||
|
A: uint8(a >> 8),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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++ {
|
||||||
|
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 {
|
||||||
|
b := grid.Image.Bounds()
|
||||||
|
dx, dy := b.Dx(), b.Dy()
|
||||||
|
cellBounds := image.Rect(
|
||||||
|
0, 0,
|
||||||
|
dx/grid.newBounds.Dx(),
|
||||||
|
dy/grid.newBounds.Dy(),
|
||||||
|
)
|
||||||
|
|
||||||
|
r := grid.Image.Bounds().Intersect(
|
||||||
|
// move cell
|
||||||
|
cellBounds.Add(
|
||||||
|
image.Point{
|
||||||
|
x * cellBounds.Dx(),
|
||||||
|
y * cellBounds.Dy(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
return avgColor(sub{grid.Image, r})
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package downscale
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"image/jpeg"
|
|
||||||
"image/png"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// open image
|
|
||||||
img, err := jpeg.Decode(os.Stdin)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
// no pre-processing needed so we just
|
|
||||||
// write image
|
|
||||||
err = png.Encode(os.Stdout, Downscaled{img, 3})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package imageutils
|
||||||
|
|
||||||
|
type Transformer interface {
|
||||||
|
Transform(image.Image) image.Image
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user