Microsoft DirectX 8.0

Alpha Blending

This article describes how to perform 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:

To use alpha blending in DES, first set the 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. For more information, see XML Reference.

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

If your video source does not have alpha, you can use an effect that creates alpha data. The Alpha Setter effect can set the alpha channel for the entire image to a constant value. To vary the alpha over time, use the IPropertySetter interface. The original source does not have to be 32 bits, as long as the group's uncompressed media type is MEDIASUBTYPE_ARGB32. You can also create your own custom Microsoft® DirectX® Transform effect that creates alpha data.

Note  If your video source already contains alpha data, you can use the Alpha Setter effect to change the alpha value of each pixel by a specified percentage. For more information, see Alpha Setter.

Finally, pass the video to an effect or transition that performs alpha blending. The Compositor and SMPTE Wipe transitions both perform alpha blending. The Key transition can key by alpha value. Some third-party DirectX Transform objects also support alpha blending.

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>