/
image.go
49 lines (43 loc) · 1017 Bytes
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
}