Skip to content

Commit

Permalink
add api doc to readme
Browse files Browse the repository at this point in the history
add doc to TS function
update package version
move package dep
  • Loading branch information
xVan Turing authored and xVan Turing committed Feb 10, 2019
1 parent 2d8f205 commit aee2e5a
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 18 deletions.
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,31 @@
> `npm i cquant`
#### Electron User
After running the install command make sure to use electron-rebuild to rebuild it for electron, usually it will just download the prebuild.
## Async!
### Async!
This package is real async. You can run multiple task without blocking the main loop
### API
``` ts
interface Color {
R: number;
G: number;
B: number;
count: number;
}
declare type Palette = Color[];
type CallBackFunc = (err: Error | undefined | string, result: Palette) => void;

function paletteAsync(buffer: Buffer, depth=3, maxColor=5, maxSub=0): Promise<Palette>;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param maxColor Color Amout You want
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
* @param callback callback with err and result
*/
function paletteAsync(buffer: Buffer, depth=3, maxColor=5, maxSub=0, callback:CallBackFunc): void;

```
### Basic
``` js
const cquant = require('cquant')
Expand All @@ -37,7 +60,7 @@ sharp('path/to/image')
})
```
### With `async.queue`
> 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
> 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
``` js
// test/example.js
const myQueue = async.queue(async (filePath) => {
Expand Down Expand Up @@ -80,10 +103,5 @@ Basically you need run this command
cmake-js -r electron -v 4.0.4 rebuild # for electron
cmake-js -r node -v 10.0.0 rebuild # for node
```
And of course if you use `electron-prebuild` make sure you add the `cache file` mentioned before

## TODO
* add para for subsampling

---
xVan Turing 2019
55 changes: 55 additions & 0 deletions cquant.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,68 @@ interface Color {
declare type Palette = Color[];
declare type CallBackFunc = (err: Error | undefined | string, result: Palette) => void;
declare type ImageDepth = 3 | 4;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param callback Callback function
*/
export declare function paletteAsync(buffer: Buffer, callback: CallBackFunc): void;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param callback Callback function
*/
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth, callback: CallBackFunc): void;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param maxColor Color Amount You want
* @param callback Callback function
*/
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth, maxColor: number, callback: CallBackFunc): void;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param maxColor Color Amount You want
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
* @param callback Callback function
*/
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth | undefined, maxColor: number | undefined, maxSub: number | undefined, callback: CallBackFunc): void;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
*/
export declare function paletteAsync(buffer: Buffer): Promise<Palette>;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
*/
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth): Promise<Palette>;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param maxColor Color Amount You want
*/
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth, maxColor: number): Promise<Palette>;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param maxColor Color Amount You want
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
*/
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth, maxColor: number, maxSub: number): Promise<Palette>;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param maxColor Color Amount You want
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
*/
export declare function paletteAsync(buffer: Buffer, depth: ImageDepth | undefined, maxColor: number | undefined, maxSub: number | undefined): Promise<Palette>;
export {};
2 changes: 1 addition & 1 deletion cquant.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 58 additions & 5 deletions cquant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,71 @@ interface Color {
type Palette = Color[];
type CallBackFunc = (err: Error | undefined | string, result: Palette) => void;
type ImageDepth = 3 | 4;


/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param callback Callback function
*/
export function paletteAsync(buffer: Buffer, callback: CallBackFunc): void;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param callback Callback function
*/
export function paletteAsync(buffer: Buffer, depth: ImageDepth, callback: CallBackFunc): void;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param maxColor Color Amount You want
* @param callback Callback function
*/
export function paletteAsync(buffer: Buffer, depth: ImageDepth, maxColor: number, callback: CallBackFunc): void;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param maxColor Color Amount You want
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
* @param callback Callback function
*/
export function paletteAsync(buffer: Buffer, depth: ImageDepth | undefined, maxColor: number | undefined, maxSub: number | undefined, callback: CallBackFunc): void;

export function paletteAsync(buffer: Buffer, ): Promise<Palette>;
export function paletteAsync(buffer: Buffer, depth: ImageDepth, ): Promise<Palette>;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
*/
export function paletteAsync(buffer: Buffer): Promise<Palette>;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
*/
export function paletteAsync(buffer: Buffer, depth: ImageDepth): Promise<Palette>;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param maxColor Color Amount You want
*/
export function paletteAsync(buffer: Buffer, depth: ImageDepth, maxColor: number): Promise<Palette>;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param maxColor Color Amount You want
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
*/
export function paletteAsync(buffer: Buffer, depth: ImageDepth, maxColor: number, maxSub: number): Promise<Palette>;
/**
*
* @param buffer Image Buffer(RGB/RGBA)
* @param depth 3 or 4 for RGB/RGBA
* @param maxColor Color Amount You want
* @param maxSub max subsample for image, 1 for no sub sample,0 for auto, by default it will scale to size of `1000x1000`
*/
export function paletteAsync(buffer: Buffer, depth: ImageDepth | undefined, maxColor: number | undefined, maxSub: number | undefined): Promise<Palette>;

export function paletteAsync() {
const [buffer, depth = 3, maxColor = 5, maxSub = 0, callback = null] = arguments
if (arguments.length < 1 || buffer == null) {
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"name": "cquant",
"version": "0.0.21",
"version": "0.0.22",
"description": "A fast and native image palette generator",
"main": "cquant.js",
"types": "./cquant.d.ts",
"scripts": {
"install": "prebuild-install || cmake-js rebuild",
"rebuild": "cmake-js rebuild",
"test": "node ./test/test.js && node ./test/api-test.js && node ./test/perf.js && node ./script/build-deploy.js"
"test": "node ./test/test.js && node ./test/api-test.js && node ./test/perf.js && node ./script/build-deploy.js",
"build": "tsc --build"
},
"keywords": [
"image-palette",
"color-quant",
"cquant",
"palette",
Expand All @@ -26,8 +28,6 @@
"dependencies": {
"async": "^2.6.1",
"bindings": "^1.3.1",
"image-palette": "^2.1.0",
"image-pixels": "^2.2.2",
"node-addon-api": "^1.6.2",
"prebuild-install": "^5.2.2"
},
Expand All @@ -36,6 +36,8 @@
"cmake-js": "^4.0.1",
"prebuild": "^8.1.2",
"typescript": "^3.3.3",
"which": "^1.3.1"
"which": "^1.3.1",
"image-palette": "^2.1.0",
"image-pixels": "^2.2.2"
}
}

0 comments on commit aee2e5a

Please sign in to comment.