5 ms·
Can anyone please contribute to how this works?
by lordlarm 16y ago
Can anyone please contribute to how this works?
- perlgeek 16y agoThe maker of the picture wrote the code first in a text editor, and then for each triple of ASCII characters he found the corresponding RGB value, and set one pixel to it. Since the bitmap is just a header (the mojibake you see at the start of the text file) and then a bunch of data bytes, the data bytes can be read as plain text again.
- jcl 16y agoSome other things to note: He is filling in the image from left-to-right, bottom-to-top. That's the scanline order of the data in BMP files, which means he is entering the code in the order it appears in the file. Also, the image he is filling in is eight pixels wide. This is important because the row data in BMP files must be padded to a multiple of four bytes. Each pixel in a 24-bit image takes three bytes. If he had picked a width that wasn't a multiple of four, he would have had garbage padding bytes in the middle of his code.
- rheide 16y agoI'm guessing the bmp format happens to look like ascii for certain pixels with certain colors. I wonder if this works in reverse. Maybe we can program the Mona Lisa in C.
- JoachimSchipper 16y agoC code is too "random" to produce nice images. You can use the least significant bits to hold some data; Google "steganography" (this is just the most basic).
- JonnieCache 16y ago>C code is too "random" to produce nice images In a world where it is possible to compute a file that contains its own MD5, I wouldn't bet on this. Wish I could find the link, there was some feted programmer who had a friend that bet him such a thing was not possible. He proceeded to write an algorithm that found such a file by brute force. I wouldn't count on the eventual C being pretty though. See also: electronic musicians hiding pictures in their music http://www.bastwood.com/?page_id=10 http://www.bastwood.com/?page_id=10
- JoachimSchipper 16y agoYou're right: sane C code is too "random" to produce nice images. ;-)
- JonnieCache 16y agoOne hacker's insanity is another's pastime. http://www.de.ioccc.org/main.html http://www.de.ioccc.org/main.html
- JoachimSchipper 16y agoYeah, that's what I thought of too. Has it been done yet?
- RodgerTheGreat 16y agoIn Java, source files can contain unicode escapes[1] of the form '\uXXXX' which are expanded prior to tokenization. In effect this gives you several options for what characters can exist in a given "pixel". I think that this, combined with careful application of whitespace and comments, should easily provide enough flexibility to make arbitrary code look roughly like a desired bitmap. [1] http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#100850 http://java.sun.com/docs/books/jls/second_edition/html/lexic...
- JoachimSchipper 16y agoJust \uXXXX (or C trigraphs etc) doesn't give you much to play with, and I'd say that selectively tokenizing Java is cheating.
- mrcharles 16y agoExample of a python script in a bitmap: http://www.bluh.org/codemap.bmp http://www.bluh.org/codemap.bmp Ultimately it's never going to be pretty if it's human readable as the range of bytes used will make a lot of greyish tones. C/C++ wouldn't look a lot different I doubt, but if you want you can grab my python script (PIL required) and pack some source files and see for yourself: http://www.github.com/mrcharles/codemap http://www.github.com/mrcharles/codemap (script has some bugs with alignment, but other than that, works)
- piaskal 16y agoIt's pretty smart, but very simple. He just puts character ASCII codes into RGB fields in color picker. In 24 bit bmp format those values are saved directly to the file.
- kbutler 16y agoSimple BMP files consist of a header followed by pixel data. By selecting the colors for individual pixels that correspond to the ASCII characters in the source code, a BMP is created that contains the source code. This seems completely useless, until you realize that early computers were programmed by flipping switches to enter the binary values the operator wanted to set... Then you realize that this is entering human-readable high-level language code that would have to be compiled, and with a header that will fail to compile, so yes, this is completely useless. grin