sort camera pixel formats on linux only

This commit is contained in:
Craig Raw 2025-04-08 13:48:59 +02:00
parent e31aa7fc80
commit 0975d12155
2 changed files with 12 additions and 8 deletions

View file

@ -3,12 +3,10 @@ package com.sparrowwallet.sparrow.control;
import com.sparrowwallet.drongo.OsType;
public enum WebcamPixelFormat {
PIX_FMT_420V("420v", true, true),
PIX_FMT_YUVS("yuvs", true, true),
//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_YUY2("YUY2", true, true),
PIX_FMT_NV12("NV12", false, false);
private final String name;

View file

@ -5,6 +5,7 @@ import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import com.sparrowwallet.bokmakierie.Bokmakierie;
import com.sparrowwallet.drongo.OsType;
import com.sparrowwallet.sparrow.io.Config;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
@ -135,11 +136,16 @@ public class WebcamService extends ScheduledService<Image> {
}
List<CaptureFormat> deviceFormats = new ArrayList<>(device.getFormats());
deviceFormats.sort((f1, f2) -> {
WebcamPixelFormat pf1 = WebcamPixelFormat.fromFourCC(f1.getFormatInfo().fourcc);
WebcamPixelFormat pf2 = WebcamPixelFormat.fromFourCC(f2.getFormatInfo().fourcc);
return Integer.compare(WebcamPixelFormat.getPriority(pf1), WebcamPixelFormat.getPriority(pf2));
});
//On *nix prioritise supported camera pixel formats, preferring RGB3 and YUYV over MJPG
//On macOS and Windows, camera pixel format is largely abstracted away
if(OsType.getCurrent() == OsType.UNIX) {
deviceFormats.sort((f1, f2) -> {
WebcamPixelFormat pf1 = WebcamPixelFormat.fromFourCC(f1.getFormatInfo().fourcc);
WebcamPixelFormat pf2 = WebcamPixelFormat.fromFourCC(f2.getFormatInfo().fourcc);
return Integer.compare(WebcamPixelFormat.getPriority(pf1), WebcamPixelFormat.getPriority(pf2));
});
}
Map<WebcamResolution, CaptureFormat> supportedResolutions = deviceFormats.stream()
.filter(f -> WebcamResolution.from(f) != null)