Thank you so much 
u.

u.
Welcome to the Bridgetek Community!
Please read our Welcome Note
Technical Support enquires
please contact the team @ Bridgetek Support
Please refer to our website for detailed information on all our products - Bridgetek - Bridging Technology
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
import struct, sys, math
def tile(f):
# Unpack the header information
(_, w, h, _, iw, _, ih, _, _, _) = struct.unpack("<IBBBHBHBHB", f.read(16))
print(_, w, h, _, iw, _, ih, _, _, _)
# Calculate block width (bw) and block height (bh)
bw = math.ceil(iw / w)
bh = math.ceil(ih / h)
print(bw, bh)
# Read the rest of the file
d = f.read()
return (bw, bh, tile2(d, bw, bh))
def tile2(d, bw, bh):
print(len(d))
print(16 * bw * bh)
# Assertion to check if the data length matches expected length
assert len(d) == 16 * bw * bh, "Data length does not match expected length"
# Split the data into 16-byte chunks
fe = [d[i:i+16] for i in range(0, len(d), 16)]
# Assertion to check if the number of chunks matches expected number of blocks
assert len(fe) == bw * bh, "Number of chunks does not match expected number of blocks"
r = []
# Nested loops to rearrange the data
for j in range(0, bh - 1, 2):
for i in range(0, bw, 2):
if i < (bw - 1):
r += [
fe[bw * j + i],
fe[bw * (j + 1) + i],
fe[bw * (j + 1) + (i + 1)],
fe[bw * j + (i + 1)]
]
if bw % 2 != 0:
r += [fe[bw * j + (bw - 1)], fe[bw * (j + 1) + (bw - 1)]]
if bh % 2 != 0:
r += fe[bw * (bh - 1):]
print(len(r))
# Assertion to check if the rearranged data length matches expected length
assert len(r) == bw * bh, "Rearranged data length does not match expected length"
return b"".join(r) # Join the list into bytes
if __name__ == '__main__':
f_name = sys.argv[1]
print('main', f_name)
image_bytes = None
with open(f_name, 'rb') as f_resource:
image_bytes = tile(f_resource)
print(image_bytes[2])
# print(image_bytes)
output_image = f'./{f_name.split(".")[0]}_astc_6x6.raw'
with open(output_image, 'wb') as f_output:
f_output.write(image_bytes[2])