Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ resolution | description
1024x768 | resizing the 640x480 image and using it again.
720x720 | images worked on by @duncanyoyo1, @vidnez, @anbernic
1280x720 | This image is pre-applied by crossmix.
960x720 | images worked on by @kk&66.
854x480 | not defined
720x480 | images worked on by @tamarindojuice.
480x320 | not defined
Expand Down Expand Up @@ -119,6 +120,35 @@ example <br>
"screen1_h":384
},
~~~

#### Alpha Channel Support

Background images now include alpha transparency channels to enable bezel overlays that can be superimposed on game screens as masks. The screen areas defined in `layout.json` are made transparent (alpha = 0), allowing the game content to show through while displaying the bezel/frame around the screens.

#### Automated Processing Script

`nd_bezel_process.py` is a Python script that automatically processes PNG images to add alpha transparency to screen areas based on `layout.json` configuration.

**Usage:**
```bash
# Process images in the default bg directory
python3 nd_bezel_process.py

# Process images in a specific directory
python3 nd_bezel_process.py /path/to/bg/directory
```

**Requirements:**
- Python 3.x
- Pillow library: `pip install Pillow`

**What it does:**
- Reads `layout.json` configuration for each resolution
- Converts images to RGBA format if needed
- Makes screen0 and screen1 areas transparent based on coordinates
- Handles rotation (90°, 270°) for vertical layouts
- Overwrites the original PNG files with transparency added

I'm not good at graphics work tools, so I'm always welcome to reflect on this git hub after someone changes the bg image.

[Support for devices or assistance in purchasing devices is always welcome.](https://ko-fi.com/trngaje) <br>
Expand Down
Binary file modified bg/1024x768/1/bg_h1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/1/bg_hh0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/1/bg_v1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/1/bg_vh_s0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/1/bg_vh_s2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/2/bg_h1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/2/bg_hh0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/2/bg_v1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/2/bg_vh_s0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/2/bg_vh_s2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/3/bg_h1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/3/bg_hh0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/3/bg_v1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/3/bg_vh_s0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/3/bg_vh_s2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/4/bg_h1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/4/bg_hh0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/4/bg_v1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/4/bg_vh_s0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/4/bg_vh_s2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/5/bg_h1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/5/bg_hh0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/5/bg_v1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/5/bg_vh_s0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/5/bg_vh_s2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bg/1024x768/6/bg_h1.png
Binary file modified bg/1024x768/6/bg_hh0.png
Binary file modified bg/1024x768/6/bg_v1.png
Binary file modified bg/1024x768/6/bg_vh_s0.png
Binary file modified bg/1024x768/6/bg_vh_s2.png
Binary file modified bg/1024x768/7/bg_h1.png
Binary file modified bg/1024x768/7/bg_hh0.png
Binary file modified bg/1024x768/7/bg_v1.png
Binary file modified bg/1024x768/7/bg_vh_s0.png
Binary file modified bg/1024x768/7/bg_vh_s2.png
Binary file modified bg/1024x768/8/bg_h1.png
Binary file modified bg/1024x768/8/bg_hh0.png
Binary file modified bg/1024x768/8/bg_v1.png
Binary file modified bg/1024x768/8/bg_vh_s0.png
Binary file modified bg/1024x768/8/bg_vh_s2.png
Binary file modified bg/1024x768/9/bg_h1.png
Binary file modified bg/1024x768/9/bg_hh0.png
Binary file modified bg/1024x768/9/bg_v1.png
Binary file modified bg/1024x768/9/bg_vh_s0.png
Binary file modified bg/1024x768/9/bg_vh_s2.png
Binary file added bg/1280x720/1/bg_vertical.png
Binary file added bg/1280x720/1/bg_vertical_ext.png
57 changes: 57 additions & 0 deletions bg/1920x1080/layout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name":"kk",
"number":2,
"layout":[
{
"index":0,
"name":"vh_t0",
"bg":"",
"type":1,

"screen0_x":0,
"screen0_y":0,
"screen0_w":256,
"screen0_h":192,

"screen1_x":0,
"screen1_y":0,
"screen1_w":1024,
"screen1_h":768
},
{
"index":1,
"name":"vh_t1",
"bg":"",
"type":1,

"screen0_x":0,
"screen0_y":0,
"screen0_w":512,
"screen0_h":384,

"screen1_x":0,
"screen1_y":0,
"screen1_w":1024,
"screen1_h":768
},

{
"index":2,
"name":"s1",
"bg":"",
"type":1,

"screen0_x":0,
"screen0_y":0,
"screen0_w":0,
"screen0_h":0,

"screen1_x":0,
"screen1_y":0,
"screen1_w":1024,
"screen1_h":768
},
]

}

62 changes: 62 additions & 0 deletions bg/1920x1200/layout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "1080p Default",
"number": 4,
"layout": [
{
"index": 0,
"type": 0,
"name": "Normal (2DS)",
"bg": "",
"screen0_x": 64,
"screen0_y": 60,
"screen0_w": 1280,
"screen0_h": 960,
"screen1_x": 1408,
"screen1_y": 372,
"screen1_w": 448,
"screen1_h": 336
},
{
"index": 1,
"type": 0,
"name": "Vertical",
"bg": "",
"screen0_x": 600,
"screen0_y": 0,
"screen0_w": 720,
"screen0_h": 540,
"screen1_x": 600,
"screen1_y": 540,
"screen1_w": 720,
"screen1_h": 540
},
{
"index": 2,
"type": 0,
"name": "Top Full",
"bg": "",
"screen0_x": 0,
"screen0_y": 0,
"screen0_w": 1440,
"screen0_h": 1080,
"screen1_x": 1440,
"screen1_y": 360,
"screen1_w": 480,
"screen1_h": 360
},
{
"index": 3,
"type": 0,
"name": "Transparent",
"bg": "",
"screen0_x": 0,
"screen0_y": 60,
"screen0_w": 1280,
"screen0_h": 960,
"screen1_x": 1280,
"screen1_y": 300,
"screen1_w": 640,
"screen1_h": 480
},
]
}
Binary file modified bg/640x480/1/bg_h0.png
Binary file modified bg/640x480/1/bg_h1.png
Binary file modified bg/640x480/1/bg_hh0.png
Binary file modified bg/640x480/1/bg_hres0.png
Binary file modified bg/640x480/1/bg_s0.png
Binary file modified bg/640x480/1/bg_v0.png
Binary file modified bg/640x480/1/bg_v1.png
Binary file modified bg/640x480/1/bg_vh_c0.png
Binary file modified bg/640x480/1/bg_vh_c1.png
Binary file modified bg/640x480/1/bg_vh_s0.png
Binary file modified bg/640x480/1/bg_vh_s1.png
Binary file modified bg/640x480/1/bg_vh_s2.png
Binary file modified bg/640x480/2/bg_h0.png
Binary file modified bg/640x480/2/bg_h1.png
Binary file modified bg/640x480/2/bg_hh0.png
Binary file modified bg/640x480/2/bg_hres0.png
Binary file modified bg/640x480/2/bg_s0.png
Binary file modified bg/640x480/2/bg_v0.png
Binary file modified bg/640x480/2/bg_v1.png
Binary file modified bg/640x480/2/bg_vh_c0.png
Binary file modified bg/640x480/2/bg_vh_c1.png
Binary file modified bg/640x480/2/bg_vh_s0.png
Binary file modified bg/640x480/2/bg_vh_s1.png
Binary file modified bg/640x480/2/bg_vh_s2.png
Binary file modified bg/640x480/3/bg_h0.png
Binary file modified bg/640x480/3/bg_h1.png
Binary file modified bg/640x480/3/bg_hh0.png
Binary file modified bg/640x480/3/bg_hres0.png
Binary file modified bg/640x480/3/bg_s0.png
Binary file modified bg/640x480/3/bg_v0.png
Binary file modified bg/640x480/3/bg_v1.png
Binary file modified bg/640x480/3/bg_vh_c0.png
Binary file modified bg/640x480/3/bg_vh_c1.png
Binary file modified bg/640x480/3/bg_vh_s0.png
Binary file modified bg/640x480/3/bg_vh_s1.png
Binary file modified bg/640x480/3/bg_vh_s2.png
Binary file modified bg/640x480/4/bg_h0.png
Binary file modified bg/640x480/4/bg_h1.png
Binary file modified bg/640x480/4/bg_hh0.png
Binary file modified bg/640x480/4/bg_hres0.png
Binary file modified bg/640x480/4/bg_s0.png
Binary file modified bg/640x480/4/bg_v0.png
Binary file modified bg/640x480/4/bg_v1.png
Binary file modified bg/640x480/4/bg_vh_c0.png
Binary file modified bg/640x480/4/bg_vh_c1.png
Binary file modified bg/640x480/4/bg_vh_s0.png
Binary file modified bg/640x480/4/bg_vh_s1.png
Binary file modified bg/640x480/4/bg_vh_s2.png
Binary file modified bg/640x480/5/bg_h0.png
Binary file modified bg/640x480/5/bg_h1.png
Binary file modified bg/640x480/5/bg_hh0.png
Binary file modified bg/640x480/5/bg_hres0.png
Binary file modified bg/640x480/5/bg_s0.png
Binary file modified bg/640x480/5/bg_v0.png
Binary file modified bg/640x480/5/bg_v1.png
Binary file modified bg/640x480/5/bg_vh_c0.png
Binary file modified bg/640x480/5/bg_vh_c1.png
Binary file modified bg/640x480/5/bg_vh_s0.png
Binary file modified bg/640x480/5/bg_vh_s1.png
Binary file modified bg/640x480/5/bg_vh_s2.png
Binary file modified bg/640x480/6/bg_h0.png
Binary file modified bg/640x480/6/bg_h1.png
Binary file modified bg/640x480/6/bg_hh0.png
Binary file modified bg/640x480/6/bg_hres0.png
Binary file modified bg/640x480/6/bg_s0.png
Binary file modified bg/640x480/6/bg_v0.png
Binary file modified bg/640x480/6/bg_v1.png
Binary file modified bg/640x480/6/bg_vh_c0.png
Binary file modified bg/640x480/6/bg_vh_c1.png
Binary file modified bg/640x480/6/bg_vh_s0.png
Binary file modified bg/640x480/6/bg_vh_s1.png
Binary file modified bg/640x480/6/bg_vh_s2.png
Binary file modified bg/640x480/7/bg_h0.png
Binary file modified bg/640x480/7/bg_h1.png
Binary file modified bg/640x480/7/bg_hh0.png
Binary file modified bg/640x480/7/bg_hres0.png
Binary file modified bg/640x480/7/bg_s0.png
Binary file modified bg/640x480/7/bg_v0.png
Binary file modified bg/640x480/7/bg_v1.png
Binary file modified bg/640x480/7/bg_vh_c0.png
Binary file modified bg/640x480/7/bg_vh_c1.png
Binary file modified bg/640x480/7/bg_vh_s0.png
Binary file modified bg/640x480/7/bg_vh_s1.png
Binary file modified bg/640x480/7/bg_vh_s2.png
Binary file modified bg/640x480/8/bg_h0.png
Binary file modified bg/640x480/8/bg_h1.png
Binary file modified bg/640x480/8/bg_hh0.png
Binary file modified bg/640x480/8/bg_hres0.png
Binary file modified bg/640x480/8/bg_s0.png
Binary file modified bg/640x480/8/bg_v0.png
Binary file modified bg/640x480/8/bg_v1.png
Binary file modified bg/640x480/8/bg_vh_c0.png
Binary file modified bg/640x480/8/bg_vh_c1.png
Binary file modified bg/640x480/8/bg_vh_s0.png
Binary file modified bg/640x480/8/bg_vh_s1.png
Binary file modified bg/640x480/8/bg_vh_s2.png
Binary file modified bg/640x480/9/bg_h0.png
Binary file modified bg/640x480/9/bg_h1.png
Binary file modified bg/640x480/9/bg_hh0.png
Binary file modified bg/640x480/9/bg_hres0.png
Binary file modified bg/640x480/9/bg_s0.png
Binary file modified bg/640x480/9/bg_v0.png
Binary file modified bg/640x480/9/bg_v1.png
Binary file modified bg/640x480/9/bg_vh_c0.png
Binary file modified bg/640x480/9/bg_vh_c1.png
Binary file modified bg/640x480/9/bg_vh_s0.png
Binary file modified bg/640x480/9/bg_vh_s1.png
Binary file modified bg/640x480/9/bg_vh_s2.png
Binary file modified bg/720x480/1/bg_h0.png
Binary file modified bg/720x480/1/bg_h1.png
Binary file modified bg/720x480/1/bg_s0.png
Binary file modified bg/720x480/1/bg_v0.png
Binary file modified bg/720x480/1/bg_v1.png
Binary file modified bg/720x480/1/bg_vh_c0.png
Binary file modified bg/720x480/1/bg_vh_s0.png
Binary file modified bg/720x480/1/bg_vh_s1.png
Binary file modified bg/720x480/2/bg_h0.png
Binary file modified bg/720x480/2/bg_h1.png
Binary file modified bg/720x480/2/bg_s0.png
Binary file modified bg/720x480/2/bg_v0.png
Binary file modified bg/720x480/2/bg_v1.png
Binary file modified bg/720x480/2/bg_vh_c0.png
Binary file modified bg/720x480/2/bg_vh_s0.png
Binary file modified bg/720x480/2/bg_vh_s1.png
Binary file modified bg/720x720/1/bg_h0.png
Binary file modified bg/720x720/1/bg_h1.png
Binary file modified bg/720x720/1/bg_hh0.png
Binary file modified bg/720x720/1/bg_hres0.png
Binary file modified bg/720x720/1/bg_s0.png
Binary file modified bg/720x720/1/bg_v0.png
Binary file modified bg/720x720/1/bg_v1.png
Binary file modified bg/720x720/1/bg_vh_c1.png
Binary file modified bg/720x720/1/bg_vh_s2.png
Binary file modified bg/720x720/2/bg_h0.png
Binary file modified bg/720x720/2/bg_h1.png
Binary file modified bg/720x720/2/bg_hh0.png
Binary file modified bg/720x720/2/bg_hres0.png
Binary file modified bg/720x720/2/bg_s0.png
Binary file modified bg/720x720/2/bg_v0.png
Binary file modified bg/720x720/2/bg_v1.png
Binary file modified bg/720x720/2/bg_vh_c1.png
Binary file modified bg/720x720/2/bg_vh_s2.png
11 changes: 6 additions & 5 deletions bg/720x720/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,16 @@
{
"index":9,
"name":"vh_c1",
"bg":"",
"bg":"bg_vh_c1.png",
"rotate":90,

"screen0_x":104,
"screen0_y":0,
"screen0_y":104,
"screen0_x":0,
"screen0_w":512,
"screen0_h":384,

"screen1_x":136,
"screen1_y":384,
"screen1_y":136,
"screen1_x":384,
"screen1_w":448,
"screen1_h":336
},
Expand Down
Binary file added bg/960x720/1/bg_vertical.png
Binary file added bg/960x720/1/bg_vertical_2ds.png
Binary file added bg/960x720/1/bg_vertical_ext.png
Binary file added bg/960x720/1/bg_vertical_full.png
1 change: 1 addition & 0 deletions bg/960x720/layout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "kk&66", "number": 7, "layout": [{"index": 0, "name": "2ds", "bg": "bg_vertical_2ds.png", "type": 1, "screen0_x": 215, "screen0_y": 0, "screen0_w": 512, "screen0_h": 384, "screen1_x": 279, "screen1_y": 431, "screen1_w": 384, "screen1_h": 288}, {"index": 1, "name": "v_ori", "bg": "bg_vertical.png", "type": 1, "screen0_x": 180, "screen0_y": 0, "screen0_w": 360, "screen0_h": 270, "screen1_x": 180, "screen1_y": 270, "screen1_w": 360, "screen1_h": 270}, {"index": 2, "name": "top_full", "bg": "bg_vertical_full.png", "type": 1, "screen0_x": 96, "screen0_y": 0, "screen0_w": 768, "screen0_h": 576, "screen1_x": 384, "screen1_y": 576, "screen1_w": 192, "screen1_h": 144}, {"index": 3, "name": "top_conn_bottom", "bg": "bg_vertical_ext.png", "type": 1, "screen0_x": 128, "screen0_y": 0, "screen0_w": 704, "screen0_h": 528, "screen1_x": 352, "screen1_y": 528, "screen1_w": 256, "screen1_h": 192}, {"index": 4, "name": "h_single", "bg": "bg_horizon_single.png", "type": 3, "screen0_x": 0, "screen0_y": 0, "screen0_w": 960, "screen0_h": 720, "screen1_x": 0, "screen1_y": 0, "screen1_w": 0, "screen1_h": 0}, {"index": 5, "name": "transparent", "bg": "", "type": 3, "screen0_x": 0, "screen0_y": 0, "screen0_w": 960, "screen0_h": 720, "screen1_x": 704, "screen1_y": 0, "screen1_w": 256, "screen1_h": 192}, {"index": 6, "name": "menu", "bg": "bg_menu.png", "type": 4, "screen0_x": 0, "screen0_y": 0, "screen0_w": 800, "screen0_h": 480, "screen1_x": 0, "screen1_y": 0, "screen1_w": 720, "screen1_h": 720}]}
137 changes: 137 additions & 0 deletions nd_bezel_process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/usr/bin/env python3
import json
import os
import sys
import argparse
from pathlib import Path
from PIL import Image

def process_bezel_images(base_path):
"""Process NDS bezel images, make screen areas transparent based on layout.json"""

nds_bg_path = Path(base_path)

# Iterate through all resolution directories
for res_dir in nds_bg_path.iterdir():
if not res_dir.is_dir():
continue

print(f"\nProcessing resolution directory: {res_dir.name}")

layout_json_path = res_dir / "layout.json"
if not layout_json_path.exists():
print(f" Skipping: layout.json not found")
continue

# Read layout.json
with open(layout_json_path, 'r', encoding='utf-8') as f:
content = f.read()
# Fix JSON format issues: remove trailing commas
import re
content = re.sub(r',\s*}', '}', content) # Trailing comma in object
content = re.sub(r',\s*\]', ']', content) # Trailing comma in array
layout_data = json.loads(content)

# Iterate through all numeric subdirectories (themes)
for theme_dir in res_dir.iterdir():
if not theme_dir.is_dir() or not theme_dir.name.isdigit():
continue

print(f" Processing theme: {theme_dir.name}")

# Create (name, bg) to layout_item mapping
layout_map = {}
for layout_item in layout_data.get("layout", []):
bg_filename = layout_item.get("bg", "")
name = layout_item.get("name", "")
if bg_filename and name:
key = (name, bg_filename)
layout_map[key] = layout_item

# Get all PNG files in theme directory
for img_file in theme_dir.glob("*.png"):
img_filename = img_file.name

# Find matching layouts (need to match both name and bg)
matching_keys = [key for key in layout_map.keys() if key[1] == img_filename]

if not matching_keys:
continue # No matching layout found

# Process corresponding image for each matching key
for (name, bg_filename), layout_item in layout_map.items():
if bg_filename != img_filename:
continue

# Find the image file
img_path = theme_dir / bg_filename
if not img_path.exists():
print(f" Skipping: {bg_filename} not found")
continue

# Open image
try:
img = Image.open(img_path)

# Ensure image has alpha channel
if img.mode != 'RGBA':
img = img.convert('RGBA')

# Check for rotate attribute
rotate_angle = layout_item.get("rotate", 0)

# Get image dimensions
width, height = img.size
pixels = img.load()

# Process screen0 area
screen0_x = layout_item.get("screen0_x", 0)
screen0_y = layout_item.get("screen0_y", 0)
screen0_w = layout_item.get("screen0_w", 0)
screen0_h = layout_item.get("screen0_h", 0)

# Swap w and h if rotated
if rotate_angle in [90, 270]:
screen0_w, screen0_h = screen0_h, screen0_w

if screen0_w > 0 and screen0_h > 0:
for sy in range(screen0_y, screen0_y + screen0_h):
for sx in range(screen0_x, screen0_x + screen0_w):
if 0 <= sy < height and 0 <= sx < width:
pixels[sx, sy] = (0, 0, 0, 0)

# Process screen1 area
screen1_x = layout_item.get("screen1_x", 0)
screen1_y = layout_item.get("screen1_y", 0)
screen1_w = layout_item.get("screen1_w", 0)
screen1_h = layout_item.get("screen1_h", 0)

# Swap w and h if rotated
if rotate_angle in [90, 270]:
screen1_w, screen1_h = screen1_h, screen1_w

if screen1_w > 0 and screen1_h > 0:
for sy in range(screen1_y, screen1_y + screen1_h):
for sx in range(screen1_x, screen1_x + screen1_w):
if 0 <= sy < height and 0 <= sx < width:
pixels[sx, sy] = (0, 0, 0, 0)

# Save image
img.save(img_path, "PNG")
print(f" Processed: {bg_filename} (name: {name}, rotate: {rotate_angle})")

# Remove from map after processing to avoid duplicate processing
del layout_map[(name, bg_filename)]
break # Process each layout only once

except Exception as e:
print(f" Error: {bg_filename} - {e}")

if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Process NDS bezel images, make screen areas transparent based on layout.json')
parser.add_argument('path', help='Directory path containing layout.json and images', nargs='?', default='/mnt/e/bezels/nds/bg')

args = parser.parse_args()

process_bezel_images(args.path)
print("\nProcessing complete!")