Uncommented beaudio code
[pwlib.git] / src / pwclib / vidwin.cxx
blob2e69d089cec750521ffd30975748f3e418523c3f
1 /*
2 * vidwin.cxx
4 * Video output window.
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
18 * under the License.
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Contributor(s): ______________________________________.
26 * $Log$
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.
38 #ifdef __GNUC__
39 #pragma implementation "vidwin.h"
40 #endif
42 #include <pwlib.h>
44 #include <pwclib/vidwin.h>
45 #include <ptlib/vconvert.h>
48 #define new PNEW
51 ///////////////////////////////////////////////////////////////
53 PVideoOutputWindow::PVideoOutputWindow()
55 preferredColourFormat = "RGB24";
56 SetColourFormat(preferredColourFormat);
58 interactor = NULL;
59 firstResize = TRUE;
63 PVideoOutputWindow::~PVideoOutputWindow()
65 Close();
69 BOOL PVideoOutputWindow::Open(const PString & /*deviceName*/,
70 BOOL /*startImmediate*/)
72 return IsOpen();
76 BOOL PVideoOutputWindow::Open(PInteractor * i)
78 PWaitAndSignal wait(mutex);
79 delete interactor;
80 interactor = PAssertNULL(i);
81 return interactor != NULL;
85 BOOL PVideoOutputWindow::IsOpen()
87 PWaitAndSignal wait(mutex);
88 return interactor != NULL;
92 BOOL PVideoOutputWindow::Close()
94 mutex.Wait();
95 PInteractor * i = interactor;
96 interactor = NULL;
97 mutex.Signal();
99 if (i != NULL)
100 i->Close();
102 return TRUE;
106 PStringList PVideoOutputWindow::GetDeviceNames() const
108 PStringList list;
109 list += "PVideoOutputFloatingDialog";
110 return list;
114 BOOL PVideoOutputWindow::SetColourFormat(const PString & colourFormat)
116 if (colourFormat != "RGB24" && colourFormat != "RGB32")
117 return FALSE;
119 return PVideoOutputDevice::SetColourFormat(colourFormat);
123 BOOL PVideoOutputWindow::SetFrameSize(unsigned width, unsigned height)
125 PWaitAndSignal wait(mutex);
127 if (interactor == NULL)
128 return FALSE;
130 if (image.IsNULL() ||
131 image->Width() != (PDIMENSION)width ||
132 image->Height() != (PDIMENSION)height) {
134 unsigned bitsPerPixel = 32;
135 if (colourFormat == "RGB24")
136 bitsPerPixel = 24;
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);
146 interactor->Show();
147 firstResize = FALSE;
150 return PVideoOutputDevice::SetFrameSize(width, height);
154 PINDEX PVideoOutputWindow::GetMaxFrameBytes()
156 PWaitAndSignal wait(mutex);
158 if (image.IsNULL())
159 return 0;
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())
172 return FALSE;
174 if (x == 0 && y == 0 && width == frameWidth && height == frameHeight) {
175 if (converter != NULL)
176 converter->Convert(data, image->GetPixelDataPtr());
177 else
178 memcpy(image->GetPixelDataPtr(), data, image->GetPixelDataSize());
180 else {
181 if (converter != NULL)
182 return FALSE;
183 for (unsigned dy = 0; dy < height; dy++)
184 image->SetRaster(x, y+dy, data+dy*width*3, width);
187 if (endFrame)
188 return EndFrame();
190 return TRUE;
194 BOOL PVideoOutputWindow::EndFrame()
196 PWaitAndSignal wait(mutex);
198 if (interactor == NULL || image.IsNULL())
199 return FALSE;
201 interactor->Invalidate();
202 return TRUE;
206 void PVideoOutputWindow::OnRedraw(PCanvas & redrawCanvas)
208 if (!image.IsNULL())
209 redrawCanvas.DrawPixels(0, 0, image);
213 ///////////////////////////////////////////////////////////////
215 PVideoOutputFloatingDialog::PVideoOutputFloatingDialog(PInteractor * parent,
216 PVideoOutputWindow * dev)
217 : PFloatingDialog(parent),
218 device(dev)
223 void PVideoOutputFloatingDialog::OnClose()
225 CloseDevice();
226 PFloatingDialog::OnClose();
230 void PVideoOutputFloatingDialog::OnCancel()
232 CloseDevice();
233 Close();
237 void PVideoOutputFloatingDialog::OnRedraw(PCanvas & canvas)
239 mutex.Wait();
240 if (device != NULL)
241 device->OnRedraw(canvas);
242 mutex.Signal();
246 void PVideoOutputFloatingDialog::CloseDevice()
248 mutex.Wait();
250 if (device != NULL) {
251 device->Close();
252 device = NULL;
255 mutex.Signal();
260 // End Of File ///////////////////////////////////////////////////////////////