-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.d.ts
153 lines (123 loc) · 4.47 KB
/
index.d.ts
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
export interface GifSpec {
loops?: number;
colorScope?: 0|1|2;
}
export interface GifEncoder {
encodeGif(frames: GifFrame[], spec: GifSpec): Promise<Gif>;
}
export interface GifDecoder {
decodeGif(buffer: Buffer): Promise<Gif>;
}
export class Gif implements GifSpec {
static readonly GlobalColorsPreferred: 0;
static readonly GlobalColorsOnly: 1;
static readonly LocalColorsOnly: 2;
width: number;
height: number;
loops: number;
usesTransparency: boolean;
colorScope: 0|1|2;
frames: GifFrame[];
buffer: Buffer;
constructor(frames: GifFrame[], buffer: Buffer, spec?: GifSpec);
}
export interface GifFrameOptions {
xOffset?: number;
yOffset?: number;
disposalMethod?: 0|1|2|3;
delayCentisecs?: number;
isInterlaced?: boolean;
}
export interface JimpBitmap {
width: number;
height: number;
data: Buffer;
}
export interface GifPalette {
colors: number[];
indexCount: number;
usesTransparency: boolean;
}
export class BitmapImage {
bitmap: JimpBitmap;
constructor(bitmap: JimpBitmap);
constructor(bitmapImage: BitmapImage);
constructor(width: number, height: number, buffer: Buffer);
constructor(width: number, height: number, backgroundRGBA?: number);
blit(toImage: BitmapImage, toX: number, toY: number, fromX: number, fromY: number,
fromWidth: number, fromHeight: number): this;
fillRGBA(color: number): this;
getRGBA(x: number, y: number): number;
getRGBASet(): Set<number>;
greyscale(): this;
reframe(xOffset: number, yOffset: number, width: number, height: number, fillRGBA?: number)
: this;
scale(factor: number): this;
scanAllCoords(handler: (x: number, y: number, bufferIndex: number) => void): void;
scanAllIndexes(handler: (bufferIndex: number) => void): void;
}
export class GifFrame extends BitmapImage implements GifFrameOptions {
static readonly DisposeToAnything: 0;
static readonly DisposeNothing: 1;
static readonly DisposeToBackgroundColor: 2;
static readonly DisposeToPrevious: 3;
xOffset: number;
yOffset: number;
disposalMethod: 0|1|2|3;
delayCentisecs: number;
interlaced: boolean;
constructor(bitmap: JimpBitmap, options?: GifFrameOptions);
constructor(bitmapImage: BitmapImage, options?: GifFrameOptions);
constructor(width: number, height: number, buffer: Buffer, options?: GifFrameOptions);
constructor(width: number, height: number, backgroundRGBA?: number, options?: GifFrameOptions);
constructor(frame: GifFrame);
getPalette(): GifPalette;
}
export interface GifCodecOptions {
transparentRGB?: number;
}
export class GifCodec implements GifEncoder, GifDecoder {
constructor(options?: GifCodecOptions);
encodeGif(frames: GifFrame[], spec?: GifSpec): Promise<Gif>;
decodeGif(buffer: Buffer): Promise<Gif>;
}
export class GifError extends Error {
constructor(message: string);
}
export namespace GifUtil {
function cloneFrames(frames: GifFrame[]): GifFrame[];
function copyAsJimp(jimp: any, bitmapImageToCopy: BitmapImage): any;
function getColorInfo(frames: GifFrame[], maxGlobalIndex?: number): {
colors?: number[],
indexCount?: number,
usesTransparency: boolean,
palettes: GifPalette[]
}
function getMaxDimensions(frames: GifFrame[]): { maxWidth: number, maxHeight: number };
function quantizeDekker(imageOrImages: BitmapImage|BitmapImage[], maxColorIndexes: number,
dither?: Dither): void;
function quantizeSorokin(imageOrImages: BitmapImage|BitmapImage[], maxColorIndexes: number,
histogram?: string, dither?: Dither): void;
function quantizeWu(imageOrImages: BitmapImage|BitmapImage[], maxColorIndexes: number,
significantBits?: number, dither?: Dither): void;
function read(source: string|Buffer, decoder?: GifDecoder): Promise<Gif>;
function shareAsJimp(jimp: any, bitmapImageToCopy: BitmapImage): any;
function write(path: string, frames: GifFrame[], spec?: GifSpec, encoder?: GifEncoder):
Promise<Gif>;
}
export type DitherAlgorithm =
'FloydSteinberg' |
'FalseFloydSteinberg' |
'Stucki' |
'Atkinson' |
'Jarvis' |
'Burkes' |
'Sierra' |
'TwoSierra' |
'SierraLite';
export type Dither = {
ditherAlgorithm: DitherAlgorithm,
minimumColorDistanceToDither?: number, // default = 0
serpentine?: boolean, // default = true
calculateErrorLikeGIMP?: boolean // default = false
};