Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Added the video library.
Browse files Browse the repository at this point in the history
Many thanks to Stefan for the initial version!
  • Loading branch information
Frederik De Bleser committed Oct 27, 2010
1 parent 4ad7c80 commit 1b0b573
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/res/configuration/config.ini
@@ -1,2 +1,2 @@
osgi.bundles=nodebox-core.jar@start,mvel2.jar@start,nodebox-builtins.jar@start,nodebox-graphics.jar@start,nodebox-app.jar@start
osgi.bundles=nodebox-core.jar@start,mvel2.jar@start,nodebox-builtins.jar@start,nodebox-graphics.jar@start,nodebox-pixie.jar@start,nodebox-video.jar@start,nodebox-app.jar@start
eclipse.ignoreApp=true
4 changes: 4 additions & 0 deletions build.xml
Expand Up @@ -8,6 +8,7 @@
<property name="module.builtins" value="builtins"/>
<property name="module.graphics" value="graphics"/>
<property name="module.pixie" value="pixie"/>
<property name="module.video" value="video"/>
<property name="module.toxiclibscore" value="toxiclibscore"/>
<property name="module.app" value="app"/>
<property name="app.res.mac" value="app/platform/mac/res"/>
Expand All @@ -25,6 +26,7 @@
<ant dir="${module.builtins}" antfile="build.xml" target="dist"/>
<ant dir="${module.graphics}" antfile="build.xml" target="dist"/>
<ant dir="${module.pixie}" antfile="build.xml" target="dist"/>
<ant dir="${module.video}" antfile="build.xml" target="dist"/>
<!-- <ant dir="${module.toxiclibscore}" antfile="build.xml" target="dist"/> -->
<ant dir="${module.app}" antfile="build.xml" target="dist"/>
<mkdir dir="dist/configuration"/>
Expand All @@ -39,6 +41,7 @@
<ant dir="${module.builtins}" antfile="build.xml" target="clean"/>
<ant dir="${module.graphics}" antfile="build.xml" target="dist"/>
<ant dir="${module.pixie}" antfile="build.xml" target="dist"/>
<ant dir="${module.video}" antfile="build.xml" target="dist"/>
<ant dir="${module.toxiclibscore}" antfile="build.xml" target="clean"/>
<ant dir="${module.app}" antfile="build.xml" target="clean"/>
<delete dir="dist"/>
Expand All @@ -48,6 +51,7 @@
<java fork="true" dir="dist" classpath="dist/equinox.jar" classname="org.eclipse.core.runtime.adaptor.EclipseStarter">
<arg value="-console"/>
<arg value="-clean"/>
<jvmarg value="-d32"/>
</java>
</target>

Expand Down
9 changes: 8 additions & 1 deletion builtins/src/nodebox/builtins/image/LoadImage.java
@@ -1,6 +1,7 @@
package nodebox.builtins.image;

import nodebox.node.*;
import processing.core.PGraphics;
import processing.core.PImage;

@Description("Load an image from disk.")
Expand All @@ -10,7 +11,7 @@ public class LoadImage extends Node {
private PImage loadedImage;

public final StringPort pFileName = new StringPort(this, "fileName", Port.Direction.INPUT);
public final ImagePort pImage = new ImagePort(this, "image", Port.Direction.OUTPUT);
public final ImagePort pImage = new ImagePort(this, "output", Port.Direction.OUTPUT);


@Override
Expand All @@ -22,4 +23,10 @@ public void execute(Context context, float time) {
}
pImage.set(loadedImage);
}

@Override
public void draw(PGraphics g, Context context, float time) {
g.image(pImage.get(), 0, 0);
}

}
Binary file added lib/processing-video.jar
Binary file not shown.
32 changes: 24 additions & 8 deletions pixie/src/nodebox/pixie/ImageNode.java
@@ -1,11 +1,27 @@
package nodebox.pixie;

/**
* Created by IntelliJ IDEA.
* User: fdb
* Date: Oct 27, 2010
* Time: 12:36:18 PM
* To change this template use File | Settings | File Templates.
*/
public class ImageNode {
import nodebox.node.Context;
import nodebox.node.ImagePort;
import nodebox.node.Node;
import nodebox.node.Port;
import processing.core.PGraphics;
import processing.core.PImage;

public abstract class ImageNode extends Node {

public final ImagePort pOutput = new ImagePort(this, "output", Port.Direction.OUTPUT);

@Override
public void execute(Context context, float time) {
PImage image = cook(context, time);
pOutput.set(image);
}

@Override
public void draw(PGraphics g, Context context, float time) {
g.image(pOutput.get(), 0, 0);
}

public abstract PImage cook(Context context, float time);

}
10 changes: 4 additions & 6 deletions pixie/src/nodebox/pixie/PointFilter.java
Expand Up @@ -8,16 +8,14 @@
import processing.core.PGraphics;
import processing.core.PImage;

public abstract class PointFilter extends Node {
public abstract class PointFilter extends ImageNode {

public final ImagePort pImage = new ImagePort(this, "image", Port.Direction.INPUT);
public final ImagePort pOutput = new ImagePort(this, "output", Port.Direction.OUTPUT);


@Override
public void execute(Context context, float time) {
public PImage cook(Context context, float time) {
PImage in = pImage.get();
if (in == null) return;
if (in == null) return null;
in.loadPixels();
PImage out = context.getApplet().createImage(in.width, in.height, PConstants.RGB);
out.loadPixels();
Expand All @@ -32,7 +30,7 @@ public void execute(Context context, float time) {
}
}
out.updatePixels();
pOutput.set(out);
return out;
}

@Override
Expand Down
11 changes: 0 additions & 11 deletions pixie/src/nodebox/pixie/Video.java

This file was deleted.

39 changes: 39 additions & 0 deletions video/build.xml
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="NodeBox Pixie" default="dist">

<property name="src" value="src"/>
<property name="lib" value="../lib"/>
<property name="build" value="build"/>
<property name="dist" value="../dist"/>

<path id="build.classpath">
<path path="${dist}/nodebox-core.jar"/>
<path path="${lib}/processing-core.jar"/>
<path path="${lib}/processing-video.jar"/>
<path path="${lib}/equinox.jar"/>
</path>

<target name="init">
<mkdir dir="${build}"/>
</target>

<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${build}" classpathref="build.classpath" source="1.5" target="1.5"/>
</target>

<target name="embed-dependencies" depends="init">
<copy file="/System/Library/Java/Extensions/QTJava.zip" todir="${build}"/>
<copy file="${lib}/processing-video.jar" todir="${build}"/>
</target>

<target name="dist" depends="compile,embed-dependencies">
<mkdir dir="${dist}"/>
<jar jarfile="${dist}/nodebox-video.jar" basedir="${build}" manifest="manifest.mf"/>
</target>

<target name="clean">
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>

</project>
8 changes: 8 additions & 0 deletions video/manifest.mf
@@ -0,0 +1,8 @@
Manifest-Version: 1
Bundle-ManifestVersion: 2
Bundle-SymbolicName: nodebox.video
Bundle-Name: Node-Video
Bundle-Version: 1.0.0
Bundle-Activator: nodebox.video.VideoActivator
Bundle-ClassPath: .,QTJava.zip,processing-video.jar
Import-Package: org.osgi.framework, processing.core, nodebox.node, nodebox.util, javax.swing
45 changes: 45 additions & 0 deletions video/src/nodebox/video/Capture.java
@@ -0,0 +1,45 @@
package nodebox.video;

import nodebox.node.*;
import processing.core.PGraphics;

@Description("Captures video images.")
public class Capture extends Node {

private static final int CAPTURE_WIDTH = 320;
private static final int CAPTURE_HEIGHT = 240;
private static final int CAPTURE_FRAME_RATE = 30;

public final ImagePort pOutput = new ImagePort(this, "output", Port.Direction.OUTPUT);
private processing.video.Capture capture;

@Override
public void activate() {
// TODO: Capture should be initialized here, but activate/deactivate are run in a different thread,
// causing a race condition.
}

@Override
public void execute(Context context, float time) {
if (capture == null) {
capture = new processing.video.Capture(getScene().getApplet(), CAPTURE_WIDTH, CAPTURE_HEIGHT, CAPTURE_FRAME_RATE);
}
if (capture.available()) {
capture.read();
}
pOutput.set(capture.get());
}

@Override
public void draw(PGraphics g, Context context, float time) {
g.image(pOutput.get(), 0, 0);
}

@Override
public void deactivate() {
capture.stop();
capture.dispose();
capture = null;
}

}
25 changes: 25 additions & 0 deletions video/src/nodebox/video/VideoActivator.java
@@ -0,0 +1,25 @@
package nodebox.video;

import nodebox.node.NodeManager;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public class VideoActivator implements BundleActivator {

public void start(BundleContext context) throws Exception {
NodeManager m = getNodeManager(context);
m.registerNodeClass(Capture.class, "Video");
}

public void stop(BundleContext context) throws Exception {
NodeManager m = getNodeManager(context);
m.unregisterNodeClass(Capture.class);
}

private NodeManager getNodeManager(BundleContext context) {
ServiceReference ref = context.getServiceReference(NodeManager.class.getName());
return (NodeManager) context.getService(ref);
}

}

0 comments on commit 1b0b573

Please sign in to comment.