00001
00035 #pragma once
00036
00037
00038 #include <DirectShow/CustomBaseFilter.h>
00039
00040
00041 static const GUID CLSID_CropFilter =
00042 { 0xf5e69199, 0x7ab2, 0x40f0, { 0xbf, 0xc0, 0x69, 0x38, 0x43, 0xf, 0x4f, 0x19 } };
00043
00044
00045 static const GUID CLSID_CropProperties =
00046 { 0x2e164ade, 0x2f13, 0x4ee9, { 0xba, 0x95, 0x28, 0xcf, 0x9a, 0xe2, 0x35, 0x11 } };
00047
00048
00049 class PicCropperBase;
00050
00051 class CCropFilter : public CCustomBaseFilter,
00052 public ISpecifyPropertyPages
00053 {
00054 public:
00055 DECLARE_IUNKNOWN
00056
00058 CCropFilter();
00060 ~CCropFilter();
00061
00063 static CUnknown * WINAPI CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr);
00064
00068 HRESULT SetMediaType(PIN_DIRECTION direction, const CMediaType *pmt);
00069
00077 HRESULT GetMediaType(int iPosition, CMediaType *pMediaType);
00078
00080
00086 HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pProp);
00087
00092 HRESULT CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut);
00093
00095 virtual void initParameters()
00096 {
00097 addParameter(TARGET_WIDTH, &m_nOutWidth, -1, true);
00098 addParameter(TARGET_HEIGHT, &m_nOutHeight, -1, true);
00099 addParameter(LEFT_CROP, &m_nLeftCrop, 0);
00100 addParameter(RIGHT_CROP, &m_nRightCrop, 0);
00101 addParameter(TOP_CROP, &m_nTopCrop, 0);
00102 addParameter(BOTTOM_CROP, &m_nBottomCrop, 0);
00103 RecalculateFilterParameters();
00104 }
00105
00106 STDMETHODIMP SetParameter( const char* type, const char* value);
00107
00109 virtual void InitialiseInputTypes();
00110
00111 STDMETHODIMP GetPages(CAUUID *pPages)
00112 {
00113 if (pPages == NULL) return E_POINTER;
00114 pPages->cElems = 1;
00115 pPages->pElems = (GUID*)CoTaskMemAlloc(sizeof(GUID));
00116 if (pPages->pElems == NULL)
00117 {
00118 return E_OUTOFMEMORY;
00119 }
00120 pPages->pElems[0] = CLSID_CropProperties;
00121 return S_OK;
00122 }
00123
00124 STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv)
00125 {
00126 if (riid == IID_ISpecifyPropertyPages)
00127 {
00128 return GetInterface(static_cast<ISpecifyPropertyPages*>(this), ppv);
00129 }
00130 else
00131 {
00132
00133 return CCustomBaseFilter::NonDelegatingQueryInterface(riid, ppv);
00134 }
00135 }
00136
00137 private:
00143 DWORD ApplyTransform(BYTE* pBufferIn, BYTE* pBufferOut);
00144
00146 HRESULT SetCropIfValid(int nTotalDimensionImage, int nNewCrop, int& nOldCrop, int nOppositeCrop );
00148 void RecalculateFilterParameters();
00149
00151 PicCropperBase* m_pCropper;
00152
00153 int m_nBytesPerPixel;
00154
00155 int m_nLeftCrop;
00156 int m_nRightCrop;
00157 int m_nTopCrop;
00158 int m_nBottomCrop;
00159
00160 int m_nStride;
00161 int m_nPadding;
00162 };