Skip to content

Commit 3365bf5

Browse files
committed
add filetype selector
1 parent fb8590b commit 3365bf5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

core/src/main/java/edu/wpi/grip/core/operations/composite/SaveImageOperation.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ public class SaveImageOperation implements Operation {
3636
.build();
3737

3838
private final SocketHint<Mat> inputHint = SocketHints.Inputs.createMatSocketHint("Input", false);
39+
private final SocketHint<FILETYPES> fileTypeHint = SocketHints.createEnumSocketHint("File type", FILETYPES.jpeg);
3940
private final SocketHint<Number> qualityHint = SocketHints.Inputs.createNumberSliderSocketHint("Quality", 90, 0, 100);
4041
private final SocketHint<Number> periodHint = SocketHints.Inputs.createNumberSpinnerSocketHint("Period", 0.1);
4142
private final SocketHint<Boolean> activeHint = SocketHints.Inputs.createCheckboxSocketHint("Active", false);
4243

4344
private final SocketHint<Mat> outputHint = SocketHints.Outputs.createMatSocketHint("Output");
4445

4546
private final InputSocket<Mat> inputSocket;
47+
private final InputSocket<FILETYPES> fileTypesSocket;
4648
private final InputSocket<Number> qualitySocket;
4749
private final InputSocket<Number> periodSocket;
4850
private final InputSocket<Boolean> activeSocket;
@@ -54,10 +56,15 @@ public class SaveImageOperation implements Operation {
5456
private final Stopwatch stopwatch = Stopwatch.createStarted();
5557
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss-SSS");
5658

59+
private enum FILETYPES {
60+
jpeg, png
61+
}
62+
5763
public SaveImageOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory, FileManager fileManager) {
5864
this.fileManager = fileManager;
5965

6066
inputSocket = inputSocketFactory.create(inputHint);
67+
fileTypesSocket = inputSocketFactory.create(fileTypeHint);
6168
qualitySocket = inputSocketFactory.create(qualityHint);
6269
periodSocket = inputSocketFactory.create(periodHint);
6370
activeSocket = inputSocketFactory.create(activeHint);
@@ -69,6 +76,7 @@ public SaveImageOperation(InputSocket.Factory inputSocketFactory, OutputSocket.F
6976
public List<InputSocket> getInputSockets() {
7077
return ImmutableList.of(
7178
inputSocket,
79+
fileTypesSocket,
7280
qualitySocket,
7381
periodSocket,
7482
activeSocket
@@ -95,7 +103,7 @@ public void perform() {
95103
stopwatch.reset();
96104
stopwatch.start();
97105

98-
imencode(".jpeg", inputSocket.getValue().get(), imagePointer, new IntPointer(CV_IMWRITE_JPEG_QUALITY,
106+
imencode("." + fileTypesSocket.getValue().get(), inputSocket.getValue().get(), imagePointer, new IntPointer(CV_IMWRITE_JPEG_QUALITY,
99107
qualitySocket.getValue().get().intValue()));
100108
byte[] buffer = new byte[128 * 1024];
101109
int bufferSize = imagePointer.limit();
@@ -104,6 +112,6 @@ public void perform() {
104112
}
105113
imagePointer.get(buffer, 0, bufferSize);
106114

107-
fileManager.saveImage(buffer, LocalDateTime.now().format(formatter) + ".jpeg");
115+
fileManager.saveImage(buffer, LocalDateTime.now().format(formatter) + "." + fileTypesSocket.getValue().get());
108116
}
109117
}

0 commit comments

Comments
 (0)