Port C fread (& struct, ....) in Python

Hey, I'm really struggling with this. I am trying to port a small piece of code to another Python code, and this is what I have:

typedef struct
{
  uint8_t Y[LUMA_HEIGHT][LUMA_WIDTH];
  uint8_t Cb[CHROMA_HEIGHT][CHROMA_WIDTH];
  uint8_t Cr[CHROMA_HEIGHT][CHROMA_WIDTH];
} __attribute__((__packed__)) frame_t;

frame_t frame;

 while (! feof(stdin))
  {
    fread(&frame, 1, sizeof(frame), stdin);

    // DO SOME STUFF
  }

Later I need to access such data: frame.Y [x] [y]

So, I created a class frame in Python and inserted the appropriate variables (frame.Y, frame.Cb, frame.Cr). I tried to sequentially map data from Y [0] [0] to Cr [MAX] [MAX], even printed the C-structure in action, but I was unable to wrap my head around the method used to place the data there. I am fighting for this with this and today I must return to the army, so any immediate help is very welcome and appreciated.

thank

+3
source share
1

struct python.
( ):

Python C Python. ( ) C- / Python. , .

: , , , array, "" Python, , - struct.

+6
source

Source: https://habr.com/ru/post/1740648/


All Articles