blob: b727679bd646134e124af8f212d4426083d37a83 (
plain)
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
|
/* Copyright (c) 2012 Patrick Ruoff
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*/
#include "ar_video_widget.h"
#include <QDebug>
using namespace std;
void ArucoVideoWidget::update_image(unsigned char *frame, int width, int height)
{
QMutexLocker foo(&mtx);
memcpy(fb, frame, width * height * 3);
this->width = width;
this->height = height;
}
void ArucoVideoWidget::update_and_repaint()
{
QMutexLocker foo(&mtx);
if (width*height <= 0)
return;
QImage qframe = QImage(width, height, QImage::Format_RGB888);
uchar* data = qframe.bits();
const int pitch = qframe.bytesPerLine();
for (int y = 0; y < height; y++)
{
const int part = y*width;
for (int x = 0; x < width; x++)
{
const int pos = 3 * (part + x);
data[y * pitch + x * 3 + 0] = fb[pos + 2];
data[y * pitch + x * 3 + 1] = fb[pos + 1];
data[y * pitch + x * 3 + 2] = fb[pos + 0];
}
}
auto qframe2 = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation);
pixmap = QPixmap::fromImage(qframe2);
update();
}
|