diff --git a/data/JPGHex.jpg b/data/JPGHex.jpg index a0d58a1..98f94a4 100644 Binary files a/data/JPGHex.jpg and b/data/JPGHex.jpg differ diff --git a/data/WEBPhex.webp b/data/WEBPhex.webp deleted file mode 100644 index eb72005..0000000 Binary files a/data/WEBPhex.webp and /dev/null differ diff --git a/data/img.png b/data/img.png index cd6ce42..808e274 100644 Binary files a/data/img.png and b/data/img.png differ diff --git a/data/result.png b/data/result.png deleted file mode 100644 index 7927e0f..0000000 Binary files a/data/result.png and /dev/null differ diff --git a/data/result.webp b/data/result.webp deleted file mode 100644 index 92d7dcd..0000000 Binary files a/data/result.webp and /dev/null differ diff --git a/data/saves.sav b/data/saves.sav index 761c446..077ff92 100755 --- a/data/saves.sav +++ b/data/saves.sav @@ -1,2 +1,2 @@ //globals -uptime = 117147364 +uptime = 117205446 diff --git a/data/webp_glitched.png b/data/webp_glitched.png new file mode 100644 index 0000000..172ab26 Binary files /dev/null and b/data/webp_glitched.png differ diff --git a/data/webp_glitched.webp b/data/webp_glitched.webp new file mode 100644 index 0000000..9870350 Binary files /dev/null and b/data/webp_glitched.webp differ diff --git a/data/webp_orig.png b/data/webp_orig.png new file mode 100644 index 0000000..6a7275b Binary files /dev/null and b/data/webp_orig.png differ diff --git a/data/webp_orig.webp b/data/webp_orig.webp new file mode 100644 index 0000000..761a801 Binary files /dev/null and b/data/webp_orig.webp differ diff --git a/data/webpdecode.command b/data/webpdecode.command deleted file mode 100755 index 7a01adf..0000000 --- a/data/webpdecode.command +++ /dev/null @@ -1 +0,0 @@ -convert "/Users/giers/Documents/Processing 3/manglr2/data/result.webp" "/Users/giers/Documents/Processing 3/manglr2/data/result.png" diff --git a/data/webpencode.command b/data/webpencode.command deleted file mode 100755 index e6a0f5e..0000000 --- a/data/webpencode.command +++ /dev/null @@ -1 +0,0 @@ -convert "/Users/giers/Documents/Processing 3/manglr2/data/img.png" "/Users/giers/Documents/Processing 3/manglr2/data/WEBPhex.webp" diff --git a/effects.pde b/effects.pde index 7879c58..09c6816 100644 --- a/effects.pde +++ b/effects.pde @@ -4387,16 +4387,42 @@ class WEBPCORRUPTION extends Shader { 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]; + canvas.image(img, canvas.width/2, canvas.height/2); + + + File oldImage = new File(dataPath("")+"/webp_orig.webp"); + if (oldImage.exists()) { + oldImage.delete(); + } + oldImage = new File(dataPath("")+"/png_orig.png"); + if (oldImage.exists()) { + oldImage.delete(); + } + oldImage = new File(dataPath("")+"/webp_glitched.webp"); + if (oldImage.exists()) { + oldImage.delete(); + } + oldImage = new File(dataPath("")+"/webp_glitched.png"); + if (oldImage.exists()) { + oldImage.delete(); + } + String[] convertToPNG = {"/usr/local/bin/convert", "-verbose", dataPath("") + "/webp_glitched.webp", dataPath("") + "/webp_glitched.png"}; + while (!runCommand(convertToPNG)) { + println("Trying to convert..."); + canvas.save(dataPath("")+"/webp_orig.png"); //save as png + String[] convertToWebp = {"/usr/local/bin/convert", "-verbose", dataPath("") + "/webp_orig.png", dataPath("") + "/webp_orig.webp"}; + while (!runCommand(convertToWebp)) { + println("Conversion failed, trying again..."); + } + + //delay(300); + //launch(dataPath("") + "/webpencode.command"); + //String[] commandToRun = {"/usr/local/bin/convert", "-verbose", dataPath("") + "/0.png", dataPath("") + "/webp_orig.webp"}; + //delay(1500); + + + brokenfile = loadBytes(dataPath("")+"/webp_orig.webp"); //and reload. just in case it wasnt a jpg. + byte[] savebytes = new byte[brokenfile.length]; double probability = float(probparam) / float(brokenfile.length); int glitchCount = 0; for (int i = 0; i < brokenfile.length; i++) { @@ -4410,19 +4436,30 @@ class WEBPCORRUPTION extends Shader { } byte hexByte[] = fromHexString(hexStr); for (int j = 0; j < hexByte.length; j++) { - savebytes2[i] += hexByte[j]; + savebytes[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; + saveBytes(dataPath("") + "/webp_glitched.webp", savebytes); + File newImage = new File(dataPath("")+"/webp_glitched.webp"); + while (!newImage.exists()) { + println("Waiting until bytes have been written to disk..."); + } + /* + String[] convertToPNG = {"/usr/local/bin/convert", "-verbose", dataPath("") + "/webp_glitched.webp", dataPath("") + "/webp_glitched.png"}; + while (!runCommand(convertToPNG)) { + println("Trying to convert..."); + } + */ } + img = loadImage(dataPath("") + "/webp_glitched.png"); + + //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"); + canvas.image(img, canvas.width/2, canvas.height/2); canvas.endDraw(); } diff --git a/manglr2.pde b/manglr2.pde index 8e39964..0d3fd4a 100644 --- a/manglr2.pde +++ b/manglr2.pde @@ -161,3 +161,29 @@ String getOS() { return "other"; } } +boolean runCommand(String[] command) { + //String returnedValues; + try { + Process p = new ProcessBuilder(command).start(); + int ii = p.waitFor(); + if (ii == 0) { //success signal + //BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); + //while ( (returnedValues = stdInput.readLine ()) != null) { + //println(returnedValues); + //} + return(true); + } else { + //BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream())); + //println("Error:"); + //while ( (returnedValues = stdErr.readLine ()) != null) { + //println(returnedValues); + //} + return(false); + } + } + catch (Exception e) { + //println("Error running command"); + //println(e); + return(false); + } +}