What are data translators?

Continuing the discussion from What is, what's so good and why Haiku?:

What are these data translators?

I found only the following:

https://www.haiku-os.org/docs/userguide/eo/preferences/datatranslations.html

But this webpage doesn’t explain them.

For a more developer oriented overview, see The Be Book - System Overview - The Translation Kit

The idea is that, given some data (as a BDataIO, typically a file opened as a BFile, but it could be something else such as data received in a copy paste or drag and drop), you can ask the translation kit to identify the data and decode it into a well-known format. Standard formats in BeOS include “bitmap streams” (that can be easily loaded into a BBitmap object) and “styled text” (that can easily be rendered by a BTextView).

The opposite direction is also possible: converting something from the well-known format into a file with a specific on-disk format: PNG, AVIF, …

Applications can provide their own translators for their own formats whenever it makes sense. The formats are identified by their MIME type, in combination with the MIME database (which you can browse in the Filetypes preferences).

4 Likes

For example, ArtPaint has no idea about GIF, PNG, JPG, etc. - it only handles BBitmaps. But through the magic of Data Translators, ArtPaint can load and save all of those image formats without even thinking about it. It’s really nice as an application developer.

1 Like

If I get it well, this means all the differencies/complexities of libpng, libjpeg, libtga, libxvidcore, libx264, libaom, libvorbis and many others are hidden into the OS itself and leveraged by the Translation Kit! Are they?

3 Likes

This an old dream of me: The program deals with the internal data structure (for example a tree) and another author has written a parser for a file format.

I see lot of potential in this concept.

1 Like

Yes, that’s the idea, however, for audio/video formats, the Media Kit provides its own framework (BMediaFile and BMediaTrack). The result is similar but it allows more finegrained access (to separate audio and video tracks for example) as well as easier use in streaming contexts (working with big files too large to fit in RAM, by reading and writing them one chunk at a time).

The end result is the same, media apps using these APIs don’t need to worry about the specific formats and can use fully generic code.

1 Like

Yes, but just to be transparent, they aren’t perfect or fully complete in all cases. For example, the GIF translator doesn’t have support for animated GIFs yet. But for the general case they work well.