00001
00002
00003
00004
00005
00006 #ifndef __WINUTIL__
00007 #define __WINUTIL__
00008
00009 const int DEFWIDTH = 320;
00010 const int DEFHEIGHT = 240;
00011 const int CAPTION = 256;
00012 const int TIMELENGTH = 50;
00013 const int PROFILESTR = 128;
00014 const WORD PALVERSION = 0x300;
00015 const LONG PALETTE_VERSION = (LONG) 1;
00016 const COLORREF VIDEO_COLOUR = 0;
00017 const HANDLE hMEMORY = (HANDLE) (-1);
00018
00019 #define WIDTH(x) ((*(x)).right - (*(x)).left)
00020 #define HEIGHT(x) ((*(x)).bottom - (*(x)).top)
00021 #define SHOWSTAGE TEXT("WM_SHOWSTAGE")
00022 #define SHOWSTAGETOP TEXT("WM_SHOWSTAGETOP")
00023 #define REALIZEPALETTE TEXT("WM_REALIZEPALETTE")
00024
00025 class AM_NOVTABLE CBaseWindow
00026 {
00027 protected:
00028
00029 HINSTANCE m_hInstance;
00030 HWND m_hwnd;
00031 HDC m_hdc;
00032 LONG m_Width;
00033 LONG m_Height;
00034 BOOL m_bActivated;
00035 LPTSTR m_pClassName;
00036 DWORD m_ClassStyles;
00037 DWORD m_WindowStyles;
00038 DWORD m_WindowStylesEx;
00039 UINT m_ShowStageMessage;
00040 UINT m_ShowStageTop;
00041 UINT m_RealizePalette;
00042 HDC m_MemoryDC;
00043 HPALETTE m_hPalette;
00044 BYTE m_bNoRealize;
00045 BYTE m_bBackground;
00046 BYTE m_bRealizing;
00047 CCritSec m_WindowLock;
00048 BOOL m_bDoGetDC;
00049 bool m_bDoPostToDestroy;
00050
00051
00052 friend LRESULT CALLBACK WndProc(HWND hwnd,
00053 UINT uMsg,
00054 WPARAM wParam,
00055 LPARAM lParam);
00056
00057 virtual LRESULT OnPaletteChange(HWND hwnd, UINT Message);
00058
00059 public:
00060
00061 CBaseWindow(BOOL bDoGetDC = TRUE, bool bPostToDestroy = false);
00062
00063 #ifdef DEBUG
00064 virtual ~CBaseWindow();
00065 #endif
00066
00067 virtual HRESULT DoneWithWindow();
00068 virtual HRESULT PrepareWindow();
00069 virtual HRESULT InactivateWindow();
00070 virtual HRESULT ActivateWindow();
00071 virtual BOOL OnSize(LONG Width, LONG Height);
00072 virtual BOOL OnClose();
00073 virtual RECT GetDefaultRect();
00074 virtual HRESULT UninitialiseWindow();
00075 virtual HRESULT InitialiseWindow(HWND hwnd);
00076
00077 HRESULT CompleteConnect();
00078 HRESULT DoCreateWindow();
00079
00080 HRESULT PerformanceAlignWindow();
00081 HRESULT DoShowWindow(LONG ShowCmd);
00082 void PaintWindow(BOOL bErase);
00083 void DoSetWindowForeground(BOOL bFocus);
00084 virtual HRESULT SetPalette(HPALETTE hPalette);
00085 void SetRealize(BOOL bRealize)
00086 {
00087 m_bNoRealize = !bRealize;
00088 }
00089
00090
00091 HRESULT SetPalette();
00092
00093 virtual HRESULT DoRealisePalette(BOOL bForceBackground = FALSE);
00094
00095 virtual BOOL PossiblyEatMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
00096 { return FALSE; };
00097
00098
00099
00100 LONG GetWindowWidth();
00101 LONG GetWindowHeight();
00102 HWND GetWindowHWND();
00103 HDC GetMemoryHDC();
00104 HDC GetWindowHDC();
00105
00106
00107
00108 virtual LRESULT OnReceiveMessage(HWND hwnd,
00109 UINT uMsg,
00110 WPARAM wParam,
00111 LPARAM lParam);
00112
00113
00114
00115 virtual LPTSTR GetClassWindowStyles(
00116 DWORD *pClassStyles,
00117 DWORD *pWindowStyles,
00118 DWORD *pWindowStylesEx) PURE;
00119 };
00120
00121 class CDrawImage
00122 {
00123 protected:
00124
00125 CBaseWindow *m_pBaseWindow;
00126 CRefTime m_StartSample;
00127 CRefTime m_EndSample;
00128 HDC m_hdc;
00129 HDC m_MemoryDC;
00130 RECT m_TargetRect;
00131 RECT m_SourceRect;
00132 BOOL m_bStretch;
00133 BOOL m_bUsingImageAllocator;
00134 CMediaType *m_pMediaType;
00135 int m_perfidRenderTime;
00136 LONG m_PaletteVersion;
00137
00138
00139
00140 void SlowRender(IMediaSample *pMediaSample);
00141 void FastRender(IMediaSample *pMediaSample);
00142 void DisplaySampleTimes(IMediaSample *pSample);
00143 void UpdateColourTable(HDC hdc,BITMAPINFOHEADER *pbmi);
00144 void SetStretchMode();
00145
00146 public:
00147
00148
00149
00150 CDrawImage(CBaseWindow *pBaseWindow);
00151 BOOL DrawImage(IMediaSample *pMediaSample);
00152 BOOL DrawVideoImageHere(HDC hdc, IMediaSample *pMediaSample,
00153 LPRECT lprcSrc, LPRECT lprcDst);
00154 void SetDrawContext();
00155 void SetTargetRect(RECT *pTargetRect);
00156 void SetSourceRect(RECT *pSourceRect);
00157 void GetTargetRect(RECT *pTargetRect);
00158 void GetSourceRect(RECT *pSourceRect);
00159 virtual RECT ScaleSourceRect(const RECT *pSource);
00160
00161
00162
00163 LONG GetPaletteVersion();
00164 void ResetPaletteVersion();
00165 void IncrementPaletteVersion();
00166
00167
00168
00169 void NotifyAllocator(BOOL bUsingImageAllocator);
00170 void NotifyMediaType(CMediaType *pMediaType);
00171 BOOL UsingImageAllocator();
00172
00173
00174
00175 void NotifyStartDraw() {
00176 MSR_START(m_perfidRenderTime);
00177 };
00178
00179
00180
00181 void NotifyEndDraw() {
00182 MSR_STOP(m_perfidRenderTime);
00183 };
00184 };
00185
00186 typedef struct tagDIBDATA {
00187
00188 LONG PaletteVersion;
00189 DIBSECTION DibSection;
00190 HBITMAP hBitmap;
00191 HANDLE hMapping;
00192 BYTE *pBase;
00193
00194 } DIBDATA;
00195
00196 class CImageSample : public CMediaSample
00197 {
00198 protected:
00199
00200 DIBDATA m_DibData;
00201 BOOL m_bInit;
00202
00203 public:
00204
00205
00206
00207 CImageSample(CBaseAllocator *pAllocator,
00208 TCHAR *pName,
00209 HRESULT *phr,
00210 LPBYTE pBuffer,
00211 LONG length);
00212
00213
00214
00215 void SetDIBData(DIBDATA *pDibData);
00216 DIBDATA *GetDIBData();
00217 };
00218
00219 class CImageAllocator : public CBaseAllocator
00220 {
00221 protected:
00222
00223 CBaseFilter *m_pFilter;
00224 CMediaType *m_pMediaType;
00225
00226
00227
00228 HRESULT Alloc();
00229 void Free();
00230
00231
00232
00233 HRESULT CreateDIB(LONG InSize,DIBDATA &DibData);
00234 STDMETHODIMP CheckSizes(ALLOCATOR_PROPERTIES *pRequest);
00235 virtual CImageSample *CreateImageSample(LPBYTE pData,LONG Length);
00236
00237 public:
00238
00239
00240
00241 CImageAllocator(CBaseFilter *pFilter,TCHAR *pName,HRESULT *phr);
00242 #ifdef DEBUG
00243 ~CImageAllocator();
00244 #endif
00245
00246 STDMETHODIMP_(ULONG) NonDelegatingAddRef();
00247 STDMETHODIMP_(ULONG) NonDelegatingRelease();
00248 void NotifyMediaType(CMediaType *pMediaType);
00249
00250
00251
00252 STDMETHODIMP SetProperties(
00253 ALLOCATOR_PROPERTIES *pRequest,
00254 ALLOCATOR_PROPERTIES *pActual);
00255 };
00256
00257 class CImagePalette
00258 {
00259 protected:
00260
00261 CBaseWindow *m_pBaseWindow;
00262 CBaseFilter *m_pFilter;
00263 CDrawImage *m_pDrawImage;
00264 HPALETTE m_hPalette;
00265
00266 public:
00267
00268 CImagePalette(CBaseFilter *pBaseFilter,
00269 CBaseWindow *pBaseWindow,
00270 CDrawImage *pDrawImage);
00271
00272 #ifdef DEBUG
00273 virtual ~CImagePalette();
00274 #endif
00275
00276 static HPALETTE MakePalette(const VIDEOINFOHEADER *pVideoInfo, LPSTR szDevice);
00277 HRESULT RemovePalette();
00278 static HRESULT MakeIdentityPalette(PALETTEENTRY *pEntry,INT iColours, LPSTR szDevice);
00279 HRESULT CopyPalette(const CMediaType *pSrc,CMediaType *pDest);
00280 BOOL ShouldUpdate(const VIDEOINFOHEADER *pNewInfo,const VIDEOINFOHEADER *pOldInfo);
00281 HRESULT PreparePalette(const CMediaType *pmtNew,const CMediaType *pmtOld,LPSTR szDevice);
00282
00283 BOOL DrawVideoImageHere(HDC hdc, IMediaSample *pMediaSample, LPRECT lprcSrc, LPRECT lprcDst)
00284 {
00285 return m_pDrawImage->DrawVideoImageHere(hdc, pMediaSample, lprcSrc,lprcDst);
00286 }
00287 };
00288
00289 class CImageDisplay : public CCritSec
00290 {
00291 protected:
00292
00293
00294
00295 VIDEOINFO m_Display;
00296
00297 static DWORD CountSetBits(const DWORD Field);
00298 static DWORD CountPrefixBits(const DWORD Field);
00299 static BOOL CheckBitFields(const VIDEOINFO *pInput);
00300
00301 public:
00302
00303
00304
00305 CImageDisplay();
00306
00307
00308
00309 const VIDEOINFO *GetDisplayFormat();
00310 HRESULT RefreshDisplayType(LPSTR szDeviceName);
00311 static BOOL CheckHeaderValidity(const VIDEOINFO *pInput);
00312 static BOOL CheckPaletteHeader(const VIDEOINFO *pInput);
00313 BOOL IsPalettised();
00314 WORD GetDisplayDepth();
00315
00316
00317
00318 HRESULT CheckMediaType(const CMediaType *pmtIn);
00319 HRESULT CheckVideoType(const VIDEOINFO *pInput);
00320 HRESULT UpdateFormat(VIDEOINFO *pVideoInfo);
00321 const DWORD *GetBitMasks(const VIDEOINFO *pVideoInfo);
00322
00323 BOOL GetColourMask(DWORD *pMaskRed,
00324 DWORD *pMaskGreen,
00325 DWORD *pMaskBlue);
00326 };
00327
00328 STDAPI ConvertVideoInfoToVideoInfo2(AM_MEDIA_TYPE *pmt);
00329
00330 #endif
00331