-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayer.cpp
152 lines (131 loc) · 3.79 KB
/
player.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
#include "player.h"
#include "ui_player.h"
#include <QtDebug>
#include <QFileDialog>
#include <QFile>
#include <QPixmap>
#include <QTimer>
Player::Player(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::Player)
{
ui->setupUi(this);
ui->scrollArea->init();
// imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
timer = new QTimer(this);
}
Player::~Player()
{
delete ui;
if (seq) {
delete seq;
}
if (timer) {
timer->stop();
delete timer;
}
}
void Player::openYuvFile()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("open YUV"), QString("F:/seq/vvc"));
ui->seqNameLabel->setText(fileName);
seq = new Sequence(fileName);
}
void Player::on_OpenButton_clicked()
{
openYuvFile();
ui->widthBox->setValue(seq->getWidth());
ui->heightBox->setValue(seq->getHeight());
ui->depthBox->setValue(seq->getDepth());
ui->frateBox->setValue(seq->getFrate());
ui->maxFrameLabel->setText(QString::number(seq->getMaxFrame()));
on_nextButton_clicked();
}
void Player::on_updateButton_clicked()
{
ui->scrollArea->setImg(rgb);
}
void Player::on_nextButton_clicked()
{
rgb = seq->nextFrame();
ui->gotoEdit->setText(QString::number(seq->getCurFrame()));
ui->scrollArea->setImg(rgb);
}
void Player::on_prevButton_clicked()
{
rgb = seq->prevFrame();
ui->gotoEdit->setText(QString(seq->getCurFrame()));
ui->scrollArea->setImg(rgb);
}
void Player::on_playButton_clicked()
{
connect(timer, &QTimer::timeout, this, &Player::on_nextButton_clicked);
int interval = int(1000 / seq->getFrate());
timer->start(interval);
}
void Player::on_stopButton_clicked()
{
timer->stop();
}
void Player::on_gotoButton_clicked()
{
bool ok;
int frame = ui->gotoEdit->text().toInt(&ok);
if (ok) {
QImage *newRgb = seq->gotoFrame(frame);
if (newRgb) {
rgb = newRgb;
ui->gotoEdit->setText(QString::number(seq->getCurFrame()));
ui->scrollArea->setImg(rgb);
}
}
}
void Player::on_heightBox_valueChanged(int height)
{
if (height != seq->getHeight()) {
qDebug() << "set height from" << seq->getHeight() << "to" << height << endl;
SeqError error = seq->setWidth(height);
if (error == SEQ_INVALID_FILE_SIZE) {
ui->logText->append(QString("The file size is not divisible by the number of bytes per frame."));
} else {
ui->logText->append(QString("Height changed."));
}
rgb = seq->nextFrame();
ui->scrollArea->setImg(rgb);
}
}
void Player::on_widthBox_valueChanged(int width)
{
if (width != seq->getWidth()) {
qDebug() << "set width from" << seq->getWidth() << "to" << width << endl;
SeqError error = seq->setWidth(width);
if (error == SEQ_INVALID_FILE_SIZE) {
ui->logText->append(QString("The file size is not divisible by the number of bytes per frame."));
} else {
ui->logText->append(QString("Width changed."));
}
rgb = seq->nextFrame();
ui->scrollArea->setImg(rgb);
}
}
void Player::on_depthBox_valueChanged(int depth)
{
if (depth != seq->getDepth()) {
qDebug() << "set depth from" << seq->getDepth() << "to" << depth << endl;
SeqError error = seq->setDepth(depth);
if (error == SEQ_INVALID_DEPTH) {
ui->logText->append(QString("Only 8bit ~ 16bit are supported."));
} else {
ui->logText->append(QString("Depth changed."));
}
rgb = seq->nextFrame();
ui->scrollArea->setImg(rgb);
}
}
void Player::on_frateBox_valueChanged(int frate)
{
if (frate != seq->getFrate()) {
qDebug() << "set frate from" << seq->getFrate() << "to" << frate << endl;
seq->setFrate(frate);
}
}