I think that the original padding calculation is wrong and only works by chance. The following should be correct:

[pascal][background=#FFFFFF][comment=#0000FF][normal=#000000]
[number=#C00000][reserved=#000000][string=#00C000]// calculate padding -- row width must be padded to 4 byte boundary
Padding := WidthInBytes and 3;
if Padding and 1 <> 0 then Padding := 4 - Padding;[/pascal]

That should be correct. There's probably a more elegant method for this, but I'm not sure because my brain has turned into mush from one too many late nights...

I've uploaded the changed version and tested it with a few bitmaps w/ different widths.