123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- #ifndef __WINUTIL__
- #define __WINUTIL__
- const int DEFWIDTH = 320;
- const int DEFHEIGHT = 240;
- const int CAPTION = 256;
- const int TIMELENGTH = 50;
- const int PROFILESTR = 128;
- const WORD PALVERSION = 0x300;
- const LONG PALETTE_VERSION = (LONG) 1;
- const COLORREF VIDEO_COLOUR = 0;
- const HANDLE hMEMORY = (HANDLE) (-1);
- #define WIDTH(x) ((*(x)).right - (*(x)).left)
- #define HEIGHT(x) ((*(x)).bottom - (*(x)).top)
- #define SHOWSTAGE TEXT("WM_SHOWSTAGE")
- #define SHOWSTAGETOP TEXT("WM_SHOWSTAGETOP")
- #define REALIZEPALETTE TEXT("WM_REALIZEPALETTE")
- class AM_NOVTABLE CBaseWindow
- {
- protected:
- HINSTANCE m_hInstance;
- HWND m_hwnd;
- HDC m_hdc;
- LONG m_Width;
- LONG m_Height;
- BOOL m_bActivated;
- LPTSTR m_pClassName;
- DWORD m_ClassStyles;
- DWORD m_WindowStyles;
- DWORD m_WindowStylesEx;
- UINT m_ShowStageMessage;
- UINT m_ShowStageTop;
- UINT m_RealizePalette;
- HDC m_MemoryDC;
- HPALETTE m_hPalette;
- BYTE m_bNoRealize;
- BYTE m_bBackground;
- BYTE m_bRealizing;
- CCritSec m_WindowLock;
- BOOL m_bDoGetDC;
- bool m_bDoPostToDestroy;
- CCritSec m_PaletteLock;
-
-
-
- friend LRESULT CALLBACK WndProc(HWND hwnd,
- UINT uMsg,
- WPARAM wParam,
- LPARAM lParam);
- virtual LRESULT OnPaletteChange(HWND hwnd, UINT Message);
- public:
- CBaseWindow(BOOL bDoGetDC = TRUE, bool bPostToDestroy = false);
- #ifdef DEBUG
- virtual ~CBaseWindow();
- #endif
- virtual HRESULT DoneWithWindow();
- virtual HRESULT PrepareWindow();
- virtual HRESULT InactivateWindow();
- virtual HRESULT ActivateWindow();
- virtual BOOL OnSize(LONG Width, LONG Height);
- virtual BOOL OnClose();
- virtual RECT GetDefaultRect();
- virtual HRESULT UninitialiseWindow();
- virtual HRESULT InitialiseWindow(HWND hwnd);
- HRESULT CompleteConnect();
- HRESULT DoCreateWindow();
- HRESULT PerformanceAlignWindow();
- HRESULT DoShowWindow(LONG ShowCmd);
- void PaintWindow(BOOL bErase);
- void DoSetWindowForeground(BOOL bFocus);
- virtual HRESULT SetPalette(HPALETTE hPalette);
- void SetRealize(BOOL bRealize)
- {
- m_bNoRealize = !bRealize;
- }
-
- HRESULT SetPalette();
- void UnsetPalette(void);
- virtual HRESULT DoRealisePalette(BOOL bForceBackground = FALSE);
- void LockPaletteLock();
- void UnlockPaletteLock();
- virtual BOOL PossiblyEatMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
- { return FALSE; };
-
- bool WindowExists();
- LONG GetWindowWidth();
- LONG GetWindowHeight();
- HWND GetWindowHWND();
- HDC GetMemoryHDC();
- HDC GetWindowHDC();
- #ifdef DEBUG
- HPALETTE GetPalette();
- #endif
-
- virtual LRESULT OnReceiveMessage(HWND hwnd,
- UINT uMsg,
- WPARAM wParam,
- LPARAM lParam);
-
- virtual LPTSTR GetClassWindowStyles(
- __out DWORD *pClassStyles,
- __out DWORD *pWindowStyles,
- __out DWORD *pWindowStylesEx) PURE;
- };
- class CDrawImage
- {
- protected:
- CBaseWindow *m_pBaseWindow;
- CRefTime m_StartSample;
- CRefTime m_EndSample;
- HDC m_hdc;
- HDC m_MemoryDC;
- RECT m_TargetRect;
- RECT m_SourceRect;
- BOOL m_bStretch;
- BOOL m_bUsingImageAllocator;
- CMediaType *m_pMediaType;
- int m_perfidRenderTime;
- LONG m_PaletteVersion;
-
- void SlowRender(IMediaSample *pMediaSample);
- void FastRender(IMediaSample *pMediaSample);
- void DisplaySampleTimes(IMediaSample *pSample);
- void UpdateColourTable(HDC hdc,__in BITMAPINFOHEADER *pbmi);
- void SetStretchMode();
- public:
-
- CDrawImage(__inout CBaseWindow *pBaseWindow);
- BOOL DrawImage(IMediaSample *pMediaSample);
- BOOL DrawVideoImageHere(HDC hdc, IMediaSample *pMediaSample,
- __in LPRECT lprcSrc, __in LPRECT lprcDst);
- void SetDrawContext();
- void SetTargetRect(__in RECT *pTargetRect);
- void SetSourceRect(__in RECT *pSourceRect);
- void GetTargetRect(__out RECT *pTargetRect);
- void GetSourceRect(__out RECT *pSourceRect);
- virtual RECT ScaleSourceRect(const RECT *pSource);
-
- LONG GetPaletteVersion();
- void ResetPaletteVersion();
- void IncrementPaletteVersion();
-
- void NotifyAllocator(BOOL bUsingImageAllocator);
- void NotifyMediaType(__in CMediaType *pMediaType);
- BOOL UsingImageAllocator();
-
- void NotifyStartDraw() {
- MSR_START(m_perfidRenderTime);
- };
-
- void NotifyEndDraw() {
- MSR_STOP(m_perfidRenderTime);
- };
- };
- typedef struct tagDIBDATA {
- LONG PaletteVersion;
- DIBSECTION DibSection;
- HBITMAP hBitmap;
- HANDLE hMapping;
- BYTE *pBase;
- } DIBDATA;
- class CImageSample : public CMediaSample
- {
- protected:
- DIBDATA m_DibData;
- BOOL m_bInit;
- public:
-
- CImageSample(__inout CBaseAllocator *pAllocator,
- __in_opt LPCTSTR pName,
- __inout HRESULT *phr,
- __in_bcount(length) LPBYTE pBuffer,
- LONG length);
-
- void SetDIBData(__in DIBDATA *pDibData);
- __out DIBDATA *GetDIBData();
- };
- class CImageAllocator : public CBaseAllocator
- {
- protected:
- CBaseFilter *m_pFilter;
- CMediaType *m_pMediaType;
-
- HRESULT Alloc();
- void Free();
-
- HRESULT CreateDIB(LONG InSize,DIBDATA &DibData);
- STDMETHODIMP CheckSizes(__in ALLOCATOR_PROPERTIES *pRequest);
- virtual CImageSample *CreateImageSample(__in_bcount(Length) LPBYTE pData,LONG Length);
- public:
-
- CImageAllocator(__inout CBaseFilter *pFilter,__in_opt LPCTSTR pName,__inout HRESULT *phr);
- #ifdef DEBUG
- ~CImageAllocator();
- #endif
- STDMETHODIMP_(ULONG) NonDelegatingAddRef();
- STDMETHODIMP_(ULONG) NonDelegatingRelease();
- void NotifyMediaType(__in CMediaType *pMediaType);
-
- STDMETHODIMP SetProperties(
- __in ALLOCATOR_PROPERTIES *pRequest,
- __out ALLOCATOR_PROPERTIES *pActual);
- };
- class CImagePalette
- {
- protected:
- CBaseWindow *m_pBaseWindow;
- CBaseFilter *m_pFilter;
- CDrawImage *m_pDrawImage;
- HPALETTE m_hPalette;
- public:
- CImagePalette(__inout CBaseFilter *pBaseFilter,
- __inout CBaseWindow *pBaseWindow,
- __inout CDrawImage *pDrawImage);
- #ifdef DEBUG
- virtual ~CImagePalette();
- #endif
- static HPALETTE MakePalette(const VIDEOINFOHEADER *pVideoInfo, __in LPSTR szDevice);
- HRESULT RemovePalette();
- static HRESULT MakeIdentityPalette(__inout_ecount_full(iColours) PALETTEENTRY *pEntry,INT iColours, __in LPSTR szDevice);
- HRESULT CopyPalette(const CMediaType *pSrc,__out CMediaType *pDest);
- BOOL ShouldUpdate(const VIDEOINFOHEADER *pNewInfo,const VIDEOINFOHEADER *pOldInfo);
- HRESULT PreparePalette(const CMediaType *pmtNew,const CMediaType *pmtOld,__in LPSTR szDevice);
- BOOL DrawVideoImageHere(HDC hdc, IMediaSample *pMediaSample, __in LPRECT lprcSrc, __in LPRECT lprcDst)
- {
- return m_pDrawImage->DrawVideoImageHere(hdc, pMediaSample, lprcSrc,lprcDst);
- }
- };
- class CImageDisplay : public CCritSec
- {
- protected:
-
-
- VIDEOINFO m_Display;
- static DWORD CountSetBits(const DWORD Field);
- static DWORD CountPrefixBits(const DWORD Field);
- static BOOL CheckBitFields(const VIDEOINFO *pInput);
- public:
-
- CImageDisplay();
-
- const VIDEOINFO *GetDisplayFormat();
- HRESULT RefreshDisplayType(__in_opt LPSTR szDeviceName);
- static BOOL CheckHeaderValidity(const VIDEOINFO *pInput);
- static BOOL CheckPaletteHeader(const VIDEOINFO *pInput);
- BOOL IsPalettised();
- WORD GetDisplayDepth();
-
- HRESULT CheckMediaType(const CMediaType *pmtIn);
- HRESULT CheckVideoType(const VIDEOINFO *pInput);
- HRESULT UpdateFormat(__inout VIDEOINFO *pVideoInfo);
- const DWORD *GetBitMasks(const VIDEOINFO *pVideoInfo);
- BOOL GetColourMask(__out DWORD *pMaskRed,
- __out DWORD *pMaskGreen,
- __out DWORD *pMaskBlue);
- };
- STDAPI ConvertVideoInfoToVideoInfo2(__inout AM_MEDIA_TYPE *pmt);
- STDAPI CheckVideoInfoType(const AM_MEDIA_TYPE *pmt);
- STDAPI CheckVideoInfo2Type(const AM_MEDIA_TYPE *pmt);
- #endif
|