fix(desktop qr): scan Windows camera frames from the preview in memory
What changed, and why it matters
This commit fixes a privacy/security bug in Stack Wallet's Windows QR scanner. Previously, every time the app scanned a QR code on Windows, it called the camera plugin's takePicture(), which permanently saved a JPEG of the QR code (which could contain a wallet seed or private key) to the user's Pictures folder. Even deleting the file afterward left a window where OneDrive, search indexing, file recovery tools, or other software could access it. The fix captures the live camera preview directly in memory, scans it without writing anything to disk, and adds tests for the new in-memory frame handling.
Treat this as a security fix and include it in the next release. Users on Windows should be advised that prior versions may have left QR-code JPEGs in their Pictures folder; they should review and clear that folder if they scanned sensitive QR codes. No immediate user action is required after updating.
Security signals we found
Sensitive data (QR codes containing seeds/private keys) was previously persisted to disk via camera_windows takePicture() JPEG writes
Prior deletion of the JPEG was best-effort and left residual exposure to sync, indexing, and recovery tools
Fix moves QR capture entirely to in-memory preview frames on Windows
Added blank-frame detection to avoid scanning empty or privacy-shutter-closed frames
Added tests covering mirror correction, buffer validation, and QR decode round-trip
Evidence from the diff
The patch removes the Windows takePicture() path in _QrCodeScannerDialogState._captureAndScanImage() and replaces it with an in-memory capture of the live preview texture. A new RepaintBoundary with a GlobalKey wraps the camera_windows preview; _captureWindowsPreviewFrame() uses RenderRepaintBoundary.toImage() at the camera’s reported resolution (capped at 1280 px), converts the raw RGBA bytes, detects blank/transparent frames, and flips the image horizontally because camera_windows mirrors its preview. The scanned frame is then passed directly to zxing without ever being encoded to JPEG or written to disk. The old File(xfile.path).delete() cleanup is removed. New unit/widget tests verify row flipping, unaligned buffers, blank-frame detection, and end-to-end QR decoding from a mirrored capture.
Changed components
lib/widgets/desktop/qr_code_scanner_dialog.dartlib/utilities/camera_preview_frame.darttest/utilities/camera_preview_capture_test.darttest/utilities/camera_preview_frame_test.dartInspect captured patch +516 / −50
### lib/utilities/camera_preview_frame.dart
@@ -0,0 +1,77 @@
+import 'dart:typed_data';
+
+import 'package:image/image.dart' as img;
+
+/// Why a frame captured from a camera preview can't be scanned.
+enum BlankPreviewFrame {
+ /// Nothing was drawn: the preview texture has no camera frame yet, or the
+ /// camera has been closed.
+ transparent,
+
+ /// Every visible pixel is black or close to it, as with a closed privacy
+ /// shutter.
+ black,
+}
+
+// Sensor noise keeps a covered webcam from being exactly 0.
+const _blackLevel = 16;
+
+/// Returns why [rgba] can't be scanned, or null if it has picture content.
+///
+/// [rgba] is tightly packed 8-bit RGBA, as from
+/// `ui.Image.toByteData(format: ui.ImageByteFormat.rawRgba)`.
+BlankPreviewFrame? blankPreviewFrame(Uint8List rgba) {
+ var anyVisible = false;
+ for (var i = 0; i + 3 < rgba.length; i += 4) {
+ if (rgba[i + 3] == 0) continue;
+ anyVisible = true;
+ if (rgba[i] > _blackLevel ||
+ rgba[i + 1] > _blackLevel ||
+ rgba[i + 2] > _blackLevel) {
+ return null;
+ }
+ }
+ return anyVisible ? BlankPreviewFrame.black : BlankPreviewFrame.transparent;
+}
+
+/// Builds an image from an RGBA capture of a horizontally mirrored camera
+/// preview, flipped back so a QR code in it reads the right way round.
+///
+/// [rgba] is tightly packed 8-bit RGBA of [width] x [height] pixels.
+img.Image imageFromMirroredPreviewRgba(
+ Uint8List rgba, {
+ required int width,
+ required int height,
+}) {
+ if (width <= 0 || height <= 0) {
+ throw ArgumentError("Invalid frame size ${width}x$height");
+ }
+ final byteLength = width * height * 4;
+ if (rgba.length < byteLength) {
+ throw ArgumentError.value(
+ rgba.length,
+ "rgba",
+ "Too short for a ${width}x$height RGBA frame",
+ );
+ }
+
+ // sublist copies into a fresh buffer, so the 32-bit view is aligned even
+ // if the caller's bytes start at an odd offset.
+ final src = rgba.sublist(0, byteLength).buffer.asUint32List();
+ final flipped = Uint32List(width * height);
+ for (var y = 0; y < height; y++) {
+ final row = y * width;
+ final last = row + width - 1;
+ for (var x = 0; x < width; x++) {
+ flipped[row + x] = src[last - x];
+ }
+ }
+
+ return img.Image.fromBytes(
+ width: width,
+ height: height,
+ bytes: flipped.buffer,
+ numChannels: 4,
+ order: img.ChannelOrder.rgba,
+ );
+}
### lib/widgets/desktop/qr_code_scanner_dialog.dart
@@ -1,6 +1,9 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
+import 'dart:math';
+import 'dart:typed_data';
+import 'dart:ui' as ui;
import 'package:camera_linux/camera_linux.dart';
import 'package:camera_macos/camera_macos_arguments.dart';
@@ -10,11 +13,14 @@ import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:camera_windows/camera_windows.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart';
import 'package:image/image.dart' as img;
import 'package:zxing2/qrcode.dart';
import '../../notifications/show_flush_bar.dart';
+import '../../themes/stack_colors.dart';
import '../../utilities/assets.dart';
+import '../../utilities/camera_preview_frame.dart';
import '../../utilities/logger.dart';
import '../../utilities/text_styles.dart';
import 'desktop_dialog.dart';
@@ -44,6 +50,16 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
String? _cameraError;
String? _initError;
+ // On Windows we scan what the preview shows rather than calling
+ // takePicture(), which always saves a JPEG to the user's Pictures folder.
+ final GlobalKey _windowsPreviewKey = GlobalKey();
+ Size? _windowsPreviewSize;
+ bool _loggedBlankWindowsFrame = false;
+ bool _hasWindowsFrame = false;
+
+ // Bigger captures cost more to read back and scan without helping zxing.
+ static const _maxWindowsFrameDimension = 1280;
+
@override
void initState() {
super.initState();
@@ -90,10 +106,9 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
// initializeCamera() starts the preview, and camera_windows picks the
// preview mode as the largest one with height <= the preset cap
// (low = 240, medium = 480, max = none) at >= 15 fps. If no mode fits,
- // it fails with "Failed to initialize video preview". The cap only
- // affects the preview; takePicture() always uses the largest mode.
- // fps and videoBitrate only apply to video recording, so leave them
- // out.
+ // it fails with "Failed to initialize video preview". We scan the
+ // preview, so this also sets the scan resolution. fps and
+ // videoBitrate only apply to video recording, so leave them out.
CameraException? lastError;
bool opened = false;
for (final camera in ordered) {
@@ -107,7 +122,14 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
camera,
MediaSettings(resolutionPreset: preset, enableAudio: false),
);
+ // The plugin reports the preview size through this event,
+ // which it adds before initializeCamera() returns.
+ final initialized =
+ _cameraWindowsPlugin.onCameraInitialized(_cameraId).first;
await _cameraWindowsPlugin.initializeCamera(_cameraId);
+ final event = await initialized;
+ _windowsPreviewSize =
+ Size(event.previewWidth, event.previewHeight);
opened = true;
break;
} on CameraException catch (e) {
@@ -133,10 +155,9 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
await _cameraWindowsPlugin.dispose(_cameraId);
return false;
}
- // await _cameraWindowsPlugin!.onCameraInitialized(_cameraId).first;
- // TODO [prio=low]: Make this work. ^^^
Logging.instance.d(
- "Windows Camera initialized with ID: $_cameraId",
+ "Windows Camera initialized with ID: $_cameraId, "
+ "preview $_windowsPreviewSize",
);
} else if (Platform.isMacOS) {
final List<CameraMacOSDevice> videoDevices = await CameraMacOS.instance
@@ -198,28 +219,82 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
}
}
+ /// Grabs the frame the Windows preview is showing, in memory. Returns null
+ /// when there is nothing to scan yet.
+ Future<img.Image?> _captureWindowsPreviewFrame() async {
+ final boundary = _windowsPreviewKey.currentContext?.findRenderObject();
+ // Not laid out or painted yet, e.g. just after the camera opened.
+ // debugNeedsPaint is always false in release builds, where toImage()
+ // would throw instead and the capture loop retries after a delay.
+ if (boundary is! RenderRepaintBoundary ||
+ !boundary.hasSize ||
+ boundary.size.isEmpty ||
+ boundary.debugNeedsPaint) {
+ return null;
+ }
+
+ // toImage() redraws the texture at whatever scale we ask for, so match
+ // the camera's own resolution instead of the on-screen size.
+ final preview = _windowsPreviewSize;
+ double pixelRatio = 1;
+ if (preview != null && preview.width > 0 && preview.height > 0) {
+ final fit = min(
+ 1.0,
+ _maxWindowsFrameDimension / max(preview.width, preview.height),
+ );
+ // toImage() rounds each side up, and the laid-out box is rarely exactly
+ // the camera's aspect ratio, so take the smaller ratio and stay a hair
+ // under it. Otherwise a 640x480 camera can come back as 640x481.
+ pixelRatio = min(
+ preview.width * fit / boundary.size.width,
+ preview.height * fit / boundary.size.height,
+ ) *
+ (1 - 1e-9);
+ }
+
+ final ui.Image frame = await boundary.toImage(pixelRatio: pixelRatio);
+ final int width = frame.width;
+ final int height = frame.height;
+ final ByteData? bytes;
+ try {
+ bytes = await frame.toByteData(format: ui.ImageByteFormat.rawRgba);
+ } finally {
+ frame.dispose();
+ }
+ // The dialog closed while we were waiting on the raster thread.
+ if (!_isScanning || !mounted || bytes == null) return null;
+
+ final rgba = bytes.buffer.asUint8List(
+ bytes.offsetInBytes,
+ bytes.lengthInBytes,
+ );
+ final blank = blankPreviewFrame(rgba);
+ if (blank != null) {
+ if (!_loggedBlankWindowsFrame) {
+ _loggedBlankWindowsFrame = true;
+ Logging.instance.w(
+ "Windows camera preview frame is ${blank.name}, "
+ "waiting for a usable one",
+ );
+ }
+ return null;
+ }
+ _loggedBlankWindowsFrame = false;
+
+ // camera_windows mirrors the preview, so flip it back for zxing.
+ return imageFromMirroredPreviewRgba(rgba, width: width, height: height);
+ }
+
Future<void> _captureAndScanImage() async {
_isScanning = true;
while (_isScanning) {
try {
String? base64Image;
+ img.Image? windowsFrame;
if (Platform.isLinux && _cameraLinuxPlugin != null) {
base64Image = await _cameraLinuxPlugin.captureImage();
} else if (Platform.isWindows) {
- final XFile xfile =
- await _cameraWindowsPlugin!.takePicture(_cameraId);
- final List<int> bytes;
- try {
- bytes = await xfile.readAsBytes();
- } finally {
- // camera_windows saves every capture as a JPEG in the user's
- // Pictures folder and never removes it.
- try {
- await File(xfile.path).delete();
- } catch (_) {}
- }
- base64Image = base64Encode(bytes);
- // We could use a Uint8List to optimize for Windows and macOS.
+ windowsFrame = await _captureWindowsPreviewFrame();
} else if (Platform.isMacOS) {
final macOSimg = await CameraMacOS.instance.takePicture();
if (macOSimg == null) {
@@ -235,14 +310,16 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
}
base64Image = base64Encode(img.encodePng(image));
}
- if (base64Image == null || base64Image.isEmpty) {
+ if (windowsFrame == null &&
+ (base64Image == null || base64Image.isEmpty)) {
// Logging.instance
// .log("Failed to capture image", level: LogLevel.Error);
// Spammy.
await Future<void>.delayed(Duration(milliseconds: _imageDelayInMs));
continue;
}
- final img.Image? image = img.decodeImage(base64Decode(base64Image));
+ final img.Image? image =
+ windowsFrame ?? img.decodeImage(base64Decode(base64Image!));
// TODO [prio=low]: Optimize this process. Docs say:
// > WARNING Since this will check the image data against all known
// > decoders, it is much slower than using an explicit decoder
@@ -256,10 +333,15 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
if (mounted) {
setState(() {
_cameraError = null;
- _image = Image.memory(
- base64Decode(base64Image!),
- fit: BoxFit.cover,
- );
+ // Windows already shows the live preview.
+ if (windowsFrame == null) {
+ _image = Image.memory(
+ base64Decode(base64Image!),
+ fit: BoxFit.cover,
+ );
+ } else {
+ _hasWindowsFrame = true;
+ }
});
}
@@ -336,6 +418,61 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
return null;
}
+ Widget _buildCameraView(BuildContext context) {
+ if (Platform.isWindows && _isCameraOpen) {
+ return _buildWindowsPreview(context);
+ }
+ if (_cameraError != null) {
+ return _buildCameraError(context);
+ }
+ if (_isCameraOpen && _image != null) {
+ return _image!;
+ }
+ return const Center(child: CircularProgressIndicator());
+ }
+
+ Widget _buildCameraError(BuildContext context) {
+ return Center(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 32),
+ child: Text(
+ _cameraError!,
+ textAlign: TextAlign.center,
+ style: STextStyles.desktopTextSmall(context),
+ ),
+ ),
+ );
+ }
+
+ Widget _buildWindowsPreview(BuildContext context) {
+ final size = _windowsPreviewSize;
+ return Stack(
+ fit: StackFit.expand,
+ children: [
+ Center(
+ child: AspectRatio(
+ aspectRatio: size != null && size.width > 0 && size.height > 0
+ ? size.width / size.height
+ : 4 / 3,
+ child: RepaintBoundary(
+ key: _windowsPreviewKey,
+ child: _cameraWindowsPlugin!.buildPreview(_cameraId),
+ ),
+ ),
+ ),
+ // Cover the preview rather than replace it, so it keeps painting and
+ // scanning picks up again once frames come back.
+ if (_cameraError != null)
+ ColoredBox(
+ color: Theme.of(context).extension<StackColors>()!.popupBG,
+ child: _buildCameraError(context),
+ )
+ else if (!_hasWindowsFrame)
+ const Center(child: CircularProgressIndicator()),
+ ],
+ );
+ }
+
@override
Widget build(BuildContext context) {
return PopScope(
@@ -361,29 +498,7 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
const DesktopDialogCloseButton(),
],
),
- Expanded(
- child: _cameraError != null
- ? Center(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 32),
- child: Text(
- _cameraError!,
- textAlign: TextAlign.center,
- style: STextStyles.desktopTextSmall(context),
- ),
- ),
- )
- : _isCameraOpen
- ? _image != null
- ? _image!
- : const Center(
- child: CircularProgressIndicator(),
- )
- : const Center(
- child:
- CircularProgressIndicator(), // Show progress indicator immediately
- ),
- ),
+ Expanded(child: _buildCameraView(context)),
Padding(
padding: const EdgeInsets.all(16),
child: Row(
### test/utilities/camera_preview_capture_test.dart
@@ -0,0 +1,143 @@
+import 'dart:ui' as ui;
+
+import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:image/image.dart' as img;
+import 'package:stackwallet/utilities/camera_preview_frame.dart';
+import 'package:zxing2/qrcode.dart';
+
+const _text = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq";
+
+/// Paints a QR code with a red marker in its top-left corner, so a capture
+/// shows whether it was flipped.
+class _QrPainter extends CustomPainter {
+ _QrPainter(this.modules);
+
+ /// True for dark modules, row by row.
+ final List<List<bool>> modules;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ canvas.drawRect(Offset.zero & size, Paint()..color = Colors.white);
+ const border = 4;
+ final module = size.width / (modules.length + 2 * border);
+ final black = Paint()
+ ..color = Colors.black
+ // Hairline seams between anti-aliased modules throw off zxing.
+ ..isAntiAlias = false;
+ for (var y = 0; y < modules.length; y++) {
+ for (var x = 0; x < modules[y].length; x++) {
+ if (modules[y][x]) {
+ canvas.drawRect(
+ Rect.fromLTWH(
+ (x + border) * module,
+ (y + border) * module,
+ module,
+ module,
+ ),
+ black,
+ );
+ }
+ }
+ }
+ canvas.drawRect(
+ Rect.fromLTWH(0, 0, module * 2, module * 2),
+ Paint()..color = const Color(0xFFFF0000),
+ );
+ }
+
+ @override
+ bool shouldRepaint(_QrPainter oldDelegate) => false;
+}
+
+void main() {
+ testWidgets("reads a QR code back from a mirrored preview capture",
+ (tester) async {
+ final matrix = Encoder.encode(_text, ErrorCorrectionLevel.m).matrix!;
+ final modules = [
+ for (var y = 0; y < matrix.height; y++)
+ [for (var x = 0; x < matrix.width; x++) matrix.get(x, y) == 1],
+ ];
+ // Whole logical pixels per module.
+ final side = (modules.length + 8) * 4.0;
+ final key = GlobalKey();
+ await tester.pumpWidget(
+ Center(
+ child: RepaintBoundary(
+ key: key,
+ child: SizedBox(
+ width: side,
+ height: side,
+ // Mirrored like the camera_windows preview.
+ child: Transform.flip(
+ flipX: true,
+ child: CustomPaint(painter: _QrPainter(modules)),
+ ),
+ ),
+ ),
+ ),
+ );
+
+ final boundary =
+ key.currentContext!.findRenderObject()! as RenderRepaintBoundary;
+ final (width, height, rgba) = (await tester.runAsync(() async {
+ final frame = await boundary.toImage(pixelRatio: 2);
+ try {
+ final bytes =
+ await frame.toByteData(format: ui.ImageByteFormat.rawRgba);
+ return (frame.width, frame.height, bytes!.buffer.asUint8List());
+ } finally {
+ frame.dispose();
+ }
+ }))!;
+
+ expect((width, height), (side * 2, side * 2));
+ expect(blankPreviewFrame(rgba), isNull);
+
+ final image =
+ imageFromMirroredPreviewRgba(rgba, width: width, height: height);
+
+ // The marker is back in the top-left once flipped.
+ final marker = image.getPixel(4, 4);
+ expect([marker.r, marker.g, marker.b], [255, 0, 0]);
+ final opposite = image.getPixel(width - 5, 4);
+ expect([opposite.r, opposite.g, opposite.b], [255, 255, 255]);
+
+ final source = RGBLuminanceSource(
+ width,
+ height,
+ image.getBytes(order: img.ChannelOrder.abgr).buffer.asInt32List(),
+ );
+ final result = QRCodeReader().decode(BinaryBitmap(HybridBinarizer(source)));
+ expect(result.text, _text);
+ });
+
+ testWidgets("sees a capture with nothing painted as transparent",
+ (tester) async {
+ final key = GlobalKey();
+ await tester.pumpWidget(
+ Center(
+ child: RepaintBoundary(
+ key: key,
+ child: const SizedBox(width: 50, height: 40),
+ ),
+ ),
+ );
+
+ final boundary =
+ key.currentContext!.findRenderObject()! as RenderRepaintBoundary;
+ final rgba = (await tester.runAsync(() async {
+ final frame = await boundary.toImage();
+ try {
+ final bytes =
+ await frame.toByteData(format: ui.ImageByteFormat.rawRgba);
+ return bytes!.buffer.asUint8List();
+ } finally {
+ frame.dispose();
+ }
+ }))!;
+
+ expect(blankPreviewFrame(rgba), BlankPreviewFrame.transparent);
+ });
+}
### test/utilities/camera_preview_frame_test.dart
@@ -0,0 +1,131 @@
+import 'dart:typed_data';
+
+import 'package:flutter_test/flutter_test.dart';
+import 'package:image/image.dart' as img;
+import 'package:stackwallet/utilities/camera_preview_frame.dart';
+
+/// Packs one RGBA pixel per entry, in row order.
+Uint8List _rgba(List<List<int>> pixels) =>
+ Uint8List.fromList([for (final p in pixels) ...p]);
+
+void main() {
+ group("imageFromMirroredPreviewRgba", () {
+ test("flips each row back", () {
+ // 3x2, every pixel distinct.
+ final rgba = _rgba([
+ [1, 2, 3, 255], [4, 5, 6, 255], [7, 8, 9, 255], //
+ [10, 11, 12, 255], [13, 14, 15, 255], [16, 17, 18, 255],
+ ]);
+
+ final image = imageFromMirroredPreviewRgba(rgba, width: 3, height: 2);
+
+ expect(image.width, 3);
+ expect(image.height, 2);
+ expect(image.numChannels, 4);
+ List<num> rgbaAt(int x, int y) {
+ final p = image.getPixel(x, y);
+ return [p.r, p.g, p.b, p.a];
+ }
+
+ expect(rgbaAt(0, 0), [7, 8, 9, 255]);
+ expect(rgbaAt(1, 0), [4, 5, 6, 255]);
+ expect(rgbaAt(2, 0), [1, 2, 3, 255]);
+ expect(rgbaAt(0, 1), [16, 17, 18, 255]);
+ expect(rgbaAt(2, 1), [10, 11, 12, 255]);
+ });
+
+ test("undoes a mirrored capture of a whole image", () {
+ final original = img.Image(width: 40, height: 30, numChannels: 4);
+ for (final p in original) {
+ p
+ ..r = (p.x * 6) % 256
+ ..g = (p.y * 8) % 256
+ ..b = (p.x + p.y) % 256
+ ..a = 255;
+ }
+ final mirrored = img.flipHorizontal(original.clone());
+ final rgba = mirrored.getBytes(order: img.ChannelOrder.rgba);
+
+ final image = imageFromMirroredPreviewRgba(rgba, width: 40, height: 30);
+
+ expect(
+ image.getBytes(order: img.ChannelOrder.rgba),
+ original.getBytes(order: img.ChannelOrder.rgba),
+ );
+ });
+
+ test("accepts bytes at an unaligned offset", () {
+ final backing = Uint8List(1 + 2 * 4);
+ backing.setAll(1, [1, 2, 3, 255, 4, 5, 6, 255]);
+ final view = Uint8List.view(backing.buffer, 1, 8);
+
+ final image = imageFromMirroredPreviewRgba(view, width: 2, height: 1);
+
+ expect(image.getPixel(0, 0).r, 4);
+ expect(image.getPixel(1, 0).r, 1);
+ });
+
+ test("rejects a buffer that is too short", () {
+ expect(
+ () => imageFromMirroredPreviewRgba(Uint8List(15), width: 2, height: 2),
+ throwsArgumentError,
+ );
+ expect(
+ () => imageFromMirroredPreviewRgba(Uint8List(0), width: 0, height: 0),
+ throwsArgumentError,
+ );
+ });
+ });
+
+ group("blankPreviewFrame", () {
+ test("reports a frame with nothing drawn as transparent", () {
+ expect(
+ blankPreviewFrame(Uint8List(4 * 16)),
+ BlankPreviewFrame.transparent,
+ );
+ expect(blankPreviewFrame(Uint8List(0)), BlankPreviewFrame.transparent);
+ });
+
+ test("reports black and near-black frames as black", () {
+ expect(
+ blankPreviewFrame(_rgba(List.filled(16, [0, 0, 0, 255]))),
+ BlankPreviewFrame.black,
+ );
+ expect(
+ blankPreviewFrame(
+ _rgba([
+ [3, 9, 1, 255],
+ [16, 12, 0, 255],
+ [0, 0, 0, 0],
+ ]),
+ ),
+ BlankPreviewFrame.black,
+ );
+ });
+
+ test("accepts a frame with any picture content", () {
+ expect(
+ blankPreviewFrame(
+ _rgba([
+ [0, 0, 0, 0],
+ [0, 0, 0, 255],
+ [0, 0, 200, 255],
+ ]),
+ ),
+ isNull,
+ );
+ });
+
+ test("ignores color in fully transparent pixels", () {
+ expect(
+ blankPreviewFrame(
+ _rgba([
+ [255, 255, 255, 0],
+ [0, 0, 0, 0],
+ ]),
+ ),
+ BlankPreviewFrame.transparent,
+ );
+ });
+ });
+}Why this scored 74/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.