Re: Transparent Merging (Antialias problems)

From: Rob Kennedy (me3_at_privacy.net)
Date: 12/02/04


Date: Thu, 02 Dec 2004 10:09:01 -0600

Osmosis wrote:
> Are there any kind of algorythms to get the alpha values of the foreground
> picture ?

Probably. For each pixel, look at the alpha value and store it in some
other data structure. That data structure might be in the form of a
grayscale bitmap.

> I 'm currently thinking that it wouldn't really matter whether the
> background color is green or white or black or any other color as long as
> you set the transparentcolor to that color.

When dealing with alpha values, there isn't really such a thing as "the"
transparent color. Transparency is determined entirely by the alpha values.

> But I'm having trouble with
> determining the alpha values, because in each case these alpha values should
> be the same, isn't it ?

Not if your text is antialiased.

When you draw antialiased text, the pixels around the edges will not
have the same 32-bit color values as the pixels on the interior. With
standard antialiasing, the 24-bit text color is blended with the 24-bit
background color; the alpha value is assumed to be a constant 100%
opaque. If you then try to remove pixels based on the background color,
you'll get a fuzzy edge around the text because those pixels aren't the
same as the background color. They're a combination of the background
color and the text color.

What you need to do instead is to start with a fully transparent (alpha
= 0) foreground image, and when you draw your text, do the antialiasing
in terms of the alpha value; the 24-bit color value will be the same
throughout the text, and only the alpha values will vary.

Now, when you blend the foreground bitmap with the background bitmap,
blend the full 32-bit color values. The parts of the foreground that are
fully transparent will not get blended at all because of their 0 alpha
values. The parts of the foreground image with intermediate alpha values
will blend with the background image proportionally to their alpha
values, so the new pixels will be partially the text color and partially
the background pixels' colors.

I suggest you try using Graphics32, a Delphi graphics library. It
supports antialiased text and alpha transparency natively.
http://www.g32.org/

-- 
Rob


Relevant Pages

  • Re: Wierd problem when alpha blitting image with text in it
    ... When the shadow is faded out, ... constant alpha is applied to the whole window. ... windows can have per-pixel but cannot have any child windows. ... So this leaves me with the image pixels being however opaque they ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Alpha Channel from mask
    ... I am not familiar with the Flash API. ... Use CreateDIBSection with a BITMAPV5HEADER as you can specify an alpha ... For all other pixels set the alpha channel to 255. ... When Flash draws itself into my buffer, it takes the pixels in my buffer ...
    (microsoft.public.win32.programmer.gdi)
  • Re: How to deal with fully transparent ARGB pixels?
    ... GDI+ solves this by using pre-multiplied alpha images. ... resulting in final partialy red pixels. ...
    (microsoft.public.dotnet.framework.drawing)
  • RE: How to do this with fixed pipeline
    ... Try using alpha testing: set the alpha of bright pink pixels to zero, ... set up the fixed pipeline to get the texure alpha. ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Question of Transparent Textures..
    ... Set the pixels' alpha to 0 and enable alpha blending and the relevant TSS ... setup (for FFP pixel pipeline). ...
    (microsoft.public.win32.programmer.directx.graphics)