This project is read-only.

Add filters and improved gradient functions

Apr 8, 2012 at 11:07 AM
Edited Apr 8, 2012 at 11:18 AM

I had included the renderer in one of my projects. It had been a pity no filter functions, and the gradient with Gdi+ does not seem to be compliant with svg. With limited time available, in the past months I had built up the filter functions gradually and created work arounds to improve the gradient display, and by the way fixed some bugs. It is uploaded now (ID: 11924). I am not the co-worker for this project. It is just to share if someone may want to continue the work...

Most of the functions are tested and work well for >95% of svg cliparts from Open ClipArt library, except below functions do not yet work properly, or are not yet implemented:

- Lighting filters - works for the example in SVG 1.1 spec, but does not work properly for some other examples

- BackgroundImage - not yet implemented but tentatively use device canvas as work around, still works well for most of examples

- FillPaint and StrokePaint - do not quick understand them, not yet implemented

- Minor color difference for ConvolveMatrix and ColorMatrix

Since pixel operations with managed codes for filter functions may be slow, I had used LockBit in unsafe way to access bitmap. It can be much faster though not recommended in general. You may change it to managed code if your project does not allow it, but take care of the speed (could be very slow)

I will still have very limited time for further work on this. If you are interested in the codes, feel free to improve it and share back....

By the way, a viewer is included in the patch. It is more convient for debug. There are 2 display windows: the left one displays the rendered image, the right one displays selected intermediate result out from filter. Read the codes in, you will see how to do...


Apr 14, 2012 at 11:52 AM

Small change uploaded (ID: 11959), the changes are:

In SvgDocument.cs, prevent reading external DTD:                                   

[Add]: settings.XmlResolver = null;                                   

[Org]: using (var reader = XmlTextReader.Create(stream, settings, parserContext))                                   

[New]: using (XmlReader reader = XmlReader.Create(stream, settings, parserContext))                                   

In feGaussianBlur.cs, fix bug to read/write in protected memory (outside locked bits)                                   

[Org]: else if (r > s0 + src.Stride) p = s0 + src.Stride;                                    

[New]: else if (r > s0 + src.Stride - 4) p = s0 + src.Stride - 4;

Apr 22, 2012 at 12:05 PM

Further update (patch ID: 12027), previous implementation applied filters before transforms, that might encounter problems when the document size is big in user coordinate system (use up too much memory resource and slow...). This implementation change to perform transforms before applying filters. Also some other enhancement. See the revision history in SvgDocument.cs