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
@@ -7,6 +7,8 @@
|
||||
* A new display-list system for glasses-side drawing, unlocking z-effects and animation
|
||||
* Menus animate when changing selection and scrolling
|
||||
* Menus bounce at the ends, and show part of the next row when there is more below
|
||||
* Fade-in/out effects when turning the screen on/off
|
||||
* Custom auto-brightness control algorithm, with configurable min, max and curve
|
||||
* Depth effects for the window switcher, top bar, and modals
|
||||
* Glanceboard has configurable distance
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ export type FirmwareInfo = {
|
||||
};
|
||||
|
||||
/** The Faceclaw firmware revision this build of the app needs. */
|
||||
export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 32;
|
||||
export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 33;
|
||||
|
||||
const FACECLAW_PREFIX = "Faceclaw/";
|
||||
const LEGACY_PREFIX = "EVENCFW";
|
||||
|
||||
@@ -19,7 +19,7 @@ export type FirmwarePatchSet = {
|
||||
export const CFW_PATCH_SET: FirmwarePatchSet = {
|
||||
"base": "g2_2.3.0.24.bin",
|
||||
"baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979",
|
||||
"outputSha256": "61f732b4a6ba10c26b1eb4f93253d990380b5a7cff4fdd18482626a883c457e6",
|
||||
"outputSha256": "9f9134e9be00201228185a8493c3520c53222ae95bd1c9236569fc22430ccc18",
|
||||
"patches": [
|
||||
{
|
||||
"offset": 1045797,
|
||||
@@ -210,43 +210,43 @@ export const CFW_PATCH_SET: FirmwarePatchSet = {
|
||||
{
|
||||
"offset": 4537963,
|
||||
"old": "",
|
||||
"new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc1b04ff62c484ef66c694ff29c5b1446cff6ff78ccf2ff09c2f2290b4ff6ff75002701260993cde90a0106e048f2a351c0f24501bff32f8f8847dbf800a0bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0ba804ff4757007f0b8fa002800f0078241464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f8009086728583c583058445848584c584058545858585c585058645868586c586058745875be8001f51457ff436afbff35f8f4be8000121b15be8001f5145f8d02be70b99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847dbf80070bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0ba804ff4757007f0dcf9002800f02b8141464218463182f8d44382f8d54382f8d64382f8d74382f8d84382f8d94382f8da4382f8db4382f8dc4382f8dd4382f8de4382f8df4382f8e04382f8e14382f8e24382f8e34382f8e44382f8e54382f8e64382f8e74382f8e84382f8e94382f8ea4382f8eb4382f8ec4382f8ed4382f8ee4382f8ef4382f8f04382f8f14382f8f24382f8f34382f8f44382f8f54382f8f64382f8f74382f8f84382f8f94382f8fa4382f8fb4382f8fc4382f8fd4382f8fe4382f8ff4382f8004482f8014482f8024482f8034482f8044482f8054482f8064482f8074482f8084482f8094482f80a4482f80b4482f80c4482f80d4482f80e4482f80f4482f8104482f8114482f8124482f8134482f8144482f8154482f8164482f8174482f8184482f819447ff470afc0f8009086728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb9427ff436afbff35f8f4be8000121b15be8001fb942f8d02be7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f09d810b98002861d00a980778a7f1170002285bd80b980c2840f086810a9e7078b178084300f08081f0780138022800f27b81b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f01082172f40f02682002a40f06281fe2800f06d86812800f06086002840f0738651ea030040f0558100f0bdbe04460020b047e8b104f51d7151e800afbaf1000f0cd1bff35f8f00bf41e80002002a00f0f58051e800afbaf1000ff5d00021bff32f8f0029bff35f8f00f0e480824692e74ff0ff3737e147f6df40c0f24f008047002701240d97adf8387006e048f2a351c0f24501bff32f8f8847dbf80060bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0c1804ff4757007f082f8002800f0b98041464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f8009084728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb1427ff436afbff35f8f4be8000159b15be8001fb142f8d02be706f5a9718847ace6012110e700200a9999b10b9a8ab1097801f07f02b2f10b0618bf0126b2f11c0718bf01278a2924dc0b2926d01c2924d03fe009900ca804f0a9fa4ff0ff3701249df8390000280ca818bf4ff0ff3704f0e5fb054644b99df8380028b94af21f30c0f247004c3080470998002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010446884794f8641119b994f80413204669b14ff0ff3742f6f760c0f2440000f5807150468847384641b0bde8f08f09900ca806ea070404f067fa0a98017801f07f061e2e04d10b9908f088fb0746b5e71d2e01f07e0018bf1a2811d1dbf800100322cff680720a40b2f1005fbff35f8f0ad10a684a4504bf002281f8812303e0a6f115010129e9d90f2e0adc092e00f37381052e00f0ef82072e40f01c8300279ae0142e00f32182102e00f0eb82112e40f011830b98022841f0c6800a9908781Line truncated
|
||||
"new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc1b04ff62c484ef66c694ff29c5b1446cff6ff78ccf2ff09c2f2290b4ff6ff75002701260993cde90a0106e048f2a351c0f24501bff32f8f8847dbf800a0bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0ba804ff4757007f0b8fa002800f0078241464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f8009086728583c583058445848584c584058545858585c585058645868586c586058745875be8001f51457ff436afbff35f8f4be8000121b15be8001f5145f8d02be70b99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847dbf80070bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0ba804ff4757007f0dcf9002800f02b8141464218463182f8d44382f8d54382f8d64382f8d74382f8d84382f8d94382f8da4382f8db4382f8dc4382f8dd4382f8de4382f8df4382f8e04382f8e14382f8e24382f8e34382f8e44382f8e54382f8e64382f8e74382f8e84382f8e94382f8ea4382f8eb4382f8ec4382f8ed4382f8ee4382f8ef4382f8f04382f8f14382f8f24382f8f34382f8f44382f8f54382f8f64382f8f74382f8f84382f8f94382f8fa4382f8fb4382f8fc4382f8fd4382f8fe4382f8ff4382f8004482f8014482f8024482f8034482f8044482f8054482f8064482f8074482f8084482f8094482f80a4482f80b4482f80c4482f80d4482f80e4482f80f4482f8104482f8114482f8124482f8134482f8144482f8154482f8164482f8174482f8184482f819447ff470afc0f8009086728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb9427ff436afbff35f8f4be8000121b15be8001fb942f8d02be7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f09d810b98002861d00a980778a7f1170002285bd80b980c2840f086810a9e7078b178084300f08081f0780138022800f27b81b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f01082172f40f02682002a40f06281fe2800f06d86812800f06086002840f0738651ea030040f0558100f0bdbe04460020b047e8b104f51d7151e800afbaf1000f0cd1bff35f8f00bf41e80002002a00f0f58051e800afbaf1000ff5d00021bff32f8f0029bff35f8f00f0e480824692e74ff0ff3737e147f6df40c0f24f008047002701240d97adf8387006e048f2a351c0f24501bff32f8f8847dbf80060bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0c1804ff4757007f082f8002800f0b98041464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f8009084728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb1427ff436afbff35f8f4be8000159b15be8001fb142f8d02be706f5a9718847ace6012110e700200a9999b10b9a8ab1097801f07f02b2f10b0618bf0126b2f11c0718bf01278a2924dc0b2926d01c2924d03fe009900ca804f0a9fa4ff0ff3701249df8390000280ca818bf4ff0ff3704f0e5fb054644b99df8380028b94af21f30c0f247004c3080470998002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010446884794f8641119b994f80413204669b14ff0ff3742f6f760c0f2440000f5807150468847384641b0bde8f08f09900ca806ea070404f067fa0a98017801f07f061e2e04d10b9908f088fb0746b5e71d2e01f07e0018bf1a2811d1dbf800100322cff680720a40b2f1005fbff35f8f0ad10a684a4504bf002281f8812303e0a6f115010129e9d90f2e0adc092e00f37381052e00f0ef82072e40f01c8300279ae0142e00f32182102e00f0eb82112e40f011830b98022841f0c6800a9908781Line truncated
|
||||
"desc": "append injected blobs to main-app payload"
|
||||
},
|
||||
{
|
||||
"offset": 779123,
|
||||
"old": "805a3900",
|
||||
"new": "c86a3a00",
|
||||
"new": "046b3a00",
|
||||
"desc": "main-app subheader payload size (ps)"
|
||||
},
|
||||
{
|
||||
"offset": 152,
|
||||
"old": "005b3900",
|
||||
"new": "486b3a00",
|
||||
"new": "846b3a00",
|
||||
"desc": "main-app TOC entry size (ps + 128)"
|
||||
},
|
||||
{
|
||||
"offset": 779243,
|
||||
"old": "805a3904",
|
||||
"new": "c86a3a04",
|
||||
"new": "046b3a04",
|
||||
"desc": "main-app preamble length (low 24 bits)"
|
||||
},
|
||||
{
|
||||
"offset": 779247,
|
||||
"old": "effdbcea",
|
||||
"new": "0d513b79",
|
||||
"new": "a487d0e1",
|
||||
"desc": "[5] ota/s200_firmware_ota.bin preamble crc32"
|
||||
},
|
||||
{
|
||||
"offset": 156,
|
||||
"old": "c0c6322a",
|
||||
"new": "ca6f630a",
|
||||
"new": "3b17b4f0",
|
||||
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)"
|
||||
},
|
||||
{
|
||||
"offset": 779127,
|
||||
"old": "c0c6322a",
|
||||
"new": "ca6f630a",
|
||||
"new": "3b17b4f0",
|
||||
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)"
|
||||
}
|
||||
]
|
||||
|
||||
+15
-9
@@ -1,6 +1,6 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
/** Revision 29 wire grammar, shared by scene planning and the local renderer. */
|
||||
/** Revision 33 wire grammar, shared by scene planning and the local renderer. */
|
||||
object DrawProtocol {
|
||||
/** Mirrors g2flash/patches/zlib_glue.c. */
|
||||
const val DRAW = CFW_MSG_DRAW_CALLS
|
||||
@@ -154,20 +154,26 @@ object DrawProtocol {
|
||||
fun playList(id: Int, target: Int? = null, depth: Int? = null): ByteArray =
|
||||
call(DRAW_OP_DISPLAY_LIST, target, depth) { writeU16(id) }
|
||||
|
||||
fun lut(width: Int, height: Int, factor: Int): ByteArray {
|
||||
val table = ByteArray(8) { i ->
|
||||
(((i * 2 * factor / 256).coerceIn(0, 15) shl 4) or
|
||||
((i * 2 + 1) * factor / 256).coerceIn(0, 15)).toByte()
|
||||
}
|
||||
/** Revision 33: target pixels with even x+y map through [even], odd ones through [odd]. */
|
||||
fun remapColors(x: Int, y: Int, width: Int, height: Int, even: IntArray, odd: IntArray): ByteArray {
|
||||
require(even.size == 16 && odd.size == 16 && (even + odd).all { it in 0..15 })
|
||||
fun packed(table: IntArray) = ByteArray(8) { i -> ((table[i * 2] shl 4) or table[i * 2 + 1]).toByte() }
|
||||
return call(DRAW_OP_REMAP_COLORS) {
|
||||
writeU16(0)
|
||||
writeU16(0)
|
||||
writeU16(x)
|
||||
writeU16(y)
|
||||
writeU16(width)
|
||||
writeU16(height)
|
||||
writeBytes(table)
|
||||
writeBytes(packed(even))
|
||||
writeBytes(packed(odd))
|
||||
}
|
||||
}
|
||||
|
||||
/** Dim the whole target's light to factor/256 with DimDither's checkerboard. */
|
||||
fun lut(width: Int, height: Int, factor: Int): ByteArray {
|
||||
val (even, odd) = DimDither.tables(factor)
|
||||
return remapColors(0, 0, width, height, even, odd)
|
||||
}
|
||||
|
||||
fun rawImage(width: Int, height: Int, pixels: ByteArray = ByteArray(((width + 1) / 2) * height)): ByteArray {
|
||||
require(width in 1..640 && height in 1..480 && pixels.size == ((width + 1) / 2) * height)
|
||||
val result = byteArrayOf(LARGE.toByte()) + word(width) + word(height) + pixels
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.pow
|
||||
|
||||
/**
|
||||
* Color-remap tables that dim the display by a light factor using a checkerboard dither.
|
||||
*
|
||||
* The panel's response looks roughly linear in light, so level 1 already emits 1/15 of full
|
||||
* brightness, and remapping each level to a single darker level has too little resolution
|
||||
* near black. A dimmed level 1 is either unchanged or gone. Instead each level maps to a
|
||||
* pair of adjacent levels, one for pixels with even x+y and one for odd x+y. That gives
|
||||
* half-step averages, e.g. level 1 becomes a 1/0 halftone.
|
||||
*/
|
||||
object DimDither {
|
||||
/** Relative light output of each level; replace with measurements if the panel isn't linear. */
|
||||
private val levelLight = DoubleArray(16) { it.toDouble() }
|
||||
|
||||
/** Half-step k shows ceil(k/2) on even pixels and floor(k/2) on odd ones. */
|
||||
private val halfStepLight = DoubleArray(31) { k -> (levelLight[(k + 1) / 2] + levelLight[k / 2]) / 2 }
|
||||
|
||||
/** Comparable perceived lightness (CIE L* is affine in the cube root at these levels). */
|
||||
private fun lightness(light: Double) = light.pow(1.0 / 3)
|
||||
|
||||
/**
|
||||
* Even- and odd-parity tables scaling light to factor256/256. Each level takes the half-step
|
||||
* perceptually nearest its dimmed light, never brighter than the original, and a visible
|
||||
* level keeps at least the 1/0 halftone.
|
||||
*/
|
||||
fun tables(factor256: Int): Pair<IntArray, IntArray> {
|
||||
require(factor256 in 0..256)
|
||||
val even = IntArray(16)
|
||||
val odd = IntArray(16)
|
||||
for (level in 1..15) {
|
||||
val target = lightness(levelLight[level] * factor256 / 256)
|
||||
val step = (1..2 * level).minBy { abs(lightness(halfStepLight[it]) - target) }
|
||||
even[level] = (step + 1) / 2
|
||||
odd[level] = step / 2
|
||||
}
|
||||
return even to odd
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -353,15 +353,17 @@ class DisplayListRenderer(
|
||||
val y = reader.readU16()
|
||||
val width = reader.readU16()
|
||||
val height = reader.readU16()
|
||||
val table = reader.readBytes(8)
|
||||
val tables = reader.readBytes(16)
|
||||
reader.requireDone()
|
||||
require(width > 0 && height > 0 && x + width <= target.width && y + height <= target.height)
|
||||
if (!walk.apply) return
|
||||
for (yy in y until y + height) for (xx in x until x + width) {
|
||||
if (xx + target.shiftX !in 0 until target.width) continue
|
||||
val value = target.get(xx + target.shiftX, yy)
|
||||
val tx = xx + target.shiftX
|
||||
if (tx !in 0 until target.width) continue
|
||||
val value = target.get(tx, yy)
|
||||
val shift = if (value % 2 == 0) 4 else 0
|
||||
target.put(xx, yy, (table[value / 2].toInt() ushr shift) and 15)
|
||||
// The even-parity table comes first; parity is of the shifted target pixel.
|
||||
target.put(xx, yy, (tables[((tx + yy) and 1) * 8 + value / 2].toInt() ushr shift) and 15)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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