You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Bill van Melle <bi...@gmail.com> on 2011/03/24 22:54:52 UTC

Want GrayscaleDecorator to respect transparency

I have an app in which I sometimes want to grey out images that are not the
current images "of interest".  So I'm using a GrayscaleDecorator, which
works fine for solid images.  But if the images have transparent parts, I
want the decorator to leave them unaffected, so that the background shows
through, rather than turning those pixels black.  Is there any way to do
that?  Is this a bug in the decorator?

Example -- fill in your favorite test image that uses transparency:

<Window
  xmlns:effects="org.apache.pivot.wtk.effects"
  xmlns="org.apache.pivot.wtk">
  <BoxPane styles="{backgroundColor:'white'}">
    <ImageView image="@test.png" styles="{backgroundColor:null}" />
    <ImageView image="@test.png" styles="{backgroundColor:null}">
      <decorators>
        <effects:GrayscaleDecorator />
      </decorators>
    </ImageView>
  </BoxPane>
</Window>

In this particular example, I could have set the background of the ImageView
to be white instead of null and it would look fine, but in general the
background won't be white, and I don't want the decorator to modify those
background pixels.

Re: Want GrayscaleDecorator to respect transparency

Posted by Bill van Melle <bi...@gmail.com>.
>
> I'm wondering if there is (or could be) some kind of repository for user
>> contributions of little decorators, transitions, and other components that
>> others could draw on.  It would be particularly useful for decorators, which
>> require some non-trivial graphics expertise.
>>
> Likewise for user provided Containers, Components and Skins and probably
> others things.
> Perhaps Sandro's recent post might be a starting point
>
> http://apache-pivot-users.399431.n3.nabble.com/Pivot-related-sites-on-Apache-Extras-td2712415.html
>

Looks interesting.  I don't see anything there at the moment (he talked of
migrating stuff from another site, but all the projects look empty to me?),
and it's unclear how easy it will be for random users to add stuff, but I'll
stay tuned.

Could you also attach an example image that can be used to compare the
> results from using the original decorator and one that includes the proposed
> change?  (Be sure to grant permissions for its use).  It can also be used to
> see if other decorators produce unexpected results with images that contain
> transparency.
>

Okay.

Re: Want GrayscaleDecorator to respect transparency

Posted by Chris Bartlett <cb...@gmail.com>.
On 26 March 2011 04:26, Bill van Melle <bi...@gmail.com> wrote:

> In an alternate reality, Pivot could end up being a 20mb download with 90%
>> of that being Decorator implementations.
>>
>
> Well, sure.  My only point was that if Pivot does supply an implementation,
> it might as well supply one that works in more cases.
>
Point taken, and I agree that an improved GrayscaleDecorator that respects
transparency, and therefore probably fulfills more use cases, is preferable
to one that turns previously transparent pixels black.  My issue was with
the wording of 'bug' or 'inadequacy'.


> I'm wondering if there is (or could be) some kind of repository for user
> contributions of little decorators, transitions, and other components that
> others could draw on.  It would be particularly useful for decorators, which
> require some non-trivial graphics expertise.
>
Likewise for user provided Containers, Components and Skins and probably
others things.
Perhaps Sandro's recent post might be a starting point
http://apache-pivot-users.399431.n3.nabble.com/Pivot-related-sites-on-Apache-Extras-td2712415.html


 The same 'issue' might apply to other decorators.
>>
> That had occurred to me, but without trying them out, I'd never know, and
> at the moment I only have use for the GrayscaleDecorator :-).
>
> Anyway, I submitted my mod to GrayscaleDecorator as
> https://issues.apache.org/jira/browse/PIVOT-723
>
Thanks for the submission.

Could you also attach an example image that can be used to compare the
results from using the original decorator and one that includes the proposed
change?  (Be sure to grant permissions for its use).  It can also be used to
see if other decorators produce unexpected results with images that contain
transparency.

Or if that is not possible, provide instructions on how to replicate the
'issue' that the improvement will address.

Chris

Re: Want GrayscaleDecorator to respect transparency

Posted by Bill van Melle <bi...@gmail.com>.
>
> In an alternate reality, Pivot could end up being a 20mb download with 90%
> of that being Decorator implementations.
>

Well, sure.  My only point was that if Pivot does supply an implementation,
it might as well supply one that works in more cases.

I would argue that Pivot *need not* provide any, but does provide a single
> version which can be used as a starting point or reference for those who
> wish to create their own implementations (of a grayscale decorator, or any
> decorator for that matter).
>

I'm wondering if there is (or could be) some kind of repository for user
contributions of little decorators, transitions, and other components that
others could draw on.  It would be particularly useful for decorators, which
require some non-trivial graphics expertise.

The same 'issue' might apply to other decorators.
>

That had occurred to me, but without trying them out, I'd never know, and at
the moment I only have use for the GrayscaleDecorator :-).

Back in WPF-land I remember struggling a lot to make a pixel shader work
properly with transparency, until I learned the little undocumented tidbit
that WPF uses "premultiplied alpha".  I may at some point try to figure out
how to do that one in Pivot.  (It was kind of the opposite
of GrayscaleDecorator -- it took as input a grey scale image and a color,
and output an image where each pixel was the given color at a brightness
that matched the input.  If someone's already written such a thing, I'd love
to see it.)

Anyway, I submitted my mod to GrayscaleDecorator as
https://issues.apache.org/jira/browse/PIVOT-723

Re: Want GrayscaleDecorator to respect transparency

Posted by Chris Bartlett <cb...@gmail.com>.
On 25 March 2011 07:04, Bill van Melle <bi...@gmail.com> wrote:

> Pivot comes with a number of Decorator implementations.  If there isn't one
>> that does exactly you need, I wouldn't describe that as a bug.
>>
>
> Well, if not a bug, at least an inadequacy.
>
IMVHO that is also a little strong.  In an alternate reality, Pivot could
end up being a 20mb download with 90% of that being Decorator
implementations.  Obviously that is not going to happen, but hopefully you
understand the point I am trying to make.

Pivot provides the interface, but cannot possibly provide every
implementation that users might want, even if they could be foreseen.  FWIW
the same applies to renderers too.

You are free to write your own implementations to meet your needs
>>
> As always.  Would be more comfortable advice if I were a graphics expert...
>
Understood.  I am also not a graphics expert and have very limited
experience with Graphics2D, but in the past a quick 'google' has provided
all I needed.  Once you realise how Pivot uses them, it then moves into a
non-Pivot area of expertise where solutions can be researched & tested
independently.


> For example, a quick search found this post demonstrating 3 different
>> grayscale conversion techniques and some comments discussing transparency.
>>
>> http://blog.codebeach.com/2008/03/convert-color-image-to-gray-scale-image.html
>>
>
> ...but fortunately, others are!  Excellent to-the-point article.  I took
> the code helpfully supplied in the comment about the transparency
> shortcoming, dropped it into the current GrayscaleDecorator implementation,
> and it works beautifully right out of the box.  Thanks!
>
That post hopefully demonstrates the point I was trying to make earlier.
 Here are 3 alternative grayscale conversion techniques which give 3 very
different results from the same source.  Combine that with the fact that at
least one didn't respect transparency - which one *should* Pivot provide?
 Would there be a clear consensus?

I would argue that Pivot *need not* provide any, but does provide a single
version which can be used as a starting point or reference for those who
wish to create their own implementations (of a grayscale decorator, or any
decorator for that matter).


> I'll submit it as a proposed improvement, and y'all can decide whether it's
> a bug fix or not.  I think it is, since the current implementation, I claim,
> is not what anyone would properly expect it to do.
>
I won't argue regarding what anyone else might expect.  Don't get me wrong,
I'm not against including this, and submissions are always welcomed, so go
for it!

You might also consider posting the modified code to this mailing list in
case anyone following the thread might find it useful.  The same 'issue'
might apply to other decorators.

Chris

Re: Want GrayscaleDecorator to respect transparency

Posted by Bill van Melle <bi...@gmail.com>.
>
> Pivot comes with a number of Decorator implementations.  If there isn't one
> that does exactly you need, I wouldn't describe that as a bug.
>

Well, if not a bug, at least an inadequacy.

You are free to write your own implementations to meet your needs
>

As always.  Would be more comfortable advice if I were a graphics expert...

For example, a quick search found this post demonstrating 3 different
> grayscale conversion techniques and some comments discussing transparency.
>
> http://blog.codebeach.com/2008/03/convert-color-image-to-gray-scale-image.html
>

...but fortunately, others are!  Excellent to-the-point article.  I took the
code helpfully supplied in the comment about the transparency shortcoming,
dropped it into the current GrayscaleDecorator implementation, and it works
beautifully right out of the box.  Thanks!

I'll submit it as a proposed improvement, and y'all can decide whether it's
a bug fix or not.  I think it is, since the current implementation, I claim,
is not what anyone would properly expect it to do.

Re: Want GrayscaleDecorator to respect transparency

Posted by Chris Bartlett <cb...@gmail.com>.
On 25 March 2011 04:54, Bill van Melle <bi...@gmail.com> wrote:

> I have an app in which I sometimes want to grey out images that are not the
> current images "of interest".  So I'm using a GrayscaleDecorator, which
> works fine for solid images.  But if the images have transparent parts, I
> want the decorator to leave them unaffected, so that the background shows
> through, rather than turning those pixels black.  Is there any way to do
> that?  Is this a bug in the decorator?


Pivot comes with a number of Decorator implementations.  If there isn't one
that does exactly you need, I wouldn't describe that as a bug.

http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/effects/Decorator.html

You are free to write your own implementations to meet your needs, so I
would recommend familiarizing yourself with the source of the various
provided Decorators, and then searching the net to find examples of how to
perform the one or more transformations/operations you might need.

For example, a quick search found this post demonstrating 3 different
grayscale conversion techniques and some comments discussing transparency.
http://blog.codebeach.com/2008/03/convert-color-image-to-gray-scale-image.html

Chris