zxing/symbian/QQrDecoder/MyVideoSurface.cpp
ftylitak@gmail.com f0e371d622 Updated QQrDecoder (ZXing + Qt).
Added zoom functionality + autofocus + automatic detection (at the immediate previous version the user had to press a button to initiate decoding).

git-svn-id: https://zxing.googlecode.com/svn/trunk@1925 59b500cc-1b3d-0410-9834-0bbf25fbcc57
2011-09-21 08:15:08 +00:00

101 lines
2.8 KiB
C++

#include "myvideosurface.h"
MyVideoSurface::MyVideoSurface(QWidget* widget, VideoIF* target, QObject* parent)
: QAbstractVideoSurface(parent)
{
m_targetWidget = widget;
m_target = target;
m_imageFormat = QImage::Format_Invalid;
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(sendImageToDecode()));
timer->start(500);
}
MyVideoSurface::~MyVideoSurface()
{
}
bool MyVideoSurface::start(const QVideoSurfaceFormat &format)
{
m_videoFormat = format;
const QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
const QSize size = format.frameSize();
if (imageFormat != QImage::Format_Invalid && !size.isEmpty()) {
m_imageFormat = imageFormat;
QAbstractVideoSurface::start(format);
return true;
} else {
return false;
}
}
bool MyVideoSurface::present(const QVideoFrame &frame)
{
m_frame = frame;
if (surfaceFormat().pixelFormat() != m_frame.pixelFormat() ||
surfaceFormat().frameSize() != m_frame.size()) {
stop();
return false;
} else {
m_target->updateVideo();
return true;
}
}
void MyVideoSurface::paint(QPainter *painter)
{
if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) {
QImage image(
m_frame.bits(),
m_frame.width(),
m_frame.height(),
m_frame.bytesPerLine(),
m_imageFormat);
QRect r = m_targetWidget->rect();
QPoint centerPic((qAbs(r.size().width() - image.size().width())) / 2, (qAbs(
r.size().height() - image.size().height())) / 2);
if (!image.isNull()) {
painter->drawImage(centerPic,image);
}
m_frame.unmap();
}
}
QList<QVideoFrame::PixelFormat> MyVideoSurface::supportedPixelFormats(
QAbstractVideoBuffer::HandleType handleType) const
{
if (handleType == QAbstractVideoBuffer::NoHandle) {
return QList<QVideoFrame::PixelFormat>()
<< QVideoFrame::Format_RGB32
<< QVideoFrame::Format_ARGB32
<< QVideoFrame::Format_ARGB32_Premultiplied
<< QVideoFrame::Format_RGB565
<< QVideoFrame::Format_RGB555;
} else {
return QList<QVideoFrame::PixelFormat>();
}
}
void MyVideoSurface::sendImageToDecode()
{
if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) {
QImage image(
m_frame.bits(),
m_frame.width(),
m_frame.height(),
m_frame.bytesPerLine(),
m_imageFormat);
if (!image.isNull())
emit imageCaptured(image);
m_frame.unmap();
}
}