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 <david.dun...@apple.com> 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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/list%40no-tek.com

This email sent to l...@no-tek.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to