Hello,

I'd like to rotate, scale, ... images by moving pixels using affine 
transformations. For example, the get a points x, y position after a 
translating it by m, n pixels, you can just add m resp n to x and y:

x' = x + m
y' = y + n


So the task is basically just to iterate over the images pixels. This was 
done by directly accessing the Pix-slice 
<https://golang.org/pkg/image/#Paletted>, but not every every in-memory 
image has this field.

The current solution uses reflection and is extracting the Set 
function (and, as a nice side effect, a new image with the same type and 
resolution as the input image):

func getSet(im image.Image) (func(int, int, color.Color), image.Image, error
) {
 set := func(x, y int, c color.Color) {}
 switch tmp := im.(type) {
 case *image.Alpha:
 im = image.NewAlpha(tmp.Rect)
 set = im.(*image.Alpha).Set
 ...
 default:
 return nil, nil, fmt.Errorf("%T has no function Set", im)
 }
 return set, im, nil
}

My favourited approach would be to use an interface which adds Set it to 
image.Image. This works, but I obviously can't just throw an image.Image in.

type ImageSetter interface {
 image.Image
 Set(int, int, color.Color)
}

What would be a go-like solution for this task?

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to