All Projects → XadillaX → Byakuren

XadillaX / Byakuren

Licence: mit
🎭 A theme color extracting library implemented by C.

Programming Languages

c
50402 projects - #5 most used programming language

Labels

Projects that are alternatives of or similar to Byakuren

Aerogameframework
AeroGameFramework is a Roblox game framework that makes development easy and fun. The framework is designed to simplify the communication between modules and seamlessly bridge the gap between the server and client.
Stars: ✭ 150 (-4.46%)
Mutual labels:  library
Android Ui Animation Components And Libraries
Android UI libraries, components and animations by @Ramotion
Stars: ✭ 1,982 (+1162.42%)
Mutual labels:  library
Pulltobounce
Animated "Pull To Refresh" Library for UIScrollView. Inspired by https://dribbble.com/shots/1797373-Pull-Down-To-Refresh
Stars: ✭ 1,866 (+1088.54%)
Mutual labels:  library
Python Quickui
Scientific One-Liner Interactive GUI Library
Stars: ✭ 153 (-2.55%)
Mutual labels:  library
Gappein Chat Sdk
A plug and play modular toolkit for integrating the Chat feature on top of Firebase!
Stars: ✭ 154 (-1.91%)
Mutual labels:  library
Codeeditor
Code Editor Native Way
Stars: ✭ 155 (-1.27%)
Mutual labels:  library
Weihanli.common
common tools,methods,extension methods etc... .net 常用工具类,公共方法,常用扩展方法等,基础类库
Stars: ✭ 152 (-3.18%)
Mutual labels:  library
Rpimotorlib
RpiMotorLib : Raspberry Pi Motor Library : A python 3 library for various motors and servos to connect to a raspberry pi
Stars: ✭ 156 (-0.64%)
Mutual labels:  library
Atty
are you or are you not a tty?
Stars: ✭ 153 (-2.55%)
Mutual labels:  library
Paintablevectorview
PaintableVectorView enables to change color of paths/groups in Vector Drawable (SVG)
Stars: ✭ 156 (-0.64%)
Mutual labels:  library
Garland View Android
≡ GarlandView seamlessly transitions between multiple lists of content. Made by @Ramotion
Stars: ✭ 1,855 (+1081.53%)
Mutual labels:  library
Jails
An alternative for Javascript Vanilla Applications
Stars: ✭ 153 (-2.55%)
Mutual labels:  library
Dem.net
Digital Elevation model library in C#. 3D terrain models, line/point Elevations, intervisibility reports
Stars: ✭ 153 (-2.55%)
Mutual labels:  library
Php Ip Tools
Useful tools for IP manipulations
Stars: ✭ 152 (-3.18%)
Mutual labels:  library
Degate
Open source software for chip reverse engineering.
Stars: ✭ 156 (-0.64%)
Mutual labels:  library
Deeply
PHP client for the DeepL.com translation API (unofficial)
Stars: ✭ 152 (-3.18%)
Mutual labels:  library
Harfbuzz
HarfBuzz text shaping engine
Stars: ✭ 2,206 (+1305.1%)
Mutual labels:  library
Isobmff
C++ Library for ISO/IEC 14496-12 - ISO Base Media File Format (QuickTime, MPEG-4, HEIF, etc)
Stars: ✭ 157 (+0%)
Mutual labels:  library
Dotnet Etcd
A C# .NET (dotnet) GRPC client for etcd v3 +
Stars: ✭ 157 (+0%)
Mutual labels:  library
Ofxgpio
Library C++ for raspberrypi and orangepi, GPIO interfaces compatible with openframeworks.
Stars: ✭ 155 (-1.27%)
Mutual labels:  library

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

  • [x] octree algorithm
  • [x] min-diff algorithm
  • [x] 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.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].