// Test surface colorspace conversion var surface = use('sdl3/surface'); var json = use('json'); // Create a test surface var surf = surface({ width: 640, height: 480, format: "rgb888" }); log.console("Created surface:"); log.console(" Size:", surf.width + "x" + surf.height); log.console(" Format:", surf.format); // Fill with a test color surf.fill([1, 0.5, 0.25, 1]); // Orange color // Test 1: Convert format only (no colorspace change) log.console("\nTest 1: Convert to RGBA8888 format only"); var converted1 = surf.convert("rgba8888"); log.console(" New format:", converted1.format); // Test 2: Convert format and colorspace log.console("\nTest 2: Convert to YUY2 format with JPEG colorspace"); var converted2 = surf.convert("yuy2", "jpeg"); log.console(" New format:", converted2.format); // Test 3: Try different colorspaces var colorspaces = ["srgb", "srgb_linear", "jpeg", "bt601_limited", "bt709_limited"]; var test_format = "rgba8888"; log.console("\nTest 3: Converting to", test_format, "with different colorspaces:"); 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"); } disruption { log.console(" " + colorspaces[i] + ": Failed"); } try_convert(); } // Test 4: YUV formats with appropriate colorspaces log.console("\nTest 4: YUV format conversions:"); var yuv_tests = [ {format: "yuy2", colorspace: "jpeg"}, {format: "nv12", colorspace: "bt601_limited"}, {format: "nv21", colorspace: "bt709_limited"}, {format: "yvyu", colorspace: "bt601_full"} ]; 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"); } disruption { log.console(" " + test.format + " with " + test.colorspace + ": Failed"); } try_yuv(); } log.console("\nColorspace conversion test complete!"); $stop();