Files
imageutils/cmd/negate/negate.go
2026-03-29 17:03:48 +03:00

40 lines
751 B
Go

package main
import (
"image"
"image/color"
"git.nkpl.cc/twocookedfaggots/imageutils/util"
)
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 main() {
if err := util.ProcessStdio(func(img image.Image) image.Image {
return Negate{img}
}); err != nil {
panic(err)
}
}