Transform Filters


This article details sample transform filters (sometimes called effects). The sample transform filters include an audio effect, some video effects, some MPEG codecs, a VCR controller, and various "null" (pass-through) filters.

Contents of this article:

Contrast Filter

The Contrast filter illustrates how to define and implement a simple custom interface within the structure provided by the DirectShow™ base classes. This filter demonstrates how to use the CTransformFilter class to implement a simple effects filter.

The Contrast filter also provides a good example of the flexibility of the filter graph architecture. This flexibility is demonstrated when the filter is used in conjunction with a tee filter to produce "before and after" (side-by-side original and modified) video streams.

The Contrast filter is a simple transform filter that adjusts the contrast of the video stream that is passed through it. It provides a custom interface for adjusting the contrast. The Contrast filter also uses the CBasePropertyPage class to provide a property page for applications that do not provide a user interface.

Note The Contrast filter adjusts the contrast by using a trick with palettes. The color palette of an image effectively determines how the image is interpreted. By changing the palette, the filter can change the contrast without changing the image pixels themselves.

Image Effect Filter (EzRGB24)

The RGB 24 video effect filter, EzRGB24, is a sample of an image processing filter. This shows usage of a number of DirectShow classes and interfaces, including CTransformFilter, CPersistStream, CBasePropertyPage, and ISpecifyPropertyPages.

This filter's purpose is to provide fast and single stream effects. The EzRGB24 filter also shows how to add image processing effects using DirectShow. You can use this filter as a component of an DirectShow video editor. Some applications can provide more sophisticated effects than these. Effects with fast execution were selected to help demonstrate DirectShow's power in enabling real-time effects—the idea was to show something that could not have been built using Microsoft Video for Windows. Developers should see this sample and be motivated to create their own image effects.

This filter performs a number of individual video effects. These include red, green, blue, darken, XOR, blur, gray, and emboss image-processing effects.

Gargle (Simple Audio Processing Filter)

The audio processing filter, Gargle, illustrates how to do a simple sound effect. Echo, flanging, band-pass filtering, and other effects can be carried out in a way similar to that demonstrated by the Gargle filter. This sample demonstrates the CTransInPlaceFilter, CPersistStream, and CBasePropertyPage classes. It also shows use of the ASSERT, DbgBreak, DbgLog, and DbgBreakPoint debug macros.

The Gargle filter modulates the waveform passing through the filter by multiplying it by another waveform that is mathematically generated within the filter. The modulating waveform is, by default, a triangular wave. The property sheet also allows the alternative of a square wave. You can set the frequency of the modulating wave through the property sheet of the filter. At low frequencies (near 1 Hz), the sound grows and diminishes. At medium frequencies (5 to 15 Hz), the sound has a tremolo quality, which is why it is referred to as gargling. At higher frequencies (100 Hz and up), the filter generates extra frequencies in the original sound. If a 500 Hz sound is played at 100 Hz, then it produces additional frequencies of 400 Hz, 600 Hz, 200 Hz, 800 Hz, and so on.

This filter is available through the Filter Graph Editor when you choose Insert Filters from the Graph menu, and select the DirectShow Filters category.

MPEG Framework Audio Codec

The MPEG framework audio codec, MPGAudio, provides a prototype for an MPEG audio decoder. It uses the CTransformFilter class.

As supplied, this framework just consumes the passed-in audio frames. That is, audio frames do not produce any output from this framework. You would need to expand the framework with code specific to the outputs desired.

MPEG Framework Video Codec

The MPEG framework video codec, MPGVideo, provides a prototype for an MPEG video decoder. It uses the CTransformFilter class. The MPGVideo filter also shows the processing of quality-management messages.

As supplied, this framework just consumes the passed-in video frames. That is, video frames do not produce any output from this framework. You would need to expand the framework with code specific to the outputs desired.

Null In-place Filter

The null in-place filter, Nullip, is an example of a transform-inplace filter. It illustrates how a transform filter can behave in a relatively transparent manner. Nullip is a simple filter that passes all data from its input pin to its output pin. No transformations are performed on the data.

The Nullip filter provides an example of using the CTransInPlaceInputPin class. It shows using the CAutoLock class to automatically release critical sections. Other classes used include CTransInPlaceFilter, CBasePropertyPage, CMediaType, and CTransInPlaceOutputPin. It also enables a user to select the media types that it can pass through itself. This filter has one input pin, one output pin, and performs its transform inplace (without copying the data) in the push thread. In other words, the CTransInPlaceFilter::Receive method is called with a buffer, which it transforms and delivers to the next filter downstream. The Receive method is then blocked until that filter returns; it subsequently returns to its own calling member function.

This filter is available through the Filter Graph Editor when you choose Insert Filters from the Graph menu, and select the DirectShow Filters category.

Nullnull Filter

The NullNull sample illustrates a minimal filter, called Minimal Null in the Filter Graph Editor. It does not support the media type selection that Nullip does. The Minimal Null filter uses the CTransInPlaceFilter class.

This filter is available through the Filter Graph Editor when you choose Insert Filters from the Graph menu, and select the DirectShow Filters category.

VCR Device Control Filter

The Vcrctrl sample is a simple implementation of DirectShow's external device control interfaces. It provides basic transport control and SMPTE timecode reading capabilities for certain Betacam and SVHS videocassette recorders with RS-422 or RS-232 serial interfaces (please see source code for specific machine types supported).

Once you build the filter from the sample code, you can register it by typing the following at the command line:


regsvr32 vcrctrl.ax

For information about building filters, see Build a Filter or Application with Visual C++ 5.x. Once you have registered the filter, run GraphEdit and insert the filter.

This sample is not intended to be a frame-accurate, system-ready implementation ready for professional applications. It is designed to show basic device control filter structure, and therefore does not implement several of the more sophisticated features of the interfaces such as edit event control. Frame-accurate control is best achieved by writing a low level, kernel-mode communications driver underneath the filter. Developers should refer to the Driver Development Kit (DDK) for the appropriate platform.

Using the Sample

With this sample, a VCR can be controlled through property pages. You should keep in mind the following:

This sample contains the following files:

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.