1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
/*****************************************************************************
*
* imagefilter.h
*
* Copyright (c) 2003 Microsoft Corporation. All Rights Reserved.
*
* DESCRIPTION:
*
* Contains class declarations for CMyFilterStream and CImageFilter
*
*******************************************************************************/
#define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
#define HEADER_SIZE 54
#ifndef PI
#define PI 3.1415926538
#endif
#define MY_TEST_FILTER_PROP WIA_PRIVATE_ITEMPROP+1
#define MY_TEST_FILTER_PROP_STR L"My test filter property"
// {AA9198F3-3B91-47d3-A371-EBE7D243F606}
static const GUID CLSID_WiaImageFilter =
{ 0xaa9198f3, 0x3b91, 0x47d3, { 0xa3, 0x71, 0xeb, 0xe7, 0xd2, 0x43, 0xf6, 0x6 } };
static LONG g_cLocks = 0;
void LockModule(void) { InterlockedIncrement(&g_cLocks); }
void UnlockModule(void) { InterlockedDecrement(&g_cLocks); }
/*****************************************************************************
*
* CMyFilterStream is our implemetation of the filtering stream.
* The only IStream method that it implements is Write().
*
* The stream keeps a reference to the applications stream into which it writes
* the filtered data (the header is not modified however).
*
*******************************************************************************/
class CMyFilterStream : public IStream
{
public:
CMyFilterStream(
VOID);
~CMyFilterStream(
VOID);
STDMETHODIMP
Initialize(
_In_ IStream *pAppStream,
LONG lBrightness,
LONG lContrast,
LONG lRotation,
LONG lDeskewX,
LONG lDeskewY,
LONG lXExtent,
LONG lYExtent,
LONG lBitDepth,
GUID guidFormat
);
STDMETHODIMP
Flush(void);
STDMETHODIMP
QueryInterface(_In_ const IID& iid_requested, _Out_ void** ppInterfaceOut);
STDMETHODIMP_(ULONG)
AddRef(void);
STDMETHODIMP_(ULONG)
Release(void);
STDMETHODIMP
Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, _Out_ ULARGE_INTEGER *plibNewPosition);
STDMETHODIMP
SetSize(ULARGE_INTEGER libNewSize);
STDMETHODIMP
LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
STDMETHODIMP
CopyTo(_In_ IStream *pstm, ULARGE_INTEGER cb, _Out_ ULARGE_INTEGER *pcbRead, _Out_ ULARGE_INTEGER *pcbWritten);
STDMETHODIMP
Commit(DWORD grfCommitFlags);
STDMETHODIMP
Revert(void);
STDMETHODIMP
UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
STDMETHODIMP
Stat(_Out_ STATSTG *pstatstg, DWORD grfStatFlag);
STDMETHODIMP
Clone(_Out_ IStream **ppstm);
STDMETHODIMP
Read(_Out_ void *pv, ULONG cb, _Out_ ULONG *pcbRead);
STDMETHODIMP
Write(_In_ const void *pv, ULONG cb, _Out_ ULONG *pcbWritten);
STDMETHODIMP
ReleaseStreams();
ULONG64 m_cBytesWritten;
private:
IStream *m_pAppStream;
IStream *m_pCachingStream;
LONG m_lBrightness;
LONG m_lContrast;
LONG m_lRotation;
LONG m_lDeskewX;
LONG m_lDeskewY;
GUID m_guidFormat;
LONG m_nRefCount;
};
/*****************************************************************************
*
* CImageFilter is the main image processing filter class. It implements IWiaImageFilter
* as well as the callback interface IWiaTransferCallback.
*
* Internally it creates the filtering stream CMyFilterStream in its GetNextStream
* implementation. Its implementation of TransferCallback simply delegates to the
* applications callback, since it does not alter the size or the flow of the data
* that the driver writes to it.
*
*******************************************************************************/
class CImageFilter : public IWiaImageFilter, public IWiaTransferCallback
{
public:
CImageFilter(
VOID);
~CImageFilter(
VOID);
STDMETHODIMP
QueryInterface(_In_ const IID& iid_requested, _Out_ void** ppInterfaceOut);
STDMETHODIMP_(ULONG)
AddRef(void);
STDMETHODIMP_(ULONG)
Release(void);
STDMETHODIMP
InitializeFilter(
_In_ IN IWiaItem2 *pWiaItem,
__callback IN IWiaTransferCallback *pWiaTransferCallback);
STDMETHODIMP
SetNewCallback(
_In_opt_ __callback IN IWiaTransferCallback *pWiaTransferCallback);
STDMETHODIMP
FilterPreviewImage(
IN LONG lFlags,
_In_ IN IWiaItem2 *pWiaChildItem,
IN RECT InputImageExtents,
_In_ IN IStream *pInputStream);
STDMETHODIMP
TransferCallback(
IN LONG lFlags,
_In_ IN WiaTransferParams *pWiaTransferParams);
STDMETHODIMP
GetNextStream(
LONG lFlags,
_In_z_ BSTR bstrItemName,
_In_z_ BSTR bstrFullItemName,
_Outptr_result_maybenull_ _At_(*ppDestination, _When_(return == S_OK, _Post_notnull_))
IStream **ppDestination);
STDMETHODIMP
ApplyProperties(
_Inout_ IN IWiaPropertyStorage *pWiaPropertyStorage);
LONG lPercentComplete;
ULONG64 m_ulTransferredBytes;
private:
CMyFilterStream *m_pCurrentStream;
IWiaItem2 *m_pWiaItem;
IWiaTransferCallback *m_pAppWiaTransferCallback;
BOOL m_bTransferCancelled;
LONG m_nRefCount;
};
|