#!/usr/bin/env python3 """Bagimsiz PNG dogrulama -- PIL/Pillow olmadan, stdlib zlib+struct ile. Bir alt-ajanin (ImageArtist vb.) ürettigi sprite PNG'sini, o ajanin kendi raporuna guvenmeden dogrulamak icin kullan: boyut, renk modu (RGBA mi), fiili benzersiz opak renk sayisi, ve kenar yumusatma (AA) icin kullanilan yari-saydam (alpha 0I', data[pos:pos + 4])[0] ctype = data[pos + 4:pos + 8] chunk = data[pos + 8:pos + 8 + length] if ctype == b'IHDR': width, height, bitdepth, colortype = struct.unpack('>IIBB', chunk[:10]) elif ctype == b'IDAT': idat += chunk pos += 8 + length + 4 raw = zlib.decompress(idat) bpp = 4 if colortype == 6 else 3 stride = width * bpp pixels = [] prev = bytearray(stride) i = 0 for _y in range(height): ftype = raw[i] i += 1 line = bytearray(raw[i:i + stride]) i += stride for x in range(stride): a = line[x - bpp] if x >= bpp else 0 b = prev[x] c = prev[x - bpp] if x >= bpp else 0 if ftype == 0: val = line[x] elif ftype == 1: val = (line[x] + a) & 0xFF elif ftype == 2: val = (line[x] + b) & 0xFF elif ftype == 3: val = (line[x] + (a + b) // 2) & 0xFF elif ftype == 4: p = a + b - c pa, pb, pc = abs(p - a), abs(p - b), abs(p - c) pr = a if pa <= pb and pa <= pc else (b if pb <= pc else c) val = (line[x] + pr) & 0xFF else: val = line[x] line[x] = val prev = line for x in range(0, stride, bpp): pixels.append(tuple(line[x:x + bpp])) return width, height, colortype, pixels def summarize(width, height, pixels): opaque = [p for p in pixels if len(p) < 4 or p[3] == 255] opaque_colors = Counter(opaque) alpha_hist = Counter(p[3] for p in pixels if len(p) == 4) print(f"size: {width}x{height}") print(f"opaque unique colors: {len(opaque_colors)}") for c, n in opaque_colors.most_common(): print(f" {c} #%02x%02x%02x n={n}" % (c[0], c[1], c[2])) print(f"alpha histogram (AA/transparency check): {dict(sorted(alpha_hist.items()))}") return opaque_colors, alpha_hist if __name__ == '__main__': p = sys.argv[1] w, h, ct, pix = decode_png(p) print(f"colortype={ct} (6=RGBA, 2=RGB)") summarize(w, h, pix)