-
Notifications
You must be signed in to change notification settings - Fork 1
/
mycamera.cpp
159 lines (139 loc) · 5.31 KB
/
mycamera.cpp
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
#include "mycamera.h"
#include <QPainter>
#include <QTimer>
#include <QDebug>
#include <QStyleOptionGraphicsItem>
#include <QVideoRendererControl>
#include <QPaintEvent>
#include <QPaintEngine>
MyCamera::MyCamera(QDeclarativeItem *parent) :
QDeclarativeItem(parent)
{
setFlag(QGraphicsItem::ItemHasNoContents, false);
videoSurface = new myVideoSurface();
m_camera = new QCamera(this);
//m_camera->setViewfinder(videoSurface);
m_camera->setCaptureMode(QCamera::CaptureStillImage);
QVideoRendererControl *control = (QVideoRendererControl*)
m_camera->service()->requestControl("com.nokia.Qt.QVideoRendererControl/1.0");
if(control){
control->setSurface(videoSurface);
qDebug()<<control->surface();
}
//videoSurface->start(QVideoSurfaceFormat(QSize(480, 360), QVideoFrame::Format_RGB24));
m_camera->start();
QTimer *timer = new QTimer();
timer->start(400);
connect(timer,SIGNAL(timeout()),this,SLOT(repaint()));
connect(m_camera,SIGNAL(error(QCamera::Error)),this,SLOT(output(QCamera::Error)));
qDebug()<<"error" << m_camera->error() <<" "<< m_camera->errorString();
qDebug()<<"VS active"<< videoSurface->isActive();
qDebug()<<"Available "<<m_camera->isAvailable();
qDebug()<<"State " <<m_camera->state();
qDebug()<<"Status " << m_camera->status();
qDebug()<<"Locked " <<m_camera->lockStatus();
qDebug()<<"Capture mode supported " << m_camera->isCaptureModeSupported(QCamera::CaptureStillImage);
}
void MyCamera::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
if (m_camera->status() == QCamera::UnloadedStatus)
m_camera->start();
qDebug()<<"Repaint";
//if (videoSurface->backBuffer.format()!=QImage::Format_Invalid && !videoSurface->backBuffer.isNull()) {
qDebug()<<"Image painted "<< videoSurface->backBuffer.size();
painter->drawImage(this->boundingRect(),videoSurface->backBuffer);
//}
painter->setPen(Qt::black);
painter->drawRect(0,0,300,300);
}
void MyCamera::output(QCamera::Error err)
{
qDebug()<<err;
}
void MyCamera::repaint()
{
this->update();
}
/*MySurface::MySurface(QObject *parent) : QAbstractVideoSurface(parent)
{
currentFrame = QImage();
//backBuffer = new QImage;
m_imageFormat = QImage::Format_Invalid;
}
bool MySurface::isFormatSupported ( const QVideoSurfaceFormat & format ) const
{
qDebug()<<"Format wird unterstützt...." << format;
return true;
}
QList<QVideoFrame::PixelFormat> MySurface::supportedPixelFormats(
QAbstractVideoBuffer::HandleType handleType) const
{
QList<QVideoFrame::PixelFormat> formats;
formats << QVideoFrame::Format_Invalid;
formats << QVideoFrame::Format_YUV444;
formats << QVideoFrame::Format_RGB24;
formats << QVideoFrame::Format_RGB32;
formats << QVideoFrame::Format_RGB24;
formats << QVideoFrame::Format_YUYV;
formats << QVideoFrame::Format_UYVY;
formats << QVideoFrame::Format_YV12;
formats << QVideoFrame::Format_AYUV444;
formats << QVideoFrame::Format_YUV420P;
formats << QVideoFrame::Format_Y16;
formats << QVideoFrame::Format_Y8;
formats << QVideoFrame::Format_IMC1;
formats << QVideoFrame::Format_IMC2;
formats << QVideoFrame::Format_IMC3;
formats << QVideoFrame::Format_IMC4;
formats << QVideoFrame::Format_AYUV444_Premultiplied;
formats << QVideoFrame::Format_ARGB32_Premultiplied;
formats << QVideoFrame::Format_RGB565;
formats << QVideoFrame::Format_RGB555;
formats << QVideoFrame::Format_ARGB8565_Premultiplied;
formats << QVideoFrame::Format_BGRA32;
formats << QVideoFrame::Format_BGRA32_Premultiplied;
formats << QVideoFrame::Format_BGR32;
formats << QVideoFrame::Format_BGR24;
formats << QVideoFrame::Format_BGR565;
formats << QVideoFrame::Format_BGR555;
formats << QVideoFrame::Format_BGRA5658_Premultiplied;
formats << QVideoFrame::Format_NV12;
formats << QVideoFrame::Format_NV21;
formats << QVideoFrame::Format_Jpeg;
formats << QVideoFrame::Format_CameraRaw;
formats << QVideoFrame::Format_AdobeDng;
qDebug()<<"Format abgefragt...";
return formats;
}
QVideoSurfaceFormat MySurface::nearestFormat ( const QVideoSurfaceFormat & format ) const
{
qDebug()<< "Asking for nearest format...got"<<format;
return QVideoSurfaceFormat ();
}
bool MySurface::present(const QVideoFrame & frame)
{
QVideoFrame newFrame(frame);
newFrame.map(QAbstractVideoBuffer::ReadOnly);
//Flip front and backbuffer
//QImage *tmp = currentFrame;
currentFrame = QImage(newFrame.bits(),newFrame.width(),newFrame.height(),m_imageFormat);
//if(!currentFrame.save("testimage.jpg"))
// qDebug()<<"Could not save image";
backBuffer = currentFrame.convertToFormat(QImage::Format_ARGB32);
qDebug()<<"Presenting frame "<< frame.isMapped() << " "<< frame.isValid() << " " << frame.isReadable() << " " << frame.pixelFormat()<< " "<<frame.size();
newFrame.unmap();
qDebug()<<"Video frame unmapped";
return true;
}
bool MySurface::start(const QVideoSurfaceFormat & format)
{
qDebug()<< "Video Surface started";
m_videoFormat = format;
m_imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
QAbstractVideoSurface::start(format);
return true;
}
void MySurface::stop()
{
QAbstractVideoSurface::stop();
}*/