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