Browse Source

added fxJPGHexGlitch

master
Victor Giers 1 year ago
parent
commit
6a99b0b8e0
6 changed files with 124 additions and 6 deletions
  1. BIN
      data/JPGHex.jpg
  2. BIN
      data/result.jpg
  3. 1
    1
      data/saves.sav
  4. 118
    2
      effects.pde
  5. 2
    2
      secondapplet.pde
  6. 3
    1
      statics_and_lists.pde

BIN
data/JPGHex.jpg View File


BIN
data/result.jpg View File


+ 1
- 1
data/saves.sav View File

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

+ 118
- 2
effects.pde View File

@@ -1,6 +1,7 @@
/*

ASDFPIXELSORT
by Kim Asendorf
*/

@@ -287,6 +288,7 @@ class ASDFPIXELSORT extends Shader {
/*

DISTORTER
by Tomasz Sulej
*/

@@ -4139,7 +4141,7 @@ class SEGMENTER extends Shader {
canvas.beginDraw();

for (int i = 0; i < iterations; i++) {
canvas.loadPixels();
canvas.loadPixels();
for (int j = bounds[1]; j < bounds[3]-1; j++) {
for (int k = bounds[0]; k < bounds[2]-1; k++) {
float bright = canvas.brightness(canvas.get(k, j));
@@ -4224,7 +4226,7 @@ class SEGMENTER extends Shader {
}//choice
}//hori loop
}//vert loop
canvas.updatePixels();
canvas.updatePixels();
}//iterations
canvas.endDraw();
}
@@ -4237,3 +4239,117 @@ class SEGMENTER extends Shader {
// }
}
}

/*

COLORCRUSHER
*/

class COLORCRUSHER extends Shader {
float c;
int m = 5;
COLORCRUSHER() {
name = "fxColorCrusher";
params.add(new Param("multiplier", INTVAL, 2, 10, new int[]{SINE, TAN, SAWTOOTH, TRIANG}));
}
void apply() {
m = (int)params.get(0).value;
canvas.beginDraw();
canvas.loadPixels();
for (int i = 0; i < canvas.pixels.length; i++) {
c = color(canvas.pixels[i]);
canvas.pixels[i] = int(c*m);
}
canvas.updatePixels();
canvas.endDraw();
}
}

/*

RAINBOWHUE
*/

//...

/*

JPGHexGlitch
by Victor Giers
*/

class JPGHEXGLITCH extends Shader {
PImage img;
byte[] brokenfile;
JPGHEXGLITCH() {
name = "fxJPGHexGlitch";
params.add(new Param("byte amount to change probability", INTVAL, 2, 20, new int[]{RANDOM}));
params.add(new Param("iterations", INTVAL, 1, 10, new int[]{RANDOM}));
params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
directionParamIndex = 2;
rw = canvas.width;
rh = canvas.height;
img = createImage(rw, rh, ARGB);
}
int rw, rh;
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();
for (int k = 0; k < iterations; k++) {
canvas.image(img, canvas.width/2, canvas.height/2);
canvas.save(dataPath("")+"/JPGHex.jpg"); //save as jpg
brokenfile = loadBytes(dataPath("")+"/JPGHex.jpg"); //and reload. just in case it wasnt a jpg.
double probability = float(probparam) / float(brokenfile.length);
byte[] savebytes2 = new byte[brokenfile.length];
boolean headerEnd = false;
boolean FFfound = false;
int glitchCount = 0;

for (int i = 0; i < brokenfile.length; i++) {
String hexStr = hex(brokenfile[i]);

if (FFfound && hexStr.equals("DA")) headerEnd = true;
FFfound = false;
if (hexStr.equals("FF")) FFfound = true;

if (headerEnd && 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.jpg", savebytes2);
img = loadImage(dataPath("") + "/result.jpg");
}

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

+ 2
- 2
secondapplet.pde View File

@@ -592,11 +592,11 @@ public class SecondApplet extends PApplet {

if (shaderList.size() == 0) {
println("adding");
addByID((int)random(29));
addByID((int)random(FX.length));
}
if (random(1)<0.01) {
println("adding");
addByID((int)random(29));
addByID((int)random(FX.length));
}

if (random(1)<0.01) {

+ 3
- 1
statics_and_lists.pde View File

@@ -28,7 +28,9 @@ String FX[] = {
"LENS",
"SLICER",
"STREAKER",
"SEGMENTER"
"SEGMENTER",
"COLORCRUSHER",
"JPGHEXGLITCH"
};



Loading…
Cancel
Save