gif.js
2.27 KB
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
'use strict';
/** @class Gif */
class Gif {
// width - width of GIF in pixels
// height - height of GIF in pixels
// loops - 0 = unending; (n > 0) = iterate n times
// usesTransparency - whether any frames have transparent pixels
// colorScope - scope of color tables in GIF
// frames - array of frames
// buffer - GIF-formatted data
/**
* Gif is a class representing an encoded GIF. It is intended to be a read-only representation of a byte-encoded GIF. Only encoders and decoders should be creating instances of this class.
*
* Property | Description
* --- | ---
* width | width of the GIF at its widest
* height | height of the GIF at its highest
* loops | the number of times the GIF should loop before stopping; 0 => loop indefinately
* usesTransparency | boolean indicating whether at least one frame contains at least one transparent pixel
* colorScope | the scope of the color tables as encoded within the GIF; either Gif.GlobalColorsOnly (== 1) or Gif.LocalColorsOnly (== 2).
* frames | a array of GifFrame instances, one for each frame of the GIF
* buffer | a Buffer holding the encoding's byte data
*
* Its constructor should only ever be called by the GIF encoder or decoder.
*
* @param {Buffer} buffer A Buffer containing the encoded bytes
* @param {GifFrame[]} frames Array of frames found in the encoding
* @param {object} spec Properties of the encoding as listed above
*/
constructor(buffer, frames, spec) {
this.width = spec.width;
this.height = spec.height;
this.loops = spec.loops;
this.usesTransparency = spec.usesTransparency;
this.colorScope = spec.colorScope;
this.frames = frames;
this.buffer = buffer;
}
}
Gif.GlobalColorsPreferred = 0;
Gif.GlobalColorsOnly = 1;
Gif.LocalColorsOnly = 2;
/** @class GifError */
class GifError extends Error {
/**
* GifError is a class representing a GIF-related error
*
* @param {string|Error} messageOrError
*/
constructor(messageOrError) {
super(messageOrError);
if (messageOrError instanceof Error) {
this.stack = 'Gif' + messageOrError.stack;
}
}
}
exports.Gif = Gif;
exports.GifError = GifError;