Bug 103728 - Optimize ColorMatrix filter
Summary: Optimize ColorMatrix filter
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-30 02:56 PST by Zoltan Herczeg
Modified: 2012-12-05 02:38 PST (History)
4 users (show)

See Also:


Attachments
patch (6.58 KB, patch)
2012-11-30 03:06 PST, Zoltan Herczeg
krit: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zoltan Herczeg 2012-11-30 02:56:53 PST
ColorMatrix recalculates a lot of values in every pixels.
Comment 1 Zoltan Herczeg 2012-11-30 03:06:03 PST
Created attachment 176934 [details]
patch
Comment 2 Zoltan Herczeg 2012-11-30 07:07:25 PST
The strange thing is that the result is not claped between [0..1]. And I couldn't find anything in the specification what happens if the result is > 1 or < 0. Anyway, this is a really powerful filter.
Comment 3 Dirk Schulze 2012-12-04 08:52:45 PST
(In reply to comment #2)
> The strange thing is that the result is not claped between [0..1]. And I couldn't find anything in the specification what happens if the result is > 1 or < 0. Anyway, this is a really powerful filter.

We clapped in the past, but decided to remove it from the spec and follow Opera (which did not clamp). Does the your result clamp?
Comment 4 Dirk Schulze 2012-12-04 08:55:57 PST
Comment on attachment 176934 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=176934&action=review

Looks reasonable to me. r=me. I am just not sure about the following:

> Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp:136
> +    if (filterType == FECOLORMATRIX_TYPE_SATURATE) {
> +        components[0] = (0.213 + 0.787 * values[0]);
> +        components[1] = (0.715 - 0.715 * values[0]);
> +        components[2] = (0.072 - 0.072 * values[0]);
> +        components[3] = (0.213 - 0.213 * values[0]);
> +        components[4] = (0.715 + 0.285 * values[0]);
> +        components[5] = (0.072 - 0.072 * values[0]);
> +        components[6] = (0.213 - 0.213 * values[0]);
> +        components[7] = (0.715 - 0.715 * values[0]);
> +        components[8] = (0.072 + 0.928 * values[0]);
> +    } else if (filterType == FECOLORMATRIX_TYPE_HUEROTATE) {
> +        float cosHue = cos(values[0] * piFloat / 180);
> +        float sinHue = sin(values[0] * piFloat / 180);
> +        components[0] = 0.213 + cosHue * 0.787 - sinHue * 0.213;
> +        components[1] = 0.715 - cosHue * 0.715 - sinHue * 0.715;
> +        components[2] = 0.072 - cosHue * 0.072 + sinHue * 0.928;
> +        components[3] = 0.213 - cosHue * 0.213 + sinHue * 0.143;
> +        components[4] = 0.715 + cosHue * 0.285 + sinHue * 0.140;
> +        components[5] = 0.072 - cosHue * 0.072 - sinHue * 0.283;
> +        components[6] = 0.213 - cosHue * 0.213 - sinHue * 0.787;
> +        components[7] = 0.715 - cosHue * 0.715 + sinHue * 0.715;
> +        components[8] = 0.072 + cosHue * 0.928 + sinHue * 0.072;
> +    }

Does it make sense to move this in inline functions? It looks so strange here and makes it less readable. Please consider it before landing.
Comment 5 Zoltan Herczeg 2012-12-05 02:38:11 PST
Thanks for the review!

> Does it make sense to move this in inline functions? It looks so strange here and makes it less readable. Please consider it before landing.

Yes, I did it.

Patch landed as: http://trac.webkit.org/changeset/136661