mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
simplify camera pixel format prioritisation
This commit is contained in:
parent
0975d12155
commit
b3a6340c45
2 changed files with 10 additions and 18 deletions
|
|
@ -3,20 +3,18 @@ package com.sparrowwallet.sparrow.control;
|
||||||
import com.sparrowwallet.drongo.OsType;
|
import com.sparrowwallet.drongo.OsType;
|
||||||
|
|
||||||
public enum WebcamPixelFormat {
|
public enum WebcamPixelFormat {
|
||||||
//Only V4L2 formats defined in linux/videodev2.h are required here
|
//Only V4L2 formats defined in linux/videodev2.h are required here, declared in order of priority for supported formats
|
||||||
PIX_FMT_RGB24("RGB3", true, true),
|
PIX_FMT_RGB24("RGB3", true),
|
||||||
PIX_FMT_YUYV("YUYV", true, true),
|
PIX_FMT_YUYV("YUYV", true),
|
||||||
PIX_FMT_MJPG("MJPG", true, false),
|
PIX_FMT_MJPG("MJPG", true),
|
||||||
PIX_FMT_NV12("NV12", false, false);
|
PIX_FMT_NV12("NV12", false);
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final boolean supported;
|
private final boolean supported;
|
||||||
private final boolean preferred;
|
|
||||||
|
|
||||||
WebcamPixelFormat(String name, boolean supported, boolean preferred) {
|
WebcamPixelFormat(String name, boolean supported) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.supported = supported;
|
this.supported = supported;
|
||||||
this.preferred = preferred;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
@ -27,10 +25,6 @@ public enum WebcamPixelFormat {
|
||||||
return supported;
|
return supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred() {
|
|
||||||
return preferred;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
@ -69,13 +63,11 @@ public enum WebcamPixelFormat {
|
||||||
|
|
||||||
public static int getPriority(WebcamPixelFormat pixelFormat) {
|
public static int getPriority(WebcamPixelFormat pixelFormat) {
|
||||||
if(pixelFormat == null) {
|
if(pixelFormat == null) {
|
||||||
return 2;
|
return values().length;
|
||||||
} else if(pixelFormat.isPreferred()) {
|
|
||||||
return 0;
|
|
||||||
} else if(pixelFormat.isSupported()) {
|
} else if(pixelFormat.isSupported()) {
|
||||||
return 1;
|
return pixelFormat.ordinal();
|
||||||
} else {
|
} else {
|
||||||
return 3;
|
return values().length + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ public class WebcamService extends ScheduledService<Image> {
|
||||||
|
|
||||||
List<CaptureFormat> deviceFormats = new ArrayList<>(device.getFormats());
|
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
|
//On macOS and Windows, camera pixel format is largely abstracted away
|
||||||
if(OsType.getCurrent() == OsType.UNIX) {
|
if(OsType.getCurrent() == OsType.UNIX) {
|
||||||
deviceFormats.sort((f1, f2) -> {
|
deviceFormats.sort((f1, f2) -> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue