Xcoder. In /2017/03/03/…

Long time no post, by Byakuren open source file to fry cold rice.

Start with the Repo address: github.com/XadillaX/by… .

The theme color

Image theme color is a variety of colors extracted from an image that can best represent the main tone of the picture. In other words, in a colorful picture, the number of different colors corresponds to the proportion of the color in the picture. The program can calculate the theme color by counting the number of pixels of different colors in the picture.

Theme color extraction algorithm

The extraction algorithm was explained in my previous blog post. In Byakuren, we actually use some of the algorithms that we talked about in the previous blog.

  • Octree extraction method
  • Minimum difference method

In addition to the above two algorithms, Byakuren also provides the Mix algorithm which combines the two algorithms.

Byakuren

Byakuren is a theme color extraction library I wrote two years ago. It is also the C version implementation after THMCLRX. Personally, I think the code quality is higher than the old version of THMCLRX. And it’s actually enterprise-level proven and has been running happily for a few years in a relevant company.

With the consent of the relevant personnel, I also calculated to open source the code that had been hidden for a long time.

What is pseudo-byakuren?

byakuren

The better White lotus (better り ゃ Utuito code, Hiziri Byakuren) is a character in the series of works “Oriental Project”, which first appeared in “Oriental Star Lotus Ship”.

  • Race: Magic agent
  • Ability: Ability to use magic degree (greatly enhanced physical ability)
  • Risk: unknown
  • Human friendliness: medium
  • Main venue: Myoren Temple
  • The abbot of Myorenji temple. Although originally a human, but due to years of practice has been completely beyond the human. Now it belongs to what people call magic agents.

Although I have entered the Buddhist gate, I don’t know why I am admired by the devil. She had never chanted a spell to ward off monsters, as the magicians in fairy tales did. The power she wielded was pure evil, not at all saintly, and although no one had ever seen her against humans, she had become a complete companion of the goblins.

Well, ANYWAY, I’m an Orientalist, so basically the project names are orientalist.

What is true Byakuren?

As the title of the article says, it is a C implementation of open source theme color extraction library, you can compile it into a link library for use.

If you are interested, you can also build your own Visual Studio project under Windows. You are also welcome to mention PR similar to CMake.

use

In fact, the detailed use method is explained in the documentation.

But here is a brief introduction.

Clone

You can Clone it if you want. In short, the warehouse address is: github.com/XadillaX/by… .

make

Then run to the directory and execute make.

$ make byakurenCopy the code

You’ll get a statically linked library of Byakuren. A.

Just take the static link library and import the header file in your project.

#include "byakuren.h"Copy the code

API

Let’s assume you have bkr_RGB * RGB image pixel information and uint32_t color_count image pixel total two variables, the following three examples are given respectively. Please refer to the documentation for detailed API parsing.

Octree
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);
bkr_release_octree(root);Copy the code

Colors is the number of theme colors, and stats will receive specific information about the theme colors.

Min-diff
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);Copy the code

Colors and STATS are described above.

Mix
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);Copy the code

Colors and STATS are described above.

preview

Maybe some of you want to see the effect, so I’ll just show you the effect.

The maximum number of theme color parameters of Octree and Mix algorithms is 16.

Results the preview

What can be done?

You can use it to write something about theme color extraction.

You can also use it to wrap theme color extraction libraries in other languages, such as Python, Lua, and so on. Welcome feedback to me.

conclusion

It’s a great feeling to open source a piece of code that you think is good, especially when it’s out in the open. ヘ |, ∀, | ノ * ~ *