add more tests

add network capability to example app
This commit is contained in:
Simon Waldherr
2018-11-06 17:09:56 +01:00
parent ab40a41cfa
commit 798fa421de
13 changed files with 167 additions and 60 deletions

49
cmd/zplgfa/image.go Normal file
View File

@@ -0,0 +1,49 @@
package main
import (
"image"
"image/color"
"math"
)
type imageSet interface {
Set(x, y int, c color.Color)
}
func editImageInvert(img image.Image) image.Image {
b := img.Bounds()
imgSet := img.(imageSet)
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
oldPixel := img.At(x, y)
r, g, b, a := oldPixel.RGBA()
r = 65535 - r
g = 65535 - g
b = 65535 - b
pixel := color.RGBA{uint8(r), uint8(g), uint8(b), uint8(a)}
imgSet.Set(x, y, pixel)
}
}
return img
}
func editImageMonochrome(img image.Image) image.Image {
b := img.Bounds()
imgSet := img.(imageSet)
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
oldPixel := img.At(x, y)
r, g, b, a := oldPixel.RGBA()
if r > math.MaxUint16/2 || g > math.MaxUint16/2 || b > math.MaxUint16/2 {
r, g, b = 65535, 65535, 65535
} else {
r, g, b = 0, 0, 0
}
pixel := color.RGBA{uint8(r), uint8(g), uint8(b), uint8(a)}
imgSet.Set(x, y, pixel)
}
}
return img
}