From this normal map I want to automatically generate a displacement map
Not really. The accuracy of your normal map is already suspect given the fact that it was generated from an image, not actual geometry. Any technique you might use to generate a displacement map would only increase the inaccuracy.
You could look at ‘normal2depth.exe’, which was written by Fabio Policarpo to generate the height maps he used in his first tests/demos of parallax mapping.
The math is rather simple, you could write this tool by your own.
Given bump-map is a heightfield, representing dh/dx and dh/dy.
Simply integrating it and centering the result will give you what you need.
You could ask ryan in crazybump’s forums I guess for some references… the displacement map is actually the occlusion map with probably different settings.
As jackis wrote previously - you would do integration across the normal-map, and approximate each pixel with a slope according to the normal. If you find it difficult, think about converting a single line of pixels at a time.
And be warned - korval and knackered will not approve of your actions
Ah, sorry, your question was about how the author of CrazyBump wrote his algo. I have only general thoughts, and they may be not correct. I’ve never tried to do this because I just never had to do this ))
If you want to wrote smth like this, first of all I’d recommend you to get more familiar with vector math and analytic geometry (how normal maps are got, what they are and so on).