// Copyright 2002-2010 Guillaume Cottenceau. // This software may be freely redistributed under the terms of // the X11 license. // // Function write_png_file taken slightly modified from // http://zarb.org/~gc/html/libpng.html #include #include #include #include #include #include #include "png_helper.h" void abort_(const char * s, ...) { va_list args; va_start(args, s); vfprintf(stderr, s, args); fprintf(stderr, "\n"); va_end(args); abort(); } void write_png_file(const char* file_name, char* pixels, int width, int height) { int x, y; png_bytep *row_pointers; png_structp png_ptr; png_infop info_ptr; png_byte bit_depth = 8; // 8 bits per channel RGBA png_byte color_type = 6; // RGBA row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height); char *p = pixels; for (y=height-1; y>=0; y--) { row_pointers[y] = (png_byte*) malloc(4*width); for (x=0; x