penrose

program for generating penrose tilings.
Log | Files | Refs | README | LICENSE

png_writer.cpp (804B)


      1 /*
      2  * © 2020 Michael Percival <m@michaelpercival.xyz>
      3  *   See LICENSE file for copyright and license details.
      4  */
      5 
      6 #include <stdio.h>
      7 
      8 #include "png_writer.hpp"
      9 
     10 void PngWriter::write_png_file(std::string file_name, int width, int height, png_bytep* row_pointers) {
     11     FILE *fp = fopen(file_name.c_str(), "wb");
     12     png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
     13     png_infop info_ptr = png_create_info_struct(png_ptr);
     14     png_init_io(png_ptr, fp);
     15 
     16     png_set_IHDR(png_ptr, info_ptr, width, height,
     17              8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE,
     18              PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
     19 
     20     png_write_info(png_ptr, info_ptr);
     21     png_write_image(png_ptr, row_pointers);
     22     png_write_end(png_ptr, NULL);
     23 
     24     fclose(fp);
     25 }