Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Usually you just pad the rows a bit.


And now I feel silly for not having thought of that :)


Happens to all of us. :)

I remember the first time I saw an image data struct that specified bits per pixel, image width and then also had bytes per row. I was a bit perplexed about why you'd store bytes per row if you could just compute it from bpp and width. Turns out you can fix/avoid a lot of performance issues if you can pad the data, so it's good practice to always save the number of bytes per row and use that in your mallocs/copies/iterators/etc.


For images, one of the main reasons to have separate bytes-per-row (usually called stride or pitch) is that it allows you to have sub-images that use the same data and stride as the parent image, but a different width and height.


Well, that too of course. :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: