forked from IENT/YUView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yuvfile.h
157 lines (122 loc) · 5.28 KB
/
yuvfile.h
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
/* YUView - YUV player with advanced analytics toolset
* Copyright (C) 2015 Institut für Nachrichtentechnik
* RWTH Aachen University, GERMANY
*
* YUView is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* YUView is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with YUView. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef YUVFILE_H
#define YUVFILE_H
#include <QObject>
#include <QFile>
#include <QtEndian>
#include <QFileInfo>
#include <QString>
#include <QDateTime>
#include <QCache>
#include "typedef.h"
#include <map>
class PixelFormat
{
public:
PixelFormat()
{
p_name = "";
p_bitsPerSample = 8;
p_bitsPerPixelNominator = 32;
p_bitsPerPixelDenominator = 1;
p_subsamplingHorizontal = 1;
p_subsamplingVertical = 1;
p_bytePerComponentSample = 1;
p_planar = true;
}
void setParams(QString name, int bitsPerSample, int bitsPerPixelNominator, int bitsPerPixelDenominator, int subsamplingHorizontal, int subsamplingVertical, bool isPlanar, int bytePerComponent=1)
{
p_name = name;
p_bitsPerSample = bitsPerSample;
p_bitsPerPixelNominator = bitsPerPixelNominator;
p_bitsPerPixelDenominator = bitsPerPixelDenominator;
p_subsamplingHorizontal = subsamplingHorizontal;
p_subsamplingVertical = subsamplingVertical;
p_planar = isPlanar;
p_bytePerComponentSample = bytePerComponent;
}
~PixelFormat() {}
QString name() { return p_name; }
int bitsPerSample() { return p_bitsPerSample; }
int bitsPerPixelNominator() { return p_bitsPerPixelNominator; }
int bitsPerPixelDenominator() { return p_bitsPerPixelDenominator; }
int subsamplingHorizontal() { return p_subsamplingHorizontal; }
int subsamplingVertical() { return p_subsamplingVertical; }
int isPlanar() { return p_planar; }
int bytePerComponent() {return p_bytePerComponentSample;}
private:
QString p_name;
int p_bitsPerSample;
int p_bitsPerPixelNominator;
int p_bitsPerPixelDenominator;
int p_subsamplingHorizontal;
int p_subsamplingVertical;
int p_bytePerComponentSample;
bool p_planar;
};
typedef std::map<YUVCPixelFormatType,PixelFormat> PixelFormatMapType;
class YUVFile : public QObject
{
Q_OBJECT
public:
explicit YUVFile(const QString &fname, QObject *parent = 0);
~YUVFile();
void extractFormat(int* width, int* height, int* numFrames, double* frameRate);
int getNumberFrames(int width, int height);
// reads one frame in YUV444 into target byte array
virtual void getOneFrame( QByteArray* targetByteArray, unsigned int frameIdx, int width, int height );
virtual QString fileName();
// methods for querying file information
virtual QString getPath() {return p_path;}
virtual QString getCreatedtime() {return p_createdtime;}
virtual QString getModifiedtime() {return p_modifiedtime;}
virtual qint64 getNumberBytes() {return getFileSize();}
virtual QString getStatus(int width, int height);
void setSrcPixelFormat(YUVCPixelFormatType newFormat) { p_srcPixelFormat = newFormat; emit yuvInformationChanged(); }
void setInterpolationMode(InterpolationMode newMode) { p_interpolationMode = newMode; emit yuvInformationChanged(); }
YUVCPixelFormatType pixelFormat() { return p_srcPixelFormat; }
InterpolationMode interpolationMode() { return p_interpolationMode; }
static PixelFormatMapType pixelFormatList();
static int verticalSubSampling(YUVCPixelFormatType pixelFormat);
static int horizontalSubSampling(YUVCPixelFormatType pixelFormat);
static int bitsPerSample(YUVCPixelFormatType pixelFormat);
static int bytesPerFrame(int width, int height, YUVCPixelFormatType cFormat);
static bool isPlanar(YUVCPixelFormatType pixelFormat);
static int bytePerComponent(YUVCPixelFormatType pixelFormat);
static void formatFromFilename(QString filePath, int* width, int* height, double* frameRate, int* numFrames,int* bitDepth, bool isYUV=true);
private:
QFile *p_srcFile;
QString p_path;
QString p_createdtime;
QString p_modifiedtime;
QByteArray p_tmpBufferYUV;
// YUV to RGB conversion
YUVCPixelFormatType p_srcPixelFormat;
InterpolationMode p_interpolationMode;
virtual qint64 getFileSize();
void convert2YUV444(QByteArray *sourceBuffer, int lumaWidth, int lumaHeight, QByteArray *targetBuffer);
static PixelFormatMapType g_pixelFormatList;
int readFrame( QByteArray *targetBuffer, unsigned int frameIdx, int width, int height );
// method tries to guess format information, returns 'true' on success
void formatFromCorrelation(int* width, int* height, YUVCPixelFormatType* cFormat, int* numFrames);
void readBytes( char* targetBuffer, unsigned int startPos, unsigned int length );
signals:
void yuvInformationChanged();
};
#endif // YUVFILE_H