Replacing KisFilter::overlapMarginNeeded

Cyrille Berger cberger at cberger.net
Sun Dec 7 11:12:26 CET 2008


Hello,

Most of what I am going to discuss here is 2.1 material, but taking a decision 
on this will affect how I fix the bug I want to fix.

I realized that KisFilter::overlapMarginNeeded wasn't very good while trying 
to fix drawing on a layer with a blur filter filter mask (any kind of kernel 
filter would have the problem), the problem of that bug is that only the 
rectangle that was changed by the drawing is updated, while for a blur filter 
the affected area is bigger.

So what the problem with KisFilter::overlapMarginNeeded ? I think it was 
designed with convolution filter in mind, which usually need a constant 
border around their work area. It also was designed only to determine which 
area is needed to compute the fitler, not which area is affected by the 
change of a filter, the good thing for a convolution filter is that it's the 
same computation... but that's not the case of every filter.

Let's take the exemple of a "translation filter", that would move pixels from 
+10px in horizontal and vertical direction. Lets say we want to compute the 
result of QRect(22, 33, 30, 40) (*), the pixels I need are QRect( 12, 23, 20, 
30), but with KisFilter::overlapMarginNeeded I would be forced to return 10, 
which would then correspond to QRect( 12, 23, 50, 60 ), a much bigger area 
that necesseray. But things get worse when I want to compute which area I 
need to update after the user modify QRect(22, 33, 30, 40), the affected area 
is QRect(32, 43, 30, 40), but with KisFilter::overlapMarginNeeded I would say 
that QRect( 12, 23, 50, 60 ) needs to be updated...

Of course, the problem of "translation filter" happen for more usefull 
filters, such as wave, distortion...

Here is a possible solution, inspired from Shiva (which inherits it from 
Hydra):

* QRect KisFilter::neededRect( QRect _outputArea ) : return the rectangle of 
pixels needed in the input paint device when Krita wants to process the 
_outputArea
* QRect KisFilter::changedRect( QRect _inputArea ) : return the rectangle of 
pixels that are going to be changed in the output paint device when the user 
has changed the _inputArea

On a side note, when looking at this, I also noted that we were missing a 
function in KisGenerator to specify which rectangle of the image is affected 
by the generator (not all generators are going to work on the full image, 
think about lensflare), for this I suggest:
* QRect KisGenerator::generatedRect( QRect _imageArea ) : return the rectangle 
of generated pixels

With the above, I would a function to KisEffectMask that would take the dirty 
rectangle of a KisLayer as argument, and return which area need to be 
updated. For 2.0, I would simply use KisFilter::overlapMarginNeeded to extend 
the rectangle.

So what do you think ?

(*) QRect = x, y, width, height
-- 
Cyrille Berger


More information about the kimageshop mailing list