Marino Šimić
Marino Šimić

Reputation: 7342

Gaussian blur on a Silverlight WriteableBitmap

I'm using a WriteableBitmap in Silverlight as a tool to temporary store and in the end draw the result of an algorithm of mine to draw a seemingly flat two dimensional uniformly distributed universe with a finite amount of matter.

To seee definitions of "universes" (Figure 3): http://alienryderflex.com/homogeneity/

I am using bitmap resizing to aproximate the algorithm, and gain a quadratic speedup with linear quality loss.

Problem is I would need to do a Gaussian blur on the image, to reduce pixelization after downscaling and upscaling, which if absent adds on the error rate of the algorithm.

You can see my test implementation Here.

If you press Generate then Draw, and wait like 20 seconds, you will see that even on the output pixelization is seen.

But I need that output bitmap as a "matter density map" in a second stage of the algorithm.

So how do I do a gaussian blur on those writable bitmaps? I really would like to find a suitable implementation instead of writing my own which would be very time consuming on an array of ints -> holy christ no byte pointers on the image data??

Thanks!

Edit:

To clarify: I need the gaussian blurred data back to operate on it: not only a visual blur over the image.

Upvotes: 2

Views: 787

Answers (1)

user180326
user180326

Reputation:

The best way do this in silveright is writing a custom graphic effect. In silverlight 3 you can write them as DirectX .fx files. These will be hardware accellerated, and will avoid slow copying back and forth between different image representations.

Here is an introduction. There are probably better ones but it will get you started. The cool thing about pixel shaders is that they are so fast that you don't need to worry about optimizations.

Upvotes: 1

Related Questions