lvgl / lv_utils

Convert images or system fonts to C arrays. Written for LVGL embedded GUI library
https://littlevgl.com
54 stars 38 forks source link

Dithering for LittlevGL #8

Closed robwin311 closed 6 years ago

robwin311 commented 6 years ago

Hello Gábor,

I've added Floyd-Steinberg dithering algorithm to image converter script as I wrote in e-mail. Here is pull request. I hope that i didn't break anything (with the pull request) and it will be useful

copy of repo and examples in: https://gitlab.com/rwinkler147/littlevgl-dithering

Other changes

In original converting script bit mask was used to classify pixels. Due to that they always be rounded down. More precise way of classification is to put the pixel to the closest possible value.

Better way of comparing strings in PHP is to use strcmp() function then == operator.

Usage

Dithering is enabled by default. If you want to disable it just add apropriate argument dith=disable:

php img_conv_core.php "name=icon&img=bunny.png&format=c_array&dith=disable"

Sorry for the confusion it's my first time with pull requests on github.

kisvegabor commented 6 years ago

Hi Robert,

It's a great feature for the image converter. I tried it and worked perfectly. I will definitely add it to the image converter tool! Thank you very much!

For the next release of LittelvGL, I'm working on lighter image support. It means supporting of indexed images (1, 2, 4, 8 bit color and/or 1 bit, 2 bit, 4 bit, 8 bit alpha). So your dither improvement came in the best time! :)

I already made some experiments with PHP's built-in true-color to indexed image converter function but didn't work well (http://php.net/manual/en/function.imagetruecolortopalette.php). Fortunately, I found a simple algorithm to do the conversation: https://en.wikipedia.org/wiki/Median_cut

If you are interested in image manipulation algorithm and if you want to contribute in the indexed image feature, please let me know and we discuss the details.

Also thank you for the other improvements. As you can see I'm not a PHP expert :)

robwin311 commented 6 years ago

I really regret but now I'm working and preparing my engineer's thesis, due to that I almost have no free time. If I can help you with dithering I will try do my best! :) but the amount of time that I dispose is limited, so I can't help you with indexed image feature.

It is a pity because I find your project really interesting! Surely, I will follow it and maybe it will be possible to help you in future. But as I said if I can help with dithering just send me message :)

kisvegabor commented 6 years ago

I see, thank you for the feedback!

No worries and good luck with your thesis! :)