   Writing compressed tga files
  Hi,finally I have set up FreeType2 and I create a nice Texture with all the characters I need ...just saving the result as a tga file does not quite work.The tga header is written properly.Right now (for font-images) the color bits are all 255 ... just the alpha values differ.Debugging the image content is what I have troubles with.There is no decent way of using logfiles that I can think of.Maybe somebody has written a tga writer and can spot an error here.I guess it has something to do with the iterators.No program I tested can open the file ... just my own loader (there is little error checking going on)It displays colorful results ... so for some reason not even the colorbits are always 255.The filesize is not insane ... between 120 and 150kb, depending on small changes I made. So I think I'm not too far off.Any help is greatly appreciated!    set_filename(filename);    const Uint8 compHeader[12] = {0,0,10,0,0,0,0,0,0,0,0,0};    const Uint8 width1  = 0; /* won't need different values */    const Uint8 width2  = (m_width/256)>255?255:(m_width/256);    const Uint8 height1 = 0; /* won't need different values */    const Uint8 height2 = (m_height/256)>256?255:(m_height/256);    const Uint8 bpp= 32;    start_writing();    /* write header */    write_uint8(compHeader,12);    write_uint8(&width1,1);    write_uint8(&width2,1);    write_uint8(&height1,1);    write_uint8(&height2,1);    write_uint8(&bpp,1);    /* write content */    Uint8 prevColor[4]; Uint8 nextColor[4];    Uint8 pixelsCount;    for (Uint32 i=0; i<m_width*m_height;) {   /* color of first pixel in chunk */   prevColor[0] = m_pPixels[(i*4)];   prevColor[1] = m_pPixels[(i*4)+1];   prevColor[2] = m_pPixels[(i*4)+2];   prevColor[3] = m_pPixels[(i*4)+3];   /* color of next pixel, only if there is a next pixel */   if (i<(m_width*m_height)-1) {  i++;  nextColor[0] = m_pPixels[(i*4)];  nextColor[1] = m_pPixels[(i*4)+1];  nextColor[2] = m_pPixels[(i*4)+2];  nextColor[3] = m_pPixels[(i*4)+3];   }   pixelsCount = 1; /* pixelCount in chunk, only first one counted */   /* check chunk type by comparing first two pixels */   if (0==memcmp(nextColor,prevColor,4)  && i<m_width*m_height) {  /* chunk of pixels with the same color */  /* compare nextColor with prevColor until- a different color is found- the max chunk size is reached- the last pixel was readincrement number of pixels in chunkincrement pixel array indexread new next color value  */  while (0==memcmp(nextColor,prevColor,4)    && pixelsCount < 128    && i<m_width*m_height) { pixelsCount++; i++; nextColor[0] = m_pPixels[(i*4)]; nextColor[1] = m_pPixels[(i*4)+1]; nextColor[2] = m_pPixels[(i*4)+2]; nextColor[3] = m_pPixels[(i*4)+3];  }  /* if two distinct pixels were found take back one iteration */  if (0!=memcmp(nextColor,prevColor,4)) { pixelsCount--; i--;  }  const Uint8 header = pixelsCount+127; /* max value: 255 */  /* write header and color of chunk */  write_uint8(&header,1);  write_uint8(prevColor,4);   } else if (0!=memcmp(nextColor,prevColor,4)    && i<m_width*m_height) {  /* chunk of pixels with different colors */  /* compare nextColor with prevColor until- two equal pixels are found- the max chunk size is reached- the last pixel was readincrement number of pixels in chunkincrement pixel array indexread new prev and next color values  */  while (0!=memcmp(nextColor,prevColor,4)    && pixelsCount < 128    && i<m_width*m_height) { pixelsCount++; i++; prevColor[0] = nextColor[0]; prevColor[1] = nextColor[1]; prevColor[2] = nextColor[2]; prevColor[3] = nextColor[3]; nextColor[0] = m_pPixels[(i*4)]; nextColor[1] = m_pPixels[(i*4)+1]; nextColor[2] = m_pPixels[(i*4)+2]; nextColor[3] = m_pPixels[(i*4)+3];  }  /* if two equal pixels were found take back one iteration */  if (i<m_width*m_height && pixelsCount<128) { pixelsCount--; i--;  } else {  }  const Uint8 header = pixelsCount-1; /* max Value 127 */  write_uint8(&header,1);  write_uint8(&m_pPixels[(i-pixelsCount)*4],pixelsCount*4);   } else {  /* only one more pixel */  const Uint8 header = 0; /* 0 represents a one pixel chunk */  write_uint8(&header,1);  write_uint8(&m_pPixels[i*4],4);   }    }    finish_writing();