import struct def decode_scanline(data, width, max_rows=100000): i = 0 n = len(data) rows = 0 row_len = 0 while i < n: if row_len >= width: rows += 1 row_len = 0 if rows > max_rows: return rows, i, False continue b = data[i] if (b & 0xC0) == 0xC0: count = b & 0x3F i += 1 if i >= n: return rows, i, False i += 1 need = width - row_len take = min(count, need) row_len += take else: row_len += 1 i += 1 if row_len == 0: return rows, i, True else: rows += 1 # partial return rows, i, False base = "/home/aria/kellogg_remake/extracted_pre/" files = ["B.BOB","E.BOB","N.BOB","O.BOB","A.BOB","J.BOB","K.BOB","D.BOB"] for fn in files: data = open(base+fn, "rb").read() n = len(data) print(f"=== {fn} size={n} ===") found_any = False for headerlen in range(0, 17, 1): if headerlen % 2 != 0: continue header = data[:headerlen] body = data[headerlen:] num_u16 = headerlen // 2 u16s = struct.unpack(f"<{num_u16}H", header) if headerlen else () # try every pair (w_idx, h_idx) among header u16 fields as (width,height) candidates for wi in range(num_u16): w = u16s[wi] if w < 2 or w > 400: continue rows, consumed, ok = decode_scanline(body, w) if ok: # check if any header u16 equals rows (=height) match_h = [hi for hi,val in enumerate(u16s) if val == rows] print(f" headerlen={headerlen} width_idx={wi} width={w} -> rows={rows} clean=True header_u16={u16s} height_field_match_idx={match_h}") found_any = True if not found_any: print(" (no clean header+width combo found in range)")