Run macOS applications on your Windows desktop, with a background runtime and integrated app windows.
C++
#pragma once
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstddef>
namespace wsm::runtime {
// Clip premultiplied BGRA geometrically. The pixels outside a Mac window can
// belong to another app, so a desktop-colour key cannot identify its corners.
inline void round_window_pixels(uint8_t* pixels, int width, int height, double radius) {
if (!pixels || width <= 0 || height <= 0) return;
radius = std::clamp(radius, 0.0, std::min(width, height) / 2.0);
if (radius < 1) return;
const int extent = static_cast<int>(std::ceil(radius));
for (int y = 0; y < extent; ++y) for (int x = 0; x < extent; ++x) {
const double dx = radius - x - 0.5, dy = radius - y - 0.5;
const double coverage = std::clamp(radius + 0.5 - std::sqrt(dx * dx + dy * dy), 0.0, 1.0);
if (coverage >= 1) continue;
const int xs[] = {x, width - 1 - x}, ys[] = {y, height - 1 - y};
for (int yy : ys) for (int xx : xs) {
auto p = pixels + (static_cast<size_t>(yy) * width + xx) * 4;
for (int c = 0; c < 4; ++c) p[c] = static_cast<uint8_t>(p[c] * coverage + 0.5);
}
}
}
}