Generate mandelbrot images using many clustered computers

ezpng.c 1.3KB

    #include <stdio.h> #include <png.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include "types.h" void savePng(char *filename, int h, int w, Pixel *buf) { FILE *fp; fp = fopen(filename, "wb"); if(!fp) { printf("ERROR: Could not save image!\r\n"); return; } png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_infop info_ptr = png_create_info_struct(png_ptr); png_set_IHDR (png_ptr, info_ptr, w, //image width h, //height 8, //bit depth PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_byte **row_pointers = png_malloc (png_ptr, h * sizeof (png_byte *)); for(int y = 0; y < h; y++) { png_byte *row = png_malloc (png_ptr, sizeof(uint8_t) * w * 3); row_pointers[y] = row; for(int x = 0; x < w; x++) { Pixel pixel = buf[x + w*y]; *row++ = pixel.red; *row++ = pixel.green; *row++ = pixel.blue; } } png_init_io (png_ptr, fp); png_set_rows (png_ptr, info_ptr, row_pointers); png_write_png (png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); fclose(fp); //Free memory for(int y = 0; y < h; y++) { png_free(png_ptr, row_pointers[y]); } png_free(png_ptr, row_pointers); png_destroy_write_struct(&png_ptr, &info_ptr); }