forked from jmerdich/aeo-light
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilmScan.h
203 lines (173 loc) · 5.78 KB
/
FilmScan.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//-----------------------------------------------------------------------------
// This file is part of AEO-Light
//
// Copyright (c) 2016 University of South Carolina
//
// This program 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.
//
// AEO-Light 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 this program; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Funding for AEO-Light development was provided through a grant from the
// National Endowment for the Humanities
//-----------------------------------------------------------------------------
// FilmScan -- objects for handling scanned images of film.
//
// FilmFrame - a scan of a single frame
// FilmStrip - a sequence of FilmFrames (usually short; not the entire film)
// FilmScan - the main interface to a scanned film source (not used currently,
// see project.h instead for an object that holds the working
// project).
// SoundSignal - a sequence of values (doubles) for the sound extracted from
// the film scan
//
//
#ifndef FILMSCAN_H
#define FILMSCAN_H
#define USELIBAV
#ifdef USELIBAV
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
#include <libavutil/timecode.h>
}
#endif
#include <vector>
#include "wav.h"
#include "videoencoder.h"
#include <QOpenGLTexture>
#ifdef USE_OPENEXR
#include <OpenEXR/ImfRgbaFile.h>
#endif
class FilmFrame {
private:
std::vector <double> buf;
unsigned int rows, cols;
public:
FilmFrame() : buf(), rows(0), cols(0) {} ;
FilmFrame(unsigned int r, unsigned int c);
~FilmFrame();
// data() is only available in C++11, so use the old &(p[0]) construction
//double *operator[](unsigned int r) { return buf.data()+(r*cols); } ;
//operator double*() { return buf.data(); }
double *operator[](unsigned int r) { return &(buf[r*cols]); } ;
operator double*() { return &(buf[0]); }
unsigned int Width() const { return cols; } ;
unsigned int Height() const { return rows; } ;
unsigned int Cols() const { return cols; } ;
unsigned int Rows() const { return rows; } ;
};
typedef std::vector< FilmFrame > FilmStrip;
typedef std::vector< double > SoundSignal;
#ifdef USELIBAV
class Video {
public:
AVFormatContext *format;
AVCodecContext *codec;
int streamIdx;
SwsContext *convertRGB;
SwsContext *convertGray16;
AVFrame *frameNative;
AVFrame *frameRGB;
AVFrame *frameGray16;
size_t curFrame;
size_t dts;
size_t dtsBase; // DTS of first frame
size_t dtsStep; // DTS between frames
Video()
: format(NULL), codec(NULL), streamIdx(0),
convertRGB(NULL), convertGray16(NULL),
frameNative(NULL), frameRGB(NULL), frameGray16(NULL),
curFrame(0), dts(0), dtsBase(0), dtsStep(1) {};
~Video();
public:
bool ReadNextFrame(size_t currFrameNum);
bool ReadFrame(size_t frameNum);
double *GetFrame(size_t frameNum, double *buf);
unsigned char *GetFrameImage(size_t frameNum, unsigned char *buf,
int &width,int &height,bool &endian);
};
#endif
typedef int SourceFormat;
#define SOURCE_DPX 0
#define SOURCE_EXR 1
#define SOURCE_TIFF 2
#define SOURCE_OTHER_IMG 3
#define SOURCE_LIBAV 4
#define SOURCE_WAV 5
#define SOURCE_UNKNOWN 6
#define SOURCE_ALL 7
class FilmScan {
private:
char *name;
char *path;
char *fnbuf;
SourceFormat srcFormat;
long firstFrame;
long numFrames;
unsigned int width;
unsigned int height;
#ifdef USELIBAV
Video *vid = NULL;
#endif
wav *synth = NULL;
std::string inputName;
public:
QString TimeCode;
public:
#ifdef USELIBAV
FilmScan()
: name(NULL), path(NULL), fnbuf(NULL),
firstFrame(0), numFrames(0), width(0), height(0), vid(NULL) {} ;
#else
FilmScan()
: name(NULL), path(NULL), fnbuf(NULL),
firstFrame(0), numFrames(0), width(0), height(0) {} ;
#endif
FilmScan(const std::string filename) { Source(filename); };
~FilmScan();
void Reset();
int getType(const std::string filename);
bool Source(const std::string filename, SourceFormat fmt=SOURCE_UNKNOWN);
bool SourceDPX(const std::string filename);
bool SourceEXR(const std::string filename);
bool SourceTIFF(const std::string filename);
bool SourceLibAV(const std::string filename);
bool SourceWav(const std::string filename);
bool SourceIdentifyImageSet(const std::string filename);
bool IsReady() const { return (numFrames>0); };
long NumFrames() const { return numFrames; };
long FirstFrame() const { return firstFrame; };
long LastFrame() const { return firstFrame + numFrames - 1; };
unsigned int Width() const { return width; };
unsigned int Height() const { return height; };
std::string GetFileName() const { return inputName; }
SourceFormat GetFormat() const { return srcFormat; }
const char *GetFormatStr() const;
static SourceFormat StrToSourceFormat(const char *str);
const char *GetPath() const { return path; }
const char *GetBaseName() const { return name; }
double *GetFrame(long frameNum, double *buf) const;
FrameTexture *GetFrameImage(long frameNum, FrameTexture *frame) const;
FilmFrame GetFrame(long frameNum) const;
FilmStrip GetFrameRange(long frameRange[2]) const;
double *GetSoundSignal(long frameNum, unsigned int l,
unsigned int r) const;
SoundSignal GetSoundLocal(FilmFrame frame, unsigned int l,
unsigned int r) const;
bool IsSynth(void) const { return (synth != NULL); };
int SynthOverlap(void) const { return (synth? synth->GetOverlap() : 0); };
};
#endif