-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
48 lines (36 loc) · 1.1 KB
/
index.js
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
var PixelStream = require('pixel-stream');
var inherits = require('util').inherits;
function ConcatFrames(callback) {
if (!(this instanceof ConcatFrames))
return new ConcatFrames(callback);
PixelStream.call(this);
this.frames = [];
this.buffers = [];
this.callback = callback;
// put the stream in flowing mode
this.resume();
}
inherits(ConcatFrames, PixelStream);
ConcatFrames.prototype._startFrame = function(frame, done) {
frame.width = frame.width || this.format.width;
frame.height = frame.height || this.format.height;
frame.colorSpace = this.format.colorSpace;
if (!frame.palette && this.format.palette)
frame.palette = this.format.palette;
this.frames.push(frame);
this.buffers = [];
done();
};
ConcatFrames.prototype._writePixels = function(data, done) {
this.buffers.push(data);
done();
};
ConcatFrames.prototype._endFrame = function(done) {
this.frames[this.frames.length - 1].pixels = Buffer.concat(this.buffers);
done();
};
ConcatFrames.prototype._end = function(done) {
this.callback(this.frames);
done();
};
module.exports = ConcatFrames;