title: Converting color bmp to grayscale bmp?
body: <p>I am trying to convert a colored BMP file to gray-scale BMP. The input bmp is 24 bit and I am producing the same 24 bit bmp at the output, only this time in gray-scale. </p>
  
  <p>The code I am using is </p>
  
  <pre><code>for(int x = 0; x &lt; max; x++)
  {
      int lum;
      lum = (r[x]*0.30) + (g[x]*0.59) + (b[x]*0.11);
      r[x] = lum;
      g[x] = lum;
      b[x] = lum;
  }
  </code></pre>
  
  <p>The <code>r</code>, <code>g</code>, <code>b</code> arrays are the RGB color components and I have them in a <code>char *r,*g,*b</code>. </p>
  
  <p>For some reasons I am not getting a clean output. I am attaching the output I am getting with this question, its patchy and contains white and black areas at palces. So what am I doing wrong here?</p>
  
  <ol>
  <li>Is it due to data loss in calculationg of lum or is there something wrong in storing int as a char?</li>
  <li>Can gray-scale bmp not be 24 bit? or is it something wrong in the way I am storing rgb values after conversion?</li>
  </ol>
  
  <p>Any help in this will be much appriciated. Thanks.</p>