A theme color extractor module for Node.js with ❤ and built on the top of Byakuren.
- Minimum Differ Algorithm
- Octree Algorithm
- Mixed Algorithm
$ npm install --save thmclrx
There only three API in Node.js now.
octree
is to get the theme colors in an octree. The colors are unsertain but fidelity.
The function is like below:
var thmclrx = require("thmclrx");
thmclrx.octree(file, [maxColors], [callback], [frameNumber]);
file
: it could be a local filename, remote url or even an image buffer.maxColors
: count of max theme colors you want to extract. Defaults to 256;callback
: it should be likefunction(err, colors) {}
. Defaults to an empty function;frameNumber
: the frame you want to extract. Usually used ingif
. Defaults to 0.
minDiff
is to get theme colors in minimum differ algorithm by passing a palette. The result theme colors are certainlly in your palette.
var thmclrx = require("thmclrx");
thmclrx.minDiff(file, [palette], [callback], [frameNumber]);
file
: it could be a local filename, remote url or even an image buffer.palette
: palette is an array that in the struct of[ { r: .., g: .., b: .., }, { r: .., g: .., b: .. } ]
. Default palette refers here.callback
: it should be likefunction(err, colors) {}
. Defaults to an empty function;frameNumber
: the frame you want to extract. Usually used ingif
. Defaults to 0.
Using mixed
get the basic fidelity theme colors and then using minDiff
to standardize the fidelity theme colors to a certain palette.
var thmclrx = require("thmclrx");
thmclrx.mixed(file, [firstStepMaxColors], [palette], [callback], [frameNumber]);
file
: same as the two functions above.firstStepMaxColors
: same as themaxColors
inoctreeGet
. Defaults to 256.palette
: same as thepalette
inmindiffGet
. Same default value.callback
: same as the two functions above.frameNumber
: same as the two functions above.
If you want to use C++ API directly, you can refer to this.
This function is called in octree
in Node.js API.
var thmclrx = require("thmclrx").cpp;
var colors = thmclrx.getByOctree(pixels, [maxColor]);
pixels
: this is an array in the struct of[ { r: .., g: .., b: .., }, { r: .., g: .., b: .. } ]
.maxColor
: same as themaxColors
inoctreeGet
of Node.js API. Defaults to 256.@return
: this function will return the theme colors.
This function is called in minDiff
in Node.js API.
var thmclrx = require("thmclrx").cpp;
var colors = thmclrx.getByMinDiff(pixels, [palette]);
pixels
: this may be same as thepixels
inoctreeGet
of C++ API. Otherwise, it may be the result ofoctreeGet
of C++ API.palette
: same as thepalette
inmindiffGet
of Node.js API. Same default value.@return
: this function will return the theme colors.
This function is called in mixed
in Node.js API.
var thmclrx = require("thmclrx").cpp;
var colors = thmclrx.getByMixed(pixels, maxColors, palette);
pixels
: this may be same as thepixels
inoctreeGet
of C++ API. Otherwise, it may be the result ofoctreeGet
of C++ API.maxColors
: same as themaxColors
inoctreeGet
of Node.js API.palette
: same as thepalette
inmindiffGet
of Node.js API.@return
: this function will return the theme colors.
thmclrx 0.x has three APIs which map three APIs in 1.x.
- octreeGet
- mindiffGet
- mixGet
In 1.x, these three APIs still exist but deprecated. They are exactly shallow points of octree
/ minDiff
and mixed
.
You may do nothing but we recommend you to rename the functions you called.
But if you're using native APIs (C++ APIs), you should read the new document.
Issues and PRs are welcomed!
「雖然我覺得不怎麼可能有人會關注我」