Datamoshing/Databending/RGB Shifting an Image

I’m attempting to “dance on the edge of a failing system” and create a glitch art creator for iOS,

I’ve been trying to play around with manipulating the unsigned char* data from ofPixel but with no luck. I have tried to convert it to a string and then back again but that also fails.

I am trying to datamosh an image, so prescriptive shaders and pseudo pseudo random functions aren’t really the way I’m looking to go.

Really I’m looking to access the image data, delete/add/modify a few bytes and then set it back as a displayable image, highly and unpredictably messed up, but not always completely broken (sometimes is fine tho!)

How can I access this data, lightly mess around with it, and then open it back up as an image?

Thanks

Hi, I think you should work with the file bytes, not with pixels.

The results and techniques depend very much on the file type. It’s harder with PNG but with jpg it’s rather easy: just copy all bytes from a jpg file to a new file, but just change one of the bytes. I think there’s a header you should avoid altering (don’t mess with the first x bytes). Then load and display the jpg with the modified byte to see the result. You can do many passes to the same file to slowly break the file by flipping bytes :slight_smile:

You could probably do it without saving and loading the image, but for that you would need to access the jpg decoding method and I don’t know if it’s public.

Similar approaches may work with video files. I think mp4 has valuable data you should not change at both file ends, but don’t quote me on that :slight_smile:

oooh yummy,
thanks! yeah i’ve played around with a few methods like that on desktop and have had some fun (textedit etc)

there’s a glitch example in the input_output folder, imageCompressionExample that does exactly this. datamoshing is something that only really works with video not individual images

@Miles the easiest way to mess with pixels is using an ofImage, and remember to call update() on the image after you’ve modified the pixels.
you might find this useful https://github.com/ofcourseio/SPRING2016/blob/master/week4/pixels.md
also, take a look at rosa menkman’s vernacular of file formats

1 Like

Thanks guys, I wasn’t able to make this work on iOS and 0.9.8, so I’ve downloaded 0.10 however, the iOS project generator included with the download appears to be the one for OSX, not iOS

Thanks, I’ve been having a play around with it, however on iOS, ofBufferFromFile leaves the ofBuffer file empty. I think it might actually be the img.save() that’s not actually saving

Ok, solved it, the compressed image needs to be saved to the Documents Directory on iOS:

string curFilename = ofxiPhoneGetDocumentsDirectory() +“compressed.jpg”;

1 Like