mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
Add types for quantize (#65669)
This commit is contained in:
62
types/quantize/index.d.ts
vendored
Normal file
62
types/quantize/index.d.ts
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
// Type definitions for quantize 1.0
|
||||
// Project: https://github.com/olivierlesnicki/quantize
|
||||
// Definitions by: matiand <https://github.com/matiand>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace quantize {
|
||||
type RgbPixel = [number, number, number];
|
||||
|
||||
interface PriorityQueue {
|
||||
debug: () => ColorObject[];
|
||||
map: <U>(callback: (item: ColorObject, index: number) => U) => U[];
|
||||
peek: (index?: number) => ColorObject;
|
||||
pop: () => ColorObject;
|
||||
push: (item: ColorObject) => void;
|
||||
size: () => number;
|
||||
}
|
||||
|
||||
interface VBox {
|
||||
r1: number;
|
||||
r2: number;
|
||||
g1: number;
|
||||
g2: number;
|
||||
b1: number;
|
||||
b2: number;
|
||||
histo: number[];
|
||||
|
||||
avg: (recalculate?: boolean) => RgbPixel;
|
||||
contains: (pixel: RgbPixel) => boolean;
|
||||
copy: () => VBox;
|
||||
count: () => number;
|
||||
volume: (recalculate?: boolean) => number;
|
||||
}
|
||||
|
||||
interface ColorObject {
|
||||
color: RgbPixel;
|
||||
vbox: VBox;
|
||||
}
|
||||
|
||||
interface ColorMap {
|
||||
vboxes: PriorityQueue;
|
||||
|
||||
/**
|
||||
* Maps the pixel from source image to the closest palette color
|
||||
*/
|
||||
map: (pixel: RgbPixel) => RgbPixel;
|
||||
nearest: (pixel: RgbPixel) => RgbPixel;
|
||||
/**
|
||||
* Returns the palette as an array of RgbPixel
|
||||
* @returns RgbPixel[][]
|
||||
*/
|
||||
palette: () => RgbPixel[];
|
||||
push: (vbox: VBox) => void;
|
||||
/**
|
||||
* Returns the size of the palette
|
||||
*/
|
||||
size: () => number;
|
||||
}
|
||||
}
|
||||
|
||||
declare function quantize(pixels: quantize.RgbPixel[], colorCount: number): quantize.ColorMap | false;
|
||||
|
||||
export = quantize;
|
||||
37
types/quantize/quantize-tests.ts
Normal file
37
types/quantize/quantize-tests.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import quantize = require('quantize');
|
||||
|
||||
// $ExpectType false | ColorMap
|
||||
const colorMap = quantize(
|
||||
[
|
||||
[255, 0, 0],
|
||||
[0, 255, 0],
|
||||
[0, 0, 255],
|
||||
],
|
||||
2,
|
||||
);
|
||||
|
||||
if (colorMap !== false) {
|
||||
// $ExpectType RgbPixel[]
|
||||
colorMap.palette();
|
||||
|
||||
// $ExpectType number
|
||||
colorMap.size();
|
||||
|
||||
// $ExpectType RgbPixel
|
||||
colorMap.map([100, 100, 100]);
|
||||
|
||||
// $ExpectType RgbPixel
|
||||
colorMap.nearest([200, 100, 0]);
|
||||
|
||||
// $ExpectType void
|
||||
colorMap.push(colorMap.vboxes.peek().vbox);
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
quantize([[255, 0]], 2);
|
||||
|
||||
// @ts-expect-error
|
||||
quantize([[255, 0, 0]]);
|
||||
|
||||
// @ts-expect-error
|
||||
quantize([[255, 0, 0]], '2');
|
||||
23
types/quantize/tsconfig.json
Normal file
23
types/quantize/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"quantize-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/quantize/tslint.json
Normal file
1
types/quantize/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "@definitelytyped/dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user