C#, MDX and Colo(u)rs
A small adventure in the managed world of DirectX to (inaccurately) simulate the perception of the desktop with color vision deficiencies.
This entry was first published on November 09, 2005, 08:58 AM, CET and categorized as .NET.
So far, 2 comments have been added to this entry. You can add your thoughts to the discussion below.
Reading about SimDaltonism made me remember my affords from October 2003: back then I used a color lookup table to do the translation and so the speed was not really satisfying. But now with Managed DirectX, pixel shaders and a nice algorithm at hand I revived the project to see if it can be made perform any better than a few frames per second. And yes, it is possible: around 100 FPS for a 640x480 screen capture simulation on my ATI 9600 Pro.
The hardest part of this project was to squeeze the algorithm into the 64 arithmetic instruction slots of a version 2.0 pixel shader. But a few optimizations later and shortcuts later the compile finally did not end in a "error X5608: Compiled shader code uses too many arithmetic instruction slots (69). Max. allowed by the target (ps_2_0) is 64."
The quick prototype used the MDX SampleFramework
class put for the final application I wanted no to use it (why? I have no idea, file size wouldn't be the reason: 204 kb with and 52 kb without do not really make a difference; maybe because I did not need the high-speed message loop…). So I had to implement all the boring device householding myself which led to some weird exception when minimizing the application. I had to cancel the devices resizing event in order to get rid of this because otherwise the device wants to recreate(?) itself which will fail for a zero-size window. Why this is necessary I do not know and the documentation does not mention this neither (at least I did not find it). This was an annoying and time costly experience :]
For the screen capturing I use an optimized version of Fusion8Design.Win32.Desktop.GetBitmap()
by Brian Scott of Cropper fame which uses one static bitmap only. Also, it captures the requested part of the screen only and not the desktop area. This reduced the memory footprint significantly - ok, I might have missed the one supposed dispose on the returned bitmap, but creating two bitmaps per frame is rather suboptimal…
…and now for something completely different: John R. Durant is right about Metallica's St. Anger: since I heard the title track for the first time it felt like the old (Ride the Lightning, Master Of Puppets and …And Justice For All) Metallica again. Powerful drums, nice riffs and cool lyrics (ok, not even a single Kirk solo is sort of confusing, but it works - and no one could have been more surprised by this than me). To me, the black album was of a disappointment back then in 1991 and I still think it is one of their weaker albums.
Note to self: I either need to find a desktop blogging application that fits my needs or create one; drafting posts in OneNote and converting it to HTML I accept is not very pleasing…
Comments
Add your comment
Scoutn, 1 week later
"I either need to find a desktop blogging application that fits my needs or create one"
Please create one!
Oh, and it seems that your preview post thingy doesn't recognise html elements. Something else to add to your NeverEndingToDoList™
Editor: Changed em tags to quotes
Björn, 1 week later
Well, the preview doesn't recognise tags because I still haven't changed MT's setup to allow a few selected tags :]