Bunny83 / Utilities

A (hopfully) growing collection of various math, geometry and general utility classes for Unity3d and C#
MIT License
67 stars 12 forks source link

Where is bmploader? #1

Open david-pfx opened 2 years ago

david-pfx commented 2 years ago

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 .

Bunny83 commented 2 years ago

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.

david-pfx commented 2 years ago

The image is part of the standard release of this product: https://zillionsofgames.com/demo/.

I have been working on a Unity reboot: https://github.com/david-pfx/AmzPlayer using your bmp loader. This is the only image that wouldn’t load (but it loads fine in Windows). The game actually only requires an image of 240x240.

There were also two WAV files that load in Windows but not in Unity. I have no idea where these assets came from, but they are at least 20 years old, so perhaps a tool long forgotten.

I also have no record of where I actually got bmploader from and it’s not on your GitHub repo, which is why I raised the issue where I did. Are you going to post an update?

Regards

David M Bennett FACS


Polygamo – Programming Languages and Players for Games and Puzzles -- http://www.polyomino.com http://www.polyomino.com/

From: Bunny83 @.> Sent: Friday, 22 October 2021 12:22 AM To: Bunny83/Utilities @.> Cc: david-pfx @.>; Author @.> Subject: Re: [Bunny83/Utilities] Where is bmploader? (#1)

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?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Bunny83/Utilities/issues/1#issuecomment-948611924 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ADBMEXJYGHML22P7LHD56TLUIAHW3ANCNFSM5GDFVA5Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub .

Bunny83 commented 2 years ago

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.

david-pfx commented 2 years ago

Found some more. These I may be able to track the source.

Issue raised.

Regards

David M Bennett FACS


Polygamo – Programming Languages and Players for Games and Puzzles -- http://www.polyomino.com http://www.polyomino.com/

From: Bunny83 @.> Sent: Friday, 22 October 2021 12:18 PM To: Bunny83/Utilities @.> Cc: david-pfx @.>; Author @.> Subject: Re: [Bunny83/Utilities] Where is bmploader? (#1)

Well, I did update it ^^. It's located in the WorkInProgress folder BMPLoader.cs https://github.com/Bunny83/Utilities/blob/master/WorkInProgress/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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Bunny83/Utilities/issues/1#issuecomment-949159069 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ADBMEXKZNMOEB4I33IFZYT3UIC3WDANCNFSM5GDFVA5Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub .