6 * Portable Windows Library
8 * Copyright (c) 2003 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Contributor(s): ______________________________________.
27 * Revision 1.3 2003/05/15 00:52:47 rjongbloed
28 * Fixed focus continually going to the video display window.
30 * Revision 1.2 2003/05/14 07:52:36 rjongbloed
31 * Fixed some trace logs.
33 * Revision 1.1 2003/03/17 07:40:58 robertj
34 * Added classes for video output device that displays in a PWlib window.
39 #pragma implementation "vidwin.h"
44 #include <pwclib/vidwin.h>
45 #include <ptlib/vconvert.h>
51 ///////////////////////////////////////////////////////////////
53 PVideoOutputWindow::PVideoOutputWindow()
55 preferredColourFormat
= "RGB24";
56 SetColourFormat(preferredColourFormat
);
63 PVideoOutputWindow::~PVideoOutputWindow()
69 BOOL
PVideoOutputWindow::Open(const PString
& /*deviceName*/,
70 BOOL
/*startImmediate*/)
76 BOOL
PVideoOutputWindow::Open(PInteractor
* i
)
78 PWaitAndSignal
wait(mutex
);
80 interactor
= PAssertNULL(i
);
81 return interactor
!= NULL
;
85 BOOL
PVideoOutputWindow::IsOpen()
87 PWaitAndSignal
wait(mutex
);
88 return interactor
!= NULL
;
92 BOOL
PVideoOutputWindow::Close()
95 PInteractor
* i
= interactor
;
106 PStringList
PVideoOutputWindow::GetDeviceNames() const
109 list
+= "PVideoOutputFloatingDialog";
114 BOOL
PVideoOutputWindow::SetColourFormat(const PString
& colourFormat
)
116 if (colourFormat
!= "RGB24" && colourFormat
!= "RGB32")
119 return PVideoOutputDevice::SetColourFormat(colourFormat
);
123 BOOL
PVideoOutputWindow::SetFrameSize(unsigned width
, unsigned height
)
125 PWaitAndSignal
wait(mutex
);
127 if (interactor
== NULL
)
130 if (image
.IsNULL() ||
131 image
->Width() != (PDIMENSION
)width
||
132 image
->Height() != (PDIMENSION
)height
) {
134 unsigned bitsPerPixel
= 32;
135 if (colourFormat
== "RGB24")
138 PTRACE(3, "PWLib\tNew video output to window size set: "
139 << width
<< 'x' << height
<< 'x' << bitsPerPixel
<< " bit");
141 image
= PPixelImage(width
, height
, bitsPerPixel
);
144 if (firstResize
|| frameWidth
!= width
|| frameHeight
!= height
) {
145 interactor
->SetDimensions(width
, height
, PInteractor::PixelCoords
);
150 return PVideoOutputDevice::SetFrameSize(width
, height
);
154 PINDEX
PVideoOutputWindow::GetMaxFrameBytes()
156 PWaitAndSignal
wait(mutex
);
161 return image
->GetPixelDataSize();
165 BOOL
PVideoOutputWindow::SetFrameData(unsigned x
, unsigned y
,
166 unsigned width
, unsigned height
,
167 const BYTE
* data
, BOOL endFrame
)
169 PWaitAndSignal
wait(mutex
);
171 if (interactor
== NULL
|| image
.IsNULL())
174 if (x
== 0 && y
== 0 && width
== frameWidth
&& height
== frameHeight
) {
175 if (converter
!= NULL
)
176 converter
->Convert(data
, image
->GetPixelDataPtr());
178 memcpy(image
->GetPixelDataPtr(), data
, image
->GetPixelDataSize());
181 if (converter
!= NULL
)
183 for (unsigned dy
= 0; dy
< height
; dy
++)
184 image
->SetRaster(x
, y
+dy
, data
+dy
*width
*3, width
);
194 BOOL
PVideoOutputWindow::EndFrame()
196 PWaitAndSignal
wait(mutex
);
198 if (interactor
== NULL
|| image
.IsNULL())
201 interactor
->Invalidate();
206 void PVideoOutputWindow::OnRedraw(PCanvas
& redrawCanvas
)
209 redrawCanvas
.DrawPixels(0, 0, image
);
213 ///////////////////////////////////////////////////////////////
215 PVideoOutputFloatingDialog::PVideoOutputFloatingDialog(PInteractor
* parent
,
216 PVideoOutputWindow
* dev
)
217 : PFloatingDialog(parent
),
223 void PVideoOutputFloatingDialog::OnClose()
226 PFloatingDialog::OnClose();
230 void PVideoOutputFloatingDialog::OnCancel()
237 void PVideoOutputFloatingDialog::OnRedraw(PCanvas
& canvas
)
241 device
->OnRedraw(canvas
);
246 void PVideoOutputFloatingDialog::CloseDevice()
250 if (device
!= NULL
) {
260 // End Of File ///////////////////////////////////////////////////////////////