diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 26 | ||||
-rw-r--r-- | tests/png.c | 86 |
2 files changed, 112 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..d596017 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,26 @@ +########################################################################### +## Copyright (C) 2008 Tavian Barnes <tavianator@gmail.com> ## +## ## +## This file is part of The FPFD Library Build Suite. ## +## ## +## The FPFD Library Build Suite is free software; you can redistribute ## +## it and/or modify it under the terms of the GNU General Public License ## +## as published by the Free Software Foundation; either version 3 of the ## +## License, or (at your option) any later version. ## +## ## +## The FPFD Library Build Suite is distributed in the hope that it will ## +## be useful, but WITHOUT ANY WARRANTY; without even the implied ## +## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See ## +## the GNU General Public License for more details. ## +## ## +## You should have received a copy of the GNU General Public License ## +## along with this program. If not, see <http://www.gnu.org/licenses/>. ## +########################################################################### + +check_PROGRAMS = png +TESTS = $(check_PROGRAMS) + +INCLUDES = -I../libdimension -I../libdimension-png + +png_SOURCES = png.c +png_LDADD = ../libdimension/libdimension.la ../libdimension-png/libdimension-png.la diff --git a/tests/png.c b/tests/png.c new file mode 100644 index 0000000..e16ee8e --- /dev/null +++ b/tests/png.c @@ -0,0 +1,86 @@ +#include "../libdimension/dimension.h" +#include "../libdimension-png/dimension-png.h" +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> + +int main() { + dmnsn_canvas *canvas; + FILE *ofile, *ifile; + unsigned int x, y; + + canvas = dmnsn_new_canvas(333, 300); + if (!canvas) { + fprintf(stderr, "--- Allocation of canvas failed! ---\n"); + return EXIT_FAILURE; + } + + ofile = fopen("dimension.png", "wb"); + if (!ofile) { + fprintf(stderr, "--- Opening 'dimension.png' for writing failed! ---\n"); + return EXIT_FAILURE; + } + + for (x = 0; x < canvas->x; ++x) { + for (y = 0; y < canvas->y; ++y) { + if (x < canvas->x/3) { + canvas->pixels[y*canvas->x + x].r = UINT16_MAX; + canvas->pixels[y*canvas->x + x].g = 0; + canvas->pixels[y*canvas->x + x].b = 0; + } else if (x < 2*canvas->x/3) { + canvas->pixels[y*canvas->x + x].r = 0; + canvas->pixels[y*canvas->x + x].g = UINT16_MAX; + canvas->pixels[y*canvas->x + x].b = 0; + } else { + canvas->pixels[y*canvas->x + x].r = 0; + canvas->pixels[y*canvas->x + x].g = 0; + canvas->pixels[y*canvas->x + x].b = UINT16_MAX; + } + + if (y < canvas->y/3) { + canvas->pixels[y*canvas->x + x].a = 0; + canvas->pixels[y*canvas->x + x].t = 0; + } else if (y < 2*canvas->y/3) { + canvas->pixels[y*canvas->x + x].a = UINT16_MAX/4; + canvas->pixels[y*canvas->x + x].t = 0; + } else { + canvas->pixels[y*canvas->x + x].a = UINT16_MAX/4; + canvas->pixels[y*canvas->x + x].t = UINT16_MAX/2; + } + } + } + + if (dmnsn_png_write_canvas(canvas, ofile)) { + fprintf(stderr, "--- Writing canvas failed! ---\n"); + return EXIT_FAILURE; + } + + dmnsn_delete_canvas(canvas); + + fclose(ofile); + ifile = fopen("dimension.png", "rb"); + if (!ifile) { + fprintf(stderr, "--- Opening 'dimension.png' for reading failed! ---\n"); + return EXIT_FAILURE; + } + + if (dmnsn_png_read_canvas(&canvas, ifile)) { + fprintf(stderr, "--- Reading canvas failed! ---\n"); + return EXIT_FAILURE; + } + + fclose(ifile); + ofile = fopen("dimension.png", "wb"); + if (!ofile) { + fprintf(stderr, "--- Opening 'dimension.png' for writing failed! ---\n"); + return EXIT_FAILURE; + } + + if (dmnsn_png_write_canvas(canvas, ofile)) { + fprintf(stderr, "--- Writing canvas failed! ---\n"); + return EXIT_FAILURE; + } + + dmnsn_delete_canvas(canvas); + return EXIT_SUCCESS; +} |