Merge branch 'main' into nightscout-missed-bolus-detector

This commit is contained in:
James Babcock committed 2026-10-12 17:09:27 -07:00
commit 8b1b914ee7
16 files changed
+307 -23

No files matched your search

+3 -3
View File
@@ -489,13 +489,13 @@ export class FaceclawCommunicatorBridge {
});
}
/** Phone-UI preview of the current composited screen, or null if none yet. */
getCompositePreview(green = false): ImageSource | null {
/** Phone-UI preview of the current composited screen (or of `crop`'s area of it), or null if none yet. */
getCompositePreview(green = false, crop: { x: number; y: number; width: number; height: number } | null = null): ImageSource | null {
const frame = this.communicator.previewComposite();
if (!frame) return null;
const width = Number(this.communicator.compositeWidth()), height = Number(this.communicator.compositeHeight());
if (width <= 0 || height <= 0) return null;
return previewPixels(fromData(frame.pixels), width, height, green);
return previewPixels(fromData(frame.pixels), width, height, green, crop);
}
/** Save the current composite as a 4-bit grayscale PNG under Documents; returns the path (empty if none). Cropping is not supported on iOS. */
+13 -3
View File
@@ -507,11 +507,21 @@ export class FaceclawCommunicatorBridge {
/**
* Phone-UI preview of the current composited screen, or null if none yet.
* `green` tints it green-on-black (the Preview color setting) instead of
* grayscale.
* grayscale; `crop` limits it to a screen area (the Preview scaling
* setting), black where that runs past the screen's edges.
*/
getCompositePreview(green = false): ImageSource | null {
getCompositePreview(green = false, crop: { x: number; y: number; width: number; height: number } | null = null): ImageSource | null {
if (!global.isAndroid) return null;
const bitmap = this.communicator.getCompositePreviewBitmap(PREVIEW_BRIGHTEN_GAMMA, green);
const bitmap = crop
? this.communicator.getCompositePreviewBitmap(
PREVIEW_BRIGHTEN_GAMMA,
green,
Math.round(crop.x),
Math.round(crop.y),
Math.round(crop.width),
Math.round(crop.height),
)
: this.communicator.getCompositePreviewBitmap(PREVIEW_BRIGHTEN_GAMMA, green);
return bitmap ? new ImageSource(bitmap) : null;
}
+17 -3
View File
@@ -3,11 +3,25 @@ import { GrayImage } from '../graphics/image'
declare const FaceclawGraphics: any
export function previewPixels(pixels: Uint8Array, width: number, height: number, green = false): ImageSource {
type CropRect = { x: number; y: number; width: number; height: number }
/** The gray pixels of a screen area; black where it runs past the frame's edges. */
function cropGray(pixels: Uint8Array, width: number, height: number, crop: CropRect): Uint8Array {
const cropped = new Uint8Array(crop.width * crop.height)
const left = Math.max(crop.x, 0), right = Math.min(crop.x + crop.width, width)
if (right <= left) return cropped
for (let y = Math.max(crop.y, 0); y < Math.min(crop.y + crop.height, height); y++) {
cropped.set(pixels.subarray(y * width + left, y * width + right), (y - crop.y) * crop.width + (left - crop.x))
}
return cropped
}
/** Gray pixels as the phone mirror's image, optionally cropped to a screen area (Preview scaling). */
export function previewPixels(pixels: Uint8Array, width: number, height: number, green = false, crop: CropRect | null = null): ImageSource {
// NSData copies the buffer; the UIImage owns its pixels after this call.
const copy = new Uint8Array(pixels)
const copy = crop ? cropGray(pixels, width, height, crop) : new Uint8Array(pixels)
const data = NSData.dataWithBytesLength(interop.handleof(copy.buffer), copy.byteLength)
const native = FaceclawGraphics.previewWidthHeightGreen(data, width, height, green)
const native = FaceclawGraphics.previewWidthHeightGreen(data, crop?.width ?? width, crop?.height ?? height, green)
if (!native) throw new Error('Could not create preview image')
return new ImageSource(native)
}
+2 -2
View File
@@ -138,8 +138,8 @@ export class PreviewDisplayTarget implements DisplayTarget {
return this.compositor.composite();
}
getCompositePreview(green = false): ImageSource | null {
return previewPixels(this.compositor.composite(), this.compositor.width, this.compositor.height, green);
getCompositePreview(green = false, crop: { x: number; y: number; width: number; height: number } | null = null): ImageSource | null {
return previewPixels(this.compositor.composite(), this.compositor.width, this.compositor.height, green, crop);
}
/** Save the current composite as a 4-bit grayscale PNG under Documents; cropping is not supported on iOS. */
+11 -2
View File
@@ -160,9 +160,18 @@ export class PreviewDisplayTarget implements DisplayTarget {
return Promise.resolve("composited");
}
getCompositePreview(green = false): ImageSource | null {
getCompositePreview(green = false, crop: { x: number; y: number; width: number; height: number } | null = null): ImageSource | null {
if (!global.isAndroid) return null;
const bitmap = this.compositor.getCompositePreviewBitmap(PREVIEW_BRIGHTEN_GAMMA, green);
const bitmap = crop
? this.compositor.getCompositePreviewBitmap(
PREVIEW_BRIGHTEN_GAMMA,
green,
Math.round(crop.x),
Math.round(crop.y),
Math.round(crop.width),
Math.round(crop.height),
)
: this.compositor.getCompositePreviewBitmap(PREVIEW_BRIGHTEN_GAMMA, green);
return bitmap ? new ImageSource(bitmap) : null;
}