to save up a progress

This commit is contained in:
2026-09-19 23:21:09 +03:00
parent 78cdfa3beb
commit e51ffde305
16 changed files with 267 additions and 13 deletions
+8 -4
View File
@@ -7,10 +7,14 @@ import (
const side = 16
type Options struct {
Factor float64
}
// tile
type grid struct {
color.Gray
Factor float64
Options
}
func (_ grid) ColorModel() color.Model {
@@ -22,7 +26,7 @@ func (_ grid) Bounds() image.Rectangle {
}
func (g grid) At(x, y int) color.Color {
n := uint8(float64(g.Gray.Y) * g.Factor)
n := uint8(float64(g.Gray.Y) * g.Options.Factor)
if n == 0 {
return color.Black
@@ -54,13 +58,13 @@ func (g uniformGrid) At(x, y int) color.Color {
type Dithering struct {
image.Image
Factor float64
Options
}
func (d Dithering) ColorModel() color.Model { return color.GrayModel }
func (d Dithering) Bounds() image.Rectangle { return d.Image.Bounds() }
func (d Dithering) At(x, y int) color.Color {
c := color.GrayModel.Convert(d.Image.At(x, y))
return uniformGrid{grid{c.(color.Gray), d.Factor}}.
return uniformGrid{grid{c.(color.Gray), d.Options.Factor}}.
At(x, y)
}
+47 -4
View File
@@ -9,6 +9,7 @@ import (
"os/exec"
"testing"
"time"
"reflect"
"git.nkpl.cc/twocookedfaggots/imageutils"
)
@@ -17,6 +18,8 @@ func init() {
rand.Seed(time.Now().UnixNano())
}
const factor = 0.75
func callImage(img image.Image) {
for y := 0; y < img.Bounds().Dy(); y++ {
for x := 0; x < img.Bounds().Dx(); x++ {
@@ -38,14 +41,14 @@ func TestGrid(t *testing.T) {
n := uint8(rand.Int() % 256)
t.Log(n)
img := imageutils.Scale(1<<6, grid{color.Gray{n}})
img := imageutils.Scale(grid{color.Gray{n}, factor}, 1<<6)
err = png.Encode(w, img)
if err != nil {
t.Fatal(err)
}
callImage(grid{color.Gray{4}})
callImage(grid{color.Gray{0}})
callImage(grid{color.Gray{4}, factor})
callImage(grid{color.Gray{0}, factor})
}
func TestDithering(t *testing.T) {
@@ -66,8 +69,48 @@ func TestDithering(t *testing.T) {
t.Fatal(err)
}
err = png.Encode(w, Dithering{img})
err = png.Encode(w, Dithering{img, factor})
if err != nil {
t.Fatal(err)
}
}
func TestRangeStruct(t *testing.T){
s := Dithering{image.Rectangle{},0}
value := reflect.ValueOf(s)
if value.Kind() == reflect.Ptr {
value = value.Elem()
}
if value.Kind() != reflect.Struct {
t.Log("Provided value is not a struct")
}
tp := value.Type()
for i := 0; i < value.NumField(); i++ {
fieldName := tp.Field(i).Name
fieldValue := value.Field(i)
if !fieldValue.CanInterface() {
t.Logf("Field %s is unexported\n", fieldName)
continue
}
if fieldValue.Kind() == reflect.Ptr {
fieldValue = fieldValue.Elem()
}
/*
if fieldValue.Kind() == reflect.Interface {
fieldValue = fieldValue.Elem()
}
*/
actualValue := fieldValue.Interface()
switch v := actualValue.(type) {
case float64:
t.Logf("Field '%s' is a float64.\n", fieldName)
case image.Image:
t.Logf("Field '%s' is a image.Image. Value: %q\n", fieldName, v)
default:
t.Logf("Field '%s' has an unhandled type: %T\n", fieldName, v)
}
}
}
+20
View File
@@ -0,0 +1,20 @@
//go:build ignore
package dithering
func valueOfType(a any) reflect.Value {
return reflect.TypeOf(a).Elem()
}
func ServeHTTP(w http.ResponseWriter, req* http.Request) {
instance := new(Dithering{})
value := reflect.ValueOf(instance).Elem()
imageType := valueOfType(new(image.Image))
floatType := valueOfType
for i := 0; i < value.NumField(); i++ {
v := value.Field(i)
switch v.Type() {
case imageType
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 KiB

After

Width:  |  Height:  |  Size: 264 KiB

Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
package main
import (
"reflect"
"git.nkpl.cc/twocookedfaggots/imageutils/pkg/mirror"
)
func main() {
cmp := func(v reflect.Value) {
switch v := reflect.f {
case
}
}
instance := &mirror.Mirror{}
value := reflect.ValueOf(instance).Elem()
for i := 0; i < value.NumField(); i++ {
value.Type().Field(i)
}
}
+16
View File
@@ -0,0 +1,16 @@
package main
import (
"log"
"net/http"
)
func main() {
addr := ":8080"
http.HandleFunc("/",
func(w http.ResponseWriter, req *http.Request) {
log.Println(req.URL.Query())
})
log.Println("listening on", addr)
log.Fatal(http.ListenAndServe(addr, nil))
}
+5
View File
@@ -0,0 +1,5 @@
image modifyer consists of:
input image
options
output (modifyed image)
usually Encoder
+22
View File
@@ -0,0 +1,22 @@
package mirror
import (
"image"
"image/color"
)
type Mirror struct {
image.Image
}
func (m Mirror) ColorModel() color.Model {
return m.Image.ColorModel()
}
func (m Mirror) Bounds() image.Rectangle {
return m.Image.Bounds()
}
func (m Mirror) At(x, y int) color.Color {
return m.Image.At(m.Bounds().Dx()-x, y)
}