added very early version of fxWEBPCorruption
This commit is contained in:
BIN
data/JPGHex.jpg
BIN
data/JPGHex.jpg
Binary file not shown.
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 682 KiB |
BIN
data/WEBPhex.webp
Normal file
BIN
data/WEBPhex.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
BIN
data/img.png
Normal file
BIN
data/img.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.5 MiB |
BIN
data/result.png
Normal file
BIN
data/result.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 MiB |
BIN
data/result.webp
Normal file
BIN
data/result.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
@@ -1,2 +1,2 @@
|
||||
//globals
|
||||
uptime = 116980695
|
||||
uptime = 117147364
|
||||
|
||||
1
data/webpdecode.command
Executable file
1
data/webpdecode.command
Executable file
@@ -0,0 +1 @@
|
||||
convert "/Users/giers/Documents/Processing 3/manglr2/data/result.webp" "/Users/giers/Documents/Processing 3/manglr2/data/result.png"
|
||||
1
data/webpencode.command
Executable file
1
data/webpencode.command
Executable file
@@ -0,0 +1 @@
|
||||
convert "/Users/giers/Documents/Processing 3/manglr2/data/img.png" "/Users/giers/Documents/Processing 3/manglr2/data/WEBPhex.webp"
|
||||
96
effects.pde
96
effects.pde
@@ -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
manglr2.pde
15
manglr2.pde
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,6 +271,7 @@ public class SecondApplet extends PApplet {
|
||||
previousRenderSize = renderSize;
|
||||
else
|
||||
renderSizeChanged = false;
|
||||
|
||||
for (int i = 0; i < shaderList.size(); i++) {
|
||||
//try {
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ String FX[] = {
|
||||
"STREAKER",
|
||||
"SEGMENTER",
|
||||
"COLORCRUSHER",
|
||||
"JPGHEXGLITCH"
|
||||
"JPGCORRUPTION",
|
||||
"WEBPCORRUPTION"
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user