Skip to content

Commit

Permalink
Reformatted and indented
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed May 24, 2024
1 parent 6060520 commit d8f6d7f
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions svitava/svitava.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,25 +755,26 @@ int ppm_write_ascii(unsigned int width, unsigned int height,
return 0;
}

int bmp_write(unsigned int width, unsigned int height,
unsigned char *pixels, const char *file_name) {
unsigned char bmp_header[] = { /* BMP header structure: */
0x42, 0x4d, /* magic number */
0x46, 0x00, 0x00, 0x00, /* size of header=70 bytes */
0x00, 0x00, /* unused */
0x00, 0x00, /* unused */
0x36, 0x00, 0x00, 0x00, /* 54 bytes - offset to data */
0x28, 0x00, 0x00, 0x00, /* 40 bytes - bytes in DIB header */
0x00, 0x00, 0x00, 0x00, /* width of bitmap */
0x00, 0x00, 0x00, 0x00, /* height of bitmap */
0x01, 0x0, /* 1 pixel plane */
0x18, 0x00, /* 24 bpp */
0x00, 0x00, 0x00, 0x00, /* no compression */
0x00, 0x00, 0x00, 0x00, /* size of pixel array */
0x13, 0x0b, 0x00, 0x00, /* 2835 pixels/meter */
0x13, 0x0b, 0x00, 0x00, /* 2835 pixels/meter */
0x00, 0x00, 0x00, 0x00, /* color palette */
0x00, 0x00, 0x00, 0x00, /* important colors */
int bmp_write(unsigned int width, unsigned int height, unsigned char *pixels,
const char *file_name) {
unsigned char bmp_header[] = {
/* BMP header structure: */
0x42, 0x4d, /* magic number */
0x46, 0x00, 0x00, 0x00, /* size of header=70 bytes */
0x00, 0x00, /* unused */
0x00, 0x00, /* unused */
0x36, 0x00, 0x00, 0x00, /* 54 bytes - offset to data */
0x28, 0x00, 0x00, 0x00, /* 40 bytes - bytes in DIB header */
0x00, 0x00, 0x00, 0x00, /* width of bitmap */
0x00, 0x00, 0x00, 0x00, /* height of bitmap */
0x01, 0x0, /* 1 pixel plane */
0x18, 0x00, /* 24 bpp */
0x00, 0x00, 0x00, 0x00, /* no compression */
0x00, 0x00, 0x00, 0x00, /* size of pixel array */
0x13, 0x0b, 0x00, 0x00, /* 2835 pixels/meter */
0x13, 0x0b, 0x00, 0x00, /* 2835 pixels/meter */
0x00, 0x00, 0x00, 0x00, /* color palette */
0x00, 0x00, 0x00, 0x00, /* important colors */
};
FILE *fout;
int x, y;
Expand All @@ -798,11 +799,11 @@ int bmp_write(unsigned int width, unsigned int height,
unsigned char *p = pixels + y * width * 4;
for (x = 0; x < width; x++) {
/* swap RGB */
fwrite(p+2, 1, 1, fout);
fwrite(p+1, 1, 1, fout);
fwrite(p + 2, 1, 1, fout);
fwrite(p + 1, 1, 1, fout);
fwrite(p, 1, 1, fout);
/* next pixel */
p+=4;
p += 4;
}
}
fclose(fout);
Expand Down

0 comments on commit d8f6d7f

Please sign in to comment.