Bunny83 / Utilities

A (hopfully) growing collection of various math, geometry and general utility classes for Unity3d and C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Where is bmploader?

david-pfx opened this issue · comments

Looking for bmploader (a) to see if any updates since 2017 (b) report a bug.

Attached file causes an index out of range crash
Blank18.zip
.

Thanks for the example image. I have figured out that for some strange reason, the image you provided explicitly encodes 272 pixels per row, even though the image is only 271 pixels wide. The pixels are in 4 bit RLE mode so this additional pixel is simply the second nibble of the last byte. Though it's strange that the number of elements is explicitly set to "18" in your image when it should have been "17".

Anyways I've updated the BMPLoader so it can actually load your example image without issues. May I ask how you generated this BMP file? What program did you use? Or did you get it from a third party?

ps: I just tested patching your bmp file and replacing all the 0x0012 in the file with the proper 0x0011 and the image loads fine with the new and old loader.

The file is essentially run length encoded but the nature of your content gives no benefit because you don't have any consecutive pixels that are the same. Therefore each line is encoded in chunks of "absolute mode". Each line consists of one chunk with 254 (0xFE) pixels (127 bytes) and a second one with 18 (0x12) pixels (9 bytes). However 254 + 18 is 272 and not 271. So it seems strange why your image explicitly encoded 272 pixels per line when the image is only 271 in size. To me that looks like an error in the encoder. Though the fix I just implemented does not do any harm and does resolve this issue.

Well, I did update it ^^. It's located in the WorkInProgress folder BMPLoader.cs

As I checked a few variations I even found another issue with normal indexed images which is now also fixed. The image you provided is really strange. It uses a 16 color palette (4bit / pixel) but uses the RLE4 format (run length encoding). However the image has way too much structure so nothing is actually run length encoded ^^. I tried resaving the image as a normal 4 bit indexed image and the resulting image is even smaller since the RLE format has some overhead.

Anyways, your image should load fine now.