Skip to content

Instantly share code, notes, and snippets.

@connors511
Created September 27, 2011 15:19
Show Gist options
  • Save connors511/1245351 to your computer and use it in GitHub Desktop.
Save connors511/1245351 to your computer and use it in GitHub Desktop.
#ifdef DEBUG
printf("Image compression: RLE8\n");
printf("Bit offset: %d\n", bmfh.BfOffBits);
#endif
i = 0;
while(1) {
fread(&pixels, sizeof(BYTE), 1, fp);
fread(&color, sizeof(BYTE), 1, fp);
if ( pixels != 0x00 ) // escape char?
{
for(j = 0; j < (int)pixels; j++)
{
image->Pixels[i - 1 + j] = color;
totalPixels++;
}
i += (int)pixels;
}
else if (color == 0x00) // EOL
{
#if DEBUG == 2
printf("\nNEW LINE: %d\n",i);
#endif
//i = ceil((double)i / image->Width) * image->Width;
for (; i < ceil((double)i / image->Width) * image->Width; i++)
{
// Assign default background color to the rest of the line
image->Pixels[i] = (BYTE)0;
}
#if DEBUG == 2
printf("i set to %d\n",i);
#endif
}
else if (color == 0x01) // EOB
{
printf("End of image\n");
printf("Pixels read: %d\n", totalPixels);
break;
}
else // color == 0x02
{
// delta is not used in this assignment
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment