Skip to content

Commit

Permalink
Switch to JDK7 and add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Sep 13, 2017
1 parent 233672f commit db8a4c5
Show file tree
Hide file tree
Showing 18 changed files with 345 additions and 75 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: java
jdk:
- openjdk6
# - openjdk6
# - oraclejdk7
# - oraclejdk8
# - openjdk7
- openjdk7

before_install:
- mvn install -DskipTests=true -e
Expand All @@ -12,7 +12,7 @@ script:
- mvn test -X

after_success:
- mvn clean cobertura:cobertura coveralls:cobertura -P ci
- mvn clean cobertura:cobertura coveralls:report -P ci

branches:
except:
Expand Down
16 changes: 13 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,20 @@
<id>ci</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<format>xml</format>
<maxmem>256m</maxmem>
<aggregate>true</aggregate>
</configuration>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>2.1.0</version>
<version>4.3.0</version>
</plugin>
</plugins>
</build>
Expand Down Expand Up @@ -206,8 +216,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
Expand Down
11 changes: 6 additions & 5 deletions webcam-capture-drivers/driver-gst1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
<name>Webcam Capture - GStreamer 1.x Driver</name>
<description>Webcam Capture driver using GStreamer 1.x framework to grab frames from camera devices</description>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>com.nativelibs4java</groupId>
<artifactId>bridj</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
Expand Down
8 changes: 0 additions & 8 deletions webcam-capture-examples/webcam-capture-applet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@
<build>
<finalName>applet</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
Expand Down
8 changes: 0 additions & 8 deletions webcam-capture-examples/webcam-capture-executable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand Down
9 changes: 0 additions & 9 deletions webcam-capture-examples/webcam-capture-javafx-fxml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@
<build>
<finalName>WebCamAppLauncher</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture</artifactId>
<version>0.3.10</version>
<version>0.3.11</version>
</dependency>
</dependencies>
</project>
14 changes: 0 additions & 14 deletions webcam-capture-examples/webcam-capture-qrcode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,4 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.github.sarxos.example2;

import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
Expand All @@ -18,6 +19,7 @@
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;


public class QrCapture extends JFrame implements Closeable {

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -52,9 +54,13 @@ public void windowClosing(WindowEvent e) {
pack();
setVisible(true);

final Thread daemon = new Thread(() -> {
while (isVisible()) {
read();
final Thread daemon = new Thread(new Runnable() {

@Override
public void run() {
while (isVisible()) {
read();
}
}
});
daemon.setDaemon(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.github.sarxos.example2;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;

Expand All @@ -7,6 +8,8 @@
import javax.swing.JFrame;
import javax.swing.JOptionPane;


@SuppressWarnings("serial")
public class WebcamQRCodeExample2 extends JFrame {

public WebcamQRCodeExample2() {
Expand All @@ -19,12 +22,16 @@ public WebcamQRCodeExample2() {

@Override
public void actionPerformed(ActionEvent e) {
final Thread thread = new Thread(() -> {
try (QrCapture qr = new QrCapture()) {
showMessage("QR code text is:\n" + qr.getResult() + "");
} catch (InterruptedException ex) {
ex.printStackTrace();
}
final Thread thread = new Thread(new Runnable() {

@Override
public void run() {
try (QrCapture qr = new QrCapture()) {
showMessage("QR code text is:\n" + qr.getResult() + "");
} catch (InterruptedException ex) {
ex.printStackTrace();
}
};
});
thread.setDaemon(true);
thread.start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.sarxos.webcam.util;

import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -81,4 +82,31 @@ public static BufferedImage readFromResource(String resource) {
}
}
}

public static BufferedImage createEmptyImage(final BufferedImage source) {
return new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_INT_RGB);
}

/**
* Clamp a value to the range 0..255
*/
public static int clamp(int c) {
if (c < 0) {
return 0;
}
if (c > 255) {
return 255;
}
return c;
}

/**
* Return image raster as bytes array.
*
* @param bi the {@link BufferedImage}
* @return The raster data as byte array
*/
public static byte[] imageToBytes(BufferedImage bi) {
return ((DataBufferByte) bi.getData().getDataBuffer()).getData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* A convenience class which implements those methods of BufferedImageOp which are rarely changed.
*/
public abstract class JHFilter implements BufferedImageOp, Cloneable {
public abstract class JHFilter implements BufferedImageOp {

@Override
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dstCM) {
Expand Down Expand Up @@ -64,8 +64,8 @@ public RenderingHints getRenderingHints() {
* @param image a BufferedImage object
* @param x the left edge of the pixel block
* @param y the right edge of the pixel block
* @param width the width of the pixel arry
* @param height the height of the pixel arry
* @param width the width of the pixel array
* @param height the height of the pixel array
* @param pixels the array to hold the returned pixels. May be null.
* @return the pixels
* @see #setRGB
Expand All @@ -85,8 +85,8 @@ public int[] getRGB(BufferedImage image, int x, int y, int width, int height, in
* @param image a BufferedImage object
* @param x the left edge of the pixel block
* @param y the right edge of the pixel block
* @param width the width of the pixel arry
* @param height the height of the pixel arry
* @param width the width of the pixel array
* @param height the height of the pixel array
* @param pixels the array of pixels to set
* @see #getRGB
*/
Expand All @@ -98,13 +98,4 @@ public void setRGB(BufferedImage image, int x, int y, int width, int height, int
image.setRGB(x, y, width, height, pixels, 0, width);
}
}

@Override
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public JHFlipFilter() {
* @param operation the filter operation
*/
public JHFlipFilter(int operation) {
this.operation = operation;
setOperation(operation);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.sarxos.webcam.util.jh;

import static com.github.sarxos.webcam.util.ImageUtils.clamp;

import java.awt.image.BufferedImage;


public class JHNormalizeFilter extends JHFilter {

@Override
public BufferedImage filter(BufferedImage src, BufferedImage dest) {

final int w = src.getWidth();
final int h = src.getHeight();

int c, a, r, g, b, i, max = 1;

for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {

c = src.getRGB(x, y);
a = clamp((c >> 24) & 0xff);
r = clamp((c >> 16) & 0xff);
g = clamp((c >> 8) & 0xff);
b = clamp(c & 0xff);
i = (a << 24) | (r << 16) | (g << 8) | b;

if (i > max) {
max = i;
}
}
}

for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
c = src.getRGB(x, y);
i = c * 256 / max;
dest.setRGB(x, y, i);
}
}

return dest;
}

}
Loading

3 comments on commit db8a4c5

@tinaket
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I want to create a desktop appliaction using Java wich can scan a Qrcode with a webcam.
I am only a beginer so please guide me step by step

@sarxos
Copy link
Owner Author

@sarxos sarxos commented on db8a4c5 May 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tinaket

Take a look at this video series for beginners by Genuine Coder:

https://github.com/sarxos/webcam-capture#youtube-tutorials

Take care!

@tinaket
Copy link

@tinaket tinaket commented on db8a4c5 May 23, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.