added fxImageLens

This commit is contained in:
2022-07-23 21:33:15 +02:00
parent af070b6edc
commit f37e8b7025
4 changed files with 208 additions and 3 deletions

View File

@@ -1,2 +1,2 @@
//globals
uptime = 116780137
uptime = 116792766

View File

@@ -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; x<img.width; x++) {
int lx = (int)map(x, 0, img.width-1, 0, limg.width-1);
for (int y=0; y<img.height; y++) {
int ly = (int)map(y, 0, img.height-1, 0, limg.height-1);
color c = limg.pixels[lx+ly*limg.width];
int posx = (x+getShift(c, 0)+2*img.width)%img.width;
int posy = (y+getShift(c, 1)+2*img.height)%img.height;
color n = img.pixels[posx+posy*img.width];
buffer.fill(n);
// fill(red(c),green(c),blue(n)); // work only on blue channel
// fill(red(n), abs(green(c)-green(n)), blue(n)); // green channel is blended using difference method
buffer.rect(x, y, 1, 1);
}
}
buffer.endDraw();
img.updatePixels();
limg.updatePixels();
canvas.beginDraw();
canvas.image(buffer, canvas.width/2, canvas.height/2);
canvas.endDraw();
}
float getChannel(color c, int channel) {
int ch = channel>5?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));
}
}
}
}

View File

@@ -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());

View File

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