title: Monochrome Bitmap (1 bbp) Padding and extra 0xF0 byte
body: <p>I am working with a Monochrome Bitmap image, 1 bit per pixel.</p>
  
  <p>When I examine the file with an hexadecimal editor, I notice that each row ends up with the following hexadecimal sequence: <code>f0 00 00 00</code>.</p>
  
  <p>Having studied the problem a little bit, I concluded that the three last bytes <code>00 00 00</code> correspond to the row padding.</p>
  
  <p>Question 1:</p>
  
  <p><strong>I would like to know if the following algorithm to determine the number of padding bytes in case of a 1 bbp BMP image is correct:</strong></p>
  
  <pre><code>if(((n_width % 32) == 0) || ((n_width % 32) &gt; 24))
  {
    n_nbPaddingBytes = 0;
  }
  else if((n_width % 32) &lt;= 8)
  {
    n_nbPaddingBytes = 3;
  }
  else if((n_width % 32) &lt;= 16)
  {
    n_nbPaddingBytes = 2;
  }
  else
  {
    n_nbPaddingBytes = 1;
  }
  </code></pre>
  
  <p><code>n_width</code> is the width in pixels of the BMP image.</p>
  
  <p>For example, if n_width = 100 px then n_nbPaddingBytes = 3.</p>
  
  <p>Question 2:</p>
  
  <p>Apart from the padding (00 00 00), I have this <code>F0</code> byte preceding the three bytes padding on every row. It results in a black vertical line of 4 pixels on the right side of the image.</p>
  
  <p>Note 1: I am manipulating the image prior to printing it on a Zebra printer (I am flipping the image vertically and reverting the colors: basically a black pixel becomes a white one and vice versa).</p>
  
  <p>Note 2: When I open the original BMP image with Paint, it has no such black vertical line on its right side.</p>
  
  <p>Is there any reason why this byte 0xF0 is present at the end of each row?</p>
  
  <p>Thank you for helping.
  Best regards.</p>