On Tue, Apr 28, 2015 at 11:21 AM, simon place wrote:
At(..) returns a color, and all colors have an interface{} with only an
RGBA method, so all code receiving colors can only 'see' RGBA anyway,
converting gray, say, to RGBA before returning from At(..) is redundant,
code that is receiving it wouldn't be able to tell the difference,
You can tell the difference, by a type assertion (see below).

to be really pedantic, are you allowed to modify what colorModel returns,
during a call to At(..) that then starts returning the type that At(..) next
returns!!! could be as far as i can tell.
You could write code to do that, and technically, you'd implement the
image.Image interface, but you'd be violating the spirit of the law,
if not the letter. ColorModel is meant to be an image-wide property,
not a per-pixel property. The Image.ColorModel method does not take x
and y as arguments.

The intent is when encoding an image, such as to PNG or JPEG format,
the compressed format can be much smaller when we're encoding a
one-channel image (grayscale) instead of a three-channel image (RGB or
YCbCr). The Image.ColorModel method lets the encoder know whether the
smaller format is applicable.

If your image is mostly gray but has splashes of non-gray colors, then
it isn't a grayscale image -- it cannot be faithfully saved as a
grayscale PNG or a grayscale JPEG image, and you can't edit it in
Photoshop or The GIMP in grayscale mode. Thus, in Go, the intent is
that such an image.Image's ColorModel method returns something that
isn't color.GrayModel. I suggested color.RGBAModel as something that
can represent all the colors of that image.

I then said that At should return color.RGBA even though they are
conceptually gray colors, so you could write something like:

var m image.Image = etc
if m.ColorModel() == color.RGBAModel {
   for y := etc {
     for x := etc {
       c := m.At(x, y)
       // The next line should never panic because we've already
       // checked that m.ColorModel() == color.RGBAModel.
       rgba := c.(color.RGBA)

http://golang.org/pkg/image/#Image says that "Image is a finite
rectangular grid of color.Color values taken from a color model",
which means that calling that color model's Convert method should be a

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


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 12 | next ›
Discussion Overview
groupgolang-nuts @
postedApr 25, '15 at 8:20p
activeMay 8, '15 at 11:52p

2 users in discussion

Simon place: 7 posts Nigel Tao: 5 posts



site design / logo © 2021 Grokbase