mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
Vendored
+100
@@ -0,0 +1,100 @@
|
||||
// Type definitions for pngjs 3.3
|
||||
// Project: https://github.com/lukeapage/pngjs
|
||||
// Definitions by: Jason Cheatham <https://github.com/jason0x43>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Duplex } from 'stream';
|
||||
import { createDeflate } from 'zlib';
|
||||
|
||||
export class PNG extends Duplex {
|
||||
static adjustGamma(src: PNG): void;
|
||||
|
||||
static bitblt(
|
||||
src: PNG,
|
||||
dst: PNG,
|
||||
srcX?: number,
|
||||
srcY?: number,
|
||||
width?: number,
|
||||
height?: number,
|
||||
deltaX?: number,
|
||||
deltaY?: number
|
||||
): void;
|
||||
|
||||
static sync: {
|
||||
read(buffer: Buffer, options?: ParserOptions): PNG;
|
||||
write(buffer: Buffer, options?: PackerOptions): PNG;
|
||||
};
|
||||
|
||||
constructor(options?: PNGOptions);
|
||||
|
||||
data: Buffer;
|
||||
gamma: number;
|
||||
height: number;
|
||||
width: number;
|
||||
|
||||
adjustGamma(): void;
|
||||
|
||||
bitblt(
|
||||
dst: PNG,
|
||||
srcX?: number,
|
||||
srcY?: number,
|
||||
width?: number,
|
||||
height?: number,
|
||||
deltaX?: number,
|
||||
deltaY?: number
|
||||
): PNG;
|
||||
|
||||
on(event: 'metadata', callback: (metadata: Metadata) => void): this;
|
||||
on(event: 'parsed', callback: (data: Buffer) => void): this;
|
||||
on(event: 'error', callback: (error: Error) => void): this;
|
||||
on(event: string, callback: (...args: any[]) => void): this;
|
||||
|
||||
pack(): PNG;
|
||||
|
||||
parse(data: string | Buffer, callback?: (error: Error, data: PNG) => void): PNG;
|
||||
}
|
||||
|
||||
export interface BaseOptions {
|
||||
width?: number;
|
||||
height?: number;
|
||||
fill?: boolean;
|
||||
}
|
||||
|
||||
export interface ParserOptions {
|
||||
checkCRC?: boolean;
|
||||
}
|
||||
|
||||
export interface PackerOptions {
|
||||
deflateChunkSize?: number;
|
||||
deflateLevel?: number;
|
||||
deflateStrategy?: number;
|
||||
deflateFactory?: typeof createDeflate;
|
||||
colorType?: ColorType;
|
||||
bitDepth?: 8 | 16;
|
||||
bgColor?: {
|
||||
red: number;
|
||||
green: number;
|
||||
blue: number;
|
||||
};
|
||||
inputHasAlpha?: boolean;
|
||||
inputColorType?: ColorType;
|
||||
filterType?: number | number[];
|
||||
}
|
||||
|
||||
export type PNGOptions = BaseOptions & ParserOptions & PackerOptions;
|
||||
|
||||
export type ColorType = 0 | 1 | 2 | 4;
|
||||
|
||||
export interface Metadata {
|
||||
width: number;
|
||||
height: number;
|
||||
depth: 1 | 2 | 4 | 8 | 16;
|
||||
interlace: boolean;
|
||||
palette: boolean;
|
||||
color: boolean;
|
||||
alpha: boolean;
|
||||
bpp: 1 | 2 | 3 | 4;
|
||||
colorType: ColorType;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { PNG } from 'pngjs';
|
||||
import { createDeflate } from 'zlib';
|
||||
|
||||
const pngs = [
|
||||
new PNG(),
|
||||
new PNG({}),
|
||||
new PNG({ width: 1 }),
|
||||
new PNG({ checkCRC: false }),
|
||||
new PNG({ deflateChunkSize: 3 }),
|
||||
new PNG({
|
||||
width: 1,
|
||||
height: 1,
|
||||
fill: false,
|
||||
checkCRC: true,
|
||||
deflateChunkSize: 1,
|
||||
deflateLevel: 1,
|
||||
deflateStrategy: 1,
|
||||
deflateFactory: createDeflate,
|
||||
colorType: 4,
|
||||
bitDepth: 8,
|
||||
inputHasAlpha: false,
|
||||
filterType: 4
|
||||
}),
|
||||
new PNG({ filterType: [1, 2, 3] })
|
||||
];
|
||||
|
||||
const png = pngs[0];
|
||||
|
||||
if (png.readable) {
|
||||
console.log('readable');
|
||||
}
|
||||
if (png.writable) {
|
||||
console.log('writable');
|
||||
}
|
||||
png.width === 1;
|
||||
png.height === 1;
|
||||
png.gamma === 1;
|
||||
png.adjustGamma();
|
||||
|
||||
png.bitblt(pngs[1]);
|
||||
png.bitblt(pngs[1], 1);
|
||||
png.bitblt(pngs[1], 1, 1);
|
||||
png.bitblt(pngs[1], 1, 1, 1, 1, 1, 1);
|
||||
|
||||
png.on('metadata', metadata => {
|
||||
metadata.bpp === 1;
|
||||
});
|
||||
png.on('parsed', data => {
|
||||
data.byteLength === 1;
|
||||
});
|
||||
png.on('error', error => {
|
||||
error === new Error('testing');
|
||||
});
|
||||
png.on('foo', () => {});
|
||||
|
||||
png.pack().adjustGamma();
|
||||
|
||||
png.parse('foo').adjustGamma();
|
||||
png.parse(Buffer.from('foo')).adjustGamma();
|
||||
png.parse('foo', (error, data) => {
|
||||
error.stack;
|
||||
data.adjustGamma();
|
||||
}).adjustGamma();
|
||||
|
||||
PNG.adjustGamma(png);
|
||||
|
||||
PNG.bitblt(png, pngs[1]);
|
||||
PNG.bitblt(png, pngs[1], 1, 1, 1, 1, 1, 1);
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"pngjs-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user