penrose

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

commit 9ec73384e5bf4d53ab1dea4ba23f3354630f9232
parent 14afef0bfa2ce97750db89260105e9d799ee1bf1
Author: mpizzzle <m@michaelpercival.xyz>
Date:   Sat, 14 Nov 2020 20:39:11 +0000

minor cleanup

Diffstat:
Mpenrose.cpp | 14+++++++-------
Mpng_writer.cpp | 58++--------------------------------------------------------
2 files changed, 9 insertions(+), 63 deletions(-)

diff --git a/penrose.cpp b/penrose.cpp @@ -10,9 +10,9 @@ #include <glm/gtx/rotate_vector.hpp> #include <array> -#include <iostream> -#include <vector> #include <random> +#include <string> +#include <vector> #include <png.h> @@ -24,6 +24,7 @@ static const uint32_t window_h = 1080 * 4; static const uint32_t depth = 10; //recursion depth static const bool p2 = false; //tiling type (p2, p3) static const float line_w = 2.0f; //line width +static const std::string file_name = "penrose.png"; static const float phi = 1.0 / ((1.0 + sqrt(5.0)) / 2); @@ -182,7 +183,6 @@ int main() { glfwPollEvents(); } - glPixelStorei(GL_PACK_ALIGNMENT, 4); glReadBuffer(GL_FRONT); @@ -191,12 +191,12 @@ int main() { png_bytep* row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * frame_h); - for (int yy = 0; yy < frame_h; ++yy) { - row_pointers[yy] = (png_byte*) malloc((4 * sizeof(png_byte)) * frame_w); - glReadPixels(0, yy, frame_w, 1, GL_RGBA, GL_UNSIGNED_BYTE, row_pointers[yy]); + for (int y = 0; y < frame_h; ++y) { + row_pointers[y] = (png_byte*) malloc((4 * sizeof(png_byte)) * frame_w); + glReadPixels(0, y, frame_w, 1, GL_RGBA, GL_UNSIGNED_BYTE, row_pointers[y]); } - PngWriter::write_png_file("test.png", frame_w, frame_h, row_pointers); + PngWriter::write_png_file(file_name, frame_w, frame_h, row_pointers); return 0; } diff --git a/png_writer.cpp b/png_writer.cpp @@ -3,77 +3,23 @@ * See LICENSE file for copyright and license details. */ -#include <unistd.h> -#include <stdlib.h> #include <stdio.h> -#include <string.h> -#include <stdarg.h> - -#define PNG_DEBUG 3 -#include <png.h> #include "png_writer.hpp" -void abort_(const char * s, ...) -{ - va_list args; - va_start(args, s); - vfprintf(stderr, s, args); - fprintf(stderr, "n"); - va_end(args); - abort(); -} - void PngWriter::write_png_file(std::string file_name, int width, int height, png_bytep* row_pointers) { - png_structp png_ptr; - png_infop info_ptr; - - /* create file */ FILE *fp = fopen(file_name.c_str(), "wb"); - if (!fp) - abort_("[write_png_file] File %s could not be opened for writing", file_name.c_str()); - - /* initialize stuff */ - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - - if (!png_ptr) - abort_("[write_png_file] png_create_write_struct failed"); - - info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - abort_("[write_png_file] png_create_info_struct failed"); - - if (setjmp(png_jmpbuf(png_ptr))) - abort_("[write_png_file] Error during init_io"); - + 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_init_io(png_ptr, fp); - /* write header */ - if (setjmp(png_jmpbuf(png_ptr))) - abort_("[write_png_file] Error during writing header"); - png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); png_write_info(png_ptr, info_ptr); - - /* write bytes */ - if (setjmp(png_jmpbuf(png_ptr))) - abort_("[write_png_file] Error during writing bytes"); - png_write_image(png_ptr, row_pointers); - - /* end write */ - if (setjmp(png_jmpbuf(png_ptr))) - abort_("[write_png_file] Error during end of write"); - png_write_end(png_ptr, NULL); - /* cleanup heap allocation */ - //for (y=0; y<height; y++) - // free(row_pointers[y]); - //free(row_pointers); - fclose(fp); }