improvised new effect for double webcam support, will be merged into singular webcam effect eventually

This commit is contained in:
2024-08-24 15:19:14 +02:00
parent e94d5c54d2
commit 0599dfcfe2
3 changed files with 129 additions and 16 deletions

View File

@@ -1,25 +1,118 @@
/*
iPhone
*/
class IPHONE extends Shader {
boolean webcamRunning;
PImage img;
int rw, rh, x, y, w, h, croptop, cropbottom, cropleft, cropright, contrast, brightness, hue, saturation, camSelected, camSelectedPrev;
final int[] blends = {BLEND, ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN};
IPHONE() {
rw = canvas.width;
rh = canvas.height;
name = "Webcam";
println(Capture.list().length);
img = createImage(rw, rh, ARGB);
if (!webcamRunning) startWebcam();
//params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
params.add(new Param("x", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN, }));
params.add(new Param("y", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param("w", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param("h", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param("croptop", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param("cropbottom", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param("cropleft", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param("cropright", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param("contrast", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param("brightness", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param("hue", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param("saturation", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param("blend mode", INTVAL, 0, this.blends.length-1, new int[]{RANDOM }));
params.add(new Param("webcam", INTVAL, 0, Capture.list().length-1, new int[]{TRIANG, SINE, RAMPUPDOWN, }));
camSelected = (int)params.get(13).getValue();
camSelectedPrev = (int)params.get(13).getValue();
}
void startWebcam() {
String[] cameras = Capture.list();
println("Hi");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
//println(cameras);
cam2.start();
webcamRunning = true;
}
void stopWebcam() { //gets never called lmao
cam2.stop();
webcamRunning = false;
}
void apply() {
rw = canvas.width;
rh = canvas.height;
x = int(params.get(0).getValue()*rw);
y = int(params.get(1).getValue()*rh);
w = int(params.get(2).getValue()*(rw*2));
h = int(params.get(3).getValue()*(rh*2));
camSelected = (int)params.get(13).getValue();
/*
if (camSelected != camSelectedPrev) {
currentCam = camSelected;
camSelectedPrev = camSelected;
stopWebcam();
startWebcam();
//new Capture(this, 1920,1080, Capture.list()[camSelected]);
}*/
//params.get(13) //camera id
//if (cam.available()) img = cam.get();
img = iPhoneImg.get();
canvas.beginDraw();
canvas.image(img, x, y, w, h);
//for ( int i = 0, l = canvas.pixels.length; i<l; i++) {
//}
canvas.endDraw();
}
void getParams() {
}
}
/*
Webcam
*/
/*
boolean webcamRunning;
void startWebcam() {
String[] cameras = Capture.list();
println("Hi");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
//println(cameras);
cam.start();
webcamRunning = true;
}
void stopWebcam() {
cam.stop();
webcamRunning = false;
}
void startWebcam() {
String[] cameras = Capture.list();
println("Hi");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
//println(cameras);
cam.start();
webcamRunning = true;
}
void stopWebcam() {
cam.stop();
webcamRunning = false;
}
*/
class WEBCAM extends Shader {
boolean webcamRunning;
PImage img;
int rw, rh, x, y, w, h, croptop, cropbottom, cropleft, cropright, contrast, brightness, hue, saturation, camSelected, camSelectedPrev;
final int[] blends = {BLEND, ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN};
@@ -48,6 +141,24 @@ class WEBCAM extends Shader {
camSelected = (int)params.get(13).getValue();
camSelectedPrev = (int)params.get(13).getValue();
}
void startWebcam() {
String[] cameras = Capture.list();
println("Hi");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
//println(cameras);
cam.start();
webcamRunning = true;
}
void stopWebcam() { //gets never called lmao
cam.stop();
webcamRunning = false;
}
void apply() {
rw = canvas.width;
rh = canvas.height;
@@ -70,7 +181,7 @@ class WEBCAM extends Shader {
//params.get(13) //camera id
if (cam.available()) img = cam.get();
//if (cam.available()) img = cam.get();
img = webcamImg.get();
canvas.beginDraw();

View File

@@ -138,6 +138,7 @@ void setup() {
PImage webcamImg;
PImage iPhoneImg;
void captureEvent(Capture c) {
c.read();
//webcamImg = cam.get();
@@ -147,7 +148,7 @@ void captureEvent(Capture c) {
webcamImg = cam.get();
}
if (c == cam2) {
println("iphone img incoming");
iPhoneImg = cam2.get();
}
}

View File

@@ -1,6 +1,7 @@
String FX[] = {
"WEBCAM",
"MASK",
"IPHONE",
"ASDFPIXELSORT",
"DISTORTER",
"FM",