Skip to content

Commit

Permalink
VIDEO: Use VideoTrack in Fader
Browse files Browse the repository at this point in the history
  • Loading branch information
clone2727 authored and DrMcCoy committed Nov 17, 2018
1 parent 24c1267 commit 606bdc2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 47 deletions.
59 changes: 19 additions & 40 deletions src/video/fader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,23 @@

namespace Video {

Fader::Fader(uint32 width, uint32 height, int n) : _c(0), _n(n), _lastUpdate(0) {
initVideo(width, height);
Fader::Fader(uint32 width, uint32 height, int n) {
addTrack(new FaderVideoTrack(width, height, n));
initVideo();
}

Fader::~Fader() {
void Fader::decodeNextTrackFrame(VideoTrack &track) {
assert(_surface);
static_cast<FaderVideoTrack &>(track).drawFrame(*_surface);
_needCopy = true;
}

bool Fader::hasTime() const {
if (!_started)
return true;

if ((EventMan.getTimestamp() - _lastUpdate) < 20)
return true;

return false;
Fader::FaderVideoTrack::FaderVideoTrack(uint32 width, uint32 height, int n) : _width(width), _height(height), _curFrame(-1), _c(0), _n(n) {
}

void Fader::processData() {
uint32 curTime = EventMan.getTimestamp();
uint32 diffTime = curTime - _lastUpdate;
if (_started && (diffTime < 20))
return;

if (!_started) {
_lastUpdate = curTime;
_started = true;

_c = 0;
} else
_c += 2;

void Fader::FaderVideoTrack::drawFrame(Graphics::Surface &surface) {
// Fade from black to green
byte *data = _surface->getData();
byte *data = surface.getData();
for (uint32 i = 0; i < _height; i++) {
byte *rowData = data;

Expand All @@ -75,30 +59,25 @@ void Fader::processData() {
rowData[3] = 255;
}

data += _surface->getWidth() * 4;
data += surface.getWidth() * 4;
}

// Keep a red square in the middle
int xPos = (_width / 2) - 2;
int yPos = (_height / 2) - 2;
int dPos = (yPos * _surface->getWidth() + xPos) * 4;
int dPos = (yPos * surface.getWidth() + xPos) * 4;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
_surface->getData()[dPos + j * 4 + 0] = 0;
_surface->getData()[dPos + j * 4 + 1] = 0;
_surface->getData()[dPos + j * 4 + 2] = 255;
_surface->getData()[dPos + j * 4 + 3] = 255;
surface.getData()[dPos + j * 4 + 0] = 0;
surface.getData()[dPos + j * 4 + 1] = 0;
surface.getData()[dPos + j * 4 + 2] = 255;
surface.getData()[dPos + j * 4 + 3] = 255;
}
dPos += _surface->getWidth() * 4;
dPos += surface.getWidth() * 4;
}

_lastUpdate = curTime;

if (_c == 0)
if (_n-- <= 0)
finish();

_needCopy = true;
_c += 2;
_curFrame++;
}

} // End of namespace Video
30 changes: 23 additions & 7 deletions src/video/fader.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef VIDEO_FADER_H
#define VIDEO_FADER_H

#include "src/common/rational.h"

#include "src/video/decoder.h"

namespace Video {
Expand All @@ -33,18 +35,32 @@ namespace Video {
class Fader : public VideoDecoder {
public:
Fader(uint32 width, uint32 height, int n);
~Fader();

bool hasTime() const;

protected:
void processData();
void decodeNextTrackFrame(VideoTrack &track);

private:
byte _c;
int _n;
class FaderVideoTrack : public FixedRateVideoTrack {
public:
FaderVideoTrack(uint32 width, uint32 height, int n);

uint32 getWidth() const { return _width; }
uint32 getHeight() const { return _height; }
int getCurFrame() const { return _curFrame; }
int getFrameCount() const { return _n * 128; }

void drawFrame(Graphics::Surface &surface);

protected:
Common::Rational getFrameRate() const { return 50; }

uint32 _lastUpdate;
private:
uint32 _width;
uint32 _height;
int _curFrame;
byte _c;
int _n;
};
};

} // End of namespace Video
Expand Down

0 comments on commit 606bdc2

Please sign in to comment.