Alpha Blending

 
Microsoft DirectShow 9.0

Alpha Blending

This article describes alpha blending in Microsoft® DirectShow® Editing Services (DES).

Alpha measures the transparency of a pixel or image. In 32-bit uncompressed RGB video, four components define each pixel: an alpha channel (A) and three color components (RGB). A pixel with an alpha value of zero is completely transparent. A pixel with an alpha value of 255 is opaque. Between these values, the pixel has various degrees of transparency.

DirectShow defines two media types for 32-bit RGB video:

  • MEDIASUBTYPE_ARGB32: The video is 32-bit RGB with a valid alpha channel.
  • MEDIASUBTYPE_RGB32: Pixels are 32 bits, but the alpha channel is not necessarily valid.

To perform alpha blending in DES, set the video group's uncompressed media type to MEDIASUBTYPE_ARGB32. In C++, call the IAMTimelineGroup::SetMediaType method. In the XTL format, setting the bitdepth attribute of the group element to 32 accomplishes this as well.

Next, you need video data that contains an alpha channel. There are several options:

  • You can use an AVI file that already has 32-bit RGB video with alpha data. Currently, alpha is not supported for MPEG or Microsoft® Windows Media™ Format (WMF) source files.
  • DES supports 32-bit bitmap (.bmp) and Targa (.tga) files with alpha data.
  • You can write a custom source filter that creates 32-bit RGB data with alpha. The output media type must be MEDIASUBTYPE_ARGB32. Use the filter as the subobject in a timeline source object.

If your video source does not have alpha, you can use an effect that creates alpha data. The Alpha Setter Effect sets the alpha channel for the entire image to a constant value. To vary the alpha over time, use the IPropertySetter interface with the Alpha Setter Effect. The original source does not have to be 32 bits, as long as the group's uncompressed media type is MEDIASUBTYPE_ARGB32.

Finally, pass the video to an effect or transition that performs alpha blending. The Compositor Transition performs alpha blending, and the Key Transition can key by alpha value.

The following sample XTL project performs alpha blending:

<timeline>
<group type="video" bitdepth="32" width="320" height="240">
<track>
  <clip start="0" stop="6" src="c:\Example.avi" />
</track>
<track>
  <clip start="0" stop="6" src="c:\Example2.avi">
    <!-- Alpha Setter effect. -->
    <effect clsid="{506D89AE-909A-44f7-9444-ABD575896E35}" start="0" stop="6">
      <param name="alpha" value="255">
        <linear time="6" value="0" />
      </param>
    </effect>
  </clip>
  <!-- Key transition, with alpha keying. -->
  <transition clsid="{C5B19592-145E-11d3-9F04-006008039E37}" start="0" stop="6">
    <param name="KeyType" value="3" />  
  </transition>
</track>
</group>
</timeline>