A theme color extractor module for Node.js with ❤.
Algorithm
- Minimum Differ Algorithm
- Octree Algorithm
Installation
API
There only three API in node.js now.
After version 0.2.0, we use a new memory pool for thmclrx.
octreeGet
octreeGet
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.octreeGet(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.
mindiffGet
mindiffGet
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.mindiffGet(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.
mixGet
Using octreeGet
get the basic fidelity theme colors and then
using mindiffGet
to standardize the fidelity theme colors to
a certain palette.
var thmclrx = require("thmclrx");
thmclrx.mixGet(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.
cleanPool
Clean memory pool in thmclrx
C++ program.
var thmclrx = require("thmclrx");
thmclrx.cleanPool();
Normally, you do not need to call it.
C++ API
If you want to use C++ API directly, you can refer to this.
octreeGet
This function is called in octreeGet
in node.js API.
var thmclrx = require("thmclrx/build/Release/thmclrx.node");
var colors = thmclrx.octreeGet(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.
mindifferGet
This function is called in mindiffGet
in node.js API.
var thmclrx = require("thmclrx/build/Release/thmclrx.node");
var colors = thmclrx.mindifferGet(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.
cleanPool
Clean memory pool.
var thmclrx = require("thmclrx/build/Release/thmclrx.node");
thmclrx.clearPool();
Normally, you do not need to call it.
Contribute
You're welcome to fork and pull requests!