Skip to content

Commit f1b8a80

Browse files
committed
refactor: simplify loadAnyImage to delegate to byte array implementation
1 parent 26598e7 commit f1b8a80

1 file changed

Lines changed: 2 additions & 32 deletions

File tree

app/common/src/main/java/stirling/software/common/util/RenderingUtils.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import app.photofox.vipsffm.VBlob;
2626
import app.photofox.vipsffm.VImage;
27-
import app.photofox.vipsffm.VSource;
2827
import app.photofox.vipsffm.VipsOption;
2928
import app.photofox.vipsffm.enums.VipsAccess;
3029
import app.photofox.vipsffm.enums.VipsBandFormat;
@@ -213,37 +212,8 @@ private static VImage bandReorder(Arena arena, VImage vimg, int... order) {
213212

214213
/** Loads an image from an InputStream, utilizing native loaders and ImageMagick fallback. */
215214
public static VImage loadAnyImage(Arena arena, InputStream inputStream) throws IOException {
216-
try {
217-
VSource source = VSource.newFromInputStream(arena, inputStream);
218-
try {
219-
// Try high-fidelity loaders with sequential access
220-
return VImage.newFromSource(arena, source, "access=sequential,n=-1,fail=true");
221-
} catch (Exception e) {
222-
try {
223-
// Retry without 'n' parameter if the format doesn't support it (e.g. JXL, PNG,
224-
// JPG)
225-
return VImage.newFromSource(arena, source, "access=sequential,fail=true");
226-
} catch (Exception ex) {
227-
log.debug(
228-
"Standard native loader failed, trying ImageMagick fallback: {}",
229-
ex.getMessage());
230-
try {
231-
return VImage.magickloadSource(arena, source, VipsOption.Int("n", -1));
232-
} catch (Exception ex2) {
233-
try {
234-
return VImage.magickloadSource(arena, source);
235-
} catch (Exception ex3) {
236-
throw ex3;
237-
}
238-
}
239-
}
240-
}
241-
} catch (Exception ex) {
242-
log.error("Failed to load image with any available native loader", ex);
243-
throw new IOException(
244-
"Failed to load image with any available native loader: " + ex.getMessage(),
245-
ex);
246-
}
215+
byte[] bytes = inputStream.readAllBytes();
216+
return loadAnyImage(arena, bytes);
247217
}
248218

249219
/** Loads an image from bytes, utilizing native loaders and ImageMagick fallback. */

0 commit comments

Comments
 (0)