Friday, August 24, 2007

Image Formats and File Extensions

This goes into the bucket of "weird X-Plane behavior": X-Plane will try both PNG and BMP file extensions when opening images, no matter what is in your file. How we got to this state is, at best, confusing.

Originally, most X-Plane image files did not contain a suffix. So an ENV file contains "grass" and X-Plane would change that to grass.bmp.

Then we added PNG support. X-Plane would try grass.png and then grass.bmp. In this case, not having the extensions turned out to be handy -- authors could simply bulk-convert their images and go on with life.

With most new scenery system files, the extensions are a lot more rigid:
  • The extension appears in the referencing file.
  • The sim only tries that extension.
  • If the format doesn't match the extension, it's an error.
So if you want a DSF file to reference a facade, it's buildings.fac and if that .fac file is actually a forest file, it's an error. The sim won't try to decide which is more correct, the header of the file or the extension, it will just go "you're nuts" and bail out.

But (for historical reasons) images are an exception. Keeping with the "any extension goes" theme for images, X-Plane will actually try PNG and then BMP versions of your file. The extension has to match the format...that is if you call your bmp foo.png X-Plane won't load it at all.

We have PNG as our primary image format and BMP for backward compatibility. But it's imaginable that we could have DDS and PNG both as primary formats -- PNG for images that need lossless fidelity and DDS for images where compression is acceptable. In such an event, X-Plane's tendency to try every extension means authors can bulk-convert from PNG to DDS (making their packages load faster) and go home happy.

No comments: