void write_bmp(void) { char header[HEADER_SIZE]; FILE *output; int x, y; unsigned int *p; output = fopen(file_name, "wb"); if (!output) G_fatal_error("PNG: couldn't open output file %s", file_name); memset(header, 0, sizeof(header)); make_bmp_header(header); fwrite(header, sizeof(header), 1, output); for (y = 0, p = grid; y < height; y++) { for (x = 0; x < width; x++, p++) { unsigned int c = *p; int r, g, b, a; get_pixel(c, &r, &g, &b, &a); fputc((unsigned char)b, output); fputc((unsigned char)g, output); fputc((unsigned char)r, output); fputc((unsigned char)a, output); } } fclose(output); }
int main(void) { t_bmp_header header; t_bmp_info_header info; unsigned int *buffer; unsigned int **img; t_point p = {0, 0}; size_t size = 64; int d; buffer = malloc(size * size * sizeof(*buffer)); img = malloc(size * sizeof(*img)); memset(buffer, 0, size * size * sizeof(*buffer)); for (size_t i = 0; i < size; ++i) img[i] = buffer + i * size; make_bmp_header(&header, size); make_bmp_info_header(&info, size); draw_square(img, &p, size, 0x0000FFFF); p.x = 10; p.y = 10; draw_square(img, &p, 22, 0x00FF0000); d = open("square.bmp", O_CREAT | O_TRUNC | O_WRONLY, 0644); write(d, &header, sizeof(header)); write(d, &info, sizeof(info)); write(d, buffer, size * size * sizeof(*buffer)); close(d); return EXIT_SUCCESS; }
int main(void) { t_bmp_header header; t_bmp_info_header info; int d; uint32_t pixel = 0x00FFFFFF; make_bmp_header(&header, 32); make_bmp_info_header(&info, 32); d = open("32px.bmp", O_CREAT | O_TRUNC | O_WRONLY, 0644); write(d, &header, sizeof(header)); write(d, &info, sizeof(info)); for (size_t i = 0; i < 32 * 32; ++i) write(d, &pixel, sizeof(pixel)); close(d); return EXIT_SUCCESS; }