diff options
author | Didier Raboud <odyx@debian.org> | 2011-06-17 11:01:37 +0200 |
---|---|---|
committer | Didier Raboud <odyx@debian.org> | 2011-06-17 11:01:37 +0200 |
commit | 6351d417d1cb5f6c4846b1af8d96732c284ee456 (patch) | |
tree | fae90673b83dba9576df6987bf052e8162ec117b /lib |
Imported Upstream version 1.0.3
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 32 | ||||
-rw-r--r-- | lib/Makefile.in | 486 | ||||
-rw-r--r-- | lib/escpr_api.c | 246 | ||||
-rw-r--r-- | lib/escpr_api.h | 52 | ||||
-rw-r--r-- | lib/escpr_cmd.c | 1820 | ||||
-rw-r--r-- | lib/escpr_cmd.h | 140 | ||||
-rw-r--r-- | lib/escpr_def.h | 216 | ||||
-rw-r--r-- | lib/escpr_osdep.c | 77 | ||||
-rw-r--r-- | lib/escpr_osdep.h | 74 | ||||
-rw-r--r-- | lib/escpr_rle.c | 133 | ||||
-rw-r--r-- | lib/escpr_rle.h | 31 | ||||
-rw-r--r-- | lib/escpr_sp.c | 1232 | ||||
-rw-r--r-- | lib/escpr_sp.h | 54 |
13 files changed, 4593 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 0000000..198881a --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,32 @@ +## Makefile.am -- an automake template for a Makefile.in file +## EPSON ESC/P-R Printer Driver for Linux +## Copyright (C) 2000-2006 AVASYS CORPORATION. +## Copyright (C) Seiko Epson Corporation 2000-2006. +## 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, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +lib_LTLIBRARIES = libescpr.la + +## Make sure these will be cleaned even when they're not built by +## default. +CLEANFILES = libescpr.la +libescpr_la_SOURCES = \ + escpr_api.c escpr_api.h \ + escpr_cmd.c escpr_cmd.h \ + escpr_def.h \ + escpr_osdep.c escpr_osdep.h \ + escpr_rle.c escpr_rle.h \ + escpr_sp.c escpr_sp.h +libescpr_la_LDFLAGS = -O2 -version-info 1:0:0 + diff --git a/lib/Makefile.in b/lib/Makefile.in new file mode 100644 index 0000000..20ea08d --- /dev/null +++ b/lib/Makefile.in @@ -0,0 +1,486 @@ +# Makefile.in generated by automake 1.10.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = lib +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(libdir)" +libLTLIBRARIES_INSTALL = $(INSTALL) +LTLIBRARIES = $(lib_LTLIBRARIES) +libescpr_la_LIBADD = +am_libescpr_la_OBJECTS = escpr_api.lo escpr_cmd.lo escpr_osdep.lo \ + escpr_rle.lo escpr_sp.lo +libescpr_la_OBJECTS = $(am_libescpr_la_OBJECTS) +libescpr_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libescpr_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libescpr_la_SOURCES) +DIST_SOURCES = $(libescpr_la_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CUPS_IMAGE_LIBS = @CUPS_IMAGE_LIBS@ +CUPS_LIBS = @CUPS_LIBS@ +CUPS_PPD_DIR = @CUPS_PPD_DIR@ +CUPS_SERVER_DIR = @CUPS_SERVER_DIR@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +NMEDIT = @NMEDIT@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_RELEASE = @PACKAGE_RELEASE@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +have_cups_config = @have_cups_config@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +lib_LTLIBRARIES = libescpr.la +CLEANFILES = libescpr.la +libescpr_la_SOURCES = \ + escpr_api.c escpr_api.h \ + escpr_cmd.c escpr_cmd.h \ + escpr_def.h \ + escpr_osdep.c escpr_osdep.h \ + escpr_rle.c escpr_rle.h \ + escpr_sp.c escpr_sp.h + +libescpr_la_LDFLAGS = -O2 -version-info 1:0:0 +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu lib/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu lib/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);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f=$(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + p=$(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libescpr.la: $(libescpr_la_OBJECTS) $(libescpr_la_DEPENDENCIES) + $(libescpr_la_LINK) -rpath $(libdir) $(libescpr_la_OBJECTS) $(libescpr_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/escpr_api.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/escpr_cmd.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/escpr_osdep.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/escpr_rle.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/escpr_sp.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(libdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-exec-am: install-libLTLIBRARIES + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-libLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool ctags 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-libLTLIBRARIES 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 \ + tags uninstall uninstall-am uninstall-libLTLIBRARIES + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/lib/escpr_api.c b/lib/escpr_api.c new file mode 100644 index 0000000..73432a4 --- /dev/null +++ b/lib/escpr_api.c @@ -0,0 +1,246 @@ +/*********************************************************************** + * + * Copyright (c) 2005 Seiko Epson Corporation. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * File Name: escpr_api.c + * + ***********************************************************************/ + +#include "escpr_api.h" +#include "escpr_cmd.h" +#include "escpr_sp.h" + +/*=======================================================================================*/ +/* Debug */ +/*=======================================================================================*/ +#ifdef _ESCPR_DEBUG +#include <stdio.h> +#define dprintf(a) printf(a) +#else +#define dprintf(a) +#endif + +/*=======================================================================================*/ +/* Define Area */ +/*=======================================================================================*/ + + +/*=======================================================================================*/ +/* Global Area */ +/*=======================================================================================*/ +ESCPR_GLOBALFUNC gESCPR_Func; + +ESCPR_STATUS gESCPR_JobStatus = ESCPR_STATUS_NOT_INITIALIZED; /* Job status */ +ESCPR_STATUS gESCPR_PageStatus = ESCPR_STATUS_NOT_INITIALIZED; /* Page status */ + +ESCPR_ERR_CODE gESCPR_ErrorCode; + +/*=======================================================================================*/ +/* ESC/P-R Core Module API */ +/*=======================================================================================*/ +ESCPR_ERR_CODE escprInitJob(const ESCPR_OPT *pRGB_opt, + const ESCPR_PRINT_QUALITY *pPrintQuality, const ESCPR_PRINT_JOB *pPrintJob) +{ + ESCPR_PRINT_QUALITY spPrintQuality; + ESCPR_PRINT_JOB spPrintJob; + + dprintf(("ESCPRAPI : escprInitJob()\n")); + + gESCPR_ErrorCode = ESCPR_ERR_NOERROR; + + /* ERROR CHECK! */ + if (gESCPR_JobStatus == ESCPR_STATUS_INITIALIZED) + { + gESCPR_ErrorCode = ESCPR_ERR_DON_T_PROCESS; + dprintf("ESCPRAPI : escprInitJob() --- illegal call\n"); + return gESCPR_ErrorCode; + } + + /* Entry Functions */ + gESCPR_Func.gfpSendData = pRGB_opt->fpspoolfunc; /* Function of Send Data */ + + /* NOTE : Using ChangeSpec function */ + /* Assigned prameters to this API would be used on the caller's side again */ + /* It must not be changed anything members of parameters */ + /* in order to avoid side-effect on the caller's side */ + /* Be sure that duplicated parameters must be used to call ChangeSpec */ + /* because it would be changed someway internally */ + spPrintQuality = *pPrintQuality; + spPrintJob = *pPrintJob; + + /* ChangeSpec : Known issue (2005/10/14 #2) */ + ESCPR_RequestServicePack(SP_REQ_FIX_720DPI, (void*)&spPrintJob, + /* reserved */ NULL, NULL, NULL); + + /* ChangeSpec : Known issue (2005/10/14 #3) */ + ESCPR_RequestServicePack(SP_REQ_FIX_COMPOSITE_BLACK, (void*)&spPrintQuality, + /* reserved */ NULL, NULL, NULL); + + /* ChangeSpec : Known issue (2005/10/14 #4) */ + ESCPR_RequestServicePack(SP_REQ_FIX_DRAFTONLY, (void*)&spPrintQuality, (void*)&spPrintJob, + /* reserved */ NULL, NULL); + + /* Send Header Command (ExitPacketMode, InitPrinter, InitPrinter) */ + gESCPR_ErrorCode = ESCPR_MakeHeaderCmd(); + + if( gESCPR_ErrorCode != ESCPR_ERR_NOERROR ){ + dprintf(("ESCPRAPI : ESCPR_MakeHeaderCmd Failed\n")); + return gESCPR_ErrorCode; + } + + /* Send Print Quality Command */ + gESCPR_ErrorCode = ESCPR_MakePrintQualityCmd(&spPrintQuality); + + if( gESCPR_ErrorCode != ESCPR_ERR_NOERROR ){ + dprintf(("ESCPRAPI : ESCPR_MakePrintQualityCmd Faild\n")); + return gESCPR_ErrorCode; + } + + /* Send Print Job Command */ + gESCPR_ErrorCode = ESCPR_MakePrintJobCmd(&spPrintJob); + + if (gESCPR_ErrorCode != ESCPR_ERR_NOERROR ){ + dprintf(("ESCPRAPI : ESCPR_MakePrintJobCmd Faild\n")); + return gESCPR_ErrorCode; + } + + /* change status */ + gESCPR_JobStatus = ESCPR_STATUS_INITIALIZED; + + return gESCPR_ErrorCode; +} + + +ESCPR_ERR_CODE escprInitPage(void) +{ + dprintf(("ESCPRAPI : escprInitPage()\n")); + + /* ERROR CHECK! */ + if (gESCPR_PageStatus == ESCPR_STATUS_INITIALIZED) + { + gESCPR_ErrorCode = ESCPR_ERR_DON_T_PROCESS; + dprintf("ESCPRAPI : escprInitPage() --- illegal call\n"); + return gESCPR_ErrorCode; + } + + /* Send Start Page Command */ + gESCPR_ErrorCode = ESCPR_MakeStartPageCmd(); + + if( gESCPR_ErrorCode != ESCPR_ERR_NOERROR ){ + dprintf(("ESCPRAPI : ESCPR_MakeStartPageCmd Faild\n")); + return gESCPR_ErrorCode; + } + + /* change status */ + gESCPR_PageStatus = ESCPR_STATUS_INITIALIZED; + + return gESCPR_ErrorCode; +} + +ESCPR_ERR_CODE escprBandOut(const ESCPR_BANDBMP *pInBmp, ESCPR_RECT *pBandRec) +{ + dprintf(("ESCPRAPI : escprBandOut()\n")); + + /* ERROR CHECK! */ + if( (gESCPR_JobStatus != ESCPR_STATUS_INITIALIZED) + || (gESCPR_PageStatus != ESCPR_STATUS_INITIALIZED) ) + { + gESCPR_ErrorCode = ESCPR_ERR_DON_T_PROCESS; + dprintf("ESCPRAPI : escprBandOut() --- illegal call\n"); + return gESCPR_ErrorCode; + } + + /* Send Image Data */ + gESCPR_ErrorCode = ESCPR_MakeImageData(pInBmp, pBandRec); + + if( gESCPR_ErrorCode != ESCPR_ERR_NOERROR ){ + dprintf(("ESCPRAPI : ESCPR_MakeImageData Faild\n")); + return gESCPR_ErrorCode; + } + + return gESCPR_ErrorCode; +} + +ESCPR_ERR_CODE escprTerminatePage(const ESCPR_UBYTE1 NextPage) +{ + dprintf(("ESCPRAPI : escprTerminatePage()\n")); + + /* ERROR CHECK! */ + if (gESCPR_PageStatus == ESCPR_STATUS_NOT_INITIALIZED) + { + gESCPR_ErrorCode = ESCPR_ERR_DON_T_PROCESS; + dprintf("ESCPRAPI : escprTerminatePage() --- illegal call\n"); + return gESCPR_ErrorCode; + } + + /* change status */ + gESCPR_PageStatus = ESCPR_STATUS_NOT_INITIALIZED; + + /* Send End Page Command */ + gESCPR_ErrorCode = ESCPR_MakeEndPageCmd(NextPage); + + if( gESCPR_ErrorCode != ESCPR_ERR_NOERROR ){ + dprintf(("ESCPRAPI : ESCPR_MakeEndPageCmd Faild\n")); + return gESCPR_ErrorCode; + } + + return gESCPR_ErrorCode; +} + +ESCPR_ERR_CODE escprDestroyJob(void) +{ + dprintf(("ESCPRAPI : escprDestroyJob()\n")); + + /* ERROR CHECK! */ + if (gESCPR_JobStatus == ESCPR_STATUS_NOT_INITIALIZED) + { + gESCPR_ErrorCode = ESCPR_ERR_DON_T_PROCESS; + dprintf("ESCPRAPI : escprDestroyJob() --- illegal call\n"); + return gESCPR_ErrorCode; + } + + /* change status */ + gESCPR_JobStatus = ESCPR_STATUS_NOT_INITIALIZED; + + /* Send End Job Command */ + gESCPR_ErrorCode = ESCPR_MakeEndJobCmd(); + + if( gESCPR_ErrorCode != ESCPR_ERR_NOERROR ){ + dprintf(("ESCPRAPI : ESCPR_MakeEndJobCmd Faild\n")); + return gESCPR_ErrorCode; + } + + return gESCPR_ErrorCode; +} + +ESCPR_ERR_CODE escprFilterPMReply(ESCPR_UBYTE1* pPMinfo) +{ + ESCPR_ERR_CODE Ret; + dprintf(("ESCPRAPI : escprFilterPMReply()\n")); + + /* ChangeSpec : Known issue (2005/10/14 #1) */ + Ret = ESCPR_RequestServicePack(SP_REQ_FIX_UPDATE_PMREPLY, pPMinfo, + /* reserved */ NULL, NULL, NULL); + + if(Ret != ESCPR_SP_ERR_NONE) { + dprintf(("ESCPRAPI : escprFilterPMReply() --- failed [%d]\n", Ret)); + gESCPR_ErrorCode = ESCPR_ERR_HAPPEN_PROBLEM; + return gESCPR_ErrorCode; + } + + return ESCPR_ERR_NOERROR; +} diff --git a/lib/escpr_api.h b/lib/escpr_api.h new file mode 100644 index 0000000..ed636a0 --- /dev/null +++ b/lib/escpr_api.h @@ -0,0 +1,52 @@ +/*********************************************************************** + * + * Copyright (c) 2005 Seiko Epson Corporation. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * File Name: escpr_api.h + * + ***********************************************************************/ + +#ifndef __EPSON_ESCPR_API_H__ +#define __EPSON_ESCPR_API_H__ + +#include "escpr_def.h" + +/*=======================================================================================*/ +/* functions */ +/*=======================================================================================*/ + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + ESCPR_ERR_CODE escprInitJob(const ESCPR_OPT *pRGB_opt, + const ESCPR_PRINT_QUALITY *pPrintQuality, + const ESCPR_PRINT_JOB *pPrintJob); + ESCPR_ERR_CODE escprInitPage(void); + ESCPR_ERR_CODE escprBandOut(const ESCPR_BANDBMP *pInBmp, ESCPR_RECT *pBandRec); + ESCPR_ERR_CODE escprTerminatePage(const ESCPR_UBYTE1 NextPage); + ESCPR_ERR_CODE escprDestroyJob(void); + ESCPR_ERR_CODE escprFilterPMReply(ESCPR_UBYTE1* pPMinfo); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif + diff --git a/lib/escpr_cmd.c b/lib/escpr_cmd.c new file mode 100644 index 0000000..a314473 --- /dev/null +++ b/lib/escpr_cmd.c @@ -0,0 +1,1820 @@ +/*********************************************************************** + * + * Copyright (c) 2005-2008 Seiko Epson Corporation. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * File Name: escpr_cmd.c + * + ***********************************************************************/ + +#include "escpr_def.h" +#include "escpr_cmd.h" +#include "escpr_rle.h" +#include "escpr_osdep.h" + +/*=======================================================================================*/ +/* Debug */ +/*=======================================================================================*/ +/* #define ESCPR_IMAGE_LOG */ + +#include <stdio.h> +#include <stdlib.h> + +#ifdef _ESCPR_DEBUG +#include <stdio.h> +#define dprintf(a) printf a +#else +#define dprintf(a) +#endif + +/*=======================================================================================*/ +/* Define Area */ +/*=======================================================================================*/ +typedef struct tagESCPR_PAGE { + ESCPR_BYTE4 Top; + ESCPR_BYTE4 Bottom; + ESCPR_BYTE4 Left; + ESCPR_BYTE4 Right; +} ESCPR_PAGE; + +typedef struct tagBASEPOINT { + ESCPR_PAGE Border; + ESCPR_PAGE Borderless; +#if defined(_ZERO_MARGIN_REPLICATE) || defined(_ZERO_MARGIN_MIRROR) + ESCPR_PAGE Pad; +#endif +} ESCPR_BASEPT; + +void SetGlobalBasePointData(const int PaperWidth); + +#define PAPERWIDTH_A3 4209 + +#if defined(_ZERO_MARGIN_MIRROR) +#define ESCPR_BLUR_FACTOR 4 +#endif + +/*=======================================================================================*/ +/* Switch for Printing Method */ +/*=======================================================================================*/ + +/*=======================================================================================*/ +/* Definition of Macro */ +/*=======================================================================================*/ +#define Max(a,b) ( ((a) > (b)) ? (a) : (b)) +#define Min(a,b) ( ((a) < (b)) ? (a) : (b)) + +#define ESCPR_FreeLocalBuf(mem) if(mem != NULL) ESCPR_Mem_Free(mem); + +#define ESCPR_SendData(h,cmd,sz) if(gESCPR_Func.gfpSendData(h, cmd, sz) < 0) \ + return ESCPR_ERR_SPOOL_IO; +#define Swap2Bytes(data) \ + ( (((data) >> 8) & 0x00FF) | (((data) << 8) & 0xFF00) ) + +#define Swap4Bytes(data) \ + ( (((data) >> 24) & 0x000000FF) | (((data) >> 8) & 0x0000FF00) | \ + (((data) << 8) & 0x00FF0000) | (((data) << 24) & 0xFF000000) ) + +/*=======================================================================================*/ +/* Global Area */ +/*=======================================================================================*/ +extern ESCPR_GLOBALFUNC gESCPR_Func; +ESCPR_BYTE4 gESCPR_ImgBufSize; +ESCPR_BYTE4 gESCPR_CompBufSize; + +#if defined(_ZERO_MARGIN_REPLICATE) || defined(_ZERO_MARGIN_MIRROR) +BOOL gESCPR_Borderless; /* borderless mode selected */ +#endif + +#if defined(_ZERO_MARGIN_MIRROR) +ESCPR_UBYTE1* gESCPR_DupBufferTop; /* buffer to hold top region of image */ +ESCPR_UBYTE1* gESCPR_DupBufferBot; /* buffer to hold bottom region of image */ +ESCPR_BYTE4 gESCPR_TopCnt; /* counter for how many rasters we have saved */ +ESCPR_BYTE4 gESCPR_BotCnt; /* counter for how many rasters we have saved */ +BOOL gESCPR_TopFlushed; /* whether top needs to be flushed */ +#endif + +ESCPR_UBYTE4 gESCPR_PrintableAreaWidth; /* users setting */ +ESCPR_UBYTE4 gESCPR_PrintableAreaLength; /* users setting */ +ESCPR_BYTE1 gESCPR_bpp; /* 3 for RGB, 1 for 256 */ +ESCPR_UBYTE2 gESCPR_offset_x, gESCPR_offset_y; /* offset to be used. calculated when changing basepoint */ + +ESCPR_BYTE2 gESCPR_DPI_Multiplier; /* 2 if resolution 720x720 + * 1 if resolution 360x360 */ +ESCPR_BASEPT gESCPR_BasePt; + +ESCPR_BYTE2 gESCPR_WhiteColorValue; /* Value of "true white" (either 255 or the 8-bit BMP index) */ + +#ifdef _ESCPR_DEBUG +ESCPR_UBYTE4 gESCPR_TotalDebugBandCount = 0; +#endif + +/*=======================================================================================*/ +/* Sub Routine */ +/*=======================================================================================*/ +static ESCPR_UBYTE4 ESCPR_SendData_CheckResult(const ESCPR_UBYTE1* pBuf, ESCPR_UBYTE4 cbBuf) +{ + if(gESCPR_Func.gfpSendData(NULL, pBuf, cbBuf) < 0) { + return ESCPR_ERR_SPOOL_IO; + } + return ESCPR_ERR_NOERROR; +} + +ESCPR_ENDIAN ESCPR_CPU_Endian(void) +{ + static ESCPR_ENDIAN platform_endian = ESCPR_ENDIAN_NOT_TESTED; + + union { + ESCPR_BYTE1 Array[2]; + ESCPR_BYTE2 Chars; + } TestUnion; + + if(platform_endian == ESCPR_ENDIAN_NOT_TESTED) { + /* Test platform Endianness */ + TestUnion.Array[0] = 'a'; + TestUnion.Array[1] = 'b'; + + if (TestUnion.Chars == 0x6162) { + platform_endian = ESCPR_ENDIAN_BIG; + } else { + platform_endian = ESCPR_ENDIAN_LITTLE; + } + } + + return platform_endian; + +} + +BOOL ESCPR_SetBigEndian_BYTE2(ESCPR_UBYTE2 value, ESCPR_UBYTE1 array[2]) +{ + if(ESCPR_CPU_Endian() == ESCPR_ENDIAN_LITTLE) { + value = Swap2Bytes(value); + } + + ESCPR_Mem_Copy((ESCPR_UBYTE1*)array, (ESCPR_UBYTE1*)&value, 2); + + return TRUE; +} + + +BOOL ESCPR_SetBigEndian_BYTE4(ESCPR_UBYTE4 value, ESCPR_UBYTE1 array[4]) +{ + if(ESCPR_CPU_Endian() == ESCPR_ENDIAN_LITTLE) { + value = Swap4Bytes(value); + } + + ESCPR_Mem_Copy((ESCPR_UBYTE1*)array, (ESCPR_UBYTE1*)&value, 4); + + return TRUE; +} + +BOOL ESCPR_SetLittleEndian_BYTE4(ESCPR_UBYTE4 value, ESCPR_UBYTE1 array[4]) +{ + if(ESCPR_CPU_Endian() == ESCPR_ENDIAN_BIG) { + value = Swap4Bytes(value); + } + + ESCPR_Mem_Copy((ESCPR_UBYTE1*)array, (ESCPR_UBYTE1*)&value, 4); + + return TRUE; +} + + +ESCPR_ERR_CODE ESCPR_MakeHeaderCmd(void) +{ + static const ESCPR_UBYTE1 cmd_ExitPacketMode[] = { + 0x00, 0x00, 0x00, 0x1B, 0x01, 0x40, 0x45, 0x4A, 0x4C, 0x20, + 0x31, 0x32, 0x38, 0x34, 0x2E, 0x34, 0x0A, 0x40, 0x45, 0x4A, + 0x4C, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0A + }; + + static const ESCPR_UBYTE1 cmd_InitPrinter[] = { + 0x1B, 0x40, + }; + + static const ESCPR_UBYTE1 cmd_EnterRemoteMode[] = { + 0x1B, 0x28, 0x52, 0x08, 0x00, 0x00, 'R', 'E', 'M', 'O', 'T', 'E', '1', + }; + + static const ESCPR_UBYTE1 cmd_RemoteJS[] = { + 'J', 'S', 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + + static const ESCPR_UBYTE1 cmd_RemoteHD[] = { + 'H', 'D', 0x03, 0x00, 0x00, 0x03, 0x04, + }; + + static const ESCPR_UBYTE1 cmd_ExitRemoteMode[] = { + 0x1B, 0x00, 0x00, 0x00, + }; + + static const ESCPR_UBYTE1 cmd_RGBMode[] = { + 0x1B, 0x28, 0x52, 0x06, 0x00, 0x00, 0x45, 0x53, 0x43, 0x50, 0x52, + }; + + /* Exit Packet Mode */ + ESCPR_SendData(NULL, cmd_ExitPacketMode, sizeof(cmd_ExitPacketMode)); + + /* Initialize */ + ESCPR_SendData(NULL, cmd_InitPrinter, sizeof(cmd_InitPrinter)); + + ESCPR_SendData(NULL, cmd_EnterRemoteMode, sizeof(cmd_EnterRemoteMode)); + + /* Remote Command - TI */ + { + ESCPR_LOCAL_TIME tm; + ESCPR_UBYTE1 value_array_2[2]; /* Temporary Buffer for 2 byte Big Endian */ + ESCPR_UBYTE1 *cmdBuff; /* Temporary Buffer for Print Quality Command */ + ESCPR_UBYTE1 cmd_RemoteTI[] = { + 'T', 'I', 0x08, 0x00, 0x00, + 0x00, 0x00, /* YYYY */ + 0x00, /* MM */ + 0x00, /* DD */ + 0x00, /* hh */ + 0x00, /* mm */ + 0x00, /* ss */ + }; + + ESCPR_GetLocalTime(&tm); + + cmdBuff = cmd_RemoteTI + REMOTE_HEADER_LENGTH; + ESCPR_SetBigEndian_BYTE2(tm.year, value_array_2); + ESCPR_Mem_Copy(cmdBuff, value_array_2, sizeof(value_array_2)); + cmdBuff += sizeof(value_array_2); + *cmdBuff++ = (ESCPR_UBYTE1)tm.mon; + *cmdBuff++ = (ESCPR_UBYTE1)tm.day; + *cmdBuff++ = (ESCPR_UBYTE1)tm.hour; + *cmdBuff++ = (ESCPR_UBYTE1)tm.min; + *cmdBuff = (ESCPR_UBYTE1)tm.sec; + + ESCPR_SendData(NULL, cmd_RemoteTI, sizeof(cmd_RemoteTI)); + } + + /* Remote Command - JS */ + ESCPR_SendData(NULL, cmd_RemoteJS, sizeof(cmd_RemoteJS)); + + /* Remote Command - HD */ + ESCPR_SendData(NULL, cmd_RemoteHD, sizeof(cmd_RemoteHD)); + + ESCPR_SendData(NULL, cmd_ExitRemoteMode, sizeof(cmd_ExitRemoteMode)); + + /* Enter ESC/P-R mode */ + ESCPR_SendData(NULL, cmd_RGBMode, sizeof(cmd_RGBMode)); + + return ESCPR_ERR_NOERROR; +} + + +ESCPR_ERR_CODE ESCPR_MakePrintQualityCmd(const ESCPR_PRINT_QUALITY *pPrintQuality) +{ + ESCPR_BYTE4 i; + ESCPR_UBYTE1* j; + BOOL whiteFound = FALSE; + ESCPR_UBYTE4 currentIndex = 0; + ESCPR_BYTE4 cmdSize; /* All Size of Print Quality Command */ + ESCPR_BYTE4 cpy_size; /* Copy Size */ + ESCPR_BYTE4 cpy_count = 0; /* Counter for Set Command */ + ESCPR_UBYTE4 paramLength; /* Parameter Length */ + ESCPR_UBYTE1 value_array_2[2]; /* Temporary Buffer for 2 byte Big Endian */ + ESCPR_UBYTE1 value_array_4[4]; /* Temporary Buffer for 4 byte Big Endian */ + ESCPR_UBYTE1 *cmdBuff; /* Temporary Buffer for Print Quality Command */ + void *Temp; + + static const ESCPR_UBYTE1 Header[2] = {0x1B, 'q'}; /* ESC + Class */ + static const ESCPR_UBYTE1 cmdName[4] = {'s', 'e', 't', 'q'}; /* Command Name */ + + if( pPrintQuality->ColorPlane == ESCPR_CP_FULLCOLOR ){ /* Full Color Printing */ + gESCPR_bpp = 3; + + /* In full color printing, set the global white value to 255 (for white raster skip) */ + gESCPR_WhiteColorValue = 255; + + /* Set All Command Size */ + paramLength = ESCPR_PRTQLTY_PARAMBLC_LENG; + cmdSize = ESCPR_HEADER_LENG + paramLength; + + /* Allocate Temporary Buffer */ + Temp = ESCPR_Mem_Alloc(cmdSize); + if(Temp == NULL){ + return ESCPR_ERR_CAN_T_ALLOC_MEMORY; + } else{ + cmdBuff = (ESCPR_UBYTE1 *)Temp; + } + + /* Set Parameter */ + + /* Header */ + cpy_size = sizeof(Header); + ESCPR_Mem_Copy((cmdBuff + cpy_count), Header, cpy_size); + cpy_count += cpy_size; + + /* Parameter Length */ + cpy_size = sizeof(value_array_4); + if(ESCPR_SetLittleEndian_BYTE4(paramLength, value_array_4)){ + ESCPR_Mem_Copy((cmdBuff + cpy_count), value_array_4, cpy_size); + cpy_count += cpy_size; + } else{ + ESCPR_FreeLocalBuf(Temp); + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Command Name */ + cpy_size = sizeof(cmdName); + ESCPR_Mem_Copy((cmdBuff + cpy_count), cmdName, cpy_size); + cpy_count += cpy_size; + + /* Media Type ID */ + *(cmdBuff + cpy_count) = pPrintQuality->MediaTypeID; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Print Quality */ + *(cmdBuff + cpy_count) = pPrintQuality->PrintQuality; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Color/Monochrome */ + *(cmdBuff + cpy_count) = pPrintQuality->ColorMono; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Brightness */ + *(cmdBuff + cpy_count) = pPrintQuality->Brightness; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Contrast */ + *(cmdBuff + cpy_count) = pPrintQuality->Contrast; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Saturation */ + *(cmdBuff + cpy_count) = pPrintQuality->Saturation; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Color Plane */ + *(cmdBuff + cpy_count) = pPrintQuality->ColorPlane; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Palette Size */ + cpy_size = sizeof(value_array_2); + if(ESCPR_SetBigEndian_BYTE2(pPrintQuality->PaletteSize, value_array_2)){ + ESCPR_Mem_Copy((cmdBuff + cpy_count), value_array_2, cpy_size); + cpy_count += cpy_size; + } else{ + ESCPR_FreeLocalBuf(Temp); + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Debug Test >>> */ + if(cmdSize == cpy_count){ + dprintf(("ESCPRCMD : PrintQualityCmd [size = %d] : ", cpy_count)); + for(i = 0; i < cpy_count; i++){ + dprintf(("%.2X ", cmdBuff[i])); + } + dprintf(("\n")); + } else{ + dprintf(("ESCPRCMD : ESCPR_Make PrintQualityCmd Faild!\n")); + ESCPR_FreeLocalBuf(Temp); + return ESCPR_ERR_HAPPEN_PROBLEM; + } + /* Debug Test <<< */ + + /* Send Print Quality Command to Printer */ + if(ESCPR_SendData_CheckResult(cmdBuff, cmdSize) != ESCPR_ERR_NOERROR) { + ESCPR_FreeLocalBuf(Temp); + return ESCPR_ERR_SPOOL_IO; + } + + } else{ /* 256 Color Printing */ + + gESCPR_bpp = 1; + + /* Scan through palette for the index value of white and set the global white + * value to this index for skipping white raster lines */ + for( j = pPrintQuality->PaletteData; + j < (pPrintQuality->PaletteData + pPrintQuality->PaletteSize); + j = j + 3){ + if(*j == 255 && *(j+1) == 255 && *(j+2) == 255){ /* If all entries in the 3-byte index are 255 (white) */ + whiteFound = TRUE; + gESCPR_WhiteColorValue = currentIndex; /* set the global white value to the current index */ + break; + } else{ + currentIndex++; + } + } + + if(whiteFound == FALSE){ /* White was never found in the palette! */ + gESCPR_WhiteColorValue = -1; /* Set the value of white to negative one */ + } + + /* Set All Command Size */ + paramLength = ESCPR_PRTQLTY_PARAMBLC_LENG + pPrintQuality->PaletteSize; + cmdSize = ESCPR_HEADER_LENG + paramLength; + + /* Allocate Temporary Buffer */ + Temp = ESCPR_Mem_Alloc(cmdSize); + if(Temp == NULL){ + return ESCPR_ERR_CAN_T_ALLOC_MEMORY; + } else{ + cmdBuff = (ESCPR_UBYTE1 *)Temp; + } + + /* Set Parameter */ + + /* Header */ + cpy_size = sizeof(Header); + ESCPR_Mem_Copy((cmdBuff + cpy_count), Header, cpy_size); + cpy_count += cpy_size; + + /* Parameter Length */ + cpy_size = sizeof(value_array_4); + if(ESCPR_SetLittleEndian_BYTE4(paramLength, value_array_4)){ + ESCPR_Mem_Copy((cmdBuff + cpy_count), value_array_4, cpy_size); + cpy_count += cpy_size; + } else{ + ESCPR_FreeLocalBuf(Temp); + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Command Name */ + cpy_size = sizeof(cmdName); + ESCPR_Mem_Copy((cmdBuff + cpy_count), cmdName, cpy_size); + cpy_count += cpy_size; + + /* Media Type ID */ + *(cmdBuff + cpy_count) = pPrintQuality->MediaTypeID; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Print Quality */ + *(cmdBuff + cpy_count) = pPrintQuality->PrintQuality; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Color/Monochrome */ + *(cmdBuff + cpy_count) = pPrintQuality->ColorMono; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Brightness */ + *(cmdBuff + cpy_count) = pPrintQuality->Brightness; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Contrast */ + *(cmdBuff + cpy_count) = pPrintQuality->Contrast; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Saturation */ + *(cmdBuff + cpy_count) = pPrintQuality->Saturation; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Color Plane */ + *(cmdBuff + cpy_count) = pPrintQuality->ColorPlane; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Palette Size */ + cpy_size = sizeof(value_array_2); + if(ESCPR_SetBigEndian_BYTE2(pPrintQuality->PaletteSize, value_array_2)){ + ESCPR_Mem_Copy((cmdBuff + cpy_count), value_array_2, cpy_size); + cpy_count += cpy_size; + } else{ + ESCPR_FreeLocalBuf(Temp); + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Palette Data */ + ESCPR_Mem_Copy((cmdBuff + cpy_count), + pPrintQuality->PaletteData, pPrintQuality->PaletteSize); + + cpy_count += pPrintQuality->PaletteSize; + + /* Debug Test >>> */ + if(cmdSize == cpy_count){ + dprintf(("ESCPRCMD : PrintQualityCmd [size = %d] : ", cpy_count)); + for(i = 0; i < cpy_count; i++){ + dprintf(("%.2X ", cmdBuff[i])); + } + dprintf(("\n")); + } else{ + dprintf(("ESCPRCMD : ESCPR_Make PrintQualityCmd Faild!\n")); + ESCPR_FreeLocalBuf(Temp); + return ESCPR_ERR_HAPPEN_PROBLEM; + } + /* Debug Test <<< */ + + /* Send Print Quality Command to Printer */ + if(ESCPR_SendData_CheckResult(cmdBuff, cmdSize) != ESCPR_ERR_NOERROR) { + ESCPR_FreeLocalBuf(Temp); + return ESCPR_ERR_SPOOL_IO; + } + } + + /* Free Temporary Buffer */ + ESCPR_Mem_Free(Temp); + + return ESCPR_ERR_NOERROR; +} + + +ESCPR_ERR_CODE ESCPR_AdjustBasePoint(ESCPR_PRINT_JOB* pPrintJob) { + /* temporary variables for max PAW/PAL */ + ESCPR_UBYTE4 maxPAWidthBorder, maxPAWidthBorderless; + ESCPR_UBYTE4 maxPALengthBorder, maxPALengthBorderless; + + BOOL adjBorderless; + + ESCPR_UBYTE4 RightMargin, BottomMargin; + + adjBorderless = (pPrintJob->LeftMargin < gESCPR_BasePt.Border.Left) + || (pPrintJob->TopMargin < gESCPR_BasePt.Border.Top); + + /* pPrintJob->ust the basepoint */ + if (adjBorderless) { + + gESCPR_offset_x = pPrintJob->LeftMargin - gESCPR_BasePt.Borderless.Left; + gESCPR_offset_y = pPrintJob->TopMargin - gESCPR_BasePt.Borderless.Top; + + pPrintJob->PrintableAreaWidth += gESCPR_offset_x; + pPrintJob->PrintableAreaLength += gESCPR_offset_y; + + pPrintJob->LeftMargin = (ESCPR_BYTE2)(gESCPR_BasePt.Borderless.Left); + pPrintJob->TopMargin = (ESCPR_BYTE2)(gESCPR_BasePt.Borderless.Top); + + /* max PAW/PAL */ + maxPALengthBorderless = pPrintJob->PaperLength*gESCPR_DPI_Multiplier + - pPrintJob->TopMargin - gESCPR_BasePt.Borderless.Bottom; + maxPAWidthBorderless = pPrintJob->PaperWidth*gESCPR_DPI_Multiplier + - pPrintJob->LeftMargin - gESCPR_BasePt.Borderless.Right; + + if (pPrintJob->PrintableAreaLength > maxPALengthBorderless) { + pPrintJob->PrintableAreaLength = maxPALengthBorderless; + } + + if (pPrintJob->PrintableAreaWidth > maxPAWidthBorderless) { + pPrintJob->PrintableAreaWidth = maxPAWidthBorderless; + } + + } else { + + gESCPR_offset_x = pPrintJob->LeftMargin - gESCPR_BasePt.Border.Left; + gESCPR_offset_y = pPrintJob->TopMargin - gESCPR_BasePt.Border.Top; + + RightMargin = (pPrintJob->PaperWidth * gESCPR_DPI_Multiplier) + - pPrintJob->LeftMargin - pPrintJob->PrintableAreaWidth; + BottomMargin = (pPrintJob->PaperLength * gESCPR_DPI_Multiplier) + - pPrintJob->TopMargin - pPrintJob->PrintableAreaLength; + + pPrintJob->PrintableAreaWidth = (pPrintJob->PaperWidth * gESCPR_DPI_Multiplier) + - gESCPR_BasePt.Border.Left - RightMargin; + pPrintJob->PrintableAreaLength = (pPrintJob->PaperLength * gESCPR_DPI_Multiplier) + - gESCPR_BasePt.Border.Top - BottomMargin; + + pPrintJob->LeftMargin = (ESCPR_BYTE2)(gESCPR_BasePt.Border.Left); + pPrintJob->TopMargin = (ESCPR_BYTE2)(gESCPR_BasePt.Border.Top); + + /* max PAW/PAL */ + maxPALengthBorder = pPrintJob->PaperLength*gESCPR_DPI_Multiplier + - pPrintJob->TopMargin - gESCPR_BasePt.Border.Bottom; + maxPAWidthBorder = pPrintJob->PaperWidth*gESCPR_DPI_Multiplier + - pPrintJob->LeftMargin - gESCPR_BasePt.Border.Right; + + if (pPrintJob->PrintableAreaLength > maxPALengthBorder) { + pPrintJob->PrintableAreaLength = maxPALengthBorder; + } + + if (pPrintJob->PrintableAreaWidth > maxPAWidthBorder) { + pPrintJob->PrintableAreaWidth = maxPAWidthBorder; + } + + } + + return ESCPR_ERR_NOERROR; +} + +ESCPR_ERR_CODE ESCPR_MakePrintJobCmd(const ESCPR_PRINT_JOB *pPrintJob) +{ + ESCPR_BYTE4 i; + ESCPR_BYTE4 cmdSize; /* All Size of Print Job Command */ + ESCPR_BYTE4 cpy_size; /* Copy Size */ + ESCPR_BYTE4 cpy_count = 0; /* Counter for Set Command */ + ESCPR_UBYTE4 paramLength; /* Parameter Length */ + ESCPR_UBYTE1 value_array_2[2]; /* Temporary Buffer for 2 byte Big Endian */ + ESCPR_UBYTE1 value_array_4[4]; /* Temporary Buffer for 4 byte Big Endian */ + + ESCPR_UBYTE1 cmdBuff[ESCPR_HEADER_LENG + ESCPR_PRTJOB_PARAMBLC_LENG]; + /* Temporary Buffer for Print Quality Command */ + + static const ESCPR_UBYTE1 Header[2] = {0x1B, 'j'}; /* ESC + Class */ + static const ESCPR_UBYTE1 cmdName[4] = {'s', 'e', 't', 'j'}; /* Command Name */ + + ESCPR_PRINT_JOB cpyPrintJob; + + /* fill out globals */ + if (pPrintJob->InResolution == ESCPR_IR_7272) { + gESCPR_DPI_Multiplier = 2; + } else { + gESCPR_DPI_Multiplier = 1; + } + + SetGlobalBasePointData(pPrintJob->PaperWidth); + + if (pPrintJob->TopMargin < gESCPR_BasePt.Borderless.Top || + pPrintJob->LeftMargin < gESCPR_BasePt.Borderless.Left) { + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* create a copy of pPrintJob */ + cpyPrintJob.PaperWidth = pPrintJob->PaperWidth; + cpyPrintJob.PaperLength = pPrintJob->PaperLength; + cpyPrintJob.TopMargin = pPrintJob->TopMargin; + cpyPrintJob.LeftMargin = pPrintJob->LeftMargin; + cpyPrintJob.PrintableAreaWidth = pPrintJob->PrintableAreaWidth; + cpyPrintJob.PrintableAreaLength = pPrintJob->PrintableAreaLength; + cpyPrintJob.InResolution = pPrintJob->InResolution; + cpyPrintJob.PrintDirection = pPrintJob->PrintDirection; + +#if defined(_ZERO_MARGIN_REPLICATE) || defined(_ZERO_MARGIN_MIRROR) + + if (cpyPrintJob.LeftMargin < 0 || cpyPrintJob.TopMargin < 0) return ESCPR_ERR_HAPPEN_PROBLEM; + /* use borderless technique or not */ + gESCPR_Borderless = (cpyPrintJob.LeftMargin == 0 + && cpyPrintJob.TopMargin == 0 + && cpyPrintJob.PaperWidth*gESCPR_DPI_Multiplier == cpyPrintJob.PrintableAreaWidth + && cpyPrintJob.PaperLength*gESCPR_DPI_Multiplier + == cpyPrintJob.PrintableAreaLength); + +#if defined(_ZERO_MARGIN_MIRROR) + gESCPR_DupBufferTop = NULL; + gESCPR_DupBufferBot = NULL; +#endif + + if (gESCPR_Borderless) { + + /* change to borderless margins */ + cpyPrintJob.TopMargin = -1*gESCPR_BasePt.Pad.Top; + cpyPrintJob.LeftMargin = -1*gESCPR_BasePt.Pad.Left; + cpyPrintJob.PrintableAreaLength += gESCPR_BasePt.Pad.Top + gESCPR_BasePt.Pad.Bottom; + cpyPrintJob.PrintableAreaWidth += gESCPR_BasePt.Pad.Left + gESCPR_BasePt.Pad.Right; + + dprintf(("cpyPrintJob.TopMargin: %d\n",cpyPrintJob.TopMargin)); + dprintf(("cpyPrintJob.LeftMargin: %d\n",cpyPrintJob.LeftMargin)); + dprintf(("cpyPrintJob.PrintableAreaWidth: %d\n",cpyPrintJob.PrintableAreaWidth)); + dprintf(("cpyPrintJob.PrintableAreaLength: %d\n",cpyPrintJob.PrintableAreaLength)); + +#if defined(_ZERO_MARGIN_MIRROR) + /* allocate memory for duplicated region and save buffer */ + gESCPR_DupBufferTop = ESCPR_Mem_Alloc( + cpyPrintJob.PrintableAreaWidth*gESCPR_bpp*gESCPR_BasePt.Pad.Top*2); + + if (gESCPR_DupBufferTop == NULL) return ESCPR_ERR_CAN_T_ALLOC_MEMORY; + ESCPR_Mem_Set(gESCPR_DupBufferTop,255, + cpyPrintJob.PrintableAreaWidth*gESCPR_bpp*gESCPR_BasePt.Pad.Top*2); + + gESCPR_DupBufferBot = ESCPR_Mem_Alloc( + cpyPrintJob.PrintableAreaWidth*gESCPR_bpp*gESCPR_BasePt.Pad.Bottom*2); + + if (gESCPR_DupBufferBot == NULL) { + ESCPR_FreeLocalBuf(gESCPR_DupBufferTop); + return ESCPR_ERR_CAN_T_ALLOC_MEMORY; + } + ESCPR_Mem_Set(gESCPR_DupBufferBot,255, + cpyPrintJob.PrintableAreaWidth*gESCPR_bpp*gESCPR_BasePt.Pad.Bottom*2); + +#endif /* defined(_ZERO_MARGIN_MIRROR) */ + } else { + ESCPR_AdjustBasePoint(&cpyPrintJob); + } +#else /* defined(_ZERO_MARGIN_REPLICATE) || defined(_ZERO_MARGIN_MIRROR) */ + ESCPR_AdjustBasePoint(&cpyPrintJob); +#endif /* defined(_ZERO_MARGIN_REPLICATE) || defined(_ZERO_MARGIN_MIRROR) */ + + gESCPR_PrintableAreaLength = cpyPrintJob.PrintableAreaLength; + gESCPR_PrintableAreaWidth = cpyPrintJob.PrintableAreaWidth; + + paramLength = ESCPR_PRTJOB_PARAMBLC_LENG; + cmdSize = ESCPR_HEADER_LENG + paramLength; + + /* Debug Test >>> */ + dprintf(("---------------\n")); + dprintf(("ESCPR_PRINT_JOB - Job Command is made from this parameter\n")); + dprintf(("---------------\n")); + dprintf(("\tPaperWidth: %d\n", cpyPrintJob.PaperWidth)); + dprintf(("\tPaperLength: %d\n", cpyPrintJob.PaperLength)); + dprintf(("\tTopMargin: %d\n", cpyPrintJob.TopMargin)); + dprintf(("\tLeftMargin: %d\n", cpyPrintJob.LeftMargin)); + dprintf(("\tPrintableAreaWidth: %d\n", cpyPrintJob.PrintableAreaWidth)); + dprintf(("\tPrintableAreaLength: %d\n", cpyPrintJob.PrintableAreaLength)); + dprintf(("\tInResolution: %d\n", cpyPrintJob.InResolution)); + dprintf(("\tPrintDirection: %d\n", cpyPrintJob.PrintDirection)); + dprintf(("\n")); + /* Debug Test <<< */ + + + /* Set Parameter */ + + /* Header */ + cpy_size = sizeof(Header); + ESCPR_Mem_Copy((cmdBuff + cpy_count), Header, cpy_size); + cpy_count += cpy_size; + + /* Parameter Length */ + cpy_size = sizeof(value_array_4); + if(ESCPR_SetLittleEndian_BYTE4(paramLength, value_array_4)){ + ESCPR_Mem_Copy((cmdBuff + cpy_count), value_array_4, cpy_size); + cpy_count += cpy_size; + } else{ +#if defined(_ZERO_MARGIN_MIRROR) + ESCPR_FreeLocalBuf(gESCPR_DupBufferTop); + ESCPR_FreeLocalBuf(gESCPR_DupBufferBot); +#endif + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Command Name */ + cpy_size = sizeof(cmdName); + ESCPR_Mem_Copy((cmdBuff + cpy_count), cmdName, cpy_size); + cpy_count += cpy_size; + + /* Paper Width */ + cpy_size = sizeof(value_array_4); + if(ESCPR_SetBigEndian_BYTE4(cpyPrintJob.PaperWidth, value_array_4)){ + ESCPR_Mem_Copy((cmdBuff + cpy_count), value_array_4, cpy_size); + cpy_count += cpy_size; + } else{ +#if defined(_ZERO_MARGIN_MIRROR) + ESCPR_FreeLocalBuf(gESCPR_DupBufferTop); + ESCPR_FreeLocalBuf(gESCPR_DupBufferBot); +#endif + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Paper Length */ + cpy_size = sizeof(value_array_4); + if(ESCPR_SetBigEndian_BYTE4(cpyPrintJob.PaperLength, value_array_4)){ + ESCPR_Mem_Copy((cmdBuff + cpy_count), value_array_4, cpy_size); + cpy_count += cpy_size; + } else{ +#if defined(_ZERO_MARGIN_MIRROR) + ESCPR_FreeLocalBuf(gESCPR_DupBufferTop); + ESCPR_FreeLocalBuf(gESCPR_DupBufferBot); +#endif + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Top Margin */ + cpy_size = sizeof(value_array_2); + if(ESCPR_SetBigEndian_BYTE2(cpyPrintJob.TopMargin, value_array_2)){ + ESCPR_Mem_Copy((cmdBuff + cpy_count), value_array_2, cpy_size); + cpy_count += cpy_size; + } else{ +#if defined(_ZERO_MARGIN_MIRROR) + ESCPR_FreeLocalBuf(gESCPR_DupBufferTop); + ESCPR_FreeLocalBuf(gESCPR_DupBufferBot); +#endif + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Left Margin */ + cpy_size = sizeof(value_array_2); + if(ESCPR_SetBigEndian_BYTE2(cpyPrintJob.LeftMargin, value_array_2)){ + ESCPR_Mem_Copy((cmdBuff + cpy_count), value_array_2, cpy_size); + cpy_count += cpy_size; + } else{ +#if defined(_ZERO_MARGIN_MIRROR) + ESCPR_FreeLocalBuf(gESCPR_DupBufferTop); + ESCPR_FreeLocalBuf(gESCPR_DupBufferBot); +#endif + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Printable Area - Width */ + cpy_size = sizeof(value_array_4); + if(ESCPR_SetBigEndian_BYTE4(cpyPrintJob.PrintableAreaWidth, value_array_4)){ + ESCPR_Mem_Copy((cmdBuff + cpy_count), value_array_4, cpy_size); + cpy_count += cpy_size; + } else{ +#if defined(_ZERO_MARGIN_MIRROR) + ESCPR_FreeLocalBuf(gESCPR_DupBufferTop); + ESCPR_FreeLocalBuf(gESCPR_DupBufferBot); +#endif + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Printable Area - Length */ + cpy_size = sizeof(value_array_4); + if(ESCPR_SetBigEndian_BYTE4(cpyPrintJob.PrintableAreaLength, value_array_4)){ + ESCPR_Mem_Copy((cmdBuff + cpy_count), value_array_4, cpy_size); + cpy_count += cpy_size; + } else{ +#if defined(_ZERO_MARGIN_MIRROR) + ESCPR_FreeLocalBuf(gESCPR_DupBufferTop); + ESCPR_FreeLocalBuf(gESCPR_DupBufferBot); +#endif + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Input Resolution */ + *(cmdBuff + cpy_count) = cpyPrintJob.InResolution; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Print Direction */ + *(cmdBuff + cpy_count) = cpyPrintJob.PrintDirection; + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Debug Test >>> */ + if(cmdSize == cpy_count){ + dprintf(("ESCPRCMD : PrintJob Cmd [size = %d] : ", cpy_count)); + for(i = 0; i < cpy_count; i++){ + dprintf(("%.2X ", cmdBuff[i])); + } + dprintf(("\n")); + } else{ + dprintf(("ESCPRCMD : ESCPR_Make PrintQualityCmd Faild!\n")); +#if defined(_ZERO_MARGIN_MIRROR) + ESCPR_FreeLocalBuf(gESCPR_DupBufferTop); + ESCPR_FreeLocalBuf(gESCPR_DupBufferBot); +#endif + return ESCPR_ERR_HAPPEN_PROBLEM; + } + /* Debug Test <<< */ + + /* Send Print Job Command to Printer */ +#if defined(_ZERO_MARGIN_MIRROR) + if(ESCPR_SendData_CheckResult(cmdBuff, cmdSize) != ESCPR_ERR_NOERROR) { + ESCPR_FreeLocalBuf(gESCPR_DupBufferTop); + ESCPR_FreeLocalBuf(gESCPR_DupBufferBot); + return ESCPR_ERR_SPOOL_IO; + } +#else + ESCPR_SendData(NULL, cmdBuff, cmdSize); +#endif + + paramLength = ESCPR_SENDDATA_PARAMBLC_LENG + + (cpyPrintJob.PrintableAreaWidth * gESCPR_bpp); + gESCPR_ImgBufSize = ESCPR_HEADER_LENG + paramLength; + + gESCPR_CompBufSize = (ESCPR_BYTE4)(cpyPrintJob.PrintableAreaWidth * gESCPR_bpp) + 256; /* 256 is temp buffer */ + + return ESCPR_ERR_NOERROR; +} + + +ESCPR_ERR_CODE ESCPR_MakeStartPageCmd(void) +{ + static const ESCPR_UBYTE1 cmd_StartPage[] = { + 0x1B, 'p', 0x00, 0x00, 0x00, 0x00, 's', 't', 't', 'p', + }; + + ESCPR_SendData(NULL, cmd_StartPage, sizeof(cmd_StartPage)); + +#if defined(_ZERO_MARGIN_MIRROR) + if (gESCPR_Borderless) { + gESCPR_TopCnt = 0; + gESCPR_BotCnt = 0; + gESCPR_TopFlushed = FALSE; + + if (gESCPR_DupBufferTop != NULL) + ESCPR_Mem_Set(gESCPR_DupBufferTop,255, + gESCPR_PrintableAreaWidth*gESCPR_bpp*gESCPR_BasePt.Pad.Top*2); + + if (gESCPR_DupBufferBot != NULL) + ESCPR_Mem_Set(gESCPR_DupBufferBot,255, + gESCPR_PrintableAreaWidth*gESCPR_bpp*gESCPR_BasePt.Pad.Bottom*2); + + } +#endif /* defined(_ZERO_MARGIN_MIRROR) */ + + return ESCPR_ERR_NOERROR; +} + + +ESCPR_ERR_CODE ESCPR_MakeImageData(const ESCPR_BANDBMP *pInBmp, ESCPR_RECT *pBandRec) +{ + ESCPR_BYTE4 i; + ESCPR_UBYTE1* j; + ESCPR_ERR_CODE Error; /* Error Code */ + ESCPR_BYTE4 BandHeight = pBandRec->bottom - pBandRec->top; /* Band Length */ + const ESCPR_BYTE4 MaxBandHeight = (ESCPR_BYTE4)gESCPR_PrintableAreaLength - pBandRec->top; + + ESCPR_RECT NewBandRec; /* New Rectangle */ + ESCPR_BANDBMP NewInBmp; /* New Band Data */ + + ESCPR_BYTE1 skip = FALSE; + +#ifdef _ESCPR_DEBUG + ESCPR_UBYTE4 DebugBandCount = 0; +#endif + + /* Initialize */ + NewInBmp.WidthBytes = pInBmp->WidthBytes; + + /* error check */ + if (pInBmp->Bits == NULL || BandHeight <= 0 || pBandRec->right - pBandRec->left <= 0) { + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + if (BandHeight > MaxBandHeight) { + BandHeight = MaxBandHeight; + } + + /************************************************************** + * Core Module 1.0.9 + * The following section of code forces the core + * module to skip raster lines that are completely white + * in order to minimize data size. + * This function is compatible with 8-bit palettized and + * 24-bit RGB bitmaps. + * ************************************************************/ + + for(i=0; i < BandHeight; i++){ + + /* calculate position of raster */ + NewInBmp.Bits = ( ((ESCPR_UBYTE1 *)pInBmp->Bits) + (i * pInBmp->WidthBytes) ); + + /* Make new BandRect */ + NewBandRec.top = pBandRec->top + i; + NewBandRec.left = pBandRec->left; + NewBandRec.bottom = NewBandRec.top + 1; + NewBandRec.right = pBandRec->right; + + skip = FALSE; + + for( j = NewInBmp.Bits; j < (NewInBmp.Bits + NewInBmp.WidthBytes); j++){ + if(*j != gESCPR_WhiteColorValue){ /* if any byte in the line is ever non-white */ + skip = FALSE; /* don't skip the line, and break out of the test loop */ + break; + } else { + skip = TRUE; /* otherwise, (tentatively) skip the band */ + } + } + + if(skip == TRUE){ /* If the line happens to be completely white, */ +#ifdef _ESCPR_DEBUG + DebugBandCount++; +#endif + continue; /* Skip the band (don't print) and iterate again */ + } + + /* Make 1 line of raster data */ + Error = ESCPR_RasterFilter(&NewInBmp, &NewBandRec); + if( Error != ESCPR_ERR_NOERROR ) return Error; + } + + /* Some useful debug information - check and see how many lines were actually skipped. */ +#ifdef _ESCPR_DEBUG + gESCPR_TotalDebugBandCount = gESCPR_TotalDebugBandCount + DebugBandCount; + dprintf(("ESCPRCMD: Skipped %d white raster lines.\n", gESCPR_TotalDebugBandCount)); +#endif + + return ESCPR_ERR_NOERROR; +} + + +ESCPR_ERR_CODE ESCPR_RasterFilter(const ESCPR_BANDBMP *pInBmp, ESCPR_RECT *pBandRec) { + + ESCPR_RECT AdjBandRec; /* Rectangle after BasePointAdjustment */ + +#if defined(_ZERO_MARGIN_REPLICATE) || defined(_ZERO_MARGIN_MIRROR) + ESCPR_BYTE4 i; + ESCPR_BANDBMP OutBmp; /* New band data */ + ESCPR_BYTE4 RepCnt = 0; /* Repeat count for band data */ + ESCPR_ERR_CODE Error; /* Error Code */ + ESCPR_UBYTE1* BandBuffer; /* Temp Buffer for band data */ + +#endif /* defined(_ZERO_MARGIN_REPLICATE) || defined(_ZERO_MARGIN_MIRROR) */ + +#if defined(_ZERO_MARGIN_MIRROR) + ESCPR_BYTE4 j; + ESCPR_RECT NewBandRec; /* New Rectangle used to divide bands */ +#endif /* defined(_ZERO_MARGIN_MIRROR) */ + + /* change rectangle due to base point adjustment */ + AdjBandRec.top = pBandRec->top + gESCPR_offset_y; + AdjBandRec.left = pBandRec->left + gESCPR_offset_x; + AdjBandRec.bottom = pBandRec->bottom + gESCPR_offset_y; + AdjBandRec.right = pBandRec->right + gESCPR_offset_x; + + /* band is not visible */ + if ((ESCPR_UBYTE4)AdjBandRec.bottom > gESCPR_PrintableAreaLength){ + return ESCPR_ERR_NOERROR; + } + + if ((ESCPR_UBYTE4)AdjBandRec.right > gESCPR_PrintableAreaWidth){ + AdjBandRec.right = (ESCPR_BYTE4)gESCPR_PrintableAreaWidth; + } + +#if defined(_ZERO_MARGIN_REPLICATE) || defined(_ZERO_MARGIN_MIRROR) + if (gESCPR_Borderless) { + if ((ESCPR_UBYTE4)AdjBandRec.top > gESCPR_PrintableAreaLength - + gESCPR_BasePt.Pad.Top - gESCPR_BasePt.Pad.Bottom || + (ESCPR_UBYTE4)AdjBandRec.left > gESCPR_PrintableAreaWidth - + gESCPR_BasePt.Pad.Left - gESCPR_BasePt.Pad.Right) { + + return ESCPR_ERR_NOERROR; + } + } +#endif + +#if defined(_ZERO_MARGIN_REPLICATE) + if (gESCPR_Borderless) { + BandBuffer = ESCPR_Mem_Alloc(gESCPR_PrintableAreaWidth*gESCPR_bpp); + if (BandBuffer == NULL) return ESCPR_ERR_CAN_T_ALLOC_MEMORY; + + Error = ESCPR_RasterFilterReplicate(pInBmp,&AdjBandRec,&RepCnt,&OutBmp,BandBuffer); + + if (Error != ESCPR_ERR_NOERROR) { + ESCPR_Mem_Free(BandBuffer); + return Error; + } + + for (i=0; i < RepCnt; i++) { + Error = ESCPR_MakeOneRasterData(&OutBmp,&AdjBandRec); + if (Error != ESCPR_ERR_NOERROR) { + ESCPR_Mem_Free(BandBuffer); + return Error; + } + + AdjBandRec.top += 1; + AdjBandRec.bottom += 1; + } + + ESCPR_Mem_Free(BandBuffer); + + return ESCPR_ERR_NOERROR; + } + +#endif /* defined(_ZERO_MARGIN_REPLICATE) */ + +#if defined(_ZERO_MARGIN_MIRROR) + if (gESCPR_Borderless) { + ESCPR_UBYTE1* pBits; /* temporary pointer used to save band data ptr */ + + BandBuffer = ESCPR_Mem_Alloc(gESCPR_PrintableAreaWidth*gESCPR_bpp); + if (BandBuffer == NULL) return ESCPR_ERR_CAN_T_ALLOC_MEMORY; + ESCPR_Mem_Set(BandBuffer,255,gESCPR_PrintableAreaWidth*gESCPR_bpp); + + Error = ESCPR_RasterFilterMirror(pInBmp,&AdjBandRec,&RepCnt,&OutBmp,BandBuffer); + if (Error != ESCPR_ERR_NOERROR) { + ESCPR_Mem_Free(BandBuffer); + return Error; + } + + dprintf(("RFZeroMirror: T,B,L,R [%d,%d,%d,%d] Rep: %d\n", + AdjBandRec.top, + AdjBandRec.bottom, + AdjBandRec.left, + AdjBandRec.right, + RepCnt)); + + pBits = OutBmp.Bits; + + for (i=0; i < RepCnt; i++) { + + NewBandRec.left = AdjBandRec.left; + NewBandRec.right = AdjBandRec.right; + + for (j=0; j < (AdjBandRec.bottom - AdjBandRec.top); j++) { + + /* change Bits to point to next band */ + OutBmp.Bits = pBits + j*gESCPR_PrintableAreaWidth*gESCPR_bpp; + + NewBandRec.top = AdjBandRec.top+j; + NewBandRec.bottom = NewBandRec.top+1; + + Error = ESCPR_MakeOneRasterData(&OutBmp,&NewBandRec); + if (Error != ESCPR_ERR_NOERROR) { + ESCPR_Mem_Free(BandBuffer); + return Error; + } + } + + AdjBandRec.top += 1; + AdjBandRec.bottom += 1; + } + + ESCPR_Mem_Free(BandBuffer); + + return ESCPR_ERR_NOERROR; + } +#endif /* defined(_ZERO_MARGIN_MIRROR) */ + + return ESCPR_MakeOneRasterData(pInBmp,&AdjBandRec); +} + + +#if defined(_ZERO_MARGIN_MIRROR) || (_ZERO_MARGIN_REPLICATE) +ESCPR_ERR_CODE ESCPR_CalculatePadding(ESCPR_RECT *pBandRec,ESCPR_BYTE2* NumPadLeft, + ESCPR_BYTE2* NumPadRight, ESCPR_UBYTE2* RasterPixelSize) { + + ESCPR_BYTE4 MaxRasterSize; + *NumPadRight = 0; + *NumPadLeft = 0; + + if (gESCPR_Borderless) { + /* we always make the left side pad because we need to align the user's + * image correctly. the right pad can be made with the user's excess data */ + MaxRasterSize = (ESCPR_BYTE4)gESCPR_PrintableAreaWidth - gESCPR_BasePt.Pad.Left - pBandRec->left; + } else { + MaxRasterSize = (ESCPR_BYTE4)gESCPR_PrintableAreaWidth; + } + + if( (ESCPR_UBYTE4)(pBandRec->right - pBandRec->left) <= MaxRasterSize){ + *RasterPixelSize = (ESCPR_UBYTE2)(pBandRec->right - pBandRec->left); + } else{ + *RasterPixelSize = (ESCPR_UBYTE2) MaxRasterSize; + } + + /* calculate the padding we need */ + if (gESCPR_Borderless) { + /* only need left pad if there is no offset */ + if (pBandRec->left == 0) { + *NumPadLeft = gESCPR_BasePt.Pad.Left; + } else { + /* add white space */ + pBandRec->left += gESCPR_BasePt.Pad.Left; + *NumPadLeft = 0; + } + + /* calculate padding */ + *NumPadRight = (ESCPR_BYTE2)gESCPR_PrintableAreaWidth - + *NumPadLeft - pBandRec->left - *RasterPixelSize; + + /* only need right pad if user sent full raster */ + if (*NumPadRight > gESCPR_BasePt.Pad.Right) *NumPadRight = 0; + if (*NumPadRight < 0) *NumPadRight = 0; + + pBandRec->right = pBandRec->left + *RasterPixelSize + *NumPadLeft + *NumPadRight; + + dprintf(("PrintableAreaWidth: %d\n",gESCPR_PrintableAreaWidth)); + dprintf(("*RasterPixelSize: %d\n",*RasterPixelSize)); + dprintf(("Pad [%d,%d]\n",*NumPadLeft,*NumPadRight)); + dprintf(("Rect L.R [%d,%d]\n",pBandRec->left,pBandRec->right)); + } + return ESCPR_ERR_NOERROR; +} + +#endif + +#if defined(_ZERO_MARGIN_REPLICATE) +ESCPR_ERR_CODE ESCPR_RasterFilterReplicate(const ESCPR_BANDBMP* pInBmp, + ESCPR_RECT *pBandRec, ESCPR_BYTE4* RepCnt, ESCPR_BANDBMP* pOutBmp, + ESCPR_UBYTE1* TempBuffer) { + + ESCPR_BYTE4 i; + ESCPR_BYTE2 NumPadLeft = 0; /* Padding on the left */ + ESCPR_BYTE2 NumPadRight = 0; /* Padding on the right */ + ESCPR_UBYTE2 RasterPixelSize; /* Raster Pixel Size */ + ESCPR_ERR_CODE Error; /* Error Code */ + + pOutBmp->Bits = TempBuffer; + pOutBmp->WidthBytes = gESCPR_bpp*gESCPR_PrintableAreaWidth; + + Error = ESCPR_CalculatePadding(pBandRec, &NumPadLeft, &NumPadRight, &RasterPixelSize); + if (Error != ESCPR_ERR_NOERROR) return Error; + + /* fill in left and right pads */ + for(i=0; i < NumPadLeft; i++) { + ESCPR_Mem_Copy(pOutBmp->Bits+i*gESCPR_bpp,pInBmp->Bits,gESCPR_bpp); + } + + ESCPR_Mem_Copy(pOutBmp->Bits+NumPadLeft*gESCPR_bpp, + pInBmp->Bits,RasterPixelSize*gESCPR_bpp); + + for (i=0; i < NumPadRight; i++) { + ESCPR_Mem_Copy(pOutBmp->Bits + +(NumPadLeft+RasterPixelSize+i)*gESCPR_bpp, + &pInBmp->Bits[(RasterPixelSize-1)*gESCPR_bpp],gESCPR_bpp); + } + + /* adjust the rectangle coordinates */ + if (pBandRec->top == 0) { + *RepCnt = gESCPR_BasePt.Pad.Top; + } else if (pBandRec->bottom == + (gESCPR_PrintableAreaLength-gESCPR_BasePt.Pad.Top-gESCPR_BasePt.Pad.Bottom)) { + + pBandRec->top += gESCPR_BasePt.Pad.Top; + pBandRec->bottom += gESCPR_BasePt.Pad.Top; + + *RepCnt = gESCPR_BasePt.Pad.Bottom; + + } else { + pBandRec->top += gESCPR_BasePt.Pad.Top; + pBandRec->bottom += gESCPR_BasePt.Pad.Top; + *RepCnt = 1; + } + + return ESCPR_ERR_NOERROR; +} +#endif + + +#if defined(_ZERO_MARGIN_MIRROR) +ESCPR_ERR_CODE ESCPR_RasterFilterMirror(const ESCPR_BANDBMP* pInBmp, ESCPR_RECT *pBandRec, + ESCPR_BYTE4* RepCnt, ESCPR_BANDBMP* pOutBmp, ESCPR_UBYTE1* TempBuffer) { + + ESCPR_BYTE4 i; + ESCPR_BYTE2 NumPadLeft = 0; /* Number of padding on the left */ + ESCPR_BYTE2 NumPadRight = 0; /* Number of padding on the right */ + ESCPR_UBYTE2 RasterPixelSize; /* Raster Pixel Size */ + const ESCPR_BYTE4 RasterWidth = (ESCPR_BYTE4)gESCPR_PrintableAreaWidth*gESCPR_bpp; + ESCPR_BYTE4 Src,Dst; /* Src/Dst for copying */ + ESCPR_BYTE4 TotalRasterSize; /* Raster pixel size + padding */ + ESCPR_ERR_CODE Error; + + pOutBmp->Bits = TempBuffer; + pOutBmp->WidthBytes = RasterWidth; + + Error = ESCPR_CalculatePadding(pBandRec, &NumPadLeft, &NumPadRight, &RasterPixelSize); + if (Error != ESCPR_ERR_NOERROR) return Error; + + /* fill in left and right pads */ + for(i=0; i < NumPadLeft; i++) { + Dst = i; + Src = NumPadLeft-i; + + Src += (rand() % (ESCPR_BLUR_FACTOR)*2) - ESCPR_BLUR_FACTOR; + if (Src < 0) Src = 0; + if (Src > RasterPixelSize-1) Src = RasterPixelSize-1; + + ESCPR_Mem_Copy( + pOutBmp->Bits + Dst*gESCPR_bpp, + pInBmp->Bits + Src*gESCPR_bpp, + gESCPR_bpp); + } + + ESCPR_Mem_Copy(pOutBmp->Bits+(NumPadLeft)*gESCPR_bpp, + pInBmp->Bits, + RasterPixelSize*gESCPR_bpp); + + for (i=0; i < NumPadRight; i++) { + Dst = i + NumPadLeft + RasterPixelSize; + Src = RasterPixelSize-1-i; + + Src += (rand() % (ESCPR_BLUR_FACTOR)*2) - ESCPR_BLUR_FACTOR; + if (Src < 0) Src = 0; + if (Src > RasterPixelSize-1) Src = RasterPixelSize-1; + + ESCPR_Mem_Copy( + pOutBmp->Bits + Dst*gESCPR_bpp, + pInBmp->Bits + Src*gESCPR_bpp, + gESCPR_bpp); + } + + /* adjust the rectangle coordinates */ + pBandRec->top += gESCPR_BasePt.Pad.Top; + pBandRec->bottom += gESCPR_BasePt.Pad.Top; + TotalRasterSize = RasterPixelSize+NumPadLeft+NumPadRight; + *RepCnt = 1; + + /*** save rasters to create duplicate region later ***/ + + /* top */ + if (pBandRec->top < 2*gESCPR_BasePt.Pad.Top) { + Dst = pBandRec->top; + Src = 0; + + ESCPR_Mem_Copy( + gESCPR_DupBufferTop+Dst*RasterWidth+pBandRec->left*gESCPR_bpp, + pOutBmp->Bits, + TotalRasterSize*gESCPR_bpp); + + *RepCnt = 0; + gESCPR_TopCnt++; + } + + if (pBandRec->top >= 2*gESCPR_BasePt.Pad.Top && gESCPR_TopFlushed == FALSE) { + /* if we passed the flushing point and top has not been flushed, it + * means user skipped the top rasters (by setting offset). there is nothing + * to flush. + */ + gESCPR_TopFlushed = TRUE; + } + + /* bottom */ + if (pBandRec->top > Max(0,gESCPR_PrintableAreaLength - 2*gESCPR_BasePt.Pad.Bottom -1)) { + Src = 0; + Dst = gESCPR_BasePt.Pad.Bottom - + (gESCPR_PrintableAreaLength - gESCPR_BasePt.Pad.Bottom - pBandRec->top); + /* distance from bottom of image */ + + ESCPR_Mem_Copy( + gESCPR_DupBufferBot+Dst*RasterWidth +pBandRec->left*gESCPR_bpp, + pOutBmp->Bits, + TotalRasterSize*gESCPR_bpp); + + /* only output this line if the top has already been printed */ + /* ( if the top has not been flushed, this line will be flushed with the top) */ + if (gESCPR_TopFlushed) { + *RepCnt = 1; + } else { + *RepCnt = 0; + } + gESCPR_BotCnt++; + } + + /*** Create duplicated region ***/ + if (pBandRec->top == gESCPR_PrintableAreaLength - gESCPR_BasePt.Pad.Bottom - 1) { + /* Create Bottom Duplication Region */ + + /* this is last raster , if top has not been flushed, we must flush */ + if (gESCPR_TopFlushed == FALSE) { + Error = ESCPR_MakeImageFlushTop(); + if (Error != ESCPR_ERR_NOERROR) return Error; + + /* since we flushed top (which includes this raster), + * do not print the first raster in MakeMirrorImageBottom */ + + Error = ESCPR_MakeMirrorImageBottom(pBandRec,pOutBmp,FALSE); + if (Error != ESCPR_ERR_NOERROR) return Error; + + } else { + Error = ESCPR_MakeMirrorImageBottom(pBandRec,pOutBmp,TRUE); + if (Error != ESCPR_ERR_NOERROR) return Error; + } + *RepCnt = 1; + + } else if (pBandRec->top == 2*gESCPR_BasePt.Pad.Top - 1) { + + /* Create Top Duplication Region */ + Error = ESCPR_MakeMirrorImageTop(pBandRec,pOutBmp); + if (Error != ESCPR_ERR_NOERROR) return Error; + + *RepCnt = 1; + } + + return ESCPR_ERR_NOERROR; +} + +ESCPR_ERR_CODE ESCPR_MakeMirrorImageBottom(ESCPR_RECT* pBandRec, ESCPR_BANDBMP* pOutBmp, + const BOOL PrintLastRaster) { + + const ESCPR_BYTE4 RasterWidth = (ESCPR_BYTE4)gESCPR_PrintableAreaWidth*gESCPR_bpp; + const ESCPR_BYTE4 LowerBoundY = Max(0,(gESCPR_BasePt.Pad.Bottom-gESCPR_BotCnt)); + const ESCPR_BYTE1 Offset = (PrintLastRaster) ? -1 : 0; + + ESCPR_BYTE4 Dst,Src; /* dst,src row */ + ESCPR_BYTE4 Src_x,Src_y; /* dst,src pixel */ + ESCPR_BYTE4 i,j; + + dprintf(("MakeMirrorImageBot: gESCPR_BotCnt: %d LowerBoundY: %d\n", + gESCPR_BotCnt,LowerBoundY)); + + for (i=0; i < gESCPR_BasePt.Pad.Bottom; i++) { + + Dst = (gESCPR_BasePt.Pad.Bottom+i); + Src = (gESCPR_BasePt.Pad.Bottom-i-1); + + for (j=0; j < gESCPR_PrintableAreaWidth; j++) { + const ESCPR_BYTE4 Dst_x = j; + + Src_x = j + (rand() % (ESCPR_BLUR_FACTOR)*2) - ESCPR_BLUR_FACTOR; + Src_y = Src + (rand() % (ESCPR_BLUR_FACTOR)*2) - ESCPR_BLUR_FACTOR; + + if (Src_x < 0) Src_x = 0; + if (Src_x > (ESCPR_BYTE4)gESCPR_PrintableAreaWidth-1) Src_x = (ESCPR_BYTE4)gESCPR_PrintableAreaWidth-1; + + if (Src_y < LowerBoundY) Src_y = LowerBoundY; + if (Src_y > gESCPR_BasePt.Pad.Bottom-1) Src_y = gESCPR_BasePt.Pad.Bottom-1; + + ESCPR_Mem_Copy( + gESCPR_DupBufferBot + Dst*RasterWidth + Dst_x*gESCPR_bpp, + gESCPR_DupBufferBot + Src_y*RasterWidth + Src_x*gESCPR_bpp, + gESCPR_bpp); + } + } + + /* only print out new section */ + pOutBmp->Bits = gESCPR_DupBufferBot + RasterWidth*(gESCPR_BasePt.Pad.Bottom+Offset); + pOutBmp->WidthBytes = RasterWidth; + + pBandRec->top = pBandRec->bottom+Offset; + pBandRec->bottom += gESCPR_BasePt.Pad.Bottom; + pBandRec->left = 0; + pBandRec->right = (ESCPR_BYTE4)gESCPR_PrintableAreaWidth; + + return ESCPR_ERR_NOERROR; +} + +ESCPR_ERR_CODE ESCPR_MakeMirrorImageTop(ESCPR_RECT* pBandRec, ESCPR_BANDBMP* pOutBmp) { + + const ESCPR_BYTE4 RasterWidth = (ESCPR_BYTE4)gESCPR_PrintableAreaWidth*gESCPR_bpp; + const ESCPR_BYTE4 UpperBoundY = Min(gESCPR_BasePt.Pad.Top,gESCPR_TopCnt); + ESCPR_BYTE4 i,j; + ESCPR_BYTE4 Dst,Src; /* dst,src row */ + ESCPR_BYTE4 Src_x,Src_y; /* dst,src pixel */ + + gESCPR_TopFlushed = TRUE; + + dprintf(("MakeMirrorImageTop: gESCPR_TopCnt: %d UpperBoundY: %d\n", + gESCPR_TopCnt,UpperBoundY)); + + for (i=0; i < gESCPR_BasePt.Pad.Top; i++) { + Dst = i; + Src = 2*gESCPR_BasePt.Pad.Top-i-1; + + for (j=0; j < gESCPR_PrintableAreaWidth; j++) { + const ESCPR_BYTE4 Dst_x = j; + + Src_x = j + (rand() % (ESCPR_BLUR_FACTOR)*2) - ESCPR_BLUR_FACTOR; + Src_y = Src + (rand() % (ESCPR_BLUR_FACTOR)*2) - ESCPR_BLUR_FACTOR; + + if (Src_x < 0) Src_x = 0; + if (Src_x > (ESCPR_BYTE4)gESCPR_PrintableAreaWidth-1) Src_x = (ESCPR_BYTE4)gESCPR_PrintableAreaWidth-1; + + if (Src_y < 0) Src_y = 0; + if (Src_y > UpperBoundY-1) Src_y = UpperBoundY-1; + + /* for now , straight copy of the rows */ + ESCPR_Mem_Copy( + gESCPR_DupBufferTop + Dst*RasterWidth + Dst_x*gESCPR_bpp, + gESCPR_DupBufferTop + Src_y*RasterWidth + Src_x*gESCPR_bpp, + gESCPR_bpp); + + } + } + + pOutBmp->Bits = gESCPR_DupBufferTop; + pOutBmp->WidthBytes = RasterWidth; + + pBandRec->top = 0; + pBandRec->bottom = gESCPR_BasePt.Pad.Top*2; + pBandRec->left = 0; + pBandRec->right = (ESCPR_BYTE4)gESCPR_PrintableAreaWidth; + + return ESCPR_ERR_NOERROR; +} + +ESCPR_ERR_CODE ESCPR_MakeImageFlushTop(void) { + ESCPR_RECT BandRec; + ESCPR_BANDBMP BandBmp; + ESCPR_ERR_CODE Error; + + dprintf(("ESCPR_MakeImageFlushTop: TopFlush\n")); + + /* there is nothing to flush */ + if (gESCPR_TopCnt == 0) { + gESCPR_TopFlushed = TRUE; + return ESCPR_ERR_NOERROR; + } + + BandRec.right = (ESCPR_BYTE4)gESCPR_PrintableAreaWidth; + BandRec.left = 0; + + /* send remaining data */ + Error = ESCPR_MakeMirrorImageTop(&BandRec,&BandBmp); + if (Error != ESCPR_ERR_NOERROR) return Error; + + /* update rectangle */ + BandRec.top = 0; + BandRec.bottom = gESCPR_TopCnt+gESCPR_BasePt.Pad.Top; + + /* turn off borderless so mirrored data isnt made again */ + gESCPR_Borderless = FALSE; + + /* create the data */ + Error = ESCPR_MakeImageData(&BandBmp,&BandRec); + + gESCPR_Borderless = TRUE; + return ESCPR_ERR_NOERROR; +} +#endif + +ESCPR_ERR_CODE ESCPR_MakeOneRasterData(const ESCPR_BANDBMP *pInBmp, ESCPR_RECT *pBandRec) +{ + ESCPR_BYTE4 cmdSize; /* All Size of Print Job Command */ + ESCPR_BYTE4 cpy_size; /* Copy Size */ + ESCPR_BYTE4 cpy_count = 0; /* Counter for Set Command */ + ESCPR_UBYTE2 RasterDataSize; /* Raster Data Size */ + ESCPR_UBYTE2 RasterPixelSize; /* Raster Pixel Size */ + ESCPR_UBYTE1 compres_flg; /* Compression flg (1:done compression */ + /* 0:undone compression) */ + + ESCPR_UBYTE4 paramLength; /* Parameter Length */ + ESCPR_UBYTE1 value_array_2[2]; /* Temporary Buffer for 2 byte Big Endian */ + ESCPR_UBYTE1 value_array_4[4]; /* Temporary Buffer for 4 byte Big Endian */ + ESCPR_UBYTE1 *compression_data, *ImageBuff; + +#ifdef ESCPR_PACKET_4KB + ESCPR_BYTE4 rest_size; + ESCPR_BYTE4 i; +#endif + void *pCompData, *pImageBuff; + + static const ESCPR_UBYTE1 Header[2] = {0x1B, 'd'}; /* ESC + Class */ + static const ESCPR_UBYTE1 cmdName[4] = {'d', 's', 'n', 'd'}; /* Command Name */ + + dprintf(("MakeOneRasterData: T,B,L,R [%d,%d,%d,%d]\n", + pBandRec->top, pBandRec->bottom, pBandRec->left, pBandRec->right)); + + if( (ESCPR_UBYTE4)(pBandRec->right - pBandRec->left) <= gESCPR_PrintableAreaWidth){ + RasterPixelSize = (ESCPR_UBYTE2)(pBandRec->right - pBandRec->left); + } else{ + RasterPixelSize = (ESCPR_UBYTE2) gESCPR_PrintableAreaWidth; + } + +#ifdef ESCPR_IMAGE_LOG + dprintf(("ESCPRCMD : ImageData [size = %d] : ", (pBandRec->right - pBandRec->left)* 3 )); + for(i = 0; i < (pBandRec->right - pBandRec->left) * 3; i++){ + dprintf(("%.2X ", pInBmp->Bits[i])); + } + dprintf(("\n")); +#endif + + pImageBuff = ESCPR_Mem_Alloc(gESCPR_ImgBufSize); + if(pImageBuff == NULL){ + return ESCPR_ERR_CAN_T_ALLOC_MEMORY; + }else{ + ImageBuff = (ESCPR_UBYTE1 *)pImageBuff; + ESCPR_Mem_Set(ImageBuff, 0xFF, gESCPR_ImgBufSize); + } + + pCompData = ESCPR_Mem_Alloc(gESCPR_CompBufSize); /* 256 is temp buffer */ + + if(pCompData == NULL){ + ESCPR_FreeLocalBuf(pImageBuff); + return ESCPR_ERR_CAN_T_ALLOC_MEMORY; + }else{ + compression_data = (ESCPR_UBYTE1 *)pCompData; + ESCPR_Mem_Set(compression_data, 0xFF, gESCPR_CompBufSize); + } + + RasterDataSize = (ESCPR_UBYTE2) ESCPR_RunLengthEncode((ESCPR_UBYTE1 *)pInBmp->Bits, + compression_data, + RasterPixelSize, + gESCPR_bpp, + &compres_flg); + + if(compres_flg == 0){ + RasterDataSize = (ESCPR_UBYTE2)(RasterPixelSize * gESCPR_bpp); + compres_flg = 0; + compression_data = (ESCPR_UBYTE1 *)pInBmp->Bits; + } + + /* Set Parameter Length */ + paramLength = ESCPR_SENDDATA_PARAMBLC_LENG + RasterDataSize; + cmdSize = ESCPR_HEADER_LENG + paramLength; + + /* Set Parameter */ + + /* Header */ + cpy_size = sizeof(Header); + ESCPR_Mem_Copy((ImageBuff + cpy_count), Header, cpy_size); + cpy_count += cpy_size; + + /* Parameter Length */ + cpy_size = sizeof(value_array_4); + if(ESCPR_SetLittleEndian_BYTE4(paramLength, value_array_4)){ + ESCPR_Mem_Copy((ImageBuff + cpy_count), value_array_4, cpy_size); + cpy_count += cpy_size; + } else{ + ESCPR_FreeLocalBuf(pCompData); + ESCPR_FreeLocalBuf(pImageBuff); + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Command Name */ + cpy_size = sizeof(cmdName); + ESCPR_Mem_Copy((ImageBuff + cpy_count), cmdName, cpy_size); + cpy_count += cpy_size; + + /* lXoffset */ + cpy_size = sizeof(value_array_2); + if(ESCPR_SetBigEndian_BYTE2((ESCPR_UBYTE2)pBandRec->left, value_array_2)){ + ESCPR_Mem_Copy((ImageBuff + cpy_count), value_array_2, cpy_size); + cpy_count += cpy_size; + } else{ + ESCPR_FreeLocalBuf(pCompData); + ESCPR_FreeLocalBuf(pImageBuff); + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* lYoffset */ + cpy_size = sizeof(value_array_2); + if(ESCPR_SetBigEndian_BYTE2((ESCPR_UBYTE2)pBandRec->top, value_array_2)){ + ESCPR_Mem_Copy((ImageBuff + cpy_count), value_array_2, cpy_size); + cpy_count += cpy_size; + } else{ + ESCPR_FreeLocalBuf(pCompData); + ESCPR_FreeLocalBuf(pImageBuff); + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* Compression Mode */ + if(compres_flg == 1){ + *(ImageBuff + cpy_count) = ESCPR_COMP_DONE; + } else{ + *(ImageBuff + cpy_count) = ESCPR_COMP_NO; + } + cpy_count += sizeof(ESCPR_UBYTE1); + + /* Raster Data Size */ + cpy_size = sizeof(value_array_2); + if(ESCPR_SetBigEndian_BYTE2(RasterDataSize, value_array_2)){ + ESCPR_Mem_Copy((ImageBuff + cpy_count), value_array_2, cpy_size); + cpy_count += cpy_size; + } else{ + ESCPR_FreeLocalBuf(pCompData); + ESCPR_FreeLocalBuf(pImageBuff); + return ESCPR_ERR_HAPPEN_PROBLEM; + } + + /* RGB Raster Data */ + ESCPR_Mem_Copy((ImageBuff + cpy_count), compression_data, RasterDataSize); + cpy_count += RasterDataSize; + + /* Send Print Quality Command to Printer */ +#ifdef ESCPR_PACKET_4KB /* Set 1 packett size in 4096byte */ + if(cmdSize > ESCPR_PACKET_SIZE_4KB) { + for(i = 0; i < (ESCPR_BYTE4)(cmdSize / ESCPR_PACKET_SIZE_4KB); i++){ + +#ifdef ESCPR_IMAGE_LOG + dprintf(("ESCPRCMD : SendData [size = %d] : ", ESCPR_PACKET_SIZE_4KB)); + for(i = 0; i < ESCPR_PACKET_SIZE_4KB; i++){ + dprintf(("%.2X ", ImageBuff[i])); + } + dprintf(("\n")); +#endif /* ESCPR_IMAGE_LOG */ + if(ESCPR_SendData_CheckResult(ImageBuff, ESCPR_PACKET_SIZE_4KB) != ESCPR_ERR_NOERROR) { + ESCPR_FreeLocalBuf(pCompData); + ESCPR_FreeLocalBuf(pImageBuff); + return ESCPR_ERR_SPOOL_IO; + } + ImageBuff += ESCPR_PACKET_SIZE_4KB; + } + rest_size = cmdSize - + ((ESCPR_BYTE4)(cmdSize / ESCPR_PACKET_SIZE_4KB)) * ESCPR_PACKET_SIZE_4KB; + + if(ESCPR_SendData_CheckResult(ImageBuff, rest_size) != ESCPR_ERR_NOERROR) { + ESCPR_FreeLocalBuf(pCompData); + ESCPR_FreeLocalBuf(pImageBuff); + return ESCPR_ERR_SPOOL_IO; + } + +#ifdef ESCPR_IMAGE_LOG + dprintf(("ESCPRCMD : SendData [size = %d] : ", rest_size)); + for(i = 0; i < rest_size; i++){ + dprintf(("%.2X ", ImageBuff[i])); + } + dprintf(("\n")); +#endif /* ESCPR_IMAGE_LOG */ + } else{ + +#ifdef ESCPR_IMAGE_LOG + if(cmdSize == cpy_count){ + dprintf(("ESCPRCMD : SendData [size = %d] : ", cpy_count)); + for(i = 0; i < cpy_count; i++){ + dprintf(("%.2X ", ImageBuff[i])); + } + dprintf(("\n")); + } else{ + dprintf(("ESCPRCMD : ESCPR_Make PrintQualityCmd Faild!\n")); + ESCPR_FreeLocalBuf(pCompData); + ESCPR_FreeLocalBuf(pImageBuff); + return ESCPR_ERR_HAPPEN_PROBLEM; + } +#endif /* ESCPR_IMAGE_LOG */ + if(ESCPR_SendData_CheckResult(ImageBuff, cmdSize) != ESCPR_ERR_NOERROR) { + ESCPR_FreeLocalBuf(pCompData); + ESCPR_FreeLocalBuf(pImageBuff); + return ESCPR_ERR_SPOOL_IO; + } + } +#else /* ESCPR_PACKET_4KB */ + +#ifdef ESCPR_IMAGE_LOG + if(cmdSize == cpy_count){ + dprintf(("ESCPRCMD : SendData [size = %d] : ", cpy_count)); + for(i = 0; i < cpy_count; i++){ + dprintf(("%.2X ", ImageBuff[i])); + } + dprintf(("\n")); + } else{ + dprintf(("ESCPRCMD : ESCPR_Make PrintQualityCmd Faild!\n")); + ESCPR_FreeLocalBuf(pCompData); + ESCPR_FreeLocalBuf(pImageBuff); + return ESCPR_ERR_HAPPEN_PROBLEM; + } +#endif /* ESCPR_IMAGE_LOG */ + if(ESCPR_SendData_CheckResult(ImageBuff, cmdSize) != ESCPR_ERR_NOERROR) { + ESCPR_FreeLocalBuf(pCompData); + ESCPR_FreeLocalBuf(pImageBuff); + return ESCPR_ERR_SPOOL_IO; + } + +#endif /* ESCPR_PACKET_4KB */ + + /* Free RunLength Compression Buffer */ + ESCPR_Mem_Free(pCompData); + + /* Free Image Data Buffer */ + ESCPR_Mem_Free(pImageBuff); + + return ESCPR_ERR_NOERROR; +} + +ESCPR_ERR_CODE ESCPR_MakeEndPageCmd(const ESCPR_UBYTE1 NextPage){ + + static const ESCPR_UBYTE1 cmd_EndPage[] = { + 0x1B, 'p', 0x01, 0x00, 0x00, 0x00, 'e', 'n', 'd', 'p'}; + +#if defined(_ZERO_MARGIN_MIRROR) + if (!gESCPR_TopFlushed && gESCPR_Borderless) { + ESCPR_MakeImageFlushTop(); + } +#endif + + ESCPR_SendData(NULL, cmd_EndPage, sizeof(cmd_EndPage)); + ESCPR_SendData(NULL, &NextPage, sizeof(NextPage)); + + return ESCPR_ERR_NOERROR; +} + + +ESCPR_ERR_CODE ESCPR_MakeEndJobCmd(void) +{ + static const ESCPR_UBYTE1 cmd_EndJob[] = { + 0x1B, 'j', 0x00, 0x00, 0x00, 0x00, 'e', 'n', 'd', 'j', + }; + + static const ESCPR_UBYTE1 cmd_InitPrinter[] = { + 0x1B, 0x40, + }; + + static const ESCPR_UBYTE1 cmd_EnterRemoteMode[] = { + 0x1B, 0x28, 0x52, 0x08, 0x00, 0x00, 'R', 'E', 'M', 'O', 'T', 'E', '1', + }; + + static const ESCPR_UBYTE1 cmd_RemoteJE[] = { + 'J', 'E', 0x01, 0x00, 0x00, + }; + + static const ESCPR_UBYTE1 cmd_ExitRemoteMode[] = { + 0x1B, 0x00, 0x00, 0x00, + }; + + /* End Job */ + ESCPR_SendData(NULL, cmd_EndJob, sizeof(cmd_EndJob)); + + /* Initialize */ + ESCPR_SendData(NULL, cmd_InitPrinter, sizeof(cmd_InitPrinter)); + + /* Remote Command - JE */ + ESCPR_SendData(NULL, cmd_EnterRemoteMode, sizeof(cmd_EnterRemoteMode)); + ESCPR_SendData(NULL, cmd_RemoteJE, sizeof(cmd_RemoteJE)); + ESCPR_SendData(NULL, cmd_ExitRemoteMode, sizeof(cmd_ExitRemoteMode)); + +#if defined(_ZERO_MARGIN_MIRROR) + if (gESCPR_DupBufferTop != NULL) ESCPR_Mem_Free(gESCPR_DupBufferTop); + if (gESCPR_DupBufferBot != NULL) ESCPR_Mem_Free(gESCPR_DupBufferBot); +#endif /* defined(_ZERO_MARGIN_MIRROR) */ + + return ESCPR_ERR_NOERROR; +} + +void SetGlobalBasePointData(const int PaperWidth) { + + /* BORDER */ + gESCPR_BasePt.Border.Top = + (42)*gESCPR_DPI_Multiplier; + gESCPR_BasePt.Border.Bottom = + (42)*gESCPR_DPI_Multiplier; + gESCPR_BasePt.Border.Left = + (42)*gESCPR_DPI_Multiplier; + gESCPR_BasePt.Border.Right = + (42)*gESCPR_DPI_Multiplier; + + /* BORDERLESS */ + gESCPR_BasePt.Borderless.Top = + (-42)*gESCPR_DPI_Multiplier; + gESCPR_BasePt.Borderless.Bottom = + (-70)*gESCPR_DPI_Multiplier; + + if (PaperWidth < PAPERWIDTH_A3) { + gESCPR_BasePt.Borderless.Left = + (-36)*gESCPR_DPI_Multiplier; + gESCPR_BasePt.Borderless.Right = + (-36)*gESCPR_DPI_Multiplier; + + } else { + gESCPR_BasePt.Borderless.Left = + (-48)*gESCPR_DPI_Multiplier; + gESCPR_BasePt.Borderless.Right = + (-48)*gESCPR_DPI_Multiplier; + } +#if defined(_ZERO_MARGIN_REPLICATE) || defined(_ZERO_MARGIN_MIRROR) + /* PAD */ + gESCPR_BasePt.Pad.Top = + (-1)*gESCPR_BasePt.Borderless.Top; + gESCPR_BasePt.Pad.Bottom = + (-1)*gESCPR_BasePt.Borderless.Bottom; + gESCPR_BasePt.Pad.Left = + (-1)*gESCPR_BasePt.Borderless.Left; + gESCPR_BasePt.Pad.Right = + (-1)*gESCPR_BasePt.Borderless.Right; +#endif +} diff --git a/lib/escpr_cmd.h b/lib/escpr_cmd.h new file mode 100644 index 0000000..5fcc21a --- /dev/null +++ b/lib/escpr_cmd.h @@ -0,0 +1,140 @@ +/*********************************************************************** + * + * Copyright (c) 2005-2008 Seiko Epson Corporation. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * File Name: escpr_cmd.h + * + ***********************************************************************/ + +#ifndef __EPSON_ESCPR_CMD_H__ +#define __EPSON_ESCPR_CMD_H__ + +#include "escpr_def.h" + +#define ESCPR_HEADER_LENG 10 +#define ESCPR_PRTQLTY_PARAMBLC_LENG 9 +#define ESCPR_PRTJOB_PARAMBLC_LENG 22 +#define ESCPR_SENDDATA_PARAMBLC_LENG 7 +#define REMOTE_HEADER_LENGTH 5 + + +/*#define ESCPR_PACKET_4KB*/ /* Set packet size to 4096byte */ + +#ifdef ESCPR_PACKET_4KB +#define ESCPR_PACKET_SIZE_4KB 4090 +#endif + +ESCPR_ERR_CODE ESCPR_MakeHeaderCmd(void); +ESCPR_ERR_CODE ESCPR_MakePrintQualityCmd(const ESCPR_PRINT_QUALITY *pPrintQuality); +ESCPR_ERR_CODE ESCPR_MakePrintJobCmd(const ESCPR_PRINT_JOB *pPrintJob); +ESCPR_ERR_CODE ESCPR_MakeStartPageCmd(void); +ESCPR_ERR_CODE ESCPR_MakeImageData(const ESCPR_BANDBMP *pInBmp, ESCPR_RECT *pBandRec); +ESCPR_ERR_CODE ESCPR_MakeEndPageCmd(const ESCPR_UBYTE1 NextPage); +ESCPR_ERR_CODE ESCPR_MakeEndJobCmd(void); +ESCPR_ERR_CODE ESCPR_MakeOneRasterData(const ESCPR_BANDBMP *pInBmp, ESCPR_RECT *pBandRec); +ESCPR_ERR_CODE ESCPR_RasterFilter(const ESCPR_BANDBMP *pInBmp, ESCPR_RECT *pBandRec); + +BOOL ESCPR_SetBigEndian_BYTE2(ESCPR_UBYTE2 value, ESCPR_UBYTE1 array[2]); +BOOL ESCPR_SetBigEndian_BYTE4(ESCPR_UBYTE4 value, ESCPR_UBYTE1 array[4]); +BOOL ESCPR_SetLittleEndian_BYTE4(ESCPR_UBYTE4 value, ESCPR_UBYTE1 array[4]); + +ESCPR_ERR_CODE ESCPR_AdjustBasePoint(ESCPR_PRINT_JOB* pPrintJob); + +ESCPR_ENDIAN ESCPR_CPU_Endian(void); + +#if defined(_ZERO_MARGIN_MIRROR) || defined (_ZERO_MARGIN_REPLICATE) + +/** + * Calculate the left & right padding, and the size of the user's raster. + * + * pBandRec I/O Rectangle for the input. Will be changed to include Padding. + * NumPadRight Output The amount of padding needed on the right. + * NumPadLeft Output The amount of padding needed on the left. + * RasterPixelSize Output The size of the user's data (not including padding). + */ +ESCPR_ERR_CODE ESCPR_CalculatePadding(ESCPR_RECT *pBandRec,ESCPR_BYTE2* NumPadLeft, + ESCPR_BYTE2* NumPadRight, ESCPR_UBYTE2* RasterPixelSize); +#endif /* defined(_ZERO_MARGIN_MIRROR) || defined (_ZERO_MARGIN_REPLICATE) */ + +#if defined(_ZERO_MARGIN_REPLICATE) +/** + * Transform the band data into the replicated band data. + * + * pInBmp Input Band data. + * pBandRec I/O Rectangle for pInBmp on input. Rectangle for pOutBmp on output. + * Band should be 1 raster only. + * repCount Output Number of times the band should be repeated. pBandRec has + * cordinates for the first band. The other (repeated) bands + * should adjust the rectangle accordingly. + * pOutBmp Output (Do not allocate memory). Pointer to band data. + * TempBuffer Input Temporary buffer that should be + * gESCPR_bpp*gESCPR_PrintableAreaWidth wide. pOutBmp may (but not + * necessarily) point to this. + */ +ESCPR_ERR_CODE ESCPR_RasterFilterReplicate(const ESCPR_BANDBMP* pInBmp, + ESCPR_RECT *pBandRec, ESCPR_BYTE4* repCount, ESCPR_BANDBMP* pOutBmp, + ESCPR_UBYTE1* TempBuffer); +#endif + +#if defined(_ZERO_MARGIN_MIRROR) +/** + * Transform the band data into the mirrored band data. + * + * pInBmp Input Band data. + * pBandRec I/O Rectangle for pInBmp on input. Rectangle for pOutBmp on output. + * Band should be 1 raster only. + * repCount Output Will be 1 or 0. + * 0 means discard output of this function (band was saved in memory). + * 1 means send pOutBmp to printer. + * pOutBmp Output (Do not allocate memory). Pointer to band data. + * TempBuffer Input Temporary buffer that should be + * gESCPR_bpp*gESCPR_PrintableAreaWidth wide. pOutBmp may (but not + * necessarily) point to this. + */ +ESCPR_ERR_CODE ESCPR_RasterFilterMirror(const ESCPR_BANDBMP* pInBmp, ESCPR_RECT *pBandRec, + ESCPR_BYTE4* repCount, ESCPR_BANDBMP* pOutBmp,ESCPR_UBYTE1* TempBuffer); + +/** + * Create a rectangle for the top mirrored area of the image, as well as the top + * area where the mirrored area was created from. i.e. Create a rectangle for + * the region 0 to 2*ESCPR_PAD_TOP. + * + * pBandRec Output Filled with dimensions for rectangle. + * pOutBmp Output Point to band data. + */ +ESCPR_ERR_CODE ESCPR_MakeMirrorImageTop(ESCPR_RECT* pBandRec,ESCPR_BANDBMP* pOutBmp); + +/** + * Create a rectangle for the bottom mirrored area of the image. If PrintLastRaster is + * TRUE, the last raster of the original data is also included in the rectangle. If + * PrintLastRaster is FALSE, only the mirrored area is included. + * + * pBandRec Output Filled with dimensions for rectangle. + * pOutBmp Output Point to band data. + * PrintLastRaster Input Whether to include the last raster of the original data. + */ +ESCPR_ERR_CODE ESCPR_MakeMirrorImageBottom(ESCPR_RECT* pBandRec,ESCPR_BANDBMP* pOutBmp, + const BOOL PrintLastRaster); + +/** + * Send the top mirrored area. Uses the data stored in gESCPR_DupBufferTop. Sets + * the global flag gESCPR_TopFlushed to TRUE. + */ +ESCPR_ERR_CODE ESCPR_MakeImageFlushTop(void); +#endif + +#endif diff --git a/lib/escpr_def.h b/lib/escpr_def.h new file mode 100644 index 0000000..bdfa9f9 --- /dev/null +++ b/lib/escpr_def.h @@ -0,0 +1,216 @@ +/*********************************************************************** + * + * Copyright (c) 2005 Seiko Epson Corporation. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * File Name: escpr_def.h + * + ***********************************************************************/ + +#ifndef __EPSON_ESCPR_DEF_H__ +#define __EPSON_ESCPR_DEF_H__ + +#include "escpr_osdep.h" + +/*=======================================================================================*/ +/* typedef */ +/*=======================================================================================*/ + +typedef ESCPR_BYTE4 (* ESCPR_FPSPOOLFUNC)(void* hParam, + const ESCPR_UBYTE1* pBuf, ESCPR_UBYTE4 cbBuf); + +typedef ESCPR_BYTE4 ESCPR_ERR_CODE; + +typedef enum _ESCPR_ENDIAN { + ESCPR_ENDIAN_NOT_TESTED = 0, + ESCPR_ENDIAN_BIG, + ESCPR_ENDIAN_LITTLE +} ESCPR_ENDIAN; + +/*=======================================================================================*/ +/* struct */ +/*=======================================================================================*/ + +typedef struct tagESCPR_RECT{ + ESCPR_BYTE4 left; + ESCPR_BYTE4 top; + ESCPR_BYTE4 right; + ESCPR_BYTE4 bottom; +}ESCPR_RECT; + +typedef struct tagESCPR_BANDBMP{ + ESCPR_UBYTE4 WidthBytes; /* number of bytes in each scan line */ + ESCPR_UBYTE1* Bits; /* pointer to the the bit values for the bitmap */ +}ESCPR_BANDBMP; + +typedef struct tagESCPR_OPT{ + ESCPR_BYTE4 nPrnID; /* Printer ID */ + ESCPR_FPSPOOLFUNC fpspoolfunc; /* pointer to spool function */ +}ESCPR_OPT; + + +/*----- Set Print Quality -----*/ +typedef struct tagESCPR_PRINT_QUALITY{ + ESCPR_UBYTE1 MediaTypeID; + ESCPR_UBYTE1 PrintQuality; + ESCPR_UBYTE1 ColorMono; + ESCPR_BYTE1 Brightness; + ESCPR_BYTE1 Contrast; + ESCPR_BYTE1 Saturation; + ESCPR_UBYTE1 ColorPlane; + ESCPR_UBYTE2 PaletteSize; + ESCPR_UBYTE1* PaletteData; +}ESCPR_PRINT_QUALITY; + +/*----- Set Print Job -----*/ +typedef struct tagESCPR_PRINT_JOB{ + ESCPR_UBYTE4 PaperWidth; + ESCPR_UBYTE4 PaperLength; + ESCPR_BYTE2 TopMargin; + ESCPR_BYTE2 LeftMargin; + ESCPR_UBYTE4 PrintableAreaWidth; + ESCPR_UBYTE4 PrintableAreaLength; + ESCPR_UBYTE1 InResolution; + ESCPR_UBYTE1 PrintDirection; +}ESCPR_PRINT_JOB; + +typedef enum tagESCPR_STATUS{ + ESCPR_STATUS_NOT_INITIALIZED, + ESCPR_STATUS_INITIALIZED +}ESCPR_STATUS; + +typedef struct { + ESCPR_FPSPOOLFUNC gfpSendData; /* A function pointer for send data function */ +} ESCPR_GLOBALFUNC; + + +/*=======================================================================================*/ +/* define */ +/*=======================================================================================*/ + +/*=======================================================================================*/ +/* Media Information of Control Command "MI" */ +/*=======================================================================================*/ +/* Media Types */ +#define ESCPR_MTID_PLAIN 0 +#define ESCPR_MTID_360INKJET 1 +#define ESCPR_MTID_IRON 2 +#define ESCPR_MTID_PHOTOINKJET 3 +#define ESCPR_MTID_PHOTOADSHEET 4 +#define ESCPR_MTID_MATTE 5 +#define ESCPR_MTID_PHOTO 6 +#define ESCPR_MTID_PHOTOFILM 7 +#define ESCPR_MTID_MINIPHOTO 8 +#define ESCPR_MTID_OHP 9 +#define ESCPR_MTID_BACKLIGHT 10 +#define ESCPR_MTID_PGPHOTO 11 +#define ESCPR_MTID_PSPHOTO 12 +#define ESCPR_MTID_PLPHOTO 13 +#define ESCPR_MTID_MCGLOSSY 14 +#define ESCPR_MTID_ARCHMATTE 15 +#define ESCPR_MTID_WATERCOLOR 16 +#define ESCPR_MTID_PROGLOSS 17 +#define ESCPR_MTID_MATTEBOARD 18 +#define ESCPR_MTID_PHOTOGLOSS 19 +#define ESCPR_MTID_SEMIPROOF 20 +#define ESCPR_MTID_SUPERFINE2 21 +#define ESCPR_MTID_DSMATTE 22 +#define ESCPR_MTID_CLPHOTO 23 +#define ESCPR_MTID_ECOPHOTO 24 +#define ESCPR_MTID_VELVETFINEART 25 +#define ESCPR_MTID_PROOFSEMI 26 +#define ESCPR_MTID_HAGAKIRECL 27 +#define ESCPR_MTID_HAGAKIINKJET 28 +#define ESCPR_MTID_PHOTOINKJET2 29 +#define ESCPR_MTID_DURABRITE 30 +#define ESCPR_MTID_MATTEMEISHI 31 +#define ESCPR_MTID_HAGAKIATENA 32 +#define ESCPR_MTID_PHOTOALBUM 33 +#define ESCPR_MTID_PHOTOSTAND 34 +#define ESCPR_MTID_RCB 35 +#define ESCPR_MTID_PGPHOTOEG 36 +#define ESCPR_MTID_ENVELOPE 37 +#define ESCPR_MTID_PLATINA 38 +#define ESCPR_MTID_ULTRASMOOTH 39 +#define ESCPR_MTID_CDDVD 91 +#define ESCPR_MTID_CDDVDHIGH 92 +#define ESCPR_MTID_CLEANING 99 + +/*=======================================================================================*/ +/* Definition of Parameter for Print Quality */ +/*=======================================================================================*/ +/* PrintQuality */ +#define ESCPR_PQ_DRAFT 0 /* Draft */ +#define ESCPR_PQ_NORMAL 1 /* Normal */ +#define ESCPR_PQ_HIGH 2 /* High */ + +/* ColorMono */ +#define ESCPR_CM_COLOR 0 /* Color */ +#define ESCPR_CM_MONOCHROME 1 /* Monochrome */ + +/* Brightness */ +#define ESCPR_BRIGHT_DEF 0 /* Default */ + +/* Contrast */ +#define ESCPR_CONT_DEF 0 /* Default */ + +/* Saturation */ +#define ESCPR_SATU_DEF 0 /* Default */ + +/* ColorPlane */ +#define ESCPR_CP_FULLCOLOR 0 /* Full Color */ +#define ESCPR_CP_256COLOR 1 /* 256 Color */ + +/*=======================================================================================*/ +/* Definition of Parameter for Print Job */ +/*=======================================================================================*/ +/* InResolution */ +#define ESCPR_IR_3636 0 /* 360 x 360 dpi */ +#define ESCPR_IR_7272 1 /* 720 x 720 dpi */ + +/* PrintDirection */ +#define ESCPR_PD_BIDIREC 0 /* Bi-direction */ +#define ESCPR_PD_UNIDIREC 1 /* Uni-direction */ + +/*=======================================================================================*/ +/* Definition of Send Data */ +/*=======================================================================================*/ +/* CompMode */ +#define ESCPR_COMP_NO 0 /* Non compression */ +#define ESCPR_COMP_DONE 1 /* Runlength compression */ + +/*=======================================================================================*/ +/* Definition of End Page */ +/*=======================================================================================*/ +#define ESCPR_END_PAGE 0 /* There is no next page */ +#define ESCPR_NEXT_PAGE 1 /* There is a next page */ + +/*=======================================================================================*/ +/* Definition of Error Code */ +/*=======================================================================================*/ +#define ESCPR_ERR_NOERROR 0 /* terminated normally */ +#define ESCPR_ERR_NOT_SUPPORT -1 /* parameter aren't be supported. */ +#define ESCPR_ERR_DON_T_PROCESS -2 /* on don't process this situation. */ +#define ESCPR_ERR_CAN_T_FREE_HANDLE -3 /* can't free handle. */ +#define ESCPR_ERR_CAN_T_ALLOC_MEMORY -4 /* can't allocate needed memory. */ +#define ESCPR_ERR_HAPPEN_PROBLEM -10 /* happened any error. */ +#define ESCPR_ERR_NOINBMP -20 /* doesn't get an input bitmap. */ +#define ESCPR_ERR_NOATBMP -21 /* doesn't get an attribute bitmap. */ +#define ESCPR_ERR_CAN_T_LOAD_DLL -30 /* can't load DLL */ +#define ESCPR_ERR_SPOOL_IO -40 /* error with spooling i/o function */ + +#endif + diff --git a/lib/escpr_osdep.c b/lib/escpr_osdep.c new file mode 100644 index 0000000..497e18f --- /dev/null +++ b/lib/escpr_osdep.c @@ -0,0 +1,77 @@ +/*********************************************************************** + * + * Copyright (c) 2005-2008 Seiko Epson Corporation. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * File Name: escpr_osdep.c + * + ***********************************************************************/ + +#include <malloc.h> +#include <string.h> +#include <time.h> + +#include "escpr_osdep.h" + +void ESCPR_Mem_Set(void *Dest, ESCPR_BYTE4 c, size_t Size) +{ + memset(Dest, c, Size); +} + +void ESCPR_Mem_Copy(void *Dest, const void *Src, size_t Size) +{ + memcpy(Dest, Src, Size); +} + +void* ESCPR_Mem_Alloc(size_t MemSize) +{ + void *pdummy; + + if(MemSize==0) + return NULL; + else { + pdummy = malloc( MemSize ); + if( pdummy == NULL ) + return pdummy; + ESCPR_Mem_Set( pdummy, 0, MemSize); + return pdummy; + } +} + +void ESCPR_Mem_Free(void *MemPtr) +{ + free(MemPtr); +} + +BOOL ESCPR_Mem_Compare(const void *s1, const void *s2, size_t n) { + return memcmp(s1,s2,n); +} + +void ESCPR_GetLocalTime(ESCPR_LOCAL_TIME *epsTime) +{ + time_t now; + struct tm *t; + + now = time(NULL); + t = localtime(&now); + + epsTime->year = (ESCPR_UBYTE2)t->tm_year; + epsTime->mon = (ESCPR_UBYTE1)t->tm_mon; + epsTime->day = (ESCPR_UBYTE1)t->tm_mday; + epsTime->hour = (ESCPR_UBYTE1)t->tm_hour; + epsTime->min = (ESCPR_UBYTE1)t->tm_min; + epsTime->sec = (ESCPR_UBYTE1)t->tm_sec; +} diff --git a/lib/escpr_osdep.h b/lib/escpr_osdep.h new file mode 100644 index 0000000..100dcdd --- /dev/null +++ b/lib/escpr_osdep.h @@ -0,0 +1,74 @@ +/*********************************************************************** + * + * Copyright (c) 2005-2008 Seiko Epson Corporation. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * File Name: escpr_osdep.h + * + ***********************************************************************/ + +#ifndef __EPSON_ESCPR_OSDEP_H__ +#define __EPSON_ESCPR_OSDEP_H__ + +#include <stddef.h> + +/*=======================================================================================*/ +/* typedef Area */ +/*=======================================================================================*/ +typedef unsigned char ESCPR_UBYTE1; +typedef unsigned short ESCPR_UBYTE2; +typedef unsigned int ESCPR_UBYTE4; + +typedef char ESCPR_BYTE1; +typedef short ESCPR_BYTE2; +typedef int ESCPR_BYTE4; + +/* Local time */ +typedef struct _tagESCPR_LOCAL_TIME_ { + ESCPR_UBYTE2 year; + ESCPR_UBYTE1 mon; + ESCPR_UBYTE1 day; + ESCPR_UBYTE1 hour; + ESCPR_UBYTE1 min; + ESCPR_UBYTE1 sec; +}ESCPR_LOCAL_TIME; + +/*=======================================================================================*/ +/* Define Area */ +/*=======================================================================================*/ +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef BOOL +#define BOOL int +#endif + +/*=======================================================================================*/ +/* Global Functions */ +/*=======================================================================================*/ +void ESCPR_Mem_Set(void* Dest, ESCPR_BYTE4 c, size_t Size); +void ESCPR_Mem_Copy(void* Dest, const void* Src, size_t Size); +void* ESCPR_Mem_Alloc(size_t MemSize); +void ESCPR_Mem_Free(void* MemPtr); +BOOL ESCPR_Mem_Compare(const void *s1, const void *s2, size_t n); +void ESCPR_GetLocalTime(ESCPR_LOCAL_TIME *epsTime); + +#endif diff --git a/lib/escpr_rle.c b/lib/escpr_rle.c new file mode 100644 index 0000000..638a191 --- /dev/null +++ b/lib/escpr_rle.c @@ -0,0 +1,133 @@ +/*********************************************************************** + * + * Copyright (c) 2005 Seiko Epson Corporation. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * File Name: escpr_rle.c + * + ***********************************************************************/ + +/************************************************************************/ +/* Function : The library of runlength compression */ +/************************************************************************/ +#include "escpr_rle.h" +#include "escpr_osdep.h" + +#include <stdio.h> +/************************************************************************/ +/* Function */ +/* runlength compression for RGB */ +/* Name */ +/* RunLengthEncode */ +/* Options */ +/* ESCPR_UBYTE1 *pSrcStartAddr : An address of original raster */ +/* ESCPR_UBYTE1 *pDstStartAddr : An address of compressed raster */ +/* ESCPR_BYTE4 pixel : original raster size */ +/* ESCPR_BYTE4 pCompress : compression flg */ +/* ESCPR_BYTE4 bpp : bits per pixel */ +/* (3) for full color */ +/* (1) for 256 */ +/* done compression : 1 */ +/* undone compressing : 0 */ +/* Return value */ +/* ESCPR_BYTE4 : compressed data size (byte) */ +/************************************************************************/ +ESCPR_BYTE4 ESCPR_RunLengthEncode(const ESCPR_UBYTE1 *pSrcAddr, + ESCPR_UBYTE1 *pDstAddr, ESCPR_BYTE2 pixel, ESCPR_BYTE1 bpp, ESCPR_UBYTE1 *pCompress) +{ + ESCPR_BYTE4 srcCnt = 0; /* counter */ + ESCPR_BYTE4 repCnt = 0; /* replay conter */ + ESCPR_BYTE4 retCnt = 0; /* conpressed data size */ + + *pCompress = 1; + + while (srcCnt < pixel) { + /* In case of replay data */ + if (((srcCnt + 1 < pixel) + && (!ESCPR_Mem_Compare(pSrcAddr, + pSrcAddr + bpp, bpp)))) { + repCnt = 2; + while ((srcCnt + repCnt < pixel) && (repCnt < 0x81) + && (!ESCPR_Mem_Compare(pSrcAddr + (repCnt - 1) * bpp, + pSrcAddr + repCnt * bpp, bpp))) { + repCnt++; + } + + /* Set replay count and data */ + /* Set data counter */ + *pDstAddr++ = (ESCPR_UBYTE1)(0xFF - repCnt + 2 ); + + /* Set data */ + ESCPR_Mem_Copy(pDstAddr, pSrcAddr, bpp); + + /* Renewal data size counter */ + srcCnt += repCnt; + + /* Renewal compressed data size counter */ + retCnt += 1 + bpp; + + /* Renewal original data address */ + pSrcAddr += bpp * repCnt; + + /* Renewal compressed data address */ + pDstAddr += bpp; + } + + /* In case of non replay data */ + else { + ESCPR_BYTE4 copySize; + repCnt = 1; + + /* compare next data with next and next data */ + while ((srcCnt + repCnt + 1< pixel) + && (repCnt < 0x80) + && (ESCPR_Mem_Compare(pSrcAddr + repCnt * bpp, + pSrcAddr + (repCnt + 1) * bpp, bpp)) ){ + repCnt++; + } + + /* Renewal compressed data size counter */ + retCnt += 1 + repCnt * bpp; + + /* Set data counter */ + *pDstAddr++ = (ESCPR_UBYTE1)(repCnt - 1); + + /* Renewal data size counter */ + + /* Size of non replay data (byte) */ + srcCnt += repCnt; + copySize = repCnt * bpp; + + /* Set data */ + ESCPR_Mem_Copy(pDstAddr, pSrcAddr, copySize); + + /* Renewal original data address */ + pSrcAddr += copySize; + + /* Renewal compressed data address */ + pDstAddr += copySize; + } + + /* If compressed data size is bigger than original data size */ + /* stop compression process. */ + if(retCnt > pixel*bpp){ + *pCompress = 0; + break; + } + } + return(retCnt); +} + diff --git a/lib/escpr_rle.h b/lib/escpr_rle.h new file mode 100644 index 0000000..31a8c2c --- /dev/null +++ b/lib/escpr_rle.h @@ -0,0 +1,31 @@ +/*********************************************************************** + * + * Copyright (c) 2005 Seiko Epson Corporation. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * File Name: escpr_rle.h + * + ***********************************************************************/ + +#ifndef __EPSON_ESCPR_RLE_H__ +#define __EPSON_ESCPR_RLE_H__ + +#include "escpr_osdep.h" + +ESCPR_BYTE4 ESCPR_RunLengthEncode(const ESCPR_UBYTE1 *pSrcAddr, ESCPR_UBYTE1 *pDstAddr, + ESCPR_BYTE2 pixel, ESCPR_BYTE1 bpp, ESCPR_UBYTE1 *pCompress); + +#endif diff --git a/lib/escpr_sp.c b/lib/escpr_sp.c new file mode 100644 index 0000000..c60a53d --- /dev/null +++ b/lib/escpr_sp.c @@ -0,0 +1,1232 @@ +/*********************************************************************** + * + * Copyright (c) 2005 Seiko Epson Corporation. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * File Name: escpr_sp.c + * + ***********************************************************************/ + +#include "escpr_sp.h" + +/*=======================================================================================*/ +/* Debug */ +/*=======================================================================================*/ +/*#define _ESCPR_DEBUG_SP*/ +/*#define _ESCPR_DEBUG_SP_VERBOSE*/ + +#ifdef _ESCPR_DEBUG_SP +#include <stdio.h> +#define dbprint(a) printf a +#else +#define dbprint(a) +#endif + +#ifdef _ESCPR_DEBUG_SP +typedef enum _DUMP_TYPE { + DUMP_HEX = 0, + DUMP_ASCII, + DUMP_S_TAG_ONLY, +} DUMP_TYPE; + +char* str[] ={ + "DUMP_HEX", + "DUMP_ASCII", + "DUMP_S_TAG_ONLY", + }; + +static void print_PMREPLY(ESCPR_UBYTE1 * pm, DUMP_TYPE type, ESCPR_BYTE1* msg) +{ + ESCPR_UBYTE1 * p = pm; + ESCPR_BYTE2 col = 0; + + if(*p != 'S') { + if(type != DUMP_HEX) { + return; /* do not anything */ + } + + /* Anyway if type is DUMP_HEX then dump it */ + } + + dbprint(("%s\n", msg)); + dbprint(("PM REPLY DUMP [TYPE:%s]\n", str[type])); + + if(type == DUMP_HEX) { + while(!((*p == 0x0D) && (*(p+1) == 0x0A))) { + dbprint(("0x%02X ", *p++)); + + if((++col % 10) == 0) { + dbprint(("\n")); + } + } + + } else { + while(*p == 'S') { + dbprint(("%c ", *p++)); + dbprint(("%02d\n", *p++)); + while(*p == 'T') { + dbprint((" %c", *p++)); + dbprint((" %02d", *p++)); + dbprint((" [0x%02X]", *p++)); + dbprint((" %c\n", *p++)); + } + dbprint(("%c\n", *p++)); + + if(type == DUMP_S_TAG_ONLY) { + break; + } + + if ((*p == 0x0D) && (*(p+1) == 0x0A)) { + break; + } + } + + } + + if(type != DUMP_S_TAG_ONLY) { + dbprint(("0x%02X ", *p++)); + dbprint(("0x%02X ", *p)); + } + + dbprint(("\nEND\n")); + +} +#endif + +#ifdef _ESCPR_DEBUG_SP +#define DUMP_PMREPLY(a) print_PMREPLY a +#else +#define DUMP_PMREPLY(a) +#endif + +#ifdef _ESCPR_DEBUG_SP_VERBOSE +#define VERBOSE_DUMP_PMREPLY(a) print_PMREPLY a +#define verbose_dbprint(a) dbprint(a) +#else +#define VERBOSE_DUMP_PMREPLY(a) +#define verbose_dbprint(a) +#endif + +/*=======================================================================================*/ +/* Define Area */ +/*=======================================================================================*/ + +/* PM infomation to be retain in Service Pack module */ +#define PM_HEADER_LEN 9 +#define PM_TERMINATOR_LEN 2 +#define PM_MAX_SIZE 512 + +typedef enum PM_STATE { + PM_STATE_NOT_FILTERED = 0, + PM_STATE_FILTERED +} PM_STATE; + +typedef struct _tagESCPR_MODEL_INFO { + PM_STATE state; + ESCPR_UBYTE1 data[PM_MAX_SIZE]; +} ESCPR_MODEL_INFO; + +/* Service Pack ChangeSpec function prototype */ +typedef ESCPR_BYTE4 (* ESCPR_PFNSP)(void *, void *, void*, void*); + +/* Each one do to fix 'Known Issue' about ESC/P-R printer */ +static ESCPR_BYTE4 _SP_ChangeSpec_UpdatePMReply(void*, void*, void*, void*); +static ESCPR_BYTE4 _SP_ChangeSpec_720DPI(void* , void*, void*,void*); +static ESCPR_BYTE4 _SP_ChangeSpec_CompositeBlack(void*, void*, void*, void*); +static ESCPR_BYTE4 _SP_ChangeSpec_DraftOnly(void*, void*, void*, void*); + +/* Functions should be ordered in the same index with SP_REQ_CODE */ +ESCPR_PFNSP fpChangeSpec [] = { + _SP_ChangeSpec_UpdatePMReply, /* SP_REQ_FIX_UPDATE_PMREPLY */ + _SP_ChangeSpec_720DPI, /* SP_REQ_FIX_720DPI */ + _SP_ChangeSpec_CompositeBlack, /* SP_REQ_FIX_COMPOSITE_BLACK */ + _SP_ChangeSpec_DraftOnly /* SP_REQ_FIX_DRAFTONLY */ + }; + +/* Support media size id */ +#define PM_MSID_A4 0x00 +#define PM_MSID_LETTER 0x01 +#define PM_MSID_LEGAL 0x02 +#define PM_MSID_A5 0x03 +#define PM_MSID_A6 0x04 +#define PM_MSID_B5 0x05 +#define PM_MSID_EXECUTIVE 0x06 +#define PM_MSID_HALFLETTER 0x07 +#define PM_MSID_PANORAMIC 0x08 +#define PM_MSID_TRIM_4X6 0x09 +#define PM_MSID_4X6 0x0A +#define PM_MSID_5X8 0x0B +#define PM_MSID_8X10 0x0C +#define PM_MSID_10X15 0x0D +#define PM_MSID_200X300 0x0E +#define PM_MSID_L 0x0F +#define PM_MSID_POSTCARD 0x10 +#define PM_MSID_DBLPOSTCARD 0x11 +#define PM_MSID_ENV_10_L 0x12 +#define PM_MSID_ENV_C6_L 0x13 +#define PM_MSID_ENV_DL_L 0x14 +#define PM_MSID_NEWEVN_L 0x15 +#define PM_MSID_CHOKEI_3 0x16 +#define PM_MSID_CHOKEI_4 0x17 +#define PM_MSID_YOKEI_1 0x18 +#define PM_MSID_YOKEI_2 0x19 +#define PM_MSID_YOKEI_3 0x1A +#define PM_MSID_YOKEI_4 0x1B +#define PM_MSID_2L 0x1C +#define PM_MSID_ENV_10_P 0x1D +#define PM_MSID_ENV_C6_P 0x1E +#define PM_MSID_ENV_DL_P 0x1F +#define PM_MSID_NEWENV_P 0x20 +#define PM_MSID_MEISHI 0x21 +#define PM_MSID_BUZCARD_89X50 0x22 +#define PM_MSID_CARD_54X86 0x23 +#define PM_MSID_BUZCARD_55X91 0x24 +#define PM_MSID_ALBUM_L 0x25 +#define PM_MSID_ALBUM_A5 0x26 +#define PM_MSID_PALBUM_L_L 0x27 +#define PM_MSID_PALBUM_2L 0x28 +#define PM_MSID_PALBUM_A5_L 0x29 +#define PM_MSID_PALBUM_A4 0x2A +#define PM_MSID_A3NOBI 0x3D +#define PM_MSID_A3 0x3E +#define PM_MSID_B4 0x3F +#define PM_MSID_USB 0x40 +#define PM_MSID_11X14 0x41 +#define PM_MSID_B3 0x42 +#define PM_MSID_A2 0x43 +#define PM_MSID_USC 0x44 +#define PM_MSID_USER 0x63 + +/* Support media type id */ +#define PM_MTID_PLAIN 0x00 +#define PM_MTID_360INKJET 0x01 +#define PM_MTID_IRON 0x02 +#define PM_MTID_PHOTOINKJET 0x03 +#define PM_MTID_PHOTOADSHEET 0x04 +#define PM_MTID_MATTE 0x05 +#define PM_MTID_PHOTO 0x06 +#define PM_MTID_PHOTOFILM 0x07 +#define PM_MTID_MINIPHOTO 0x08 +#define PM_MTID_OHP 0x09 +#define PM_MTID_BACKLIGHT 0x0A +#define PM_MTID_PGPHOTO 0x0B +#define PM_MTID_PSPHOTO 0x0C +#define PM_MTID_PLPHOTO 0x0D +#define PM_MTID_MCGLOSSY 0x0E +#define PM_MTID_ARCHMATTE 0x0F +#define PM_MTID_WATERCOLOR 0x10 +#define PM_MTID_PROGLOSS 0x11 +#define PM_MTID_MATTEBOARD 0x12 +#define PM_MTID_PHOTOGLOSS 0x13 +#define PM_MTID_SEMIPROOF 0x14 +#define PM_MTID_SUPERFINE2 0x15 +#define PM_MTID_DSMATTE 0x16 +#define PM_MTID_CLPHOTO 0x17 +#define PM_MTID_ECOPHOTO 0x18 +#define PM_MTID_VELVETFINEART 0x19 +#define PM_MTID_PROOFSEMI 0x1A +#define PM_MTID_HAGAKIRECL 0x1B +#define PM_MTID_HAGAKIINKJET 0x1C +#define PM_MTID_PHOTOINKJET2 0x1D +#define PM_MTID_DURABRITE 0x1E +#define PM_MTID_MATTEMEISHI 0x1F +#define PM_MTID_HAGAKIATENA 0x20 +#define PM_MTID_PHOTOALBUM 0x21 +#define PM_MTID_PHOTOSTAND 0x22 +#define PM_MTID_RCB 0x23 +#define PM_MTID_PGPHOTOEG 0x24 +#define PM_MTID_ENVELOPE 0x25 +#define PM_MTID_PLATINA 0x26 +#define PM_MTID_ULTRASMOOTH 0x27 +/* add Wed Jan 28 2009 v */ +#define PM_MTID_SFHAGAKI 0x28 /* "Super Fine Postcard" */ +#define PM_MTID_PHOTOSTD 0x29 /* "Premium Glossy Photo Paper" */ +#define PM_MTID_GLOSSYHAGAKI 0x2A /* "Glossy Postcard" */ +#define PM_MTID_GLOSSYPHOTO 0x2B /* "Glossy Photo Paper" */ +#define PM_MTID_GLOSSYCAST 0x2C /* "Epson Photo" */ +#define PM_MTID_BUSINESSCOAT 0x2D /* "Business Ink Jet Coat Paper" */ +/* add Wed Jan 28 2009 ^ */ +#define PM_MTID_CDDVD 0x5B +#define PM_MTID_CDDVDHIGH 0x5C +#define PM_MTID_CLEANING 0x63 + +/* Support media size id table */ +static struct _tag_PM_PAPER_SIZE { + ESCPR_UBYTE1 id; /* PM_MTID_xx */ + ESCPR_BYTE4 width; /* pixels for 360 DPI */ + ESCPR_BYTE4 length; /* pixels for 360 DPI */ +} PM_PAPER_SIZE [] = { + /* ID Width Length */ + {PM_MSID_A4, 2976, 4209}, + {PM_MSID_LETTER, 3060, 3960}, + {PM_MSID_LEGAL, 3060, 5040}, + {PM_MSID_A5, 2098, 2976}, + {PM_MSID_A6, 1488, 2098}, + {PM_MSID_B5, 2580, 3643}, + {PM_MSID_EXECUTIVE, 2610, 3780}, + {PM_MSID_HALFLETTER, 1980, 3060}, + {PM_MSID_PANORAMIC, 2976, 8419}, + {PM_MSID_TRIM_4X6, 1610, 2330}, + {PM_MSID_4X6, 1440, 2160}, + {PM_MSID_5X8, 1800, 2880}, + {PM_MSID_8X10, 2880, 3600}, + {PM_MSID_10X15, 1417, 2125}, + {PM_MSID_200X300, 3061, 4790}, + {PM_MSID_L, 1260, 1800}, + {PM_MSID_POSTCARD, 1417, 2098}, + {PM_MSID_DBLPOSTCARD, 2835, 2098}, + {PM_MSID_ENV_10_L, 3420, 1485}, + {PM_MSID_ENV_C6_L, 2296, 1616}, + {PM_MSID_ENV_DL_L, 3118, 1559}, + {PM_MSID_NEWEVN_L, 3118, 1871}, + {PM_MSID_CHOKEI_3, 1701, 3685}, + {PM_MSID_CHOKEI_4, 1276, 3161}, + {PM_MSID_YOKEI_1, 1701, 2494}, + {PM_MSID_YOKEI_2, 1616, 2296}, + {PM_MSID_YOKEI_3, 1389, 2098}, + {PM_MSID_YOKEI_4, 1488, 3331}, + {PM_MSID_2L, 1800, 2522}, + {PM_MSID_ENV_10_P, 1485, 3420}, + {PM_MSID_ENV_C6_P, 1616, 2296}, + {PM_MSID_ENV_DL_P, 1559, 3118}, + {PM_MSID_NEWENV_P, 1871, 3118}, + {PM_MSID_MEISHI, 1261, 779}, + {PM_MSID_BUZCARD_89X50, 1261, 709}, + {PM_MSID_CARD_54X86, 765, 1219}, + {PM_MSID_BUZCARD_55X91, 780, 1290}, + {PM_MSID_ALBUM_L, 1800, 2607}, + {PM_MSID_ALBUM_A5, 2976, 4294}, + {PM_MSID_PALBUM_L_L, 1800, 1260}, + {PM_MSID_PALBUM_2L, 1800, 2521}, + {PM_MSID_PALBUM_A5_L, 2976, 2101}, + {PM_MSID_PALBUM_A4, 2976, 4203}, + {PM_MSID_A3NOBI, 4663, 6846}, + {PM_MSID_A3, 4209, 5953}, + {PM_MSID_B4, 3643, 5159}, + {PM_MSID_USB, 3960, 6120}, + {PM_MSID_11X14, 3960, 5040}, + {PM_MSID_B3, 5159, 7285}, + {PM_MSID_A2, 5953, 8419}, + {PM_MSID_USC, 6120, 7920}, + {PM_MSID_USER, 0, 0}, +}; + +ESCPR_BYTE2 NUM_PAPER_SIZE = sizeof(PM_PAPER_SIZE) / sizeof(PM_PAPER_SIZE[0]); + +/* Support media type id table */ +ESCPR_UBYTE1 PM_TYPE_IDS [] = { + PM_MTID_PLAIN, + PM_MTID_360INKJET, + PM_MTID_IRON, + PM_MTID_PHOTOINKJET, + PM_MTID_PHOTOADSHEET, + PM_MTID_MATTE, + PM_MTID_PHOTO, + PM_MTID_PHOTOFILM, + PM_MTID_MINIPHOTO, + PM_MTID_OHP, + PM_MTID_BACKLIGHT, + PM_MTID_PGPHOTO, + PM_MTID_PSPHOTO, + PM_MTID_PLPHOTO, + PM_MTID_MCGLOSSY, + PM_MTID_ARCHMATTE, + PM_MTID_WATERCOLOR, + PM_MTID_PROGLOSS, + PM_MTID_MATTEBOARD, + PM_MTID_PHOTOGLOSS, + PM_MTID_SEMIPROOF, + PM_MTID_SUPERFINE2, + PM_MTID_DSMATTE, + PM_MTID_CLPHOTO, + PM_MTID_ECOPHOTO, + PM_MTID_VELVETFINEART, + PM_MTID_PROOFSEMI, + PM_MTID_HAGAKIRECL, + PM_MTID_HAGAKIINKJET, + PM_MTID_PHOTOINKJET2, + PM_MTID_DURABRITE, + PM_MTID_MATTEMEISHI, + PM_MTID_HAGAKIATENA, + PM_MTID_PHOTOALBUM, + PM_MTID_PHOTOSTAND, + PM_MTID_RCB, + PM_MTID_PGPHOTOEG, + PM_MTID_ENVELOPE, + PM_MTID_PLATINA, + PM_MTID_ULTRASMOOTH, +/* add Wed Jan 28 2009 v */ + PM_MTID_SFHAGAKI, /* "Super Fine Postcard" */ + PM_MTID_PHOTOSTD, /* "Premium Glossy Photo Paper" */ + PM_MTID_GLOSSYHAGAKI, /* "Glossy Postcard" */ + PM_MTID_GLOSSYPHOTO, /* "Glossy Photo Paper" */ + PM_MTID_GLOSSYCAST, /* "Epson Photo" */ + PM_MTID_BUSINESSCOAT, /* "Business Ink Jet Coat Paper" */ +/* add Wed Jan 28 2009 ^ */ + PM_MTID_CDDVD, + PM_MTID_CDDVDHIGH, + PM_MTID_CLEANING, +}; + +ESCPR_BYTE2 NUM_TYPE_IDS = sizeof(PM_TYPE_IDS) / sizeof(PM_TYPE_IDS[0]); + +/*=======================================================================================*/ +/* Global Area */ +/*=======================================================================================*/ +static ESCPR_MODEL_INFO g_PMinfo; /* Filtered pm info to be retained within ServicePack */ + +/*=======================================================================================*/ +/* Local function definition Area */ +/*=======================================================================================*/ +/* ---------------------------------*/ +/* Local function : _pmFindSfield() */ +/* ---------------------------------*/ +/* Find a 'S' field to match the id in pSrc and save its */ +/* starting('S') and ending pointer('/') to each parameters */ +/* pSrc should be a complete PM REPLY format */ +/* that start with 'S' and terminate at '0x0D 0x0A' */ +/* function return length of found 'S' fields */ +/* or (-1) to indicate no matching field exist */ +static ESCPR_BYTE2 _pmFindSfield(ESCPR_UBYTE1 id, ESCPR_UBYTE1* pSrc, + ESCPR_UBYTE1** pStart, ESCPR_UBYTE1** pEnd) +{ + + while (*pSrc != 0xD || *(pSrc+1) != 0xA) { + + *pStart = NULL; + *pEnd = NULL; + + /* find 'S' */ + while(*pSrc == 'S') { + if(id == *(pSrc+1)) { + *pStart = pSrc; + } + + pSrc += 2; + + while(*pSrc == 'T') { + pSrc += 4; + } + + /* Found id */ + if(*pStart != NULL) { + *pEnd = pSrc; + return (*pEnd - *pStart)+1; + } + + /* next 'S' */ + pSrc++; + } + } + + return (-1); + +} + + +/* ---------------------------------- */ +/* Local function : _pmAppendTfield() */ +/* ---------------------------------- */ +/* Append 'T' field to pDes if same field dose not exsit */ +/* but same one aleady exsits just combine mode properdy */ +/* pDes should have a complete 'S' field consist of 'S' and '/' */ +/* and pT should have a 'T' field of 4 bytes starts with 'T' */ +/* function return increased bytes so that caller change the last pos */ +/* or (-1) to indicate nothing changed */ +static ESCPR_BYTE2 _pmAppendTfield(ESCPR_UBYTE1* pT, ESCPR_UBYTE1* pDes) +{ + ESCPR_UBYTE1 t_id = *(pT+1); + ESCPR_BYTE2 t_exist = 0; + + if(*pDes == 'S') { + + pDes += 2; /* move to first 'T' */ + + while(*pDes == 'T') { + + /* same id exist */ + if(t_id == *(pDes+1)) { + /* Just combine mode property */ + *(pDes+2) |= *(pT+2); + + t_exist = 1; + break; + } + + /* next 'T' */ + pDes += 4; + } + + /* samd id field dose not exist */ + /* Append new 'T' fields */ + if(t_exist == 0) { + ESCPR_Mem_Copy(pDes, pT, 4); + pDes += 4; + *pDes = '/'; + + return 4; /* size of 'T' field */ + } + + /* type id aleady exist then do not anything */ + } + + return (-1); + +} + + +/* -------------------------------- */ +/* Local function : _pmScanTfield() */ +/* -------------------------------- */ +/* find a 'T' field to match the id */ +/* function return the first pos of matched 'T' at the pSfield or NULL */ +static ESCPR_UBYTE1 * _pmScanTfield(ESCPR_UBYTE1 id, ESCPR_UBYTE1* pSfield) +{ + ESCPR_UBYTE1* pScan = pSfield; + ESCPR_UBYTE1* pT = NULL; + + if(*pScan == 'S') { + pScan += 2; + + while(*pScan == 'T') { + if(id == *(pScan+1)) { + pT = pScan; + break; + } + + pScan += 4; + } + } + + return pT; + +} + + +/* ------------------------------------------------ */ +/* Lcoal function : _pmValidateRemoveUnknownSfield() */ +/* ------------------------------------------------ */ +/* Copy valid fields to reply buffer only. */ +/* Remove unknown 'S' field */ +/* Minimum conditons for valid PM REPLY */ +/* - it must have a complete 'S' field more than one ( 'S' ~ '/') */ +/* - it must end with 0xD and 0xA */ +/* function returns the number of valid fields */ +static ESCPR_BYTE2 _pmValidateRemoveUnknownSfield(ESCPR_UBYTE1* pDes, ESCPR_UBYTE1* pSrc) +{ + + ESCPR_UBYTE1* pPrev = NULL; /* save previous pointer */ + ESCPR_UBYTE1* pS = NULL; /* valid field's starting position */ + ESCPR_UBYTE1* pE = NULL; /* valid field's ending postion */ + + ESCPR_BYTE2 valid = 0; /* flag for indicating 'S' field's validation */ + ESCPR_BYTE2 t_cnt = 0; /* count valid 'T' fields */ + ESCPR_BYTE2 s_idx = 0; /* index of PM_PAPER_SIZE */ + + ESCPR_BYTE2 num_valid_fields = 0; /* value for returning */ + +#ifdef _TEST_PM_STEP_1 /* Change first 'S' field's id to unknown id such as 0xFF */ + *(pSrc+1) = 0xFF; +#endif + + while (*pSrc != 0xD || *(pSrc+1) != 0xA) { + pPrev = pSrc; + + pS = NULL; + pE = NULL; + valid = 0; + t_cnt = 0; + s_idx = 0; + + + if(*pSrc == 'S') { + pS = pSrc; + pSrc += 2; + + while(*pSrc == 'T') { + pSrc += 3; + + if(*pSrc == '/') { + pSrc++; + t_cnt++; + } + } + + if(t_cnt && *pSrc == '/') { + pE = pSrc; + } + + } + + /* Copy valid and support 'S' fields only */ + /* Valid means size id should be find in its table */ + /* and 'T' field exist at least more than one */ + /* Unknown 'S' field should be removed */ + if(pS && pE) { + for(s_idx = 0; s_idx < NUM_PAPER_SIZE; s_idx++) { + if(PM_PAPER_SIZE[s_idx].id == *(pS+1)) { + ESCPR_Mem_Copy(pDes, pS, (pE-pS)+1); + pDes += (pE-pS)+1; + valid = 1; + + /* now increase num of valid fields */ + num_valid_fields++; + + break; + } + } + } + + /* Restore work buffer pos to the previous */ + /* cause fail to get a valid fields */ + if(valid == 0) { + pSrc = pPrev; + } + + pSrc++; + } + + *pDes++ = *pSrc++; /* 0xD */ + *pDes++ = *pSrc; /* 0xA */ + + return num_valid_fields; + +} + + +/* ----------------------------------------- */ +/* Local function : _pmCorrectUnknownTfield() */ +/* ----------------------------------------- */ +/* Change a unknown 'T' field to PGPP's in case of */ +/* PGPP dose not exist its 'S' field */ +/* if aleady PGPP exist delete it */ +static void _pmCorrectUnknownTfield(ESCPR_UBYTE1* pDes, ESCPR_UBYTE1* pSrc) +{ + + static const ESCPR_UBYTE1 PGPP_FIELD [ ] = { 0x54, 0x0B, 0x87, 0x2F }; + + ESCPR_BYTE2 PGPP = 0; /* Premium Glossy Photo Paper (type id : 0x0b) */ + ESCPR_BYTE2 t_idx = 0; /* Index of table defined Support 'T' id table */ + ESCPR_UBYTE1 * pScan = NULL; /* word pointer for scanning id */ + +#ifdef _TEST_PM_STEP_2 /* Change 'T' field's id to unknown id such as 0xFF */ + *(pSrc+3) = 0xFF; +#endif + + while (*pSrc != 0xD || *(pSrc+1) != 0xA) { + /* reset PGPP flag each new 'S' field */ + PGPP = 0; + + if(*pSrc == 'S') { + /* Scan PGPP in current 'S' field */ + pScan = pSrc; + + if(_pmScanTfield(PM_MTID_PGPHOTO, pScan) != NULL) { + PGPP = 1; + } + + *pDes++ = *pSrc++; + *pDes++ = *pSrc++; + + while(*pSrc == 'T') { + /* Copy support 'T' field */ + for(t_idx = 0; t_idx < NUM_TYPE_IDS; t_idx++) { + if(PM_TYPE_IDS[t_idx] == *(pSrc+1)) { + ESCPR_Mem_Copy(pDes, pSrc, 4); + pDes += 4; + break; + } + } + + /* Unknown type id encountered */ + /* if PGPP did not exist in 'S' field */ + /* then append PGPP fields to pDes */ + if(t_idx == NUM_TYPE_IDS && PGPP == 0) { + ESCPR_Mem_Copy(pDes, PGPP_FIELD, 4); + pDes += 4; + + PGPP = 1; + } + + /* move to next 'T' */ + pSrc += 4; + } + + /* copy '/' and move next 'S' */ + *pDes++ = *pSrc++; + } + } + + *pDes++ = *pSrc++; /* 0xD */ + *pDes++ = *pSrc; /* 0xA */ + +} + + +/* --------------------------------------------- */ +/* Local function : _pmCorrectDupulicatedFields() */ +/* --------------------------------------------- */ +/* Merge duplicated fields */ +static void _pmCorrectDupulicatedFields(ESCPR_UBYTE1* pDes, ESCPR_UBYTE1* pSrc) +{ +/* MERGED_FIELD only meaning in this function */ +#define MERGED_FIELD 0xFF +/* memcpy macro for readability */ +#define COPY_BYTES(des,src,size) ESCPR_Mem_Copy(des,src,size); des+=size; + + ESCPR_UBYTE1 merged_buf[PM_MAX_SIZE]; + + ESCPR_UBYTE1* pFieldS = NULL; /* current 'S' in merged buffer */ + ESCPR_UBYTE1* pFieldT = NULL; /* work pontter to merge a 'T' */ + ESCPR_UBYTE1* pS = NULL; /* duplicated field's starting position */ + ESCPR_UBYTE1* pE = NULL; /* duplicated field's ending postion */ + ESCPR_UBYTE1* pM = NULL; /* pos of merged buffer */ + ESCPR_UBYTE1* pScan = NULL; /* work pointer to find a field */ + ESCPR_UBYTE1 s_id = (-1); /* current 'S' id */ + ESCPR_BYTE2 bytes; + +#ifdef _TEST_PM_STEP_3 + *(pSrc+8) = 0x0F; /* make duplicate 'S' */ +#endif + + pM = &merged_buf[0]; + + /* Aleady merged fields no need to copy again */ + while (*pSrc != 0xD || *(pSrc+1) != 0xA) { + pFieldS = NULL; + + + if(*pSrc == 'S') { + VERBOSE_DUMP_PMREPLY((pSrc, DUMP_S_TAG_ONLY, "< STEP 3 : SOURCE 'S' ... >")); + + /* save current 'S' id */ + s_id = *(pSrc+1); + + if(s_id != MERGED_FIELD) { + /* Current 'S' field's starting pos */ + /* it is used to merge fields later */ + pFieldS = pM; + + COPY_BYTES(pM, pSrc, 2); + } + + pSrc += 2; /* move to first 'T' */ + + /* Merge 'T' fields */ + while(*pSrc == 'T') { + + if(pFieldS && s_id != MERGED_FIELD) { + /* if 'T' aleady exist just combine its property by BIT OR operation */ + if((pFieldT = _pmScanTfield(*(pSrc+1), pFieldS)) != NULL) { + *(pFieldT+2) |= *(pSrc+2); + } + + /* Copy only new 'T' field */ + if(pFieldT == NULL) { + COPY_BYTES(pM, pSrc, 4); + } + } + + pSrc += 4; /* next 'T' */ + } + } + + if(s_id != MERGED_FIELD) { + COPY_BYTES(pM, pSrc, 1); + } + pSrc++; + + /* aleady merged field just go on next */ + if(s_id == MERGED_FIELD) { + continue; + } + + /*----------------------------------------------------*/ + /* Find dupulicated 'S' being followed and merge them */ + + pScan = pSrc; /* do not change pSrc in following loop */ + + while(_pmFindSfield(s_id, pScan, &pS, &pE) > 0) { + + /* Change source's 'S' id to MERGED_FIELD */ + *(pS+1) = MERGED_FIELD; + pS += 2; + + /* merge dupulicated 'T' */ + while(*pS == 'T') { + + /* Append NEW 'T' field to the current 'S' field */ + /* aleady same 'T' exist only its mode property will be combined */ + /* after called function */ + if(pFieldS) { + if((bytes = _pmAppendTfield(pS, pFieldS)) > 0) { + + /* update merged_buf's the last pos that pM point it */ + pM += bytes; /* MUST 4 BYTES(size of 'T' field) ! */ + } + } + + pS += 4; /* next 'T' */ + } + + /* find next 'S' */ + pScan = (pE+1); + + VERBOSE_DUMP_PMREPLY((pFieldS, DUMP_S_TAG_ONLY, "< STEP 3 : MERGE PROCESSING ... >")); + } + } + + /* 0x0D & 0x0A */ + COPY_BYTES(pM, pSrc, 2); + + /*----------------------------------*/ + /* Copy the merged PM REPLY to pDes */ + + pM = &merged_buf[0]; + + while (*pM != 0xD || *(pM+1) != 0xA) { + *pDes++ = *pM++; + } + + *pDes++ = *pM++; /* 0xD */ + *pDes++ = *pM; /* 0xA */ + +} + + +/* --------------------------------------------- */ +/* Local function : _pmAdjustQuality() */ +/* --------------------------------------------- */ +/* Adjust quality properties to the formal */ +/* example : quality has only draft mode -> turn on normal mode */ +static void _pmAdjustQuality(ESCPR_UBYTE1* pData) +{ + ESCPR_UBYTE1* p = pData; + + /* skip pm heder */ + p += PM_HEADER_LEN; + + verbose_dbprint(("< STEP 4 : Adjust quality >\n")); + + /* adjuct each quality properties */ + while(!(*p == 0x0D && *(p+1) == 0x0A)) { + while(*p == 'S') { + + verbose_dbprint(("%c %02d\n", *p, *(p+1))); + + p += 2; /* move to the first T field */ + + while(*p == 'T') { + + verbose_dbprint(("\t%c %02d 0x%02x %c -> ", *p, *(p+1), *(p+2), *(p+3))); + + p += 2; /* move to quality pos */ + + /* Quality property */ + switch(*p & 0x07) { + /* Should be handled following case 1 bit of Draft turned on only */ + case 0x01: /* 0 0 1 -> 0 1 1 */ + *p |= (1<<1); /* turn normal on */ + break; + default: + break; + } + + verbose_dbprint(("%c %02d 0x%02x %c\n", *(p-2), *(p-1), *(p), *(p+1))); + + p += 2; /* move to the next T field */ + } + + p += 1; /* move to the next S field */ + } + } + +} + + +/*=======================================================================================*/ +/* ESC/P-R Service Pack ChangeSpec Known Issues (only used by ESC/P-R Core module) */ +/*=======================================================================================*/ + +/* Known Issue : 2005/10/14 #1 */ +/*======================================================================================= + SYMPTOMS + CAUSE + RESOLUTION + - Invalid formats : Delete + - Unknown 'S' field : Delete + - Unknown 'T' field : Replace to PGPP-Premium Glossy Photo Paper(id:0x0b) - field + If PGPP aleady exist its 'S' field + then just combine the mode property + - Duplicated 'S' fields : Merge together + - Duplicated 'T' fields : Merge together and combine each mode properties + - Only DRAFT mode exist : Add NORMAL mode to its print quality property + + NOTE : Be sure that the pData is a pointers that a starting address of 512 bytes buffer + should be assigned or memory acces violation should be occured. + + Last Modification : 2005/10/14 + Revision : 1.0 +=======================================================================================*/ +static ESCPR_BYTE4 _SP_ChangeSpec_UpdatePMReply(void* pData, void* pReserved1, void* pReserved2, void* pReserved3) +{ + ESCPR_UBYTE1* pBefore = (ESCPR_UBYTE1*)pData; + ESCPR_UBYTE1* pAfter = NULL; + ESCPR_UBYTE1* pSrc = NULL; + ESCPR_UBYTE1* pDes = NULL; + + static const ESCPR_UBYTE1 PM_REPLY_HEADER[PM_HEADER_LEN] = { + /* @ B D C <SP> P M <CR> <LF> */ + 0x40, 0x42, 0x44, 0x43, 0x20, 0x50, 0x4D, 0x0D, 0x0A + }; + + + ESCPR_BYTE2 i; + + dbprint(("[[ ESC/P-R CHANGE SPEC : Known issue (2005/10/14 #1) ]]\n")); + + /* Check parameters */ + if(pBefore == NULL) { + dbprint(("_SP_ChangeSpec_UpdatePMReply > ESCPR_SP_ERR_PM_INVALID_POINTER\n")); + return (ESCPR_SP_ERR_PM_INVALID_POINTER); + } + + if(ESCPR_Mem_Compare(pBefore, PM_REPLY_HEADER, PM_HEADER_LEN) != 0) { + dbprint(("_SP_ChangeSpec_UpdatePMReply > ESCPR_SP_ERR_PM_INVALID_HEADER\n")); + return (ESCPR_SP_ERR_PM_INVALID_HEADER); + } + + for(i = PM_HEADER_LEN; i <= (PM_MAX_SIZE-PM_TERMINATOR_LEN); i++) { + if(pBefore[i]== 0x0D && pBefore[i+1] == 0x0A) { + break; + } + } + + if(i > (PM_MAX_SIZE-PM_TERMINATOR_LEN)) { + dbprint(("_SP_ChangeSpec_UpdatePMReply > ESCPR_SP_ERR_PM_INVALID_TERMINATOR\n")); + return (ESCPR_SP_ERR_PM_INVALID_TERMINATOR); + } + + /* Initialize g_PMinfo */ + ESCPR_Mem_Set(&g_PMinfo.data[0], 0x00, PM_MAX_SIZE); + ESCPR_Mem_Copy(&g_PMinfo.data[0], PM_REPLY_HEADER, PM_HEADER_LEN); + g_PMinfo.state = PM_STATE_NOT_FILTERED; + + /* Use work pointers to call each filter functions */ + pBefore = (ESCPR_UBYTE1*)pData; + pAfter = &g_PMinfo.data[PM_HEADER_LEN]; + + pSrc = pBefore; + pDes = pAfter; + + /* Correct PM REPLY following 4 steps */ + + /* STEP 1 : Copy only valid fields to reply buffer and remove unknown 'S' from reply */ + pSrc += PM_HEADER_LEN; /* the position of first 'S' field */ + + DUMP_PMREPLY((pSrc, DUMP_HEX, "< ORIGINAL >")); + + if(_pmValidateRemoveUnknownSfield(pDes, pSrc) == 0) { + dbprint(("_SP_ChangeSpec_UpdatePMReply > ESCPR_SP_ERR_PM_NO_VALID_FIELD\n")); + return (ESCPR_SP_ERR_PM_NO_VALID_FIELD); + } + + VERBOSE_DUMP_PMREPLY((pDes, DUMP_ASCII, "< STEP 1 PASSED >")); + + /* STEP 2 : Correct unknown 'T' fields */ + ESCPR_Mem_Set(pBefore, 0x00, PM_MAX_SIZE); + ESCPR_Mem_Copy(pBefore, pDes, PM_MAX_SIZE); + + pSrc = pBefore; + pDes = pAfter; + + _pmCorrectUnknownTfield(pDes, pSrc); + + VERBOSE_DUMP_PMREPLY((pDes, DUMP_ASCII, "< STEP 2 PASSED >")); + + /* STEP 3 : Merge duplicated fields */ + ESCPR_Mem_Set(pBefore, 0x00, PM_MAX_SIZE); + ESCPR_Mem_Copy(pBefore, pDes, PM_MAX_SIZE); + + pSrc = pBefore; + pDes = pAfter; + + _pmCorrectDupulicatedFields(pDes, pSrc); + + VERBOSE_DUMP_PMREPLY((pDes, DUMP_ASCII, "< STEP 3 PASSED >")); + + /* Now, Service Pack retains filtered data its original quality properties */ + /* within the inner buffer g_PMinfo.data */ + /* This data would be referenced whenever it is required to compare its originality */ + DUMP_PMREPLY((&g_PMinfo.data[PM_HEADER_LEN], DUMP_ASCII, \ + "< FILTERED (Retained within SP-same printer's caps) >")); + g_PMinfo.state = PM_STATE_FILTERED; + + /* STEP 4 : Adjust quality properties to the formal in order to return to the driver */ + /* it dose not change the filtered data through previous steps retained within Service Pack */ + /* but just change the buffer asigned as parameter (in this case pData) */ + /* after duplicating the filtered data to it */ + /* See releated Known Issue : 2005/10/14 #4 */ + ESCPR_Mem_Copy(pData, &g_PMinfo.data[0], PM_MAX_SIZE); + _pmAdjustQuality((ESCPR_UBYTE1*)pData); + DUMP_PMREPLY(((ESCPR_UBYTE1*)pData+PM_HEADER_LEN, DUMP_ASCII, \ + "< FILTERED (Returned data to the driver-adjusted quality properties) >")); + + return ESCPR_SP_ERR_NONE; +} + + +/* Known Issue : 2005/10/14 #2 */ +/*======================================================================================= + SYMPTOMS + CAUSE + RESOLUTION + Last Modification : 2005/10/14 + Revision : 1.0 +=======================================================================================*/ +static ESCPR_BYTE4 _SP_ChangeSpec_720DPI(void* pData, void* pReserved1, void* pReserved2, void* pReserved3) +{ + ESCPR_PRINT_JOB* pPrintJob = (ESCPR_PRINT_JOB*)pData; + + dbprint(("[[ ESC/P-R CHANGE SPEC : Known issue (2005/10/14 #2) ]]\n")); + + verbose_dbprint(("pPrintJob->PaperWidth = %d\n", pPrintJob->PaperWidth)); + verbose_dbprint(("pPrintJob->PaperLength = %d\n", pPrintJob->PaperLength)); + verbose_dbprint(("pPrintJob->TopMargin = %d\n", pPrintJob->TopMargin)); + verbose_dbprint(("pPrintJob->LeftMargin = %d\n", pPrintJob->LeftMargin)); + verbose_dbprint(("pPrintJob->PrintableAreaWidth = %d\n", pPrintJob->PrintableAreaWidth)); + verbose_dbprint(("pPrintJob->PrintableAreaLength = %d\n", pPrintJob->PrintableAreaLength)); + verbose_dbprint(("pPrintJob->InResolution = %d\n", pPrintJob->InResolution)); + verbose_dbprint(("pPrintJob->PrintDirection = %d\n", pPrintJob->PrintDirection)); + + /* Support Input Resolution 360x360dpi only */ + if(pPrintJob->InResolution == ESCPR_IR_7272){ + pPrintJob->TopMargin /= 2; + pPrintJob->LeftMargin /= 2; + pPrintJob->PrintableAreaWidth /= 2; + pPrintJob->PrintableAreaLength /= 2; + pPrintJob->InResolution = ESCPR_IR_3636; + + verbose_dbprint((">> ESC/P-R input resolution has been changed to 360x360 from 720x720 dpi\n")); + verbose_dbprint(("pPrintJob->PaperWidth = %d\n", pPrintJob->PaperWidth)); + verbose_dbprint(("pPrintJob->PaperLength = %d\n", pPrintJob->PaperLength)); + verbose_dbprint(("pPrintJob->TopMargin = %d\n", pPrintJob->TopMargin)); + verbose_dbprint(("pPrintJob->LeftMargin = %d\n", pPrintJob->LeftMargin)); + verbose_dbprint(("pPrintJob->PrintableAreaWidth = %d\n", pPrintJob->PrintableAreaWidth)); + verbose_dbprint(("pPrintJob->PrintableAreaLength = %d\n", pPrintJob->PrintableAreaLength)); + verbose_dbprint(("pPrintJob->InResolution = %d\n", pPrintJob->InResolution)); + verbose_dbprint(("pPrintJob->PrintDirection = %d\n", pPrintJob->PrintDirection)); + } + + return ESCPR_SP_ERR_NONE; +} + + +/* Known Issue : 2005/10/14 #3 */ +/*======================================================================================= + SYMPTOMS + CAUSE + RESOLUTION + Last Modification : 2005/10/14 + Revision : 1.0 +=======================================================================================*/ +static ESCPR_BYTE4 _SP_ChangeSpec_CompositeBlack(void* pData, void* pReserved1, void* pReserved2, void* pReserved3) +{ + ESCPR_PRINT_QUALITY* pPrintQuality = (ESCPR_PRINT_QUALITY*)pData; + + dbprint(("[[ ESC/P-R CHANGE SPEC : Known issue (2005/10/14 #3) ]]\n")); + + verbose_dbprint((">> pPrintQuality->ColorMono : %d -> ", pPrintQuality->ColorMono)); + + /* Use the composite black for the monochrome printing */ + if(pPrintQuality->ColorMono == ESCPR_CM_MONOCHROME){ + pPrintQuality->ColorMono = ESCPR_CM_COLOR; + } + + verbose_dbprint(("%d\n", pPrintQuality->ColorMono)); + + return ESCPR_SP_ERR_NONE; +} + + +/* Known Issue : 2005/10/14 #4 */ +/*======================================================================================= + SYMPTOMS + CAUSE + RESOLUTION + Last Modification : 2005/10/14 + Revision : 1.0 +=======================================================================================*/ +static ESCPR_BYTE4 _SP_ChangeSpec_DraftOnly(void* pPrintQuality, void* pPrintJob, + void* pReserved1, void* pReserved2) +{ + +#define Q_DRAFT 0 +#define Q_NORMAL 1 +#define Q_HIGH 2 + + ESCPR_PRINT_QUALITY* pQuality = (ESCPR_PRINT_QUALITY*)pPrintQuality; + ESCPR_PRINT_JOB* pJob = (ESCPR_PRINT_JOB*)pPrintJob; + + ESCPR_BYTE4 width, length; + ESCPR_UBYTE1 s_id = -1; + ESCPR_UBYTE1 t_id = -1; + ESCPR_UBYTE1* pPMinfo = NULL; + ESCPR_UBYTE1* pS_begin = NULL; + ESCPR_UBYTE1* pS_end = NULL; + ESCPR_UBYTE1* pTfield = NULL; + + ESCPR_BYTE2 i; + ESCPR_BYTE1 quality[3]; /* Q_DRAFT / Q_NORMAL / Q_HIGH */ + + dbprint(("[[ ESC/P-R CHANGE SPEC : Known issue (2005/10/14 #4) ]]\n")); + + if(g_PMinfo.state != PM_STATE_FILTERED) { + dbprint(("ChangeSpec_DraftOnly : PM info not initialized\n")); + /* it is not able to hadle this situation so do nothing */ + return ESCPR_SP_ERR_NONE; + } + + if(!(pQuality->PrintQuality == ESCPR_PQ_DRAFT || + pQuality->PrintQuality == ESCPR_PQ_NORMAL || + pQuality->PrintQuality == ESCPR_PQ_HIGH)) { + dbprint(("ChangeSpec_DraftOnly : invalid value for PrintQuality (%d)\n", pQuality->PrintQuality)); + /* it is not able to hadle this situation so do nothing */ + return ESCPR_SP_ERR_NONE; + } + + /* find S id with paper size */ + width = pJob->PaperWidth; + length = pJob->PaperLength; + + /* use 360 dpi unit */ + if(pJob->InResolution == ESCPR_IR_7272) { + width /= 2; + length /= 2; + } + + for(i = 0; i < NUM_PAPER_SIZE; i++) { + if(PM_PAPER_SIZE[i].width == width && + PM_PAPER_SIZE[i].length == length) { + s_id = PM_PAPER_SIZE[i].id; + } + } + verbose_dbprint(("ChangeSpec_DrfatOnly : size id(%d), width(%d), length(%d)\n", s_id, width, length)); + + /* Refer the data retained within Service Pack */ + pPMinfo = &g_PMinfo.data[PM_HEADER_LEN]; + + /* S field start postion */ + if(_pmFindSfield(s_id, pPMinfo, &pS_begin, &pS_end) < 0) { + dbprint(("ChangeSpec_DraftOnly : cannot find S_id(%d)\n", s_id)); + /* it is not able to hadle this situation so do nothing */ + return ESCPR_SP_ERR_NONE; + }; + + VERBOSE_DUMP_PMREPLY((pS_begin, DUMP_S_TAG_ONLY, + "< ChangeSpec_DraftOnly : retained S field info >")); + + /* Fetch the T field */ + t_id = pQuality->MediaTypeID; + + if((pTfield = _pmScanTfield(t_id, pS_begin)) == NULL) { + dbprint(("ChangeSpec_DraftOnly : cannot find T_id(%d)\n", t_id)); + /* it is not able to hadle this situation so do nothing */ + return ESCPR_SP_ERR_NONE; + } + + /* Quality should be assigned to the only supported mode */ + verbose_dbprint((" >> adjusted PrintQuality : %d -> ", pQuality->PrintQuality)); + + if(!((*(pTfield+2) & 0x07) & /* Printer's support mode actually */ + (1<<pQuality->PrintQuality))) { /* Upper layer(driver) assigned mode */ + + /* The quality mode which is not supported by printer is assigned */ + /* Replace it to printer's support mode */ + switch(*(pTfield+2) & 0x07) { + case 0x01: /* 0 0 1 : Draft only */ + quality[Q_DRAFT] = ESCPR_PQ_DRAFT; + quality[Q_NORMAL] = ESCPR_PQ_DRAFT; + quality[Q_HIGH] = ESCPR_PQ_DRAFT; + break; + case 0x02: /* 0 1 0 : Normal only */ + quality[Q_DRAFT] = ESCPR_PQ_NORMAL; + quality[Q_NORMAL] = ESCPR_PQ_NORMAL; + quality[Q_HIGH] = ESCPR_PQ_NORMAL; + break; + case 0x04: /* 1 0 0 : High only */ + quality[Q_DRAFT] = ESCPR_PQ_HIGH; + quality[Q_NORMAL] = ESCPR_PQ_HIGH; + quality[Q_HIGH] = ESCPR_PQ_HIGH; + break; + case 0x03: /* 0 1 1 : Normal and Draft */ + quality[Q_DRAFT] = ESCPR_PQ_DRAFT; + quality[Q_NORMAL] = ESCPR_PQ_NORMAL; + quality[Q_HIGH] = ESCPR_PQ_NORMAL; + break; + case 0x05: /* 1 0 1 : High and Draft */ + quality[Q_DRAFT] = ESCPR_PQ_DRAFT; + quality[Q_NORMAL] = ESCPR_PQ_HIGH; + quality[Q_HIGH] = ESCPR_PQ_HIGH; + break; + case 0x06: /* 1 1 0 : High and Normal */ + quality[Q_DRAFT] = ESCPR_PQ_NORMAL; + quality[Q_NORMAL] = ESCPR_PQ_NORMAL; + quality[Q_HIGH] = ESCPR_PQ_HIGH; + break; + case 0x07: /* 1 1 1 : Anything possible */ + break; + default: + break; + } + + /* Now, the value of quality array of index which is same as PrintQuality is valid */ + pQuality->PrintQuality = quality[pQuality->PrintQuality]; + } + + verbose_dbprint(("%d\n", pQuality->PrintQuality)); + + return ESCPR_SP_ERR_NONE; +} + + +/*=======================================================================================*/ +/* ESC/P-R Service Pack Module API (only used by ESC/P-R Core module) */ +/*=======================================================================================*/ +ESCPR_ERR_CODE ESCPR_RequestServicePack(SP_REQ_CODE request, + void* pData1st, void* pData2nd, void* pData3th, void* pData4th) +{ + ESCPR_BYTE4 Ret = ESCPR_SP_ERR_NONE; + + /* Validation request code */ + switch(request) { + case SP_REQ_FIX_UPDATE_PMREPLY: + case SP_REQ_FIX_720DPI: + case SP_REQ_FIX_COMPOSITE_BLACK: + case SP_REQ_FIX_DRAFTONLY: + break; + default: + return ESCPR_SP_ERR_INVALID_REQUEST; + } + + /* Call ChangeSpec function */ + Ret = (*fpChangeSpec[request])(pData1st, pData2nd, pData3th, pData4th); + + return Ret; +} + + +/* Enf of File */ diff --git a/lib/escpr_sp.h b/lib/escpr_sp.h new file mode 100644 index 0000000..e695e7e --- /dev/null +++ b/lib/escpr_sp.h @@ -0,0 +1,54 @@ +/*********************************************************************** + * + * Copyright (c) 2005 Seiko Epson Corporation. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * File Name: escpr_sp.h + * + ***********************************************************************/ + +#ifndef __EPSON_ESCPR_SP_H__ +#define __EPSON_ESCPR_SP_H__ + +#include "escpr_def.h" + +/* Function retun code */ +#define ESCPR_SP_ERR_NONE 0 +#define ESCPR_SP_ERR_INVALID_REQUEST (-1) +#define ESCPR_SP_ERR_PM_INVALID_POINTER (-2) +#define ESCPR_SP_ERR_PM_INVALID_HEADER (-3) +#define ESCPR_SP_ERR_PM_INVALID_TERMINATOR (-4) +#define ESCPR_SP_ERR_PM_NO_VALID_FIELD (-5) + +/* Service Pack request code */ +typedef enum _SP_REQ { + SP_REQ_FIX_UPDATE_PMREPLY= 0, + SP_REQ_FIX_720DPI, + SP_REQ_FIX_COMPOSITE_BLACK, + SP_REQ_FIX_DRAFTONLY +} SP_REQ_CODE; + +/* note about parameters */ +/* request : Request code */ +/* pData1st : Required data type for specific request */ +/* pData2nd : Required data type for specific request */ +/* pData3th : Required data type for specific request (currently just reserved) */ +/* pData4th : Required data type for specific request (currently just reserved) */ +ESCPR_ERR_CODE ESCPR_RequestServicePack(SP_REQ_CODE request, + void* pData1st, void* pData2nd, void* pData3th, void* pData4th); + +#endif + |