Re: [filter-effects] Color clamping of intermediate filter primitive results

On Jul 23, 2013, at 7:41 AM, Robert O'Callahan <robert@ocallahan.org> wrote:

> On Tue, Jul 23, 2013 at 5:38 PM, Dirk Schulze <dschulze@adobe.com> wrote:
> It should be clarified, indeed. But first I would like to get to an agreement that we just clamp a sub-chain with combined filter operations instead of each single operation. Multiplying color matrices together and apply them to the content and clamp once is a lot more efficient than doing each filter operation individually and clamp each single time.
> 
> I'm afraid that your proposed change may be rather complex though. I'd like to see the details.

grayscale, sepia, saturate, hue-rotate, invert, opacity, brightness and contrast are all filter operations that can be represented by a color matrix. Lets take a look at the following example:

	grayscale(0.5) sepia(0.5) hue-rotate(45deg) invert(0.1) brightness(0.2).

With the current clamping requirement you would do:

* Apply grayscale(0.5) clamp pixel values
* Apply sepia(0.5) clamp pixel values
* Apply hue-rotate(45deg) clamp pixel values
* Apply invert(0.1) clamp pixel values
* Apply brightness(0.2) clamp pixel values

You run over the content 5 times. In comparison to transform each filter function to a color matrix and multiply these matrices together

* matrix = grayscale(0.5) * sepia(0.5) * hue-rotate(45deg) * invert(0.1) * brightness(0.2)
* Apply matrix clamp pixel values

Here you do the filter operation once and just clamp once. As you can see, the operation can be 5 times faster without clamping intermediate filter results. This does of course not work with all filter operations:

	grayscale(0.5) sepia(0.5) drop-shadow(3px 3px 3px blue) hue-rotate(45deg) invert(0.1) brightness(0.2).

drop-shadow can not be combined into the same filter chain, instead you would split the chain into three parts:

* grayscale(0.5) sepia(0.5)
	* multiply color matrices together, apply resulting matrix, clamp
* drop-shadow(3px 3px 3px blue)
	* apply filter operation, clamp (nothing to clamp here really)
* hue-rotate(45deg) invert(0.1) brightness(0.2)
	* multiply color matrices together, apply resulting matrix, clamp

Instead of filtering the content 6 times, you just do it 3 times. This would still be a lot more efficient but just works if you do not require clamping after each single filter operation.

You should also notice that the separation of the filter chain is rarely necessary. Often it gives more pleasant results if you add drop-shadow or blur at the end of the filter chain and most authors do that already. In certain situations the implementation could do that automatically and reduce the second example to just two filter operations.

Greetings,
Dirk

> 
> Rob
> -- 
> Jtehsauts  tshaei dS,o n" Wohfy  Mdaon  yhoaus  eanuttehrotraiitny  eovni le atrhtohu gthot sf oirng iyvoeu rs ihnesa.r"t sS?o  Whhei csha iids  teoa stiheer :p atroa lsyazye,d  'mYaonu,r  "sGients  uapr,e  tfaokreg iyvoeunr, 'm aotr  atnod  sgaoy ,h o'mGee.t"  uTph eann dt hwea lmka'n?  gBoutt  uIp  waanndt  wyeonut  thoo mken.o w  

Received on Tuesday, 23 July 2013 05:59:18 UTC