-
Notifications
You must be signed in to change notification settings - Fork 1
/
y4mparser.cpp
85 lines (70 loc) · 1.59 KB
/
y4mparser.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
#include "y4mparser.h"
#include <QStringList>
Y4mParser::Y4mParser()
{
}
int Y4mParser::getHeight(QString filename)
{
int height;
height = getParameter('H',filename).toInt();
return height;
}
int Y4mParser::getWidth(QString filename)
{
int width;
width = getParameter('W',filename).toInt();
return width;
}
double Y4mParser::getFrameRate(QString filename)
{
double frameRate;
QString temp = getParameter('F',filename);
if(temp!=NULL)
{
QStringList list = temp.split(':');
if(list.length()!=2)
return NULL;
frameRate=list.at(0).toDouble()/list.at(1).toDouble();
}
return frameRate;
}
QString Y4mParser::getParameter(char parameter,QString filename)
{
FILE *file;
QString value;
char *header = new char[80];
char y4m_Delimiter[] {'Y','U','V','4','M','P','E','G','2',' '};
fopen_s(&file,filename.toStdString().c_str(),"r");
if(file==NULL)
{
error="Cannot open file for reading.";
return NULL;
}
if(fread_s(header,80,1,80,file)==80)
{
int i;
for(i=0;i<10;i++)
{
if(header[i]!=y4m_Delimiter[i])
{
error="Wrong y4m header.";
return NULL;
}
}
while(i<80)
{
if(header[i]==parameter)
{
i++;
while(header[i]!=' ')
{
value.append(header[i]);
i++;
}
return value;
}
i++;
}
}
return NULL;
}