Strange graphics file format

Started by
17 comments, last by Stainless 10 years ago

Okay getting somewhere ...

Looks like the pixels are stored as differences. Seriously strange.

Using that tool, I converted the IMF file to tga and compared the two files.

The TGA file starts with a pixel 9D,9D,9D,00 and I can see that in the IMF file.

The TGA version continues with a bunch of the same pixels, the IMF with a bunch of 0,0,0,0

Further on I can see a pixel 9c,9c,9c,03 and in the IMF file FF,FF,FF,00

And again later on the TGA goes back to 9d,9d,9d in the IMF file I can see 1,1,1,

It doesn't all fit yet, but the mist is clearing a little

Advertisement

It's some weird ass proprietary format:

7 bytes - magic

1 byte - mode (0 = 24 bit, 1 = 32 bit)

2 bytes - width

2 bytes - height

height bytes - color row modes (0 = ???, 1 = row is stored as diff starting from 0, 2 = row is stored as diff starting from previous row end value, 3 = ???, 4 = ???)

color row 1 (1 byte r, 1 byte g, 1 byte b)

color row 2

.. (up to height rows)

height bytes - alpha row modes (same as above)

alpha row 1 (1 byte a)

alpha row 2

... (up to height rows)

That's interesting, I'll give it a try.

That's much closer, I'm getting structures now.

I was wrong about the modes, mode 1 means it's the difference from the pixel at (x - 1, y), mode 2 means it's the difference from the pixel at (x, y - 1). Still no clue about the other modes.

Edit: mode 3 is the difference from (pixel[x - 1, y] + pixel[x, y - 1]) / 2 or something like that

I was wrong about the modes, mode 1 means it's the difference from the pixel at (x - 1, y), mode 2 means it's the difference from the pixel at (x, y - 1). Still no clue about the other modes.

Edit: mode 3 is the difference from (pixel[x - 1, y] + pixel[x, y - 1]) / 2 or something like that

These appear to be the PNG filters. 1,2,3 correspond; other possible values include 0 (unaltered pixel) and 4 (Paeth predictor, see the PNG spec). Filter type 3 has a floor operation: the reference value is floor((pixel[x - 1, y] + pixel[x, y - 1]) / 2) in your notation.

Omae Wa Mou Shindeiru

Brilliant catch, it's so close now.

I have probably got an accuracy issue in mode 3, or a bug in my Paeth predictor, but most of the image is now correct.

Thanks guys

progress report, so close now.

3541046_orig.png

Ok, this has been fun. It's a long time since I just stared at a hex editor looking for structure. Kinda miss it.

Anyway the problem above was caused by an initial value problem. In mode 4 the first pixel in a line has to be set to be the same as the pixel directly above it, in all other modes it has to be set to zero.

Then you run the relevant filter, really strange.

Well I have 24 of these graphics, my code now loads 23 of them perfectly. Why one graphic has a glitch, I don't know. The code will do what I need it to now, so I'm stopping.

Thanks for the help and ideas guys.

This topic is closed to new replies.

Advertisement