This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Quantise to Palette filter layer

Tags: None
(comma "," separated)
User avatar
surt
Registered Member
Posts
20
Karma
0
OS

Quantise to Palette filter layer

Sat Jun 01, 2019 3:30 am
A filter layer to quantise colours to fit a user specified palette.
Would be nice for keeping pixelart palette conforming.
Now that palettes can be stored in document won't need to rely on an external palette.
ramskulls
Registered Member
Posts
134
Karma
2
Oh... yes that would be incredible. I wonder how feasible it would be though?
User avatar
surt
Registered Member
Posts
20
Karma
0
OS
I'm working on it at the moment.
So far got the basic palettization working fine.
Using a boost::geometry rtree to accelerate palette search, so it's speedy enough.
Want to add some dithering options yet, if I can figure out how to do so to my liking.
ramskulls
Registered Member
Posts
134
Karma
2
WOW that's pretty awesome!!! <:0 Thank you so much for doing this ♥️
User avatar
TheraHedwig
KDE Developer
Posts
1794
Karma
10
OS
surt wrote:I'm working on it at the moment.
So far got the basic palettization working fine.
Using a boost::geometry rtree to accelerate palette search, so it's speedy enough.
Want to add some dithering options yet, if I can figure out how to do so to my liking.

I was thinking of reworking the index-colors filter for this, as it was originally designed for that, maybe you can find some inspiration there?

It was written by Manuel Riecke/MrBeast who is(was) an OpenGameArt regular :p But at the time we didn't realize what he wanted to do could've been done with palettes instead of him generating one.
User avatar
surt
Registered Member
Posts
20
Karma
0
OS
TheraHedwig wrote:I was thinking of reworking the index-colors filter for this, as it was originally designed for that, maybe you can find some inspiration there?

My motivation is much the same I think, HD index painting, but I'm not keen on the automatic palette generation's lack of individual colour control.

It looks to be brute-forcing palette search, but does calculate the colour distance in the Lab colourspace.

Using boost::geometry rtree's built-in euclidean distance rather than the colourspace distance function as so far I haven't found a way to use a custom distance metric with rtree.

I'm not very knowledgeable about colourspaces and at the moment I'm just comparing distance in RGB which I know isn't great. I know Lab is much better than RGB for this, but is it definitively the "best" colourspace for measuring colour distance, or should I just use the image colourspace?
User avatar
halla
KDE Developer
Posts
5092
Karma
20
OS
Using Lab is definitely the right choice.
User avatar
surt
Registered Member
Posts
20
Karma
0
OS

Re: Quantise to Palette filter layer

Sat Jun 08, 2019 10:57 am
Got some simple dithering working. Just finds the two nearest colours and thresholds a pattern between them based on relative distances. Not super sure about it, but can produce some decent results.

DawnBringer 16 colour palette and 4x4 bayer pattern: http://img.uninhabitant.com/Screenshot_20190608_205106.png
User avatar
halla
KDE Developer
Posts
5092
Karma
20
OS

Re: Quantise to Palette filter layer

Sat Jun 08, 2019 11:29 am
Looks pretty cool!
User avatar
surt
Registered Member
Posts
20
Karma
0
OS
Got the GUI basically done, just got a semi-problem with configuration not being saved when first creating a filter layer. Updating the configuration on property widget changes hides this quite reliably, but still the problem is there.

Turns out the PAT format patterns which I thought were 1-bit are actually RGBA, so to use them I added a "use alpha" option, but otherwise uses pattern colour lightness.

Also added a noise dither option as already had it for testing.

http://img.uninhabitant.com/Screenshot_20190609_132501.png
User avatar
surt
Registered Member
Posts
20
Karma
0
OS
Put an initial patch up on Phabricator if anyone wants to try it: https://phabricator.kde.org/D21682


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Evergrowing, Google [Bot], rblackwell