Tests: the native suite in seconds, every test on its own, all cores
- scripts/test-native.py (just t WORD): builds once, runs each test in its own process in parallel, longest first, with a timeout; CI and just test use it. - Tests no longer search this machine's apps and icon themes. - Compiled wasm modules are cached between test processes (CHANDRA_WASM_CACHE). - draw_circle fills its middle with spans (same pixels); encode_png writes into one buffer, with a CRC table. - The ffprobe helper always waited out its 20 s: its done file was empty. - The fake polkit helper no longer depends on which shell sh is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d1d1bb398c
commit
5ca7242615
12 files changed
+397
-81
No files matched your search
@@ -346,10 +346,42 @@ fn draw_circle(
|
||||
let cg = color.g.to_int()
|
||||
let cb = color.b.to_int()
|
||||
let ca = color.a.to_int()
|
||||
// What can show: the pixmap, intersected with the clip, as offsets from the centre.
|
||||
let mut x0 = 0
|
||||
let mut y0 = 0
|
||||
let mut x1 = dst.width
|
||||
let mut y1 = dst.height
|
||||
match clip {
|
||||
Some(c) => {
|
||||
x0 = x0.max(c.x)
|
||||
y0 = y0.max(c.y)
|
||||
x1 = x1.min(c.x + c.w)
|
||||
y1 = y1.min(c.y + c.h)
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
let dx0 = (x0 - cx).max(-radius - 1)
|
||||
let dx1 = (x1 - 1 - cx).min(radius + 1)
|
||||
let dy0 = (y0 - cy).max(-radius - 1)
|
||||
let dy1 = (y1 - 1 - cy).min(radius + 1)
|
||||
// Antialiased: per-pixel coverage from the distance to the edge (1px wide ring when unfilled).
|
||||
let rad = radius.to_double()
|
||||
for dy = -radius - 1; dy <= radius + 1; dy = dy + 1 {
|
||||
for dx = -radius - 1; dx <= radius + 1; dx = dx + 1 {
|
||||
let alpha = ca.to_double()
|
||||
// Within this distance every pixel is alike: fully covered, or the empty middle of a ring.
|
||||
let even = if filled { rad - 0.5 } else { rad - 1.5 }
|
||||
for dy = dy0; dy <= dy1; dy = dy + 1 {
|
||||
let rest = even * even - (dy * dy).to_double()
|
||||
let half = if even > 0.0 && rest > 0.0 { rest.sqrt().to_int() - 1 } else { -1 }
|
||||
let mut dx = dx0
|
||||
while dx <= dx1 {
|
||||
if half >= 0 && dx >= -half && dx <= half {
|
||||
let last = half.min(dx1)
|
||||
if filled {
|
||||
blend_span(dst, cy + dy, cx + dx, cx + last + 1, cr, cg, cb, ca)
|
||||
}
|
||||
dx = last + 1
|
||||
continue
|
||||
}
|
||||
let d = (dx * dx + dy * dy).to_double().sqrt()
|
||||
let outer = rad + 0.5 - d
|
||||
let mut cov = if outer > 1.0 { 1.0 } else { outer }
|
||||
@@ -361,8 +393,9 @@ fn draw_circle(
|
||||
}
|
||||
}
|
||||
if cov > 0.02 {
|
||||
blend_pixel(dst, cx + dx, cy + dy, cr, cg, cb, (ca.to_double() * cov).round().to_int(), clip)
|
||||
blend_pixel(dst, cx + dx, cy + dy, cr, cg, cb, (alpha * cov + 0.5).to_int(), clip)
|
||||
}
|
||||
dx = dx + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -955,18 +988,20 @@ fn push_u32_be(out : Array[Byte], v : UInt) -> Unit {
|
||||
out.push((v & 0xFFU).to_byte())
|
||||
}
|
||||
|
||||
///|
|
||||
let crc_table : FixedArray[UInt] = FixedArray::makei(256, n => {
|
||||
let mut c = n.reinterpret_as_uint()
|
||||
for _b = 0; _b < 8; _b = _b + 1 {
|
||||
c = if (c & 1U) != 0U { (c >> 1) ^ 0xEDB8_8320U } else { c >> 1 }
|
||||
}
|
||||
c
|
||||
})
|
||||
|
||||
///|
|
||||
fn crc32(bytes : Array[Byte], start : Int, len : Int) -> UInt {
|
||||
let mut c = 0xFFFF_FFFFU
|
||||
for i = 0; i < len; i = i + 1 {
|
||||
c = c ^ bytes[start + i].to_uint()
|
||||
for _b = 0; _b < 8; _b = _b + 1 {
|
||||
if (c & 1U) != 0U {
|
||||
c = (c >> 1) ^ 0xEDB8_8320U
|
||||
} else {
|
||||
c = c >> 1
|
||||
}
|
||||
}
|
||||
for i = start; i < start + len; i = i + 1 {
|
||||
c = (c >> 8) ^ crc_table[((c ^ bytes[i].to_uint()) & 0xFFU).reinterpret_as_int()]
|
||||
}
|
||||
c ^ 0xFFFF_FFFFU
|
||||
}
|
||||
@@ -985,65 +1020,101 @@ fn push_png_chunk(out : Array[Byte], tag : String, payload : Array[Byte]) -> Uni
|
||||
push_u32_be(out, crc)
|
||||
}
|
||||
|
||||
///| Encode Pixmap as a valid uncompressed RGBA PNG in pure MoonBit.
|
||||
///| Encode Pixmap as a valid uncompressed RGBA PNG in pure MoonBit. Written straight into a buffer
|
||||
/// of the final size: the tests save many of these, unoptimised.
|
||||
pub fn encode_png(p : Pixmap) -> Bytes {
|
||||
let out : Array[Byte] = [
|
||||
b'\x89', b'\x50', b'\x4e', b'\x47', b'\x0d', b'\x0a', b'\x1a', b'\x0a',
|
||||
]
|
||||
let row = 1 + p.width * 4 // the filter byte (0), then the pixels
|
||||
let total = row * p.height
|
||||
let blocks = (total + 65534) / 65535 // stored deflate blocks
|
||||
let idat = 2 + total + 5 * blocks + 4
|
||||
let out : FixedArray[Byte] = FixedArray::make(8 + 25 + 12 + idat + 12, b'\x00')
|
||||
let mut at = 0
|
||||
fn byte(v : Int) {
|
||||
out[at] = v.to_byte()
|
||||
at = at + 1
|
||||
}
|
||||
|
||||
// IHDR
|
||||
let ihdr : Array[Byte] = []
|
||||
push_u32_be(ihdr, p.width.reinterpret_as_uint())
|
||||
push_u32_be(ihdr, p.height.reinterpret_as_uint())
|
||||
ihdr.push(b'\x08') // bit depth = 8
|
||||
ihdr.push(b'\x06') // color type = RGBA
|
||||
ihdr.push(b'\x00') // compression = 0
|
||||
ihdr.push(b'\x00') // filter = 0
|
||||
ihdr.push(b'\x00') // interlace = 0
|
||||
push_png_chunk(out, "IHDR", ihdr)
|
||||
fn u32(v : UInt) {
|
||||
byte(((v >> 24) & 0xFFU).reinterpret_as_int())
|
||||
byte(((v >> 16) & 0xFFU).reinterpret_as_int())
|
||||
byte(((v >> 8) & 0xFFU).reinterpret_as_int())
|
||||
byte((v & 0xFFU).reinterpret_as_int())
|
||||
}
|
||||
|
||||
// Raw scanlines: 1 filter byte (0) + width * 4 bytes per row
|
||||
let row_bytes = 1 + p.width * 4
|
||||
let raw : Array[Byte] = Array(capacity=row_bytes * p.height)
|
||||
fn tag(s : String) {
|
||||
for ch in s {
|
||||
byte(ch.to_int())
|
||||
}
|
||||
}
|
||||
|
||||
fn crc(start : Int) {
|
||||
let mut c = 0xFFFF_FFFFU
|
||||
let table = crc_table
|
||||
for i = start; i < at; i = i + 1 {
|
||||
c = (c >> 8) ^ table[((c ^ out[i].to_uint()) & 0xFFU).reinterpret_as_int()]
|
||||
}
|
||||
u32(c ^ 0xFFFF_FFFFU)
|
||||
}
|
||||
|
||||
for b in [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a] {
|
||||
byte(b)
|
||||
}
|
||||
u32(13U)
|
||||
let start = at
|
||||
tag("IHDR")
|
||||
u32(p.width.reinterpret_as_uint())
|
||||
u32(p.height.reinterpret_as_uint())
|
||||
for b in [8, 6, 0, 0, 0] { // 8 bits, RGBA, deflate, filter method 0, not interlaced
|
||||
byte(b)
|
||||
}
|
||||
crc(start)
|
||||
u32(idat.reinterpret_as_uint())
|
||||
let start = at
|
||||
tag("IDAT")
|
||||
byte(0x78)
|
||||
byte(0x01)
|
||||
let mut s1 = 1U
|
||||
let mut s2 = 0U
|
||||
for y = 0; y < p.height; y = y + 1 {
|
||||
raw.push(b'\x00')
|
||||
s1 = (s1 + 0U) % 65521U
|
||||
s2 = (s2 + s1) % 65521U
|
||||
let row_off = y * p.width * 4
|
||||
for i = 0; i < p.width * 4; i = i + 1 {
|
||||
let b = p.data[row_off + i]
|
||||
raw.push(b)
|
||||
s1 = (s1 + b.to_uint()) % 65521U
|
||||
s2 = (s2 + s1) % 65521U
|
||||
}
|
||||
}
|
||||
|
||||
// Zlib stream with stored (uncompressed) deflate blocks (max 65535 bytes each)
|
||||
let idat : Array[Byte] = [b'\x78', b'\x01']
|
||||
let mut pos = 0
|
||||
let total = raw.length()
|
||||
let mut left = 0 // in this block
|
||||
let mut pos = 0 // in the scanlines
|
||||
let mut col = 0 // in the row
|
||||
let mut src = 0
|
||||
let mut due = 5552 // bytes until the Adler sums could overflow
|
||||
let data = p.data
|
||||
while pos < total {
|
||||
let rem = total - pos
|
||||
let blk = if rem > 65535 { 65535 } else { rem }
|
||||
let is_last = pos + blk >= total
|
||||
idat.push(if is_last { b'\x01' } else { b'\x00' })
|
||||
idat.push((blk & 0xFF).to_byte())
|
||||
idat.push(((blk >> 8) & 0xFF).to_byte())
|
||||
let nlen = blk ^ 0xFFFF
|
||||
idat.push((nlen & 0xFF).to_byte())
|
||||
idat.push(((nlen >> 8) & 0xFF).to_byte())
|
||||
for i = 0; i < blk; i = i + 1 {
|
||||
idat.push(raw[pos + i])
|
||||
if left == 0 {
|
||||
left = (total - pos).min(65535)
|
||||
byte(if pos + left == total { 1 } else { 0 })
|
||||
byte(left & 0xFF)
|
||||
byte(left >> 8)
|
||||
byte((left ^ 0xFFFF) & 0xFF)
|
||||
byte((left ^ 0xFFFF) >> 8)
|
||||
}
|
||||
pos = pos + blk
|
||||
let b = if col == 0 {
|
||||
b'\x00'
|
||||
} else {
|
||||
src = src + 1
|
||||
data[src - 1]
|
||||
}
|
||||
out[at] = b
|
||||
at = at + 1
|
||||
s1 = s1 + b.to_uint()
|
||||
s2 = s2 + s1
|
||||
due = due - 1
|
||||
if due == 0 {
|
||||
s1 = s1 % 65521U
|
||||
s2 = s2 % 65521U
|
||||
due = 5552
|
||||
}
|
||||
col = if col + 1 == row { 0 } else { col + 1 }
|
||||
pos = pos + 1
|
||||
left = left - 1
|
||||
}
|
||||
let adler = (s2 << 16) | s1
|
||||
push_u32_be(idat, adler)
|
||||
push_png_chunk(out, "IDAT", idat)
|
||||
|
||||
// IEND
|
||||
push_png_chunk(out, "IEND", [])
|
||||
Bytes::from_array(out)
|
||||
u32((s2 % 65521U << 16) | (s1 % 65521U))
|
||||
crc(start)
|
||||
u32(0U)
|
||||
let start = at
|
||||
tag("IEND")
|
||||
crc(start)
|
||||
Bytes::from_fixedarray(out)
|
||||
}
|
||||
Reference in new issue
Block a user