Browse Source

added very early version of fxWEBPCorruption

master
Victor Giers 2 years ago
parent
commit
8832351b4a
12 changed files with 113 additions and 6 deletions
  1. BIN
      data/JPGHex.jpg
  2. BIN
      data/WEBPhex.webp
  3. BIN
      data/img.png
  4. BIN
      data/result.png
  5. BIN
      data/result.webp
  6. 1
    1
      data/saves.sav
  7. 1
    0
      data/webpdecode.command
  8. 1
    0
      data/webpencode.command
  9. 92
    4
      effects.pde
  10. 15
    0
      manglr2.pde
  11. 1
    0
      secondapplet.pde
  12. 2
    1
      statics_and_lists.pde

BIN
data/JPGHex.jpg View File


BIN
data/WEBPhex.webp View File


BIN
data/img.png View File


BIN
data/result.png View File


BIN
data/result.webp View File


+ 1
- 1
data/saves.sav View File

@@ -1,2 +1,2 @@
//globals
uptime = 116980695
uptime = 117147364

+ 1
- 0
data/webpdecode.command View File

@@ -0,0 +1 @@
convert "/Users/giers/Documents/Processing 3/manglr2/data/result.webp" "/Users/giers/Documents/Processing 3/manglr2/data/result.png"

+ 1
- 0
data/webpencode.command View File

@@ -0,0 +1 @@
convert "/Users/giers/Documents/Processing 3/manglr2/data/img.png" "/Users/giers/Documents/Processing 3/manglr2/data/WEBPhex.webp"

+ 92
- 4
effects.pde View File

@@ -4276,17 +4276,17 @@ class COLORCRUSHER extends Shader {

/*

JPGHexGlitch
JPGCorruption
by Victor Giers
*/

class JPGHEXGLITCH extends Shader {
class JPGCORRUPTION extends Shader {
PImage img;
byte[] brokenfile;
JPGHEXGLITCH() {
JPGCORRUPTION() {
name = "fxJPGHexGlitch";
params.add(new Param("byte amount to change probability", INTVAL, 2, 20, new int[]{RANDOM}));
params.add(new Param("byte amount to change probability", INTVAL, 2, 200, new int[]{RANDOM}));
params.add(new Param("iterations", INTVAL, 2, 10, new int[]{RANDOM}));
params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
directionParamIndex = 2;
@@ -4353,3 +4353,91 @@ class JPGHEXGLITCH extends Shader {
return result;
}
}

class WEBPCORRUPTION extends Shader {
PImage img;
byte[] brokenfile;
int rw, rh;
WEBPCORRUPTION() {
name = "fxWebpCorruption";
params.add(new Param("byte amount to change probability", INTVAL, 2, 50, new int[]{RANDOM}));
params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
directionParamIndex = 1;
rw = canvas.width;
rh = canvas.height;
img = createImage(rw, rh, ARGB);
String encodecmd[] = {"convert \"" + dataPath("") + "/img.png\" \"" + dataPath("") + "/WEBPhex.webp\""};
String decodecmd[] = {"convert \"" + dataPath("") + "/result.webp\" \"" + dataPath("") + "/result.png\""};
if (OS == "mac") {
saveStrings(dataPath("") + "/webpencode.command", encodecmd);
saveStrings(dataPath("") + "/webpdecode.command", decodecmd);
} else if (OS == "windows") {
saveStrings(dataPath("") + "/webpencode.cmd", encodecmd);
saveStrings(dataPath("") + "/webpdecode.cmd", decodecmd);
}
}

void apply() {
if (rw != canvas.width || rh != canvas.height) {
rw = canvas.width;
rh = canvas.height;
img.resize(rw, rh);
}
int probparam = (int)params.get(0).value;
int iterations = (int)params.get(1).value;
img = canvas.get();
canvas.beginDraw();
boolean finished = false;
while(!finished) {
println("yo");
canvas.image(img, canvas.width/2, canvas.height/2);
canvas.save(dataPath("")+"/img.png"); //save as png
delay(300);
launch(dataPath("") + "/webpencode.command");
delay(1500);
brokenfile = loadBytes(dataPath("")+"/WEBPhex.webp"); //and reload. just in case it wasnt a jpg.
byte[] savebytes2 = new byte[brokenfile.length];
double probability = float(probparam) / float(brokenfile.length);
int glitchCount = 0;
for (int i = 0; i < brokenfile.length; i++) {
String hexStr = hex(brokenfile[i]);
if (i > 10) { // skip header
if (random(1)<probability) {
String randomHex = (str(Character.forDigit((int)random(16), 16)) + str(Character.forDigit((int)random(16), 16))).toUpperCase();
hexStr = randomHex;
glitchCount++;
}
}
byte hexByte[] = fromHexString(hexStr);
for (int j = 0; j < hexByte.length; j++) {
savebytes2[i] += hexByte[j];
}
}
println("Glitched " + glitchCount + " bytes");
saveBytes(dataPath("") + "/result.webp", savebytes2);
delay(300);
launch(dataPath("") + "/webpdecode.command");
delay(1500);
//try or load fallback image and redo in while loop
PImage compare = img.get();
img = loadImage(dataPath("") + "/result.png");
if (img != compare) finished = true;
}
canvas.image(img, canvas.width/2, canvas.height/2);
canvas.endDraw();
}

byte[] fromHexString(final String encoded) {
if ((encoded.length() % 2) != 0)
throw new IllegalArgumentException("Input string must contain an even number of characters");

final byte result[] = new byte[encoded.length()/2];
final char enc[] = encoded.toCharArray();
for (int i = 0; i < enc.length; i += 2) {
StringBuilder curr = new StringBuilder(2);
curr.append(enc[i]).append(enc[i + 1]);
result[i/2] = (byte) Integer.parseInt(curr.toString(), 16);
}
return result;
}
}

+ 15
- 0
manglr2.pde View File

@@ -23,6 +23,7 @@ boolean recording; //save every frame?
int renderSize = 500; //px
float renderFrameRate;
String[] saveData;
String OS;
int w, h;

boolean spawnPlaying = false;
@@ -66,6 +67,7 @@ void setup() {
fallbackImage = loadImage(dataPath("0.png"));
bin = loadImage(dataPath("bin.png"));
cam = new Capture(this, 1280, 768);
OS = getOS();

String[] args = {"SecondFrame"};
//gui = new SecondApplet(this);
@@ -146,3 +148,16 @@ void mouseWheel(MouseEvent event) {
else renderSize -= 8;
renderSize = constrain(renderSize, 8, 15000);
}

String getOS() {
String os = System.getProperty("os.name");
if (os.contains("Windows")) {
return "windows";
} else if (os.contains("Mac")) {
return "mac";
} else if (os.contains("Linux")) {
return "linux";
} else {
return "other";
}
}

+ 1
- 0
secondapplet.pde View File

@@ -271,6 +271,7 @@ public class SecondApplet extends PApplet {
previousRenderSize = renderSize;
else
renderSizeChanged = false;
for (int i = 0; i < shaderList.size(); i++) {
//try {


+ 2
- 1
statics_and_lists.pde View File

@@ -30,7 +30,8 @@ String FX[] = {
"STREAKER",
"SEGMENTER",
"COLORCRUSHER",
"JPGHEXGLITCH"
"JPGCORRUPTION",
"WEBPCORRUPTION"
};



Loading…
Cancel
Save