| 1 | /* |
|---|
| 2 | * QuteCom, a voice over Internet phone |
|---|
| 3 | * Copyright (C) 2010 Mbdsys |
|---|
| 4 | * |
|---|
| 5 | * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | * it under the terms of the GNU General Public License as published by |
|---|
| 7 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | * (at your option) any later version. |
|---|
| 9 | * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | * GNU General Public License for more details. |
|---|
| 14 | * |
|---|
| 15 | * You should have received a copy of the GNU General Public License |
|---|
| 16 | * along with this program; if not, write to the Free Software |
|---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #include "VideoWindow.h" |
|---|
| 21 | |
|---|
| 22 | #include <webcam/WebcamDriver.h> |
|---|
| 23 | |
|---|
| 24 | #include <util/SafeConnect.h> |
|---|
| 25 | #include <util/SafeDelete.h> |
|---|
| 26 | |
|---|
| 27 | #include <QtGui/QtGui> |
|---|
| 28 | |
|---|
| 29 | VideoWindow::VideoWindow() |
|---|
| 30 | : QWidget() { |
|---|
| 31 | |
|---|
| 32 | SAFE_CONNECT(WebcamDriver::getInstance(), SIGNAL(frameCapturedSignal(piximage *)), |
|---|
| 33 | SLOT(frameCapturedSlot(piximage *))); |
|---|
| 34 | |
|---|
| 35 | setMaximumSize(320, 240); |
|---|
| 36 | setMinimumSize(320, 240); |
|---|
| 37 | resize(320, 240); |
|---|
| 38 | |
|---|
| 39 | _image = NULL; |
|---|
| 40 | _rgbImage = pix_alloc(PIX_OSI_RGB32, 320, 240); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | VideoWindow::~VideoWindow() { |
|---|
| 44 | pix_free(_rgbImage); |
|---|
| 45 | OWSAFE_DELETE(_image); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | void VideoWindow::frameCapturedSlot(piximage * image) { |
|---|
| 49 | QMutexLocker locker(&_mutex); |
|---|
| 50 | |
|---|
| 51 | pix_convert(PIX_NO_FLAG, _rgbImage, image); |
|---|
| 52 | |
|---|
| 53 | OWSAFE_DELETE(_image); |
|---|
| 54 | _image = new QImage(QSize(width(), height()), QImage::Format_ARGB32); |
|---|
| 55 | |
|---|
| 56 | memcpy(_image->bits(), _rgbImage->data, _rgbImage->width * _rgbImage->height * 4); |
|---|
| 57 | |
|---|
| 58 | update(); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | void VideoWindow::mouseReleaseEvent(QMouseEvent * event) { |
|---|
| 62 | VideoWindow * newWindow = new VideoWindow(); |
|---|
| 63 | newWindow->show(); |
|---|
| 64 | |
|---|
| 65 | QWidget::mouseReleaseEvent(event); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | void VideoWindow::paintEvent(QPaintEvent *) { |
|---|
| 69 | QMutexLocker locker(&_mutex); |
|---|
| 70 | |
|---|
| 71 | QPainter painter(this); |
|---|
| 72 | if (_image) { |
|---|
| 73 | painter.drawImage(0, 0, *_image, 0, 0, _image->width(), _image->height()); |
|---|
| 74 | } |
|---|
| 75 | } |
|---|