Skip to content

Instantly share code, notes, and snippets.

@GiorgioRegni
Created September 13, 2010 20:39
Show Gist options
  • Save GiorgioRegni/577996 to your computer and use it in GitHub Desktop.
Save GiorgioRegni/577996 to your computer and use it in GitHub Desktop.
void write_bmp(unsigned char *img, int width, int height) {
bmpfile_t *bmp;
int i, j;
rgb_pixel_t palette[PALETE_NUM_COLORS] = {0};
if ((bmp = bmp_create(width, height, 32)) == NULL) {
printf("Could not create bitmap");
exit(-1);
}
/* Palette initialization code removed ... */
for (j = 0; j < height; ++j) {
for (i = 0; i < width; ++i) {
int index = j*width+i;
int c = img[index];
bmp_set_pixel(bmp, i, j, palette[c % PALETE_NUM_COLORS]);
}
}
bmp_save(bmp, "image.bmp");
bmp_destroy(bmp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment