diff --git a/cmd/playground/circles/circles.go b/cmd/playground/circles/circles.go index dc79df9..cbdbf87 100644 --- a/cmd/playground/circles/circles.go +++ b/cmd/playground/circles/circles.go @@ -29,14 +29,14 @@ func Circles(b image.Rectangle, radius int) chan iu.Circle { var exchange = color.ModelFunc( func(c color.Color) color.Color { - if color.Alpha16Model.Convert(c) == color.Transparent{ + if color.Alpha16Model.Convert(c) == color.Transparent { return color.Opaque } return color.Transparent }, ) -type Exchange struct { image.Image } +type Exchange struct{ image.Image } func (e Exchange) ColorModel() color.Model { return color.Alpha16Model } func (e Exchange) Bounds() image.Rectangle { return e.Image.Bounds() } @@ -47,7 +47,7 @@ func (e Exchange) At(x, y int) color.Color { var blackAndWhite = color.ModelFunc( func(c color.Color) color.Color { - if color.Alpha16Model.Convert(c) == color.Transparent{ + if color.Alpha16Model.Convert(c) == color.Transparent { return color.Black } return color.White @@ -55,7 +55,7 @@ var blackAndWhite = color.ModelFunc( ) // Black and white's alpha image. -type BlackAndWhite struct { image.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() } diff --git a/cmd/playground/circles/colored.go b/cmd/playground/circles/colored.go index 427cb7b..068857a 100644 --- a/cmd/playground/circles/colored.go +++ b/cmd/playground/circles/colored.go @@ -15,10 +15,10 @@ func main() { 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}, + color.RGBA{R: 255, A: 255}, + color.RGBA{G: 255, A: 255}, + color.RGBA{B: 255, A: 255}, } c := palette[rand.Int()%2] - + } diff --git a/cmd/playground/circles/main.go b/cmd/playground/circles/main.go index 653d77e..1d70c58 100644 --- a/cmd/playground/circles/main.go +++ b/cmd/playground/circles/main.go @@ -10,10 +10,10 @@ func main() { 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, - ) + draw.DrawMask( + canvas, canvas.Bounds(), &image.Uniform{color.White}, + image.Point{}, xor{c, canvas}, image.Point{}, draw.Src, + ) */ } /* diff --git a/cmd/playground/circles/xor.go b/cmd/playground/circles/xor.go index 6dd9ca2..3054399 100644 --- a/cmd/playground/circles/xor.go +++ b/cmd/playground/circles/xor.go @@ -11,7 +11,7 @@ func (t xor) At(x, y int) color.Color { srcColor := t.ColorModel().Convert(t.src.At(x, y)) // xor operation (a || b) && !(a && b) - if ((dstColor == color.Opaque) || (srcColor == color.Opaque)) && + if ((dstColor == color.Opaque) || (srcColor == color.Opaque)) && !((dstColor == color.Opaque) && (srcColor == color.Opaque)) { return color.Opaque } diff --git a/cmd/playground/circles/xor_colored.go b/cmd/playground/circles/xor_colored.go index 1110061..06ab7d0 100644 --- a/cmd/playground/circles/xor_colored.go +++ b/cmd/playground/circles/xor_colored.go @@ -1,3 +1 @@ package main - - diff --git a/cmd/playground/main.go b/cmd/playground/main.go index e1b7f4c..0d3ed4a 100644 --- a/cmd/playground/main.go +++ b/cmd/playground/main.go @@ -5,5 +5,5 @@ import ( ) func main() { - + } diff --git a/cmd/scale/downscale.go b/cmd/scale/downscale.go index 7df49df..4406643 100644 --- a/cmd/scale/downscale.go +++ b/cmd/scale/downscale.go @@ -1,4 +1,5 @@ //go:build upsampling + package main import ( diff --git a/cmd/scale/downscaled.png b/cmd/scale/downscaled.png new file mode 100644 index 0000000..e69de29 diff --git a/cmd/scale/griddownscale.go b/cmd/scale/griddownscale.go index 27835dc..e502440 100644 --- a/cmd/scale/griddownscale.go +++ b/cmd/scale/griddownscale.go @@ -1,23 +1,22 @@ -packagemain +package main import ( "flag" "image" "git.nkpl.cc/twocookedfaggots/imageutils/pkg/downscale" - "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") +var x = flag.Int("x", 1024, "dx value of new bounds") +var y = flag.Int("y", 1024, "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), + Image: img, + NewBounds: image.Rect(0, 0, *x, *y), } }); err != nil { panic(err) diff --git a/cmd/scale/img.png b/cmd/scale/img.png new file mode 100644 index 0000000..9deb5b5 Binary files /dev/null and b/cmd/scale/img.png differ diff --git a/cmd/textonimage/main.go b/cmd/textonimage/main.go index 6031678..700d8e5 100644 --- a/cmd/textonimage/main.go +++ b/cmd/textonimage/main.go @@ -10,29 +10,27 @@ var ( 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, - }) + 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)) + 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)) } diff --git a/http/http.go b/http/http.go index c84af96..3b67352 100644 --- a/http/http.go +++ b/http/http.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "log" + "net/http" ) type imageTransform struct { @@ -29,14 +29,14 @@ func indexHTML(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) log.Println("copy error:", err) return - } + } } func main() { http.HandleFunc("/", indexHTML) http.Handle("POST /upload", imageTransform) - err := http.ListenAndServe(":8080", nil) + err := http.ListenAndServe(":8080", nil) if err != nil { log.Panicln(err) } diff --git a/http/test.go b/http/test.go index 5a5af85..4581657 100644 --- a/http/test.go +++ b/http/test.go @@ -5,13 +5,13 @@ package main import ( + "git.nkpl.cc/twocookedfaggots/imageutils" + "git.nkpl.cc/twocookedfaggots/imageutils/http/blank" "image" "image/color" - "image/png" "image/jpeg" + "image/png" "os" -"git.nkpl.cc/twocookedfaggots/imageutils" - "git.nkpl.cc/twocookedfaggots/imageutils/http/blank" ) func BlankFillWhite(img image.Image) image.Image { diff --git a/pkg/center/main.go b/pkg/center/main.go index 1cfe847..be3de78 100644 --- a/pkg/center/main.go +++ b/pkg/center/main.go @@ -12,7 +12,7 @@ func (i Into) At(x, y int) color.Color { r := image.Rect(x1, y1, x1+i.Src.Bounds().Dx(), y1+i.Src.Bounds().Dy()) if (image.Point{x, y}).In(r) { - return i.Src.At(x-x1,y-y2) + return i.Src.At(x-x1, y-y2) } return i.Dst.At(x, y) } diff --git a/pkg/dithering/grid.go b/pkg/dithering/grid.go index ca04034..3ff03d0 100644 --- a/pkg/dithering/grid.go +++ b/pkg/dithering/grid.go @@ -27,7 +27,7 @@ func (g grid) At(x, y int) color.Color { if n == 0 { return color.Black } - step := int((side*side-1) / n) + step := int((side*side - 1) / n) if (y*side+x)%step == 0 { return color.White } diff --git a/pkg/downscale/.grid.go.swp b/pkg/downscale/.grid.go.swp new file mode 100644 index 0000000..f8ba58e Binary files /dev/null and b/pkg/downscale/.grid.go.swp differ diff --git a/pkg/downscale/grid.go b/pkg/downscale/grid.go index 4deab89..f07802b 100644 --- a/pkg/downscale/grid.go +++ b/pkg/downscale/grid.go @@ -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}) } diff --git a/pkg/mesh/wallpaper/swaybg.go b/pkg/mesh/wallpaper/swaybg.go index 69c8060..6191e1d 100644 --- a/pkg/mesh/wallpaper/swaybg.go +++ b/pkg/mesh/wallpaper/swaybg.go @@ -12,11 +12,11 @@ var err error func Wallpaper(img image.Image) error { /* - cmd := exec.Command( - "swaybg", - "--image", "/dev/stdin", - "--mode", "fill", - ) + cmd := exec.Command( + "swaybg", + "--image", "/dev/stdin", + "--mode", "fill", + ) */ cmd := exec.Command("imv", "/dev/stdin") diff --git a/pkg/mkpalette/palette.go b/pkg/mkpalette/palette.go index acd4afe..2b4688f 100644 --- a/pkg/mkpalette/palette.go +++ b/pkg/mkpalette/palette.go @@ -57,10 +57,10 @@ func main() { slices.Collect(maps.Keys(p)), imgutil.ColorToHex, ) /* - h := make([]hex, 0, len(s)) - for i := range s { - h = append(h, hex(s[i])) - } + h := make([]hex, 0, len(s)) + for i := range s { + h = append(h, hex(s[i])) + } */ err = w.Write(s) check(err) diff --git a/pkg/showpalette/show.go b/pkg/showpalette/show.go index 0450654..3e5b650 100644 --- a/pkg/showpalette/show.go +++ b/pkg/showpalette/show.go @@ -68,7 +68,7 @@ func main() { }, ), ) - + err = png.Encode(os.Stdout, showColors{palette}) check(err) } diff --git a/scale_test.go b/scale_test.go index 2bd22bf..08f5835 100644 --- a/scale_test.go +++ b/scale_test.go @@ -33,7 +33,6 @@ func BenchmarkScale(b *testing.B) { } } - type SinglePixel struct{} func (s SinglePixel) At(x, y int) color.Color {