Paul, thanks for such an exhaustive answer!
Here are answers to your questions:
1. My case is the simple one -- I'm rendering all text layers at once.
2. Yes and no. As I said, I am implementing the cross-fade effect,
when one text fades out and another text fades in. The texts can be of
the same color (simplest case) or of different color (different shades
of gray), and their alphas change during the fading animation. The
problem is that the semi-transparent areas of text, when overlapping,
produce brighter pixels, the annoying "flash" effect, I'm trying to
get rid of.
My further research shows that kCGBlendModeLighten does not seem to
apply to the alpha channel. Namely, colors are indeed composited using
the lighten rule, but then the resulting color is alpha blended with
the background as usual, so that two overlapping semitransparent
pixels still produce a more opaque pixel, which is undesirable
Am I missing the clue how to make kCGBlendModeLighten apply to the
alpha channel as well?
I have come to the following workaround: I fill the text layers with
opaque black background. In this case the kCGBlendModeLighten works
perfectly, as expected.
Unfortunately, I am not fully satisfied with this solution, because I
need the background of the text layers to be half-transparent as well.
This returns me to the question of how to make kCGBlendModeLighten to
the alpha channel.
You said I could "average the color components but max the alphas."
How can I do this? Thanks!
On Sun, Sep 27, 2009 at 3:45 AM, Paul M <email@hidden> wrote:
This is a multi-pass operation - you wont find a single
blend mode that will do this in any simple manner.
First question: Are you doing this all in one hit, or sequentially,
ie, rendering the first layer of text then adding subsequent
layers later?
Second question: is the text all the same colour and have the
same alpha component?
If you're rendering all the text layers at once, you need to first
combine the text layers, then composite over the background. In the
simple case you describe, I imagine you'll need to average the colour
components but max the alphas. This should give you the results you
asked for.
If you need to comosite different layers at different times, it
becomes a lot more complex.
If your text is not all the same colour then you need access to all
the previous layers so that they may be combined as above and the
composite redone.
If your text is all the same colour then you can write the alpha from
the first layer into the composite so that this may be extracted and
used later in the 2nd and subsequent composites. The process for
these later composites gets pretty gnarley, and you're really better
of keeping a reference to the preceeding layers if that's at all
possible.
paulm
On 27/09/2009, at 12:17 AM, Oleg Krupnov wrote:
Thanks!
It seemed exactly what I need but I've found that it doesn't work as
expected. The interpolated semi-transparent parts of the rendered
text
still appears brighter than it should.
Namely, consider drawing white text on black background, and then
drawing the same white text one more time over the first one.
Suppose that when a letter is rasterized, one of the resulting
interpolated pixels is semitransparent white, with alpha = 50%.
After
alpha blending with the black background, the pixel becomes a 50%
gray
pixel.
Now when the second text is drawn on top, there will be also the
same
semitransparent white pixel with alpha = 50% at the same location.
What result I'd like to achieve would be to have the same 50% gray
pixel at this location. However, with kCGBlendModeLighten mode,
what I
think what's happening is that the system picks pure white as the
lighter of two colors: 50% gray of the background and pure white
(without taking into account the alpha of the new pixel), and then
applies the usual alpha blending rule, which results in 75% gray.
Is there a workaround? Or am I doing something wrong? Thanks!
On Tue, Sep 22, 2009 at 7:23 PM, David Duncan
<email@hidden>
wrote:
On Sep 22, 2009, at 6:22 AM, Oleg Krupnov wrote:
Hi,
I'd like to draw in a graphics context in such a compositing mode:
R = MAX(S, D)
i.e. out of two colors (source and destination), the maximum color
(channel-wise) was chosen. This is basically equivalent to ORing
the
colors.
This is the Lighten blend mode (kCGBlendModeLighten). There doesn't
appear
to be a corresponding NS composting mode, and I'm not sure why,
but you
can
easily get a CGContext from an NSGraphicsContext by asking it for
its
graphicsPort, so this shouldn't be hard to integrate.
--
David Duncan
Apple DTS Animation and Printing
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden