Added configure options to disable arithmetic encoding/decoding


git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@300 632fc199-4ca6-4c93-a231-07263d6284db
diff --git a/ChangeLog.txt b/ChangeLog.txt
index 068fafd..bb1aabf 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -18,7 +18,8 @@
 [6] All symbols in the libjpeg-turbo dynamic library are now versioned, even
 when the library is built with libjpeg v6b emulation.
 
-[7] Added arithmetic encoding and decoding support.
+[7] Added arithmetic encoding and decoding support (can be disabled via
+configure options)
 
 
 Significant changes since 1.0.0
diff --git a/Makefile.am b/Makefile.am
index 2450930..c17c912 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,15 +7,32 @@
 HDRS = jchuff.h jdct.h jdhuff.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
 	jpegint.h jpeglib.h jversion.h jsimd.h jsimddct.h jpegcomp.h
 
-libjpeg_la_SOURCES = $(HDRS) jaricom.c jcapimin.c jcapistd.c jcarith.c \
-	jccoefct.c jccolor.c jcdctmgr.c jchuff.c jcinit.c jcmainct.c \
-	jcmarker.c jcmaster.c jcomapi.c jcparam.c jcphuff.c jcprepct.c \
-	jcsample.c jctrans.c jdapimin.c jdapistd.c jdarith.c \
-	jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
-	jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
-	jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
-	jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c \
-	jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c
+libjpeg_la_SOURCES = $(HDRS) jcapimin.c jcapistd.c jccoefct.c jccolor.c \
+	jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \
+	jcomapi.c jcparam.c jcphuff.c jcprepct.c jcsample.c jctrans.c \
+	jdapimin.c jdapistd.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \
+	jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \
+	jdmerge.c jdphuff.c jdpostct.c jdsample.c jdtrans.c jerror.c \
+	jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c \
+	jidctred.c jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c
+
+if WITH_ARITH
+
+libjpeg_la_SOURCES += jaricom.c
+
+endif
+
+if WITH_ARITH_ENC
+
+libjpeg_la_SOURCES += jcarith.c
+
+endif
+
+if WITH_ARITH_DEC
+
+libjpeg_la_SOURCES += jdarith.c
+
+endif
 
 libturbojpeg_la_SOURCES = $(libjpeg_la_SOURCES) turbojpegl.c turbojpeg.h \
 	turbojpeg-mapfile
@@ -128,14 +145,18 @@
 endif
 	./djpeg -dct int -bmp -colors 256 -outfile testout.bmp  $(srcdir)/testorig.jpg
 	cmp $(srcdir)/testimg.bmp testout.bmp
+if WITH_ARITH_ENC
 	./cjpeg -dct int -arithmetic -outfile testoutari.jpg $(srcdir)/testorig.ppm
 	cmp $(srcdir)/testimgari.jpg testoutari.jpg
+	./jpegtran -arithmetic -outfile testouta.jpg $(srcdir)/testimgint.jpg
+	cmp $(srcdir)/testimgari.jpg testouta.jpg
+endif
+if WITH_ARITH_DEC
 	./djpeg -dct int -fast -ppm -outfile testoutari.ppm $(srcdir)/testimgari.jpg
 	cmp $(srcdir)/testimgari.ppm testoutari.ppm
-	./jpegtran -arithmetic -outfile testouta.jpg testoutint.jpg
-	cmp $(srcdir)/testimgari.jpg testouta.jpg
-	./jpegtran -outfile testouta.jpg testoutari.jpg
+	./jpegtran -outfile testouta.jpg $(srcdir)/testimgari.jpg
 	cmp $(srcdir)/testimgint.jpg testouta.jpg
+endif
 	./cjpeg -dct int -progressive -outfile testoutp.jpg $(srcdir)/testorig.ppm
 	cmp $(srcdir)/testimgp.jpg testoutp.jpg
 	./jpegtran -outfile testoutt.jpg testoutp.jpg
diff --git a/README-turbo.txt b/README-turbo.txt
index b6789f3..9aa44ab 100755
--- a/README-turbo.txt
+++ b/README-turbo.txt
@@ -270,8 +270,5 @@
 -- libjpeg: Fancy downsampling in compressor
    cinfo.do_fancy_downsampling is silently ignored.
 
--- libjpeg: Arithmetic coding/decoding
-   Not supported due to patent concerns.
-
 -- jpegtran: Scaling
    Seems to depend on the DCT scaling feature, which isn't supported.
diff --git a/configure.ac b/configure.ac
index fb022f2..7faf146 100644
--- a/configure.ac
+++ b/configure.ac
@@ -207,6 +207,30 @@
 AC_SUBST(VERSION_SCRIPT_FLAG)
 AC_SUBST(ANON_VERSION_SCRIPT_FLAG)
 
+AC_MSG_CHECKING([whether to use arithmetic encoding])
+AC_ARG_WITH([arith-enc],
+    AC_HELP_STRING([--without-arith-enc], [Omit arithmetic encoding support]))
+if test "x$with_arith_enc" = "xno"; then
+    AC_MSG_RESULT(no)
+else
+    AC_DEFINE([C_ARITH_CODING_SUPPORTED], [1], [Support arithmetic encoding])
+    AC_MSG_RESULT(yes)
+fi
+AM_CONDITIONAL([WITH_ARITH_ENC], [test "x$with_arith_enc" != "xno"])
+
+AC_MSG_CHECKING([whether to use arithmetic decoding])
+AC_ARG_WITH([arith-dec],
+    AC_HELP_STRING([--without-arith-dec], [Omit arithmetic decoding support]))
+if test "x$with_arith_dec" = "xno"; then
+    AC_MSG_RESULT(no)
+else
+    AC_DEFINE([D_ARITH_CODING_SUPPORTED], [1], [Support arithmetic decoding])
+    AC_MSG_RESULT(yes)
+fi
+AM_CONDITIONAL([WITH_ARITH_DEC], [test "x$with_arith_dec" != "xno"])
+
+AM_CONDITIONAL([WITH_ARITH], [test "x$with_arith_dec" != "xno" -o "x$with_arith_enc" != "xno"])
+
 # SIMD is optional
 AC_ARG_WITH([simd],
     AC_HELP_STRING([--without-simd],[Omit accelerated SIMD routines.]))
diff --git a/jconfig.h.in b/jconfig.h.in
index c8d0dd7..670afab 100644
--- a/jconfig.h.in
+++ b/jconfig.h.in
@@ -3,6 +3,12 @@
  */
 #define JPEG_LIB_VERSION  62	/* Version 6b */
 
+/* Support arithmetic encoding */
+#undef C_ARITH_CODING_SUPPORTED
+
+/* Support arithmetic decoding */
+#undef D_ARITH_CODING_SUPPORTED
+
 /* Define if your compiler supports prototypes */
 #undef HAVE_PROTOTYPES
 
diff --git a/jerror.h b/jerror.h
index 0eb0341..88f019e 100644
--- a/jerror.h
+++ b/jerror.h
@@ -41,7 +41,7 @@
 
 /* For maintenance convenience, list is alphabetical by message code name */
 JMESSAGE(JERR_ARITH_NOTIMPL,
-	 "Sorry, there are legal restrictions on arithmetic coding")
+	 "Sorry, arithmetic coding is not implemented")
 JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
 JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
 JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
diff --git a/jmorecfg.h b/jmorecfg.h
index 9ab2a90..c14a5f3 100644
--- a/jmorecfg.h
+++ b/jmorecfg.h
@@ -265,7 +265,6 @@
 
 /* Encoder capability options: */
 
-#define C_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
 #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
 #define C_PROGRESSIVE_SUPPORTED	    /* Progressive JPEG? (Requires MULTISCAN)*/
 #define ENTROPY_OPT_SUPPORTED	    /* Optimization of entropy coding parms? */
@@ -281,7 +280,6 @@
 
 /* Decoder capability options: */
 
-#define D_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
 #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
 #define D_PROGRESSIVE_SUPPORTED	    /* Progressive JPEG? (Requires MULTISCAN)*/
 #define SAVE_MARKERS_SUPPORTED	    /* jpeg_save_markers() needed? */