Grid Sage Forums
REXPaint => Everything REXPaint => Topic started by: gumix on September 02, 2021, 09:49:09 AM
-
Hey, is there command to replace foreground and/or background colors (as enabled by apply flags) of all cells on current layer with nearest colors in selected palette?
I would have my head cut off there was such thing but I cannot find it in manual now.
-
There indeed is not, and in fact I'm not even sure what "nearest colors" would mean in this case! There being multiple ways to define that...
You can replace specific colors in an image using various means via the palette. Reminder:
Shift-LMB x2 Swap Occurences of Color 1 with Color 2
Alt-LMB (x2) Edit and Replace Foreground Color in Image
Alt-RMB (x2) Edit and Replace Background Color in Image
Also:
Shift-clicking will also open the color picker, but once the new color is confirmed will also replace all matching colors in the image (applied to foreground and/or background, depending on which apply modes are active at the time, NOT whether LMB/RMB used).
Could these be something you're looking for?
-
Thanks Kyzrati,
That is what I've used in the past and probably I've messed it up with another program... ahh yes with my own xp automation :X
There being multiple ways to define that...
Yep I'm aware of that, simple RGB least square diff would be a thing! :)
Is this 2.0 backlog applicable?
-
So in this case "replace with nearest colors" seems like you're trying to convert an image from one entire palette to another different palette, eh? Makes more sense when I think of it like that (I was originally just thinking of one color at a time), although seems pretty niche :P
Could certainly add it to the list for the future, but that's kinda far away, I think... Might be kind of a complicated feature to do a patch for now.
How does "RGB least square diff " work?
-
Yea, it's 100% niche - 1 stupid user (me), I've painted many new sprites using arbitrary rgb colors "just for now, to see how it look".
Then it turned to look really good but sprites were using out of production palette colors :(
How does "RGB least square diff " work?
I meant, for every x,y cell on active layer, separately for background and foreground, we're looking for such palette index (0-255) on active palette which results in smallest color error given by:
int ColorDiff(uint8 rgb1[3], uint8 rgb2[3])
{
static const int w[3] = {3,4,1}; // human is less sensitive to blue changes, this could be configurable
int dr = rgb1[0] - rgb2[0]; // per channel difference
int dg = rgb1[1] - rgb2[1];
int db = rgb1[2] - rgb2[2];
return w[0]*dr*dr + w[1]*dg*dg + w[2]*db*db; // weighted sum of square diffs
}
Of course I've fixed my mistake outside of RP, so it is not must have feature in RP.
-
Gotcha. Well I could probably find a way to slip it into a little patch if you or others have a repeated need for something like this, especially you since you're such a big RP user ;)
-
That's awesome, having it working with apply flags on all unlocked and visible layers would make me the happiest RP user, but probably I'm already :)
-
Alrighty gumix, your special delivery has finally arrived!
Remapping a layer's colors to the current palette can now be done via Shift-Alt-p, or use Ctrl-Shift-Alt-p to remap all unlocked layers.
Demos:
(https://i.imgur.com/DZNp0uV.gif)
(https://i.imgur.com/AIlykQW.gif)
You can download the patch here, with files for overwriting the latest v1.60. Edit: Patch removed, is now included in REXPaint 1.7 (https://www.gridsagegames.com/forums/index.php?topic=1686.0).
Let me know if there are any issues, but based on my tests it currently seems to be working as intended...
-
Works great :)
Previously I've posted a false bug report, I've deleted it immediately after figuring out I'm using wrong key stroke (ctrl_alt_shift_w instead of ctrl_alt_shift_p). I'm sorry, if you had a chance to read it :)
And showing number of colors changed / unique colors is a great addition!
Thank you!
-
Ha, yes I did see that at first since I got it via email and thought it sounded kinda weird ("wait what I reversed the foreground/background in the code or something???"). Happy painting :)
-
Hey, may I ask what actual color difference is implemented?
Works very well, I'm just curious.
-
Yeah I think the results turned out pretty well. I indeed went with Euclidean RGB distance, as per your suggestion. I spent some time researching other options before finalizing that bit, but this approach ended up being both the easiest and fastest, so went with that.
I was kinda surprised it worked as well as it did, since in the past other RGB-related comparison operations I've worked with didn't seem to have nearly as nice an effect as in HSV space. I'd be interested in comparing RGB vs HSV in terms of color matching for this purpose, too (weighted, naturally), but I don't really have a good enough collection of sample material to work with, so that would take too long...
-
Great, thanks. Yes, HSV may be better if snapping to particular hue is more important than global luminance match.