Skip to content

Commit

Permalink
Start working on SWT composite, refs #91
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed May 7, 2013
1 parent 73e6ad8 commit 2915081
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<modules>
<module>webcam-capture</module>
<module>webcam-capture-addons</module>
<module>webcam-capture-drivers</module>
<module>webcam-capture-examples</module>
<module>webcam-capture-pages</module>
Expand Down
17 changes: 17 additions & 0 deletions webcam-capture-addons/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>webcam-capture-addons</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
41 changes: 41 additions & 0 deletions webcam-capture-addons/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-parent</artifactId>
<version>0.3.10-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-addons</artifactId>
<packaging>pom</packaging>

<name>Webcam Capture Addons</name>
<description>Parent POM for Webcam Capture addons set</description>

<modules>
<module>webcam-capture-addon-swt</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

</project>
26 changes: 26 additions & 0 deletions webcam-capture-addons/webcam-capture-addon-swt/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions webcam-capture-addons/webcam-capture-addon-swt/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>webcam-capture-addon-swt</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
73 changes: 73 additions & 0 deletions webcam-capture-addons/webcam-capture-addon-swt/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-addons</artifactId>
<version>0.3.10-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-addon-swt</artifactId>
<packaging>jar</packaging>

<name>Webcam Capture - SWT Addon</name>
<description>SWT addon for Webcam Capture</description>

<profiles>
<profile>
<id>mac</id>
<activation>
<os>
<name>mac os x</name>
</os>
</activation>
<properties>
<swt.artifactId>org.eclipse.swt.cocoa.macosx.x86_64</swt.artifactId>
</properties>
</profile>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<swt.artifactId>org.eclipse.swt.win32.win32.x86_64</swt.artifactId>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<os>
<family>linux</family>
</os>
</activation>
<properties>
<swt.artifactId>org.eclipse.swt.gtk.linux.x86_64</swt.artifactId>
</properties>
</profile>
</profiles>

<repositories>
<repository>
<id>swt-repo</id>
<url>https://swt-repo.googlecode.com/svn/repo/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>${swt.artifactId}</artifactId>
<version>4.2.1</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.github.sarxos.webcam.addon.swt;

import java.awt.image.BufferedImage;
import java.awt.image.DirectColorModel;
import java.awt.image.WritableRaster;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.github.sarxos.webcam.Webcam;


public class WebcamComposite extends Composite {

private Display display = null;
private Webcam webcam = null;
private Image image = null;

public WebcamComposite(Display display, Composite parent, int style) {
super(parent, style);
// setLayout(new FillLayout(SWT.HORIZONTAL));
this.display = display;
}

public void setWebcam(Webcam webcam) {
if (webcam == null) {
throw new IllegalArgumentException("Webcam cannot be null");
}
this.webcam = webcam;
}

public ImageData getImageData() {

BufferedImage image = webcam.getImage();

DirectColorModel model = (DirectColorModel) image.getColorModel();
PaletteData palette = new PaletteData(model.getRedMask(), model.getGreenMask(), model.getBlueMask());
ImageData data = new ImageData(image.getWidth(), image.getHeight(), model.getPixelSize(), palette);
WritableRaster raster = image.getRaster();

int[] pixelArray = new int[3];

for (int y = 0; y < data.height; y++) {
for (int x = 0; x < data.width; x++) {
raster.getPixel(x, y, pixelArray);
int pixel = palette.getPixel(new RGB(pixelArray[0], pixelArray[1], pixelArray[2]));
data.setPixel(x, y, pixel);
}
}

return data;
}

@Override
public void dispose() {
if (image != null) {
image.dispose();
}
super.dispose();
}

@Override
public void update() {

Image tmp = image;
try {
image = new Image(display, getImageData());
} finally {
if (tmp != null) {
tmp.dispose();
}
}
}

public static void main(String[] args) {

Display display = new Display();
Shell shell = new Shell(display);

shell.setLayout(new FillLayout(SWT.HORIZONTAL));
shell.setText("Test");
shell.setSize(640, 480);

WebcamComposite wc = new WebcamComposite(display, shell, SWT.EMBEDDED);
wc.setWebcam(Webcam.getDefault());

shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
System.out.println("uuu");
display.sleep();
}
}

System.out.println("pp");

wc.dispose();
display.dispose();
}
}

0 comments on commit 2915081

Please sign in to comment.