FAQ
I eyeballed some of the source code. One tip:

func ConvertImage(img image.Image) image.Image {
   out := image.NewRGBA(img.Bounds())
   for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
     for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ {
       out.Set(x, y, ConvertColor(img.At(x, y)))
     }
   }
   return out
}

You are making a lot of interface method calls inside your inner loop.
It should be faster to say:

b := img.Bounds()
for y := b.Min.Y; y < b.Max.Y; y++ {
   // Likewise for x.
   etc
}

instead of

for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
   etc
}

Also, calling out.SetRGBA instead of out.Set will also avoid
unnecessary indirection.

But for a different approach, which should be much faster, see
https://go.googlesource.com/exp/+/master/shiny/driver/internal/swizzle/

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 2 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 7, '15 at 7:27p
activeDec 14, '15 at 10:14a
posts2
users2
websitegolang.org

2 users in discussion

Xojoc: 1 post Nigel Tao: 1 post

People

Translate

site design / logo © 2021 Grokbase