From f37e8b7025472249f1a15533ffa03b0dffb31b10 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sat, 23 Jul 2022 21:33:15 +0200 Subject: [PATCH] added fxImageLens --- data/saves.sav | 2 +- effects.pde | 178 ++++++++++++++++++++++++++++++++++++++++++ secondapplet.pde | 6 +- statics_and_lists.pde | 25 +++++- 4 files changed, 208 insertions(+), 3 deletions(-) diff --git a/data/saves.sav b/data/saves.sav index c6f5d7c..065ad76 100755 --- a/data/saves.sav +++ b/data/saves.sav @@ -1,2 +1,2 @@ //globals -uptime = 116780137 +uptime = 116792766 diff --git a/effects.pde b/effects.pde index 1ccae5b..f5d4d32 100644 --- a/effects.pde +++ b/effects.pde @@ -3279,6 +3279,184 @@ class LZ77 { } } +/* + + IMAGELENS + + */ + +class IMAGELENS extends Shader { + + // parameters + float bendx = 0.1; // from 0 to 1 + float bendy = 0.1; // from 0 to 1 + float[] power_vals = { 2, 0.5 }; // two values of power from 0.1 to 10, one for x and second for y + int[] types = { LINEAR, POWER }; // always to types one for x second for y + int[] channels = { BRIGHTNESS, SATURATION }; // as above + float[] facts = new float[2]; + ////////////// + PImage img; + PImage limg; + + int shaderListLength; + // working buffer + PGraphics buffer; + + IMAGELENS() { + name = "fxImageLens"; + shaderListLength = gui.shaderList.size(); + params.add(new Param("lens image layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM})); + params.add(new Param("power x", FLOATVAL, 0.1, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); + params.add(new Param("power y", FLOATVAL, 0.1, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); + params.add(new Param("lens type x", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); + params.add(new Param("lens type y", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); + params.add(new Param("channel x", INTVAL, 0, 11, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); + params.add(new Param("channel y", INTVAL, 0, 11, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); + params.add(new Param("curvature factor x", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); + params.add(new Param("curvature factor y", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); + params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); + directionParamIndex = 9; + + rw = canvas.width; + rh = canvas.height; + + img = createImage(rw, rh, ARGB); + limg = createImage(rw, rh, ARGB); + + buffer = createGraphics(rw, rh); + buffer.beginDraw(); + buffer.noStroke(); + buffer.endDraw(); + } + + int rw, rh; + void apply() { + if (rw != canvas.width || rh != canvas.height) { + rw = canvas.width; + rh = canvas.height; + buffer = createGraphics(rw, rh); + buffer.beginDraw(); + buffer.noStroke(); + buffer.endDraw(); + img.resize(rw, rh); + limg.resize(rw, rh); + } + if (shaderListLength != gui.shaderList.size()) { + shaderListLength = gui.shaderList.size(); + changeParam(0, new Param("lens image layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM})); + } + img = canvas.get(); + if ((int)params.get(0).value == pos) { + limg = canvas.get(); + } else { + limg = gui.shaderList.get((int)params.get(0).value).canvas.get(); + } + + power_vals[0] = params.get(1).value; + power_vals[1] = params.get(2).value; + types[0] = (int)params.get(3).value; + types[1] = (int)params.get(4).value; + channels[0] = (int)params.get(5).value; + channels[1] = (int)params.get(6).value; + bendx = params.get(7).value; + bendy = params.get(8).value; + facts[0] = bendx * img.width; + facts[1] = bendy * img.height; + + + img.loadPixels(); + limg.loadPixels(); + buffer.beginDraw(); + buffer.background(0); + + for (int x=0; x5?channel-6:channel; + float cc; + + switch(ch) { + case RED: + cc = red(c); + break; + case GREEN: + cc = green(c); + break; + case BLUE: + cc = blue(c); + break; + case HUE: + cc = hue(c); + break; + case SATURATION: + cc = saturation(c); + break; + default: + cc= brightness(c); + break; + } + + return channel>5?255-cc:cc; + } + + int getShift(color c, int idx) { + float cc = getChannel(c, channels[idx]); + + switch(types[idx]) { + case LINEAR: + return (int)(facts[idx] * cc/255.0); + case POWER: + return (int)(facts[idx]*map(pow(cc/255.0, power_vals[idx]), 0, 1, -1, 1)); + case SINUSOIDAL: + return (int)(facts[idx]*sin(map(cc, 0, 255, -PI, PI))); + default: + { // POLAR + float c1 = idx==0?cc:getChannel(c, channels[1]); + float c2 = idx==1?cc:getChannel(c, channels[0]); + float ang = map(c1, 0, 255, 0, TWO_PI); + float r = map(c2, 0, 255, 0, facts[0]); + return (int)(idx==0?r*cos(ang):r*sin(ang)); + } + } + } +} + + + + + + + + diff --git a/secondapplet.pde b/secondapplet.pde index c5c9325..743b305 100644 --- a/secondapplet.pde +++ b/secondapplet.pde @@ -182,7 +182,7 @@ public class SecondApplet extends PApplet { bricks.get(i).updateSliderPos(); } for (int i = min(pos1, pos2); i < shaderList.size(); i++) { - println(i); + //println(i); //shaderList.get(i).change = true; } } @@ -612,6 +612,10 @@ public class SecondApplet extends PApplet { break; case(26): shaderManager.addShader(new LZ7()); + break; + case(27): + shaderManager.addShader(new IMAGELENS()); + break; /* case(4): shaderManager.addShader(new AUECHO()); diff --git a/statics_and_lists.pde b/statics_and_lists.pde index 79d04cd..9e8e2e7 100644 --- a/statics_and_lists.pde +++ b/statics_and_lists.pde @@ -21,6 +21,28 @@ final static int RAMPUPDOWN = 9; //line up, stay, line down, stay final static int RANDOM = 10; +// LENS TYPES for imagelens +final static int LINEAR = 0; +final static int POWER = 1; +final static int POLAR = 2; +final static int SINUSOIDAL = 3; + +// general channels to work with +final static int RED = 0; +final static int GREEN = 1; +final static int BLUE = 2; +final static int HUE = 3; +final static int SATURATION = 4; +final static int BRIGHTNESS = 5; +final static int NRED = 6; +final static int NGREEN = 7; +final static int NBLUE = 8; +final static int NHUE = 9; +final static int NSATURATION = 10; +final static int NBRIGHTNESS = 11; + + + // FLAGS, ALGORITHMS and EASING mathod by sulej for ultimate sort @@ -75,5 +97,6 @@ String availableFx[] = { "fxDripDrip", "fxWrongQSort", "fxVHS", - "fxLZ77" + "fxLZ77", + "fxImagelens" };