diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 13 | ||||
-rw-r--r-- | test/Makefile.in | 204 | ||||
-rw-r--r-- | test/bjc-unprint.c | 3 | ||||
-rw-r--r-- | test/compress-5level.sh.in | 66 | ||||
-rw-r--r-- | test/compress-6level.sh.in | 68 | ||||
-rw-r--r-- | test/curve.c | 53 | ||||
-rw-r--r-- | test/escp2-weavetest.c | 3 | ||||
-rw-r--r-- | test/gen-printer-list.c | 3 | ||||
-rw-r--r-- | test/parse-bjc.in | 153 | ||||
-rwxr-xr-x | test/parse-escp2 | 240 | ||||
-rw-r--r-- | test/parse-escp2.in | 1017 | ||||
-rw-r--r-- | test/pcl-unprint.c | 823 | ||||
-rwxr-xr-x | test/run-testdither | 20 | ||||
-rw-r--r-- | test/run-testdither.in | 86 | ||||
-rwxr-xr-x | test/run-weavetest | 15 | ||||
-rw-r--r-- | test/run-weavetest.in | 120 | ||||
-rwxr-xr-x | test/test-curve | 62 | ||||
-rw-r--r-- | test/test-curve.in | 62 | ||||
-rw-r--r-- | test/testdither.c | 208 | ||||
-rw-r--r-- | test/uncompress-5level.sh.in | 82 | ||||
-rw-r--r-- | test/uncompress-6level.sh.in | 82 | ||||
-rw-r--r-- | test/unprint.c | 3 | ||||
-rw-r--r-- | test/xml-curve.c | 3 |
23 files changed, 2977 insertions, 412 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index ce0ae64..8bc37c2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -11,8 +11,7 @@ ## 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, write to the Free Software -## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +## along with this program. If not, see <https://www.gnu.org/licenses/>. ## Process this file with automake to produce Makefile.in. @@ -20,7 +19,6 @@ include $(top_srcdir)/scripts/global.mk - ## Variables LOCAL_CPPFLAGS = -I$(top_srcdir)/src/main $(GUTENPRINT_CFLAGS) @@ -28,14 +26,19 @@ LOCAL_CPPFLAGS = -I$(top_srcdir)/src/main $(GUTENPRINT_CFLAGS) ## run-weavetest is extremely time consuming and provides little value for ## release testing since the last material change was made in 2008. ## It is essentially a giant unit test for the weave code. -TESTS = curve run-testdither +## testdither doesn't actually test anything; there appears to be no way +## for it to actually return anything. +TESTS = test-curve run-weavetest run-testdither ## Programs if BUILD_TEST +AM_TESTS_ENVIRONMENT=STP_MODULE_PATH=$(top_builddir)/src/main/.libs:$(top_builddir)/src/main STP_DATA_PATH=$(top_srcdir)/src/xml noinst_PROGRAMS = testdither escp2-weavetest unprint pcl-unprint bjc-unprint curve xml-curve pixma_parse gen-printer-list endif +noinst_SCRIPTS=test-curve run-weavetest run-testdither + escp2_weavetest_SOURCES = escp2-weavetest.c escp2_weavetest_LDADD = $(GUTENPRINT_LIBS) @@ -72,4 +75,4 @@ pixma_parse_SOURCES = pixma_parse.c pixma_parse.h CLEANFILES = mixed-color-1bit.ppm MAINTAINERCLEANFILES = Makefile.in -EXTRA_DIST = cyan-sweep.tif parse-escp2 run-weavetest run-testdither +EXTRA_DIST = cyan-sweep.tif parse-escp2 run-weavetest run-testdither test-curve diff --git a/test/Makefile.in b/test/Makefile.in index 933d551..4a2920d 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.16.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2018 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -19,8 +19,19 @@ #export STP_MODULE_PATH = $(top_builddir)/src/main/.libs:$(top_builddir)/src/main #export STP_DATA_PATH = $(top_srcdir)/src/xml + VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ @@ -83,10 +94,6 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -DIST_COMMON = $(top_srcdir)/scripts/global.mk $(srcdir)/Makefile.in \ - $(srcdir)/Makefile.am $(top_srcdir)/scripts/depcomp \ - $(top_srcdir)/scripts/test-driver -TESTS = curve$(EXEEXT) run-testdither @BUILD_TEST_TRUE@noinst_PROGRAMS = testdither$(EXEEXT) \ @BUILD_TEST_TRUE@ escp2-weavetest$(EXEEXT) unprint$(EXEEXT) \ @BUILD_TEST_TRUE@ pcl-unprint$(EXEEXT) bjc-unprint$(EXEEXT) \ @@ -96,20 +103,23 @@ TESTS = curve$(EXEEXT) run-testdither subdir = test ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \ - $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \ - $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \ - $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ - $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ - $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ - $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ - $(top_srcdir)/m4/stp.m4 $(top_srcdir)/m4/stp_cups.m4 \ - $(top_srcdir)/m4/stp_gimp.m4 $(top_srcdir)/m4/stp_option.m4 \ + $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/intlmacosx.m4 \ + $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ + $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \ + $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/stp.m4 \ + $(top_srcdir)/m4/stp_cups.m4 $(top_srcdir)/m4/stp_option.m4 \ $(top_srcdir)/m4/stp_release.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = +CONFIG_CLEAN_FILES = compress-5level.sh compress-6level.sh \ + uncompress-5level.sh uncompress-6level.sh parse-bjc \ + parse-escp2 run-testdither run-weavetest test-curve CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) am_bjc_unprint_OBJECTS = bjc-unprint.$(OBJEXT) @@ -143,6 +153,7 @@ unprint_DEPENDENCIES = $(GUTENPRINT_LIBS) am_xml_curve_OBJECTS = xml-curve.$(OBJEXT) xml_curve_OBJECTS = $(am_xml_curve_OBJECTS) xml_curve_DEPENDENCIES = $(GUTENPRINT_LIBS) +SCRIPTS = $(noinst_SCRIPTS) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -157,7 +168,12 @@ am__v_at_0 = @ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/scripts/depcomp -am__depfiles_maybe = depfiles +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/bjc-unprint.Po ./$(DEPDIR)/curve.Po \ + ./$(DEPDIR)/escp2-weavetest.Po ./$(DEPDIR)/gen-printer-list.Po \ + ./$(DEPDIR)/pcl-unprint.Po ./$(DEPDIR)/pixma_parse.Po \ + ./$(DEPDIR)/testdither.Po ./$(DEPDIR)/unprint.Po \ + ./$(DEPDIR)/xml-curve.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -413,6 +429,15 @@ TEST_LOGS = $(am__test_logs2:.test.log=.log) TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/scripts/test-driver TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \ $(TEST_LOG_FLAGS) +am__DIST_COMMON = $(srcdir)/Makefile.in \ + $(srcdir)/compress-5level.sh.in \ + $(srcdir)/compress-6level.sh.in $(srcdir)/parse-bjc.in \ + $(srcdir)/parse-escp2.in $(srcdir)/run-testdither.in \ + $(srcdir)/run-weavetest.in $(srcdir)/test-curve.in \ + $(srcdir)/uncompress-5level.sh.in \ + $(srcdir)/uncompress-6level.sh.in \ + $(top_srcdir)/scripts/depcomp $(top_srcdir)/scripts/global.mk \ + $(top_srcdir)/scripts/test-driver DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ ALL_LINGUAS = @ALL_LINGUAS@ @@ -423,6 +448,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BASH = @BASH@ +BASHREAL = @BASHREAL@ BUILD_CUPS_PPDS = @BUILD_CUPS_PPDS@ BZIP2 = @BZIP2@ CC = @CC@ @@ -443,7 +470,6 @@ DB2PDF = @DB2PDF@ DB2PS = @DB2PS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ -DIALOG = @DIALOG@ DLLTOOL = @DLLTOOL@ DOXYGEN = @DOXYGEN@ DSYMUTIL = @DSYMUTIL@ @@ -460,6 +486,7 @@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ FIND = @FIND@ GENPPD_LIBS = @GENPPD_LIBS@ +GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ GIMP2_CFLAGS = @GIMP2_CFLAGS@ GIMP2_LIBS = @GIMP2_LIBS@ GIMPTOOL2_CHECK = @GIMPTOOL2_CHECK@ @@ -522,10 +549,12 @@ LTALLOCA = @LTALLOCA@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAINTAINER_CFLAGS = @MAINTAINER_CFLAGS@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ +MINIMAL_PRINTERS_TO_TEST = @MINIMAL_PRINTERS_TO_TEST@ MKDIR_P = @MKDIR_P@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ @@ -549,7 +578,6 @@ PKGROOT = @PKGROOT@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ -PLUG_IN_PATH = @PLUG_IN_PATH@ POSUB = @POSUB@ RANLIB = @RANLIB@ RELEASE_DATE = @RELEASE_DATE@ @@ -567,9 +595,11 @@ VERSION = @VERSION@ WHICH_PPDS = @WHICH_PPDS@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ +XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ XZ = @XZ@ YACC = @YACC@ YFLAGS = @YFLAGS@ +ZPAQ = @ZPAQ@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ @@ -637,8 +667,10 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include $(LOCAL_CPPFLAGS) $(GNUCFLAGS) -GUTENPRINTUI_LIBS = $(top_builddir)/src/gutenprintui/libgutenprintui.la LOCAL_CPPFLAGS = -I$(top_srcdir)/src/main $(GUTENPRINT_CFLAGS) +TESTS = test-curve run-weavetest run-testdither +@BUILD_TEST_TRUE@AM_TESTS_ENVIRONMENT = STP_MODULE_PATH=$(top_builddir)/src/main/.libs:$(top_builddir)/src/main STP_DATA_PATH=$(top_srcdir)/src/xml +noinst_SCRIPTS = test-curve run-weavetest run-testdither escp2_weavetest_SOURCES = escp2-weavetest.c escp2_weavetest_LDADD = $(GUTENPRINT_LIBS) unprint_SOURCES = unprint.c @@ -660,7 +692,7 @@ pixma_parse_SOURCES = pixma_parse.c pixma_parse.h #run-weavetest: escp2-weavetest CLEANFILES = mixed-color-1bit.ppm MAINTAINERCLEANFILES = Makefile.in -EXTRA_DIST = cyan-sweep.tif parse-escp2 run-weavetest run-testdither +EXTRA_DIST = cyan-sweep.tif parse-escp2 run-weavetest run-testdither test-curve all: all-am .SUFFIXES: @@ -677,16 +709,15 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu test/Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; -$(top_srcdir)/scripts/global.mk: +$(top_srcdir)/scripts/global.mk $(am__empty): $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh @@ -696,6 +727,24 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): +compress-5level.sh: $(top_builddir)/config.status $(srcdir)/compress-5level.sh.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +compress-6level.sh: $(top_builddir)/config.status $(srcdir)/compress-6level.sh.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +uncompress-5level.sh: $(top_builddir)/config.status $(srcdir)/uncompress-5level.sh.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +uncompress-6level.sh: $(top_builddir)/config.status $(srcdir)/uncompress-6level.sh.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +parse-bjc: $(top_builddir)/config.status $(srcdir)/parse-bjc.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +parse-escp2: $(top_builddir)/config.status $(srcdir)/parse-escp2.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +run-testdither: $(top_builddir)/config.status $(srcdir)/run-testdither.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +run-weavetest: $(top_builddir)/config.status $(srcdir)/run-weavetest.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +test-curve: $(top_builddir)/config.status $(srcdir)/test-curve.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ clean-noinstPROGRAMS: @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \ @@ -748,29 +797,35 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bjc-unprint.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/curve.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/escp2-weavetest.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen-printer-list.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pcl-unprint.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pixma_parse.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testdither.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unprint.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xml-curve.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bjc-unprint.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/curve.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/escp2-weavetest.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen-printer-list.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pcl-unprint.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pixma_parse.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testdither.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unprint.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xml-curve.Po@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -867,7 +922,7 @@ $(TEST_SUITE_LOG): $(TEST_LOGS) if test -n "$$am__remaking_logs"; then \ echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \ "recursion detected" >&2; \ - else \ + elif test -n "$$redo_logs"; then \ am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \ fi; \ if $(am__make_dryrun); then :; else \ @@ -957,7 +1012,7 @@ $(TEST_SUITE_LOG): $(TEST_LOGS) fi; \ $$success || exit 1 -check-TESTS: +check-TESTS: @list='$(RECHECK_LOGS)'; test -z "$$list" || rm -f $$list @list='$(RECHECK_LOGS:.log=.trs)'; test -z "$$list" || rm -f $$list @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) @@ -978,9 +1033,16 @@ recheck: all am__force_recheck=am--force-recheck \ TEST_LOGS="$$log_list"; \ exit $$? -curve.log: curve$(EXEEXT) - @p='curve$(EXEEXT)'; \ - b='curve'; \ +test-curve.log: test-curve + @p='test-curve'; \ + b='test-curve'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +run-weavetest.log: run-weavetest + @p='run-weavetest'; \ + b='run-weavetest'; \ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ @@ -1007,7 +1069,10 @@ run-testdither.log: run-testdither @am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ @am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) -distdir: $(DISTFILES) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ @@ -1040,7 +1105,7 @@ distdir: $(DISTFILES) check-am: all-am $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-am -all-am: Makefile $(PROGRAMS) +all-am: Makefile $(PROGRAMS) $(SCRIPTS) installdirs: install: install-am install-exec: install-exec-am @@ -1083,7 +1148,15 @@ clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \ mostlyclean-am distclean: distclean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/bjc-unprint.Po + -rm -f ./$(DEPDIR)/curve.Po + -rm -f ./$(DEPDIR)/escp2-weavetest.Po + -rm -f ./$(DEPDIR)/gen-printer-list.Po + -rm -f ./$(DEPDIR)/pcl-unprint.Po + -rm -f ./$(DEPDIR)/pixma_parse.Po + -rm -f ./$(DEPDIR)/testdither.Po + -rm -f ./$(DEPDIR)/unprint.Po + -rm -f ./$(DEPDIR)/xml-curve.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -1129,7 +1202,15 @@ install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/bjc-unprint.Po + -rm -f ./$(DEPDIR)/curve.Po + -rm -f ./$(DEPDIR)/escp2-weavetest.Po + -rm -f ./$(DEPDIR)/gen-printer-list.Po + -rm -f ./$(DEPDIR)/pcl-unprint.Po + -rm -f ./$(DEPDIR)/pixma_parse.Po + -rm -f ./$(DEPDIR)/testdither.Po + -rm -f ./$(DEPDIR)/unprint.Po + -rm -f ./$(DEPDIR)/xml-curve.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -1150,19 +1231,22 @@ uninstall-am: .MAKE: check-am install-am install-strip -.PHONY: CTAGS GTAGS TAGS all all-am check check-TESTS check-am clean \ - clean-generic clean-libtool clean-noinstPROGRAMS cscopelist-am \ - ctags ctags-am distclean distclean-compile distclean-generic \ - distclean-libtool distclean-tags distdir dvi dvi-am html \ - html-am info info-am install install-am install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-pdf install-pdf-am \ - install-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - recheck tags tags-am uninstall uninstall-am +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-TESTS \ + check-am clean clean-generic clean-libtool \ + clean-noinstPROGRAMS cscopelist-am ctags ctags-am distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am recheck tags tags-am uninstall \ + uninstall-am + +.PRECIOUS: Makefile @SET_MAKE@ @@ -1173,10 +1257,6 @@ $(top_builddir)/src/main/libgutenprint.la: cd $(top_builddir)/src/main; \ $(MAKE) -$(top_builddir)/src/gutenprintui/libgutenprintui.la: - cd $(top_builddir)/src/gutenprintui; \ - $(MAKE) - $(top_builddir)/src/gutenprintui2/libgutenprintui2.la: cd $(top_builddir)/src/gutenprintui2; \ $(MAKE) diff --git a/test/bjc-unprint.c b/test/bjc-unprint.c index 182e686..13b1197 100644 --- a/test/bjc-unprint.c +++ b/test/bjc-unprint.c @@ -14,8 +14,7 @@ * for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with this program. If not, see <https://www.gnu.org/licenses/>. */ diff --git a/test/compress-5level.sh.in b/test/compress-5level.sh.in new file mode 100644 index 0000000..23aa024 --- /dev/null +++ b/test/compress-5level.sh.in @@ -0,0 +1,66 @@ +#!@SHELL@ + +# compression of 5-level inks (irrespective of bits per level) +# 3-level, 5 pixels = 1024 combinations: 10 bits long +# but since not all levels used: unique are 242, or 1 byte +# 4-level, 4 pixels = 65536 combinations: 16 bits long +# but since only 2 bits per pixel used there are 256 combinations, or 1 byte +# 5-level, 3 pixels: 15 bits long +# but since only 3 bits per pixel used there are 125 unique combinations, or 1 byte + + +# m: max number of levels used +m=5 +# z: max number allowed by bits +z=16 +# a: iteration of array subscript +a=1 +# n: iteration of valid combinations +n=0 +# iteration of pixels +#i=0 +j=0 +k=0 +l=0 + +echo "static const unsigned char ninetoeight[] =" +echo "{" + +#for (( i=1; i<=$z; i++ )) +#do + for (( j=1; j<=$z; j++ )) + do + for (( k=1; k<=$z; k++ )) + do + for (( l=1; l<=$z; l++ )) + do +# if test $i -gt $m -o $j -gt $m -o $k -gt $m -o $l -gt $m + if test $j -gt $m -o $k -gt $m -o $l -gt $m + then + array[$a]=0 + else + array[$a]=$n + n=$(( $n+1 )) + fi + # print line of output + remainder=$(( $a % 16 )) + a=$(( $a+1 )) + if test $remainder -eq 0 + then + printf " " + pstart=$(( 256*($j-1)+16*($k-1)+1 )) + pfinal=$(( 256*($j-1)+16*$k )) + #echo "array subscript: $a, pstart: $pstart, pfinal: $pfinal, iterators: $j $k $l" + for (( p=$pstart; p<=$pfinal; p++ )) + do + printf "%3d," ${array[$p]} + done + printf "\n" + fi + done + done + done +#done + +echo "};" +echo "max number of valid combinations: $n" diff --git a/test/compress-6level.sh.in b/test/compress-6level.sh.in new file mode 100644 index 0000000..62bc38a --- /dev/null +++ b/test/compress-6level.sh.in @@ -0,0 +1,68 @@ +#!@SHELL@ + +# compression of 6-level inks (irrespective of bits per level) +# 3-level, 5 pixels = 1024 combinations: 10 bits long +# but since not all levels used: unique are 242, or 1 byte +# 4-level, 4 pixels = 65536 combinations: 16 bits long +# but since only 2 bits per pixel used there are 256 combinations, or 1 byte +# 5-level, 3 pixels: 15 bits long +# but since only 3 bits per pixel used there are 125 unique combinations, or 1 byte +# 6-level, 3 pixels: 15 bits long +# but since only 3 bits per pixel used there are 216 unique combinations, or 1 byte + + +# m: max number of levels used +m=6 +# z: max number allowed by bits +z=16 +# a: iteration of array subscript +a=1 +# n: iteration of valid combinations +n=0 +# iteration of pixels +#i=0 +j=0 +k=0 +l=0 + +echo "static const unsigned char ninetoeight2[] =" +echo "{" + +#for (( i=1; i<=$z; i++ )) +#do + for (( j=1; j<=$z; j++ )) + do + for (( k=1; k<=$z; k++ )) + do + for (( l=1; l<=$z; l++ )) + do +# if test $i -gt $m -o $j -gt $m -o $k -gt $m -o $l -gt $m + if test $j -gt $m -o $k -gt $m -o $l -gt $m + then + array[$a]=0 + else + array[$a]=$n + n=$(( $n+1 )) + fi + # print line of output + remainder=$(( $a % 16 )) + a=$(( $a+1 )) + if test $remainder -eq 0 + then + printf " " + pstart=$(( 256*($j-1)+16*($k-1)+1 )) + pfinal=$(( 256*($j-1)+16*$k )) + #echo "array subscript: $a, pstart: $pstart, pfinal: $pfinal, iterators: $j $k $l" + for (( p=$pstart; p<=$pfinal; p++ )) + do + printf "%3d," ${array[$p]} + done + printf "\n" + fi + done + done + done +#done + +echo "};" +echo "max number of valid combinations: $n" diff --git a/test/curve.c b/test/curve.c index 4a643de..bcd0b7d 100644 --- a/test/curve.c +++ b/test/curve.c @@ -13,8 +13,7 @@ * for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H @@ -22,8 +21,10 @@ #endif #include <stdlib.h> #include <stdio.h> +#include <fcntl.h> #include <unistd.h> #include <string.h> +#include <limits.h> #ifdef __GNU_LIBRARY__ #include <getopt.h> #endif @@ -58,12 +59,15 @@ struct test_failure static struct test_failure *test_failure_head = NULL; static struct test_failure *test_failure_tail = NULL; +static const char *current_test_name; +static int current_test_line; + static void TEST_internal(const char *name, int line) { global_test_count++; - printf("%d.%d: Checking %s... ", global_test_count, line, name); - fflush(stdout); + current_test_name = name; + current_test_line = line; } #define TEST(name) TEST_internal(name, __LINE__) @@ -71,7 +75,9 @@ TEST_internal(const char *name, int line) static void TEST_PASS(void) { - printf("PASS\n"); + if (verbose) + printf("%d.%d: Checking %s... PASS\n", global_test_count, current_test_line, + current_test_name); fflush(stdout); } @@ -94,7 +100,8 @@ TEST_FAIL(void) } global_error_count++; - printf("FAIL\n"); + printf("%d.%d: Checking %s... FAIL\n", global_test_count, current_test_line, + current_test_name); fflush(stdout); } @@ -557,6 +564,7 @@ piecewise_curve_checks(stp_curve_t *curve1, int resample_points, int expected) } else TEST_PASS(); + stp_curve_destroy(curve2); if (resample_points > 0) { @@ -598,6 +606,8 @@ piecewise_curve_checks(stp_curve_t *curve1, int resample_points, int expected) SIMPLE_TEST_CHECK((curve2 = stp_curve_get_subrange(curve1, 0, 2))); if (verbose && curve2) stp_curve_write(stdout, curve2); + if (curve2) + stp_curve_destroy(curve2); if (resample_points > 10) { @@ -613,6 +623,8 @@ piecewise_curve_checks(stp_curve_t *curve1, int resample_points, int expected) } else TEST_FAIL(); + if (curve2) + stp_curve_destroy(curve2); } } } @@ -654,7 +666,6 @@ main(int argc, char **argv) break; } } - stp_init(); TEST("creation of XML string from curve"); @@ -691,7 +702,7 @@ main(int argc, char **argv) } if (!quiet) - printf("Testing known bad curves...\n"); + printf("Testing known bad curves... (expect messages)\n"); for (i = 0; i < bad_curve_count; i++) { stp_curve_t *bad = NULL; @@ -1010,6 +1021,11 @@ main(int argc, char **argv) stp_curve_destroy(curve1); curve1 = NULL; } + if (curve2) + { + stp_curve_destroy(curve2); + curve2 = NULL; + } } TEST("Creating piecewise wrap-around curve"); @@ -1024,6 +1040,7 @@ main(int argc, char **argv) SIMPLE_TEST_CHECK(tmp); if (verbose) printf("%s\n", tmp); + stp_free(tmp); TEST("Check curve is piecewise"); SIMPLE_TEST_CHECK(stp_curve_is_piecewise(curve1)); @@ -1042,7 +1059,7 @@ main(int argc, char **argv) TEST("Copy in place piecewise curve"); stp_curve_copy(curve2, curve1); - SIMPLE_TEST_CHECK(curve1); + SIMPLE_TEST_CHECK(curve1 != NULL); piecewise_curve_checks(curve2, 10, 48); stp_curve_copy(curve2, curve1); piecewise_curve_checks(curve2, 15, 48); @@ -1057,6 +1074,7 @@ main(int argc, char **argv) stp_curve_copy(curve2, curve1); piecewise_curve_checks(curve2, 100, 48); stp_curve_destroy(curve1); + stp_curve_destroy(curve2); TEST("Creating piecewise no-wrap curve with not enough data (PASS is an expected failure)"); curve1 = stp_curve_create(STP_CURVE_WRAP_NONE); @@ -1073,6 +1091,7 @@ main(int argc, char **argv) SIMPLE_TEST_CHECK(tmp); if (verbose) printf("%s\n", tmp); + stp_free(tmp); TEST("Check curve is piecewise"); SIMPLE_TEST_CHECK(stp_curve_is_piecewise(curve1)); @@ -1090,6 +1109,7 @@ main(int argc, char **argv) TEST("Copy in place piecewise curve"); stp_curve_copy(curve2, curve1); + SIMPLE_TEST_CHECK(curve1 != NULL); piecewise_curve_checks(curve2, 10, 49); stp_curve_copy(curve2, curve1); piecewise_curve_checks(curve2, 15, 49); @@ -1103,7 +1123,8 @@ main(int argc, char **argv) piecewise_curve_checks(curve2, 50, 49); stp_curve_copy(curve2, curve1); piecewise_curve_checks(curve2, 100, 49); - + stp_curve_destroy(curve2); + stp_curve_destroy(curve1); TEST("Creating piecewise spline wrap-around curve"); curve1 = stp_curve_create(STP_CURVE_WRAP_AROUND); @@ -1118,6 +1139,7 @@ main(int argc, char **argv) SIMPLE_TEST_CHECK(tmp); if (verbose) printf("%s\n", tmp); + stp_free(tmp); TEST("Check curve is piecewise"); SIMPLE_TEST_CHECK(stp_curve_is_piecewise(curve1)); @@ -1135,6 +1157,7 @@ main(int argc, char **argv) TEST("Copy in place piecewise curve"); stp_curve_copy(curve2, curve1); + SIMPLE_TEST_CHECK(curve1 != NULL); piecewise_curve_checks(curve2, 10, 48); stp_curve_copy(curve2, curve1); piecewise_curve_checks(curve2, 15, 48); @@ -1163,10 +1186,16 @@ main(int argc, char **argv) SIMPLE_TEST_CHECK(tmp); if (verbose) printf("%s\n", tmp); + stp_free(tmp); TEST("Check curve is piecewise"); SIMPLE_TEST_CHECK(stp_curve_is_piecewise(curve1)); + if (curve2) + { + stp_curve_destroy(curve2); + curve2 = NULL; + } TEST("Create copy of piecewise curve"); curve2 = stp_curve_create_copy(curve1); SIMPLE_TEST_CHECK(curve2); @@ -1180,6 +1209,7 @@ main(int argc, char **argv) TEST("Copy in place piecewise curve"); stp_curve_copy(curve2, curve1); + SIMPLE_TEST_CHECK(curve1 != NULL); piecewise_curve_checks(curve2, 10, 49); stp_curve_copy(curve2, curve1); piecewise_curve_checks(curve2, 15, 49); @@ -1193,6 +1223,7 @@ main(int argc, char **argv) piecewise_curve_checks(curve2, 50, 49); stp_curve_copy(curve2, curve1); piecewise_curve_checks(curve2, 100, 49); + stp_curve_destroy(curve1); TEST("Create small piecewise curve"); curve1 = stp_curve_create_from_string(small_piecewise_curve); @@ -1216,6 +1247,6 @@ main(int argc, char **argv) } } else - printf("All tests passed successfully.\n"); + printf("All %d tests passed successfully.\n", global_test_count); return global_error_count ? 1 : 0; } diff --git a/test/escp2-weavetest.c b/test/escp2-weavetest.c index 4c57d4e..b68bdbd 100644 --- a/test/escp2-weavetest.c +++ b/test/escp2-weavetest.c @@ -15,8 +15,7 @@ * for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with this program. If not, see <https://www.gnu.org/licenses/>. * * Test for the soft weave algorithm. This program calculates the weave * parameters for each input line and verifies that a number of conditions diff --git a/test/gen-printer-list.c b/test/gen-printer-list.c index 5eb8047..976ed02 100644 --- a/test/gen-printer-list.c +++ b/test/gen-printer-list.c @@ -15,8 +15,7 @@ * for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with this program. If not, see <https://www.gnu.org/licenses/>. */ /* diff --git a/test/parse-bjc.in b/test/parse-bjc.in new file mode 100644 index 0000000..f5d7565 --- /dev/null +++ b/test/parse-bjc.in @@ -0,0 +1,153 @@ +#!@PERL@ + +while (<>) { + $stuff .= $_; +} + +$OFFS=$ENV{"OFFS"}; +$GRX=$ENV{"GRX"}; + +%seqtable = ( "@", 0, + "\x0d", 0, + "[K", 4, + "(a", "VARIABLE", + "(b", "VARIABLE", + "(c", "VARIABLE", + "(d", "VARIABLE", + "(e", "GRAPHICS", + "(l", "VARIABLE", + "(m", "VARIABLE", + "(p", "VARIABLE", + "(q", "VARIABLE", + "(r", "VARIABLE", + "(t", "VARIABLE", + "(v", "VARIABLE", + "(w", "VARIABLE", + "(A", "GRAPHICS", + "\\", 2, + "\$", 2, + "(\\", "VARIABLE", + "(C", "VARIABLE", + "(F", "GRAPHICS", + "(I", "VARIABLE", + "(J", "VARIABLE", + "(L", "VARIABLE", + "(P", "VARIABLE", + "(T", "VARIABLE", + ".", "SPECIAL", + "i", "SPECIAL1" + ); + +$esc = "\033"; + +$skipcount = 0; +$curpos = 0; +$verbose = 1; + +while ($stuff ne "") { + if ($stuff=~ s/^(BJLSTART.+BJLEND?)//sm) { + + printf "\n$1"; + $curpos+= length($1); + + } elsif (substr($stuff, 0, 1) eq "\xa") { + + print "<a"; + $curpos++; + substr($stuff, 0, 1) = ""; + + } elsif (substr($stuff, 0, 1) eq "\xd") { + + print "<d" if ($GRX); + $curpos++; + substr($stuff, 0, 1) = ""; + + } elsif (substr($stuff, 0, 1) eq "$esc") { + + $found = 0; + foreach $key (keys %seqtable) { + if (substr($stuff, 1, length $key) eq $key) { + $skipchars = $seqtable{$key}; + if ($skipchars eq "GRAPHICS") { + if ($GRX) { + print "\n"; + printf "%08x ", $curpos if ($OFFS); + print "1b "; + } + $startoff = 0; + $lchar = substr($stuff, (length $key) + 1, 1); + $nlchar = unpack("C", $lchar); + $hchar = substr($stuff, (length $key) + 2, 1); + $nhchar = unpack("C", $hchar); + $skipchars = ($nhchar * 256) + $nlchar; + $startoff = 2; + + if ($GRX) { + for ($i = 0; + $i < $skipchars + (length $key) + $startoff; + $i++) { + $char = substr($stuff, $i + 1, 1); + $nchar = unpack("C", $char); + if ($i < 2 && $nchar >= 32 && $nchar < 127) { + print "$char "; + } elsif ($i==4 && $nchar >= 32 && $nchar < 127) { + print "$char$char "; + } else { + printf "%02x ", unpack("C", $char); + } + } + } + $found = 1; + } else { + print "\n"; + printf "%08x ", $curpos if ($OFFS); + print "1b "; + $startoff = 0; + if ($skipchars eq "VARIABLE") { + $lchar = substr($stuff, (length $key) + 1, 1); + $nlchar = unpack("C", $lchar); + $hchar = substr($stuff, (length $key) + 2, 1); + $nhchar = unpack("C", $hchar); + $skipchars = ($nhchar * 256) + $nlchar; + $startoff = 2; + } + for ($i = 0; + $i < $skipchars + (length $key) + $startoff; + $i++) { + $char = substr($stuff, $i + 1, 1); + $nchar = unpack("C", $char); + if ($i < 2 && $nchar >= 32 && $nchar < 127) { + print "$char "; + } else { + printf "%02x ", unpack("C", $char); + } + } + $found = 1; + } + $bytes = length($key) + 1 + $skipchars + $startoff; + last; + } + } + if (! $found) { + print "\n"; + printf "%08x ", $curpos if ($OFFS); + print "1b "; + substr($stuff, 0, 1) = ""; + $curpos += 1; + } elsif ($found == 1) { + substr($stuff, 0, $bytes) = ""; + $curpos += $bytes; + } else { + } + } else { + $char = substr($stuff, 0, 1); + $nchar = unpack("C", $char); + if ($nchar >= 32 && $nchar < 127) { + print "*$char "; + } else { + printf "*%02x ", unpack("C", $char); + } + $curpos++; + substr($stuff, 0, 1) = ""; + } +} diff --git a/test/parse-escp2 b/test/parse-escp2 index bca4c97..b2cffef 100755 --- a/test/parse-escp2 +++ b/test/parse-escp2 @@ -13,8 +13,7 @@ # for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# along with this program. If not, see <https://www.gnu.org/licenses/>. use Getopt::Std; use strict; @@ -22,6 +21,7 @@ use strict; getopts('VvO:'); use vars qw($atend + $escpr $stuff $opt_v $opt_V @@ -30,6 +30,7 @@ use vars qw($atend $curpos $esc $initial_vertical_position + $null $page_mgmt_unit $horizontal_position $horizontal_unit @@ -49,6 +50,7 @@ use vars qw($atend @offsets); $atend = 0; +$escpr = 0; %chartable = (); %xchartable = (); %nchartable = (); @@ -88,6 +90,7 @@ map { map { $keylengths{$_} = length $_ } @seqkeys; $esc = "\033"; +$null = "\000"; $curpos = 0; $curoffset = 0; @@ -148,6 +151,36 @@ sub get_byte_at($) { return get_byte(get_raw_at($offset, 1)) } +sub get_blong_at($) { + my ($offset) = @_; + return get_blong(substr($stuff, $curoffset + $offset, 4)); +} + +sub get_bshort_at($) { + my ($offset) = @_; + return get_bshort(substr($stuff, $curoffset + $offset, 2)); +} + +sub get_blong($) { + my ($string) = @_; + my ($tmp) = unpack("N", $string); + if ($tmp >= (1 << 31)) { + return -(0xffffffff ^ $tmp) - 1; + } else { + return $tmp; + } +} + +sub get_bshort($) { + my ($string) = @_; + my ($tmp) = unpack("n", $string); + if ($tmp >= (1 << 15)) { + return -(0xffff ^ $tmp) - 1; + } else { + return $tmp; + } +} + sub get_string_at($$) { my ($offset, $count) = @_; return join('', map { $rchartable{get_raw_at($offset + $_)}} (0..$count-1)); @@ -210,19 +243,172 @@ sub increment_curpos($) { $curoffset += $curpos_increment; } +sub print_escpr_data($$$$$) { + my ($outbytes, $compression, $bpp, $offset, $expected) = @_; + if ($compression == 0) { + printf("%*v02x ", " ", substr($stuff, $offset, $outbytes * 3)); + if ($expected != $outbytes) { + printf "**** Wrong byte count: got %d, expected %d (%x)!!!", $outbytes, $expected, $expected; + } + } else { + my ($totbytes) = 0; + my ($orig_outbytes) = $outbytes; + while ($outbytes > 0) { + my ($place) = $offset + $orig_outbytes - $outbytes; + my $counter = ord(substr($stuff, $place, 1)); + $place++; + $outbytes--; + if ($counter <= 127) { + $counter++; + $counter *= $bpp; + $outbytes -= $counter; + printf("%*v02x ", " ", substr($stuff, $place, $counter)); + } else { + $counter = 257 - $counter; + $counter *= $bpp; + $outbytes -= $bpp; + my ($fchar) = sprintf "%*v02x ", " ", substr($stuff, $place, $bpp); + my ($outdata); + map { $outdata .= $fchar } (0..$counter - 1); + print $outdata; + } + $totbytes += $counter; + } + $totbytes /= $bpp; + if ($totbytes != $expected) { + print "**** Wrong byte count: got $totbytes, expected $expected!!!"; + } + } +} + +sub do_escpr() { + my ($print_width, $print_length, $bpp); + while (fill_buffer(4)) { + printf("\n%08x ", $curpos); + my ($cmd) = substr($stuff, $curoffset, 1); + my ($ncmd) = $nchartable{$cmd}; + printf(" %02x ", $ncmd); + increment_curpos(1); + if ($cmd ne "$esc") { + next; + } + my ($class) = substr($stuff, $curoffset, 1); + printf(" %s ", $class); + increment_curpos(1); + if ($class eq "@") { + return; + } + my ($skipchars) = get_long(substr($stuff, $curoffset + 0, 4)); + printf " %08x ", $skipchars; + increment_curpos(4); + fill_buffer(4); + my ($remaining) = $skipchars; + $cmd = substr($stuff, $curoffset + 0, 4); + printf(" %4s ", $cmd); + increment_curpos(4); + fill_buffer($skipchars); + if ($cmd eq "setq") { # Set Quality + my (@qualities) = qw(draft normal high); + my (@colormono) = qw(color mono); + my (@colordepth) = qw(24 8); + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, $skipchars)); + if ($opt_v) { + printf(" (Set Quality: Media: %02x Quality: %s Color: %s Brightness: %02x Contrast: %02x Saturation: %02x Color Depth: %x (%s) Palette Size: %04x)", + get_byte_at(0), + $qualities[get_byte_at(1)], + $colormono[get_byte_at(2)], + get_byte_at(3), + get_byte_at(4), + get_byte_at(5), + get_byte_at(6), + $colordepth[get_byte_at(6)], + get_short_at(7)); + } + $bpp = get_byte_at(6) ? 1 : 3; + increment_curpos($skipchars); + } elsif ($cmd eq "setj") { # Set Job + my (@resolution) = qw(360 720); + my (@direction) = qw(bi uni); + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, $skipchars)); + if ($opt_v) { + printf(" (Set Job: Paper (%d %d) (%.1f %.1f) Top %d Left %d Printable (%d %d) (%.2f %.2f) In Resolution %s Direction %s)", + get_blong_at(0), + get_blong_at(4), + get_blong_at(0) / $resolution[get_byte_at(20)], + get_blong_at(4) / $resolution[get_byte_at(20)], + get_bshort_at(8), + get_bshort_at(10), + get_blong_at(12), + get_blong_at(16), + get_blong_at(12) / $resolution[get_byte_at(20)], + get_blong_at(16) / $resolution[get_byte_at(20)], + $resolution[get_byte_at(20)], + $direction[get_byte_at(21)]); + } + $print_width = get_blong_at(12); + $print_length = get_blong_at(16); + increment_curpos($skipchars); + } elsif ($cmd eq "sttp") { # Start Page + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, $skipchars)); + } elsif ($cmd eq "dsnd") { # Data Send + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, 7)); + if ($opt_v) { + printf(" (Send Data: Offset (%d %d) Compression %d Size %d) ", + get_bshort_at(0), + get_bshort_at(2), + get_byte_at(4), + get_bshort_at(5)); + } + if ($opt_V) { + print_escpr_data(get_bshort_at(5), get_byte_at(4), $bpp, $curoffset + 7, $print_width); + increment_curpos($skipchars); + } else { + increment_curpos($skipchars); + } + } elsif ($cmd eq "bsnd") { # Data Send -- ??? + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, 34)); + my ($data_size) = get_blong_at(18) + get_blong_at(22) + get_blong_at(26); + if ($opt_v) { + printf(" (Send Data: Offset (%d %d) Compression %d Size %d %d %d = %x, delta = %x) ", + get_bshort_at(3), + get_bshort_at(5), + get_byte_at(7), + get_blong_at(18), + get_blong_at(22), + get_blong_at(26), + $data_size, + $skipchars - ($data_size + 42)) + } + if ($opt_V) { + print_escpr_data($data_size, get_byte_at(7), $bpp, $curoffset + 34, $print_width); + } + increment_curpos($skipchars); + } elsif ($cmd eq "endp") { # End Page + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, $skipchars)); + increment_curpos($skipchars); + } elsif ($cmd eq "endj") { # End Job + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, $skipchars)); + increment_curpos($skipchars); + } else { + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, $skipchars)); + increment_curpos($skipchars); + } + } +} + sub print_remote_SN($) { my ($skipchars) = @_; if ($skipchars == 1) { - print(" (Setup)"); + print(" (Setup)"); } elsif ($skipchars == 3) { my ($subcmd) = get_byte_at(1); my ($arg) = get_byte_at(2); if ($subcmd == 0) { - print(" (Feed Sequence $arg)"); + print(" (Feed Sequence $arg)"); } elsif ($subcmd == 4) { - print(" (Feed Adjustment $arg)"); + print(" (Feed Adjustment $arg)"); } elsif ($subcmd == 5) { - print(" (Vacuum Intensity $arg)"); + print(" (Vacuum Intensity $arg)"); } else { print(" (Unknown command $subcmd, arg $arg)"); } @@ -359,25 +545,16 @@ sub print_remote_PP($) { print(" (Set input slot, printer-specific)"); } -sub do_remote_command() { - printf "\n%08x 1b ( R ", $curpos; - increment_curpos(3); - fill_buffer(2); - my ($nlchar) = get_byte_at(0); - my ($nhchar) = get_byte_at(1); - my $skipchars = ($nhchar * 256) + $nlchar; - increment_curpos(2); - fill_buffer($skipchars); - print get_string_at(0, $skipchars); - increment_curpos($skipchars); +sub do_remote() { while (fill_buffer(2) && get_raw_at(0, 2) =~ /[A-Z0-9][A-Z0-9]/) { printf "\n%08x ", $curpos; my ($cmd) = get_raw_at(0, 2); print $cmd; increment_curpos(2); fill_buffer(2); - $nlchar = get_byte_at(0); - $nhchar = get_byte_at(1); + my $nlchar = get_byte_at(0); + my $nhchar = get_byte_at(1); + my $skipchars; if ($cmd eq "DF") { $skipchars = 0; } else { @@ -397,6 +574,25 @@ sub do_remote_command() { } } +sub do_remote_command() { + printf "\n%08x 1b ( R ", $curpos; + increment_curpos(3); + fill_buffer(2); + my ($nlchar) = get_byte_at(0); + my ($nhchar) = get_byte_at(1); + my $skipchars = ($nhchar * 256) + $nlchar; + increment_curpos(2); + fill_buffer($skipchars); + my $rstring = get_string_at(0, $skipchars); + print $rstring; + increment_curpos($skipchars); + if ($rstring eq "00 ESCPR") { + do_escpr(); + } else { + do_remote(); + } +} + sub print_prefix_bytes($$) { my ($bytes_to_print) = @_; printf "\n%08x 1b ", $curpos; @@ -584,7 +780,7 @@ sub do_xcmd_S($) { $height = get_short_at(7); } indent_cmd($skipchars); - printf (" (paper size %d %d %.2f %.2f)", $width, $height, + printf (" (paper size %d %d %.2f %.2f)", $width, $height, $width / $page_mgmt_unit, $height / $page_mgmt_unit); } } @@ -683,7 +879,7 @@ sub do_xcmd_d($) { sub do_xcmd_m($) { my ($skipchars) = @_; - if ($opt_v) { + if ($opt_v) { indent_cmd($skipchars); printf(" (print method %x)", get_byte_at(5)); } @@ -699,7 +895,7 @@ sub do_xcmd_e($) { sub do_xcmd_G($) { my ($skipchars) = @_; - if ($opt_v) { + if ($opt_v) { indent_cmd($skipchars); print(" (set graphics mode)"); } diff --git a/test/parse-escp2.in b/test/parse-escp2.in new file mode 100644 index 0000000..9ff3510 --- /dev/null +++ b/test/parse-escp2.in @@ -0,0 +1,1017 @@ +#!@PERL@ + +# Copyright 2000-2008 Robert Krawitz <rlk@alum.mit.edu> +# +# This program 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 should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +use Getopt::Std; +use strict; + +getopts('VvO:'); + +use vars qw($atend + $escpr + $stuff + $opt_v + $opt_V + $opt_O + $curoffset + $curpos + $esc + $initial_vertical_position + $null + $page_mgmt_unit + $horizontal_position + $horizontal_unit + $vertical_unit + $vertical_position + $raster_x + $raster_y + $print_offsets + %seqtable + @seqkeys + %chartable + %xchartable + %nchartable + %rchartable + %keylengths + $total_length + @offsets); + +$atend = 0; +$escpr = 0; +%chartable = (); +%xchartable = (); +%nchartable = (); +%rchartable = (); +%keylengths = (); + +%seqtable = ( "@", 0, + "(R", "REMOTE", + "(", "VARIABLE", + "U", 1, + "\\", 2, + "\$", 2, + "r", 1, + "\031", 1, + ".", "SPECIAL", + "i", "SPECIAL1", + "\000", 2, + "\001", 22 + ); + +map { + my ($xchar) = pack("C", $_); + if ($_ >= 32 && $_ < 127) { + $chartable{$xchar} = " $xchar"; + $xchartable{$xchar} = " *$xchar"; + $rchartable{$xchar} = $xchar; + } else { + $chartable{$xchar} = sprintf("%02x", $_); + $xchartable{$xchar} = sprintf("*%02x", $_); + $rchartable{$xchar} = sprintf("%02x ", $_); + } + $nchartable{$xchar} = $_; +} (0..255); + +@seqkeys = (sort { length $b <=> length $a } keys %seqtable); + +map { $keylengths{$_} = length $_ } @seqkeys; + +$esc = "\033"; +$null = "\000"; + +$curpos = 0; +$curoffset = 0; + +$page_mgmt_unit = 360; +$horizontal_unit = 180; +$vertical_unit = 360; + +$initial_vertical_position = 0; +$vertical_position = 0; +$horizontal_position = 0; +$print_offsets = 0; +$total_length = 0; + +sub get_long($) { + my ($string) = @_; + my ($tmp) = unpack("V", $string); + if ($tmp >= (1 << 31)) { + return -(0xffffffff ^ $tmp) - 1; + } else { + return $tmp; + } +} + +sub get_long_at($) { + my ($offset) = @_; + return get_long(substr($stuff, $curoffset + $offset, 4)) +} + +sub get_short($) { + my ($string) = @_; + my ($tmp) = unpack("v", $string); + if ($tmp >= (1 << 15)) { + return -(0xffff ^ $tmp) - 1; + } else { + return $tmp; + } +} + +sub get_raw_at($;$) { + my ($offset, $count) = @_; + $count = 1 if ! defined $count; + return substr($stuff, $curoffset + $offset, $count); +} + +sub get_short_at($) { + my ($offset) = @_; + return get_short(get_raw_at($offset, 2)) +} + +sub get_byte($) { + my ($string) = @_; + return $nchartable{substr($string, 0, 1)}; +} + +sub get_byte_at($) { + my ($offset) = @_; + return get_byte(get_raw_at($offset, 1)) +} + +sub get_blong_at($) { + my ($offset) = @_; + return get_blong(substr($stuff, $curoffset + $offset, 4)); +} + +sub get_bshort_at($) { + my ($offset) = @_; + return get_bshort(substr($stuff, $curoffset + $offset, 2)); +} + +sub get_blong($) { + my ($string) = @_; + my ($tmp) = unpack("N", $string); + if ($tmp >= (1 << 31)) { + return -(0xffffffff ^ $tmp) - 1; + } else { + return $tmp; + } +} + +sub get_bshort($) { + my ($string) = @_; + my ($tmp) = unpack("n", $string); + if ($tmp >= (1 << 15)) { + return -(0xffff ^ $tmp) - 1; + } else { + return $tmp; + } +} + +sub get_string_at($$) { + my ($offset, $count) = @_; + return join('', map { $rchartable{get_raw_at($offset + $_)}} (0..$count-1)); +} + +sub get_char_at($) { + my ($offset) = @_; + return $chartable{get_raw_at($offset, 1)}; +} + +sub get_vector_at($$;$) { + my ($offset, $count, $nospc) = @_; + my ($str) = get_raw_at($offset, $count); + if ($nospc) { + return sprintf("%*v02x ", $str); + } else { + return sprintf("%*v02x ", " ", $str); + } +} + +sub fill_buffer($) { + my ($where) = @_; + return 1 if $total_length - $curoffset >= $where; + my ($end) = $total_length - $curoffset; + if ($curpos == 0 && $end == 0) { + $stuff = <>; # Need to do this once to "activate" ARGV + $total_length = length $stuff; + $end = $total_length - $curoffset; + } + my ($old_end) = $end; + my ($tmp); + my ($bytes_to_read) = 16384; + if ($where - $end > $bytes_to_read) { + $bytes_to_read = $where - $end; + } + if ($curoffset >= 16384) { + substr($stuff, 0, $curoffset) = ""; + $total_length -= $curoffset; + $curoffset = 0; + } + while ($end < $where) { + my $foo = read ARGV, $tmp, $bytes_to_read; + $stuff .= $tmp; + $end += $foo; + $total_length += $foo; + if ($old_end == $end) { + $atend = 1; + return 0; + } else { + $bytes_to_read -= $end - $old_end; + $old_end = $end; + } + } + return 1; +} + +sub increment_curpos($) { + my ($curpos_increment) = @_; + $curpos += $curpos_increment; + $curoffset += $curpos_increment; +} + +sub print_escpr_data($$$$$) { + my ($outbytes, $compression, $bpp, $offset, $expected) = @_; + if ($compression == 0) { + printf("%*v02x ", " ", substr($stuff, $offset, $outbytes * 3)); + if ($expected != $outbytes) { + printf "**** Wrong byte count: got %d, expected %d (%x)!!!", $outbytes, $expected, $expected; + } + } else { + my ($totbytes) = 0; + my ($orig_outbytes) = $outbytes; + while ($outbytes > 0) { + my ($place) = $offset + $orig_outbytes - $outbytes; + my $counter = ord(substr($stuff, $place, 1)); + $place++; + $outbytes--; + if ($counter <= 127) { + $counter++; + $counter *= $bpp; + $outbytes -= $counter; + printf("%*v02x ", " ", substr($stuff, $place, $counter)); + } else { + $counter = 257 - $counter; + $counter *= $bpp; + $outbytes -= $bpp; + my ($fchar) = sprintf "%*v02x ", " ", substr($stuff, $place, $bpp); + my ($outdata); + map { $outdata .= $fchar } (0..$counter - 1); + print $outdata; + } + $totbytes += $counter; + } + $totbytes /= $bpp; + if ($totbytes != $expected) { + print "**** Wrong byte count: got $totbytes, expected $expected!!!"; + } + } +} + +sub do_escpr() { + my ($print_width, $print_length, $bpp); + while (fill_buffer(4)) { + printf("\n%08x ", $curpos); + my ($cmd) = substr($stuff, $curoffset, 1); + my ($ncmd) = $nchartable{$cmd}; + printf(" %02x ", $ncmd); + increment_curpos(1); + if ($cmd ne "$esc") { + next; + } + my ($class) = substr($stuff, $curoffset, 1); + printf(" %s ", $class); + increment_curpos(1); + if ($class eq "@") { + return; + } + my ($skipchars) = get_long(substr($stuff, $curoffset + 0, 4)); + printf " %08x ", $skipchars; + increment_curpos(4); + fill_buffer(4); + my ($remaining) = $skipchars; + $cmd = substr($stuff, $curoffset + 0, 4); + printf(" %4s ", $cmd); + increment_curpos(4); + fill_buffer($skipchars); + if ($cmd eq "setq") { # Set Quality + my (@qualities) = qw(draft normal high); + my (@colormono) = qw(color mono); + my (@colordepth) = qw(24 8); + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, $skipchars)); + if ($opt_v) { + printf(" (Set Quality: Media: %02x Quality: %s Color: %s Brightness: %02x Contrast: %02x Saturation: %02x Color Depth: %x (%s) Palette Size: %04x)", + get_byte_at(0), + $qualities[get_byte_at(1)], + $colormono[get_byte_at(2)], + get_byte_at(3), + get_byte_at(4), + get_byte_at(5), + get_byte_at(6), + $colordepth[get_byte_at(6)], + get_short_at(7)); + } + $bpp = get_byte_at(6) ? 1 : 3; + increment_curpos($skipchars); + } elsif ($cmd eq "setj") { # Set Job + my (@resolution) = qw(360 720); + my (@direction) = qw(bi uni); + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, $skipchars)); + if ($opt_v) { + printf(" (Set Job: Paper (%d %d) (%.1f %.1f) Top %d Left %d Printable (%d %d) (%.2f %.2f) In Resolution %s Direction %s)", + get_blong_at(0), + get_blong_at(4), + get_blong_at(0) / $resolution[get_byte_at(20)], + get_blong_at(4) / $resolution[get_byte_at(20)], + get_bshort_at(8), + get_bshort_at(10), + get_blong_at(12), + get_blong_at(16), + get_blong_at(12) / $resolution[get_byte_at(20)], + get_blong_at(16) / $resolution[get_byte_at(20)], + $resolution[get_byte_at(20)], + $direction[get_byte_at(21)]); + } + $print_width = get_blong_at(12); + $print_length = get_blong_at(16); + increment_curpos($skipchars); + } elsif ($cmd eq "sttp") { # Start Page + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, $skipchars)); + } elsif ($cmd eq "dsnd") { # Data Send + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, 7)); + if ($opt_v) { + printf(" (Send Data: Offset (%d %d) Compression %d Size %d) ", + get_bshort_at(0), + get_bshort_at(2), + get_byte_at(4), + get_bshort_at(5)); + } + if ($opt_V) { + print_escpr_data(get_bshort_at(5), get_byte_at(4), $bpp, $curoffset + 7, $print_width); + increment_curpos($skipchars); + } else { + increment_curpos($skipchars); + } + } elsif ($cmd eq "bsnd") { # Data Send -- ??? + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, 34)); + my ($data_size) = get_blong_at(18) + get_blong_at(22) + get_blong_at(26); + if ($opt_v) { + printf(" (Send Data: Offset (%d %d) Compression %d Size %d %d %d = %x, delta = %x) ", + get_bshort_at(3), + get_bshort_at(5), + get_byte_at(7), + get_blong_at(18), + get_blong_at(22), + get_blong_at(26), + $data_size, + $skipchars - ($data_size + 42)) + } + if ($opt_V) { + print_escpr_data($data_size, get_byte_at(7), $bpp, $curoffset + 34, $print_width); + } + increment_curpos($skipchars); + } elsif ($cmd eq "endp") { # End Page + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, $skipchars)); + increment_curpos($skipchars); + } elsif ($cmd eq "endj") { # End Job + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, $skipchars)); + increment_curpos($skipchars); + } else { + printf("%*v02x ", " ", substr($stuff, $curoffset + 0, $skipchars)); + increment_curpos($skipchars); + } + } +} + +sub print_remote_SN($) { + my ($skipchars) = @_; + if ($skipchars == 1) { + print(" (Setup)"); + } elsif ($skipchars == 3) { + my ($subcmd) = get_byte_at(1); + my ($arg) = get_byte_at(2); + if ($subcmd == 0) { + print(" (Feed Sequence $arg)"); + } elsif ($subcmd == 4) { + print(" (Feed Adjustment $arg)"); + } elsif ($subcmd == 5) { + print(" (Vacuum Intensity $arg)"); + } else { + print(" (Unknown command $subcmd, arg $arg)"); + } + } else { + print(" (Unknown command)"); + } +} + +sub print_remote_DR($) { + my ($skipchars) = @_; + if ($skipchars == 4) { + my ($subcmd) = get_byte_at(1); + my ($arg) = get_short_at(2); + if ($subcmd == 0) { + printf(" (Scan dry time %.1f)", $arg / 10.0); + } elsif ($subcmd == 1) { + printf(" (Page dry time %.1f)", $arg / 10.0); + } elsif ($subcmd == 0x40) { + printf(" (Scan minimum dry time %.1f)", $arg / 10.0); + } else { + print(" (Unknown command $subcmd, arg $arg)"); + } + } else { + print(" (Unknown command)"); + } +} + +sub print_remote_CO($) { + my ($skipchars) = @_; + if ($skipchars == 8) { + my ($cmd) = get_byte_at(2); + my ($arg) = get_long_at(4); + if ($cmd == 0) { + print(" (cut)"); + } elsif ($cmd == 1) { + print(" (cut all at $arg)"); + } elsif ($cmd == 2) { + print(" (cut last at $arg)"); + } else { + print(" (Unknown command $cmd)"); + } + } else { + print(" (unknown command)"); + } +} + +sub print_remote_MI($) { + my ($skipchars) = @_; + if ($skipchars == 4) { + my ($media) = get_byte_at(2); + my ($size) = get_byte_at(3); + print(" (Media type $media, size code $size)"); + } else { + print(" (unknown command)"); + } +} + +sub print_remote_DP($) { + my ($skipchars) = @_; + if ($skipchars == 2) { + my ($cmd) = get_byte_at(1); + if ($cmd == 0) { + print(" (no duplex)"); + } elsif ($cmd == 1) { + print(" (duplex no tumble)"); + } elsif ($cmd == 2) { + print(" (duplex tumble)"); + } else { + print(" (unknown duplex command $cmd)"); + } + } else { + print(" (unknown command)"); + } +} + +sub print_remote_PH($) { + my ($skipchars) = @_; + if ($skipchars == 2) { + my ($thickness) = get_byte_at(1); + print(" (Paper thickness $thickness)"); + } else { + print(" (unknown command)"); + } +} + +sub print_remote_US($) { + my ($skipchars) = @_; + if ($skipchars == 3) { + my ($cmd) = get_byte_at(1); + my ($arg) = get_byte_at(2); + if ($cmd == 1) { + print(" (Platen gap $arg)"); + } else { + print(" (Unknown command $cmd, arg $arg)"); + } + } else { + print(" (unknown command)"); + } +} + +sub print_remote_FP($) { + my ($skipchars) = @_; + if ($skipchars == 3) { + my ($offset) = get_short_at(1); + print(" (Full bleed, offset $offset)"); + } else { + print(" (unknown command)"); + } +} + +sub print_remote_IK($) { + my ($skipchars) = @_; + if ($skipchars == 2) { + my ($ink_type) = get_byte_at(1); + my ($ink) = $ink_type >= 0x80 ? "matte" : "photo"; + print(" (Ink type $ink_type, probably $ink)"); + } else { + print(" (unknown command)"); + } +} + +sub print_remote_JS($) { + my ($skipchars) = @_; + print(" (Job start)"); +} + +sub print_remote_JE($) { + my ($skipchars) = @_; + print(" (Job end)"); +} + +sub print_remote_PP($) { + my ($skipchars) = @_; + print(" (Set input slot, printer-specific)"); +} + +sub do_remote() { + while (fill_buffer(2) && get_raw_at(0, 2) =~ /[A-Z0-9][A-Z0-9]/) { + printf "\n%08x ", $curpos; + my ($cmd) = get_raw_at(0, 2); + print $cmd; + increment_curpos(2); + fill_buffer(2); + my $nlchar = get_byte_at(0); + my $nhchar = get_byte_at(1); + my $skipchars; + if ($cmd eq "DF") { + $skipchars = 0; + } else { + $skipchars = ($nhchar * 256) + $nlchar; + } + printf(" %02x %02x ", $nlchar, $nhchar); + increment_curpos(2); + fill_buffer($skipchars); + print get_vector_at(0, $skipchars); + if ($opt_v) { + if (eval "defined \&print_remote_$cmd") { + map { print(" "); } ($skipchars...5) if ($skipchars < 6); + eval "print_remote_$cmd($skipchars)"; + } + } + increment_curpos($skipchars); + } +} + +sub do_remote_command() { + printf "\n%08x 1b ( R ", $curpos; + increment_curpos(3); + fill_buffer(2); + my ($nlchar) = get_byte_at(0); + my ($nhchar) = get_byte_at(1); + my $skipchars = ($nhchar * 256) + $nlchar; + increment_curpos(2); + fill_buffer($skipchars); + my $rstring = get_string_at(0, $skipchars); + print $rstring; + increment_curpos($skipchars); + if ($rstring eq "00 ESCPR") { + do_escpr(); + } else { + do_remote(); + } +} + +sub print_prefix_bytes($$) { + my ($bytes_to_print) = @_; + printf "\n%08x 1b ", $curpos; + fill_buffer($bytes_to_print); + print get_char_at(1), " ", get_vector_at(2, $bytes_to_print - 2); + increment_curpos($bytes_to_print); +} + +sub print_output_data($$$$$$) { + my ($comptype, $bitsperpixel, $dots, $rows, $dot_scale, $color) = @_; + my $counter; + my $fchar; + my $last_row = 0; + my $first_row = -1; + my $i; + my $vstuff; + $dots *= 8; + $dots /= $dot_scale; + my $real_dots = $dots / $bitsperpixel; + if ($opt_v) { + my ($xcolor) = sprintf("%02x", $color); + print " ($xcolor color $real_dots dots, $rows rows, $bitsperpixel bits"; + } + my $savedots = $dots; + if ($comptype == 0) { + foreach $i (0..$rows-1) { + fill_buffer($dots / 8); + print get_vector_at(0, $dots / 8) if ($opt_V); + increment_curpos($dots / 8); + } + } elsif ($comptype == 1) { + foreach $i (0..$rows-1) { + my ($found_something) = 0; + $dots = $savedots; + my ($tstuff) = "\n $i "; + while ($dots > 0) { + fill_buffer(1); + $counter = ord(substr($stuff, $curoffset + 0, 1)); + increment_curpos(1); + if ($counter <= 127) { + $counter++; + fill_buffer($counter); + if ($opt_v || $opt_V) { + my $tmp = get_vector_at(0, $counter); + if (!($tmp =~ /^[0 ]+$/)) { + $found_something = 1; + $last_row = $i; + if ($first_row == -1) { + $first_row = $i; + } + } + if ($opt_V) { + $tstuff .= $tmp; + } + } + increment_curpos($counter); + } else { + $counter = 257 - $counter; + fill_buffer(1); + if ($opt_v || $opt_V) { + $fchar = sprintf "%v02x ", get_raw_at(0, 1); + if ($fchar ne "00 ") { + $found_something = 1; + $last_row = $i; + if ($first_row == -1) { + $first_row = $i; + } + } + } + if ($opt_V) { + map { $tstuff .= $fchar } (0..$counter - 1); + } + increment_curpos(1); + } + $dots -= $counter * 8; + } + if ($opt_V && $found_something) { + $vstuff .= $tstuff; + } + } + } else { + print "\nUnknown compression type $comptype!\n"; + } + if ($opt_v) { + my ($offset) = $offsets[$color]; + my ($first_position) = ($vertical_position / $vertical_unit) + + ($first_row + $offset) * $raster_y; + my ($last_position) = ($vertical_position / $vertical_unit) + + ($last_row + $offset) * $raster_y; + my ($final_position) = ($vertical_position / $vertical_unit) + + ($rows + $offset) * $raster_y; + my ($final_horizontal) = $horizontal_position + + ($real_dots * $page_mgmt_unit * $raster_x); + if ($print_offsets) { + printf (" %d,%d+%d %.4f %d,%d+%d %.4f %.4f) ", + $horizontal_position, $first_row, $offset, $first_position, + $final_horizontal, $last_row, $offset, $last_position, + $final_position); + } else { + printf (" %d,%d %.4f %d,%d %.4f %.4f) ", + $horizontal_position, $first_row, $first_position, + $final_horizontal, $last_row, $last_position, + $final_position); + } + } + if ($opt_V) { + print " $vstuff"; + } +} + +sub purge_line() { + fill_buffer(1); + while (get_raw_at(0) eq "\r") { + fill_buffer(1); + increment_curpos(1); + } +} + +sub do_special_command() { + fill_buffer(8); + my $comptype = get_byte_at(2); + my $color = 0; + my $dots = get_short_at(6); + my $rows = get_byte_at(5); + print_prefix_bytes(8, 2); + print_output_data($comptype, 1, $dots, $rows, 8, $color); + purge_line(); +} + +sub do_special1_command() { + fill_buffer(9); + my $color = get_byte_at(2); + my $comptype = get_byte_at(3); + my $bitsperpixel = get_byte_at(4); + my $dots = get_short_at(5); + my $rows = get_short_at(7); + print_prefix_bytes(9, 1); + print_output_data($comptype, $bitsperpixel, $dots, $rows, 1, $color); + purge_line(); +} + +if ($opt_O) { + my (@stuff) = split(/,/, $opt_O); + map { + my ($key, $val) = split(/=/, $_); + if ($val) { + $print_offsets = 1; + } + @offsets[$key] = $val; + } @stuff; +} + +sub indent_cmd($) { + my ($skipchars) = @_; + map { print(" "); } ($skipchars...3) if ($skipchars < 4); +} + +sub do_xcmd_c($) { + my ($skipchars) = @_; + my ($top, $bottom); + if ($skipchars == 8) { + $top = get_long_at(5); + $bottom = get_long_at(9) if ($opt_v); + } else { + $top = get_short_at(5); + $bottom = get_short_at(7) if ($opt_v); + } + if ($opt_v) { + printf (" (page format %d %d %.2f %.2f)", $top, $bottom, + $top / $page_mgmt_unit, $bottom / $page_mgmt_unit); + } + $initial_vertical_position = $top * $vertical_unit / $page_mgmt_unit; + $vertical_position = $initial_vertical_position; +} + +sub do_xcmd_S($) { + my ($skipchars) = @_; + if ($opt_v) { + my ($width, $height); + if ($skipchars == 8) { + $width = get_long_at(5); + $height = get_long_at(9); + } else { + $width = get_short_at(5); + $height = get_short_at(7); + } + indent_cmd($skipchars); + printf (" (paper size %d %d %.2f %.2f)", $width, $height, + $width / $page_mgmt_unit, $height / $page_mgmt_unit); + } +} + +sub do_xcmd_C($) { + my ($skipchars) = @_; + if ($opt_v) { + my ($length); + if ($skipchars == 4) { + $length = get_long_at(5); + } else { + $length = get_short_at(5); + } + indent_cmd($skipchars); + printf (" (page length %d %.2f)", $length, $length / $page_mgmt_unit); + } +} + +sub do_xcmd_D($) { + my ($skipchars) = @_; + my $base = get_short_at(5); + my $y = get_byte_at(7); + my $x = get_byte_at(8); + $raster_x = $x / $base; + $raster_y = $y / $base; + if ($opt_v) { + indent_cmd($skipchars); + printf (" (raster base %d, %d x %d)", $base, $base / $x, $base / $y); + } +} + +sub do_xcmd_U($) { + my ($skipchars) = @_; + my $page_mgmt = get_byte_at(5); + if ($skipchars == 5) { + my $vertical = get_byte_at(6); + my $horiz = get_byte_at(7); + my $scale = get_short_at(8); + $page_mgmt_unit = $scale / $page_mgmt; + $horizontal_unit = $scale / $horiz; + $vertical_unit = $scale / $vertical; + if ($opt_v) { + indent_cmd($skipchars); + printf (" (units base %d mgmt %d vert %d horiz %d)", + $scale, $page_mgmt_unit, $vertical_unit, $horizontal_unit); + } + } else { + if ($opt_v) { + indent_cmd($skipchars); + printf " (units base = %d/3600)", $page_mgmt; + } + $page_mgmt_unit = 3600 / $page_mgmt; + $horizontal_unit = 3600 / $page_mgmt; + $vertical_unit = 3600 / $page_mgmt; + } +} + +sub do_xcmd_v($) { + my ($skipchars) = @_; + my ($length); + if ($skipchars == 4) { + $length = get_long_at(5); + } else { + $length = get_short_at(5); + } + $vertical_position += $length; + if ($opt_v) { + indent_cmd($skipchars); + printf (" (skip vertical %d at %d %.4f)", $length, $vertical_position, + $vertical_position / $vertical_unit); + } +} + +sub do_xcmd_dlr($) { + my ($skipchars) = @_; + if ($skipchars == 4) { + $horizontal_position = get_long_at(5); + } else { + $horizontal_position = get_short_at(5); + } + if ($opt_v) { + indent_cmd($skipchars); + printf (" (horizontal position %d %.4f)", + $horizontal_position, $horizontal_position / $horizontal_unit); + } +} + +sub do_xcmd_d($) { + my ($skipchars) = @_; + if ($opt_v) { + my ($bytes) = get_short_at(3); + indent_cmd($skipchars); + printf " (nop $bytes bytes)"; + } +} + +sub do_xcmd_m($) { + my ($skipchars) = @_; + if ($opt_v) { + indent_cmd($skipchars); + printf(" (print method %x)", get_byte_at(5)); + } +} + +sub do_xcmd_e($) { + my ($skipchars) = @_; + if ($opt_v) { + indent_cmd($skipchars); + printf(" (dot size %x)", get_byte_at(6)); + } +} + +sub do_xcmd_G($) { + my ($skipchars) = @_; + if ($opt_v) { + indent_cmd($skipchars); + print(" (set graphics mode)"); + } +} + +sub do_xcmd_K($) { + my ($skipchars) = @_; + if ($opt_v) { + indent_cmd($skipchars); + my ($ctype) = get_byte_at(6); + if ($ctype == 1) { + print(" (BW mode)"); + } elsif ($ctype == 2) { + print(" (Color mode)"); + } elsif ($ctype == 3) { + print(" (Fast 360 color mode)"); + } else { + print(" (Unknown BW/color mode)"); + } + } +} + +sub do_xcmd_i($) { + my ($skipchars) = @_; + if ($opt_v) { + indent_cmd($skipchars); + my ($ctype) = get_byte_at(5); + if ($ctype == 0) { + print(" (Soft weave)"); + } else { + printf(" (Printer weave method %d)", $ctype); + } + } +} + +while (! $atend) { + my $found; + my $skipchars; + my $startoff; + my $bytes; + my ($maxklen) = $keylengths{$seqkeys[0]}; + fill_buffer(1); + my $cchar = get_raw_at(0); + if ($cchar eq "$esc") { + $found = 0; + fill_buffer(2 + $maxklen); + foreach my $key (@seqkeys) { + my ($klen) = $keylengths{$key}; + if (get_raw_at(1, $klen) eq $key) { + $skipchars = $seqtable{$key}; + if ($skipchars eq "SPECIAL") { + do_special_command(); + $found = 2; + } elsif ($skipchars eq "SPECIAL1") { + do_special1_command(); + $found = 2; + } elsif ($skipchars eq "REMOTE") { + do_remote_command(); + $found = 2; + } else { + printf "\n%08x 1b ", $curpos; + $startoff = 0; + my $print_stuff = 0; + my $print_variable = 0; + if ($skipchars eq "VARIABLE") { + fill_buffer(3); + $print_variable = 1; + my $nlchar = get_byte_at($klen + 2); + my $nhchar = get_byte_at($klen + 3); + $skipchars = ($nhchar * 256) + $nlchar; + $startoff = 3; + $print_stuff = 1; + } + my ($blen) = $skipchars + $klen + $startoff; + fill_buffer($blen + 1); + print get_char_at(1), " "; + if ($blen > 1) { + my $char = get_raw_at(2); + print get_char_at(2), " "; + if ($blen > 2) { + if ($print_variable && $char eq "d") { + print get_vector_at(3, 2); + } else { + print get_vector_at(3, $blen - 2); + } + } + } + if ($print_stuff) { + my $xchar = get_raw_at(2); + if ($xchar eq '$') { + $xchar = 'dlr'; + } + if (eval defined "defined do_xcmd_$xchar") { + eval "do_xcmd_$xchar($skipchars)"; + } + } + $found = 1; + } + $bytes = $klen + 1 + $skipchars + $startoff; + last; + } + } + if (! $found) { + printf "\n%08x 1b ", $curpos; + increment_curpos(1); + } elsif ($found == 1) { + increment_curpos($bytes); + } + } elsif ($cchar eq "\0" || $cchar eq "\f") { + printf "\n%08x $chartable{$cchar} ", $curpos; + $vertical_position = $initial_vertical_position; + increment_curpos(1); + } else { + print "$xchartable{$cchar} " if ($cchar ne "\021"); + increment_curpos(1); + } +} + +print "\n" if $curpos > 1; diff --git a/test/pcl-unprint.c b/test/pcl-unprint.c index 3d16047..aa28803 100644 --- a/test/pcl-unprint.c +++ b/test/pcl-unprint.c @@ -14,8 +14,7 @@ * for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with this program. If not, see <https://www.gnu.org/licenses/>. * * Revision History: * @@ -34,13 +33,13 @@ /* * Size of buffer used to read file */ -#define READ_SIZE 1024 +#define READ_SIZE 16384 /* * Largest data attached to a command. 1024 means that we can have up to 8192 * pixels in a row */ -#define MAX_DATA 1024 +#define MAX_DATA 16384 FILE *read_fd,*write_fd; char read_buffer[READ_SIZE]; @@ -49,6 +48,7 @@ char initial_command[3]; int initial_command_index; char final_command; int numeric_arg; +int max_data_len = 0; int read_pointer; int read_size; @@ -62,6 +62,7 @@ int skip_output = 0; typedef struct { int colour_type; /* Mono, 3/4 colour */ + int pixel_type; /* Mono, CMY, RGB */ int black_depth; /* 2 level, 4 level */ int cyan_depth; /* 2 level, 4 level */ int magenta_depth; /* 2 level, 4 level */ @@ -93,43 +94,92 @@ typedef struct { int buffer_length; int active_length; /* Length of output data */ int output_depth; + int input_depth; + int pixels_depth; } output_t; #define PCL_MONO 1 #define PCL_CMY 3 #define PCL_CMYK 4 #define PCL_CMYKcm 6 +#define PCL_RGB 65 #define PCL_COMPRESSION_NONE 0 #define PCL_COMPRESSION_RUNLENGTH 1 #define PCL_COMPRESSION_TIFF 2 #define PCL_COMPRESSION_DELTA 3 +#define PCL_COMPRESSION_ADAPTIVE 5 #define PCL_COMPRESSION_CRDR 9 /* Compressed row delta replacement */ /* PCL COMMANDS */ typedef enum { - PCL_RESET = 1,PCL_MEDIA_SIZE,PCL_PERF_SKIP,PCL_TOP_MARGIN,PCL_MEDIA_TYPE, - PCL_MEDIA_SOURCE,PCL_SHINGLING,PCL_RASTERGRAPHICS_QUALITY,PCL_DEPLETION, - PCL_CONFIGURE,PCL_RESOLUTION,PCL_COLOURTYPE,PCL_COMPRESSIONTYPE, - PCL_LEFTRASTER_POS,PCL_TOPRASTER_POS,PCL_RASTER_WIDTH,PCL_RASTER_HEIGHT, - PCL_START_RASTER,PCL_END_RASTER,PCL_END_COLOUR_RASTER,PCL_DATA,PCL_DATA_LAST, - PCL_PRINT_QUALITY,PCL_ENTER_PJL,PCL_GRAY_BALANCE,PCL_DRIVER_CONFIG, - PCL_PAGE_ORIENTATION,PCL_VERTICAL_CURSOR_POSITIONING_BY_DOTS, - PCL_HORIZONTAL_CURSOR_POSITIONING_BY_DOTS,PCL_UNIT_OF_MEASURE, - PCL_RELATIVE_VERTICAL_PIXEL_MOVEMENT,PCL_PALETTE_CONFIGURATION, - PCL_LPI,PCL_CPI,PCL_PAGE_LENGTH,PCL_NUM_COPIES,PCL_DUPLEX, - PCL_MEDIA_SIDE,RTL_CONFIGURE,PCL_ENTER_PCL,PCL_ENTER_HPGL2, - PCL_NEGATIVE_MOTION,PCL_MEDIA_DEST,PCL_JOB_SEPARATION, - PCL_LEFT_OFFSET_REGISTRATION,PCL_TOP_OFFSET_REGISTRATION, - PCL_PRINT_DIRECTION,PCL_LEFT_MARGIN,PCL_RIGHT_MARGIN, - PCL_RESET_MARGINS,PCL_TEXT_LENGTH + PCL_RESET = 1, + PCL_MEDIA_SIZE, + PCL_PERF_SKIP, + PCL_TOP_MARGIN, + PCL_MEDIA_TYPE, + PCL_MEDIA_SOURCE, + PCL_SHINGLING, + PCL_RASTERGRAPHICS_QUALITY, + PCL_DEPLETION, + PCL_CONFIGURE, + PCL_RESOLUTION, + PCL_COLOURTYPE, + PCL_COMPRESSIONTYPE, + PCL_LEFTRASTER_POS, + PCL_TOPRASTER_POS, + PCL_RASTER_WIDTH, + PCL_RASTER_HEIGHT, + PCL_START_RASTER, + PCL_END_RASTER, + PCL_END_COLOUR_RASTER, + PCL_DATA, + PCL_DATA_LAST, + PCL_PRINT_QUALITY, + PCL_ENTER_PJL, + PCL_GRAY_BALANCE, + PCL_DRIVER_CONFIG, + PCL_PAGE_ORIENTATION, + PCL_VERTICAL_CURSOR_POSITIONING_BY_DOTS, + PCL_HORIZONTAL_CURSOR_POSITIONING_BY_DOTS, + PCL_UNIT_OF_MEASURE, + PCL_RELATIVE_VERTICAL_PIXEL_MOVEMENT, + PCL_PALETTE_CONFIGURATION, + PCL_LPI, + PCL_CPI, + PCL_PAGE_LENGTH, + PCL_NUM_COPIES, + PCL_DUPLEX, + PCL_MEDIA_SIDE, + PCL_RTL_CONFIGURE, + PCL_ENTER_PCL, + PCL_ENTER_HPGL2, + PCL_NEGATIVE_MOTION, + PCL_MEDIA_DEST, + PCL_JOB_SEPARATION, + PCL_LEFT_OFFSET_REGISTRATION, + PCL_TOP_OFFSET_REGISTRATION, + PCL_PRINT_DIRECTION, + PCL_LEFT_MARGIN, + PCL_RIGHT_MARGIN, + PCL_RESET_MARGINS,PCL_TEXT_LENGTH, + /* Added by rlk 2017-12-25 */ + PCL_RASTER_RENDER, /* Rendering algorithm */ + PCL_COLOR_COMPONENT_1, /* Color component 1 */ + PCL_COLOR_COMPONENT_2, /* Color component 2 */ + PCL_COLOR_COMPONENT_3, /* Color component 3 */ + PCL_ASSIGN_COLOR_INDEX, + PCL_SET_FOREGROUND_COLOR, + PCL_SET_VMI, + PCL_SEED_ROW_SOURCE, } command_t; typedef struct { const char initial_command[3]; /* First part of command */ const char final_command; /* Last part of command */ int has_data; /* Data follows */ + int clean_state; /* Leaves printer state clean */ command_t command; /* Command name */ const char *description; /* Text for printing */ } commands_t; @@ -137,79 +187,90 @@ typedef struct { const commands_t pcl_commands[] = { /* Two-character sequences ESC <x> */ - { "E", '\0', 0, PCL_RESET, "PCL RESET" }, - { "9", '\0', 0, PCL_RESET_MARGINS, "Reset Margins" }, - { "%", 'A', 0, PCL_ENTER_PCL, "PCL mode" }, - { "%", 'B', 0, PCL_ENTER_HPGL2, "HPGL/2 mode" }, - { "%", 'X', 0, PCL_ENTER_PJL, "UEL/Enter PJL mode" }, + { "E", '\0', 0, 1, PCL_RESET, "PCL RESET" }, + { "9", '\0', 0, 0, PCL_RESET_MARGINS, "Reset Margins" }, + { "%", 'A', 0, 0, PCL_ENTER_PCL, "PCL mode" }, + { "%", 'B', 0, 0, PCL_ENTER_HPGL2, "HPGL/2 mode" }, + { "%", 'X', 0, 0, PCL_ENTER_PJL, "UEL/Enter PJL mode" }, /* Parameterised sequences */ /* Raster positioning */ - { "&a", 'G', 0, PCL_MEDIA_SIDE, "Set Media Side" }, - { "&a", 'H', 0, PCL_LEFTRASTER_POS, "Left Raster Position" }, - { "&a", 'L', 0, PCL_LEFT_MARGIN, "Left Margin by Column" }, - { "&a", 'M', 0, PCL_RIGHT_MARGIN, "Right Margin by Column" }, - { "&a", 'N', 0, PCL_NEGATIVE_MOTION, "Negative Motion" }, - { "&a", 'P', 0, PCL_PRINT_DIRECTION, "Print Direction" }, - { "&a", 'V', 0, PCL_TOPRASTER_POS, "Top Raster Position" }, + { "&a", 'G', 0, 0, PCL_MEDIA_SIDE, "Set Media Side" }, + { "&a", 'H', 0, 0, PCL_LEFTRASTER_POS, "Left Raster Position" }, + { "&a", 'L', 0, 0, PCL_LEFT_MARGIN, "Left Margin by Column" }, + { "&a", 'M', 0, 0, PCL_RIGHT_MARGIN, "Right Margin by Column" }, + { "&a", 'N', 0, 0, PCL_NEGATIVE_MOTION, "Negative Motion" }, + { "&a", 'P', 0, 0, PCL_PRINT_DIRECTION, "Print Direction" }, + { "&a", 'V', 0, 0, PCL_TOPRASTER_POS, "Top Raster Position" }, /* Characters */ - { "&k", 'H', 0, PCL_CPI, "Characters per Inch" }, + { "&k", 'H', 0, 0, PCL_CPI, "Characters per Inch" }, /* Media */ - { "&l", 'A', 0, PCL_MEDIA_SIZE , "Media Size" }, - { "&l", 'D', 0, PCL_LPI , "Lines per Inch" }, - { "&l", 'E', 0, PCL_TOP_MARGIN , "Top Margin" }, - { "&l", 'F', 0, PCL_TEXT_LENGTH , "Text Length" }, - { "&l", 'G', 0, PCL_MEDIA_DEST, "Media Destination" }, - { "&l", 'H', 0, PCL_MEDIA_SOURCE, "Media Source" }, - { "&l", 'L', 0, PCL_PERF_SKIP , "Perf. Skip" }, - { "&l", 'M', 0, PCL_MEDIA_TYPE , "Media Type" }, - { "&l", 'O', 0, PCL_PAGE_ORIENTATION, "Page Orientation" }, - { "&l", 'P', 0, PCL_PAGE_LENGTH, "Page Length in Lines" }, - { "&l", 'S', 0, PCL_DUPLEX, "Duplex mode" }, - { "&l", 'T', 0, PCL_JOB_SEPARATION, "Job Separation" }, - { "&l", 'U', 0, PCL_LEFT_OFFSET_REGISTRATION, "Left Offset Registration" }, - { "&l", 'X', 0, PCL_NUM_COPIES, "Number of copies" }, - { "&l", 'Z', 0, PCL_TOP_OFFSET_REGISTRATION, "Top Offset Registration" }, + { "&l", 'A', 0, 0, PCL_MEDIA_SIZE , "Media Size" }, + { "&l", 'C', 0, 0, PCL_SET_VMI, "Set Vertical Line Spacing" }, + { "&l", 'D', 0, 0, PCL_LPI , "Lines per Inch" }, + { "&l", 'E', 0, 0, PCL_TOP_MARGIN , "Top Margin" }, + { "&l", 'F', 0, 0, PCL_TEXT_LENGTH , "Text Length" }, + { "&l", 'G', 0, 0, PCL_MEDIA_DEST, "Media Destination" }, + { "&l", 'H', 0, 0, PCL_MEDIA_SOURCE, "Media Source" }, + { "&l", 'L', 0, 0, PCL_PERF_SKIP , "Perf. Skip" }, + { "&l", 'M', 0, 0, PCL_MEDIA_TYPE , "Media Type" }, + { "&l", 'O', 0, 0, PCL_PAGE_ORIENTATION, "Page Orientation" }, + { "&l", 'P', 0, 0, PCL_PAGE_LENGTH, "Page Length in Lines" }, + { "&l", 'S', 0, 0, PCL_DUPLEX, "Duplex mode" }, + { "&l", 'T', 0, 0, PCL_JOB_SEPARATION, "Job Separation" }, + { "&l", 'U', 0, 0, PCL_LEFT_OFFSET_REGISTRATION, "Left Offset Registration" }, + { "&l", 'X', 0, 0, PCL_NUM_COPIES, "Number of copies" }, + { "&l", 'Z', 0, 0, PCL_TOP_OFFSET_REGISTRATION, "Top Offset Registration" }, /* Units */ - { "&u", 'D', 0, PCL_UNIT_OF_MEASURE, "Unit of Measure" }, /* from bpd05446 */ + { "&u", 'D', 0, 0, PCL_UNIT_OF_MEASURE, "Unit of Measure" }, /* from bpd05446 */ /* Raster data */ - { "*b", 'B', 0, PCL_GRAY_BALANCE, "Gray Balance" }, /* from PCL Developer's Guide 6.0 */ - { "*b", 'M', 0, PCL_COMPRESSIONTYPE, "Compression Type" }, - { "*b", 'V', 1, PCL_DATA, "Data, intermediate" }, - { "*b", 'W', 1, PCL_DATA_LAST, "Data, last" }, - { "*b", 'Y', 0, PCL_RELATIVE_VERTICAL_PIXEL_MOVEMENT, "Relative Vertical Pixel Movement" }, + { "*b", 'B', 0, 0, PCL_GRAY_BALANCE, "Gray Balance" }, /* from PCL Developer's Guide 6.0 */ + { "*b", 'M', 0, 0, PCL_COMPRESSIONTYPE, "Compression Type" }, + { "*b", 'S', 0, 0, PCL_SEED_ROW_SOURCE, "Seed row # source" }, + { "*b", 'V', 1, 0, PCL_DATA, "Data, intermediate" }, + { "*b", 'W', 1, 0, PCL_DATA_LAST, "Data, last" }, + { "*b", 'Y', 0, 0, PCL_RELATIVE_VERTICAL_PIXEL_MOVEMENT, "Relative Vertical Pixel Movement" }, /* Palette */ - { "*d", 'W', 1, PCL_PALETTE_CONFIGURATION, "Palette Configuration" }, + { "*d", 'W', 1, 0, PCL_PALETTE_CONFIGURATION, "Palette Configuration" }, /* Plane configuration */ - { "*g", 'W', 1, PCL_CONFIGURE, "Configure Raster Data" }, + { "*g", 'W', 1, 0, PCL_CONFIGURE, "Configure Raster Data" }, /* Raster Graphics */ - { "*o", 'D', 0, PCL_DEPLETION, "Depletion" }, - { "*o", 'M', 0, PCL_PRINT_QUALITY, "Print Quality" }, - { "*o", 'Q', 0, PCL_SHINGLING, "Raster Graphics Shingling" }, - { "*o", 'W', 1, PCL_DRIVER_CONFIG, "Driver Configuration Command" }, + { "*o", 'D', 0, 0, PCL_DEPLETION, "Depletion" }, + { "*o", 'M', 0, 0, PCL_PRINT_QUALITY, "Print Quality" }, + { "*o", 'Q', 0, 0, PCL_SHINGLING, "Raster Graphics Shingling" }, + { "*o", 'W', 1, 0, PCL_DRIVER_CONFIG, "Driver Configuration Command" }, /* Cursor Positioning */ - { "*p", 'X', 0, PCL_HORIZONTAL_CURSOR_POSITIONING_BY_DOTS, "Horizontal Cursor Positioning by Dots" }, - { "*p", 'Y', 0, PCL_VERTICAL_CURSOR_POSITIONING_BY_DOTS, "Vertical Cursor Positioning by Dots" }, + { "*p", 'X', 0, 0, PCL_HORIZONTAL_CURSOR_POSITIONING_BY_DOTS, "Horizontal Cursor Positioning by Dots" }, + { "*p", 'Y', 0, 0, PCL_VERTICAL_CURSOR_POSITIONING_BY_DOTS, "Vertical Cursor Positioning by Dots" }, /* Raster graphics */ - { "*r", 'A', 0, PCL_START_RASTER, "Start Raster Graphics" }, - { "*r", 'B', 0, PCL_END_RASTER, "End Raster Graphics"}, - { "*r", 'C', 0, PCL_END_COLOUR_RASTER, "End Colour Raster Graphics" }, - { "*r", 'Q', 0, PCL_RASTERGRAPHICS_QUALITY, "Raster Graphics Quality" }, - { "*r", 'S', 0, PCL_RASTER_WIDTH, "Raster Width" }, - { "*r", 'T', 0, PCL_RASTER_HEIGHT, "Raster Height" }, - { "*r", 'U', 0, PCL_COLOURTYPE, "Colour Type" }, + { "*r", 'A', 0, 0, PCL_START_RASTER, "Start Raster Graphics" }, + { "*r", 'B', 0, 0, PCL_END_RASTER, "End Raster Graphics"}, + { "*r", 'C', 0, 0, PCL_END_COLOUR_RASTER, "End Colour Raster Graphics" }, + { "*r", 'Q', 0, 0, PCL_RASTERGRAPHICS_QUALITY, "Raster Graphics Quality" }, + { "*r", 'S', 0, 0, PCL_RASTER_WIDTH, "Raster Width" }, + { "*r", 'T', 0, 0, PCL_RASTER_HEIGHT, "Raster Height" }, + { "*r", 'U', 0, 0, PCL_COLOURTYPE, "Colour Type" }, /* Resolution */ - { "*t", 'R', 0, PCL_RESOLUTION, "Resolution" }, + { "*t", 'R', 0, 0, PCL_RESOLUTION, "Resolution" }, + { "*t", 'J', 0, 0, PCL_RASTER_RENDER, "Render Algorithm" }, /* RTL/PCL5 */ - { "*v", 'W', 1, RTL_CONFIGURE, "RTL Configure Image Data" }, + { "*v", 'W', 1, 0, PCL_RTL_CONFIGURE, "RTL Configure Image Data" }, + { "*v", 'A', 0, 0, PCL_COLOR_COMPONENT_1, "Color Component 1" }, + { "*v", 'B', 0, 0, PCL_COLOR_COMPONENT_2, "Color Component 2" }, + { "*v", 'C', 0, 0, PCL_COLOR_COMPONENT_3, "Color Component 3" }, + { "*v", 'I', 0, 0, PCL_ASSIGN_COLOR_INDEX, "Assign Color Index" }, + { "*v", 'S', 0, 0, PCL_SET_FOREGROUND_COLOR, "Set Foreground Color" }, }; int pcl_find_command (void); void fill_buffer (void); void pcl_read_command (void); void write_grey (output_t *output, image_t *image); +void write_pixel (output_t *output, image_t *image); void write_colour (output_t *output, image_t *image); int decode_tiff (char *in_buffer, int data_length, char *decode_buf, int maxlen); +int decode_delta (char *in_buffer, int data_length, char *decode_buf, + int maxlen); void pcl_reset (image_t *i); int depth_to_rows (int depth); @@ -327,19 +388,20 @@ void pcl_read_command(void) */ if (combined_command == 0) { - + int non_ff_skipped_chars = 0; if(c != (char) 0x1b) { - fprintf(stderr, "ERROR: No ESC found (out of sync?) searching... "); - /* * all we can do is to chew through the file looking for another ESC. */ skipped_chars = 0; + fprintf(stderr, " "); while (c != (char) 0x1b) { if (c == (char) 0x0c) - fprintf(stderr, "FF "); + fprintf(stderr, " FF"); + else + non_ff_skipped_chars++; skipped_chars++; fill_buffer(); if (eof == 1) { @@ -348,7 +410,10 @@ void pcl_read_command(void) } c = read_buffer[read_pointer++]; } - fprintf(stderr, "%d characters skipped.\n", skipped_chars); + if (non_ff_skipped_chars != 0) + fprintf(stderr, "ERROR: No ESC found (out of sync?) searching... "); + fprintf(stderr, " %d character%s skipped.\n", skipped_chars, + skipped_chars == 1 ? "" : "s"); } /* @@ -553,6 +618,31 @@ void write_grey(output_t *output, /* I: data */ (void) fwrite(&tb[0], sizeof(char), (size_t) crumbs, write_fd); } + +/* + * write_pixel() - write out one line of pixel PNM image + */ + +/* FIXME - other than direct by pixel */ +void write_pixel(output_t *output, /* I: data */ + image_t *image) /* I: Image data */ +{ + unsigned char *buf = (unsigned char *) (output->black_bufs[0]); + int i; + if (image->colour_type == PCL_CMY) { + for (i = 0; i < image->image_width * 3; i++) { + buf[i] = -buf[i]; + } + } + (void) fwrite(buf, sizeof(char), image->image_width * 3, write_fd); + /* Needed for delta compression */ + if (image->colour_type == PCL_CMY) { + for (i = 0; i < image->image_width * 3; i++) { + buf[i] = -buf[i]; + } + } +} + /* * write_colour() - Write out one row of RGB PNM data. */ @@ -573,6 +663,7 @@ void write_colour(output_t *output, /* I: Data buffers */ char *yellow_buf; char *black_buf; + return; cyan_buf = output->cyan_bufs[0]; magenta_buf = output->magenta_bufs[0]; yellow_buf = output->yellow_bufs[0]; @@ -581,7 +672,6 @@ void write_colour(output_t *output, /* I: Data buffers */ else black_buf = NULL; -#ifdef DEBUG fprintf(stderr, "Data Length: %d, wholebytes: %d, crumbs: %d, planes: %d\n", output->active_length, wholebytes, crumbs, image->colour_type); @@ -607,78 +697,78 @@ void write_colour(output_t *output, /* I: Data buffers */ } fprintf(stderr, "\n"); } -#endif - if (image->colour_type == PCL_CMY) { - for (i=0; i < wholebytes; i++) { - for (j=0,jj=0; j < 8; j++,jj+=3) { - tb[jj] = (((cyan_buf[i] >> (7-j)) & 1)); + if (output->pixels_depth == 1) { + if (image->colour_type == PCL_CMY) { + for (i=0; i < wholebytes; i++) { + for (j=0,jj=0; j < 8; j++,jj+=3) { + tb[jj] = (((cyan_buf[i] >> (7-j)) & 1)); + tb[jj] = output->output_depth - tb[jj]; + tb[jj+1] = (((magenta_buf[i] >> (7-j)) & 1)); + tb[jj+1] = output->output_depth - tb[jj+1]; + tb[jj+2] = (((yellow_buf[i] >> (7-j)) & 1)); + tb[jj+2] = output->output_depth - tb[jj+2]; + } + (void) fwrite(&tb[0], sizeof(char), (size_t) (8*3), write_fd); + } + for (j=0,jj=0; j < crumbs; j++,jj+=3) { + tb[jj] = (((cyan_buf[wholebytes] >> (7-j)) & 1)); tb[jj] = output->output_depth - tb[jj]; - tb[jj+1] = (((magenta_buf[i] >> (7-j)) & 1)); + tb[jj+1] = (((magenta_buf[wholebytes] >> (7-j)) & 1)); tb[jj+1] = output->output_depth - tb[jj+1]; - tb[jj+2] = (((yellow_buf[i] >> (7-j)) & 1)); + tb[jj+2] = (((yellow_buf[wholebytes] >> (7-j)) & 1)); tb[jj+2] = output->output_depth - tb[jj+2]; } - (void) fwrite(&tb[0], sizeof(char), (size_t) (8*3), write_fd); - } - for (j=0,jj=0; j < crumbs; j++,jj+=3) { - tb[jj] = (((cyan_buf[wholebytes] >> (7-j)) & 1)); - tb[jj] = output->output_depth - tb[jj]; - tb[jj+1] = (((magenta_buf[wholebytes] >> (7-j)) & 1)); - tb[jj+1] = output->output_depth - tb[jj+1]; - tb[jj+2] = (((yellow_buf[wholebytes] >> (7-j)) & 1)); - tb[jj+2] = output->output_depth - tb[jj+2]; + (void) fwrite(&tb[0], sizeof(char), (size_t) crumbs*3, write_fd); } - (void) fwrite(&tb[0], sizeof(char), (size_t) crumbs*3, write_fd); - } - else { - for (i=0; i < wholebytes; i++) { - for (j=0,jj=0; j < 8; j++,jj+=3) { -#if !defined OUTPUT_CMYK_ONLY_K && !defined OUTPUT_CMYK_ONLY_CMY - tb[jj] = ((((cyan_buf[i]|black_buf[i]) >> (7-j)) & 1)); - tb[jj+1] = ((((magenta_buf[i]|black_buf[i]) >> (7-j)) & 1)); - tb[jj+2] = ((((yellow_buf[i]|black_buf[i]) >> (7-j)) & 1)); -#endif -#ifdef OUTPUT_CMYK_ONLY_K - tb[jj] = (((black_buf[i] >> (7-j)) & 1)); - tb[jj+1] = (((black_buf[i] >> (7-j)) & 1)); - tb[jj+2] = (((black_buf[i] >> (7-j)) & 1)); -#endif -#ifdef OUTPUT_CMYK_ONLY_CMY - tb[jj] = (((cyan_buf[i] >> (7-j)) & 1)); - tb[jj+1] = (((magenta_buf[i] >> (7-j)) & 1)); - tb[jj+2] = (((yellow_buf[i] >> (7-j)) & 1)); -#endif + else { + for (i=0; i < wholebytes; i++) { + for (j=0,jj=0; j < 8; j++,jj+=3) { + #if !defined OUTPUT_CMYK_ONLY_K && !defined OUTPUT_CMYK_ONLY_CMY + tb[jj] = ((((cyan_buf[i]|black_buf[i]) >> (7-j)) & 1)); + tb[jj+1] = ((((magenta_buf[i]|black_buf[i]) >> (7-j)) & 1)); + tb[jj+2] = ((((yellow_buf[i]|black_buf[i]) >> (7-j)) & 1)); + #endif + #ifdef OUTPUT_CMYK_ONLY_K + tb[jj] = (((black_buf[i] >> (7-j)) & 1)); + tb[jj+1] = (((black_buf[i] >> (7-j)) & 1)); + tb[jj+2] = (((black_buf[i] >> (7-j)) & 1)); + #endif + #ifdef OUTPUT_CMYK_ONLY_CMY + tb[jj] = (((cyan_buf[i] >> (7-j)) & 1)); + tb[jj+1] = (((magenta_buf[i] >> (7-j)) & 1)); + tb[jj+2] = (((yellow_buf[i] >> (7-j)) & 1)); + #endif + tb[jj] = output->output_depth - tb[jj]; + tb[jj+1] = output->output_depth - tb[jj+1]; + tb[jj+2] = output->output_depth - tb[jj+2]; + } + (void) fwrite(&tb[0], sizeof(char), (size_t) (8*3), write_fd); + } + for (j=0,jj=0; j < crumbs; j++,jj+=3) { + #if !defined OUTPUT_CMYK_ONLY_K && !defined OUTPUT_CMYK_ONLY_CMY + tb[jj] = ((((cyan_buf[wholebytes]|black_buf[wholebytes]) >> (7-j)) & 1)); + tb[jj+1] = ((((magenta_buf[wholebytes]|black_buf[wholebytes]) >> (7-j)) & 1)); + tb[jj+2] = ((((yellow_buf[wholebytes]|black_buf[wholebytes]) >> (7-j)) & 1)); + #endif + #ifdef OUTPUT_CMYK_ONLY_K + tb[jj] = (((black_buf[wholebytes] >> (7-j)) & 1)); + tb[jj+1] = (((black_buf[wholebytes] >> (7-j)) & 1)); + tb[jj+2] = (((black_buf[wholebytes] >> (7-j)) & 1)); + #endif + #ifdef OUTPUT_CMYK_ONLY_CMY + tb[jj] = (((cyan_buf[wholebytes] >> (7-j)) & 1)); + tb[jj+1] = (((magenta_buf[wholebytes] >> (7-j)) & 1)); + tb[jj+2] = (((yellow_buf[wholebytes] >> (7-j)) & 1)); + #endif tb[jj] = output->output_depth - tb[jj]; tb[jj+1] = output->output_depth - tb[jj+1]; tb[jj+2] = output->output_depth - tb[jj+2]; } - (void) fwrite(&tb[0], sizeof(char), (size_t) (8*3), write_fd); - } - for (j=0,jj=0; j < crumbs; j++,jj+=3) { -#if !defined OUTPUT_CMYK_ONLY_K && !defined OUTPUT_CMYK_ONLY_CMY - tb[jj] = ((((cyan_buf[wholebytes]|black_buf[wholebytes]) >> (7-j)) & 1)); - tb[jj+1] = ((((magenta_buf[wholebytes]|black_buf[wholebytes]) >> (7-j)) & 1)); - tb[jj+2] = ((((yellow_buf[wholebytes]|black_buf[wholebytes]) >> (7-j)) & 1)); -#endif -#ifdef OUTPUT_CMYK_ONLY_K - tb[jj] = (((black_buf[wholebytes] >> (7-j)) & 1)); - tb[jj+1] = (((black_buf[wholebytes] >> (7-j)) & 1)); - tb[jj+2] = (((black_buf[wholebytes] >> (7-j)) & 1)); -#endif -#ifdef OUTPUT_CMYK_ONLY_CMY - tb[jj] = (((cyan_buf[wholebytes] >> (7-j)) & 1)); - tb[jj+1] = (((magenta_buf[wholebytes] >> (7-j)) & 1)); - tb[jj+2] = (((yellow_buf[wholebytes] >> (7-j)) & 1)); -#endif - tb[jj] = output->output_depth - tb[jj]; - tb[jj+1] = output->output_depth - tb[jj+1]; - tb[jj+2] = output->output_depth - tb[jj+2]; + (void) fwrite(&tb[0], sizeof(char), (size_t) crumbs*3, write_fd); } - (void) fwrite(&tb[0], sizeof(char), (size_t) crumbs*3, write_fd); } } - /* * decode_tiff() - Uncompress a TIFF encoded buffer */ @@ -716,7 +806,7 @@ int decode_tiff(char *in_buffer, /* I: Data buffer */ fprintf(stderr, "\n"); #endif if ((dpos + count + 1) > maxlen) { - fprintf(stderr, "ERROR: Too much expanded data (%d)!\n", dpos + count + 1); + fprintf(stderr, "ERROR: Too much expanded data (%d > %d)!\n", dpos + count + 1, maxlen); exit(EXIT_FAILURE); } memcpy(&decode_buf[dpos], &in_buffer[pos+1], (size_t) (count + 1)); @@ -728,7 +818,7 @@ int decode_tiff(char *in_buffer, /* I: Data buffer */ fprintf(stderr, "%02x repeated %d times\n", (unsigned char) in_buffer[pos + 1], 1 - count); #endif if ((dpos + 1 - count) > maxlen) { - fprintf(stderr, "ERROR: Too much expanded data (%d)!\n", dpos + 1 - count); + fprintf(stderr, "ERROR: Too much expanded data (%d > %d)!\n", dpos + 1 - count, maxlen); exit(EXIT_FAILURE); } memset(&decode_buf[dpos], in_buffer[pos + 1], (size_t) (1 - count)); @@ -752,12 +842,92 @@ int decode_tiff(char *in_buffer, /* I: Data buffer */ } /* + * decode_delta() - Uncompress a delta encoded buffer + */ + +int decode_delta(char *in_buffer, /* I: Data buffer */ + int data_length, /* I: Length of data */ + char *decode_buf, /* I/O: decoded data */ + int maxlen) /* I: Max length of decode_buf */ +{ + + unsigned command_byte = 0; + unsigned delta_bytes = 0; + unsigned offset_from_last = 0; + unsigned next_offset = 0; + + int pos = 0; + int dpos = 0; +#ifdef DEBUG + int i = 0; + int j = 0; +#endif + +#ifdef DEBUG + fprintf(stderr, ">>>Decode delta %p %d %p %d\n", in_buffer, data_length, + decode_buf, maxlen); +#endif + while(pos < data_length ) { + + command_byte = in_buffer[pos]; + delta_bytes = (((unsigned char) command_byte) >> 5) + 1; + offset_from_last = (command_byte & ((1 << 5) - 1)); + if (offset_from_last == 31) { + do { + next_offset = (unsigned char) in_buffer[++pos]; + offset_from_last += next_offset; + } while (next_offset == 0xff); + } +#ifdef DEBUG + fprintf(stderr, "%d: command %02x (delta %d, offset %d)\n", i, + (unsigned char) command_byte, delta_bytes, offset_from_last); + fprintf(stderr, " pos %d dpos %d data_length %d maxlen %d\n", + pos, dpos, data_length, maxlen); +#endif + pos++; + if (data_length - pos < delta_bytes) { + fprintf(stderr, "ERROR: data overrun in delta (delta %d, remaining %d)\n", + delta_bytes, data_length - pos); + } + dpos += offset_from_last; + (void) memcpy(decode_buf + dpos, in_buffer + pos, delta_bytes); +#ifdef DEBUG + fprintf(stderr, " "); + for (j = 0; j < delta_bytes; j++) { + fprintf(stderr, "%02x ", (unsigned char) in_buffer[pos + j]); + } + fprintf(stderr, "\n"); +#endif + pos += delta_bytes; + dpos += delta_bytes; +#ifdef DEBUG + fprintf(stderr, " pos %d dpos %d data_length %d maxlen %d\n", + pos, dpos, data_length, maxlen); + i++; +#endif + } + /* + fprintf(stderr, " Decode delta %d %d %d\n", pos, data_length, dpos); + */ + +#ifdef DEBUG + fprintf(stderr, "DELTAOUT: "); + for (i=0; i< dpos; i++) { + fprintf(stderr, "%02x ", (unsigned char) decode_buf[i]); + } + fprintf(stderr, "\n"); +#endif + return(dpos); +} + +/* * pcl_reset() - Rest image parameters to default */ void pcl_reset(image_t *i) { i->colour_type = PCL_MONO; + i->pixel_type = PCL_MONO; i->black_depth = 2; /* Assume mono */ i->cyan_depth = 0; i->magenta_depth = 0; @@ -791,6 +961,15 @@ int depth_to_rows(int depth) return(0); /* ?? */ } +static void +print_command(int index, int arg) +{ + char buf[16]; + const commands_t *cmd = &(pcl_commands[index]); + (void) snprintf(buf, 15, "%s%d%c", cmd->initial_command, arg, cmd->final_command); + fprintf(stderr, "%-8s (%s): ", buf, pcl_commands[index].description); +} + /* * Main */ @@ -802,11 +981,14 @@ int main(int argc, char *argv[]) command_t command; int i, j; /* Loop/general variables */ int image_row_counter = -1; /* Count of current row */ + int total_image_rows = 0; /* All rows seen */ int current_data_row = -1; /* Count of data rows received for this output row */ int expected_data_rows_per_row = -1; /* Expected no of data rows per output row */ image_t image_data; /* Data concerning image */ long filepos = -1; + int wrote_header = 0; + int state_is_clean = 1; /* * Holders for the decoded lines @@ -837,6 +1019,8 @@ int main(int argc, char *argv[]) output_data.buffer_length = 0; output_data.active_length = 0; output_data.output_depth = 0; + output_data.input_depth = 1; + output_data.pixels_depth = 1; received_rows = NULL; @@ -882,9 +1066,8 @@ int main(int argc, char *argv[]) while (1) { pcl_read_command(); if (eof == 1) { -/* #ifdef DEBUG */ - fprintf(stderr, "EOF while reading command.\n"); -/* #endif */ + if (! state_is_clean) + fprintf(stderr, "EOF while reading command.\n"); (void) fclose(read_fd); (void) fclose(write_fd); exit(EXIT_SUCCESS); @@ -903,6 +1086,7 @@ int main(int argc, char *argv[]) } else { command = pcl_commands[command_index].command; + state_is_clean = pcl_commands[command_index].clean_state; if (pcl_commands[command_index].has_data == 1) { /* Read the data into data_buffer */ @@ -912,7 +1096,7 @@ int main(int argc, char *argv[]) #endif if (numeric_arg > MAX_DATA) { - fprintf(stderr, "ERROR: Too much data (%d), increase MAX_DATA!\n", numeric_arg); + fprintf(stderr, "ERROR: Too much data (%d), increase MAX_DATA (%d)!\n", numeric_arg, MAX_DATA); exit(EXIT_FAILURE); } @@ -937,16 +1121,19 @@ int main(int argc, char *argv[]) } switch(command) { case PCL_RESET : - fprintf(stderr, "%s\n", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); + fprintf(stderr, "\n"); pcl_reset(&image_data); break; case PCL_RESET_MARGINS : - fprintf(stderr, "%s\n", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); + fprintf(stderr, "\n"); break; case PCL_START_RASTER : - fprintf(stderr, "%s\n", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); + fprintf(stderr, "\n"); /* Make sure we have all the stuff needed to work out what we are going to write out. */ @@ -984,8 +1171,9 @@ int main(int argc, char *argv[]) fprintf(stderr, "WARNING: Light magenta dithers not yet handled.\n"); } - if ((image_data.compression_type != PCL_COMPRESSION_NONE) && - (image_data.compression_type != PCL_COMPRESSION_TIFF)) { + if (image_data.compression_type != PCL_COMPRESSION_NONE && + image_data.compression_type != PCL_COMPRESSION_TIFF && + image_data.compression_type != PCL_COMPRESSION_DELTA) { fprintf(stderr, "Sorry, only 'no compression' or 'tiff compression' handled.\n"); i++; @@ -997,22 +1185,25 @@ int main(int argc, char *argv[]) } if (skip_output == 0) { - if (image_data.colour_type == PCL_MONO) - (void) fputs("P5\n", write_fd); /* Raw, Grey */ - else - (void) fputs("P6\n", write_fd); /* Raw, RGB */ + if (! wrote_header) { + if (image_data.colour_type == PCL_MONO && + image_data.pixel_type == PCL_MONO) + (void) fputs("P5\n", write_fd); /* Raw, Grey */ + else + (void) fputs("P6\n", write_fd); /* Raw, RGB */ - (void) fputs("# Written by pclunprint.\n", write_fd); + (void) fputs("# Written by pclunprint.\n", write_fd); -/* - * Remember the file position where we wrote the image width and height - * (you don't want to know why!) - */ + /* + * Remember the file position where we wrote the image width and height + * (you don't want to know why!) + */ - filepos = ftell(write_fd); + filepos = ftell(write_fd); - fprintf(write_fd, "%10d %10d\n", image_data.image_width, - image_data.image_height); + fprintf(write_fd, "%10d %10d\n", image_data.image_width, + image_data.image_height); + } /* * Write the depth of the image @@ -1022,7 +1213,14 @@ int main(int argc, char *argv[]) output_data.output_depth = image_data.black_depth - 1; else output_data.output_depth = image_data.cyan_depth - 1; - fprintf(write_fd, "%d\n", output_data.output_depth); + if (! wrote_header) { + if (output_data.pixels_depth > 1) + fprintf(write_fd, "%d\n", 255); + else + fprintf(write_fd, "%d\n", output_data.output_depth); + } + wrote_header = 1; + image_row_counter = 0; current_data_row = 0; @@ -1041,39 +1239,39 @@ int main(int argc, char *argv[]) output_data.buffer_length = (image_data.image_width + 7) / 8; if (output_data.black_data_rows_per_row != 0) { - output_data.black_bufs = stp_malloc(output_data.black_data_rows_per_row * sizeof (char *)); + output_data.black_bufs = stp_zalloc(output_data.black_data_rows_per_row * sizeof (char *)); for (i=0; i < output_data.black_data_rows_per_row; i++) { - output_data.black_bufs[i] = stp_malloc(output_data.buffer_length * sizeof (char)); + output_data.black_bufs[i] = stp_zalloc(output_data.buffer_length * sizeof (char) * output_data.input_depth * output_data.pixels_depth); } } if (output_data.cyan_data_rows_per_row != 0) { - output_data.cyan_bufs = stp_malloc(output_data.cyan_data_rows_per_row * sizeof (char *)); + output_data.cyan_bufs = stp_zalloc(output_data.cyan_data_rows_per_row * sizeof (char *)); for (i=0; i < output_data.cyan_data_rows_per_row; i++) { - output_data.cyan_bufs[i] = stp_malloc(output_data.buffer_length * sizeof (char)); + output_data.cyan_bufs[i] = stp_zalloc(output_data.buffer_length * sizeof (char) * output_data.input_depth * output_data.pixels_depth); } } if (output_data.magenta_data_rows_per_row != 0) { - output_data.magenta_bufs = stp_malloc(output_data.magenta_data_rows_per_row * sizeof (char *)); + output_data.magenta_bufs = stp_zalloc(output_data.magenta_data_rows_per_row * sizeof (char *)); for (i=0; i < output_data.magenta_data_rows_per_row; i++) { - output_data.magenta_bufs[i] = stp_malloc(output_data.buffer_length * sizeof (char)); + output_data.magenta_bufs[i] = stp_zalloc(output_data.buffer_length * sizeof (char) * output_data.input_depth * output_data.pixels_depth); } } if (output_data.yellow_data_rows_per_row != 0) { - output_data.yellow_bufs = stp_malloc(output_data.yellow_data_rows_per_row * sizeof (char *)); + output_data.yellow_bufs = stp_zalloc(output_data.yellow_data_rows_per_row * sizeof (char *)); for (i=0; i < output_data.yellow_data_rows_per_row; i++) { - output_data.yellow_bufs[i] = stp_malloc(output_data.buffer_length * sizeof (char)); + output_data.yellow_bufs[i] = stp_zalloc(output_data.buffer_length * sizeof (char) * output_data.input_depth * output_data.pixels_depth); } } if (output_data.lcyan_data_rows_per_row != 0) { - output_data.lcyan_bufs = stp_malloc(output_data.lcyan_data_rows_per_row * sizeof (char *)); + output_data.lcyan_bufs = stp_zalloc(output_data.lcyan_data_rows_per_row * sizeof (char *)); for (i=0; i < output_data.lcyan_data_rows_per_row; i++) { - output_data.lcyan_bufs[i] = stp_malloc(output_data.buffer_length * sizeof (char)); + output_data.lcyan_bufs[i] = stp_zalloc(output_data.buffer_length * sizeof (char) * output_data.input_depth * output_data.pixels_depth); } } if (output_data.lmagenta_data_rows_per_row != 0) { - output_data.lmagenta_bufs = stp_malloc(output_data.lmagenta_data_rows_per_row * sizeof (char *)); + output_data.lmagenta_bufs = stp_zalloc(output_data.lmagenta_data_rows_per_row * sizeof (char *)); for (i=0; i < output_data.lmagenta_data_rows_per_row; i++) { - output_data.lmagenta_bufs[i] = stp_malloc(output_data.buffer_length * sizeof (char)); + output_data.lmagenta_bufs[i] = stp_zalloc(output_data.buffer_length * sizeof (char) * output_data.input_depth * output_data.pixels_depth); } } @@ -1106,7 +1304,7 @@ int main(int argc, char *argv[]) case PCL_END_RASTER : case PCL_END_COLOUR_RASTER : - fprintf(stderr, "%s\n", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); if (skip_output == 0) { @@ -1118,9 +1316,10 @@ int main(int argc, char *argv[]) if (image_data.image_height == -1) { image_data.image_height = image_row_counter; + total_image_rows += image_row_counter; if (fseek(write_fd, filepos, SEEK_SET) != -1) { fprintf(write_fd, "%10d %10d\n", image_data.image_width, - image_data.image_height); + total_image_rows); fseek(write_fd, 0L, SEEK_END); } } @@ -1129,7 +1328,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "ERROR: Row count mismatch. Expected %d rows, got %d rows.\n", image_data.image_height, image_row_counter); else - fprintf(stderr, "\t%d rows processed.\n", image_row_counter); + fprintf(stderr, "\t%d rows processed, max %d.\n", + image_row_counter, max_data_len); image_data.image_height = -1; image_row_counter = -1; @@ -1187,8 +1387,13 @@ int main(int argc, char *argv[]) } break; + case PCL_SET_VMI : + print_command(command_index, numeric_arg); + fprintf(stderr, "\n"); + break; + case PCL_MEDIA_SIZE : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); switch (numeric_arg) { case 2 : fprintf(stderr, "Letter\n"); @@ -1215,7 +1420,7 @@ int main(int argc, char *argv[]) break; case PCL_MEDIA_TYPE : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); switch (numeric_arg) { case 0 : fprintf(stderr, "Plain\n"); @@ -1245,7 +1450,7 @@ int main(int argc, char *argv[]) break; case PCL_MEDIA_SOURCE : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); switch (numeric_arg) { case -2 : fprintf(stderr, "FEED CURRENT\n"); @@ -1281,7 +1486,7 @@ int main(int argc, char *argv[]) break; case PCL_SHINGLING : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); switch (numeric_arg) { case 0 : fprintf(stderr, "None\n"); @@ -1299,7 +1504,7 @@ int main(int argc, char *argv[]) break; case PCL_RASTERGRAPHICS_QUALITY : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); switch (numeric_arg) { case 0 : fprintf(stderr, "(set by printer controls)\n"); @@ -1316,7 +1521,7 @@ int main(int argc, char *argv[]) break; case PCL_DEPLETION : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); switch (numeric_arg) { case 1 : fprintf(stderr, "None\n"); @@ -1337,7 +1542,7 @@ int main(int argc, char *argv[]) break; case PCL_PRINT_QUALITY : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); switch (numeric_arg) { case -1 : fprintf(stderr, "Draft\n"); @@ -1355,7 +1560,7 @@ int main(int argc, char *argv[]) break; case PCL_RELATIVE_VERTICAL_PIXEL_MOVEMENT : - fprintf(stderr, "%s: %d\n", pcl_commands[command_index].description, numeric_arg); + print_command(command_index, numeric_arg); if (skip_output == 0) { @@ -1371,21 +1576,27 @@ int main(int argc, char *argv[]) for (i=0; i<expected_data_rows_per_row; i++) { - memset(received_rows[i], 0, (size_t) output_data.buffer_length * sizeof(char)); + memset(received_rows[i], 0, (size_t) output_data.buffer_length * sizeof(char) * output_data.output_depth); } for (i=0; i<numeric_arg; i++) { - if (image_data.colour_type == PCL_MONO) - write_grey(&output_data, &image_data); - else + if (image_data.colour_type == PCL_MONO) { + if (image_data.pixel_type == PCL_MONO) { + write_grey(&output_data, &image_data); + } else { + write_pixel(&output_data, &image_data); + } + } else { write_colour(&output_data, &image_data); + } image_row_counter++; } } + fprintf(stderr, "\n"); break; case PCL_DUPLEX : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); switch (numeric_arg) { case 0 : fprintf(stderr, "None\n"); @@ -1402,6 +1613,93 @@ int main(int argc, char *argv[]) } break; + case PCL_DRIVER_CONFIG : + print_command(command_index, numeric_arg); + fprintf(stderr, "(ignored)"); + fprintf(stderr, " Data: "); + for (i=0; i < numeric_arg; i++) { + fprintf(stderr, "%02x ", (unsigned char) data_buffer[i]); + } + fprintf(stderr, "\n"); + fprintf(stderr, " Device: "); + switch (data_buffer[0]) { + case 6: + fprintf(stderr, "Color Laser Printer\n"); + break; + default: + fprintf(stderr, "Unknown\n"); + break; + } + fprintf(stderr, " Function: "); + switch (data_buffer[1]) { + case 0: + fprintf(stderr, "Lightness %d\n", data_buffer[2]); + break; + case 1: + fprintf(stderr, "Saturation %d\n", data_buffer[2]); + break; + case 3: + fprintf(stderr, "Scaling Algorithm: "); + switch (data_buffer[2]) { + case 0: + fprintf(stderr, "Pixel Replication\n"); + break; + case 1: + fprintf(stderr, "Bilinear Interpolation\n"); + break; + case 2: + fprintf(stderr, "Modified Bilinear Interpolation\n"); + break; + default: + fprintf(stderr, "Unknown\n"); + } + break; + case 4: + fprintf(stderr, "Color Treatment: "); + switch (data_buffer[2]) { + case 0: + fprintf(stderr, "No Adjustment\n"); + break; + case 1: + fprintf(stderr, "Process Blue\n"); + break; + case 2: + fprintf(stderr, "Vivid Graphics\n"); + break; + case 3: + fprintf(stderr, "Transparency\n"); + break; + case 4: + fprintf(stderr, "Out of Gamut\n"); + break; + case 5: + fprintf(stderr, "CIE Lab Match\n"); + break; + case 6: + fprintf(stderr, "Screen Match\n"); + break; + default: + fprintf(stderr, "Unknown\n"); + } + break; + case 5: + fprintf(stderr, "Download Color Map: "); + switch (data_buffer[2]) { + case 1: + fprintf(stderr, "CMY Color Space\n"); + break; + case 3: + fprintf(stderr, "CIE Lab Color Space\n"); + break; + default: + fprintf(stderr, "Unknown\n"); + } + break; + default: + fprintf(stderr, "Unknown\n"); + break; + } + break; case PCL_PERF_SKIP : case PCL_TOP_MARGIN : case PCL_RESOLUTION : @@ -1412,12 +1710,10 @@ int main(int argc, char *argv[]) case PCL_PALETTE_CONFIGURATION : case PCL_UNIT_OF_MEASURE : case PCL_GRAY_BALANCE : - case PCL_DRIVER_CONFIG : case PCL_LPI : case PCL_CPI : case PCL_PAGE_LENGTH : case PCL_NUM_COPIES : - case RTL_CONFIGURE : case PCL_ENTER_PCL : case PCL_NEGATIVE_MOTION : case PCL_JOB_SEPARATION : @@ -1427,7 +1723,8 @@ int main(int argc, char *argv[]) case PCL_LEFT_MARGIN : case PCL_RIGHT_MARGIN : case PCL_TEXT_LENGTH : - fprintf(stderr, "%s: %d (ignored)", pcl_commands[command_index].description, numeric_arg); + print_command(command_index, numeric_arg); + fprintf(stderr, "(ignored)"); if (pcl_commands[command_index].has_data == 1) { fprintf(stderr, " Data: "); for (i=0; i < numeric_arg; i++) { @@ -1438,7 +1735,7 @@ int main(int argc, char *argv[]) break; case PCL_COLOURTYPE : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); image_data.colour_type = -numeric_arg; switch (image_data.colour_type) { case PCL_MONO : @@ -1465,7 +1762,7 @@ int main(int argc, char *argv[]) break; case PCL_COMPRESSIONTYPE : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); image_data.compression_type = numeric_arg; switch (image_data.compression_type) { case PCL_COMPRESSION_NONE : @@ -1477,6 +1774,12 @@ int main(int argc, char *argv[]) case PCL_COMPRESSION_TIFF : fprintf(stderr, "TIFF\n"); break; + case PCL_COMPRESSION_DELTA : + fprintf(stderr, "DELTA\n"); + break; + case PCL_COMPRESSION_ADAPTIVE : + fprintf(stderr, "ADAPTIVE (mono only)\n"); + break; case PCL_COMPRESSION_CRDR : fprintf(stderr, "Compressed Row Delta Replacement\n"); break; @@ -1487,18 +1790,70 @@ int main(int argc, char *argv[]) break; case PCL_RASTER_WIDTH : - fprintf(stderr, "%s: %d\n", pcl_commands[command_index].description, numeric_arg); + print_command(command_index, numeric_arg); + fprintf(stderr, "\n"); image_data.image_width = numeric_arg; break; case PCL_RASTER_HEIGHT : - fprintf(stderr, "%s: %d\n", pcl_commands[command_index].description, numeric_arg); + print_command(command_index, numeric_arg); + fprintf(stderr, "\n"); image_data.image_height = numeric_arg; break; + case PCL_SEED_ROW_SOURCE : + print_command(command_index, numeric_arg); + fprintf(stderr, "\n"); + break; + + case PCL_RTL_CONFIGURE : + print_command(command_index, numeric_arg); + for (i = 0; i < numeric_arg; i++) + fprintf(stderr, " %02x", (unsigned char) data_buffer[i]); + fprintf(stderr, "\n"); + fprintf(stderr, " Color Space: "); + switch (data_buffer[0]) { + case 0: + fprintf(stderr, "DeviceRGB\n"); + image_data.pixel_type = PCL_RGB; + break; + case 1: + fprintf(stderr, "DeviceCMY\n"); + image_data.pixel_type = PCL_CMY; + break; + case 2: + fprintf(stderr, "sRGB\n"); + image_data.pixel_type = PCL_RGB; + break; + default: + fprintf(stderr, "Unknown\n"); + break; + } + fprintf(stderr, " Encoding: "); + switch (data_buffer[1]) { + case 0: + case 1: + fprintf(stderr, "Indexed by %s, %d bits/index", + data_buffer[1] == 0 ? "Plane" : "Pixel", + data_buffer[2]); + output_data.input_depth = data_buffer[2]; + break; + case 2: + case 3: + fprintf(stderr, "Direct by %s, depth %d\n", + data_buffer[1] == 2 ? "Plane" : "Pixel", + data_buffer[3]); + output_data.pixels_depth = 3; + output_data.input_depth = data_buffer[3]; + break; + default: + fprintf(stderr, "Unknown\n"); + break; + } + break; + case PCL_CONFIGURE : - fprintf(stderr, "%s (size=%d)\n", pcl_commands[command_index].description, - numeric_arg); + print_command(command_index, numeric_arg); fprintf(stderr, "\tFormat: %d\n", data_buffer[0]); if (data_buffer[0] == 2) { @@ -1607,7 +1962,7 @@ int main(int argc, char *argv[]) case PCL_DATA : case PCL_DATA_LAST : if (skip_output == 1) { - fprintf(stderr, "%s, length: %d\n", pcl_commands[command_index].description, numeric_arg); + print_command(command_index, numeric_arg); } else { @@ -1618,6 +1973,8 @@ int main(int argc, char *argv[]) if (expected_data_rows_per_row == -1) fprintf(stderr, "ERROR: raster data without start raster!\n"); + if (numeric_arg > max_data_len) + max_data_len = numeric_arg; /* * The last flag indicates that this is the end of the planes for a row * so we check it against the number of planes we have seen and are @@ -1637,19 +1994,38 @@ int main(int argc, char *argv[]) /* * Accumulate the data rows for each output row,then write the image. */ +/* + fprintf(stderr, ">>>>>Current %d %p %p %p\n", + current_data_row, received_rows, + data_buffer, received_rows[current_data_row]); +*/ if (image_data.compression_type == PCL_COMPRESSION_NONE) { memcpy(received_rows[current_data_row], &data_buffer, (size_t) numeric_arg); - output_data.active_length = numeric_arg; + output_data.active_length = numeric_arg * output_data.input_depth * output_data.pixels_depth; } - else - output_data.active_length = decode_tiff(data_buffer, numeric_arg, received_rows[current_data_row], output_data.buffer_length); + else if (image_data.compression_type == PCL_COMPRESSION_TIFF) { + output_data.active_length = decode_tiff(data_buffer, numeric_arg, received_rows[current_data_row], output_data.buffer_length * output_data.input_depth * output_data.pixels_depth); + } + else if (image_data.compression_type == PCL_COMPRESSION_DELTA) { + output_data.active_length = decode_delta(data_buffer, numeric_arg, received_rows[current_data_row], output_data.buffer_length * output_data.input_depth * output_data.pixels_depth); + } + /* + fprintf(stderr, "<<<<<Current %d %p %p %p\n", + current_data_row, received_rows, + data_buffer, received_rows[current_data_row]); + */ if (command == PCL_DATA_LAST) { - if (image_data.colour_type == PCL_MONO) - write_grey(&output_data, &image_data); - else + if (image_data.colour_type == PCL_MONO) { + if (image_data.pixel_type == PCL_MONO) { + write_grey(&output_data, &image_data); + } else { + write_pixel(&output_data, &image_data); + } + } else { write_colour(&output_data, &image_data); + } current_data_row = 0; image_row_counter++; } @@ -1661,7 +2037,7 @@ int main(int argc, char *argv[]) case PCL_ENTER_HPGL2 : case PCL_ENTER_PJL : { int c; - fprintf(stderr, "%s %d\n", pcl_commands[command_index].description, numeric_arg); + print_command(command_index, numeric_arg); /* * This is a special command. Read up to the next ESC and output it. @@ -1690,7 +2066,7 @@ int main(int argc, char *argv[]) break; case PCL_PAGE_ORIENTATION : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); switch (numeric_arg) { case 0 : fprintf(stderr, "Portrait"); @@ -1712,7 +2088,7 @@ int main(int argc, char *argv[]) break; case PCL_MEDIA_SIDE : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); switch (numeric_arg) { case 0 : fprintf(stderr, "Next side"); @@ -1731,7 +2107,7 @@ int main(int argc, char *argv[]) break; case PCL_MEDIA_DEST : - fprintf(stderr, "%s: ", pcl_commands[command_index].description); + print_command(command_index, numeric_arg); switch (numeric_arg) { case 1 : fprintf(stderr, "Upper Output bin"); @@ -1746,6 +2122,39 @@ int main(int argc, char *argv[]) fprintf(stderr, " (ignored)\n"); break; + case PCL_RASTER_RENDER : + print_command(command_index, numeric_arg); + switch (numeric_arg) { + case 0 : + fprintf(stderr, "Continuous tone detail (high lpi)"); + break; + case 3 : + fprintf(stderr, "Device-best dither"); + break; + case 15 : + fprintf(stderr, "Continuous tone smooth (high lpi)"); + break; + case 18 : + fprintf(stderr, "Continuous tone basic (low lpi)"); + break; + default : + fprintf(stderr, "Unknown (%d)", numeric_arg); + break; + } + fprintf(stderr, " (ignored)\n"); + break; + case PCL_COLOR_COMPONENT_1 : + case PCL_COLOR_COMPONENT_2 : + case PCL_COLOR_COMPONENT_3 : + case PCL_ASSIGN_COLOR_INDEX : + print_command(command_index, numeric_arg); + fprintf(stderr, " (ignored)\n"); + break; + case PCL_SET_FOREGROUND_COLOR : + print_command(command_index, numeric_arg); + fprintf(stderr, " (ignored)\n"); + break; + default : fprintf(stderr, "ERROR: No handler for %s!\n", pcl_commands[command_index].description); break; diff --git a/test/run-testdither b/test/run-testdither index b402588..b6fd6ce 100755 --- a/test/run-testdither +++ b/test/run-testdither @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Driver for testdither # @@ -15,8 +15,20 @@ # for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# Don't want to run this at all as part of automated test +[ -n "$STP_TEST_SUITE" ] && exit 77 + +if [[ -n "$STP_TEST_LOG_PREFIX" ]] ; then + redir="${STP_TEST_LOG_PREFIX}${0##*/}_$$.log" + if [[ -n $BUILD_VERBOSE ]] ; then + exec > >(tee -a "$redir" >&3) + else + exec 1>>"$redir" + fi + exec 2>&1 +fi out_status=0 @@ -68,7 +80,7 @@ case "$valcount" in esac if [ -n "$valopts" ] ; then - valgrind="valgrind $valopts" + valgrind="libtool --mode=execute valgrind $valopts" fi $valgrind ./testdither diff --git a/test/run-testdither.in b/test/run-testdither.in new file mode 100644 index 0000000..b057f66 --- /dev/null +++ b/test/run-testdither.in @@ -0,0 +1,86 @@ +#!@BASHREAL@ + +# Driver for testdither +# +# Copyright 2001-2008 Robert Krawitz (rlk@alum.mit.edu) +# +# This program 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 should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# Don't want to run this at all as part of automated test +[ -n "$STP_TEST_SUITE" ] && exit 77 + +if [[ -n "$STP_TEST_LOG_PREFIX" ]] ; then + redir="${STP_TEST_LOG_PREFIX}${0##*/}_$$.log" + if [[ -n $BUILD_VERBOSE ]] ; then + exec > >(tee -a "$redir" >&3) + else + exec 1>>"$redir" + fi + exec 2>&1 +fi + +out_status=0 + +if [ -z "$srcdir" -o "$srcdir" = "." ] ; then + sdir=`pwd` +elif [ -n "`echo $srcdir |grep '^/'`" ] ; then + sdir="$srcdir" +else + sdir="`pwd`/$srcdir" +fi + +if [ -z "$STP_DATA_PATH" ] ; then + STP_DATA_PATH="$sdir/../src/xml" + export STP_DATA_PATH +fi + +if [ -z "$STP_MODULE_PATH" ] ; then + STP_MODULE_PATH="$sdir/../src/main:$sdir/../src/main/.libs" + export STP_MODULE_PATH +fi + +valcount=0 +valgrind= +valopts='' + +set_args() { + while true ; do + case "$1" in + -h*|--h*) usage ;; + -v|--valgrind) valopts='--tool=memcheck' ; valcount=`expr $valgrind + 1` ;; + -c|--cachegrind) valopts='--tool=cachegrind'; valcount=4 ;; + -g|--gdb-attach) valopts='--gdb-attach=yes' ;; + -V|--verbose) quiet= ;; + -q|--quiet) quiet=quiet ;; + --) shift; args="$@"; return ;; + *) return ;; + esac + shift + done +} + +set_args `getopt hgvqncV "$@"` + +case "$valcount" in + 1) valopts="$valopts -q --num-callers=100 --error-limit=no --leak-check=yes";; + 2) valopts="$valopts --num-callers=100 --error-limit=no --leak-resolution=high --leak-check=yes" ;; + 3) valopts="$valopts --error-limit=no --num-callers=100 --show-reachable=yes --leak-resolution=high --leak-check=yes" ;; + *) ;; +esac + +if [ -n "$valopts" ] ; then + valgrind="libtool --mode=execute valgrind $valopts" +fi + +$valgrind ./testdither diff --git a/test/run-weavetest b/test/run-weavetest index d551ac2..10c1d32 100755 --- a/test/run-weavetest +++ b/test/run-weavetest @@ -1,4 +1,17 @@ -#!/bin/sh +#!/bin/bash + +# Don't want to run this at all as part of automated test +[ -n "$STP_TEST_SUITE" ] && exit 77 + +if [[ -n "$STP_TEST_LOG_PREFIX" ]] ; then + redir="${STP_TEST_LOG_PREFIX}${0##*/}_$$.log" + if [[ -n $BUILD_VERBOSE ]] ; then + exec > >(tee -a "$redir" >&3) + else + exec 1>>"$redir" + fi + exec 2>&1 +fi if [ -z "$srcdir" -o "$srcdir" = "." ] ; then sdir=`pwd` diff --git a/test/run-weavetest.in b/test/run-weavetest.in new file mode 100644 index 0000000..731cad5 --- /dev/null +++ b/test/run-weavetest.in @@ -0,0 +1,120 @@ +#!@BASHREAL@ + +# Don't want to run this at all as part of automated test +[ -n "$STP_TEST_SUITE" ] && exit 77 + +if [[ -n "$STP_TEST_LOG_PREFIX" ]] ; then + redir="${STP_TEST_LOG_PREFIX}${0##*/}_$$.log" + if [[ -n $BUILD_VERBOSE ]] ; then + exec > >(tee -a "$redir" >&3) + else + exec 1>>"$redir" + fi + exec 2>&1 +fi + +if [ -z "$srcdir" -o "$srcdir" = "." ] ; then + sdir=`pwd` +elif [ -n "`echo $srcdir |grep '^/'`" ] ; then + sdir="$srcdir" +else + sdir="`pwd`/$srcdir" +fi + +if [ -z "$STP_DATA_PATH" ] ; then + STP_DATA_PATH="$sdir/../src/xml" + export STP_DATA_PATH +fi + +if [ -z "$STP_MODULE_PATH" ] ; then + STP_MODULE_PATH="$sdir/../src/main:$sdir/../src/main/.libs" + export STP_MODULE_PATH +fi + +passes='1,1,1 2,1,1 1,2,1 1,2,2 1,4,1 4,1,1 1,8,1 1,16,1 4,2,1 4,4,1 4,8,1 4,16,1 2,2,1 2,4,1 2,8,1 2,16,1 1,4,2 1,8,2 1,16,2 2,2,2 2,4,2 2,8,2 2,16,2 8,1,1 4,4,2 4,8,2 8,2,1 8,4,1 8,8,1 16,1,1 16,2,1 16,4,1' + +# All numbers of jets used by any printer. +jets='1 2 4 8 15 16 20 21 24 29 32 42 47 48 59 60 64 90 96 128 144 180 192 208 358 360 384' + +# All nozzle separations used by any printer at any resolution. +separations='1 2 3 4 6 8 12 16 24' + +# Weave strategies +strategies='0 1 2 3 4' +# Strategy 5 is currently broken +#strategies='5' + +# Color head arrangement (for offset-head printers such as the Epson C80) +arrangements='0 1 2 3' + +# Set to the largest possible multiple of the number of heads and +# the nozzle separation. At present, the WorkForce 40 has 384 heads spaced +# 1/360" apart, with a maximum resolution of 2880x2880. There's no +# point right now in testing anything higher than this, and it's very +# time consuming. +head_limit=3072 + +if [ $# -eq 0 ] ; then + QUIET=1 + export QUIET +fi + +# For valgrind use, use +# valgrind --partial-loads-ok=no --num-callers=50 --leak-check=yes +# +# and use these suppressions: +# +#{ +# gettext +# Addr4 +# fun:__dcigettext +# fun:__dcgettext +#} +# +#{ +# nl_load_locale +# Addr4 +# fun:_nl_load_locale +# fun:_nl_find_locale +# fun:setlocale +#} +# +#{ +# setlocale +# Addr4 +# fun:setlocale +#} +# +#{ +# c_strlen +# Addr4 +# fun:c_strlen +#} + +( +for strategy in $strategies ; do + for jet in $jets ; do + for sep in $separations ; do + start=`expr $jet \* $sep` + if [ $start -le $head_limit ] ; then + rows=`expr $start \* 5` + if [ $rows -lt 200 ] ; then + rows=200 + fi + s1=`expr $start - 1` + for f in 0 41 $start $s1 ; do + end=`expr $rows + $f + $start` + end1=`expr $rows + $f` + end2=`expr $rows + $f + 35` + for g in $end $end1 $end2 ; do + for pass in $passes ; do + for arrangement in $arrangements; do + echo "$jet $sep $pass $rows $f $g $arrangement $strategy" + done + done + done + done + fi + done + done +done) | sed 's/,/ /g' | ./escp2-weavetest diff --git a/test/test-curve b/test/test-curve new file mode 100755 index 0000000..6c5b46a --- /dev/null +++ b/test/test-curve @@ -0,0 +1,62 @@ +#!/bin/bash + +# Driver for curve tester +# +# Copyright 2018 Robert Krawitz (rlk@alum.mit.edu) +# +# This program 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 should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +if [[ -n "$STP_TEST_LOG_PREFIX" ]] ; then + redir="${STP_TEST_LOG_PREFIX}${0##*/}_$$.log" + if [[ -n $BUILD_VERBOSE ]] ; then + exec > >(tee -a "$redir" >&3) + else + exec 1>>"$redir" + fi + exec 2>&1 +fi +set -e + +retval=0 + +if [[ -z $srcdir || $srcdir = . ]] ; then + sdir=$(pwd) +elif [[ $srcdir =~ ^/ ]] ; then + sdir="$srcdir" +else + sdir="$(pwd)/$srcdir" +fi + +export STP_DATA_PATH=${STP_DATA_PATH:-"$sdir/../src/xml"} +export STP_MODULE_PATH=${STP_MODULE_PATH:-"$sdir/../src/main:$sdir/../src/main/.libs"} + +declare valgrind=0 + +function runit() { + echo "================================================================" + echo "$@" + [[ -z $STP_TEST_DEBUG ]] && "$@" +} + +case "$STP_TEST_PROFILE" in + valgrind*) + vg="libtool --mode=execute valgrind $valopts" + valgrind="$vg --num-callers=50 --leak-check=yes --error-limit=no --error-exitcode=1" + ;; + *) + valgrind= + ;; +esac + +runit $valgrind ./curve diff --git a/test/test-curve.in b/test/test-curve.in new file mode 100644 index 0000000..874a72e --- /dev/null +++ b/test/test-curve.in @@ -0,0 +1,62 @@ +#!@BASHREAL@ + +# Driver for curve tester +# +# Copyright 2018 Robert Krawitz (rlk@alum.mit.edu) +# +# This program 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 should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +if [[ -n "$STP_TEST_LOG_PREFIX" ]] ; then + redir="${STP_TEST_LOG_PREFIX}${0##*/}_$$.log" + if [[ -n $BUILD_VERBOSE ]] ; then + exec > >(tee -a "$redir" >&3) + else + exec 1>>"$redir" + fi + exec 2>&1 +fi +set -e + +retval=0 + +if [[ -z $srcdir || $srcdir = . ]] ; then + sdir=$(pwd) +elif [[ $srcdir =~ ^/ ]] ; then + sdir="$srcdir" +else + sdir="$(pwd)/$srcdir" +fi + +export STP_DATA_PATH=${STP_DATA_PATH:-"$sdir/../src/xml"} +export STP_MODULE_PATH=${STP_MODULE_PATH:-"$sdir/../src/main:$sdir/../src/main/.libs"} + +declare valgrind=0 + +function runit() { + echo "================================================================" + echo "$@" + [[ -z $STP_TEST_DEBUG ]] && "$@" +} + +case "$STP_TEST_PROFILE" in + valgrind*) + vg="libtool --mode=execute valgrind $valopts" + valgrind="$vg --num-callers=50 --leak-check=yes --error-limit=no --error-exitcode=1" + ;; + *) + valgrind= + ;; +esac + +runit $valgrind ./curve diff --git a/test/testdither.c b/test/testdither.c index 433b56b..f587c59 100644 --- a/test/testdither.c +++ b/test/testdither.c @@ -14,8 +14,7 @@ * for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H @@ -34,20 +33,20 @@ * Definitions for dither test... */ -#define IMAGE_WIDTH 5760 /* 8in * 720dpi */ -#define IMAGE_HEIGHT 2880 /* 4in * 720dpi */ -#define BUFFER_SIZE IMAGE_WIDTH +#define MAX_IMAGE_WIDTH 5760 /* 8in * 720dpi */ +#define MAX_IMAGE_HEIGHT 2880 /* 4in * 720dpi */ +#define BUFFER_SIZE MAX_IMAGE_WIDTH -#define IMAGE_MIXED 0 /* Mix of line types */ -#define IMAGE_WHITE 1 /* All white image */ -#define IMAGE_BLACK 2 /* All black image */ -#define IMAGE_COLOR 3 /* All color image */ -#define IMAGE_RANDOM 4 /* All random image */ +#define IMAGE_MIXED 0 /* Mix of line types */ +#define IMAGE_WHITE 1 /* All white image */ +#define IMAGE_BLACK 2 /* All black image */ +#define IMAGE_COLOR 3 /* All color image */ +#define IMAGE_RANDOM 4 /* All random image */ -#define DITHER_GRAY 0 /* Dither grayscale pixels */ -#define DITHER_COLOR 1 /* Dither color pixels */ -#define DITHER_PHOTO 2 /* Dither photo pixels */ -#define DITHER_CMYK 3 /* Dither photo pixels */ +#define DITHER_GRAY 0 /* Dither grayscale pixels */ +#define DITHER_COLOR 1 /* Dither color pixels */ +#define DITHER_PHOTO 2 /* Dither photo pixels */ +#define DITHER_CMYK 3 /* Dither photo pixels */ #define DITHER_PHOTO_CMYK 4 /* Dither photo pixels */ @@ -56,17 +55,20 @@ */ int image_type = IMAGE_MIXED; -int stpi_dither_type = DITHER_COLOR; +int dither_type = DITHER_COLOR; const char *dither_name = NULL; int dither_bits = 1; int write_image = 1; -int quiet; -unsigned short white_line[IMAGE_WIDTH * 6], - black_line[IMAGE_WIDTH * 6], - color_line[IMAGE_WIDTH * 6], - random_line[IMAGE_WIDTH * 6]; - -static const char *stpi_dither_types[] = /* Different dithering modes */ +int quiet = 0; +int dont_regenerate_input = 0; +int dimage_width = MAX_IMAGE_WIDTH; +int dimage_height = MAX_IMAGE_HEIGHT; +unsigned short white_line[MAX_IMAGE_WIDTH * 6], + black_line[MAX_IMAGE_WIDTH * 6], + color_line[MAX_IMAGE_WIDTH * 6], + random_line[MAX_IMAGE_WIDTH * 6]; + +static const char *dither_types[] = /* Different dithering modes */ { "gray", "color", @@ -150,7 +152,7 @@ writefunc(void *file, const char *buf, size_t bytes) static int image_width(stp_image_t *image) { - return IMAGE_WIDTH; + return dimage_width; } static stp_image_t theImage = @@ -178,8 +180,8 @@ run_one_testdither(void) lcyan[BUFFER_SIZE], /* Light cyan bitmap data */ lmagenta[BUFFER_SIZE], /* Light magenta bitmap data */ yellow[BUFFER_SIZE]; /* Yellow bitmap data */ - unsigned short rgb[IMAGE_WIDTH * 6], /* RGB buffer */ - gray[IMAGE_WIDTH]; /* Grayscale buffer */ + unsigned short rgb[MAX_IMAGE_WIDTH * 6], /* RGB buffer */ + gray[MAX_IMAGE_WIDTH]; /* Grayscale buffer */ FILE *fp = NULL; /* PPM/PGM output file */ char filename[1024]; /* Name of file */ stp_vars_t *v; /* Dither variables */ @@ -213,7 +215,7 @@ run_one_testdither(void) stp_set_string_parameter(v, "DitherAlgorithm", dither_name); stp_set_string_parameter(v, "ChannelBitDepth", "8"); - switch (stpi_dither_type) + switch (dither_type) { case DITHER_GRAY: stp_set_string_parameter(v, "PrintingMode", "BW"); @@ -231,13 +233,13 @@ run_one_testdither(void) break; } - stp_dither_init(v, &theImage, IMAGE_WIDTH, 1, 1); + stp_dither_init(v, &theImage, dimage_width, 1, 1); /* * Now dither the "page"... */ - switch (stpi_dither_type) + switch (dither_type) { case DITHER_PHOTO: stp_dither_add_channel(v, lcyan, STP_ECOLOR_C, 1); @@ -261,14 +263,14 @@ run_one_testdither(void) stp_dither_add_channel(v, black, STP_ECOLOR_K, 0); } - if (stpi_dither_type == DITHER_PHOTO) + if (dither_type == DITHER_PHOTO) stp_set_float_parameter(v, "GCRLower", 0.4 / dither_bits + 0.1); else stp_set_float_parameter(v, "GCRLower", 0.25 / dither_bits); stp_set_float_parameter(v, "GCRUpper", .5); - switch (stpi_dither_type) + switch (dither_type) { case DITHER_GRAY : switch (dither_bits) @@ -360,9 +362,9 @@ run_one_testdither(void) sprintf(filename, "%s-%s-%s-%dbit.%s", image_types[image_type], - stpi_dither_types[stpi_dither_type], + dither_types[dither_type], dither_name ? dither_name : desc.deflt.str, dither_bits, - (stpi_dither_type == DITHER_GRAY) ? "pgm" : "ppm"); + (dither_type == DITHER_GRAY) ? "pgm" : "ppm"); stp_parameter_description_destroy(&desc); @@ -376,12 +378,12 @@ run_one_testdither(void) { if ((fp = fopen(filename, "wb")) != NULL) { - if (stpi_dither_type == DITHER_GRAY) + if (dither_type == DITHER_GRAY) fputs("P5\n", fp); else fputs("P6\n", fp); - fprintf(fp, "%d\n%d\n255\n", IMAGE_WIDTH, IMAGE_HEIGHT); + fprintf(fp, "%d\n%d\n255\n", dimage_width, dimage_height); } else perror("Create"); @@ -389,7 +391,7 @@ run_one_testdither(void) (void) gettimeofday(&tv1, NULL); - for (i = 0; i < IMAGE_HEIGHT; i ++) + for (i = 0; i < dimage_height; i ++) { if (print_progress && !quiet && (i & 63) == 0) { @@ -397,7 +399,7 @@ run_one_testdither(void) fflush(stdout); } - switch (stpi_dither_type) + switch (dither_type) { case DITHER_GRAY : image_get_row(gray, i); @@ -434,8 +436,8 @@ run_one_testdither(void) if (print_progress) fputc('\r', stdout); printf("%-30s %d pix %.3f sec %.2f pix/sec\n", - filename, IMAGE_WIDTH * IMAGE_HEIGHT, compute_interval(&tv1, &tv2), - (float)(IMAGE_WIDTH * IMAGE_HEIGHT) / compute_interval(&tv1, &tv2)); + filename, dimage_width * dimage_height, compute_interval(&tv1, &tv2), + (float)(dimage_width * dimage_height) / compute_interval(&tv1, &tv2)); fflush(stdout); } return 0; @@ -472,13 +474,19 @@ run_testdither_from_cmdline(int argc, char **argv) continue; } + if (strcmp(argv[i], "dont_regenerate_input") == 0) + { + dont_regenerate_input = 1; + continue; + } + for (j = 0; j < 5; j ++) - if (strcmp(argv[i], stpi_dither_types[j]) == 0) + if (strcmp(argv[i], dither_types[j]) == 0) break; if (j < 5) { - stpi_dither_type = j; + dither_type = j; continue; } @@ -515,6 +523,10 @@ run_standard_testdithers(void) write_image = 0; quiet = 1; + dont_regenerate_input = 1; + /* For automatic test purposes, this should suffice -- rlk 20171230 */ + dimage_width = dimage_width / 8; + dimage_height = dimage_height / 8; for (j = 0; j < stp_string_list_count(desc.bounds.str); j ++) { dither_name = stp_string_list_param(desc.bounds.str, j)->name; @@ -523,9 +535,9 @@ run_standard_testdithers(void) printf("%s", dither_name); fflush(stdout); for (dither_bits = 1; dither_bits <= 2; dither_bits++) - for (stpi_dither_type = 0; - stpi_dither_type < sizeof(stpi_dither_types) / sizeof(const char *); - stpi_dither_type++) + for (dither_type = 0; + dither_type < sizeof(dither_types) / sizeof(const char *); + dither_type++) for (image_type = 0; image_type < sizeof(image_types) / sizeof(const char *); image_type++) @@ -534,7 +546,7 @@ run_standard_testdithers(void) if (status) { printf("%s %d %s %s\n", dither_name, dither_bits, - stpi_dither_types[stpi_dither_type], + dither_types[dither_type], image_types[image_type]); failures++; } @@ -568,7 +580,6 @@ image_get_row(unsigned short *data, { unsigned short *src; - switch (image_type) { case IMAGE_MIXED : @@ -604,27 +615,41 @@ image_get_row(unsigned short *data, break; } - switch (stpi_dither_type) + switch (dither_type) { case DITHER_GRAY: - memcpy(data, src, IMAGE_WIDTH * 2); + memcpy(data, src, dimage_width * 2); break; case DITHER_COLOR: - memcpy(data, src, IMAGE_WIDTH * 6); + memcpy(data, src, dimage_width * 6); break; case DITHER_CMYK: - memcpy(data, src, IMAGE_WIDTH * 8); + memcpy(data, src, dimage_width * 8); break; case DITHER_PHOTO: - memcpy(data, src, IMAGE_WIDTH * 10); + memcpy(data, src, dimage_width * 10); break; case DITHER_PHOTO_CMYK: - memcpy(data, src, IMAGE_WIDTH * 12); + memcpy(data, src, dimage_width * 12); break; } } +/* + * Much faster than built-in rand(), and quite good enough. + * From rand(3), attributed to POSIX.1-2001. + */ +static unsigned long next = 1; +static unsigned +myrand(void) +{ + next = next * 1103515245 + 12345; + return((unsigned)(next/65536) % 256); +} + +static int image_is_initialized = 0; + void image_init(void) { @@ -632,6 +657,9 @@ image_init(void) unsigned short *cptr, *rptr; + if (image_is_initialized && dont_regenerate_input) + return; + image_is_initialized = 1; /* * Set the white and black line data... @@ -644,37 +672,37 @@ image_init(void) * Fill in the color and random data... */ - for (i = IMAGE_WIDTH, cptr = color_line, rptr = random_line; i > 0; i --) + for (i = dimage_width, cptr = color_line, rptr = random_line; i > 0; i --) { /* * Do 64 color or grayscale blocks over the line... */ - j = i / (IMAGE_WIDTH / 64); + j = i / (dimage_width / 64); - switch (stpi_dither_type) + switch (dither_type) { case DITHER_GRAY: *cptr++ = 65535 * j / 63; - *rptr++ = 65535 * (rand() & 255) / 255; + *rptr++ = 65535 * myrand() / 255; break; case DITHER_COLOR: *cptr++ = 65535 * (j >> 4) / 3; *cptr++ = 65535 * ((j >> 2) & 3) / 3; *cptr++ = 65535 * (j & 3) / 3; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; break; case DITHER_CMYK: *cptr++ = 65535 * (j >> 4) / 3; *cptr++ = 65535 * ((j >> 2) & 3) / 3; *cptr++ = 65535 * (j & 3) / 3; *cptr++ = 65535 * j / 63; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; break; case DITHER_PHOTO: *cptr++ = 65535 * (j >> 4) / 3; @@ -682,11 +710,11 @@ image_init(void) *cptr++ = 65535 * (j & 3) / 3; *cptr++ = 65535 * j / 63; *cptr++ = 65535 * (j >> 4) / 3; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; break; case DITHER_PHOTO_CMYK: *cptr++ = 65535 * (j >> 4) / 3; @@ -695,12 +723,12 @@ image_init(void) *cptr++ = 65535 * j / 63; *cptr++ = 65535 * (j >> 4) / 3; *cptr++ = 65535 * ((j >> 2) & 3) / 3; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; - *rptr++ = 65535 * (rand() & 255) / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; + *rptr++ = 65535 * myrand() / 255; break; } } @@ -719,7 +747,7 @@ write_gray(FILE *fp, if (dither_bits == 1) { - for (count = IMAGE_WIDTH, byte = *black++, bit = 128; count > 0; count --) + for (count = dimage_width, byte = *black++, bit = 128; count > 0; count --) { if (byte & bit) putc(0, fp); @@ -739,8 +767,8 @@ write_gray(FILE *fp, { unsigned char kb[BUFFER_SIZE]; unsigned char *kbuf = kb; - stp_fold(black, IMAGE_WIDTH / 8, kbuf); - for (count = IMAGE_WIDTH, byte = *kbuf++, shift = 6; count > 0; count --) + stp_fold(black, dimage_width / 8, kbuf); + for (count = dimage_width, byte = *kbuf++, shift = 6; count > 0; count --) { putc(255 - 255 * ((byte >> shift) & 3) / 3, fp); @@ -775,7 +803,7 @@ write_color(FILE *fp, if (dither_bits == 1) { - for (count = IMAGE_WIDTH, cbyte = *cyan++, mbyte = *magenta++, + for (count = dimage_width, cbyte = *cyan++, mbyte = *magenta++, ybyte = *yellow++, kbyte = *black++, bit = 128; count > 0; count --) @@ -826,11 +854,11 @@ write_color(FILE *fp, unsigned char *cbuf = cb; unsigned char *mbuf = mb; unsigned char *ybuf = yb; - stp_fold(black, IMAGE_WIDTH / 8, kbuf); - stp_fold(cyan, IMAGE_WIDTH / 8, cbuf); - stp_fold(magenta, IMAGE_WIDTH / 8, mbuf); - stp_fold(yellow, IMAGE_WIDTH / 8, ybuf); - for (count = IMAGE_WIDTH, cbyte = *cbuf++, mbyte = *mbuf++, + stp_fold(black, dimage_width / 8, kbuf); + stp_fold(cyan, dimage_width / 8, cbuf); + stp_fold(magenta, dimage_width / 8, mbuf); + stp_fold(yellow, dimage_width / 8, ybuf); + for (count = dimage_width, cbyte = *cbuf++, mbyte = *mbuf++, ybyte = *ybuf++, kbyte = *kbuf++, shift = 6; count > 0; count --) @@ -893,7 +921,7 @@ write_photo(FILE *fp, if (dither_bits == 1) { - for (count = IMAGE_WIDTH, cbyte = *cyan++, lcbyte = *lcyan++, + for (count = dimage_width, cbyte = *cyan++, lcbyte = *lcyan++, mbyte = *magenta++, lmbyte = *lmagenta++, ybyte = *yellow++, kbyte = *black++, bit = 128; count > 0; @@ -955,13 +983,13 @@ write_photo(FILE *fp, unsigned char *lcbuf = lcb; unsigned char *lmbuf = lmb; unsigned char *ybuf = yb; - stp_fold(black, IMAGE_WIDTH / 8, kbuf); - stp_fold(cyan, IMAGE_WIDTH / 8, cbuf); - stp_fold(magenta, IMAGE_WIDTH / 8, mbuf); - stp_fold(yellow, IMAGE_WIDTH / 8, ybuf); - stp_fold(lcyan, IMAGE_WIDTH / 8, lcbuf); - stp_fold(lmagenta, IMAGE_WIDTH / 8, lmbuf); - for (count = IMAGE_WIDTH, cbyte = *cbuf++, mbyte = *mbuf++, + stp_fold(black, dimage_width / 8, kbuf); + stp_fold(cyan, dimage_width / 8, cbuf); + stp_fold(magenta, dimage_width / 8, mbuf); + stp_fold(yellow, dimage_width / 8, ybuf); + stp_fold(lcyan, dimage_width / 8, lcbuf); + stp_fold(lmagenta, dimage_width / 8, lmbuf); + for (count = dimage_width, cbyte = *cbuf++, mbyte = *mbuf++, ybyte = *ybuf++, kbyte = *kbuf++, lmbyte = *lmbuf++, lcbyte = *lcyan++, shift = 6; count > 0; diff --git a/test/uncompress-5level.sh.in b/test/uncompress-5level.sh.in new file mode 100644 index 0000000..087a65e --- /dev/null +++ b/test/uncompress-5level.sh.in @@ -0,0 +1,82 @@ +#!@SHELL@ + +# compression of 5-level inks (irrespective of bits per level) +# 3-level, 5 pixels = 1024 combinations: 10 bits long +# but since not all levels used: unique are 242, or 1 byte +# 4-level, 4 pixels = 65536 combinations: 16 bits long +# but since only 2 bits per pixel used there are 256 combinations, or 1 byte +# 5-level, 3 pixels: 15 bits long +# but since only 3 bits per pixel used there are 125 unique combinations, or 1 byte + + +# m: max number of levels used +m=5 +maxl=$(( $m-1 )) # the max level numerical value +# z: max number allowed by bits (numerical value) +z=15 +# a: iteration of valid array subscript (1-based) +a=1 +# iteration of pixels +#i=0 +j=0 +k=0 +l=0 + +echo "static const unsigned short Table5Level[] =" +echo "{" + +#for (( i=0; i<=$z; i++ )) +#do + for (( j=0; j<=$z; j++ )) + do + for (( k=0; k<=$z; k++ )) + do + for (( l=0; l<=$z; l++ )) + do + if test $j -le ${maxl} -a $k -le ${maxl} -a $l -le ${maxl} + then + bj=$(echo "ibase=16;obase=2; $j" | bc | awk '{if ($0<10){print "000"$0} else if ($0<100){print "00"$0} else if ($0<1000){print "0"$0} else {print $0} }') + bk=$(echo "ibase=16;obase=2; $k" | bc | awk '{if ($0<10){print "000"$0} else if ($0<100){print "00"$0} else if ($0<1000){print "0"$0} else {print $0} }') + bl=$(echo "ibase=16;obase=2; $l" | bc | awk '{if ($0<10){print "000"$0} else if ($0<100){print "00"$0} else if ($0<1000){print "0"$0} else {print $0} }') + binput="${bj}${bk}${bl}" + #echo "test:" ${bj} ${bk} ${bl} ":" ${binput} ":" $(echo "ibase=2;obase=10000; ${binput}" | bc) + array[$a]=$(echo "ibase=2;obase=10000; ${binput}" | bc) + remainder=$(( $a % 16 )) + a=$(( $a+1 )) + #echo "test:" ${remainder} + # print line of output + if test ${remainder} -eq 0 + then + printf " " + pstart=$(( $a-16 )) + pfinal=$(( $a-1 )) + #echo "array subscript: $a, pstart: $pstart, pfinal: $pfinal, iterators: $j $k $l" + for (( p=$pstart; p<=$pfinal; p++ )) + do + printf "0x%x," 0x${array[$p]} + done + printf "\n" + fi + fi + done + done + done +#done + +# need to print out the last set of combinations +dividend=$(( $a-1 )) +divisor=${dividend}/16 # the number of completed rows already printed +printf " " +pstart=$(( ${divisor}*16+1 )) +pfinal=${dividend} +#echo "array subscript: $a, pstart: $pstart, pfinal: $pfinal, iterators: $j $k $l" +for (( p=$pstart; p<=$pfinal; p++ )) +do + printf "0x%x," 0x${array[$p]} +done +printf "\n" + + + +echo "};" +echo "max number of valid combinations: $(( a-1 ))" diff --git a/test/uncompress-6level.sh.in b/test/uncompress-6level.sh.in new file mode 100644 index 0000000..f4bd9e9 --- /dev/null +++ b/test/uncompress-6level.sh.in @@ -0,0 +1,82 @@ +#!@SHELL@ + +# compression of 5-level inks (irrespective of bits per level) +# 3-level, 5 pixels = 1024 combinations: 10 bits long +# but since not all levels used: unique are 242, or 1 byte +# 4-level, 4 pixels = 65536 combinations: 16 bits long +# but since only 2 bits per pixel used there are 256 combinations, or 1 byte +# 5-level, 3 pixels: 15 bits long +# but since only 3 bits per pixel used there are 125 unique combinations, or 1 byte + + +# m: max number of levels used +m=6 +maxl=$(( $m-1 )) # the max level numerical value +# z: max number allowed by bits (numerical value) +z=15 +# a: iteration of valid array subscript (1-based) +a=1 +# iteration of pixels +#i=0 +j=0 +k=0 +l=0 + +echo "static const unsigned short Table6Level[] =" +echo "{" + +#for (( i=0; i<=$z; i++ )) +#do + for (( j=0; j<=$z; j++ )) + do + for (( k=0; k<=$z; k++ )) + do + for (( l=0; l<=$z; l++ )) + do + if test $j -le ${maxl} -a $k -le ${maxl} -a $l -le ${maxl} + then + bj=$(echo "ibase=16;obase=2; $j" | bc | awk '{if ($0<10){print "000"$0} else if ($0<100){print "00"$0} else if ($0<1000){print "0"$0} else {print $0} }') + bk=$(echo "ibase=16;obase=2; $k" | bc | awk '{if ($0<10){print "000"$0} else if ($0<100){print "00"$0} else if ($0<1000){print "0"$0} else {print $0} }') + bl=$(echo "ibase=16;obase=2; $l" | bc | awk '{if ($0<10){print "000"$0} else if ($0<100){print "00"$0} else if ($0<1000){print "0"$0} else {print $0} }') + binput="${bj}${bk}${bl}" + #echo "test:" ${bj} ${bk} ${bl} ":" ${binput} ":" $(echo "ibase=2;obase=10000; ${binput}" | bc) + array[$a]=$(echo "ibase=2;obase=10000; ${binput}" | bc) + remainder=$(( $a % 16 )) + a=$(( $a+1 )) + #echo "test:" ${remainder} + # print line of output + if test ${remainder} -eq 0 + then + printf " " + pstart=$(( $a-16 )) + pfinal=$(( $a-1 )) + #echo "array subscript: $a, pstart: $pstart, pfinal: $pfinal, iterators: $j $k $l" + for (( p=$pstart; p<=$pfinal; p++ )) + do + printf "0x%x," 0x${array[$p]} + done + printf "\n" + fi + fi + done + done + done +#done + +# need to print out the last set of combinations +dividend=$(( $a-1 )) +divisor=${dividend}/16 # the number of completed rows already printed +printf " " +pstart=$(( ${divisor}*16+1 )) +pfinal=${dividend} +#echo "array subscript: $a, pstart: $pstart, pfinal: $pfinal, iterators: $j $k $l" +for (( p=$pstart; p<=$pfinal; p++ )) +do + printf "0x%x," 0x${array[$p]} +done +printf "\n" + + + +echo "};" +echo "max number of valid combinations: $(( a-1 ))" diff --git a/test/unprint.c b/test/unprint.c index 3b1e5ef..85d4daf 100644 --- a/test/unprint.c +++ b/test/unprint.c @@ -16,8 +16,7 @@ * for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H diff --git a/test/xml-curve.c b/test/xml-curve.c index d1d1bbb..3fb9e71 100644 --- a/test/xml-curve.c +++ b/test/xml-curve.c @@ -13,8 +13,7 @@ * for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H |