Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Padding in 24-bits rgb bitmap

could somebody explain to me why in 24-bit rgb bitmap file I have to add a padding which size depends on width of image ? What for ?

I mean I must add this code to my program (in C):

 if( read % 4 != 0 ) {
   read = 4 - (read%4);
   printf( "Padding: %d bytes\n", read );
   fread( pixel, read, 1, inFile );
  }
like image 981
salieri Avatar asked Apr 08 '10 15:04

salieri


1 Answers

Because 24 bits is an odd number of bytes (3) and for a variety of reasons all the image rows are required to start at an address which is a multiple of 4 bytes.

like image 110
Paul R Avatar answered Oct 14 '22 01:10

Paul R