We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
glitch art (Read 2880 times)
glitch art
Oct 17th, 2007, 5:29pm
 
hey there,

i was wondering if there is a way to load images or even movies into processing and mess with their binary data, so that the result would be a messed-up glitch-esque piece of art.

i'm not that experienced with processing, so i don't even know how to load these files as binaries.

any suggestions?

thanks a lot!

EDIT:
one approach that comes to my mind:
converting an image to a textfile, randomly mess around with the content, and then add a gif/jpg/whatever header again.
is that possible?
Re: glitch art
Reply #1 - Oct 17th, 2007, 6:49pm
 
i think you can loadStrings() and saveStrings() with bmp files. just tested with textedit / photoshop .. gives funny results

F
Re: glitch art
Reply #2 - Oct 18th, 2007, 4:07pm
 
thanks i'll give it a try.

the problem (for me) is to write a routine that systematically changes the content of the file.
if you just randomly f*** around, you might destroy the file's header, or make it unreadable by giving it an "unexpected end of file".

has anyone tried to do this before? someone able to provide me with some code snippets?

thanks

EDIT:
ok, reading a normal .bmp file (1.5 mb) simply takes forever to load with loadstrings.

what i did:
------
     

String lines[] = loadStrings("test.bmp");
println("there are " + lines.length + " lines");
for (int i=0; i < lines.length; i++) {
 println(lines[i]);
}
-------

processing acutally does output the lines of the file, but it takes about 2 minutes or something.

is there a faster way to load the text content of an image?

EDIT 2:
alright, stupid me.
only the printing of the lines took so long...

so now how to i exchange some of the characters of the file with new characters. i'm really pretty new to processing, especially the I/O section.
i don't just want to add some characters/lines, because that would make the file unreadable. i really want it to keep the exact amount of characters, but some of them exchanged.
any hint is totally appreciated!
Re: glitch art
Reply #3 - Oct 18th, 2007, 6:45pm
 
You don't need ot treat the data as text, it's binary, so you can treat it as binary:

Code:
byte[] data=loadBytes("myimg.bmp");
for(int i=0;i<100;i++) // 100 changes
{
int loc=random(128,data.length)//guess at header being 128 bytes at most..
data[loc]=(byte)random(255);
}
saveBytes("myimgedited.bmp",data);
Re: glitch art
Reply #4 - Oct 18th, 2007, 7:14pm
 
thanks a LOT for the reply!

looks great.

anyway, i get the following error:
"unexpected token: int".

any clue?
it's probably something really easy, but as i said:
i'm not tooooo good at processing...
Re: glitch art
Reply #5 - Oct 18th, 2007, 8:24pm
 
I missed a ; from the end of the "int loc=..." line.
Re: glitch art
Reply #6 - Oct 18th, 2007, 9:52pm
 
thanks man,
should have recognized that myself...Wink

but could you please try your piece of code on your computer?
i'm getting another message about some float/int variable assignment errors. this is totally not my speciality...

thanks a lot for your help!
Re: glitch art
Reply #7 - Oct 18th, 2007, 10:24pm
 
Ah, I put one cast in, but not another:
Code:
byte[] data=loadBytes("myimg.bmp");
for(int i=0;i<100;i++) // 100 changes
{
int loc=(int)random(128,data.length);//guess at header being 128 bytes at most..
data[loc]=(byte)random(255);
}
saveBytes("myimgedited.bmp",data);


FWIW, it seems that mussing up bmp files does very little, however with jpeg files you get visible effects.
Re: glitch art
Reply #8 - Oct 19th, 2007, 8:38am
 
thank you so much!

messing around with jpg files brings some reeaaally amazing results. keeping the number of changes rather small (around 30) turned out to be best for beautiful subtle effects.

however, it seems to be not really working with bmp files.
i used to get some nice glitched images when i opened bmp files with a text editor and manually edited the content.
but when i run a bmp through this code, it apparently only changes the value of some of the pixels to red or green, giving it a rather boring grainy effect.

anyway, thanks again. you rule!

i'll now try to find out how to manipulate movie files without making them completely unreadable. seems to be a harder task.

another EDIT:
haha, no, it's really not hard. your code can manage .mov files too. whenever i edited movie files in a texteditor, i destroyed them.

EDIT #20000:
ok, your code can destroy them too. sometimes it hits the wrong byte. it's just totally random.
Page Index Toggle Pages: 1