Skip to content

Commit 5f618e6

Browse files
committed
Add getPropertyLimits to retrieve property limits
1 parent 2579aba commit 5f618e6

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.github.doblon8.openpnp.capture;
2+
3+
public enum CaptureProperty
4+
{
5+
EXPOSURE(1),
6+
FOCUS(2),
7+
ZOOM(3),
8+
WHITE_BALANCE(4),
9+
GAIN(5),
10+
BRIGHTNESS(6),
11+
CONTRAST(7),
12+
SATURATION(8),
13+
GAMMA(9),
14+
HUE(10),
15+
SHARPNESS(11),
16+
BACK_LIGHT_COMPENSATION(12),
17+
POWER_LINE_FREQUENCY(13),
18+
LAST(14),
19+
;
20+
21+
private final int value;
22+
CaptureProperty(int value) {
23+
this.value = value;
24+
}
25+
26+
public int value() {
27+
return value;
28+
}
29+
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,34 @@ public int getStreamFrameCount() {
7373
return Cap_getStreamFrameCount(context.getSegment(), id);
7474
}
7575

76+
/**
77+
* Get the min/max limits and the default value of a camera/stream property (e.g. zoom, exposure etc.).
78+
*
79+
* @param property the property to get the limits for.
80+
* @return a PropertyLimits object containing the min/max limits and the default value of the property.
81+
* @throws CaptureException if an error occurs while getting the property limits.
82+
*/
83+
public PropertyLimits getPropertyLimits(CaptureProperty property) {
84+
try (Arena arena = Arena.ofConfined()) {
85+
MemorySegment minPointer = arena.allocate(ValueLayout.JAVA_INT);
86+
MemorySegment maxPointer = arena.allocate(ValueLayout.JAVA_INT);
87+
MemorySegment defaultValuePointer = arena.allocate(ValueLayout.JAVA_INT);
88+
89+
int result = Cap_getPropertyLimits(context.getSegment(), id, property.value(), minPointer, maxPointer, defaultValuePointer);
90+
CaptureResult captureResult = CaptureResult.values()[result];
91+
return switch (captureResult) {
92+
case OK -> new PropertyLimits(
93+
minPointer.get(ValueLayout.JAVA_INT, 0),
94+
maxPointer.get(ValueLayout.JAVA_INT, 0),
95+
defaultValuePointer.get(ValueLayout.JAVA_INT, 0)
96+
);
97+
case PROPERTY_NOT_SUPPORTED ->
98+
throw new CaptureException("Property " + property + " is not supported by this stream.");
99+
default -> throw new CaptureException("Error getting property limit for property " + property + ": context, stream are invalid.");
100+
};
101+
}
102+
}
103+
76104
/**
77105
* Check if a stream is open, i.e. is capturing data.
78106
*
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package io.github.doblon8.openpnp.capture;
2+
3+
public record PropertyLimits(int min, int max, int defaultValue) {
4+
}

0 commit comments

Comments
 (0)