diff --git a/pom.xml b/pom.xml index 306d423c..28f0d48c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.sarxos webcam-capture-parent - 0.3.2 + 0.3.4 pom Webcam Capture - Root POM @@ -153,52 +153,6 @@ 1.6 - - org.apache.maven.plugins - maven-source-plugin - 2.1.2 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.8.1 - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-dependency-plugin - 2.4 - - - copy-dependencies - prepare-package - - copy-dependencies - - - ${project.build.directory}/dependencies - false - false - true - - - - diff --git a/webcam-capture-driver-civil/pom.xml b/webcam-capture-driver-civil/pom.xml index f608c0c8..15f185f3 100644 --- a/webcam-capture-driver-civil/pom.xml +++ b/webcam-capture-driver-civil/pom.xml @@ -5,7 +5,7 @@ com.github.sarxos webcam-capture-parent - 0.3.2 + 0.3.4 webcam-capture-driver-civil diff --git a/webcam-capture-driver-jmf/pom.xml b/webcam-capture-driver-jmf/pom.xml index ad2feb8a..d8003680 100644 --- a/webcam-capture-driver-jmf/pom.xml +++ b/webcam-capture-driver-jmf/pom.xml @@ -5,7 +5,7 @@ com.github.sarxos webcam-capture-parent - 0.3.2 + 0.3.4 webcam-capture-driver-jmf diff --git a/webcam-capture-driver-openimaj/pom.xml b/webcam-capture-driver-openimaj/pom.xml index f9a8a534..895b3f1e 100644 --- a/webcam-capture-driver-openimaj/pom.xml +++ b/webcam-capture-driver-openimaj/pom.xml @@ -5,7 +5,7 @@ com.github.sarxos webcam-capture-parent - 0.3.2 + 0.3.4 webcam-capture-driver-openimaj diff --git a/webcam-capture/.classpath b/webcam-capture/.classpath index f8342b55..458d921d 100644 --- a/webcam-capture/.classpath +++ b/webcam-capture/.classpath @@ -1,9 +1,10 @@ - + + diff --git a/webcam-capture/pom.xml b/webcam-capture/pom.xml index 26af9a92..c1fd4218 100644 --- a/webcam-capture/pom.xml +++ b/webcam-capture/pom.xml @@ -29,7 +29,7 @@ MIT License http://www.opensource.org/licenses/mit-license.html - repo + repo,manual @@ -47,15 +47,29 @@ - GitHub + GitHub Issues Manager https://github.com/sarxos/webcam-capture/issues + + Travis CI + http://travis-ci.org/#!/sarxos/webcam-capture + + sarxos Bartosz Firyn bartoszfiryn@gmail.com + + Project Manager + Architect + Developer + + http://me.sarxos.pl/ + Bartosz Firyn (SarXos) + https://github.com/sarxos + +1 @@ -80,6 +94,12 @@ logback-classic 0.9.18 + + junit + junit + 4.10 + test + @@ -285,17 +305,41 @@ cam,webcam,camera,spycam,capture + + org.apache.maven.plugins + maven-jxr-plugin + 2.1 + + true + true + + org.codehaus.mojo taglist-maven-plugin 2.4 - - TODO - @todo - FIXME - XXX - + + + + Todos + + + TODO + exact + + + FIXME + exact + + + XXX + exact + + + + + true @@ -321,15 +365,6 @@ com.github.sarxos.webcam - - org.apache.maven.plugins - maven-jxr-plugin - 2.1 - - true - true - - org.apache.maven.plugins maven-pmd-plugin diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java index 3648a8b0..e1c29e4d 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java @@ -4,6 +4,7 @@ import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.slf4j.Logger; @@ -228,7 +229,8 @@ public static List getWebcams() { } } } - return webcams; + + return Collections.unmodifiableList(webcams); } /** diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/DefaultDevice.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/DefaultDevice.java index a68e82d9..6b7355f9 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/DefaultDevice.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/DefaultDevice.java @@ -93,8 +93,11 @@ public BufferedImage getImage() { DataBufferByte buffer = new DataBufferByte(data, bytes.length, OFFSET); WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null); + BufferedImage bi = new BufferedImage(colorModel, raster, false, null); - return new BufferedImage(colorModel, raster, false, null); + bi.flush(); + + return bi; } @Override diff --git a/webcam-capture/src/test/java/com/github/sarxos/webcam/WebcamTest.java b/webcam-capture/src/test/java/com/github/sarxos/webcam/WebcamTest.java new file mode 100644 index 00000000..be4610b1 --- /dev/null +++ b/webcam-capture/src/test/java/com/github/sarxos/webcam/WebcamTest.java @@ -0,0 +1,37 @@ +package com.github.sarxos.webcam; + +import java.util.List; + +import junit.framework.Assert; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.github.sarxos.webcam.ds.test.DummyDriver; + + +/** + * @author bfiryn + */ +public class WebcamTest { + + @BeforeClass + public static void setUp() { + Webcam.setDriver(DummyDriver.class); + } + + @Test + public void test_getDevices() { + + List webcams = Webcam.getWebcams(); + List devices = DummyDriver.getInstance().getDevices(); + + Assert.assertEquals(devices.size(), webcams.size()); + } + + // @Test + // public void test_setDriver() { + // + // } + +} diff --git a/webcam-capture/src/test/java/com/github/sarxos/webcam/ds/test/DummyDevice.java b/webcam-capture/src/test/java/com/github/sarxos/webcam/ds/test/DummyDevice.java new file mode 100644 index 00000000..39ee2c1d --- /dev/null +++ b/webcam-capture/src/test/java/com/github/sarxos/webcam/ds/test/DummyDevice.java @@ -0,0 +1,77 @@ +package com.github.sarxos.webcam.ds.test; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.util.concurrent.atomic.AtomicInteger; + +import com.github.sarxos.webcam.WebcamDevice; +import com.github.sarxos.webcam.WebcamException; + + +public class DummyDevice implements WebcamDevice { + + private static final AtomicInteger INSTANCE_NUM = new AtomicInteger(0); + private static final Dimension[] DIMENSIONS = new Dimension[] { + new Dimension(300, 200), + new Dimension(400, 300), + }; + + private String name = DummyDevice.class.getSimpleName() + "-" + INSTANCE_NUM.incrementAndGet(); + private Dimension size = DIMENSIONS[0]; + private boolean open = false; + + @Override + public String getName() { + return name; + } + + @Override + public Dimension[] getSizes() { + return DIMENSIONS; + } + + @Override + public Dimension getSize() { + return size; + } + + @Override + public void setSize(Dimension size) { + this.size = size; + } + + @Override + public BufferedImage getImage() { + + if (!open) { + throw new WebcamException("Not open"); + } + + BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); + Graphics2D g2 = bi.createGraphics(); + g2.setColor(Color.RED); + g2.fillRect(0, 0, size.width, size.height); + g2.drawString(getName(), 20, 20); + g2.dispose(); + bi.flush(); + + return bi; + } + + @Override + public void open() { + open = true; + } + + @Override + public void close() { + open = false; + } + + public boolean isOpen() { + return open; + } + +} diff --git a/webcam-capture/src/test/java/com/github/sarxos/webcam/ds/test/DummyDriver.java b/webcam-capture/src/test/java/com/github/sarxos/webcam/ds/test/DummyDriver.java new file mode 100644 index 00000000..fead1141 --- /dev/null +++ b/webcam-capture/src/test/java/com/github/sarxos/webcam/ds/test/DummyDriver.java @@ -0,0 +1,39 @@ +package com.github.sarxos.webcam.ds.test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import com.github.sarxos.webcam.WebcamDevice; +import com.github.sarxos.webcam.WebcamDriver; + + +public class DummyDriver implements WebcamDriver { + + private static final List DEVICES = new ArrayList(Arrays.asList(new WebcamDevice[] { + new DummyDevice(), + new DummyDevice(), + new DummyDevice(), + new DummyDevice(), + })); + + private static DummyDriver instance = null; + + public DummyDriver() throws InstantiationException { + if (instance == null) { + instance = this; + } else { + throw new InstantiationException("Cannot be constructed twice"); + } + } + + public static DummyDriver getInstance() { + return instance; + } + + @Override + public List getDevices() { + return DEVICES; + } + +}