Skip to content

Commit

Permalink
demo 2 works
Browse files Browse the repository at this point in the history
A QPixmap is randomly created and updated on the image item.
  • Loading branch information
vijiboy committed Jan 4, 2016
1 parent f2e1026 commit 2e8a15a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
20 changes: 0 additions & 20 deletions VideoCaptureControls.qml
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,6 @@ FocusScope {
id: buttonsColumn
spacing: 8

Image{
id : currentFrame
source: "image://updatedframeprovider/yellow"
cache: false
asynchronous: false //true
}

Timer {
interval: 1000
repeat: true
running: true
onTriggered: { currentFrame.source = ""; currentFrame.source = "image://updatedframeprovider/red" }
}
Timer {
interval: 1500
repeat: true
running: true
onTriggered: { currentFrame.source = ""; currentFrame.source = "image://updatedframeprovider/yellow" }
}

CameraButton {
text: "Demo 2 (Toggle)"
visible: camera.cameraStatus == Camera.ActiveStatus
Expand Down
25 changes: 25 additions & 0 deletions VideoPreview.qml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ Item {
}
}

Image{
id : currentFrame
source: "image://updatedframeprovider/yellow"
cache: false
asynchronous: false //true
anchors.fill: parent
}

Timer {
interval: 1000
repeat: true
running: true
onTriggered: { currentFrame.source = ""; currentFrame.source = "image://updatedframeprovider/" + getRandomColor() }
}

VideoOutput {
source: player
anchors.fill : parent
Expand All @@ -68,5 +83,15 @@ Item {
videoPreview.closed();
}
}

function getRandomColor() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}

}

2 changes: 1 addition & 1 deletion declarative-camera.qml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Rectangle {

VideoOutput {
id: viewfinder
visible: cameraUI.state == "PhotoCapture" || cameraUI.state == "PhotoPreview"
visible: cameraUI.state == "PhotoCapture" || cameraUI.state == "PhotoPreview" || cameraUI.state == "VideoCapture"

filters: cameraUI.state == "PhotoPreview" ? [filter]: "" // adding the video filter

Expand Down
21 changes: 17 additions & 4 deletions qmlcamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ class MyFilterRunnable : public QVideoFilterRunnable {
if (!input->isValid())
return *input;

// Note! Overwriting input buffer with a bigger image for demo purpose only
input->map(QAbstractVideoBuffer::ReadWrite);

// TODO: Get the current frame updated for Demo1 using the application object instance.

// DEMO ONLY CODE: Overwriting input buffer with a bigger image for demo purpose only ----
QVideoFrame *output = new QVideoFrame(input->width()*input->height()*2,
QSize(input->width()*2,input->height()),
input->width()*2,
QVideoFrame::Format_RGB32);
output->map(QAbstractVideoBuffer::ReadWrite);
//input->map(QAbstractVideoBuffer::ReadWrite);

// Modify the frame in format of your choice finally returning in frame format
// e.g. QVideoFrame to QImage or OpenCV (Cv::Mat) image to QVideoFrame
Expand All @@ -70,7 +73,9 @@ class MyFilterRunnable : public QVideoFilterRunnable {
outputBits[i] = 127; // graying out a strip from the image

output->unmap();
//input->unmap();
// DEMO ONLY CODE ends here -----

input->unmap();
//emit finished(input); //TODO: check if this works, can help in notifying

return *output;
Expand All @@ -94,7 +99,12 @@ class ColorImageProvider : public QQuickImageProvider
}

QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
{ // This method, requestPixmap is called at regular interval to refresh the GUI by returning a new QPixmap

// For demo purpose we are creating a QPixmap, where a GetMyCurrentFrame API method can be called.

// TODO: use the application object instance to get the actual frame for Demo 2 here.

int width = 100;
int height = 50;

Expand All @@ -118,6 +128,9 @@ int main(int argc, char* argv[])
QQmlEngine *engine = view.engine();
engine->addImageProvider("updatedframeprovider",new ColorImageProvider);

// TODO: create/initialise the sole application object here to provide Demo1 and Demo2 frames.
// TODO: access this singleton application object in the run method and requestPixMap method defined earlier.

view.setResizeMode(QQuickView::SizeRootObjectToView);
// Qt.quit() called in embedded .qml by default only emits
// quit() signal, so do this (optionally use Qt.exit()).
Expand Down

0 comments on commit 2e8a15a

Please sign in to comment.