new rgbsplit
This commit is contained in:
parent
3ac85ca3f0
commit
a9900d7b43
|
@ -3,7 +3,6 @@ package pixelflut
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -115,14 +114,15 @@ func Flut(t FlutTask, stop chan bool, wg *sync.WaitGroup) {
|
||||||
|
|
||||||
func generateCommands(t FlutTask) (cmds commands) {
|
func generateCommands(t FlutTask) (cmds commands) {
|
||||||
if t.RGBSplit {
|
if t.RGBSplit {
|
||||||
white := color.NRGBA{0xff, 0xff, 0xff, 0xff}
|
r, g, b := render.ImgRGBSplit(t.Img, 10)
|
||||||
imgmod := render.ImgColorFilter(t.Img, white, color.NRGBA{0xff, 0, 0, 0xff})
|
cmds = append(cmds, commandsFromImage(r, t.RenderOrder, t.Offset)...)
|
||||||
cmds = append(cmds, commandsFromImage(imgmod, t.RenderOrder, t.Offset.Add(image.Pt(-10, -10)))...)
|
cmds = append(cmds, commandsFromImage(g, t.RenderOrder, t.Offset)...)
|
||||||
imgmod = render.ImgColorFilter(t.Img, white, color.NRGBA{0, 0xff, 0, 0xff})
|
cmds = append(cmds, commandsFromImage(b, t.RenderOrder, t.Offset)...)
|
||||||
cmds = append(cmds, commandsFromImage(imgmod, t.RenderOrder, t.Offset.Add(image.Pt(10, 0)))...)
|
if t.RenderOrder == Shuffle {
|
||||||
imgmod = render.ImgColorFilter(t.Img, white, color.NRGBA{0, 0, 0xff, 0xff})
|
cmds.Shuffle()
|
||||||
cmds = append(cmds, commandsFromImage(imgmod, t.RenderOrder, t.Offset.Add(image.Pt(-10, 10)))...)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
cmds = append(cmds, commandsFromImage(t.Img, t.RenderOrder, t.Offset)...)
|
cmds = append(cmds, commandsFromImage(t.Img, t.RenderOrder, t.Offset)...)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,25 @@ func ImgColorFilter(img *image.NRGBA, from, to color.NRGBA) *image.NRGBA {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ImgRGBSplit returns three images containing the RGB components, optionally shifted by some offset
|
||||||
|
func ImgRGBSplit(img *image.NRGBA, shift int) (*image.NRGBA, *image.NRGBA, *image.NRGBA) {
|
||||||
|
bounds := img.Bounds().Inset(-shift)
|
||||||
|
r := image.NewNRGBA(bounds)
|
||||||
|
g := image.NewNRGBA(bounds)
|
||||||
|
b := image.NewNRGBA(bounds)
|
||||||
|
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
||||||
|
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
||||||
|
c := img.At(x, y).(color.NRGBA)
|
||||||
|
if c.A != 0 {
|
||||||
|
r.Set(x-shift, y-shift, color.NRGBA{R: c.R, A: c.A / 3})
|
||||||
|
g.Set(x+shift, y, color.NRGBA{G: c.G, A: c.A / 3})
|
||||||
|
b.Set(x-shift, y+shift, color.NRGBA{B: c.B, A: c.A / 3})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r, g, b
|
||||||
|
}
|
||||||
|
|
||||||
func ScaleImage(img image.Image, factor int) (scaled *image.NRGBA) {
|
func ScaleImage(img image.Image, factor int) (scaled *image.NRGBA) {
|
||||||
b := img.Bounds()
|
b := img.Bounds()
|
||||||
scaledBounds := image.Rect(0, 0, b.Max.X*factor, b.Max.Y*factor)
|
scaledBounds := image.Rect(0, 0, b.Max.X*factor, b.Max.Y*factor)
|
||||||
|
|
Loading…
Reference in New Issue