Giter VIP home page Giter VIP logo

thmclrx's Introduction

Thmclrx

A theme color extractor module for Node.js with ❤ and built on the top of Byakuren.

Algorithm

  • Minimum Differ Algorithm
  • Octree Algorithm
  • Mixed Algorithm

Installation

$ npm install --save thmclrx

API

There only three API in Node.js now.

octree

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 like function(err, colors) {}. Defaults to an empty function;
  • frameNumber: the frame you want to extract. Usually used in gif. Defaults to 0.

minDiff

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 like function(err, colors) {}. Defaults to an empty function;
  • frameNumber: the frame you want to extract. Usually used in gif. Defaults to 0.

mixed

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 the maxColors in octreeGet. Defaults to 256.
  • palette: same as the palette in mindiffGet. Same default value.
  • callback: same as the two functions above.
  • frameNumber: same as the two functions above.

C++ API

If you want to use C++ API directly, you can refer to this.

getByOctree

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 the maxColors in octreeGet of Node.js API. Defaults to 256.
  • @return: this function will return the theme colors.

getByMinDiff

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 the pixels in octreeGet of C++ API. Otherwise, it may be the result of octreeGet of C++ API.
  • palette: same as the palette in mindiffGet of Node.js API. Same default value.
  • @return: this function will return the theme colors.

getByMixed

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 the pixels in octreeGet of C++ API. Otherwise, it may be the result of octreeGet of C++ API.
  • maxColors: same as the maxColors in octreeGet of Node.js API.
  • palette: same as the palette in mindiffGet of Node.js API.
  • @return: this function will return the theme colors.

Migrate From 0.x To 1.x

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.

Contribute

Issues and PRs are welcomed!

「雖然我覺得不怎麼可能有人會關注我」

thmclrx's People

Contributors

xadillax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

thmclrx's Issues

linux 安装 thmclrx的时候报错

In file included from ../deps/byakuren/const/palette.c:55:0: ../deps/byakuren/const/palette.h:62:1: warning: ‘extern’ is not at beginning of declaration [-Wold-style-declaration] const extern bkr_palette_array _default_palette; ^ CC(target) Release/obj.target/byakuren/deps/byakuren/lib/mindiff.o In file included from ../deps/byakuren/lib/mindiff.c:56:0: ../deps/byakuren/lib/../const/palette.h:62:1: warning: ‘extern’ is not at beginning of declaration [-Wold-style-declaration] const extern bkr_palette_array _default_palette; ^ ../deps/byakuren/lib/mindiff.c: In function ‘_bkr_find_mindiff’: ../deps/byakuren/lib/mindiff.c:75:5: error: ‘for’ loop initial declarations are only allowed in C99 mode for(uint32_t i = 0; i < palette_count; i++) ^ ../deps/byakuren/lib/mindiff.c:75:5: note: use option -std=c99 or -std=gnu99 to compile your code ../deps/byakuren/lib/mindiff.c: In function ‘_bkr_mindiff_calc’: ../deps/byakuren/lib/mindiff.c:94:5: error: ‘for’ loop initial declarations are only allowed in C99 mode for(uint32_t i = 0; i < pixel_count; i++) ^ ../deps/byakuren/lib/mindiff.c:105:18: error: redefinition of ‘i’ for(uint32_t i = 0; i < colored_count; i++) ^ ../deps/byakuren/lib/mindiff.c:94:18: note: previous definition of ‘i’ was here for(uint32_t i = 0; i < pixel_count; i++) ^ ../deps/byakuren/lib/mindiff.c:105:5: error: ‘for’ loop initial declarations are only allowed in C99 mode for(uint32_t i = 0; i < colored_count; i++) ^ ../deps/byakuren/lib/mindiff.c:112:18: error: redefinition of ‘i’ for(uint32_t i = 0; i < grayed_count; i++) ^ ../deps/byakuren/lib/mindiff.c:105:18: note: previous definition of ‘i’ was here for(uint32_t i = 0; i < colored_count; i++) ^ ../deps/byakuren/lib/mindiff.c:112:5: error: ‘for’ loop initial declarations are only allowed in C99 mode for(uint32_t i = 0; i < grayed_count; i++) ^ ../deps/byakuren/lib/mindiff.c: In function ‘_bkr_generate_colored_and_gray_pelette’: ../deps/byakuren/lib/mindiff.c:152:9: error: ‘for’ loop initial declarations are only allowed in C99 mode for(uint32_t i = 0; i < palette->count; i++) ^ ../deps/byakuren/lib/mindiff.c:165:9: error: ‘for’ loop initial declarations are only allowed in C99 mode for(uint32_t i = 0; i < palette->count; i++)

CentOS 7.4 上编译错误

> [email protected] install /node_modules/thmclrx
> node-gyp rebuild

make: Entering directory `/node_modules/thmclrx/build'
  CC(target) Release/obj.target/byakuren/deps/byakuren/byakuren.o
  CC(target) Release/obj.target/byakuren/deps/byakuren/common.o
  CC(target) Release/obj.target/byakuren/deps/byakuren/const/palette.o
In file included from ../deps/byakuren/const/palette.c:55:0:
../deps/byakuren/const/palette.h:62:1: warning: ‘extern’ is not at beginning of declaration [-Wold-style-declaration]
 const extern bkr_palette_array _default_palette;
 ^
  CC(target) Release/obj.target/byakuren/deps/byakuren/lib/mindiff.o
In file included from ../deps/byakuren/lib/mindiff.c:56:0:
../deps/byakuren/lib/../const/palette.h:62:1: warning: ‘extern’ is not at beginning of declaration [-Wold-style-declaration]
 const extern bkr_palette_array _default_palette;
 ^
../deps/byakuren/lib/mindiff.c: In function ‘_bkr_find_mindiff’:
../deps/byakuren/lib/mindiff.c:75:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
     for(uint32_t i = 0; i < palette_count; i++)
     ^
../deps/byakuren/lib/mindiff.c:75:5: note: use option -std=c99 or -std=gnu99 to compile your code
../deps/byakuren/lib/mindiff.c: In function ‘_bkr_mindiff_calc’:
../deps/byakuren/lib/mindiff.c:94:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
     for(uint32_t i = 0; i < pixel_count; i++)
     ^
../deps/byakuren/lib/mindiff.c:105:18: error: redefinition of ‘i’
     for(uint32_t i = 0; i < colored_count; i++)
                  ^
../deps/byakuren/lib/mindiff.c:94:18: note: previous definition of ‘i’ was here
     for(uint32_t i = 0; i < pixel_count; i++)
                  ^
../deps/byakuren/lib/mindiff.c:105:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
     for(uint32_t i = 0; i < colored_count; i++)
     ^
../deps/byakuren/lib/mindiff.c:112:18: error: redefinition of ‘i’
     for(uint32_t i = 0; i < grayed_count; i++)
                  ^
../deps/byakuren/lib/mindiff.c:105:18: note: previous definition of ‘i’ was here
     for(uint32_t i = 0; i < colored_count; i++)
                  ^
../deps/byakuren/lib/mindiff.c:112:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
     for(uint32_t i = 0; i < grayed_count; i++)
     ^
../deps/byakuren/lib/mindiff.c: In function ‘_bkr_generate_colored_and_gray_pelette’:
../deps/byakuren/lib/mindiff.c:152:9: error: ‘for’ loop initial declarations are only allowed in C99 mode
         for(uint32_t i = 0; i < palette->count; i++)
         ^
../deps/byakuren/lib/mindiff.c:165:9: error: ‘for’ loop initial declarations are only allowed in C99 mode
         for(uint32_t i = 0; i < palette->count; i++)
         ^
make: *** [Release/obj.target/byakuren/deps/byakuren/lib/mindiff.o] Error 1
make: Leaving directory `/node_modules/thmclrx/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at ChildProcess.emit (events.js:180:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
gyp ERR! System Linux 3.10.0-693.21.1.el7.x86_64
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/gaowhen/suede/server/node_modules/thmclrx
gyp ERR! node -v v9.8.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

VS2013编译出错

VS2013编译出错,手动使用如下命令编译:

node-gyp clean
node-gyp configure
node-gyp build
,引入了xmempool后报void*语法错误。

Lab instead of RGB?

What do you think about change for better search color space from RGB to Lab or LCH?
I am not profi, but in CIE76 (color diff. algorithm) using euclidian distance in Lab color space.
In CIE94 used LCH color space.

windows编译时报错

vs2017:
mindiff.c
c:\users\flysoft\desktop\thmclrx-master\deps\byakuren\lib\mindiff.c : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为
Unicode 格式以防止数据丢失 [C:\Users\Flysoft\Desktop\thmclrx-master\build\byakuren.vcxproj]
c:\users\flysoft\desktop\thmclrx-master\deps\byakuren\lib\mindiff.h : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为
Unicode 格式以防止数据丢失 [C:\Users\Flysoft\Desktop\thmclrx-master\build\byakuren.vcxproj]
c:\users\flysoft\desktop\thmclrx-master\deps\byakuren\common.h : warning C4819: 该文件包含不能在当前代码页(936)中表示的 字符。请将该文件保存为 Unico
de 格式以防止数据丢失 [C:\Users\Flysoft\Desktop\thmclrx-master\build\byakuren.vcxproj]
c:\users\flysoft\desktop\thmclrx-master\deps\byakuren\const\palette.h : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存
为 Unicode 格式以防止数据丢失 [C:\Users\Flysoft\Desktop\thmclrx-master\build\byakuren.vcxproj]
c:\users\flysoft\desktop\thmclrx-master\deps\byakuren\lib\mindiff.c(107): error C2065: “_stats_cmp”: 未声明的标识符 [C:\Users
Flysoft\Desktop\thmclrx-master\build\byakuren.vcxproj]
c:\users\flysoft\desktop\thmclrx-master\deps\byakuren\lib\mindiff.c(107): warning C4047: “函数”:“_CoreCrtNonSecureSearchS
ortCompareFunction”与“int”的间接级别不同 [C:\Users\Flysoft\Desktop\thmclrx-master\build\byakuren.vcxproj]
c:\users\flysoft\desktop\thmclrx-master\deps\byakuren\lib\mindiff.c(107): warning C4024: “qsort”: 形参和实参 4 的类型不
同 [C:\Use
rs\Flysoft\Desktop\thmclrx-master\build\byakuren.vcxproj]
c:\users\flysoft\desktop\thmclrx-master\deps\byakuren\lib\mindiff.c(213): error C2065: “result”: 未声明的标识符 [C:\Users\Flys
oft\Desktop\thmclrx-master\build\byakuren.vcxproj]

Hit stdint.h not find in node 0.12.2

node_modules\thmclrx\src\third-party\xmempool\xmempool.h(23): fatal error C1083: Cannot open include file: 'stdint.h': No such file or directory

Any clue for this? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.