• Stars
    star
    169
  • Rank 224,453 (Top 5 %)
  • Language
    C
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🎭 A theme color extracting library implemented by C.

Byakuren

A theme color extracting library implemented by C.

This library is used in a related company for years.

TODO: Using KD-Tree to find some colors.

聖 白蓮

聖 白蓮

聖 白蓮(ひじり びゃくれん,Hiziri Byakuren)是系列作品《东方project》中的角色,首次登场于《东方星莲船》。

  • 种族:魔法使
  • 能力:使用魔法程度的能力(酣畅增强身体能力的)
  • 危险度:不明
  • 人类友好度:中
  • 主要活动场所:命莲寺之类

命莲寺的住持。虽然原本是人类,不过由于常年的修行已经完全超越了人类。现在已经属于人们常说的魔法使了。

虽然已经入了佛门,但是不知道什么原因却被妖怪敬仰着。她从来没有像童话故事中的魔法使那样,念诵着咒语治退妖怪。使用的力量完全是邪恶的,一点都不像是圣人,虽然并没有人目击到她与人类为敌,但其实已彻底成为妖怪的同伴了。

Compile Static Library

Clone the project first.

$ git clone --recurse-submodules https://github.com/XadillaX/byakuren.git

This project can be compiled to a static libary (byakuren.a) for using.

$ make byakuren

After compiling, you may use this library just by including byakuren.h in your project.

#include "byakuren.h"

Supported Algorithm

  • octree algorithm
  • min-diff algorithm
  • mix-in algorithm

APIs

bkr_rgb Structure

typedef struct bkr_rgb {
    uint8_t red;
    uint8_t green;
    uint8_t blue
} bkr_rgb;

RGB pixel structure.

name type description
red uint8_t the RED value (0-255)
green uint8_t the GREEN value (0-255)
blue uint8_t the BLUE value (0-255)

bkr_color_stats Structure

typedef struct bkr_color_stats {
    bkr_rgb color;
    uint32_t value;
    uint32_t count;
} bkr_color_stats;

Stats of theme color result.

name type description
color bkr_rgb a color pixel to indicate a theme color
value uint32_t a color pixel's INT32 value to indicates the theme color
count uint32_t stats of this theme color in the picture
typedef struct bkr_palette_array {
    uint32_t count;
    bkr_rgb* colors;
} bkr_palette_array;

A crowd of colors to indicate a theme color palette.

name type description
count uint32_t color count in this palette
colors bkr_rgb* each color in this palette

bkr_mindiff_parameter Structure

typedef struct bkr_mindiff_parameter {
    bkr_palette_array* palette;
    int16_t gray_offset;
} bkr_mindiff_parameter;

A parameter passes to Min-diff Algorithm.

name type description
palette bkr_palette_array* a palette to calculate the theme color, left for NULL to indicate the default palette
gray_offset int16_t the offset to judge whether a color is gray, recommand to be 5

Initialization & Release

Before the whole work you should initialize the Byakuren environment:

int bkr_init();

And after all the work you should release the environment:

void bkr_destroy();

Octree Algorithm

Build Octree

bkr_octree_node* bkr_build_octree(
        bkr_rgb* pixels,
        uint32_t pixel_count,
        uint32_t max_colors);
parameter type description
pixels bkr_rgb* the RGB pixels of a picture
pixel_count uint32_t pixel count of the picture
max_colors uint32_t maximum theme color count this octree will have
  • Return an octree

Calculate

int bkr_octree_calculate_color_stats(
        bkr_octree_node* node,
        bkr_color_stats stats[]);
parameter type description
node bkr_octree_node* the octree which bkr_build_octree returned
stats bkr_color_stats an array to receive each theme color stats
  • Return the count of theme colors.

Release Octree

void bkr_release_octree(bkr_octree_node* node);
parameter type description
node bkr_octree_node* the octree to be released

Example

bkr_rgb* rgb = GET_PICTURE_RGB(); // implement by yourself
uint32_t color_count = GET_PICTURE_PIXEL_COUNT(); // implement by yourself
bkr_color_stats stats[256];
bkr_octree_node* root = bkr_build_octree(rgb, color_count, 256);
int colors = bkr_octree_calculate_color_stats(root, stats);

Min-diff Algorithm

Calculate

int bkr_mindiff_calculate_color_stats(
        bkr_rgb* pixels,
        uint32_t pixel_count,
        bkr_color_stats stats[],
        bkr_mindiff_parameter* param);
parameter type description
pixels bkr_rgb* the RGB pixels of a picture
pixel_count uint32_t pixel count of the picture
stats bkr_color_stats an array to receive each theme color stats
param bkr_mindiff_parameter* the parameter passes to Min-diff Algorithm for calculating
  • Return the count of theme colors.

Example

bkr_rgb* rgb = GET_PICTURE_RGB(); // implement by yourself
uint32_t color_count = GET_PICTURE_PIXEL_COUNT(); // implement by yourself
bkr_color_stats stats[256];
bkr_mindiff_parameter param;
param.gray_offset = 5;
param.palette = NULL;
int colors = bkr_mindiff_calculate_color_stats(rgb, color_count, stats, &param);

Mix Algorithm

Mix Octree and Min-diff up.

Calculate

int bkr_mix_calculate_color_stats(
        bkr_rgb* pixels,
        uint32_t pixel_count,
        uint32_t octree_max_colors,
        bkr_mindiff_parameter* mindiff_param,
        bkr_color_stats stats[]);
parameter type description
pixels bkr_rgb* the RGB pixels of a picture
pixel_count uint32_t pixel count of the picture
octree_max_colors uint32_t maximum theme color count this octree will have
param bkr_mindiff_parameter* the parameter passes to Min-diff Algorithm for calculating
stats bkr_color_stats an array to receive each theme color stats
  • Return the count of theme colors.

Example

bkr_rgb* rgb = GET_PICTURE_RGB(); // implement by yourself
uint32_t color_count = GET_PICTURE_PIXEL_COUNT(); // implement by yourself
bkr_color_stats stats[256];
bkr_mindiff_parameter param;
param.gray_offset = -1;
param.palette = NULL;
int colors = bkr_mix_calculate_color_stats(rgb, color_count, 256, &param, stats);

Test Command

$ make ./test/bkr_test

After make command, you should generate a binary file named test.rgb. Then run:

$ cd test && ./bkr_test ALGORITHM

You may create your own .rgb file by referring test/run.js or test/test.c. Or you may have a look at Test Helper.

ALGORITHM is a parameter means algorithm you want to test.

support octreemindiff and mix so far.

Test Helper

If you want to test quickly (no *.rgb), you may use a simple script.

Install Node.js first and come to test folder. Then run:

$ cd test
$ npm install

NOTICE: You can start test helper directly under OSX. Otherwise, you should compile a test binary executor before testing, that is $ make ./test/bkr_test.

After installing, run --help.

$ ./run.js --help

You will see some introduction. -u means a URL.

For an example:

$ ./run.js -u http://cdn.duitang.com/uploads/item/201205/22/20120522224448_43nFu.thumb.600_0.jpeg -a octree

After command above, a browser will be open to display the result.

If you want to test three algorithm at one time, you should make -a be all.

For an example:

$ ./run.js -u http://cdn.duitang.com/uploads/item/201205/22/20120522224448_43nFu.thumb.600_0.jpeg -a all

How It Look Like

Result

With octree_max_colors be 16 in Octree and Mix algorithm.

Contribution

You're welcome to make Pull Requests.

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

More Repositories

1

nyaa-nodejs-demo

Source code of "Node.js: Let's Write a Dozen of C++ Add-ons". 《Node.js:来一打 C++ 扩展》随书源码。
C++
379
star
2

Toshihiko

🥚 Yet another simple ORM for Node.js.
JavaScript
258
star
3

chinese-random-name

🈺 Generate Chinese name using Node.js.
JavaScript
257
star
4

thmclrx

🎨 A theme color extractor module for Node.js.
JavaScript
199
star
5

aliyun-ons

☁️ SDK of Node.js for Aliyun ONS. 🚀
C++
157
star
6

xto

💌 Just an API for Node.js to query each express.
JavaScript
142
star
7

sfml.js

A cross-platform SFML's Node.js binding.
C++
77
star
8

hexadillax

A hexo blogging system theme.
CSS
65
star
9

zhaofuli-reader

👙 A light-weighted reader for zfl520.com.
JavaScript
38
star
10

bling_hashes

String hash algorithms for node.js.
C++
38
star
11

fbibik-json

Parse JSON-Object string (not normalized JSON string) into JSON object.
JavaScript
33
star
12

wanimal-spider

An image spider for a certain Lofter Blog called WANIMAL.
JavaScript
32
star
13

node-redis-as-queue

A node.js package for regarding redis as a message queue.
JavaScript
28
star
14

alinode-docker

Dockfile for alinode.
Shell
28
star
15

bilibili-av

This module is for getting bilibili subtitles via a certain av number and its page number.
JavaScript
28
star
16

ama

Ask me anything!
27
star
17

chinese-random-skill

Generate Chinese skill using Node.js.
JavaScript
27
star
18

hexo-xnew

X'new theme for Hexo. Referred from https://github.com/sjaakvandenberg/flexy.
Pug
27
star
19

nyaa-express

An express query app demo built by Express and XTO.
JavaScript
27
star
20

spidex

A web requester for node.js.
JavaScript
25
star
21

eggirl

A React-Native implemented girl collections of jandan. Only for studying.
JavaScript
23
star
22

node-sfml-demos

Demos for sfml.js.
JavaScript
22
star
23

ez-upyun

Yet another upyun SDK for node.js which are eazy to use.
JavaScript
21
star
24

illyria2

The next generation Illyria RPC SDK for node.js.
JavaScript
20
star
25

scarlet-task

A task queue module for node.js. You can set several children-queue for one task queue.
TypeScript
20
star
26

play-nes

A cross-platform desktop NES emulator powered by OpenGL in Node.js.
JavaScript
19
star
27

vscode-language-viml

VimL plugin for VSCode.
TypeScript
19
star
28

node-efsw

Watching your filesystem events just like fsevents. But node-efsw is cross-platform.
C++
19
star
29

me

CV of mine on GitHub.
17
star
30

ssunneljs

An easy ssh-tunnel web ui tool.
CSS
17
star
31

public-file-house

A temporary file store net disk.
JavaScript
15
star
32

true-html-escape

True module to escape and unescape html, including some unicode unescaping like `〹` that other escaping modules don't include.
JavaScript
15
star
33

workflow-xto

Alfred workflow for XTO.
JavaScript
14
star
34

xmempool

🛀 A memory pool implemented by C.
C++
13
star
35

theme-color-test

Theme color pick - experimental.
JavaScript
13
star
36

dloucflare

To run at a server which has a dynamic IP and cloudflare service. It can dynamic modify your DNS record by your realtime IP address.
JavaScript
12
star
37

yuna

The extra Zookeeper support for Illyria client pool.
JavaScript
11
star
38

xaengine

一个基于HGE不成熟且太监了的游戏引擎。并附了两个由该引擎写的小游戏。
C++
11
star
39

ihuyi106js

iHuyi 106 SMS sender for node.js.
JavaScript
11
star
40

12zodiac

Calculate out which zodiac one certain day is.
JavaScript
10
star
41

auto-object

☄️ Create auto properties object and class in Node.js just like Proxy.
JavaScript
10
star
42

gensokyo

An RPC framework implemented in Node.js with https://github.com/XadillaX/illyria2 which is in use of Huaban.com.
JavaScript
10
star
43

syncRunner

To execute a binary executable file and return its standard output synchronization. (node.js)
C++
9
star
44

lianliankan

本科时期早期代码,连连看,留个档。
C++
8
star
45

_vimrc

XadillaX' Vimrc.
Vim Script
7
star
46

pixel-getter

Image pixels information getter for node.js.
JavaScript
7
star
47

dpdd

Dynamic Domain for DNSPod.
JavaScript
7
star
48

mcregion

A node.js parser for Minecraft region (*.mca) file.
JavaScript
6
star
49

liburlencode

C++ library for urlencode.
Python
6
star
50

egg-rfc1775-fictitious

The fictitious example for Egg.js RFC1775.
6
star
51

www.cst.zju.edu.cn-cengwang

浙大软院蹭网小脚本,用于教室学生账号,没有学生账号的时候暴力去试。
JavaScript
6
star
52

json-formatter.vim

A VIM plugin for formatting saved JSON file.
Vim Script
5
star
53

node-mp4duration

A node.js package to parse mp4 file's duration.
C++
5
star
54

chengdu-fcc

5
star
55

mikasa

A kafka sender for testing.
JavaScript
5
star
56

fetion-sender

The Fetion sender for Node.js.
JavaScript
5
star
57

libwhatwgurl

C++ implement for WHATWG URL.
C++
5
star
58

gyp-io-service

Temporary solution to let node-gyp run `rebuild` under io.js.
JavaScript
5
star
59

jquery.loadingMask

To quickly build a loading mask.
JavaScript
4
star
60

vjudge-submitter.old

The Virtual Judge core module of NODE.JS.
JavaScript
4
star
61

bling_hashes_js

Pure JavaScript dist for Bling Hashes.
JavaScript
4
star
62

SevenzJS

A super light weighted Node.JS framework with easy router.
JavaScript
4
star
63

wil-viewer

Legend of Mir2 WIL Viewer - a cross-platform *.wil file viewer.
TypeScript
4
star
64

daily-sentence

A `daily-sentence` module for node.js. (data from http://xue.youdao.com/w?page=1&type=all&position=tinyEnglish)
JavaScript
4
star
65

vim-mir2-colorscheme

Mir2 color scheme for Vim.
Vim Script
3
star
66

GujianEditor

古剑奇谭存档修改器——2010 年老代码留档。
C++
3
star
67

rukoto

Yet another simple MySQL ORM for Node.js.
3
star
68

hexo-site

一个伪宅级别的码畜。
HTML
3
star
69

ghosadillax

A node-ghost blogging system theme.
CSS
3
star
70

render-ojn

Renders O2Jam OJN/OJM to MP3/WAV/OGG music file. (Forked from https://github.com/djzmo/render-ojn)
C
3
star
71

gobangofpomelo

A tiny gobang game built by pomelo.
JavaScript
3
star
72

Toshihiko-Memcached

The memcached support for Toshihiko as an addon.
JavaScript
3
star
73

zh-rust-by-example

跟着例子学 Rust(包含在线编辑器)中文版。http://rustbyexample.com
Rust
3
star
74

tmuxrc

My tmux configuration.
Shell
3
star
75

vscode-mir2-colorscheme

The Legend of Mir2 Theme for VSCode.
3
star
76

clj-jb

The Clojure version of Jieba (https://github.com/fxsjy/jieba). 结巴分词 Clojure 版。
Java
3
star
77

vscode-extension-fengdie-schema

Fengdie schema support for Visual Studio Code.
2
star
78

wil-parser

Parser for *.wil (Legacy version of "Legend of Mir2", with *.wix) files.
JavaScript
2
star
79

node-motto

A node package to get random motto.
JavaScript
2
star
80

vscode-gyp

gyp support for VSCode.
TypeScript
2
star
81

node-hge-demo

A minimum verifiably HGE demo for Node.js.
C++
2
star
82

nbt.cc

Minecraft NBT format parser and modifier without zlib compression.
C++
2
star
83

cpplint.js

Node.js wrapper for CPPLINT.
C++
2
star
84

jjson

A CLI json beautify program written by node.js.
JavaScript
2
star
85

thmclrx-stress-tester

Stress tester for thmclrx.
HTML
2
star
86

vscode-van-gogh-paintings

Vincent van Gogh's painting themes for VSCode.
2
star
87

day-from-1970

Calculate out which day, month, year and week from 1970.1.1 via one timestamp.
JavaScript
2
star
88

detect-python-interpreter

Detect the executable python interpreter cmd in $PATH.
JavaScript
2
star
89

XadillaX

2
star
90

node_tasted

Node.js 浅尝辄止——分享至我仍未知道名字的十楼公司。
2
star
91

biulog

A taste for Rust to parse MySQL binlog by faking slave.
Rust
1
star
92

hge-mfc-demo

It's an MFC demo for HGE (This project is due to my one previous company). An map maker demo included.
C++
1
star
93

otrans

Object key transformation for Node.js.
JavaScript
1
star
94

aliyun-ons-purejs

☁️ SDK of Node.js for Aliyun ONS with pure js. 🚀
JavaScript
1
star
95

theme-color-slide

Theme color share slide in huaban.
JavaScript
1
star
96

hero-snake

A C++ game.
C++
1
star
97

exmcached-session

Ⓜ️ Session store for expressjs with memcached.
JavaScript
1
star
98

50prob

My first cocos2d-x game.
C
1
star
99

vscode-language-webidl

VSCode support for `*.webidl`.
1
star
100

localip

Get your local IP in node.js.
1
star