Skip to content

Commit 8df9f5e

Browse files
versi-techlopcode
authored andcommitted
Add support for multi-output operations
1 parent b355fc7 commit 8df9f5e

36 files changed

+1797
-270
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repositories {
2323
}
2424

2525
dependencies {
26-
implementation("app.photofox.vips-ffm:vips-ffm-core:1.7.1")
26+
implementation("app.photofox.vips-ffm:vips-ffm-core:1.8.0")
2727
}
2828
```
2929

core/src/main/java/app/photofox/vipsffm/VImage.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ public VImage fillNearest(VipsOption... args) throws VipsError {
21832183
/// @optionalArg threshold [VipsOption.Double] Object threshold
21842184
/// @optionalArg background [VipsOption.ArrayDouble] Color for background pixels
21852185
/// @optionalArg line-art [VipsOption.Boolean] Enable line art mode
2186-
public int findTrim(VipsOption... args) throws VipsError {
2186+
public FindTrimOutput findTrim(VipsOption... args) throws VipsError {
21872187
var inOption = VipsOption.Image("in", this);
21882188
var leftOption = VipsOption.Int("left");
21892189
var topOption = VipsOption.Int("top");
@@ -2196,7 +2196,7 @@ public int findTrim(VipsOption... args) throws VipsError {
21962196
callArgs.add(widthOption);
21972197
callArgs.add(heightOption);
21982198
VipsInvoker.invokeOperation(arena, "find_trim", callArgs);
2199-
return leftOption.valueOrThrow();
2199+
return new FindTrimOutput(leftOption.valueOrThrow(), topOption.valueOrThrow(), widthOption.valueOrThrow(), heightOption.valueOrThrow());
22002200
}
22012201

22022202
/// Read a FITS image file into a VIPS image.
@@ -6495,7 +6495,9 @@ public static VImage ppmload(Arena arena, String filename, VipsOption... args) t
64956495
return outOption.valueOrThrow();
64966496
}
64976497

6498-
/// Load ppm from buffer
6498+
/// Exactly as [VImage#ppmload], but read from a memory source.
6499+
///
6500+
/// See also: [VImage#ppmload]
64996501
/// @param arena The arena that bounds resulting memory allocations during this operation
65006502
/// @param buffer Buffer to load from
65016503
/// @param args Array of VipsOption to apply to this operation
@@ -6666,7 +6668,7 @@ public VImage prewitt(VipsOption... args) throws VipsError {
66666668
///
66676669
/// See also: [VImage#project], [VImage#histFind]
66686670
/// @param args Array of VipsOption to apply to this operation
6669-
public VImage profile(VipsOption... args) throws VipsError {
6671+
public ProfileOutput profile(VipsOption... args) throws VipsError {
66706672
var inOption = VipsOption.Image("in", this);
66716673
var columnsOption = VipsOption.Image("columns");
66726674
var rowsOption = VipsOption.Image("rows");
@@ -6675,7 +6677,7 @@ public VImage profile(VipsOption... args) throws VipsError {
66756677
callArgs.add(columnsOption);
66766678
callArgs.add(rowsOption);
66776679
VipsInvoker.invokeOperation(arena, "profile", callArgs);
6678-
return columnsOption.valueOrThrow();
6680+
return new ProfileOutput(columnsOption.valueOrThrow(), rowsOption.valueOrThrow());
66796681
}
66806682

66816683
/// Find the horizontal and vertical projections of an image, ie. the sum
@@ -6686,7 +6688,7 @@ public VImage profile(VipsOption... args) throws VipsError {
66866688
///
66876689
/// See also: [VImage#histFind], [VImage#profile]
66886690
/// @param args Array of VipsOption to apply to this operation
6689-
public VImage project(VipsOption... args) throws VipsError {
6691+
public ProjectOutput project(VipsOption... args) throws VipsError {
66906692
var inOption = VipsOption.Image("in", this);
66916693
var columnsOption = VipsOption.Image("columns");
66926694
var rowsOption = VipsOption.Image("rows");
@@ -6695,7 +6697,7 @@ public VImage project(VipsOption... args) throws VipsError {
66956697
callArgs.add(columnsOption);
66966698
callArgs.add(rowsOption);
66976699
VipsInvoker.invokeOperation(arena, "project", callArgs);
6698-
return columnsOption.valueOrThrow();
6700+
return new ProjectOutput(columnsOption.valueOrThrow(), rowsOption.valueOrThrow());
66996701
}
67006702

67016703
/// Transform an image with a 0, 1, 2, or 3rd order polynomial.
@@ -9935,4 +9937,16 @@ public List<String> getFields() {
99359937
VipsRaw.vips_image_map(this.address, callbackPointer, MemorySegment.NULL);
99369938
return fieldNameStrings;
99379939
}
9940+
9941+
/// Helper record to hold multiple outputs from the [VImage#findTrim] operation
9942+
public record FindTrimOutput(int left, int top, int width, int height) {
9943+
}
9944+
9945+
/// Helper record to hold multiple outputs from the [VImage#profile] operation
9946+
public record ProfileOutput(VImage columns, VImage rows) {
9947+
}
9948+
9949+
/// Helper record to hold multiple outputs from the [VImage#project] operation
9950+
public record ProjectOutput(VImage columns, VImage rows) {
9951+
}
99389952
}

core/src/main/java/app/photofox/vipsffm/VipsOption.java

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public int valueOrThrow() throws VipsError {
1818
);
1919
}
2020

21+
public Integer valueOrNull() {
22+
var optionalValue = box.get();
23+
return optionalValue.orElse(null);
24+
}
25+
2126
public boolean hasValue() {
2227
return box.get().isPresent();
2328
}
@@ -36,6 +41,11 @@ public double valueOrThrow() throws VipsError {
3641
);
3742
}
3843

44+
public java.lang.Double valueOrNull() {
45+
var optionalValue = box.get();
46+
return optionalValue.orElse(null);
47+
}
48+
3949
public boolean hasValue() {
4050
return box.get().isPresent();
4151
}
@@ -54,6 +64,11 @@ public java.lang.Long valueOrThrow() throws VipsError {
5464
);
5565
}
5666

67+
public java.lang.Long valueOrNull() {
68+
var optionalValue = box.get();
69+
return optionalValue.orElse(null);
70+
}
71+
5772
public boolean hasValue() {
5873
return box.get().isPresent();
5974
}
@@ -72,6 +87,11 @@ public boolean valueOrThrow() throws VipsError {
7287
);
7388
}
7489

90+
public java.lang.Boolean valueOrNull() {
91+
var optionalValue = box.get();
92+
return optionalValue.orElse(null);
93+
}
94+
7595
public boolean hasValue() {
7696
return box.get().isPresent();
7797
}
@@ -90,6 +110,11 @@ public java.lang.String valueOrThrow() throws VipsError {
90110
);
91111
}
92112

113+
public java.lang.String valueOrNull() {
114+
var optionalValue = box.get();
115+
return optionalValue.orElse(null);
116+
}
117+
93118
public boolean hasValue() {
94119
return box.get().isPresent();
95120
}
@@ -108,6 +133,11 @@ public VImage valueOrThrow() throws VipsError {
108133
);
109134
}
110135

136+
public VImage valueOrNull() {
137+
var optionalValue = box.get();
138+
return optionalValue.orElse(null);
139+
}
140+
111141
public boolean hasValue() {
112142
return box.get().isPresent();
113143
}
@@ -126,6 +156,11 @@ public VSource valueOrThrow() throws VipsError {
126156
);
127157
}
128158

159+
public VSource valueOrNull() {
160+
var optionalValue = box.get();
161+
return optionalValue.orElse(null);
162+
}
163+
129164
public boolean hasValue() {
130165
return box.get().isPresent();
131166
}
@@ -144,6 +179,11 @@ public VTarget valueOrThrow() throws VipsError {
144179
);
145180
}
146181

182+
public VTarget valueOrNull() {
183+
var optionalValue = box.get();
184+
return optionalValue.orElse(null);
185+
}
186+
147187
public boolean hasValue() {
148188
return box.get().isPresent();
149189
}
@@ -162,6 +202,11 @@ public VBlob valueOrThrow() throws VipsError {
162202
);
163203
}
164204

205+
public VBlob valueOrNull() {
206+
var optionalValue = box.get();
207+
return optionalValue.orElse(null);
208+
}
209+
165210
public boolean hasValue() {
166211
return box.get().isPresent();
167212
}
@@ -180,6 +225,11 @@ public List<java.lang.Double> valueOrThrow() throws VipsError {
180225
);
181226
}
182227

228+
public List<java.lang.Double> valueOrNull() {
229+
var optionalValue = box.get();
230+
return optionalValue.orElse(null);
231+
}
232+
183233
public boolean hasValue() {
184234
return box.get().isPresent();
185235
}
@@ -194,10 +244,15 @@ record ArrayInt(java.lang.String key, AtomicReference<Optional<List<Integer>>> b
194244
public List<Integer> valueOrThrow() throws VipsError {
195245
var optionalValue = box.get();
196246
return optionalValue.orElseThrow(
197-
() -> new VipsError("unexpected empty value")
247+
() -> new VipsError("unexpected empty value")
198248
);
199249
}
200250

251+
public List<java.lang.Integer> valueOrNull() {
252+
var optionalValue = box.get();
253+
return optionalValue.orElse(null);
254+
}
255+
201256
public boolean hasValue() {
202257
return box.get().isPresent();
203258
}
@@ -216,6 +271,11 @@ public List<VImage> valueOrThrow() throws VipsError {
216271
);
217272
}
218273

274+
public List<VImage> valueOrNull() {
275+
var optionalValue = box.get();
276+
return optionalValue.orElse(null);
277+
}
278+
219279
public boolean hasValue() {
220280
return box.get().isPresent();
221281
}
@@ -234,6 +294,11 @@ public VInterpolate valueOrThrow() throws VipsError {
234294
);
235295
}
236296

297+
public VInterpolate valueOrNull() {
298+
var optionalValue = box.get();
299+
return optionalValue.orElse(null);
300+
}
301+
237302
public boolean hasValue() {
238303
return box.get().isPresent();
239304
}
@@ -252,6 +317,11 @@ public VEnum valueOrThrow() throws VipsError {
252317
);
253318
}
254319

320+
public VEnum valueOrNull() {
321+
var optionalValue = box.get();
322+
return optionalValue.orElse(null);
323+
}
324+
255325
public boolean hasValue() {
256326
return box.get().isPresent();
257327
}

0 commit comments

Comments
 (0)