BRT Community

Please login or register.

Login with username, password and session length
Advanced search  

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

Author Topic: BT81x -- used ASTC-Format  (Read 18402 times)

JuergenD

  • Newbie
  • *
  • Posts: 5
    • View Profile
BT81x -- used ASTC-Format
« on: April 26, 2019, 04:10:24 PM »

Hello,
as I understood, the ASTC-Format is a standard  Format, which is also used for different other GPUs, e.g. Nvidia, Andriods .

Is it necessary to use the 'original' Asset builder to convert Pictures to the ASTC-Format, used for BT81x or is it also possible to use ASTC-Pictures, directly generated from 3rd Party Tools?

In other words: does the ASTC-Format, which is used for the BT81x meet the Standards or is this a kind of propriatary format for the BT81x?

I am asking because I generated a ASTC pic, (of Course with the right Resolution and Format Settings) with a different tool and the binary, generated with this tool,  looked completely different to the pic, which was converted with the asset Manager. Header info looked completely different. (and is not working as expected)

Thank you


   
Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 770
    • View Profile
Re: BT81x -- used ASTC-Format
« Reply #1 on: April 29, 2019, 12:57:00 PM »

Hello,

In short, our EAB tool is using the ARM ASTC encoder to convert the PNG into ASTC blocks.  However, our EVE decoder assumes certain policy of ASTC block layout, it is called tile in 2x2.   Mentioned in the Programmers guide.

When there is an odd number of blocks on a line, the final two blocks are packed into a 1x2. When
there is an odd number of rows, then the final row of blocks is linear.
The diagram in section 6.1 of the programmers guide shows the same piece of memory loaded with ASTC blocks drawn with ascending memory addresses. The first column shows the addresses used by cell 0, the second column cell 1.

Best Regards,
BRT Community
Logged

JuergenD

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: BT81x -- used ASTC-Format
« Reply #2 on: April 30, 2019, 11:26:42 AM »

Hello,

thank you for your quick reply.

Unfortunately we have to use the ARM ASTC Encoder because this encoding must necessarily run on a Linux machine which feeds the content to an embedded device (which contains the BT81x)

The idea is to take the format, generated by the ARM Encoder, load it to the target  and convert it on the target before we load it to the BT Flash.
Means we have to write a converter for it, basically the same which you did in the Asset manager.

It would be very helpful for us to have some more Information about this conversion from the output, generated by the ARM ASTC Encoder to the format used by the BRT (and generated by the EAB Tool. It would save us a lot of time.

Could you provide us a code snippets for this conversation of this part of Code to get the ARM ASTC Output running on the BT81x?
Or maybe some more information or example?

Appreciate your help, thanks in advance.

Juergen
Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 770
    • View Profile
Re: BT81x -- used ASTC-Format
« Reply #3 on: May 02, 2019, 10:50:44 AM »

Hello,

Please have a look at the attached code snippet, written in python where the 'f' object is the output of the ARM ASTC encoder. This has a 16 byte header as follows:

Code: [Select]
struct astc_header { uint8_t magic [ 4 ];
uint8_t blockdim_x;
uint8_t blockdim_y;
uint8_t blockdim_z ;
uint8_t xsize [ 3 ];
uint8_t ysize [ 3 ];
uint8_t zsize [ 3 ]; };

Best Regards,
BRT Community
Logged

JuergenD

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: BT81x -- used ASTC-Format
« Reply #4 on: May 03, 2019, 08:13:48 AM »

Great, this is exactly what we need. Thank you
Logged

ubidefeo

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: BT81x -- used ASTC-Format
« Reply #5 on: 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
Code: [Select]
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
Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 770
    • View Profile
Re: BT81x -- used ASTC-Format
« Reply #6 on: June 27, 2024, 11:34:04 AM »

Hello ubidefeo,

Thank you for your post, and for asking! BRT has no issue with you including this code in your open source library, and we are grateful for your contribution to the EVE community. Hopefully your script is useful for other customers.

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
Code: [Select]
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

Best Regards,
BRT Community
Logged

ubidefeo

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: BT81x -- used ASTC-Format
« Reply #7 on: June 28, 2024, 05:37:29 AM »

Thank you so much  :)

u.
Logged