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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
|
/**************************************************************************
AVStream Simulated Hardware Sample
Copyright (c) 2001, Microsoft Corporation.
File:
image.h
Abstract:
The image synthesis and overlay header. These objects provide image
synthesis (pixel, color-bar, etc...) onto RGB24 and UYVY buffers as
well as software string overlay into these buffers.
History:
created 1/16/2001
**************************************************************************/
/**************************************************************************
Constants
**************************************************************************/
//
// COLOR:
//
// Pixel color for placement onto the synthesis buffer.
//
typedef enum {
BLACK = 0,
WHITE,
YELLOW,
CYAN,
GREEN,
MAGENTA,
RED,
BLUE,
GREY,
MAX_COLOR,
TRANSPARENT,
} COLOR;
//
// POSITION_CENTER:
//
// Only useful for text overlay. This can be substituted for LocX or LocY
// in order to center the text screen on the synthesis buffer.
//
#define POSITION_CENTER ((ULONG)-1)
/*************************************************
CImageSynthesizer
This class synthesizes images in various formats for output from the
capture filter. It is capable of performing various text overlays onto
the image surface.
*************************************************/
class CImageSynthesizer {
protected:
//
// The width and height the synthesizer is set to.
//
ULONG m_Width;
ULONG m_Height;
//
// The synthesis buffer. All scan conversion happens in the synthesis
// buffer. This must be set with SetBuffer() before any scan conversion
// routines are called.
//
PUCHAR m_SynthesisBuffer;
//
// The default cursor. This is a pointer into the synthesis buffer where
// a non specific PutPixel will be placed.
//
PUCHAR m_Cursor;
public:
//
// PutPixel():
//
// Place a pixel at the specified image cursor and move right
// by one pixel. No bounds checking... wrap around occurs.
//
virtual void
PutPixel (
PUCHAR *ImageLocation,
COLOR Color
) = 0;
//
// PutPixel():
//
// Place a pixel at the default image cursor and move right
// by one pixel. No bounds checking... wrap around occurs.
//
// If the derived class doesn't provide an implementation, provide
// one.
//
virtual void
PutPixel (
COLOR Color
)
{
PutPixel (&m_Cursor, Color);
}
//
// Fill():
//
// Fill an area of the image with a specific color.
//
virtual void
Fill (
IN ULONG X_TopLeft,
IN ULONG Y_TopLeft,
IN ULONG X_BottomRight,
IN ULONG Y_BottomRight,
IN COLOR Color
);
//
// GetImageLocation():
//
// Get the location into the image buffer for a specific X/Y location.
// This also sets the synthesizer's default cursor to the position
// LocX, LocY.
//
virtual PUCHAR
GetImageLocation (
ULONG LocX,
ULONG LocY
) = 0;
//
// SetImageSize():
//
// Set the image size of the synthesis buffer.
//
void
SetImageSize (
ULONG Width,
ULONG Height
)
{
m_Width = Width;
m_Height = Height;
}
//
// SetBuffer():
//
// Set the buffer the synthesizer generates images to.
//
void
SetBuffer (
PUCHAR SynthesisBuffer
)
{
m_SynthesisBuffer = SynthesisBuffer;
}
//
// SynthesizeBars():
//
// Synthesize EIA-189-A standard color bars.
//
void
SynthesizeBars (
);
//
// OverlayText():
//
// Overlay a text string onto the image.
//
void
OverlayText (
_In_ ULONG LocX,
_In_ ULONG LocY,
_In_ ULONG Scaling,
_In_ LPSTR Text,
_In_ COLOR BgColor,
_In_ COLOR FgColor
);
//
// DEFAULT CONSTRUCTOR
//
CImageSynthesizer (
) :
m_Width (0),
m_Height (0),
m_SynthesisBuffer (NULL)
{
}
//
// CONSTRUCTOR:
//
CImageSynthesizer (
ULONG Width,
ULONG Height
) :
m_Width (Width),
m_Height (Height),
m_SynthesisBuffer (NULL)
{
}
//
// DESTRUCTOR:
//
virtual
~CImageSynthesizer (
)
{
}
};
/*************************************************
CRGB24Synthesizer
Image synthesizer for RGB24 format.
*************************************************/
class CRGB24Synthesizer : public CImageSynthesizer {
private:
const static UCHAR Colors [MAX_COLOR][3];
BOOLEAN m_FlipVertical;
public:
//
// PutPixel():
//
// Place a pixel at a specific cursor location. *ImageLocation must
// reside within the synthesis buffer.
//
virtual void
PutPixel (
PUCHAR *ImageLocation,
COLOR Color
)
{
if (Color != TRANSPARENT) {
*(*ImageLocation)++ = Colors [(ULONG)Color][0];
*(*ImageLocation)++ = Colors [(ULONG)Color][1];
*(*ImageLocation)++ = Colors [(ULONG)Color][2];
} else {
*ImageLocation += 3;
}
}
//
// PutPixel():
//
// Place a pixel at the default cursor location. The cursor location
// must be set via GetImageLocation(x, y).
//
virtual void
PutPixel (
COLOR Color
)
{
if (Color != TRANSPARENT) {
*m_Cursor++ = Colors [(ULONG)Color][0];
*m_Cursor++ = Colors [(ULONG)Color][1];
*m_Cursor++ = Colors [(ULONG)Color][2];
} else {
m_Cursor += 3;
}
}
virtual PUCHAR
GetImageLocation (
ULONG LocX,
ULONG LocY
)
{
if (m_FlipVertical) {
return (m_Cursor =
(m_SynthesisBuffer + 3 *
(LocX + (m_Height - 1 - LocY) * m_Width))
);
} else {
return (m_Cursor =
(m_SynthesisBuffer + 3 * (LocX + LocY * m_Width))
);
}
}
//
// DEFAULT CONSTRUCTOR:
//
CRGB24Synthesizer (
BOOLEAN FlipVertical
) :
m_FlipVertical (FlipVertical)
{
}
//
// CONSTRUCTOR:
//
CRGB24Synthesizer (
BOOLEAN FlipVertical,
ULONG Width,
ULONG Height
) :
CImageSynthesizer (Width, Height),
m_FlipVertical (FlipVertical)
{
}
//
// DESTRUCTOR:
//
virtual
~CRGB24Synthesizer (
)
{
}
};
/*************************************************
CYUVSynthesizer
Image synthesizer for YUV format.
*************************************************/
class CYUVSynthesizer : public CImageSynthesizer {
private:
const static UCHAR Colors [MAX_COLOR][3];
BOOLEAN m_Parity;
public:
//
// PutPixel():
//
// Place a pixel at a specific cursor location. *ImageLocation must
// reside within the synthesis buffer.
//
virtual void
PutPixel (
PUCHAR *ImageLocation,
COLOR Color
)
{
BOOLEAN Parity = (((*ImageLocation - m_SynthesisBuffer) & 0x2) != 0);
#if DBG
//
// Check that the current pixel points to a valid start pixel
// in the UYVY buffer.
//
BOOLEAN Odd = (((*ImageLocation - m_SynthesisBuffer) & 0x1) != 0);
NT_ASSERT ((m_Parity && Odd) || (!m_Parity && !Odd));
#endif // DBG
if (Color != TRANSPARENT) {
if (Parity) {
*(*ImageLocation)++ = Colors [(ULONG)Color][1];
} else {
*(*ImageLocation)++ = Colors [(ULONG)Color][0];
*(*ImageLocation)++ = Colors [(ULONG)Color][1];
*(*ImageLocation)++ = Colors [(ULONG)Color][2];
}
} else {
*ImageLocation += (Parity ? 1 : 3);
}
}
//
// PutPixel():
//
// Place a pixel at the default cursor location. The cursor location
// must be set via GetImageLocation(x, y).
//
virtual void
PutPixel (
COLOR Color
)
{
if (Color != TRANSPARENT) {
if (m_Parity) {
*m_Cursor++ = Colors [(ULONG)Color][1];
} else {
*m_Cursor++ = Colors [(ULONG)Color][0];
*m_Cursor++ = Colors [(ULONG)Color][1];
*m_Cursor++ = Colors [(ULONG)Color][2];
}
} else {
m_Cursor += (m_Parity ? 1 : 3);
}
m_Parity = !m_Parity;
}
virtual PUCHAR
GetImageLocation (
ULONG LocX,
ULONG LocY
)
{
m_Cursor = m_SynthesisBuffer + ((LocX + LocY * m_Width) << 1);
if (m_Parity = ((LocX & 1) != 0))
m_Cursor++;
return m_Cursor;
}
//
// DEFAULT CONSTRUCTOR:
//
CYUVSynthesizer (
)
{
}
//
// CONSTRUCTOR:
//
CYUVSynthesizer (
ULONG Width,
ULONG Height
) :
CImageSynthesizer (Width, Height)
{
}
//
// DESTRUCTOR:
//
virtual
~CYUVSynthesizer (
)
{
}
};
|