Skip to content

Commit 9d87a9e

Browse files
committed
Add openStream method to create a capture stream
1 parent 72a34fc commit 9d87a9e

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/main/java/io/github/doblon8/openpnp/capture/CaptureDevice.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ public CaptureDevice(CaptureContext context, int deviceId) {
2626
.toList();
2727
}
2828

29+
/**
30+
* Open a capture stream to a device with specific format requirements
31+
* <p>
32+
* Although the (internal) frame buffer format is set via the fourCC ID,
33+
* the frames returned by Cap_captureFrame are always 24-bit RGB.
34+
*
35+
* @param format the format requirements for the capture stream. The format must be supported by the device,
36+
* i.e. it must be in the list of formats returned by getFormats().
37+
* @return a capture stream to the device with the given format requirements.
38+
*/
39+
public CaptureStream openStream(CaptureFormat format) {
40+
int streamId = Cap_openStream(context.getSegment(), id, format.id());
41+
if (streamId == -1) {
42+
throw new CaptureException("Error opening capture stream: " + streamId);
43+
}
44+
return new CaptureStream(context, streamId);
45+
}
46+
2947
/**
3048
* Get the name of a capture device.
3149
*

0 commit comments

Comments
 (0)