forked from fuzzie/unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfvf_decoder.h
119 lines (90 loc) · 3.45 KB
/
fvf_decoder.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
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef FVF_DECODER_H
#define FVF_DECODER_H
#include "common/rational.h"
#include "video/video_decoder.h"
#include "image/codecs/codec.h"
#include "audio/audiostream.h"
#include "audio/mixer.h"
namespace Unity {
class FVFDecoder : public ::Video::VideoDecoder {
public:
FVFDecoder(Audio::Mixer *mixer,
Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType);
virtual ~FVFDecoder();
bool loadStream(Common::SeekableReadStream *stream);
void close();
bool isVideoLoaded() const { return _fileStream != 0; }
::Graphics::Surface *internalDecodeNextFrame();
::Graphics::PixelFormat getPixelFormat() const;
protected:
class FVFVideoTrack : public FixedRateVideoTrack {
public:
FVFVideoTrack(FVFDecoder *parent) : _parent(parent) { }
protected:
Common::Rational getFrameRate() const { return _parent->_frameRate; }
uint16 getWidth() const { return _parent->_width; }
uint16 getHeight() const { return _parent->_height; }
int getCurFrame() const { return _parent->_curFrame; }
const ::Graphics::Surface *decodeNextFrame() { return _parent->internalDecodeNextFrame(); }
::Graphics::PixelFormat getPixelFormat() const { return _parent->getPixelFormat(); }
int getFrameCount() const { return _parent->_frameCount; }
FVFDecoder *_parent;
};
class FVFAudioTrack : public AudioTrack {
public:
FVFAudioTrack(FVFDecoder *parent) : AudioTrack(Audio::Mixer::kPlainSoundType), _parent(parent) { }
protected:
virtual Audio::AudioStream *getAudioStream() const { return _parent->_audioStream; }
FVFDecoder *_parent;
};
private:
Audio::Mixer *_mixer;
Audio::Mixer::SoundType _soundType;
Audio::QueuingAudioStream *_audioStream;
Audio::QueuingAudioStream *createAudioStream();
uint16 _width;
uint16 _height;
uint16 _bpp;
uint32 _frameCount;
uint32 _curFrame;
Common::Rational _frameRate;
Common::SeekableReadStream *_fileStream;
::Graphics::Surface _surface;
byte palette_entry_count, header_pal_count;
void readNextBlock();
uint32 curr_block_remaining_frames, curr_block_remaining_size;
// generated lookup tables
uint32 block_id_to_offset[6000];
uint32 block_status_lookup[6000];
uint16 block_lookup[16000];
byte modify_lookup[32768];
// front/back buffers
byte real_front_buffer[64000], real_back_buffer[64000],
real_colour_front_buffer[32000], real_colour_back_buffer[32000];
byte *front_buffer, *back_buffer, *colour_front_buffer, *colour_back_buffer;
// decoder state (visibility)
byte curr_status;
byte block_status[6000];
// decoder state (per-frame offset data)
int16 storage[256];
void setupTables();
void decodeVideoFrame(uint16 *frame, unsigned int len);
void decodeVideoFrameData(uint16 *frame, unsigned int len);
unsigned int GetOddPixelOffset(unsigned int in);
};
} // Unity
#endif