Sunday, December 22, 2013

FMod - Bitmap

I was right. FMod is going to usurp all my free time for the next few months. Sigh... let's dev!

Since it will probably become important at some point, I wrote a class to encapsulate a 16-color (4-bit) bitmap that doesn't really conform to any standard but Keen's. That was exceedingly painful because [1] two pixels are packed into each byte, [2] each row has to be a multiple of four bytes - not pixels - long, which wouldn't be so bad if it weren't for the fact that [3] the entire thing is actually stored upside down - but still left to right. The first problem I encountered was that the bottom image was interspersed with black horizontal lines and made the entire image. It didn't take terribly long to figure out that I had made an error in calculating the start of a new line of pixels. However, the next problem was much more painful: assigned pixels were being shifted to the left one. It took literally two hours of messing with ten lines of loop code to make any headway on it. The shift was fixed by adding calls to Math.Ceiling in various places, but then I was stuck with a black vertical line on the left. Fortunately, a little more shuffling of "+1", "-1", "*2", and "/2" fixed it.

With the bitmap class working well, I ripped the compression algorithms out of the level IO code and into their own reusable module. That module will later contain implementations of LZW and Carmack compression.

No comments:

Post a Comment