title: Getting incorrect width when decoding bitmap
body: <p>I have an error with my source code which basically causes bitmap images to appear too wide. for example it will print the width and the height and the height is perfect (256) and the width should also be 256 but the programs says it is billions of pixels wide and it is different everytime. here is the source code.</p>
  
  <pre><code>#include "glob.h"
  
  /* Image type - contains height, width, and data */
  struct Image {
      unsigned long sizeX;
      unsigned long sizeY;
      char *data;
  };
  typedef struct Image Image;
  
  int ImageLoad(char *filename, Image *image) {
      FILE *file;
      unsigned long size;                 // size of the image in bytes.
      unsigned long i;                    // standard counter.
      unsigned short int planes;          // number of planes in image (must be 1)
      unsigned short int bpp;             // number of bits per pixel (must be 24)
      char temp;                          // temporary color storage for bgr-rgb conversion.
  
      // make sure the file is there.
      if ((file = fopen(filename, "rb"))==NULL){
          printf("bitmap Not Found : %s\n",filename);
          return 0;
      }
  
      // seek through the bmp header, up to the width/height:
      fseek(file, 18, SEEK_CUR);
  
      // read the width
      if ((i = fread(&amp;image-&gt;sizeX, 4, 1, file)) != 1) {
          printf("Error reading width from %s.\n", filename);
          return 0;
      }
      printf("Width of %s: %lu\n", filename, image-&gt;sizeX);
  
      // read the height
      if ((i = fread(&amp;image-&gt;sizeY, 4, 1, file)) != 1) {
          printf("Error reading height from %s.\n", filename);
          return 0;
      }
      printf("Height of %s: %lu\n", filename, image-&gt;sizeY);
  
      // calculate the size (assuming 24 bits or 3 bytes per pixel).
      size = image-&gt;sizeX * image-&gt;sizeY * 3;
  
      // read the planes
      if ((fread(&amp;planes, 2, 1, file)) != 1) {
          printf("Error reading planes from %s.\n", filename);
          return 0;
      }
      if (planes != 1) {
          printf("Planes from %s is not 1: %u\n", filename, planes);
          return 0;
      }
  
      // read the bpp
      if ((i = fread(&amp;bpp, 2, 1, file)) != 1) {
          printf("Error reading bpp from %s.\n", filename);
          return 0;
      }
      if (bpp != 24) {
          printf("Bpp from %s is not 24: %u\n", filename, bpp);
          return 0;
      }
  
      // seek past the rest of the bitmap header.
      fseek(file, 24, SEEK_CUR);
  
      // read the data.
      image-&gt;data = (char *) malloc(size);
      if (image-&gt;data == NULL) {
          printf("Error allocating memory for color-corrected image data\n");
          return 0;
      }
  
      if ((i = fread(image-&gt;data, size, 1, file)) != 1) {
          printf("Error reading image data from %s.\n", filename);
          return 0;
      }
  
      for (i=0; i&lt;size; i+=3) { // reverse all of the colors. (bgr -&gt; rgb)
          temp = image-&gt;data[i];
          image-&gt;data[i] = image-&gt;data[i+2];
          image-&gt;data[i+2] = temp;
      }
  
      // we're done.
      return 0;
  }
  
  // Load Bitmaps And Convert To Textures
  void glob::LoadGLTextures() {
      // Load Texture
      Image *image1;
  
      // allocate space for texture
      image1 = (Image *) malloc(sizeof(Image));
      if (image1 == NULL) {
          printf("(image1 == NULL)\n");
          exit(0);
      }
  
      ImageLoad("data/textures/NeHe.bmp", image1);
  
      // Create Texture
      glGenTextures(1, &amp;texture);
      glBindTexture(GL_TEXTURE_2D, texture);   // 2d texture (x and y size)
  
      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture
      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale linearly when image smalled than texture
  
      // 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image,
      // border 0 (normal), rgb color data, unsigned byte data, and finally the data itself.
      glTexImage2D(GL_TEXTURE_2D, 0, 3, image1-&gt;sizeX, image1-&gt;sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1-&gt;data);
  };
  </code></pre>
  
  <p>glob.h is this:</p>
  
  <pre><code>#ifndef GLOB_H_INCLUDED
  #define GLOB_H_INCLUDED
  
  #include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;      // Header file for standard file i/o.
  
  #include &lt;GL/glx.h&gt;    /* this includes the necessary X headers */
  #include &lt;GL/gl.h&gt;
  //#include &lt;GL/glut.h&gt;    // Header File For The GLUT Library
  //#include &lt;GL/glu.h&gt;   // Header File For The GLu32 Library
  
  #include &lt;X11/X.h&gt;    /* X11 constant (e.g. TrueColor) */
  #include &lt;X11/keysym.h&gt;
  
  class glob {
      bool Running;
      GLuint texture; //make an array when we start using more then 1
      Display     *dpy;
      Window       win;
      XEvent       event;
      GLboolean    doubleBuffer;
      GLboolean    needRedraw;
      GLfloat      xAngle, yAngle, zAngle;
      float        camera_x, camera_y, camera_z;
  public:
      glob();
      int OnExecute();
  public:
      int init(int argc, char **argv);
      void LoadGLTextures();
      void OnEvent();
      void redraw(void);
  };
  
  #endif // GLOB_H_INCLUDED
  </code></pre>
  
  <p>can any body help me fix this problem?</p>