Files
cell/tests/surface.js

37 lines
1.1 KiB
JavaScript

// Test SDL_Surface module
var Surface = use('surface');
// Test creating a surface
var surf = new Surface({width: 100, height: 100});
console.log("Created surface:", surf.width, "x", surf.height);
console.log(json.encode(surf))
// Test fill
surf.fill([1, 0, 0, 1]); // Red
// Test dup
var surf2 = surf.dup();
console.log("Duplicated surface:", surf2.width, "x", surf2.height);
// Test scale
var surf3 = surf.scale([50, 50], "linear");
console.log("Scaled surface:", surf3.width, "x", surf3.height);
// Test format
console.log("Surface format:", surf.format);
// Test pixels
var pixels = surf.pixels();
console.log("Got pixels array buffer, length:", pixels.byteLength);
// Test creating surface with custom format
var surf4 = new Surface({width: 64, height: 64, format: "rgb24"});
console.log("Created RGB24 surface:", surf4.width, "x", surf4.height, "format:", surf4.format);
// Test creating surface from pixels
var pixelData = new ArrayBuffer(32 * 32 * 4); // 32x32 RGBA
var surf5 = new Surface({width: 32, height: 32, pixels: pixelData});
console.log("Created surface from pixels:", surf5.width, "x", surf5.height);
console.log("Surface module test passed!");