When I define ROW_PIXEL as 640, it is printig I_frame_pitch and P_frame_pitch both as 640, moment I increase the ROW_PIXEL to 656 it prints 704, furher I changes ROW_PIXEL to 720 it prints 768. Again when I set ROW_PIXEL as 1024 it prints 1024…I cannot understand what is happening here. I want it to work correctly for 720 !
Everything is ok except 656->704 …Check again maybe you did a typo.
Pitch represents new width to satisfy alignment requirements. Yor image of 720 bytes (i said bytes because you use sizeof(char)) in width must be extended to 768 bytes because width must be the product of 128. Or by other words
width % 128 == 0
Imagine that like your 2D image is stored in 1D memory buffer as sequence of rows.
First row followed with second row and so on.
To achieve maximal performance, beginning of each row must be at aligned address in that buffer. It is possible only if width%128==0 but it is not the case with 720 bytes, so extra 48 bytes are inserted after each row. Such new pitched width is in Pitch variable.
Accesing byte from coordinate (x,y) is easy
if(x<720) YourByte = buffer[y * Pitch + x]
Condition is used to allow processing only of bytes from image and not inserted.
Pixelsize is 1 in your case otherwise line would be
if(x<ImageWidth) YourByte = buffer[y * Pitch + x * PixelSize]
I’m not sure, but I think it can depend on what compute capability. The cards I’ve worked with have coalcesced access to 16 * 4-word patterns = 64 bytes. AFAIK. 128 may be safer for future cards or something like that.