jbig2dec
Ralph Giles <[email protected]> Mon, 08 Jul 2002 06:40:18 -0700
| Newsgroups | gmane.comp.printing.ghostscript.jbig2dec.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/jbig2dec/jbig2dec
In directory usw-pr-cvs1:/tmp/cvs-serv18403
Modified Files:
autogen.sh configure.ac jbig2.c jbig2_arith.c
jbig2_arith_iaid.c jbig2_arith_int.c jbig2_generic.c
jbig2_huffman.c jbig2_image.c jbig2_image_png.c jbig2_mmr.c
jbig2_page.c jbig2_segment.c jbig2_symbol_dict.c jbig2_text.c
jbig2dec.c
Log Message:
Work around stdint.h portability problems. If the C99 header isn't available,
look for uint32_t in a few other likely headers. Also try and discover appropriate
sizes and use our own typedefs if no useful header is found.
All this goes into a new generated header file 'config_types.h'. We abuse
autogen.sh to create the template so it doesn't clutter cvs for non-autotools
builds.
Include config.h and config_types.h into every file that includes jbig2_priv.h
so ensure the types are defined.
Index: autogen.sh
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/autogen.sh,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- autogen.sh 8 May 2002 00:59:20 -0000 1.1
+++ autogen.sh 8 Jul 2002 13:40:15 -0000 1.2
@@ -23,11 +23,37 @@
echo " aclocal $ACLOCAL_FLAGS"
aclocal $ACLOCAL_FLAGS
+
echo " autoheader"
autoheader
+
+echo " creating config_types.h.in"
+cat >config_types.h.in <<EOF
+/*
+ generated header with missing types for the
+ jbig2dec program and library. include this
+ after config.h, within the HAVE_CONFIG_H
+ ifdef
+*/
+
+#ifndef HAVE_STDINT_H
+# ifdef JBIG2_REPLACE_STDINT_H
+# include <@JBIG2_STDINT_H@>
+# else
+ typedef unsigned @JBIG2_INT32_T@ uint32_t;
+ typedef unsigned @JBIG2_INT16_T@ uint16_t;
+ typedef unsigned @JBIG2_INT8_T@ uint8_t;
+ typedef signed @JBIG2_INT32_T@ int32_t;
+ typedef signed @JBIG2_INT16_T@ int16_t;
+ typedef signed @JBIG2_INT8_T@ int8_t;
+# endif /* JBIG2_REPLACE_STDINT */
+#endif /* HAVE_STDINT_H */
+EOF
+
echo " automake --add-missing $AUTOMAKE_FLAGS"
automake --add-missing $AUTOMAKE_FLAGS
echo " running autoconf"
+
autoconf
if test -z "$*"; then
Index: configure.ac
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/configure.ac,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- configure.ac 15 Jun 2002 15:47:21 -0000 1.3
+++ configure.ac 8 Jul 2002 13:40:15 -0000 1.4
@@ -18,15 +18,86 @@
# Checks for libraries.
AC_CHECK_LIB([png], [png_check_sig], [
+ AC_CHECK_HEADER([png.h], [
+ AC_CHECK_LIB([z], [deflate], [
AC_DEFINE(HAVE_LIBPNG, 1, [Define if libpng is available (-lpng)])
- LIBS="$LIBS -lpng"
+ LIBS="$LIBS -lpng -lz"
LIBOBJS="$LIBOBJS jbig2_image_png.o"
- AC_CHECK_LIB([z], [deflate])
+ ])
+ ])
])
# Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS([libintl.h stddef.h stdint.h stdlib.h string.h strings.h unistd.h])
+AC_CHECK_HEADERS([libintl.h stddef.h unistd.h strings.h])
+
+dnl We assume the fixed-size types from stdint.h. If that header is are not available,
+dnl look for the same types in a few other headers. We also attempt to define them
+dnl ourselves, but only use those is the native versions aren't available.
+dnl The substitutions happen in a file config_types.h, whose template is
+dnl created by autogen.sh
+stdint_types_in="no_replacement_found"
+stdint_types_discovered="yes"
+AC_CHECK_SIZEOF(char)
+AC_CHECK_SIZEOF(short)
+AC_CHECK_SIZEOF(int)
+AC_CHECK_SIZEOF(long)
+if test $ac_cv_sizeof_char = 1; then
+ AC_MSG_RESULT([can define int8_t as char])
+ int8_type="char"
+else
+ stdint_types_discovered="no"
+fi
+if test $ac_cv_sizeof_short = 2; then
+ AC_MSG_RESULT([can define int16_t as short])
+ int16_type="short"
+elif test $ac_cv_sizeof_char = 2; then
+ AC_MSG_RESULT([can define int16_t as char])
+ int16_type="char"
+elif test $ac_cv_sizeof_int = 2; then
+ AC_MSG_RESULT([can define int16_t as int])
+ int16_type="char"
+else
+ stdint_types_discovered="no"
+fi
+if test $ac_cv_sizeof_int = 4; then
+ AC_MSG_RESULT([can define int32_t as int])
+ int32_type="int"
+elif test $ac_cv_sizeof_long = 4; then
+ AC_MSG_RESULT([can define int32_t as long])
+ int32_type="long"
+elif test $ac_cv_sizeof_short = 4; then
+ AC_MSG_RESULT([can define int32_t as short])
+ int32_type="short"
+else
+ stdint_types_discovered="no"
+fi
+AC_CHECK_HEADER([stdint.h])
+if test "x$ac_cv_header_stdint_h" != "xyes"; then
+ for include in sys/types.h inttypes.h sys/inttypes.h sys/int_types.h ; do
+ AC_MSG_CHECKING([for uint32_t in $include])
+ AC_TRY_COMPILE([#include <$include>], [uint32_t canary;], [
+ AC_MSG_RESULT([yes])
+ stdint_types_in="$include"
+ break;
+ ], AC_MSG_RESULT([no])
+ )
+ done
+ if test "x$stding_types_in" != "xno_replacement_found"; then
+ AC_MSG_RESULT([Adding $stdint_types_in to config header for stdint types])
+ AC_DEFINE([JBIG2_REPLACE_STDINT_H],,
+ [set by configure if an alternate header with the stdint.h types is found])
+ elif test "x$stdint_types_discovered" = "xno"; then
+ AC_MSG_ERROR([
+Unable to find suitable definitions of the stdint.h types (uint32_t and friends)
+You will have to define these yourself in a separate header
+ ])
+ fi
+fi
+AC_SUBST(JBIG2_INT32_T, [$int32_type])
+AC_SUBST(JBIG2_INT16_T, [$int16_type])
+AC_SUBST(JBIG2_INT8_T, [$int8_type])
+AC_SUBST(JBIG2_STDINT_H, [$stdint_types_in])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
@@ -45,5 +116,5 @@
# generate output
AC_SUBST(LIBOJBS)
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([Makefile config_types.h])
AC_OUTPUT
Index: jbig2.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- jbig2.c 4 Jul 2002 16:33:44 -0000 1.12
+++ jbig2.c 8 Jul 2002 13:40:15 -0000 1.13
@@ -11,10 +11,17 @@
$Id$
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
#include <stdint.h>
+#endif
+
+#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-#include <stdio.h>
#include "jbig2.h"
#include "jbig2_priv.h"
Index: jbig2_arith.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_arith.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- jbig2_arith.c 5 Jun 2002 00:15:57 -0000 1.8
+++ jbig2_arith.c 8 Jul 2002 13:40:15 -0000 1.9
@@ -11,9 +11,16 @@
$Id$
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
-#include <stdint.h>
#include "jbig2.h"
#include "jbig2_priv.h"
Index: jbig2_arith_iaid.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_arith_iaid.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- jbig2_arith_iaid.c 4 Jul 2002 13:34:29 -0000 1.2
+++ jbig2_arith_iaid.c 8 Jul 2002 13:40:15 -0000 1.3
@@ -1,12 +1,19 @@
/* Annex A.3 */
-#ifdef VERBOSE
-#include <stdio.h> /* for debug printing only */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
#endif
#include <stddef.h>
-#include <stdint.h>
#include <string.h> /* memset() */
+
+#ifdef VERBOSE
+#include <stdio.h> /* for debug printing only */
+#endif
#include "jbig2.h"
#include "jbig2_priv.h"
Index: jbig2_arith_int.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_arith_int.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- jbig2_arith_int.c 4 Jul 2002 13:34:29 -0000 1.3
+++ jbig2_arith_int.c 8 Jul 2002 13:40:15 -0000 1.4
@@ -1,7 +1,14 @@
/* Annex A */
-#include <stddef.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
#include <stdint.h>
+#endif
+
+#include <stddef.h>
#include <string.h> /* memset() */
#include "jbig2.h"
Index: jbig2_generic.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_generic.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- jbig2_generic.c 4 Jul 2002 13:34:29 -0000 1.10
+++ jbig2_generic.c 8 Jul 2002 13:40:15 -0000 1.11
@@ -15,13 +15,21 @@
* Generic region handlers.
**/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
#include <stdint.h>
+#endif
+
#include <stddef.h>
#include <string.h> /* memcpy(), memset() */
#ifdef OUTPUT_PBM
#include <stdio.h>
#endif
+
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
Index: jbig2_huffman.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_huffman.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- jbig2_huffman.c 15 Jun 2002 16:02:53 -0000 1.8
+++ jbig2_huffman.c 8 Jul 2002 13:40:15 -0000 1.9
@@ -14,6 +14,14 @@
/* Huffman table decoding procedures
-- See Annex B of the JBIG2 draft spec */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
#include <stdlib.h>
#include "jbig2.h"
Index: jbig2_image.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_image.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- jbig2_image.c 4 Jul 2002 13:34:29 -0000 1.16
+++ jbig2_image.c 8 Jul 2002 13:40:15 -0000 1.17
@@ -11,9 +11,16 @@
$Id$
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
-#include <stdint.h>
#include <string.h> /* memcpy() */
#include "jbig2.h"
Index: jbig2_image_png.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_image_png.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- jbig2_image_png.c 3 Jul 2002 00:30:20 -0000 1.3
+++ jbig2_image_png.c 8 Jul 2002 13:40:15 -0000 1.4
@@ -11,6 +11,14 @@
$Id$
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <png.h>
Index: jbig2_mmr.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_mmr.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- jbig2_mmr.c 4 Jul 2002 13:34:29 -0000 1.5
+++ jbig2_mmr.c 8 Jul 2002 13:40:15 -0000 1.6
@@ -2,7 +2,14 @@
in Ghostscript.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
#include <stdint.h>
+#endif
+
#include <stddef.h>
#include <stdio.h>
Index: jbig2_page.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_page.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- jbig2_page.c 7 Jul 2002 20:38:26 -0000 1.9
+++ jbig2_page.c 8 Jul 2002 13:40:15 -0000 1.10
@@ -11,6 +11,14 @@
$Id$
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
#include <stdlib.h>
#include "jbig2.h"
Index: jbig2_segment.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_segment.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- jbig2_segment.c 7 Jul 2002 20:38:26 -0000 1.13
+++ jbig2_segment.c 8 Jul 2002 13:40:15 -0000 1.14
@@ -11,8 +11,15 @@
$Id$
*/
-#include <stdlib.h> /* size_t */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
#include <stdint.h>
+#endif
+
+#include <stddef.h> /* size_t */
#include "jbig2.h"
#include "jbig2_priv.h"
Index: jbig2_symbol_dict.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_symbol_dict.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- jbig2_symbol_dict.c 4 Jul 2002 13:34:29 -0000 1.14
+++ jbig2_symbol_dict.c 8 Jul 2002 13:40:15 -0000 1.15
@@ -13,13 +13,16 @@
symbol dictionary segment decode and support
*/
-#include <stddef.h>
-#include <stdint.h>
-#include <string.h> /* memset() */
-
#ifdef HAVE_CONFIG_H
#include "config.h"
+#include "config_types.h"
#endif
+#if HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+#include <stddef.h>
+#include <string.h> /* memset() */
#include "jbig2.h"
#include "jbig2_priv.h"
Index: jbig2_text.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_text.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- jbig2_text.c 7 Jul 2002 20:38:26 -0000 1.11
+++ jbig2_text.c 8 Jul 2002 13:40:15 -0000 1.12
@@ -11,15 +11,17 @@
$Id$
*/
-#include <stddef.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h> /* memset() */
-
#ifdef HAVE_CONFIG_H
#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
#endif
+#include <stddef.h>
+#include <string.h> /* memset() */
+
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
@@ -144,9 +146,7 @@
} else {
code = jbig2_arith_int_decode(IADT, as, &STRIPT);
}
-#ifdef DEBUG
- fprintf(stderr, "decoded stript value %d (scale to %d)\n", STRIPT, -STRIPT*params->SBSTRIPS);
-#endif
+
/* 6.4.5 (2) */
STRIPT *= -(params->SBSTRIPS);
FIRSTS = 0;
@@ -162,9 +162,7 @@
}
DT *= params->SBSTRIPS;
STRIPT += DT;
-#ifdef DEBUG
- fprintf(stderr, "decoded DT = %d, STRIPT = %d\n", DT, STRIPT);
-#endif
+
first_symbol = TRUE;
/* 6.4.5 (3c) - decode symbols in strip */
for (;;) {
@@ -179,9 +177,7 @@
FIRSTS += DFS;
CURS = FIRSTS;
first_symbol = FALSE;
-#ifdef DEBUG
- fprintf(stderr, "decoded DFS = %d (first symbol) CURS = %d\n", DFS, CURS);
-#endif
+
} else {
/* (3c.ii / 6.4.8) */
if (params->SBHUFF) {
@@ -190,15 +186,9 @@
code = jbig2_arith_int_decode(IADS, as, &IDS);
}
if (code) {
-#ifdef DEBUG
- fprintf(stderr, "Symbol instance S coordinate OOB: End of Strip\n");
-#endif
break;
}
CURS += IDS + params->SBDSOFFSET;
-#ifdef DEBUG
- fprintf(stderr, "decoded IDS = %d, CURS = %d\n", IDS, CURS);
-#endif
}
/* (3c.iii / 6.4.9) */
@@ -210,9 +200,7 @@
code = jbig2_arith_int_decode(IAIT, as, &CURT);
}
T = STRIPT + CURT;
-#ifdef DEBUG
- fprintf(stderr, "decoded CURT = %d, STRIPT = %d, T = %d\n", CURT, STRIPT, T);
-#endif
+
/* (3b.iv / 6.4.10) decode the symbol id */
if (params->SBHUFF) {
/* todo */
@@ -223,9 +211,7 @@
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"symbol id out of range! (%d/%d)", ID, max_id);
}
-#ifdef DEBUG
- fprintf(stderr, "decoded symbol id = %d (code = %d)\n", ID, code);
-#endif
+
/* (3c.v) look up the symbol bitmap IB */
{
int id = ID;
Index: jbig2dec.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2dec.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- jbig2dec.c 4 Jul 2002 16:33:44 -0000 1.26
+++ jbig2dec.c 8 Jul 2002 13:40:15 -0000 1.27
@@ -11,14 +11,18 @@
$Id$
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-
#ifdef HAVE_CONFIG_H
#include "config.h"
+#include "config_types.h"
#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+#include <stdio.h>
+# include <stdlib.h>
+# include <stddef.h>
+# include <string.h>
#ifdef HAVE_GETOPT_H
# include <getopt.h>