3

I have an FBX with embedded image content. The image is in Base64. I read the chunk and decode it successfully. The problem comes when the image is bigger. The FBX splits the image into 2 lines which seems like base64, but I don't get how should I decode it.

  1. I tried decoding both lines in base64 and concatenating them before decompressing the png, but the png is corrupted.
  2. I tried concatenating the Base64 strings but it does not work, as the ending = trail is wrong this way.
  3. I tried to decompress first the first line ( a correct png but only half of the image) and decompress the second one as a bitmap, but as the second one does not have the headers is an invalid image.

Content: , "iVBORw0KGgoAAAANSUhEUg...AAAAA=", "AAAAAAAAAAAAAAAAAA...AD//wEAAP///noceab5flIAAAAASUVORK5CYII="

As you can see, the first line is the PNG header (iVBOR...) but the second line does not have a header. The first line and the second one has base64 ending, so I suspect they should be decoded separately.

Does somebody know how to?

How to replicate: open 3ds max create a plane, apply image as texture, save as ascii FBX with embed media.

PNG with enough size to be split

diego.martinez
  • 1,051
  • 2
  • 11
  • 25

1 Answers1

2

I downloaded and installed the latest version of 3ds max. I created a plane and added a PNG image as a texture, I exported it as an fbx file in the (default version) ascii format using embedded media.

I saw multiple lines of base64-encoded ascii. The first line contained a PNG header and my decoder recognized it as a PNG file. Subsequent lines did not contain PNG headers and were decoded as BIN files. All of this is exactly as you describe.

However, in my case simply concatenating the decoded segments correctly regenerated the original PNG file, just as you would expect.

I used this site to decode all of the individual chunks and download them as binary files before concatenating them.

I used the open source binary editor HexEdit to examine the chunks and to concatenate them.

Since this process worked as expected, I surmise that your Base64 decoding or concatenation must be at fault. Did you write your own decoding routine? if so, perhaps you forgot to discard any bytes corresponding to padding characters (the terminal = or == used to make the final count of bytes evenly divisible by three for each line). Note that these bytes must be discarded after decoding, not before. Virtually all decoding libraries do this for you invisibly.

If this does not solve your problem, please post the PNG file you are using, the full Base64 for the first and second lines of the output, and the routine you are using to decode and concatenate them. If you do so, we will look more closely to help you sort out the problem.

Craig.Feied
  • 2,617
  • 2
  • 16
  • 25
  • hi! Your help was useful to find out that my base64 decode routine was in fact, losing the last byte due to a bug in padding. Then , after the concatenation, it was corrupted. I changed my routine with the one here https://stackoverflow.com/questions/180947/base64-decode-snippet-in-c and worked like a charm. Thank you very much. – diego.martinez May 15 '19 at 10:02