Fix transparency?

This commit is contained in:
2026-07-20 11:40:45 +05:00
parent eb13c87dd3
commit b9309e2326
4 changed files with 119 additions and 13 deletions

View File

@@ -104,8 +104,12 @@ int main(int argc, char **argv)
const char internal_url[] =
"data:text/html,<body style='background:rgb(3,5,7)'><div id='box'></div></body>";
const char transparent_css[] = "html,body{margin:0}"
"#box{position:fixed;inset:16px;background:rgba(255,0,0,.5)}";
const char transparent_css[] =
"html,body{margin:0}"
"#box{position:fixed;left:16px;top:16px;width:16px;height:16px;"
"background:rgb(241,23,17)}"
"#box:after{content:'';position:fixed;left:32px;top:32px;width:16px;"
"height:16px;background:rgba(255,0,0,.5)}";
const char opaque_css[] = "html,body{margin:0;background:rgb(7,19,31)!important}"
"#box{position:fixed;left:16px;top:16px;width:32px;height:32px;"
"background:rgb(241,23,17);transform:translateZ(0);filter:blur(.1px)}";
@@ -136,6 +140,7 @@ int main(int argc, char **argv)
write_exact(control[0], css, strlen(css));
uint8_t last_bgra[4] = {0};
uint8_t last_corner_bgra[4] = {0};
uint8_t last_half_bgra[4] = {0};
bool found_red = false;
int max_attempts = external_url ? 120 : 60;
for (int attempt = 0; sent && attempt < max_attempts; attempt++) {
@@ -168,10 +173,15 @@ int main(int argc, char **argv)
continue;
}
size_t center = zoom ? ((size_t)5 * width + 15) * 4
: ((size_t)(height / 2) * width + width / 2) * 4;
: opaque ? ((size_t)(height / 2) * width + width / 2) * 4
: ((size_t)24 * width + 24) * 4;
memcpy(last_bgra, frame + center, sizeof(last_bgra));
size_t corner = zoom ? ((size_t)5 * width + 25) * 4 : 0;
memcpy(last_corner_bgra, frame + corner, sizeof(last_corner_bgra));
if (!zoom && !opaque) {
size_t half = ((size_t)40 * width + 40) * 4;
memcpy(last_half_bgra, frame + half, sizeof(last_half_bgra));
}
bool expected = zoom
? last_bgra[0] < 32 && last_bgra[1] < 40 && last_bgra[2] > 210 &&
last_bgra[3] == 255 && last_corner_bgra[0] > 20 &&
@@ -180,8 +190,10 @@ int main(int argc, char **argv)
: opaque
? last_bgra[0] < 32 && last_bgra[1] < 40 && last_bgra[2] > 210 &&
last_bgra[3] == 255
: last_bgra[0] < 8 && last_bgra[1] < 8 && last_bgra[2] > 248 &&
last_bgra[3] > 120 && last_bgra[3] < 136 &&
: last_bgra[0] < 32 && last_bgra[1] < 40 && last_bgra[2] > 225 &&
last_bgra[3] == 255 && last_half_bgra[0] < 8 &&
last_half_bgra[1] < 8 && last_half_bgra[2] > 248 &&
last_half_bgra[3] > 120 && last_half_bgra[3] < 136 &&
last_corner_bgra[0] == 0 && last_corner_bgra[1] == 0 &&
last_corner_bgra[2] == 0 && last_corner_bgra[3] == 0;
if (expected) {
@@ -207,10 +219,12 @@ int main(int argc, char **argv)
}
fprintf(stderr,
"renderer did not produce the expected %s red BGRA frame "
"(center BGRA=%u,%u,%u,%u; corner BGRA=%u,%u,%u,%u)\n",
"(center BGRA=%u,%u,%u,%u; half BGRA=%u,%u,%u,%u; "
"corner BGRA=%u,%u,%u,%u)\n",
zoom ? "200%-zoomed" : opaque ? "opaque" : "transparent",
last_bgra[0], last_bgra[1],
last_bgra[2], last_bgra[3], last_corner_bgra[0], last_corner_bgra[1],
last_bgra[2], last_bgra[3], last_half_bgra[0], last_half_bgra[1],
last_half_bgra[2], last_half_bgra[3], last_corner_bgra[0], last_corner_bgra[1],
last_corner_bgra[2], last_corner_bgra[3]);
return 1;
}