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
+4 -4
View File
@@ -29,14 +29,14 @@ func Circles(b image.Rectangle, radius int) chan iu.Circle {
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 {
return color.Opaque return color.Opaque
} }
return color.Transparent 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) ColorModel() color.Model { return color.Alpha16Model }
func (e Exchange) Bounds() image.Rectangle { return e.Image.Bounds() } 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( var blackAndWhite = 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 {
return color.Black return color.Black
} }
return color.White return color.White
@@ -55,7 +55,7 @@ var blackAndWhite = color.ModelFunc(
) )
// Black and white's alpha image. // 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) ColorModel() color.Model { return color.GrayModel }
func (b BlackAndWhite) Bounds() image.Rectangle { return b.Image.Bounds() } func (b BlackAndWhite) Bounds() image.Rectangle { return b.Image.Bounds() }
+3 -3
View File
@@ -15,9 +15,9 @@ func main() {
circles := Circles(canvas.Bounds(), 2160/6) circles := Circles(canvas.Bounds(), 2160/6)
palette := []color.Color{ palette := []color.Color{
color.RGBA{R:255, A:255}, color.RGBA{R: 255, A: 255},
color.RGBA{G:255, A:255}, color.RGBA{G: 255, A: 255},
color.RGBA{B:255, A:255}, color.RGBA{B: 255, A: 255},
} }
c := palette[rand.Int()%2] c := palette[rand.Int()%2]
+4 -4
View File
@@ -10,10 +10,10 @@ func main() {
draw.Draw(canvas, c.Bounds(), xor{c, canvas}, c.Bounds().Min, draw.Src) draw.Draw(canvas, c.Bounds(), xor{c, canvas}, c.Bounds().Min, draw.Src)
/* /*
draw.DrawMask( draw.DrawMask(
canvas, canvas.Bounds(), &image.Uniform{color.White}, canvas, canvas.Bounds(), &image.Uniform{color.White},
image.Point{}, xor{c, canvas}, image.Point{}, draw.Src, image.Point{}, xor{c, canvas}, image.Point{}, draw.Src,
) )
*/ */
} }
/* /*
-2
View File
@@ -1,3 +1 @@
package main package main
+1
View File
@@ -1,4 +1,5 @@
//go:build upsampling //go:build upsampling
package main package main
import ( import (
View File
+5 -6
View File
@@ -1,23 +1,22 @@
packagemain package main
import ( import (
"flag" "flag"
"image" "image"
"git.nkpl.cc/twocookedfaggots/imageutils/pkg/downscale" "git.nkpl.cc/twocookedfaggots/imageutils/pkg/downscale"
"git.nkpl.cc/twocookedfaggots/imageutils/downscale"
"git.nkpl.cc/twocookedfaggots/imageutils/util" "git.nkpl.cc/twocookedfaggots/imageutils/util"
) )
var x = flag.Int("x", 256, "dx value of new bounds") var x = flag.Int("x", 1024, "dx value of new bounds")
var y = flag.Int("y", 256, "dy value of new bounds") var y = flag.Int("y", 1024, "dy value of new bounds")
func main() { func main() {
flag.Parse() flag.Parse()
if err := util.ProcessStdio(func(img image.Image) image.Image { if err := util.ProcessStdio(func(img image.Image) image.Image {
return downscale.GridDownscale{ return downscale.GridDownscale{
Image: img, Image: img,
Rectangle: image.Rect(0,0,x,y), NewBounds: image.Rect(0, 0, *x, *y),
} }
}); err != nil { }); err != nil {
panic(err) panic(err)
+21 -23
View File
@@ -10,29 +10,27 @@ var (
func main() { func main() {
flag.Parse() flag.Parse()
f, err := truetype.Parse(gomono.TTF) f, err := truetype.Parse(gomono.TTF)
if err != nil { if err != nil {
panic(err) panic(err)
} }
face := truetype.NewFace(f, &truetype.Options{ face := truetype.NewFace(f, &truetype.Options{
Size: float64(img.Bounds().Dx() / size), Size: float64(img.Bounds().Dx() / size),
DPI: 72, DPI: 72,
Hinting: font.HintingNone, Hinting: font.HintingNone,
}) })
d := &font.Drawer{ d := &font.Drawer{
Dst: dst, Dst: dst,
Src: image.NewUniform(color.Black), Src: image.NewUniform(color.Black),
Face: face, Face: face,
Dot: fixed.Point26_6{fixed.Int26_6(img.Bounds().Dx() / Dot: fixed.Point26_6{fixed.Int26_6(img.Bounds().Dx() /
x, x,
), ),
fixed.Int26_6(img.Bounds().Dy() / fixed.Int26_6(img.Bounds().Dy() /
y, y,
), ),
}, },
} }
d.DrawString(time.Now().Format(time.Kitchen)) d.DrawString(time.Now().Format(time.Kitchen))
} }
+1 -1
View File
@@ -1,8 +1,8 @@
package main package main
import ( import (
"net/http"
"log" "log"
"net/http"
) )
type imageTransform struct { type imageTransform struct {
+3 -3
View File
@@ -5,13 +5,13 @@
package main package main
import ( import (
"git.nkpl.cc/twocookedfaggots/imageutils"
"git.nkpl.cc/twocookedfaggots/imageutils/http/blank"
"image" "image"
"image/color" "image/color"
"image/png"
"image/jpeg" "image/jpeg"
"image/png"
"os" "os"
"git.nkpl.cc/twocookedfaggots/imageutils"
"git.nkpl.cc/twocookedfaggots/imageutils/http/blank"
) )
func BlankFillWhite(img image.Image) image.Image { func BlankFillWhite(img image.Image) image.Image {
+1 -1
View File
@@ -12,7 +12,7 @@ func (i Into) At(x, y int) color.Color {
r := image.Rect(x1, y1, r := image.Rect(x1, y1,
x1+i.Src.Bounds().Dx(), y1+i.Src.Bounds().Dy()) x1+i.Src.Bounds().Dx(), y1+i.Src.Bounds().Dy())
if (image.Point{x, y}).In(r) { 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) return i.Dst.At(x, y)
} }
+1 -1
View File
@@ -27,7 +27,7 @@ func (g grid) At(x, y int) color.Color {
if n == 0 { if n == 0 {
return color.Black return color.Black
} }
step := int((side*side-1) / n) step := int((side*side - 1) / n)
if (y*side+x)%step == 0 { if (y*side+x)%step == 0 {
return color.White return color.White
} }
Binary file not shown.
+11 -9
View File
@@ -18,7 +18,7 @@ func (sub sub) At(x, y int) color.Color {
type GridDownscale struct { type GridDownscale struct {
image.Image image.Image
newBounds image.Rectangle NewBounds image.Rectangle
} }
func blend(c1, c2 color.Color) color.RGBA { 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) { func avgColor(img image.Image) (c color.Color) {
dx, dy := img.Bounds().Dx(), img.Bounds().Dy() b := img.Bounds()
for y := 0; y < dy; y++ { c = img.At(b.Min.X, b.Min.Y)
for x := 0; x < dx; x++ { 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)) c = blend(c, img.At(x, y))
} }
} }
return return
} }
func (grid grid) ColorModel() color.Model { return grid.Image.ColorModel } func (grid GridDownscale) ColorModel() color.Model { return grid.Image.ColorModel() }
func (grid grid) Bounds() image.Rectangle { return grid.NewBounds } func (grid GridDownscale) Bounds() image.Rectangle { return grid.NewBounds }
func (grid grid) At(x, y int) color.Color { func (grid GridDownscale) At(x, y int) color.Color {
b := grid.Image.Bounds() b := grid.Image.Bounds()
dx, dy := b.Dx(), b.Dy() dx, dy := b.Dx(), b.Dy()
cellBounds := image.Rect( cellBounds := image.Rect(
0, 0, 0, 0,
dx/grid.newBounds.Dx(), dx/grid.NewBounds.Dx(),
dy/grid.newBounds.Dy(), dy/grid.NewBounds.Dy(),
) )
r := grid.Image.Bounds().Intersect( 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}) return avgColor(sub{grid.Image, r})
} }
+5 -5
View File
@@ -12,11 +12,11 @@ var err error
func Wallpaper(img image.Image) error { func Wallpaper(img image.Image) error {
/* /*
cmd := exec.Command( cmd := exec.Command(
"swaybg", "swaybg",
"--image", "/dev/stdin", "--image", "/dev/stdin",
"--mode", "fill", "--mode", "fill",
) )
*/ */
cmd := exec.Command("imv", "/dev/stdin") cmd := exec.Command("imv", "/dev/stdin")
+4 -4
View File
@@ -57,10 +57,10 @@ func main() {
slices.Collect(maps.Keys(p)), imgutil.ColorToHex, slices.Collect(maps.Keys(p)), imgutil.ColorToHex,
) )
/* /*
h := make([]hex, 0, len(s)) h := make([]hex, 0, len(s))
for i := range s { for i := range s {
h = append(h, hex(s[i])) h = append(h, hex(s[i]))
} }
*/ */
err = w.Write(s) err = w.Write(s)
check(err) check(err)
-1
View File
@@ -33,7 +33,6 @@ func BenchmarkScale(b *testing.B) {
} }
} }
type SinglePixel struct{} type SinglePixel struct{}
func (s SinglePixel) At(x, y int) color.Color { func (s SinglePixel) At(x, y int) color.Color {