improved fxwebp
This commit is contained in:
35
effects.pde
35
effects.pde
@@ -4358,6 +4358,8 @@ class WEBPCORRUPTION extends Shader {
|
||||
PImage img;
|
||||
byte[] brokenfile;
|
||||
int rw, rh;
|
||||
String[] convertToPNG;
|
||||
String[] convertToWebp;
|
||||
WEBPCORRUPTION() {
|
||||
name = "fxWebpCorruption";
|
||||
params.add(new Param("byte amount to change probability", INTVAL, 2, 50, new int[]{RANDOM}));
|
||||
@@ -4366,15 +4368,8 @@ class WEBPCORRUPTION extends Shader {
|
||||
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);
|
||||
}
|
||||
convertToPNG = new String[]{"/usr/local/bin/convert", "-verbose", dataPath("") + "/webp_glitched.webp", dataPath("") + "/webp_glitched.png"};
|
||||
convertToWebp = new String[]{"/usr/local/bin/convert", "-verbose", dataPath("") + "/webp_orig.png", dataPath("") + "/webp_orig.webp"};
|
||||
}
|
||||
|
||||
void apply() {
|
||||
@@ -4390,11 +4385,11 @@ class WEBPCORRUPTION extends Shader {
|
||||
canvas.image(img, canvas.width/2, canvas.height/2);
|
||||
|
||||
|
||||
File oldImage = new File(dataPath("")+"/webp_orig.webp");
|
||||
File oldImage = new File(dataPath("")+"/webp_orig.png");
|
||||
if (oldImage.exists()) {
|
||||
oldImage.delete();
|
||||
}
|
||||
oldImage = new File(dataPath("")+"/png_orig.png");
|
||||
oldImage = new File(dataPath("")+"/webp_orig.webp"); //is it better to move this up again?
|
||||
if (oldImage.exists()) {
|
||||
oldImage.delete();
|
||||
}
|
||||
@@ -4406,21 +4401,14 @@ class WEBPCORRUPTION extends Shader {
|
||||
if (oldImage.exists()) {
|
||||
oldImage.delete();
|
||||
}
|
||||
String[] convertToPNG = {"/usr/local/bin/convert", "-verbose", dataPath("") + "/webp_glitched.webp", dataPath("") + "/webp_glitched.png"};
|
||||
while (!runCommand(convertToPNG)) {
|
||||
canvas.save(dataPath("")+"/webp_orig.png"); //save as png
|
||||
int failCount = 0;
|
||||
while (!runCommand(convertToPNG) && failCount < 25) {
|
||||
failCount ++;
|
||||
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);
|
||||
@@ -4452,7 +4440,8 @@ class WEBPCORRUPTION extends Shader {
|
||||
}
|
||||
*/
|
||||
}
|
||||
img = loadImage(dataPath("") + "/webp_glitched.png");
|
||||
if(failCount == 50) println("Failed 50 times, skipping webp glitch");
|
||||
else img = loadImage(dataPath("") + "/webp_glitched.png");
|
||||
|
||||
//launch(dataPath("") + "/webpdecode.command");
|
||||
//delay(1500);
|
||||
|
||||
Reference in New Issue
Block a user