Is a picture worth a thousand words?
November 27th, 2006
The other day there was a thread on a mailing list related to getting large amounts of text in to a Shockwave movie and keeping the bandwidth small. Since you can’t use the UnZip Xtra in Shockwave someone mentioned the idea of having data that represents text placed inside an image, and then convert the image to the text in the dcr.
For some reason I suddenly thought of when I was a kid trying to write top secret notes that only my buddy would be able to read if he knew “the code,” so I figured I’d play with this for a few minutes after eating a bit too much turkey the other day.
In terms of a basic image, each pixel of the image consists of red, green, and blue (when working in the RGB color model). Since each pixel has three colors (and each color ranges from 0 to 255) I decided to use a very simple method where each pixel will represent three letters of the text. Using a 100 x 100 pixel image I can get 30,000 characters of text. A typical png of that size is around 6k, so the png is very small compared to the amount of data you can extract.
When converting from text to image I embed the total number of characters in the first pixel (see code for method used), and then use the remaining pixels to store the characters (three characters/pixel). Each character is turned in to a number using the charToNum
function, and that set of three characters is then turned in to the pixel using setPixel
.
When going from image to text I basically do the opposite. I read the first pixel (using getPixel
) to see how many characters I have to deal with, and then start reading all the rest of the pixels and using numToChar
to translate the red, green, and blue colors in to characters. The reason I put the total number of characters in that first pixel was so that I wouldn’t have to read all 10,000 pixels every time (only as many as needed to save time).
This was a very simple way to do this and you could add a lot of features that would enable more interesting encryption methods, as well as other ways to encode the data that would lead to far more compression.
Click to view example (pop up window)
Director Source Code (zip file)
Note: I have not added any error checking to the source code, so many thing could cause an error (as well as the shockwave sample).
Entry Filed under: Daily thoughts,Demo Files,Imaging Lingo
7 Comments Add your own
1. Laurent | November 21st, 2006 at 8:36 am
Can’t download samples !
Anyway, very usefull info !
2. MultimediaGuy | November 26th, 2006 at 7:19 pm
Whoops. I’ve updated the links.
3. Kris | November 29th, 2006 at 7:28 am
Cool!
4. Johan | November 30th, 2006 at 4:59 am
Simple, yet effective, I’m gonna have fun with this one!!
5. CC | December 5th, 2006 at 6:02 pm
You might be able to get even better compression. Typically, you’ll only be using ASCII characters 32-128, which means that you could store each character in 7 bits, leaving an extra bit for each color value. You could then recover an extra three characters for every seven pixels.
If you only needed to store upper case letters (or only lower case letters), you could reduce this even further to characters 32-95, using 6 bits per character, which would leave you with 4 characters for every pixel. (You could still use this technique if you have infrequent case changes by prefixing them with an unused character like a carat. As long as they occur less than once every three characters, you’d still see a size savings.)
6. blog properties | April 25th, 2007 at 4:54 am
I can download those samples but i can’t view clearly and sometimes prompt do u want to countinue or not.
7. mtpb | April 26th, 2007 at 6:01 am
This can be used to download things at the library!
Once upon a time, in a world where I used to have to send and receive BIG files via dial up, I used to dream of how I could utilize my public library’s T1 connection. The computers there had no floppy, no CD, no nothing… I mostly had to receive big files, turn into Director movies, and then mail overnight. The receive part was so painful. The dream was…. could I attach suction cups outfitted with photocells to a CRT in strategic places and have the content I needed to download become rasterized into blinking boxes? Think about that!
-MTPB
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed