fix syntax

This commit is contained in:
2026-02-17 09:15:15 -06:00
parent f310c18b84
commit 4e1b63fd0e
52 changed files with 2169 additions and 1754 deletions

View File

@@ -2,20 +2,22 @@
var Anim = (() => {
def DEFAULT_MIN = 1 / 60; /* 16 ms one frame */
function play(source, loop=true){
function play(source, loop){
var local_loop = !is_null(loop) ? loop : (!is_null(source.loop) ? source.loop : true);
return {
src : source,
idx : 0,
timer : 0,
loop : loop ?? source.loop ?? true
loop : local_loop
};
}
function update(a, dt){
a.timer += dt;
def frames = a.src.frames;
var frames = a.src.frames;
var time = null;
while(true){
def time = max(frames[a.idx].time || 0, Anim.minDelay);
time = max(frames[a.idx].time || 0, Anim.minDelay);
if(a.timer < time) break; /* still on current frame */
a.timer -= time;

View File

@@ -52,10 +52,14 @@ function hsl_to_rgb(h, s, l) {
var bunny_count = 20
for (var i = 0; i < bunny_count; i++) {
var pct = i/bunny_count
var hue = 270 * i / bunny_count
var sp = sprite.create(bunny, {
var i = 0;
var pct = 0;
var hue = 0;
var sp = null;
for (i = 0; i < bunny_count; i++) {
pct = i/bunny_count
hue = 270 * i / bunny_count
sp = sprite.create(bunny, {
pos: [random.random()*dim.x*pct, random.random()*dim.y*pct],
center,
color: hsl_to_rgb(hue, 0.5, 0.5)

View File

@@ -18,8 +18,10 @@ log.console("\nLooking for different colorspaces in supported formats...");
// Group formats by colorspace
var colorspaces = {};
for (var i = 0; i < length(formats); i++) {
var fmt = formats[i];
var i = 0;
var fmt = null;
for (i = 0; i < length(formats); i++) {
fmt = formats[i];
if (!colorspaces[fmt.colorspace]) {
colorspaces[fmt.colorspace] = [];
}
@@ -53,8 +55,9 @@ arrfor(array(colorspaces), function(cs) {
};
var cam = camera.open(cam_id, custom_format);
var actual = null;
if (cam) {
var actual = cam.get_format();
actual = cam.get_format();
log.console(" Opened successfully!");
log.console(" Actual colorspace: " + actual.colorspace);

View File

@@ -40,67 +40,76 @@ $receiver(e => {
});
// Wait for approval then capture
var srgb_surf = null;
var linear_surf = null;
var jpeg_surf = null;
var hd_surf = null;
function capture_test() {
if (!approved) {
$delay(capture_test, 0.1);
return;
}
log.console("\nCapturing frame...");
var surf = cam.capture();
if (!surf) {
log.console("No frame captured yet, retrying...");
$delay(capture_test, 0.1);
return;
}
log.console("\nCaptured surface:");
log.console(" Size:", surf.width + "x" + surf.height);
log.console(" Format:", surf.format);
// Test various colorspace conversions
log.console("\nTesting colorspace conversions:");
// Convert to sRGB if not already
var convert_srgb = function() {
srgb_surf = surf.convert(surf.format, "srgb");
log.console(" Converted to sRGB colorspace");
} disruption {
log.console(" sRGB conversion failed");
}
if (format.colorspace != "srgb") {
try {
var srgb_surf = surf.convert(surf.format, "srgb");
log.console(" Converted to sRGB colorspace");
} catch(e) {
log.console(" sRGB conversion failed:", e.message);
}
convert_srgb();
}
// Convert to linear sRGB for processing
try {
var linear_surf = surf.convert("rgba8888", "srgb_linear");
var convert_linear = function() {
linear_surf = surf.convert("rgba8888", "srgb_linear");
log.console(" Converted to linear sRGB (RGBA8888) for processing");
} catch(e) {
log.console(" Linear sRGB conversion failed:", e.message);
} disruption {
log.console(" Linear sRGB conversion failed");
}
convert_linear();
// Convert to JPEG colorspace (common for compression)
try {
var jpeg_surf = surf.convert("rgb888", "jpeg");
var convert_jpeg = function() {
jpeg_surf = surf.convert("rgb888", "jpeg");
log.console(" Converted to JPEG colorspace (RGB888) for compression");
} catch(e) {
log.console(" JPEG colorspace conversion failed:", e.message);
} disruption {
log.console(" JPEG colorspace conversion failed");
}
convert_jpeg();
// If YUV format, try BT.709 (HD video standard)
if (search(surf.format, "yuv") != null || search(surf.format, "yuy") != null) {
try {
var hd_surf = surf.convert(surf.format, "bt709_limited");
log.console(" Converted to BT.709 limited (HD video standard)");
} catch(e) {
log.console(" BT.709 conversion failed:", e.message);
}
var convert_hd = function() {
hd_surf = surf.convert(surf.format, "bt709_limited");
log.console(" Converted to BT.709 limited (HD video standard)");
} disruption {
log.console(" BT.709 conversion failed");
}
if (search(surf.format, "yuv") != null || search(surf.format, "yuy") != null) {
convert_hd();
}
log.console("\nTest complete!");
$stop();
}
// Start capture test after a short delay
$delay(capture_test, 0.5);
$delay(capture_test, 0.5);

View File

@@ -10,23 +10,32 @@ var cameras = camera.list();
log.console("Found", length(cameras), "cameras");
// Get info about each camera
for (var i = 0; i < length(cameras); i++) {
var cam_id = cameras[i];
var i = 0;
var j = 0;
var cam_id = null;
var formats = null;
var fmt = null;
var preferred_format = null;
var cam = null;
var actual_format = null;
for (i = 0; i < length(cameras); i++) {
cam_id = cameras[i];
log.console("\nCamera", i + 1, "ID:", cam_id);
log.console(" Name:", camera.name(cam_id));
log.console(" Position:", camera.position(cam_id));
// Get supported formats
var formats = camera.supported_formats(cam_id);
formats = camera.supported_formats(cam_id);
log.console(" Supported formats:", length(formats));
// Show first few formats
for (var j = 0; j < length(formats); j++) {
var fmt = formats[j];
for (j = 0; j < length(formats); j++) {
fmt = formats[j];
log.console(" Format", j + 1 + ":");
log.console(" Pixel format:", fmt.format);
log.console(" Resolution:", fmt.width + "x" + fmt.height);
log.console(" FPS:", fmt.framerate_numerator + "/" + fmt.framerate_denominator,
log.console(" FPS:", fmt.framerate_numerator + "/" + fmt.framerate_denominator,
"(" + (fmt.framerate_numerator / fmt.framerate_denominator) + ")");
log.console(" Colorspace:", fmt.colorspace);
}
@@ -35,19 +44,19 @@ for (var i = 0; i < length(cameras); i++) {
// Open the first camera with a specific format if available
if (length(cameras) > 0) {
log.console("\nOpening first camera...");
var cam_id = cameras[0];
var formats = camera.supported_formats(cam_id);
cam_id = cameras[0];
formats = camera.supported_formats(cam_id);
// Try to find a 640x480 format
var preferred_format = null;
for (var i = 0; i < length(formats); i++) {
preferred_format = null;
for (i = 0; i < length(formats); i++) {
if (formats[i].width == 640 && formats[i].height == 480) {
preferred_format = formats[i];
break;
}
}
var cam;
cam = null;
if (preferred_format) {
log.console("Opening with 640x480 format...");
cam = camera.open(cam_id, preferred_format);
@@ -55,21 +64,21 @@ if (length(cameras) > 0) {
log.console("Opening with default format...");
cam = camera.open(cam_id);
}
if (cam) {
log.console("Camera opened successfully!");
log.console("Driver being used:", cam.get_driver());
// Get the actual format being used
var actual_format = cam.get_format();
actual_format = cam.get_format();
log.console("Actual format being used:");
log.console(" Pixel format:", actual_format.format);
log.console(" Resolution:", actual_format.width + "x" + actual_format.height);
log.console(" FPS:", actual_format.framerate_numerator + "/" + actual_format.framerate_denominator,
"(" + (actual_format.framerate_numerator / actual_format.framerate_denominator) + ")");
log.console(" Colorspace:", actual_format.colorspace);
// Clean up - camera will be closed when object is freed
cam = null;
}
}
}

View File

@@ -1,6 +1,6 @@
// Test draw2d module without moth framework
var draw2d
var graphics
var draw2d = null
var graphics = null
var os = use('os');
var input = use('input')
var math = use('math/radians')
@@ -170,11 +170,16 @@ function start_drawing() {
// Draw some points in a pattern
var point_count = 20;
for (var i = 0; i < point_count; i++) {
var angle = (i / point_count) * pi * 2;
var r = 30 + math.sine(t * 4 + i * 0.5) * 10;
var px = 650 + math.cosine(angle) * r;
var py = 300 + math.sine(angle) * r;
var i = 0;
var angle = 0;
var r = 0;
var px = 0;
var py = 0;
for (i = 0; i < point_count; i++) {
angle = (i / point_count) * pi * 2;
r = 30 + math.sine(t * 4 + i * 0.5) * 10;
px = 650 + math.cosine(angle) * r;
py = 300 + math.sine(angle) * r;
draw2d.point(
[px, py],

View File

@@ -31,13 +31,17 @@ var colorspaces = ["srgb", "srgb_linear", "jpeg", "bt601_limited", "bt709_limite
var test_format = "rgba8888";
log.console("\nTest 3: Converting to", test_format, "with different colorspaces:");
for (var i = 0; i < length(colorspaces); i++) {
try {
var conv = surf.convert(test_format, colorspaces[i]);
var i = 0;
var conv = null;
var try_convert = null;
for (i = 0; i < length(colorspaces); i++) {
try_convert = function() {
conv = surf.convert(test_format, colorspaces[i]);
log.console(" " + colorspaces[i] + ": Success");
} catch(e) {
log.console(" " + colorspaces[i] + ": Failed -", e.message);
} disruption {
log.console(" " + colorspaces[i] + ": Failed");
}
try_convert();
}
// Test 4: YUV formats with appropriate colorspaces
@@ -49,15 +53,18 @@ var yuv_tests = [
{format: "yvyu", colorspace: "bt601_full"}
];
for (var i = 0; i < length(yuv_tests); i++) {
var test = yuv_tests[i];
try {
var conv = surf.convert(test.format, test.colorspace);
var test = null;
var try_yuv = null;
for (i = 0; i < length(yuv_tests); i++) {
test = yuv_tests[i];
try_yuv = function() {
conv = surf.convert(test.format, test.colorspace);
log.console(" " + test.format + " with " + test.colorspace + ": Success");
} catch(e) {
log.console(" " + test.format + " with " + test.colorspace + ": Failed -", e.message);
} disruption {
log.console(" " + test.format + " with " + test.colorspace + ": Failed");
}
try_yuv();
}
log.console("\nColorspace conversion test complete!");
$stop();
$stop();

View File

@@ -1,6 +1,6 @@
// Test webcam display
var draw2d
var graphics
var draw2d = null
var graphics = null
var os = use('os');
var input = use('input')
var json = use('json')
@@ -88,7 +88,8 @@ send(video_actor, {
// Look for a 640x480 format with preferred colorspace
var preferred_format = null;
for (var i = 0; i < length(formats); i++) {
var i = 0;
for (i = 0; i < length(formats); i++) {
if (formats[i].width == 640 && formats[i].height == 480) {
preferred_format = formats[i];
// Prefer JPEG or sRGB colorspace if available