I was working on a bitmap generator a while back, and I decided to mess around with it a bit yesterday, and noticed it wasn't working as expected. Giving it dimensions that aren't powers of 2 generate broken images.
Here's the code generating an 8x8 bitmap:
$ java -jar libDib.jar; hexdump -v tmp.dib
0000000 4d42 00f6 0000 0000 0000 0036 0000 0028
0000010 0000 0008 0000 0008 0000 0001 0018 0000
0000020 0000 00c0 0000 0200 0000 0200 0000 0000
0000030 0000 0000 0000 ffff ffff ffff ffff ffff
0000040 ffff ffff ffff ffff ffff ffff ffff ffff
0000050 ffff ffff ffff ffff ffff ffff ffff ffff
0000060 ffff ffff ffff ffff ffff ffff ffff ffff
0000070 ffff ffff ffff ffff ffff ffff ffff ffff
0000080 ffff ffff ffff ffff ffff ffff ffff ffff
0000090 ffff ffff ffff ffff ffff ffff ffff ffff
00000a0 ffff ffff ffff ffff ffff ffff ffff ffff
00000b0 ffff ffff ffff ffff ffff ffff ffff ffff
00000c0 ffff ffff ffff ffff ffff ffff ffff ffff
00000d0 ffff ffff ffff ffff ffff ffff ffff ffff
00000e0 ffff ffff ffff ffff ffff ffff ffff ffff
00000f0 ffff ffff ffff
00000f6
The f's represent the image data, what I call the canvas. I've got 192 sets of f's. 192/3 = 64 (For each color, red, green, and blue.), and 8*8 = 64. The image seems fine, and it also looks that way in an image viewer.
Here I do the same thing with a 7x7 image:
$ java -jar libDib.jar; hexdump -v tmp.dib
0000000 4d42 00c9 0000 0000 0000 0036 0000 0028
0000010 0000 0007 0000 0007 0000 0001 0018 0000
0000020 0000 0093 0000 0200 0000 0200 0000 0000
0000030 0000 0000 0000 ffff ffff ffff ffff ffff
0000040 ffff ffff ffff ffff ffff ffff ffff ffff
0000050 ffff ffff ffff ffff ffff ffff ffff ffff
0000060 ffff ffff ffff ffff ffff ffff ffff ffff
0000070 ffff ffff ffff ffff ffff ffff ffff ffff
0000080 ffff ffff ffff ffff ffff ffff ffff ffff
0000090 ffff ffff ffff ffff ffff ffff ffff ffff
00000a0 ffff ffff ffff ffff ffff ffff ffff ffff
00000b0 ffff ffff ffff ffff ffff ffff ffff ffff
00000c0 ffff ffff ffff ffff 00ff
00000c9
Now the canvas has 147 bytes, (7*7*3 = 147, you can ignore that last blank bit, that's just some hexdump "feature."), the header is fine too, but for some reason the image is read weird, like so:
Scaled with GIMP. That black bar shouldn't be there.
Here's my source, am I writing the data wrong or something?