diff --git a/.gitignore b/.gitignore index 7164dd3..204fcdd 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ pipi/pipi.pc genethumb/genethumb examples/blur examples/img2rubik +test/u8tof32tou8 stamp-h1 .auto .deps diff --git a/Makefile.am b/Makefile.am index a7b424a..be36347 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ # $Id$ -SUBDIRS = pipi genethumb examples +SUBDIRS = pipi genethumb examples test EXTRA_DIST = bootstrap common.h AUTOMAKE_OPTIONS = dist-bzip2 diff --git a/configure.ac b/configure.ac index f6eee06..4673b99 100644 --- a/configure.ac +++ b/configure.ac @@ -109,6 +109,7 @@ AC_CONFIG_FILES([ pipi/Makefile genethumb/Makefile examples/Makefile + test/Makefile ]) AC_CONFIG_FILES([ pipi/pipi.pc diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..dce9be0 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,11 @@ + +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/pipi + +noinst_PROGRAMS = u8tof32tou8 + +TESTS = $(noinst_PROGRAMS) + +u8tof32tou8_LDADD = ../pipi/libpipi.la + +EXTRA_DIST = mona.png + diff --git a/test/mona.png b/test/mona.png new file mode 100644 index 0000000..c527aac Binary files /dev/null and b/test/mona.png differ diff --git a/test/u8tof32tou8.c b/test/u8tof32tou8.c new file mode 100644 index 0000000..528fb83 --- /dev/null +++ b/test/u8tof32tou8.c @@ -0,0 +1,65 @@ +/* + * libpipi Proper image processing implementation library + * Copyright (c) 2004-2008 Sam Hocevar + * All Rights Reserved + * + * $Id$ + * + * This library is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/wtfpl/COPYING for more details. + */ + +/* + * loadsave.c: unit test to check that converting an image to float values + * and back to 8-bit integers does not change it. + */ + +#include "config.h" +#include "common.h" + +#include +#include + +#include + +int main(int argc, char *argv[]) +{ + pipi_image_t *img1, *img2; + pipi_pixels_t *pix1, *pix2; + uint32_t *data1, *data2; + int x, y, ret = EXIT_SUCCESS; + + img1 = pipi_load("mona.png"); + img2 = pipi_load("mona.png"); + + pix1 = pipi_getpixels(img1, PIPI_PIXELS_RGBA32); + data1 = (uint32_t *)pix1->pixels; + + pipi_getpixels(img2, PIPI_PIXELS_RGBA_F); + pix2 = pipi_getpixels(img2, PIPI_PIXELS_RGBA32); + data2 = (uint32_t *)pix2->pixels; + + for(y = 0; y < pix1->h; y++) + { + for(x = 0; x < pix1->w; x++) + { + uint32_t a = data1[y * pix1->w + x]; + uint32_t b = data2[y * pix2->w + x]; + + if(a != b) + { + printf("loadsave: %08x != %08x at (%i,%i)\n", a, b, x, y); + ret = EXIT_FAILURE; + } + } + } + + pipi_free(img1); + pipi_free(img2); + + return ret; +} +