forked from Blendman974/faceclaw
Dither when darkening for the system context menu
This commit is contained in:
1 parent
4f3ad37c20
commit
90d60cee10
9 files changed
+132
-25
No files matched your search
@@ -0,0 +1,54 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class DimDitherTest {
|
||||
@Test fun contextMenuDimHalftonesLevelsThatWouldRoundAway() {
|
||||
// CONTEXT_MENU_DIM = 0.25: level 1 becomes a 1/0 halftone instead of black or 1.
|
||||
val (even, odd) = DimDither.tables(64)
|
||||
assertContentEquals(intArrayOf(0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4), even)
|
||||
assertContentEquals(intArrayOf(0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4), odd)
|
||||
}
|
||||
|
||||
@Test fun everyFactorGivesMonotonicAdjacentPairsThatKeepVisiblePixels() {
|
||||
for (factor in 0..256) {
|
||||
val (even, odd) = DimDither.tables(factor)
|
||||
assertEquals(0, even[0])
|
||||
assertEquals(0, odd[0])
|
||||
for (level in 1..15) {
|
||||
val halfSteps = even[level] + odd[level]
|
||||
assertTrue(even[level] - odd[level] in 0..1, "factor=$factor level=$level")
|
||||
assertTrue(halfSteps in 1..2 * level, "factor=$factor level=$level")
|
||||
assertTrue(halfSteps >= even[level - 1] + odd[level - 1], "factor=$factor level=$level")
|
||||
}
|
||||
}
|
||||
val (even, odd) = DimDither.tables(256)
|
||||
assertContentEquals(IntArray(16) { it }, even)
|
||||
assertContentEquals(IntArray(16) { it }, odd)
|
||||
}
|
||||
|
||||
@Test fun remapUsesTheEvenTableWhereShiftedXPlusYIsEven() {
|
||||
val even = IntArray(16) { 15 - it }
|
||||
val odd = IntArray(16) { it / 2 }
|
||||
val call = DrawProtocol.remapColors(0, 0, 3, 2, even, odd)
|
||||
assertContentEquals(byteArrayOf(DRAW_OP_REMAP_COLORS.toByte(), 0, 0, 0, 0, 0, 3, 0, 2, 0,
|
||||
0xfe.toByte(), 0xdc.toByte(), 0xba.toByte(), 0x98.toByte(), 0x76, 0x54, 0x32, 0x10,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77), call)
|
||||
for (shift in listOf(0, 1)) {
|
||||
// Rows of 4 pixels: 4, 5, 6, 7 then 8, 9, 10, 11.
|
||||
val pixels = byteArrayOf(0x45, 0x67, 0x89.toByte(), 0xab.toByte())
|
||||
DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(call)),
|
||||
DisplayListRenderer.Target(pixels, 4, 2).shifted(shift))
|
||||
val target = DisplayListRenderer.Target(pixels, 4, 2)
|
||||
for (y in 0..1) for (x in 0..3) {
|
||||
val source = 4 + y * 4 + x
|
||||
val expected = when {
|
||||
x !in shift until shift + 3 -> source
|
||||
(x + y) % 2 == 0 -> even[source]
|
||||
else -> odd[source]
|
||||
}
|
||||
assertEquals(expected, target.get(x, y), "shift=$shift x=$x y=$y")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class DisplayListTest {
|
||||
val renderer=DisplayListRenderer(resources)
|
||||
assertEquals(setOf(10,11,12,20,21),renderer.render(21,DisplayListRenderer.Target(screen,8,4),DisplayListRenderer.Target(output,8,4)))
|
||||
// Shared with the C sanitizer harness: signed clipping, resource target override, font and LUT.
|
||||
assertContentEquals(hex("71122334755061700112233445534477"),output)
|
||||
assertContentEquals(hex("81223344755162701122334445544578"),output)
|
||||
val first=output.copyOf(); screen.copyInto(output); renderer.render(21,DisplayListRenderer.Target(screen,8,4),DisplayListRenderer.Target(output,8,4))
|
||||
assertContentEquals(first,output)
|
||||
assertContentEquals(hex("123456789abcdef0123456789abcdef0"),screen)
|
||||
@@ -215,7 +215,8 @@ class DisplayListTest {
|
||||
val overlay=ShellScene(listOf(ShellScene.Layer(1,0,0,3,3,128,hex("fff0fff0fff0"))))
|
||||
val first=planner.plan(app,640,480,null,overlay,1);glasses.apply(first.commands)
|
||||
assertContentEquals(app,glasses.screen);assertEquals(255,glasses.composition[0].toInt() and 255)
|
||||
assertEquals(0x44,glasses.composition[100].toInt() and 255)
|
||||
// Half of level 9 is a 5/4 checkerboard; x=200 on row 0 is an even pixel.
|
||||
assertEquals(0x54,glasses.composition[100].toInt() and 255)
|
||||
val changed=ShellScene(listOf(ShellScene.Layer(1,0,0,3,3,128,hex("111011101110"))))
|
||||
val repaint=planner.plan(app,640,480,null,changed,1)
|
||||
assertFalse(repaint.commands.any { it[0].toInt() in listOf(21,22,29) })
|
||||
|
||||
@@ -17,7 +17,7 @@ class DrawWireTest {
|
||||
DrawProtocol.playList(511, depth = 127) to "07027fff01",
|
||||
DrawProtocol.roundedRect(-1, 2, 640, 480, 65535, 15, 16) to
|
||||
"08007f028002e001ffff0f10",
|
||||
DrawProtocol.lut(640, 480, 256) to "0600000000008002e0010123456789abcdef",
|
||||
DrawProtocol.lut(640, 480, 256) to "0600000000008002e0010123456789abcdef0123456789abcdef",
|
||||
DrawProtocol.bbox(hex("ffffffffffffffff"), 4, 0, 0, 8, 2) to "010000000002010f10",
|
||||
DrawProtocol.bbox(hex("0f"), 1, 1, 0, 1, 1) to "01000101000000010001001f",
|
||||
DrawProtocol.clear(15, target = 511) to "0901ff010f",
|
||||
|
||||
Reference in new issue
Block a user