Skip to content

Commit

Permalink
Implement non-blocking mechanisms
Browse files Browse the repository at this point in the history
fixes #26
  • Loading branch information
sarxos committed Feb 5, 2013
1 parent 0a2bb20 commit c5955bf
Show file tree
Hide file tree
Showing 36 changed files with 610 additions and 699 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String getName() {
}

@Override
public Dimension[] getSizes() {
public Dimension[] getResolutions() {

if (dimensions == null) {
dimensions = new ArrayList<Dimension>();
Expand Down Expand Up @@ -180,17 +180,22 @@ public void close() {
}

@Override
public Dimension getSize() {
public Dimension getResolution() {
return size;
}

@Override
public void setSize(Dimension d) {
public void setResolution(Dimension d) {
this.size = d;
}

@Override
public void dispose() {
disposed = true;
}

@Override
public boolean isOpen() {
return open;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public String getName() {
}

@Override
public Dimension[] getSizes() {
public Dimension[] getResolutions() {

if (sizes != null) {
return sizes;
Expand Down Expand Up @@ -268,15 +268,15 @@ protected void setSizes(Dimension[] sizes) {
}

@Override
public Dimension getSize() {
public Dimension getResolution() {
if (size == null) {
size = getSizes()[0];
size = getResolutions()[0];
}
return size;
}

@Override
public void setSize(Dimension size) {
public void setResolution(Dimension size) {
this.size = size;
}

Expand Down Expand Up @@ -441,4 +441,9 @@ public void setFailOnError(boolean failOnError) {
public void dispose() {
disposed = true;
}

@Override
public boolean isOpen() {
return open;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public X104S(String name, URL base) {
}

@Override
public Dimension[] getSizes() {
public Dimension[] getResolutions() {
return SIZES;
}

@Override
public void setSize(Dimension size) {
public void setResolution(Dimension size) {

int index = -1;
for (int i = 0; i < SIZES.length; i++) {
Expand All @@ -61,15 +61,15 @@ public void setSize(Dimension size) {
throw new IllegalArgumentException(String.format("Incorrect size %s", size));
}

super.setSize(size);
super.setResolution(size);
}

@Override
public URL getURL() {

int index = -1;
for (int i = 0; i < SIZES.length; i++) {
if (SIZES[i].equals(getSize())) {
if (SIZES[i].equals(getResolution())) {
index = i;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public B7210(String name, URL base) {
}

@Override
public Dimension[] getSizes() {
public Dimension[] getResolutions() {
return SIZES;
}

@Override
public void setSize(Dimension size) {
public void setResolution(Dimension size) {

int index = -1;
for (int i = 0; i < SIZES.length; i++) {
Expand All @@ -59,15 +59,15 @@ public void setSize(Dimension size) {
throw new IllegalArgumentException(String.format("Incorrect size %s", size));
}

super.setSize(size);
super.setResolution(size);
}

@Override
public URL getURL() {

int index = -1;
for (int i = 0; i < SIZES.length; i++) {
if (SIZES[i].equals(getSize())) {
if (SIZES[i].equals(getResolution())) {
index = i;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public F3201(String name, URL base) {
}

@Override
public Dimension[] getSizes() {
public Dimension[] getResolutions() {
return SIZES;
}

@Override
public void setSize(Dimension size) {
public void setResolution(Dimension size) {

int index = -1;
for (int i = 0; i < SIZES.length; i++) {
Expand All @@ -59,15 +59,15 @@ public void setSize(Dimension size) {
throw new IllegalArgumentException(String.format("Incorrect size %s", size));
}

super.setSize(size);
super.setResolution(size);
}

@Override
public URL getURL() {

int index = -1;
for (int i = 0; i < SIZES.length; i++) {
if (SIZES[i].equals(getSize())) {
if (SIZES[i].equals(getResolution())) {
index = i;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ public String getName() {
}

@Override
public Dimension[] getSizes() {
public Dimension[] getResolutions() {
throw new WebcamException("Not implemented");
}

@Override
public Dimension getSize() {
public Dimension getResolution() {
throw new WebcamException("Not implemented");
}

@Override
public void setSize(Dimension size) {
public void setResolution(Dimension size) {
throw new WebcamException("Not implemented");
}

Expand Down Expand Up @@ -116,4 +116,9 @@ public void close() {
public void dispose() {
disposed = true;
}

@Override
public boolean isOpen() {
return open;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private VideoFormat getLargestVideoFormat() {
}

@Override
public Dimension[] getSizes() {
public Dimension[] getResolutions() {

if (dimensions == null) {
dimensions = new ArrayList<Dimension>();
Expand Down Expand Up @@ -267,12 +267,12 @@ public int compare(Dimension a, Dimension b) {
}

@Override
public Dimension getSize() {
public Dimension getResolution() {
return dimension;
}

@Override
public void setSize(Dimension size) {
public void setResolution(Dimension size) {
this.dimension = size;
}

Expand Down Expand Up @@ -387,4 +387,9 @@ public void dispose() {
disposed = true;
}

@Override
public boolean isOpen() {
return open;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ public String getName() {
}

@Override
public Dimension[] getSizes() {
public Dimension[] getResolutions() {
return DIMENSIONS;
}

@Override
public Dimension getSize() {
public Dimension getResolution() {
return size;
}

@Override
public void setSize(Dimension size) {
public void setResolution(Dimension size) {
if (open) {
throw new RuntimeException("Cannot set new size when device is open, please close it first");
}
Expand Down Expand Up @@ -129,4 +129,9 @@ public void close() {
public void dispose() {
disposed = true;
}

@Override
public boolean isOpen() {
return open;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ public String getName() {
}

@Override
public Dimension[] getSizes() {
public Dimension[] getResolutions() {
return DIMENSIONS;
}

@Override
public Dimension getSize() {
public Dimension getResolution() {
return size;
}

@Override
public void setSize(Dimension size) {
public void setResolution(Dimension size) {
this.size = size;
}

Expand Down Expand Up @@ -199,4 +199,9 @@ public synchronized void close() {
public synchronized void dispose() {
disposed = true;
}

@Override
public boolean isOpen() {
return open;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

import java.io.IOException;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamMotionDetector;
import com.github.sarxos.webcam.WebcamMotionEvent;
import com.github.sarxos.webcam.WebcamMotionListener;


/**
* Detect motion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
public class TakePictureExample {

public static void main(String[] args) throws IOException {

// automatically open if webcam is closed
Webcam.setAutoOpenMode(true);

// get image
BufferedImage image = Webcam.getDefault().getImage();

// save image to PNG file
ImageIO.write(image, "PNG", new File("test.png"));
}
}
2 changes: 1 addition & 1 deletion webcam-capture/src/example/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
<root level="trace">
<root level="warn">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Loading

0 comments on commit c5955bf

Please sign in to comment.