From a9900d7b430614e86e8c5f7442187d94b7bb037f Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Fri, 1 Jan 2021 06:29:14 +0100 Subject: [PATCH] new rgbsplit --- pixelflut/flut.go | 18 +++++++++--------- render/image.go | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/pixelflut/flut.go b/pixelflut/flut.go index 1d470b3..a7c31e5 100644 --- a/pixelflut/flut.go +++ b/pixelflut/flut.go @@ -3,7 +3,6 @@ package pixelflut import ( "fmt" "image" - "image/color" "sync" "time" @@ -115,14 +114,15 @@ func Flut(t FlutTask, stop chan bool, wg *sync.WaitGroup) { func generateCommands(t FlutTask) (cmds commands) { if t.RGBSplit { - white := color.NRGBA{0xff, 0xff, 0xff, 0xff} - imgmod := render.ImgColorFilter(t.Img, white, color.NRGBA{0xff, 0, 0, 0xff}) - cmds = append(cmds, commandsFromImage(imgmod, t.RenderOrder, t.Offset.Add(image.Pt(-10, -10)))...) - imgmod = render.ImgColorFilter(t.Img, white, color.NRGBA{0, 0xff, 0, 0xff}) - cmds = append(cmds, commandsFromImage(imgmod, t.RenderOrder, t.Offset.Add(image.Pt(10, 0)))...) - imgmod = render.ImgColorFilter(t.Img, white, color.NRGBA{0, 0, 0xff, 0xff}) - cmds = append(cmds, commandsFromImage(imgmod, t.RenderOrder, t.Offset.Add(image.Pt(-10, 10)))...) + r, g, b := render.ImgRGBSplit(t.Img, 10) + cmds = append(cmds, commandsFromImage(r, t.RenderOrder, t.Offset)...) + cmds = append(cmds, commandsFromImage(g, t.RenderOrder, t.Offset)...) + cmds = append(cmds, commandsFromImage(b, t.RenderOrder, t.Offset)...) + if t.RenderOrder == Shuffle { + cmds.Shuffle() + } + } else { + cmds = append(cmds, commandsFromImage(t.Img, t.RenderOrder, t.Offset)...) } - cmds = append(cmds, commandsFromImage(t.Img, t.RenderOrder, t.Offset)...) return } diff --git a/render/image.go b/render/image.go index 1e9605a..b065c98 100644 --- a/render/image.go +++ b/render/image.go @@ -63,6 +63,25 @@ func ImgColorFilter(img *image.NRGBA, from, to color.NRGBA) *image.NRGBA { 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) { b := img.Bounds() scaledBounds := image.Rect(0, 0, b.Max.X*factor, b.Max.Y*factor)