simplify camera pixel format prioritisation

This commit is contained in:
Craig Raw 2025-04-08 14:50:38 +02:00
parent 0975d12155
commit b3a6340c45
2 changed files with 10 additions and 18 deletions

View file

@ -3,20 +3,18 @@ package com.sparrowwallet.sparrow.control;
import com.sparrowwallet.drongo.OsType;
public enum WebcamPixelFormat {
//Only V4L2 formats defined in linux/videodev2.h are required here
PIX_FMT_RGB24("RGB3", true, true),
PIX_FMT_YUYV("YUYV", true, true),
PIX_FMT_MJPG("MJPG", true, false),
PIX_FMT_NV12("NV12", false, false);
//Only V4L2 formats defined in linux/videodev2.h are required here, declared in order of priority for supported formats
PIX_FMT_RGB24("RGB3", true),
PIX_FMT_YUYV("YUYV", true),
PIX_FMT_MJPG("MJPG", true),
PIX_FMT_NV12("NV12", false);
private final String name;
private final boolean supported;
private final boolean preferred;
WebcamPixelFormat(String name, boolean supported, boolean preferred) {
WebcamPixelFormat(String name, boolean supported) {
this.name = name;
this.supported = supported;
this.preferred = preferred;
}
public String getName() {
@ -27,10 +25,6 @@ public enum WebcamPixelFormat {
return supported;
}
public boolean isPreferred() {
return preferred;
}
public String toString() {
return name;
}
@ -69,13 +63,11 @@ public enum WebcamPixelFormat {
public static int getPriority(WebcamPixelFormat pixelFormat) {
if(pixelFormat == null) {
return 2;
} else if(pixelFormat.isPreferred()) {
return 0;
return values().length;
} else if(pixelFormat.isSupported()) {
return 1;
return pixelFormat.ordinal();
} else {
return 3;
return values().length + 1;
}
}
}

View file

@ -137,7 +137,7 @@ public class WebcamService extends ScheduledService<Image> {
List<CaptureFormat> deviceFormats = new ArrayList<>(device.getFormats());
//On *nix prioritise supported camera pixel formats, preferring RGB3 and YUYV over MJPG
//On *nix prioritise supported camera pixel formats, preferring RGB3, then YUYV, then MJPG
//On macOS and Windows, camera pixel format is largely abstracted away
if(OsType.getCurrent() == OsType.UNIX) {
deviceFormats.sort((f1, f2) -> {