|
|
@@ -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; |
|
|
|
} |
|
|
|
} |