playMaker

Author Topic: [Scripting] Creating a raw "Pic-code" image manually  (Read 1340 times)

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
[Scripting] Creating a raw "Pic-code" image manually
« on: June 26, 2015, 09:42:16 AM »
Okay, this is gonna be a thing that is part "pie-in-the-sky" idea but also something I think if it CAN work might help with data transfer between devices.

The concept is a little complicated and I'm not sure how tall of an order it is but bear with me because I've been bouncing this idea off people that have far more knowledge in coding than I do and all of them agree that something like this is (mostly) possible.

What I'd like to do, however, is do this in PlayMaker... Because, well, why not? Of course the techniques could easily be applied to non PlayMaker applications but I want to stick with PlayMaker first.

PREAMBLE/THEORY:
Since an image file that has four channels (R, G, B and A) that can suggest, via a similar mathematical conversion process for bin, dec, hex, etc it can mean that each pixel has a potential maximum value of 256^4 (So, 4,294,967,296 as a total maximum value that each pixel can represent.) What sort of data can be stored depends on how it's encoded but for this I'm thinking of taking a bit-flag integer value (also because I've got actions that worked with them so this is somewhat familiar territory for me.) Now, for this I'm only going to work with a small file as the end result. (maybe encoding four bit-flag integer values... One for each pixel and resulting in a 2x2px file) so, theoretically, I'll only need a 2x2px max image for this prototype system... I've made a PNG file (png 24 in Gimp) and the end resulting file size is 115 bytes... So, Four bit-flags. Since I am limited to a maximum value of the max an int value can store (yes, a long value holds more but I'm not that confident at being able to handle it quite yet) But for a 31 boolean encoded bit-flag, the max value would be 2,147,483,647 which will fit into one pixel.

So, 31*4 boolean values condensed into a 115 byte file that can be transferred... (for a prototype system... The bit-flags are more intended as proof of concept.)

WHAT:
Data encoding via encrypting it into an image. (Lossless is needed so maybe a BMP or PNG would work as long as it's not losing any information from compression... Still unsure what would be best but I'm going to stick with PNG for now since it's a somewhat universal image format.)

HOW:
This is where I'm at a loss... I've googled how to do creation of image files by referencing stack overflow and it seems I can do that in C#... Whether I can do this in PlayMaker is another issue (and I'm not even sure it can be done in Unity at all but at least it's something I think could be worth trying.)

PROCESS:
Create the code to encode and build the image... then create the code to read and decode the image. Once that's done, do tests to ensure that the data IS being transferred accurately.

Second step would be to try maybe encoding an XML file in some manner... Maybe using the ASCII tables to assign each character a value and then do a raw read/encode/transfer/decode process...

CONCLUSION:
Yes, this is a ballsy idea and a little bit insane... But I think it might be fun to work on it (And this is intended to be an open-source idea... Because I like the idea of keeping it open and free.)

So... Anyone have any tips, advice, suggestions?

And yeah, the working name would be "Pic-code." IT doesn't need one but if it's a viable idea why the hell not give it an easier to remember name than "picture encoding of data for easy transfer" or whatever.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14342
  • Official Playmaker Support
    • View Profile
Re: [Scripting] Creating a raw "Pic-code" image manually
« Reply #1 on: June 27, 2015, 07:58:17 AM »
Hi,

 Interesting topic.


Basically, if you reduce an image to a byte array, then, there is no advantages in using the image as a "medium" to store data, it's called in mysql a "BLOB" : Binary Large OBject

https://en.wikipedia.org/wiki/Binary_large_object

http://stackoverflow.com/questions/11624807/what-is-the-differences-between-blob-and-text-in-mysql-data-types

And so, this is indeed a very important part of software development., but I don't think you need to make your life harder then it needs, unless you have some reasons and use cases?

IF you go into such framework development, creating a Unity Object  would be the ideal way, and then inside PlayMaker you can use FsmObject and point to the type you will have created for the purpose. If you need examples on this, I'll give access to a work in progress about color referencing and palettes inside Unity UI, it makes uses of Unity Objects.

Also, look at the current serializers for example from WhyDoIDoIt, it's perfectly capable of doing what you are aiming for.


Bye,

 Jean