cleaning up, early http server draft
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 MiB |
Binary file not shown.
@@ -1,39 +0,0 @@
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Reshade struct{ image.Image }
|
||||
|
||||
func (rs Reshade) ColorModel() color.Model { return rs.Image.ColorModel() }
|
||||
func (rs Reshade) Bounds() image.Rectangle { return rs.Image.Bounds() }
|
||||
func (rs Reshade) At(x, y int) color.Color {
|
||||
c := rs.Image.At(x, y)
|
||||
r, g, b, a := c.RGBA()
|
||||
// minus 19 blue
|
||||
return color.RGBA{
|
||||
uint8(r >> 8),
|
||||
uint8(g >> 8),
|
||||
uint8(b>>8) - 8*8,
|
||||
uint8(a >> 8),
|
||||
}
|
||||
}
|
||||
|
||||
func check(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
img, err := png.Decode(os.Stdin)
|
||||
check(err)
|
||||
err = png.Encode(os.Stdout, Reshade{img})
|
||||
check(err)
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"math/rand"
|
||||
"os"
|
||||
)
|
||||
|
||||
type MixedNegation struct {
|
||||
src image.Image
|
||||
counter int
|
||||
}
|
||||
|
||||
func toRGBA(c color.Color) color.RGBA {
|
||||
r, g, b, a := c.RGBA()
|
||||
return color.RGBA{
|
||||
R: uint8(r >> 8),
|
||||
G: uint8(g >> 8),
|
||||
B: uint8(b >> 8),
|
||||
A: uint8(a >> 8),
|
||||
}
|
||||
}
|
||||
|
||||
func negateRGBA(c color.RGBA) color.RGBA {
|
||||
c.R = 255 - c.R
|
||||
c.G = 255 - c.G
|
||||
c.B = 255 - c.B
|
||||
return c
|
||||
}
|
||||
|
||||
func Negate(c color.Color) color.Color {
|
||||
return negateRGBA(toRGBA(c))
|
||||
}
|
||||
|
||||
func randomBool() bool {
|
||||
return rand.Intn(3) == 0
|
||||
}
|
||||
|
||||
func (mn MixedNegation) ColorModel() color.Model { return mn.src.ColorModel() }
|
||||
func (mn MixedNegation) Bounds() image.Rectangle { return mn.src.Bounds() }
|
||||
func (mn *MixedNegation) At(x, y int) color.Color {
|
||||
if (x%1 != 0) && (y%8 != 0) {
|
||||
if randomBool() {
|
||||
return Negate(mn.src.At(x, y))
|
||||
}
|
||||
|
||||
}
|
||||
return mn.src.At(x, y)
|
||||
}
|
||||
|
||||
func pixelCount(img image.Image) int {
|
||||
return img.Bounds().Dx() * img.Bounds().Dy()
|
||||
}
|
||||
|
||||
func main() {
|
||||
img, err := png.Decode(os.Stdin)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
n := pixelCount(img)
|
||||
println(n)
|
||||
|
||||
err = png.Encode(os.Stdout, &MixedNegation{src: img, counter: n})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,44 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"os"
|
||||
)
|
||||
|
||||
func NegateRGBA(c color.RGBA) color.RGBA {
|
||||
c.R = 255 - c.R
|
||||
c.G = 255 - c.G
|
||||
c.B = 255 - c.B
|
||||
return c
|
||||
}
|
||||
|
||||
type Negate struct{ image.Image }
|
||||
|
||||
func (n Negate) ColorModel() color.Model { return n.Image.ColorModel() }
|
||||
func (n Negate) Bounds() image.Rectangle { return n.Image.Bounds() }
|
||||
func (n Negate) At(x, y int) color.Color {
|
||||
c := n.Image.At(x, y)
|
||||
r, g, b, a := c.RGBA()
|
||||
RGBAColor := color.RGBA{
|
||||
R: uint8(r >> 8),
|
||||
G: uint8(g >> 8),
|
||||
B: uint8(b >> 8),
|
||||
A: uint8(a >> 8),
|
||||
}
|
||||
return NegateRGBA(RGBAColor)
|
||||
}
|
||||
|
||||
func check(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
img, err := png.Decode(os.Stdin)
|
||||
check(err)
|
||||
err = png.Encode(os.Stdout, Negate{img})
|
||||
check(err)
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 977 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 MiB |
Reference in New Issue
Block a user