programming tips: pre-filled pattern

Pre-fill a buffer with a pattern, and check how many lines have been changed, after a certain operation (e.g. transferring some image data from external interface into memory)
// the buffer is UYVY format, with each two bytes representing one pixel. The code writes 00000000 to the middle of each line

uint32_t *write_pos = (uint32_t *)(buf->pointer) + buf->stride /8;

int nlines = 0;

for(; nlines < buf->height; write_pos += buf->stride /4, nlines++) {

*write_pos = 0;


// Read each line from the top. If we only concern the bottom part, reset the counter “lines_untouched“, the value is changed. If we want to count every “hole”, no reset is needed.

uint32_t *read_pos = (uint32_t *)(buf->pointer) + buf->stride /8;

int nlines = 0;

int lines_untouched = 0;

for(; nlines < buf->height; read_pos += buf->stride /4, nlines++) {

if(*read_pos == 0) {



else {

lines_untouched = 0;




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s