| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- """Pixel-analysis of the gameupdate window screenshot to find button regions.
- Buttons in Chinese game launchers are distinct-colored rectangles. Detect:
- 1. Horizontal color bands distinct from background
- 2. Rectangular regions of uniform color
- Then print candidate click coordinates (client coords).
- """
- from pathlib import Path
- from PIL import Image
- img = Image.open("gameupdate2.png").convert("RGB")
- w, h = img.size
- print(f"image: {w}x{h}")
- # 1. Sample a color histogram (quantized) to find dominant + accent colors
- colors: dict[tuple[int, int, int], int] = {}
- px = img.load()
- for y in range(0, h, 2):
- for x in range(0, w, 2):
- c = px[x, y]
- q = (c[0] // 32, c[1] // 32, c[2] // 32)
- colors[q] = colors.get(q, 0) + 1
- total = sum(colors.values())
- print("\ntop colors (quantized to 32):")
- for c, n in sorted(colors.items(), key=lambda kv: -kv[1])[:8]:
- print(f" RGB~({c[0]*32},{c[1]*32},{c[2]*32}) {n/total:.1%}")
- # 2. Row bands: average color per row → find rows that differ from neighbors (button rows)
- print("\nrow bands (rows where avg color changes sharply):")
- prev = None
- for y in range(h):
- rs = gs = bs = 0
- for x in range(0, w, 4):
- r, g, b = px[x, y]
- rs += r; gs += g; bs += b
- n = max(1, w // 4)
- avg = (rs // n, gs // n, bs // n)
- if prev and (abs(avg[0]-prev[0]) + abs(avg[1]-prev[1]) + abs(avg[2]-prev[2]) > 60):
- print(f" y={y}: {prev} -> {avg}")
- prev = avg
- # 3. Detect bright/saturated rectangles (buttons are usually brightest or most saturated)
- print("\nsaturated/bright pixel clusters (candidate buttons):")
- from collections import defaultdict
- clusters = defaultdict(int)
- for y in range(0, h, 3):
- for x in range(0, w, 3):
- r, g, b = px[x, y]
- sat = max(r, g, b) - min(r, g, b)
- bright = (r + g + b) / 3
- if sat > 80 or bright > 200: # strongly colored or very bright
- clusters[(x // 40, y // 40)] += 1
- # find dense clusters
- dense = sorted(clusters.items(), key=lambda kv: -kv[1])[:10]
- if dense:
- for (cx, cy), n in dense:
- # cluster center in client coords
- x = cx * 40 + 20
- y = cy * 40 + 20
- print(f" cluster @ ({x},{y}) density={n}")
- else:
- print(" no saturated clusters; window may be grayscale/gray button")
- # 4. Dump a coarse ASCII map of brightness to see the layout
- print("\nbrightness map (#=dark, .=light), 8px cells:")
- for y in range(0, h, 8):
- row = ""
- for x in range(0, w, 8):
- r, g, b = px[x, y]
- v = (r + g + b) / 3
- row += "#" if v < 80 else ("+" if v < 160 else ".")
- print(f" {y:3d} {row}")
|