summaryrefslogtreecommitdiff
path: root/lcms2mt/utils/jpgicc
diff options
context:
space:
mode:
Diffstat (limited to 'lcms2mt/utils/jpgicc')
-rwxr-xr-xlcms2mt/utils/jpgicc/LICENSE_iccjpeg67
-rw-r--r--lcms2mt/utils/jpgicc/Makefile.am22
-rw-r--r--lcms2mt/utils/jpgicc/Makefile.in739
-rw-r--r--lcms2mt/utils/jpgicc/iccjpeg.c248
-rw-r--r--lcms2mt/utils/jpgicc/iccjpeg.h73
-rw-r--r--lcms2mt/utils/jpgicc/jpgicc.1122
-rw-r--r--lcms2mt/utils/jpgicc/jpgicc.c1263
7 files changed, 2534 insertions, 0 deletions
diff --git a/lcms2mt/utils/jpgicc/LICENSE_iccjpeg b/lcms2mt/utils/jpgicc/LICENSE_iccjpeg
new file mode 100755
index 000000000..b77d4cbff
--- /dev/null
+++ b/lcms2mt/utils/jpgicc/LICENSE_iccjpeg
@@ -0,0 +1,67 @@
+
+THIS LICENSE APPLIES ONLY TO iccjpeg.c file
+-----
+In plain English:
+
+1. We don't promise that this software works. (But if you find any bugs,
+ please let us know!)
+2. You can use this software for whatever you want. You don't have to pay us.
+3. You may not pretend that you wrote this software. If you use it in a
+ program, you must acknowledge somewhere in your documentation that
+ you've used the IJG code.
+
+In legalese:
+
+The authors make NO WARRANTY or representation, either express or implied,
+with respect to this software, its quality, accuracy, merchantability, or
+fitness for a particular purpose. This software is provided "AS IS", and you,
+its user, assume the entire risk as to its quality and accuracy.
+
+This software is copyright (C) 1991-2013, Thomas G. Lane, Guido Vollbeding.
+All Rights Reserved except as specified below.
+
+Permission is hereby granted to use, copy, modify, and distribute this
+software (or portions thereof) for any purpose, without fee, subject to these
+conditions:
+(1) If any part of the source code for this software is distributed, then this
+README file must be included, with this copyright and no-warranty notice
+unaltered; and any additions, deletions, or changes to the original files
+must be clearly indicated in accompanying documentation.
+(2) If only executable code is distributed, then the accompanying
+documentation must state that "this software is based in part on the work of
+the Independent JPEG Group".
+(3) Permission for use of this software is granted only if the user accepts
+full responsibility for any undesirable consequences; the authors accept
+NO LIABILITY for damages of any kind.
+
+These conditions apply to any software derived from or based on the IJG code,
+not just to the unmodified library. If you use our work, you ought to
+acknowledge us.
+
+Permission is NOT granted for the use of any IJG author's name or company name
+in advertising or publicity relating to this software or products derived from
+it. This software may be referred to only as "the Independent JPEG Group's
+software".
+
+We specifically permit and encourage the use of this software as the basis of
+commercial products, provided that all warranty or liability claims are
+assumed by the product vendor.
+
+
+The Unix configuration script "configure" was produced with GNU Autoconf.
+It is copyright by the Free Software Foundation but is freely distributable.
+The same holds for its supporting scripts (config.guess, config.sub,
+ltmain.sh). Another support script, install-sh, is copyright by X Consortium
+but is also freely distributable.
+
+The IJG distribution formerly included code to read and write GIF files.
+To avoid entanglement with the Unisys LZW patent, GIF reading support has
+been removed altogether, and the GIF writer has been simplified to produce
+"uncompressed GIFs". This technique does not use the LZW algorithm; the
+resulting GIF files are larger than usual, but are readable by all standard
+GIF decoders.
+
+We are required to state that
+ "The Graphics Interchange Format(c) is the Copyright property of
+ CompuServe Incorporated. GIF(sm) is a Service Mark property of
+ CompuServe Incorporated."
diff --git a/lcms2mt/utils/jpgicc/Makefile.am b/lcms2mt/utils/jpgicc/Makefile.am
new file mode 100644
index 000000000..d0a0897f3
--- /dev/null
+++ b/lcms2mt/utils/jpgicc/Makefile.am
@@ -0,0 +1,22 @@
+#
+# Makefile for building jpegicc
+# Written by Bob Friesenhahn, June 2003
+# Bugs introduced by Marti Maria on October 2004
+
+# Don't require all the GNU mandated files
+AUTOMAKE_OPTIONS = 1.7 foreign no-dependencies
+
+AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include \
+ -I$(top_srcdir)/utils/common -I$(top_builddir)/utils/common
+if HasJPEG
+bin_PROGRAMS = jpgicc
+else
+bin_PROGRAMS =
+endif
+
+jpgicc_LDADD = $(top_builddir)/src/liblcms2.la @JPEGICC_DEPLIBS@
+jpgicc_LDFLAGS = @LDFLAGS@
+jpgicc_SOURCES = jpgicc.c iccjpeg.c ../common/xgetopt.c ../common/vprf.c ../common/utils.h
+man_MANS = jpgicc.1
+
+EXTRA_DIST = iccjpeg.h $(man_MANS)
diff --git a/lcms2mt/utils/jpgicc/Makefile.in b/lcms2mt/utils/jpgicc/Makefile.in
new file mode 100644
index 000000000..69032832d
--- /dev/null
+++ b/lcms2mt/utils/jpgicc/Makefile.in
@@ -0,0 +1,739 @@
+# Makefile.in generated by automake 1.15 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2014 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@
+
+#
+# Makefile for building jpegicc
+# Written by Bob Friesenhahn, June 2003
+# Bugs introduced by Marti Maria on October 2004
+
+VPATH = @srcdir@
+am__is_gnu_make = { \
+ if test -z '$(MAKELEVEL)'; then \
+ false; \
+ elif test -n '$(MAKE_HOST)'; then \
+ true; \
+ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+ true; \
+ else \
+ false; \
+ fi; \
+}
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@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@
+@HasJPEG_TRUE@bin_PROGRAMS = jpgicc$(EXEEXT)
+subdir = utils/jpgicc
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/acx_pthread.m4 \
+ $(top_srcdir)/m4/ax_append_compile_flags.m4 \
+ $(top_srcdir)/m4/ax_append_flag.m4 \
+ $(top_srcdir)/m4/ax_check_compile_flag.m4 \
+ $(top_srcdir)/m4/ax_gcc_func_attribute.m4 \
+ $(top_srcdir)/m4/ax_require_defined.m4 \
+ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
+mkinstalldirs = $(install_sh) -d
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"
+PROGRAMS = $(bin_PROGRAMS)
+am__dirstamp = $(am__leading_dot)dirstamp
+am_jpgicc_OBJECTS = jpgicc.$(OBJEXT) iccjpeg.$(OBJEXT) \
+ ../common/xgetopt.$(OBJEXT) ../common/vprf.$(OBJEXT)
+jpgicc_OBJECTS = $(am_jpgicc_OBJECTS)
+jpgicc_DEPENDENCIES = $(top_builddir)/src/liblcms2.la
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 =
+jpgicc_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(jpgicc_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
+DEFAULT_INCLUDES = -I.@am__isrc@
+depcomp =
+am__depfiles_maybe =
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
+SOURCES = $(jpgicc_SOURCES)
+DIST_SOURCES = $(jpgicc_SOURCES)
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
+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 = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+ test -z "$$files" \
+ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+ $(am__cd) "$$dir" && rm -f $$files; }; \
+ }
+man1dir = $(mandir)/man1
+NROFF = nroff
+MANS = $(man_MANS)
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
+ETAGS = etags
+CTAGS = ctags
+am__DIST_COMMON = $(srcdir)/Makefile.in
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+AS = @AS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+JPEGICC_DEPLIBS = @JPEGICC_DEPLIBS@
+LCMS_LIB_DEPLIBS = @LCMS_LIB_DEPLIBS@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBRARY_AGE = @LIBRARY_AGE@
+LIBRARY_CURRENT = @LIBRARY_CURRENT@
+LIBRARY_REVISION = @LIBRARY_REVISION@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIB_JPEG = @LIB_JPEG@
+LIB_MATH = @LIB_MATH@
+LIB_THREAD = @LIB_THREAD@
+LIB_TIFF = @LIB_TIFF@
+LIB_ZLIB = @LIB_ZLIB@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PTHREAD_CC = @PTHREAD_CC@
+PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
+PTHREAD_CXX = @PTHREAD_CXX@
+PTHREAD_LIBS = @PTHREAD_LIBS@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+TIFFICC_DEPLIBS = @TIFFICC_DEPLIBS@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+acx_pthread_config = @acx_pthread_config@
+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@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+inline = @inline@
+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@
+runstatedir = @runstatedir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+
+# Don't require all the GNU mandated files
+AUTOMAKE_OPTIONS = 1.7 foreign no-dependencies
+AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include \
+ -I$(top_srcdir)/utils/common -I$(top_builddir)/utils/common
+
+jpgicc_LDADD = $(top_builddir)/src/liblcms2.la @JPEGICC_DEPLIBS@
+jpgicc_LDFLAGS = @LDFLAGS@
+jpgicc_SOURCES = jpgicc.c iccjpeg.c ../common/xgetopt.c ../common/vprf.c ../common/utils.h
+man_MANS = jpgicc.1
+EXTRA_DIST = iccjpeg.h $(man_MANS)
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign utils/jpgicc/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign utils/jpgicc/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: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-binPROGRAMS: $(bin_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \
+ fi; \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed 's/$(EXEEXT)$$//' | \
+ while read p p1; do if test -f $$p \
+ || test -f $$p1 \
+ ; then echo "$$p"; echo "$$p"; else :; fi; \
+ done | \
+ sed -e 'p;s,.*/,,;n;h' \
+ -e 's|.*|.|' \
+ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+ sed 'N;N;N;s,\n, ,g' | \
+ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+ if ($$2 == $$4) files[d] = files[d] " " $$1; \
+ else { print "f", $$3 "/" $$4, $$1; } } \
+ END { for (d in files) print "f", d, files[d] }' | \
+ while read type dir files; do \
+ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+ test -z "$$files" || { \
+ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
+ } \
+ ; done
+
+uninstall-binPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+ files=`for p in $$list; do echo "$$p"; done | \
+ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+ -e 's/$$/$(EXEEXT)/' \
+ `; \
+ test -n "$$list" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(bindir)" && rm -f $$files
+
+clean-binPROGRAMS:
+ @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+../common/$(am__dirstamp):
+ @$(MKDIR_P) ../common
+ @: > ../common/$(am__dirstamp)
+../common/xgetopt.$(OBJEXT): ../common/$(am__dirstamp)
+../common/vprf.$(OBJEXT): ../common/$(am__dirstamp)
+
+jpgicc$(EXEEXT): $(jpgicc_OBJECTS) $(jpgicc_DEPENDENCIES) $(EXTRA_jpgicc_DEPENDENCIES)
+ @rm -f jpgicc$(EXEEXT)
+ $(AM_V_CCLD)$(jpgicc_LINK) $(jpgicc_OBJECTS) $(jpgicc_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+ -rm -f ../common/*.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+.c.o:
+ $(AM_V_CC)$(COMPILE) -c -o $@ $<
+
+.c.obj:
+ $(AM_V_CC)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.c.lo:
+ $(AM_V_CC)$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+install-man1: $(man_MANS)
+ @$(NORMAL_INSTALL)
+ @list1=''; \
+ list2='$(man_MANS)'; \
+ test -n "$(man1dir)" \
+ && test -n "`echo $$list1$$list2`" \
+ || exit 0; \
+ echo " $(MKDIR_P) '$(DESTDIR)$(man1dir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(man1dir)" || exit 1; \
+ { for i in $$list1; do echo "$$i"; done; \
+ if test -n "$$list2"; then \
+ for i in $$list2; do echo "$$i"; done \
+ | sed -n '/\.1[a-z]*$$/p'; \
+ fi; \
+ } | while read p; do \
+ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; echo "$$p"; \
+ done | \
+ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \
+ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \
+ sed 'N;N;s,\n, ,g' | { \
+ list=; while read file base inst; do \
+ if test "$$base" = "$$inst"; then list="$$list $$file"; else \
+ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man1dir)/$$inst'"; \
+ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man1dir)/$$inst" || exit $$?; \
+ fi; \
+ done; \
+ for i in $$list; do echo "$$i"; done | $(am__base_list) | \
+ while read files; do \
+ test -z "$$files" || { \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man1dir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(man1dir)" || exit $$?; }; \
+ done; }
+
+uninstall-man1:
+ @$(NORMAL_UNINSTALL)
+ @list=''; test -n "$(man1dir)" || exit 0; \
+ files=`{ for i in $$list; do echo "$$i"; done; \
+ l2='$(man_MANS)'; for i in $$l2; do echo "$$i"; done | \
+ sed -n '/\.1[a-z]*$$/p'; \
+ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \
+ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
+ dir='$(DESTDIR)$(man1dir)'; $(am__uninstall_files_from_dir)
+
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ set x; \
+ here=`pwd`; \
+ $(am__define_uniq_tagged_files); \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
+
+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 "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$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 $(PROGRAMS) $(MANS)
+installdirs:
+ for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"; 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:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+ -rm -f ../common/$(am__dirstamp)
+
+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-binPROGRAMS clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-man
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-binPROGRAMS
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man: install-man1
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -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-binPROGRAMS uninstall-man
+
+uninstall-man: uninstall-man1
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean \
+ clean-binPROGRAMS clean-generic clean-libtool cscopelist-am \
+ ctags ctags-am distclean distclean-compile distclean-generic \
+ distclean-libtool distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-binPROGRAMS \
+ install-data install-data-am install-dvi install-dvi-am \
+ install-exec install-exec-am install-html install-html-am \
+ install-info install-info-am install-man install-man1 \
+ 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 tags-am uninstall uninstall-am \
+ uninstall-binPROGRAMS uninstall-man uninstall-man1
+
+.PRECIOUS: Makefile
+
+
+# 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/lcms2mt/utils/jpgicc/iccjpeg.c b/lcms2mt/utils/jpgicc/iccjpeg.c
new file mode 100644
index 000000000..d08b4bd08
--- /dev/null
+++ b/lcms2mt/utils/jpgicc/iccjpeg.c
@@ -0,0 +1,248 @@
+/*
+ * iccprofile.c
+ *
+ * This file provides code to read and write International Color Consortium
+ * (ICC) device profiles embedded in JFIF JPEG image files. The ICC has
+ * defined a standard format for including such data in JPEG "APP2" markers.
+ * The code given here does not know anything about the internal structure
+ * of the ICC profile data; it just knows how to put the profile data into
+ * a JPEG file being written, or get it back out when reading.
+ *
+ * This code depends on new features added to the IJG JPEG library as of
+ * IJG release 6b; it will not compile or work with older IJG versions.
+ *
+ * NOTE: this code would need surgery to work on 16-bit-int machines
+ * with ICC profiles exceeding 64K bytes in size. If you need to do that,
+ * change all the "unsigned int" variables to "INT32". You'll also need
+ * to find a malloc() replacement that can allocate more than 64K.
+ */
+
+#include "iccjpeg.h"
+#include <stdlib.h> /* define malloc() */
+
+
+/*
+ * Since an ICC profile can be larger than the maximum size of a JPEG marker
+ * (64K), we need provisions to split it into multiple markers. The format
+ * defined by the ICC specifies one or more APP2 markers containing the
+ * following data:
+ * Identifying string ASCII "ICC_PROFILE\0" (12 bytes)
+ * Marker sequence number 1 for first APP2, 2 for next, etc (1 byte)
+ * Number of markers Total number of APP2's used (1 byte)
+ * Profile data (remainder of APP2 data)
+ * Decoders should use the marker sequence numbers to reassemble the profile,
+ * rather than assuming that the APP2 markers appear in the correct sequence.
+ */
+
+#define ICC_MARKER (JPEG_APP0 + 2) /* JPEG marker code for ICC */
+#define ICC_OVERHEAD_LEN 14 /* size of non-profile data in APP2 */
+#define MAX_BYTES_IN_MARKER 65533 /* maximum data len of a JPEG marker */
+#define MAX_DATA_BYTES_IN_MARKER (MAX_BYTES_IN_MARKER - ICC_OVERHEAD_LEN)
+
+
+/*
+ * This routine writes the given ICC profile data into a JPEG file.
+ * It *must* be called AFTER calling jpeg_start_compress() and BEFORE
+ * the first call to jpeg_write_scanlines().
+ * (This ordering ensures that the APP2 marker(s) will appear after the
+ * SOI and JFIF or Adobe markers, but before all else.)
+ */
+
+void
+write_icc_profile (j_compress_ptr cinfo,
+ const JOCTET *icc_data_ptr,
+ unsigned int icc_data_len)
+{
+ unsigned int num_markers; /* total number of markers we'll write */
+ int cur_marker = 1; /* per spec, counting starts at 1 */
+ unsigned int length; /* number of bytes to write in this marker */
+
+ /* Calculate the number of markers we'll need, rounding up of course */
+ num_markers = icc_data_len / MAX_DATA_BYTES_IN_MARKER;
+ if (num_markers * MAX_DATA_BYTES_IN_MARKER != icc_data_len)
+ num_markers++;
+
+ while (icc_data_len > 0) {
+ /* length of profile to put in this marker */
+ length = icc_data_len;
+ if (length > MAX_DATA_BYTES_IN_MARKER)
+ length = MAX_DATA_BYTES_IN_MARKER;
+ icc_data_len -= length;
+
+ /* Write the JPEG marker header (APP2 code and marker length) */
+ jpeg_write_m_header(cinfo, ICC_MARKER,
+ (unsigned int) (length + ICC_OVERHEAD_LEN));
+
+ /* Write the marker identifying string "ICC_PROFILE" (null-terminated).
+ * We code it in this less-than-transparent way so that the code works
+ * even if the local character set is not ASCII.
+ */
+ jpeg_write_m_byte(cinfo, 0x49);
+ jpeg_write_m_byte(cinfo, 0x43);
+ jpeg_write_m_byte(cinfo, 0x43);
+ jpeg_write_m_byte(cinfo, 0x5F);
+ jpeg_write_m_byte(cinfo, 0x50);
+ jpeg_write_m_byte(cinfo, 0x52);
+ jpeg_write_m_byte(cinfo, 0x4F);
+ jpeg_write_m_byte(cinfo, 0x46);
+ jpeg_write_m_byte(cinfo, 0x49);
+ jpeg_write_m_byte(cinfo, 0x4C);
+ jpeg_write_m_byte(cinfo, 0x45);
+ jpeg_write_m_byte(cinfo, 0x0);
+
+ /* Add the sequencing info */
+ jpeg_write_m_byte(cinfo, cur_marker);
+ jpeg_write_m_byte(cinfo, (int) num_markers);
+
+ /* Add the profile data */
+ while (length--) {
+ jpeg_write_m_byte(cinfo, *icc_data_ptr);
+ icc_data_ptr++;
+ }
+ cur_marker++;
+ }
+}
+
+
+/*
+ * Prepare for reading an ICC profile
+ */
+
+void
+setup_read_icc_profile (j_decompress_ptr cinfo)
+{
+ /* Tell the library to keep any APP2 data it may find */
+ jpeg_save_markers(cinfo, ICC_MARKER, 0xFFFF);
+}
+
+
+/*
+ * Handy subroutine to test whether a saved marker is an ICC profile marker.
+ */
+
+static boolean
+marker_is_icc (jpeg_saved_marker_ptr marker)
+{
+ return
+ marker->marker == ICC_MARKER &&
+ marker->data_length >= ICC_OVERHEAD_LEN &&
+ /* verify the identifying string */
+ GETJOCTET(marker->data[0]) == 0x49 &&
+ GETJOCTET(marker->data[1]) == 0x43 &&
+ GETJOCTET(marker->data[2]) == 0x43 &&
+ GETJOCTET(marker->data[3]) == 0x5F &&
+ GETJOCTET(marker->data[4]) == 0x50 &&
+ GETJOCTET(marker->data[5]) == 0x52 &&
+ GETJOCTET(marker->data[6]) == 0x4F &&
+ GETJOCTET(marker->data[7]) == 0x46 &&
+ GETJOCTET(marker->data[8]) == 0x49 &&
+ GETJOCTET(marker->data[9]) == 0x4C &&
+ GETJOCTET(marker->data[10]) == 0x45 &&
+ GETJOCTET(marker->data[11]) == 0x0;
+}
+
+
+/*
+ * See if there was an ICC profile in the JPEG file being read;
+ * if so, reassemble and return the profile data.
+ *
+ * TRUE is returned if an ICC profile was found, FALSE if not.
+ * If TRUE is returned, *icc_data_ptr is set to point to the
+ * returned data, and *icc_data_len is set to its length.
+ *
+ * IMPORTANT: the data at **icc_data_ptr has been allocated with malloc()
+ * and must be freed by the caller with free() when the caller no longer
+ * needs it. (Alternatively, we could write this routine to use the
+ * IJG library's memory allocator, so that the data would be freed implicitly
+ * at jpeg_finish_decompress() time. But it seems likely that many apps
+ * will prefer to have the data stick around after decompression finishes.)
+ *
+ * NOTE: if the file contains invalid ICC APP2 markers, we just silently
+ * return FALSE. You might want to issue an error message instead.
+ */
+
+boolean
+read_icc_profile (j_decompress_ptr cinfo,
+ JOCTET **icc_data_ptr,
+ unsigned int *icc_data_len)
+{
+ jpeg_saved_marker_ptr marker;
+ int num_markers = 0;
+ int seq_no;
+ JOCTET *icc_data;
+ unsigned int total_length;
+#define MAX_SEQ_NO 255 /* sufficient since marker numbers are bytes */
+ char marker_present[MAX_SEQ_NO+1]; /* 1 if marker found */
+ unsigned int data_length[MAX_SEQ_NO+1]; /* size of profile data in marker */
+ unsigned int data_offset[MAX_SEQ_NO+1]; /* offset for data in marker */
+
+ *icc_data_ptr = NULL; /* avoid confusion if FALSE return */
+ *icc_data_len = 0;
+
+ /* This first pass over the saved markers discovers whether there are
+ * any ICC markers and verifies the consistency of the marker numbering.
+ */
+
+ for (seq_no = 1; seq_no <= MAX_SEQ_NO; seq_no++)
+ marker_present[seq_no] = 0;
+
+ for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) {
+ if (marker_is_icc(marker)) {
+ if (num_markers == 0)
+ num_markers = GETJOCTET(marker->data[13]);
+ else if (num_markers != GETJOCTET(marker->data[13]))
+ return FALSE; /* inconsistent num_markers fields */
+ seq_no = GETJOCTET(marker->data[12]);
+ if (seq_no <= 0 || seq_no > num_markers)
+ return FALSE; /* bogus sequence number */
+ if (marker_present[seq_no])
+ return FALSE; /* duplicate sequence numbers */
+ marker_present[seq_no] = 1;
+ data_length[seq_no] = marker->data_length - ICC_OVERHEAD_LEN;
+ }
+ }
+
+ if (num_markers == 0)
+ return FALSE;
+
+ /* Check for missing markers, count total space needed,
+ * compute offset of each marker's part of the data.
+ */
+
+ total_length = 0;
+ for (seq_no = 1; seq_no <= num_markers; seq_no++) {
+ if (marker_present[seq_no] == 0)
+ return FALSE; /* missing sequence number */
+ data_offset[seq_no] = total_length;
+ total_length += data_length[seq_no];
+ }
+
+ if (total_length == 0)
+ return FALSE; /* found only empty markers? */
+
+ /* Allocate space for assembled data */
+ icc_data = (JOCTET *) malloc(total_length * sizeof(JOCTET));
+ if (icc_data == NULL)
+ return FALSE; /* oops, out of memory */
+
+ /* and fill it in */
+ for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) {
+ if (marker_is_icc(marker)) {
+ JOCTET FAR *src_ptr;
+ JOCTET *dst_ptr;
+ unsigned int length;
+ seq_no = GETJOCTET(marker->data[12]);
+ dst_ptr = icc_data + data_offset[seq_no];
+ src_ptr = marker->data + ICC_OVERHEAD_LEN;
+ length = data_length[seq_no];
+ while (length--) {
+ *dst_ptr++ = *src_ptr++;
+ }
+ }
+ }
+
+ *icc_data_ptr = icc_data;
+ *icc_data_len = total_length;
+
+ return TRUE;
+}
diff --git a/lcms2mt/utils/jpgicc/iccjpeg.h b/lcms2mt/utils/jpgicc/iccjpeg.h
new file mode 100644
index 000000000..5e1888d9e
--- /dev/null
+++ b/lcms2mt/utils/jpgicc/iccjpeg.h
@@ -0,0 +1,73 @@
+/*
+ * iccprofile.h
+ *
+ * This file provides code to read and write International Color Consortium
+ * (ICC) device profiles embedded in JFIF JPEG image files. The ICC has
+ * defined a standard format for including such data in JPEG "APP2" markers.
+ * The code given here does not know anything about the internal structure
+ * of the ICC profile data; it just knows how to put the profile data into
+ * a JPEG file being written, or get it back out when reading.
+ *
+ * This code depends on new features added to the IJG JPEG library as of
+ * IJG release 6b; it will not compile or work with older IJG versions.
+ *
+ * NOTE: this code would need surgery to work on 16-bit-int machines
+ * with ICC profiles exceeding 64K bytes in size. See iccprofile.c
+ * for details.
+ */
+
+#include <stdio.h> /* needed to define "FILE", "NULL" */
+#include "jpeglib.h"
+
+
+/*
+ * This routine writes the given ICC profile data into a JPEG file.
+ * It *must* be called AFTER calling jpeg_start_compress() and BEFORE
+ * the first call to jpeg_write_scanlines().
+ * (This ordering ensures that the APP2 marker(s) will appear after the
+ * SOI and JFIF or Adobe markers, but before all else.)
+ */
+
+extern void write_icc_profile JPP((j_compress_ptr cinfo,
+ const JOCTET *icc_data_ptr,
+ unsigned int icc_data_len));
+
+
+/*
+ * Reading a JPEG file that may contain an ICC profile requires two steps:
+ *
+ * 1. After jpeg_create_decompress() but before jpeg_read_header(),
+ * call setup_read_icc_profile(). This routine tells the IJG library
+ * to save in memory any APP2 markers it may find in the file.
+ *
+ * 2. After jpeg_read_header(), call read_icc_profile() to find out
+ * whether there was a profile and obtain it if so.
+ */
+
+
+/*
+ * Prepare for reading an ICC profile
+ */
+
+extern void setup_read_icc_profile JPP((j_decompress_ptr cinfo));
+
+
+/*
+ * See if there was an ICC profile in the JPEG file being read;
+ * if so, reassemble and return the profile data.
+ *
+ * TRUE is returned if an ICC profile was found, FALSE if not.
+ * If TRUE is returned, *icc_data_ptr is set to point to the
+ * returned data, and *icc_data_len is set to its length.
+ *
+ * IMPORTANT: the data at **icc_data_ptr has been allocated with malloc()
+ * and must be freed by the caller with free() when the caller no longer
+ * needs it. (Alternatively, we could write this routine to use the
+ * IJG library's memory allocator, so that the data would be freed implicitly
+ * at jpeg_finish_decompress() time. But it seems likely that many apps
+ * will prefer to have the data stick around after decompression finishes.)
+ */
+
+extern boolean read_icc_profile JPP((j_decompress_ptr cinfo,
+ JOCTET **icc_data_ptr,
+ unsigned int *icc_data_len));
diff --git a/lcms2mt/utils/jpgicc/jpgicc.1 b/lcms2mt/utils/jpgicc/jpgicc.1
new file mode 100644
index 000000000..44795a38e
--- /dev/null
+++ b/lcms2mt/utils/jpgicc/jpgicc.1
@@ -0,0 +1,122 @@
+.\"Shiju P. Nair September 30, 2004
+.\"Thomas Weber <tweber@debian.org> April 23, 2014
+.TH JPGICC 1 "September 30, 2004"
+.SH NAME
+jpgicc - little cms ICC profile applier for JPEG.
+.SH SYNOPSIS
+.B jpgicc
+.RI [ options ] " input.jpg output.jpg"
+.SH DESCRIPTION
+lcms is a standalone CMM engine, which deals with the color management.
+It implements a fast transformation between ICC profiles.
+.B jpgicc
+is a little cms ICC profile applier for JPEG.
+.SH OPTIONS
+.TP
+.B \-b
+Black point compensation.
+.TP
+.BI \-c\ NUM
+Precalculates transform (0=Off, 1=Normal, 2=Hi-res, 3=LoRes) [defaults to 1].
+.TP
+.BI \-d\ NUM
+Observer adaptation state (abs.col. only), (0..1.0, float value) [defaults to 0.0].
+.TP
+.B \-e
+Embed destination profile.
+.TP
+.B \-g
+Marks out-of-gamut colors on softproof.
+.TP
+.BI \-h\ NUM
+Show summary of options and examples (0=help, 1=Examples, 2=Built-in profiles, 3=Contact information)
+.TP
+.BI \-i\ profile
+Input profile (defaults to sRGB).
+.TP
+.BI \-l\ link
+TODO: explain this option.
+.TP
+.BI \-m\ NUM
+SoftProof intent (0,1,2,3) [defaults to 0].
+.TP
+.B \-n
+Ignore embedded profile.
+.TP
+.BI \-o\ profile
+Output profile (defaults to sRGB).
+.TP
+.BI \-p\ profile
+Soft proof profile.
+.TP
+.BI \-q\ NUM
+Output JPEG quality, (0..100) [defaults to 75].
+.TP
+.BI \-s\ newprofile
+Save embedded profile as \fInewprofile\fR.
+.TP
+.BI \-t\ NUM
+Rendering intent
+.nf
+.RS
+0=Perceptual [default]
+1=Relative colorimetric
+2=Saturation
+3=Absolute colorimetric
+10=Perceptual preserving black ink
+11=Relative colorimetric preserving black ink
+12=Saturation preserving black ink
+13=Perceptual preserving black plane
+14=Relative colorimetric preserving black plane
+15=Saturation preserving black plane
+.RE
+.fi
+.TP
+.B \-v
+Verbose.
+.TP
+.BI \-!\ NUM,NUM,NUM
+Out-of-gamut marker channel values (r,g,b) [defaults: 128,128,128].
+.SH BUILT-IN PROFILES
+.nf
+ *Lab2 -- D50-based v2 CIEL*a*b
+ *Lab4 -- D50-based v4 CIEL*a*b
+ *Lab -- D50-based v4 CIEL*a*b
+ *XYZ -- CIE XYZ (PCS)
+ *sRGB -- sRGB color space
+ *Gray22 - Monochrome of Gamma 2.2
+ *Gray30 - Monochrome of Gamma 3.0
+ *null - Monochrome black for all input
+ *Lin2222- CMYK linearization of gamma 2.2 on each channel
+.fi
+.SH EXAMPLES
+.nf
+To color correct from scanner to sRGB:
+ jpgicc -iscanner.icm in.jpg out.jpg
+
+To convert from monitor1 to monitor2:
+ jpgicc -imon1.icm -omon2.icm in.jpg out.jpg
+
+To make a CMYK separation:
+ jpgicc -oprinter.icm inrgb.jpg outcmyk.jpg
+
+To recover sRGB from a CMYK separation:
+ jpgicc -iprinter.icm incmyk.jpg outrgb.jpg
+
+To convert from CIELab ITU/Fax JPEG to sRGB
+ jpgicc -iitufax.icm in.jpg out.jpg
+
+To convert from CIELab ITU/Fax JPEG to sRGB
+ jpgicc in.jpg out.jpg
+.fi
+.SH NOTES
+For suggestions, comments, bug reports etc. send mail to
+info@littlecms.com.
+.SH SEE ALSO
+.BR linkicc (1),
+.BR psicc (1),
+.BR tificc (1),
+.BR transicc (1)
+.SH AUTHOR
+This manual page was written by Shiju p. Nair <shiju.p@gmail.com>,
+for the Debian project.
diff --git a/lcms2mt/utils/jpgicc/jpgicc.c b/lcms2mt/utils/jpgicc/jpgicc.c
new file mode 100644
index 000000000..b4a880040
--- /dev/null
+++ b/lcms2mt/utils/jpgicc/jpgicc.c
@@ -0,0 +1,1263 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System
+// Copyright (c) 1998-2017 Marti Maria Saguer
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the Software
+// is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+// This program does apply profiles to (some) JPEG files
+
+
+#include "utils.h"
+
+#include "jpeglib.h"
+#include "iccjpeg.h"
+
+// Flags
+static cmsBool BlackPointCompensation = FALSE;
+static cmsBool IgnoreEmbedded = FALSE;
+static cmsBool GamutCheck = FALSE;
+static cmsBool lIsITUFax = FALSE;
+static cmsBool lIsPhotoshopApp13 = FALSE;
+static cmsBool lIsEXIF;
+static cmsBool lIsDeviceLink = FALSE;
+static cmsBool EmbedProfile = FALSE;
+
+static const char* SaveEmbedded = NULL;
+
+static int Intent = INTENT_PERCEPTUAL;
+static int ProofingIntent = INTENT_PERCEPTUAL;
+static int PrecalcMode = 1;
+
+static int jpegQuality = 75;
+
+static cmsFloat64Number ObserverAdaptationState = 0;
+
+
+static char *cInpProf = NULL;
+static char *cOutProf = NULL;
+static char *cProofing = NULL;
+
+static FILE * InFile;
+static FILE * OutFile;
+
+static struct jpeg_decompress_struct Decompressor;
+static struct jpeg_compress_struct Compressor;
+
+
+static struct my_error_mgr {
+
+ struct jpeg_error_mgr pub; // "public" fields
+ void* Cargo; // "private" fields
+
+} ErrorHandler;
+
+
+cmsUInt16Number Alarm[4] = {128,128,128,0};
+
+
+static
+void my_error_exit (j_common_ptr cinfo)
+{
+ char buffer[JMSG_LENGTH_MAX];
+
+ (*cinfo->err->format_message) (cinfo, buffer);
+ FatalError(buffer);
+}
+
+/*
+Definition of the APPn Markers Defined for continuous-tone G3FAX
+
+The application code APP1 initiates identification of the image as
+a G3FAX application and defines the spatial resolution and subsampling.
+This marker directly follows the SOI marker. The data format will be as follows:
+
+X'FFE1' (APP1), length, FAX identifier, version, spatial resolution.
+
+The above terms are defined as follows:
+
+Length: (Two octets) Total APP1 field octet count including the octet count itself, but excluding the APP1
+marker.
+
+FAX identifier: (Six octets) X'47', X'33', X'46', X'41', X'58', X'00'. This X'00'-terminated string "G3FAX"
+uniquely identifies this APP1 marker.
+
+Version: (Two octets) X'07CA'. This string specifies the year of approval of the standard, for identification
+in the case of future revision (for example, 1994).
+
+Spatial Resolution: (Two octets) Lightness pixel density in pels/25.4 mm. The basic value is 200. Allowed values are
+100, 200, 300, 400, 600 and 1200 pels/25.4 mm, with square (or equivalent) pels.
+
+NOTE – The functional equivalence of inch-based and mm-based resolutions is maintained. For example, the 200 × 200
+*/
+
+static
+cmsBool IsITUFax(jpeg_saved_marker_ptr ptr)
+{
+ while (ptr)
+ {
+ if (ptr -> marker == (JPEG_APP0 + 1) && ptr -> data_length > 5) {
+
+ const char* data = (const char*) ptr -> data;
+
+ if (strcmp(data, "G3FAX") == 0) return TRUE;
+ }
+
+ ptr = ptr -> next;
+ }
+
+ return FALSE;
+}
+
+// Save a ITU T.42/Fax marker with defaults on boundaries. This is the only mode we support right now.
+static
+void SetITUFax(j_compress_ptr cinfo)
+{
+ unsigned char Marker[] = "G3FAX\x00\0x07\xCA\x00\xC8";
+
+ jpeg_write_marker(cinfo, (JPEG_APP0 + 1), Marker, 10);
+}
+
+
+// Build a profile for decoding ITU T.42/Fax JPEG streams.
+// The profile has an additional ability in the input direction of
+// gamut compress values between 85 < a < -85 and -75 < b < 125. This conforms
+// the default range for ITU/T.42 -- See RFC 2301, section 6.2.3 for details
+
+// L* = [0, 100]
+// a* = [–85, 85]
+// b* = [–75, 125]
+
+
+// These functions does convert the encoding of ITUFAX to floating point
+// and vice-versa. No gamut mapping is performed yet.
+
+static
+void ITU2Lab(const cmsUInt16Number In[3], cmsCIELab* Lab)
+{
+ Lab -> L = (double) In[0] / 655.35;
+ Lab -> a = (double) 170.* (In[1] - 32768.) / 65535.;
+ Lab -> b = (double) 200.* (In[2] - 24576.) / 65535.;
+}
+
+static
+void Lab2ITU(const cmsCIELab* Lab, cmsUInt16Number Out[3])
+{
+ Out[0] = (cmsUInt16Number) floor((double) (Lab -> L / 100.)* 65535. );
+ Out[1] = (cmsUInt16Number) floor((double) (Lab -> a / 170.)* 65535. + 32768. );
+ Out[2] = (cmsUInt16Number) floor((double) (Lab -> b / 200.)* 65535. + 24576. );
+}
+
+// These are the samplers-- They are passed as callbacks to cmsStageSampleCLut16bit()
+// then, cmsSample3DGrid() will sweel whole Lab gamut calling these functions
+// once for each node. In[] will contain the Lab PCS value to convert to ITUFAX
+// on PCS2ITU, or the ITUFAX value to convert to Lab in ITU2PCS
+// You can change the number of sample points if desired, the algorithm will
+// remain same. 33 points gives good accurancy, but you can reduce to 22 or less
+// is space is critical
+
+#define GRID_POINTS 33
+
+static
+int PCS2ITU(cmsContext ContextID, register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
+{
+ cmsCIELab Lab;
+
+ cmsLabEncoded2Float(NULL, &Lab, In);
+ cmsDesaturateLab(NULL, &Lab, 85, -85, 125, -75); // This function does the necessary gamut remapping
+ Lab2ITU(&Lab, Out);
+ return TRUE;
+
+ UTILS_UNUSED_PARAMETER(Cargo);
+ UTILS_UNUSED_PARAMETER(ContextID);
+}
+
+
+static
+int ITU2PCS(cmsContext ContextID, register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
+{
+ cmsCIELab Lab;
+
+ ITU2Lab(In, &Lab);
+ cmsFloat2LabEncoded(NULL, Out, &Lab);
+ return TRUE;
+
+ UTILS_UNUSED_PARAMETER(Cargo);
+ UTILS_UNUSED_PARAMETER(ContextID);
+}
+
+// This function does create the virtual input profile, which decodes ITU to the profile connection space
+static
+cmsHPROFILE CreateITU2PCS_ICC(void)
+{
+ cmsHPROFILE hProfile;
+ cmsPipeline* AToB0;
+ cmsStage* ColorMap;
+
+ AToB0 = cmsPipelineAlloc(0, 3, 3);
+ if (AToB0 == NULL) return NULL;
+
+ ColorMap = cmsStageAllocCLut16bit(0, GRID_POINTS, 3, 3, NULL);
+ if (ColorMap == NULL) return NULL;
+
+ cmsPipelineInsertStage(NULL, AToB0, cmsAT_BEGIN, ColorMap);
+ cmsStageSampleCLut16bit(NULL, ColorMap, ITU2PCS, NULL, 0);
+
+ hProfile = cmsCreateProfilePlaceholder(0);
+ if (hProfile == NULL) {
+ cmsPipelineFree(NULL, AToB0);
+ return NULL;
+ }
+
+ cmsWriteTag(NULL, hProfile, cmsSigAToB0Tag, AToB0);
+ cmsSetColorSpace(NULL, hProfile, cmsSigLabData);
+ cmsSetPCS(NULL, hProfile, cmsSigLabData);
+ cmsSetDeviceClass(NULL, hProfile, cmsSigColorSpaceClass);
+ cmsPipelineFree(NULL, AToB0);
+
+ return hProfile;
+}
+
+
+// This function does create the virtual output profile, with the necessary gamut mapping
+static
+cmsHPROFILE CreatePCS2ITU_ICC(void)
+{
+ cmsHPROFILE hProfile;
+ cmsPipeline* BToA0;
+ cmsStage* ColorMap;
+
+ BToA0 = cmsPipelineAlloc(0, 3, 3);
+ if (BToA0 == NULL) return NULL;
+
+ ColorMap = cmsStageAllocCLut16bit(0, GRID_POINTS, 3, 3, NULL);
+ if (ColorMap == NULL) return NULL;
+
+ cmsPipelineInsertStage(NULL, BToA0, cmsAT_BEGIN, ColorMap);
+ cmsStageSampleCLut16bit(NULL, ColorMap, PCS2ITU, NULL, 0);
+
+ hProfile = cmsCreateProfilePlaceholder(0);
+ if (hProfile == NULL) {
+ cmsPipelineFree(NULL, BToA0);
+ return NULL;
+ }
+
+ cmsWriteTag(NULL, hProfile, cmsSigBToA0Tag, BToA0);
+ cmsSetColorSpace(NULL, hProfile, cmsSigLabData);
+ cmsSetPCS(NULL, hProfile, cmsSigLabData);
+ cmsSetDeviceClass(NULL, hProfile, cmsSigColorSpaceClass);
+
+ cmsPipelineFree(NULL, BToA0);
+
+ return hProfile;
+}
+
+
+
+#define PS_FIXED_TO_FLOAT(h, l) ((float) (h) + ((float) (l)/(1<<16)))
+
+static
+cmsBool ProcessPhotoshopAPP13(JOCTET FAR *data, int datalen)
+{
+ int i;
+
+ for (i = 14; i < datalen; )
+ {
+ long len;
+ unsigned int type;
+
+ if (!(GETJOCTET(data[i] ) == 0x38 &&
+ GETJOCTET(data[i+1]) == 0x42 &&
+ GETJOCTET(data[i+2]) == 0x49 &&
+ GETJOCTET(data[i+3]) == 0x4D)) break; // Not recognized
+
+ i += 4; // identifying string
+
+ type = (unsigned int) (GETJOCTET(data[i]<<8) + GETJOCTET(data[i+1]));
+
+ i += 2; // resource type
+
+ i += GETJOCTET(data[i]) + ((GETJOCTET(data[i]) & 1) ? 1 : 2); // resource name
+
+ len = ((((GETJOCTET(data[i]<<8) + GETJOCTET(data[i+1]))<<8) +
+ GETJOCTET(data[i+2]))<<8) + GETJOCTET(data[i+3]);
+
+ i += 4; // Size
+
+ if (type == 0x03ED && len >= 16) {
+
+ Decompressor.X_density = (UINT16) PS_FIXED_TO_FLOAT(GETJOCTET(data[i]<<8) + GETJOCTET(data[i+1]),
+ GETJOCTET(data[i+2]<<8) + GETJOCTET(data[i+3]));
+ Decompressor.Y_density = (UINT16) PS_FIXED_TO_FLOAT(GETJOCTET(data[i+8]<<8) + GETJOCTET(data[i+9]),
+ GETJOCTET(data[i+10]<<8) + GETJOCTET(data[i+11]));
+
+ // Set the density unit to 1 since the
+ // Vertical and Horizontal resolutions
+ // are specified in Pixels per inch
+
+ Decompressor.density_unit = 0x01;
+ return TRUE;
+
+ }
+
+ i += len + ((len & 1) ? 1 : 0); // Alignment
+ }
+ return FALSE;
+}
+
+
+static
+cmsBool HandlePhotoshopAPP13(jpeg_saved_marker_ptr ptr)
+{
+ while (ptr) {
+
+ if (ptr -> marker == (JPEG_APP0 + 13) && ptr -> data_length > 9)
+ {
+ JOCTET FAR* data = ptr -> data;
+
+ if(GETJOCTET(data[0]) == 0x50 &&
+ GETJOCTET(data[1]) == 0x68 &&
+ GETJOCTET(data[2]) == 0x6F &&
+ GETJOCTET(data[3]) == 0x74 &&
+ GETJOCTET(data[4]) == 0x6F &&
+ GETJOCTET(data[5]) == 0x73 &&
+ GETJOCTET(data[6]) == 0x68 &&
+ GETJOCTET(data[7]) == 0x6F &&
+ GETJOCTET(data[8]) == 0x70) {
+
+ ProcessPhotoshopAPP13(data, ptr -> data_length);
+ return TRUE;
+ }
+ }
+
+ ptr = ptr -> next;
+ }
+
+ return FALSE;
+}
+
+
+typedef unsigned short uint16_t;
+typedef unsigned char uint8_t;
+typedef unsigned int uint32_t;
+
+#define INTEL_BYTE_ORDER 0x4949
+#define XRESOLUTION 0x011a
+#define YRESOLUTION 0x011b
+#define RESOLUTION_UNIT 0x128
+
+// Read a 16-bit word
+static
+uint16_t read16(uint8_t* arr, int pos, int swapBytes)
+{
+ uint8_t b1 = arr[pos];
+ uint8_t b2 = arr[pos+1];
+
+ return (swapBytes) ? ((b2 << 8) | b1) : ((b1 << 8) | b2);
+}
+
+
+// Read a 32-bit word
+static
+uint32_t read32(uint8_t* arr, int pos, int swapBytes)
+{
+
+ if(!swapBytes) {
+
+ return (arr[pos] << 24) |
+ (arr[pos+1] << 16) |
+ (arr[pos+2] << 8) |
+ arr[pos+3];
+ }
+
+ return arr[pos] |
+ (arr[pos+1] << 8) |
+ (arr[pos+2] << 16) |
+ (arr[pos+3] << 24);
+}
+
+
+
+static
+int read_tag(uint8_t* arr, int pos, int swapBytes, void* dest)
+{
+ // Format should be 5 over here (rational)
+ uint32_t format = read16(arr, pos + 2, swapBytes);
+ // Components should be 1
+ uint32_t components = read32(arr, pos + 4, swapBytes);
+ // Points to the value
+ uint32_t offset;
+
+ // sanity
+ if (components != 1) return 0;
+
+ if (format == 3)
+ offset = pos + 8;
+ else
+ offset = read32(arr, pos + 8, swapBytes);
+
+ switch (format) {
+
+ case 5: // Rational
+ {
+ double num = read32(arr, offset, swapBytes);
+ double den = read32(arr, offset + 4, swapBytes);
+ *(double *) dest = num / den;
+ }
+ break;
+
+ case 3: // uint 16
+ *(int*) dest = read16(arr, offset, swapBytes);
+ break;
+
+ default: return 0;
+ }
+
+ return 1;
+}
+
+
+
+// Handler for EXIF data
+static
+ cmsBool HandleEXIF(struct jpeg_decompress_struct* cinfo)
+{
+ jpeg_saved_marker_ptr ptr;
+ uint32_t ifd_ofs;
+ int pos = 0, swapBytes = 0;
+ uint32_t i, numEntries;
+ double XRes = -1, YRes = -1;
+ int Unit = 2; // Inches
+
+
+ for (ptr = cinfo ->marker_list; ptr; ptr = ptr ->next) {
+
+ if ((ptr ->marker == JPEG_APP0+1) && ptr ->data_length > 6) {
+ JOCTET FAR* data = ptr -> data;
+
+ if (memcmp(data, "Exif\0\0", 6) == 0) {
+
+ data += 6; // Skip EXIF marker
+
+ // 8 byte TIFF header
+ // first two determine byte order
+ pos = 0;
+ if (read16(data, pos, 0) == INTEL_BYTE_ORDER) {
+ swapBytes = 1;
+ }
+
+ pos += 2;
+
+ // next two bytes are always 0x002A (TIFF version)
+ pos += 2;
+
+ // offset to Image File Directory (includes the previous 8 bytes)
+ ifd_ofs = read32(data, pos, swapBytes);
+
+ // Search the directory for resolution tags
+ numEntries = read16(data, ifd_ofs, swapBytes);
+
+ for (i=0; i < numEntries; i++) {
+
+ uint32_t entryOffset = ifd_ofs + 2 + (12 * i);
+ uint32_t tag = read16(data, entryOffset, swapBytes);
+
+ switch (tag) {
+
+ case RESOLUTION_UNIT:
+ if (!read_tag(data, entryOffset, swapBytes, &Unit)) return FALSE;
+ break;
+
+ case XRESOLUTION:
+ if (!read_tag(data, entryOffset, swapBytes, &XRes)) return FALSE;
+ break;
+
+ case YRESOLUTION:
+ if (!read_tag(data, entryOffset, swapBytes, &YRes)) return FALSE;
+ break;
+
+ default:;
+ }
+
+ }
+
+ // Proceed if all found
+
+ if (XRes != -1 && YRes != -1)
+ {
+
+ // 1 = None
+ // 2 = inches
+ // 3 = cm
+
+ switch (Unit) {
+
+ case 2:
+
+ cinfo ->X_density = (UINT16) floor(XRes + 0.5);
+ cinfo ->Y_density = (UINT16) floor(YRes + 0.5);
+ break;
+
+ case 1:
+
+ cinfo ->X_density = (UINT16) floor(XRes * 2.54 + 0.5);
+ cinfo ->Y_density = (UINT16) floor(YRes * 2.54 + 0.5);
+ break;
+
+ default: return FALSE;
+ }
+
+ cinfo ->density_unit = 1; /* 1 for dots/inch, or 2 for dots/cm.*/
+
+ }
+
+
+ }
+ }
+ }
+ return FALSE;
+}
+
+
+static
+cmsBool OpenInput(const char* FileName)
+{
+ int m;
+
+ lIsITUFax = FALSE;
+ InFile = fopen(FileName, "rb");
+ if (InFile == NULL) {
+ FatalError("Cannot open '%s'", FileName);
+ }
+
+ // Now we can initialize the JPEG decompression object.
+ Decompressor.err = jpeg_std_error(&ErrorHandler.pub);
+ ErrorHandler.pub.error_exit = my_error_exit;
+ ErrorHandler.pub.output_message = my_error_exit;
+
+ jpeg_create_decompress(&Decompressor);
+ jpeg_stdio_src(&Decompressor, InFile);
+
+ for (m = 0; m < 16; m++)
+ jpeg_save_markers(&Decompressor, JPEG_APP0 + m, 0xFFFF);
+
+ // setup_read_icc_profile(&Decompressor);
+
+ fseek(InFile, 0, SEEK_SET);
+ jpeg_read_header(&Decompressor, TRUE);
+
+ return TRUE;
+}
+
+
+static
+cmsBool OpenOutput(const char* FileName)
+{
+
+ OutFile = fopen(FileName, "wb");
+ if (OutFile == NULL) {
+ FatalError("Cannot create '%s'", FileName);
+
+ }
+
+ Compressor.err = jpeg_std_error(&ErrorHandler.pub);
+ ErrorHandler.pub.error_exit = my_error_exit;
+ ErrorHandler.pub.output_message = my_error_exit;
+
+ Compressor.input_components = Compressor.num_components = 4;
+
+ jpeg_create_compress(&Compressor);
+ jpeg_stdio_dest(&Compressor, OutFile);
+ return TRUE;
+}
+
+static
+cmsBool Done(void)
+{
+ jpeg_destroy_decompress(&Decompressor);
+ jpeg_destroy_compress(&Compressor);
+ return fclose(InFile) + fclose(OutFile);
+
+}
+
+
+// Build up the pixeltype descriptor
+
+static
+cmsUInt32Number GetInputPixelType(void)
+{
+ int space, bps, extra, ColorChannels, Flavor;
+
+ lIsITUFax = IsITUFax(Decompressor.marker_list);
+ lIsPhotoshopApp13 = HandlePhotoshopAPP13(Decompressor.marker_list);
+ lIsEXIF = HandleEXIF(&Decompressor);
+
+ ColorChannels = Decompressor.num_components;
+ extra = 0; // Alpha = None
+ bps = 1; // 8 bits
+ Flavor = 0; // Vanilla
+
+ if (lIsITUFax) {
+
+ space = PT_Lab;
+ Decompressor.out_color_space = JCS_YCbCr; // Fake to don't touch
+ }
+ else
+ switch (Decompressor.jpeg_color_space) {
+
+ case JCS_GRAYSCALE: // monochrome
+ space = PT_GRAY;
+ Decompressor.out_color_space = JCS_GRAYSCALE;
+ break;
+
+ case JCS_RGB: // red/green/blue
+ space = PT_RGB;
+ Decompressor.out_color_space = JCS_RGB;
+ break;
+
+ case JCS_YCbCr: // Y/Cb/Cr (also known as YUV)
+ space = PT_RGB; // Let IJG code to do the conversion
+ Decompressor.out_color_space = JCS_RGB;
+ break;
+
+ case JCS_CMYK: // C/M/Y/K
+ space = PT_CMYK;
+ Decompressor.out_color_space = JCS_CMYK;
+ if (Decompressor.saw_Adobe_marker) // Adobe keeps CMYK inverted, so change flavor
+ Flavor = 1; // from vanilla to chocolate
+ break;
+
+ case JCS_YCCK: // Y/Cb/Cr/K
+ space = PT_CMYK;
+ Decompressor.out_color_space = JCS_CMYK;
+ if (Decompressor.saw_Adobe_marker) // ditto
+ Flavor = 1;
+ break;
+
+ default:
+ FatalError("Unsupported color space (0x%x)", Decompressor.jpeg_color_space);
+ return 0;
+ }
+
+ return (EXTRA_SH(extra)|CHANNELS_SH(ColorChannels)|BYTES_SH(bps)|COLORSPACE_SH(space)|FLAVOR_SH(Flavor));
+}
+
+
+// Rearrange pixel type to build output descriptor
+static
+cmsUInt32Number ComputeOutputFormatDescriptor(cmsUInt32Number dwInput, int OutColorSpace)
+{
+ int IsPlanar = T_PLANAR(dwInput);
+ int Channels = 0;
+ int Flavor = 0;
+
+ switch (OutColorSpace) {
+
+ case PT_GRAY:
+ Channels = 1;
+ break;
+ case PT_RGB:
+ case PT_CMY:
+ case PT_Lab:
+ case PT_YUV:
+ case PT_YCbCr:
+ Channels = 3;
+ break;
+
+ case PT_CMYK:
+ if (Compressor.write_Adobe_marker) // Adobe keeps CMYK inverted, so change flavor to chocolate
+ Flavor = 1;
+ Channels = 4;
+ break;
+ default:
+ FatalError("Unsupported output color space");
+ }
+
+ return (COLORSPACE_SH(OutColorSpace)|PLANAR_SH(IsPlanar)|CHANNELS_SH(Channels)|BYTES_SH(1)|FLAVOR_SH(Flavor));
+}
+
+
+// Equivalence between ICC color spaces and lcms color spaces
+static
+int GetProfileColorSpace(cmsHPROFILE hProfile)
+{
+ cmsColorSpaceSignature ProfileSpace = cmsGetColorSpace(NULL, hProfile);
+
+ return _cmsLCMScolorSpace(NULL, ProfileSpace);
+}
+
+static
+int GetDevicelinkColorSpace(cmsHPROFILE hProfile)
+{
+ cmsColorSpaceSignature ProfileSpace = cmsGetPCS(NULL, hProfile);
+
+ return _cmsLCMScolorSpace(NULL, ProfileSpace);
+}
+
+
+// From TRANSUPP
+
+static
+void jcopy_markers_execute(j_decompress_ptr srcinfo, j_compress_ptr dstinfo)
+{
+ jpeg_saved_marker_ptr marker;
+
+ /* In the current implementation, we don't actually need to examine the
+ * option flag here; we just copy everything that got saved.
+ * But to avoid confusion, we do not output JFIF and Adobe APP14 markers
+ * if the encoder library already wrote one.
+ */
+ for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
+
+ if (dstinfo->write_JFIF_header &&
+ marker->marker == JPEG_APP0 &&
+ marker->data_length >= 5 &&
+ GETJOCTET(marker->data[0]) == 0x4A &&
+ GETJOCTET(marker->data[1]) == 0x46 &&
+ GETJOCTET(marker->data[2]) == 0x49 &&
+ GETJOCTET(marker->data[3]) == 0x46 &&
+ GETJOCTET(marker->data[4]) == 0)
+ continue; /* reject duplicate JFIF */
+
+ if (dstinfo->write_Adobe_marker &&
+ marker->marker == JPEG_APP0+14 &&
+ marker->data_length >= 5 &&
+ GETJOCTET(marker->data[0]) == 0x41 &&
+ GETJOCTET(marker->data[1]) == 0x64 &&
+ GETJOCTET(marker->data[2]) == 0x6F &&
+ GETJOCTET(marker->data[3]) == 0x62 &&
+ GETJOCTET(marker->data[4]) == 0x65)
+ continue; /* reject duplicate Adobe */
+
+ jpeg_write_marker(dstinfo, marker->marker,
+ marker->data, marker->data_length);
+ }
+}
+
+static
+void WriteOutputFields(int OutputColorSpace)
+{
+ J_COLOR_SPACE in_space, jpeg_space;
+ int components;
+
+ switch (OutputColorSpace) {
+
+ case PT_GRAY: in_space = jpeg_space = JCS_GRAYSCALE;
+ components = 1;
+ break;
+
+ case PT_RGB: in_space = JCS_RGB;
+ jpeg_space = JCS_YCbCr;
+ components = 3;
+ break; // red/green/blue
+
+ case PT_YCbCr: in_space = jpeg_space = JCS_YCbCr;
+ components = 3;
+ break; // Y/Cb/Cr (also known as YUV)
+
+ case PT_CMYK: in_space = JCS_CMYK;
+ jpeg_space = JCS_YCCK;
+ components = 4;
+ break; // C/M/Y/components
+
+ case PT_Lab: in_space = jpeg_space = JCS_YCbCr;
+ components = 3;
+ break; // Fake to don't touch
+ default:
+ FatalError("Unsupported output color space");
+ return;
+ }
+
+
+ if (jpegQuality >= 100) {
+
+ // avoid destructive conversion when asking for lossless compression
+ jpeg_space = in_space;
+ }
+
+ Compressor.in_color_space = in_space;
+ Compressor.jpeg_color_space = jpeg_space;
+ Compressor.input_components = Compressor.num_components = components;
+ jpeg_set_defaults(&Compressor);
+ jpeg_set_colorspace(&Compressor, jpeg_space);
+
+
+ // Make sure to pass resolution through
+ if (OutputColorSpace == PT_CMYK)
+ Compressor.write_JFIF_header = 1;
+
+ // Avoid subsampling on high quality factor
+ jpeg_set_quality(&Compressor, jpegQuality, 1);
+ if (jpegQuality >= 70) {
+
+ int i;
+ for(i=0; i < Compressor.num_components; i++) {
+
+ Compressor.comp_info[i].h_samp_factor = 1;
+ Compressor.comp_info[i].v_samp_factor = 1;
+ }
+
+ }
+
+}
+
+
+static
+void DoEmbedProfile(const char* ProfileFile)
+{
+ FILE* f;
+ size_t size, EmbedLen;
+ cmsUInt8Number* EmbedBuffer;
+
+ f = fopen(ProfileFile, "rb");
+ if (f == NULL) return;
+
+ size = cmsfilelength(f);
+ EmbedBuffer = (cmsUInt8Number*) malloc(size + 1);
+ EmbedLen = fread(EmbedBuffer, 1, size, f);
+ fclose(f);
+ EmbedBuffer[EmbedLen] = 0;
+
+ write_icc_profile (&Compressor, EmbedBuffer, (unsigned int) EmbedLen);
+ free(EmbedBuffer);
+}
+
+
+
+static
+int DoTransform(cmsHTRANSFORM hXForm, int OutputColorSpace)
+{
+ JSAMPROW ScanLineIn;
+ JSAMPROW ScanLineOut;
+
+
+ //Preserve resolution values from the original
+ // (Thanks to Robert Bergs for finding out this bug)
+ Compressor.density_unit = Decompressor.density_unit;
+ Compressor.X_density = Decompressor.X_density;
+ Compressor.Y_density = Decompressor.Y_density;
+
+ // Compressor.write_JFIF_header = 1;
+
+ jpeg_start_decompress(&Decompressor);
+ jpeg_start_compress(&Compressor, TRUE);
+
+ if (OutputColorSpace == PT_Lab)
+ SetITUFax(&Compressor);
+
+ // Embed the profile if needed
+ if (EmbedProfile && cOutProf)
+ DoEmbedProfile(cOutProf);
+
+ ScanLineIn = (JSAMPROW) malloc(Decompressor.output_width * Decompressor.num_components);
+ ScanLineOut = (JSAMPROW) malloc(Compressor.image_width * Compressor.num_components);
+
+ while (Decompressor.output_scanline <
+ Decompressor.output_height) {
+
+ jpeg_read_scanlines(&Decompressor, &ScanLineIn, 1);
+
+ cmsDoTransform(NULL, hXForm, ScanLineIn, ScanLineOut, Decompressor.output_width);
+
+ jpeg_write_scanlines(&Compressor, &ScanLineOut, 1);
+ }
+
+ free(ScanLineIn);
+ free(ScanLineOut);
+
+ jpeg_finish_decompress(&Decompressor);
+ jpeg_finish_compress(&Compressor);
+
+ return TRUE;
+}
+
+
+
+// Transform one image
+
+static
+int TransformImage(char *cDefInpProf, char *cOutputProf)
+{
+ cmsHPROFILE hIn, hOut, hProof;
+ cmsHTRANSFORM xform;
+ cmsUInt32Number wInput, wOutput;
+ int OutputColorSpace;
+ cmsUInt32Number dwFlags = 0;
+ cmsUInt32Number EmbedLen;
+ cmsUInt8Number* EmbedBuffer;
+
+
+ cmsSetAdaptationState(ObserverAdaptationState);
+
+ if (BlackPointCompensation) {
+
+ dwFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
+ }
+
+
+ switch (PrecalcMode) {
+
+ case 0: dwFlags |= cmsFLAGS_NOOPTIMIZE; break;
+ case 2: dwFlags |= cmsFLAGS_HIGHRESPRECALC; break;
+ case 3: dwFlags |= cmsFLAGS_LOWRESPRECALC; break;
+ default:;
+ }
+
+
+ if (GamutCheck) {
+ dwFlags |= cmsFLAGS_GAMUTCHECK;
+ cmsSetAlarmCodes(Alarm);
+ }
+
+ // Take input color space
+ wInput = GetInputPixelType();
+
+ if (lIsDeviceLink) {
+
+ hIn = cmsOpenProfileFromFile(cDefInpProf, "r");
+ hOut = NULL;
+ hProof = NULL;
+ }
+ else {
+
+ if (!IgnoreEmbedded && read_icc_profile(&Decompressor, &EmbedBuffer, &EmbedLen))
+ {
+ hIn = cmsOpenProfileFromMem(EmbedBuffer, EmbedLen);
+
+ if (Verbose) {
+
+ fprintf(stdout, " (Embedded profile found)\n");
+ PrintProfileInformation(NULL, hIn);
+ fflush(stdout);
+ }
+
+ if (hIn != NULL && SaveEmbedded != NULL)
+ SaveMemoryBlock(EmbedBuffer, EmbedLen, SaveEmbedded);
+
+ free(EmbedBuffer);
+ }
+ else
+ {
+ // Default for ITU/Fax
+ if (cDefInpProf == NULL && T_COLORSPACE(wInput) == PT_Lab)
+ cDefInpProf = "*Lab";
+
+ if (cDefInpProf != NULL && cmsstrcasecmp(cDefInpProf, "*lab") == 0)
+ hIn = CreateITU2PCS_ICC();
+ else
+ hIn = OpenStockProfile(0, cDefInpProf);
+ }
+
+ if (cOutputProf != NULL && cmsstrcasecmp(cOutputProf, "*lab") == 0)
+ hOut = CreatePCS2ITU_ICC();
+ else
+ hOut = OpenStockProfile(0, cOutputProf);
+
+ hProof = NULL;
+ if (cProofing != NULL) {
+
+ hProof = OpenStockProfile(0, cProofing);
+ if (hProof == NULL) {
+ FatalError("Proofing profile couldn't be read.");
+ }
+ dwFlags |= cmsFLAGS_SOFTPROOFING;
+ }
+ }
+
+ if (!hIn)
+ FatalError("Input profile couldn't be read.");
+ if (!lIsDeviceLink && !hOut)
+ FatalError("Output profile couldn't be read.");
+
+ // Assure both, input profile and input JPEG are on same colorspace
+ if (cmsGetColorSpace(NULL, hIn) != _cmsICCcolorSpace(NULL, T_COLORSPACE(wInput)))
+ FatalError("Input profile is not operating in proper color space");
+
+
+ // Output colorspace is given by output profile
+
+ if (lIsDeviceLink) {
+ OutputColorSpace = GetDevicelinkColorSpace(hIn);
+ }
+ else {
+ OutputColorSpace = GetProfileColorSpace(hOut);
+ }
+
+ jpeg_copy_critical_parameters(&Decompressor, &Compressor);
+
+ WriteOutputFields(OutputColorSpace);
+
+ wOutput = ComputeOutputFormatDescriptor(wInput, OutputColorSpace);
+
+
+ xform = cmsCreateProofingTransform(hIn, wInput,
+ hOut, wOutput,
+ hProof, Intent,
+ ProofingIntent, dwFlags);
+ if (xform == NULL)
+ FatalError("Cannot transform by using the profiles");
+
+ DoTransform(xform, OutputColorSpace);
+
+
+ jcopy_markers_execute(&Decompressor, &Compressor);
+
+ cmsDeleteTransform(NULL, xform);
+ cmsCloseProfile(NULL, hIn);
+ cmsCloseProfile(NULL, hOut);
+ if (hProof) cmsCloseProfile(NULL, hProof);
+
+ return 1;
+}
+
+
+// Simply print help
+
+static
+void Help(int level)
+{
+ fprintf(stderr, "little cms ICC profile applier for JPEG - v3.2 [LittleCMS %2.2f]\n\n", LCMS_VERSION / 1000.0);
+
+ switch(level) {
+
+ default:
+ case 0:
+
+ fprintf(stderr, "usage: jpgicc [flags] input.jpg output.jpg\n");
+
+ fprintf(stderr, "\nflags:\n\n");
+ fprintf(stderr, "%cv - Verbose\n", SW);
+ fprintf(stderr, "%ci<profile> - Input profile (defaults to sRGB)\n", SW);
+ fprintf(stderr, "%co<profile> - Output profile (defaults to sRGB)\n", SW);
+
+ PrintRenderingIntents();
+
+
+ fprintf(stderr, "%cb - Black point compensation\n", SW);
+ fprintf(stderr, "%cd<0..1> - Observer adaptation state (abs.col. only)\n", SW);
+ fprintf(stderr, "%cn - Ignore embedded profile\n", SW);
+ fprintf(stderr, "%ce - Embed destination profile\n", SW);
+ fprintf(stderr, "%cs<new profile> - Save embedded profile as <new profile>\n", SW);
+
+ fprintf(stderr, "\n");
+
+ fprintf(stderr, "%cc<0,1,2,3> - Precalculates transform (0=Off, 1=Normal, 2=Hi-res, 3=LoRes) [defaults to 1]\n", SW);
+ fprintf(stderr, "\n");
+
+ fprintf(stderr, "%cp<profile> - Soft proof profile\n", SW);
+ fprintf(stderr, "%cm<0,1,2,3> - SoftProof intent\n", SW);
+ fprintf(stderr, "%cg - Marks out-of-gamut colors on softproof\n", SW);
+ fprintf(stderr, "%c!<r>,<g>,<b> - Out-of-gamut marker channel values\n", SW);
+
+ fprintf(stderr, "\n");
+ fprintf(stderr, "%cq<0..100> - Output JPEG quality\n", SW);
+
+ fprintf(stderr, "\n");
+ fprintf(stderr, "%ch<0,1,2,3> - More help\n", SW);
+ break;
+
+ case 1:
+
+ fprintf(stderr, "Examples:\n\n"
+ "To color correct from scanner to sRGB:\n"
+ "\tjpgicc %ciscanner.icm in.jpg out.jpg\n"
+ "To convert from monitor1 to monitor2:\n"
+ "\tjpgicc %cimon1.icm %comon2.icm in.jpg out.jpg\n"
+ "To make a CMYK separation:\n"
+ "\tjpgicc %coprinter.icm inrgb.jpg outcmyk.jpg\n"
+ "To recover sRGB from a CMYK separation:\n"
+ "\tjpgicc %ciprinter.icm incmyk.jpg outrgb.jpg\n"
+ "To convert from CIELab ITU/Fax JPEG to sRGB\n"
+ "\tjpgicc in.jpg out.jpg\n\n",
+ SW, SW, SW, SW, SW);
+ break;
+
+ case 2:
+ PrintBuiltins();
+ break;
+
+ case 3:
+
+ fprintf(stderr, "This program is intended to be a demo of the little cms\n"
+ "engine. Both lcms and this program are freeware. You can\n"
+ "obtain both in source code at http://www.littlecms.com\n"
+ "For suggestions, comments, bug reports etc. send mail to\n"
+ "marti@littlecms.com\n\n");
+ break;
+ }
+
+ exit(0);
+}
+
+
+// The toggles stuff
+
+static
+void HandleSwitches(int argc, char *argv[])
+{
+ int s;
+
+ while ((s=xgetopt(argc,argv,"bBnNvVGgh:H:i:I:o:O:P:p:t:T:c:C:Q:q:M:m:L:l:eEs:S:!:D:d:")) != EOF) {
+
+ switch (s)
+ {
+
+ case 'b':
+ case 'B':
+ BlackPointCompensation = TRUE;
+ break;
+
+ case 'd':
+ case 'D': ObserverAdaptationState = atof(xoptarg);
+ if (ObserverAdaptationState < 0 ||
+ ObserverAdaptationState > 1.0)
+ FatalError("Adaptation state should be 0..1");
+ break;
+
+ case 'v':
+ case 'V':
+ Verbose = TRUE;
+ break;
+
+ case 'i':
+ case 'I':
+ if (lIsDeviceLink)
+ FatalError("Device-link already specified");
+
+ cInpProf = xoptarg;
+ break;
+
+ case 'o':
+ case 'O':
+ if (lIsDeviceLink)
+ FatalError("Device-link already specified");
+
+ cOutProf = xoptarg;
+ break;
+
+ case 'l':
+ case 'L':
+ if (cInpProf != NULL || cOutProf != NULL)
+ FatalError("input/output profiles already specified");
+
+ cInpProf = xoptarg;
+ lIsDeviceLink = TRUE;
+ break;
+
+ case 'p':
+ case 'P':
+ cProofing = xoptarg;
+ break;
+
+ case 't':
+ case 'T':
+ Intent = atoi(xoptarg);
+ break;
+
+ case 'N':
+ case 'n':
+ IgnoreEmbedded = TRUE;
+ break;
+
+ case 'e':
+ case 'E':
+ EmbedProfile = TRUE;
+ break;
+
+
+ case 'g':
+ case 'G':
+ GamutCheck = TRUE;
+ break;
+
+ case 'c':
+ case 'C':
+ PrecalcMode = atoi(xoptarg);
+ if (PrecalcMode < 0 || PrecalcMode > 2)
+ FatalError("Unknown precalc mode '%d'", PrecalcMode);
+ break;
+
+ case 'H':
+ case 'h': {
+
+ int a = atoi(xoptarg);
+ Help(a);
+ }
+ break;
+
+ case 'q':
+ case 'Q':
+ jpegQuality = atoi(xoptarg);
+ if (jpegQuality > 100) jpegQuality = 100;
+ if (jpegQuality < 0) jpegQuality = 0;
+ break;
+
+ case 'm':
+ case 'M':
+ ProofingIntent = atoi(xoptarg);
+ break;
+
+ case 's':
+ case 'S': SaveEmbedded = xoptarg;
+ break;
+
+ case '!':
+ if (sscanf(xoptarg, "%hu,%hu,%hu", &Alarm[0], &Alarm[1], &Alarm[2]) == 3) {
+ int i;
+ for (i=0; i < 3; i++) {
+ Alarm[i] = (Alarm[i] << 8) | Alarm[i];
+ }
+ }
+ break;
+
+ default:
+
+ FatalError("Unknown option - run without args to see valid ones");
+ }
+
+ }
+}
+
+
+int main(int argc, char* argv[])
+{
+ InitUtils("jpgicc");
+
+ HandleSwitches(argc, argv);
+
+ if ((argc - xoptind) != 2) {
+ Help(0);
+ }
+
+ OpenInput(argv[xoptind]);
+ OpenOutput(argv[xoptind+1]);
+
+ TransformImage(cInpProf, cOutProf);
+
+
+ if (Verbose) { fprintf(stdout, "\n"); fflush(stdout); }
+
+ Done();
+
+ return 0;
+}
+
+
+