aboutsummaryrefslogtreecommitdiff
path: root/lib/tests
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2023-01-06 10:02:49 +0200
committerIgor Pashev <pashev.igor@gmail.com>2023-01-06 10:04:59 +0200
commit1145733c29db0a678537ce99ff60e21613f622a8 (patch)
tree63d5d6c324629d4eef1354db3c97f857d6016a34 /lib/tests
downloadiscan-1145733c29db0a678537ce99ff60e21613f622a8.tar.gz
Import iscan 2.30.4-2
Diffstat (limited to 'lib/tests')
-rw-r--r--lib/tests/Makefile.am46
-rw-r--r--lib/tests/even-width.pbmbin0 -> 2427 bytes
-rw-r--r--lib/tests/even-width.pgmbin0 -> 19343 bytes
-rw-r--r--lib/tests/even-width.ppmbin0 -> 57999 bytes
-rw-r--r--lib/tests/odd-width.pbmbin0 -> 2612 bytes
-rw-r--r--lib/tests/odd-width.pgmbin0 -> 19752 bytes
-rw-r--r--lib/tests/odd-width.ppmbin0 -> 59226 bytes
-rw-r--r--lib/tests/pnm.c141
-rw-r--r--lib/tests/pnm.h62
-rwxr-xr-xlib/tests/run-test-pcx.sh76
-rw-r--r--lib/tests/test-pcx.cc85
11 files changed, 410 insertions, 0 deletions
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am
new file mode 100644
index 0000000..c51b8ef
--- /dev/null
+++ b/lib/tests/Makefile.am
@@ -0,0 +1,46 @@
+## Makefile.am -- an -*- automake -*- template for Makefile.in
+## Copyright (C) 2011 SEIKO EPSON CORPORATION
+##
+## License: GPLv2+
+## Authors: AVASYS CORPORATION
+##
+## This file is part of the "Image Scan!" build infra-structure.
+##
+## The "Image Scan!" build infra-structure 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 2 of the License or at your option any later version.
+##
+## This program 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 ought to have received a copy of the GNU General Public License
+## along with this package. If not, see <http://www.gnu.org/licenses/>.
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/lib
+
+TESTS = \
+ run-test-pcx.sh
+
+check_PROGRAMS = \
+ test-pcx
+
+test_pcx_LDADD = \
+ ../libimage-stream.la \
+ -lstdc++
+test_pcx_SOURCES = \
+ test-pcx.cc \
+ pnm.c \
+ pnm.h
+
+EXTRA_DIST = \
+ even-width.pbm \
+ even-width.pgm \
+ even-width.ppm \
+ odd-width.pbm \
+ odd-width.pgm \
+ odd-width.ppm \
+ run-test-pcx.sh
diff --git a/lib/tests/even-width.pbm b/lib/tests/even-width.pbm
new file mode 100644
index 0000000..65bf750
--- /dev/null
+++ b/lib/tests/even-width.pbm
Binary files differ
diff --git a/lib/tests/even-width.pgm b/lib/tests/even-width.pgm
new file mode 100644
index 0000000..3b4bf37
--- /dev/null
+++ b/lib/tests/even-width.pgm
Binary files differ
diff --git a/lib/tests/even-width.ppm b/lib/tests/even-width.ppm
new file mode 100644
index 0000000..0179c95
--- /dev/null
+++ b/lib/tests/even-width.ppm
Binary files differ
diff --git a/lib/tests/odd-width.pbm b/lib/tests/odd-width.pbm
new file mode 100644
index 0000000..76a669a
--- /dev/null
+++ b/lib/tests/odd-width.pbm
Binary files differ
diff --git a/lib/tests/odd-width.pgm b/lib/tests/odd-width.pgm
new file mode 100644
index 0000000..9c29d53
--- /dev/null
+++ b/lib/tests/odd-width.pgm
Binary files differ
diff --git a/lib/tests/odd-width.ppm b/lib/tests/odd-width.ppm
new file mode 100644
index 0000000..0e945b9
--- /dev/null
+++ b/lib/tests/odd-width.ppm
Binary files differ
diff --git a/lib/tests/pnm.c b/lib/tests/pnm.c
new file mode 100644
index 0000000..d9ba1b6
--- /dev/null
+++ b/lib/tests/pnm.c
@@ -0,0 +1,141 @@
+/* pnm.c -- utility functions for testing purposes
+ * Copyright (C) 2019 SEIKO EPSON Corporation
+ *
+ * License: EPSON END USER SOFTWARE LICENSE
+ * Author : SEIKO EPSON Corporation
+ *
+ * This file is part of Image Scan! for Linux.
+ * It is distributed under the terms of the EPSON END USER SOFTWARE LICENSE.
+ *
+ * You should have received a verbatim copy of the EPSON END USER SOFTWARE
+ * LICENSE along with the software.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "pnm.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+pnm *
+read_pnm (const char *file)
+{
+ pnm image, *rv;
+
+ char *line = NULL;
+ size_t sz = 0;
+
+ FILE *fp;
+
+ if (file)
+ fp = fopen (file, "r");
+ else
+ fp = stdin;
+
+ if (!fp) return NULL;
+
+ getline (&line, &sz, fp); /* file magic number */
+ if ('P' != line[0]) return NULL;
+
+ image.depth = 8;
+ /**/ if ('6' == line[1]) image.format = 1;
+ else if ('5' == line[1]) image.format = 0;
+ else if ('4' == line[1]) { image.format = 0; image.depth = 1; }
+ else return NULL;
+
+ getline (&line, &sz, fp);
+ while ('#' == line[0]) /* skip header comments */
+ getline (&line, &sz, fp);
+ sscanf (line, "%d%d", &image.pixels_per_line, &image.lines);
+ if (1 < image.depth)
+ {
+ getline (&line, &sz, fp); /* max color value */
+ sscanf (line, "%d", &image.depth);
+ /**/ if (image.depth < (1 << 1)) image.depth = 1;
+ else if (image.depth < (1 << 8)) image.depth = 8;
+ else if (image.depth < (1 << 16)) image.depth = 16;
+ else return NULL;
+ }
+
+ free (line);
+ sz = 0;
+
+ image.bytes_per_line = (image.pixels_per_line
+ * (image.format ? 3 :1)
+ * (image.depth == 16 ? 2 : 1));
+ if (1 == image.depth)
+ {
+ image.bytes_per_line = (image.bytes_per_line + 7) / 8;
+ }
+ image.size = image.bytes_per_line * image.lines;
+
+ image.buffer = malloc (image.size);
+ if (!image.buffer) return NULL;
+ while (sz < image.size)
+ {
+ size_t s = fread (image.buffer, 1, image.size, fp);
+ if (0 == s)
+ {
+ if (ferror (fp))
+ {
+ fprintf (stderr, "error reading image file\n");
+ free (image.buffer);
+ return NULL;
+ }
+ if (feof (fp))
+ {
+ fprintf (stderr, "premature end of image file\n");
+ free (image.buffer);
+ return NULL;
+ }
+ }
+ sz += s;
+ }
+ fclose (fp);
+
+ rv = (pnm *) malloc (sizeof (pnm));
+ if (!rv)
+ {
+ free (image.buffer);
+ return NULL;
+ }
+ memcpy (rv, &image, sizeof (pnm));
+
+ return rv;
+}
+
+void
+write_pnm (const char *file, const pnm *image, const char *comment)
+{
+ FILE *fp;
+
+ if (file)
+ fp = fopen (file, "w");
+ else
+ fp = stdout;
+
+ if (!fp) return;
+
+ if (1 == image->depth)
+ {
+ fprintf (fp, "P4\n");
+ }
+ else
+ {
+ fprintf (fp, "P%d\n", (image->format ? 6 : 5));
+ }
+ fprintf (fp, "# %s\n", comment);
+ fprintf (fp, "%d %d\n", image->pixels_per_line, image->lines);
+ if (1 != image->depth)
+ {
+ fprintf (fp, "%d\n", (1 << image->depth) - 1);
+ }
+ fwrite (image->buffer, 1, image->bytes_per_line * image->lines, fp);
+ fflush (fp);
+ fclose (fp);
+}
diff --git a/lib/tests/pnm.h b/lib/tests/pnm.h
new file mode 100644
index 0000000..fcc2b9e
--- /dev/null
+++ b/lib/tests/pnm.h
@@ -0,0 +1,62 @@
+/* pnm.c -- utility functions for testing purposes
+ * Copyright (C) 2019 SEIKO EPSON Corporation
+ *
+ * License: EPSON END USER SOFTWARE LICENSE
+ * Author : SEIKO EPSON Corporation
+ *
+ * This file is part of Image Scan! for Linux.
+ * It is distributed under the terms of the EPSON END USER SOFTWARE LICENSE.
+ *
+ * You should have received a verbatim copy of the EPSON END USER SOFTWARE
+ * LICENSE along with the software.
+ */
+
+
+#ifndef pnm_h
+#define pnm_h
+
+#include <stddef.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ typedef struct {
+ void *buffer; /*!< image data */
+ size_t size; /*!< number of bytes allocated for buffer */
+ int format; /*!< zero for grayscale, non-zero for RGB */
+ int32_t bytes_per_line;
+ int32_t pixels_per_line;
+ int32_t lines;
+ int32_t depth;
+ } pnm;
+
+ /*! \brief Reads a PNM image from \a file
+ *
+ * Comments in the image file are allowed only between the first
+ * and second non-comment lines. That is, only a single block of
+ * consecutive comment lines after the first line is supported.
+ *
+ * Memory to hold the image data is acquired using malloc() and the
+ * caller is responsible for releasing this resource.
+ *
+ * Passing the \c NULL pointer for \a file will read from \c stdin.
+ */
+ pnm * read_pnm (const char *file);
+
+ /*! \brief Outputs a PNM \a image to \a file
+ *
+ * Files produced are reusable for input.
+ *
+ * Passing the \c NULL pointer for \a file will result in output on
+ * \c stdout.
+ */
+ void write_pnm (const char *file, const pnm *image,
+ const char *comment);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* defined (pnm_h) */
diff --git a/lib/tests/run-test-pcx.sh b/lib/tests/run-test-pcx.sh
new file mode 100755
index 0000000..c186ea2
--- /dev/null
+++ b/lib/tests/run-test-pcx.sh
@@ -0,0 +1,76 @@
+#! /bin/sh
+# run-test-pcx.sh -- unit test for pcxstream class
+# Copyright (C) 2011 SEIKO EPSON CORPORATION
+#
+# License: GPLv2+
+# Authors: AVASYS CORPORATION
+#
+# This file is part of the "Image Scan!" test suite.
+#
+# The "Image Scan!" test 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 2 of the License or at your option any later version.
+#
+# This program 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 ought to have received a copy of the GNU General Public License
+# along with this package. If not, see <http://www.gnu.org/licenses/>.
+
+if ! test -x ./test-pcx; then
+ echo "FAIL: ./test-pcx not found, run make first"
+ exit 1
+fi
+
+DO_COMPARE=`type convert >/dev/null && echo yes`
+if test "xyes" != x$DO_COMPARE; then
+ echo "INFO: compare test is skipped"
+fi
+
+# Compare test is additional.
+compare () {
+ FMT=`echo $SRC | sed 's,.*\.,,'`
+ convert "pcx:$DST" "$FMT:-" 2>/dev/null | cmp "$SRC" -
+ return $?
+}
+
+# Make temporary output in $builddir unless overridden. Only clean up
+# if tests succeed.
+run_test () {
+ SRC="$input"
+ DST=`mktemp ${TMPDIR:=.}/pcx.XXXXXXXX`
+
+ if ! ./test-pcx "$SRC" "$DST"; then
+ echo "FAIL: ./test-pcx $SRC $DST"
+ TEST_RESULT=FAIL
+ return
+ fi
+ if test "xyes" = x$DO_COMPARE; then
+ if ! compare "$SRC" "$DST"; then
+ echo "FAIL: compare $SRC $DST"
+ TEST_RESULT=FAIL
+ return
+ fi
+ fi
+ rm -f "$DST"
+}
+
+# `make check` normally sets $srcdir
+SRCDIR=${srcdir:=.}
+TEST_RESULT=PASS
+for input in \
+ "$SRCDIR/even-width.pbm" \
+ "$SRCDIR/even-width.pgm" \
+ "$SRCDIR/even-width.ppm" \
+ "$SRCDIR/odd-width.pbm" \
+ "$SRCDIR/odd-width.pgm" \
+ "$SRCDIR/odd-width.ppm" \
+ ; do
+ run_test
+done
+
+test "PASS" = "$TEST_RESULT"
+exit $?
diff --git a/lib/tests/test-pcx.cc b/lib/tests/test-pcx.cc
new file mode 100644
index 0000000..86e9a0e
--- /dev/null
+++ b/lib/tests/test-pcx.cc
@@ -0,0 +1,85 @@
+/* test-pcx.cc -- utility functions for testing purposes
+ * Copyright (C) 2019 SEIKO EPSON Corporation
+ *
+ * License: EPSON END USER SOFTWARE LICENSE
+ * Author : SEIKO EPSON Corporation
+ *
+ * This file is part of Image Scan! for Linux.
+ * It is distributed under the terms of the EPSON END USER SOFTWARE LICENSE.
+ *
+ * You should have received a verbatim copy of the EPSON END USER SOFTWARE
+ * LICENSE along with the software.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <iostream>
+#include "file-opener.hh"
+#include "imgstream.hh"
+#include "pnm.h"
+
+int main (int argc, char *argv[])
+{
+ using iscan::file_opener;
+ using iscan::imgstream;
+
+ char *i = NULL;
+ char *o = NULL;
+
+ pnm *img = NULL;
+ int x_res = 0;
+ int y_res = 0;
+
+ if (argc != 3)
+ {
+ std::cerr << "usage: ./test-pcx input.pnm output.pcx"
+ << std::endl;
+ return EXIT_FAILURE;
+ }
+ i = argv[1];
+ o = argv[2];
+
+ img = read_pnm (i);
+ if (!img)
+ return EXIT_FAILURE;
+
+ x_res = 300;
+ y_res = 300;
+
+ file_opener *fo = NULL;
+ imgstream *is = NULL;
+ iscan::file_format format = iscan::PCX;
+ fo = new file_opener (std::string (o));
+ is = create_imgstream (*fo, format, false);
+
+ is->next ();
+ is->size (img->pixels_per_line, img->lines);
+ is->depth (img->depth);
+ iscan::colour_space space;
+ if (1 == img->format)
+ space = iscan::RGB;
+ else if (0 == img->format && 1 == img->depth)
+ space = iscan::mono;
+ else if (0 == img->format)
+ space = iscan::grey;
+ else
+ return EXIT_FAILURE;
+ is->colour (space);
+ is->resolution (x_res, y_res);
+
+ int l;
+ char *ptr = (char *)img->buffer;
+ for (l=0; l<img->lines; ++l)
+ {
+ is->write (ptr, img->bytes_per_line);
+ ptr += img->bytes_per_line;
+ }
+ is->flush ();
+
+ delete is;
+ delete fo;
+
+ return 0;
+}