Infognition forum
August 01, 2010, 07:07:16 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Last GraphEditPlus version: 1.4.0   Last Video Enhancer version: 1.9.3
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Modifying Windows SDK PushSourceBitmap Filter  (Read 800 times)
markr
Newbie
*

Karma: +0/-0
Posts: 23


View Profile
« on: October 27, 2009, 06:48:39 PM »

I am trying to use the PushSourceBitmap Filter sample that comes with the Windows SDK 6.1, but in a slightly different way than it's original design.  The main problem is that I am NOT a good C++ programmer.  I am very much a Newbie to that language.  I am not trying to be a filter developer either.  Primarily, I am using the DirectShow Library for .NET and writing graphs, etc. using C# (along with the wonderful GraphEditPlus app).

The original design of the PushSourceBitmap sample requires the need of an external bitmap file called sample.bmp.  I just simply want to eliminate the need for that external file and use a plain 1000 wide x 240 high white background in-memory bitmap for each frame of this stream.  Once this gets implemented into the graph, I will use a downstream SampleGrabber filter to overlay stuff to this stream, but all that is already done in C#.

In the original PushSourceBitmap.CPP file, the constructor for CPushPinBitmap::CPushPinBitmap mostly just loads the external file and gets the pointer to the bitmap's buffer in a variable called m_pImage.  This variable is then subsequently used in the FillBuffer method for filling the IMediaSample's buffer.  Therefore, it seems that the major work that I should do is in the constructor and replace the file loading, etc. with the creation of a new bitmap and then set the m_pImage pointer to it instead.  Here is my replacement:

CPushPinBitmap::CPushPinBitmap(HRESULT *phr, CSource *pFilter)
      : CSourceStream(NAME("ImagePOINTE Overlay"), phr, pFilter, L"Out"),
        m_FramesWritten(0),
        m_bZeroMemory(0),
        m_pImage(NULL),
        m_iFrameNumber(0),
        m_rtFrameLength(FPS_10)
{

   // new method - create in-memory bitmap image that is 1000 x 240 x 24 bits - white background color
   RECT rect = {0, 0, 1000, 240};
   HDC hDC = GetDC(null);
   HDC memDC = CreateCompatibleDC(hDC);
   HBITMAP memBM = CreateCompatibleBitmap(hDC, 1000, 240);
   SelectObject(memDC, memBM);
   COLORREF backColor = RGB(255,255,255);
   HBRUSH hBgBrush = CreateSolidBrush(backColor);
   FillRect(memDC, &rect, hBgBrush);
   DeleteObject(hBgBrush);

   BITMAPINFOHEADER bi;
   ::ZeroMemory(&bi, sizeof(BITMAPINFOHEADER));
   bi.biSize        = sizeof(BITMAPINFOHEADER);
   bi.biWidth       = 1000;
   bi.biHeight      = 240;
   bi.biPlanes      = 1;
   bi.biBitCount    = 24;
   bi.biCompression = BI_RGB;

   int dResult = GetDIBits(memDC, memBM, 0, 240, NULL, (BITMAPINFO*)&bi, DIB_RGB_COLORS);
   LPVOID lpvBits = GlobalAlloc(GMEM_FIXED,bi.biSizeImage);
   dResult = GetDIBits(memDC, memBM, 0, 240, lpvBits, (BITMAPINFO*)&bi, DIB_RGB_COLORS);

   m_pImage = (BYTE*)lpvBits;

   DeleteDC(hDC);
   DeleteDC(memDC);
}

I have compiled the project under a different .DLL name as well as different CLSID with success.  I have registered the filter and used it in a DS graph with the expected results, so I know this will work.  However, I think I may actually be doing more work than what is necessary???

Any suggestions or comments would be appreciated.

Thanks,

Mark
« Last Edit: October 28, 2009, 01:09:26 AM by markr » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!