6/20/2014

Update on the program of azimuthal equidistant projection

I wrote codes to project a real image of the earth by using azimuthal equidistant projection 2 years ago. But recently I found out it did not work on newer PC.
It seemed that the cause might be the version of .Net framework. The version I was working on to create the program was 3.0, on which it can run normally. The version it did not correctly run on was 4.5. But I had been so screwed up with this problem.

Finally, I found the cause was the minor difference of behavior of Marshal::Copy() in different versions. In my program, I used this copying function to transform data on an array to the form of 24-bit bitmap, and vice versa. If you learned computer engineering, you may know 24-bit bitmap has "padding", or additional space, at the end of each row of the image so that the byte size of the row can be a multiple of 4. Actually, I didn't know well about how the function worked, so I just put data on an array without padding and let it convert data to bitmap. The old version seems to flexibly convert data and automatically put necessary padding, but the newer one seems so strict about the format of the array and some portion of data had been accidentally put into the space of padding. This means the order of RGB data could be corrupted. That's why the result of problematic image lost colors and was distorted.
The width of the image is 533. So the total byte size of the row is 533 x 3 = 1599 bytes. To make this a multiple of 4, 1 byte of padding must be added. The image above misses this 1-byte space, and the function mistakenly took next 1 byte of data as padding. So the row of image gradually shifts to the left as it goes from top to bottom.

So I took this feature into consideration. I reformatted the array so that it has padding in each row.
Now the program can normally run on .Net framework 4.5!
Phew..., it was hardwork...
Anyway, you can download the program at http://sites.google.com/site/somedayuniverse/contents/azimuthal-projection