Port C's fread(&struct,....) to Python

Posted by user287669 on Stack Overflow See other posts from Stack Overflow or by user287669
Published on 2010-04-11T10:16:00Z Indexed on 2010/04/11 10:23 UTC
Read the original article Hit count: 328

Filed under:
|
|
|

Hey, I'm really struggling with this one. I'am trying to port a small piece of someone else's code to Python 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 the data like so: frame.Y[x][y]

So I made a Class 'frame' in Python and inserted the corresponding variables(frame.Y, frame.Cb, frame.Cr). I have tried to sequentially map the data from Y[0][0] to Cr[MAX][MAX], even printed out the C struct in action but didn't manage to wrap my head around the method used to put the data in there. I've been struggling overnight with this and have to get back to the army tonight, so any immediate help is very welcome and appreciated.

Thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about c