INNER CODE UNIT · Python

generate_dmg_background

dddevid/Musly · tools/generate_dmg_background.py:6

def generate_dmg_background(out_path="packaging/macos/dmg_background.png"):
    # Target window dimensions: 660 x 400 points
    # In macOS Finder, a 660x400 px image with 72 DPI maps 1:1 to a 660x400 window
    w, h = 660, 400
    
    img = bytearray(w * h * 4)
    
    def set_pixel(x, y, r, g, b, a):
        if 0 <= x < w and 0 <= y < h:
            idx = (y * w + x) * 4
            src_a = a / 255.0
            dst_a = img[idx + 3] / 255.0
            out_a = src_a + dst_a * (1.0 - src_a)
            if out_a > 0:
                out_r = int((r * src_a + img[idx] * dst_a * (1.0 - src_a)) / out_a)
                out_g = int((g * src_a + img[idx + 1] * dst_a * (1.0 - src_a)) / out_a)
                out_b = int((b * src_a + img[idx + 2] * dst_a * (1.0 - src_a)) / out_a)
                img[idx] = min(255, max(0, out_r))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…