Skip to content

Commit aee2e5a

Browse files
xVan TuringxVan Turing
authored andcommitted
add api doc to readme
add doc to TS function update package version move package dep
1 parent 2d8f205 commit aee2e5a

File tree

5 files changed

+146
-18
lines changed

5 files changed

+146
-18
lines changed

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,31 @@
1313
> `npm i cquant`
1414
#### Electron User
1515
After running the install command make sure to use electron-rebuild to rebuild it for electron, usually it will just download the prebuild.
16-
## Async!
16+
### Async!
1717
This package is real async. You can run multiple task without blocking the main loop
18+
### API
19+
``` ts
20+
interface Color {
21+
R: number;
22+
G: number;
23+
B: number;
24+
count: number;
25+
}
26+
declare type Palette = Color[];
27+
type CallBackFunc = (err: Error | undefined | string, result: Palette) => void;
28+
29+
function paletteAsync(buffer: Buffer, depth=3, maxColor=5, maxSub=0): Promise<Palette>;
30+
/**
31+
*
32+
* @param buffer Image Buffer(RGB/RGBA)
33+
* @param depth 3 or 4 for RGB/RGBA
34+
* @param maxColor Color Amout You want
35+
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
36+
* @param callback callback with err and result
37+
*/
38+
function paletteAsync(buffer: Buffer, depth=3, maxColor=5, maxSub=0, callback:CallBackFunc): void;
39+
40+
```
1841
### Basic
1942
``` js
2043
const cquant = require('cquant')
@@ -37,7 +60,7 @@ sharp('path/to/image')
3760
})
3861
```
3962
### With `async.queue`
40-
> If you have lots of image to process, the best way to do it is using [async](https://www.npmjs.com/package/async).queue for parallel, and control-able
63+
> If you have lots of image to process, the best way to do it is using [async](https://www.npmjs.com/package/async).queue for parallel, and controllable
4164
``` js
4265
// test/example.js
4366
const myQueue = async.queue(async (filePath) => {
@@ -80,10 +103,5 @@ Basically you need run this command
80103
cmake-js -r electron -v 4.0.4 rebuild # for electron
81104
cmake-js -r node -v 10.0.0 rebuild # for node
82105
```
83-
And of course if you use `electron-prebuild` make sure you add the `cache file` mentioned before
84-
85-
## TODO
86-
* add para for subsampling
87-
88106
---
89107
xVan Turing 2019

cquant.d.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,68 @@ interface Color {
88
declare type Palette = Color[];
99
declare type CallBackFunc = (err: Error | undefined | string, result: Palette) => void;
1010
declare type ImageDepth = 3 | 4;
11+
/**
12+
*
13+
* @param buffer Image Buffer(RGB/RGBA)
14+
* @param callback Callback function
15+
*/
1116
export declare function paletteAsync(buffer: Buffer, callback: CallBackFunc): void;
17+
/**
18+
*
19+
* @param buffer Image Buffer(RGB/RGBA)
20+
* @param depth 3 or 4 for RGB/RGBA
21+
* @param callback Callback function
22+
*/
1223
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth, callback: CallBackFunc): void;
24+
/**
25+
*
26+
* @param buffer Image Buffer(RGB/RGBA)
27+
* @param depth 3 or 4 for RGB/RGBA
28+
* @param maxColor Color Amount You want
29+
* @param callback Callback function
30+
*/
1331
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth, maxColor: number, callback: CallBackFunc): void;
32+
/**
33+
*
34+
* @param buffer Image Buffer(RGB/RGBA)
35+
* @param depth 3 or 4 for RGB/RGBA
36+
* @param maxColor Color Amount You want
37+
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
38+
* @param callback Callback function
39+
*/
1440
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth | undefined, maxColor: number | undefined, maxSub: number | undefined, callback: CallBackFunc): void;
41+
/**
42+
*
43+
* @param buffer Image Buffer(RGB/RGBA)
44+
*/
1545
export declare function paletteAsync(buffer: Buffer): Promise<Palette>;
46+
/**
47+
*
48+
* @param buffer Image Buffer(RGB/RGBA)
49+
* @param depth 3 or 4 for RGB/RGBA
50+
*/
1651
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth): Promise<Palette>;
52+
/**
53+
*
54+
* @param buffer Image Buffer(RGB/RGBA)
55+
* @param depth 3 or 4 for RGB/RGBA
56+
* @param maxColor Color Amount You want
57+
*/
1758
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth, maxColor: number): Promise<Palette>;
59+
/**
60+
*
61+
* @param buffer Image Buffer(RGB/RGBA)
62+
* @param depth 3 or 4 for RGB/RGBA
63+
* @param maxColor Color Amount You want
64+
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
65+
*/
1866
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth, maxColor: number, maxSub: number): Promise<Palette>;
67+
/**
68+
*
69+
* @param buffer Image Buffer(RGB/RGBA)
70+
* @param depth 3 or 4 for RGB/RGBA
71+
* @param maxColor Color Amount You want
72+
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
73+
*/
1974
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth | undefined, maxColor: number | undefined, maxSub: number | undefined): Promise<Palette>;
2075
export {};

cquant.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cquant.ts

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,71 @@ interface Color {
88
type Palette = Color[];
99
type CallBackFunc = (err: Error | undefined | string, result: Palette) => void;
1010
type ImageDepth = 3 | 4;
11-
12-
11+
/**
12+
*
13+
* @param buffer Image Buffer(RGB/RGBA)
14+
* @param callback Callback function
15+
*/
1316
export function paletteAsync(buffer: Buffer, callback: CallBackFunc): void;
17+
/**
18+
*
19+
* @param buffer Image Buffer(RGB/RGBA)
20+
* @param depth 3 or 4 for RGB/RGBA
21+
* @param callback Callback function
22+
*/
1423
export function paletteAsync(buffer: Buffer, depth: ImageDepth, callback: CallBackFunc): void;
24+
/**
25+
*
26+
* @param buffer Image Buffer(RGB/RGBA)
27+
* @param depth 3 or 4 for RGB/RGBA
28+
* @param maxColor Color Amount You want
29+
* @param callback Callback function
30+
*/
1531
export function paletteAsync(buffer: Buffer, depth: ImageDepth, maxColor: number, callback: CallBackFunc): void;
32+
/**
33+
*
34+
* @param buffer Image Buffer(RGB/RGBA)
35+
* @param depth 3 or 4 for RGB/RGBA
36+
* @param maxColor Color Amount You want
37+
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
38+
* @param callback Callback function
39+
*/
1640
export function paletteAsync(buffer: Buffer, depth: ImageDepth | undefined, maxColor: number | undefined, maxSub: number | undefined, callback: CallBackFunc): void;
17-
18-
export function paletteAsync(buffer: Buffer, ): Promise<Palette>;
19-
export function paletteAsync(buffer: Buffer, depth: ImageDepth, ): Promise<Palette>;
41+
/**
42+
*
43+
* @param buffer Image Buffer(RGB/RGBA)
44+
*/
45+
export function paletteAsync(buffer: Buffer): Promise<Palette>;
46+
/**
47+
*
48+
* @param buffer Image Buffer(RGB/RGBA)
49+
* @param depth 3 or 4 for RGB/RGBA
50+
*/
51+
export function paletteAsync(buffer: Buffer, depth: ImageDepth): Promise<Palette>;
52+
/**
53+
*
54+
* @param buffer Image Buffer(RGB/RGBA)
55+
* @param depth 3 or 4 for RGB/RGBA
56+
* @param maxColor Color Amount You want
57+
*/
2058
export function paletteAsync(buffer: Buffer, depth: ImageDepth, maxColor: number): Promise<Palette>;
59+
/**
60+
*
61+
* @param buffer Image Buffer(RGB/RGBA)
62+
* @param depth 3 or 4 for RGB/RGBA
63+
* @param maxColor Color Amount You want
64+
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
65+
*/
2166
export function paletteAsync(buffer: Buffer, depth: ImageDepth, maxColor: number, maxSub: number): Promise<Palette>;
67+
/**
68+
*
69+
* @param buffer Image Buffer(RGB/RGBA)
70+
* @param depth 3 or 4 for RGB/RGBA
71+
* @param maxColor Color Amount You want
72+
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
73+
*/
2274
export function paletteAsync(buffer: Buffer, depth: ImageDepth | undefined, maxColor: number | undefined, maxSub: number | undefined): Promise<Palette>;
75+
2376
export function paletteAsync() {
2477
const [buffer, depth = 3, maxColor = 5, maxSub = 0, callback = null] = arguments
2578
if (arguments.length < 1 || buffer == null) {

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
22
"name": "cquant",
3-
"version": "0.0.21",
3+
"version": "0.0.22",
44
"description": "A fast and native image palette generator",
55
"main": "cquant.js",
66
"types": "./cquant.d.ts",
77
"scripts": {
88
"install": "prebuild-install || cmake-js rebuild",
99
"rebuild": "cmake-js rebuild",
10-
"test": "node ./test/test.js && node ./test/api-test.js && node ./test/perf.js && node ./script/build-deploy.js"
10+
"test": "node ./test/test.js && node ./test/api-test.js && node ./test/perf.js && node ./script/build-deploy.js",
11+
"build": "tsc --build"
1112
},
1213
"keywords": [
14+
"image-palette",
1315
"color-quant",
1416
"cquant",
1517
"palette",
@@ -26,8 +28,6 @@
2628
"dependencies": {
2729
"async": "^2.6.1",
2830
"bindings": "^1.3.1",
29-
"image-palette": "^2.1.0",
30-
"image-pixels": "^2.2.2",
3131
"node-addon-api": "^1.6.2",
3232
"prebuild-install": "^5.2.2"
3333
},
@@ -36,6 +36,8 @@
3636
"cmake-js": "^4.0.1",
3737
"prebuild": "^8.1.2",
3838
"typescript": "^3.3.3",
39-
"which": "^1.3.1"
39+
"which": "^1.3.1",
40+
"image-palette": "^2.1.0",
41+
"image-pixels": "^2.2.2"
4042
}
4143
}

0 commit comments

Comments
 (0)