Skip to content

Commit abaf107

Browse files
committed
Add BufferAccess interface to IpCamDevice, refs #607
1 parent 12c3f55 commit abaf107

File tree

1 file changed

+31
-1
lines changed
  • webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam

1 file changed

+31
-1
lines changed

webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDevice.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.net.URI;
1010
import java.net.URISyntaxException;
1111
import java.net.URL;
12+
import java.nio.ByteBuffer;
1213

1314
import javax.imageio.ImageIO;
1415

@@ -34,17 +35,19 @@
3435
import org.slf4j.LoggerFactory;
3536

3637
import com.github.sarxos.webcam.WebcamDevice;
38+
import com.github.sarxos.webcam.WebcamDevice.BufferAccess;
3739
import com.github.sarxos.webcam.WebcamDevice.FPSSource;
3840
import com.github.sarxos.webcam.WebcamException;
3941
import com.github.sarxos.webcam.ds.ipcam.impl.IpCamMJPEGStream;
42+
import com.github.sarxos.webcam.util.ImageUtils;
4043

4144

4245
/**
4346
* IP camera device.
4447
*
4548
* @author Bartosz Firyn (sarxos)
4649
*/
47-
public class IpCamDevice implements WebcamDevice, FPSSource {
50+
public class IpCamDevice implements WebcamDevice, FPSSource, BufferAccess {
4851

4952
/**
5053
* Logger.
@@ -431,4 +434,31 @@ public boolean isOpen() {
431434
public double getFPS() {
432435
return reader.getFPS();
433436
}
437+
438+
/**
439+
* Return image RGB data in form of {@link ByteBuffer}. Please note that {@link ByteBuffer}
440+
* returned by this method does not contain original JPEG data bytes, but bytes representing RGB
441+
* data of the image constructed from JPEG data.
442+
*/
443+
@Override
444+
public synchronized ByteBuffer getImageBytes() {
445+
final BufferedImage bi = getImage();
446+
if (bi == null) {
447+
return null;
448+
}
449+
return ByteBuffer.wrap(ImageUtils.imageToBytes(bi));
450+
}
451+
452+
/**
453+
* Put image RGB data into the {@link ByteBuffer}. Please note that data from {@link ByteBuffer}
454+
* consumed by this method does not contain original JPEG data bytes, but bytes representing RGB
455+
* data of the image constructed from JPEG data.
456+
*/
457+
@Override
458+
public void getImageBytes(ByteBuffer buffer) {
459+
final BufferedImage bi = getImage();
460+
if (bi != null) {
461+
buffer.put(ImageUtils.imageToBytes(bi));
462+
}
463+
}
434464
}

0 commit comments

Comments
 (0)