Skip to content

Commit

Permalink
Add BufferAccess interface to IpCamDevice, refs #607
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jan 15, 2018
1 parent 12c3f55 commit abaf107
Showing 1 changed file with 31 additions and 1 deletion.
Expand Up @@ -9,6 +9,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.ByteBuffer;

import javax.imageio.ImageIO;

Expand All @@ -34,17 +35,19 @@
import org.slf4j.LoggerFactory;

import com.github.sarxos.webcam.WebcamDevice;
import com.github.sarxos.webcam.WebcamDevice.BufferAccess;
import com.github.sarxos.webcam.WebcamDevice.FPSSource;
import com.github.sarxos.webcam.WebcamException;
import com.github.sarxos.webcam.ds.ipcam.impl.IpCamMJPEGStream;
import com.github.sarxos.webcam.util.ImageUtils;


/**
* IP camera device.
*
* @author Bartosz Firyn (sarxos)
*/
public class IpCamDevice implements WebcamDevice, FPSSource {
public class IpCamDevice implements WebcamDevice, FPSSource, BufferAccess {

/**
* Logger.
Expand Down Expand Up @@ -431,4 +434,31 @@ public boolean isOpen() {
public double getFPS() {
return reader.getFPS();
}

/**
* Return image RGB data in form of {@link ByteBuffer}. Please note that {@link ByteBuffer}
* returned by this method does not contain original JPEG data bytes, but bytes representing RGB
* data of the image constructed from JPEG data.
*/
@Override
public synchronized ByteBuffer getImageBytes() {
final BufferedImage bi = getImage();
if (bi == null) {
return null;
}
return ByteBuffer.wrap(ImageUtils.imageToBytes(bi));
}

/**
* Put image RGB data into the {@link ByteBuffer}. Please note that data from {@link ByteBuffer}
* consumed by this method does not contain original JPEG data bytes, but bytes representing RGB
* data of the image constructed from JPEG data.
*/
@Override
public void getImageBytes(ByteBuffer buffer) {
final BufferedImage bi = getImage();
if (bi != null) {
buffer.put(ImageUtils.imageToBytes(bi));
}
}
}

0 comments on commit abaf107

Please sign in to comment.