123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- class WZIP extends Shader {
-
-
- final float sqrt05 = sqrt(0.5);
-
- float[] raw, raw1, raw2, raw3;
- float[] in, w, out;
- float[] in1, in2, in3, out1, out2, out3;
- int n, n2, s;
- float scalingfactorin, scalingfactorout;
-
- PImage img;
- String sessionid;
-
-
-
- WZIP() {
-
- name = "fxWZIP";/*
- params.add(new Param ("scale", 0, 1000));
- params.add(new Param ("factor1", 0, 1));
- params.add(new Param ("factor2", 0, 1));
- params.add(new Param ("hsb", 2));
- params.add(new Param ("mode", 2));
- */
-
- sessionid = hex((int)random(0xffff), 4);
- img = createImage(renderer.width, renderer.height, ARGB);
- img = renderer.get(0, 0, renderer.width, renderer.height);
-
-
-
- // printOption();
- // printScale();
- }
-
- /*
- float inc1, inc2;
- void animate() {
- inc1+=.03;
- inc2+=.04;
- //gui.brickP5.getController("knobZero-"+str(brick)).setValue( map(sin(inc1), -1, 1, 0, 255));
- //gui.brickP5.getController("knobOne-"+str(brick)).setValue(map(cos(inc2), -1, 1, 0, 255));
- if (random(1) > .99) {
- for (int i = 0; i < params.size(); i++)
- params.get(i).randomize();
- }
- }
- */
- void apply() {
- // img = createImage(renderer.width, renderer.height, ARGB);
- img.resize(renderer.width, renderer.height);
- img = renderer.get(0, 0, renderer.width, renderer.height);
-
- s = img.width*img.height;
- raw = new float[s*3];
- raw1 = new float[s];
- raw2 = new float[s];
- raw3 = new float[s];
- renderer.beginDraw();
- renderer.background(0);
- renderer.noStroke();
- if (boolean((int)params.get(3).value)) {
- renderer.colorMode(HSB, 255);
- colorMode(HSB, 255);
- } else {
- renderer.colorMode(RGB, 255);
- colorMode(RGB, 255);
- }
-
- scalingfactorin = map(params.get(1).value, 0, 1, 0, params.get(0).value);
- scalingfactorout = map(params.get(2).value, 0, 1, 0, params.get(0).value);
- int iter=0;
- int iter2 = 0;
- for (int y=0; y<img.height; y++) {
- for (int x=0; x<img.width; x++) {
- color c = img.get(x, y);
- float r, g, b;
- if (boolean((int)params.get(3).value)) {
- r = hue(c)>127?hue(c)-256:hue(c);
- g = saturation(c)>127?saturation(c)-256:saturation(c);
- b = brightness(c)>127?brightness(c)-256:brightness(c);
- } else {
- r = red(c)>127?red(c)-256:red(c);
- g = green(c)>127?green(c)-256:green(c);
- b = blue(c)>127?blue(c)-256:blue(c);
- }
- raw[iter++] = r;
- raw[iter++] = g;
- raw[iter++] = b;
- raw1[iter2] = r;
- raw2[iter2] = g;
- raw3[iter2] = b;
- iter2++;
- }
- }
-
- n = (int)pow(2, ceil(log(s*3)/log(2)));
- n2 = (int)pow(2, ceil(log(s)/log(2)));
-
- in = new float[n];
- w = new float[n];
- out = new float[n];
- out1 = new float[n2];
- out2 = new float[n2];
- out3 = new float[n2];
- in1 = new float[n2];
- in2 = new float[n2];
- in3 = new float[n2];
-
- arrayCopy(raw, 0, in, 0, raw.length);
- for (int i=raw.length; i<n; i++) in[i] = raw[raw.length-1];
-
- arrayCopy(raw1, 0, in1, 0, s);
- arrayCopy(raw2, 0, in2, 0, s);
- arrayCopy(raw3, 0, in3, 0, s);
-
- for (int i=s; i<n2; i++) {
- in1[i] = raw1[s-1];
- in2[i] = raw2[s-1];
- in3[i] = raw3[s-1];
- }
- if (boolean((int)params.get(4).value)) option1();
- else option2();
- renderer.colorMode(RGB);
- colorMode(RGB);
- renderer.endDraw();
- }
- // void printOption() {
- // String str1, str2;
- // if (do_hsb) {
- // str1 = "HSBHSBHSB...";
- // str2 = "HHH...SSS...BBB...";
- // } else {
- // str1 = "RGBRGBRGB...";
- // str2 = "RRR...GGG...BBB...";
- // }
- // if (option1) println("channels combined: " + str1);
- // else println("channels separated: " + str2);
- // }
- //
- // void printScale() {
- // println("Scale: 0.."+sc);
- // }
-
- float clamp(float c) {
- return(abs(c<0?256+c:c)%255.0);
- }
- void option2() {
- wtrafo(in1, n2);
- wbtrafo(out1, n2);
-
- wtrafo(in2, n2);
- wbtrafo(out2, n2);
-
- wtrafo(in3, n2);
- wbtrafo(out3, n2);
-
- for (int i=0; i<s; i++) {
- float r = clamp(out1[i]);
- float g = clamp(out2[i]);
- float b = clamp(out3[i]);
- renderer.fill(r, g, b);
- renderer.rect(i%img.width, i/img.width, 1, 1);
- }
- }
- void option1() {
- wtrafo(in, n);
- wbtrafo(out, n);
-
- float r=0, g=0, b=0;
- int state = 0;
-
- for (int i=0; i<raw.length; i++) {
- float c = clamp(out[i]);
- switch(state) {
- case 0:
- r = c;
- break;
- case 1:
- g = c;
- break;
- case 2:
- b = c;
- break;
- default:
- {
- r = c;
- renderer.fill(r, g, b);
- renderer.rect(floor(i/3.0)%img.width, floor(i/3.0)/img.width, 1, 1);
- state = 0;
- }
- }
- state++;
- }
- }
-
-
-
-
- void wbtrafo(float[] y, int n) {
- float[] d = new float[n];
- d[n-2] = w[n-1];
- int b1 = n-4;
- int b2 = n-2;
- int a=1;
- while (a<n/2) {
- for (int i=0; i<a; i++) {
- d[2*i+b1]=(d[i+b2]+w[i+b2])*sqrt05;
- d[2*i+1+b1]=(d[i+b2]-w[i+b2])*sqrt05;
- }
- b2=b1;
- b1=b1-4*a;
- a*=2;
- }
-
- for (int i=0; i<a; i++) {
- y[2*i]=(d[i]+w[i])*sqrt05;
- y[2*i+1]=(d[i]-w[i])*sqrt05;
- }
-
- for (int i=0; i<n; i++) y[i] *= scalingfactorout;
- }
-
- void wtrafo(float[] y, int n) {
- float[] d = new float[n];
- int a = n/2;
- for (int i=0; i<a; i++) {
- w[i] = (y[2*i]-y[2*i+1])*sqrt05;
- d[i] = (y[2*i]+y[2*i+1])*sqrt05;
- }
- int b1 = 0;
- int b2 = a;
- a/=2;
- while (a>0) {
- for (int i=0; i<a; i++) {
- w[i+b2]=(d[2*i+b1]-d[2*i+1+b1])*sqrt05;
- d[i+b2]=(d[2*i+b1]+d[2*i+1+b1])*sqrt05;
- }
- b1=b2;
- b2=b2+a;
- a/=2;
- }
- w[b2] = d[b1];
-
- for (int i=0; i<n-1; i++) w[i] = (int)(w[i]/scalingfactorin);
- if (w[n-1]>0) w[n-1] = (int)(w[n-1]/scalingfactorin+0.5);
- else w[n-1] = (int)(w[n-1]/scalingfactorin-0.5);
- }
- }
|