|
9 | 9 | import java.net.URI; |
10 | 10 | import java.net.URISyntaxException; |
11 | 11 | import java.net.URL; |
| 12 | +import java.nio.ByteBuffer; |
12 | 13 |
|
13 | 14 | import javax.imageio.ImageIO; |
14 | 15 |
|
|
34 | 35 | import org.slf4j.LoggerFactory; |
35 | 36 |
|
36 | 37 | import com.github.sarxos.webcam.WebcamDevice; |
| 38 | +import com.github.sarxos.webcam.WebcamDevice.BufferAccess; |
37 | 39 | import com.github.sarxos.webcam.WebcamDevice.FPSSource; |
38 | 40 | import com.github.sarxos.webcam.WebcamException; |
39 | 41 | import com.github.sarxos.webcam.ds.ipcam.impl.IpCamMJPEGStream; |
| 42 | +import com.github.sarxos.webcam.util.ImageUtils; |
40 | 43 |
|
41 | 44 |
|
42 | 45 | /** |
43 | 46 | * IP camera device. |
44 | 47 | * |
45 | 48 | * @author Bartosz Firyn (sarxos) |
46 | 49 | */ |
47 | | -public class IpCamDevice implements WebcamDevice, FPSSource { |
| 50 | +public class IpCamDevice implements WebcamDevice, FPSSource, BufferAccess { |
48 | 51 |
|
49 | 52 | /** |
50 | 53 | * Logger. |
@@ -431,4 +434,31 @@ public boolean isOpen() { |
431 | 434 | public double getFPS() { |
432 | 435 | return reader.getFPS(); |
433 | 436 | } |
| 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 | + } |
434 | 464 | } |
0 commit comments