Home > Delphi, OP4JS > Pictures as a medium for binary data

Pictures as a medium for binary data

May 7, 2012

At work I am currently adding the final touches to Smart Mobile Studio (with some excellent help from Primoz Gabrijelcic and Eric Grange. If you havent seen what these guys do then you are in for a treat!). For people moving their code from object pascal to HTMLr5 however, one of the biggest problems is the fact that JavaScript doesn’t allow you to access files directly, only indirectly. In fact large parts of JavaScript is like that so it can be very frustrating for us native Spartans! Some desktop browsers have reader and writer objects to access files – but again they differ in that every operation is async. So your “stream.read()” may call back in 80 seconds if your network is dizzed. And dont get me started on the mobile scene (the javascript frameworks on sale out there “huff and puff” but they are for the most part re-hashing bad news. Delphi users on the other hand, are in the business of creating good news, so we skip that part *smile*).

Pondering how we could solve the mysterious case of alien data (i.e when you got a binary file that you dont want to hand-punch as an array), I realized that we could use pictures as a medium. It wont help loading files from the device (unless you compile to phonegap), but it will help with converting files from Delphi to HTML5. While I can only speculate on the maximum size we can get and the differences between mobile and stationary webkit  (behind Apple’s “bling” it’s all unix after all), –under winAPI a DIB (device independent bitmap) has a max size of 4096 x 4096 x 32 bits – which yields a total of 67108864 bytes of storage space. I think you can go higher if you throw in a memory mapped file handle – but it’s been a while since I hacked around the winAPI to be honest. I got sick of the whole limitation and coded my own system (see “uni-surface” under pixelrage).

So, right now im adding a new wizard to Smart Mobile which allows you to embed a binary file as a picture. Instead of RGBA pixel data, we write the bytes from the file – and you can read them out via a normal TW3ImageData object.

Thanks to Kostas for the head’s up!

Spirit of Delphi

On a second note, my main man Dorin is ever pushing limits to the max and have released an awesome example of source code mini maps for synEdit. With some of the killer stuff Dorin is knocking out these days — he will probably take over the world in 10 years time. Head over to the spirit of Delphi and check out his top-notch stuff!

Advertisements
%d bloggers like this: