cmd
This commit is contained in:
44
cmd/negate/negate.go
Normal file
44
cmd/negate/negate.go
Normal file
@@ -0,0 +1,44 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user