Okay, so... edge detection filter.
My initial impetus to work on this was that I was looking at Inkscape's svg filters, and thinking to myself, "darn, that specular looks awful", and that's because the heightmap to normal map code isn't stellar.
And then I realised we still had this issue with our own heightmap code in the phongbumpmap, and there's also been a request to make a general heightmap to normal map filter.
Now, the basis of a heightmap to normal map filter is a edge detection convolution filter. Our current sobel filter is a little old, and thus lacked the systems to make it a proper filter layer, like the gaussian blur did, so that gets up to this patch.
We have here a "Edge Detection" filter that can do prewit, sobel, and the super-simple cousin of sobel based on the old sobel filter. The larger sizes are determined based on the 4th answer noted here: https://stackoverflow.com/questions/9567882/sobel-filter-kernel-of-large-size (I wanna try the third answer as well at some point, but I am still trying to determine how kernels really work, so number 4 was easier to implement).
Now, the patch isn't complete, I have several questions:
@dkazakov:
1. The maths in the filter doesn't really match up with the old sobel filter. The old sobel filter, amongst others...
1. In the old filter, the two horizontal versions are subtracted from on another, same for the two vertical versions. Then, the horizontal and vertical version have the pythagoras theorem applied to them for mysterious reasons. Should I copy this fully(Right now just using addition)? I would then need to make a seperate blending mode that does a pythagoras equation to the src and dst, would I not? Is this of any use at all?
2. The result is also divided by a certain value. I think I know where this comes from, it's mentioned at the end of the third answer in that stack overflow post. How would I go about applying this division? Make a colortransform? Or just abuse the division blending mode? (Like, fill a device with a color of value 8, apply division blending mode, see what comes out)
2. I would like to make a variation of this that instead of overwriting the whole device, it makes a grayscale version and writes the result into the alpha of the device. This is much more useful to artists, as it gives a thin outline to their colorpatches. How would I go about writing the grayscale result that is in a seperate paint device into the alpha channel of the main paint device when I only have kispainter and kispaintdevice to my disposal? (And, technically, is there a method for doing this with any of the channels? That'd be necessary for the normal map filter which I'll make later :) )
@boud: I am having trouble determining how to load the filter type into the comboboxes. Like, filtertype to config goes fine, but the result is a bit... flaky? How can I make this robust as possible?
I am also thinking.. theoretically, I could make this filter encompass the old left/right/top/bottom edge detection on top of the old sobel filter, but I think that would need either a) 4 sliders, or b) two sliders and a toggle for left/right/both and top/bottom/both? Would this be sensible?
Maybe I should divide the filter UI into two tabs: one that is interesting to artists, and an advanced tab, for these kind of fiddly features that are there for backward compatibility.
Any other comments are welcome too.