General BMP and Image I/O Question

Hello all.



I’m working on an Image I/O plugin to read a file format to use as textures. The format is a multiple image per file type, which appears to hold compressed BMP images. I have a working PERL script (ported from an old VB app) that converts this multi-image format into several BMP files.



While trying to port this to an Image I/O plugin, I noticed an inconsistency with image and data size. This came to light as I continuely ran into an ArrayIndexOutOfBounds error.



For example. Image 1, 35x93. That means the data should be 3255 bytes long. Right? But, my PERL script puts out 3348 bytes of data. I’d be less confused if that BMPs my script created didn’t load properly… but they do. Additionally, if I run the standard BMP RLE 8-bit decode on a data block, it runs out of space.



Strangly, the data wants to decompress to a size larger then the image format. In both PERL and Java.



Does anyone have any experience with images, BMP and/or Image I/O plugins? Could you help elevate my utter confusion? :slight_smile:

Is the Perl script writing to a BMP file that can be read by an image program such as MS Paint or PaintShop Pro? If so, then it would also write out the header information. The file header is 14 bytes and the bitmap header is 40 bytes. Next comes the palette if there is one. Plus there is padding to put each line on a DWORD boundary.

Yes, the BMP is valid and can be read by any program. You can find it here, if you really want to see it :slight_smile: http://www.rightstep.org/snipets/perl/spr2bmp/



The length of the data is stored in the BMP header, which is what is confusing me. It is this value that does not match the (width * height) value, but everything loads up just fine. The stored value in the BMP header is 93 bytes larger then what the math says it should be. But… everything works and it loads. Weird.



I’ve looked at things again, and I am now aware that the information in the SPR (the original format) is not stored in a standard BMP RLE compression. However, I can decompress the data (the same way I do in my Perl script) and have a block of data I could send out to a BMP file. I have been trying to learn how to load that data and the associated palette into a BufferedImage (for the Image I/O plugin) but I’ve failed up until now. The complete lack of worthwhile documentation on the subject doesn’t help. :frowning: