Write your own filter to change the color of the screen

Source: Internet
Author: User

The Help documentation for DirectX Show is a good reference. But a lot of things in there are too much to talk about, and we in the beginning of contact, all want to start from the simplest things, and then gradually in-depth, but the reference SDK inside the example program, always foggy, especially their own hands to write filter, to brush off its plexus fog, it is really some not easy.

Lu Qiming's "DirectX Show Development Guide" has a more classical explanation of DirectX show, which can be seen in some articles posted online. It is a pity that this place is too backward to buy this book, I am also a DS of beginners, I would like to ask you a lot of advice.

The GraphEdit of Directx show is a good filter debugging tool, located in ... The \dxsdk\bin\dxutils directory. In: Start-> program->microsoft directx9.0 sdk->directx Utilities can also find the tool, I wrote this filter, the reader opens the tool after the menu: Graph->insert Filter opens the "WHICH FILTERS do you WANT to insert" dialog box, click "Directxshow filters->huang RGB Filter" To insert it, and then from "File->render ME DIA file "Open a MPG format, you can play your video, you can change the color of the screen by Huang RGB Filter." Here's what it says about filter.

There are three kinds of filter:

    • 1. SOURCE FILTER; (such as network streaming media, local media files)
    • 2. TRANSFORM filter (part of the change to the media file, this filter is both)
    • 3. RENDER FILTER (video display)

Filter Connection: (Care only for partial implementation of the program, not for full discussion)

    • 1. Enter a connection for your PIN: The first thing you need to do to add your filter to filter graph is to check the type of media supported on the input pin of your filter. The Checkinputtype is implemented on the filter.
    • 2. Output PIN Connection: Downstream filter to connect your filter first, you need to view the type of media supported on the output pin. The function called is getmediatype, and the function is implemented in filter. Once the output pin supports the connected media type, filter checktransform to check whether the input output media type satisfies the requirements, checktransform after the success, the allocator is negotiated. Completed in the decidebuffersize. With so simple a few functions, filter can be connected to the filter GRAPH.
    • 3. Transfer of media:

      This example is based on Ctransformfilter, so the Ctransformfilter::transform (imediasample *psource,imediasample *pDest) function is invoked at the time of transmission, What we're going to do is copy the data on the Psource to the pdest. If you are simply transmitting, the copy function in the example can meet the requirements and be modified on the media only on Pdest. This example refers to the SDK filter Constrast This example to change the color, this example has a lot of deficiencies, it is not used to achieve what the full function, he is just a simple example of the program, let us operate the media. It's funny.

Here's the thing about the program:

  • 1. Through a custom simplest interface ichangecolor to complete the transfer of RGB value, which has a little bit of COM knowledge, in COM, the interface is based on components to achieve, This example ccolorfilter is both a transport filter and a component that implements the interface Ichangecolor. The implementation of all Ichangecolor functions is defined and implemented in Ccolorfilter, so it is interesting to call the Ichangcolor interface in Cprop, and the related action is done in Ccolorfilter. //IChangeColor implement
       STDMETHODIMP Get_RGBColor(BYTE *r,BYTE *g,BYTE *b);
       STDMETHODIMP Put_RGBColor(BYTE r,BYTE g,BYTE b);
    these two methods are completed.
  • 2. In the Cprop through the Ichangcolor can deal with the interface, this part of the separate to write is simple. Please see the source code for details. Several functions are required, and to understand how they work, you can add test code.
  • 3. Ccolorfilter is the key, and this is a minimal realization. HRESULT CheckInputType(const CMediaType *pmtin);
      HRESULT GetMediaType(int iPosition, CMediaType *pMediaType);
      HRESULT CheckTransform(const CMediaType *mtin,const CMediaType *mtout);
      HRESULT DecideBufferSize(IMemAllocator *pAlloc,ALLOCATOR_PROPERTIES *pProp);
      HRESULT Transform(IMediaSample *pin,IMediaSample *pout);
    is the method of the parent class ctransformfilter that must be implemented. void AdjustConstrast(BYTE *r,BYTE *g,BYTE *b);
      HRESULT Transform(AM_MEDIA_TYPE *pDest);
      HRESULT Transform(IMediaSample *pMediaSample);
      HRESULT copy(IMediaSample *pin,IMediaSample *pout);
      void ChangeContrast(RGBQUAD *pElem);
    is a function of your own, mainly to change the media color.

To program registration, you need to recompile. After the Registration successful dialog box appears, you can use the GraphEdit tool to use the method described above. To compile successfully, set the include and LIB paths according to your actual situation.

You can also directly use regsvr32 This document this book I provide to you. \debug\proppage.ax. program Environment vc6.0+win2000+dx9.0;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.