Re: OR compositing operation?
This simplifies things a lot. Just do an animated mix (crossfade) of the 2 text layers, including the alpha channels, then simply composite the result over your background. I'm not sure exactly which blend mode you'd use, but it will be a simple alpha composite/blend/mix. paulm On 28/09/2009, at 3:02 AM, Oleg Krupnov wrote: With a second thought, I think it would do perfectly with simply averaging ALL channels, R, G, B, and A, for this cross-fade effect. So I am reformulating my questions as follows: How do I produce the blending mode when the foreground and background colors are averaged channel-wise, for all channels, including the alpha channel? Thanks On Sun, Sep 27, 2009 at 4:25 PM, Oleg Krupnov wrote: 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 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 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
Re: OR compositing operation?
With a second thought, I think it would do perfectly with simply averaging ALL channels, R, G, B, and A, for this cross-fade effect. So I am reformulating my questions as follows: How do I produce the blending mode when the foreground and background colors are averaged channel-wise, for all channels, including the alpha channel? Thanks On Sun, Sep 27, 2009 at 4:25 PM, Oleg Krupnov wrote: > 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 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 >>> 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
Re: OR compositing operation?
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 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 >> 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
Re: OR compositing operation?
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 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
Re: OR compositing operation?
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 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/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: OR compositing operation?
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/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: OR compositing operation?
Thanks for quick reply. > Rr = (Sr > Dr) ? Sr : Dr > Rg = (Sg > Dg) ? Sg : Dg > Rb = (Sb > Db) ? Sb : Db Yes, that's what I want. After giving it another thought, I see that it's not equivalent to bitwise OR, say MAX (1,2) = 2, wheres OR (1,2) = 3. Anyway, I would like to know if it's possible to use the MAX compositing operation (this time I need MAX, but maybe I will also need other, such as MIN, OR, AND, NOT, whatever). I have checked all values of NSCompositingOperation, but haven't found what I need. They all seem to be dealing with transparency mostly, not with color values. Any ideas? Here's where I found this problem. I'm implementing a cross-fade animation of text. One string fades out, and another string fades in at the same time. The problem is that in areas where the text glyphs from the two strings overlap, the sum of colors results in brighter pixels than each of the strings taken separately. This results in an annoying flash of brighter color in the middle of the animation. I'd like to fix it by limiting the brightness of all pixels by the value of the text color. ___ 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
Re: OR compositing operation?
Thanks for quick reply. > Rr = (Sr > Dr) ? Sr : Dr > Rg = (Sg > Dg) ? Sg : Dg > Rb = (Sb > Db) ? Sb : Db Yes, that's what I want. After giving it another thought, I see that it's not equivalent to bitwise OR, say MAX (1,2) = 2, wheres OR (1,2) = 3. Anyway, I would like to know if it's possible to use the MAX compositing operation (this time I need MAX, but maybe I will also need other, such as MIN, OR, AND, NOT, whatever). I have checked all values of NSCompositingOperation, but haven't found what I need. They all seem to be dealing with transparency mostly, not with color values. Any ideas? Here's where I found this problem. I'm implementing a cross-fade animation of text. One string fades out, and another string fades in at the same time. The problem is that in areas where the text glyphs from the two strings overlap, the sum of colors results in brighter pixels than each of the strings taken separately. This results in an annoying flash of brighter color in the middle of the animation. I'd like to fix it by limiting the brightness of all pixels by the value of the text color. On Tue, Sep 22, 2009 at 4:58 PM, Colin Howarth wrote: > On 22 Sep, 2009, at 15:22, 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. >> >> Is this possible? I don't see such NSCompositingOperation. There's >> only NSCompositeXOR, but no NSCompositeOR... > > > I'm not quite sure what you mean by "maximum color (channel-wise)". > Do you mean > > Rr = (Sr > Dr) ? Sr : Dr > Rg = (Sg > Dg) ? Sg : Dg > Rb = (Sb > Db) ? Sb : Db > > > > A quick google threw up http://my.safaribooksonline.com/0672322307/ch14 > for the compositing operations. The logic operation XOR appears to be binary > (opaque/transparent). It might be that what you want is simply called > something > else (like NSCompositeSourceOver). > > > > A long time ago I remember XORing pixels D' = (S XOR D) changed the colour > and (S XOR D') > changed it back again. But that was bitwise XOR, ie. > > Rr0 = Sr0 XOR Dr0 > Rr1 = Sr1 XOR Dr1 > ... > etc. > > > > And finally, mathematically, A OR B = (A XOR B) XOR (A AND B) > > > > > I wonder if any of that helps? :-) > > ___ 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
OR compositing operation?
On 22 Sep, 2009, at 15:22, 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. Is this possible? I don't see such NSCompositingOperation. There's only NSCompositeXOR, but no NSCompositeOR... I'm not quite sure what you mean by "maximum color (channel-wise)". Do you mean Rr = (Sr > Dr) ? Sr : Dr Rg = (Sg > Dg) ? Sg : Dg Rb = (Sb > Db) ? Sb : Db A quick google threw up http://my.safaribooksonline.com/0672322307/ch14 for the compositing operations. The logic operation XOR appears to be binary (opaque/transparent). It might be that what you want is simply called something else (like NSCompositeSourceOver). A long time ago I remember XORing pixels D' = (S XOR D) changed the colour and (S XOR D') changed it back again. But that was bitwise XOR, ie. Rr0 = Sr0 XOR Dr0 Rr1 = Sr1 XOR Dr1 ... etc. And finally, mathematically, A OR B = (A XOR B) XOR (A AND B) I wonder if any of that helps? :-) ___ 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
OR compositing operation?
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. Is this possible? I don't see such NSCompositingOperation. There's only NSCompositeXOR, but no NSCompositeOR... Thanks! ___ 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