News:

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

Main Menu
Menu

Show posts

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

Messages - ubidefeo

#1
Discussion - EVE / Re: BT81x -- used ASTC-Format
June 28, 2024, 05:37:29 AM
Thank you so much  :)

u.
#2
Discussion - EVE / Re: BT81x -- used ASTC-Format
June 27, 2024, 10:40:53 AM
hi everyone

I know this is an old topic, but the Python script really helped us figure out a few things.
Could this code be used in an open-source library we're working on for Python/MicroPython?

I'd like to have a confirmation.
Also I made a couple fixes to the script because it failed on assert.
Also added file save as .raw

I'm sure others will look for a solution to this, and seeing code in the forum would be way more helpful than having to signup and be able to see a picture as an attachment
That definitely took me a while :D

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])





  • use astcenc to encode the file into astc
  • run the python script passing in the output astc file as an argument