Improve scanner repeatability guardrails
This commit is contained in:
+19
-1
@@ -407,6 +407,12 @@ async function captureSourceFromGdi(sourceId: string, sourceName: string, option
|
||||
}
|
||||
|
||||
function nativeImageFromGdiCapture(gdi: Awaited<ReturnType<InputHelperService["capturePrimaryScreenViaGdi"]>>) {
|
||||
if (gdi.imageBase64) {
|
||||
return nativeImage.createFromBuffer(Buffer.from(gdi.imageBase64, "base64"));
|
||||
}
|
||||
if (!gdi.dataUrl) {
|
||||
throw new Error("GDI capture returned no image payload.");
|
||||
}
|
||||
return nativeImage.createFromDataURL(gdi.dataUrl);
|
||||
}
|
||||
|
||||
@@ -1296,6 +1302,14 @@ async function buildCaptureResult(
|
||||
const omitInventoryPreview = Boolean(options.omitInventoryPreview || options.ocrMode === "artifact");
|
||||
const detailFingerprint = imageCropFingerprint(sourceImage, detailRect, size);
|
||||
const inventoryFingerprint = imageCropFingerprint(sourceImage, inventoryRect, size);
|
||||
const fastOcrPriority: Record<string, number> = {
|
||||
"artifact-substats": 0,
|
||||
"artifact-name": 1,
|
||||
"artifact-footer": 2,
|
||||
"artifact-slot": 3,
|
||||
"artifact-main-stat-label": 4,
|
||||
"artifact-level": 5,
|
||||
};
|
||||
const croppedPayload = crops
|
||||
.filter((crop) => crop.ocrEnabled !== false)
|
||||
.map((crop) => {
|
||||
@@ -1307,7 +1321,11 @@ async function buildCaptureResult(
|
||||
}
|
||||
: null;
|
||||
})
|
||||
.filter((crop): crop is OcrCropPayload => Boolean(crop));
|
||||
.filter((crop): crop is OcrCropPayload => Boolean(crop))
|
||||
.sort((left, right) => {
|
||||
if (options.ocrMode !== "artifact" || options.ocrProfile !== "fast") return 0;
|
||||
return (fastOcrPriority[left.id] ?? 100) - (fastOcrPriority[right.id] ?? 100);
|
||||
});
|
||||
const prepareMs = Date.now() - buildStartedAt;
|
||||
const ocrEngine = ocrEngineFromOptions(options);
|
||||
const ocrStartedAt = Date.now();
|
||||
|
||||
@@ -292,7 +292,9 @@ export function createInputHelperService(options: { userDataPath: string; exePat
|
||||
: "primary-screen";
|
||||
|
||||
return {
|
||||
dataUrl: `data:image/png;base64,${base64}`,
|
||||
...(typeof result.imageBase64 === "string" && result.imageBase64
|
||||
? { imageBase64: base64 }
|
||||
: { dataUrl: `data:image/png;base64,${base64}` }),
|
||||
width: Number(result.width),
|
||||
height: Number(result.height),
|
||||
originX: Number(result.originX),
|
||||
|
||||
Reference in New Issue
Block a user