I’ve used ImageMagick in the past and it had that useful color remap function that map a full 24 bit image to a 256 colors picture. So I’ve made a compositor node that does exactly that:
Currently, I’m using the FloydSteinberg algorithm and I’ve put an adjustable threshold parameter. The palette is from an image you open using the node i.e. I’ve copied the code of the ImageNode to load an image.
Can you give feedback on how I should improve or what I should add?
I’m also kind of new to the code versioning system that blender uses, is it similar to github?
Right now, only FloydSteinberg dithering is implemented. The threshold percentage is configurable using a slider. In the future, positioned dithering might be worth implementing, and letting the user choose the dithering method using a combox box.
EDIT - I have a nasty assert when moving the node
/* This function should be removed whenever #ui_layout_replace_but_ptr is removed. */
void ui_button_group_replace_but_ptr(uiBlock *block, const void *old_but_ptr, uiBut *new_but)
{
LISTBASE_FOREACH (uiButtonGroup *, button_group, &block->button_groups) {
LISTBASE_FOREACH (LinkData *, link, &button_group->buttons) {
if (link->data == old_but_ptr) {
link->data = new_but;
return;
}
}
}
/* The button should be in a group. */
BLI_assert(false);
}
EDIT - ok, it does that on any node, debug is broken in latest version…
Hi,
first I want to say that it is nice to see in the diff what actually goes into creating a new node. Kind of a minimal example on how to get a node working…
I think the function itself is nice to have, my only point would be the name:
Saw its named ‘color map’ in ImageMagick, but that is a too unspecific name for what it does - don’t you think?
Maybe something more along the lines of ‘Color Dithering’?
edit: maybe I just don’t see it (didn’t look at the code), but how do you set the number of colors in the node?
Atair, in ImageMagick, the function is called “Color Remap”. It cannot be called Color Dithering as you can remap the colors without actually applying dithering if you put the dithering threshold to 0% i.e. it will only map to the closest color in the palette.
The color palette is set by opening an image using the file browser (like the image node). It then reads all the different colors in the image and push them into a color table that the FloydSteinberg operation uses afterward.
I’m a contributor for the OpenRCT2 project and we need a pipeline to produce sprites in the rct2 color palette. For rendering custom rides, there can be more than 1000 sprites to render, it would be great that blender applies the dithering effect automatically at the end of the rendering process.
Here is an example of the rct2 color palette image file:
In rct2, there are specific colors that when used, they can remap to a different color palette.
Right now, I’m using the blender compositor + ImageMagick for the dithering function to automate the rendering of sprites. Here are some trees I’ve recently done for example (disregard the dark trunk):
The trees uses the same sprite using the recolorable palette. It’s not the best dithering example as it is quite noisy, but for simpler shapes, the dithering is very important!
The trunk is mapped to the purple palette and the leaves are mapped to the green palette, then summed together. This helps to fasten up the post-effects process.
Okay, thanks.
Another question arises, is using an image as a color table the best option?
Is it possible to use something like ‘.cube’, ‘.3dl’ files for this purpose. (Not sure, just a question.)
if it could use cube files I think it would become a much more general purpose node, than it is in its current state. Because I can imagine it being rejected for being too specific in its use-case.
The moment it supports cube files (and palette mapped image inputs as well as dithering) it becomes a node that is compatible with many different programs
EDIT2 - I’m not sure if a LUT is actually in the scope of the functionality I wanted to implement with this. A LUT seems more like a transform that you need to apply interpolation between the points defined in the cube, while the functionality I’m targeting is to restrict to specific colors the image.
Also, GIMP and ImageMagick do not take LUT files when remapping colors, they either take a palette or an image file.
I mostly meant something similar to ‘.cube’, ‘.3dl’ files, i.e. something like a plain text file with a list of colors. But, Yes, as you’ve noticed the use of a palette is suitable for this. You could try using the palette widget (uiTemplatePalette) for this.
You might need to add import/export. But I found “PALETTE_OT_extract_from_image”, so I think you can easily convert your image-table to palette.