aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/monniaux/bitsliced-aes/tests/tests.c7
-rw-r--r--test/monniaux/jpeg-6b/Makefile392
-rw-r--r--test/monniaux/jpeg-6b/ansi2knr.c693
-rwxr-xr-xtest/monniaux/jpeg-6b/ccomp.sh1
-rw-r--r--test/monniaux/jpeg-6b/cdjpeg.c362
-rw-r--r--test/monniaux/jpeg-6b/cjpeg.c1212
-rw-r--r--test/monniaux/jpeg-6b/cjpeg.i3270
-rwxr-xr-xtest/monniaux/jpeg-6b/configure2
-rw-r--r--test/monniaux/jpeg-6b/djpeg.c1232
-rwxr-xr-xtest/monniaux/jpeg-6b/dm_configure_ccomp.sh1
-rw-r--r--test/monniaux/jpeg-6b/example.c866
-rw-r--r--test/monniaux/jpeg-6b/jcapimin.c16
-rw-r--r--test/monniaux/jpeg-6b/jccoefct.c10
-rw-r--r--test/monniaux/jpeg-6b/jccolor.c4
-rw-r--r--test/monniaux/jpeg-6b/jcdctmgr.c8
-rw-r--r--test/monniaux/jpeg-6b/jchuff.c10
-rw-r--r--test/monniaux/jpeg-6b/jcinit.c4
-rw-r--r--test/monniaux/jpeg-6b/jcmainct.c8
-rw-r--r--test/monniaux/jpeg-6b/jcmarker.c4
-rw-r--r--test/monniaux/jpeg-6b/jcmaster.c10
-rw-r--r--test/monniaux/jpeg-6b/jconfig.h174
-rw-r--r--test/monniaux/jpeg-6b/jcparam.c12
-rw-r--r--test/monniaux/jpeg-6b/jcprepct.c8
-rw-r--r--test/monniaux/jpeg-6b/jcprepct.i3092
-rw-r--r--test/monniaux/jpeg-6b/jcsample.c14
-rw-r--r--test/monniaux/jpeg-6b/jdapimin.c66
-rw-r--r--test/monniaux/jpeg-6b/jdatadst.c4
-rw-r--r--test/monniaux/jpeg-6b/jdcoefct.c24
-rw-r--r--test/monniaux/jpeg-6b/jdhuff.c4
-rw-r--r--test/monniaux/jpeg-6b/jdinput.c6
-rw-r--r--test/monniaux/jpeg-6b/jdmainct.c34
-rw-r--r--test/monniaux/jpeg-6b/jdmarker.c16
-rw-r--r--test/monniaux/jpeg-6b/jdmaster.c4
-rw-r--r--test/monniaux/jpeg-6b/jdphuff.c2
-rw-r--r--test/monniaux/jpeg-6b/jdsample.c16
-rw-r--r--test/monniaux/jpeg-6b/jerror.c508
-rw-r--r--test/monniaux/jpeg-6b/jmemmgr.c2239
-rw-r--r--test/monniaux/jpeg-6b/jmemnobs.c17
-rw-r--r--test/monniaux/jpeg-6b/jmorecfg.h21
-rw-r--r--test/monniaux/jpeg-6b/jpegtran.c1008
-rw-r--r--test/monniaux/jpeg-6b/jquant1.c20
-rw-r--r--test/monniaux/jpeg-6b/jquant2.c6
-rw-r--r--test/monniaux/jpeg-6b/jutils.c4
-rw-r--r--test/monniaux/jpeg-6b/modulo_division.c15
-rw-r--r--test/monniaux/jpeg-6b/rdbmp.c8
-rw-r--r--test/monniaux/jpeg-6b/rdcolmap.c2
-rw-r--r--test/monniaux/jpeg-6b/rdgif.c76
-rw-r--r--test/monniaux/jpeg-6b/rdjpgcom.c1009
-rw-r--r--test/monniaux/jpeg-6b/rdppm.c2
-rw-r--r--test/monniaux/jpeg-6b/rdswitch.c664
-rw-r--r--test/monniaux/jpeg-6b/transupp.c122
-rw-r--r--test/monniaux/jpeg-6b/wrbmp.c2
-rw-r--r--test/monniaux/jpeg-6b/wrgif.c5
-rw-r--r--test/monniaux/jpeg-6b/wrjpgcom.c1166
-rw-r--r--test/monniaux/jpeg-6b/wrppm.c4
-rw-r--r--test/monniaux/jpeg-6b/wrtarga.c4
-rw-r--r--test/monniaux/micro-bunzip/micro-bunzip.c4
57 files changed, 5778 insertions, 12716 deletions
diff --git a/test/monniaux/bitsliced-aes/tests/tests.c b/test/monniaux/bitsliced-aes/tests/tests.c
index 0c564082..d3e464f7 100644
--- a/test/monniaux/bitsliced-aes/tests/tests.c
+++ b/test/monniaux/bitsliced-aes/tests/tests.c
@@ -10,7 +10,6 @@
#else
#include <stdio.h>
#endif
-extern FILE *fdopen(int fd, const char *mode);
void aes_ecb_test()
{
@@ -33,16 +32,14 @@ void aes_ecb_test()
printf("plain text: \n");
dump_hex((uint8_t * )input,16);
- FILE *err = fdopen(2, "w");
-
if (memcmp(pt_vector, input, 16) != 0)
{
- fprintf(err,"error: decrypted ciphertext is not the same as the input plaintext\n");
+ fprintf(stderr,"error: decrypted ciphertext is not the same as the input plaintext\n");
exit(1);
}
else if (memcmp(ct_vector, output, 16) != 0)
{
- fprintf(err,"error: ciphertext is not the same as the test vector\n");
+ fprintf(stderr,"error: ciphertext is not the same as the test vector\n");
exit(1);
}
else
diff --git a/test/monniaux/jpeg-6b/Makefile b/test/monniaux/jpeg-6b/Makefile
index 5e9e5fe8..68c73c30 100644
--- a/test/monniaux/jpeg-6b/Makefile
+++ b/test/monniaux/jpeg-6b/Makefile
@@ -1,29 +1,18 @@
-# Generated automatically from makefile.cfg by configure.
# Makefile for Independent JPEG Group's software
-# makefile.cfg is edited by configure to produce a custom Makefile.
+# This makefile is suitable for Unix-like systems with non-ANSI compilers.
+# If you have an ANSI compiler, makefile.ansi is a better starting point.
# Read installation instructions before saying "make" !!
-# For compiling with source and object files in different directories.
-srcdir = .
-
-# Where to install the programs and man pages.
-prefix = /usr/local
-exec_prefix = ${prefix}
-bindir = $(exec_prefix)/bin
-libdir = $(exec_prefix)/lib
-includedir = $(prefix)/include
-binprefix =
-manprefix =
-manext = 1
-mandir = $(prefix)/man/man$(manext)
-
# The name of your C compiler:
-CC= ./ccomp.sh
+CC= ../../../ccomp
+GCC=k1-mbr-gcc
+# GCC=$(CC)
+EXECUTE=k1-cluster --syscall=libstd_scalls.so --
# You may need to adjust these cc options:
-CFLAGS= -DNO_DOUBLE -DNO_32BIT_DIVISION -DNO_FLOAT -DNO_SWITCH -DTAIL_CALL_MISSING -DMEMCPY_MISSING -I$(srcdir)
+CFLAGS= -O3 -Wall
# Generally, we recommend defining any configuration symbols in jconfig.h,
# NOT via -D switches here.
# However, any special defines for ansi2knr.c may be included here:
@@ -35,39 +24,22 @@ LDFLAGS=
# To link any special libraries, add the necessary -l commands here.
LDLIBS=
-# If using GNU libtool, LIBTOOL references it; if not, LIBTOOL is empty.
-LIBTOOL =
-# $(O) expands to "lo" if using libtool, plain "o" if not.
-# Similarly, $(A) expands to "la" or "a".
-O = o
-A = a
-
-# Library version ID; libtool uses this for the shared library version number.
-# Note: we suggest this match the macro of the same name in jpeglib.h.
-JPEG_LIB_VERSION = 62
-
# Put here the object file name for the correct system-dependent memory
# manager file. For Unix this is usually jmemnobs.o, but you may want
# to use jmemansi.o or jmemname.o if you have limited swap space.
-SYSDEPMEM= jmemnobs.$(O)
+SYSDEPMEM= jmemnobs.o
# miscellaneous OS-dependent stuff
-SHELL= /bin/sh
# linker
LN= $(CC)
# file deletion command
RM= rm -f
-# directory creation command
-MKDIR= mkdir
+# file rename command
+MV= mv
# library (.a) file creation command
AR= ar rc
# second step in .a creation (use "touch" if not needed)
AR2= ranlib
-# installation program
-INSTALL= /usr/bin/install -c
-INSTALL_PROGRAM= ${INSTALL}
-INSTALL_LIB= ${INSTALL} -m 644
-INSTALL_DATA= ${INSTALL} -m 644
# End of configurable options.
@@ -110,216 +82,204 @@ TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
$(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
# library object files common to compression and decompression
-COMOBJECTS= jcomapi.$(O) jutils.$(O) jerror.$(O) jmemmgr.$(O) $(SYSDEPMEM)
+COMOBJECTS= jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)
# compression library object files
-CLIBOBJECTS= jcapimin.$(O) jcapistd.$(O) jctrans.$(O) jcparam.$(O) \
- jdatadst.$(O) jcinit.$(O) jcmaster.$(O) jcmarker.$(O) jcmainct.$(O) \
- jcprepct.$(O) jccoefct.$(O) jccolor.$(O) jcsample.$(O) jchuff.$(O) \
- jcphuff.$(O) jcdctmgr.$(O) jfdctfst.$(O) jfdctflt.$(O) \
- jfdctint.$(O)
+CLIBOBJECTS= jcapimin.o jcapistd.o jctrans.o jcparam.o jdatadst.o jcinit.o \
+ jcmaster.o jcmarker.o jcmainct.o jcprepct.o jccoefct.o jccolor.o \
+ jcsample.o jchuff.o jcphuff.o jcdctmgr.o jfdctfst.o jfdctflt.o \
+ jfdctint.o
# decompression library object files
-DLIBOBJECTS= jdapimin.$(O) jdapistd.$(O) jdtrans.$(O) jdatasrc.$(O) \
- jdmaster.$(O) jdinput.$(O) jdmarker.$(O) jdhuff.$(O) jdphuff.$(O) \
- jdmainct.$(O) jdcoefct.$(O) jdpostct.$(O) jddctmgr.$(O) \
- jidctfst.$(O) jidctflt.$(O) jidctint.$(O) jidctred.$(O) \
- jdsample.$(O) jdcolor.$(O) jquant1.$(O) jquant2.$(O) jdmerge.$(O)
+DLIBOBJECTS= jdapimin.o jdapistd.o jdtrans.o jdatasrc.o jdmaster.o \
+ jdinput.o jdmarker.o jdhuff.o jdphuff.o jdmainct.o jdcoefct.o \
+ jdpostct.o jddctmgr.o jidctfst.o jidctflt.o jidctint.o jidctred.o \
+ jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o
# These objectfiles are included in libjpeg.a
LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
# object files for sample applications (excluding library files)
-COBJECTS= cjpeg.$(O) rdppm.$(O) rdgif.$(O) rdtarga.$(O) rdrle.$(O) \
- rdbmp.$(O) rdswitch.$(O) cdjpeg.$(O)
-DOBJECTS= djpeg.$(O) wrppm.$(O) wrgif.$(O) wrtarga.$(O) wrrle.$(O) \
- wrbmp.$(O) rdcolmap.$(O) cdjpeg.$(O)
-TROBJECTS= jpegtran.$(O) rdswitch.$(O) cdjpeg.$(O) transupp.$(O)
+COBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o \
+ cdjpeg.o
+DOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o \
+ cdjpeg.o
+TROBJECTS= jpegtran.o rdswitch.o cdjpeg.o transupp.o
-all: libjpeg.$(A) cjpeg djpeg jpegtran rdjpgcom wrjpgcom
+all: libjpeg.a cjpeg djpeg jpegtran rdjpgcom wrjpgcom
-# Special compilation rules to support ansi2knr and libtool.
-.SUFFIXES: .lo .la
+# This rule causes ansi2knr to be invoked.
+# .c.o:
+# ./ansi2knr $*.c T$*.c
+# $(CC) $(CFLAGS) -c T$*.c
+# $(RM) T$*.c $*.o
+# $(MV) T$*.o $*.o
-# How to compile with libtool.
-# .c.lo:
-# $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/$*.c
+%.i : %.c
+ $(CC) $(CFLAGS) -E $< -o $@
-# How to use ansi2knr, when not using libtool.
-# .c.o:
-# ./ansi2knr $(srcdir)/$*.c knr/$*.c
-# $(CC) $(CFLAGS) -c knr/$*.c
-# $(RM) knr/$*.c
+# wrjpgcom.o : wrjpgcom.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-# How to use ansi2knr AND libtool.
-# .c.lo:
-# ./ansi2knr $(srcdir)/$*.c knr/$*.c
-# $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c knr/$*.c
-# $(RM) knr/$*.c
+# rdjpgcom.o : rdjpgcom.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-ansi2knr: ansi2knr.c
- $(CC) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr $(srcdir)/ansi2knr.c
- $(MKDIR) knr
+# rdswitch.o : rdswitch.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-# the library:
+# rdgif.o : rdgif.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-EXTRAOBJECTS= modulo_division.o
+# jmemmgr.o : jmemmgr.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-# without libtool:
-libjpeg.a: $(LIBOBJECTS) $(EXTRAOBJECTS)
- $(RM) libjpeg.a
- $(AR) libjpeg.a $(LIBOBJECTS) $(EXTRAOBJECTS)
- $(AR2) libjpeg.a
+# jerror.o : jerror.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-# with libtool:
-libjpeg.la: $(LIBOBJECTS)
- $(LIBTOOL) --mode=link $(CC) -o libjpeg.la $(LIBOBJECTS) \
- -rpath $(libdir) -version-info $(JPEG_LIB_VERSION)
+# example.o : example.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-# sample programs:
+# cjpeg.o : cjpeg.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-cjpeg: $(COBJECTS) libjpeg.$(A)
- $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.$(A) $(LDLIBS)
+# cdjpeg.o : cdjpeg.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-djpeg: $(DOBJECTS) libjpeg.$(A)
- $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.$(A) $(LDLIBS)
+# djpeg.o : djpeg.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-jpegtran: $(TROBJECTS) libjpeg.$(A)
- $(LN) $(LDFLAGS) -o jpegtran $(TROBJECTS) libjpeg.$(A) $(LDLIBS)
+# rdppm.o : rdppm.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-rdjpgcom: rdjpgcom.$(O)
- $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.$(O) $(LDLIBS)
+# rdbmp.o : rdbmp.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-wrjpgcom: wrjpgcom.$(O)
- $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.$(O) $(LDLIBS)
+# rdtarga.o : rdtarga.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-# Installation rules:
+# wrgif.o : wrgif.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-install: cjpeg djpeg jpegtran rdjpgcom wrjpgcom
- $(INSTALL_PROGRAM) cjpeg $(bindir)/$(binprefix)cjpeg
- $(INSTALL_PROGRAM) djpeg $(bindir)/$(binprefix)djpeg
- $(INSTALL_PROGRAM) jpegtran $(bindir)/$(binprefix)jpegtran
- $(INSTALL_PROGRAM) rdjpgcom $(bindir)/$(binprefix)rdjpgcom
- $(INSTALL_PROGRAM) wrjpgcom $(bindir)/$(binprefix)wrjpgcom
- $(INSTALL_DATA) $(srcdir)/cjpeg.1 $(mandir)/$(manprefix)cjpeg.$(manext)
- $(INSTALL_DATA) $(srcdir)/djpeg.1 $(mandir)/$(manprefix)djpeg.$(manext)
- $(INSTALL_DATA) $(srcdir)/jpegtran.1 $(mandir)/$(manprefix)jpegtran.$(manext)
- $(INSTALL_DATA) $(srcdir)/rdjpgcom.1 $(mandir)/$(manprefix)rdjpgcom.$(manext)
- $(INSTALL_DATA) $(srcdir)/wrjpgcom.1 $(mandir)/$(manprefix)wrjpgcom.$(manext)
+# wrbmp.o : wrbmp.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-install-lib: libjpeg.$(A) install-headers
- $(INSTALL_LIB) libjpeg.$(A) $(libdir)/$(binprefix)libjpeg.$(A)
+# wrtarga.o : wrtarga.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-install-headers: jconfig.h
- $(INSTALL_DATA) jconfig.h $(includedir)/jconfig.h
- $(INSTALL_DATA) $(srcdir)/jpeglib.h $(includedir)/jpeglib.h
- $(INSTALL_DATA) $(srcdir)/jmorecfg.h $(includedir)/jmorecfg.h
- $(INSTALL_DATA) $(srcdir)/jerror.h $(includedir)/jerror.h
+# rdcolmap.o : rdcolmap.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-clean:
- $(RM) *.o *.lo libjpeg.a libjpeg.la
- $(RM) cjpeg djpeg jpegtran rdjpgcom wrjpgcom
- $(RM) ansi2knr core testout* config.log config.status
- $(RM) -r knr .libs _libs
+# jpegtran.o : jpegtran.c
+# $(GCC) $(CFLAGS) -c $< -o $@
-distclean: clean
- $(RM) Makefile jconfig.h libtool config.cache
+libjpeg.a: $(LIBOBJECTS)
+ $(RM) libjpeg.a
+ $(AR) libjpeg.a $(LIBOBJECTS)
+ $(AR2) libjpeg.a
-test: cjpeg djpeg jpegtran
- $(RM) testout*
- ./djpeg -dct int -ppm -outfile testout.ppm $(srcdir)/testorig.jpg
- ./djpeg -dct int -bmp -colors 256 -outfile testout.bmp $(srcdir)/testorig.jpg
- ./cjpeg -dct int -outfile testout.jpg $(srcdir)/testimg.ppm
- ./djpeg -dct int -ppm -outfile testoutp.ppm $(srcdir)/testprog.jpg
- ./cjpeg -dct int -progressive -opt -outfile testoutp.jpg $(srcdir)/testimg.ppm
- ./jpegtran -outfile testoutt.jpg $(srcdir)/testprog.jpg
- cmp $(srcdir)/testimg.ppm testout.ppm
- cmp $(srcdir)/testimg.bmp testout.bmp
- cmp $(srcdir)/testimg.jpg testout.jpg
- cmp $(srcdir)/testimg.ppm testoutp.ppm
- cmp $(srcdir)/testimgp.jpg testoutp.jpg
- cmp $(srcdir)/testorig.jpg testoutt.jpg
-
-check: test
-
-# Mistake catcher:
+cjpeg: $(COBJECTS) libjpeg.a
+ $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.a $(LDLIBS)
+
+djpeg: $(DOBJECTS) libjpeg.a
+ $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.a $(LDLIBS)
+
+jpegtran: $(TROBJECTS) libjpeg.a
+ $(LN) $(LDFLAGS) -o jpegtran $(TROBJECTS) libjpeg.a $(LDLIBS)
+
+rdjpgcom: rdjpgcom.o
+ $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)
+
+wrjpgcom: wrjpgcom.o
+ $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)
jconfig.h: jconfig.doc
echo You must prepare a system-dependent jconfig.h file.
echo Please read the installation directions in install.doc.
exit 1
-# GNU Make likes to know which target names are not really files to be made:
-.PHONY: all install install-lib install-headers clean distclean test check
-
-
-jcapimin.$(O): jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jcapistd.$(O): jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jccoefct.$(O): jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jccolor.$(O): jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jcdctmgr.$(O): jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
-jchuff.$(O): jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
-jcinit.$(O): jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jcmainct.$(O): jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jcmarker.$(O): jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jcmaster.$(O): jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jcomapi.$(O): jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jcparam.$(O): jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jcphuff.$(O): jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
-jcprepct.$(O): jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jcsample.$(O): jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jctrans.$(O): jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jdapimin.$(O): jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jdapistd.$(O): jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jdatadst.$(O): jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
-jdatasrc.$(O): jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
-jdcoefct.$(O): jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jdcolor.$(O): jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jddctmgr.$(O): jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
-jdhuff.$(O): jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
-jdinput.$(O): jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jdmainct.$(O): jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jdmarker.$(O): jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jdmaster.$(O): jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jdmerge.$(O): jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jdphuff.$(O): jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
-jdpostct.$(O): jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jdsample.$(O): jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jdtrans.$(O): jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jerror.$(O): jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
-jfdctflt.$(O): jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
-jfdctfst.$(O): jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
-jfdctint.$(O): jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
-jidctflt.$(O): jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
-jidctfst.$(O): jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
-jidctint.$(O): jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
-jidctred.$(O): jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
-jquant1.$(O): jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jquant2.$(O): jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jutils.$(O): jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
-jmemmgr.$(O): jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
-jmemansi.$(O): jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
-jmemname.$(O): jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
-jmemnobs.$(O): jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
-jmemdos.$(O): jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
-jmemmac.$(O): jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
-cjpeg.$(O): cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
-djpeg.$(O): djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
-jpegtran.$(O): jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
-rdjpgcom.$(O): rdjpgcom.c jinclude.h jconfig.h
-wrjpgcom.$(O): wrjpgcom.c jinclude.h jconfig.h
-cdjpeg.$(O): cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-rdcolmap.$(O): rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-rdswitch.$(O): rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-transupp.$(O): transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
-rdppm.$(O): rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-wrppm.$(O): wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-rdgif.$(O): rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-wrgif.$(O): wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-rdtarga.$(O): rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-wrtarga.$(O): wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-rdbmp.$(O): rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-wrbmp.$(O): wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-rdrle.$(O): rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-wrrle.$(O): wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
-
-FALLBACK_CC=k1-mbr-gcc
-modulo_division.o: modulo_division.c
- $(FALLBACK_CC) -Wall -c $< -o $@
+clean:
+ $(RM) *.o cjpeg djpeg jpegtran libjpeg.a rdjpgcom wrjpgcom
+ $(RM) core testout*
+
+test: cjpeg djpeg jpegtran
+ $(RM) testout*
+ $(EXECUTE) ./djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
+ $(EXECUTE) ./djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg
+ $(EXECUTE) ./cjpeg -dct int -outfile testout.jpg testimg.ppm
+ $(EXECUTE) ./djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg
+ $(EXECUTE) ./cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm
+ $(EXECUTE) ./jpegtran -outfile testoutt.jpg testprog.jpg
+ cmp testimg.ppm testout.ppm
+ cmp testimg.bmp testout.bmp
+ cmp testimg.jpg testout.jpg
+ cmp testimg.ppm testoutp.ppm
+ cmp testimgp.jpg testoutp.jpg
+ cmp testorig.jpg testoutt.jpg
+
+
+jcapimin.o: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcapistd.o: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccoefct.o: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccolor.o: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcdctmgr.o: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jchuff.o: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcinit.o: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmainct.o: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmarker.o: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmaster.o: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcomapi.o: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcparam.o: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcphuff.o: jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcprepct.o: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcsample.o: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jctrans.o: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapimin.o: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapistd.o: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdatadst.o: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdatasrc.o: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdcoefct.o: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdcolor.o: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jddctmgr.o: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jdhuff.o: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdinput.o: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmainct.o: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmarker.o: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmaster.o: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmerge.o: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdphuff.o: jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdpostct.o: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdsample.o: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdtrans.o: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jerror.o: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
+jfdctflt.o: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctfst.o: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctint.o: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctflt.o: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctfst.o: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctint.o: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctred.o: jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jquant1.o: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jquant2.o: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jutils.o: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jmemmgr.o: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemansi.o: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemname.o: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemnobs.o: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemdos.o: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemmac.o: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+cjpeg.o: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+djpeg.o: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+jpegtran.o: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
+rdjpgcom.o: rdjpgcom.c jinclude.h jconfig.h
+wrjpgcom.o: wrjpgcom.c jinclude.h jconfig.h
+cdjpeg.o: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdcolmap.o: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdswitch.o: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+transupp.o: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
+rdppm.o: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrppm.o: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdgif.o: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrgif.o: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdtarga.o: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrtarga.o: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdbmp.o: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrbmp.o: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdrle.o: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrrle.o: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
diff --git a/test/monniaux/jpeg-6b/ansi2knr.c b/test/monniaux/jpeg-6b/ansi2knr.c
deleted file mode 100644
index 4e05fc2d..00000000
--- a/test/monniaux/jpeg-6b/ansi2knr.c
+++ /dev/null
@@ -1,693 +0,0 @@
-/* ansi2knr.c */
-/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
-
-/*
-ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY. No author or distributor accepts responsibility to anyone for the
-consequences of using it or for whether it serves any particular purpose or
-works at all, unless he says so in writing. Refer to the GNU General Public
-License (the "GPL") for full details.
-
-Everyone is granted permission to copy, modify and redistribute ansi2knr,
-but only under the conditions described in the GPL. A copy of this license
-is supposed to have been given to you along with ansi2knr so you can know
-your rights and responsibilities. It should be in a file named COPYLEFT.
-[In the IJG distribution, the GPL appears below, not in a separate file.]
-Among other things, the copyright notice and this notice must be preserved
-on all copies.
-
-We explicitly state here what we believe is already implied by the GPL: if
-the ansi2knr program is distributed as a separate set of sources and a
-separate executable file which are aggregated on a storage medium together
-with another program, this in itself does not bring the other program under
-the GPL, nor does the mere fact that such a program or the procedures for
-constructing it invoke the ansi2knr executable bring any other part of the
-program under the GPL.
-*/
-
-/*
----------- Here is the GNU GPL file COPYLEFT, referred to above ----------
------ These terms do NOT apply to the JPEG software itself; see README ------
-
- GHOSTSCRIPT GENERAL PUBLIC LICENSE
- (Clarified 11 Feb 1988)
-
- Copyright (C) 1988 Richard M. Stallman
- Everyone is permitted to copy and distribute verbatim copies of this
- license, but changing it is not allowed. You can also use this wording
- to make the terms for other programs.
-
- The license agreements of most software companies keep you at the
-mercy of those companies. By contrast, our general public license is
-intended to give everyone the right to share Ghostscript. To make sure
-that you get the rights we want you to have, we need to make
-restrictions that forbid anyone to deny you these rights or to ask you
-to surrender the rights. Hence this license agreement.
-
- Specifically, we want to make sure that you have the right to give
-away copies of Ghostscript, that you receive source code or else can get
-it if you want it, that you can change Ghostscript or use pieces of it
-in new free programs, and that you know you can do these things.
-
- To make sure that everyone has such rights, we have to forbid you to
-deprive anyone else of these rights. For example, if you distribute
-copies of Ghostscript, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must tell them their rights.
-
- Also, for our own protection, we must make certain that everyone finds
-out that there is no warranty for Ghostscript. If Ghostscript is
-modified by someone else and passed on, we want its recipients to know
-that what they have is not what we distributed, so that any problems
-introduced by others will not reflect on our reputation.
-
- Therefore we (Richard M. Stallman and the Free Software Foundation,
-Inc.) make the following terms which say what you must do to be allowed
-to distribute or change Ghostscript.
-
-
- COPYING POLICIES
-
- 1. You may copy and distribute verbatim copies of Ghostscript source
-code as you receive it, in any medium, provided that you conspicuously
-and appropriately publish on each copy a valid copyright and license
-notice "Copyright (C) 1989 Aladdin Enterprises. All rights reserved.
-Distributed by Free Software Foundation, Inc." (or with whatever year is
-appropriate); keep intact the notices on all files that refer to this
-License Agreement and to the absence of any warranty; and give any other
-recipients of the Ghostscript program a copy of this License Agreement
-along with the program. You may charge a distribution fee for the
-physical act of transferring a copy.
-
- 2. You may modify your copy or copies of Ghostscript or any portion of
-it, and copy and distribute such modifications under the terms of
-Paragraph 1 above, provided that you also do the following:
-
- a) cause the modified files to carry prominent notices stating
- that you changed the files and the date of any change; and
-
- b) cause the whole of any work that you distribute or publish,
- that in whole or in part contains or is a derivative of Ghostscript
- or any part thereof, to be licensed at no charge to all third
- parties on terms identical to those contained in this License
- Agreement (except that you may choose to grant more extensive
- warranty protection to some or all third parties, at your option).
-
- c) You may charge a distribution fee for the physical act of
- transferring a copy, and you may at your option offer warranty
- protection in exchange for a fee.
-
-Mere aggregation of another unrelated program with this program (or its
-derivative) on a volume of a storage or distribution medium does not bring
-the other program under the scope of these terms.
-
- 3. You may copy and distribute Ghostscript (or a portion or derivative
-of it, under Paragraph 2) in object code or executable form under the
-terms of Paragraphs 1 and 2 above provided that you also do one of the
-following:
-
- a) accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of
- Paragraphs 1 and 2 above; or,
-
- b) accompany it with a written offer, valid for at least three
- years, to give any third party free (except for a nominal
- shipping charge) a complete machine-readable copy of the
- corresponding source code, to be distributed under the terms of
- Paragraphs 1 and 2 above; or,
-
- c) accompany it with the information you received as to where the
- corresponding source code may be obtained. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form alone.)
-
-For an executable file, complete source code means all the source code for
-all modules it contains; but, as a special exception, it need not include
-source code for modules which are standard libraries that accompany the
-operating system on which the executable file runs.
-
- 4. You may not copy, sublicense, distribute or transfer Ghostscript
-except as expressly provided under this License Agreement. Any attempt
-otherwise to copy, sublicense, distribute or transfer Ghostscript is
-void and your rights to use the program under this License agreement
-shall be automatically terminated. However, parties who have received
-computer software programs from you with this License Agreement will not
-have their licenses terminated so long as such parties remain in full
-compliance.
-
- 5. If you wish to incorporate parts of Ghostscript into other free
-programs whose distribution conditions are different, write to the Free
-Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not
-yet worked out a simple rule that can be stated here, but we will often
-permit this. We will be guided by the two goals of preserving the free
-status of all derivatives of our free software and of promoting the
-sharing and reuse of software.
-
-Your comments and suggestions about our licensing policies and our
-software are welcome! Please contact the Free Software Foundation,
-Inc., 675 Mass Ave, Cambridge, MA 02139, or call (617) 876-3296.
-
- NO WARRANTY
-
- BECAUSE GHOSTSCRIPT IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
-NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
-WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC, RICHARD
-M. STALLMAN, ALADDIN ENTERPRISES, L. PETER DEUTSCH, AND/OR OTHER PARTIES
-PROVIDE GHOSTSCRIPT "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
-EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
-ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF GHOSTSCRIPT IS WITH
-YOU. SHOULD GHOSTSCRIPT PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
-NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
-STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., L. PETER DEUTSCH, ALADDIN
-ENTERPRISES, AND/OR ANY OTHER PARTY WHO MAY MODIFY AND REDISTRIBUTE
-GHOSTSCRIPT AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING
-ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, INCIDENTAL OR
-CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
-(INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
-INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE
-PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) GHOSTSCRIPT, EVEN IF YOU
-HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM
-BY ANY OTHER PARTY.
-
--------------------- End of file COPYLEFT ------------------------------
-*/
-
-/*
- * Usage:
- ansi2knr input_file [output_file]
- * If no output_file is supplied, output goes to stdout.
- * There are no error messages.
- *
- * ansi2knr recognizes function definitions by seeing a non-keyword
- * identifier at the left margin, followed by a left parenthesis,
- * with a right parenthesis as the last character on the line,
- * and with a left brace as the first token on the following line
- * (ignoring possible intervening comments).
- * It will recognize a multi-line header provided that no intervening
- * line ends with a left or right brace or a semicolon.
- * These algorithms ignore whitespace and comments, except that
- * the function name must be the first thing on the line.
- * The following constructs will confuse it:
- * - Any other construct that starts at the left margin and
- * follows the above syntax (such as a macro or function call).
- * - Some macros that tinker with the syntax of the function header.
- */
-
-/*
- * The original and principal author of ansi2knr is L. Peter Deutsch
- * <ghost@aladdin.com>. Other authors are noted in the change history
- * that follows (in reverse chronological order):
- lpd 96-01-21 added code to cope with not HAVE_CONFIG_H and with
- compilers that don't understand void, as suggested by
- Tom Lane
- lpd 96-01-15 changed to require that the first non-comment token
- on the line following a function header be a left brace,
- to reduce sensitivity to macros, as suggested by Tom Lane
- <tgl@sss.pgh.pa.us>
- lpd 95-06-22 removed #ifndefs whose sole purpose was to define
- undefined preprocessor symbols as 0; changed all #ifdefs
- for configuration symbols to #ifs
- lpd 95-04-05 changed copyright notice to make it clear that
- including ansi2knr in a program does not bring the entire
- program under the GPL
- lpd 94-12-18 added conditionals for systems where ctype macros
- don't handle 8-bit characters properly, suggested by
- Francois Pinard <pinard@iro.umontreal.ca>;
- removed --varargs switch (this is now the default)
- lpd 94-10-10 removed CONFIG_BROKETS conditional
- lpd 94-07-16 added some conditionals to help GNU `configure',
- suggested by Francois Pinard <pinard@iro.umontreal.ca>;
- properly erase prototype args in function parameters,
- contributed by Jim Avera <jima@netcom.com>;
- correct error in writeblanks (it shouldn't erase EOLs)
- lpd 89-xx-xx original version
- */
-
-/* Most of the conditionals here are to make ansi2knr work with */
-/* or without the GNU configure machinery. */
-
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdio.h>
-#include <ctype.h>
-
-#if HAVE_CONFIG_H
-
-/*
- For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h).
- This will define HAVE_CONFIG_H and so, activate the following lines.
- */
-
-# if STDC_HEADERS || HAVE_STRING_H
-# include <string.h>
-# else
-# include <strings.h>
-# endif
-
-#else /* not HAVE_CONFIG_H */
-
-/* Otherwise do it the hard way */
-
-# ifdef BSD
-# include <strings.h>
-# else
-# ifdef VMS
- extern int strlen(), strncmp();
-# else
-# include <string.h>
-# endif
-# endif
-
-#endif /* not HAVE_CONFIG_H */
-
-#if STDC_HEADERS
-# include <stdlib.h>
-#else
-/*
- malloc and free should be declared in stdlib.h,
- but if you've got a K&R compiler, they probably aren't.
- */
-# ifdef MSDOS
-# include <malloc.h>
-# else
-# ifdef VMS
- extern char *malloc();
- extern void free();
-# else
- extern char *malloc();
- extern int free();
-# endif
-# endif
-
-#endif
-
-/*
- * The ctype macros don't always handle 8-bit characters correctly.
- * Compensate for this here.
- */
-#ifdef isascii
-# undef HAVE_ISASCII /* just in case */
-# define HAVE_ISASCII 1
-#else
-#endif
-#if STDC_HEADERS || !HAVE_ISASCII
-# define is_ascii(c) 1
-#else
-# define is_ascii(c) isascii(c)
-#endif
-
-#define is_space(c) (is_ascii(c) && isspace(c))
-#define is_alpha(c) (is_ascii(c) && isalpha(c))
-#define is_alnum(c) (is_ascii(c) && isalnum(c))
-
-/* Scanning macros */
-#define isidchar(ch) (is_alnum(ch) || (ch) == '_')
-#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_')
-
-/* Forward references */
-char *skipspace();
-int writeblanks();
-int test1();
-int convert1();
-
-/* The main program */
-int
-main(argc, argv)
- int argc;
- char *argv[];
-{ FILE *in, *out;
-#define bufsize 5000 /* arbitrary size */
- char *buf;
- char *line;
- char *more;
- /*
- * In previous versions, ansi2knr recognized a --varargs switch.
- * If this switch was supplied, ansi2knr would attempt to convert
- * a ... argument to va_alist and va_dcl; if this switch was not
- * supplied, ansi2knr would simply drop any such arguments.
- * Now, ansi2knr always does this conversion, and we only
- * check for this switch for backward compatibility.
- */
- int convert_varargs = 1;
-
- if ( argc > 1 && argv[1][0] == '-' )
- { if ( !strcmp(argv[1], "--varargs") )
- { convert_varargs = 1;
- argc--;
- argv++;
- }
- else
- { fprintf(stderr, "Unrecognized switch: %s\n", argv[1]);
- exit(1);
- }
- }
- switch ( argc )
- {
- default:
- printf("Usage: ansi2knr input_file [output_file]\n");
- exit(0);
- case 2:
- out = stdout;
- break;
- case 3:
- out = fopen(argv[2], "w");
- if ( out == NULL )
- { fprintf(stderr, "Cannot open output file %s\n", argv[2]);
- exit(1);
- }
- }
- in = fopen(argv[1], "r");
- if ( in == NULL )
- { fprintf(stderr, "Cannot open input file %s\n", argv[1]);
- exit(1);
- }
- fprintf(out, "#line 1 \"%s\"\n", argv[1]);
- buf = malloc(bufsize);
- line = buf;
- while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
- {
-test: line += strlen(line);
- switch ( test1(buf) )
- {
- case 2: /* a function header */
- convert1(buf, out, 1, convert_varargs);
- break;
- case 1: /* a function */
- /* Check for a { at the start of the next line. */
- more = ++line;
-f: if ( line >= buf + (bufsize - 1) ) /* overflow check */
- goto wl;
- if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL )
- goto wl;
- switch ( *skipspace(more, 1) )
- {
- case '{':
- /* Definitely a function header. */
- convert1(buf, out, 0, convert_varargs);
- fputs(more, out);
- break;
- case 0:
- /* The next line was blank or a comment: */
- /* keep scanning for a non-comment. */
- line += strlen(line);
- goto f;
- default:
- /* buf isn't a function header, but */
- /* more might be. */
- fputs(buf, out);
- strcpy(buf, more);
- line = buf;
- goto test;
- }
- break;
- case -1: /* maybe the start of a function */
- if ( line != buf + (bufsize - 1) ) /* overflow check */
- continue;
- /* falls through */
- default: /* not a function */
-wl: fputs(buf, out);
- break;
- }
- line = buf;
- }
- if ( line != buf )
- fputs(buf, out);
- free(buf);
- fclose(out);
- fclose(in);
- return 0;
-}
-
-/* Skip over space and comments, in either direction. */
-char *
-skipspace(p, dir)
- register char *p;
- register int dir; /* 1 for forward, -1 for backward */
-{ for ( ; ; )
- { while ( is_space(*p) )
- p += dir;
- if ( !(*p == '/' && p[dir] == '*') )
- break;
- p += dir; p += dir;
- while ( !(*p == '*' && p[dir] == '/') )
- { if ( *p == 0 )
- return p; /* multi-line comment?? */
- p += dir;
- }
- p += dir; p += dir;
- }
- return p;
-}
-
-/*
- * Write blanks over part of a string.
- * Don't overwrite end-of-line characters.
- */
-int
-writeblanks(start, end)
- char *start;
- char *end;
-{ char *p;
- for ( p = start; p < end; p++ )
- if ( *p != '\r' && *p != '\n' )
- *p = ' ';
- return 0;
-}
-
-/*
- * Test whether the string in buf is a function definition.
- * The string may contain and/or end with a newline.
- * Return as follows:
- * 0 - definitely not a function definition;
- * 1 - definitely a function definition;
- * 2 - definitely a function prototype (NOT USED);
- * -1 - may be the beginning of a function definition,
- * append another line and look again.
- * The reason we don't attempt to convert function prototypes is that
- * Ghostscript's declaration-generating macros look too much like
- * prototypes, and confuse the algorithms.
- */
-int
-test1(buf)
- char *buf;
-{ register char *p = buf;
- char *bend;
- char *endfn;
- int contin;
-
- if ( !isidfirstchar(*p) )
- return 0; /* no name at left margin */
- bend = skipspace(buf + strlen(buf) - 1, -1);
- switch ( *bend )
- {
- case ';': contin = 0 /*2*/; break;
- case ')': contin = 1; break;
- case '{': return 0; /* not a function */
- case '}': return 0; /* not a function */
- default: contin = -1;
- }
- while ( isidchar(*p) )
- p++;
- endfn = p;
- p = skipspace(p, 1);
- if ( *p++ != '(' )
- return 0; /* not a function */
- p = skipspace(p, 1);
- if ( *p == ')' )
- return 0; /* no parameters */
- /* Check that the apparent function name isn't a keyword. */
- /* We only need to check for keywords that could be followed */
- /* by a left parenthesis (which, unfortunately, is most of them). */
- { static char *words[] =
- { "asm", "auto", "case", "char", "const", "double",
- "extern", "float", "for", "if", "int", "long",
- "register", "return", "short", "signed", "sizeof",
- "static", "switch", "typedef", "unsigned",
- "void", "volatile", "while", 0
- };
- char **key = words;
- char *kp;
- int len = endfn - buf;
-
- while ( (kp = *key) != 0 )
- { if ( strlen(kp) == len && !strncmp(kp, buf, len) )
- return 0; /* name is a keyword */
- key++;
- }
- }
- return contin;
-}
-
-/* Convert a recognized function definition or header to K&R syntax. */
-int
-convert1(buf, out, header, convert_varargs)
- char *buf;
- FILE *out;
- int header; /* Boolean */
- int convert_varargs; /* Boolean */
-{ char *endfn;
- register char *p;
- char **breaks;
- unsigned num_breaks = 2; /* for testing */
- char **btop;
- char **bp;
- char **ap;
- char *vararg = 0;
-
- /* Pre-ANSI implementations don't agree on whether strchr */
- /* is called strchr or index, so we open-code it here. */
- for ( endfn = buf; *(endfn++) != '('; )
- ;
-top: p = endfn;
- breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
- if ( breaks == 0 )
- { /* Couldn't allocate break table, give up */
- fprintf(stderr, "Unable to allocate break table!\n");
- fputs(buf, out);
- return -1;
- }
- btop = breaks + num_breaks * 2 - 2;
- bp = breaks;
- /* Parse the argument list */
- do
- { int level = 0;
- char *lp = NULL;
- char *rp;
- char *end = NULL;
-
- if ( bp >= btop )
- { /* Filled up break table. */
- /* Allocate a bigger one and start over. */
- free((char *)breaks);
- num_breaks <<= 1;
- goto top;
- }
- *bp++ = p;
- /* Find the end of the argument */
- for ( ; end == NULL; p++ )
- { switch(*p)
- {
- case ',':
- if ( !level ) end = p;
- break;
- case '(':
- if ( !level ) lp = p;
- level++;
- break;
- case ')':
- if ( --level < 0 ) end = p;
- else rp = p;
- break;
- case '/':
- p = skipspace(p, 1) - 1;
- break;
- default:
- ;
- }
- }
- /* Erase any embedded prototype parameters. */
- if ( lp )
- writeblanks(lp + 1, rp);
- p--; /* back up over terminator */
- /* Find the name being declared. */
- /* This is complicated because of procedure and */
- /* array modifiers. */
- for ( ; ; )
- { p = skipspace(p - 1, -1);
- switch ( *p )
- {
- case ']': /* skip array dimension(s) */
- case ')': /* skip procedure args OR name */
- { int level = 1;
- while ( level )
- switch ( *--p )
- {
- case ']': case ')': level++; break;
- case '[': case '(': level--; break;
- case '/': p = skipspace(p, -1) + 1; break;
- default: ;
- }
- }
- if ( *p == '(' && *skipspace(p + 1, 1) == '*' )
- { /* We found the name being declared */
- while ( !isidfirstchar(*p) )
- p = skipspace(p, 1) + 1;
- goto found;
- }
- break;
- default:
- goto found;
- }
- }
-found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
- { if ( convert_varargs )
- { *bp++ = "va_alist";
- vararg = p-2;
- }
- else
- { p++;
- if ( bp == breaks + 1 ) /* sole argument */
- writeblanks(breaks[0], p);
- else
- writeblanks(bp[-1] - 1, p);
- bp--;
- }
- }
- else
- { while ( isidchar(*p) ) p--;
- *bp++ = p+1;
- }
- p = end;
- }
- while ( *p++ == ',' );
- *bp = p;
- /* Make a special check for 'void' arglist */
- if ( bp == breaks+2 )
- { p = skipspace(breaks[0], 1);
- if ( !strncmp(p, "void", 4) )
- { p = skipspace(p+4, 1);
- if ( p == breaks[2] - 1 )
- { bp = breaks; /* yup, pretend arglist is empty */
- writeblanks(breaks[0], p + 1);
- }
- }
- }
- /* Put out the function name and left parenthesis. */
- p = buf;
- while ( p != endfn ) putc(*p, out), p++;
- /* Put out the declaration. */
- if ( header )
- { fputs(");", out);
- for ( p = breaks[0]; *p; p++ )
- if ( *p == '\r' || *p == '\n' )
- putc(*p, out);
- }
- else
- { for ( ap = breaks+1; ap < bp; ap += 2 )
- { p = *ap;
- while ( isidchar(*p) )
- putc(*p, out), p++;
- if ( ap < bp - 1 )
- fputs(", ", out);
- }
- fputs(") ", out);
- /* Put out the argument declarations */
- for ( ap = breaks+2; ap <= bp; ap += 2 )
- (*ap)[-1] = ';';
- if ( vararg != 0 )
- { *vararg = 0;
- fputs(breaks[0], out); /* any prior args */
- fputs("va_dcl", out); /* the final arg */
- fputs(bp[0], out);
- }
- else
- fputs(breaks[0], out);
- }
- free((char *)breaks);
- return 0;
-}
diff --git a/test/monniaux/jpeg-6b/ccomp.sh b/test/monniaux/jpeg-6b/ccomp.sh
deleted file mode 100755
index 45c7923a..00000000
--- a/test/monniaux/jpeg-6b/ccomp.sh
+++ /dev/null
@@ -1 +0,0 @@
-exec /home/monniaux/work/Kalray/CompCert/ccomp "$@"
diff --git a/test/monniaux/jpeg-6b/cdjpeg.c b/test/monniaux/jpeg-6b/cdjpeg.c
index b6250ff9..89fe6337 100644
--- a/test/monniaux/jpeg-6b/cdjpeg.c
+++ b/test/monniaux/jpeg-6b/cdjpeg.c
@@ -1,181 +1,181 @@
-/*
- * cdjpeg.c
- *
- * Copyright (C) 1991-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains common support routines used by the IJG application
- * programs (cjpeg, djpeg, jpegtran).
- */
-
-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
-#include <ctype.h> /* to declare isupper(), tolower() */
-#ifdef NEED_SIGNAL_CATCHER
-#include <signal.h> /* to declare signal() */
-#endif
-#ifdef USE_SETMODE
-#include <fcntl.h> /* to declare setmode()'s parameter macros */
-/* If you have setmode() but not <io.h>, just delete this line: */
-#include <io.h> /* to declare setmode() */
-#endif
-
-
-/*
- * Signal catcher to ensure that temporary files are removed before aborting.
- * NB: for Amiga Manx C this is actually a global routine named _abort();
- * we put "#define signal_catcher _abort" in jconfig.h. Talk about bogus...
- */
-
-#ifdef NEED_SIGNAL_CATCHER
-
-static j_common_ptr sig_cinfo;
-
-void /* must be global for Manx C */
-signal_catcher (int signum)
-{
- if (sig_cinfo != NULL) {
- if (sig_cinfo->err != NULL) /* turn off trace output */
- sig_cinfo->err->trace_level = 0;
- jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */
- }
- exit(EXIT_FAILURE);
-}
-
-
-GLOBAL(void)
-enable_signal_catcher (j_common_ptr cinfo)
-{
- sig_cinfo = cinfo;
-#ifdef SIGINT /* not all systems have SIGINT */
- signal(SIGINT, signal_catcher);
-#endif
-#ifdef SIGTERM /* not all systems have SIGTERM */
- signal(SIGTERM, signal_catcher);
-#endif
-}
-
-#endif
-
-
-/*
- * Optional progress monitor: display a percent-done figure on stderr.
- */
-
-#ifdef PROGRESS_REPORT
-
-METHODDEF(void)
-progress_monitor (j_common_ptr cinfo)
-{
- cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress;
- int total_passes = prog->pub.total_passes + prog->total_extra_passes;
- int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit);
-
- if (percent_done != prog->percent_done) {
- prog->percent_done = percent_done;
- if (total_passes > 1) {
- fprintf(stderr, "\rPass %d/%d: %3d%% ",
- prog->pub.completed_passes + prog->completed_extra_passes + 1,
- total_passes, percent_done);
- } else {
- fprintf(stderr, "\r %3d%% ", percent_done);
- }
- fflush(stderr);
- }
-}
-
-
-GLOBAL(void)
-start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress)
-{
- /* Enable progress display, unless trace output is on */
- if (cinfo->err->trace_level == 0) {
- progress->pub.progress_monitor = progress_monitor;
- progress->completed_extra_passes = 0;
- progress->total_extra_passes = 0;
- progress->percent_done = -1;
- cinfo->progress = &progress->pub;
- }
-}
-
-
-GLOBAL(void)
-end_progress_monitor (j_common_ptr cinfo)
-{
- /* Clear away progress display */
- if (cinfo->err->trace_level == 0) {
- fprintf(stderr, "\r \r");
- fflush(stderr);
- }
-}
-
-#endif
-
-
-/*
- * Case-insensitive matching of possibly-abbreviated keyword switches.
- * keyword is the constant keyword (must be lower case already),
- * minchars is length of minimum legal abbreviation.
- */
-
-GLOBAL(boolean)
-keymatch (char * arg, const char * keyword, int minchars)
-{
- register int ca, ck;
- register int nmatched = 0;
-
- while ((ca = *arg++) != '\0') {
- if ((ck = *keyword++) == '\0')
- return FALSE; /* arg longer than keyword, no good */
- if (isupper(ca)) /* force arg to lcase (assume ck is already) */
- ca = tolower(ca);
- if (ca != ck)
- return FALSE; /* no good */
- nmatched++; /* count matched characters */
- }
- /* reached end of argument; fail if it's too short for unique abbrev */
- if (nmatched < minchars)
- return FALSE;
- return TRUE; /* A-OK */
-}
-
-
-/*
- * Routines to establish binary I/O mode for stdin and stdout.
- * Non-Unix systems often require some hacking to get out of text mode.
- */
-
-GLOBAL(FILE *)
-read_stdin (void)
-{
- FILE * input_file = stdin;
-
-#ifdef USE_SETMODE /* need to hack file mode? */
- setmode(fileno(stdin), O_BINARY);
-#endif
-#ifdef USE_FDOPEN /* need to re-open in binary mode? */
- if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
- fprintf(stderr, "Cannot reopen stdin\n");
- exit(EXIT_FAILURE);
- }
-#endif
- return input_file;
-}
-
-
-GLOBAL(FILE *)
-write_stdout (void)
-{
- FILE * output_file = stdout;
-
-#ifdef USE_SETMODE /* need to hack file mode? */
- setmode(fileno(stdout), O_BINARY);
-#endif
-#ifdef USE_FDOPEN /* need to re-open in binary mode? */
- if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {
- fprintf(stderr, "Cannot reopen stdout\n");
- exit(EXIT_FAILURE);
- }
-#endif
- return output_file;
-}
+/*
+ * cdjpeg.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains common support routines used by the IJG application
+ * programs (cjpeg, djpeg, jpegtran).
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+#include <ctype.h> /* to declare isupper(), tolower() */
+#ifdef NEED_SIGNAL_CATCHER
+#include <signal.h> /* to declare signal() */
+#endif
+#ifdef USE_SETMODE
+#include <fcntl.h> /* to declare setmode()'s parameter macros */
+/* If you have setmode() but not <io.h>, just delete this line: */
+#include <io.h> /* to declare setmode() */
+#endif
+
+
+/*
+ * Signal catcher to ensure that temporary files are removed before aborting.
+ * NB: for Amiga Manx C this is actually a global routine named _abort();
+ * we put "#define signal_catcher _abort" in jconfig.h. Talk about bogus...
+ */
+
+#ifdef NEED_SIGNAL_CATCHER
+
+static j_common_ptr sig_cinfo;
+
+void /* must be global for Manx C */
+signal_catcher (int signum)
+{
+ if (sig_cinfo != NULL) {
+ if (sig_cinfo->err != NULL) /* turn off trace output */
+ sig_cinfo->err->trace_level = 0;
+ jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */
+ }
+ exit(EXIT_FAILURE);
+}
+
+
+GLOBAL(void)
+enable_signal_catcher (j_common_ptr cinfo)
+{
+ sig_cinfo = cinfo;
+#ifdef SIGINT /* not all systems have SIGINT */
+ signal(SIGINT, signal_catcher);
+#endif
+#ifdef SIGTERM /* not all systems have SIGTERM */
+ signal(SIGTERM, signal_catcher);
+#endif
+}
+
+#endif
+
+
+/*
+ * Optional progress monitor: display a percent-done figure on stderr.
+ */
+
+#ifdef PROGRESS_REPORT
+
+METHODDEF(void)
+progress_monitor (j_common_ptr cinfo)
+{
+ cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress;
+ int total_passes = prog->pub.total_passes + prog->total_extra_passes;
+ int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit);
+
+ if (percent_done != prog->percent_done) {
+ prog->percent_done = percent_done;
+ if (total_passes > 1) {
+ fprintf(stderr, "\rPass %d/%d: %3d%% ",
+ prog->pub.completed_passes + prog->completed_extra_passes + 1,
+ total_passes, percent_done);
+ } else {
+ fprintf(stderr, "\r %3d%% ", percent_done);
+ }
+ fflush(stderr);
+ }
+}
+
+
+GLOBAL(void)
+start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress)
+{
+ /* Enable progress display, unless trace output is on */
+ if (cinfo->err->trace_level == 0) {
+ progress->pub.progress_monitor = progress_monitor;
+ progress->completed_extra_passes = 0;
+ progress->total_extra_passes = 0;
+ progress->percent_done = -1;
+ cinfo->progress = &progress->pub;
+ }
+}
+
+
+GLOBAL(void)
+end_progress_monitor (j_common_ptr cinfo)
+{
+ /* Clear away progress display */
+ if (cinfo->err->trace_level == 0) {
+ fprintf(stderr, "\r \r");
+ fflush(stderr);
+ }
+}
+
+#endif
+
+
+/*
+ * Case-insensitive matching of possibly-abbreviated keyword switches.
+ * keyword is the constant keyword (must be lower case already),
+ * minchars is length of minimum legal abbreviation.
+ */
+
+GLOBAL(boolean)
+keymatch (char * arg, const char * keyword, int minchars)
+{
+ register int ca, ck;
+ register int nmatched = 0;
+
+ while ((ca = *arg++) != '\0') {
+ if ((ck = *keyword++) == '\0')
+ return FALSE; /* arg longer than keyword, no good */
+ if (isupper(ca)) /* force arg to lcase (assume ck is already) */
+ ca = tolower(ca);
+ if (ca != ck)
+ return FALSE; /* no good */
+ nmatched++; /* count matched characters */
+ }
+ /* reached end of argument; fail if it's too short for unique abbrev */
+ if (nmatched < minchars)
+ return FALSE;
+ return TRUE; /* A-OK */
+}
+
+
+/*
+ * Routines to establish binary I/O mode for stdin and stdout.
+ * Non-Unix systems often require some hacking to get out of text mode.
+ */
+
+GLOBAL(FILE *)
+read_stdin (void)
+{
+ FILE * input_file = stdin;
+
+#ifdef USE_SETMODE /* need to hack file mode? */
+ setmode(fileno(stdin), O_BINARY);
+#endif
+#ifdef USE_FDOPEN /* need to re-open in binary mode? */
+ if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
+ fprintf(stderr, "Cannot reopen stdin\n");
+ exit(EXIT_FAILURE);
+ }
+#endif
+ return input_file;
+}
+
+
+GLOBAL(FILE *)
+write_stdout (void)
+{
+ FILE * output_file = stdout;
+
+#ifdef USE_SETMODE /* need to hack file mode? */
+ setmode(fileno(stdout), O_BINARY);
+#endif
+#ifdef USE_FDOPEN /* need to re-open in binary mode? */
+ if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {
+ fprintf(stderr, "Cannot reopen stdout\n");
+ exit(EXIT_FAILURE);
+ }
+#endif
+ return output_file;
+}
diff --git a/test/monniaux/jpeg-6b/cjpeg.c b/test/monniaux/jpeg-6b/cjpeg.c
index f2a929f0..b9102ee9 100644
--- a/test/monniaux/jpeg-6b/cjpeg.c
+++ b/test/monniaux/jpeg-6b/cjpeg.c
@@ -1,606 +1,606 @@
-/*
- * cjpeg.c
- *
- * Copyright (C) 1991-1998, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains a command-line user interface for the JPEG compressor.
- * It should work on any system with Unix- or MS-DOS-style command lines.
- *
- * Two different command line styles are permitted, depending on the
- * compile-time switch TWO_FILE_COMMANDLINE:
- * cjpeg [options] inputfile outputfile
- * cjpeg [options] [inputfile]
- * In the second style, output is always to standard output, which you'd
- * normally redirect to a file or pipe to some other program. Input is
- * either from a named file or from standard input (typically redirected).
- * The second style is convenient on Unix but is unhelpful on systems that
- * don't support pipes. Also, you MUST use the first style if your system
- * doesn't do binary I/O to stdin/stdout.
- * To simplify script writing, the "-outfile" switch is provided. The syntax
- * cjpeg [options] -outfile outputfile inputfile
- * works regardless of which command line style is used.
- */
-
-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
-#include "jversion.h" /* for version message */
-
-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
-#ifdef __MWERKS__
-#include <SIOUX.h> /* Metrowerks needs this */
-#include <console.h> /* ... and this */
-#endif
-#ifdef THINK_C
-#include <console.h> /* Think declares it here */
-#endif
-#endif
-
-
-/* Create the add-on message string table. */
-
-#define JMESSAGE(code,string) string ,
-
-static const char * const cdjpeg_message_table[] = {
-#include "cderror.h"
- NULL
-};
-
-
-/*
- * This routine determines what format the input file is,
- * and selects the appropriate input-reading module.
- *
- * To determine which family of input formats the file belongs to,
- * we may look only at the first byte of the file, since C does not
- * guarantee that more than one character can be pushed back with ungetc.
- * Looking at additional bytes would require one of these approaches:
- * 1) assume we can fseek() the input file (fails for piped input);
- * 2) assume we can push back more than one character (works in
- * some C implementations, but unportable);
- * 3) provide our own buffering (breaks input readers that want to use
- * stdio directly, such as the RLE library);
- * or 4) don't put back the data, and modify the input_init methods to assume
- * they start reading after the start of file (also breaks RLE library).
- * #1 is attractive for MS-DOS but is untenable on Unix.
- *
- * The most portable solution for file types that can't be identified by their
- * first byte is to make the user tell us what they are. This is also the
- * only approach for "raw" file types that contain only arbitrary values.
- * We presently apply this method for Targa files. Most of the time Targa
- * files start with 0x00, so we recognize that case. Potentially, however,
- * a Targa file could start with any byte value (byte 0 is the length of the
- * seldom-used ID field), so we provide a switch to force Targa input mode.
- */
-
-static boolean is_targa; /* records user -targa switch */
-
-
-LOCAL(cjpeg_source_ptr)
-select_file_type (j_compress_ptr cinfo, FILE * infile)
-{
- int c;
-
- if (is_targa) {
-#ifdef TARGA_SUPPORTED
- return jinit_read_targa(cinfo);
-#else
- ERREXIT(cinfo, JERR_TGA_NOTCOMP);
-#endif
- }
-
- if ((c = getc(infile)) == EOF)
- ERREXIT(cinfo, JERR_INPUT_EMPTY);
- if (ungetc(c, infile) == EOF)
- ERREXIT(cinfo, JERR_UNGETC_FAILED);
-
- switch (c) {
-#ifdef BMP_SUPPORTED
- case 'B':
- return jinit_read_bmp(cinfo);
-#endif
-#ifdef GIF_SUPPORTED
- case 'G':
- return jinit_read_gif(cinfo);
-#endif
-#ifdef PPM_SUPPORTED
- case 'P':
- return jinit_read_ppm(cinfo);
-#endif
-#ifdef RLE_SUPPORTED
- case 'R':
- return jinit_read_rle(cinfo);
-#endif
-#ifdef TARGA_SUPPORTED
- case 0x00:
- return jinit_read_targa(cinfo);
-#endif
- default:
- ERREXIT(cinfo, JERR_UNKNOWN_FORMAT);
- break;
- }
-
- return NULL; /* suppress compiler warnings */
-}
-
-
-/*
- * Argument-parsing code.
- * The switch parser is designed to be useful with DOS-style command line
- * syntax, ie, intermixed switches and file names, where only the switches
- * to the left of a given file name affect processing of that file.
- * The main program in this file doesn't actually use this capability...
- */
-
-
-static const char * progname; /* program name for error messages */
-static char * outfilename; /* for -outfile switch */
-
-
-LOCAL(void)
-usage (void)
-/* complain about bad command line */
-{
- fprintf(stderr, "usage: %s [switches] ", progname);
-#ifdef TWO_FILE_COMMANDLINE
- fprintf(stderr, "inputfile outputfile\n");
-#else
- fprintf(stderr, "[inputfile]\n");
-#endif
-
- fprintf(stderr, "Switches (names may be abbreviated):\n");
- fprintf(stderr, " -quality N Compression quality (0..100; 5-95 is useful range)\n");
- fprintf(stderr, " -grayscale Create monochrome JPEG file\n");
-#ifdef ENTROPY_OPT_SUPPORTED
- fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
-#endif
-#ifdef C_PROGRESSIVE_SUPPORTED
- fprintf(stderr, " -progressive Create progressive JPEG file\n");
-#endif
-#ifdef TARGA_SUPPORTED
- fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n");
-#endif
- fprintf(stderr, "Switches for advanced users:\n");
-#ifdef DCT_ISLOW_SUPPORTED
- fprintf(stderr, " -dct int Use integer DCT method%s\n",
- (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
-#endif
-#ifdef DCT_IFAST_SUPPORTED
- fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
- (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
-#endif
-#ifdef DCT_FLOAT_SUPPORTED
- fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
- (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
-#endif
- fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
-#ifdef INPUT_SMOOTHING_SUPPORTED
- fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength)\n");
-#endif
- fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
- fprintf(stderr, " -outfile name Specify name for output file\n");
- fprintf(stderr, " -verbose or -debug Emit debug output\n");
- fprintf(stderr, "Switches for wizards:\n");
-#ifdef C_ARITH_CODING_SUPPORTED
- fprintf(stderr, " -arithmetic Use arithmetic coding\n");
-#endif
- fprintf(stderr, " -baseline Force baseline quantization tables\n");
- fprintf(stderr, " -qtables file Use quantization tables given in file\n");
- fprintf(stderr, " -qslots N[,...] Set component quantization tables\n");
- fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n");
-#ifdef C_MULTISCAN_FILES_SUPPORTED
- fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n");
-#endif
- exit(EXIT_FAILURE);
-}
-
-
-LOCAL(int)
-parse_switches (j_compress_ptr cinfo, int argc, char **argv,
- int last_file_arg_seen, boolean for_real)
-/* Parse optional switches.
- * Returns argv[] index of first file-name argument (== argc if none).
- * Any file names with indexes <= last_file_arg_seen are ignored;
- * they have presumably been processed in a previous iteration.
- * (Pass 0 for last_file_arg_seen on the first or only iteration.)
- * for_real is FALSE on the first (dummy) pass; we may skip any expensive
- * processing.
- */
-{
- int argn;
- char * arg;
- int quality; /* -quality parameter */
- int q_scale_factor; /* scaling percentage for -qtables */
- boolean force_baseline;
- boolean simple_progressive;
- char * qtablefile = NULL; /* saves -qtables filename if any */
- char * qslotsarg = NULL; /* saves -qslots parm if any */
- char * samplearg = NULL; /* saves -sample parm if any */
- char * scansarg = NULL; /* saves -scans parm if any */
-
- /* Set up default JPEG parameters. */
- /* Note that default -quality level need not, and does not,
- * match the default scaling for an explicit -qtables argument.
- */
- quality = 75; /* default -quality value */
- q_scale_factor = 100; /* default to no scaling for -qtables */
- force_baseline = FALSE; /* by default, allow 16-bit quantizers */
- simple_progressive = FALSE;
- is_targa = FALSE;
- outfilename = NULL;
- cinfo->err->trace_level = 0;
-
- /* Scan command line options, adjust parameters */
-
- for (argn = 1; argn < argc; argn++) {
- arg = argv[argn];
- if (*arg != '-') {
- /* Not a switch, must be a file name argument */
- if (argn <= last_file_arg_seen) {
- outfilename = NULL; /* -outfile applies to just one input file */
- continue; /* ignore this name if previously processed */
- }
- break; /* else done parsing switches */
- }
- arg++; /* advance past switch marker character */
-
- if (keymatch(arg, "arithmetic", 1)) {
- /* Use arithmetic coding. */
-#ifdef C_ARITH_CODING_SUPPORTED
- cinfo->arith_code = TRUE;
-#else
- fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
- progname);
- exit(EXIT_FAILURE);
-#endif
-
- } else if (keymatch(arg, "baseline", 1)) {
- /* Force baseline-compatible output (8-bit quantizer values). */
- force_baseline = TRUE;
-
- } else if (keymatch(arg, "dct", 2)) {
- /* Select DCT algorithm. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (keymatch(argv[argn], "int", 1)) {
- cinfo->dct_method = JDCT_ISLOW;
- } else if (keymatch(argv[argn], "fast", 2)) {
- cinfo->dct_method = JDCT_IFAST;
- } else if (keymatch(argv[argn], "float", 2)) {
- cinfo->dct_method = JDCT_FLOAT;
- } else
- usage();
-
- } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
- /* Enable debug printouts. */
- /* On first -d, print version identification */
- static boolean printed_version = FALSE;
-
- if (! printed_version) {
- fprintf(stderr, "Independent JPEG Group's CJPEG, version %s\n%s\n",
- JVERSION, JCOPYRIGHT);
- printed_version = TRUE;
- }
- cinfo->err->trace_level++;
-
- } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
- /* Force a monochrome JPEG file to be generated. */
- jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
-
- } else if (keymatch(arg, "maxmemory", 3)) {
- /* Maximum memory in Kb (or Mb with 'm'). */
- long lval;
- char ch = 'x';
-
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
- usage();
- if (ch == 'm' || ch == 'M')
- lval *= 1000L;
- cinfo->mem->max_memory_to_use = lval * 1000L;
-
- } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
- /* Enable entropy parm optimization. */
-#ifdef ENTROPY_OPT_SUPPORTED
- cinfo->optimize_coding = TRUE;
-#else
- fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
- progname);
- exit(EXIT_FAILURE);
-#endif
-
- } else if (keymatch(arg, "outfile", 4)) {
- /* Set output file name. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- outfilename = argv[argn]; /* save it away for later use */
-
- } else if (keymatch(arg, "progressive", 1)) {
- /* Select simple progressive mode. */
-#ifdef C_PROGRESSIVE_SUPPORTED
- simple_progressive = TRUE;
- /* We must postpone execution until num_components is known. */
-#else
- fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
- progname);
- exit(EXIT_FAILURE);
-#endif
-
- } else if (keymatch(arg, "quality", 1)) {
- /* Quality factor (quantization table scaling factor). */
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (sscanf(argv[argn], "%d", &quality) != 1)
- usage();
- /* Change scale factor in case -qtables is present. */
- q_scale_factor = jpeg_quality_scaling(quality);
-
- } else if (keymatch(arg, "qslots", 2)) {
- /* Quantization table slot numbers. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- qslotsarg = argv[argn];
- /* Must delay setting qslots until after we have processed any
- * colorspace-determining switches, since jpeg_set_colorspace sets
- * default quant table numbers.
- */
-
- } else if (keymatch(arg, "qtables", 2)) {
- /* Quantization tables fetched from file. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- qtablefile = argv[argn];
- /* We postpone actually reading the file in case -quality comes later. */
-
- } else if (keymatch(arg, "restart", 1)) {
- /* Restart interval in MCU rows (or in MCUs with 'b'). */
- long lval;
- char ch = 'x';
-
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
- usage();
- if (lval < 0 || lval > 65535L)
- usage();
- if (ch == 'b' || ch == 'B') {
- cinfo->restart_interval = (unsigned int) lval;
- cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
- } else {
- cinfo->restart_in_rows = (int) lval;
- /* restart_interval will be computed during startup */
- }
-
- } else if (keymatch(arg, "sample", 2)) {
- /* Set sampling factors. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- samplearg = argv[argn];
- /* Must delay setting sample factors until after we have processed any
- * colorspace-determining switches, since jpeg_set_colorspace sets
- * default sampling factors.
- */
-
- } else if (keymatch(arg, "scans", 2)) {
- /* Set scan script. */
-#ifdef C_MULTISCAN_FILES_SUPPORTED
- if (++argn >= argc) /* advance to next argument */
- usage();
- scansarg = argv[argn];
- /* We must postpone reading the file in case -progressive appears. */
-#else
- fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
- progname);
- exit(EXIT_FAILURE);
-#endif
-
- } else if (keymatch(arg, "smooth", 2)) {
- /* Set input smoothing factor. */
- int val;
-
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (sscanf(argv[argn], "%d", &val) != 1)
- usage();
- if (val < 0 || val > 100)
- usage();
- cinfo->smoothing_factor = val;
-
- } else if (keymatch(arg, "targa", 1)) {
- /* Input file is Targa format. */
- is_targa = TRUE;
-
- } else {
- usage(); /* bogus switch */
- }
- }
-
- /* Post-switch-scanning cleanup */
-
- if (for_real) {
-
- /* Set quantization tables for selected quality. */
- /* Some or all may be overridden if -qtables is present. */
- jpeg_set_quality(cinfo, quality, force_baseline);
-
- if (qtablefile != NULL) /* process -qtables if it was present */
- if (! read_quant_tables(cinfo, qtablefile,
- q_scale_factor, force_baseline))
- usage();
-
- if (qslotsarg != NULL) /* process -qslots if it was present */
- if (! set_quant_slots(cinfo, qslotsarg))
- usage();
-
- if (samplearg != NULL) /* process -sample if it was present */
- if (! set_sample_factors(cinfo, samplearg))
- usage();
-
-#ifdef C_PROGRESSIVE_SUPPORTED
- if (simple_progressive) /* process -progressive; -scans can override */
- jpeg_simple_progression(cinfo);
-#endif
-
-#ifdef C_MULTISCAN_FILES_SUPPORTED
- if (scansarg != NULL) /* process -scans if it was present */
- if (! read_scan_script(cinfo, scansarg))
- usage();
-#endif
- }
-
- return argn; /* return index of next arg (file name) */
-}
-
-
-/*
- * The main program.
- */
-
-int
-main (int argc, char **argv)
-{
- struct jpeg_compress_struct cinfo;
- struct jpeg_error_mgr jerr;
-#ifdef PROGRESS_REPORT
- struct cdjpeg_progress_mgr progress;
-#endif
- int file_index;
- cjpeg_source_ptr src_mgr;
- FILE * input_file;
- FILE * output_file;
- JDIMENSION num_scanlines;
-
- /* On Mac, fetch a command line. */
-#ifdef USE_CCOMMAND
- argc = ccommand(&argv);
-#endif
-
- progname = argv[0];
- if (progname == NULL || progname[0] == 0)
- progname = "cjpeg"; /* in case C library doesn't provide it */
-
- /* Initialize the JPEG compression object with default error handling. */
- cinfo.err = jpeg_std_error(&jerr);
- jpeg_create_compress(&cinfo);
- /* Add some application-specific error messages (from cderror.h) */
- jerr.addon_message_table = cdjpeg_message_table;
- jerr.first_addon_message = JMSG_FIRSTADDONCODE;
- jerr.last_addon_message = JMSG_LASTADDONCODE;
-
- /* Now safe to enable signal catcher. */
-#ifdef NEED_SIGNAL_CATCHER
- enable_signal_catcher((j_common_ptr) &cinfo);
-#endif
-
- /* Initialize JPEG parameters.
- * Much of this may be overridden later.
- * In particular, we don't yet know the input file's color space,
- * but we need to provide some value for jpeg_set_defaults() to work.
- */
-
- cinfo.in_color_space = JCS_RGB; /* arbitrary guess */
- jpeg_set_defaults(&cinfo);
-
- /* Scan command line to find file names.
- * It is convenient to use just one switch-parsing routine, but the switch
- * values read here are ignored; we will rescan the switches after opening
- * the input file.
- */
-
- file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
-
-#ifdef TWO_FILE_COMMANDLINE
- /* Must have either -outfile switch or explicit output file name */
- if (outfilename == NULL) {
- if (file_index != argc-2) {
- fprintf(stderr, "%s: must name one input and one output file\n",
- progname);
- usage();
- }
- outfilename = argv[file_index+1];
- } else {
- if (file_index != argc-1) {
- fprintf(stderr, "%s: must name one input and one output file\n",
- progname);
- usage();
- }
- }
-#else
- /* Unix style: expect zero or one file name */
- if (file_index < argc-1) {
- fprintf(stderr, "%s: only one input file\n", progname);
- usage();
- }
-#endif /* TWO_FILE_COMMANDLINE */
-
- /* Open the input file. */
- if (file_index < argc) {
- if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
- exit(EXIT_FAILURE);
- }
- } else {
- /* default input file is stdin */
- input_file = read_stdin();
- }
-
- /* Open the output file. */
- if (outfilename != NULL) {
- if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
- exit(EXIT_FAILURE);
- }
- } else {
- /* default output file is stdout */
- output_file = write_stdout();
- }
-
-#ifdef PROGRESS_REPORT
- start_progress_monitor((j_common_ptr) &cinfo, &progress);
-#endif
-
- /* Figure out the input file format, and set up to read it. */
- src_mgr = select_file_type(&cinfo, input_file);
- src_mgr->input_file = input_file;
-
- /* Read the input file header to obtain file size & colorspace. */
- (*src_mgr->start_input) (&cinfo, src_mgr);
-
- /* Now that we know input colorspace, fix colorspace-dependent defaults */
- jpeg_default_colorspace(&cinfo);
-
- /* Adjust default compression parameters by re-parsing the options */
- file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
-
- /* Specify data destination for compression */
- jpeg_stdio_dest(&cinfo, output_file);
-
- /* Start compressor */
- jpeg_start_compress(&cinfo, TRUE);
-
- /* Process data */
- while (cinfo.next_scanline < cinfo.image_height) {
- num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
- (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
- }
-
- /* Finish compression and release memory */
- (*src_mgr->finish_input) (&cinfo, src_mgr);
- jpeg_finish_compress(&cinfo);
- jpeg_destroy_compress(&cinfo);
-
- /* Close files, if we opened them */
- if (input_file != stdin)
- fclose(input_file);
- if (output_file != stdout)
- fclose(output_file);
-
-#ifdef PROGRESS_REPORT
- end_progress_monitor((j_common_ptr) &cinfo);
-#endif
-
- /* All done. */
- exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
- return 0; /* suppress no-return-value warnings */
-}
+/*
+ * cjpeg.c
+ *
+ * Copyright (C) 1991-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a command-line user interface for the JPEG compressor.
+ * It should work on any system with Unix- or MS-DOS-style command lines.
+ *
+ * Two different command line styles are permitted, depending on the
+ * compile-time switch TWO_FILE_COMMANDLINE:
+ * cjpeg [options] inputfile outputfile
+ * cjpeg [options] [inputfile]
+ * In the second style, output is always to standard output, which you'd
+ * normally redirect to a file or pipe to some other program. Input is
+ * either from a named file or from standard input (typically redirected).
+ * The second style is convenient on Unix but is unhelpful on systems that
+ * don't support pipes. Also, you MUST use the first style if your system
+ * doesn't do binary I/O to stdin/stdout.
+ * To simplify script writing, the "-outfile" switch is provided. The syntax
+ * cjpeg [options] -outfile outputfile inputfile
+ * works regardless of which command line style is used.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+#include "jversion.h" /* for version message */
+
+#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
+#ifdef __MWERKS__
+#include <SIOUX.h> /* Metrowerks needs this */
+#include <console.h> /* ... and this */
+#endif
+#ifdef THINK_C
+#include <console.h> /* Think declares it here */
+#endif
+#endif
+
+
+/* Create the add-on message string table. */
+
+#define JMESSAGE(code,string) string ,
+
+static const char * const cdjpeg_message_table[] = {
+#include "cderror.h"
+ NULL
+};
+
+
+/*
+ * This routine determines what format the input file is,
+ * and selects the appropriate input-reading module.
+ *
+ * To determine which family of input formats the file belongs to,
+ * we may look only at the first byte of the file, since C does not
+ * guarantee that more than one character can be pushed back with ungetc.
+ * Looking at additional bytes would require one of these approaches:
+ * 1) assume we can fseek() the input file (fails for piped input);
+ * 2) assume we can push back more than one character (works in
+ * some C implementations, but unportable);
+ * 3) provide our own buffering (breaks input readers that want to use
+ * stdio directly, such as the RLE library);
+ * or 4) don't put back the data, and modify the input_init methods to assume
+ * they start reading after the start of file (also breaks RLE library).
+ * #1 is attractive for MS-DOS but is untenable on Unix.
+ *
+ * The most portable solution for file types that can't be identified by their
+ * first byte is to make the user tell us what they are. This is also the
+ * only approach for "raw" file types that contain only arbitrary values.
+ * We presently apply this method for Targa files. Most of the time Targa
+ * files start with 0x00, so we recognize that case. Potentially, however,
+ * a Targa file could start with any byte value (byte 0 is the length of the
+ * seldom-used ID field), so we provide a switch to force Targa input mode.
+ */
+
+static boolean is_targa; /* records user -targa switch */
+
+
+LOCAL(cjpeg_source_ptr)
+select_file_type (j_compress_ptr cinfo, FILE * infile)
+{
+ int c;
+
+ if (is_targa) {
+#ifdef TARGA_SUPPORTED
+ return jinit_read_targa(cinfo);
+#else
+ ERREXIT(cinfo, JERR_TGA_NOTCOMP);
+#endif
+ }
+
+ if ((c = getc(infile)) == EOF)
+ ERREXIT(cinfo, JERR_INPUT_EMPTY);
+ if (ungetc(c, infile) == EOF)
+ ERREXIT(cinfo, JERR_UNGETC_FAILED);
+
+ switch (c) {
+#ifdef BMP_SUPPORTED
+ case 'B':
+ return jinit_read_bmp(cinfo);
+#endif
+#ifdef GIF_SUPPORTED
+ case 'G':
+ return jinit_read_gif(cinfo);
+#endif
+#ifdef PPM_SUPPORTED
+ case 'P':
+ return jinit_read_ppm(cinfo);
+#endif
+#ifdef RLE_SUPPORTED
+ case 'R':
+ return jinit_read_rle(cinfo);
+#endif
+#ifdef TARGA_SUPPORTED
+ case 0x00:
+ return jinit_read_targa(cinfo);
+#endif
+ default:
+ ERREXIT(cinfo, JERR_UNKNOWN_FORMAT);
+ break;
+ }
+
+ return NULL; /* suppress compiler warnings */
+}
+
+
+/*
+ * Argument-parsing code.
+ * The switch parser is designed to be useful with DOS-style command line
+ * syntax, ie, intermixed switches and file names, where only the switches
+ * to the left of a given file name affect processing of that file.
+ * The main program in this file doesn't actually use this capability...
+ */
+
+
+static const char * progname; /* program name for error messages */
+static char * outfilename; /* for -outfile switch */
+
+
+LOCAL(void)
+usage (void)
+/* complain about bad command line */
+{
+ fprintf(stderr, "usage: %s [switches] ", progname);
+#ifdef TWO_FILE_COMMANDLINE
+ fprintf(stderr, "inputfile outputfile\n");
+#else
+ fprintf(stderr, "[inputfile]\n");
+#endif
+
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
+ fprintf(stderr, " -quality N Compression quality (0..100; 5-95 is useful range)\n");
+ fprintf(stderr, " -grayscale Create monochrome JPEG file\n");
+#ifdef ENTROPY_OPT_SUPPORTED
+ fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
+#endif
+#ifdef C_PROGRESSIVE_SUPPORTED
+ fprintf(stderr, " -progressive Create progressive JPEG file\n");
+#endif
+#ifdef TARGA_SUPPORTED
+ fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n");
+#endif
+ fprintf(stderr, "Switches for advanced users:\n");
+#ifdef DCT_ISLOW_SUPPORTED
+ fprintf(stderr, " -dct int Use integer DCT method%s\n",
+ (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
+#endif
+#ifdef DCT_IFAST_SUPPORTED
+ fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
+ (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
+#endif
+#ifdef DCT_FLOAT_SUPPORTED
+ fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
+ (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
+#endif
+ fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
+#ifdef INPUT_SMOOTHING_SUPPORTED
+ fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength)\n");
+#endif
+ fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
+ fprintf(stderr, " -outfile name Specify name for output file\n");
+ fprintf(stderr, " -verbose or -debug Emit debug output\n");
+ fprintf(stderr, "Switches for wizards:\n");
+#ifdef C_ARITH_CODING_SUPPORTED
+ fprintf(stderr, " -arithmetic Use arithmetic coding\n");
+#endif
+ fprintf(stderr, " -baseline Force baseline quantization tables\n");
+ fprintf(stderr, " -qtables file Use quantization tables given in file\n");
+ fprintf(stderr, " -qslots N[,...] Set component quantization tables\n");
+ fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n");
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n");
+#endif
+ exit(EXIT_FAILURE);
+}
+
+
+LOCAL(int)
+parse_switches (j_compress_ptr cinfo, int argc, char **argv,
+ int last_file_arg_seen, boolean for_real)
+/* Parse optional switches.
+ * Returns argv[] index of first file-name argument (== argc if none).
+ * Any file names with indexes <= last_file_arg_seen are ignored;
+ * they have presumably been processed in a previous iteration.
+ * (Pass 0 for last_file_arg_seen on the first or only iteration.)
+ * for_real is FALSE on the first (dummy) pass; we may skip any expensive
+ * processing.
+ */
+{
+ int argn;
+ char * arg;
+ int quality; /* -quality parameter */
+ int q_scale_factor; /* scaling percentage for -qtables */
+ boolean force_baseline;
+ boolean simple_progressive;
+ char * qtablefile = NULL; /* saves -qtables filename if any */
+ char * qslotsarg = NULL; /* saves -qslots parm if any */
+ char * samplearg = NULL; /* saves -sample parm if any */
+ char * scansarg = NULL; /* saves -scans parm if any */
+
+ /* Set up default JPEG parameters. */
+ /* Note that default -quality level need not, and does not,
+ * match the default scaling for an explicit -qtables argument.
+ */
+ quality = 75; /* default -quality value */
+ q_scale_factor = 100; /* default to no scaling for -qtables */
+ force_baseline = FALSE; /* by default, allow 16-bit quantizers */
+ simple_progressive = FALSE;
+ is_targa = FALSE;
+ outfilename = NULL;
+ cinfo->err->trace_level = 0;
+
+ /* Scan command line options, adjust parameters */
+
+ for (argn = 1; argn < argc; argn++) {
+ arg = argv[argn];
+ if (*arg != '-') {
+ /* Not a switch, must be a file name argument */
+ if (argn <= last_file_arg_seen) {
+ outfilename = NULL; /* -outfile applies to just one input file */
+ continue; /* ignore this name if previously processed */
+ }
+ break; /* else done parsing switches */
+ }
+ arg++; /* advance past switch marker character */
+
+ if (keymatch(arg, "arithmetic", 1)) {
+ /* Use arithmetic coding. */
+#ifdef C_ARITH_CODING_SUPPORTED
+ cinfo->arith_code = TRUE;
+#else
+ fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "baseline", 1)) {
+ /* Force baseline-compatible output (8-bit quantizer values). */
+ force_baseline = TRUE;
+
+ } else if (keymatch(arg, "dct", 2)) {
+ /* Select DCT algorithm. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (keymatch(argv[argn], "int", 1)) {
+ cinfo->dct_method = JDCT_ISLOW;
+ } else if (keymatch(argv[argn], "fast", 2)) {
+ cinfo->dct_method = JDCT_IFAST;
+ } else if (keymatch(argv[argn], "float", 2)) {
+ cinfo->dct_method = JDCT_FLOAT;
+ } else
+ usage();
+
+ } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
+ /* Enable debug printouts. */
+ /* On first -d, print version identification */
+ static boolean printed_version = FALSE;
+
+ if (! printed_version) {
+ fprintf(stderr, "Independent JPEG Group's CJPEG, version %s\n%s\n",
+ JVERSION, JCOPYRIGHT);
+ printed_version = TRUE;
+ }
+ cinfo->err->trace_level++;
+
+ } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
+ /* Force a monochrome JPEG file to be generated. */
+ jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
+
+ } else if (keymatch(arg, "maxmemory", 3)) {
+ /* Maximum memory in Kb (or Mb with 'm'). */
+ long lval;
+ char ch = 'x';
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
+ usage();
+ if (ch == 'm' || ch == 'M')
+ lval *= 1000L;
+ cinfo->mem->max_memory_to_use = lval * 1000L;
+
+ } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
+ /* Enable entropy parm optimization. */
+#ifdef ENTROPY_OPT_SUPPORTED
+ cinfo->optimize_coding = TRUE;
+#else
+ fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "outfile", 4)) {
+ /* Set output file name. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ outfilename = argv[argn]; /* save it away for later use */
+
+ } else if (keymatch(arg, "progressive", 1)) {
+ /* Select simple progressive mode. */
+#ifdef C_PROGRESSIVE_SUPPORTED
+ simple_progressive = TRUE;
+ /* We must postpone execution until num_components is known. */
+#else
+ fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "quality", 1)) {
+ /* Quality factor (quantization table scaling factor). */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%d", &quality) != 1)
+ usage();
+ /* Change scale factor in case -qtables is present. */
+ q_scale_factor = jpeg_quality_scaling(quality);
+
+ } else if (keymatch(arg, "qslots", 2)) {
+ /* Quantization table slot numbers. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ qslotsarg = argv[argn];
+ /* Must delay setting qslots until after we have processed any
+ * colorspace-determining switches, since jpeg_set_colorspace sets
+ * default quant table numbers.
+ */
+
+ } else if (keymatch(arg, "qtables", 2)) {
+ /* Quantization tables fetched from file. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ qtablefile = argv[argn];
+ /* We postpone actually reading the file in case -quality comes later. */
+
+ } else if (keymatch(arg, "restart", 1)) {
+ /* Restart interval in MCU rows (or in MCUs with 'b'). */
+ long lval;
+ char ch = 'x';
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
+ usage();
+ if (lval < 0 || lval > 65535L)
+ usage();
+ if (ch == 'b' || ch == 'B') {
+ cinfo->restart_interval = (unsigned int) lval;
+ cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
+ } else {
+ cinfo->restart_in_rows = (int) lval;
+ /* restart_interval will be computed during startup */
+ }
+
+ } else if (keymatch(arg, "sample", 2)) {
+ /* Set sampling factors. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ samplearg = argv[argn];
+ /* Must delay setting sample factors until after we have processed any
+ * colorspace-determining switches, since jpeg_set_colorspace sets
+ * default sampling factors.
+ */
+
+ } else if (keymatch(arg, "scans", 2)) {
+ /* Set scan script. */
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ scansarg = argv[argn];
+ /* We must postpone reading the file in case -progressive appears. */
+#else
+ fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "smooth", 2)) {
+ /* Set input smoothing factor. */
+ int val;
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%d", &val) != 1)
+ usage();
+ if (val < 0 || val > 100)
+ usage();
+ cinfo->smoothing_factor = val;
+
+ } else if (keymatch(arg, "targa", 1)) {
+ /* Input file is Targa format. */
+ is_targa = TRUE;
+
+ } else {
+ usage(); /* bogus switch */
+ }
+ }
+
+ /* Post-switch-scanning cleanup */
+
+ if (for_real) {
+
+ /* Set quantization tables for selected quality. */
+ /* Some or all may be overridden if -qtables is present. */
+ jpeg_set_quality(cinfo, quality, force_baseline);
+
+ if (qtablefile != NULL) /* process -qtables if it was present */
+ if (! read_quant_tables(cinfo, qtablefile,
+ q_scale_factor, force_baseline))
+ usage();
+
+ if (qslotsarg != NULL) /* process -qslots if it was present */
+ if (! set_quant_slots(cinfo, qslotsarg))
+ usage();
+
+ if (samplearg != NULL) /* process -sample if it was present */
+ if (! set_sample_factors(cinfo, samplearg))
+ usage();
+
+#ifdef C_PROGRESSIVE_SUPPORTED
+ if (simple_progressive) /* process -progressive; -scans can override */
+ jpeg_simple_progression(cinfo);
+#endif
+
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ if (scansarg != NULL) /* process -scans if it was present */
+ if (! read_scan_script(cinfo, scansarg))
+ usage();
+#endif
+ }
+
+ return argn; /* return index of next arg (file name) */
+}
+
+
+/*
+ * The main program.
+ */
+
+int
+main (int argc, char **argv)
+{
+ struct jpeg_compress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+#ifdef PROGRESS_REPORT
+ struct cdjpeg_progress_mgr progress;
+#endif
+ int file_index;
+ cjpeg_source_ptr src_mgr;
+ FILE * input_file;
+ FILE * output_file;
+ JDIMENSION num_scanlines;
+
+ /* On Mac, fetch a command line. */
+#ifdef USE_CCOMMAND
+ argc = ccommand(&argv);
+#endif
+
+ progname = argv[0];
+ if (progname == NULL || progname[0] == 0)
+ progname = "cjpeg"; /* in case C library doesn't provide it */
+
+ /* Initialize the JPEG compression object with default error handling. */
+ cinfo.err = jpeg_std_error(&jerr);
+ jpeg_create_compress(&cinfo);
+ /* Add some application-specific error messages (from cderror.h) */
+ jerr.addon_message_table = cdjpeg_message_table;
+ jerr.first_addon_message = JMSG_FIRSTADDONCODE;
+ jerr.last_addon_message = JMSG_LASTADDONCODE;
+
+ /* Now safe to enable signal catcher. */
+#ifdef NEED_SIGNAL_CATCHER
+ enable_signal_catcher((j_common_ptr) &cinfo);
+#endif
+
+ /* Initialize JPEG parameters.
+ * Much of this may be overridden later.
+ * In particular, we don't yet know the input file's color space,
+ * but we need to provide some value for jpeg_set_defaults() to work.
+ */
+
+ cinfo.in_color_space = JCS_RGB; /* arbitrary guess */
+ jpeg_set_defaults(&cinfo);
+
+ /* Scan command line to find file names.
+ * It is convenient to use just one switch-parsing routine, but the switch
+ * values read here are ignored; we will rescan the switches after opening
+ * the input file.
+ */
+
+ file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
+
+#ifdef TWO_FILE_COMMANDLINE
+ /* Must have either -outfile switch or explicit output file name */
+ if (outfilename == NULL) {
+ if (file_index != argc-2) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ outfilename = argv[file_index+1];
+ } else {
+ if (file_index != argc-1) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ }
+#else
+ /* Unix style: expect zero or one file name */
+ if (file_index < argc-1) {
+ fprintf(stderr, "%s: only one input file\n", progname);
+ usage();
+ }
+#endif /* TWO_FILE_COMMANDLINE */
+
+ /* Open the input file. */
+ if (file_index < argc) {
+ if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default input file is stdin */
+ input_file = read_stdin();
+ }
+
+ /* Open the output file. */
+ if (outfilename != NULL) {
+ if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default output file is stdout */
+ output_file = write_stdout();
+ }
+
+#ifdef PROGRESS_REPORT
+ start_progress_monitor((j_common_ptr) &cinfo, &progress);
+#endif
+
+ /* Figure out the input file format, and set up to read it. */
+ src_mgr = select_file_type(&cinfo, input_file);
+ src_mgr->input_file = input_file;
+
+ /* Read the input file header to obtain file size & colorspace. */
+ (*src_mgr->start_input) (&cinfo, src_mgr);
+
+ /* Now that we know input colorspace, fix colorspace-dependent defaults */
+ jpeg_default_colorspace(&cinfo);
+
+ /* Adjust default compression parameters by re-parsing the options */
+ file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
+
+ /* Specify data destination for compression */
+ jpeg_stdio_dest(&cinfo, output_file);
+
+ /* Start compressor */
+ jpeg_start_compress(&cinfo, TRUE);
+
+ /* Process data */
+ while (cinfo.next_scanline < cinfo.image_height) {
+ num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
+ (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
+ }
+
+ /* Finish compression and release memory */
+ (*src_mgr->finish_input) (&cinfo, src_mgr);
+ jpeg_finish_compress(&cinfo);
+ jpeg_destroy_compress(&cinfo);
+
+ /* Close files, if we opened them */
+ if (input_file != stdin)
+ fclose(input_file);
+ if (output_file != stdout)
+ fclose(output_file);
+
+#ifdef PROGRESS_REPORT
+ end_progress_monitor((j_common_ptr) &cinfo);
+#endif
+
+ /* All done. */
+ exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
+ return 0; /* suppress no-return-value warnings */
+}
diff --git a/test/monniaux/jpeg-6b/cjpeg.i b/test/monniaux/jpeg-6b/cjpeg.i
deleted file mode 100644
index 3ac77ff4..00000000
--- a/test/monniaux/jpeg-6b/cjpeg.i
+++ /dev/null
@@ -1,3270 +0,0 @@
-# 1 "cjpeg.c"
-# 1 "<built-in>"
-# 1 "<command-line>"
-# 1 "cjpeg.c"
-# 26 "cjpeg.c"
-# 1 "cdjpeg.h" 1
-# 14 "cdjpeg.h"
-# 1 "jinclude.h" 1
-# 20 "jinclude.h"
-# 1 "jconfig.h" 1
-# 21 "jinclude.h" 2
-# 35 "jinclude.h"
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 1 3 4
-# 147 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 3 4
-typedef long int ptrdiff_t;
-# 212 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 3 4
-typedef unsigned long long size_t;
-# 324 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 3 4
-typedef int wchar_t;
-# 36 "jinclude.h" 2
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 1 3
-# 10 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/ieeefp.h" 1 3
-# 11 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/_ansi.h" 1 3
-# 15 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/_ansi.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/newlib.h" 1 3
-# 16 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/_ansi.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/config.h" 1 3
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/ieeefp.h" 1 3
-# 5 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/config.h" 2 3
-# 17 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/_ansi.h" 2 3
-# 12 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 2 3
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 1 3 4
-# 16 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 2 3
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 1 3
-# 13 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/_ansi.h" 1 3
-# 14 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/_types.h" 1 3
-# 12 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/_types.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_types.h" 1 3
-
-
-
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 1 3
-# 22 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include-fixed/limits.h" 1 3 4
-# 23 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 2 3
-
-
-
-typedef signed char __int8_t ;
-typedef unsigned char __uint8_t ;
-# 36 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 3
-typedef signed short __int16_t;
-typedef unsigned short __uint16_t;
-# 46 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 3
-typedef __int16_t __int_least16_t;
-typedef __uint16_t __uint_least16_t;
-# 62 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 3
-typedef signed int __int32_t;
-typedef unsigned int __uint32_t;
-# 76 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 3
-typedef __int32_t __int_least32_t;
-typedef __uint32_t __uint_least32_t;
-# 93 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 3
-typedef signed long __int64_t;
-typedef unsigned long __uint64_t;
-# 8 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_types.h" 2 3
-# 13 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/_types.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/lock.h" 1 3
-# 9 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/lock.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 1 3
-# 12 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 1 3
-# 13 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/registers.h" 1 3
-# 14 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/types.h" 1 3
-# 16 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/types.h" 3
-typedef unsigned char __k1_uchar;
-
-
-typedef unsigned short __k1_ushort;
-
-
-typedef unsigned int __k1_uint;
-
-
-typedef unsigned long __k1_ulong;
-
-
-typedef signed long __k1_long;
-
-
-
-typedef unsigned char __k1_uint8_t;
-
-
-typedef signed char __k1_int8_t;
-
-
-typedef unsigned short __k1_uint16_t;
-
-
-typedef signed short __k1_int16_t;
-
-
-typedef unsigned int __k1_uint32_t;
-
-
-typedef signed int __k1_int32_t;
-
-
-typedef unsigned long long __k1_uint64_t;
-
-
-typedef signed long long __k1_int64_t;
-# 63 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/types.h" 3
-typedef long __k1_intptr_t;
-
-
-typedef unsigned long __k1_uintptr_t;
-# 15 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/assert.h" 1 3
-# 11 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/assert.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/common.h" 1 3
-# 12 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/assert.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/scall_no.h" 1 3
-# 13 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/assert.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 1 3
-# 9 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 1 3
-# 41 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef signed char int8_t ;
-typedef unsigned char uint8_t ;
-
-
-
-
-typedef signed char int_least8_t;
-typedef unsigned char uint_least8_t;
-# 57 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef signed short int16_t;
-typedef unsigned short uint16_t;
-# 67 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef int16_t int_least16_t;
-typedef uint16_t uint_least16_t;
-# 83 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef signed int int32_t;
-typedef unsigned int uint32_t;
-# 97 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef int32_t int_least32_t;
-typedef uint32_t uint_least32_t;
-# 115 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef signed long int64_t;
-typedef unsigned long uint64_t;
-# 129 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef int64_t int_least64_t;
-typedef uint64_t uint_least64_t;
-# 159 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
- typedef signed int int_fast8_t;
- typedef unsigned int uint_fast8_t;
-
-
-
-
- typedef signed int int_fast16_t;
- typedef unsigned int uint_fast16_t;
-
-
-
-
- typedef signed int int_fast32_t;
- typedef unsigned int uint_fast32_t;
-# 213 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
- typedef int_least64_t int_fast64_t;
- typedef uint_least64_t uint_fast64_t;
-
-
-
-
-
-
-
- typedef long int intmax_t;
-# 231 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
- typedef long unsigned int uintmax_t;
-# 244 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
- typedef int64_t intptr_t;
- typedef uint64_t uintptr_t;
-# 10 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 2 3
-# 21 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall(const uint32_t syscall);
-# 38 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall_with_args(const uint64_t syscall, uint64_t sc_arg0, uint64_t sc_arg1,
- uint64_t sc_arg2, uint64_t sc_arg3, uint64_t sc_arg4,
- uint64_t sc_arg5);
-# 52 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall0(const uint32_t syscall);
-# 61 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall1(const uint32_t syscall, uint64_t sc_arg0);
-# 72 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall2(const uint32_t syscall, uint64_t sc_arg0,
- uint64_t sc_arg1);
-# 85 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall3(const uint32_t syscall, uint64_t sc_arg0, uint64_t sc_arg1,
- uint64_t sc_arg2);
-# 100 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall4(const uint32_t syscall, uint64_t sc_arg0, uint64_t sc_arg1,
- uint64_t sc_arg2, uint64_t sc_arg3);
-# 116 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int
-__k1_syscall5(const uint32_t syscall, uint64_t sc_arg0, uint64_t sc_arg1,
- uint64_t sc_arg2, uint64_t sc_arg3, uint64_t sc_arg4);
-# 135 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall6(const uint32_t syscall, uint64_t sc_arg0, uint64_t sc_arg1,
- uint64_t sc_arg2, uint64_t sc_arg3, uint64_t sc_arg4,
- uint64_t sc_arg5);
-# 14 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/assert.h" 2 3
-# 16 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 2 3
-
-
-
-
-
-
-
-extern unsigned long __bsp_rtl_simu __attribute__ ((weak));
-# 32 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 3
-extern unsigned long __bsp_core_only __attribute__ ((weak));
-
-
-
-
-
-
-extern char __k1_streaming_enable(char);
-
-
-
-
-
-extern char __k1_streaming_disable(char);
-
-
-
-
-
- extern unsigned int __bsp_frequency;
-# 80 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 3
-extern int __k1_is_rm(char) __attribute__((__const__));
-
-
-
-
-
-
-extern int __k1_get_cpu_id(char) __attribute__((__const__));
-
-
-
-
-
-
-extern int __k1_get_rm_id(char);
-
-
-
-
-
-
-
-extern __k1_uint32_t __k1_sysreg_get_num(unsigned int n);
-
-
-
-
-
-
-
-extern char __k1_sysreg_set_num(unsigned int n, __k1_uint32_t i);
-
-
-
-
-
-
-extern unsigned int __k1_hw_loop_enabled(char);
-
-
-
-
-
-extern char __k1_hwloops_enable(char);
-
-
-
-
-
-extern char __k1_hwloops_disable(char);
-
-
-
-
-
-enum __k1_fpu_rounding_mode {
- _K1_FPU_NEAREST_EVEN = 0,
- _K1_FPU_TOWARDS_PLUS_INF = 1,
- _K1_FPU_TOWARDS_MINUS_INF = 2,
- _K1_FPU_TOWARDS_ZERO = 3
-};
-
-
-
-
-
-extern char __k1_fpu_set_rounding_mode(enum __k1_fpu_rounding_mode mode);
-
-
-
-
-
-extern enum __k1_fpu_rounding_mode __k1_fpu_get_rounding_mode(char);
-
-
-
-
-
-enum __k1_fpu_exceptions {
- _K1_FPU_INVALID_OPERATION = 0x2LL,
- _K1_FPU_DIVIDE_BY_ZERO = 0x4LL,
- _K1_FPU_OVERFLOW = 0x8LL,
- _K1_FPU_UNDERFLOW = 0x10LL,
- _K1_FPU_INEXACT = 0x20LL,
- _K1_FPU_ALL_EXCEPTS = 0x2LL | 0x4LL | 0x8LL | 0x10LL | 0x20LL
-};
-
-
-
-
-
-extern char __k1_fpu_raise_exceptions(int excepts);
-
-
-
-
-
-extern char __k1_fpu_clear_exceptions(int excepts);
-
-
-
-
-
-extern unsigned int __k1_fpu_get_exceptions(char);
-# 13 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 1 3
-# 47 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern unsigned int __k1_icache_enabled(char);
-
-
-
-
-
-extern char __k1_icache_enable(char);
-
-
-
-
-
-extern char __k1_icache_disable(char);
-# 70 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern char __k1_icache_invalidate_mem_area(uintptr_t addr, int size);
-# 81 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern unsigned int __k1_dcache_enabled(char);
-
-
-
-
-
-extern char __k1_dcache_enable(char);
-
-
-
-
-
-extern char __k1_dcache_disable(char);
-# 104 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern char __k1_dcache_invalidate_mem_area(uintptr_t addr, int size);
-
-
-
-
-
-extern char __k1_l1_coherency_enable(char);
-
-
-
-
-
-extern char __k1_l1_coherency_disable(char);
-
-
-
-
-
-extern char __k1_l2cache_enable(char);
-
-
-
-
-
-extern char __k1_l2cache_disable(char);
-
-
-
-
-
-
-extern char __k1_mb(char);
-
-
-
-
-
-
-extern char __k1_wmb(char);
-
-
-
-
-
-
-char __k1_rmb(char);
-# 14 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/io.h" 1 3
-# 28 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/io.h" 3
-extern uint8_t __k1_io_read8(char *addr);
-
-
-
-
-
-
-
-extern uint16_t __k1_io_read16(char *addr);
-
-
-
-
-
-
-
-extern uint32_t __k1_io_read32(char *addr);
-
-
-
-
-
-
-
-extern uint64_t __k1_io_read64(char *addr);
-# 64 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/io.h" 3
-extern char __k1_io_write8(char *addr, uint8_t val);
-
-
-
-
-
-
-
-extern char __k1_io_write16(char *addr, uint16_t val);
-
-
-
-
-
-
-
-extern char __k1_io_write32(char *addr, uint32_t val);
-
-
-
-
-
-
-
-extern char __k1_io_write64(char *addr, uint64_t val);
-# 104 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/io.h" 3
-extern uint32_t __k1_umem_read32(char *addr __attribute__((unused)));
-
-
-
-
-
-
-
-extern uint64_t __k1_umem_read64(char *addr);
-
-
-
-
-
-
-
-extern uint8_t __k1_umem_read8(char *addr __attribute__((unused)));
-
-
-
-
-
-
-
-extern uint16_t __k1_umem_read16(char *addr);
-# 140 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/io.h" 3
-extern char __k1_umem_write32(char *addr, uint32_t val);
-
-
-
-
-
-
-
-extern char __k1_umem_write64(char *addr, uint64_t val);
-
-
-
-
-
-
-
-extern char __k1_umem_write8(char *addr, uint8_t val);
-
-
-
-
-
-
-
-extern char __k1_umem_write16(char *addr, uint16_t val);
-# 15 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 2 3
-# 33 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-extern uint32_t __k1_atomic_swap32(char *addr, uint32_t new_value);
-
-
-
-
-
-
-
-extern uint64_t __k1_atomic_swap64(char *addr, uint64_t new_value);
-
-
-
-
-
-
-
-extern int32_t __k1_atomic_add32(char *addr, int32_t value);
-
-
-
-
-
-
-
-extern int __k1_compare_and_swap32(char *ptr, uint32_t old_value,
- uint32_t new_value);
-# 73 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-typedef struct __k1_recursive_lock __k1_recursive_lock_t;
-
-struct __k1_recursive_lock {
- uint32_t owner;
- uint32_t counter;
-};
-# 94 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-extern char __k1_recursive_initlock_base(__k1_recursive_lock_t *lock);
-# 107 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-extern int __k1_recursive_trylock_base(__k1_recursive_lock_t *lock,
- uint32_t myself);
-# 117 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-extern char __k1_recursive_lock_base(__k1_recursive_lock_t *lock,
- uint64_t myself);
-# 129 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-extern int __k1_recursive_unlock_base(__k1_recursive_lock_t *lock,
- uint64_t myself);
-# 141 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-extern int __k1_recursive_release_base(__k1_recursive_lock_t *lock,
- uint64_t myself);
-# 10 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/lock.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 1 3
-# 47 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern unsigned int __k1_icache_enabled(char);
-
-
-
-
-
-extern char __k1_icache_enable(char);
-
-
-
-
-
-extern char __k1_icache_disable(char);
-# 70 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern char __k1_icache_invalidate_mem_area(uintptr_t addr, int size);
-# 81 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern unsigned int __k1_dcache_enabled(char);
-
-
-
-
-
-extern char __k1_dcache_enable(char);
-
-
-
-
-
-extern char __k1_dcache_disable(char);
-# 104 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern char __k1_dcache_invalidate_mem_area(uintptr_t addr, int size);
-
-
-
-
-
-extern char __k1_l1_coherency_enable(char);
-
-
-
-
-
-extern char __k1_l1_coherency_disable(char);
-
-
-
-
-
-extern char __k1_l2cache_enable(char);
-
-
-
-
-
-extern char __k1_l2cache_disable(char);
-
-
-
-
-
-
-extern char __k1_mb(char);
-
-
-
-
-
-
-extern char __k1_wmb(char);
-
-
-
-
-
-
-char __k1_rmb(char);
-# 11 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/lock.h" 2 3
-
-
-
-
-typedef struct __libc_lock_recursive_s
-{
- __k1_recursive_lock_t lock;
-} __libc_lock_recursive_t __attribute__ ((aligned (((64*8)/8))));
-
-typedef struct __libc_lock_recursive_s __libc_lock_t;
-
-
-
-
-
-
-int __libc_lock_init_recursive(__libc_lock_recursive_t *lock);
-int __libc_lock_close_recursive(__libc_lock_recursive_t *lock);
-int __libc_lock_acquire_recursive(__libc_lock_recursive_t *lock);
-int __libc_lock_try_acquire_recursive(__libc_lock_recursive_t *lock);
-int __libc_lock_release_recursive(__libc_lock_recursive_t *lock);
-# 42 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/lock.h" 3
-typedef __libc_lock_t _LOCK_T __attribute__ ((aligned (((64*8)/8))));
-typedef __libc_lock_recursive_t _LOCK_RECURSIVE_T __attribute__ ((aligned (((64*8)/8))));
-# 14 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/_types.h" 2 3
-
-
-typedef long _off_t;
-
-
-
-
-
-
-
-typedef short __dev_t;
-
-
-
-
-typedef unsigned short __uid_t;
-
-
-typedef unsigned short __gid_t;
-
-
-
-__extension__ typedef long long _off64_t;
-
-
-
-
-
-
-
-typedef long _fpos_t;
-# 56 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/_types.h" 3
-typedef int _ssize_t;
-
-
-
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 1 3 4
-# 353 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 3 4
-typedef unsigned int wint_t;
-# 64 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/_types.h" 2 3
-
-
-
-typedef struct
-{
- int __count;
- union
- {
- wint_t __wch;
- unsigned char __wchb[4];
- } __value;
-} _mbstate_t;
-
-
-
-typedef _LOCK_RECURSIVE_T _flock_t;
-
-
-
-
-typedef char *_iconv_t;
-# 15 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 2 3
-# 24 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-typedef unsigned int __ULong;
-# 37 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-struct _reent;
-
-
-
-
-
-
-struct _Bigint
-{
- struct _Bigint *_next;
- int _k, _maxwds, _sign, _wds;
- __ULong _x[1];
-};
-
-
-struct __tm
-{
- int __tm_sec;
- int __tm_min;
- int __tm_hour;
- int __tm_mday;
- int __tm_mon;
- int __tm_year;
- int __tm_wday;
- int __tm_yday;
- int __tm_isdst;
-};
-
-
-
-
-
-
-
-struct _on_exit_args {
- char * _fnargs[32];
- char * _dso_handle[32];
-
- __ULong _fntypes;
-
-
- __ULong _is_cxa;
-};
-# 89 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-struct _atexit {
- struct _atexit *_next;
- int _ind;
-
- char (*_fns[32])(char);
- struct _on_exit_args _on_exit_args;
-};
-# 105 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-struct __sbuf {
- unsigned char *_base;
- int _size;
-};
-# 169 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-struct __sFILE {
- unsigned char *_p;
- int _r;
- int _w;
- short _flags;
- short _file;
- struct __sbuf _bf;
- int _lbfsize;
-
-
-
-
-
-
- char * _cookie;
-
- int (* _read) (struct _reent *, char *, char *, int)
- ;
- int (* _write) (struct _reent *, char *, const char *, int)
- ;
- _fpos_t (* _seek) (struct _reent *, char *, _fpos_t, int);
- int (* _close) (struct _reent *, char *);
-
-
- struct __sbuf _ub;
- unsigned char *_up;
- int _ur;
-
-
- unsigned char _ubuf[3];
- unsigned char _nbuf[1];
-
-
- struct __sbuf _lb;
-
-
- int _blksize;
- int _offset;
-
-
- struct _reent *_data;
-
-
-
- _flock_t _lock;
-
- _mbstate_t _mbstate;
- int _flags2;
-};
-# 273 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-typedef struct __sFILE __FILE;
-
-
-
-struct _glue
-{
- struct _glue *_next;
- int _niobs;
- __FILE *_iobs;
-};
-# 305 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-struct _rand48 {
- unsigned short _seed[3];
- unsigned short _mult[3];
- unsigned short _add;
-
-
-
-
-};
-# 579 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-struct _reent
-{
- int _errno;
-
-
-
-
- __FILE *_stdin, *_stdout, *_stderr;
-
- int _inc;
- char _emergency[25];
-
- int _current_category;
- const char *_current_locale;
-
- int __sdidinit;
-
- char (* __cleanup) (struct _reent *);
-
-
- struct _Bigint *_result;
- int _result_k;
- struct _Bigint *_p5s;
- struct _Bigint **_freelist;
-
-
- int _cvtlen;
- char *_cvtbuf;
-
- union
- {
- struct
- {
- unsigned int _unused_rand;
- char * _strtok_last;
- char _asctime_buf[26];
- struct __tm _localtime_buf;
- int _gamma_signgam;
- __extension__ unsigned long long _rand_next;
- struct _rand48 _r48;
- _mbstate_t _mblen_state;
- _mbstate_t _mbtowc_state;
- _mbstate_t _wctomb_state;
- char _l64a_buf[8];
- char _signal_buf[24];
- int _getdate_err;
- _mbstate_t _mbrlen_state;
- _mbstate_t _mbrtowc_state;
- _mbstate_t _mbsrtowcs_state;
- _mbstate_t _wcrtomb_state;
- _mbstate_t _wcsrtombs_state;
- int _h_errno;
- } _reent;
-
-
-
- struct
- {
-
- unsigned char * _nextf[30];
- unsigned int _nmalloc[30];
- } _unused;
- } _new;
-
-
- struct _atexit *_atexit;
- struct _atexit _atexit0;
-
-
- char (**(_sig_func))(int);
-
-
-
-
- struct _glue __sglue;
- __FILE __sf[3];
-};
-# 817 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-extern struct _reent *_impure_ptr ;
-extern struct _reent *const _global_impure_ptr ;
-
-char _reclaim_reent (struct _reent *);
-# 18 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/stdlib.h" 1 3
-# 19 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 2 3
-# 27 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 3
-
-
-typedef struct
-{
- int quot;
- int rem;
-} div_t;
-
-typedef struct
-{
- long quot;
- long rem;
-} ldiv_t;
-# 58 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 3
-extern int __mb_cur_max;
-
-
-
-char abort (char) ;
-int abs (int);
-int atexit (char (*__func)(char));
-double atof (const char *__nptr);
-
-
-
-int atoi (const char *__nptr);
-int _atoi_r (struct _reent *, const char *__nptr);
-long atol (const char *__nptr);
-long _atol_r (struct _reent *, const char *__nptr);
-char * bsearch (const char * __key, const char * __base, size_t __nmemb, size_t __size, int (* _compar) (const char *, const char *))
-
-
-
- ;
-char * calloc (size_t __nmemb, size_t __size) ;
-div_t div (int __numer, int __denom);
-char exit (int __status) ;
-char free (char *) ;
-char * getenv (const char *__string);
-char * _getenv_r (struct _reent *, const char *__string);
-char * _findenv (const char *, int *);
-char * _findenv_r (struct _reent *, const char *, int *);
-long labs (long);
-ldiv_t ldiv (long __numer, long __denom);
-char * malloc (size_t __size) ;
-int mblen (const char *, size_t);
-int _mblen_r (struct _reent *, const char *, size_t, _mbstate_t *);
-int mbtowc (wchar_t *, const char *, size_t);
-int _mbtowc_r (struct _reent *, wchar_t *, const char *, size_t, _mbstate_t *);
-int wctomb (char *, wchar_t);
-int _wctomb_r (struct _reent *, char *, wchar_t, _mbstate_t *);
-size_t mbstowcs (wchar_t *, const char *, size_t);
-size_t _mbstowcs_r (struct _reent *, wchar_t *, const char *, size_t, _mbstate_t *);
-size_t wcstombs (char *, const wchar_t *, size_t);
-size_t _wcstombs_r (struct _reent *, char *, const wchar_t *, size_t, _mbstate_t *);
-# 111 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 3
-char qsort (char * __base, size_t __nmemb, size_t __size, int(*_compar)(const char *, const char *));
-int rand (char);
-char * realloc (char * __r, size_t __size) ;
-
-
-
-char srand (unsigned __seed);
-double strtod (const char *__n, char **__end_PTR);
-double _strtod_r (struct _reent *,const char *__n, char **__end_PTR);
-float strtof (const char *__n, char **__end_PTR);
-
-
-
-
-
-
-long strtol (const char *__n, char **__end_PTR, int __base);
-long _strtol_r (struct _reent *,const char *__n, char **__end_PTR, int __base);
-unsigned long strtoul (const char *__n, char **__end_PTR, int __base);
-unsigned long _strtoul_r (struct _reent *,const char *__n, char **__end_PTR, int __base);
-
-int system (const char *__string);
-# 198 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 3
-char * _dtoa_r (struct _reent *, double, int, int, int *, int*, char**);
-
-char * _malloc_r (struct _reent *, size_t) ;
-char * _calloc_r (struct _reent *, size_t, size_t) ;
-char _free_r (struct _reent *, char *) ;
-char * _realloc_r (struct _reent *, char *, size_t) ;
-char _mstats_r (struct _reent *, char *);
-
-int _system_r (struct _reent *, const char *);
-
-char __eprintf (const char *, const char *, unsigned int, const char *);
-
-
-
-extern long double strtold (const char *, char **);
-extern long double wcstold (const wchar_t *, wchar_t **);
-
-
-
-# 40 "jinclude.h" 2
-
-
-
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 1 3
-# 34 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 1 3 4
-# 35 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 2 3
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stdarg.h" 1 3 4
-# 40 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stdarg.h" 3 4
-typedef __builtin_va_list __gnuc_va_list;
-# 38 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 2 3
-# 46 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 1 3
-# 69 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 1 3 4
-# 70 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/types.h" 1 3
-# 19 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/types.h" 3
-typedef long int __off_t;
-typedef int __pid_t;
-
-
-
-typedef long int __loff_t;
-# 71 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 2 3
-# 92 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef unsigned char u_char;
-typedef unsigned short u_short;
-typedef unsigned int u_int;
-typedef unsigned long u_long;
-
-
-
-typedef unsigned short ushort;
-typedef unsigned int uint;
-
-
-
-typedef unsigned long clock_t;
-
-
-
-
-typedef long time_t;
-
-
-
-
-struct timespec {
- time_t tv_sec;
- long tv_nsec;
-};
-
-struct itimerspec {
- struct timespec it_interval;
- struct timespec it_value;
-};
-
-
-typedef long daddr_t;
-typedef char * caddr_t;
-
-
-
-
-
-
-typedef unsigned short ino_t;
-# 162 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef _off_t off_t;
-typedef __dev_t dev_t;
-typedef __uid_t uid_t;
-typedef __gid_t gid_t;
-
-
-
-
-
-typedef int pid_t;
-
-
-
-typedef long key_t;
-
-typedef _ssize_t ssize_t;
-# 191 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef unsigned int mode_t ;
-
-
-
-
-typedef unsigned short nlink_t;
-# 218 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef long fd_mask;
-
-
-
-
-
-
-
-typedef struct _types_fd_set {
- fd_mask fds_bits[(((64)+(((sizeof (fd_mask) * 8))-1))/((sizeof (fd_mask) * 8)))];
-} _types_fd_set;
-# 249 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef unsigned long clockid_t;
-
-
-
-
-typedef unsigned long timer_t;
-
-
-
-typedef unsigned long useconds_t;
-typedef long suseconds_t;
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/features.h" 1 3
-# 262 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 2 3
-# 273 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/sched.h" 1 3
-# 46 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/sched.h" 3
-struct sched_param {
- int sched_priority;
-# 59 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/sched.h" 3
-};
-# 274 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 2 3
-# 282 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef __uint32_t pthread_t;
-# 344 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef struct {
- int is_initialized;
- char *stackaddr;
- int stacksize;
- int contentionscope;
- int inheritsched;
- int schedpolicy;
- struct sched_param schedparam;
-
-
-
-
-
-
- int detachstate;
-
-} pthread_attr_t;
-# 459 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef __uint32_t pthread_mutex_t;
-
-
-typedef struct {
- int is_initialized;
-# 474 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
- int recursive;
-} pthread_mutexattr_t;
-
-
-
-
-
-
-
-typedef __uint32_t pthread_cond_t;
-
-
-typedef struct {
- int is_initialized;
-
-
-
-} pthread_condattr_t;
-
-
-
-
-
-
-typedef __uint32_t pthread_key_t;
-
-
-typedef struct {
- int is_initialized;
- int init_executed;
-} pthread_once_t;
-# 517 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef __uint32_t pthread_barrier_t;
-
-
-typedef struct {
- int is_initialized;
-
-
-
-} pthread_barrierattr_t;
-# 537 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef __uint32_t pthread_spinlock_t;
-# 47 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 2 3
-
-
-
-typedef __FILE FILE;
-# 59 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-typedef _fpos_t fpos_t;
-
-
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/stdio.h" 1 3
-# 66 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 2 3
-# 175 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-FILE * tmpfile (char);
-char * tmpnam (char *);
-int fclose (FILE *);
-int fflush (FILE *);
-FILE * freopen (const char *, const char *, FILE *);
-char setbuf (FILE *, char *);
-int setvbuf (FILE *, char *, int, size_t);
-int fprintf (FILE *, const char *, ...)
- ;
-int fscanf (FILE *, const char *, ...)
- ;
-int printf (const char *, ...)
- ;
-int scanf (const char *, ...)
- ;
-int sscanf (const char *, const char *, ...)
- ;
-int vfprintf (FILE *, const char *, char*)
- ;
-int vprintf (const char *, char*)
- ;
-int vsprintf (char *, const char *, char*)
- ;
-int fgetc (FILE *);
-char * fgets (char *, int, FILE *);
-int fputc (int, FILE *);
-int fputs (const char *, FILE *);
-int getc (FILE *);
-int getchar (char);
-char * gets (char *);
-int putc (int, FILE *);
-int putchar (int);
-int puts (const char *);
-int ungetc (int, FILE *);
-size_t fread (char *, size_t _size, size_t _n, FILE *);
-size_t fwrite (const char * , size_t _size, size_t _n, FILE *);
-
-
-
-int fgetpos (FILE *, fpos_t *);
-
-int fseek (FILE *, long, int);
-
-
-
-int fsetpos (FILE *, const fpos_t *);
-
-long ftell ( FILE *);
-char rewind (FILE *);
-char clearerr (FILE *);
-int feof (FILE *);
-int ferror (FILE *);
-char perror (const char *);
-
-FILE * fopen (const char *_name, const char *_type);
-int sprintf (char *, const char *, ...)
- ;
-int remove (const char *);
-int rename (const char *, const char *);
-# 246 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-int asiprintf (char **, const char *, ...)
- ;
-char * asniprintf (char *, size_t *, const char *, ...)
- ;
-char * asnprintf (char *, size_t *, const char *, ...)
- ;
-int asprintf (char **, const char *, ...)
- ;
-
-int diprintf (int, const char *, ...)
- ;
-
-int fcloseall (char);
-int fiprintf (FILE *, const char *, ...)
- ;
-int fiscanf (FILE *, const char *, ...)
- ;
-int iprintf (const char *, ...)
- ;
-int iscanf (const char *, ...)
- ;
-int siprintf (char *, const char *, ...)
- ;
-int siscanf (const char *, const char *, ...)
- ;
-int snprintf (char *, size_t, const char *, ...)
- ;
-int sniprintf (char *, size_t, const char *, ...)
- ;
-char * tempnam (const char *, const char *);
-int vasiprintf (char **, const char *, char*)
- ;
-char * vasniprintf (char *, size_t *, const char *, char*)
- ;
-char * vasnprintf (char *, size_t *, const char *, char*)
- ;
-int vasprintf (char **, const char *, char*)
- ;
-int vdiprintf (int, const char *, char*)
- ;
-int vfiprintf (FILE *, const char *, char*)
- ;
-int vfiscanf (FILE *, const char *, char*)
- ;
-int vfscanf (FILE *, const char *, char*)
- ;
-int viprintf (const char *, char*)
- ;
-int viscanf (const char *, char*)
- ;
-int vscanf (const char *, char*)
- ;
-int vsiprintf (char *, const char *, char*)
- ;
-int vsiscanf (const char *, const char *, char*)
- ;
-int vsniprintf (char *, size_t, const char *, char*)
- ;
-int vsnprintf (char *, size_t, const char *, char*)
- ;
-int vsscanf (const char *, const char *, char*)
- ;
-# 361 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-int _asiprintf_r (struct _reent *, char **, const char *, ...)
- ;
-char * _asniprintf_r (struct _reent *, char *, size_t *, const char *, ...)
- ;
-char * _asnprintf_r (struct _reent *, char *, size_t *, const char *, ...)
- ;
-int _asprintf_r (struct _reent *, char **, const char *, ...)
- ;
-int _diprintf_r (struct _reent *, int, const char *, ...)
- ;
-int _dprintf_r (struct _reent *, int, const char *, ...)
- ;
-int _fclose_r (struct _reent *, FILE *);
-int _fcloseall_r (struct _reent *);
-FILE * _fdopen_r (struct _reent *, int, const char *);
-int _fflush_r (struct _reent *, FILE *);
-int _fgetc_r (struct _reent *, FILE *);
-char * _fgets_r (struct _reent *, char *, int, FILE *);
-
-
-
-
-int _fgetpos_r (struct _reent *, FILE *, fpos_t *);
-int _fsetpos_r (struct _reent *, FILE *, const fpos_t *);
-
-int _fiprintf_r (struct _reent *, FILE *, const char *, ...)
- ;
-int _fiscanf_r (struct _reent *, FILE *, const char *, ...)
- ;
-FILE * _fmemopen_r (struct _reent *, char *, size_t, const char *);
-FILE * _fopen_r (struct _reent *, const char *, const char *);
-FILE * _freopen_r (struct _reent *, const char *, const char *, FILE *);
-int _fprintf_r (struct _reent *, FILE *, const char *, ...)
- ;
-int _fpurge_r (struct _reent *, FILE *);
-int _fputc_r (struct _reent *, int, FILE *);
-int _fputs_r (struct _reent *, const char *, FILE *);
-size_t _fread_r (struct _reent *, char *, size_t _size, size_t _n, FILE *);
-int _fscanf_r (struct _reent *, FILE *, const char *, ...)
- ;
-int _fseek_r (struct _reent *, FILE *, long, int);
-int _fseeko_r (struct _reent *, FILE *, _off_t, int);
-long _ftell_r (struct _reent *, FILE *);
-_off_t _ftello_r (struct _reent *, FILE *);
-char _rewind_r (struct _reent *, FILE *);
-size_t _fwrite_r (struct _reent *, const char * , size_t _size, size_t _n, FILE *);
-int _getc_r (struct _reent *, FILE *);
-int _getc_unlocked_r (struct _reent *, FILE *);
-int _getchar_r (struct _reent *);
-int _getchar_unlocked_r (struct _reent *);
-char * _gets_r (struct _reent *, char *);
-int _iprintf_r (struct _reent *, const char *, ...)
- ;
-int _iscanf_r (struct _reent *, const char *, ...)
- ;
-FILE * _open_memstream_r (struct _reent *, char **, size_t *);
-char _perror_r (struct _reent *, const char *);
-int _printf_r (struct _reent *, const char *, ...)
- ;
-int _putc_r (struct _reent *, int, FILE *);
-int _putc_unlocked_r (struct _reent *, int, FILE *);
-int _putchar_unlocked_r (struct _reent *, int);
-int _putchar_r (struct _reent *, int);
-int _puts_r (struct _reent *, const char *);
-int _remove_r (struct _reent *, const char *);
-int _rename_r (struct _reent *, const char *_old, const char *_new)
- ;
-int _scanf_r (struct _reent *, const char *, ...)
- ;
-int _siprintf_r (struct _reent *, char *, const char *, ...)
- ;
-int _siscanf_r (struct _reent *, const char *, const char *, ...)
- ;
-int _sniprintf_r (struct _reent *, char *, size_t, const char *, ...)
- ;
-int _snprintf_r (struct _reent *, char *, size_t, const char *, ...)
- ;
-int _sprintf_r (struct _reent *, char *, const char *, ...)
- ;
-int _sscanf_r (struct _reent *, const char *, const char *, ...)
- ;
-char * _tempnam_r (struct _reent *, const char *, const char *);
-FILE * _tmpfile_r (struct _reent *);
-char * _tmpnam_r (struct _reent *, char *);
-int _ungetc_r (struct _reent *, int, FILE *);
-int _vasiprintf_r (struct _reent *, char **, const char *, char*)
- ;
-char * _vasniprintf_r (struct _reent*, char *, size_t *, const char *, char*)
- ;
-char * _vasnprintf_r (struct _reent*, char *, size_t *, const char *, char*)
- ;
-int _vasprintf_r (struct _reent *, char **, const char *, char*)
- ;
-int _vdiprintf_r (struct _reent *, int, const char *, char*)
- ;
-int _vdprintf_r (struct _reent *, int, const char *, char*)
- ;
-int _vfiprintf_r (struct _reent *, FILE *, const char *, char*)
- ;
-int _vfiscanf_r (struct _reent *, FILE *, const char *, char*)
- ;
-int _vfprintf_r (struct _reent *, FILE *, const char *, char*)
- ;
-int _vfscanf_r (struct _reent *, FILE *, const char *, char*)
- ;
-int _viprintf_r (struct _reent *, const char *, char*)
- ;
-int _viscanf_r (struct _reent *, const char *, char*)
- ;
-int _vprintf_r (struct _reent *, const char *, char*)
- ;
-int _vscanf_r (struct _reent *, const char *, char*)
- ;
-int _vsiprintf_r (struct _reent *, char *, const char *, char*)
- ;
-int _vsiscanf_r (struct _reent *, const char *, const char *, char*)
- ;
-int _vsniprintf_r (struct _reent *, char *, size_t, const char *, char*)
- ;
-int _vsnprintf_r (struct _reent *, char *, size_t, const char *, char*)
- ;
-int _vsprintf_r (struct _reent *, char *, const char *, char*)
- ;
-int _vsscanf_r (struct _reent *, const char *, const char *, char*)
- ;
-
-
-
-int fpurge (FILE *);
-ssize_t __getdelim (char **, size_t *, int, FILE *);
-ssize_t __getline (char **, size_t *, FILE *);
-# 519 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-int __srget_r (struct _reent *, FILE *);
-int __swbuf_r (struct _reent *, int, FILE *);
-# 687 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-
-# 47 "jinclude.h" 2
-# 66 "jinclude.h"
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/string.h" 1 3
-# 14 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/string.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 1 3 4
-# 15 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/string.h" 2 3
-
-
-
-
-
-
-
-char * memchr (const char *, int, size_t);
-int memcmp (const char *, const char *, size_t);
-char * memcpy (char *, const char *, size_t);
-char * memmove (char *, const char *, size_t);
-char * memset (char *, int, size_t);
-char *strcat (char *, const char *);
-char *strchr (const char *, int);
-int strcmp (const char *, const char *);
-int strcoll (const char *, const char *);
-char *strcpy (char *, const char *);
-size_t strcspn (const char *, const char *);
-char *strerror (int);
-size_t strlen (const char *);
-char *strncat (char *, const char *, size_t);
-int strncmp (const char *, const char *, size_t);
-char *strncpy (char *, const char *, size_t);
-char *strpbrk (const char *, const char *);
-char *strrchr (const char *, int);
-size_t strspn (const char *, const char *);
-char *strstr (const char *, const char *);
-
-
-char *strtok (char *, const char *);
-
-
-size_t strxfrm (char *, const char *, size_t);
-# 78 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/string.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/string.h" 1 3
-# 79 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/string.h" 2 3
-
-
-# 67 "jinclude.h" 2
-# 15 "cdjpeg.h" 2
-# 1 "jpeglib.h" 1
-# 26 "jpeglib.h"
-# 1 "jmorecfg.h" 1
-# 66 "jmorecfg.h"
-typedef unsigned char JSAMPLE;
-# 106 "jmorecfg.h"
-typedef short JCOEF;
-# 117 "jmorecfg.h"
-typedef unsigned char JOCTET;
-# 142 "jmorecfg.h"
-typedef unsigned char UINT8;
-# 154 "jmorecfg.h"
-typedef unsigned short UINT16;
-
-
-
-
-
-
-
-typedef short INT16;
-
-
-
-
-
-typedef long INT32;
-# 178 "jmorecfg.h"
-typedef unsigned int JDIMENSION;
-# 234 "jmorecfg.h"
-typedef int boolean;
-# 27 "jpeglib.h" 2
-# 66 "jpeglib.h"
-typedef JSAMPLE *JSAMPROW;
-typedef JSAMPROW *JSAMPARRAY;
-typedef JSAMPARRAY *JSAMPIMAGE;
-
-typedef JCOEF JBLOCK[64];
-typedef JBLOCK *JBLOCKROW;
-typedef JBLOCKROW *JBLOCKARRAY;
-typedef JBLOCKARRAY *JBLOCKIMAGE;
-
-typedef JCOEF *JCOEFPTR;
-
-
-
-
-
-
-
-typedef struct {
-
-
-
-
- UINT16 quantval[64];
-
-
-
-
-
- boolean sent_table;
-} JQUANT_TBL;
-
-
-
-
-typedef struct {
-
- UINT8 bits[17];
-
- UINT8 huffval[256];
-
-
-
-
-
- boolean sent_table;
-} JHUFF_TBL;
-
-
-
-
-typedef struct {
-
-
-
- int component_id;
- int component_index;
- int h_samp_factor;
- int v_samp_factor;
- int quant_tbl_no;
-
-
-
-
- int dc_tbl_no;
- int ac_tbl_no;
-# 139 "jpeglib.h"
- JDIMENSION width_in_blocks;
- JDIMENSION height_in_blocks;
-
-
-
-
-
-
- int DCT_scaled_size;
-
-
-
-
-
-
- JDIMENSION downsampled_width;
- JDIMENSION downsampled_height;
-
-
-
-
- boolean component_needed;
-
-
-
- int MCU_width;
- int MCU_height;
- int MCU_blocks;
- int MCU_sample_width;
- int last_col_width;
- int last_row_height;
-
-
-
-
-
- JQUANT_TBL * quant_table;
-
-
- char * dct_table;
-} jpeg_component_info;
-
-
-
-
-typedef struct {
- int comps_in_scan;
- int component_index[4];
- int Ss, Se;
- int Ah, Al;
-} jpeg_scan_info;
-
-
-
-typedef struct jpeg_marker_struct * jpeg_saved_marker_ptr;
-
-struct jpeg_marker_struct {
- jpeg_saved_marker_ptr next;
- UINT8 marker;
- unsigned int original_length;
- unsigned int data_length;
- JOCTET * data;
-
-};
-
-
-
-typedef enum {
- JCS_UNKNOWN,
- JCS_GRAYSCALE,
- JCS_RGB,
- JCS_YCbCr,
- JCS_CMYK,
- JCS_YCCK
-} J_COLOR_SPACE;
-
-
-
-typedef enum {
- JDCT_ISLOW,
- JDCT_IFAST,
- JDCT_FLOAT
-} J_DCT_METHOD;
-# 232 "jpeglib.h"
-typedef enum {
- JDITHER_NONE,
- JDITHER_ORDERED,
- JDITHER_FS
-} J_DITHER_MODE;
-# 253 "jpeglib.h"
-struct jpeg_common_struct {
- struct jpeg_error_mgr * err; struct jpeg_memory_mgr * mem; struct jpeg_progress_mgr * progress; char * client_data; boolean is_decompressor; int global_state;
-
-
-
-
-};
-
-typedef struct jpeg_common_struct * j_common_ptr;
-typedef struct jpeg_compress_struct * j_compress_ptr;
-typedef struct jpeg_decompress_struct * j_decompress_ptr;
-
-
-
-
-struct jpeg_compress_struct {
- struct jpeg_error_mgr * err; struct jpeg_memory_mgr * mem; struct jpeg_progress_mgr * progress; char * client_data; boolean is_decompressor; int global_state;
-
-
- struct jpeg_destination_mgr * dest;
-
-
-
-
-
-
- JDIMENSION image_width;
- JDIMENSION image_height;
- int input_components;
- J_COLOR_SPACE in_color_space;
-
- double input_gamma;
-# 294 "jpeglib.h"
- int data_precision;
-
- int num_components;
- J_COLOR_SPACE jpeg_color_space;
-
- jpeg_component_info * comp_info;
-
-
- JQUANT_TBL * quant_tbl_ptrs[4];
-
-
- JHUFF_TBL * dc_huff_tbl_ptrs[4];
- JHUFF_TBL * ac_huff_tbl_ptrs[4];
-
-
- UINT8 arith_dc_L[16];
- UINT8 arith_dc_U[16];
- UINT8 arith_ac_K[16];
-
- int num_scans;
- const jpeg_scan_info * scan_info;
-
-
-
-
-
- boolean raw_data_in;
- boolean arith_code;
- boolean optimize_coding;
- boolean CCIR601_sampling;
- int smoothing_factor;
- J_DCT_METHOD dct_method;
-
-
-
-
-
-
- unsigned int restart_interval;
- int restart_in_rows;
-
-
-
- boolean write_JFIF_header;
- UINT8 JFIF_major_version;
- UINT8 JFIF_minor_version;
-
-
-
-
- UINT8 density_unit;
- UINT16 X_density;
- UINT16 Y_density;
- boolean write_Adobe_marker;
-
-
-
-
-
-
- JDIMENSION next_scanline;
-# 363 "jpeglib.h"
- boolean progressive_mode;
- int max_h_samp_factor;
- int max_v_samp_factor;
-
- JDIMENSION total_iMCU_rows;
-# 378 "jpeglib.h"
- int comps_in_scan;
- jpeg_component_info * cur_comp_info[4];
-
-
- JDIMENSION MCUs_per_row;
- JDIMENSION MCU_rows_in_scan;
-
- int blocks_in_MCU;
- int MCU_membership[10];
-
-
-
- int Ss, Se, Ah, Al;
-
-
-
-
- struct jpeg_comp_master * master;
- struct jpeg_c_main_controller * main;
- struct jpeg_c_prep_controller * prep;
- struct jpeg_c_coef_controller * coef;
- struct jpeg_marker_writer * marker;
- struct jpeg_color_converter * cconvert;
- struct jpeg_downsampler * downsample;
- struct jpeg_forward_dct * fdct;
- struct jpeg_entropy_encoder * entropy;
- jpeg_scan_info * script_space;
- int script_space_size;
-};
-
-
-
-
-struct jpeg_decompress_struct {
- struct jpeg_error_mgr * err; struct jpeg_memory_mgr * mem; struct jpeg_progress_mgr * progress; char * client_data; boolean is_decompressor; int global_state;
-
-
- struct jpeg_source_mgr * src;
-
-
-
-
- JDIMENSION image_width;
- JDIMENSION image_height;
- int num_components;
- J_COLOR_SPACE jpeg_color_space;
-
-
-
-
-
-
- J_COLOR_SPACE out_color_space;
-
- unsigned int scale_num, scale_denom;
-
- double output_gamma;
-
- boolean buffered_image;
- boolean raw_data_out;
-
- J_DCT_METHOD dct_method;
- boolean do_fancy_upsampling;
- boolean do_block_smoothing;
-
- boolean quantize_colors;
-
- J_DITHER_MODE dither_mode;
- boolean two_pass_quantize;
- int desired_number_of_colors;
-
- boolean enable_1pass_quant;
- boolean enable_external_quant;
- boolean enable_2pass_quant;
-
-
-
-
-
-
-
- JDIMENSION output_width;
- JDIMENSION output_height;
- int out_color_components;
- int output_components;
-
-
-
- int rec_outbuf_height;
-# 478 "jpeglib.h"
- int actual_number_of_colors;
- JSAMPARRAY colormap;
-# 489 "jpeglib.h"
- JDIMENSION output_scanline;
-
-
-
-
- int input_scan_number;
- JDIMENSION input_iMCU_row;
-
-
-
-
-
- int output_scan_number;
- JDIMENSION output_iMCU_row;
-# 511 "jpeglib.h"
- int (*coef_bits)[64];
-# 522 "jpeglib.h"
- JQUANT_TBL * quant_tbl_ptrs[4];
-
-
- JHUFF_TBL * dc_huff_tbl_ptrs[4];
- JHUFF_TBL * ac_huff_tbl_ptrs[4];
-
-
-
-
-
-
- int data_precision;
-
- jpeg_component_info * comp_info;
-
-
- boolean progressive_mode;
- boolean arith_code;
-
- UINT8 arith_dc_L[16];
- UINT8 arith_dc_U[16];
- UINT8 arith_ac_K[16];
-
- unsigned int restart_interval;
-
-
-
-
- boolean saw_JFIF_marker;
-
- UINT8 JFIF_major_version;
- UINT8 JFIF_minor_version;
- UINT8 density_unit;
- UINT16 X_density;
- UINT16 Y_density;
- boolean saw_Adobe_marker;
- UINT8 Adobe_transform;
-
- boolean CCIR601_sampling;
-
-
-
-
-
- jpeg_saved_marker_ptr marker_list;
-# 575 "jpeglib.h"
- int max_h_samp_factor;
- int max_v_samp_factor;
-
- int min_DCT_scaled_size;
-
- JDIMENSION total_iMCU_rows;
-# 589 "jpeglib.h"
- JSAMPLE * sample_range_limit;
-
-
-
-
-
-
- int comps_in_scan;
- jpeg_component_info * cur_comp_info[4];
-
-
- JDIMENSION MCUs_per_row;
- JDIMENSION MCU_rows_in_scan;
-
- int blocks_in_MCU;
- int MCU_membership[10];
-
-
-
- int Ss, Se, Ah, Al;
-
-
-
-
-
- int unread_marker;
-
-
-
-
- struct jpeg_decomp_master * master;
- struct jpeg_d_main_controller * main;
- struct jpeg_d_coef_controller * coef;
- struct jpeg_d_post_controller * post;
- struct jpeg_input_controller * inputctl;
- struct jpeg_marker_reader * marker;
- struct jpeg_entropy_decoder * entropy;
- struct jpeg_inverse_dct * idct;
- struct jpeg_upsampler * upsample;
- struct jpeg_color_deconverter * cconvert;
- struct jpeg_color_quantizer * cquantize;
-};
-# 643 "jpeglib.h"
-struct jpeg_error_mgr {
-
- char (*error_exit) (j_common_ptr cinfo);
-
- char (*emit_message) (j_common_ptr cinfo, int msg_level);
-
- char (*output_message) (j_common_ptr cinfo);
-
- char (*format_message) (j_common_ptr cinfo, char * buffer);
-
-
- char (*reset_error_mgr) (j_common_ptr cinfo);
-
-
-
-
- int msg_code;
-
- union {
- int i[8];
- char s[80];
- } msg_parm;
-
-
-
- int trace_level;
-
-
-
-
-
-
-
- long num_warnings;
-# 688 "jpeglib.h"
- const char * const * jpeg_message_table;
- int last_jpeg_message;
-
-
-
- const char * const * addon_message_table;
- int first_addon_message;
- int last_addon_message;
-};
-
-
-
-
-struct jpeg_progress_mgr {
- char (*progress_monitor) (j_common_ptr cinfo);
-
- long pass_counter;
- long pass_limit;
- int completed_passes;
- int total_passes;
-};
-
-
-
-
-struct jpeg_destination_mgr {
- JOCTET * next_output_byte;
- size_t free_in_buffer;
-
- char (*init_destination) (j_compress_ptr cinfo);
- boolean (*empty_output_buffer) (j_compress_ptr cinfo);
- char (*term_destination) (j_compress_ptr cinfo);
-};
-
-
-
-
-struct jpeg_source_mgr {
- const JOCTET * next_input_byte;
- size_t bytes_in_buffer;
-
- char (*init_source) (j_decompress_ptr cinfo);
- boolean (*fill_input_buffer) (j_decompress_ptr cinfo);
- char (*skip_input_data) (j_decompress_ptr cinfo, long num_bytes);
- boolean (*resync_to_restart) (j_decompress_ptr cinfo, int desired);
- char (*term_source) (j_decompress_ptr cinfo);
-};
-# 752 "jpeglib.h"
-typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
-typedef struct jvirt_barray_control * jvirt_barray_ptr;
-
-
-struct jpeg_memory_mgr {
-
- char * (*alloc_small) (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
- ;
- char * (*alloc_large) (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
- ;
- JSAMPARRAY (*alloc_sarray) (j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow, JDIMENSION numrows)
-
- ;
- JBLOCKARRAY (*alloc_barray) (j_common_ptr cinfo, int pool_id, JDIMENSION blocksperrow, JDIMENSION numrows)
-
- ;
- jvirt_sarray_ptr (*request_virt_sarray) (j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION samplesperrow, JDIMENSION numrows, JDIMENSION maxaccess)
-
-
-
-
- ;
- jvirt_barray_ptr (*request_virt_barray) (j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION blocksperrow, JDIMENSION numrows, JDIMENSION maxaccess)
-
-
-
-
- ;
- char (*realize_virt_arrays) (j_common_ptr cinfo);
- JSAMPARRAY (*access_virt_sarray) (j_common_ptr cinfo, jvirt_sarray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
-
-
-
- ;
- JBLOCKARRAY (*access_virt_barray) (j_common_ptr cinfo, jvirt_barray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
-
-
-
- ;
- char (*free_pool) (j_common_ptr cinfo, int pool_id);
- char (*self_destruct) (j_common_ptr cinfo);
-
-
-
-
-
-
- long max_memory_to_use;
-
-
- long max_alloc_chunk;
-};
-
-
-
-
-
-typedef boolean (*jpeg_marker_parser_method) (j_decompress_ptr cinfo);
-# 884 "jpeglib.h"
-extern struct jpeg_error_mgr * jpeg_std_error
- (struct jpeg_error_mgr * err);
-# 900 "jpeglib.h"
-extern char jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
- ;
-extern char jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
- ;
-
-extern char jpeg_destroy_compress (j_compress_ptr cinfo);
-extern char jpeg_destroy_decompress (j_decompress_ptr cinfo);
-
-
-
-extern char jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile);
-extern char jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile);
-
-
-extern char jpeg_set_defaults (j_compress_ptr cinfo);
-
-extern char jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
- ;
-extern char jpeg_default_colorspace (j_compress_ptr cinfo);
-extern char jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
- ;
-extern char jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, boolean force_baseline)
-
- ;
-extern char jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, const unsigned int *basic_table, int scale_factor, boolean force_baseline)
-
-
- ;
-extern int jpeg_quality_scaling (int quality);
-extern char jpeg_simple_progression (j_compress_ptr cinfo);
-extern char jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
- ;
-extern JQUANT_TBL * jpeg_alloc_quant_table (j_common_ptr cinfo);
-extern JHUFF_TBL * jpeg_alloc_huff_table (j_common_ptr cinfo);
-
-
-extern char jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
- ;
-extern JDIMENSION jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)
-
- ;
-extern char jpeg_finish_compress (j_compress_ptr cinfo);
-
-
-extern JDIMENSION jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data, JDIMENSION num_lines)
-
- ;
-
-
-extern char jpeg_write_marker
- (j_compress_ptr cinfo, int marker, const JOCTET * dataptr, unsigned int datalen)
- ;
-
-extern char jpeg_write_m_header
- (j_compress_ptr cinfo, int marker, unsigned int datalen);
-extern char jpeg_write_m_byte
- (j_compress_ptr cinfo, int val);
-
-
-extern char jpeg_write_tables (j_compress_ptr cinfo);
-
-
-extern int jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
- ;
-# 975 "jpeglib.h"
-extern boolean jpeg_start_decompress (j_decompress_ptr cinfo);
-extern JDIMENSION jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)
-
- ;
-extern boolean jpeg_finish_decompress (j_decompress_ptr cinfo);
-
-
-extern JDIMENSION jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data, JDIMENSION max_lines)
-
- ;
-
-
-extern boolean jpeg_has_multiple_scans (j_decompress_ptr cinfo);
-extern boolean jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
- ;
-extern boolean jpeg_finish_output (j_decompress_ptr cinfo);
-extern boolean jpeg_input_complete (j_decompress_ptr cinfo);
-extern char jpeg_new_colormap (j_decompress_ptr cinfo);
-extern int jpeg_consume_input (j_decompress_ptr cinfo);
-# 1002 "jpeglib.h"
-extern char jpeg_calc_output_dimensions (j_decompress_ptr cinfo);
-
-
-extern char jpeg_save_markers
- (j_decompress_ptr cinfo, int marker_code, unsigned int length_limit)
- ;
-
-
-extern char jpeg_set_marker_processor
- (j_decompress_ptr cinfo, int marker_code, jpeg_marker_parser_method routine)
- ;
-
-
-extern jvirt_barray_ptr * jpeg_read_coefficients (j_decompress_ptr cinfo);
-extern char jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
- ;
-extern char jpeg_copy_critical_parameters (j_decompress_ptr srcinfo, j_compress_ptr dstinfo)
- ;
-
-
-
-
-
-
-
-extern char jpeg_abort_compress (j_compress_ptr cinfo);
-extern char jpeg_abort_decompress (j_decompress_ptr cinfo);
-
-
-
-
-extern char jpeg_abort (j_common_ptr cinfo);
-extern char jpeg_destroy (j_common_ptr cinfo);
-
-
-extern boolean jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
- ;
-# 16 "cdjpeg.h" 2
-# 1 "jerror.h" 1
-# 33 "jerror.h"
-typedef enum {
-
-
-
-
-
-JMSG_NOMESSAGE ,
-
-
-JERR_ARITH_NOTIMPL ,
-
-JERR_BAD_ALIGN_TYPE ,
-JERR_BAD_ALLOC_CHUNK ,
-JERR_BAD_BUFFER_MODE ,
-JERR_BAD_COMPONENT_ID ,
-JERR_BAD_DCT_COEF ,
-JERR_BAD_DCTSIZE ,
-JERR_BAD_HUFF_TABLE ,
-JERR_BAD_IN_COLORSPACE ,
-JERR_BAD_J_COLORSPACE ,
-JERR_BAD_LENGTH ,
-JERR_BAD_LIB_VERSION ,
-
-JERR_BAD_MCU_SIZE ,
-JERR_BAD_POOL_ID ,
-JERR_BAD_PRECISION ,
-JERR_BAD_PROGRESSION ,
-
-JERR_BAD_PROG_SCRIPT ,
-
-JERR_BAD_SAMPLING ,
-JERR_BAD_SCAN_SCRIPT ,
-JERR_BAD_STATE ,
-JERR_BAD_STRUCT_SIZE ,
-
-JERR_BAD_VIRTUAL_ACCESS ,
-JERR_BUFFER_SIZE ,
-JERR_CANT_SUSPEND ,
-JERR_CCIR601_NOTIMPL ,
-JERR_COMPONENT_COUNT ,
-JERR_CONVERSION_NOTIMPL ,
-JERR_DAC_INDEX ,
-JERR_DAC_VALUE ,
-JERR_DHT_INDEX ,
-JERR_DQT_INDEX ,
-JERR_EMPTY_IMAGE ,
-JERR_EMS_READ ,
-JERR_EMS_WRITE ,
-JERR_EOI_EXPECTED ,
-JERR_FILE_READ ,
-JERR_FILE_WRITE ,
-JERR_FRACT_SAMPLE_NOTIMPL ,
-JERR_HUFF_CLEN_OVERFLOW ,
-JERR_HUFF_MISSING_CODE ,
-JERR_IMAGE_TOO_BIG ,
-JERR_INPUT_EMPTY ,
-JERR_INPUT_EOF ,
-JERR_MISMATCHED_QUANT_TABLE ,
-
-JERR_MISSING_DATA ,
-JERR_MODE_CHANGE ,
-JERR_NOTIMPL ,
-JERR_NOT_COMPILED ,
-JERR_NO_BACKING_STORE ,
-JERR_NO_HUFF_TABLE ,
-JERR_NO_IMAGE ,
-JERR_NO_QUANT_TABLE ,
-JERR_NO_SOI ,
-JERR_OUT_OF_MEMORY ,
-JERR_QUANT_COMPONENTS ,
-
-JERR_QUANT_FEW_COLORS ,
-JERR_QUANT_MANY_COLORS ,
-JERR_SOF_DUPLICATE ,
-JERR_SOF_NO_SOS ,
-JERR_SOF_UNSUPPORTED ,
-JERR_SOI_DUPLICATE ,
-JERR_SOS_NO_SOF ,
-JERR_TFILE_CREATE ,
-JERR_TFILE_READ ,
-JERR_TFILE_SEEK ,
-JERR_TFILE_WRITE ,
-
-JERR_TOO_LITTLE_DATA ,
-JERR_UNKNOWN_MARKER ,
-JERR_VIRTUAL_BUG ,
-JERR_WIDTH_OVERFLOW ,
-JERR_XMS_READ ,
-JERR_XMS_WRITE ,
-JMSG_COPYRIGHT ,
-JMSG_VERSION ,
-JTRC_16BIT_TABLES ,
-
-JTRC_ADOBE ,
-
-JTRC_APP0 ,
-JTRC_APP14 ,
-JTRC_DAC ,
-JTRC_DHT ,
-JTRC_DQT ,
-JTRC_DRI ,
-JTRC_EMS_CLOSE ,
-JTRC_EMS_OPEN ,
-JTRC_EOI ,
-JTRC_HUFFBITS ,
-JTRC_JFIF ,
-JTRC_JFIF_BADTHUMBNAILSIZE ,
-
-JTRC_JFIF_EXTENSION ,
-
-JTRC_JFIF_THUMBNAIL ,
-JTRC_MISC_MARKER ,
-JTRC_PARMLESS_MARKER ,
-JTRC_QUANTVALS ,
-JTRC_QUANT_3_NCOLORS ,
-JTRC_QUANT_NCOLORS ,
-JTRC_QUANT_SELECTED ,
-JTRC_RECOVERY_ACTION ,
-JTRC_RST ,
-JTRC_SMOOTH_NOTIMPL ,
-
-JTRC_SOF ,
-JTRC_SOF_COMPONENT ,
-JTRC_SOI ,
-JTRC_SOS ,
-JTRC_SOS_COMPONENT ,
-JTRC_SOS_PARAMS ,
-JTRC_TFILE_CLOSE ,
-JTRC_TFILE_OPEN ,
-JTRC_THUMB_JPEG ,
-
-JTRC_THUMB_PALETTE ,
-
-JTRC_THUMB_RGB ,
-
-JTRC_UNKNOWN_IDS ,
-
-JTRC_XMS_CLOSE ,
-JTRC_XMS_OPEN ,
-JWRN_ADOBE_XFORM ,
-JWRN_BOGUS_PROGRESSION ,
-
-JWRN_EXTRANEOUS_DATA ,
-
-JWRN_HIT_MARKER ,
-JWRN_HUFF_BAD_CODE ,
-JWRN_JFIF_MAJOR ,
-JWRN_JPEG_EOF ,
-JWRN_MUST_RESYNC ,
-
-JWRN_NOT_SEQUENTIAL ,
-JWRN_TOO_MUCH_DATA ,
-
-
-
- JMSG_LASTMSGCODE
-} J_MESSAGE_CODE;
-# 17 "cdjpeg.h" 2
-# 1 "cderror.h" 1
-# 33 "cderror.h"
-typedef enum {
-
-
-
-
-
-JMSG_FIRSTADDONCODE=1000 ,
-
-
-JERR_BMP_BADCMAP ,
-JERR_BMP_BADDEPTH ,
-JERR_BMP_BADHEADER ,
-JERR_BMP_BADPLANES ,
-JERR_BMP_COLORSPACE ,
-JERR_BMP_COMPRESSED ,
-JERR_BMP_NOT ,
-JTRC_BMP ,
-JTRC_BMP_MAPPED ,
-JTRC_BMP_OS2 ,
-JTRC_BMP_OS2_MAPPED ,
-
-
-
-JERR_GIF_BUG ,
-JERR_GIF_CODESIZE ,
-JERR_GIF_COLORSPACE ,
-JERR_GIF_IMAGENOTFOUND ,
-JERR_GIF_NOT ,
-JTRC_GIF ,
-JTRC_GIF_BADVERSION ,
-
-JTRC_GIF_EXTENSION ,
-JTRC_GIF_NONSQUARE ,
-JWRN_GIF_BADDATA ,
-JWRN_GIF_CHAR ,
-JWRN_GIF_ENDCODE ,
-JWRN_GIF_NOMOREDATA ,
-
-
-
-JERR_PPM_COLORSPACE ,
-JERR_PPM_NONNUMERIC ,
-JERR_PPM_NOT ,
-JTRC_PGM ,
-JTRC_PGM_TEXT ,
-JTRC_PPM ,
-JTRC_PPM_TEXT ,
-# 100 "cderror.h"
-JERR_TGA_BADCMAP ,
-JERR_TGA_BADPARMS ,
-JERR_TGA_COLORSPACE ,
-JTRC_TGA ,
-JTRC_TGA_GRAY ,
-JTRC_TGA_MAPPED ,
-
-
-
-
-JERR_BAD_CMAP_FILE ,
-
-JERR_TOO_MANY_COLORS ,
-
-JERR_UNGETC_FAILED ,
-
-JERR_UNKNOWN_FORMAT ,
-
-
-
-
-JERR_UNSUPPORTED_FORMAT ,
-
-
-
- JMSG_LASTADDONCODE
-} ADDON_MESSAGE_CODE;
-# 18 "cdjpeg.h" 2
-
-
-
-
-
-
-typedef struct cjpeg_source_struct * cjpeg_source_ptr;
-
-struct cjpeg_source_struct {
- char (*start_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
- ;
- JDIMENSION (*get_pixel_rows) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
- ;
- char (*finish_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
- ;
-
- FILE *input_file;
-
- JSAMPARRAY buffer;
- JDIMENSION buffer_height;
-};
-
-
-
-
-
-
-typedef struct djpeg_dest_struct * djpeg_dest_ptr;
-
-struct djpeg_dest_struct {
-
-
-
- char (*start_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
- ;
-
- char (*put_pixel_rows) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, JDIMENSION rows_supplied)
-
- ;
-
- char (*finish_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
- ;
-
-
- FILE * output_file;
-
-
-
-
-
- JSAMPARRAY buffer;
- JDIMENSION buffer_height;
-};
-# 81 "cdjpeg.h"
-struct cdjpeg_progress_mgr {
- struct jpeg_progress_mgr pub;
- int completed_extra_passes;
- int total_extra_passes;
-
- int percent_done;
-};
-
-typedef struct cdjpeg_progress_mgr * cd_progress_ptr;
-# 119 "cdjpeg.h"
-extern cjpeg_source_ptr jinit_read_bmp (j_compress_ptr cinfo);
-extern djpeg_dest_ptr jinit_write_bmp (j_decompress_ptr cinfo, boolean is_os2)
- ;
-extern cjpeg_source_ptr jinit_read_gif (j_compress_ptr cinfo);
-extern djpeg_dest_ptr jinit_write_gif (j_decompress_ptr cinfo);
-extern cjpeg_source_ptr jinit_read_ppm (j_compress_ptr cinfo);
-extern djpeg_dest_ptr jinit_write_ppm (j_decompress_ptr cinfo);
-extern cjpeg_source_ptr jinit_read_rle (j_compress_ptr cinfo);
-extern djpeg_dest_ptr jinit_write_rle (j_decompress_ptr cinfo);
-extern cjpeg_source_ptr jinit_read_targa (j_compress_ptr cinfo);
-extern djpeg_dest_ptr jinit_write_targa (j_decompress_ptr cinfo);
-
-
-
-extern boolean read_quant_tables (j_compress_ptr cinfo, char * filename, int scale_factor, boolean force_baseline)
- ;
-extern boolean read_scan_script (j_compress_ptr cinfo, char * filename);
-extern boolean set_quant_slots (j_compress_ptr cinfo, char *arg);
-extern boolean set_sample_factors (j_compress_ptr cinfo, char *arg);
-
-
-
-extern char read_color_map (j_decompress_ptr cinfo, FILE * infile);
-
-
-
-extern char enable_signal_catcher (j_common_ptr cinfo);
-extern char start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress)
- ;
-extern char end_progress_monitor (j_common_ptr cinfo);
-extern boolean keymatch (char * arg, const char * keyword, int minchars);
-extern FILE * read_stdin (char);
-extern FILE * write_stdout (char);
-# 27 "cjpeg.c" 2
-# 1 "jversion.h" 1
-# 28 "cjpeg.c" 2
-# 44 "cjpeg.c"
-static const char * const cdjpeg_message_table[] = {
-# 1 "cderror.h" 1
-# 39 "cderror.h"
-((char *)0) ,
-
-
-"Unsupported BMP colormap format" ,
-"Only 8- and 24-bit BMP files are supported" ,
-"Invalid BMP file: bad header length" ,
-"Invalid BMP file: biPlanes not equal to 1" ,
-"BMP output must be grayscale or RGB" ,
-"Sorry, compressed BMPs not yet supported" ,
-"Not a BMP file - does not start with BM" ,
-"%ux%u 24-bit BMP image" ,
-"%ux%u 8-bit colormapped BMP image" ,
-"%ux%u 24-bit OS2 BMP image" ,
-"%ux%u 8-bit colormapped OS2 BMP image" ,
-
-
-
-"GIF output got confused" ,
-"Bogus GIF codesize %d" ,
-"GIF output must be grayscale or RGB" ,
-"Too few images in GIF file" ,
-"Not a GIF file" ,
-"%ux%ux%d GIF image" ,
-"Warning: unexpected GIF version number '%c%c%c'" ,
-
-"Ignoring GIF extension block of type 0x%02x" ,
-"Caution: nonsquare pixels in input" ,
-"Corrupt data in GIF file" ,
-"Bogus char 0x%02x in GIF file, ignoring" ,
-"Premature end of GIF image" ,
-"Ran out of GIF bits" ,
-
-
-
-"PPM output must be grayscale or RGB" ,
-"Nonnumeric data in PPM file" ,
-"Not a PPM/PGM file" ,
-"%ux%u PGM image" ,
-"%ux%u text PGM image" ,
-"%ux%u PPM image" ,
-"%ux%u text PPM image" ,
-# 100 "cderror.h"
-"Unsupported Targa colormap format" ,
-"Invalid or unsupported Targa file" ,
-"Targa output must be grayscale or RGB" ,
-"%ux%u RGB Targa image" ,
-"%ux%u grayscale Targa image" ,
-"%ux%u colormapped Targa image" ,
-
-
-
-
-"Color map file is invalid or of unsupported format" ,
-
-"Output file format cannot handle %d colormap entries" ,
-
-"ungetc failed" ,
-
-"Unrecognized input file format --- perhaps you need -targa" ,
-
-
-
-
-"Unsupported output file format" ,
-# 46 "cjpeg.c" 2
- ((char *)0)
-};
-# 76 "cjpeg.c"
-static boolean is_targa;
-
-
-static cjpeg_source_ptr
-select_file_type (j_compress_ptr cinfo, FILE * infile)
-{
- int c;
-
- if (is_targa) {
-
- return jinit_read_targa(cinfo);
-
-
-
- }
-
- if ((c = (--(infile)->_r < 0 ? __srget_r(_impure_ptr, infile) : (int)(*(infile)->_p++))) == (-1))
- ((cinfo)->err->msg_code = (JERR_INPUT_EMPTY), (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)));
- if (ungetc(c, infile) == (-1))
- ((cinfo)->err->msg_code = (JERR_UNGETC_FAILED), (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)));
-
- switch (c) {
-
- case 'B':
- return jinit_read_bmp(cinfo);
-
-
- case 'G':
- return jinit_read_gif(cinfo);
-
-
- case 'P':
- return jinit_read_ppm(cinfo);
-
-
-
-
-
-
- case 0x00:
- return jinit_read_targa(cinfo);
-
- default:
- ((cinfo)->err->msg_code = (JERR_UNKNOWN_FORMAT), (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)));
- break;
- }
-
- return ((char *)0);
-}
-# 136 "cjpeg.c"
-static const char * progname;
-static char * outfilename;
-
-
-static char
-usage (char)
-
-{
- fprintf((_impure_ptr->_stderr), "usage: %s [switches] ", progname);
-
-
-
- fprintf((_impure_ptr->_stderr), "[inputfile]\n");
-
-
- fprintf((_impure_ptr->_stderr), "Switches (names may be abbreviated):\n");
- fprintf((_impure_ptr->_stderr), " -quality N Compression quality (0..100; 5-95 is useful range)\n");
- fprintf((_impure_ptr->_stderr), " -grayscale Create monochrome JPEG file\n");
-
- fprintf((_impure_ptr->_stderr), " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
-
-
- fprintf((_impure_ptr->_stderr), " -progressive Create progressive JPEG file\n");
-
-
- fprintf((_impure_ptr->_stderr), " -targa Input file is Targa format (usually not needed)\n");
-
- fprintf((_impure_ptr->_stderr), "Switches for advanced users:\n");
-
- fprintf((_impure_ptr->_stderr), " -dct int Use integer DCT method%s\n",
- (JDCT_ISLOW == JDCT_ISLOW ? " (default)" : ""));
-
-
- fprintf((_impure_ptr->_stderr), " -dct fast Use fast integer DCT (less accurate)%s\n",
- (JDCT_ISLOW == JDCT_IFAST ? " (default)" : ""));
-
-
-
-
-
- fprintf((_impure_ptr->_stderr), " -restart N Set restart interval in rows, or in blocks with B\n");
-
- fprintf((_impure_ptr->_stderr), " -smooth N Smooth dithered input (N=1..100 is strength)\n");
-
- fprintf((_impure_ptr->_stderr), " -maxmemory N Maximum memory to use (in kbytes)\n");
- fprintf((_impure_ptr->_stderr), " -outfile name Specify name for output file\n");
- fprintf((_impure_ptr->_stderr), " -verbose or -debug Emit debug output\n");
- fprintf((_impure_ptr->_stderr), "Switches for wizards:\n");
-
-
-
- fprintf((_impure_ptr->_stderr), " -baseline Force baseline quantization tables\n");
- fprintf((_impure_ptr->_stderr), " -qtables file Use quantization tables given in file\n");
- fprintf((_impure_ptr->_stderr), " -qslots N[,...] Set component quantization tables\n");
- fprintf((_impure_ptr->_stderr), " -sample HxV[,...] Set component sampling factors\n");
-
- fprintf((_impure_ptr->_stderr), " -scans file Create multi-scan JPEG per script file\n");
-
- exit(1);
-}
-
-
-static int
-parse_switches (j_compress_ptr cinfo, int argc, char **argv,
- int last_file_arg_seen, boolean for_real)
-# 209 "cjpeg.c"
-{
- int argn;
- char * arg;
- int quality;
- int q_scale_factor;
- boolean force_baseline;
- boolean simple_progressive;
- char * qtablefile = ((char *)0);
- char * qslotsarg = ((char *)0);
- char * samplearg = ((char *)0);
- char * scansarg = ((char *)0);
-
-
-
-
-
- quality = 75;
- q_scale_factor = 100;
- force_baseline = 0;
- simple_progressive = 0;
- is_targa = 0;
- outfilename = ((char *)0);
- cinfo->err->trace_level = 0;
-
-
-
- for (argn = 1; argn < argc; argn++) {
- arg = argv[argn];
- if (*arg != '-') {
-
- if (argn <= last_file_arg_seen) {
- outfilename = ((char *)0);
- continue;
- }
- break;
- }
- arg++;
-
- if (keymatch(arg, "arithmetic", 1)) {
-
-
-
-
- fprintf((_impure_ptr->_stderr), "%s: sorry, arithmetic coding not supported\n",
- progname);
- exit(1);
-
-
- } else if (keymatch(arg, "baseline", 1)) {
-
- force_baseline = 1;
-
- } else if (keymatch(arg, "dct", 2)) {
-
- if (++argn >= argc)
- usage();
- if (keymatch(argv[argn], "int", 1)) {
- cinfo->dct_method = JDCT_ISLOW;
- } else if (keymatch(argv[argn], "fast", 2)) {
- cinfo->dct_method = JDCT_IFAST;
- } else if (keymatch(argv[argn], "float", 2)) {
- cinfo->dct_method = JDCT_FLOAT;
- } else
- usage();
-
- } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
-
-
- static boolean printed_version = 0;
-
- if (! printed_version) {
- fprintf((_impure_ptr->_stderr), "Independent JPEG Group's CJPEG, version %s\n%s\n",
- "6b 27-Mar-1998", "Copyright (C) 1998, Thomas G. Lane");
- printed_version = 1;
- }
- cinfo->err->trace_level++;
-
- } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
-
- jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
-
- } else if (keymatch(arg, "maxmemory", 3)) {
-
- long lval;
- char ch = 'x';
-
- if (++argn >= argc)
- usage();
- if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
- usage();
- if (ch == 'm' || ch == 'M')
- lval *= 1000L;
- cinfo->mem->max_memory_to_use = lval * 1000L;
-
- } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
-
-
- cinfo->optimize_coding = 1;
-
-
-
-
-
-
- } else if (keymatch(arg, "outfile", 4)) {
-
- if (++argn >= argc)
- usage();
- outfilename = argv[argn];
-
- } else if (keymatch(arg, "progressive", 1)) {
-
-
- simple_progressive = 1;
-
-
-
-
-
-
-
- } else if (keymatch(arg, "quality", 1)) {
-
- if (++argn >= argc)
- usage();
- if (sscanf(argv[argn], "%d", &quality) != 1)
- usage();
-
- q_scale_factor = jpeg_quality_scaling(quality);
-
- } else if (keymatch(arg, "qslots", 2)) {
-
- if (++argn >= argc)
- usage();
- qslotsarg = argv[argn];
-
-
-
-
-
- } else if (keymatch(arg, "qtables", 2)) {
-
- if (++argn >= argc)
- usage();
- qtablefile = argv[argn];
-
-
- } else if (keymatch(arg, "restart", 1)) {
-
- long lval;
- char ch = 'x';
-
- if (++argn >= argc)
- usage();
- if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
- usage();
- if (lval < 0 || lval > 65535L)
- usage();
- if (ch == 'b' || ch == 'B') {
- cinfo->restart_interval = (unsigned int) lval;
- cinfo->restart_in_rows = 0;
- } else {
- cinfo->restart_in_rows = (int) lval;
-
- }
-
- } else if (keymatch(arg, "sample", 2)) {
-
- if (++argn >= argc)
- usage();
- samplearg = argv[argn];
-
-
-
-
-
- } else if (keymatch(arg, "scans", 2)) {
-
-
- if (++argn >= argc)
- usage();
- scansarg = argv[argn];
-
-
-
-
-
-
-
- } else if (keymatch(arg, "smooth", 2)) {
-
- int val;
-
- if (++argn >= argc)
- usage();
- if (sscanf(argv[argn], "%d", &val) != 1)
- usage();
- if (val < 0 || val > 100)
- usage();
- cinfo->smoothing_factor = val;
-
- } else if (keymatch(arg, "targa", 1)) {
-
- is_targa = 1;
-
- } else {
- usage();
- }
- }
-
-
-
- if (for_real) {
-
-
-
- jpeg_set_quality(cinfo, quality, force_baseline);
-
- if (qtablefile != ((char *)0))
- if (! read_quant_tables(cinfo, qtablefile,
- q_scale_factor, force_baseline))
- usage();
-
- if (qslotsarg != ((char *)0))
- if (! set_quant_slots(cinfo, qslotsarg))
- usage();
-
- if (samplearg != ((char *)0))
- if (! set_sample_factors(cinfo, samplearg))
- usage();
-
-
- if (simple_progressive)
- jpeg_simple_progression(cinfo);
-
-
-
- if (scansarg != ((char *)0))
- if (! read_scan_script(cinfo, scansarg))
- usage();
-
- }
-
- return argn;
-}
-
-
-
-
-
-
-int
-main (int argc, char **argv)
-{
- struct jpeg_compress_struct cinfo;
- struct jpeg_error_mgr jerr;
-
-
-
- int file_index;
- cjpeg_source_ptr src_mgr;
- FILE * input_file;
- FILE * output_file;
- JDIMENSION num_scanlines;
-
-
-
-
-
-
- progname = argv[0];
- if (progname == ((char *)0) || progname[0] == 0)
- progname = "cjpeg";
-
-
- cinfo.err = jpeg_std_error(&jerr);
- jpeg_CreateCompress((&cinfo), 62, (size_t) sizeof(struct jpeg_compress_struct));
-
- jerr.addon_message_table = cdjpeg_message_table;
- jerr.first_addon_message = JMSG_FIRSTADDONCODE;
- jerr.last_addon_message = JMSG_LASTADDONCODE;
-# 502 "cjpeg.c"
- cinfo.in_color_space = JCS_RGB;
- jpeg_set_defaults(&cinfo);
-
-
-
-
-
-
-
- file_index = parse_switches(&cinfo, argc, argv, 0, 0);
-# 531 "cjpeg.c"
- if (file_index < argc-1) {
- fprintf((_impure_ptr->_stderr), "%s: only one input file\n", progname);
- usage();
- }
-
-
-
- if (file_index < argc) {
- if ((input_file = fopen(argv[file_index], "rb")) == ((char *)0)) {
- fprintf((_impure_ptr->_stderr), "%s: can't open %s\n", progname, argv[file_index]);
- exit(1);
- }
- } else {
-
- input_file = read_stdin();
- }
-
-
- if (outfilename != ((char *)0)) {
- if ((output_file = fopen(outfilename, "wb")) == ((char *)0)) {
- fprintf((_impure_ptr->_stderr), "%s: can't open %s\n", progname, outfilename);
- exit(1);
- }
- } else {
-
- output_file = write_stdout();
- }
-
-
-
-
-
-
- src_mgr = select_file_type(&cinfo, input_file);
- src_mgr->input_file = input_file;
-
-
- (*src_mgr->start_input) (&cinfo, src_mgr);
-
-
- jpeg_default_colorspace(&cinfo);
-
-
- file_index = parse_switches(&cinfo, argc, argv, 0, 1);
-
-
- jpeg_stdio_dest(&cinfo, output_file);
-
-
- jpeg_start_compress(&cinfo, 1);
-
-
- while (cinfo.next_scanline < cinfo.image_height) {
- num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
- (char) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
- }
-
-
- (*src_mgr->finish_input) (&cinfo, src_mgr);
- jpeg_finish_compress(&cinfo);
- jpeg_destroy_compress(&cinfo);
-
-
- if (input_file != (_impure_ptr->_stdin))
- fclose(input_file);
- if (output_file != (_impure_ptr->_stdout))
- fclose(output_file);
-
-
-
-
-
-
- exit(jerr.num_warnings ? 2 : 0);
- return 0;
-}
diff --git a/test/monniaux/jpeg-6b/configure b/test/monniaux/jpeg-6b/configure
index ce76b557..35c9db5c 100755
--- a/test/monniaux/jpeg-6b/configure
+++ b/test/monniaux/jpeg-6b/configure
@@ -623,7 +623,7 @@ cross_compiling=$ac_cv_prog_cc_cross
cat > conftest.$ac_ext <<EOF
#line 625 "configure"
#include "confdefs.h"
-int main(){return(0);}
+main(){return(0);}
EOF
if { (eval echo configure:629: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
ac_cv_prog_cc_works=yes
diff --git a/test/monniaux/jpeg-6b/djpeg.c b/test/monniaux/jpeg-6b/djpeg.c
index e099e90a..a63523c5 100644
--- a/test/monniaux/jpeg-6b/djpeg.c
+++ b/test/monniaux/jpeg-6b/djpeg.c
@@ -1,616 +1,616 @@
-/*
- * djpeg.c
- *
- * Copyright (C) 1991-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains a command-line user interface for the JPEG decompressor.
- * It should work on any system with Unix- or MS-DOS-style command lines.
- *
- * Two different command line styles are permitted, depending on the
- * compile-time switch TWO_FILE_COMMANDLINE:
- * djpeg [options] inputfile outputfile
- * djpeg [options] [inputfile]
- * In the second style, output is always to standard output, which you'd
- * normally redirect to a file or pipe to some other program. Input is
- * either from a named file or from standard input (typically redirected).
- * The second style is convenient on Unix but is unhelpful on systems that
- * don't support pipes. Also, you MUST use the first style if your system
- * doesn't do binary I/O to stdin/stdout.
- * To simplify script writing, the "-outfile" switch is provided. The syntax
- * djpeg [options] -outfile outputfile inputfile
- * works regardless of which command line style is used.
- */
-
-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
-#include "jversion.h" /* for version message */
-
-#include <ctype.h> /* to declare isprint() */
-
-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
-#ifdef __MWERKS__
-#include <SIOUX.h> /* Metrowerks needs this */
-#include <console.h> /* ... and this */
-#endif
-#ifdef THINK_C
-#include <console.h> /* Think declares it here */
-#endif
-#endif
-
-
-/* Create the add-on message string table. */
-
-#define JMESSAGE(code,string) string ,
-
-static const char * const cdjpeg_message_table[] = {
-#include "cderror.h"
- NULL
-};
-
-
-/*
- * This list defines the known output image formats
- * (not all of which need be supported by a given version).
- * You can change the default output format by defining DEFAULT_FMT;
- * indeed, you had better do so if you undefine PPM_SUPPORTED.
- */
-
-typedef enum {
- FMT_BMP, /* BMP format (Windows flavor) */
- FMT_GIF, /* GIF format */
- FMT_OS2, /* BMP format (OS/2 flavor) */
- FMT_PPM, /* PPM/PGM (PBMPLUS formats) */
- FMT_RLE, /* RLE format */
- FMT_TARGA, /* Targa format */
- FMT_TIFF /* TIFF format */
-} IMAGE_FORMATS;
-
-#ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */
-#define DEFAULT_FMT FMT_PPM
-#endif
-
-static IMAGE_FORMATS requested_fmt;
-
-
-/*
- * Argument-parsing code.
- * The switch parser is designed to be useful with DOS-style command line
- * syntax, ie, intermixed switches and file names, where only the switches
- * to the left of a given file name affect processing of that file.
- * The main program in this file doesn't actually use this capability...
- */
-
-
-static const char * progname; /* program name for error messages */
-static char * outfilename; /* for -outfile switch */
-
-
-LOCAL(void)
-usage (void)
-/* complain about bad command line */
-{
- fprintf(stderr, "usage: %s [switches] ", progname);
-#ifdef TWO_FILE_COMMANDLINE
- fprintf(stderr, "inputfile outputfile\n");
-#else
- fprintf(stderr, "[inputfile]\n");
-#endif
-
- fprintf(stderr, "Switches (names may be abbreviated):\n");
- fprintf(stderr, " -colors N Reduce image to no more than N colors\n");
- fprintf(stderr, " -fast Fast, low-quality processing\n");
- fprintf(stderr, " -grayscale Force grayscale output\n");
-#ifdef IDCT_SCALING_SUPPORTED
- fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n");
-#endif
-#ifdef BMP_SUPPORTED
- fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n",
- (DEFAULT_FMT == FMT_BMP ? " (default)" : ""));
-#endif
-#ifdef GIF_SUPPORTED
- fprintf(stderr, " -gif Select GIF output format%s\n",
- (DEFAULT_FMT == FMT_GIF ? " (default)" : ""));
-#endif
-#ifdef BMP_SUPPORTED
- fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n",
- (DEFAULT_FMT == FMT_OS2 ? " (default)" : ""));
-#endif
-#ifdef PPM_SUPPORTED
- fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n",
- (DEFAULT_FMT == FMT_PPM ? " (default)" : ""));
-#endif
-#ifdef RLE_SUPPORTED
- fprintf(stderr, " -rle Select Utah RLE output format%s\n",
- (DEFAULT_FMT == FMT_RLE ? " (default)" : ""));
-#endif
-#ifdef TARGA_SUPPORTED
- fprintf(stderr, " -targa Select Targa output format%s\n",
- (DEFAULT_FMT == FMT_TARGA ? " (default)" : ""));
-#endif
- fprintf(stderr, "Switches for advanced users:\n");
-#ifdef DCT_ISLOW_SUPPORTED
- fprintf(stderr, " -dct int Use integer DCT method%s\n",
- (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
-#endif
-#ifdef DCT_IFAST_SUPPORTED
- fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
- (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
-#endif
-#ifdef DCT_FLOAT_SUPPORTED
- fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
- (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
-#endif
- fprintf(stderr, " -dither fs Use F-S dithering (default)\n");
- fprintf(stderr, " -dither none Don't use dithering in quantization\n");
- fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n");
-#ifdef QUANT_2PASS_SUPPORTED
- fprintf(stderr, " -map FILE Map to colors used in named image file\n");
-#endif
- fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n");
-#ifdef QUANT_1PASS_SUPPORTED
- fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n");
-#endif
- fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
- fprintf(stderr, " -outfile name Specify name for output file\n");
- fprintf(stderr, " -verbose or -debug Emit debug output\n");
- exit(EXIT_FAILURE);
-}
-
-
-LOCAL(int)
-parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
- int last_file_arg_seen, boolean for_real)
-/* Parse optional switches.
- * Returns argv[] index of first file-name argument (== argc if none).
- * Any file names with indexes <= last_file_arg_seen are ignored;
- * they have presumably been processed in a previous iteration.
- * (Pass 0 for last_file_arg_seen on the first or only iteration.)
- * for_real is FALSE on the first (dummy) pass; we may skip any expensive
- * processing.
- */
-{
- int argn;
- char * arg;
-
- /* Set up default JPEG parameters. */
- requested_fmt = DEFAULT_FMT; /* set default output file format */
- outfilename = NULL;
- cinfo->err->trace_level = 0;
-
- /* Scan command line options, adjust parameters */
-
- for (argn = 1; argn < argc; argn++) {
- arg = argv[argn];
- if (*arg != '-') {
- /* Not a switch, must be a file name argument */
- if (argn <= last_file_arg_seen) {
- outfilename = NULL; /* -outfile applies to just one input file */
- continue; /* ignore this name if previously processed */
- }
- break; /* else done parsing switches */
- }
- arg++; /* advance past switch marker character */
-
- if (keymatch(arg, "bmp", 1)) {
- /* BMP output format. */
- requested_fmt = FMT_BMP;
-
- } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
- keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) {
- /* Do color quantization. */
- int val;
-
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (sscanf(argv[argn], "%d", &val) != 1)
- usage();
- cinfo->desired_number_of_colors = val;
- cinfo->quantize_colors = TRUE;
-
- } else if (keymatch(arg, "dct", 2)) {
- /* Select IDCT algorithm. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (keymatch(argv[argn], "int", 1)) {
- cinfo->dct_method = JDCT_ISLOW;
- } else if (keymatch(argv[argn], "fast", 2)) {
- cinfo->dct_method = JDCT_IFAST;
- } else if (keymatch(argv[argn], "float", 2)) {
- cinfo->dct_method = JDCT_FLOAT;
- } else
- usage();
-
- } else if (keymatch(arg, "dither", 2)) {
- /* Select dithering algorithm. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (keymatch(argv[argn], "fs", 2)) {
- cinfo->dither_mode = JDITHER_FS;
- } else if (keymatch(argv[argn], "none", 2)) {
- cinfo->dither_mode = JDITHER_NONE;
- } else if (keymatch(argv[argn], "ordered", 2)) {
- cinfo->dither_mode = JDITHER_ORDERED;
- } else
- usage();
-
- } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
- /* Enable debug printouts. */
- /* On first -d, print version identification */
- static boolean printed_version = FALSE;
-
- if (! printed_version) {
- fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n",
- JVERSION, JCOPYRIGHT);
- printed_version = TRUE;
- }
- cinfo->err->trace_level++;
-
- } else if (keymatch(arg, "fast", 1)) {
- /* Select recommended processing options for quick-and-dirty output. */
- cinfo->two_pass_quantize = FALSE;
- cinfo->dither_mode = JDITHER_ORDERED;
- if (! cinfo->quantize_colors) /* don't override an earlier -colors */
- cinfo->desired_number_of_colors = 216;
- cinfo->dct_method = JDCT_FASTEST;
- cinfo->do_fancy_upsampling = FALSE;
-
- } else if (keymatch(arg, "gif", 1)) {
- /* GIF output format. */
- requested_fmt = FMT_GIF;
-
- } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
- /* Force monochrome output. */
- cinfo->out_color_space = JCS_GRAYSCALE;
-
- } else if (keymatch(arg, "map", 3)) {
- /* Quantize to a color map taken from an input file. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (for_real) { /* too expensive to do twice! */
-#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
- FILE * mapfile;
-
- if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
- exit(EXIT_FAILURE);
- }
- read_color_map(cinfo, mapfile);
- fclose(mapfile);
- cinfo->quantize_colors = TRUE;
-#else
- ERREXIT(cinfo, JERR_NOT_COMPILED);
-#endif
- }
-
- } else if (keymatch(arg, "maxmemory", 3)) {
- /* Maximum memory in Kb (or Mb with 'm'). */
- long lval;
- char ch = 'x';
-
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
- usage();
- if (ch == 'm' || ch == 'M')
- lval *= 1000L;
- cinfo->mem->max_memory_to_use = lval * 1000L;
-
- } else if (keymatch(arg, "nosmooth", 3)) {
- /* Suppress fancy upsampling */
- cinfo->do_fancy_upsampling = FALSE;
-
- } else if (keymatch(arg, "onepass", 3)) {
- /* Use fast one-pass quantization. */
- cinfo->two_pass_quantize = FALSE;
-
- } else if (keymatch(arg, "os2", 3)) {
- /* BMP output format (OS/2 flavor). */
- requested_fmt = FMT_OS2;
-
- } else if (keymatch(arg, "outfile", 4)) {
- /* Set output file name. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- outfilename = argv[argn]; /* save it away for later use */
-
- } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) {
- /* PPM/PGM output format. */
- requested_fmt = FMT_PPM;
-
- } else if (keymatch(arg, "rle", 1)) {
- /* RLE output format. */
- requested_fmt = FMT_RLE;
-
- } else if (keymatch(arg, "scale", 1)) {
- /* Scale the output image by a fraction M/N. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (sscanf(argv[argn], "%d/%d",
- &cinfo->scale_num, &cinfo->scale_denom) != 2)
- usage();
-
- } else if (keymatch(arg, "targa", 1)) {
- /* Targa output format. */
- requested_fmt = FMT_TARGA;
-
- } else {
- usage(); /* bogus switch */
- }
- }
-
- return argn; /* return index of next arg (file name) */
-}
-
-
-/*
- * Marker processor for COM and interesting APPn markers.
- * This replaces the library's built-in processor, which just skips the marker.
- * We want to print out the marker as text, to the extent possible.
- * Note this code relies on a non-suspending data source.
- */
-
-LOCAL(unsigned int)
-jpeg_getc (j_decompress_ptr cinfo)
-/* Read next byte */
-{
- struct jpeg_source_mgr * datasrc = cinfo->src;
-
- if (datasrc->bytes_in_buffer == 0) {
- if (! (*datasrc->fill_input_buffer) (cinfo))
- ERREXIT(cinfo, JERR_CANT_SUSPEND);
- }
- datasrc->bytes_in_buffer--;
- return GETJOCTET(*datasrc->next_input_byte++);
-}
-
-
-METHODDEF(boolean)
-print_text_marker (j_decompress_ptr cinfo)
-{
- boolean traceit = (cinfo->err->trace_level >= 1);
- INT32 length;
- unsigned int ch;
- unsigned int lastch = 0;
-
- length = jpeg_getc(cinfo) << 8;
- length += jpeg_getc(cinfo);
- length -= 2; /* discount the length word itself */
-
- if (traceit) {
- if (cinfo->unread_marker == JPEG_COM)
- fprintf(stderr, "Comment, length %ld:\n", (long) length);
- else /* assume it is an APPn otherwise */
- fprintf(stderr, "APP%d, length %ld:\n",
- cinfo->unread_marker - JPEG_APP0, (long) length);
- }
-
- while (--length >= 0) {
- ch = jpeg_getc(cinfo);
- if (traceit) {
- /* Emit the character in a readable form.
- * Nonprintables are converted to \nnn form,
- * while \ is converted to \\.
- * Newlines in CR, CR/LF, or LF form will be printed as one newline.
- */
- if (ch == '\r') {
- fprintf(stderr, "\n");
- } else if (ch == '\n') {
- if (lastch != '\r')
- fprintf(stderr, "\n");
- } else if (ch == '\\') {
- fprintf(stderr, "\\\\");
- } else if (isprint(ch)) {
- putc(ch, stderr);
- } else {
- fprintf(stderr, "\\%03o", ch);
- }
- lastch = ch;
- }
- }
-
- if (traceit)
- fprintf(stderr, "\n");
-
- return TRUE;
-}
-
-
-/*
- * The main program.
- */
-
-int
-main (int argc, char **argv)
-{
- struct jpeg_decompress_struct cinfo;
- struct jpeg_error_mgr jerr;
-#ifdef PROGRESS_REPORT
- struct cdjpeg_progress_mgr progress;
-#endif
- int file_index;
- djpeg_dest_ptr dest_mgr = NULL;
- FILE * input_file;
- FILE * output_file;
- JDIMENSION num_scanlines;
-
- /* On Mac, fetch a command line. */
-#ifdef USE_CCOMMAND
- argc = ccommand(&argv);
-#endif
-
- progname = argv[0];
- if (progname == NULL || progname[0] == 0)
- progname = "djpeg"; /* in case C library doesn't provide it */
-
- /* Initialize the JPEG decompression object with default error handling. */
- cinfo.err = jpeg_std_error(&jerr);
- jpeg_create_decompress(&cinfo);
- /* Add some application-specific error messages (from cderror.h) */
- jerr.addon_message_table = cdjpeg_message_table;
- jerr.first_addon_message = JMSG_FIRSTADDONCODE;
- jerr.last_addon_message = JMSG_LASTADDONCODE;
-
- /* Insert custom marker processor for COM and APP12.
- * APP12 is used by some digital camera makers for textual info,
- * so we provide the ability to display it as text.
- * If you like, additional APPn marker types can be selected for display,
- * but don't try to override APP0 or APP14 this way (see libjpeg.doc).
- */
- jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
- jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);
-
- /* Now safe to enable signal catcher. */
-#ifdef NEED_SIGNAL_CATCHER
- enable_signal_catcher((j_common_ptr) &cinfo);
-#endif
-
- /* Scan command line to find file names. */
- /* It is convenient to use just one switch-parsing routine, but the switch
- * values read here are ignored; we will rescan the switches after opening
- * the input file.
- * (Exception: tracing level set here controls verbosity for COM markers
- * found during jpeg_read_header...)
- */
-
- file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
-
-#ifdef TWO_FILE_COMMANDLINE
- /* Must have either -outfile switch or explicit output file name */
- if (outfilename == NULL) {
- if (file_index != argc-2) {
- fprintf(stderr, "%s: must name one input and one output file\n",
- progname);
- usage();
- }
- outfilename = argv[file_index+1];
- } else {
- if (file_index != argc-1) {
- fprintf(stderr, "%s: must name one input and one output file\n",
- progname);
- usage();
- }
- }
-#else
- /* Unix style: expect zero or one file name */
- if (file_index < argc-1) {
- fprintf(stderr, "%s: only one input file\n", progname);
- usage();
- }
-#endif /* TWO_FILE_COMMANDLINE */
-
- /* Open the input file. */
- if (file_index < argc) {
- if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
- exit(EXIT_FAILURE);
- }
- } else {
- /* default input file is stdin */
- input_file = read_stdin();
- }
-
- /* Open the output file. */
- if (outfilename != NULL) {
- if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
- exit(EXIT_FAILURE);
- }
- } else {
- /* default output file is stdout */
- output_file = write_stdout();
- }
-
-#ifdef PROGRESS_REPORT
- start_progress_monitor((j_common_ptr) &cinfo, &progress);
-#endif
-
- /* Specify data source for decompression */
- jpeg_stdio_src(&cinfo, input_file);
-
- /* Read file header, set default decompression parameters */
- (void) jpeg_read_header(&cinfo, TRUE);
-
- /* Adjust default decompression parameters by re-parsing the options */
- file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
-
- /* Initialize the output module now to let it override any crucial
- * option settings (for instance, GIF wants to force color quantization).
- */
- switch (requested_fmt) {
-#ifdef BMP_SUPPORTED
- case FMT_BMP:
- dest_mgr = jinit_write_bmp(&cinfo, FALSE);
- break;
- case FMT_OS2:
- dest_mgr = jinit_write_bmp(&cinfo, TRUE);
- break;
-#endif
-#ifdef GIF_SUPPORTED
- case FMT_GIF:
- dest_mgr = jinit_write_gif(&cinfo);
- break;
-#endif
-#ifdef PPM_SUPPORTED
- case FMT_PPM:
- dest_mgr = jinit_write_ppm(&cinfo);
- break;
-#endif
-#ifdef RLE_SUPPORTED
- case FMT_RLE:
- dest_mgr = jinit_write_rle(&cinfo);
- break;
-#endif
-#ifdef TARGA_SUPPORTED
- case FMT_TARGA:
- dest_mgr = jinit_write_targa(&cinfo);
- break;
-#endif
- default:
- ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
- break;
- }
- dest_mgr->output_file = output_file;
-
- /* Start decompressor */
- (void) jpeg_start_decompress(&cinfo);
-
- /* Write output file header */
- (*dest_mgr->start_output) (&cinfo, dest_mgr);
-
- /* Process data */
- while (cinfo.output_scanline < cinfo.output_height) {
- num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
- dest_mgr->buffer_height);
- (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
- }
-
-#ifdef PROGRESS_REPORT
- /* Hack: count final pass as done in case finish_output does an extra pass.
- * The library won't have updated completed_passes.
- */
- progress.pub.completed_passes = progress.pub.total_passes;
-#endif
-
- /* Finish decompression and release memory.
- * I must do it in this order because output module has allocated memory
- * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.
- */
- (*dest_mgr->finish_output) (&cinfo, dest_mgr);
- (void) jpeg_finish_decompress(&cinfo);
- jpeg_destroy_decompress(&cinfo);
-
- /* Close files, if we opened them */
- if (input_file != stdin)
- fclose(input_file);
- if (output_file != stdout)
- fclose(output_file);
-
-#ifdef PROGRESS_REPORT
- end_progress_monitor((j_common_ptr) &cinfo);
-#endif
-
- /* All done. */
- exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
- return 0; /* suppress no-return-value warnings */
-}
+/*
+ * djpeg.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a command-line user interface for the JPEG decompressor.
+ * It should work on any system with Unix- or MS-DOS-style command lines.
+ *
+ * Two different command line styles are permitted, depending on the
+ * compile-time switch TWO_FILE_COMMANDLINE:
+ * djpeg [options] inputfile outputfile
+ * djpeg [options] [inputfile]
+ * In the second style, output is always to standard output, which you'd
+ * normally redirect to a file or pipe to some other program. Input is
+ * either from a named file or from standard input (typically redirected).
+ * The second style is convenient on Unix but is unhelpful on systems that
+ * don't support pipes. Also, you MUST use the first style if your system
+ * doesn't do binary I/O to stdin/stdout.
+ * To simplify script writing, the "-outfile" switch is provided. The syntax
+ * djpeg [options] -outfile outputfile inputfile
+ * works regardless of which command line style is used.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+#include "jversion.h" /* for version message */
+
+#include <ctype.h> /* to declare isprint() */
+
+#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
+#ifdef __MWERKS__
+#include <SIOUX.h> /* Metrowerks needs this */
+#include <console.h> /* ... and this */
+#endif
+#ifdef THINK_C
+#include <console.h> /* Think declares it here */
+#endif
+#endif
+
+
+/* Create the add-on message string table. */
+
+#define JMESSAGE(code,string) string ,
+
+static const char * const cdjpeg_message_table[] = {
+#include "cderror.h"
+ NULL
+};
+
+
+/*
+ * This list defines the known output image formats
+ * (not all of which need be supported by a given version).
+ * You can change the default output format by defining DEFAULT_FMT;
+ * indeed, you had better do so if you undefine PPM_SUPPORTED.
+ */
+
+typedef enum {
+ FMT_BMP, /* BMP format (Windows flavor) */
+ FMT_GIF, /* GIF format */
+ FMT_OS2, /* BMP format (OS/2 flavor) */
+ FMT_PPM, /* PPM/PGM (PBMPLUS formats) */
+ FMT_RLE, /* RLE format */
+ FMT_TARGA, /* Targa format */
+ FMT_TIFF /* TIFF format */
+} IMAGE_FORMATS;
+
+#ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */
+#define DEFAULT_FMT FMT_PPM
+#endif
+
+static IMAGE_FORMATS requested_fmt;
+
+
+/*
+ * Argument-parsing code.
+ * The switch parser is designed to be useful with DOS-style command line
+ * syntax, ie, intermixed switches and file names, where only the switches
+ * to the left of a given file name affect processing of that file.
+ * The main program in this file doesn't actually use this capability...
+ */
+
+
+static const char * progname; /* program name for error messages */
+static char * outfilename; /* for -outfile switch */
+
+
+LOCAL(void)
+usage (void)
+/* complain about bad command line */
+{
+ fprintf(stderr, "usage: %s [switches] ", progname);
+#ifdef TWO_FILE_COMMANDLINE
+ fprintf(stderr, "inputfile outputfile\n");
+#else
+ fprintf(stderr, "[inputfile]\n");
+#endif
+
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
+ fprintf(stderr, " -colors N Reduce image to no more than N colors\n");
+ fprintf(stderr, " -fast Fast, low-quality processing\n");
+ fprintf(stderr, " -grayscale Force grayscale output\n");
+#ifdef IDCT_SCALING_SUPPORTED
+ fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n");
+#endif
+#ifdef BMP_SUPPORTED
+ fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n",
+ (DEFAULT_FMT == FMT_BMP ? " (default)" : ""));
+#endif
+#ifdef GIF_SUPPORTED
+ fprintf(stderr, " -gif Select GIF output format%s\n",
+ (DEFAULT_FMT == FMT_GIF ? " (default)" : ""));
+#endif
+#ifdef BMP_SUPPORTED
+ fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n",
+ (DEFAULT_FMT == FMT_OS2 ? " (default)" : ""));
+#endif
+#ifdef PPM_SUPPORTED
+ fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n",
+ (DEFAULT_FMT == FMT_PPM ? " (default)" : ""));
+#endif
+#ifdef RLE_SUPPORTED
+ fprintf(stderr, " -rle Select Utah RLE output format%s\n",
+ (DEFAULT_FMT == FMT_RLE ? " (default)" : ""));
+#endif
+#ifdef TARGA_SUPPORTED
+ fprintf(stderr, " -targa Select Targa output format%s\n",
+ (DEFAULT_FMT == FMT_TARGA ? " (default)" : ""));
+#endif
+ fprintf(stderr, "Switches for advanced users:\n");
+#ifdef DCT_ISLOW_SUPPORTED
+ fprintf(stderr, " -dct int Use integer DCT method%s\n",
+ (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
+#endif
+#ifdef DCT_IFAST_SUPPORTED
+ fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
+ (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
+#endif
+#ifdef DCT_FLOAT_SUPPORTED
+ fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
+ (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
+#endif
+ fprintf(stderr, " -dither fs Use F-S dithering (default)\n");
+ fprintf(stderr, " -dither none Don't use dithering in quantization\n");
+ fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n");
+#ifdef QUANT_2PASS_SUPPORTED
+ fprintf(stderr, " -map FILE Map to colors used in named image file\n");
+#endif
+ fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n");
+#ifdef QUANT_1PASS_SUPPORTED
+ fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n");
+#endif
+ fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
+ fprintf(stderr, " -outfile name Specify name for output file\n");
+ fprintf(stderr, " -verbose or -debug Emit debug output\n");
+ exit(EXIT_FAILURE);
+}
+
+
+LOCAL(int)
+parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
+ int last_file_arg_seen, boolean for_real)
+/* Parse optional switches.
+ * Returns argv[] index of first file-name argument (== argc if none).
+ * Any file names with indexes <= last_file_arg_seen are ignored;
+ * they have presumably been processed in a previous iteration.
+ * (Pass 0 for last_file_arg_seen on the first or only iteration.)
+ * for_real is FALSE on the first (dummy) pass; we may skip any expensive
+ * processing.
+ */
+{
+ int argn;
+ char * arg;
+
+ /* Set up default JPEG parameters. */
+ requested_fmt = DEFAULT_FMT; /* set default output file format */
+ outfilename = NULL;
+ cinfo->err->trace_level = 0;
+
+ /* Scan command line options, adjust parameters */
+
+ for (argn = 1; argn < argc; argn++) {
+ arg = argv[argn];
+ if (*arg != '-') {
+ /* Not a switch, must be a file name argument */
+ if (argn <= last_file_arg_seen) {
+ outfilename = NULL; /* -outfile applies to just one input file */
+ continue; /* ignore this name if previously processed */
+ }
+ break; /* else done parsing switches */
+ }
+ arg++; /* advance past switch marker character */
+
+ if (keymatch(arg, "bmp", 1)) {
+ /* BMP output format. */
+ requested_fmt = FMT_BMP;
+
+ } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
+ keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) {
+ /* Do color quantization. */
+ int val;
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%d", &val) != 1)
+ usage();
+ cinfo->desired_number_of_colors = val;
+ cinfo->quantize_colors = TRUE;
+
+ } else if (keymatch(arg, "dct", 2)) {
+ /* Select IDCT algorithm. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (keymatch(argv[argn], "int", 1)) {
+ cinfo->dct_method = JDCT_ISLOW;
+ } else if (keymatch(argv[argn], "fast", 2)) {
+ cinfo->dct_method = JDCT_IFAST;
+ } else if (keymatch(argv[argn], "float", 2)) {
+ cinfo->dct_method = JDCT_FLOAT;
+ } else
+ usage();
+
+ } else if (keymatch(arg, "dither", 2)) {
+ /* Select dithering algorithm. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (keymatch(argv[argn], "fs", 2)) {
+ cinfo->dither_mode = JDITHER_FS;
+ } else if (keymatch(argv[argn], "none", 2)) {
+ cinfo->dither_mode = JDITHER_NONE;
+ } else if (keymatch(argv[argn], "ordered", 2)) {
+ cinfo->dither_mode = JDITHER_ORDERED;
+ } else
+ usage();
+
+ } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
+ /* Enable debug printouts. */
+ /* On first -d, print version identification */
+ static boolean printed_version = FALSE;
+
+ if (! printed_version) {
+ fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n",
+ JVERSION, JCOPYRIGHT);
+ printed_version = TRUE;
+ }
+ cinfo->err->trace_level++;
+
+ } else if (keymatch(arg, "fast", 1)) {
+ /* Select recommended processing options for quick-and-dirty output. */
+ cinfo->two_pass_quantize = FALSE;
+ cinfo->dither_mode = JDITHER_ORDERED;
+ if (! cinfo->quantize_colors) /* don't override an earlier -colors */
+ cinfo->desired_number_of_colors = 216;
+ cinfo->dct_method = JDCT_FASTEST;
+ cinfo->do_fancy_upsampling = FALSE;
+
+ } else if (keymatch(arg, "gif", 1)) {
+ /* GIF output format. */
+ requested_fmt = FMT_GIF;
+
+ } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
+ /* Force monochrome output. */
+ cinfo->out_color_space = JCS_GRAYSCALE;
+
+ } else if (keymatch(arg, "map", 3)) {
+ /* Quantize to a color map taken from an input file. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (for_real) { /* too expensive to do twice! */
+#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
+ FILE * mapfile;
+
+ if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
+ exit(EXIT_FAILURE);
+ }
+ read_color_map(cinfo, mapfile);
+ fclose(mapfile);
+ cinfo->quantize_colors = TRUE;
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ }
+
+ } else if (keymatch(arg, "maxmemory", 3)) {
+ /* Maximum memory in Kb (or Mb with 'm'). */
+ long lval;
+ char ch = 'x';
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
+ usage();
+ if (ch == 'm' || ch == 'M')
+ lval *= 1000L;
+ cinfo->mem->max_memory_to_use = lval * 1000L;
+
+ } else if (keymatch(arg, "nosmooth", 3)) {
+ /* Suppress fancy upsampling */
+ cinfo->do_fancy_upsampling = FALSE;
+
+ } else if (keymatch(arg, "onepass", 3)) {
+ /* Use fast one-pass quantization. */
+ cinfo->two_pass_quantize = FALSE;
+
+ } else if (keymatch(arg, "os2", 3)) {
+ /* BMP output format (OS/2 flavor). */
+ requested_fmt = FMT_OS2;
+
+ } else if (keymatch(arg, "outfile", 4)) {
+ /* Set output file name. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ outfilename = argv[argn]; /* save it away for later use */
+
+ } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) {
+ /* PPM/PGM output format. */
+ requested_fmt = FMT_PPM;
+
+ } else if (keymatch(arg, "rle", 1)) {
+ /* RLE output format. */
+ requested_fmt = FMT_RLE;
+
+ } else if (keymatch(arg, "scale", 1)) {
+ /* Scale the output image by a fraction M/N. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%d/%d",
+ &cinfo->scale_num, &cinfo->scale_denom) != 2)
+ usage();
+
+ } else if (keymatch(arg, "targa", 1)) {
+ /* Targa output format. */
+ requested_fmt = FMT_TARGA;
+
+ } else {
+ usage(); /* bogus switch */
+ }
+ }
+
+ return argn; /* return index of next arg (file name) */
+}
+
+
+/*
+ * Marker processor for COM and interesting APPn markers.
+ * This replaces the library's built-in processor, which just skips the marker.
+ * We want to print out the marker as text, to the extent possible.
+ * Note this code relies on a non-suspending data source.
+ */
+
+LOCAL(unsigned int)
+jpeg_getc (j_decompress_ptr cinfo)
+/* Read next byte */
+{
+ struct jpeg_source_mgr * datasrc = cinfo->src;
+
+ if (datasrc->bytes_in_buffer == 0) {
+ if (! (*datasrc->fill_input_buffer) (cinfo))
+ ERREXIT(cinfo, JERR_CANT_SUSPEND);
+ }
+ datasrc->bytes_in_buffer--;
+ return GETJOCTET(*datasrc->next_input_byte++);
+}
+
+
+METHODDEF(boolean)
+print_text_marker (j_decompress_ptr cinfo)
+{
+ boolean traceit = (cinfo->err->trace_level >= 1);
+ INT32 length;
+ unsigned int ch;
+ unsigned int lastch = 0;
+
+ length = jpeg_getc(cinfo) << 8;
+ length += jpeg_getc(cinfo);
+ length -= 2; /* discount the length word itself */
+
+ if (traceit) {
+ if (cinfo->unread_marker == JPEG_COM)
+ fprintf(stderr, "Comment, length %ld:\n", (long) length);
+ else /* assume it is an APPn otherwise */
+ fprintf(stderr, "APP%d, length %ld:\n",
+ cinfo->unread_marker - JPEG_APP0, (long) length);
+ }
+
+ while (--length >= 0) {
+ ch = jpeg_getc(cinfo);
+ if (traceit) {
+ /* Emit the character in a readable form.
+ * Nonprintables are converted to \nnn form,
+ * while \ is converted to \\.
+ * Newlines in CR, CR/LF, or LF form will be printed as one newline.
+ */
+ if (ch == '\r') {
+ fprintf(stderr, "\n");
+ } else if (ch == '\n') {
+ if (lastch != '\r')
+ fprintf(stderr, "\n");
+ } else if (ch == '\\') {
+ fprintf(stderr, "\\\\");
+ } else if (isprint(ch)) {
+ putc(ch, stderr);
+ } else {
+ fprintf(stderr, "\\%03o", ch);
+ }
+ lastch = ch;
+ }
+ }
+
+ if (traceit)
+ fprintf(stderr, "\n");
+
+ return TRUE;
+}
+
+
+/*
+ * The main program.
+ */
+
+int
+main (int argc, char **argv)
+{
+ struct jpeg_decompress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+#ifdef PROGRESS_REPORT
+ struct cdjpeg_progress_mgr progress;
+#endif
+ int file_index;
+ djpeg_dest_ptr dest_mgr = NULL;
+ FILE * input_file;
+ FILE * output_file;
+ JDIMENSION num_scanlines;
+
+ /* On Mac, fetch a command line. */
+#ifdef USE_CCOMMAND
+ argc = ccommand(&argv);
+#endif
+
+ progname = argv[0];
+ if (progname == NULL || progname[0] == 0)
+ progname = "djpeg"; /* in case C library doesn't provide it */
+
+ /* Initialize the JPEG decompression object with default error handling. */
+ cinfo.err = jpeg_std_error(&jerr);
+ jpeg_create_decompress(&cinfo);
+ /* Add some application-specific error messages (from cderror.h) */
+ jerr.addon_message_table = cdjpeg_message_table;
+ jerr.first_addon_message = JMSG_FIRSTADDONCODE;
+ jerr.last_addon_message = JMSG_LASTADDONCODE;
+
+ /* Insert custom marker processor for COM and APP12.
+ * APP12 is used by some digital camera makers for textual info,
+ * so we provide the ability to display it as text.
+ * If you like, additional APPn marker types can be selected for display,
+ * but don't try to override APP0 or APP14 this way (see libjpeg.doc).
+ */
+ jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
+ jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);
+
+ /* Now safe to enable signal catcher. */
+#ifdef NEED_SIGNAL_CATCHER
+ enable_signal_catcher((j_common_ptr) &cinfo);
+#endif
+
+ /* Scan command line to find file names. */
+ /* It is convenient to use just one switch-parsing routine, but the switch
+ * values read here are ignored; we will rescan the switches after opening
+ * the input file.
+ * (Exception: tracing level set here controls verbosity for COM markers
+ * found during jpeg_read_header...)
+ */
+
+ file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
+
+#ifdef TWO_FILE_COMMANDLINE
+ /* Must have either -outfile switch or explicit output file name */
+ if (outfilename == NULL) {
+ if (file_index != argc-2) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ outfilename = argv[file_index+1];
+ } else {
+ if (file_index != argc-1) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ }
+#else
+ /* Unix style: expect zero or one file name */
+ if (file_index < argc-1) {
+ fprintf(stderr, "%s: only one input file\n", progname);
+ usage();
+ }
+#endif /* TWO_FILE_COMMANDLINE */
+
+ /* Open the input file. */
+ if (file_index < argc) {
+ if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default input file is stdin */
+ input_file = read_stdin();
+ }
+
+ /* Open the output file. */
+ if (outfilename != NULL) {
+ if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default output file is stdout */
+ output_file = write_stdout();
+ }
+
+#ifdef PROGRESS_REPORT
+ start_progress_monitor((j_common_ptr) &cinfo, &progress);
+#endif
+
+ /* Specify data source for decompression */
+ jpeg_stdio_src(&cinfo, input_file);
+
+ /* Read file header, set default decompression parameters */
+ (void) jpeg_read_header(&cinfo, TRUE);
+
+ /* Adjust default decompression parameters by re-parsing the options */
+ file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
+
+ /* Initialize the output module now to let it override any crucial
+ * option settings (for instance, GIF wants to force color quantization).
+ */
+ switch (requested_fmt) {
+#ifdef BMP_SUPPORTED
+ case FMT_BMP:
+ dest_mgr = jinit_write_bmp(&cinfo, FALSE);
+ break;
+ case FMT_OS2:
+ dest_mgr = jinit_write_bmp(&cinfo, TRUE);
+ break;
+#endif
+#ifdef GIF_SUPPORTED
+ case FMT_GIF:
+ dest_mgr = jinit_write_gif(&cinfo);
+ break;
+#endif
+#ifdef PPM_SUPPORTED
+ case FMT_PPM:
+ dest_mgr = jinit_write_ppm(&cinfo);
+ break;
+#endif
+#ifdef RLE_SUPPORTED
+ case FMT_RLE:
+ dest_mgr = jinit_write_rle(&cinfo);
+ break;
+#endif
+#ifdef TARGA_SUPPORTED
+ case FMT_TARGA:
+ dest_mgr = jinit_write_targa(&cinfo);
+ break;
+#endif
+ default:
+ ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
+ break;
+ }
+ dest_mgr->output_file = output_file;
+
+ /* Start decompressor */
+ (void) jpeg_start_decompress(&cinfo);
+
+ /* Write output file header */
+ (*dest_mgr->start_output) (&cinfo, dest_mgr);
+
+ /* Process data */
+ while (cinfo.output_scanline < cinfo.output_height) {
+ num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
+ dest_mgr->buffer_height);
+ (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
+ }
+
+#ifdef PROGRESS_REPORT
+ /* Hack: count final pass as done in case finish_output does an extra pass.
+ * The library won't have updated completed_passes.
+ */
+ progress.pub.completed_passes = progress.pub.total_passes;
+#endif
+
+ /* Finish decompression and release memory.
+ * I must do it in this order because output module has allocated memory
+ * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.
+ */
+ (*dest_mgr->finish_output) (&cinfo, dest_mgr);
+ (void) jpeg_finish_decompress(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+
+ /* Close files, if we opened them */
+ if (input_file != stdin)
+ fclose(input_file);
+ if (output_file != stdout)
+ fclose(output_file);
+
+#ifdef PROGRESS_REPORT
+ end_progress_monitor((j_common_ptr) &cinfo);
+#endif
+
+ /* All done. */
+ exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
+ return 0; /* suppress no-return-value warnings */
+}
diff --git a/test/monniaux/jpeg-6b/dm_configure_ccomp.sh b/test/monniaux/jpeg-6b/dm_configure_ccomp.sh
deleted file mode 100755
index ef531cb4..00000000
--- a/test/monniaux/jpeg-6b/dm_configure_ccomp.sh
+++ /dev/null
@@ -1 +0,0 @@
-CC=./ccomp.sh CFLAGS="-DNO_DOUBLE -DNO_32BIT_DIVISION -DNO_FLOAT -DNO_SWITCH -DTAIL_CALL_MISSING" ./configure
diff --git a/test/monniaux/jpeg-6b/example.c b/test/monniaux/jpeg-6b/example.c
index 7fc354f0..9dcbd7d9 100644
--- a/test/monniaux/jpeg-6b/example.c
+++ b/test/monniaux/jpeg-6b/example.c
@@ -1,433 +1,433 @@
-/*
- * example.c
- *
- * This file illustrates how to use the IJG code as a subroutine library
- * to read or write JPEG image files. You should look at this code in
- * conjunction with the documentation file libjpeg.doc.
- *
- * This code will not do anything useful as-is, but it may be helpful as a
- * skeleton for constructing routines that call the JPEG library.
- *
- * We present these routines in the same coding style used in the JPEG code
- * (ANSI function definitions, etc); but you are of course free to code your
- * routines in a different style if you prefer.
- */
-
-#include <stdio.h>
-
-/*
- * Include file for users of JPEG library.
- * You will need to have included system headers that define at least
- * the typedefs FILE and size_t before you can include jpeglib.h.
- * (stdio.h is sufficient on ANSI-conforming systems.)
- * You may also wish to include "jerror.h".
- */
-
-#include "jpeglib.h"
-
-/*
- * <setjmp.h> is used for the optional error recovery mechanism shown in
- * the second part of the example.
- */
-
-#include <setjmp.h>
-
-
-
-/******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/
-
-/* This half of the example shows how to feed data into the JPEG compressor.
- * We present a minimal version that does not worry about refinements such
- * as error recovery (the JPEG code will just exit() if it gets an error).
- */
-
-
-/*
- * IMAGE DATA FORMATS:
- *
- * The standard input image format is a rectangular array of pixels, with
- * each pixel having the same number of "component" values (color channels).
- * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars).
- * If you are working with color data, then the color values for each pixel
- * must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit
- * RGB color.
- *
- * For this example, we'll assume that this data structure matches the way
- * our application has stored the image in memory, so we can just pass a
- * pointer to our image buffer. In particular, let's say that the image is
- * RGB color and is described by:
- */
-
-extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
-extern int image_height; /* Number of rows in image */
-extern int image_width; /* Number of columns in image */
-
-
-/*
- * Sample routine for JPEG compression. We assume that the target file name
- * and a compression quality factor are passed in.
- */
-
-GLOBAL(void)
-write_JPEG_file (char * filename, int quality)
-{
- /* This struct contains the JPEG compression parameters and pointers to
- * working space (which is allocated as needed by the JPEG library).
- * It is possible to have several such structures, representing multiple
- * compression/decompression processes, in existence at once. We refer
- * to any one struct (and its associated working data) as a "JPEG object".
- */
- struct jpeg_compress_struct cinfo;
- /* This struct represents a JPEG error handler. It is declared separately
- * because applications often want to supply a specialized error handler
- * (see the second half of this file for an example). But here we just
- * take the easy way out and use the standard error handler, which will
- * print a message on stderr and call exit() if compression fails.
- * Note that this struct must live as long as the main JPEG parameter
- * struct, to avoid dangling-pointer problems.
- */
- struct jpeg_error_mgr jerr;
- /* More stuff */
- FILE * outfile; /* target file */
- JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
- int row_stride; /* physical row width in image buffer */
-
- /* Step 1: allocate and initialize JPEG compression object */
-
- /* We have to set up the error handler first, in case the initialization
- * step fails. (Unlikely, but it could happen if you are out of memory.)
- * This routine fills in the contents of struct jerr, and returns jerr's
- * address which we place into the link field in cinfo.
- */
- cinfo.err = jpeg_std_error(&jerr);
- /* Now we can initialize the JPEG compression object. */
- jpeg_create_compress(&cinfo);
-
- /* Step 2: specify data destination (eg, a file) */
- /* Note: steps 2 and 3 can be done in either order. */
-
- /* Here we use the library-supplied code to send compressed data to a
- * stdio stream. You can also write your own code to do something else.
- * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
- * requires it in order to write binary files.
- */
- if ((outfile = fopen(filename, "wb")) == NULL) {
- fprintf(stderr, "can't open %s\n", filename);
- exit(1);
- }
- jpeg_stdio_dest(&cinfo, outfile);
-
- /* Step 3: set parameters for compression */
-
- /* First we supply a description of the input image.
- * Four fields of the cinfo struct must be filled in:
- */
- cinfo.image_width = image_width; /* image width and height, in pixels */
- cinfo.image_height = image_height;
- cinfo.input_components = 3; /* # of color components per pixel */
- cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
- /* Now use the library's routine to set default compression parameters.
- * (You must set at least cinfo.in_color_space before calling this,
- * since the defaults depend on the source color space.)
- */
- jpeg_set_defaults(&cinfo);
- /* Now you can set any non-default parameters you wish to.
- * Here we just illustrate the use of quality (quantization table) scaling:
- */
- jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
-
- /* Step 4: Start compressor */
-
- /* TRUE ensures that we will write a complete interchange-JPEG file.
- * Pass TRUE unless you are very sure of what you're doing.
- */
- jpeg_start_compress(&cinfo, TRUE);
-
- /* Step 5: while (scan lines remain to be written) */
- /* jpeg_write_scanlines(...); */
-
- /* Here we use the library's state variable cinfo.next_scanline as the
- * loop counter, so that we don't have to keep track ourselves.
- * To keep things simple, we pass one scanline per call; you can pass
- * more if you wish, though.
- */
- row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */
-
- while (cinfo.next_scanline < cinfo.image_height) {
- /* jpeg_write_scanlines expects an array of pointers to scanlines.
- * Here the array is only one element long, but you could pass
- * more than one scanline at a time if that's more convenient.
- */
- row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
- (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
- }
-
- /* Step 6: Finish compression */
-
- jpeg_finish_compress(&cinfo);
- /* After finish_compress, we can close the output file. */
- fclose(outfile);
-
- /* Step 7: release JPEG compression object */
-
- /* This is an important step since it will release a good deal of memory. */
- jpeg_destroy_compress(&cinfo);
-
- /* And we're done! */
-}
-
-
-/*
- * SOME FINE POINTS:
- *
- * In the above loop, we ignored the return value of jpeg_write_scanlines,
- * which is the number of scanlines actually written. We could get away
- * with this because we were only relying on the value of cinfo.next_scanline,
- * which will be incremented correctly. If you maintain additional loop
- * variables then you should be careful to increment them properly.
- * Actually, for output to a stdio stream you needn't worry, because
- * then jpeg_write_scanlines will write all the lines passed (or else exit
- * with a fatal error). Partial writes can only occur if you use a data
- * destination module that can demand suspension of the compressor.
- * (If you don't know what that's for, you don't need it.)
- *
- * If the compressor requires full-image buffers (for entropy-coding
- * optimization or a multi-scan JPEG file), it will create temporary
- * files for anything that doesn't fit within the maximum-memory setting.
- * (Note that temp files are NOT needed if you use the default parameters.)
- * On some systems you may need to set up a signal handler to ensure that
- * temporary files are deleted if the program is interrupted. See libjpeg.doc.
- *
- * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG
- * files to be compatible with everyone else's. If you cannot readily read
- * your data in that order, you'll need an intermediate array to hold the
- * image. See rdtarga.c or rdbmp.c for examples of handling bottom-to-top
- * source data using the JPEG code's internal virtual-array mechanisms.
- */
-
-
-
-/******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/
-
-/* This half of the example shows how to read data from the JPEG decompressor.
- * It's a bit more refined than the above, in that we show:
- * (a) how to modify the JPEG library's standard error-reporting behavior;
- * (b) how to allocate workspace using the library's memory manager.
- *
- * Just to make this example a little different from the first one, we'll
- * assume that we do not intend to put the whole image into an in-memory
- * buffer, but to send it line-by-line someplace else. We need a one-
- * scanline-high JSAMPLE array as a work buffer, and we will let the JPEG
- * memory manager allocate it for us. This approach is actually quite useful
- * because we don't need to remember to deallocate the buffer separately: it
- * will go away automatically when the JPEG object is cleaned up.
- */
-
-
-/*
- * ERROR HANDLING:
- *
- * The JPEG library's standard error handler (jerror.c) is divided into
- * several "methods" which you can override individually. This lets you
- * adjust the behavior without duplicating a lot of code, which you might
- * have to update with each future release.
- *
- * Our example here shows how to override the "error_exit" method so that
- * control is returned to the library's caller when a fatal error occurs,
- * rather than calling exit() as the standard error_exit method does.
- *
- * We use C's setjmp/longjmp facility to return control. This means that the
- * routine which calls the JPEG library must first execute a setjmp() call to
- * establish the return point. We want the replacement error_exit to do a
- * longjmp(). But we need to make the setjmp buffer accessible to the
- * error_exit routine. To do this, we make a private extension of the
- * standard JPEG error handler object. (If we were using C++, we'd say we
- * were making a subclass of the regular error handler.)
- *
- * Here's the extended error handler struct:
- */
-
-struct my_error_mgr {
- struct jpeg_error_mgr pub; /* "public" fields */
-
- jmp_buf setjmp_buffer; /* for return to caller */
-};
-
-typedef struct my_error_mgr * my_error_ptr;
-
-/*
- * Here's the routine that will replace the standard error_exit method:
- */
-
-METHODDEF(void)
-my_error_exit (j_common_ptr cinfo)
-{
- /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
- my_error_ptr myerr = (my_error_ptr) cinfo->err;
-
- /* Always display the message. */
- /* We could postpone this until after returning, if we chose. */
- (*cinfo->err->output_message) (cinfo);
-
- /* Return control to the setjmp point */
- longjmp(myerr->setjmp_buffer, 1);
-}
-
-
-/*
- * Sample routine for JPEG decompression. We assume that the source file name
- * is passed in. We want to return 1 on success, 0 on error.
- */
-
-
-GLOBAL(int)
-read_JPEG_file (char * filename)
-{
- /* This struct contains the JPEG decompression parameters and pointers to
- * working space (which is allocated as needed by the JPEG library).
- */
- struct jpeg_decompress_struct cinfo;
- /* We use our private extension JPEG error handler.
- * Note that this struct must live as long as the main JPEG parameter
- * struct, to avoid dangling-pointer problems.
- */
- struct my_error_mgr jerr;
- /* More stuff */
- FILE * infile; /* source file */
- JSAMPARRAY buffer; /* Output row buffer */
- int row_stride; /* physical row width in output buffer */
-
- /* In this example we want to open the input file before doing anything else,
- * so that the setjmp() error recovery below can assume the file is open.
- * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
- * requires it in order to read binary files.
- */
-
- if ((infile = fopen(filename, "rb")) == NULL) {
- fprintf(stderr, "can't open %s\n", filename);
- return 0;
- }
-
- /* Step 1: allocate and initialize JPEG decompression object */
-
- /* We set up the normal JPEG error routines, then override error_exit. */
- cinfo.err = jpeg_std_error(&jerr.pub);
- jerr.pub.error_exit = my_error_exit;
- /* Establish the setjmp return context for my_error_exit to use. */
- if (setjmp(jerr.setjmp_buffer)) {
- /* If we get here, the JPEG code has signaled an error.
- * We need to clean up the JPEG object, close the input file, and return.
- */
- jpeg_destroy_decompress(&cinfo);
- fclose(infile);
- return 0;
- }
- /* Now we can initialize the JPEG decompression object. */
- jpeg_create_decompress(&cinfo);
-
- /* Step 2: specify data source (eg, a file) */
-
- jpeg_stdio_src(&cinfo, infile);
-
- /* Step 3: read file parameters with jpeg_read_header() */
-
- (void) jpeg_read_header(&cinfo, TRUE);
- /* We can ignore the return value from jpeg_read_header since
- * (a) suspension is not possible with the stdio data source, and
- * (b) we passed TRUE to reject a tables-only JPEG file as an error.
- * See libjpeg.doc for more info.
- */
-
- /* Step 4: set parameters for decompression */
-
- /* In this example, we don't need to change any of the defaults set by
- * jpeg_read_header(), so we do nothing here.
- */
-
- /* Step 5: Start decompressor */
-
- (void) jpeg_start_decompress(&cinfo);
- /* We can ignore the return value since suspension is not possible
- * with the stdio data source.
- */
-
- /* We may need to do some setup of our own at this point before reading
- * the data. After jpeg_start_decompress() we have the correct scaled
- * output image dimensions available, as well as the output colormap
- * if we asked for color quantization.
- * In this example, we need to make an output work buffer of the right size.
- */
- /* JSAMPLEs per row in output buffer */
- row_stride = cinfo.output_width * cinfo.output_components;
- /* Make a one-row-high sample array that will go away when done with image */
- buffer = (*cinfo.mem->alloc_sarray)
- ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
-
- /* Step 6: while (scan lines remain to be read) */
- /* jpeg_read_scanlines(...); */
-
- /* Here we use the library's state variable cinfo.output_scanline as the
- * loop counter, so that we don't have to keep track ourselves.
- */
- while (cinfo.output_scanline < cinfo.output_height) {
- /* jpeg_read_scanlines expects an array of pointers to scanlines.
- * Here the array is only one element long, but you could ask for
- * more than one scanline at a time if that's more convenient.
- */
- (void) jpeg_read_scanlines(&cinfo, buffer, 1);
- /* Assume put_scanline_someplace wants a pointer and sample count. */
- put_scanline_someplace(buffer[0], row_stride);
- }
-
- /* Step 7: Finish decompression */
-
- (void) jpeg_finish_decompress(&cinfo);
- /* We can ignore the return value since suspension is not possible
- * with the stdio data source.
- */
-
- /* Step 8: Release JPEG decompression object */
-
- /* This is an important step since it will release a good deal of memory. */
- jpeg_destroy_decompress(&cinfo);
-
- /* After finish_decompress, we can close the input file.
- * Here we postpone it until after no more JPEG errors are possible,
- * so as to simplify the setjmp error logic above. (Actually, I don't
- * think that jpeg_destroy can do an error exit, but why assume anything...)
- */
- fclose(infile);
-
- /* At this point you may want to check to see whether any corrupt-data
- * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
- */
-
- /* And we're done! */
- return 1;
-}
-
-
-/*
- * SOME FINE POINTS:
- *
- * In the above code, we ignored the return value of jpeg_read_scanlines,
- * which is the number of scanlines actually read. We could get away with
- * this because we asked for only one line at a time and we weren't using
- * a suspending data source. See libjpeg.doc for more info.
- *
- * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress();
- * we should have done it beforehand to ensure that the space would be
- * counted against the JPEG max_memory setting. In some systems the above
- * code would risk an out-of-memory error. However, in general we don't
- * know the output image dimensions before jpeg_start_decompress(), unless we
- * call jpeg_calc_output_dimensions(). See libjpeg.doc for more about this.
- *
- * Scanlines are returned in the same order as they appear in the JPEG file,
- * which is standardly top-to-bottom. If you must emit data bottom-to-top,
- * you can use one of the virtual arrays provided by the JPEG memory manager
- * to invert the data. See wrbmp.c for an example.
- *
- * As with compression, some operating modes may require temporary files.
- * On some systems you may need to set up a signal handler to ensure that
- * temporary files are deleted if the program is interrupted. See libjpeg.doc.
- */
+/*
+ * example.c
+ *
+ * This file illustrates how to use the IJG code as a subroutine library
+ * to read or write JPEG image files. You should look at this code in
+ * conjunction with the documentation file libjpeg.doc.
+ *
+ * This code will not do anything useful as-is, but it may be helpful as a
+ * skeleton for constructing routines that call the JPEG library.
+ *
+ * We present these routines in the same coding style used in the JPEG code
+ * (ANSI function definitions, etc); but you are of course free to code your
+ * routines in a different style if you prefer.
+ */
+
+#include <stdio.h>
+
+/*
+ * Include file for users of JPEG library.
+ * You will need to have included system headers that define at least
+ * the typedefs FILE and size_t before you can include jpeglib.h.
+ * (stdio.h is sufficient on ANSI-conforming systems.)
+ * You may also wish to include "jerror.h".
+ */
+
+#include "jpeglib.h"
+
+/*
+ * <setjmp.h> is used for the optional error recovery mechanism shown in
+ * the second part of the example.
+ */
+
+#include <setjmp.h>
+
+
+
+/******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/
+
+/* This half of the example shows how to feed data into the JPEG compressor.
+ * We present a minimal version that does not worry about refinements such
+ * as error recovery (the JPEG code will just exit() if it gets an error).
+ */
+
+
+/*
+ * IMAGE DATA FORMATS:
+ *
+ * The standard input image format is a rectangular array of pixels, with
+ * each pixel having the same number of "component" values (color channels).
+ * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars).
+ * If you are working with color data, then the color values for each pixel
+ * must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit
+ * RGB color.
+ *
+ * For this example, we'll assume that this data structure matches the way
+ * our application has stored the image in memory, so we can just pass a
+ * pointer to our image buffer. In particular, let's say that the image is
+ * RGB color and is described by:
+ */
+
+extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
+extern int image_height; /* Number of rows in image */
+extern int image_width; /* Number of columns in image */
+
+
+/*
+ * Sample routine for JPEG compression. We assume that the target file name
+ * and a compression quality factor are passed in.
+ */
+
+GLOBAL(void)
+write_JPEG_file (char * filename, int quality)
+{
+ /* This struct contains the JPEG compression parameters and pointers to
+ * working space (which is allocated as needed by the JPEG library).
+ * It is possible to have several such structures, representing multiple
+ * compression/decompression processes, in existence at once. We refer
+ * to any one struct (and its associated working data) as a "JPEG object".
+ */
+ struct jpeg_compress_struct cinfo;
+ /* This struct represents a JPEG error handler. It is declared separately
+ * because applications often want to supply a specialized error handler
+ * (see the second half of this file for an example). But here we just
+ * take the easy way out and use the standard error handler, which will
+ * print a message on stderr and call exit() if compression fails.
+ * Note that this struct must live as long as the main JPEG parameter
+ * struct, to avoid dangling-pointer problems.
+ */
+ struct jpeg_error_mgr jerr;
+ /* More stuff */
+ FILE * outfile; /* target file */
+ JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
+ int row_stride; /* physical row width in image buffer */
+
+ /* Step 1: allocate and initialize JPEG compression object */
+
+ /* We have to set up the error handler first, in case the initialization
+ * step fails. (Unlikely, but it could happen if you are out of memory.)
+ * This routine fills in the contents of struct jerr, and returns jerr's
+ * address which we place into the link field in cinfo.
+ */
+ cinfo.err = jpeg_std_error(&jerr);
+ /* Now we can initialize the JPEG compression object. */
+ jpeg_create_compress(&cinfo);
+
+ /* Step 2: specify data destination (eg, a file) */
+ /* Note: steps 2 and 3 can be done in either order. */
+
+ /* Here we use the library-supplied code to send compressed data to a
+ * stdio stream. You can also write your own code to do something else.
+ * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
+ * requires it in order to write binary files.
+ */
+ if ((outfile = fopen(filename, "wb")) == NULL) {
+ fprintf(stderr, "can't open %s\n", filename);
+ exit(1);
+ }
+ jpeg_stdio_dest(&cinfo, outfile);
+
+ /* Step 3: set parameters for compression */
+
+ /* First we supply a description of the input image.
+ * Four fields of the cinfo struct must be filled in:
+ */
+ cinfo.image_width = image_width; /* image width and height, in pixels */
+ cinfo.image_height = image_height;
+ cinfo.input_components = 3; /* # of color components per pixel */
+ cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
+ /* Now use the library's routine to set default compression parameters.
+ * (You must set at least cinfo.in_color_space before calling this,
+ * since the defaults depend on the source color space.)
+ */
+ jpeg_set_defaults(&cinfo);
+ /* Now you can set any non-default parameters you wish to.
+ * Here we just illustrate the use of quality (quantization table) scaling:
+ */
+ jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
+
+ /* Step 4: Start compressor */
+
+ /* TRUE ensures that we will write a complete interchange-JPEG file.
+ * Pass TRUE unless you are very sure of what you're doing.
+ */
+ jpeg_start_compress(&cinfo, TRUE);
+
+ /* Step 5: while (scan lines remain to be written) */
+ /* jpeg_write_scanlines(...); */
+
+ /* Here we use the library's state variable cinfo.next_scanline as the
+ * loop counter, so that we don't have to keep track ourselves.
+ * To keep things simple, we pass one scanline per call; you can pass
+ * more if you wish, though.
+ */
+ row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */
+
+ while (cinfo.next_scanline < cinfo.image_height) {
+ /* jpeg_write_scanlines expects an array of pointers to scanlines.
+ * Here the array is only one element long, but you could pass
+ * more than one scanline at a time if that's more convenient.
+ */
+ row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
+ (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
+ }
+
+ /* Step 6: Finish compression */
+
+ jpeg_finish_compress(&cinfo);
+ /* After finish_compress, we can close the output file. */
+ fclose(outfile);
+
+ /* Step 7: release JPEG compression object */
+
+ /* This is an important step since it will release a good deal of memory. */
+ jpeg_destroy_compress(&cinfo);
+
+ /* And we're done! */
+}
+
+
+/*
+ * SOME FINE POINTS:
+ *
+ * In the above loop, we ignored the return value of jpeg_write_scanlines,
+ * which is the number of scanlines actually written. We could get away
+ * with this because we were only relying on the value of cinfo.next_scanline,
+ * which will be incremented correctly. If you maintain additional loop
+ * variables then you should be careful to increment them properly.
+ * Actually, for output to a stdio stream you needn't worry, because
+ * then jpeg_write_scanlines will write all the lines passed (or else exit
+ * with a fatal error). Partial writes can only occur if you use a data
+ * destination module that can demand suspension of the compressor.
+ * (If you don't know what that's for, you don't need it.)
+ *
+ * If the compressor requires full-image buffers (for entropy-coding
+ * optimization or a multi-scan JPEG file), it will create temporary
+ * files for anything that doesn't fit within the maximum-memory setting.
+ * (Note that temp files are NOT needed if you use the default parameters.)
+ * On some systems you may need to set up a signal handler to ensure that
+ * temporary files are deleted if the program is interrupted. See libjpeg.doc.
+ *
+ * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG
+ * files to be compatible with everyone else's. If you cannot readily read
+ * your data in that order, you'll need an intermediate array to hold the
+ * image. See rdtarga.c or rdbmp.c for examples of handling bottom-to-top
+ * source data using the JPEG code's internal virtual-array mechanisms.
+ */
+
+
+
+/******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/
+
+/* This half of the example shows how to read data from the JPEG decompressor.
+ * It's a bit more refined than the above, in that we show:
+ * (a) how to modify the JPEG library's standard error-reporting behavior;
+ * (b) how to allocate workspace using the library's memory manager.
+ *
+ * Just to make this example a little different from the first one, we'll
+ * assume that we do not intend to put the whole image into an in-memory
+ * buffer, but to send it line-by-line someplace else. We need a one-
+ * scanline-high JSAMPLE array as a work buffer, and we will let the JPEG
+ * memory manager allocate it for us. This approach is actually quite useful
+ * because we don't need to remember to deallocate the buffer separately: it
+ * will go away automatically when the JPEG object is cleaned up.
+ */
+
+
+/*
+ * ERROR HANDLING:
+ *
+ * The JPEG library's standard error handler (jerror.c) is divided into
+ * several "methods" which you can override individually. This lets you
+ * adjust the behavior without duplicating a lot of code, which you might
+ * have to update with each future release.
+ *
+ * Our example here shows how to override the "error_exit" method so that
+ * control is returned to the library's caller when a fatal error occurs,
+ * rather than calling exit() as the standard error_exit method does.
+ *
+ * We use C's setjmp/longjmp facility to return control. This means that the
+ * routine which calls the JPEG library must first execute a setjmp() call to
+ * establish the return point. We want the replacement error_exit to do a
+ * longjmp(). But we need to make the setjmp buffer accessible to the
+ * error_exit routine. To do this, we make a private extension of the
+ * standard JPEG error handler object. (If we were using C++, we'd say we
+ * were making a subclass of the regular error handler.)
+ *
+ * Here's the extended error handler struct:
+ */
+
+struct my_error_mgr {
+ struct jpeg_error_mgr pub; /* "public" fields */
+
+ jmp_buf setjmp_buffer; /* for return to caller */
+};
+
+typedef struct my_error_mgr * my_error_ptr;
+
+/*
+ * Here's the routine that will replace the standard error_exit method:
+ */
+
+METHODDEF(void)
+my_error_exit (j_common_ptr cinfo)
+{
+ /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
+ my_error_ptr myerr = (my_error_ptr) cinfo->err;
+
+ /* Always display the message. */
+ /* We could postpone this until after returning, if we chose. */
+ (*cinfo->err->output_message) (cinfo);
+
+ /* Return control to the setjmp point */
+ longjmp(myerr->setjmp_buffer, 1);
+}
+
+
+/*
+ * Sample routine for JPEG decompression. We assume that the source file name
+ * is passed in. We want to return 1 on success, 0 on error.
+ */
+
+
+GLOBAL(int)
+read_JPEG_file (char * filename)
+{
+ /* This struct contains the JPEG decompression parameters and pointers to
+ * working space (which is allocated as needed by the JPEG library).
+ */
+ struct jpeg_decompress_struct cinfo;
+ /* We use our private extension JPEG error handler.
+ * Note that this struct must live as long as the main JPEG parameter
+ * struct, to avoid dangling-pointer problems.
+ */
+ struct my_error_mgr jerr;
+ /* More stuff */
+ FILE * infile; /* source file */
+ JSAMPARRAY buffer; /* Output row buffer */
+ int row_stride; /* physical row width in output buffer */
+
+ /* In this example we want to open the input file before doing anything else,
+ * so that the setjmp() error recovery below can assume the file is open.
+ * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
+ * requires it in order to read binary files.
+ */
+
+ if ((infile = fopen(filename, "rb")) == NULL) {
+ fprintf(stderr, "can't open %s\n", filename);
+ return 0;
+ }
+
+ /* Step 1: allocate and initialize JPEG decompression object */
+
+ /* We set up the normal JPEG error routines, then override error_exit. */
+ cinfo.err = jpeg_std_error(&jerr.pub);
+ jerr.pub.error_exit = my_error_exit;
+ /* Establish the setjmp return context for my_error_exit to use. */
+ if (setjmp(jerr.setjmp_buffer)) {
+ /* If we get here, the JPEG code has signaled an error.
+ * We need to clean up the JPEG object, close the input file, and return.
+ */
+ jpeg_destroy_decompress(&cinfo);
+ fclose(infile);
+ return 0;
+ }
+ /* Now we can initialize the JPEG decompression object. */
+ jpeg_create_decompress(&cinfo);
+
+ /* Step 2: specify data source (eg, a file) */
+
+ jpeg_stdio_src(&cinfo, infile);
+
+ /* Step 3: read file parameters with jpeg_read_header() */
+
+ (void) jpeg_read_header(&cinfo, TRUE);
+ /* We can ignore the return value from jpeg_read_header since
+ * (a) suspension is not possible with the stdio data source, and
+ * (b) we passed TRUE to reject a tables-only JPEG file as an error.
+ * See libjpeg.doc for more info.
+ */
+
+ /* Step 4: set parameters for decompression */
+
+ /* In this example, we don't need to change any of the defaults set by
+ * jpeg_read_header(), so we do nothing here.
+ */
+
+ /* Step 5: Start decompressor */
+
+ (void) jpeg_start_decompress(&cinfo);
+ /* We can ignore the return value since suspension is not possible
+ * with the stdio data source.
+ */
+
+ /* We may need to do some setup of our own at this point before reading
+ * the data. After jpeg_start_decompress() we have the correct scaled
+ * output image dimensions available, as well as the output colormap
+ * if we asked for color quantization.
+ * In this example, we need to make an output work buffer of the right size.
+ */
+ /* JSAMPLEs per row in output buffer */
+ row_stride = cinfo.output_width * cinfo.output_components;
+ /* Make a one-row-high sample array that will go away when done with image */
+ buffer = (*cinfo.mem->alloc_sarray)
+ ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
+
+ /* Step 6: while (scan lines remain to be read) */
+ /* jpeg_read_scanlines(...); */
+
+ /* Here we use the library's state variable cinfo.output_scanline as the
+ * loop counter, so that we don't have to keep track ourselves.
+ */
+ while (cinfo.output_scanline < cinfo.output_height) {
+ /* jpeg_read_scanlines expects an array of pointers to scanlines.
+ * Here the array is only one element long, but you could ask for
+ * more than one scanline at a time if that's more convenient.
+ */
+ (void) jpeg_read_scanlines(&cinfo, buffer, 1);
+ /* Assume put_scanline_someplace wants a pointer and sample count. */
+ put_scanline_someplace(buffer[0], row_stride);
+ }
+
+ /* Step 7: Finish decompression */
+
+ (void) jpeg_finish_decompress(&cinfo);
+ /* We can ignore the return value since suspension is not possible
+ * with the stdio data source.
+ */
+
+ /* Step 8: Release JPEG decompression object */
+
+ /* This is an important step since it will release a good deal of memory. */
+ jpeg_destroy_decompress(&cinfo);
+
+ /* After finish_decompress, we can close the input file.
+ * Here we postpone it until after no more JPEG errors are possible,
+ * so as to simplify the setjmp error logic above. (Actually, I don't
+ * think that jpeg_destroy can do an error exit, but why assume anything...)
+ */
+ fclose(infile);
+
+ /* At this point you may want to check to see whether any corrupt-data
+ * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
+ */
+
+ /* And we're done! */
+ return 1;
+}
+
+
+/*
+ * SOME FINE POINTS:
+ *
+ * In the above code, we ignored the return value of jpeg_read_scanlines,
+ * which is the number of scanlines actually read. We could get away with
+ * this because we asked for only one line at a time and we weren't using
+ * a suspending data source. See libjpeg.doc for more info.
+ *
+ * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress();
+ * we should have done it beforehand to ensure that the space would be
+ * counted against the JPEG max_memory setting. In some systems the above
+ * code would risk an out-of-memory error. However, in general we don't
+ * know the output image dimensions before jpeg_start_decompress(), unless we
+ * call jpeg_calc_output_dimensions(). See libjpeg.doc for more about this.
+ *
+ * Scanlines are returned in the same order as they appear in the JPEG file,
+ * which is standardly top-to-bottom. If you must emit data bottom-to-top,
+ * you can use one of the virtual arrays provided by the JPEG memory manager
+ * to invert the data. See wrbmp.c for an example.
+ *
+ * As with compression, some operating modes may require temporary files.
+ * On some systems you may need to set up a signal handler to ensure that
+ * temporary files are deleted if the program is interrupted. See libjpeg.doc.
+ */
diff --git a/test/monniaux/jpeg-6b/jcapimin.c b/test/monniaux/jpeg-6b/jcapimin.c
index 39cd76ab..038797e0 100644
--- a/test/monniaux/jpeg-6b/jcapimin.c
+++ b/test/monniaux/jpeg-6b/jcapimin.c
@@ -73,7 +73,7 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
cinfo->script_space = NULL;
-#ifndef NO_DOUBLE
+#ifdef HAVE_FLOAT
cinfo->input_gamma = 1.0; /* in case application forgets */
#endif
@@ -222,20 +222,14 @@ jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
(*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
-#ifdef TAIL_CALL_MISSING
- datalen += 1;
- datalen -= 1;
-#endif
+ KILL_TAIL_CALL();
}
GLOBAL(void)
jpeg_write_m_byte (j_compress_ptr cinfo, int val)
{
(*cinfo->marker->write_marker_byte) (cinfo, val);
-#ifdef TAIL_CALL_MISSING
- val += 1;
- val -= 1;
-#endif
+ KILL_TAIL_CALL();
}
@@ -287,7 +281,5 @@ jpeg_write_tables (j_compress_ptr cinfo)
* An app that prefers the old behavior can call jpeg_abort for itself after
* each call to jpeg_write_tables().
*/
-#ifdef TAIL_CALL_MISSING
- int dummy = 1;
-#endif
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/jccoefct.c b/test/monniaux/jpeg-6b/jccoefct.c
index a7e7e6bd..e0cb42a4 100644
--- a/test/monniaux/jpeg-6b/jccoefct.c
+++ b/test/monniaux/jpeg-6b/jccoefct.c
@@ -126,9 +126,7 @@ start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
break;
}
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
@@ -268,13 +266,13 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
block_rows = compptr->v_samp_factor;
else {
/* NB: can't use last_row_height here, since may not be set! */
- block_rows = (int) DIVISION(compptr->height_in_blocks, compptr->v_samp_factor);
+ block_rows = (int) INT_UMOD(compptr->height_in_blocks, compptr->v_samp_factor);
if (block_rows == 0) block_rows = compptr->v_samp_factor;
}
blocks_across = compptr->width_in_blocks;
h_samp_factor = compptr->h_samp_factor;
/* Count number of dummy blocks to be added at the right margin. */
- ndummy = (int) DIVISION(blocks_across, h_samp_factor);
+ ndummy = (int) INT_UMOD(blocks_across, h_samp_factor);
if (ndummy > 0)
ndummy = h_samp_factor - ndummy;
/* Perform DCT for all non-dummy blocks in this iMCU row. Each call
@@ -303,7 +301,7 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
*/
if (coef->iMCU_row_num == last_iMCU_row) {
blocks_across += ndummy; /* include lower right corner */
- MCUs_across = DIVISION(blocks_across, h_samp_factor);
+ MCUs_across = INT_DIV(blocks_across, h_samp_factor);
for (block_row = block_rows; block_row < compptr->v_samp_factor;
block_row++) {
thisblockrow = buffer[block_row];
diff --git a/test/monniaux/jpeg-6b/jccolor.c b/test/monniaux/jpeg-6b/jccolor.c
index b3e6055b..edc9f831 100644
--- a/test/monniaux/jpeg-6b/jccolor.c
+++ b/test/monniaux/jpeg-6b/jccolor.c
@@ -456,7 +456,5 @@ jinit_color_converter (j_compress_ptr cinfo)
cconvert->pub.color_convert = null_convert;
break;
}
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/jcdctmgr.c b/test/monniaux/jpeg-6b/jcdctmgr.c
index 658a674e..b85b0832 100644
--- a/test/monniaux/jpeg-6b/jcdctmgr.c
+++ b/test/monniaux/jpeg-6b/jcdctmgr.c
@@ -243,14 +243,10 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
* for a < b to discover whether a/b is 0.
* If your machine's division is fast enough, define FAST_DIVIDE.
*/
-#ifdef NO_32BIT_DIVISION
-#define DIVIDE_BY(a,b) a = (long long) a / b
-#else
#ifdef FAST_DIVIDE
-#define DIVIDE_BY(a,b) a /= b
+#define DIVIDE_BY(a,b) a = INT_DIV(a, b)
#else
-#define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
-#endif
+#define DIVIDE_BY(a,b) if (a >= b) a = INT_DIV(a, b); else a = 0
#endif
if (temp < 0) {
temp = -temp;
diff --git a/test/monniaux/jpeg-6b/jchuff.c b/test/monniaux/jpeg-6b/jchuff.c
index 4a2d0da2..f2352505 100644
--- a/test/monniaux/jpeg-6b/jchuff.c
+++ b/test/monniaux/jpeg-6b/jchuff.c
@@ -95,6 +95,7 @@ METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
#endif
+
/*
* Initialize for a Huffman-compressed scan.
* If gather_statistics is TRUE, we do not output anything during the scan,
@@ -262,6 +263,7 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
}
}
+
/* Outputting bytes to the file */
/* Emit a byte, taking 'action' if must suspend. */
@@ -440,6 +442,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
return TRUE;
}
+
/*
* Emit a restart marker & resynchronize predictions.
*/
@@ -548,6 +551,7 @@ finish_pass_huff (j_compress_ptr cinfo)
ASSIGN_STATE(entropy->saved, state.cur);
}
+
/*
* Huffman coding optimization.
*
@@ -561,6 +565,7 @@ finish_pass_huff (j_compress_ptr cinfo)
#ifdef ENTROPY_OPT_SUPPORTED
+
/* Process a single block's worth of coefficients */
LOCAL(void)
@@ -630,12 +635,12 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
ac_counts[0]++;
}
+
/*
* Trial-encode one MCU's worth of Huffman-compressed coefficients.
* No data is actually output, so no suspension return is possible.
*/
-
METHODDEF(boolean)
encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{
@@ -892,7 +897,8 @@ jinit_huff_encoder (j_compress_ptr cinfo)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(huff_entropy_encoder));
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
- ASSIGN_FUNPTR(entropy->pub.start_pass, start_pass_huff);
+ entropy->pub.start_pass = start_pass_huff;
+
/* Mark tables unallocated */
for (i = 0; i < NUM_HUFF_TBLS; i++) {
entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
diff --git a/test/monniaux/jpeg-6b/jcinit.c b/test/monniaux/jpeg-6b/jcinit.c
index adbccb3f..578fbe81 100644
--- a/test/monniaux/jpeg-6b/jcinit.c
+++ b/test/monniaux/jpeg-6b/jcinit.c
@@ -69,7 +69,5 @@ jinit_compress_master (j_compress_ptr cinfo)
* This lets application insert special markers after the SOI.
*/
(*cinfo->marker->write_file_header) (cinfo);
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/jcmainct.c b/test/monniaux/jpeg-6b/jcmainct.c
index 9f822dd7..6ae91018 100644
--- a/test/monniaux/jpeg-6b/jcmainct.c
+++ b/test/monniaux/jpeg-6b/jcmainct.c
@@ -100,9 +100,7 @@ start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
break;
}
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
@@ -293,7 +291,5 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
}
}
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/jcmarker.c b/test/monniaux/jpeg-6b/jcmarker.c
index 91293ec7..ed98ef9f 100644
--- a/test/monniaux/jpeg-6b/jcmarker.c
+++ b/test/monniaux/jpeg-6b/jcmarker.c
@@ -115,9 +115,7 @@ emit_byte (j_compress_ptr cinfo, int val)
if (! (*dest->empty_output_buffer) (cinfo))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
}
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/jcmaster.c b/test/monniaux/jpeg-6b/jcmaster.c
index 27a28054..fd136535 100644
--- a/test/monniaux/jpeg-6b/jcmaster.c
+++ b/test/monniaux/jpeg-6b/jcmaster.c
@@ -330,7 +330,7 @@ per_scan_setup (j_compress_ptr cinfo)
/* For noninterleaved scans, it is convenient to define last_row_height
* as the number of block rows present in the last iMCU row.
*/
- tmp = (int) (MODULO(compptr->height_in_blocks,compptr->v_samp_factor));
+ tmp = (int) INT_UMOD(compptr->height_in_blocks, compptr->v_samp_factor);
if (tmp == 0) tmp = compptr->v_samp_factor;
compptr->last_row_height = tmp;
@@ -363,10 +363,10 @@ per_scan_setup (j_compress_ptr cinfo)
compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
/* Figure number of non-dummy blocks in last MCU column & row */
- tmp = (int) (MODULO(compptr->width_in_blocks, compptr->MCU_width));
+ tmp = (int) INT_UMOD(compptr->width_in_blocks, compptr->MCU_width);
if (tmp == 0) tmp = compptr->MCU_width;
compptr->last_col_width = tmp;
- tmp = (int) MODULO(compptr->height_in_blocks, compptr->MCU_height);
+ tmp = (int) INT_UMOD(compptr->height_in_blocks, compptr->MCU_height);
if (tmp == 0) tmp = compptr->MCU_height;
compptr->last_row_height = tmp;
/* Prepare array describing MCU composition */
@@ -492,9 +492,7 @@ pass_startup (j_compress_ptr cinfo)
(*cinfo->marker->write_frame_header) (cinfo);
(*cinfo->marker->write_scan_header) (cinfo);
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/jconfig.h b/test/monniaux/jpeg-6b/jconfig.h
index 1b30a525..b2f0b94f 100644
--- a/test/monniaux/jpeg-6b/jconfig.h
+++ b/test/monniaux/jpeg-6b/jconfig.h
@@ -1,45 +1,179 @@
-/* jconfig.h. Generated automatically by configure. */
-/* jconfig.cfg --- source file edited by configure script */
-/* see jconfig.doc for explanations */
-
-#define HAVE_PROTOTYPES
-#define HAVE_UNSIGNED_CHAR
-#define HAVE_UNSIGNED_SHORT
-/* wtf #define void char */
-#undef const
+/*
+ * jconfig.doc
+ *
+ * Copyright (C) 1991-1994, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file documents the configuration options that are required to
+ * customize the JPEG software for a particular system.
+ *
+ * The actual configuration options for a particular installation are stored
+ * in jconfig.h. On many machines, jconfig.h can be generated automatically
+ * or copied from one of the "canned" jconfig files that we supply. But if
+ * you need to generate a jconfig.h file by hand, this file tells you how.
+ *
+ * DO NOT EDIT THIS FILE --- IT WON'T ACCOMPLISH ANYTHING.
+ * EDIT A COPY NAMED JCONFIG.H.
+ */
+
+
+/*
+ * These symbols indicate the properties of your machine or compiler.
+ * #define the symbol if yes, #undef it if no.
+ */
+
+/* Does your compiler support function prototypes?
+ * (If not, you also need to use ansi2knr, see install.doc)
+ */
+#define HAVE_PROTOTYPES
+
+#define NO_SWITCH
+
+#ifdef __COMPCERT__
+extern long long __compcert_i64_sdiv(long long a, long long b);
+extern long long __compcert_i64_smod(long long a, long long b);
+
+#define INT_UMOD(a, b) __compcert_i64_smod(a, b)
+#define INT_MOD(a, b) __compcert_i64_smod(a, b)
+#define INT_UDIV(a, b) __compcert_i64_sdiv(a, b)
+#define INT_DIV(a, b) __compcert_i64_sdiv(a, b)
+#define LONG_DIV(a, b) __compcert_i64_sdiv(a, b)
+
+#define KILL_TAIL_CALL() { int x=1; }
+
+#else
+#define INT_UMOD(a, b) ((a) % (b))
+#define INT_MOD(a, b) ((a) % (b))
+#define INT_UDIV(a, b) ((a) / (b))
+#define INT_DIV(a, b) ((a) / (b))
+#define LONG_DIV(a, b) ((a) / (b))
+
+#define KILL_TAIL_CALL() { }
+#endif
+
+/* Does your compiler support the declaration "unsigned char" ?
+ * How about "unsigned short" ?
+ */
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_UNSIGNED_SHORT
+
+/* Define "void" as "char" if your compiler doesn't know about type void.
+ * NOTE: be sure to define void such that "void *" represents the most general
+ * pointer type, e.g., that returned by malloc().
+ */
+/* #define void char */
+
+/* Define "const" as empty if your compiler doesn't know the "const" keyword.
+ */
+/* #define const */
+
+/* Define this if an ordinary "char" type is unsigned.
+ * If you're not sure, leaving it undefined will work at some cost in speed.
+ * If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal.
+ */
#undef CHAR_IS_UNSIGNED
-#define HAVE_STDDEF_H
-#define HAVE_STDLIB_H
+
+/* Define this if your system has an ANSI-conforming <stddef.h> file.
+ */
+#define HAVE_STDDEF_H
+
+/* Define this if your system has an ANSI-conforming <stdlib.h> file.
+ */
+#define HAVE_STDLIB_H
+
+/* Define this if your system does not have an ANSI/SysV <string.h>,
+ * but does have a BSD-style <strings.h>.
+ */
#undef NEED_BSD_STRINGS
+
+/* Define this if your system does not provide typedef size_t in any of the
+ * ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in
+ * <sys/types.h> instead.
+ */
#undef NEED_SYS_TYPES_H
+
+/* For 80x86 machines, you need to define NEED_FAR_POINTERS,
+ * unless you are using a large-data memory model or 80386 flat-memory mode.
+ * On less brain-damaged CPUs this symbol must not be defined.
+ * (Defining this symbol causes large data structures to be referenced through
+ * "far" pointers and to be allocated with a special version of malloc.)
+ */
#undef NEED_FAR_POINTERS
+
+/* Define this if your linker needs global names to be unique in less
+ * than the first 15 characters.
+ */
#undef NEED_SHORT_EXTERNAL_NAMES
-/* Define this if you get warnings about undefined structures. */
+
+/* Although a real ANSI C compiler can deal perfectly well with pointers to
+ * unspecified structures (see "incomplete types" in the spec), a few pre-ANSI
+ * and pseudo-ANSI compilers get confused. To keep one of these bozos happy,
+ * define INCOMPLETE_TYPES_BROKEN. This is not recommended unless you
+ * actually get "missing structure definition" warnings or errors while
+ * compiling the JPEG code.
+ */
#undef INCOMPLETE_TYPES_BROKEN
+
+/*
+ * The following options affect code selection within the JPEG library,
+ * but they don't need to be visible to applications using the library.
+ * To minimize application namespace pollution, the symbols won't be
+ * defined unless JPEG_INTERNALS has been defined.
+ */
+
#ifdef JPEG_INTERNALS
+/* Define this if your compiler implements ">>" on signed values as a logical
+ * (unsigned) shift; leave it undefined if ">>" is a signed (arithmetic) shift,
+ * which is the normal and rational definition.
+ */
#undef RIGHT_SHIFT_IS_UNSIGNED
-#define INLINE __inline__
-/* These are for configuring the JPEG memory manager. */
-#undef DEFAULT_MAX_MEM
-#undef NO_MKTEMP
+
#endif /* JPEG_INTERNALS */
+
+/*
+ * The remaining options do not affect the JPEG library proper,
+ * but only the sample applications cjpeg/djpeg (see cjpeg.c, djpeg.c).
+ * Other applications can ignore these.
+ */
+
#ifdef JPEG_CJPEG_DJPEG
-#undef BMP_SUPPORTED /* BMP image file format */
-#undef GIF_SUPPORTED /* GIF image file format */
+/* These defines indicate which image (non-JPEG) file formats are allowed. */
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
#undef RLE_SUPPORTED /* Utah RLE image file format */
-#undef TARGA_SUPPORTED /* Targa image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+/* Define this if you want to name both input and output files on the command
+ * line, rather than using stdout and optionally stdin. You MUST do this if
+ * your system can't cope with binary I/O to stdin/stdout. See comments at
+ * head of cjpeg.c or djpeg.c.
+ */
#undef TWO_FILE_COMMANDLINE
+
+/* Define this if your system needs explicit cleanup of temporary files.
+ * This is crucial under MS-DOS, where the temporary "files" may be areas
+ * of extended memory; on most other systems it's not as important.
+ */
#undef NEED_SIGNAL_CATCHER
+
+/* By default, we open image files with fopen(...,"rb") or fopen(...,"wb").
+ * This is necessary on systems that distinguish text files from binary files,
+ * and is harmless on most systems that don't. If you have one of the rare
+ * systems that complains about the "b" spec, define this symbol.
+ */
#undef DONT_USE_B_MODE
-/* Define this if you want percent-done progress reports from cjpeg/djpeg. */
+/* Define this if you want percent-done progress reports from cjpeg/djpeg.
+ */
#undef PROGRESS_REPORT
+
#endif /* JPEG_CJPEG_DJPEG */
diff --git a/test/monniaux/jpeg-6b/jcparam.c b/test/monniaux/jpeg-6b/jcparam.c
index b6206fd1..f6c90f47 100644
--- a/test/monniaux/jpeg-6b/jcparam.c
+++ b/test/monniaux/jpeg-6b/jcparam.c
@@ -46,7 +46,7 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
*qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
for (i = 0; i < DCTSIZE2; i++) {
- temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
+ temp = LONG_DIV((basic_table[i] * scale_factor + 50L), 100L);
/* limit the values to the valid range */
if (temp <= 0L) temp = 1L;
if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
@@ -120,7 +120,7 @@ jpeg_quality_scaling (int quality)
* Qualities 1..50 are converted to scaling percentage 5000/Q.
*/
if (quality < 50)
- quality = DIVISION(5000, quality);
+ quality = INT_DIV(5000, quality);
else
quality = 200 - quality*2;
@@ -380,9 +380,7 @@ jpeg_default_colorspace (j_compress_ptr cinfo)
default:
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
}
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
@@ -469,9 +467,7 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
default:
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
}
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/jcprepct.c b/test/monniaux/jpeg-6b/jcprepct.c
index 85892e21..fa93333d 100644
--- a/test/monniaux/jpeg-6b/jcprepct.c
+++ b/test/monniaux/jpeg-6b/jcprepct.c
@@ -288,8 +288,8 @@ create_context_buffer (j_compress_ptr cinfo)
*/
true_buffer = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE,
- (JDIMENSION) DIVISION(((long) compptr->width_in_blocks * DCTSIZE *
- cinfo->max_h_samp_factor), compptr->h_samp_factor),
+ (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
+ cinfo->max_h_samp_factor) / compptr->h_samp_factor),
(JDIMENSION) (3 * rgroup_height));
/* Copy true buffer row pointers into the middle of the fake row array */
MEMCOPY(fake_buffer + rgroup_height, true_buffer,
@@ -346,8 +346,8 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
ci++, compptr++) {
prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE,
- (JDIMENSION) DIVISION(((long) compptr->width_in_blocks * DCTSIZE *
- cinfo->max_h_samp_factor), compptr->h_samp_factor),
+ (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
+ cinfo->max_h_samp_factor) / compptr->h_samp_factor),
(JDIMENSION) cinfo->max_v_samp_factor);
}
}
diff --git a/test/monniaux/jpeg-6b/jcprepct.i b/test/monniaux/jpeg-6b/jcprepct.i
deleted file mode 100644
index c0b55a87..00000000
--- a/test/monniaux/jpeg-6b/jcprepct.i
+++ /dev/null
@@ -1,3092 +0,0 @@
-# 1 "jcprepct.c"
-# 1 "<built-in>"
-# 1 "<command-line>"
-# 1 "jcprepct.c"
-# 18 "jcprepct.c"
-# 1 "jinclude.h" 1
-# 20 "jinclude.h"
-# 1 "jconfig.h" 1
-# 21 "jinclude.h" 2
-# 35 "jinclude.h"
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 1 3 4
-# 147 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 3 4
-typedef long int ptrdiff_t;
-# 212 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 3 4
-typedef unsigned long long size_t;
-# 324 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 3 4
-typedef int wchar_t;
-# 36 "jinclude.h" 2
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 1 3
-# 10 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/ieeefp.h" 1 3
-# 11 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/_ansi.h" 1 3
-# 15 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/_ansi.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/newlib.h" 1 3
-# 16 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/_ansi.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/config.h" 1 3
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/ieeefp.h" 1 3
-# 5 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/config.h" 2 3
-# 17 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/_ansi.h" 2 3
-# 12 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 2 3
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 1 3 4
-# 16 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 2 3
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 1 3
-# 13 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/_ansi.h" 1 3
-# 14 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/_types.h" 1 3
-# 12 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/_types.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_types.h" 1 3
-
-
-
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 1 3
-# 22 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include-fixed/limits.h" 1 3 4
-# 23 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 2 3
-
-
-
-typedef signed char __int8_t ;
-typedef unsigned char __uint8_t ;
-# 36 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 3
-typedef signed short __int16_t;
-typedef unsigned short __uint16_t;
-# 46 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 3
-typedef __int16_t __int_least16_t;
-typedef __uint16_t __uint_least16_t;
-# 62 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 3
-typedef signed int __int32_t;
-typedef unsigned int __uint32_t;
-# 76 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 3
-typedef __int32_t __int_least32_t;
-typedef __uint32_t __uint_least32_t;
-# 93 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_default_types.h" 3
-typedef signed long __int64_t;
-typedef unsigned long __uint64_t;
-# 8 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/_types.h" 2 3
-# 13 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/_types.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/lock.h" 1 3
-# 9 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/lock.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 1 3
-# 12 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 1 3
-# 13 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/registers.h" 1 3
-# 14 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/types.h" 1 3
-# 16 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/types.h" 3
-typedef unsigned char __k1_uchar;
-
-
-typedef unsigned short __k1_ushort;
-
-
-typedef unsigned int __k1_uint;
-
-
-typedef unsigned long __k1_ulong;
-
-
-typedef signed long __k1_long;
-
-
-
-typedef unsigned char __k1_uint8_t;
-
-
-typedef signed char __k1_int8_t;
-
-
-typedef unsigned short __k1_uint16_t;
-
-
-typedef signed short __k1_int16_t;
-
-
-typedef unsigned int __k1_uint32_t;
-
-
-typedef signed int __k1_int32_t;
-
-
-typedef unsigned long long __k1_uint64_t;
-
-
-typedef signed long long __k1_int64_t;
-# 63 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/types.h" 3
-typedef long __k1_intptr_t;
-
-
-typedef unsigned long __k1_uintptr_t;
-# 15 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/assert.h" 1 3
-# 11 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/assert.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/common.h" 1 3
-# 12 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/assert.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/scall_no.h" 1 3
-# 13 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/assert.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 1 3
-# 9 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 1 3
-# 41 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef signed char int8_t ;
-typedef unsigned char uint8_t ;
-
-
-
-
-typedef signed char int_least8_t;
-typedef unsigned char uint_least8_t;
-# 57 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef signed short int16_t;
-typedef unsigned short uint16_t;
-# 67 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef int16_t int_least16_t;
-typedef uint16_t uint_least16_t;
-# 83 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef signed int int32_t;
-typedef unsigned int uint32_t;
-# 97 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef int32_t int_least32_t;
-typedef uint32_t uint_least32_t;
-# 115 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef signed long int64_t;
-typedef unsigned long uint64_t;
-# 129 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
-typedef int64_t int_least64_t;
-typedef uint64_t uint_least64_t;
-# 159 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
- typedef signed int int_fast8_t;
- typedef unsigned int uint_fast8_t;
-
-
-
-
- typedef signed int int_fast16_t;
- typedef unsigned int uint_fast16_t;
-
-
-
-
- typedef signed int int_fast32_t;
- typedef unsigned int uint_fast32_t;
-# 213 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
- typedef int_least64_t int_fast64_t;
- typedef uint_least64_t uint_fast64_t;
-
-
-
-
-
-
-
- typedef long int intmax_t;
-# 231 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
- typedef long unsigned int uintmax_t;
-# 244 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdint.h" 3
- typedef int64_t intptr_t;
- typedef uint64_t uintptr_t;
-# 10 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 2 3
-# 21 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall(const uint32_t syscall);
-# 38 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall_with_args(const uint64_t syscall, uint64_t sc_arg0, uint64_t sc_arg1,
- uint64_t sc_arg2, uint64_t sc_arg3, uint64_t sc_arg4,
- uint64_t sc_arg5);
-# 52 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall0(const uint32_t syscall);
-# 61 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall1(const uint32_t syscall, uint64_t sc_arg0);
-# 72 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall2(const uint32_t syscall, uint64_t sc_arg0,
- uint64_t sc_arg1);
-# 85 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall3(const uint32_t syscall, uint64_t sc_arg0, uint64_t sc_arg1,
- uint64_t sc_arg2);
-# 100 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall4(const uint32_t syscall, uint64_t sc_arg0, uint64_t sc_arg1,
- uint64_t sc_arg2, uint64_t sc_arg3);
-# 116 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int
-__k1_syscall5(const uint32_t syscall, uint64_t sc_arg0, uint64_t sc_arg1,
- uint64_t sc_arg2, uint64_t sc_arg3, uint64_t sc_arg4);
-# 135 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/syscall.h" 3
-extern int __k1_syscall6(const uint32_t syscall, uint64_t sc_arg0, uint64_t sc_arg1,
- uint64_t sc_arg2, uint64_t sc_arg3, uint64_t sc_arg4,
- uint64_t sc_arg5);
-# 14 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/assert.h" 2 3
-# 16 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 2 3
-
-
-
-
-
-
-
-extern unsigned long __bsp_rtl_simu __attribute__ ((weak));
-# 32 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 3
-extern unsigned long __bsp_core_only __attribute__ ((weak));
-
-
-
-
-
-
-extern char __k1_streaming_enable(char);
-
-
-
-
-
-extern char __k1_streaming_disable(char);
-
-
-
-
-
- extern unsigned int __bsp_frequency;
-# 80 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cpu.h" 3
-extern int __k1_is_rm(char) __attribute__((__const__));
-
-
-
-
-
-
-extern int __k1_get_cpu_id(char) __attribute__((__const__));
-
-
-
-
-
-
-extern int __k1_get_rm_id(char);
-
-
-
-
-
-
-
-extern __k1_uint32_t __k1_sysreg_get_num(unsigned int n);
-
-
-
-
-
-
-
-extern char __k1_sysreg_set_num(unsigned int n, __k1_uint32_t i);
-
-
-
-
-
-
-extern unsigned int __k1_hw_loop_enabled(char);
-
-
-
-
-
-extern char __k1_hwloops_enable(char);
-
-
-
-
-
-extern char __k1_hwloops_disable(char);
-
-
-
-
-
-enum __k1_fpu_rounding_mode {
- _K1_FPU_NEAREST_EVEN = 0,
- _K1_FPU_TOWARDS_PLUS_INF = 1,
- _K1_FPU_TOWARDS_MINUS_INF = 2,
- _K1_FPU_TOWARDS_ZERO = 3
-};
-
-
-
-
-
-extern char __k1_fpu_set_rounding_mode(enum __k1_fpu_rounding_mode mode);
-
-
-
-
-
-extern enum __k1_fpu_rounding_mode __k1_fpu_get_rounding_mode(char);
-
-
-
-
-
-enum __k1_fpu_exceptions {
- _K1_FPU_INVALID_OPERATION = 0x2LL,
- _K1_FPU_DIVIDE_BY_ZERO = 0x4LL,
- _K1_FPU_OVERFLOW = 0x8LL,
- _K1_FPU_UNDERFLOW = 0x10LL,
- _K1_FPU_INEXACT = 0x20LL,
- _K1_FPU_ALL_EXCEPTS = 0x2LL | 0x4LL | 0x8LL | 0x10LL | 0x20LL
-};
-
-
-
-
-
-extern char __k1_fpu_raise_exceptions(int excepts);
-
-
-
-
-
-extern char __k1_fpu_clear_exceptions(int excepts);
-
-
-
-
-
-extern unsigned int __k1_fpu_get_exceptions(char);
-# 13 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 1 3
-# 47 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern unsigned int __k1_icache_enabled(char);
-
-
-
-
-
-extern char __k1_icache_enable(char);
-
-
-
-
-
-extern char __k1_icache_disable(char);
-# 70 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern char __k1_icache_invalidate_mem_area(uintptr_t addr, int size);
-# 81 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern unsigned int __k1_dcache_enabled(char);
-
-
-
-
-
-extern char __k1_dcache_enable(char);
-
-
-
-
-
-extern char __k1_dcache_disable(char);
-# 104 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern char __k1_dcache_invalidate_mem_area(uintptr_t addr, int size);
-
-
-
-
-
-extern char __k1_l1_coherency_enable(char);
-
-
-
-
-
-extern char __k1_l1_coherency_disable(char);
-
-
-
-
-
-extern char __k1_l2cache_enable(char);
-
-
-
-
-
-extern char __k1_l2cache_disable(char);
-
-
-
-
-
-
-extern char __k1_mb(char);
-
-
-
-
-
-
-extern char __k1_wmb(char);
-
-
-
-
-
-
-char __k1_rmb(char);
-# 14 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/io.h" 1 3
-# 28 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/io.h" 3
-extern uint8_t __k1_io_read8(char *addr);
-
-
-
-
-
-
-
-extern uint16_t __k1_io_read16(char *addr);
-
-
-
-
-
-
-
-extern uint32_t __k1_io_read32(char *addr);
-
-
-
-
-
-
-
-extern uint64_t __k1_io_read64(char *addr);
-# 64 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/io.h" 3
-extern char __k1_io_write8(char *addr, uint8_t val);
-
-
-
-
-
-
-
-extern char __k1_io_write16(char *addr, uint16_t val);
-
-
-
-
-
-
-
-extern char __k1_io_write32(char *addr, uint32_t val);
-
-
-
-
-
-
-
-extern char __k1_io_write64(char *addr, uint64_t val);
-# 104 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/io.h" 3
-extern uint32_t __k1_umem_read32(char *addr __attribute__((unused)));
-
-
-
-
-
-
-
-extern uint64_t __k1_umem_read64(char *addr);
-
-
-
-
-
-
-
-extern uint8_t __k1_umem_read8(char *addr __attribute__((unused)));
-
-
-
-
-
-
-
-extern uint16_t __k1_umem_read16(char *addr);
-# 140 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/io.h" 3
-extern char __k1_umem_write32(char *addr, uint32_t val);
-
-
-
-
-
-
-
-extern char __k1_umem_write64(char *addr, uint64_t val);
-
-
-
-
-
-
-
-extern char __k1_umem_write8(char *addr, uint8_t val);
-
-
-
-
-
-
-
-extern char __k1_umem_write16(char *addr, uint16_t val);
-# 15 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 2 3
-# 33 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-extern uint32_t __k1_atomic_swap32(char *addr, uint32_t new_value);
-
-
-
-
-
-
-
-extern uint64_t __k1_atomic_swap64(char *addr, uint64_t new_value);
-
-
-
-
-
-
-
-extern int32_t __k1_atomic_add32(char *addr, int32_t value);
-
-
-
-
-
-
-
-extern int __k1_compare_and_swap32(char *ptr, uint32_t old_value,
- uint32_t new_value);
-# 73 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-typedef struct __k1_recursive_lock __k1_recursive_lock_t;
-
-struct __k1_recursive_lock {
- uint32_t owner;
- uint32_t counter;
-};
-# 94 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-extern char __k1_recursive_initlock_base(__k1_recursive_lock_t *lock);
-# 107 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-extern int __k1_recursive_trylock_base(__k1_recursive_lock_t *lock,
- uint32_t myself);
-# 117 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-extern char __k1_recursive_lock_base(__k1_recursive_lock_t *lock,
- uint64_t myself);
-# 129 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-extern int __k1_recursive_unlock_base(__k1_recursive_lock_t *lock,
- uint64_t myself);
-# 141 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/atomic.h" 3
-extern int __k1_recursive_release_base(__k1_recursive_lock_t *lock,
- uint64_t myself);
-# 10 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/lock.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 1 3
-# 47 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern unsigned int __k1_icache_enabled(char);
-
-
-
-
-
-extern char __k1_icache_enable(char);
-
-
-
-
-
-extern char __k1_icache_disable(char);
-# 70 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern char __k1_icache_invalidate_mem_area(uintptr_t addr, int size);
-# 81 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern unsigned int __k1_dcache_enabled(char);
-
-
-
-
-
-extern char __k1_dcache_enable(char);
-
-
-
-
-
-extern char __k1_dcache_disable(char);
-# 104 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/mppa_bare_runtime/k1c/cache.h" 3
-extern char __k1_dcache_invalidate_mem_area(uintptr_t addr, int size);
-
-
-
-
-
-extern char __k1_l1_coherency_enable(char);
-
-
-
-
-
-extern char __k1_l1_coherency_disable(char);
-
-
-
-
-
-extern char __k1_l2cache_enable(char);
-
-
-
-
-
-extern char __k1_l2cache_disable(char);
-
-
-
-
-
-
-extern char __k1_mb(char);
-
-
-
-
-
-
-extern char __k1_wmb(char);
-
-
-
-
-
-
-char __k1_rmb(char);
-# 11 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/lock.h" 2 3
-
-
-
-
-typedef struct __libc_lock_recursive_s
-{
- __k1_recursive_lock_t lock;
-} __libc_lock_recursive_t __attribute__ ((aligned (((64*8)/8))));
-
-typedef struct __libc_lock_recursive_s __libc_lock_t;
-
-
-
-
-
-
-int __libc_lock_init_recursive(__libc_lock_recursive_t *lock);
-int __libc_lock_close_recursive(__libc_lock_recursive_t *lock);
-int __libc_lock_acquire_recursive(__libc_lock_recursive_t *lock);
-int __libc_lock_try_acquire_recursive(__libc_lock_recursive_t *lock);
-int __libc_lock_release_recursive(__libc_lock_recursive_t *lock);
-# 42 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/lock.h" 3
-typedef __libc_lock_t _LOCK_T __attribute__ ((aligned (((64*8)/8))));
-typedef __libc_lock_recursive_t _LOCK_RECURSIVE_T __attribute__ ((aligned (((64*8)/8))));
-# 14 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/_types.h" 2 3
-
-
-typedef long _off_t;
-
-
-
-
-
-
-
-typedef short __dev_t;
-
-
-
-
-typedef unsigned short __uid_t;
-
-
-typedef unsigned short __gid_t;
-
-
-
-__extension__ typedef long long _off64_t;
-
-
-
-
-
-
-
-typedef long _fpos_t;
-# 56 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/_types.h" 3
-typedef int _ssize_t;
-
-
-
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 1 3 4
-# 353 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 3 4
-typedef unsigned int wint_t;
-# 64 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/_types.h" 2 3
-
-
-
-typedef struct
-{
- int __count;
- union
- {
- wint_t __wch;
- unsigned char __wchb[4];
- } __value;
-} _mbstate_t;
-
-
-
-typedef _LOCK_RECURSIVE_T _flock_t;
-
-
-
-
-typedef char *_iconv_t;
-# 15 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 2 3
-# 24 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-typedef unsigned int __ULong;
-# 37 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-struct _reent;
-
-
-
-
-
-
-struct _Bigint
-{
- struct _Bigint *_next;
- int _k, _maxwds, _sign, _wds;
- __ULong _x[1];
-};
-
-
-struct __tm
-{
- int __tm_sec;
- int __tm_min;
- int __tm_hour;
- int __tm_mday;
- int __tm_mon;
- int __tm_year;
- int __tm_wday;
- int __tm_yday;
- int __tm_isdst;
-};
-
-
-
-
-
-
-
-struct _on_exit_args {
- char * _fnargs[32];
- char * _dso_handle[32];
-
- __ULong _fntypes;
-
-
- __ULong _is_cxa;
-};
-# 89 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-struct _atexit {
- struct _atexit *_next;
- int _ind;
-
- char (*_fns[32])(char);
- struct _on_exit_args _on_exit_args;
-};
-# 105 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-struct __sbuf {
- unsigned char *_base;
- int _size;
-};
-# 169 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-struct __sFILE {
- unsigned char *_p;
- int _r;
- int _w;
- short _flags;
- short _file;
- struct __sbuf _bf;
- int _lbfsize;
-
-
-
-
-
-
- char * _cookie;
-
- int (* _read) (struct _reent *, char *, char *, int)
- ;
- int (* _write) (struct _reent *, char *, const char *, int)
- ;
- _fpos_t (* _seek) (struct _reent *, char *, _fpos_t, int);
- int (* _close) (struct _reent *, char *);
-
-
- struct __sbuf _ub;
- unsigned char *_up;
- int _ur;
-
-
- unsigned char _ubuf[3];
- unsigned char _nbuf[1];
-
-
- struct __sbuf _lb;
-
-
- int _blksize;
- int _offset;
-
-
- struct _reent *_data;
-
-
-
- _flock_t _lock;
-
- _mbstate_t _mbstate;
- int _flags2;
-};
-# 273 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-typedef struct __sFILE __FILE;
-
-
-
-struct _glue
-{
- struct _glue *_next;
- int _niobs;
- __FILE *_iobs;
-};
-# 305 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-struct _rand48 {
- unsigned short _seed[3];
- unsigned short _mult[3];
- unsigned short _add;
-
-
-
-
-};
-# 579 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-struct _reent
-{
- int _errno;
-
-
-
-
- __FILE *_stdin, *_stdout, *_stderr;
-
- int _inc;
- char _emergency[25];
-
- int _current_category;
- const char *_current_locale;
-
- int __sdidinit;
-
- char (* __cleanup) (struct _reent *);
-
-
- struct _Bigint *_result;
- int _result_k;
- struct _Bigint *_p5s;
- struct _Bigint **_freelist;
-
-
- int _cvtlen;
- char *_cvtbuf;
-
- union
- {
- struct
- {
- unsigned int _unused_rand;
- char * _strtok_last;
- char _asctime_buf[26];
- struct __tm _localtime_buf;
- int _gamma_signgam;
- __extension__ unsigned long long _rand_next;
- struct _rand48 _r48;
- _mbstate_t _mblen_state;
- _mbstate_t _mbtowc_state;
- _mbstate_t _wctomb_state;
- char _l64a_buf[8];
- char _signal_buf[24];
- int _getdate_err;
- _mbstate_t _mbrlen_state;
- _mbstate_t _mbrtowc_state;
- _mbstate_t _mbsrtowcs_state;
- _mbstate_t _wcrtomb_state;
- _mbstate_t _wcsrtombs_state;
- int _h_errno;
- } _reent;
-
-
-
- struct
- {
-
- unsigned char * _nextf[30];
- unsigned int _nmalloc[30];
- } _unused;
- } _new;
-
-
- struct _atexit *_atexit;
- struct _atexit _atexit0;
-
-
- char (**(_sig_func))(int);
-
-
-
-
- struct _glue __sglue;
- __FILE __sf[3];
-};
-# 817 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/reent.h" 3
-extern struct _reent *_impure_ptr ;
-extern struct _reent *const _global_impure_ptr ;
-
-char _reclaim_reent (struct _reent *);
-# 18 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/stdlib.h" 1 3
-# 19 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 2 3
-# 27 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 3
-
-
-typedef struct
-{
- int quot;
- int rem;
-} div_t;
-
-typedef struct
-{
- long quot;
- long rem;
-} ldiv_t;
-# 58 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 3
-extern int __mb_cur_max;
-
-
-
-char abort (char) ;
-int abs (int);
-int atexit (char (*__func)(char));
-double atof (const char *__nptr);
-
-
-
-int atoi (const char *__nptr);
-int _atoi_r (struct _reent *, const char *__nptr);
-long atol (const char *__nptr);
-long _atol_r (struct _reent *, const char *__nptr);
-char * bsearch (const char * __key, const char * __base, size_t __nmemb, size_t __size, int (* _compar) (const char *, const char *))
-
-
-
- ;
-char * calloc (size_t __nmemb, size_t __size) ;
-div_t div (int __numer, int __denom);
-char exit (int __status) ;
-char free (char *) ;
-char * getenv (const char *__string);
-char * _getenv_r (struct _reent *, const char *__string);
-char * _findenv (const char *, int *);
-char * _findenv_r (struct _reent *, const char *, int *);
-long labs (long);
-ldiv_t ldiv (long __numer, long __denom);
-char * malloc (size_t __size) ;
-int mblen (const char *, size_t);
-int _mblen_r (struct _reent *, const char *, size_t, _mbstate_t *);
-int mbtowc (wchar_t *, const char *, size_t);
-int _mbtowc_r (struct _reent *, wchar_t *, const char *, size_t, _mbstate_t *);
-int wctomb (char *, wchar_t);
-int _wctomb_r (struct _reent *, char *, wchar_t, _mbstate_t *);
-size_t mbstowcs (wchar_t *, const char *, size_t);
-size_t _mbstowcs_r (struct _reent *, wchar_t *, const char *, size_t, _mbstate_t *);
-size_t wcstombs (char *, const wchar_t *, size_t);
-size_t _wcstombs_r (struct _reent *, char *, const wchar_t *, size_t, _mbstate_t *);
-# 111 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 3
-char qsort (char * __base, size_t __nmemb, size_t __size, int(*_compar)(const char *, const char *));
-int rand (char);
-char * realloc (char * __r, size_t __size) ;
-
-
-
-char srand (unsigned __seed);
-double strtod (const char *__n, char **__end_PTR);
-double _strtod_r (struct _reent *,const char *__n, char **__end_PTR);
-float strtof (const char *__n, char **__end_PTR);
-
-
-
-
-
-
-long strtol (const char *__n, char **__end_PTR, int __base);
-long _strtol_r (struct _reent *,const char *__n, char **__end_PTR, int __base);
-unsigned long strtoul (const char *__n, char **__end_PTR, int __base);
-unsigned long _strtoul_r (struct _reent *,const char *__n, char **__end_PTR, int __base);
-
-int system (const char *__string);
-# 198 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdlib.h" 3
-char * _dtoa_r (struct _reent *, double, int, int, int *, int*, char**);
-
-char * _malloc_r (struct _reent *, size_t) ;
-char * _calloc_r (struct _reent *, size_t, size_t) ;
-char _free_r (struct _reent *, char *) ;
-char * _realloc_r (struct _reent *, char *, size_t) ;
-char _mstats_r (struct _reent *, char *);
-
-int _system_r (struct _reent *, const char *);
-
-char __eprintf (const char *, const char *, unsigned int, const char *);
-
-
-
-extern long double strtold (const char *, char **);
-extern long double wcstold (const wchar_t *, wchar_t **);
-
-
-
-# 40 "jinclude.h" 2
-
-
-
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 1 3
-# 34 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 1 3 4
-# 35 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 2 3
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stdarg.h" 1 3 4
-# 40 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stdarg.h" 3 4
-typedef __builtin_va_list __gnuc_va_list;
-# 38 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 2 3
-# 46 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 1 3
-# 69 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 1 3 4
-# 70 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 2 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/types.h" 1 3
-# 19 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/machine/types.h" 3
-typedef long int __off_t;
-typedef int __pid_t;
-
-
-
-typedef long int __loff_t;
-# 71 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 2 3
-# 92 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef unsigned char u_char;
-typedef unsigned short u_short;
-typedef unsigned int u_int;
-typedef unsigned long u_long;
-
-
-
-typedef unsigned short ushort;
-typedef unsigned int uint;
-
-
-
-typedef unsigned long clock_t;
-
-
-
-
-typedef long time_t;
-
-
-
-
-struct timespec {
- time_t tv_sec;
- long tv_nsec;
-};
-
-struct itimerspec {
- struct timespec it_interval;
- struct timespec it_value;
-};
-
-
-typedef long daddr_t;
-typedef char * caddr_t;
-
-
-
-
-
-
-typedef unsigned short ino_t;
-# 162 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef _off_t off_t;
-typedef __dev_t dev_t;
-typedef __uid_t uid_t;
-typedef __gid_t gid_t;
-
-
-
-
-
-typedef int pid_t;
-
-
-
-typedef long key_t;
-
-typedef _ssize_t ssize_t;
-# 191 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef unsigned int mode_t ;
-
-
-
-
-typedef unsigned short nlink_t;
-# 218 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef long fd_mask;
-
-
-
-
-
-
-
-typedef struct _types_fd_set {
- fd_mask fds_bits[(((64)+(((sizeof (fd_mask) * 8))-1))/((sizeof (fd_mask) * 8)))];
-} _types_fd_set;
-# 249 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef unsigned long clockid_t;
-
-
-
-
-typedef unsigned long timer_t;
-
-
-
-typedef unsigned long useconds_t;
-typedef long suseconds_t;
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/features.h" 1 3
-# 262 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 2 3
-# 273 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/sched.h" 1 3
-# 46 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/sched.h" 3
-struct sched_param {
- int sched_priority;
-# 59 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/sched.h" 3
-};
-# 274 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 2 3
-# 282 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef __uint32_t pthread_t;
-# 344 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef struct {
- int is_initialized;
- char *stackaddr;
- int stacksize;
- int contentionscope;
- int inheritsched;
- int schedpolicy;
- struct sched_param schedparam;
-
-
-
-
-
-
- int detachstate;
-
-} pthread_attr_t;
-# 459 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef __uint32_t pthread_mutex_t;
-
-
-typedef struct {
- int is_initialized;
-# 474 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
- int recursive;
-} pthread_mutexattr_t;
-
-
-
-
-
-
-
-typedef __uint32_t pthread_cond_t;
-
-
-typedef struct {
- int is_initialized;
-
-
-
-} pthread_condattr_t;
-
-
-
-
-
-
-typedef __uint32_t pthread_key_t;
-
-
-typedef struct {
- int is_initialized;
- int init_executed;
-} pthread_once_t;
-# 517 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef __uint32_t pthread_barrier_t;
-
-
-typedef struct {
- int is_initialized;
-
-
-
-} pthread_barrierattr_t;
-# 537 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/types.h" 3
-typedef __uint32_t pthread_spinlock_t;
-# 47 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 2 3
-
-
-
-typedef __FILE FILE;
-# 59 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-typedef _fpos_t fpos_t;
-
-
-
-
-
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/stdio.h" 1 3
-# 66 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 2 3
-# 175 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-FILE * tmpfile (char);
-char * tmpnam (char *);
-int fclose (FILE *);
-int fflush (FILE *);
-FILE * freopen (const char *, const char *, FILE *);
-char setbuf (FILE *, char *);
-int setvbuf (FILE *, char *, int, size_t);
-int fprintf (FILE *, const char *, ...)
- ;
-int fscanf (FILE *, const char *, ...)
- ;
-int printf (const char *, ...)
- ;
-int scanf (const char *, ...)
- ;
-int sscanf (const char *, const char *, ...)
- ;
-int vfprintf (FILE *, const char *, char*)
- ;
-int vprintf (const char *, char*)
- ;
-int vsprintf (char *, const char *, char*)
- ;
-int fgetc (FILE *);
-char * fgets (char *, int, FILE *);
-int fputc (int, FILE *);
-int fputs (const char *, FILE *);
-int getc (FILE *);
-int getchar (char);
-char * gets (char *);
-int putc (int, FILE *);
-int putchar (int);
-int puts (const char *);
-int ungetc (int, FILE *);
-size_t fread (char *, size_t _size, size_t _n, FILE *);
-size_t fwrite (const char * , size_t _size, size_t _n, FILE *);
-
-
-
-int fgetpos (FILE *, fpos_t *);
-
-int fseek (FILE *, long, int);
-
-
-
-int fsetpos (FILE *, const fpos_t *);
-
-long ftell ( FILE *);
-char rewind (FILE *);
-char clearerr (FILE *);
-int feof (FILE *);
-int ferror (FILE *);
-char perror (const char *);
-
-FILE * fopen (const char *_name, const char *_type);
-int sprintf (char *, const char *, ...)
- ;
-int remove (const char *);
-int rename (const char *, const char *);
-# 246 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-int asiprintf (char **, const char *, ...)
- ;
-char * asniprintf (char *, size_t *, const char *, ...)
- ;
-char * asnprintf (char *, size_t *, const char *, ...)
- ;
-int asprintf (char **, const char *, ...)
- ;
-
-int diprintf (int, const char *, ...)
- ;
-
-int fcloseall (char);
-int fiprintf (FILE *, const char *, ...)
- ;
-int fiscanf (FILE *, const char *, ...)
- ;
-int iprintf (const char *, ...)
- ;
-int iscanf (const char *, ...)
- ;
-int siprintf (char *, const char *, ...)
- ;
-int siscanf (const char *, const char *, ...)
- ;
-int snprintf (char *, size_t, const char *, ...)
- ;
-int sniprintf (char *, size_t, const char *, ...)
- ;
-char * tempnam (const char *, const char *);
-int vasiprintf (char **, const char *, char*)
- ;
-char * vasniprintf (char *, size_t *, const char *, char*)
- ;
-char * vasnprintf (char *, size_t *, const char *, char*)
- ;
-int vasprintf (char **, const char *, char*)
- ;
-int vdiprintf (int, const char *, char*)
- ;
-int vfiprintf (FILE *, const char *, char*)
- ;
-int vfiscanf (FILE *, const char *, char*)
- ;
-int vfscanf (FILE *, const char *, char*)
- ;
-int viprintf (const char *, char*)
- ;
-int viscanf (const char *, char*)
- ;
-int vscanf (const char *, char*)
- ;
-int vsiprintf (char *, const char *, char*)
- ;
-int vsiscanf (const char *, const char *, char*)
- ;
-int vsniprintf (char *, size_t, const char *, char*)
- ;
-int vsnprintf (char *, size_t, const char *, char*)
- ;
-int vsscanf (const char *, const char *, char*)
- ;
-# 361 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-int _asiprintf_r (struct _reent *, char **, const char *, ...)
- ;
-char * _asniprintf_r (struct _reent *, char *, size_t *, const char *, ...)
- ;
-char * _asnprintf_r (struct _reent *, char *, size_t *, const char *, ...)
- ;
-int _asprintf_r (struct _reent *, char **, const char *, ...)
- ;
-int _diprintf_r (struct _reent *, int, const char *, ...)
- ;
-int _dprintf_r (struct _reent *, int, const char *, ...)
- ;
-int _fclose_r (struct _reent *, FILE *);
-int _fcloseall_r (struct _reent *);
-FILE * _fdopen_r (struct _reent *, int, const char *);
-int _fflush_r (struct _reent *, FILE *);
-int _fgetc_r (struct _reent *, FILE *);
-char * _fgets_r (struct _reent *, char *, int, FILE *);
-
-
-
-
-int _fgetpos_r (struct _reent *, FILE *, fpos_t *);
-int _fsetpos_r (struct _reent *, FILE *, const fpos_t *);
-
-int _fiprintf_r (struct _reent *, FILE *, const char *, ...)
- ;
-int _fiscanf_r (struct _reent *, FILE *, const char *, ...)
- ;
-FILE * _fmemopen_r (struct _reent *, char *, size_t, const char *);
-FILE * _fopen_r (struct _reent *, const char *, const char *);
-FILE * _freopen_r (struct _reent *, const char *, const char *, FILE *);
-int _fprintf_r (struct _reent *, FILE *, const char *, ...)
- ;
-int _fpurge_r (struct _reent *, FILE *);
-int _fputc_r (struct _reent *, int, FILE *);
-int _fputs_r (struct _reent *, const char *, FILE *);
-size_t _fread_r (struct _reent *, char *, size_t _size, size_t _n, FILE *);
-int _fscanf_r (struct _reent *, FILE *, const char *, ...)
- ;
-int _fseek_r (struct _reent *, FILE *, long, int);
-int _fseeko_r (struct _reent *, FILE *, _off_t, int);
-long _ftell_r (struct _reent *, FILE *);
-_off_t _ftello_r (struct _reent *, FILE *);
-char _rewind_r (struct _reent *, FILE *);
-size_t _fwrite_r (struct _reent *, const char * , size_t _size, size_t _n, FILE *);
-int _getc_r (struct _reent *, FILE *);
-int _getc_unlocked_r (struct _reent *, FILE *);
-int _getchar_r (struct _reent *);
-int _getchar_unlocked_r (struct _reent *);
-char * _gets_r (struct _reent *, char *);
-int _iprintf_r (struct _reent *, const char *, ...)
- ;
-int _iscanf_r (struct _reent *, const char *, ...)
- ;
-FILE * _open_memstream_r (struct _reent *, char **, size_t *);
-char _perror_r (struct _reent *, const char *);
-int _printf_r (struct _reent *, const char *, ...)
- ;
-int _putc_r (struct _reent *, int, FILE *);
-int _putc_unlocked_r (struct _reent *, int, FILE *);
-int _putchar_unlocked_r (struct _reent *, int);
-int _putchar_r (struct _reent *, int);
-int _puts_r (struct _reent *, const char *);
-int _remove_r (struct _reent *, const char *);
-int _rename_r (struct _reent *, const char *_old, const char *_new)
- ;
-int _scanf_r (struct _reent *, const char *, ...)
- ;
-int _siprintf_r (struct _reent *, char *, const char *, ...)
- ;
-int _siscanf_r (struct _reent *, const char *, const char *, ...)
- ;
-int _sniprintf_r (struct _reent *, char *, size_t, const char *, ...)
- ;
-int _snprintf_r (struct _reent *, char *, size_t, const char *, ...)
- ;
-int _sprintf_r (struct _reent *, char *, const char *, ...)
- ;
-int _sscanf_r (struct _reent *, const char *, const char *, ...)
- ;
-char * _tempnam_r (struct _reent *, const char *, const char *);
-FILE * _tmpfile_r (struct _reent *);
-char * _tmpnam_r (struct _reent *, char *);
-int _ungetc_r (struct _reent *, int, FILE *);
-int _vasiprintf_r (struct _reent *, char **, const char *, char*)
- ;
-char * _vasniprintf_r (struct _reent*, char *, size_t *, const char *, char*)
- ;
-char * _vasnprintf_r (struct _reent*, char *, size_t *, const char *, char*)
- ;
-int _vasprintf_r (struct _reent *, char **, const char *, char*)
- ;
-int _vdiprintf_r (struct _reent *, int, const char *, char*)
- ;
-int _vdprintf_r (struct _reent *, int, const char *, char*)
- ;
-int _vfiprintf_r (struct _reent *, FILE *, const char *, char*)
- ;
-int _vfiscanf_r (struct _reent *, FILE *, const char *, char*)
- ;
-int _vfprintf_r (struct _reent *, FILE *, const char *, char*)
- ;
-int _vfscanf_r (struct _reent *, FILE *, const char *, char*)
- ;
-int _viprintf_r (struct _reent *, const char *, char*)
- ;
-int _viscanf_r (struct _reent *, const char *, char*)
- ;
-int _vprintf_r (struct _reent *, const char *, char*)
- ;
-int _vscanf_r (struct _reent *, const char *, char*)
- ;
-int _vsiprintf_r (struct _reent *, char *, const char *, char*)
- ;
-int _vsiscanf_r (struct _reent *, const char *, const char *, char*)
- ;
-int _vsniprintf_r (struct _reent *, char *, size_t, const char *, char*)
- ;
-int _vsnprintf_r (struct _reent *, char *, size_t, const char *, char*)
- ;
-int _vsprintf_r (struct _reent *, char *, const char *, char*)
- ;
-int _vsscanf_r (struct _reent *, const char *, const char *, char*)
- ;
-
-
-
-int fpurge (FILE *);
-ssize_t __getdelim (char **, size_t *, int, FILE *);
-ssize_t __getline (char **, size_t *, FILE *);
-# 519 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-int __srget_r (struct _reent *, FILE *);
-int __swbuf_r (struct _reent *, int, FILE *);
-# 687 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/stdio.h" 3
-
-# 47 "jinclude.h" 2
-# 66 "jinclude.h"
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/string.h" 1 3
-# 14 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/string.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/lib/gcc/k1-mbr/4.9.4/include/stddef.h" 1 3 4
-# 15 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/string.h" 2 3
-
-
-
-
-
-
-
-char * memchr (const char *, int, size_t);
-int memcmp (const char *, const char *, size_t);
-char * memcpy (char *, const char *, size_t);
-char * memmove (char *, const char *, size_t);
-char * memset (char *, int, size_t);
-char *strcat (char *, const char *);
-char *strchr (const char *, int);
-int strcmp (const char *, const char *);
-int strcoll (const char *, const char *);
-char *strcpy (char *, const char *);
-size_t strcspn (const char *, const char *);
-char *strerror (int);
-size_t strlen (const char *);
-char *strncat (char *, const char *, size_t);
-int strncmp (const char *, const char *, size_t);
-char *strncpy (char *, const char *, size_t);
-char *strpbrk (const char *, const char *);
-char *strrchr (const char *, int);
-size_t strspn (const char *, const char *);
-char *strstr (const char *, const char *);
-
-
-char *strtok (char *, const char *);
-
-
-size_t strxfrm (char *, const char *, size_t);
-# 78 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/string.h" 3
-# 1 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/sys/string.h" 1 3
-# 79 "/opt/Kalray/usr/local/k1rdtools/k1-mbr/include/string.h" 2 3
-
-
-# 67 "jinclude.h" 2
-# 19 "jcprepct.c" 2
-# 1 "jpeglib.h" 1
-# 26 "jpeglib.h"
-# 1 "jmorecfg.h" 1
-# 66 "jmorecfg.h"
-typedef unsigned char JSAMPLE;
-# 106 "jmorecfg.h"
-typedef short JCOEF;
-# 117 "jmorecfg.h"
-typedef unsigned char JOCTET;
-# 142 "jmorecfg.h"
-typedef unsigned char UINT8;
-# 154 "jmorecfg.h"
-typedef unsigned short UINT16;
-
-
-
-
-
-
-
-typedef short INT16;
-
-
-
-
-
-typedef long INT32;
-# 178 "jmorecfg.h"
-typedef unsigned int JDIMENSION;
-# 234 "jmorecfg.h"
-typedef int boolean;
-# 27 "jpeglib.h" 2
-# 66 "jpeglib.h"
-typedef JSAMPLE *JSAMPROW;
-typedef JSAMPROW *JSAMPARRAY;
-typedef JSAMPARRAY *JSAMPIMAGE;
-
-typedef JCOEF JBLOCK[64];
-typedef JBLOCK *JBLOCKROW;
-typedef JBLOCKROW *JBLOCKARRAY;
-typedef JBLOCKARRAY *JBLOCKIMAGE;
-
-typedef JCOEF *JCOEFPTR;
-
-
-
-
-
-
-
-typedef struct {
-
-
-
-
- UINT16 quantval[64];
-
-
-
-
-
- boolean sent_table;
-} JQUANT_TBL;
-
-
-
-
-typedef struct {
-
- UINT8 bits[17];
-
- UINT8 huffval[256];
-
-
-
-
-
- boolean sent_table;
-} JHUFF_TBL;
-
-
-
-
-typedef struct {
-
-
-
- int component_id;
- int component_index;
- int h_samp_factor;
- int v_samp_factor;
- int quant_tbl_no;
-
-
-
-
- int dc_tbl_no;
- int ac_tbl_no;
-# 139 "jpeglib.h"
- JDIMENSION width_in_blocks;
- JDIMENSION height_in_blocks;
-
-
-
-
-
-
- int DCT_scaled_size;
-
-
-
-
-
-
- JDIMENSION downsampled_width;
- JDIMENSION downsampled_height;
-
-
-
-
- boolean component_needed;
-
-
-
- int MCU_width;
- int MCU_height;
- int MCU_blocks;
- int MCU_sample_width;
- int last_col_width;
- int last_row_height;
-
-
-
-
-
- JQUANT_TBL * quant_table;
-
-
- char * dct_table;
-} jpeg_component_info;
-
-
-
-
-typedef struct {
- int comps_in_scan;
- int component_index[4];
- int Ss, Se;
- int Ah, Al;
-} jpeg_scan_info;
-
-
-
-typedef struct jpeg_marker_struct * jpeg_saved_marker_ptr;
-
-struct jpeg_marker_struct {
- jpeg_saved_marker_ptr next;
- UINT8 marker;
- unsigned int original_length;
- unsigned int data_length;
- JOCTET * data;
-
-};
-
-
-
-typedef enum {
- JCS_UNKNOWN,
- JCS_GRAYSCALE,
- JCS_RGB,
- JCS_YCbCr,
- JCS_CMYK,
- JCS_YCCK
-} J_COLOR_SPACE;
-
-
-
-typedef enum {
- JDCT_ISLOW,
- JDCT_IFAST,
- JDCT_FLOAT
-} J_DCT_METHOD;
-# 232 "jpeglib.h"
-typedef enum {
- JDITHER_NONE,
- JDITHER_ORDERED,
- JDITHER_FS
-} J_DITHER_MODE;
-# 253 "jpeglib.h"
-struct jpeg_common_struct {
- struct jpeg_error_mgr * err; struct jpeg_memory_mgr * mem; struct jpeg_progress_mgr * progress; char * client_data; boolean is_decompressor; int global_state;
-
-
-
-
-};
-
-typedef struct jpeg_common_struct * j_common_ptr;
-typedef struct jpeg_compress_struct * j_compress_ptr;
-typedef struct jpeg_decompress_struct * j_decompress_ptr;
-
-
-
-
-struct jpeg_compress_struct {
- struct jpeg_error_mgr * err; struct jpeg_memory_mgr * mem; struct jpeg_progress_mgr * progress; char * client_data; boolean is_decompressor; int global_state;
-
-
- struct jpeg_destination_mgr * dest;
-
-
-
-
-
-
- JDIMENSION image_width;
- JDIMENSION image_height;
- int input_components;
- J_COLOR_SPACE in_color_space;
-
- double input_gamma;
-# 294 "jpeglib.h"
- int data_precision;
-
- int num_components;
- J_COLOR_SPACE jpeg_color_space;
-
- jpeg_component_info * comp_info;
-
-
- JQUANT_TBL * quant_tbl_ptrs[4];
-
-
- JHUFF_TBL * dc_huff_tbl_ptrs[4];
- JHUFF_TBL * ac_huff_tbl_ptrs[4];
-
-
- UINT8 arith_dc_L[16];
- UINT8 arith_dc_U[16];
- UINT8 arith_ac_K[16];
-
- int num_scans;
- const jpeg_scan_info * scan_info;
-
-
-
-
-
- boolean raw_data_in;
- boolean arith_code;
- boolean optimize_coding;
- boolean CCIR601_sampling;
- int smoothing_factor;
- J_DCT_METHOD dct_method;
-
-
-
-
-
-
- unsigned int restart_interval;
- int restart_in_rows;
-
-
-
- boolean write_JFIF_header;
- UINT8 JFIF_major_version;
- UINT8 JFIF_minor_version;
-
-
-
-
- UINT8 density_unit;
- UINT16 X_density;
- UINT16 Y_density;
- boolean write_Adobe_marker;
-
-
-
-
-
-
- JDIMENSION next_scanline;
-# 363 "jpeglib.h"
- boolean progressive_mode;
- int max_h_samp_factor;
- int max_v_samp_factor;
-
- JDIMENSION total_iMCU_rows;
-# 378 "jpeglib.h"
- int comps_in_scan;
- jpeg_component_info * cur_comp_info[4];
-
-
- JDIMENSION MCUs_per_row;
- JDIMENSION MCU_rows_in_scan;
-
- int blocks_in_MCU;
- int MCU_membership[10];
-
-
-
- int Ss, Se, Ah, Al;
-
-
-
-
- struct jpeg_comp_master * master;
- struct jpeg_c_main_controller * main;
- struct jpeg_c_prep_controller * prep;
- struct jpeg_c_coef_controller * coef;
- struct jpeg_marker_writer * marker;
- struct jpeg_color_converter * cconvert;
- struct jpeg_downsampler * downsample;
- struct jpeg_forward_dct * fdct;
- struct jpeg_entropy_encoder * entropy;
- jpeg_scan_info * script_space;
- int script_space_size;
-};
-
-
-
-
-struct jpeg_decompress_struct {
- struct jpeg_error_mgr * err; struct jpeg_memory_mgr * mem; struct jpeg_progress_mgr * progress; char * client_data; boolean is_decompressor; int global_state;
-
-
- struct jpeg_source_mgr * src;
-
-
-
-
- JDIMENSION image_width;
- JDIMENSION image_height;
- int num_components;
- J_COLOR_SPACE jpeg_color_space;
-
-
-
-
-
-
- J_COLOR_SPACE out_color_space;
-
- unsigned int scale_num, scale_denom;
-
- double output_gamma;
-
- boolean buffered_image;
- boolean raw_data_out;
-
- J_DCT_METHOD dct_method;
- boolean do_fancy_upsampling;
- boolean do_block_smoothing;
-
- boolean quantize_colors;
-
- J_DITHER_MODE dither_mode;
- boolean two_pass_quantize;
- int desired_number_of_colors;
-
- boolean enable_1pass_quant;
- boolean enable_external_quant;
- boolean enable_2pass_quant;
-
-
-
-
-
-
-
- JDIMENSION output_width;
- JDIMENSION output_height;
- int out_color_components;
- int output_components;
-
-
-
- int rec_outbuf_height;
-# 478 "jpeglib.h"
- int actual_number_of_colors;
- JSAMPARRAY colormap;
-# 489 "jpeglib.h"
- JDIMENSION output_scanline;
-
-
-
-
- int input_scan_number;
- JDIMENSION input_iMCU_row;
-
-
-
-
-
- int output_scan_number;
- JDIMENSION output_iMCU_row;
-# 511 "jpeglib.h"
- int (*coef_bits)[64];
-# 522 "jpeglib.h"
- JQUANT_TBL * quant_tbl_ptrs[4];
-
-
- JHUFF_TBL * dc_huff_tbl_ptrs[4];
- JHUFF_TBL * ac_huff_tbl_ptrs[4];
-
-
-
-
-
-
- int data_precision;
-
- jpeg_component_info * comp_info;
-
-
- boolean progressive_mode;
- boolean arith_code;
-
- UINT8 arith_dc_L[16];
- UINT8 arith_dc_U[16];
- UINT8 arith_ac_K[16];
-
- unsigned int restart_interval;
-
-
-
-
- boolean saw_JFIF_marker;
-
- UINT8 JFIF_major_version;
- UINT8 JFIF_minor_version;
- UINT8 density_unit;
- UINT16 X_density;
- UINT16 Y_density;
- boolean saw_Adobe_marker;
- UINT8 Adobe_transform;
-
- boolean CCIR601_sampling;
-
-
-
-
-
- jpeg_saved_marker_ptr marker_list;
-# 575 "jpeglib.h"
- int max_h_samp_factor;
- int max_v_samp_factor;
-
- int min_DCT_scaled_size;
-
- JDIMENSION total_iMCU_rows;
-# 589 "jpeglib.h"
- JSAMPLE * sample_range_limit;
-
-
-
-
-
-
- int comps_in_scan;
- jpeg_component_info * cur_comp_info[4];
-
-
- JDIMENSION MCUs_per_row;
- JDIMENSION MCU_rows_in_scan;
-
- int blocks_in_MCU;
- int MCU_membership[10];
-
-
-
- int Ss, Se, Ah, Al;
-
-
-
-
-
- int unread_marker;
-
-
-
-
- struct jpeg_decomp_master * master;
- struct jpeg_d_main_controller * main;
- struct jpeg_d_coef_controller * coef;
- struct jpeg_d_post_controller * post;
- struct jpeg_input_controller * inputctl;
- struct jpeg_marker_reader * marker;
- struct jpeg_entropy_decoder * entropy;
- struct jpeg_inverse_dct * idct;
- struct jpeg_upsampler * upsample;
- struct jpeg_color_deconverter * cconvert;
- struct jpeg_color_quantizer * cquantize;
-};
-# 643 "jpeglib.h"
-struct jpeg_error_mgr {
-
- char (*error_exit) (j_common_ptr cinfo);
-
- char (*emit_message) (j_common_ptr cinfo, int msg_level);
-
- char (*output_message) (j_common_ptr cinfo);
-
- char (*format_message) (j_common_ptr cinfo, char * buffer);
-
-
- char (*reset_error_mgr) (j_common_ptr cinfo);
-
-
-
-
- int msg_code;
-
- union {
- int i[8];
- char s[80];
- } msg_parm;
-
-
-
- int trace_level;
-
-
-
-
-
-
-
- long num_warnings;
-# 688 "jpeglib.h"
- const char * const * jpeg_message_table;
- int last_jpeg_message;
-
-
-
- const char * const * addon_message_table;
- int first_addon_message;
- int last_addon_message;
-};
-
-
-
-
-struct jpeg_progress_mgr {
- char (*progress_monitor) (j_common_ptr cinfo);
-
- long pass_counter;
- long pass_limit;
- int completed_passes;
- int total_passes;
-};
-
-
-
-
-struct jpeg_destination_mgr {
- JOCTET * next_output_byte;
- size_t free_in_buffer;
-
- char (*init_destination) (j_compress_ptr cinfo);
- boolean (*empty_output_buffer) (j_compress_ptr cinfo);
- char (*term_destination) (j_compress_ptr cinfo);
-};
-
-
-
-
-struct jpeg_source_mgr {
- const JOCTET * next_input_byte;
- size_t bytes_in_buffer;
-
- char (*init_source) (j_decompress_ptr cinfo);
- boolean (*fill_input_buffer) (j_decompress_ptr cinfo);
- char (*skip_input_data) (j_decompress_ptr cinfo, long num_bytes);
- boolean (*resync_to_restart) (j_decompress_ptr cinfo, int desired);
- char (*term_source) (j_decompress_ptr cinfo);
-};
-# 752 "jpeglib.h"
-typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
-typedef struct jvirt_barray_control * jvirt_barray_ptr;
-
-
-struct jpeg_memory_mgr {
-
- char * (*alloc_small) (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
- ;
- char * (*alloc_large) (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
- ;
- JSAMPARRAY (*alloc_sarray) (j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow, JDIMENSION numrows)
-
- ;
- JBLOCKARRAY (*alloc_barray) (j_common_ptr cinfo, int pool_id, JDIMENSION blocksperrow, JDIMENSION numrows)
-
- ;
- jvirt_sarray_ptr (*request_virt_sarray) (j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION samplesperrow, JDIMENSION numrows, JDIMENSION maxaccess)
-
-
-
-
- ;
- jvirt_barray_ptr (*request_virt_barray) (j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION blocksperrow, JDIMENSION numrows, JDIMENSION maxaccess)
-
-
-
-
- ;
- char (*realize_virt_arrays) (j_common_ptr cinfo);
- JSAMPARRAY (*access_virt_sarray) (j_common_ptr cinfo, jvirt_sarray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
-
-
-
- ;
- JBLOCKARRAY (*access_virt_barray) (j_common_ptr cinfo, jvirt_barray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
-
-
-
- ;
- char (*free_pool) (j_common_ptr cinfo, int pool_id);
- char (*self_destruct) (j_common_ptr cinfo);
-
-
-
-
-
-
- long max_memory_to_use;
-
-
- long max_alloc_chunk;
-};
-
-
-
-
-
-typedef boolean (*jpeg_marker_parser_method) (j_decompress_ptr cinfo);
-# 884 "jpeglib.h"
-extern struct jpeg_error_mgr * jpeg_std_error
- (struct jpeg_error_mgr * err);
-# 900 "jpeglib.h"
-extern char jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
- ;
-extern char jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
- ;
-
-extern char jpeg_destroy_compress (j_compress_ptr cinfo);
-extern char jpeg_destroy_decompress (j_decompress_ptr cinfo);
-
-
-
-extern char jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile);
-extern char jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile);
-
-
-extern char jpeg_set_defaults (j_compress_ptr cinfo);
-
-extern char jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
- ;
-extern char jpeg_default_colorspace (j_compress_ptr cinfo);
-extern char jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
- ;
-extern char jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, boolean force_baseline)
-
- ;
-extern char jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, const unsigned int *basic_table, int scale_factor, boolean force_baseline)
-
-
- ;
-extern int jpeg_quality_scaling (int quality);
-extern char jpeg_simple_progression (j_compress_ptr cinfo);
-extern char jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
- ;
-extern JQUANT_TBL * jpeg_alloc_quant_table (j_common_ptr cinfo);
-extern JHUFF_TBL * jpeg_alloc_huff_table (j_common_ptr cinfo);
-
-
-extern char jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
- ;
-extern JDIMENSION jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)
-
- ;
-extern char jpeg_finish_compress (j_compress_ptr cinfo);
-
-
-extern JDIMENSION jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data, JDIMENSION num_lines)
-
- ;
-
-
-extern char jpeg_write_marker
- (j_compress_ptr cinfo, int marker, const JOCTET * dataptr, unsigned int datalen)
- ;
-
-extern char jpeg_write_m_header
- (j_compress_ptr cinfo, int marker, unsigned int datalen);
-extern char jpeg_write_m_byte
- (j_compress_ptr cinfo, int val);
-
-
-extern char jpeg_write_tables (j_compress_ptr cinfo);
-
-
-extern int jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
- ;
-# 975 "jpeglib.h"
-extern boolean jpeg_start_decompress (j_decompress_ptr cinfo);
-extern JDIMENSION jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)
-
- ;
-extern boolean jpeg_finish_decompress (j_decompress_ptr cinfo);
-
-
-extern JDIMENSION jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data, JDIMENSION max_lines)
-
- ;
-
-
-extern boolean jpeg_has_multiple_scans (j_decompress_ptr cinfo);
-extern boolean jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
- ;
-extern boolean jpeg_finish_output (j_decompress_ptr cinfo);
-extern boolean jpeg_input_complete (j_decompress_ptr cinfo);
-extern char jpeg_new_colormap (j_decompress_ptr cinfo);
-extern int jpeg_consume_input (j_decompress_ptr cinfo);
-# 1002 "jpeglib.h"
-extern char jpeg_calc_output_dimensions (j_decompress_ptr cinfo);
-
-
-extern char jpeg_save_markers
- (j_decompress_ptr cinfo, int marker_code, unsigned int length_limit)
- ;
-
-
-extern char jpeg_set_marker_processor
- (j_decompress_ptr cinfo, int marker_code, jpeg_marker_parser_method routine)
- ;
-
-
-extern jvirt_barray_ptr * jpeg_read_coefficients (j_decompress_ptr cinfo);
-extern char jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
- ;
-extern char jpeg_copy_critical_parameters (j_decompress_ptr srcinfo, j_compress_ptr dstinfo)
- ;
-
-
-
-
-
-
-
-extern char jpeg_abort_compress (j_compress_ptr cinfo);
-extern char jpeg_abort_decompress (j_decompress_ptr cinfo);
-
-
-
-
-extern char jpeg_abort (j_common_ptr cinfo);
-extern char jpeg_destroy (j_common_ptr cinfo);
-
-
-extern boolean jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
- ;
-# 1092 "jpeglib.h"
-# 1 "jpegint.h" 1
-# 16 "jpegint.h"
-typedef enum {
- JBUF_PASS_THRU,
-
- JBUF_SAVE_SOURCE,
- JBUF_CRANK_DEST,
- JBUF_SAVE_AND_PASS
-} J_BUF_MODE;
-# 45 "jpegint.h"
-struct jpeg_comp_master {
- char (*prepare_for_pass) (j_compress_ptr cinfo);
- char (*pass_startup) (j_compress_ptr cinfo);
- char (*finish_pass) (j_compress_ptr cinfo);
-
-
- boolean call_pass_startup;
- boolean is_last_pass;
-};
-
-
-struct jpeg_c_main_controller {
- char (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
- char (*process_data) (j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)
-
- ;
-};
-
-
-struct jpeg_c_prep_controller {
- char (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
- char (*pre_process_data) (j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail, JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, JDIMENSION out_row_groups_avail)
-
-
-
-
-
- ;
-};
-
-
-struct jpeg_c_coef_controller {
- char (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
- boolean (*compress_data) (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
- ;
-};
-
-
-struct jpeg_color_converter {
- char (*start_pass) (j_compress_ptr cinfo);
- char (*color_convert) (j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
-
- ;
-};
-
-
-struct jpeg_downsampler {
- char (*start_pass) (j_compress_ptr cinfo);
- char (*downsample) (j_compress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION in_row_index, JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
-
-
- ;
-
- boolean need_context_rows;
-};
-
-
-struct jpeg_forward_dct {
- char (*start_pass) (j_compress_ptr cinfo);
-
- char (*forward_DCT) (j_compress_ptr cinfo, jpeg_component_info * compptr, JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JDIMENSION start_row, JDIMENSION start_col, JDIMENSION num_blocks)
-
-
-
- ;
-};
-
-
-struct jpeg_entropy_encoder {
- char (*start_pass) (j_compress_ptr cinfo, boolean gather_statistics);
- boolean (*encode_mcu) (j_compress_ptr cinfo, JBLOCKROW *MCU_data);
- char (*finish_pass) (j_compress_ptr cinfo);
-};
-
-
-struct jpeg_marker_writer {
- char (*write_file_header) (j_compress_ptr cinfo);
- char (*write_frame_header) (j_compress_ptr cinfo);
- char (*write_scan_header) (j_compress_ptr cinfo);
- char (*write_file_trailer) (j_compress_ptr cinfo);
- char (*write_tables_only) (j_compress_ptr cinfo);
-
-
- char (*write_marker_header) (j_compress_ptr cinfo, int marker, unsigned int datalen)
- ;
- char (*write_marker_byte) (j_compress_ptr cinfo, int val);
-};
-
-
-
-
-
-struct jpeg_decomp_master {
- char (*prepare_for_output_pass) (j_decompress_ptr cinfo);
- char (*finish_output_pass) (j_decompress_ptr cinfo);
-
-
- boolean is_dummy_pass;
-};
-
-
-struct jpeg_input_controller {
- int (*consume_input) (j_decompress_ptr cinfo);
- char (*reset_input_controller) (j_decompress_ptr cinfo);
- char (*start_input_pass) (j_decompress_ptr cinfo);
- char (*finish_input_pass) (j_decompress_ptr cinfo);
-
-
- boolean has_multiple_scans;
- boolean eoi_reached;
-};
-
-
-struct jpeg_d_main_controller {
- char (*start_pass) (j_decompress_ptr cinfo, J_BUF_MODE pass_mode);
- char (*process_data) (j_decompress_ptr cinfo, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
-
- ;
-};
-
-
-struct jpeg_d_coef_controller {
- char (*start_input_pass) (j_decompress_ptr cinfo);
- int (*consume_data) (j_decompress_ptr cinfo);
- char (*start_output_pass) (j_decompress_ptr cinfo);
- int (*decompress_data) (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
- ;
-
- jvirt_barray_ptr *coef_arrays;
-};
-
-
-struct jpeg_d_post_controller {
- char (*start_pass) (j_decompress_ptr cinfo, J_BUF_MODE pass_mode);
- char (*post_process_data) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
-
-
-
-
-
- ;
-};
-
-
-struct jpeg_marker_reader {
- char (*reset_marker_reader) (j_decompress_ptr cinfo);
-
-
-
-
- int (*read_markers) (j_decompress_ptr cinfo);
-
- jpeg_marker_parser_method read_restart_marker;
-
-
-
-
- boolean saw_SOI;
- boolean saw_SOF;
- int next_restart_num;
- unsigned int discarded_bytes;
-};
-
-
-struct jpeg_entropy_decoder {
- char (*start_pass) (j_decompress_ptr cinfo);
- boolean (*decode_mcu) (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
- ;
-
-
-
- boolean insufficient_data;
-};
-
-
-typedef char (*inverse_DCT_method_ptr) (j_decompress_ptr cinfo, jpeg_component_info * compptr, JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)
-
-
- ;
-
-struct jpeg_inverse_dct {
- char (*start_pass) (j_decompress_ptr cinfo);
-
- inverse_DCT_method_ptr inverse_DCT[10];
-};
-
-
-struct jpeg_upsampler {
- char (*start_pass) (j_decompress_ptr cinfo);
- char (*upsample) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
-
-
-
-
-
- ;
-
- boolean need_context_rows;
-};
-
-
-struct jpeg_color_deconverter {
- char (*start_pass) (j_decompress_ptr cinfo);
- char (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
-
- ;
-};
-
-
-struct jpeg_color_quantizer {
- char (*start_pass) (j_decompress_ptr cinfo, boolean is_pre_scan);
- char (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
-
- ;
- char (*finish_pass) (j_decompress_ptr cinfo);
- char (*new_color_map) (j_decompress_ptr cinfo);
-};
-# 334 "jpegint.h"
-extern char jinit_compress_master (j_compress_ptr cinfo);
-extern char jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
- ;
-extern char jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
- ;
-extern char jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
- ;
-extern char jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
- ;
-extern char jinit_color_converter (j_compress_ptr cinfo);
-extern char jinit_downsampler (j_compress_ptr cinfo);
-extern char jinit_forward_dct (j_compress_ptr cinfo);
-extern char jinit_huff_encoder (j_compress_ptr cinfo);
-extern char jinit_phuff_encoder (j_compress_ptr cinfo);
-extern char jinit_marker_writer (j_compress_ptr cinfo);
-
-extern char jinit_master_decompress (j_decompress_ptr cinfo);
-extern char jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
- ;
-extern char jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
- ;
-extern char jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
- ;
-extern char jinit_input_controller (j_decompress_ptr cinfo);
-extern char jinit_marker_reader (j_decompress_ptr cinfo);
-extern char jinit_huff_decoder (j_decompress_ptr cinfo);
-extern char jinit_phuff_decoder (j_decompress_ptr cinfo);
-extern char jinit_inverse_dct (j_decompress_ptr cinfo);
-extern char jinit_upsampler (j_decompress_ptr cinfo);
-extern char jinit_color_deconverter (j_decompress_ptr cinfo);
-extern char jinit_1pass_quantizer (j_decompress_ptr cinfo);
-extern char jinit_2pass_quantizer (j_decompress_ptr cinfo);
-extern char jinit_merged_upsampler (j_decompress_ptr cinfo);
-
-extern char jinit_memory_mgr (j_common_ptr cinfo);
-
-
-extern long jdiv_round_up (long a, long b);
-extern long jround_up (long a, long b);
-extern char jcopy_sample_rows (JSAMPARRAY input_array, int source_row, JSAMPARRAY output_array, int dest_row, int num_rows, JDIMENSION num_cols)
-
- ;
-extern char jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, JDIMENSION num_blocks)
- ;
-extern char jzero_far (char * target, size_t bytestozero);
-
-
-
-
-extern const int jpeg_natural_order[];
-# 1093 "jpeglib.h" 2
-# 1 "jerror.h" 1
-# 33 "jerror.h"
-typedef enum {
-
-
-
-
-
-JMSG_NOMESSAGE ,
-
-
-JERR_ARITH_NOTIMPL ,
-
-JERR_BAD_ALIGN_TYPE ,
-JERR_BAD_ALLOC_CHUNK ,
-JERR_BAD_BUFFER_MODE ,
-JERR_BAD_COMPONENT_ID ,
-JERR_BAD_DCT_COEF ,
-JERR_BAD_DCTSIZE ,
-JERR_BAD_HUFF_TABLE ,
-JERR_BAD_IN_COLORSPACE ,
-JERR_BAD_J_COLORSPACE ,
-JERR_BAD_LENGTH ,
-JERR_BAD_LIB_VERSION ,
-
-JERR_BAD_MCU_SIZE ,
-JERR_BAD_POOL_ID ,
-JERR_BAD_PRECISION ,
-JERR_BAD_PROGRESSION ,
-
-JERR_BAD_PROG_SCRIPT ,
-
-JERR_BAD_SAMPLING ,
-JERR_BAD_SCAN_SCRIPT ,
-JERR_BAD_STATE ,
-JERR_BAD_STRUCT_SIZE ,
-
-JERR_BAD_VIRTUAL_ACCESS ,
-JERR_BUFFER_SIZE ,
-JERR_CANT_SUSPEND ,
-JERR_CCIR601_NOTIMPL ,
-JERR_COMPONENT_COUNT ,
-JERR_CONVERSION_NOTIMPL ,
-JERR_DAC_INDEX ,
-JERR_DAC_VALUE ,
-JERR_DHT_INDEX ,
-JERR_DQT_INDEX ,
-JERR_EMPTY_IMAGE ,
-JERR_EMS_READ ,
-JERR_EMS_WRITE ,
-JERR_EOI_EXPECTED ,
-JERR_FILE_READ ,
-JERR_FILE_WRITE ,
-JERR_FRACT_SAMPLE_NOTIMPL ,
-JERR_HUFF_CLEN_OVERFLOW ,
-JERR_HUFF_MISSING_CODE ,
-JERR_IMAGE_TOO_BIG ,
-JERR_INPUT_EMPTY ,
-JERR_INPUT_EOF ,
-JERR_MISMATCHED_QUANT_TABLE ,
-
-JERR_MISSING_DATA ,
-JERR_MODE_CHANGE ,
-JERR_NOTIMPL ,
-JERR_NOT_COMPILED ,
-JERR_NO_BACKING_STORE ,
-JERR_NO_HUFF_TABLE ,
-JERR_NO_IMAGE ,
-JERR_NO_QUANT_TABLE ,
-JERR_NO_SOI ,
-JERR_OUT_OF_MEMORY ,
-JERR_QUANT_COMPONENTS ,
-
-JERR_QUANT_FEW_COLORS ,
-JERR_QUANT_MANY_COLORS ,
-JERR_SOF_DUPLICATE ,
-JERR_SOF_NO_SOS ,
-JERR_SOF_UNSUPPORTED ,
-JERR_SOI_DUPLICATE ,
-JERR_SOS_NO_SOF ,
-JERR_TFILE_CREATE ,
-JERR_TFILE_READ ,
-JERR_TFILE_SEEK ,
-JERR_TFILE_WRITE ,
-
-JERR_TOO_LITTLE_DATA ,
-JERR_UNKNOWN_MARKER ,
-JERR_VIRTUAL_BUG ,
-JERR_WIDTH_OVERFLOW ,
-JERR_XMS_READ ,
-JERR_XMS_WRITE ,
-JMSG_COPYRIGHT ,
-JMSG_VERSION ,
-JTRC_16BIT_TABLES ,
-
-JTRC_ADOBE ,
-
-JTRC_APP0 ,
-JTRC_APP14 ,
-JTRC_DAC ,
-JTRC_DHT ,
-JTRC_DQT ,
-JTRC_DRI ,
-JTRC_EMS_CLOSE ,
-JTRC_EMS_OPEN ,
-JTRC_EOI ,
-JTRC_HUFFBITS ,
-JTRC_JFIF ,
-JTRC_JFIF_BADTHUMBNAILSIZE ,
-
-JTRC_JFIF_EXTENSION ,
-
-JTRC_JFIF_THUMBNAIL ,
-JTRC_MISC_MARKER ,
-JTRC_PARMLESS_MARKER ,
-JTRC_QUANTVALS ,
-JTRC_QUANT_3_NCOLORS ,
-JTRC_QUANT_NCOLORS ,
-JTRC_QUANT_SELECTED ,
-JTRC_RECOVERY_ACTION ,
-JTRC_RST ,
-JTRC_SMOOTH_NOTIMPL ,
-
-JTRC_SOF ,
-JTRC_SOF_COMPONENT ,
-JTRC_SOI ,
-JTRC_SOS ,
-JTRC_SOS_COMPONENT ,
-JTRC_SOS_PARAMS ,
-JTRC_TFILE_CLOSE ,
-JTRC_TFILE_OPEN ,
-JTRC_THUMB_JPEG ,
-
-JTRC_THUMB_PALETTE ,
-
-JTRC_THUMB_RGB ,
-
-JTRC_UNKNOWN_IDS ,
-
-JTRC_XMS_CLOSE ,
-JTRC_XMS_OPEN ,
-JWRN_ADOBE_XFORM ,
-JWRN_BOGUS_PROGRESSION ,
-
-JWRN_EXTRANEOUS_DATA ,
-
-JWRN_HIT_MARKER ,
-JWRN_HUFF_BAD_CODE ,
-JWRN_JFIF_MAJOR ,
-JWRN_JPEG_EOF ,
-JWRN_MUST_RESYNC ,
-
-JWRN_NOT_SEQUENTIAL ,
-JWRN_TOO_MUCH_DATA ,
-
-
-
- JMSG_LASTMSGCODE
-} J_MESSAGE_CODE;
-# 1094 "jpeglib.h" 2
-# 20 "jcprepct.c" 2
-# 53 "jcprepct.c"
-typedef struct {
- struct jpeg_c_prep_controller pub;
-
-
-
-
- JSAMPARRAY color_buf[10];
-
- JDIMENSION rows_to_go;
- int next_buf_row;
-
-
- int this_row_group;
- int next_buf_stop;
-
-} my_prep_controller;
-
-typedef my_prep_controller * my_prep_ptr;
-
-
-
-
-
-
-static char
-start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
-{
- my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
-
- if (pass_mode != JBUF_PASS_THRU)
- ((cinfo)->err->msg_code = (JERR_BAD_BUFFER_MODE), (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)));
-
-
- prep->rows_to_go = cinfo->image_height;
-
- prep->next_buf_row = 0;
-
-
-
-
- prep->this_row_group = 0;
-
- prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
-
-}
-
-
-
-
-
-
-
-static char
-expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
- int input_rows, int output_rows)
-{
- register int row;
-
- for (row = input_rows; row < output_rows; row++) {
- jcopy_sample_rows(image_data, input_rows-1, image_data, row,
- 1, num_cols);
- }
-}
-# 127 "jcprepct.c"
-static char
-pre_process_data (j_compress_ptr cinfo,
- JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
- JDIMENSION in_rows_avail,
- JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
- JDIMENSION out_row_groups_avail)
-{
- my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
- int numrows, ci;
- JDIMENSION inrows;
- jpeg_component_info * compptr;
-
- while (*in_row_ctr < in_rows_avail &&
- *out_row_group_ctr < out_row_groups_avail) {
-
- inrows = in_rows_avail - *in_row_ctr;
- numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
- numrows = (int) (((JDIMENSION) numrows) < (inrows) ? ((JDIMENSION) numrows) : (inrows));
- (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
- prep->color_buf,
- (JDIMENSION) prep->next_buf_row,
- numrows);
- *in_row_ctr += numrows;
- prep->next_buf_row += numrows;
- prep->rows_to_go -= numrows;
-
- if (prep->rows_to_go == 0 &&
- prep->next_buf_row < cinfo->max_v_samp_factor) {
- for (ci = 0; ci < cinfo->num_components; ci++) {
- expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
- prep->next_buf_row, cinfo->max_v_samp_factor);
- }
- prep->next_buf_row = cinfo->max_v_samp_factor;
- }
-
- if (prep->next_buf_row == cinfo->max_v_samp_factor) {
- (*cinfo->downsample->downsample) (cinfo,
- prep->color_buf, (JDIMENSION) 0,
- output_buf, *out_row_group_ctr);
- prep->next_buf_row = 0;
- (*out_row_group_ctr)++;
- }
-
-
-
- if (prep->rows_to_go == 0 &&
- *out_row_group_ctr < out_row_groups_avail) {
- for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
- ci++, compptr++) {
- expand_bottom_edge(output_buf[ci],
- compptr->width_in_blocks * 8,
- (int) (*out_row_group_ctr * compptr->v_samp_factor),
- (int) (out_row_groups_avail * compptr->v_samp_factor));
- }
- *out_row_group_ctr = out_row_groups_avail;
- break;
- }
- }
-}
-# 194 "jcprepct.c"
-static char
-pre_process_context (j_compress_ptr cinfo,
- JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
- JDIMENSION in_rows_avail,
- JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
- JDIMENSION out_row_groups_avail)
-{
- my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
- int numrows, ci;
- int buf_height = cinfo->max_v_samp_factor * 3;
- JDIMENSION inrows;
-
- while (*out_row_group_ctr < out_row_groups_avail) {
- if (*in_row_ctr < in_rows_avail) {
-
- inrows = in_rows_avail - *in_row_ctr;
- numrows = prep->next_buf_stop - prep->next_buf_row;
- numrows = (int) (((JDIMENSION) numrows) < (inrows) ? ((JDIMENSION) numrows) : (inrows));
- (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
- prep->color_buf,
- (JDIMENSION) prep->next_buf_row,
- numrows);
-
- if (prep->rows_to_go == cinfo->image_height) {
- for (ci = 0; ci < cinfo->num_components; ci++) {
- int row;
- for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
- jcopy_sample_rows(prep->color_buf[ci], 0,
- prep->color_buf[ci], -row,
- 1, cinfo->image_width);
- }
- }
- }
- *in_row_ctr += numrows;
- prep->next_buf_row += numrows;
- prep->rows_to_go -= numrows;
- } else {
-
- if (prep->rows_to_go != 0)
- break;
-
- if (prep->next_buf_row < prep->next_buf_stop) {
- for (ci = 0; ci < cinfo->num_components; ci++) {
- expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
- prep->next_buf_row, prep->next_buf_stop);
- }
- prep->next_buf_row = prep->next_buf_stop;
- }
- }
-
- if (prep->next_buf_row == prep->next_buf_stop) {
- (*cinfo->downsample->downsample) (cinfo,
- prep->color_buf,
- (JDIMENSION) prep->this_row_group,
- output_buf, *out_row_group_ctr);
- (*out_row_group_ctr)++;
-
- prep->this_row_group += cinfo->max_v_samp_factor;
- if (prep->this_row_group >= buf_height)
- prep->this_row_group = 0;
- if (prep->next_buf_row >= buf_height)
- prep->next_buf_row = 0;
- prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
- }
- }
-}
-
-
-
-
-
-
-static char
-create_context_buffer (j_compress_ptr cinfo)
-{
- my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
- int rgroup_height = cinfo->max_v_samp_factor;
- int ci, i;
- jpeg_component_info * compptr;
- JSAMPARRAY true_buffer, fake_buffer;
-
-
-
-
- fake_buffer = (JSAMPARRAY)
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, 1,
- (cinfo->num_components * 5 * rgroup_height) *
- ((size_t) sizeof(JSAMPROW)));
-
- for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
- ci++, compptr++) {
-
-
-
-
- true_buffer = (*cinfo->mem->alloc_sarray)
- ((j_common_ptr) cinfo, 1,
- (JDIMENSION) (((long) compptr->width_in_blocks * 8 *
- cinfo->max_h_samp_factor) / compptr->h_samp_factor),
- (JDIMENSION) (3 * rgroup_height));
-
- memcpy((char *)(fake_buffer + rgroup_height), (const char *)(true_buffer), (size_t)(3 * rgroup_height * ((size_t) sizeof(JSAMPROW))))
- ;
-
- for (i = 0; i < rgroup_height; i++) {
- fake_buffer[i] = true_buffer[2 * rgroup_height + i];
- fake_buffer[4 * rgroup_height + i] = true_buffer[i];
- }
- prep->color_buf[ci] = fake_buffer + rgroup_height;
- fake_buffer += 5 * rgroup_height;
- }
-}
-# 314 "jcprepct.c"
-char
-jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
-{
- my_prep_ptr prep;
- int ci;
- jpeg_component_info * compptr;
-
- if (need_full_buffer)
- ((cinfo)->err->msg_code = (JERR_BAD_BUFFER_MODE), (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)));
-
- prep = (my_prep_ptr)
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, 1,
- ((size_t) sizeof(my_prep_controller)));
- cinfo->prep = (struct jpeg_c_prep_controller *) prep;
- prep->pub.start_pass = start_pass_prep;
-
-
-
-
-
- if (cinfo->downsample->need_context_rows) {
-
-
- prep->pub.pre_process_data = pre_process_context;
- create_context_buffer(cinfo);
-
-
-
- } else {
-
- prep->pub.pre_process_data = pre_process_data;
- for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
- ci++, compptr++) {
- prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
- ((j_common_ptr) cinfo, 1,
- (JDIMENSION) ((long long) (((long) compptr->width_in_blocks * 8 * cinfo->max_h_samp_factor)) / (long long) (compptr->h_samp_factor))
- ,
- (JDIMENSION) cinfo->max_v_samp_factor);
- }
- }
-}
diff --git a/test/monniaux/jpeg-6b/jcsample.c b/test/monniaux/jpeg-6b/jcsample.c
index cc390da6..5cd42abd 100644
--- a/test/monniaux/jpeg-6b/jcsample.c
+++ b/test/monniaux/jpeg-6b/jcsample.c
@@ -146,8 +146,8 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPROW inptr, outptr;
INT32 outvalue;
- h_expand = DIVISION(cinfo->max_h_samp_factor, compptr->h_samp_factor);
- v_expand = DIVISION(cinfo->max_v_samp_factor, compptr->v_samp_factor);
+ h_expand = INT_DIV(cinfo->max_h_samp_factor, compptr->h_samp_factor);
+ v_expand = INT_DIV(cinfo->max_v_samp_factor, compptr->v_samp_factor);
numpix = h_expand * v_expand;
numpix2 = numpix/2;
@@ -170,7 +170,7 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
outvalue += (INT32) GETJSAMPLE(*inptr++);
}
}
- *outptr++ = (JSAMPLE) DIVISION((outvalue + numpix2), numpix);
+ *outptr++ = (JSAMPLE) INT_DIV((outvalue + numpix2), numpix);
}
inrow += v_expand;
}
@@ -504,8 +504,8 @@ jinit_downsampler (j_compress_ptr cinfo)
} else
#endif
downsample->methods[ci] = h2v2_downsample;
- } else if (DIVISION(cinfo->max_h_samp_factor, compptr->h_samp_factor) == 0 &&
- DIVISION(cinfo->max_v_samp_factor, compptr->v_samp_factor) == 0) {
+ } else if (INT_UMOD(cinfo->max_h_samp_factor, compptr->h_samp_factor) == 0 &&
+ INT_UMOD(cinfo->max_v_samp_factor, compptr->v_samp_factor) == 0) {
smoothok = FALSE;
downsample->methods[ci] = int_downsample;
} else
@@ -516,7 +516,5 @@ jinit_downsampler (j_compress_ptr cinfo)
if (cinfo->smoothing_factor && !smoothok)
TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
#endif
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/jdapimin.c b/test/monniaux/jpeg-6b/jdapimin.c
index fe6c8973..ef09983b 100644
--- a/test/monniaux/jpeg-6b/jdapimin.c
+++ b/test/monniaux/jpeg-6b/jdapimin.c
@@ -116,26 +116,24 @@ default_decompress_parms (j_decompress_ptr cinfo)
/* Guess the input colorspace, and set output colorspace accordingly. */
/* (Wish JPEG committee had provided a real way to specify this...) */
/* Note application may override our guesses. */
+
#ifdef NO_SWITCH
- int numc = cinfo->num_components;
- if (numc == 1) {
+ int choice = cinfo->num_components;
+ if (choice == 1) {
cinfo->jpeg_color_space = JCS_GRAYSCALE;
cinfo->out_color_space = JCS_GRAYSCALE;
- } else if (numc == 3) {
+ } else if (choice == 3) {
if (cinfo->saw_JFIF_marker) {
cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
} else if (cinfo->saw_Adobe_marker) {
- switch (cinfo->Adobe_transform) {
- case 0:
+ int choice2 = cinfo->Adobe_transform;
+ if (choice2 == 0) {
cinfo->jpeg_color_space = JCS_RGB;
- break;
- case 1:
+ } else if (choice2 == 1) {
cinfo->jpeg_color_space = JCS_YCbCr;
- break;
- default:
+ } else {
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
- break;
}
} else {
/* Saw no special markers, try to guess from the component IDs */
@@ -154,26 +152,23 @@ default_decompress_parms (j_decompress_ptr cinfo)
}
/* Always guess RGB is proper output colorspace. */
cinfo->out_color_space = JCS_RGB;
- } else if (numc == 4) {
+ } else if (choice == 4) {
if (cinfo->saw_Adobe_marker) {
- switch (cinfo->Adobe_transform) {
- case 0:
+ int choice2 = cinfo->Adobe_transform;
+ if (choice2 == 0) {
cinfo->jpeg_color_space = JCS_CMYK;
- break;
- case 2:
+ } else if (choice2 == 2) {
cinfo->jpeg_color_space = JCS_YCCK;
- break;
- default:
+ } else {
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
- break;
}
} else {
/* No special markers, assume straight CMYK. */
cinfo->jpeg_color_space = JCS_CMYK;
}
cinfo->out_color_space = JCS_CMYK;
- } else {
+ } else {
cinfo->jpeg_color_space = JCS_UNKNOWN;
cinfo->out_color_space = JCS_UNKNOWN;
}
@@ -250,7 +245,7 @@ default_decompress_parms (j_decompress_ptr cinfo)
/* Set defaults for other decompression parameters. */
cinfo->scale_num = 1; /* 1:1 scaling */
cinfo->scale_denom = 1;
-#ifndef NO_FLOAT
+#ifdef HAS_FLOAT
cinfo->output_gamma = 1.0;
#endif
cinfo->buffered_image = FALSE;
@@ -355,13 +350,14 @@ jpeg_consume_input (j_decompress_ptr cinfo)
/* NB: every possible DSTATE value should be listed in this switch */
#ifdef NO_SWITCH
- int gstate = cinfo->global_state;
- if (gstate == DSTATE_START) {
+ int choice = cinfo->global_state;
+ if (choice == DSTATE_START) {
/* Start-of-datastream actions: reset appropriate modules */
(*cinfo->inputctl->reset_input_controller) (cinfo);
/* Initialize application's data source module */
(*cinfo->src->init_source) (cinfo);
cinfo->global_state = DSTATE_INHEADER;
+ /*FALLTHROUGH*/
retcode = (*cinfo->inputctl->consume_input) (cinfo);
if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
/* Set up default parameters based on header data */
@@ -369,7 +365,7 @@ jpeg_consume_input (j_decompress_ptr cinfo)
/* Set global state: ready for start_decompress */
cinfo->global_state = DSTATE_READY;
}
- } else if (gstate == DSTATE_INHEADER) {
+ } else if (choice == DSTATE_INHEADER) {
retcode = (*cinfo->inputctl->consume_input) (cinfo);
if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
/* Set up default parameters based on header data */
@@ -377,24 +373,21 @@ jpeg_consume_input (j_decompress_ptr cinfo)
/* Set global state: ready for start_decompress */
cinfo->global_state = DSTATE_READY;
}
- } else if (gstate == DSTATE_READY) {
+ } else if (choice == DSTATE_READY) {
+ /* Can't advance past first SOS until start_decompress is called */
retcode = JPEG_REACHED_SOS;
- } else if (gstate == DSTATE_PRELOAD ||
- gstate == DSTATE_PRESCAN ||
- gstate == DSTATE_SCANNING ||
- gstate == DSTATE_RAW_OK ||
- gstate == DSTATE_BUFIMAGE ||
- gstate == DSTATE_BUFPOST ||
- gstate == DSTATE_STOPPING) {
+ } else if (choice == DSTATE_PRELOAD ||
+ choice == DSTATE_PRESCAN ||
+ choice == DSTATE_SCANNING ||
+ choice == DSTATE_RAW_OK ||
+ choice == DSTATE_BUFIMAGE ||
+ choice == DSTATE_BUFPOST ||
+ choice == DSTATE_STOPPING) {
retcode = (*cinfo->inputctl->consume_input) (cinfo);
-#ifdef TAIL_CALL_MISSING
- retcode += 1;
- retcode -= 1;
-#endif
} else {
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
}
-#else
+#else
switch (cinfo->global_state) {
case DSTATE_START:
/* Start-of-datastream actions: reset appropriate modules */
@@ -429,6 +422,7 @@ jpeg_consume_input (j_decompress_ptr cinfo)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
}
#endif
+ KILL_TAIL_CALL();
return retcode;
}
diff --git a/test/monniaux/jpeg-6b/jdatadst.c b/test/monniaux/jpeg-6b/jdatadst.c
index a3586e67..08fa7b62 100644
--- a/test/monniaux/jpeg-6b/jdatadst.c
+++ b/test/monniaux/jpeg-6b/jdatadst.c
@@ -117,9 +117,7 @@ term_destination (j_compress_ptr cinfo)
/* Make sure we wrote the output file OK */
if (ferror(dest->outfile))
ERREXIT(cinfo, JERR_FILE_WRITE);
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/jdcoefct.c b/test/monniaux/jpeg-6b/jdcoefct.c
index 0aba1d9f..54888720 100644
--- a/test/monniaux/jpeg-6b/jdcoefct.c
+++ b/test/monniaux/jpeg-6b/jdcoefct.c
@@ -349,7 +349,7 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
block_rows = compptr->v_samp_factor;
else {
/* NB: can't use last_row_height here; it is input-side-dependent! */
- block_rows = (int) MODULO(compptr->height_in_blocks, compptr->v_samp_factor);
+ block_rows = (int) INT_MOD(compptr->height_in_blocks, compptr->v_samp_factor);
if (block_rows == 0) block_rows = compptr->v_samp_factor;
}
inverse_DCT = cinfo->idct->inverse_DCT[ci];
@@ -508,7 +508,7 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
last_row = FALSE;
} else {
/* NB: can't use last_row_height here; it is input-side-dependent! */
- block_rows = (int) MODULO(compptr->height_in_blocks, compptr->v_samp_factor);
+ block_rows = (int) INT_MOD(compptr->height_in_blocks, compptr->v_samp_factor);
if (block_rows == 0) block_rows = compptr->v_samp_factor;
access_rows = block_rows; /* this iMCU row only */
last_row = TRUE;
@@ -575,11 +575,11 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
num = 36 * Q00 * (DC4 - DC6);
if (num >= 0) {
- pred = (int) DIVISION(((Q01<<7) + num), (Q01<<8));
+ pred = (int) INT_DIV(((Q01<<7) + num), (Q01<<8));
if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1;
} else {
- pred = (int) DIVISION(((Q01<<7) - num), (Q01<<8));
+ pred = (int) INT_DIV(((Q01<<7) - num), (Q01<<8));
if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1;
pred = -pred;
@@ -590,11 +590,11 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
num = 36 * Q00 * (DC2 - DC8);
if (num >= 0) {
- pred = (int) DIVISION(((Q10<<7) + num), (Q10<<8));
+ pred = (int) INT_DIV(((Q10<<7) + num), (Q10<<8));
if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1;
} else {
- pred = (int) DIVISION(((Q10<<7) - num), (Q10<<8));
+ pred = (int) INT_DIV(((Q10<<7) - num), (Q10<<8));
if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1;
pred = -pred;
@@ -605,11 +605,11 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
if (num >= 0) {
- pred = (int) DIVISION(((Q20<<7) + num), (Q20<<8));
+ pred = (int) INT_DIV(((Q20<<7) + num), (Q20<<8));
if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1;
} else {
- pred = (int) DIVISION(((Q20<<7) - num), (Q20<<8));
+ pred = (int) INT_DIV(((Q20<<7) - num), (Q20<<8));
if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1;
pred = -pred;
@@ -620,11 +620,11 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
if (num >= 0) {
- pred = (int) DIVISION(((Q11<<7) + num), (Q11<<8));
+ pred = (int) INT_DIV(((Q11<<7) + num), (Q11<<8));
if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1;
} else {
- pred = (int) DIVISION(((Q11<<7) - num), (Q11<<8));
+ pred = (int) INT_DIV(((Q11<<7) - num), (Q11<<8));
if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1;
pred = -pred;
@@ -635,11 +635,11 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
if (num >= 0) {
- pred = (int) DIVISION(((Q02<<7) + num), (Q02<<8));
+ pred = (int) INT_DIV(((Q02<<7) + num), (Q02<<8));
if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1;
} else {
- pred = (int) DIVISION(((Q02<<7) - num), (Q02<<8));
+ pred = (int) INT_DIV(((Q02<<7) - num), (Q02<<8));
if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1;
pred = -pred;
diff --git a/test/monniaux/jpeg-6b/jdhuff.c b/test/monniaux/jpeg-6b/jdhuff.c
index 41dab479..b5ba39f7 100644
--- a/test/monniaux/jpeg-6b/jdhuff.c
+++ b/test/monniaux/jpeg-6b/jdhuff.c
@@ -641,8 +641,8 @@ jinit_huff_decoder (j_decompress_ptr cinfo)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(huff_entropy_decoder));
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
- ASSIGN_FUNPTR(entropy->pub.start_pass, start_pass_huff_decoder);
- ASSIGN_FUNPTR(entropy->pub.decode_mcu, decode_mcu);
+ entropy->pub.start_pass = start_pass_huff_decoder;
+ entropy->pub.decode_mcu = decode_mcu;
/* Mark tables unallocated */
for (i = 0; i < NUM_HUFF_TBLS; i++) {
diff --git a/test/monniaux/jpeg-6b/jdinput.c b/test/monniaux/jpeg-6b/jdinput.c
index 471ddcee..8a676164 100644
--- a/test/monniaux/jpeg-6b/jdinput.c
+++ b/test/monniaux/jpeg-6b/jdinput.c
@@ -143,7 +143,7 @@ per_scan_setup (j_decompress_ptr cinfo)
/* For noninterleaved scans, it is convenient to define last_row_height
* as the number of block rows present in the last iMCU row.
*/
- tmp = (int) MODULO(compptr->height_in_blocks, compptr->v_samp_factor);
+ tmp = (int) INT_MOD(compptr->height_in_blocks, compptr->v_samp_factor);
if (tmp == 0) tmp = compptr->v_samp_factor;
compptr->last_row_height = tmp;
@@ -176,10 +176,10 @@ per_scan_setup (j_decompress_ptr cinfo)
compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
/* Figure number of non-dummy blocks in last MCU column & row */
- tmp = (int) MODULO(compptr->width_in_blocks, compptr->MCU_width);
+ tmp = (int) INT_MOD(compptr->width_in_blocks, compptr->MCU_width);
if (tmp == 0) tmp = compptr->MCU_width;
compptr->last_col_width = tmp;
- tmp = (int) MODULO(compptr->height_in_blocks, compptr->MCU_height);
+ tmp = (int) INT_MOD(compptr->height_in_blocks, compptr->MCU_height);
if (tmp == 0) tmp = compptr->MCU_height;
compptr->last_row_height = tmp;
/* Prepare array describing MCU composition */
diff --git a/test/monniaux/jpeg-6b/jdmainct.c b/test/monniaux/jpeg-6b/jdmainct.c
index cd987e05..4d49d26f 100644
--- a/test/monniaux/jpeg-6b/jdmainct.c
+++ b/test/monniaux/jpeg-6b/jdmainct.c
@@ -175,8 +175,9 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {
- rgroup = DIVISION((compptr->v_samp_factor * compptr->DCT_scaled_size),
- cinfo->min_DCT_scaled_size); /* height of a row group of component */
+ rgroup = INT_DIV((compptr->v_samp_factor * compptr->DCT_scaled_size),
+ cinfo->min_DCT_scaled_size);
+ /* height of a row group of component */
/* Get space for pointer lists --- M+4 row groups in each list.
* We alloc both pointer lists with one call to save a few cycles.
*/
@@ -208,8 +209,9 @@ make_funny_pointers (j_decompress_ptr cinfo)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {
- rgroup = DIVISION((compptr->v_samp_factor * compptr->DCT_scaled_size),
- cinfo->min_DCT_scaled_size); /* height of a row group of component */
+ rgroup = INT_DIV((compptr->v_samp_factor * compptr->DCT_scaled_size),
+ cinfo->min_DCT_scaled_size);
+ /* height of a row group of component */
xbuf0 = main->xbuffer[0][ci];
xbuf1 = main->xbuffer[1][ci];
/* First copy the workspace pointers as-is */
@@ -248,8 +250,9 @@ set_wraparound_pointers (j_decompress_ptr cinfo)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {
- rgroup = DIVISION((compptr->v_samp_factor * compptr->DCT_scaled_size),
- cinfo->min_DCT_scaled_size); /* height of a row group of component */
+ rgroup = INT_DIV((compptr->v_samp_factor * compptr->DCT_scaled_size),
+ cinfo->min_DCT_scaled_size);
+ /* height of a row group of component */
xbuf0 = main->xbuffer[0][ci];
xbuf1 = main->xbuffer[1][ci];
for (i = 0; i < rgroup; i++) {
@@ -278,15 +281,15 @@ set_bottom_pointers (j_decompress_ptr cinfo)
ci++, compptr++) {
/* Count sample rows in one iMCU row and in one row group */
iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
- rgroup = DIVISION(iMCUheight, cinfo->min_DCT_scaled_size);
+ rgroup = INT_DIV(iMCUheight, cinfo->min_DCT_scaled_size);
/* Count nondummy sample rows remaining for this component */
- rows_left = (int) MODULO(compptr->downsampled_height, (JDIMENSION) iMCUheight);
+ rows_left = (int) INT_MOD(compptr->downsampled_height, (JDIMENSION) iMCUheight);
if (rows_left == 0) rows_left = iMCUheight;
/* Count nondummy row groups. Should get same answer for each component,
* so we need only do it once.
*/
if (ci == 0) {
- main->rowgroups_avail = (JDIMENSION) (DIVISION(rows_left-1, rgroup + 1));
+ main->rowgroups_avail = (JDIMENSION) (INT_DIV((rows_left-1), rgroup) + 1);
}
/* Duplicate the last real sample row rgroup*2 times; this pads out the
* last partial rowgroup and ensures at least one full rowgroup of context.
@@ -333,9 +336,7 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
break;
}
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
@@ -466,9 +467,7 @@ process_data_crank_post (j_decompress_ptr cinfo,
(*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
(JDIMENSION *) NULL, (JDIMENSION) 0,
output_buf, out_row_ctr, out_rows_avail);
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
#endif /* QUANT_2PASS_SUPPORTED */
@@ -508,8 +507,9 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {
- rgroup = DIVISION((compptr->v_samp_factor * compptr->DCT_scaled_size),
- cinfo->min_DCT_scaled_size); /* height of a row group of component */
+ rgroup = INT_DIV((compptr->v_samp_factor * compptr->DCT_scaled_size),
+ cinfo->min_DCT_scaled_size);
+ /* height of a row group of component */
main->buffer[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE,
compptr->width_in_blocks * compptr->DCT_scaled_size,
diff --git a/test/monniaux/jpeg-6b/jdmarker.c b/test/monniaux/jpeg-6b/jdmarker.c
index ee999f25..71feff86 100644
--- a/test/monniaux/jpeg-6b/jdmarker.c
+++ b/test/monniaux/jpeg-6b/jdmarker.c
@@ -653,9 +653,7 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
/* Start of APP0 does not match "JFIF" or "JFXX", or too short */
TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
}
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
@@ -687,9 +685,7 @@ examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
/* Start of APP14 does not match "Adobe", or too short */
TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
}
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
@@ -1342,9 +1338,7 @@ jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
} else
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
#endif /* SAVE_MARKERS_SUPPORTED */
@@ -1366,7 +1360,5 @@ jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
marker->process_APPn[marker_code - (int) M_APP0] = routine;
else
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/jdmaster.c b/test/monniaux/jpeg-6b/jdmaster.c
index 48df48a5..512bd679 100644
--- a/test/monniaux/jpeg-6b/jdmaster.c
+++ b/test/monniaux/jpeg-6b/jdmaster.c
@@ -529,9 +529,7 @@ jpeg_new_colormap (j_decompress_ptr cinfo)
master->pub.is_dummy_pass = FALSE; /* just in case */
} else
ERREXIT(cinfo, JERR_MODE_CHANGE);
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
#endif /* D_MULTISCAN_FILES_SUPPORTED */
diff --git a/test/monniaux/jpeg-6b/jdphuff.c b/test/monniaux/jpeg-6b/jdphuff.c
index 1750bdd0..22678099 100644
--- a/test/monniaux/jpeg-6b/jdphuff.c
+++ b/test/monniaux/jpeg-6b/jdphuff.c
@@ -648,7 +648,7 @@ jinit_phuff_decoder (j_decompress_ptr cinfo)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(phuff_entropy_decoder));
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
- ASSIGN_FUNPTR(entropy->pub.start_pass, start_pass_phuff_decoder);
+ entropy->pub.start_pass = start_pass_phuff_decoder;
/* Mark derived tables unallocated */
for (i = 0; i < NUM_HUFF_TBLS; i++) {
diff --git a/test/monniaux/jpeg-6b/jdsample.c b/test/monniaux/jpeg-6b/jdsample.c
index 766ca28f..96d56f0c 100644
--- a/test/monniaux/jpeg-6b/jdsample.c
+++ b/test/monniaux/jpeg-6b/jdsample.c
@@ -428,10 +428,10 @@ jinit_upsampler (j_decompress_ptr cinfo)
/* Compute size of an "input group" after IDCT scaling. This many samples
* are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
*/
- h_in_group = DIVISION((compptr->h_samp_factor * compptr->DCT_scaled_size),
- cinfo->min_DCT_scaled_size);
- v_in_group = DIVISION((compptr->v_samp_factor * compptr->DCT_scaled_size),
- cinfo->min_DCT_scaled_size);
+ h_in_group = INT_DIV((compptr->h_samp_factor * compptr->DCT_scaled_size),
+ cinfo->min_DCT_scaled_size);
+ v_in_group = INT_DIV((compptr->v_samp_factor * compptr->DCT_scaled_size),
+ cinfo->min_DCT_scaled_size);
h_out_group = cinfo->max_h_samp_factor;
v_out_group = cinfo->max_v_samp_factor;
upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
@@ -459,12 +459,12 @@ jinit_upsampler (j_decompress_ptr cinfo)
upsample->pub.need_context_rows = TRUE;
} else
upsample->methods[ci] = h2v2_upsample;
- } else if (MODULO(h_out_group, h_in_group) == 0 &&
- MODULO(v_out_group, v_in_group) == 0) {
+ } else if (INT_MOD(h_out_group, h_in_group) == 0 &&
+ INT_MOD(v_out_group, v_in_group) == 0) {
/* Generic integral-factors upsampling method */
upsample->methods[ci] = int_upsample;
- upsample->h_expand[ci] = (UINT8) DIVISION(h_out_group, h_in_group);
- upsample->v_expand[ci] = (UINT8) DIVISION(v_out_group, v_in_group);
+ upsample->h_expand[ci] = (UINT8) INT_DIV(h_out_group, h_in_group);
+ upsample->v_expand[ci] = (UINT8) INT_DIV(v_out_group, v_in_group);
} else
ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
if (need_buffer) {
diff --git a/test/monniaux/jpeg-6b/jerror.c b/test/monniaux/jpeg-6b/jerror.c
index b5221a85..e1b585e9 100644
--- a/test/monniaux/jpeg-6b/jerror.c
+++ b/test/monniaux/jpeg-6b/jerror.c
@@ -1,255 +1,253 @@
-/*
- * jerror.c
- *
- * Copyright (C) 1991-1998, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains simple error-reporting and trace-message routines.
- * These are suitable for Unix-like systems and others where writing to
- * stderr is the right thing to do. Many applications will want to replace
- * some or all of these routines.
- *
- * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile,
- * you get a Windows-specific hack to display error messages in a dialog box.
- * It ain't much, but it beats dropping error messages into the bit bucket,
- * which is what happens to output to stderr under most Windows C compilers.
- *
- * These routines are used by both the compression and decompression code.
- */
-
-/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
-#include "jinclude.h"
-#include "jpeglib.h"
-#include "jversion.h"
-#include "jerror.h"
-
-#ifdef USE_WINDOWS_MESSAGEBOX
-#include <windows.h>
-#endif
-
-#ifndef EXIT_FAILURE /* define exit() codes if not provided */
-#define EXIT_FAILURE 1
-#endif
-
-
-/*
- * Create the message string table.
- * We do this from the master message list in jerror.h by re-reading
- * jerror.h with a suitable definition for macro JMESSAGE.
- * The message table is made an external symbol just in case any applications
- * want to refer to it directly.
- */
-
-#ifdef NEED_SHORT_EXTERNAL_NAMES
-#define jpeg_std_message_table jMsgTable
-#endif
-
-#define JMESSAGE(code,string) string ,
-
-const char * const jpeg_std_message_table[] = {
-#include "jerror.h"
- NULL
-};
-
-
-/*
- * Error exit handler: must not return to caller.
- *
- * Applications may override this if they want to get control back after
- * an error. Typically one would longjmp somewhere instead of exiting.
- * The setjmp buffer can be made a private field within an expanded error
- * handler object. Note that the info needed to generate an error message
- * is stored in the error object, so you can generate the message now or
- * later, at your convenience.
- * You should make sure that the JPEG object is cleaned up (with jpeg_abort
- * or jpeg_destroy) at some point.
- */
-
-METHODDEF(void)
-error_exit (j_common_ptr cinfo)
-{
- /* Always display the message */
- (*cinfo->err->output_message) (cinfo);
-
- /* Let the memory manager delete any temp files before we die */
- jpeg_destroy(cinfo);
-
- exit(EXIT_FAILURE);
-}
-
-
-/*
- * Actual output of an error or trace message.
- * Applications may override this method to send JPEG messages somewhere
- * other than stderr.
- *
- * On Windows, printing to stderr is generally completely useless,
- * so we provide optional code to produce an error-dialog popup.
- * Most Windows applications will still prefer to override this routine,
- * but if they don't, it'll do something at least marginally useful.
- *
- * NOTE: to use the library in an environment that doesn't support the
- * C stdio library, you may have to delete the call to fprintf() entirely,
- * not just not use this routine.
- */
-
-METHODDEF(void)
-output_message (j_common_ptr cinfo)
-{
- char buffer[JMSG_LENGTH_MAX];
-
- /* Create the message */
- (*cinfo->err->format_message) (cinfo, buffer);
-
-#ifdef USE_WINDOWS_MESSAGEBOX
- /* Display it in a message dialog box */
- MessageBox(GetActiveWindow(), buffer, "JPEG Library Error",
- MB_OK | MB_ICONERROR);
-#else
- /* Send it to stderr, adding a newline */
- fprintf(stderr, "%s\n", buffer);
-#endif
-}
-
-
-/*
- * Decide whether to emit a trace or warning message.
- * msg_level is one of:
- * -1: recoverable corrupt-data warning, may want to abort.
- * 0: important advisory messages (always display to user).
- * 1: first level of tracing detail.
- * 2,3,...: successively more detailed tracing messages.
- * An application might override this method if it wanted to abort on warnings
- * or change the policy about which messages to display.
- */
-
-METHODDEF(void)
-emit_message (j_common_ptr cinfo, int msg_level)
-{
- struct jpeg_error_mgr * err = cinfo->err;
-
- if (msg_level < 0) {
- /* It's a warning message. Since corrupt files may generate many warnings,
- * the policy implemented here is to show only the first warning,
- * unless trace_level >= 3.
- */
- if (err->num_warnings == 0 || err->trace_level >= 3)
- (*err->output_message) (cinfo);
- /* Always count warnings in num_warnings. */
- err->num_warnings++;
- } else {
- /* It's a trace message. Show it if trace_level >= msg_level. */
- if (err->trace_level >= msg_level)
- (*err->output_message) (cinfo);
- }
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
-}
-
-
-/*
- * Format a message string for the most recent JPEG error or message.
- * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX
- * characters. Note that no '\n' character is added to the string.
- * Few applications should need to override this method.
- */
-
-METHODDEF(void)
-format_message (j_common_ptr cinfo, char * buffer)
-{
- struct jpeg_error_mgr * err = cinfo->err;
- int msg_code = err->msg_code;
- const char * msgtext = NULL;
- const char * msgptr;
- char ch;
- boolean isstring;
-
- /* Look up message string in proper table */
- if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
- msgtext = err->jpeg_message_table[msg_code];
- } else if (err->addon_message_table != NULL &&
- msg_code >= err->first_addon_message &&
- msg_code <= err->last_addon_message) {
- msgtext = err->addon_message_table[msg_code - err->first_addon_message];
- }
-
- /* Defend against bogus message number */
- if (msgtext == NULL) {
- err->msg_parm.i[0] = msg_code;
- msgtext = err->jpeg_message_table[0];
- }
-
- /* Check for string parameter, as indicated by %s in the message text */
- isstring = FALSE;
- msgptr = msgtext;
- while ((ch = *msgptr++) != '\0') {
- if (ch == '%') {
- if (*msgptr == 's') isstring = TRUE;
- break;
- }
- }
-
- /* Format the message into the passed buffer */
- if (isstring)
- sprintf(buffer, msgtext, err->msg_parm.s);
- else
- sprintf(buffer, msgtext,
- err->msg_parm.i[0], err->msg_parm.i[1],
- err->msg_parm.i[2], err->msg_parm.i[3],
- err->msg_parm.i[4], err->msg_parm.i[5],
- err->msg_parm.i[6], err->msg_parm.i[7]);
-}
-
-
-/*
- * Reset error state variables at start of a new image.
- * This is called during compression startup to reset trace/error
- * processing to default state, without losing any application-specific
- * method pointers. An application might possibly want to override
- * this method if it has additional error processing state.
- */
-
-METHODDEF(void)
-reset_error_mgr (j_common_ptr cinfo)
-{
- cinfo->err->num_warnings = 0;
- /* trace_level is not reset since it is an application-supplied parameter */
- cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
-}
-
-
-/*
- * Fill in the standard error-handling methods in a jpeg_error_mgr object.
- * Typical call is:
- * struct jpeg_compress_struct cinfo;
- * struct jpeg_error_mgr err;
- *
- * cinfo.err = jpeg_std_error(&err);
- * after which the application may override some of the methods.
- */
-
-GLOBAL(struct jpeg_error_mgr *)
-jpeg_std_error (struct jpeg_error_mgr * err)
-{
- err->error_exit = error_exit;
- err->emit_message = emit_message;
- err->output_message = output_message;
- err->format_message = format_message;
- err->reset_error_mgr = reset_error_mgr;
-
- err->trace_level = 0; /* default = no tracing */
- err->num_warnings = 0; /* no warnings emitted yet */
- err->msg_code = 0; /* may be useful as a flag for "no error" */
-
- /* Initialize message table pointers */
- err->jpeg_message_table = jpeg_std_message_table;
- err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
-
- err->addon_message_table = NULL;
- err->first_addon_message = 0; /* for safety */
- err->last_addon_message = 0;
-
- return err;
-}
+/*
+ * jerror.c
+ *
+ * Copyright (C) 1991-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains simple error-reporting and trace-message routines.
+ * These are suitable for Unix-like systems and others where writing to
+ * stderr is the right thing to do. Many applications will want to replace
+ * some or all of these routines.
+ *
+ * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile,
+ * you get a Windows-specific hack to display error messages in a dialog box.
+ * It ain't much, but it beats dropping error messages into the bit bucket,
+ * which is what happens to output to stderr under most Windows C compilers.
+ *
+ * These routines are used by both the compression and decompression code.
+ */
+
+/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jversion.h"
+#include "jerror.h"
+
+#ifdef USE_WINDOWS_MESSAGEBOX
+#include <windows.h>
+#endif
+
+#ifndef EXIT_FAILURE /* define exit() codes if not provided */
+#define EXIT_FAILURE 1
+#endif
+
+
+/*
+ * Create the message string table.
+ * We do this from the master message list in jerror.h by re-reading
+ * jerror.h with a suitable definition for macro JMESSAGE.
+ * The message table is made an external symbol just in case any applications
+ * want to refer to it directly.
+ */
+
+#ifdef NEED_SHORT_EXTERNAL_NAMES
+#define jpeg_std_message_table jMsgTable
+#endif
+
+#define JMESSAGE(code,string) string ,
+
+const char * const jpeg_std_message_table[] = {
+#include "jerror.h"
+ NULL
+};
+
+
+/*
+ * Error exit handler: must not return to caller.
+ *
+ * Applications may override this if they want to get control back after
+ * an error. Typically one would longjmp somewhere instead of exiting.
+ * The setjmp buffer can be made a private field within an expanded error
+ * handler object. Note that the info needed to generate an error message
+ * is stored in the error object, so you can generate the message now or
+ * later, at your convenience.
+ * You should make sure that the JPEG object is cleaned up (with jpeg_abort
+ * or jpeg_destroy) at some point.
+ */
+
+METHODDEF(void)
+error_exit (j_common_ptr cinfo)
+{
+ /* Always display the message */
+ (*cinfo->err->output_message) (cinfo);
+
+ /* Let the memory manager delete any temp files before we die */
+ jpeg_destroy(cinfo);
+
+ exit(EXIT_FAILURE);
+}
+
+
+/*
+ * Actual output of an error or trace message.
+ * Applications may override this method to send JPEG messages somewhere
+ * other than stderr.
+ *
+ * On Windows, printing to stderr is generally completely useless,
+ * so we provide optional code to produce an error-dialog popup.
+ * Most Windows applications will still prefer to override this routine,
+ * but if they don't, it'll do something at least marginally useful.
+ *
+ * NOTE: to use the library in an environment that doesn't support the
+ * C stdio library, you may have to delete the call to fprintf() entirely,
+ * not just not use this routine.
+ */
+
+METHODDEF(void)
+output_message (j_common_ptr cinfo)
+{
+ char buffer[JMSG_LENGTH_MAX];
+
+ /* Create the message */
+ (*cinfo->err->format_message) (cinfo, buffer);
+
+#ifdef USE_WINDOWS_MESSAGEBOX
+ /* Display it in a message dialog box */
+ MessageBox(GetActiveWindow(), buffer, "JPEG Library Error",
+ MB_OK | MB_ICONERROR);
+#else
+ /* Send it to stderr, adding a newline */
+ fprintf(stderr, "%s\n", buffer);
+#endif
+}
+
+
+/*
+ * Decide whether to emit a trace or warning message.
+ * msg_level is one of:
+ * -1: recoverable corrupt-data warning, may want to abort.
+ * 0: important advisory messages (always display to user).
+ * 1: first level of tracing detail.
+ * 2,3,...: successively more detailed tracing messages.
+ * An application might override this method if it wanted to abort on warnings
+ * or change the policy about which messages to display.
+ */
+
+METHODDEF(void)
+emit_message (j_common_ptr cinfo, int msg_level)
+{
+ struct jpeg_error_mgr * err = cinfo->err;
+
+ if (msg_level < 0) {
+ /* It's a warning message. Since corrupt files may generate many warnings,
+ * the policy implemented here is to show only the first warning,
+ * unless trace_level >= 3.
+ */
+ if (err->num_warnings == 0 || err->trace_level >= 3)
+ (*err->output_message) (cinfo);
+ /* Always count warnings in num_warnings. */
+ err->num_warnings++;
+ } else {
+ /* It's a trace message. Show it if trace_level >= msg_level. */
+ if (err->trace_level >= msg_level)
+ (*err->output_message) (cinfo);
+ }
+ KILL_TAIL_CALL();
+}
+
+
+/*
+ * Format a message string for the most recent JPEG error or message.
+ * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX
+ * characters. Note that no '\n' character is added to the string.
+ * Few applications should need to override this method.
+ */
+
+METHODDEF(void)
+format_message (j_common_ptr cinfo, char * buffer)
+{
+ struct jpeg_error_mgr * err = cinfo->err;
+ int msg_code = err->msg_code;
+ const char * msgtext = NULL;
+ const char * msgptr;
+ char ch;
+ boolean isstring;
+
+ /* Look up message string in proper table */
+ if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
+ msgtext = err->jpeg_message_table[msg_code];
+ } else if (err->addon_message_table != NULL &&
+ msg_code >= err->first_addon_message &&
+ msg_code <= err->last_addon_message) {
+ msgtext = err->addon_message_table[msg_code - err->first_addon_message];
+ }
+
+ /* Defend against bogus message number */
+ if (msgtext == NULL) {
+ err->msg_parm.i[0] = msg_code;
+ msgtext = err->jpeg_message_table[0];
+ }
+
+ /* Check for string parameter, as indicated by %s in the message text */
+ isstring = FALSE;
+ msgptr = msgtext;
+ while ((ch = *msgptr++) != '\0') {
+ if (ch == '%') {
+ if (*msgptr == 's') isstring = TRUE;
+ break;
+ }
+ }
+
+ /* Format the message into the passed buffer */
+ if (isstring)
+ sprintf(buffer, msgtext, err->msg_parm.s);
+ else
+ sprintf(buffer, msgtext,
+ err->msg_parm.i[0], err->msg_parm.i[1],
+ err->msg_parm.i[2], err->msg_parm.i[3],
+ err->msg_parm.i[4], err->msg_parm.i[5],
+ err->msg_parm.i[6], err->msg_parm.i[7]);
+}
+
+
+/*
+ * Reset error state variables at start of a new image.
+ * This is called during compression startup to reset trace/error
+ * processing to default state, without losing any application-specific
+ * method pointers. An application might possibly want to override
+ * this method if it has additional error processing state.
+ */
+
+METHODDEF(void)
+reset_error_mgr (j_common_ptr cinfo)
+{
+ cinfo->err->num_warnings = 0;
+ /* trace_level is not reset since it is an application-supplied parameter */
+ cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
+}
+
+
+/*
+ * Fill in the standard error-handling methods in a jpeg_error_mgr object.
+ * Typical call is:
+ * struct jpeg_compress_struct cinfo;
+ * struct jpeg_error_mgr err;
+ *
+ * cinfo.err = jpeg_std_error(&err);
+ * after which the application may override some of the methods.
+ */
+
+GLOBAL(struct jpeg_error_mgr *)
+jpeg_std_error (struct jpeg_error_mgr * err)
+{
+ err->error_exit = error_exit;
+ err->emit_message = emit_message;
+ err->output_message = output_message;
+ err->format_message = format_message;
+ err->reset_error_mgr = reset_error_mgr;
+
+ err->trace_level = 0; /* default = no tracing */
+ err->num_warnings = 0; /* no warnings emitted yet */
+ err->msg_code = 0; /* may be useful as a flag for "no error" */
+
+ /* Initialize message table pointers */
+ err->jpeg_message_table = jpeg_std_message_table;
+ err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
+
+ err->addon_message_table = NULL;
+ err->first_addon_message = 0; /* for safety */
+ err->last_addon_message = 0;
+
+ return err;
+}
diff --git a/test/monniaux/jpeg-6b/jmemmgr.c b/test/monniaux/jpeg-6b/jmemmgr.c
index 925890a3..01533319 100644
--- a/test/monniaux/jpeg-6b/jmemmgr.c
+++ b/test/monniaux/jpeg-6b/jmemmgr.c
@@ -1,1120 +1,1119 @@
-/*
- * jmemmgr.c
- *
- * Copyright (C) 1991-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains the JPEG system-independent memory management
- * routines. This code is usable across a wide variety of machines; most
- * of the system dependencies have been isolated in a separate file.
- * The major functions provided here are:
- * * pool-based allocation and freeing of memory;
- * * policy decisions about how to divide available memory among the
- * virtual arrays;
- * * control logic for swapping virtual arrays between main memory and
- * backing storage.
- * The separate system-dependent file provides the actual backing-storage
- * access code, and it contains the policy decision about how much total
- * main memory to use.
- * This file is system-dependent in the sense that some of its functions
- * are unnecessary in some systems. For example, if there is enough virtual
- * memory so that backing storage will never be used, much of the virtual
- * array control logic could be removed. (Of course, if you have that much
- * memory then you shouldn't care about a little bit of unused code...)
- */
-
-#define JPEG_INTERNALS
-#define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
-#include "jinclude.h"
-#include "jpeglib.h"
-#include "jmemsys.h" /* import the system-dependent declarations */
-
-#ifndef NO_GETENV
-#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
-extern char * getenv JPP((const char * name));
-#endif
-#endif
-
-
-/*
- * Some important notes:
- * The allocation routines provided here must never return NULL.
- * They should exit to error_exit if unsuccessful.
- *
- * It's not a good idea to try to merge the sarray and barray routines,
- * even though they are textually almost the same, because samples are
- * usually stored as bytes while coefficients are shorts or ints. Thus,
- * in machines where byte pointers have a different representation from
- * word pointers, the resulting machine code could not be the same.
- */
-
-
-/*
- * Many machines require storage alignment: longs must start on 4-byte
- * boundaries, doubles on 8-byte boundaries, etc. On such machines, malloc()
- * always returns pointers that are multiples of the worst-case alignment
- * requirement, and we had better do so too.
- * There isn't any really portable way to determine the worst-case alignment
- * requirement. This module assumes that the alignment requirement is
- * multiples of sizeof(ALIGN_TYPE).
- * By default, we define ALIGN_TYPE as double. This is necessary on some
- * workstations (where doubles really do need 8-byte alignment) and will work
- * fine on nearly everything. If your machine has lesser alignment needs,
- * you can save a few bytes by making ALIGN_TYPE smaller.
- * The only place I know of where this will NOT work is certain Macintosh
- * 680x0 compilers that define double as a 10-byte IEEE extended float.
- * Doing 10-byte alignment is counterproductive because longwords won't be
- * aligned well. Put "#define ALIGN_TYPE long" in jconfig.h if you have
- * such a compiler.
- */
-
-#ifndef ALIGN_TYPE /* so can override from jconfig.h */
-#define ALIGN_TYPE double
-#endif
-
-
-/*
- * We allocate objects from "pools", where each pool is gotten with a single
- * request to jpeg_get_small() or jpeg_get_large(). There is no per-object
- * overhead within a pool, except for alignment padding. Each pool has a
- * header with a link to the next pool of the same class.
- * Small and large pool headers are identical except that the latter's
- * link pointer must be FAR on 80x86 machines.
- * Notice that the "real" header fields are union'ed with a dummy ALIGN_TYPE
- * field. This forces the compiler to make SIZEOF(small_pool_hdr) a multiple
- * of the alignment requirement of ALIGN_TYPE.
- */
-
-typedef union small_pool_struct * small_pool_ptr;
-
-typedef union small_pool_struct {
- struct {
- small_pool_ptr next; /* next in list of pools */
- size_t bytes_used; /* how many bytes already used within pool */
- size_t bytes_left; /* bytes still available in this pool */
- } hdr;
- ALIGN_TYPE dummy; /* included in union to ensure alignment */
-} small_pool_hdr;
-
-typedef union large_pool_struct FAR * large_pool_ptr;
-
-typedef union large_pool_struct {
- struct {
- large_pool_ptr next; /* next in list of pools */
- size_t bytes_used; /* how many bytes already used within pool */
- size_t bytes_left; /* bytes still available in this pool */
- } hdr;
- ALIGN_TYPE dummy; /* included in union to ensure alignment */
-} large_pool_hdr;
-
-
-/*
- * Here is the full definition of a memory manager object.
- */
-
-typedef struct {
- struct jpeg_memory_mgr pub; /* public fields */
-
- /* Each pool identifier (lifetime class) names a linked list of pools. */
- small_pool_ptr small_list[JPOOL_NUMPOOLS];
- large_pool_ptr large_list[JPOOL_NUMPOOLS];
-
- /* Since we only have one lifetime class of virtual arrays, only one
- * linked list is necessary (for each datatype). Note that the virtual
- * array control blocks being linked together are actually stored somewhere
- * in the small-pool list.
- */
- jvirt_sarray_ptr virt_sarray_list;
- jvirt_barray_ptr virt_barray_list;
-
- /* This counts total space obtained from jpeg_get_small/large */
- long total_space_allocated;
-
- /* alloc_sarray and alloc_barray set this value for use by virtual
- * array routines.
- */
- JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
-} my_memory_mgr;
-
-typedef my_memory_mgr * my_mem_ptr;
-
-
-/*
- * The control blocks for virtual arrays.
- * Note that these blocks are allocated in the "small" pool area.
- * System-dependent info for the associated backing store (if any) is hidden
- * inside the backing_store_info struct.
- */
-
-struct jvirt_sarray_control {
- JSAMPARRAY mem_buffer; /* => the in-memory buffer */
- JDIMENSION rows_in_array; /* total virtual array height */
- JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
- JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
- JDIMENSION rows_in_mem; /* height of memory buffer */
- JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
- JDIMENSION cur_start_row; /* first logical row # in the buffer */
- JDIMENSION first_undef_row; /* row # of first uninitialized row */
- boolean pre_zero; /* pre-zero mode requested? */
- boolean dirty; /* do current buffer contents need written? */
- boolean b_s_open; /* is backing-store data valid? */
- jvirt_sarray_ptr next; /* link to next virtual sarray control block */
- backing_store_info b_s_info; /* System-dependent control info */
-};
-
-struct jvirt_barray_control {
- JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
- JDIMENSION rows_in_array; /* total virtual array height */
- JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
- JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
- JDIMENSION rows_in_mem; /* height of memory buffer */
- JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
- JDIMENSION cur_start_row; /* first logical row # in the buffer */
- JDIMENSION first_undef_row; /* row # of first uninitialized row */
- boolean pre_zero; /* pre-zero mode requested? */
- boolean dirty; /* do current buffer contents need written? */
- boolean b_s_open; /* is backing-store data valid? */
- jvirt_barray_ptr next; /* link to next virtual barray control block */
- backing_store_info b_s_info; /* System-dependent control info */
-};
-
-
-#ifdef MEM_STATS /* optional extra stuff for statistics */
-
-LOCAL(void)
-print_mem_stats (j_common_ptr cinfo, int pool_id)
-{
- my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
- small_pool_ptr shdr_ptr;
- large_pool_ptr lhdr_ptr;
-
- /* Since this is only a debugging stub, we can cheat a little by using
- * fprintf directly rather than going through the trace message code.
- * This is helpful because message parm array can't handle longs.
- */
- fprintf(stderr, "Freeing pool %d, total space = %ld\n",
- pool_id, mem->total_space_allocated);
-
- for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
- lhdr_ptr = lhdr_ptr->hdr.next) {
- fprintf(stderr, " Large chunk used %ld\n",
- (long) lhdr_ptr->hdr.bytes_used);
- }
-
- for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
- shdr_ptr = shdr_ptr->hdr.next) {
- fprintf(stderr, " Small chunk used %ld free %ld\n",
- (long) shdr_ptr->hdr.bytes_used,
- (long) shdr_ptr->hdr.bytes_left);
- }
-}
-
-#endif /* MEM_STATS */
-
-
-LOCAL(void)
-out_of_memory (j_common_ptr cinfo, int which)
-/* Report an out-of-memory error and stop execution */
-/* If we compiled MEM_STATS support, report alloc requests before dying */
-{
-#ifdef MEM_STATS
- cinfo->err->trace_level = 2; /* force self_destruct to report stats */
-#endif
- ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
- KILL_TAIL_CALL
-}
-
-
-/*
- * Allocation of "small" objects.
- *
- * For these, we use pooled storage. When a new pool must be created,
- * we try to get enough space for the current request plus a "slop" factor,
- * where the slop will be the amount of leftover space in the new pool.
- * The speed vs. space tradeoff is largely determined by the slop values.
- * A different slop value is provided for each pool class (lifetime),
- * and we also distinguish the first pool of a class from later ones.
- * NOTE: the values given work fairly well on both 16- and 32-bit-int
- * machines, but may be too small if longs are 64 bits or more.
- */
-
-static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
-{
- 1600, /* first PERMANENT pool */
- 16000 /* first IMAGE pool */
-};
-
-static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
-{
- 0, /* additional PERMANENT pools */
- 5000 /* additional IMAGE pools */
-};
-
-#define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
-
-
-METHODDEF(void *)
-alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
-/* Allocate a "small" object */
-{
- my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
- small_pool_ptr hdr_ptr, prev_hdr_ptr;
- char * data_ptr;
- size_t odd_bytes, min_request, slop;
-
- /* Check for unsatisfiable request (do now to ensure no overflow below) */
- if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
- out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
-
- /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
- odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
- if (odd_bytes > 0)
- sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
-
- /* See if space is available in any existing pool */
- if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
- ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
- prev_hdr_ptr = NULL;
- hdr_ptr = mem->small_list[pool_id];
- while (hdr_ptr != NULL) {
- if (hdr_ptr->hdr.bytes_left >= sizeofobject)
- break; /* found pool with enough space */
- prev_hdr_ptr = hdr_ptr;
- hdr_ptr = hdr_ptr->hdr.next;
- }
-
- /* Time to make a new pool? */
- if (hdr_ptr == NULL) {
- /* min_request is what we need now, slop is what will be leftover */
- min_request = sizeofobject + SIZEOF(small_pool_hdr);
- if (prev_hdr_ptr == NULL) /* first pool in class? */
- slop = first_pool_slop[pool_id];
- else
- slop = extra_pool_slop[pool_id];
- /* Don't ask for more than MAX_ALLOC_CHUNK */
- if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
- slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
- /* Try to get space, if fail reduce slop and try again */
- for (;;) {
- hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
- if (hdr_ptr != NULL)
- break;
- slop /= 2;
- if (slop < MIN_SLOP) /* give up when it gets real small */
- out_of_memory(cinfo, 2); /* jpeg_get_small failed */
- }
- mem->total_space_allocated += min_request + slop;
- /* Success, initialize the new pool header and add to end of list */
- hdr_ptr->hdr.next = NULL;
- hdr_ptr->hdr.bytes_used = 0;
- hdr_ptr->hdr.bytes_left = sizeofobject + slop;
- if (prev_hdr_ptr == NULL) /* first pool in class? */
- mem->small_list[pool_id] = hdr_ptr;
- else
- prev_hdr_ptr->hdr.next = hdr_ptr;
- }
-
- /* OK, allocate the object from the current pool */
- data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
- data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
- hdr_ptr->hdr.bytes_used += sizeofobject;
- hdr_ptr->hdr.bytes_left -= sizeofobject;
-
- return (void *) data_ptr;
-}
-
-
-/*
- * Allocation of "large" objects.
- *
- * The external semantics of these are the same as "small" objects,
- * except that FAR pointers are used on 80x86. However the pool
- * management heuristics are quite different. We assume that each
- * request is large enough that it may as well be passed directly to
- * jpeg_get_large; the pool management just links everything together
- * so that we can free it all on demand.
- * Note: the major use of "large" objects is in JSAMPARRAY and JBLOCKARRAY
- * structures. The routines that create these structures (see below)
- * deliberately bunch rows together to ensure a large request size.
- */
-
-METHODDEF(void FAR *)
-alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
-/* Allocate a "large" object */
-{
- my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
- large_pool_ptr hdr_ptr;
- size_t odd_bytes;
-
- /* Check for unsatisfiable request (do now to ensure no overflow below) */
- if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
- out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
-
- /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
- odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
- if (odd_bytes > 0)
- sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
-
- /* Always make a new pool */
- if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
- ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
-
- hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
- SIZEOF(large_pool_hdr));
- if (hdr_ptr == NULL)
- out_of_memory(cinfo, 4); /* jpeg_get_large failed */
- mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
-
- /* Success, initialize the new pool header and add to list */
- hdr_ptr->hdr.next = mem->large_list[pool_id];
- /* We maintain space counts in each pool header for statistical purposes,
- * even though they are not needed for allocation.
- */
- hdr_ptr->hdr.bytes_used = sizeofobject;
- hdr_ptr->hdr.bytes_left = 0;
- mem->large_list[pool_id] = hdr_ptr;
-
- return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
-}
-
-
-/*
- * Creation of 2-D sample arrays.
- * The pointers are in near heap, the samples themselves in FAR heap.
- *
- * To minimize allocation overhead and to allow I/O of large contiguous
- * blocks, we allocate the sample rows in groups of as many rows as possible
- * without exceeding MAX_ALLOC_CHUNK total bytes per allocation request.
- * NB: the virtual array control routines, later in this file, know about
- * this chunking of rows. The rowsperchunk value is left in the mem manager
- * object so that it can be saved away if this sarray is the workspace for
- * a virtual array.
- */
-
-METHODDEF(JSAMPARRAY)
-alloc_sarray (j_common_ptr cinfo, int pool_id,
- JDIMENSION samplesperrow, JDIMENSION numrows)
-/* Allocate a 2-D sample array */
-{
- my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
- JSAMPARRAY result;
- JSAMPROW workspace;
- JDIMENSION rowsperchunk, currow, i;
- long ltemp;
-
- /* Calculate max # of rows allowed in one allocation chunk */
- ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
- ((long) samplesperrow * SIZEOF(JSAMPLE));
- if (ltemp <= 0)
- ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
- if (ltemp < (long) numrows)
- rowsperchunk = (JDIMENSION) ltemp;
- else
- rowsperchunk = numrows;
- mem->last_rowsperchunk = rowsperchunk;
-
- /* Get space for row pointers (small object) */
- result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
- (size_t) (numrows * SIZEOF(JSAMPROW)));
-
- /* Get the rows themselves (large objects) */
- currow = 0;
- while (currow < numrows) {
- rowsperchunk = MIN(rowsperchunk, numrows - currow);
- workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
- (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
- * SIZEOF(JSAMPLE)));
- for (i = rowsperchunk; i > 0; i--) {
- result[currow++] = workspace;
- workspace += samplesperrow;
- }
- }
-
- return result;
-}
-
-
-/*
- * Creation of 2-D coefficient-block arrays.
- * This is essentially the same as the code for sample arrays, above.
- */
-
-METHODDEF(JBLOCKARRAY)
-alloc_barray (j_common_ptr cinfo, int pool_id,
- JDIMENSION blocksperrow, JDIMENSION numrows)
-/* Allocate a 2-D coefficient-block array */
-{
- my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
- JBLOCKARRAY result;
- JBLOCKROW workspace;
- JDIMENSION rowsperchunk, currow, i;
- long ltemp;
-
- /* Calculate max # of rows allowed in one allocation chunk */
- ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
- ((long) blocksperrow * SIZEOF(JBLOCK));
- if (ltemp <= 0)
- ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
- if (ltemp < (long) numrows)
- rowsperchunk = (JDIMENSION) ltemp;
- else
- rowsperchunk = numrows;
- mem->last_rowsperchunk = rowsperchunk;
-
- /* Get space for row pointers (small object) */
- result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
- (size_t) (numrows * SIZEOF(JBLOCKROW)));
-
- /* Get the rows themselves (large objects) */
- currow = 0;
- while (currow < numrows) {
- rowsperchunk = MIN(rowsperchunk, numrows - currow);
- workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
- (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
- * SIZEOF(JBLOCK)));
- for (i = rowsperchunk; i > 0; i--) {
- result[currow++] = workspace;
- workspace += blocksperrow;
- }
- }
-
- return result;
-}
-
-
-/*
- * About virtual array management:
- *
- * The above "normal" array routines are only used to allocate strip buffers
- * (as wide as the image, but just a few rows high). Full-image-sized buffers
- * are handled as "virtual" arrays. The array is still accessed a strip at a
- * time, but the memory manager must save the whole array for repeated
- * accesses. The intended implementation is that there is a strip buffer in
- * memory (as high as is possible given the desired memory limit), plus a
- * backing file that holds the rest of the array.
- *
- * The request_virt_array routines are told the total size of the image and
- * the maximum number of rows that will be accessed at once. The in-memory
- * buffer must be at least as large as the maxaccess value.
- *
- * The request routines create control blocks but not the in-memory buffers.
- * That is postponed until realize_virt_arrays is called. At that time the
- * total amount of space needed is known (approximately, anyway), so free
- * memory can be divided up fairly.
- *
- * The access_virt_array routines are responsible for making a specific strip
- * area accessible (after reading or writing the backing file, if necessary).
- * Note that the access routines are told whether the caller intends to modify
- * the accessed strip; during a read-only pass this saves having to rewrite
- * data to disk. The access routines are also responsible for pre-zeroing
- * any newly accessed rows, if pre-zeroing was requested.
- *
- * In current usage, the access requests are usually for nonoverlapping
- * strips; that is, successive access start_row numbers differ by exactly
- * num_rows = maxaccess. This means we can get good performance with simple
- * buffer dump/reload logic, by making the in-memory buffer be a multiple
- * of the access height; then there will never be accesses across bufferload
- * boundaries. The code will still work with overlapping access requests,
- * but it doesn't handle bufferload overlaps very efficiently.
- */
-
-
-METHODDEF(jvirt_sarray_ptr)
-request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
- JDIMENSION samplesperrow, JDIMENSION numrows,
- JDIMENSION maxaccess)
-/* Request a virtual 2-D sample array */
-{
- my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
- jvirt_sarray_ptr result;
-
- /* Only IMAGE-lifetime virtual arrays are currently supported */
- if (pool_id != JPOOL_IMAGE)
- ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
-
- /* get control block */
- result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
- SIZEOF(struct jvirt_sarray_control));
-
- result->mem_buffer = NULL; /* marks array not yet realized */
- result->rows_in_array = numrows;
- result->samplesperrow = samplesperrow;
- result->maxaccess = maxaccess;
- result->pre_zero = pre_zero;
- result->b_s_open = FALSE; /* no associated backing-store object */
- result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
- mem->virt_sarray_list = result;
-
- return result;
-}
-
-
-METHODDEF(jvirt_barray_ptr)
-request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
- JDIMENSION blocksperrow, JDIMENSION numrows,
- JDIMENSION maxaccess)
-/* Request a virtual 2-D coefficient-block array */
-{
- my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
- jvirt_barray_ptr result;
-
- /* Only IMAGE-lifetime virtual arrays are currently supported */
- if (pool_id != JPOOL_IMAGE)
- ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
-
- /* get control block */
- result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
- SIZEOF(struct jvirt_barray_control));
-
- result->mem_buffer = NULL; /* marks array not yet realized */
- result->rows_in_array = numrows;
- result->blocksperrow = blocksperrow;
- result->maxaccess = maxaccess;
- result->pre_zero = pre_zero;
- result->b_s_open = FALSE; /* no associated backing-store object */
- result->next = mem->virt_barray_list; /* add to list of virtual arrays */
- mem->virt_barray_list = result;
-
- return result;
-}
-
-
-METHODDEF(void)
-realize_virt_arrays (j_common_ptr cinfo)
-/* Allocate the in-memory buffers for any unrealized virtual arrays */
-{
- my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
- long space_per_minheight, maximum_space, avail_mem;
- long minheights, max_minheights;
- jvirt_sarray_ptr sptr;
- jvirt_barray_ptr bptr;
-
- /* Compute the minimum space needed (maxaccess rows in each buffer)
- * and the maximum space needed (full image height in each buffer).
- * These may be of use to the system-dependent jpeg_mem_available routine.
- */
- space_per_minheight = 0;
- maximum_space = 0;
- for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
- if (sptr->mem_buffer == NULL) { /* if not realized yet */
- space_per_minheight += (long) sptr->maxaccess *
- (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
- maximum_space += (long) sptr->rows_in_array *
- (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
- }
- }
- for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
- if (bptr->mem_buffer == NULL) { /* if not realized yet */
- space_per_minheight += (long) bptr->maxaccess *
- (long) bptr->blocksperrow * SIZEOF(JBLOCK);
- maximum_space += (long) bptr->rows_in_array *
- (long) bptr->blocksperrow * SIZEOF(JBLOCK);
- }
- }
-
- if (space_per_minheight <= 0)
- return; /* no unrealized arrays, no work */
-
- /* Determine amount of memory to actually use; this is system-dependent. */
- avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
- mem->total_space_allocated);
-
- /* If the maximum space needed is available, make all the buffers full
- * height; otherwise parcel it out with the same number of minheights
- * in each buffer.
- */
- if (avail_mem >= maximum_space)
- max_minheights = 1000000000L;
- else {
- max_minheights = DIVISION(avail_mem, space_per_minheight);
- /* If there doesn't seem to be enough space, try to get the minimum
- * anyway. This allows a "stub" implementation of jpeg_mem_available().
- */
- if (max_minheights <= 0)
- max_minheights = 1;
- }
-
- /* Allocate the in-memory buffers and initialize backing store as needed. */
-
- for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
- if (sptr->mem_buffer == NULL) { /* if not realized yet */
- minheights = DIVISION(((long) sptr->rows_in_array - 1L), sptr->maxaccess) + 1L;
- if (minheights <= max_minheights) {
- /* This buffer fits in memory */
- sptr->rows_in_mem = sptr->rows_in_array;
- } else {
- /* It doesn't fit in memory, create backing store. */
- sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
- jpeg_open_backing_store(cinfo, & sptr->b_s_info,
- (long) sptr->rows_in_array *
- (long) sptr->samplesperrow *
- (long) SIZEOF(JSAMPLE));
- sptr->b_s_open = TRUE;
- }
- sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
- sptr->samplesperrow, sptr->rows_in_mem);
- sptr->rowsperchunk = mem->last_rowsperchunk;
- sptr->cur_start_row = 0;
- sptr->first_undef_row = 0;
- sptr->dirty = FALSE;
- }
- }
-
- for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
- if (bptr->mem_buffer == NULL) { /* if not realized yet */
- minheights = DIVISION(((long) bptr->rows_in_array - 1L), bptr->maxaccess) + 1L;
- if (minheights <= max_minheights) {
- /* This buffer fits in memory */
- bptr->rows_in_mem = bptr->rows_in_array;
- } else {
- /* It doesn't fit in memory, create backing store. */
- bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
- jpeg_open_backing_store(cinfo, & bptr->b_s_info,
- (long) bptr->rows_in_array *
- (long) bptr->blocksperrow *
- (long) SIZEOF(JBLOCK));
- bptr->b_s_open = TRUE;
- }
- bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
- bptr->blocksperrow, bptr->rows_in_mem);
- bptr->rowsperchunk = mem->last_rowsperchunk;
- bptr->cur_start_row = 0;
- bptr->first_undef_row = 0;
- bptr->dirty = FALSE;
- }
- }
- KILL_TAIL_CALL
-}
-
-
-LOCAL(void)
-do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
-/* Do backing store read or write of a virtual sample array */
-{
- long bytesperrow, file_offset, byte_count, rows, thisrow, i;
-
- bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
- file_offset = ptr->cur_start_row * bytesperrow;
- /* Loop to read or write each allocation chunk in mem_buffer */
- for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
- /* One chunk, but check for short chunk at end of buffer */
- rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
- /* Transfer no more than is currently defined */
- thisrow = (long) ptr->cur_start_row + i;
- rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
- /* Transfer no more than fits in file */
- rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
- if (rows <= 0) /* this chunk might be past end of file! */
- break;
- byte_count = rows * bytesperrow;
- if (writing)
- (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
- (void FAR *) ptr->mem_buffer[i],
- file_offset, byte_count);
- else
- (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
- (void FAR *) ptr->mem_buffer[i],
- file_offset, byte_count);
- file_offset += byte_count;
- }
-}
-
-
-LOCAL(void)
-do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
-/* Do backing store read or write of a virtual coefficient-block array */
-{
- long bytesperrow, file_offset, byte_count, rows, thisrow, i;
-
- bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
- file_offset = ptr->cur_start_row * bytesperrow;
- /* Loop to read or write each allocation chunk in mem_buffer */
- for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
- /* One chunk, but check for short chunk at end of buffer */
- rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
- /* Transfer no more than is currently defined */
- thisrow = (long) ptr->cur_start_row + i;
- rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
- /* Transfer no more than fits in file */
- rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
- if (rows <= 0) /* this chunk might be past end of file! */
- break;
- byte_count = rows * bytesperrow;
- if (writing)
- (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
- (void FAR *) ptr->mem_buffer[i],
- file_offset, byte_count);
- else
- (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
- (void FAR *) ptr->mem_buffer[i],
- file_offset, byte_count);
- file_offset += byte_count;
- }
-}
-
-
-METHODDEF(JSAMPARRAY)
-access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
- JDIMENSION start_row, JDIMENSION num_rows,
- boolean writable)
-/* Access the part of a virtual sample array starting at start_row */
-/* and extending for num_rows rows. writable is true if */
-/* caller intends to modify the accessed area. */
-{
- JDIMENSION end_row = start_row + num_rows;
- JDIMENSION undef_row;
-
- /* debugging check */
- if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
- ptr->mem_buffer == NULL)
- ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
-
- /* Make the desired part of the virtual array accessible */
- if (start_row < ptr->cur_start_row ||
- end_row > ptr->cur_start_row+ptr->rows_in_mem) {
- if (! ptr->b_s_open)
- ERREXIT(cinfo, JERR_VIRTUAL_BUG);
- /* Flush old buffer contents if necessary */
- if (ptr->dirty) {
- do_sarray_io(cinfo, ptr, TRUE);
- ptr->dirty = FALSE;
- }
- /* Decide what part of virtual array to access.
- * Algorithm: if target address > current window, assume forward scan,
- * load starting at target address. If target address < current window,
- * assume backward scan, load so that target area is top of window.
- * Note that when switching from forward write to forward read, will have
- * start_row = 0, so the limiting case applies and we load from 0 anyway.
- */
- if (start_row > ptr->cur_start_row) {
- ptr->cur_start_row = start_row;
- } else {
- /* use long arithmetic here to avoid overflow & unsigned problems */
- long ltemp;
-
- ltemp = (long) end_row - (long) ptr->rows_in_mem;
- if (ltemp < 0)
- ltemp = 0; /* don't fall off front end of file */
- ptr->cur_start_row = (JDIMENSION) ltemp;
- }
- /* Read in the selected part of the array.
- * During the initial write pass, we will do no actual read
- * because the selected part is all undefined.
- */
- do_sarray_io(cinfo, ptr, FALSE);
- }
- /* Ensure the accessed part of the array is defined; prezero if needed.
- * To improve locality of access, we only prezero the part of the array
- * that the caller is about to access, not the entire in-memory array.
- */
- if (ptr->first_undef_row < end_row) {
- if (ptr->first_undef_row < start_row) {
- if (writable) /* writer skipped over a section of array */
- ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
- undef_row = start_row; /* but reader is allowed to read ahead */
- } else {
- undef_row = ptr->first_undef_row;
- }
- if (writable)
- ptr->first_undef_row = end_row;
- if (ptr->pre_zero) {
- size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
- undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
- end_row -= ptr->cur_start_row;
- while (undef_row < end_row) {
- jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
- undef_row++;
- }
- } else {
- if (! writable) /* reader looking at undefined data */
- ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
- }
- }
- /* Flag the buffer dirty if caller will write in it */
- if (writable)
- ptr->dirty = TRUE;
- /* Return address of proper part of the buffer */
- return ptr->mem_buffer + (start_row - ptr->cur_start_row);
-}
-
-
-METHODDEF(JBLOCKARRAY)
-access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
- JDIMENSION start_row, JDIMENSION num_rows,
- boolean writable)
-/* Access the part of a virtual block array starting at start_row */
-/* and extending for num_rows rows. writable is true if */
-/* caller intends to modify the accessed area. */
-{
- JDIMENSION end_row = start_row + num_rows;
- JDIMENSION undef_row;
-
- /* debugging check */
- if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
- ptr->mem_buffer == NULL)
- ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
-
- /* Make the desired part of the virtual array accessible */
- if (start_row < ptr->cur_start_row ||
- end_row > ptr->cur_start_row+ptr->rows_in_mem) {
- if (! ptr->b_s_open)
- ERREXIT(cinfo, JERR_VIRTUAL_BUG);
- /* Flush old buffer contents if necessary */
- if (ptr->dirty) {
- do_barray_io(cinfo, ptr, TRUE);
- ptr->dirty = FALSE;
- }
- /* Decide what part of virtual array to access.
- * Algorithm: if target address > current window, assume forward scan,
- * load starting at target address. If target address < current window,
- * assume backward scan, load so that target area is top of window.
- * Note that when switching from forward write to forward read, will have
- * start_row = 0, so the limiting case applies and we load from 0 anyway.
- */
- if (start_row > ptr->cur_start_row) {
- ptr->cur_start_row = start_row;
- } else {
- /* use long arithmetic here to avoid overflow & unsigned problems */
- long ltemp;
-
- ltemp = (long) end_row - (long) ptr->rows_in_mem;
- if (ltemp < 0)
- ltemp = 0; /* don't fall off front end of file */
- ptr->cur_start_row = (JDIMENSION) ltemp;
- }
- /* Read in the selected part of the array.
- * During the initial write pass, we will do no actual read
- * because the selected part is all undefined.
- */
- do_barray_io(cinfo, ptr, FALSE);
- }
- /* Ensure the accessed part of the array is defined; prezero if needed.
- * To improve locality of access, we only prezero the part of the array
- * that the caller is about to access, not the entire in-memory array.
- */
- if (ptr->first_undef_row < end_row) {
- if (ptr->first_undef_row < start_row) {
- if (writable) /* writer skipped over a section of array */
- ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
- undef_row = start_row; /* but reader is allowed to read ahead */
- } else {
- undef_row = ptr->first_undef_row;
- }
- if (writable)
- ptr->first_undef_row = end_row;
- if (ptr->pre_zero) {
- size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
- undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
- end_row -= ptr->cur_start_row;
- while (undef_row < end_row) {
- jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
- undef_row++;
- }
- } else {
- if (! writable) /* reader looking at undefined data */
- ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
- }
- }
- /* Flag the buffer dirty if caller will write in it */
- if (writable)
- ptr->dirty = TRUE;
- /* Return address of proper part of the buffer */
- return ptr->mem_buffer + (start_row - ptr->cur_start_row);
-}
-
-
-/*
- * Release all objects belonging to a specified pool.
- */
-
-METHODDEF(void)
-free_pool (j_common_ptr cinfo, int pool_id)
-{
- my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
- small_pool_ptr shdr_ptr;
- large_pool_ptr lhdr_ptr;
- size_t space_freed;
-
- if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
- ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
-
-#ifdef MEM_STATS
- if (cinfo->err->trace_level > 1)
- print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
-#endif
-
- /* If freeing IMAGE pool, close any virtual arrays first */
- if (pool_id == JPOOL_IMAGE) {
- jvirt_sarray_ptr sptr;
- jvirt_barray_ptr bptr;
-
- for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
- if (sptr->b_s_open) { /* there may be no backing store */
- sptr->b_s_open = FALSE; /* prevent recursive close if error */
- (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
- }
- }
- mem->virt_sarray_list = NULL;
- for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
- if (bptr->b_s_open) { /* there may be no backing store */
- bptr->b_s_open = FALSE; /* prevent recursive close if error */
- (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
- }
- }
- mem->virt_barray_list = NULL;
- }
-
- /* Release large objects */
- lhdr_ptr = mem->large_list[pool_id];
- mem->large_list[pool_id] = NULL;
-
- while (lhdr_ptr != NULL) {
- large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
- space_freed = lhdr_ptr->hdr.bytes_used +
- lhdr_ptr->hdr.bytes_left +
- SIZEOF(large_pool_hdr);
- jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
- mem->total_space_allocated -= space_freed;
- lhdr_ptr = next_lhdr_ptr;
- }
-
- /* Release small objects */
- shdr_ptr = mem->small_list[pool_id];
- mem->small_list[pool_id] = NULL;
-
- while (shdr_ptr != NULL) {
- small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
- space_freed = shdr_ptr->hdr.bytes_used +
- shdr_ptr->hdr.bytes_left +
- SIZEOF(small_pool_hdr);
- jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
- mem->total_space_allocated -= space_freed;
- shdr_ptr = next_shdr_ptr;
- }
-}
-
-
-/*
- * Close up shop entirely.
- * Note that this cannot be called unless cinfo->mem is non-NULL.
- */
-
-METHODDEF(void)
-self_destruct (j_common_ptr cinfo)
-{
- int pool;
-
- /* Close all backing store, release all memory.
- * Releasing pools in reverse order might help avoid fragmentation
- * with some (brain-damaged) malloc libraries.
- */
- for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
- free_pool(cinfo, pool);
- }
-
- /* Release the memory manager control block too. */
- jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
- cinfo->mem = NULL; /* ensures I will be called only once */
-
- jpeg_mem_term(cinfo); /* system-dependent cleanup */
-}
-
-
-/*
- * Memory manager initialization.
- * When this is called, only the error manager pointer is valid in cinfo!
- */
-
-GLOBAL(void)
-jinit_memory_mgr (j_common_ptr cinfo)
-{
- my_mem_ptr mem;
- long max_to_use;
- int pool;
- size_t test_mac;
-
- cinfo->mem = NULL; /* for safety if init fails */
-
- /* Check for configuration errors.
- * SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably
- * doesn't reflect any real hardware alignment requirement.
- * The test is a little tricky: for X>0, X and X-1 have no one-bits
- * in common if and only if X is a power of 2, ie has only one one-bit.
- * Some compilers may give an "unreachable code" warning here; ignore it.
- */
- if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
- ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
- /* MAX_ALLOC_CHUNK must be representable as type size_t, and must be
- * a multiple of SIZEOF(ALIGN_TYPE).
- * Again, an "unreachable code" warning may be ignored here.
- * But a "constant too large" warning means you need to fix MAX_ALLOC_CHUNK.
- */
- test_mac = (size_t) MAX_ALLOC_CHUNK;
- if ((long) test_mac != MAX_ALLOC_CHUNK ||
- (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
- ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
-
- max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
-
- /* Attempt to allocate memory manager's control block */
- mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
-
- if (mem == NULL) {
- jpeg_mem_term(cinfo); /* system-dependent cleanup */
- ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
- }
-
- /* OK, fill in the method pointers */
- mem->pub.alloc_small = alloc_small;
- mem->pub.alloc_large = alloc_large;
- mem->pub.alloc_sarray = alloc_sarray;
- mem->pub.alloc_barray = alloc_barray;
- mem->pub.request_virt_sarray = request_virt_sarray;
- mem->pub.request_virt_barray = request_virt_barray;
- mem->pub.realize_virt_arrays = realize_virt_arrays;
- mem->pub.access_virt_sarray = access_virt_sarray;
- mem->pub.access_virt_barray = access_virt_barray;
- mem->pub.free_pool = free_pool;
- mem->pub.self_destruct = self_destruct;
-
- /* Make MAX_ALLOC_CHUNK accessible to other modules */
- mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
-
- /* Initialize working state */
- mem->pub.max_memory_to_use = max_to_use;
-
- for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
- mem->small_list[pool] = NULL;
- mem->large_list[pool] = NULL;
- }
- mem->virt_sarray_list = NULL;
- mem->virt_barray_list = NULL;
-
- mem->total_space_allocated = SIZEOF(my_memory_mgr);
-
- /* Declare ourselves open for business */
- cinfo->mem = & mem->pub;
-
- /* Check for an environment variable JPEGMEM; if found, override the
- * default max_memory setting from jpeg_mem_init. Note that the
- * surrounding application may again override this value.
- * If your system doesn't support getenv(), define NO_GETENV to disable
- * this feature.
- */
-#ifndef NO_GETENV
- { char * memenv;
-
- if ((memenv = getenv("JPEGMEM")) != NULL) {
- char ch = 'x';
-
- if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
- if (ch == 'm' || ch == 'M')
- max_to_use *= 1000L;
- mem->pub.max_memory_to_use = max_to_use * 1000L;
- }
- }
- }
-#endif
-
-}
+/*
+ * jmemmgr.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains the JPEG system-independent memory management
+ * routines. This code is usable across a wide variety of machines; most
+ * of the system dependencies have been isolated in a separate file.
+ * The major functions provided here are:
+ * * pool-based allocation and freeing of memory;
+ * * policy decisions about how to divide available memory among the
+ * virtual arrays;
+ * * control logic for swapping virtual arrays between main memory and
+ * backing storage.
+ * The separate system-dependent file provides the actual backing-storage
+ * access code, and it contains the policy decision about how much total
+ * main memory to use.
+ * This file is system-dependent in the sense that some of its functions
+ * are unnecessary in some systems. For example, if there is enough virtual
+ * memory so that backing storage will never be used, much of the virtual
+ * array control logic could be removed. (Of course, if you have that much
+ * memory then you shouldn't care about a little bit of unused code...)
+ */
+
+#define JPEG_INTERNALS
+#define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jmemsys.h" /* import the system-dependent declarations */
+
+#ifndef NO_GETENV
+#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
+extern char * getenv JPP((const char * name));
+#endif
+#endif
+
+
+/*
+ * Some important notes:
+ * The allocation routines provided here must never return NULL.
+ * They should exit to error_exit if unsuccessful.
+ *
+ * It's not a good idea to try to merge the sarray and barray routines,
+ * even though they are textually almost the same, because samples are
+ * usually stored as bytes while coefficients are shorts or ints. Thus,
+ * in machines where byte pointers have a different representation from
+ * word pointers, the resulting machine code could not be the same.
+ */
+
+
+/*
+ * Many machines require storage alignment: longs must start on 4-byte
+ * boundaries, doubles on 8-byte boundaries, etc. On such machines, malloc()
+ * always returns pointers that are multiples of the worst-case alignment
+ * requirement, and we had better do so too.
+ * There isn't any really portable way to determine the worst-case alignment
+ * requirement. This module assumes that the alignment requirement is
+ * multiples of sizeof(ALIGN_TYPE).
+ * By default, we define ALIGN_TYPE as double. This is necessary on some
+ * workstations (where doubles really do need 8-byte alignment) and will work
+ * fine on nearly everything. If your machine has lesser alignment needs,
+ * you can save a few bytes by making ALIGN_TYPE smaller.
+ * The only place I know of where this will NOT work is certain Macintosh
+ * 680x0 compilers that define double as a 10-byte IEEE extended float.
+ * Doing 10-byte alignment is counterproductive because longwords won't be
+ * aligned well. Put "#define ALIGN_TYPE long" in jconfig.h if you have
+ * such a compiler.
+ */
+
+#ifndef ALIGN_TYPE /* so can override from jconfig.h */
+#define ALIGN_TYPE double
+#endif
+
+
+/*
+ * We allocate objects from "pools", where each pool is gotten with a single
+ * request to jpeg_get_small() or jpeg_get_large(). There is no per-object
+ * overhead within a pool, except for alignment padding. Each pool has a
+ * header with a link to the next pool of the same class.
+ * Small and large pool headers are identical except that the latter's
+ * link pointer must be FAR on 80x86 machines.
+ * Notice that the "real" header fields are union'ed with a dummy ALIGN_TYPE
+ * field. This forces the compiler to make SIZEOF(small_pool_hdr) a multiple
+ * of the alignment requirement of ALIGN_TYPE.
+ */
+
+typedef union small_pool_struct * small_pool_ptr;
+
+typedef union small_pool_struct {
+ struct {
+ small_pool_ptr next; /* next in list of pools */
+ size_t bytes_used; /* how many bytes already used within pool */
+ size_t bytes_left; /* bytes still available in this pool */
+ } hdr;
+ ALIGN_TYPE dummy; /* included in union to ensure alignment */
+} small_pool_hdr;
+
+typedef union large_pool_struct FAR * large_pool_ptr;
+
+typedef union large_pool_struct {
+ struct {
+ large_pool_ptr next; /* next in list of pools */
+ size_t bytes_used; /* how many bytes already used within pool */
+ size_t bytes_left; /* bytes still available in this pool */
+ } hdr;
+ ALIGN_TYPE dummy; /* included in union to ensure alignment */
+} large_pool_hdr;
+
+
+/*
+ * Here is the full definition of a memory manager object.
+ */
+
+typedef struct {
+ struct jpeg_memory_mgr pub; /* public fields */
+
+ /* Each pool identifier (lifetime class) names a linked list of pools. */
+ small_pool_ptr small_list[JPOOL_NUMPOOLS];
+ large_pool_ptr large_list[JPOOL_NUMPOOLS];
+
+ /* Since we only have one lifetime class of virtual arrays, only one
+ * linked list is necessary (for each datatype). Note that the virtual
+ * array control blocks being linked together are actually stored somewhere
+ * in the small-pool list.
+ */
+ jvirt_sarray_ptr virt_sarray_list;
+ jvirt_barray_ptr virt_barray_list;
+
+ /* This counts total space obtained from jpeg_get_small/large */
+ long total_space_allocated;
+
+ /* alloc_sarray and alloc_barray set this value for use by virtual
+ * array routines.
+ */
+ JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
+} my_memory_mgr;
+
+typedef my_memory_mgr * my_mem_ptr;
+
+
+/*
+ * The control blocks for virtual arrays.
+ * Note that these blocks are allocated in the "small" pool area.
+ * System-dependent info for the associated backing store (if any) is hidden
+ * inside the backing_store_info struct.
+ */
+
+struct jvirt_sarray_control {
+ JSAMPARRAY mem_buffer; /* => the in-memory buffer */
+ JDIMENSION rows_in_array; /* total virtual array height */
+ JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
+ JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
+ JDIMENSION rows_in_mem; /* height of memory buffer */
+ JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
+ JDIMENSION cur_start_row; /* first logical row # in the buffer */
+ JDIMENSION first_undef_row; /* row # of first uninitialized row */
+ boolean pre_zero; /* pre-zero mode requested? */
+ boolean dirty; /* do current buffer contents need written? */
+ boolean b_s_open; /* is backing-store data valid? */
+ jvirt_sarray_ptr next; /* link to next virtual sarray control block */
+ backing_store_info b_s_info; /* System-dependent control info */
+};
+
+struct jvirt_barray_control {
+ JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
+ JDIMENSION rows_in_array; /* total virtual array height */
+ JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
+ JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
+ JDIMENSION rows_in_mem; /* height of memory buffer */
+ JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
+ JDIMENSION cur_start_row; /* first logical row # in the buffer */
+ JDIMENSION first_undef_row; /* row # of first uninitialized row */
+ boolean pre_zero; /* pre-zero mode requested? */
+ boolean dirty; /* do current buffer contents need written? */
+ boolean b_s_open; /* is backing-store data valid? */
+ jvirt_barray_ptr next; /* link to next virtual barray control block */
+ backing_store_info b_s_info; /* System-dependent control info */
+};
+
+
+#ifdef MEM_STATS /* optional extra stuff for statistics */
+
+LOCAL(void)
+print_mem_stats (j_common_ptr cinfo, int pool_id)
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ small_pool_ptr shdr_ptr;
+ large_pool_ptr lhdr_ptr;
+
+ /* Since this is only a debugging stub, we can cheat a little by using
+ * fprintf directly rather than going through the trace message code.
+ * This is helpful because message parm array can't handle longs.
+ */
+ fprintf(stderr, "Freeing pool %d, total space = %ld\n",
+ pool_id, mem->total_space_allocated);
+
+ for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
+ lhdr_ptr = lhdr_ptr->hdr.next) {
+ fprintf(stderr, " Large chunk used %ld\n",
+ (long) lhdr_ptr->hdr.bytes_used);
+ }
+
+ for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
+ shdr_ptr = shdr_ptr->hdr.next) {
+ fprintf(stderr, " Small chunk used %ld free %ld\n",
+ (long) shdr_ptr->hdr.bytes_used,
+ (long) shdr_ptr->hdr.bytes_left);
+ }
+}
+
+#endif /* MEM_STATS */
+
+
+LOCAL(void)
+out_of_memory (j_common_ptr cinfo, int which)
+/* Report an out-of-memory error and stop execution */
+/* If we compiled MEM_STATS support, report alloc requests before dying */
+{
+#ifdef MEM_STATS
+ cinfo->err->trace_level = 2; /* force self_destruct to report stats */
+#endif
+ ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
+ KILL_TAIL_CALL();
+}
+
+
+/*
+ * Allocation of "small" objects.
+ *
+ * For these, we use pooled storage. When a new pool must be created,
+ * we try to get enough space for the current request plus a "slop" factor,
+ * where the slop will be the amount of leftover space in the new pool.
+ * The speed vs. space tradeoff is largely determined by the slop values.
+ * A different slop value is provided for each pool class (lifetime),
+ * and we also distinguish the first pool of a class from later ones.
+ * NOTE: the values given work fairly well on both 16- and 32-bit-int
+ * machines, but may be too small if longs are 64 bits or more.
+ */
+
+static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
+{
+ 1600, /* first PERMANENT pool */
+ 16000 /* first IMAGE pool */
+};
+
+static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
+{
+ 0, /* additional PERMANENT pools */
+ 5000 /* additional IMAGE pools */
+};
+
+#define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
+
+
+METHODDEF(void *)
+alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
+/* Allocate a "small" object */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ small_pool_ptr hdr_ptr, prev_hdr_ptr;
+ char * data_ptr;
+ size_t odd_bytes, min_request, slop;
+
+ /* Check for unsatisfiable request (do now to ensure no overflow below) */
+ if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
+ out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
+
+ /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
+ odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
+ if (odd_bytes > 0)
+ sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
+
+ /* See if space is available in any existing pool */
+ if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
+ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
+ prev_hdr_ptr = NULL;
+ hdr_ptr = mem->small_list[pool_id];
+ while (hdr_ptr != NULL) {
+ if (hdr_ptr->hdr.bytes_left >= sizeofobject)
+ break; /* found pool with enough space */
+ prev_hdr_ptr = hdr_ptr;
+ hdr_ptr = hdr_ptr->hdr.next;
+ }
+
+ /* Time to make a new pool? */
+ if (hdr_ptr == NULL) {
+ /* min_request is what we need now, slop is what will be leftover */
+ min_request = sizeofobject + SIZEOF(small_pool_hdr);
+ if (prev_hdr_ptr == NULL) /* first pool in class? */
+ slop = first_pool_slop[pool_id];
+ else
+ slop = extra_pool_slop[pool_id];
+ /* Don't ask for more than MAX_ALLOC_CHUNK */
+ if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
+ slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
+ /* Try to get space, if fail reduce slop and try again */
+ for (;;) {
+ hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
+ if (hdr_ptr != NULL)
+ break;
+ slop /= 2;
+ if (slop < MIN_SLOP) /* give up when it gets real small */
+ out_of_memory(cinfo, 2); /* jpeg_get_small failed */
+ }
+ mem->total_space_allocated += min_request + slop;
+ /* Success, initialize the new pool header and add to end of list */
+ hdr_ptr->hdr.next = NULL;
+ hdr_ptr->hdr.bytes_used = 0;
+ hdr_ptr->hdr.bytes_left = sizeofobject + slop;
+ if (prev_hdr_ptr == NULL) /* first pool in class? */
+ mem->small_list[pool_id] = hdr_ptr;
+ else
+ prev_hdr_ptr->hdr.next = hdr_ptr;
+ }
+
+ /* OK, allocate the object from the current pool */
+ data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
+ data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
+ hdr_ptr->hdr.bytes_used += sizeofobject;
+ hdr_ptr->hdr.bytes_left -= sizeofobject;
+
+ return (void *) data_ptr;
+}
+
+
+/*
+ * Allocation of "large" objects.
+ *
+ * The external semantics of these are the same as "small" objects,
+ * except that FAR pointers are used on 80x86. However the pool
+ * management heuristics are quite different. We assume that each
+ * request is large enough that it may as well be passed directly to
+ * jpeg_get_large; the pool management just links everything together
+ * so that we can free it all on demand.
+ * Note: the major use of "large" objects is in JSAMPARRAY and JBLOCKARRAY
+ * structures. The routines that create these structures (see below)
+ * deliberately bunch rows together to ensure a large request size.
+ */
+
+METHODDEF(void FAR *)
+alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
+/* Allocate a "large" object */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ large_pool_ptr hdr_ptr;
+ size_t odd_bytes;
+
+ /* Check for unsatisfiable request (do now to ensure no overflow below) */
+ if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
+ out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
+
+ /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
+ odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
+ if (odd_bytes > 0)
+ sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
+
+ /* Always make a new pool */
+ if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
+ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
+
+ hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
+ SIZEOF(large_pool_hdr));
+ if (hdr_ptr == NULL)
+ out_of_memory(cinfo, 4); /* jpeg_get_large failed */
+ mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
+
+ /* Success, initialize the new pool header and add to list */
+ hdr_ptr->hdr.next = mem->large_list[pool_id];
+ /* We maintain space counts in each pool header for statistical purposes,
+ * even though they are not needed for allocation.
+ */
+ hdr_ptr->hdr.bytes_used = sizeofobject;
+ hdr_ptr->hdr.bytes_left = 0;
+ mem->large_list[pool_id] = hdr_ptr;
+
+ return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
+}
+
+
+/*
+ * Creation of 2-D sample arrays.
+ * The pointers are in near heap, the samples themselves in FAR heap.
+ *
+ * To minimize allocation overhead and to allow I/O of large contiguous
+ * blocks, we allocate the sample rows in groups of as many rows as possible
+ * without exceeding MAX_ALLOC_CHUNK total bytes per allocation request.
+ * NB: the virtual array control routines, later in this file, know about
+ * this chunking of rows. The rowsperchunk value is left in the mem manager
+ * object so that it can be saved away if this sarray is the workspace for
+ * a virtual array.
+ */
+
+METHODDEF(JSAMPARRAY)
+alloc_sarray (j_common_ptr cinfo, int pool_id,
+ JDIMENSION samplesperrow, JDIMENSION numrows)
+/* Allocate a 2-D sample array */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ JSAMPARRAY result;
+ JSAMPROW workspace;
+ JDIMENSION rowsperchunk, currow, i;
+ long ltemp;
+
+ /* Calculate max # of rows allowed in one allocation chunk */
+ ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
+ ((long) samplesperrow * SIZEOF(JSAMPLE));
+ if (ltemp <= 0)
+ ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
+ if (ltemp < (long) numrows)
+ rowsperchunk = (JDIMENSION) ltemp;
+ else
+ rowsperchunk = numrows;
+ mem->last_rowsperchunk = rowsperchunk;
+
+ /* Get space for row pointers (small object) */
+ result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
+ (size_t) (numrows * SIZEOF(JSAMPROW)));
+
+ /* Get the rows themselves (large objects) */
+ currow = 0;
+ while (currow < numrows) {
+ rowsperchunk = MIN(rowsperchunk, numrows - currow);
+ workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
+ (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
+ * SIZEOF(JSAMPLE)));
+ for (i = rowsperchunk; i > 0; i--) {
+ result[currow++] = workspace;
+ workspace += samplesperrow;
+ }
+ }
+
+ return result;
+}
+
+
+/*
+ * Creation of 2-D coefficient-block arrays.
+ * This is essentially the same as the code for sample arrays, above.
+ */
+
+METHODDEF(JBLOCKARRAY)
+alloc_barray (j_common_ptr cinfo, int pool_id,
+ JDIMENSION blocksperrow, JDIMENSION numrows)
+/* Allocate a 2-D coefficient-block array */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ JBLOCKARRAY result;
+ JBLOCKROW workspace;
+ JDIMENSION rowsperchunk, currow, i;
+ long ltemp;
+
+ /* Calculate max # of rows allowed in one allocation chunk */
+ ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
+ ((long) blocksperrow * SIZEOF(JBLOCK));
+ if (ltemp <= 0)
+ ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
+ if (ltemp < (long) numrows)
+ rowsperchunk = (JDIMENSION) ltemp;
+ else
+ rowsperchunk = numrows;
+ mem->last_rowsperchunk = rowsperchunk;
+
+ /* Get space for row pointers (small object) */
+ result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
+ (size_t) (numrows * SIZEOF(JBLOCKROW)));
+
+ /* Get the rows themselves (large objects) */
+ currow = 0;
+ while (currow < numrows) {
+ rowsperchunk = MIN(rowsperchunk, numrows - currow);
+ workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
+ (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
+ * SIZEOF(JBLOCK)));
+ for (i = rowsperchunk; i > 0; i--) {
+ result[currow++] = workspace;
+ workspace += blocksperrow;
+ }
+ }
+
+ return result;
+}
+
+
+/*
+ * About virtual array management:
+ *
+ * The above "normal" array routines are only used to allocate strip buffers
+ * (as wide as the image, but just a few rows high). Full-image-sized buffers
+ * are handled as "virtual" arrays. The array is still accessed a strip at a
+ * time, but the memory manager must save the whole array for repeated
+ * accesses. The intended implementation is that there is a strip buffer in
+ * memory (as high as is possible given the desired memory limit), plus a
+ * backing file that holds the rest of the array.
+ *
+ * The request_virt_array routines are told the total size of the image and
+ * the maximum number of rows that will be accessed at once. The in-memory
+ * buffer must be at least as large as the maxaccess value.
+ *
+ * The request routines create control blocks but not the in-memory buffers.
+ * That is postponed until realize_virt_arrays is called. At that time the
+ * total amount of space needed is known (approximately, anyway), so free
+ * memory can be divided up fairly.
+ *
+ * The access_virt_array routines are responsible for making a specific strip
+ * area accessible (after reading or writing the backing file, if necessary).
+ * Note that the access routines are told whether the caller intends to modify
+ * the accessed strip; during a read-only pass this saves having to rewrite
+ * data to disk. The access routines are also responsible for pre-zeroing
+ * any newly accessed rows, if pre-zeroing was requested.
+ *
+ * In current usage, the access requests are usually for nonoverlapping
+ * strips; that is, successive access start_row numbers differ by exactly
+ * num_rows = maxaccess. This means we can get good performance with simple
+ * buffer dump/reload logic, by making the in-memory buffer be a multiple
+ * of the access height; then there will never be accesses across bufferload
+ * boundaries. The code will still work with overlapping access requests,
+ * but it doesn't handle bufferload overlaps very efficiently.
+ */
+
+
+METHODDEF(jvirt_sarray_ptr)
+request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
+ JDIMENSION samplesperrow, JDIMENSION numrows,
+ JDIMENSION maxaccess)
+/* Request a virtual 2-D sample array */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ jvirt_sarray_ptr result;
+
+ /* Only IMAGE-lifetime virtual arrays are currently supported */
+ if (pool_id != JPOOL_IMAGE)
+ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
+
+ /* get control block */
+ result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
+ SIZEOF(struct jvirt_sarray_control));
+
+ result->mem_buffer = NULL; /* marks array not yet realized */
+ result->rows_in_array = numrows;
+ result->samplesperrow = samplesperrow;
+ result->maxaccess = maxaccess;
+ result->pre_zero = pre_zero;
+ result->b_s_open = FALSE; /* no associated backing-store object */
+ result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
+ mem->virt_sarray_list = result;
+
+ return result;
+}
+
+
+METHODDEF(jvirt_barray_ptr)
+request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
+ JDIMENSION blocksperrow, JDIMENSION numrows,
+ JDIMENSION maxaccess)
+/* Request a virtual 2-D coefficient-block array */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ jvirt_barray_ptr result;
+
+ /* Only IMAGE-lifetime virtual arrays are currently supported */
+ if (pool_id != JPOOL_IMAGE)
+ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
+
+ /* get control block */
+ result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
+ SIZEOF(struct jvirt_barray_control));
+
+ result->mem_buffer = NULL; /* marks array not yet realized */
+ result->rows_in_array = numrows;
+ result->blocksperrow = blocksperrow;
+ result->maxaccess = maxaccess;
+ result->pre_zero = pre_zero;
+ result->b_s_open = FALSE; /* no associated backing-store object */
+ result->next = mem->virt_barray_list; /* add to list of virtual arrays */
+ mem->virt_barray_list = result;
+
+ return result;
+}
+
+
+METHODDEF(void)
+realize_virt_arrays (j_common_ptr cinfo)
+/* Allocate the in-memory buffers for any unrealized virtual arrays */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ long space_per_minheight, maximum_space, avail_mem;
+ long minheights, max_minheights;
+ jvirt_sarray_ptr sptr;
+ jvirt_barray_ptr bptr;
+
+ /* Compute the minimum space needed (maxaccess rows in each buffer)
+ * and the maximum space needed (full image height in each buffer).
+ * These may be of use to the system-dependent jpeg_mem_available routine.
+ */
+ space_per_minheight = 0;
+ maximum_space = 0;
+ for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
+ if (sptr->mem_buffer == NULL) { /* if not realized yet */
+ space_per_minheight += (long) sptr->maxaccess *
+ (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
+ maximum_space += (long) sptr->rows_in_array *
+ (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
+ }
+ }
+ for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
+ if (bptr->mem_buffer == NULL) { /* if not realized yet */
+ space_per_minheight += (long) bptr->maxaccess *
+ (long) bptr->blocksperrow * SIZEOF(JBLOCK);
+ maximum_space += (long) bptr->rows_in_array *
+ (long) bptr->blocksperrow * SIZEOF(JBLOCK);
+ }
+ }
+
+ if (space_per_minheight <= 0)
+ return; /* no unrealized arrays, no work */
+
+ /* Determine amount of memory to actually use; this is system-dependent. */
+ avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
+ mem->total_space_allocated);
+
+ /* If the maximum space needed is available, make all the buffers full
+ * height; otherwise parcel it out with the same number of minheights
+ * in each buffer.
+ */
+ if (avail_mem >= maximum_space)
+ max_minheights = 1000000000L;
+ else {
+ max_minheights = avail_mem / space_per_minheight;
+ /* If there doesn't seem to be enough space, try to get the minimum
+ * anyway. This allows a "stub" implementation of jpeg_mem_available().
+ */
+ if (max_minheights <= 0)
+ max_minheights = 1;
+ }
+
+ /* Allocate the in-memory buffers and initialize backing store as needed. */
+
+ for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
+ if (sptr->mem_buffer == NULL) { /* if not realized yet */
+ minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
+ if (minheights <= max_minheights) {
+ /* This buffer fits in memory */
+ sptr->rows_in_mem = sptr->rows_in_array;
+ } else {
+ /* It doesn't fit in memory, create backing store. */
+ sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
+ jpeg_open_backing_store(cinfo, & sptr->b_s_info,
+ (long) sptr->rows_in_array *
+ (long) sptr->samplesperrow *
+ (long) SIZEOF(JSAMPLE));
+ sptr->b_s_open = TRUE;
+ }
+ sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
+ sptr->samplesperrow, sptr->rows_in_mem);
+ sptr->rowsperchunk = mem->last_rowsperchunk;
+ sptr->cur_start_row = 0;
+ sptr->first_undef_row = 0;
+ sptr->dirty = FALSE;
+ }
+ }
+
+ for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
+ if (bptr->mem_buffer == NULL) { /* if not realized yet */
+ minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
+ if (minheights <= max_minheights) {
+ /* This buffer fits in memory */
+ bptr->rows_in_mem = bptr->rows_in_array;
+ } else {
+ /* It doesn't fit in memory, create backing store. */
+ bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
+ jpeg_open_backing_store(cinfo, & bptr->b_s_info,
+ (long) bptr->rows_in_array *
+ (long) bptr->blocksperrow *
+ (long) SIZEOF(JBLOCK));
+ bptr->b_s_open = TRUE;
+ }
+ bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
+ bptr->blocksperrow, bptr->rows_in_mem);
+ bptr->rowsperchunk = mem->last_rowsperchunk;
+ bptr->cur_start_row = 0;
+ bptr->first_undef_row = 0;
+ bptr->dirty = FALSE;
+ }
+ }
+}
+
+
+LOCAL(void)
+do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
+/* Do backing store read or write of a virtual sample array */
+{
+ long bytesperrow, file_offset, byte_count, rows, thisrow, i;
+
+ bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
+ file_offset = ptr->cur_start_row * bytesperrow;
+ /* Loop to read or write each allocation chunk in mem_buffer */
+ for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
+ /* One chunk, but check for short chunk at end of buffer */
+ rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
+ /* Transfer no more than is currently defined */
+ thisrow = (long) ptr->cur_start_row + i;
+ rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
+ /* Transfer no more than fits in file */
+ rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
+ if (rows <= 0) /* this chunk might be past end of file! */
+ break;
+ byte_count = rows * bytesperrow;
+ if (writing)
+ (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
+ (void FAR *) ptr->mem_buffer[i],
+ file_offset, byte_count);
+ else
+ (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
+ (void FAR *) ptr->mem_buffer[i],
+ file_offset, byte_count);
+ file_offset += byte_count;
+ }
+}
+
+
+LOCAL(void)
+do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
+/* Do backing store read or write of a virtual coefficient-block array */
+{
+ long bytesperrow, file_offset, byte_count, rows, thisrow, i;
+
+ bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
+ file_offset = ptr->cur_start_row * bytesperrow;
+ /* Loop to read or write each allocation chunk in mem_buffer */
+ for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
+ /* One chunk, but check for short chunk at end of buffer */
+ rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
+ /* Transfer no more than is currently defined */
+ thisrow = (long) ptr->cur_start_row + i;
+ rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
+ /* Transfer no more than fits in file */
+ rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
+ if (rows <= 0) /* this chunk might be past end of file! */
+ break;
+ byte_count = rows * bytesperrow;
+ if (writing)
+ (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
+ (void FAR *) ptr->mem_buffer[i],
+ file_offset, byte_count);
+ else
+ (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
+ (void FAR *) ptr->mem_buffer[i],
+ file_offset, byte_count);
+ file_offset += byte_count;
+ }
+}
+
+
+METHODDEF(JSAMPARRAY)
+access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
+ JDIMENSION start_row, JDIMENSION num_rows,
+ boolean writable)
+/* Access the part of a virtual sample array starting at start_row */
+/* and extending for num_rows rows. writable is true if */
+/* caller intends to modify the accessed area. */
+{
+ JDIMENSION end_row = start_row + num_rows;
+ JDIMENSION undef_row;
+
+ /* debugging check */
+ if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
+ ptr->mem_buffer == NULL)
+ ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
+
+ /* Make the desired part of the virtual array accessible */
+ if (start_row < ptr->cur_start_row ||
+ end_row > ptr->cur_start_row+ptr->rows_in_mem) {
+ if (! ptr->b_s_open)
+ ERREXIT(cinfo, JERR_VIRTUAL_BUG);
+ /* Flush old buffer contents if necessary */
+ if (ptr->dirty) {
+ do_sarray_io(cinfo, ptr, TRUE);
+ ptr->dirty = FALSE;
+ }
+ /* Decide what part of virtual array to access.
+ * Algorithm: if target address > current window, assume forward scan,
+ * load starting at target address. If target address < current window,
+ * assume backward scan, load so that target area is top of window.
+ * Note that when switching from forward write to forward read, will have
+ * start_row = 0, so the limiting case applies and we load from 0 anyway.
+ */
+ if (start_row > ptr->cur_start_row) {
+ ptr->cur_start_row = start_row;
+ } else {
+ /* use long arithmetic here to avoid overflow & unsigned problems */
+ long ltemp;
+
+ ltemp = (long) end_row - (long) ptr->rows_in_mem;
+ if (ltemp < 0)
+ ltemp = 0; /* don't fall off front end of file */
+ ptr->cur_start_row = (JDIMENSION) ltemp;
+ }
+ /* Read in the selected part of the array.
+ * During the initial write pass, we will do no actual read
+ * because the selected part is all undefined.
+ */
+ do_sarray_io(cinfo, ptr, FALSE);
+ }
+ /* Ensure the accessed part of the array is defined; prezero if needed.
+ * To improve locality of access, we only prezero the part of the array
+ * that the caller is about to access, not the entire in-memory array.
+ */
+ if (ptr->first_undef_row < end_row) {
+ if (ptr->first_undef_row < start_row) {
+ if (writable) /* writer skipped over a section of array */
+ ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
+ undef_row = start_row; /* but reader is allowed to read ahead */
+ } else {
+ undef_row = ptr->first_undef_row;
+ }
+ if (writable)
+ ptr->first_undef_row = end_row;
+ if (ptr->pre_zero) {
+ size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
+ undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
+ end_row -= ptr->cur_start_row;
+ while (undef_row < end_row) {
+ jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
+ undef_row++;
+ }
+ } else {
+ if (! writable) /* reader looking at undefined data */
+ ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
+ }
+ }
+ /* Flag the buffer dirty if caller will write in it */
+ if (writable)
+ ptr->dirty = TRUE;
+ /* Return address of proper part of the buffer */
+ return ptr->mem_buffer + (start_row - ptr->cur_start_row);
+}
+
+
+METHODDEF(JBLOCKARRAY)
+access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
+ JDIMENSION start_row, JDIMENSION num_rows,
+ boolean writable)
+/* Access the part of a virtual block array starting at start_row */
+/* and extending for num_rows rows. writable is true if */
+/* caller intends to modify the accessed area. */
+{
+ JDIMENSION end_row = start_row + num_rows;
+ JDIMENSION undef_row;
+
+ /* debugging check */
+ if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
+ ptr->mem_buffer == NULL)
+ ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
+
+ /* Make the desired part of the virtual array accessible */
+ if (start_row < ptr->cur_start_row ||
+ end_row > ptr->cur_start_row+ptr->rows_in_mem) {
+ if (! ptr->b_s_open)
+ ERREXIT(cinfo, JERR_VIRTUAL_BUG);
+ /* Flush old buffer contents if necessary */
+ if (ptr->dirty) {
+ do_barray_io(cinfo, ptr, TRUE);
+ ptr->dirty = FALSE;
+ }
+ /* Decide what part of virtual array to access.
+ * Algorithm: if target address > current window, assume forward scan,
+ * load starting at target address. If target address < current window,
+ * assume backward scan, load so that target area is top of window.
+ * Note that when switching from forward write to forward read, will have
+ * start_row = 0, so the limiting case applies and we load from 0 anyway.
+ */
+ if (start_row > ptr->cur_start_row) {
+ ptr->cur_start_row = start_row;
+ } else {
+ /* use long arithmetic here to avoid overflow & unsigned problems */
+ long ltemp;
+
+ ltemp = (long) end_row - (long) ptr->rows_in_mem;
+ if (ltemp < 0)
+ ltemp = 0; /* don't fall off front end of file */
+ ptr->cur_start_row = (JDIMENSION) ltemp;
+ }
+ /* Read in the selected part of the array.
+ * During the initial write pass, we will do no actual read
+ * because the selected part is all undefined.
+ */
+ do_barray_io(cinfo, ptr, FALSE);
+ }
+ /* Ensure the accessed part of the array is defined; prezero if needed.
+ * To improve locality of access, we only prezero the part of the array
+ * that the caller is about to access, not the entire in-memory array.
+ */
+ if (ptr->first_undef_row < end_row) {
+ if (ptr->first_undef_row < start_row) {
+ if (writable) /* writer skipped over a section of array */
+ ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
+ undef_row = start_row; /* but reader is allowed to read ahead */
+ } else {
+ undef_row = ptr->first_undef_row;
+ }
+ if (writable)
+ ptr->first_undef_row = end_row;
+ if (ptr->pre_zero) {
+ size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
+ undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
+ end_row -= ptr->cur_start_row;
+ while (undef_row < end_row) {
+ jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
+ undef_row++;
+ }
+ } else {
+ if (! writable) /* reader looking at undefined data */
+ ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
+ }
+ }
+ /* Flag the buffer dirty if caller will write in it */
+ if (writable)
+ ptr->dirty = TRUE;
+ /* Return address of proper part of the buffer */
+ return ptr->mem_buffer + (start_row - ptr->cur_start_row);
+}
+
+
+/*
+ * Release all objects belonging to a specified pool.
+ */
+
+METHODDEF(void)
+free_pool (j_common_ptr cinfo, int pool_id)
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ small_pool_ptr shdr_ptr;
+ large_pool_ptr lhdr_ptr;
+ size_t space_freed;
+
+ if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
+ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
+
+#ifdef MEM_STATS
+ if (cinfo->err->trace_level > 1)
+ print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
+#endif
+
+ /* If freeing IMAGE pool, close any virtual arrays first */
+ if (pool_id == JPOOL_IMAGE) {
+ jvirt_sarray_ptr sptr;
+ jvirt_barray_ptr bptr;
+
+ for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
+ if (sptr->b_s_open) { /* there may be no backing store */
+ sptr->b_s_open = FALSE; /* prevent recursive close if error */
+ (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
+ }
+ }
+ mem->virt_sarray_list = NULL;
+ for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
+ if (bptr->b_s_open) { /* there may be no backing store */
+ bptr->b_s_open = FALSE; /* prevent recursive close if error */
+ (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
+ }
+ }
+ mem->virt_barray_list = NULL;
+ }
+
+ /* Release large objects */
+ lhdr_ptr = mem->large_list[pool_id];
+ mem->large_list[pool_id] = NULL;
+
+ while (lhdr_ptr != NULL) {
+ large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
+ space_freed = lhdr_ptr->hdr.bytes_used +
+ lhdr_ptr->hdr.bytes_left +
+ SIZEOF(large_pool_hdr);
+ jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
+ mem->total_space_allocated -= space_freed;
+ lhdr_ptr = next_lhdr_ptr;
+ }
+
+ /* Release small objects */
+ shdr_ptr = mem->small_list[pool_id];
+ mem->small_list[pool_id] = NULL;
+
+ while (shdr_ptr != NULL) {
+ small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
+ space_freed = shdr_ptr->hdr.bytes_used +
+ shdr_ptr->hdr.bytes_left +
+ SIZEOF(small_pool_hdr);
+ jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
+ mem->total_space_allocated -= space_freed;
+ shdr_ptr = next_shdr_ptr;
+ }
+}
+
+
+/*
+ * Close up shop entirely.
+ * Note that this cannot be called unless cinfo->mem is non-NULL.
+ */
+
+METHODDEF(void)
+self_destruct (j_common_ptr cinfo)
+{
+ int pool;
+
+ /* Close all backing store, release all memory.
+ * Releasing pools in reverse order might help avoid fragmentation
+ * with some (brain-damaged) malloc libraries.
+ */
+ for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
+ free_pool(cinfo, pool);
+ }
+
+ /* Release the memory manager control block too. */
+ jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
+ cinfo->mem = NULL; /* ensures I will be called only once */
+
+ jpeg_mem_term(cinfo); /* system-dependent cleanup */
+}
+
+
+/*
+ * Memory manager initialization.
+ * When this is called, only the error manager pointer is valid in cinfo!
+ */
+
+GLOBAL(void)
+jinit_memory_mgr (j_common_ptr cinfo)
+{
+ my_mem_ptr mem;
+ long max_to_use;
+ int pool;
+ size_t test_mac;
+
+ cinfo->mem = NULL; /* for safety if init fails */
+
+ /* Check for configuration errors.
+ * SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably
+ * doesn't reflect any real hardware alignment requirement.
+ * The test is a little tricky: for X>0, X and X-1 have no one-bits
+ * in common if and only if X is a power of 2, ie has only one one-bit.
+ * Some compilers may give an "unreachable code" warning here; ignore it.
+ */
+ if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
+ ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
+ /* MAX_ALLOC_CHUNK must be representable as type size_t, and must be
+ * a multiple of SIZEOF(ALIGN_TYPE).
+ * Again, an "unreachable code" warning may be ignored here.
+ * But a "constant too large" warning means you need to fix MAX_ALLOC_CHUNK.
+ */
+ test_mac = (size_t) MAX_ALLOC_CHUNK;
+ if ((long) test_mac != MAX_ALLOC_CHUNK ||
+ (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
+ ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
+
+ max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
+
+ /* Attempt to allocate memory manager's control block */
+ mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
+
+ if (mem == NULL) {
+ jpeg_mem_term(cinfo); /* system-dependent cleanup */
+ ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
+ }
+
+ /* OK, fill in the method pointers */
+ mem->pub.alloc_small = alloc_small;
+ mem->pub.alloc_large = alloc_large;
+ mem->pub.alloc_sarray = alloc_sarray;
+ mem->pub.alloc_barray = alloc_barray;
+ mem->pub.request_virt_sarray = request_virt_sarray;
+ mem->pub.request_virt_barray = request_virt_barray;
+ mem->pub.realize_virt_arrays = realize_virt_arrays;
+ mem->pub.access_virt_sarray = access_virt_sarray;
+ mem->pub.access_virt_barray = access_virt_barray;
+ mem->pub.free_pool = free_pool;
+ mem->pub.self_destruct = self_destruct;
+
+ /* Make MAX_ALLOC_CHUNK accessible to other modules */
+ mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
+
+ /* Initialize working state */
+ mem->pub.max_memory_to_use = max_to_use;
+
+ for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
+ mem->small_list[pool] = NULL;
+ mem->large_list[pool] = NULL;
+ }
+ mem->virt_sarray_list = NULL;
+ mem->virt_barray_list = NULL;
+
+ mem->total_space_allocated = SIZEOF(my_memory_mgr);
+
+ /* Declare ourselves open for business */
+ cinfo->mem = & mem->pub;
+
+ /* Check for an environment variable JPEGMEM; if found, override the
+ * default max_memory setting from jpeg_mem_init. Note that the
+ * surrounding application may again override this value.
+ * If your system doesn't support getenv(), define NO_GETENV to disable
+ * this feature.
+ */
+#ifndef NO_GETENV
+ { char * memenv;
+
+ if ((memenv = getenv("JPEGMEM")) != NULL) {
+ char ch = 'x';
+
+ if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
+ if (ch == 'm' || ch == 'M')
+ max_to_use *= 1000L;
+ mem->pub.max_memory_to_use = max_to_use * 1000L;
+ }
+ }
+ }
+#endif
+
+}
diff --git a/test/monniaux/jpeg-6b/jmemnobs.c b/test/monniaux/jpeg-6b/jmemnobs.c
index 8bf9f8be..02e14a1a 100644
--- a/test/monniaux/jpeg-6b/jmemnobs.c
+++ b/test/monniaux/jpeg-6b/jmemnobs.c
@@ -25,6 +25,7 @@ extern void * malloc JPP((size_t size));
extern void free JPP((void *ptr));
#endif
+
/*
* Memory allocation and freeing are controlled by the regular library
* routines malloc() and free().
@@ -33,21 +34,16 @@ extern void free JPP((void *ptr));
GLOBAL(void *)
jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
{
- void *p= (void *) malloc(sizeofobject);
- if (p==NULL) { /* DM */
- printf("malloc (%zu) failed\n", sizeofobject);
- }
- return p;
+ return (void *) malloc(sizeofobject);
}
GLOBAL(void)
jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
{
-#ifdef DMONNIAUX_FREE
free(object);
-#endif
}
+
/*
* "Large" objects are treated the same as "small" ones.
* NB: although we include FAR keywords in the routine declarations,
@@ -64,11 +60,10 @@ jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
GLOBAL(void)
jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
{
-#ifdef DMONNIAUX_FREE
- free((void*)object);
-#endif
+ free(object);
}
+
/*
* This routine computes the total memory space available for allocation.
* Here we always say, "we got all you want bud!"
@@ -93,7 +88,7 @@ jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
long total_bytes_needed)
{
ERREXIT(cinfo, JERR_NO_BACKING_STORE);
- KILL_TAIL_CALL
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/jmorecfg.h b/test/monniaux/jpeg-6b/jmorecfg.h
index 121b65d7..c274ca3a 100644
--- a/test/monniaux/jpeg-6b/jmorecfg.h
+++ b/test/monniaux/jpeg-6b/jmorecfg.h
@@ -10,21 +10,6 @@
* optimizations. Most users will not need to touch this file.
*/
-#ifdef NO_32BIT_DIVISION
-#define MODULO(x, y) ((long long) (x) % (y))
-#define DIVISION(x, y) ((long long) (x) / (y))
-#else
-#define MODULO(x, y) ((x) % (y))
-#define DIVISION(x, y) ((x) / (y))
-#endif
-
-#ifdef TAIL_CALL_MISSING
-#define KILL_TAIL_CALL { int val = 1; }
-#else
-#define KILL_TAIL_CALL
-#endif
-
-#define ASSIGN_FUNPTR(x, y) x = y
/*
* Define BITS_IN_JSAMPLE as either
@@ -277,9 +262,9 @@ typedef int boolean;
#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
-#ifndef NO_FLOAT
-#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
-#endif
+
+/* DM */
+#undef DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
/* Encoder capability options: */
diff --git a/test/monniaux/jpeg-6b/jpegtran.c b/test/monniaux/jpeg-6b/jpegtran.c
index 20ef111b..719aaa73 100644
--- a/test/monniaux/jpeg-6b/jpegtran.c
+++ b/test/monniaux/jpeg-6b/jpegtran.c
@@ -1,504 +1,504 @@
-/*
- * jpegtran.c
- *
- * Copyright (C) 1995-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains a command-line user interface for JPEG transcoding.
- * It is very similar to cjpeg.c, but provides lossless transcoding between
- * different JPEG file formats. It also provides some lossless and sort-of-
- * lossless transformations of JPEG data.
- */
-
-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
-#include "transupp.h" /* Support routines for jpegtran */
-#include "jversion.h" /* for version message */
-
-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
-#ifdef __MWERKS__
-#include <SIOUX.h> /* Metrowerks needs this */
-#include <console.h> /* ... and this */
-#endif
-#ifdef THINK_C
-#include <console.h> /* Think declares it here */
-#endif
-#endif
-
-
-/*
- * Argument-parsing code.
- * The switch parser is designed to be useful with DOS-style command line
- * syntax, ie, intermixed switches and file names, where only the switches
- * to the left of a given file name affect processing of that file.
- * The main program in this file doesn't actually use this capability...
- */
-
-
-static const char * progname; /* program name for error messages */
-static char * outfilename; /* for -outfile switch */
-static JCOPY_OPTION copyoption; /* -copy switch */
-static jpeg_transform_info transformoption; /* image transformation options */
-
-
-LOCAL(void)
-usage (void)
-/* complain about bad command line */
-{
- fprintf(stderr, "usage: %s [switches] ", progname);
-#ifdef TWO_FILE_COMMANDLINE
- fprintf(stderr, "inputfile outputfile\n");
-#else
- fprintf(stderr, "[inputfile]\n");
-#endif
-
- fprintf(stderr, "Switches (names may be abbreviated):\n");
- fprintf(stderr, " -copy none Copy no extra markers from source file\n");
- fprintf(stderr, " -copy comments Copy only comment markers (default)\n");
- fprintf(stderr, " -copy all Copy all extra markers\n");
-#ifdef ENTROPY_OPT_SUPPORTED
- fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
-#endif
-#ifdef C_PROGRESSIVE_SUPPORTED
- fprintf(stderr, " -progressive Create progressive JPEG file\n");
-#endif
-#if TRANSFORMS_SUPPORTED
- fprintf(stderr, "Switches for modifying the image:\n");
- fprintf(stderr, " -grayscale Reduce to grayscale (omit color data)\n");
- fprintf(stderr, " -flip [horizontal|vertical] Mirror image (left-right or top-bottom)\n");
- fprintf(stderr, " -rotate [90|180|270] Rotate image (degrees clockwise)\n");
- fprintf(stderr, " -transpose Transpose image\n");
- fprintf(stderr, " -transverse Transverse transpose image\n");
- fprintf(stderr, " -trim Drop non-transformable edge blocks\n");
-#endif /* TRANSFORMS_SUPPORTED */
- fprintf(stderr, "Switches for advanced users:\n");
- fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
- fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
- fprintf(stderr, " -outfile name Specify name for output file\n");
- fprintf(stderr, " -verbose or -debug Emit debug output\n");
- fprintf(stderr, "Switches for wizards:\n");
-#ifdef C_ARITH_CODING_SUPPORTED
- fprintf(stderr, " -arithmetic Use arithmetic coding\n");
-#endif
-#ifdef C_MULTISCAN_FILES_SUPPORTED
- fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n");
-#endif
- exit(EXIT_FAILURE);
-}
-
-
-LOCAL(void)
-select_transform (JXFORM_CODE transform)
-/* Silly little routine to detect multiple transform options,
- * which we can't handle.
- */
-{
-#if TRANSFORMS_SUPPORTED
- if (transformoption.transform == JXFORM_NONE ||
- transformoption.transform == transform) {
- transformoption.transform = transform;
- } else {
- fprintf(stderr, "%s: can only do one image transformation at a time\n",
- progname);
- usage();
- }
-#else
- fprintf(stderr, "%s: sorry, image transformation was not compiled\n",
- progname);
- exit(EXIT_FAILURE);
-#endif
-}
-
-
-LOCAL(int)
-parse_switches (j_compress_ptr cinfo, int argc, char **argv,
- int last_file_arg_seen, boolean for_real)
-/* Parse optional switches.
- * Returns argv[] index of first file-name argument (== argc if none).
- * Any file names with indexes <= last_file_arg_seen are ignored;
- * they have presumably been processed in a previous iteration.
- * (Pass 0 for last_file_arg_seen on the first or only iteration.)
- * for_real is FALSE on the first (dummy) pass; we may skip any expensive
- * processing.
- */
-{
- int argn;
- char * arg;
- boolean simple_progressive;
- char * scansarg = NULL; /* saves -scans parm if any */
-
- /* Set up default JPEG parameters. */
- simple_progressive = FALSE;
- outfilename = NULL;
- copyoption = JCOPYOPT_DEFAULT;
- transformoption.transform = JXFORM_NONE;
- transformoption.trim = FALSE;
- transformoption.force_grayscale = FALSE;
- cinfo->err->trace_level = 0;
-
- /* Scan command line options, adjust parameters */
-
- for (argn = 1; argn < argc; argn++) {
- arg = argv[argn];
- if (*arg != '-') {
- /* Not a switch, must be a file name argument */
- if (argn <= last_file_arg_seen) {
- outfilename = NULL; /* -outfile applies to just one input file */
- continue; /* ignore this name if previously processed */
- }
- break; /* else done parsing switches */
- }
- arg++; /* advance past switch marker character */
-
- if (keymatch(arg, "arithmetic", 1)) {
- /* Use arithmetic coding. */
-#ifdef C_ARITH_CODING_SUPPORTED
- cinfo->arith_code = TRUE;
-#else
- fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
- progname);
- exit(EXIT_FAILURE);
-#endif
-
- } else if (keymatch(arg, "copy", 1)) {
- /* Select which extra markers to copy. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (keymatch(argv[argn], "none", 1)) {
- copyoption = JCOPYOPT_NONE;
- } else if (keymatch(argv[argn], "comments", 1)) {
- copyoption = JCOPYOPT_COMMENTS;
- } else if (keymatch(argv[argn], "all", 1)) {
- copyoption = JCOPYOPT_ALL;
- } else
- usage();
-
- } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
- /* Enable debug printouts. */
- /* On first -d, print version identification */
- static boolean printed_version = FALSE;
-
- if (! printed_version) {
- fprintf(stderr, "Independent JPEG Group's JPEGTRAN, version %s\n%s\n",
- JVERSION, JCOPYRIGHT);
- printed_version = TRUE;
- }
- cinfo->err->trace_level++;
-
- } else if (keymatch(arg, "flip", 1)) {
- /* Mirror left-right or top-bottom. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (keymatch(argv[argn], "horizontal", 1))
- select_transform(JXFORM_FLIP_H);
- else if (keymatch(argv[argn], "vertical", 1))
- select_transform(JXFORM_FLIP_V);
- else
- usage();
-
- } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) {
- /* Force to grayscale. */
-#if TRANSFORMS_SUPPORTED
- transformoption.force_grayscale = TRUE;
-#else
- select_transform(JXFORM_NONE); /* force an error */
-#endif
-
- } else if (keymatch(arg, "maxmemory", 3)) {
- /* Maximum memory in Kb (or Mb with 'm'). */
- long lval;
- char ch = 'x';
-
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
- usage();
- if (ch == 'm' || ch == 'M')
- lval *= 1000L;
- cinfo->mem->max_memory_to_use = lval * 1000L;
-
- } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
- /* Enable entropy parm optimization. */
-#ifdef ENTROPY_OPT_SUPPORTED
- cinfo->optimize_coding = TRUE;
-#else
- fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
- progname);
- exit(EXIT_FAILURE);
-#endif
-
- } else if (keymatch(arg, "outfile", 4)) {
- /* Set output file name. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- outfilename = argv[argn]; /* save it away for later use */
-
- } else if (keymatch(arg, "progressive", 1)) {
- /* Select simple progressive mode. */
-#ifdef C_PROGRESSIVE_SUPPORTED
- simple_progressive = TRUE;
- /* We must postpone execution until num_components is known. */
-#else
- fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
- progname);
- exit(EXIT_FAILURE);
-#endif
-
- } else if (keymatch(arg, "restart", 1)) {
- /* Restart interval in MCU rows (or in MCUs with 'b'). */
- long lval;
- char ch = 'x';
-
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
- usage();
- if (lval < 0 || lval > 65535L)
- usage();
- if (ch == 'b' || ch == 'B') {
- cinfo->restart_interval = (unsigned int) lval;
- cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
- } else {
- cinfo->restart_in_rows = (int) lval;
- /* restart_interval will be computed during startup */
- }
-
- } else if (keymatch(arg, "rotate", 2)) {
- /* Rotate 90, 180, or 270 degrees (measured clockwise). */
- if (++argn >= argc) /* advance to next argument */
- usage();
- if (keymatch(argv[argn], "90", 2))
- select_transform(JXFORM_ROT_90);
- else if (keymatch(argv[argn], "180", 3))
- select_transform(JXFORM_ROT_180);
- else if (keymatch(argv[argn], "270", 3))
- select_transform(JXFORM_ROT_270);
- else
- usage();
-
- } else if (keymatch(arg, "scans", 1)) {
- /* Set scan script. */
-#ifdef C_MULTISCAN_FILES_SUPPORTED
- if (++argn >= argc) /* advance to next argument */
- usage();
- scansarg = argv[argn];
- /* We must postpone reading the file in case -progressive appears. */
-#else
- fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
- progname);
- exit(EXIT_FAILURE);
-#endif
-
- } else if (keymatch(arg, "transpose", 1)) {
- /* Transpose (across UL-to-LR axis). */
- select_transform(JXFORM_TRANSPOSE);
-
- } else if (keymatch(arg, "transverse", 6)) {
- /* Transverse transpose (across UR-to-LL axis). */
- select_transform(JXFORM_TRANSVERSE);
-
- } else if (keymatch(arg, "trim", 3)) {
- /* Trim off any partial edge MCUs that the transform can't handle. */
- transformoption.trim = TRUE;
-
- } else {
- usage(); /* bogus switch */
- }
- }
-
- /* Post-switch-scanning cleanup */
-
- if (for_real) {
-
-#ifdef C_PROGRESSIVE_SUPPORTED
- if (simple_progressive) /* process -progressive; -scans can override */
- jpeg_simple_progression(cinfo);
-#endif
-
-#ifdef C_MULTISCAN_FILES_SUPPORTED
- if (scansarg != NULL) /* process -scans if it was present */
- if (! read_scan_script(cinfo, scansarg))
- usage();
-#endif
- }
-
- return argn; /* return index of next arg (file name) */
-}
-
-
-/*
- * The main program.
- */
-
-int
-main (int argc, char **argv)
-{
- struct jpeg_decompress_struct srcinfo;
- struct jpeg_compress_struct dstinfo;
- struct jpeg_error_mgr jsrcerr, jdsterr;
-#ifdef PROGRESS_REPORT
- struct cdjpeg_progress_mgr progress;
-#endif
- jvirt_barray_ptr * src_coef_arrays;
- jvirt_barray_ptr * dst_coef_arrays;
- int file_index;
- FILE * input_file;
- FILE * output_file;
-
- /* On Mac, fetch a command line. */
-#ifdef USE_CCOMMAND
- argc = ccommand(&argv);
-#endif
-
- progname = argv[0];
- if (progname == NULL || progname[0] == 0)
- progname = "jpegtran"; /* in case C library doesn't provide it */
-
- /* Initialize the JPEG decompression object with default error handling. */
- srcinfo.err = jpeg_std_error(&jsrcerr);
- jpeg_create_decompress(&srcinfo);
- /* Initialize the JPEG compression object with default error handling. */
- dstinfo.err = jpeg_std_error(&jdsterr);
- jpeg_create_compress(&dstinfo);
-
- /* Now safe to enable signal catcher.
- * Note: we assume only the decompression object will have virtual arrays.
- */
-#ifdef NEED_SIGNAL_CATCHER
- enable_signal_catcher((j_common_ptr) &srcinfo);
-#endif
-
- /* Scan command line to find file names.
- * It is convenient to use just one switch-parsing routine, but the switch
- * values read here are mostly ignored; we will rescan the switches after
- * opening the input file. Also note that most of the switches affect the
- * destination JPEG object, so we parse into that and then copy over what
- * needs to affects the source too.
- */
-
- file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE);
- jsrcerr.trace_level = jdsterr.trace_level;
- srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use;
-
-#ifdef TWO_FILE_COMMANDLINE
- /* Must have either -outfile switch or explicit output file name */
- if (outfilename == NULL) {
- if (file_index != argc-2) {
- fprintf(stderr, "%s: must name one input and one output file\n",
- progname);
- usage();
- }
- outfilename = argv[file_index+1];
- } else {
- if (file_index != argc-1) {
- fprintf(stderr, "%s: must name one input and one output file\n",
- progname);
- usage();
- }
- }
-#else
- /* Unix style: expect zero or one file name */
- if (file_index < argc-1) {
- fprintf(stderr, "%s: only one input file\n", progname);
- usage();
- }
-#endif /* TWO_FILE_COMMANDLINE */
-
- /* Open the input file. */
- if (file_index < argc) {
- if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
- exit(EXIT_FAILURE);
- }
- } else {
- /* default input file is stdin */
- input_file = read_stdin();
- }
-
- /* Open the output file. */
- if (outfilename != NULL) {
- if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
- exit(EXIT_FAILURE);
- }
- } else {
- /* default output file is stdout */
- output_file = write_stdout();
- }
-
-#ifdef PROGRESS_REPORT
- start_progress_monitor((j_common_ptr) &dstinfo, &progress);
-#endif
-
- /* Specify data source for decompression */
- jpeg_stdio_src(&srcinfo, input_file);
-
- /* Enable saving of extra markers that we want to copy */
- jcopy_markers_setup(&srcinfo, copyoption);
-
- /* Read file header */
- (void) jpeg_read_header(&srcinfo, TRUE);
-
- /* Any space needed by a transform option must be requested before
- * jpeg_read_coefficients so that memory allocation will be done right.
- */
-#if TRANSFORMS_SUPPORTED
- jtransform_request_workspace(&srcinfo, &transformoption);
-#endif
-
- /* Read source file as DCT coefficients */
- src_coef_arrays = jpeg_read_coefficients(&srcinfo);
-
- /* Initialize destination compression parameters from source values */
- jpeg_copy_critical_parameters(&srcinfo, &dstinfo);
-
- /* Adjust destination parameters if required by transform options;
- * also find out which set of coefficient arrays will hold the output.
- */
-#if TRANSFORMS_SUPPORTED
- dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo,
- src_coef_arrays,
- &transformoption);
-#else
- dst_coef_arrays = src_coef_arrays;
-#endif
-
- /* Adjust default compression parameters by re-parsing the options */
- file_index = parse_switches(&dstinfo, argc, argv, 0, TRUE);
-
- /* Specify data destination for compression */
- jpeg_stdio_dest(&dstinfo, output_file);
-
- /* Start compressor (note no image data is actually written here) */
- jpeg_write_coefficients(&dstinfo, dst_coef_arrays);
-
- /* Copy to the output file any extra markers that we want to preserve */
- jcopy_markers_execute(&srcinfo, &dstinfo, copyoption);
-
- /* Execute image transformation, if any */
-#if TRANSFORMS_SUPPORTED
- jtransform_execute_transformation(&srcinfo, &dstinfo,
- src_coef_arrays,
- &transformoption);
-#endif
-
- /* Finish compression and release memory */
- jpeg_finish_compress(&dstinfo);
- jpeg_destroy_compress(&dstinfo);
- (void) jpeg_finish_decompress(&srcinfo);
- jpeg_destroy_decompress(&srcinfo);
-
- /* Close files, if we opened them */
- if (input_file != stdin)
- fclose(input_file);
- if (output_file != stdout)
- fclose(output_file);
-
-#ifdef PROGRESS_REPORT
- end_progress_monitor((j_common_ptr) &dstinfo);
-#endif
-
- /* All done. */
- exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS);
- return 0; /* suppress no-return-value warnings */
-}
+/*
+ * jpegtran.c
+ *
+ * Copyright (C) 1995-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a command-line user interface for JPEG transcoding.
+ * It is very similar to cjpeg.c, but provides lossless transcoding between
+ * different JPEG file formats. It also provides some lossless and sort-of-
+ * lossless transformations of JPEG data.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+#include "transupp.h" /* Support routines for jpegtran */
+#include "jversion.h" /* for version message */
+
+#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
+#ifdef __MWERKS__
+#include <SIOUX.h> /* Metrowerks needs this */
+#include <console.h> /* ... and this */
+#endif
+#ifdef THINK_C
+#include <console.h> /* Think declares it here */
+#endif
+#endif
+
+
+/*
+ * Argument-parsing code.
+ * The switch parser is designed to be useful with DOS-style command line
+ * syntax, ie, intermixed switches and file names, where only the switches
+ * to the left of a given file name affect processing of that file.
+ * The main program in this file doesn't actually use this capability...
+ */
+
+
+static const char * progname; /* program name for error messages */
+static char * outfilename; /* for -outfile switch */
+static JCOPY_OPTION copyoption; /* -copy switch */
+static jpeg_transform_info transformoption; /* image transformation options */
+
+
+LOCAL(void)
+usage (void)
+/* complain about bad command line */
+{
+ fprintf(stderr, "usage: %s [switches] ", progname);
+#ifdef TWO_FILE_COMMANDLINE
+ fprintf(stderr, "inputfile outputfile\n");
+#else
+ fprintf(stderr, "[inputfile]\n");
+#endif
+
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
+ fprintf(stderr, " -copy none Copy no extra markers from source file\n");
+ fprintf(stderr, " -copy comments Copy only comment markers (default)\n");
+ fprintf(stderr, " -copy all Copy all extra markers\n");
+#ifdef ENTROPY_OPT_SUPPORTED
+ fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
+#endif
+#ifdef C_PROGRESSIVE_SUPPORTED
+ fprintf(stderr, " -progressive Create progressive JPEG file\n");
+#endif
+#if TRANSFORMS_SUPPORTED
+ fprintf(stderr, "Switches for modifying the image:\n");
+ fprintf(stderr, " -grayscale Reduce to grayscale (omit color data)\n");
+ fprintf(stderr, " -flip [horizontal|vertical] Mirror image (left-right or top-bottom)\n");
+ fprintf(stderr, " -rotate [90|180|270] Rotate image (degrees clockwise)\n");
+ fprintf(stderr, " -transpose Transpose image\n");
+ fprintf(stderr, " -transverse Transverse transpose image\n");
+ fprintf(stderr, " -trim Drop non-transformable edge blocks\n");
+#endif /* TRANSFORMS_SUPPORTED */
+ fprintf(stderr, "Switches for advanced users:\n");
+ fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
+ fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
+ fprintf(stderr, " -outfile name Specify name for output file\n");
+ fprintf(stderr, " -verbose or -debug Emit debug output\n");
+ fprintf(stderr, "Switches for wizards:\n");
+#ifdef C_ARITH_CODING_SUPPORTED
+ fprintf(stderr, " -arithmetic Use arithmetic coding\n");
+#endif
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n");
+#endif
+ exit(EXIT_FAILURE);
+}
+
+
+LOCAL(void)
+select_transform (JXFORM_CODE transform)
+/* Silly little routine to detect multiple transform options,
+ * which we can't handle.
+ */
+{
+#if TRANSFORMS_SUPPORTED
+ if (transformoption.transform == JXFORM_NONE ||
+ transformoption.transform == transform) {
+ transformoption.transform = transform;
+ } else {
+ fprintf(stderr, "%s: can only do one image transformation at a time\n",
+ progname);
+ usage();
+ }
+#else
+ fprintf(stderr, "%s: sorry, image transformation was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+}
+
+
+LOCAL(int)
+parse_switches (j_compress_ptr cinfo, int argc, char **argv,
+ int last_file_arg_seen, boolean for_real)
+/* Parse optional switches.
+ * Returns argv[] index of first file-name argument (== argc if none).
+ * Any file names with indexes <= last_file_arg_seen are ignored;
+ * they have presumably been processed in a previous iteration.
+ * (Pass 0 for last_file_arg_seen on the first or only iteration.)
+ * for_real is FALSE on the first (dummy) pass; we may skip any expensive
+ * processing.
+ */
+{
+ int argn;
+ char * arg;
+ boolean simple_progressive;
+ char * scansarg = NULL; /* saves -scans parm if any */
+
+ /* Set up default JPEG parameters. */
+ simple_progressive = FALSE;
+ outfilename = NULL;
+ copyoption = JCOPYOPT_DEFAULT;
+ transformoption.transform = JXFORM_NONE;
+ transformoption.trim = FALSE;
+ transformoption.force_grayscale = FALSE;
+ cinfo->err->trace_level = 0;
+
+ /* Scan command line options, adjust parameters */
+
+ for (argn = 1; argn < argc; argn++) {
+ arg = argv[argn];
+ if (*arg != '-') {
+ /* Not a switch, must be a file name argument */
+ if (argn <= last_file_arg_seen) {
+ outfilename = NULL; /* -outfile applies to just one input file */
+ continue; /* ignore this name if previously processed */
+ }
+ break; /* else done parsing switches */
+ }
+ arg++; /* advance past switch marker character */
+
+ if (keymatch(arg, "arithmetic", 1)) {
+ /* Use arithmetic coding. */
+#ifdef C_ARITH_CODING_SUPPORTED
+ cinfo->arith_code = TRUE;
+#else
+ fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "copy", 1)) {
+ /* Select which extra markers to copy. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (keymatch(argv[argn], "none", 1)) {
+ copyoption = JCOPYOPT_NONE;
+ } else if (keymatch(argv[argn], "comments", 1)) {
+ copyoption = JCOPYOPT_COMMENTS;
+ } else if (keymatch(argv[argn], "all", 1)) {
+ copyoption = JCOPYOPT_ALL;
+ } else
+ usage();
+
+ } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
+ /* Enable debug printouts. */
+ /* On first -d, print version identification */
+ static boolean printed_version = FALSE;
+
+ if (! printed_version) {
+ fprintf(stderr, "Independent JPEG Group's JPEGTRAN, version %s\n%s\n",
+ JVERSION, JCOPYRIGHT);
+ printed_version = TRUE;
+ }
+ cinfo->err->trace_level++;
+
+ } else if (keymatch(arg, "flip", 1)) {
+ /* Mirror left-right or top-bottom. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (keymatch(argv[argn], "horizontal", 1))
+ select_transform(JXFORM_FLIP_H);
+ else if (keymatch(argv[argn], "vertical", 1))
+ select_transform(JXFORM_FLIP_V);
+ else
+ usage();
+
+ } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) {
+ /* Force to grayscale. */
+#if TRANSFORMS_SUPPORTED
+ transformoption.force_grayscale = TRUE;
+#else
+ select_transform(JXFORM_NONE); /* force an error */
+#endif
+
+ } else if (keymatch(arg, "maxmemory", 3)) {
+ /* Maximum memory in Kb (or Mb with 'm'). */
+ long lval;
+ char ch = 'x';
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
+ usage();
+ if (ch == 'm' || ch == 'M')
+ lval *= 1000L;
+ cinfo->mem->max_memory_to_use = lval * 1000L;
+
+ } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
+ /* Enable entropy parm optimization. */
+#ifdef ENTROPY_OPT_SUPPORTED
+ cinfo->optimize_coding = TRUE;
+#else
+ fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "outfile", 4)) {
+ /* Set output file name. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ outfilename = argv[argn]; /* save it away for later use */
+
+ } else if (keymatch(arg, "progressive", 1)) {
+ /* Select simple progressive mode. */
+#ifdef C_PROGRESSIVE_SUPPORTED
+ simple_progressive = TRUE;
+ /* We must postpone execution until num_components is known. */
+#else
+ fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "restart", 1)) {
+ /* Restart interval in MCU rows (or in MCUs with 'b'). */
+ long lval;
+ char ch = 'x';
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
+ usage();
+ if (lval < 0 || lval > 65535L)
+ usage();
+ if (ch == 'b' || ch == 'B') {
+ cinfo->restart_interval = (unsigned int) lval;
+ cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
+ } else {
+ cinfo->restart_in_rows = (int) lval;
+ /* restart_interval will be computed during startup */
+ }
+
+ } else if (keymatch(arg, "rotate", 2)) {
+ /* Rotate 90, 180, or 270 degrees (measured clockwise). */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (keymatch(argv[argn], "90", 2))
+ select_transform(JXFORM_ROT_90);
+ else if (keymatch(argv[argn], "180", 3))
+ select_transform(JXFORM_ROT_180);
+ else if (keymatch(argv[argn], "270", 3))
+ select_transform(JXFORM_ROT_270);
+ else
+ usage();
+
+ } else if (keymatch(arg, "scans", 1)) {
+ /* Set scan script. */
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ scansarg = argv[argn];
+ /* We must postpone reading the file in case -progressive appears. */
+#else
+ fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "transpose", 1)) {
+ /* Transpose (across UL-to-LR axis). */
+ select_transform(JXFORM_TRANSPOSE);
+
+ } else if (keymatch(arg, "transverse", 6)) {
+ /* Transverse transpose (across UR-to-LL axis). */
+ select_transform(JXFORM_TRANSVERSE);
+
+ } else if (keymatch(arg, "trim", 3)) {
+ /* Trim off any partial edge MCUs that the transform can't handle. */
+ transformoption.trim = TRUE;
+
+ } else {
+ usage(); /* bogus switch */
+ }
+ }
+
+ /* Post-switch-scanning cleanup */
+
+ if (for_real) {
+
+#ifdef C_PROGRESSIVE_SUPPORTED
+ if (simple_progressive) /* process -progressive; -scans can override */
+ jpeg_simple_progression(cinfo);
+#endif
+
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ if (scansarg != NULL) /* process -scans if it was present */
+ if (! read_scan_script(cinfo, scansarg))
+ usage();
+#endif
+ }
+
+ return argn; /* return index of next arg (file name) */
+}
+
+
+/*
+ * The main program.
+ */
+
+int
+main (int argc, char **argv)
+{
+ struct jpeg_decompress_struct srcinfo;
+ struct jpeg_compress_struct dstinfo;
+ struct jpeg_error_mgr jsrcerr, jdsterr;
+#ifdef PROGRESS_REPORT
+ struct cdjpeg_progress_mgr progress;
+#endif
+ jvirt_barray_ptr * src_coef_arrays;
+ jvirt_barray_ptr * dst_coef_arrays;
+ int file_index;
+ FILE * input_file;
+ FILE * output_file;
+
+ /* On Mac, fetch a command line. */
+#ifdef USE_CCOMMAND
+ argc = ccommand(&argv);
+#endif
+
+ progname = argv[0];
+ if (progname == NULL || progname[0] == 0)
+ progname = "jpegtran"; /* in case C library doesn't provide it */
+
+ /* Initialize the JPEG decompression object with default error handling. */
+ srcinfo.err = jpeg_std_error(&jsrcerr);
+ jpeg_create_decompress(&srcinfo);
+ /* Initialize the JPEG compression object with default error handling. */
+ dstinfo.err = jpeg_std_error(&jdsterr);
+ jpeg_create_compress(&dstinfo);
+
+ /* Now safe to enable signal catcher.
+ * Note: we assume only the decompression object will have virtual arrays.
+ */
+#ifdef NEED_SIGNAL_CATCHER
+ enable_signal_catcher((j_common_ptr) &srcinfo);
+#endif
+
+ /* Scan command line to find file names.
+ * It is convenient to use just one switch-parsing routine, but the switch
+ * values read here are mostly ignored; we will rescan the switches after
+ * opening the input file. Also note that most of the switches affect the
+ * destination JPEG object, so we parse into that and then copy over what
+ * needs to affects the source too.
+ */
+
+ file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE);
+ jsrcerr.trace_level = jdsterr.trace_level;
+ srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use;
+
+#ifdef TWO_FILE_COMMANDLINE
+ /* Must have either -outfile switch or explicit output file name */
+ if (outfilename == NULL) {
+ if (file_index != argc-2) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ outfilename = argv[file_index+1];
+ } else {
+ if (file_index != argc-1) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ }
+#else
+ /* Unix style: expect zero or one file name */
+ if (file_index < argc-1) {
+ fprintf(stderr, "%s: only one input file\n", progname);
+ usage();
+ }
+#endif /* TWO_FILE_COMMANDLINE */
+
+ /* Open the input file. */
+ if (file_index < argc) {
+ if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default input file is stdin */
+ input_file = read_stdin();
+ }
+
+ /* Open the output file. */
+ if (outfilename != NULL) {
+ if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default output file is stdout */
+ output_file = write_stdout();
+ }
+
+#ifdef PROGRESS_REPORT
+ start_progress_monitor((j_common_ptr) &dstinfo, &progress);
+#endif
+
+ /* Specify data source for decompression */
+ jpeg_stdio_src(&srcinfo, input_file);
+
+ /* Enable saving of extra markers that we want to copy */
+ jcopy_markers_setup(&srcinfo, copyoption);
+
+ /* Read file header */
+ (void) jpeg_read_header(&srcinfo, TRUE);
+
+ /* Any space needed by a transform option must be requested before
+ * jpeg_read_coefficients so that memory allocation will be done right.
+ */
+#if TRANSFORMS_SUPPORTED
+ jtransform_request_workspace(&srcinfo, &transformoption);
+#endif
+
+ /* Read source file as DCT coefficients */
+ src_coef_arrays = jpeg_read_coefficients(&srcinfo);
+
+ /* Initialize destination compression parameters from source values */
+ jpeg_copy_critical_parameters(&srcinfo, &dstinfo);
+
+ /* Adjust destination parameters if required by transform options;
+ * also find out which set of coefficient arrays will hold the output.
+ */
+#if TRANSFORMS_SUPPORTED
+ dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo,
+ src_coef_arrays,
+ &transformoption);
+#else
+ dst_coef_arrays = src_coef_arrays;
+#endif
+
+ /* Adjust default compression parameters by re-parsing the options */
+ file_index = parse_switches(&dstinfo, argc, argv, 0, TRUE);
+
+ /* Specify data destination for compression */
+ jpeg_stdio_dest(&dstinfo, output_file);
+
+ /* Start compressor (note no image data is actually written here) */
+ jpeg_write_coefficients(&dstinfo, dst_coef_arrays);
+
+ /* Copy to the output file any extra markers that we want to preserve */
+ jcopy_markers_execute(&srcinfo, &dstinfo, copyoption);
+
+ /* Execute image transformation, if any */
+#if TRANSFORMS_SUPPORTED
+ jtransform_execute_transformation(&srcinfo, &dstinfo,
+ src_coef_arrays,
+ &transformoption);
+#endif
+
+ /* Finish compression and release memory */
+ jpeg_finish_compress(&dstinfo);
+ jpeg_destroy_compress(&dstinfo);
+ (void) jpeg_finish_decompress(&srcinfo);
+ jpeg_destroy_decompress(&srcinfo);
+
+ /* Close files, if we opened them */
+ if (input_file != stdin)
+ fclose(input_file);
+ if (output_file != stdout)
+ fclose(output_file);
+
+#ifdef PROGRESS_REPORT
+ end_progress_monitor((j_common_ptr) &dstinfo);
+#endif
+
+ /* All done. */
+ exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS);
+ return 0; /* suppress no-return-value warnings */
+}
diff --git a/test/monniaux/jpeg-6b/jquant1.c b/test/monniaux/jpeg-6b/jquant1.c
index bb366391..9f5d67bc 100644
--- a/test/monniaux/jpeg-6b/jquant1.c
+++ b/test/monniaux/jpeg-6b/jquant1.c
@@ -227,7 +227,7 @@ select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
for (i = 0; i < nc; i++) {
j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
/* calculate new total_colors if Ncolors[j] is incremented */
- temp = DIVISION(total_colors, Ncolors[j]);
+ temp = INT_DIV(total_colors, Ncolors[j]);
temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
if (temp > (long) max_colors)
break; /* won't fit, done with this pass */
@@ -251,7 +251,7 @@ output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
* (Forcing the upper and lower values to the limits ensures that
* dithering can't produce a color outside the selected gamut.)
*/
- return (int) DIVISION(((INT32) j * MAXJSAMPLE + maxj/2), maxj);
+ return (int) INT_DIV(((INT32) j * MAXJSAMPLE + maxj/2), maxj);
}
@@ -261,7 +261,7 @@ largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
/* Must have largest(j=0) >= 0, and largest(j=maxj) >= MAXJSAMPLE */
{
/* Breakpoints are halfway between values returned by output_value */
- return (int) DIVISION(((INT32) (2*j + 1) * MAXJSAMPLE + maxj), (2*maxj));
+ return (int) INT_DIV(((INT32) (2*j + 1) * MAXJSAMPLE + maxj), (2*maxj));
}
@@ -303,7 +303,7 @@ create_colormap (j_decompress_ptr cinfo)
for (i = 0; i < cinfo->out_color_components; i++) {
/* fill in colormap entries for i'th color component */
nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
- blksize = DIVISION(blkdist, nci);
+ blksize = INT_DIV(blkdist, nci);
for (j = 0; j < nci; j++) {
/* Compute j'th output value (out of nci) for component */
val = output_value(cinfo, i, j, nci-1);
@@ -360,7 +360,7 @@ create_colorindex (j_decompress_ptr cinfo)
for (i = 0; i < cinfo->out_color_components; i++) {
/* fill in colorindex entries for i'th color component */
nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
- blksize = DIVISION(blksize, nci);
+ blksize = INT_DIV(blksize, nci);
/* adjust colorindex pointers to provide padding at negative indexes. */
if (pad)
@@ -415,7 +415,7 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors)
/* Ensure round towards zero despite C's lack of consistency
* about rounding negative values in integer division...
*/
- odither[j][k] = (int) (num<0 ? -DIVISION((-num), den) : DIVISION(num, den));
+ odither[j][k] = (int) (num<0 ? -INT_DIV((-num),den) : INT_DIV(num,den));
}
}
return odither;
@@ -787,9 +787,7 @@ start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
ERREXIT(cinfo, JERR_NOT_COMPILED);
break;
}
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
@@ -813,9 +811,7 @@ METHODDEF(void)
new_color_map_1_quant (j_decompress_ptr cinfo)
{
ERREXIT(cinfo, JERR_MODE_CHANGE);
-#ifdef TAIL_CALL_MISSING
- int dummy=1;
-#endif
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/jquant2.c b/test/monniaux/jpeg-6b/jquant2.c
index 32b2aa88..6eb3bb17 100644
--- a/test/monniaux/jpeg-6b/jquant2.c
+++ b/test/monniaux/jpeg-6b/jquant2.c
@@ -529,9 +529,9 @@ compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
}
}
- cinfo->colormap[0][icolor] = (JSAMPLE) DIVISION((c0total + (total>>1)), total);
- cinfo->colormap[1][icolor] = (JSAMPLE) DIVISION((c1total + (total>>1)), total);
- cinfo->colormap[2][icolor] = (JSAMPLE) DIVISION((c2total + (total>>1)), total);
+ cinfo->colormap[0][icolor] = (JSAMPLE) INT_DIV((c0total + (total>>1)), total);
+ cinfo->colormap[1][icolor] = (JSAMPLE) INT_DIV((c1total + (total>>1)), total);
+ cinfo->colormap[2][icolor] = (JSAMPLE) INT_DIV((c2total + (total>>1)), total);
}
diff --git a/test/monniaux/jpeg-6b/jutils.c b/test/monniaux/jpeg-6b/jutils.c
index 505c3a07..d18a9555 100644
--- a/test/monniaux/jpeg-6b/jutils.c
+++ b/test/monniaux/jpeg-6b/jutils.c
@@ -73,7 +73,7 @@ jdiv_round_up (long a, long b)
/* Compute a/b rounded up to next integer, ie, ceil(a/b) */
/* Assumes a >= 0, b > 0 */
{
- return DIVISION((a + b - 1L), b);
+ return (a + b - 1L) / b;
}
@@ -83,7 +83,7 @@ jround_up (long a, long b)
/* Assumes a >= 0, b > 0 */
{
a += b - 1L;
- return a - DIVISION(a, b);
+ return a - (a % b);
}
diff --git a/test/monniaux/jpeg-6b/modulo_division.c b/test/monniaux/jpeg-6b/modulo_division.c
deleted file mode 100644
index 75d78a37..00000000
--- a/test/monniaux/jpeg-6b/modulo_division.c
+++ /dev/null
@@ -1,15 +0,0 @@
-int supplied_modulo(int x, int y) {
- return x % y;
-}
-int supplied_division(int x, int y) {
- return x / y;
-}
-unsigned long long __compcert_i64_udiv(unsigned long long x, unsigned long long y) {
- return x / y;
-}
-long long __compcert_i64_sdiv(long long x, long long y) {
- return x / y;
-}
-long long __compcert_i64_smod(long long x, long long y) {
- return x % y;
-}
diff --git a/test/monniaux/jpeg-6b/rdbmp.c b/test/monniaux/jpeg-6b/rdbmp.c
index b8bed4f9..e999a56b 100644
--- a/test/monniaux/jpeg-6b/rdbmp.c
+++ b/test/monniaux/jpeg-6b/rdbmp.c
@@ -229,8 +229,8 @@ preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
source->source_row = cinfo->image_height;
/* And read the first row */
- JDIMENSION ret = (*source->pub.get_pixel_rows) (cinfo, sinfo);
- KILL_TAIL_CALL
+ int ret= (*source->pub.get_pixel_rows) (cinfo, sinfo);
+ KILL_TAIL_CALL();
return ret;
}
@@ -338,8 +338,8 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) {
/* Set JFIF density parameters from the BMP data */
- cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */
- cinfo->Y_density = (UINT16) (biYPelsPerMeter/100);
+ cinfo->X_density = (UINT16) INT_DIV(biXPelsPerMeter, 100); /* 100 cm per meter */
+ cinfo->Y_density = (UINT16) INT_DIV(biYPelsPerMeter, 100);
cinfo->density_unit = 2; /* dots/cm */
}
break;
diff --git a/test/monniaux/jpeg-6b/rdcolmap.c b/test/monniaux/jpeg-6b/rdcolmap.c
index d9898d01..95d97358 100644
--- a/test/monniaux/jpeg-6b/rdcolmap.c
+++ b/test/monniaux/jpeg-6b/rdcolmap.c
@@ -248,7 +248,7 @@ read_color_map (j_decompress_ptr cinfo, FILE * infile)
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
break;
}
- KILL_TAIL_CALL
+ KILL_TAIL_CALL();
}
#endif /* QUANT_2PASS_SUPPORTED */
diff --git a/test/monniaux/jpeg-6b/rdgif.c b/test/monniaux/jpeg-6b/rdgif.c
index b27c1675..b0757e71 100644
--- a/test/monniaux/jpeg-6b/rdgif.c
+++ b/test/monniaux/jpeg-6b/rdgif.c
@@ -1,38 +1,38 @@
-/*
- * rdgif.c
- *
- * Copyright (C) 1991-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to read input images in GIF format.
- *
- *****************************************************************************
- * NOTE: to avoid entanglements with Unisys' patent on LZW compression, *
- * the ability to read GIF files has been removed from the IJG distribution. *
- * Sorry about that. *
- *****************************************************************************
- *
- * 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."
- */
-
-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
-
-#ifdef GIF_SUPPORTED
-
-/*
- * The module selection routine for GIF format input.
- */
-
-GLOBAL(cjpeg_source_ptr)
-jinit_read_gif (j_compress_ptr cinfo)
-{
- fprintf(stderr, "GIF input is unsupported for legal reasons. Sorry.\n");
- exit(EXIT_FAILURE);
- return NULL; /* keep compiler happy */
-}
-
-#endif /* GIF_SUPPORTED */
+/*
+ * rdgif.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to read input images in GIF format.
+ *
+ *****************************************************************************
+ * NOTE: to avoid entanglements with Unisys' patent on LZW compression, *
+ * the ability to read GIF files has been removed from the IJG distribution. *
+ * Sorry about that. *
+ *****************************************************************************
+ *
+ * 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."
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+
+#ifdef GIF_SUPPORTED
+
+/*
+ * The module selection routine for GIF format input.
+ */
+
+GLOBAL(cjpeg_source_ptr)
+jinit_read_gif (j_compress_ptr cinfo)
+{
+ fprintf(stderr, "GIF input is unsupported for legal reasons. Sorry.\n");
+ exit(EXIT_FAILURE);
+ return NULL; /* keep compiler happy */
+}
+
+#endif /* GIF_SUPPORTED */
diff --git a/test/monniaux/jpeg-6b/rdjpgcom.c b/test/monniaux/jpeg-6b/rdjpgcom.c
index ffe6fc62..c6cb47ce 100644
--- a/test/monniaux/jpeg-6b/rdjpgcom.c
+++ b/test/monniaux/jpeg-6b/rdjpgcom.c
@@ -1,496 +1,513 @@
-/*
- * rdjpgcom.c
- *
- * Copyright (C) 1994-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains a very simple stand-alone application that displays
- * the text in COM (comment) markers in a JFIF file.
- * This may be useful as an example of the minimum logic needed to parse
- * JPEG markers.
- */
-
-#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
-#include "jinclude.h" /* get auto-config symbols, <stdio.h> */
-
-#include <ctype.h> /* to declare isupper(), tolower() */
-#ifdef USE_SETMODE
-#include <fcntl.h> /* to declare setmode()'s parameter macros */
-/* If you have setmode() but not <io.h>, just delete this line: */
-#include <io.h> /* to declare setmode() */
-#endif
-
-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
-#ifdef __MWERKS__
-#include <SIOUX.h> /* Metrowerks needs this */
-#include <console.h> /* ... and this */
-#endif
-#ifdef THINK_C
-#include <console.h> /* Think declares it here */
-#endif
-#endif
-
-#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
-#define READ_BINARY "r"
-#else
-#ifdef VMS /* VMS is very nonstandard */
-#define READ_BINARY "rb", "ctx=stm"
-#else /* standard ANSI-compliant case */
-#define READ_BINARY "rb"
-#endif
-#endif
-
-#ifndef EXIT_FAILURE /* define exit() codes if not provided */
-#define EXIT_FAILURE 1
-#endif
-#ifndef EXIT_SUCCESS
-#ifdef VMS
-#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
-#else
-#define EXIT_SUCCESS 0
-#endif
-#endif
-
-
-/*
- * These macros are used to read the input file.
- * To reuse this code in another application, you might need to change these.
- */
-
-static FILE * infile; /* input JPEG file */
-
-/* Return next input byte, or EOF if no more */
-#define NEXTBYTE() getc(infile)
-
-
-/* Error exit handler */
-#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE))
-
-
-/* Read one byte, testing for EOF */
-static int
-read_1_byte (void)
-{
- int c;
-
- c = NEXTBYTE();
- if (c == EOF)
- ERREXIT("Premature EOF in JPEG file");
- return c;
-}
-
-/* Read 2 bytes, convert to unsigned int */
-/* All 2-byte quantities in JPEG markers are MSB first */
-static unsigned int
-read_2_bytes (void)
-{
- int c1, c2;
-
- c1 = NEXTBYTE();
- if (c1 == EOF)
- ERREXIT("Premature EOF in JPEG file");
- c2 = NEXTBYTE();
- if (c2 == EOF)
- ERREXIT("Premature EOF in JPEG file");
- return (((unsigned int) c1) << 8) + ((unsigned int) c2);
-}
-
-
-/*
- * JPEG markers consist of one or more 0xFF bytes, followed by a marker
- * code byte (which is not an FF). Here are the marker codes of interest
- * in this program. (See jdmarker.c for a more complete list.)
- */
-
-#define M_SOF0 0xC0 /* Start Of Frame N */
-#define M_SOF1 0xC1 /* N indicates which compression process */
-#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
-#define M_SOF3 0xC3
-#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
-#define M_SOF6 0xC6
-#define M_SOF7 0xC7
-#define M_SOF9 0xC9
-#define M_SOF10 0xCA
-#define M_SOF11 0xCB
-#define M_SOF13 0xCD
-#define M_SOF14 0xCE
-#define M_SOF15 0xCF
-#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
-#define M_EOI 0xD9 /* End Of Image (end of datastream) */
-#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
-#define M_APP0 0xE0 /* Application-specific marker, type N */
-#define M_APP12 0xEC /* (we don't bother to list all 16 APPn's) */
-#define M_COM 0xFE /* COMment */
-
-
-/*
- * Find the next JPEG marker and return its marker code.
- * We expect at least one FF byte, possibly more if the compressor used FFs
- * to pad the file.
- * There could also be non-FF garbage between markers. The treatment of such
- * garbage is unspecified; we choose to skip over it but emit a warning msg.
- * NB: this routine must not be used after seeing SOS marker, since it will
- * not deal correctly with FF/00 sequences in the compressed image data...
- */
-
-static int
-next_marker (void)
-{
- int c;
- int discarded_bytes = 0;
-
- /* Find 0xFF byte; count and skip any non-FFs. */
- c = read_1_byte();
- while (c != 0xFF) {
- discarded_bytes++;
- c = read_1_byte();
- }
- /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs
- * are legal as pad bytes, so don't count them in discarded_bytes.
- */
- do {
- c = read_1_byte();
- } while (c == 0xFF);
-
- if (discarded_bytes != 0) {
- fprintf(stderr, "Warning: garbage data found in JPEG file\n");
- }
-
- return c;
-}
-
-
-/*
- * Read the initial marker, which should be SOI.
- * For a JFIF file, the first two bytes of the file should be literally
- * 0xFF M_SOI. To be more general, we could use next_marker, but if the
- * input file weren't actually JPEG at all, next_marker might read the whole
- * file and then return a misleading error message...
- */
-
-static int
-first_marker (void)
-{
- int c1, c2;
-
- c1 = NEXTBYTE();
- c2 = NEXTBYTE();
- if (c1 != 0xFF || c2 != M_SOI)
- ERREXIT("Not a JPEG file");
- return c2;
-}
-
-
-/*
- * Most types of marker are followed by a variable-length parameter segment.
- * This routine skips over the parameters for any marker we don't otherwise
- * want to process.
- * Note that we MUST skip the parameter segment explicitly in order not to
- * be fooled by 0xFF bytes that might appear within the parameter segment;
- * such bytes do NOT introduce new markers.
- */
-
-static void
-skip_variable (void)
-/* Skip over an unknown or uninteresting variable-length marker */
-{
- unsigned int length;
-
- /* Get the marker parameter length count */
- length = read_2_bytes();
- /* Length includes itself, so must be at least 2 */
- if (length < 2)
- ERREXIT("Erroneous JPEG marker length");
- length -= 2;
- /* Skip over the remaining bytes */
- while (length > 0) {
- (void) read_1_byte();
- length--;
- }
-}
-
-
-/*
- * Process a COM marker.
- * We want to print out the marker contents as legible text;
- * we must guard against non-text junk and varying newline representations.
- */
-
-static void
-process_COM (void)
-{
- unsigned int length;
- int ch;
- int lastch = 0;
-
- /* Get the marker parameter length count */
- length = read_2_bytes();
- /* Length includes itself, so must be at least 2 */
- if (length < 2)
- ERREXIT("Erroneous JPEG marker length");
- length -= 2;
-
- while (length > 0) {
- ch = read_1_byte();
- /* Emit the character in a readable form.
- * Nonprintables are converted to \nnn form,
- * while \ is converted to \\.
- * Newlines in CR, CR/LF, or LF form will be printed as one newline.
- */
- if (ch == '\r') {
- printf("\n");
- } else if (ch == '\n') {
- if (lastch != '\r')
- printf("\n");
- } else if (ch == '\\') {
- printf("\\\\");
- } else if (isprint(ch)) {
- putc(ch, stdout);
- } else {
- printf("\\%03o", ch);
- }
- lastch = ch;
- length--;
- }
- printf("\n");
-}
-
-
-/*
- * Process a SOFn marker.
- * This code is only needed if you want to know the image dimensions...
- */
-
-static void
-process_SOFn (int marker)
-{
- unsigned int length;
- unsigned int image_height, image_width;
- int data_precision, num_components;
- const char * process;
- int ci;
-
- length = read_2_bytes(); /* usual parameter length count */
-
- data_precision = read_1_byte();
- image_height = read_2_bytes();
- image_width = read_2_bytes();
- num_components = read_1_byte();
-
- switch (marker) {
- case M_SOF0: process = "Baseline"; break;
- case M_SOF1: process = "Extended sequential"; break;
- case M_SOF2: process = "Progressive"; break;
- case M_SOF3: process = "Lossless"; break;
- case M_SOF5: process = "Differential sequential"; break;
- case M_SOF6: process = "Differential progressive"; break;
- case M_SOF7: process = "Differential lossless"; break;
- case M_SOF9: process = "Extended sequential, arithmetic coding"; break;
- case M_SOF10: process = "Progressive, arithmetic coding"; break;
- case M_SOF11: process = "Lossless, arithmetic coding"; break;
- case M_SOF13: process = "Differential sequential, arithmetic coding"; break;
- case M_SOF14: process = "Differential progressive, arithmetic coding"; break;
- case M_SOF15: process = "Differential lossless, arithmetic coding"; break;
- default: process = "Unknown"; break;
- }
-
- printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n",
- image_width, image_height, num_components, data_precision);
- printf("JPEG process: %s\n", process);
-
- if (length != (unsigned int) (8 + num_components * 3))
- ERREXIT("Bogus SOF marker length");
-
- for (ci = 0; ci < num_components; ci++) {
- (void) read_1_byte(); /* Component ID code */
- (void) read_1_byte(); /* H, V sampling factors */
- (void) read_1_byte(); /* Quantization table number */
- }
-}
-
-
-/*
- * Parse the marker stream until SOS or EOI is seen;
- * display any COM markers.
- * While the companion program wrjpgcom will always insert COM markers before
- * SOFn, other implementations might not, so we scan to SOS before stopping.
- * If we were only interested in the image dimensions, we would stop at SOFn.
- * (Conversely, if we only cared about COM markers, there would be no need
- * for special code to handle SOFn; we could treat it like other markers.)
- */
-
-static int
-scan_JPEG_header (int verbose)
-{
- int marker;
-
- /* Expect SOI at start of file */
- if (first_marker() != M_SOI)
- ERREXIT("Expected SOI marker first");
-
- /* Scan miscellaneous markers until we reach SOS. */
- for (;;) {
- marker = next_marker();
- switch (marker) {
- /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,
- * treated as SOFn. C4 in particular is actually DHT.
- */
- case M_SOF0: /* Baseline */
- case M_SOF1: /* Extended sequential, Huffman */
- case M_SOF2: /* Progressive, Huffman */
- case M_SOF3: /* Lossless, Huffman */
- case M_SOF5: /* Differential sequential, Huffman */
- case M_SOF6: /* Differential progressive, Huffman */
- case M_SOF7: /* Differential lossless, Huffman */
- case M_SOF9: /* Extended sequential, arithmetic */
- case M_SOF10: /* Progressive, arithmetic */
- case M_SOF11: /* Lossless, arithmetic */
- case M_SOF13: /* Differential sequential, arithmetic */
- case M_SOF14: /* Differential progressive, arithmetic */
- case M_SOF15: /* Differential lossless, arithmetic */
- if (verbose)
- process_SOFn(marker);
- else
- skip_variable();
- break;
-
- case M_SOS: /* stop before hitting compressed data */
- return marker;
-
- case M_EOI: /* in case it's a tables-only JPEG stream */
- return marker;
-
- case M_COM:
- process_COM();
- break;
-
- case M_APP12:
- /* Some digital camera makers put useful textual information into
- * APP12 markers, so we print those out too when in -verbose mode.
- */
- if (verbose) {
- printf("APP12 contains:\n");
- process_COM();
- } else
- skip_variable();
- break;
-
- default: /* Anything else just gets skipped */
- skip_variable(); /* we assume it has a parameter count... */
- break;
- }
- } /* end loop */
-}
-
-
-/* Command line parsing code */
-
-static const char * progname; /* program name for error messages */
-
-
-static void
-usage (void)
-/* complain about bad command line */
-{
- fprintf(stderr, "rdjpgcom displays any textual comments in a JPEG file.\n");
-
- fprintf(stderr, "Usage: %s [switches] [inputfile]\n", progname);
-
- fprintf(stderr, "Switches (names may be abbreviated):\n");
- fprintf(stderr, " -verbose Also display dimensions of JPEG image\n");
-
- exit(EXIT_FAILURE);
-}
-
-
-static int
-keymatch (char * arg, const char * keyword, int minchars)
-/* Case-insensitive matching of (possibly abbreviated) keyword switches. */
-/* keyword is the constant keyword (must be lower case already), */
-/* minchars is length of minimum legal abbreviation. */
-{
- register int ca, ck;
- register int nmatched = 0;
-
- while ((ca = *arg++) != '\0') {
- if ((ck = *keyword++) == '\0')
- return 0; /* arg longer than keyword, no good */
- if (isupper(ca)) /* force arg to lcase (assume ck is already) */
- ca = tolower(ca);
- if (ca != ck)
- return 0; /* no good */
- nmatched++; /* count matched characters */
- }
- /* reached end of argument; fail if it's too short for unique abbrev */
- if (nmatched < minchars)
- return 0;
- return 1; /* A-OK */
-}
-
-
-/*
- * The main program.
- */
-
-int
-main (int argc, char **argv)
-{
- int argn;
- char * arg;
- int verbose = 0;
-
- /* On Mac, fetch a command line. */
-#ifdef USE_CCOMMAND
- argc = ccommand(&argv);
-#endif
-
- progname = argv[0];
- if (progname == NULL || progname[0] == 0)
- progname = "rdjpgcom"; /* in case C library doesn't provide it */
-
- /* Parse switches, if any */
- for (argn = 1; argn < argc; argn++) {
- arg = argv[argn];
- if (arg[0] != '-')
- break; /* not switch, must be file name */
- arg++; /* advance over '-' */
- if (keymatch(arg, "verbose", 1)) {
- verbose++;
- } else
- usage();
- }
-
- /* Open the input file. */
- /* Unix style: expect zero or one file name */
- if (argn < argc-1) {
- fprintf(stderr, "%s: only one input file\n", progname);
- usage();
- }
- if (argn < argc) {
- if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
- exit(EXIT_FAILURE);
- }
- } else {
- /* default input file is stdin */
-#ifdef USE_SETMODE /* need to hack file mode? */
- setmode(fileno(stdin), O_BINARY);
-#endif
-#ifdef USE_FDOPEN /* need to re-open in binary mode? */
- if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open stdin\n", progname);
- exit(EXIT_FAILURE);
- }
-#else
- infile = stdin;
-#endif
- }
-
- /* Scan the JPEG headers. */
- (void) scan_JPEG_header(verbose);
-
- /* All done. */
- exit(EXIT_SUCCESS);
- return 0; /* suppress no-return-value warnings */
-}
+/*
+ * rdjpgcom.c
+ *
+ * Copyright (C) 1994-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a very simple stand-alone application that displays
+ * the text in COM (comment) markers in a JFIF file.
+ * This may be useful as an example of the minimum logic needed to parse
+ * JPEG markers.
+ */
+
+#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
+#include "jinclude.h" /* get auto-config symbols, <stdio.h> */
+
+#include <ctype.h> /* to declare isupper(), tolower() */
+#ifdef USE_SETMODE
+#include <fcntl.h> /* to declare setmode()'s parameter macros */
+/* If you have setmode() but not <io.h>, just delete this line: */
+#include <io.h> /* to declare setmode() */
+#endif
+
+#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
+#ifdef __MWERKS__
+#include <SIOUX.h> /* Metrowerks needs this */
+#include <console.h> /* ... and this */
+#endif
+#ifdef THINK_C
+#include <console.h> /* Think declares it here */
+#endif
+#endif
+
+#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
+#define READ_BINARY "r"
+#else
+#ifdef VMS /* VMS is very nonstandard */
+#define READ_BINARY "rb", "ctx=stm"
+#else /* standard ANSI-compliant case */
+#define READ_BINARY "rb"
+#endif
+#endif
+
+#ifndef EXIT_FAILURE /* define exit() codes if not provided */
+#define EXIT_FAILURE 1
+#endif
+#ifndef EXIT_SUCCESS
+#ifdef VMS
+#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
+#else
+#define EXIT_SUCCESS 0
+#endif
+#endif
+
+
+/*
+ * These macros are used to read the input file.
+ * To reuse this code in another application, you might need to change these.
+ */
+
+static FILE * infile; /* input JPEG file */
+
+/* Return next input byte, or EOF if no more */
+#define NEXTBYTE() getc(infile)
+
+
+/* Error exit handler */
+#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE))
+
+
+/* Read one byte, testing for EOF */
+static int
+read_1_byte (void)
+{
+ int c;
+
+ c = NEXTBYTE();
+ if (c == EOF)
+ ERREXIT("Premature EOF in JPEG file");
+ return c;
+}
+
+/* Read 2 bytes, convert to unsigned int */
+/* All 2-byte quantities in JPEG markers are MSB first */
+static unsigned int
+read_2_bytes (void)
+{
+ int c1, c2;
+
+ c1 = NEXTBYTE();
+ if (c1 == EOF)
+ ERREXIT("Premature EOF in JPEG file");
+ c2 = NEXTBYTE();
+ if (c2 == EOF)
+ ERREXIT("Premature EOF in JPEG file");
+ return (((unsigned int) c1) << 8) + ((unsigned int) c2);
+}
+
+
+/*
+ * JPEG markers consist of one or more 0xFF bytes, followed by a marker
+ * code byte (which is not an FF). Here are the marker codes of interest
+ * in this program. (See jdmarker.c for a more complete list.)
+ */
+
+#define M_SOF0 0xC0 /* Start Of Frame N */
+#define M_SOF1 0xC1 /* N indicates which compression process */
+#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
+#define M_SOF3 0xC3
+#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
+#define M_SOF6 0xC6
+#define M_SOF7 0xC7
+#define M_SOF9 0xC9
+#define M_SOF10 0xCA
+#define M_SOF11 0xCB
+#define M_SOF13 0xCD
+#define M_SOF14 0xCE
+#define M_SOF15 0xCF
+#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
+#define M_EOI 0xD9 /* End Of Image (end of datastream) */
+#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
+#define M_APP0 0xE0 /* Application-specific marker, type N */
+#define M_APP12 0xEC /* (we don't bother to list all 16 APPn's) */
+#define M_COM 0xFE /* COMment */
+
+
+/*
+ * Find the next JPEG marker and return its marker code.
+ * We expect at least one FF byte, possibly more if the compressor used FFs
+ * to pad the file.
+ * There could also be non-FF garbage between markers. The treatment of such
+ * garbage is unspecified; we choose to skip over it but emit a warning msg.
+ * NB: this routine must not be used after seeing SOS marker, since it will
+ * not deal correctly with FF/00 sequences in the compressed image data...
+ */
+
+static int
+next_marker (void)
+{
+ int c;
+ int discarded_bytes = 0;
+
+ /* Find 0xFF byte; count and skip any non-FFs. */
+ c = read_1_byte();
+ while (c != 0xFF) {
+ discarded_bytes++;
+ c = read_1_byte();
+ }
+ /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs
+ * are legal as pad bytes, so don't count them in discarded_bytes.
+ */
+ do {
+ c = read_1_byte();
+ } while (c == 0xFF);
+
+ if (discarded_bytes != 0) {
+ fprintf(stderr, "Warning: garbage data found in JPEG file\n");
+ }
+
+ return c;
+}
+
+
+/*
+ * Read the initial marker, which should be SOI.
+ * For a JFIF file, the first two bytes of the file should be literally
+ * 0xFF M_SOI. To be more general, we could use next_marker, but if the
+ * input file weren't actually JPEG at all, next_marker might read the whole
+ * file and then return a misleading error message...
+ */
+
+static int
+first_marker (void)
+{
+ int c1, c2;
+
+ c1 = NEXTBYTE();
+ c2 = NEXTBYTE();
+ if (c1 != 0xFF || c2 != M_SOI)
+ ERREXIT("Not a JPEG file");
+ return c2;
+}
+
+
+/*
+ * Most types of marker are followed by a variable-length parameter segment.
+ * This routine skips over the parameters for any marker we don't otherwise
+ * want to process.
+ * Note that we MUST skip the parameter segment explicitly in order not to
+ * be fooled by 0xFF bytes that might appear within the parameter segment;
+ * such bytes do NOT introduce new markers.
+ */
+
+static void
+skip_variable (void)
+/* Skip over an unknown or uninteresting variable-length marker */
+{
+ unsigned int length;
+
+ /* Get the marker parameter length count */
+ length = read_2_bytes();
+ /* Length includes itself, so must be at least 2 */
+ if (length < 2)
+ ERREXIT("Erroneous JPEG marker length");
+ length -= 2;
+ /* Skip over the remaining bytes */
+ while (length > 0) {
+ (void) read_1_byte();
+ length--;
+ }
+}
+
+
+/*
+ * Process a COM marker.
+ * We want to print out the marker contents as legible text;
+ * we must guard against non-text junk and varying newline representations.
+ */
+
+static void
+process_COM (void)
+{
+ unsigned int length;
+ int ch;
+ int lastch = 0;
+
+ /* Get the marker parameter length count */
+ length = read_2_bytes();
+ /* Length includes itself, so must be at least 2 */
+ if (length < 2)
+ ERREXIT("Erroneous JPEG marker length");
+ length -= 2;
+
+ while (length > 0) {
+ ch = read_1_byte();
+ /* Emit the character in a readable form.
+ * Nonprintables are converted to \nnn form,
+ * while \ is converted to \\.
+ * Newlines in CR, CR/LF, or LF form will be printed as one newline.
+ */
+ if (ch == '\r') {
+ printf("\n");
+ } else if (ch == '\n') {
+ if (lastch != '\r')
+ printf("\n");
+ } else if (ch == '\\') {
+ printf("\\\\");
+ } else if (isprint(ch)) {
+ putc(ch, stdout);
+ } else {
+ printf("\\%03o", ch);
+ }
+ lastch = ch;
+ length--;
+ }
+ printf("\n");
+}
+
+
+/*
+ * Process a SOFn marker.
+ * This code is only needed if you want to know the image dimensions...
+ */
+
+static void
+process_SOFn (int marker)
+{
+ unsigned int length;
+ unsigned int image_height, image_width;
+ int data_precision, num_components;
+ const char * process;
+ int ci;
+
+ length = read_2_bytes(); /* usual parameter length count */
+
+ data_precision = read_1_byte();
+ image_height = read_2_bytes();
+ image_width = read_2_bytes();
+ num_components = read_1_byte();
+
+#ifdef NO_SWITCH
+ if (marker==M_SOF0) process = "Baseline";
+ else if (marker==M_SOF1) process = "Extended sequential";
+ else if (marker==M_SOF2) process = "Progressive";
+ else if (marker==M_SOF3) process = "Lossless";
+ else if (marker==M_SOF5) process = "Differential sequential";
+ else if (marker==M_SOF6) process = "Differential progressive";
+ else if (marker==M_SOF7) process = "Differential lossless";
+ else if (marker==M_SOF9) process = "Extended sequential, arithmetic coding";
+ else if (marker==M_SOF10) process = "Progressive, arithmetic coding";
+ else if (marker==M_SOF11) process = "Lossless, arithmetic coding";
+ else if (marker==M_SOF13) process = "Differential sequential, arithmetic coding";
+ else if (marker==M_SOF14) process = "Differential progressive, arithmetic coding";
+ else if (marker==M_SOF15) process = "Differential lossless, arithmetic coding";
+ else process = "Unknown";
+#else
+ switch (marker) {
+ case M_SOF0: process = "Baseline"; break;
+ case M_SOF1: process = "Extended sequential"; break;
+ case M_SOF2: process = "Progressive"; break;
+ case M_SOF3: process = "Lossless"; break;
+ case M_SOF5: process = "Differential sequential"; break;
+ case M_SOF6: process = "Differential progressive"; break;
+ case M_SOF7: process = "Differential lossless"; break;
+ case M_SOF9: process = "Extended sequential, arithmetic coding"; break;
+ case M_SOF10: process = "Progressive, arithmetic coding"; break;
+ case M_SOF11: process = "Lossless, arithmetic coding"; break;
+ case M_SOF13: process = "Differential sequential, arithmetic coding"; break;
+ case M_SOF14: process = "Differential progressive, arithmetic coding"; break;
+ case M_SOF15: process = "Differential lossless, arithmetic coding"; break;
+ default: process = "Unknown"; break;
+ }
+#endif
+
+ printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n",
+ image_width, image_height, num_components, data_precision);
+ printf("JPEG process: %s\n", process);
+
+ if (length != (unsigned int) (8 + num_components * 3))
+ ERREXIT("Bogus SOF marker length");
+
+ for (ci = 0; ci < num_components; ci++) {
+ (void) read_1_byte(); /* Component ID code */
+ (void) read_1_byte(); /* H, V sampling factors */
+ (void) read_1_byte(); /* Quantization table number */
+ }
+}
+
+
+/*
+ * Parse the marker stream until SOS or EOI is seen;
+ * display any COM markers.
+ * While the companion program wrjpgcom will always insert COM markers before
+ * SOFn, other implementations might not, so we scan to SOS before stopping.
+ * If we were only interested in the image dimensions, we would stop at SOFn.
+ * (Conversely, if we only cared about COM markers, there would be no need
+ * for special code to handle SOFn; we could treat it like other markers.)
+ */
+
+static int
+scan_JPEG_header (int verbose)
+{
+ int marker;
+
+ /* Expect SOI at start of file */
+ if (first_marker() != M_SOI)
+ ERREXIT("Expected SOI marker first");
+
+ /* Scan miscellaneous markers until we reach SOS. */
+ for (;;) {
+ marker = next_marker();
+ switch (marker) {
+ /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,
+ * treated as SOFn. C4 in particular is actually DHT.
+ */
+ case M_SOF0: /* Baseline */
+ case M_SOF1: /* Extended sequential, Huffman */
+ case M_SOF2: /* Progressive, Huffman */
+ case M_SOF3: /* Lossless, Huffman */
+ case M_SOF5: /* Differential sequential, Huffman */
+ case M_SOF6: /* Differential progressive, Huffman */
+ case M_SOF7: /* Differential lossless, Huffman */
+ case M_SOF9: /* Extended sequential, arithmetic */
+ case M_SOF10: /* Progressive, arithmetic */
+ case M_SOF11: /* Lossless, arithmetic */
+ case M_SOF13: /* Differential sequential, arithmetic */
+ case M_SOF14: /* Differential progressive, arithmetic */
+ case M_SOF15: /* Differential lossless, arithmetic */
+ if (verbose)
+ process_SOFn(marker);
+ else
+ skip_variable();
+ break;
+
+ case M_SOS: /* stop before hitting compressed data */
+ return marker;
+
+ case M_EOI: /* in case it's a tables-only JPEG stream */
+ return marker;
+
+ case M_COM:
+ process_COM();
+ break;
+
+ case M_APP12:
+ /* Some digital camera makers put useful textual information into
+ * APP12 markers, so we print those out too when in -verbose mode.
+ */
+ if (verbose) {
+ printf("APP12 contains:\n");
+ process_COM();
+ } else
+ skip_variable();
+ break;
+
+ default: /* Anything else just gets skipped */
+ skip_variable(); /* we assume it has a parameter count... */
+ break;
+ }
+ } /* end loop */
+}
+
+
+/* Command line parsing code */
+
+static const char * progname; /* program name for error messages */
+
+
+static void
+usage (void)
+/* complain about bad command line */
+{
+ fprintf(stderr, "rdjpgcom displays any textual comments in a JPEG file.\n");
+
+ fprintf(stderr, "Usage: %s [switches] [inputfile]\n", progname);
+
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
+ fprintf(stderr, " -verbose Also display dimensions of JPEG image\n");
+
+ exit(EXIT_FAILURE);
+}
+
+
+static int
+keymatch (char * arg, const char * keyword, int minchars)
+/* Case-insensitive matching of (possibly abbreviated) keyword switches. */
+/* keyword is the constant keyword (must be lower case already), */
+/* minchars is length of minimum legal abbreviation. */
+{
+ register int ca, ck;
+ register int nmatched = 0;
+
+ while ((ca = *arg++) != '\0') {
+ if ((ck = *keyword++) == '\0')
+ return 0; /* arg longer than keyword, no good */
+ if (isupper(ca)) /* force arg to lcase (assume ck is already) */
+ ca = tolower(ca);
+ if (ca != ck)
+ return 0; /* no good */
+ nmatched++; /* count matched characters */
+ }
+ /* reached end of argument; fail if it's too short for unique abbrev */
+ if (nmatched < minchars)
+ return 0;
+ return 1; /* A-OK */
+}
+
+
+/*
+ * The main program.
+ */
+
+int
+main (int argc, char **argv)
+{
+ int argn;
+ char * arg;
+ int verbose = 0;
+
+ /* On Mac, fetch a command line. */
+#ifdef USE_CCOMMAND
+ argc = ccommand(&argv);
+#endif
+
+ progname = argv[0];
+ if (progname == NULL || progname[0] == 0)
+ progname = "rdjpgcom"; /* in case C library doesn't provide it */
+
+ /* Parse switches, if any */
+ for (argn = 1; argn < argc; argn++) {
+ arg = argv[argn];
+ if (arg[0] != '-')
+ break; /* not switch, must be file name */
+ arg++; /* advance over '-' */
+ if (keymatch(arg, "verbose", 1)) {
+ verbose++;
+ } else
+ usage();
+ }
+
+ /* Open the input file. */
+ /* Unix style: expect zero or one file name */
+ if (argn < argc-1) {
+ fprintf(stderr, "%s: only one input file\n", progname);
+ usage();
+ }
+ if (argn < argc) {
+ if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default input file is stdin */
+#ifdef USE_SETMODE /* need to hack file mode? */
+ setmode(fileno(stdin), O_BINARY);
+#endif
+#ifdef USE_FDOPEN /* need to re-open in binary mode? */
+ if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open stdin\n", progname);
+ exit(EXIT_FAILURE);
+ }
+#else
+ infile = stdin;
+#endif
+ }
+
+ /* Scan the JPEG headers. */
+ (void) scan_JPEG_header(verbose);
+
+ /* All done. */
+ exit(EXIT_SUCCESS);
+ return 0; /* suppress no-return-value warnings */
+}
diff --git a/test/monniaux/jpeg-6b/rdppm.c b/test/monniaux/jpeg-6b/rdppm.c
index 2543ff5e..1df35c1b 100644
--- a/test/monniaux/jpeg-6b/rdppm.c
+++ b/test/monniaux/jpeg-6b/rdppm.c
@@ -418,7 +418,7 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
half_maxval = maxval / 2;
for (val = 0; val <= (INT32) maxval; val++) {
/* The multiplication here must be done in 32 bits to avoid overflow */
- source->rescale[val] = (JSAMPLE) DIVISION((val*MAXJSAMPLE + half_maxval), maxval);
+ source->rescale[val] = (JSAMPLE) ((val*MAXJSAMPLE + half_maxval)/maxval);
}
}
}
diff --git a/test/monniaux/jpeg-6b/rdswitch.c b/test/monniaux/jpeg-6b/rdswitch.c
index 4f4bb4f5..b915ad9d 100644
--- a/test/monniaux/jpeg-6b/rdswitch.c
+++ b/test/monniaux/jpeg-6b/rdswitch.c
@@ -1,332 +1,332 @@
-/*
- * rdswitch.c
- *
- * Copyright (C) 1991-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to process some of cjpeg's more complicated
- * command-line switches. Switches processed here are:
- * -qtables file Read quantization tables from text file
- * -scans file Read scan script from text file
- * -qslots N[,N,...] Set component quantization table selectors
- * -sample HxV[,HxV,...] Set component sampling factors
- */
-
-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
-#include <ctype.h> /* to declare isdigit(), isspace() */
-
-
-LOCAL(int)
-text_getc (FILE * file)
-/* Read next char, skipping over any comments (# to end of line) */
-/* A comment/newline sequence is returned as a newline */
-{
- register int ch;
-
- ch = getc(file);
- if (ch == '#') {
- do {
- ch = getc(file);
- } while (ch != '\n' && ch != EOF);
- }
- return ch;
-}
-
-
-LOCAL(boolean)
-read_text_integer (FILE * file, long * result, int * termchar)
-/* Read an unsigned decimal integer from a file, store it in result */
-/* Reads one trailing character after the integer; returns it in termchar */
-{
- register int ch;
- register long val;
-
- /* Skip any leading whitespace, detect EOF */
- do {
- ch = text_getc(file);
- if (ch == EOF) {
- *termchar = ch;
- return FALSE;
- }
- } while (isspace(ch));
-
- if (! isdigit(ch)) {
- *termchar = ch;
- return FALSE;
- }
-
- val = ch - '0';
- while ((ch = text_getc(file)) != EOF) {
- if (! isdigit(ch))
- break;
- val *= 10;
- val += ch - '0';
- }
- *result = val;
- *termchar = ch;
- return TRUE;
-}
-
-
-GLOBAL(boolean)
-read_quant_tables (j_compress_ptr cinfo, char * filename,
- int scale_factor, boolean force_baseline)
-/* Read a set of quantization tables from the specified file.
- * The file is plain ASCII text: decimal numbers with whitespace between.
- * Comments preceded by '#' may be included in the file.
- * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values.
- * The tables are implicitly numbered 0,1,etc.
- * NOTE: does not affect the qslots mapping, which will default to selecting
- * table 0 for luminance (or primary) components, 1 for chrominance components.
- * You must use -qslots if you want a different component->table mapping.
- */
-{
- FILE * fp;
- int tblno, i, termchar;
- long val;
- unsigned int table[DCTSIZE2];
-
- if ((fp = fopen(filename, "r")) == NULL) {
- fprintf(stderr, "Can't open table file %s\n", filename);
- return FALSE;
- }
- tblno = 0;
-
- while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */
- if (tblno >= NUM_QUANT_TBLS) {
- fprintf(stderr, "Too many tables in file %s\n", filename);
- fclose(fp);
- return FALSE;
- }
- table[0] = (unsigned int) val;
- for (i = 1; i < DCTSIZE2; i++) {
- if (! read_text_integer(fp, &val, &termchar)) {
- fprintf(stderr, "Invalid table data in file %s\n", filename);
- fclose(fp);
- return FALSE;
- }
- table[i] = (unsigned int) val;
- }
- jpeg_add_quant_table(cinfo, tblno, table, scale_factor, force_baseline);
- tblno++;
- }
-
- if (termchar != EOF) {
- fprintf(stderr, "Non-numeric data in file %s\n", filename);
- fclose(fp);
- return FALSE;
- }
-
- fclose(fp);
- return TRUE;
-}
-
-
-#ifdef C_MULTISCAN_FILES_SUPPORTED
-
-LOCAL(boolean)
-read_scan_integer (FILE * file, long * result, int * termchar)
-/* Variant of read_text_integer that always looks for a non-space termchar;
- * this simplifies parsing of punctuation in scan scripts.
- */
-{
- register int ch;
-
- if (! read_text_integer(file, result, termchar))
- return FALSE;
- ch = *termchar;
- while (ch != EOF && isspace(ch))
- ch = text_getc(file);
- if (isdigit(ch)) { /* oops, put it back */
- if (ungetc(ch, file) == EOF)
- return FALSE;
- ch = ' ';
- } else {
- /* Any separators other than ';' and ':' are ignored;
- * this allows user to insert commas, etc, if desired.
- */
- if (ch != EOF && ch != ';' && ch != ':')
- ch = ' ';
- }
- *termchar = ch;
- return TRUE;
-}
-
-
-GLOBAL(boolean)
-read_scan_script (j_compress_ptr cinfo, char * filename)
-/* Read a scan script from the specified text file.
- * Each entry in the file defines one scan to be emitted.
- * Entries are separated by semicolons ';'.
- * An entry contains one to four component indexes,
- * optionally followed by a colon ':' and four progressive-JPEG parameters.
- * The component indexes denote which component(s) are to be transmitted
- * in the current scan. The first component has index 0.
- * Sequential JPEG is used if the progressive-JPEG parameters are omitted.
- * The file is free format text: any whitespace may appear between numbers
- * and the ':' and ';' punctuation marks. Also, other punctuation (such
- * as commas or dashes) can be placed between numbers if desired.
- * Comments preceded by '#' may be included in the file.
- * Note: we do very little validity checking here;
- * jcmaster.c will validate the script parameters.
- */
-{
- FILE * fp;
- int scanno, ncomps, termchar;
- long val;
- jpeg_scan_info * scanptr;
-#define MAX_SCANS 100 /* quite arbitrary limit */
- jpeg_scan_info scans[MAX_SCANS];
-
- if ((fp = fopen(filename, "r")) == NULL) {
- fprintf(stderr, "Can't open scan definition file %s\n", filename);
- return FALSE;
- }
- scanptr = scans;
- scanno = 0;
-
- while (read_scan_integer(fp, &val, &termchar)) {
- if (scanno >= MAX_SCANS) {
- fprintf(stderr, "Too many scans defined in file %s\n", filename);
- fclose(fp);
- return FALSE;
- }
- scanptr->component_index[0] = (int) val;
- ncomps = 1;
- while (termchar == ' ') {
- if (ncomps >= MAX_COMPS_IN_SCAN) {
- fprintf(stderr, "Too many components in one scan in file %s\n",
- filename);
- fclose(fp);
- return FALSE;
- }
- if (! read_scan_integer(fp, &val, &termchar))
- goto bogus;
- scanptr->component_index[ncomps] = (int) val;
- ncomps++;
- }
- scanptr->comps_in_scan = ncomps;
- if (termchar == ':') {
- if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
- goto bogus;
- scanptr->Ss = (int) val;
- if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
- goto bogus;
- scanptr->Se = (int) val;
- if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
- goto bogus;
- scanptr->Ah = (int) val;
- if (! read_scan_integer(fp, &val, &termchar))
- goto bogus;
- scanptr->Al = (int) val;
- } else {
- /* set non-progressive parameters */
- scanptr->Ss = 0;
- scanptr->Se = DCTSIZE2-1;
- scanptr->Ah = 0;
- scanptr->Al = 0;
- }
- if (termchar != ';' && termchar != EOF) {
-bogus:
- fprintf(stderr, "Invalid scan entry format in file %s\n", filename);
- fclose(fp);
- return FALSE;
- }
- scanptr++, scanno++;
- }
-
- if (termchar != EOF) {
- fprintf(stderr, "Non-numeric data in file %s\n", filename);
- fclose(fp);
- return FALSE;
- }
-
- if (scanno > 0) {
- /* Stash completed scan list in cinfo structure.
- * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data,
- * but if you want to compress multiple images you'd want JPOOL_PERMANENT.
- */
- scanptr = (jpeg_scan_info *)
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
- scanno * SIZEOF(jpeg_scan_info));
- MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info));
- cinfo->scan_info = scanptr;
- cinfo->num_scans = scanno;
- }
-
- fclose(fp);
- return TRUE;
-}
-
-#endif /* C_MULTISCAN_FILES_SUPPORTED */
-
-
-GLOBAL(boolean)
-set_quant_slots (j_compress_ptr cinfo, char *arg)
-/* Process a quantization-table-selectors parameter string, of the form
- * N[,N,...]
- * If there are more components than parameters, the last value is replicated.
- */
-{
- int val = 0; /* default table # */
- int ci;
- char ch;
-
- for (ci = 0; ci < MAX_COMPONENTS; ci++) {
- if (*arg) {
- ch = ','; /* if not set by sscanf, will be ',' */
- if (sscanf(arg, "%d%c", &val, &ch) < 1)
- return FALSE;
- if (ch != ',') /* syntax check */
- return FALSE;
- if (val < 0 || val >= NUM_QUANT_TBLS) {
- fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n",
- NUM_QUANT_TBLS-1);
- return FALSE;
- }
- cinfo->comp_info[ci].quant_tbl_no = val;
- while (*arg && *arg++ != ',') /* advance to next segment of arg string */
- ;
- } else {
- /* reached end of parameter, set remaining components to last table */
- cinfo->comp_info[ci].quant_tbl_no = val;
- }
- }
- return TRUE;
-}
-
-
-GLOBAL(boolean)
-set_sample_factors (j_compress_ptr cinfo, char *arg)
-/* Process a sample-factors parameter string, of the form
- * HxV[,HxV,...]
- * If there are more components than parameters, "1x1" is assumed for the rest.
- */
-{
- int ci, val1, val2;
- char ch1, ch2;
-
- for (ci = 0; ci < MAX_COMPONENTS; ci++) {
- if (*arg) {
- ch2 = ','; /* if not set by sscanf, will be ',' */
- if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3)
- return FALSE;
- if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */
- return FALSE;
- if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) {
- fprintf(stderr, "JPEG sampling factors must be 1..4\n");
- return FALSE;
- }
- cinfo->comp_info[ci].h_samp_factor = val1;
- cinfo->comp_info[ci].v_samp_factor = val2;
- while (*arg && *arg++ != ',') /* advance to next segment of arg string */
- ;
- } else {
- /* reached end of parameter, set remaining components to 1x1 sampling */
- cinfo->comp_info[ci].h_samp_factor = 1;
- cinfo->comp_info[ci].v_samp_factor = 1;
- }
- }
- return TRUE;
-}
+/*
+ * rdswitch.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to process some of cjpeg's more complicated
+ * command-line switches. Switches processed here are:
+ * -qtables file Read quantization tables from text file
+ * -scans file Read scan script from text file
+ * -qslots N[,N,...] Set component quantization table selectors
+ * -sample HxV[,HxV,...] Set component sampling factors
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+#include <ctype.h> /* to declare isdigit(), isspace() */
+
+
+LOCAL(int)
+text_getc (FILE * file)
+/* Read next char, skipping over any comments (# to end of line) */
+/* A comment/newline sequence is returned as a newline */
+{
+ register int ch;
+
+ ch = getc(file);
+ if (ch == '#') {
+ do {
+ ch = getc(file);
+ } while (ch != '\n' && ch != EOF);
+ }
+ return ch;
+}
+
+
+LOCAL(boolean)
+read_text_integer (FILE * file, long * result, int * termchar)
+/* Read an unsigned decimal integer from a file, store it in result */
+/* Reads one trailing character after the integer; returns it in termchar */
+{
+ register int ch;
+ register long val;
+
+ /* Skip any leading whitespace, detect EOF */
+ do {
+ ch = text_getc(file);
+ if (ch == EOF) {
+ *termchar = ch;
+ return FALSE;
+ }
+ } while (isspace(ch));
+
+ if (! isdigit(ch)) {
+ *termchar = ch;
+ return FALSE;
+ }
+
+ val = ch - '0';
+ while ((ch = text_getc(file)) != EOF) {
+ if (! isdigit(ch))
+ break;
+ val *= 10;
+ val += ch - '0';
+ }
+ *result = val;
+ *termchar = ch;
+ return TRUE;
+}
+
+
+GLOBAL(boolean)
+read_quant_tables (j_compress_ptr cinfo, char * filename,
+ int scale_factor, boolean force_baseline)
+/* Read a set of quantization tables from the specified file.
+ * The file is plain ASCII text: decimal numbers with whitespace between.
+ * Comments preceded by '#' may be included in the file.
+ * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values.
+ * The tables are implicitly numbered 0,1,etc.
+ * NOTE: does not affect the qslots mapping, which will default to selecting
+ * table 0 for luminance (or primary) components, 1 for chrominance components.
+ * You must use -qslots if you want a different component->table mapping.
+ */
+{
+ FILE * fp;
+ int tblno, i, termchar;
+ long val;
+ unsigned int table[DCTSIZE2];
+
+ if ((fp = fopen(filename, "r")) == NULL) {
+ fprintf(stderr, "Can't open table file %s\n", filename);
+ return FALSE;
+ }
+ tblno = 0;
+
+ while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */
+ if (tblno >= NUM_QUANT_TBLS) {
+ fprintf(stderr, "Too many tables in file %s\n", filename);
+ fclose(fp);
+ return FALSE;
+ }
+ table[0] = (unsigned int) val;
+ for (i = 1; i < DCTSIZE2; i++) {
+ if (! read_text_integer(fp, &val, &termchar)) {
+ fprintf(stderr, "Invalid table data in file %s\n", filename);
+ fclose(fp);
+ return FALSE;
+ }
+ table[i] = (unsigned int) val;
+ }
+ jpeg_add_quant_table(cinfo, tblno, table, scale_factor, force_baseline);
+ tblno++;
+ }
+
+ if (termchar != EOF) {
+ fprintf(stderr, "Non-numeric data in file %s\n", filename);
+ fclose(fp);
+ return FALSE;
+ }
+
+ fclose(fp);
+ return TRUE;
+}
+
+
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+
+LOCAL(boolean)
+read_scan_integer (FILE * file, long * result, int * termchar)
+/* Variant of read_text_integer that always looks for a non-space termchar;
+ * this simplifies parsing of punctuation in scan scripts.
+ */
+{
+ register int ch;
+
+ if (! read_text_integer(file, result, termchar))
+ return FALSE;
+ ch = *termchar;
+ while (ch != EOF && isspace(ch))
+ ch = text_getc(file);
+ if (isdigit(ch)) { /* oops, put it back */
+ if (ungetc(ch, file) == EOF)
+ return FALSE;
+ ch = ' ';
+ } else {
+ /* Any separators other than ';' and ':' are ignored;
+ * this allows user to insert commas, etc, if desired.
+ */
+ if (ch != EOF && ch != ';' && ch != ':')
+ ch = ' ';
+ }
+ *termchar = ch;
+ return TRUE;
+}
+
+
+GLOBAL(boolean)
+read_scan_script (j_compress_ptr cinfo, char * filename)
+/* Read a scan script from the specified text file.
+ * Each entry in the file defines one scan to be emitted.
+ * Entries are separated by semicolons ';'.
+ * An entry contains one to four component indexes,
+ * optionally followed by a colon ':' and four progressive-JPEG parameters.
+ * The component indexes denote which component(s) are to be transmitted
+ * in the current scan. The first component has index 0.
+ * Sequential JPEG is used if the progressive-JPEG parameters are omitted.
+ * The file is free format text: any whitespace may appear between numbers
+ * and the ':' and ';' punctuation marks. Also, other punctuation (such
+ * as commas or dashes) can be placed between numbers if desired.
+ * Comments preceded by '#' may be included in the file.
+ * Note: we do very little validity checking here;
+ * jcmaster.c will validate the script parameters.
+ */
+{
+ FILE * fp;
+ int scanno, ncomps, termchar;
+ long val;
+ jpeg_scan_info * scanptr;
+#define MAX_SCANS 100 /* quite arbitrary limit */
+ jpeg_scan_info scans[MAX_SCANS];
+
+ if ((fp = fopen(filename, "r")) == NULL) {
+ fprintf(stderr, "Can't open scan definition file %s\n", filename);
+ return FALSE;
+ }
+ scanptr = scans;
+ scanno = 0;
+
+ while (read_scan_integer(fp, &val, &termchar)) {
+ if (scanno >= MAX_SCANS) {
+ fprintf(stderr, "Too many scans defined in file %s\n", filename);
+ fclose(fp);
+ return FALSE;
+ }
+ scanptr->component_index[0] = (int) val;
+ ncomps = 1;
+ while (termchar == ' ') {
+ if (ncomps >= MAX_COMPS_IN_SCAN) {
+ fprintf(stderr, "Too many components in one scan in file %s\n",
+ filename);
+ fclose(fp);
+ return FALSE;
+ }
+ if (! read_scan_integer(fp, &val, &termchar))
+ goto bogus;
+ scanptr->component_index[ncomps] = (int) val;
+ ncomps++;
+ }
+ scanptr->comps_in_scan = ncomps;
+ if (termchar == ':') {
+ if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
+ goto bogus;
+ scanptr->Ss = (int) val;
+ if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
+ goto bogus;
+ scanptr->Se = (int) val;
+ if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
+ goto bogus;
+ scanptr->Ah = (int) val;
+ if (! read_scan_integer(fp, &val, &termchar))
+ goto bogus;
+ scanptr->Al = (int) val;
+ } else {
+ /* set non-progressive parameters */
+ scanptr->Ss = 0;
+ scanptr->Se = DCTSIZE2-1;
+ scanptr->Ah = 0;
+ scanptr->Al = 0;
+ }
+ if (termchar != ';' && termchar != EOF) {
+bogus:
+ fprintf(stderr, "Invalid scan entry format in file %s\n", filename);
+ fclose(fp);
+ return FALSE;
+ }
+ scanptr++, scanno++;
+ }
+
+ if (termchar != EOF) {
+ fprintf(stderr, "Non-numeric data in file %s\n", filename);
+ fclose(fp);
+ return FALSE;
+ }
+
+ if (scanno > 0) {
+ /* Stash completed scan list in cinfo structure.
+ * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data,
+ * but if you want to compress multiple images you'd want JPOOL_PERMANENT.
+ */
+ scanptr = (jpeg_scan_info *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ scanno * SIZEOF(jpeg_scan_info));
+ MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info));
+ cinfo->scan_info = scanptr;
+ cinfo->num_scans = scanno;
+ }
+
+ fclose(fp);
+ return TRUE;
+}
+
+#endif /* C_MULTISCAN_FILES_SUPPORTED */
+
+
+GLOBAL(boolean)
+set_quant_slots (j_compress_ptr cinfo, char *arg)
+/* Process a quantization-table-selectors parameter string, of the form
+ * N[,N,...]
+ * If there are more components than parameters, the last value is replicated.
+ */
+{
+ int val = 0; /* default table # */
+ int ci;
+ char ch;
+
+ for (ci = 0; ci < MAX_COMPONENTS; ci++) {
+ if (*arg) {
+ ch = ','; /* if not set by sscanf, will be ',' */
+ if (sscanf(arg, "%d%c", &val, &ch) < 1)
+ return FALSE;
+ if (ch != ',') /* syntax check */
+ return FALSE;
+ if (val < 0 || val >= NUM_QUANT_TBLS) {
+ fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n",
+ NUM_QUANT_TBLS-1);
+ return FALSE;
+ }
+ cinfo->comp_info[ci].quant_tbl_no = val;
+ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
+ ;
+ } else {
+ /* reached end of parameter, set remaining components to last table */
+ cinfo->comp_info[ci].quant_tbl_no = val;
+ }
+ }
+ return TRUE;
+}
+
+
+GLOBAL(boolean)
+set_sample_factors (j_compress_ptr cinfo, char *arg)
+/* Process a sample-factors parameter string, of the form
+ * HxV[,HxV,...]
+ * If there are more components than parameters, "1x1" is assumed for the rest.
+ */
+{
+ int ci, val1, val2;
+ char ch1, ch2;
+
+ for (ci = 0; ci < MAX_COMPONENTS; ci++) {
+ if (*arg) {
+ ch2 = ','; /* if not set by sscanf, will be ',' */
+ if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3)
+ return FALSE;
+ if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */
+ return FALSE;
+ if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) {
+ fprintf(stderr, "JPEG sampling factors must be 1..4\n");
+ return FALSE;
+ }
+ cinfo->comp_info[ci].h_samp_factor = val1;
+ cinfo->comp_info[ci].v_samp_factor = val2;
+ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
+ ;
+ } else {
+ /* reached end of parameter, set remaining components to 1x1 sampling */
+ cinfo->comp_info[ci].h_samp_factor = 1;
+ cinfo->comp_info[ci].v_samp_factor = 1;
+ }
+ }
+ return TRUE;
+}
diff --git a/test/monniaux/jpeg-6b/transupp.c b/test/monniaux/jpeg-6b/transupp.c
index e5ec5642..9f6e57f4 100644
--- a/test/monniaux/jpeg-6b/transupp.c
+++ b/test/monniaux/jpeg-6b/transupp.c
@@ -79,7 +79,7 @@ do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
* mirroring by changing the signs of odd-numbered columns.
* Partial iMCUs at the right edge are left untouched.
*/
- MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
+ MCU_cols = INT_DIV(dstinfo->image_width, (dstinfo->max_h_samp_factor * DCTSIZE));
for (ci = 0; ci < dstinfo->num_components; ci++) {
compptr = dstinfo->comp_info + ci;
@@ -131,7 +131,7 @@ do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
* of odd-numbered rows.
* Partial iMCUs at the bottom edge are copied verbatim.
*/
- MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
+ MCU_rows = INT_DIV(dstinfo->image_height, (dstinfo->max_v_samp_factor * DCTSIZE));
for (ci = 0; ci < dstinfo->num_components; ci++) {
compptr = dstinfo->comp_info + ci;
@@ -246,7 +246,7 @@ do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
* at the (output) right edge properly. They just get transposed and
* not mirrored.
*/
- MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
+ MCU_cols = INT_DIV(dstinfo->image_width, (dstinfo->max_h_samp_factor * DCTSIZE));
for (ci = 0; ci < dstinfo->num_components; ci++) {
compptr = dstinfo->comp_info + ci;
@@ -310,7 +310,7 @@ do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
* at the (output) bottom edge properly. They just get transposed and
* not mirrored.
*/
- MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
+ MCU_rows = INT_DIV(dstinfo->image_height, (dstinfo->max_v_samp_factor * DCTSIZE));
for (ci = 0; ci < dstinfo->num_components; ci++) {
compptr = dstinfo->comp_info + ci;
@@ -371,8 +371,8 @@ do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
JCOEFPTR src_ptr, dst_ptr;
jpeg_component_info *compptr;
- MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
- MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
+ MCU_cols = INT_DIV(dstinfo->image_width, (dstinfo->max_h_samp_factor * DCTSIZE));
+ MCU_rows = INT_DIV(dstinfo->image_height, (dstinfo->max_v_samp_factor * DCTSIZE));
for (ci = 0; ci < dstinfo->num_components; ci++) {
compptr = dstinfo->comp_info + ci;
@@ -475,8 +475,8 @@ do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
JCOEFPTR src_ptr, dst_ptr;
jpeg_component_info *compptr;
- MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
- MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
+ MCU_cols = INT_DIV(dstinfo->image_width, (dstinfo->max_h_samp_factor * DCTSIZE));
+ MCU_rows = INT_DIV(dstinfo->image_height, (dstinfo->max_v_samp_factor * DCTSIZE));
for (ci = 0; ci < dstinfo->num_components; ci++) {
compptr = dstinfo->comp_info + ci;
@@ -582,6 +582,52 @@ jtransform_request_workspace (j_decompress_ptr srcinfo,
info->num_components = srcinfo->num_components;
}
+#ifdef NO_SWITCH
+ int choice = info->transform;
+ if (choice == JXFORM_NONE ||
+ choice == JXFORM_FLIP_H) {
+ } else if (choice == JXFORM_FLIP_V ||
+ choice == JXFORM_ROT_180) {
+ /* Need workspace arrays having same dimensions as source image.
+ * Note that we allocate arrays padded out to the next iMCU boundary,
+ * so that transform routines need not worry about missing edge blocks.
+ */
+ coef_arrays = (jvirt_barray_ptr *)
+ (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
+ SIZEOF(jvirt_barray_ptr) * info->num_components);
+ for (ci = 0; ci < info->num_components; ci++) {
+ compptr = srcinfo->comp_info + ci;
+ coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
+ ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
+ (JDIMENSION) jround_up((long) compptr->width_in_blocks,
+ (long) compptr->h_samp_factor),
+ (JDIMENSION) jround_up((long) compptr->height_in_blocks,
+ (long) compptr->v_samp_factor),
+ (JDIMENSION) compptr->v_samp_factor);
+ }
+ } else if (choice == JXFORM_TRANSPOSE ||
+ choice == JXFORM_TRANSVERSE ||
+ choice == JXFORM_ROT_90 ||
+ choice == JXFORM_ROT_270) {
+ /* Need workspace arrays having transposed dimensions.
+ * Note that we allocate arrays padded out to the next iMCU boundary,
+ * so that transform routines need not worry about missing edge blocks.
+ */
+ coef_arrays = (jvirt_barray_ptr *)
+ (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
+ SIZEOF(jvirt_barray_ptr) * info->num_components);
+ for (ci = 0; ci < info->num_components; ci++) {
+ compptr = srcinfo->comp_info + ci;
+ coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
+ ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
+ (JDIMENSION) jround_up((long) compptr->height_in_blocks,
+ (long) compptr->v_samp_factor),
+ (JDIMENSION) jround_up((long) compptr->width_in_blocks,
+ (long) compptr->h_samp_factor),
+ (JDIMENSION) compptr->h_samp_factor);
+ }
+ }
+#else
switch (info->transform) {
case JXFORM_NONE:
case JXFORM_FLIP_H:
@@ -630,6 +676,7 @@ jtransform_request_workspace (j_decompress_ptr srcinfo,
}
break;
}
+#endif
info->workspace_coef_arrays = coef_arrays;
}
@@ -691,7 +738,7 @@ trim_right_edge (j_compress_ptr dstinfo)
int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
}
- MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
+ MCU_cols = INT_DIV(dstinfo->image_width, (max_h_samp_factor * DCTSIZE));
if (MCU_cols > 0) /* can't trim to 0 pixels */
dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
}
@@ -711,7 +758,7 @@ trim_bottom_edge (j_compress_ptr dstinfo)
int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
}
- MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
+ MCU_rows = INT_DIV(dstinfo->image_height, (max_v_samp_factor * DCTSIZE));
if (MCU_rows > 0) /* can't trim to 0 pixels */
dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
}
@@ -758,6 +805,39 @@ jtransform_adjust_parameters (j_decompress_ptr srcinfo,
}
/* Correct the destination's image dimensions etc if necessary */
+#ifdef NO_SWITCH
+ int choice = info->transform;
+ if (choice == JXFORM_NONE) {
+ } else if (choice == JXFORM_FLIP_H) {
+ if (info->trim)
+ trim_right_edge(dstinfo);
+ } else if (choice == JXFORM_FLIP_V) {
+ if (info->trim)
+ trim_bottom_edge(dstinfo);
+ } else if (choice == JXFORM_TRANSPOSE) {
+ transpose_critical_parameters(dstinfo);
+ /* transpose does NOT have to trim anything */
+ } else if (choice == JXFORM_TRANSVERSE) {
+ transpose_critical_parameters(dstinfo);
+ if (info->trim) {
+ trim_right_edge(dstinfo);
+ trim_bottom_edge(dstinfo);
+ }
+ } else if (choice == JXFORM_ROT_90) {
+ transpose_critical_parameters(dstinfo);
+ if (info->trim)
+ trim_right_edge(dstinfo);
+ } else if (choice == JXFORM_ROT_180) {
+ if (info->trim) {
+ trim_right_edge(dstinfo);
+ trim_bottom_edge(dstinfo);
+ }
+ } else if (choice == JXFORM_ROT_270) {
+ transpose_critical_parameters(dstinfo);
+ if (info->trim)
+ trim_bottom_edge(dstinfo);
+ }
+#else
switch (info->transform) {
case JXFORM_NONE:
/* Nothing to do */
@@ -798,7 +878,7 @@ jtransform_adjust_parameters (j_decompress_ptr srcinfo,
trim_bottom_edge(dstinfo);
break;
}
-
+#endif
/* Return the appropriate output data set */
if (info->workspace_coef_arrays != NULL)
return info->workspace_coef_arrays;
@@ -823,6 +903,25 @@ jtransform_execute_transformation (j_decompress_ptr srcinfo,
{
jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
+#ifdef NO_SWITCH
+ int choice = info->transform;
+ if (choice == JXFORM_NONE) {
+ } else if (choice == JXFORM_FLIP_H) {
+ do_flip_h(srcinfo, dstinfo, src_coef_arrays);
+ } else if (choice == JXFORM_FLIP_V) {
+ do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
+ } else if (choice == JXFORM_TRANSPOSE) {
+ do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
+ } else if (choice == JXFORM_TRANSVERSE) {
+ do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
+ } else if (choice == JXFORM_ROT_90) {
+ do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
+ } else if (choice == JXFORM_ROT_180) {
+ do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
+ } else if (choice == JXFORM_ROT_270) {
+ do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
+ }
+#else
switch (info->transform) {
case JXFORM_NONE:
break;
@@ -848,6 +947,7 @@ jtransform_execute_transformation (j_decompress_ptr srcinfo,
do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
break;
}
+#endif
}
#endif /* TRANSFORMS_SUPPORTED */
diff --git a/test/monniaux/jpeg-6b/wrbmp.c b/test/monniaux/jpeg-6b/wrbmp.c
index 44978834..0d13482c 100644
--- a/test/monniaux/jpeg-6b/wrbmp.c
+++ b/test/monniaux/jpeg-6b/wrbmp.c
@@ -379,7 +379,7 @@ finish_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
fflush(outfile);
if (ferror(outfile))
ERREXIT(cinfo, JERR_FILE_WRITE);
- KILL_TAIL_CALL
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/wrgif.c b/test/monniaux/jpeg-6b/wrgif.c
index 73e28633..6d3eaf39 100644
--- a/test/monniaux/jpeg-6b/wrgif.c
+++ b/test/monniaux/jpeg-6b/wrgif.c
@@ -271,7 +271,7 @@ emit_header (gif_dest_ptr dinfo, int num_colors, JSAMPARRAY colormap)
}
} else {
/* Create a gray-scale map of num_colors values, range 0..255 */
- put_3bytes(dinfo, DIVISION((i * 255 + (num_colors-1)/2), (num_colors-1)));
+ put_3bytes(dinfo, INT_DIV((i * 255 + (num_colors-1)/2), (num_colors-1)));
}
} else {
/* fill out the map to a power of 2 */
@@ -291,7 +291,6 @@ emit_header (gif_dest_ptr dinfo, int num_colors, JSAMPARRAY colormap)
/* Initialize for "compression" of image data */
compress_init(dinfo, InitCodeSize+1);
- KILL_TAIL_CALL
}
@@ -350,7 +349,7 @@ finish_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
fflush(dest->pub.output_file);
if (ferror(dest->pub.output_file))
ERREXIT(cinfo, JERR_FILE_WRITE);
- KILL_TAIL_CALL
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/wrjpgcom.c b/test/monniaux/jpeg-6b/wrjpgcom.c
index 8c04b055..7d10ee66 100644
--- a/test/monniaux/jpeg-6b/wrjpgcom.c
+++ b/test/monniaux/jpeg-6b/wrjpgcom.c
@@ -1,583 +1,583 @@
-/*
- * wrjpgcom.c
- *
- * Copyright (C) 1994-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains a very simple stand-alone application that inserts
- * user-supplied text as a COM (comment) marker in a JFIF file.
- * This may be useful as an example of the minimum logic needed to parse
- * JPEG markers.
- */
-
-#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
-#include "jinclude.h" /* get auto-config symbols, <stdio.h> */
-
-#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc() */
-extern void * malloc ();
-#endif
-#include <ctype.h> /* to declare isupper(), tolower() */
-#ifdef USE_SETMODE
-#include <fcntl.h> /* to declare setmode()'s parameter macros */
-/* If you have setmode() but not <io.h>, just delete this line: */
-#include <io.h> /* to declare setmode() */
-#endif
-
-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
-#ifdef __MWERKS__
-#include <SIOUX.h> /* Metrowerks needs this */
-#include <console.h> /* ... and this */
-#endif
-#ifdef THINK_C
-#include <console.h> /* Think declares it here */
-#endif
-#endif
-
-#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
-#define READ_BINARY "r"
-#define WRITE_BINARY "w"
-#else
-#ifdef VMS /* VMS is very nonstandard */
-#define READ_BINARY "rb", "ctx=stm"
-#define WRITE_BINARY "wb", "ctx=stm"
-#else /* standard ANSI-compliant case */
-#define READ_BINARY "rb"
-#define WRITE_BINARY "wb"
-#endif
-#endif
-
-#ifndef EXIT_FAILURE /* define exit() codes if not provided */
-#define EXIT_FAILURE 1
-#endif
-#ifndef EXIT_SUCCESS
-#ifdef VMS
-#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
-#else
-#define EXIT_SUCCESS 0
-#endif
-#endif
-
-/* Reduce this value if your malloc() can't allocate blocks up to 64K.
- * On DOS, compiling in large model is usually a better solution.
- */
-
-#ifndef MAX_COM_LENGTH
-#define MAX_COM_LENGTH 65000L /* must be <= 65533 in any case */
-#endif
-
-
-/*
- * These macros are used to read the input file and write the output file.
- * To reuse this code in another application, you might need to change these.
- */
-
-static FILE * infile; /* input JPEG file */
-
-/* Return next input byte, or EOF if no more */
-#define NEXTBYTE() getc(infile)
-
-static FILE * outfile; /* output JPEG file */
-
-/* Emit an output byte */
-#define PUTBYTE(x) putc((x), outfile)
-
-
-/* Error exit handler */
-#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE))
-
-
-/* Read one byte, testing for EOF */
-static int
-read_1_byte (void)
-{
- int c;
-
- c = NEXTBYTE();
- if (c == EOF)
- ERREXIT("Premature EOF in JPEG file");
- return c;
-}
-
-/* Read 2 bytes, convert to unsigned int */
-/* All 2-byte quantities in JPEG markers are MSB first */
-static unsigned int
-read_2_bytes (void)
-{
- int c1, c2;
-
- c1 = NEXTBYTE();
- if (c1 == EOF)
- ERREXIT("Premature EOF in JPEG file");
- c2 = NEXTBYTE();
- if (c2 == EOF)
- ERREXIT("Premature EOF in JPEG file");
- return (((unsigned int) c1) << 8) + ((unsigned int) c2);
-}
-
-
-/* Routines to write data to output file */
-
-static void
-write_1_byte (int c)
-{
- PUTBYTE(c);
-}
-
-static void
-write_2_bytes (unsigned int val)
-{
- PUTBYTE((val >> 8) & 0xFF);
- PUTBYTE(val & 0xFF);
-}
-
-static void
-write_marker (int marker)
-{
- PUTBYTE(0xFF);
- PUTBYTE(marker);
-}
-
-static void
-copy_rest_of_file (void)
-{
- int c;
-
- while ((c = NEXTBYTE()) != EOF)
- PUTBYTE(c);
-}
-
-
-/*
- * JPEG markers consist of one or more 0xFF bytes, followed by a marker
- * code byte (which is not an FF). Here are the marker codes of interest
- * in this program. (See jdmarker.c for a more complete list.)
- */
-
-#define M_SOF0 0xC0 /* Start Of Frame N */
-#define M_SOF1 0xC1 /* N indicates which compression process */
-#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
-#define M_SOF3 0xC3
-#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
-#define M_SOF6 0xC6
-#define M_SOF7 0xC7
-#define M_SOF9 0xC9
-#define M_SOF10 0xCA
-#define M_SOF11 0xCB
-#define M_SOF13 0xCD
-#define M_SOF14 0xCE
-#define M_SOF15 0xCF
-#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
-#define M_EOI 0xD9 /* End Of Image (end of datastream) */
-#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
-#define M_COM 0xFE /* COMment */
-
-
-/*
- * Find the next JPEG marker and return its marker code.
- * We expect at least one FF byte, possibly more if the compressor used FFs
- * to pad the file. (Padding FFs will NOT be replicated in the output file.)
- * There could also be non-FF garbage between markers. The treatment of such
- * garbage is unspecified; we choose to skip over it but emit a warning msg.
- * NB: this routine must not be used after seeing SOS marker, since it will
- * not deal correctly with FF/00 sequences in the compressed image data...
- */
-
-static int
-next_marker (void)
-{
- int c;
- int discarded_bytes = 0;
-
- /* Find 0xFF byte; count and skip any non-FFs. */
- c = read_1_byte();
- while (c != 0xFF) {
- discarded_bytes++;
- c = read_1_byte();
- }
- /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs
- * are legal as pad bytes, so don't count them in discarded_bytes.
- */
- do {
- c = read_1_byte();
- } while (c == 0xFF);
-
- if (discarded_bytes != 0) {
- fprintf(stderr, "Warning: garbage data found in JPEG file\n");
- }
-
- return c;
-}
-
-
-/*
- * Read the initial marker, which should be SOI.
- * For a JFIF file, the first two bytes of the file should be literally
- * 0xFF M_SOI. To be more general, we could use next_marker, but if the
- * input file weren't actually JPEG at all, next_marker might read the whole
- * file and then return a misleading error message...
- */
-
-static int
-first_marker (void)
-{
- int c1, c2;
-
- c1 = NEXTBYTE();
- c2 = NEXTBYTE();
- if (c1 != 0xFF || c2 != M_SOI)
- ERREXIT("Not a JPEG file");
- return c2;
-}
-
-
-/*
- * Most types of marker are followed by a variable-length parameter segment.
- * This routine skips over the parameters for any marker we don't otherwise
- * want to process.
- * Note that we MUST skip the parameter segment explicitly in order not to
- * be fooled by 0xFF bytes that might appear within the parameter segment;
- * such bytes do NOT introduce new markers.
- */
-
-static void
-copy_variable (void)
-/* Copy an unknown or uninteresting variable-length marker */
-{
- unsigned int length;
-
- /* Get the marker parameter length count */
- length = read_2_bytes();
- write_2_bytes(length);
- /* Length includes itself, so must be at least 2 */
- if (length < 2)
- ERREXIT("Erroneous JPEG marker length");
- length -= 2;
- /* Skip over the remaining bytes */
- while (length > 0) {
- write_1_byte(read_1_byte());
- length--;
- }
-}
-
-static void
-skip_variable (void)
-/* Skip over an unknown or uninteresting variable-length marker */
-{
- unsigned int length;
-
- /* Get the marker parameter length count */
- length = read_2_bytes();
- /* Length includes itself, so must be at least 2 */
- if (length < 2)
- ERREXIT("Erroneous JPEG marker length");
- length -= 2;
- /* Skip over the remaining bytes */
- while (length > 0) {
- (void) read_1_byte();
- length--;
- }
-}
-
-
-/*
- * Parse the marker stream until SOFn or EOI is seen;
- * copy data to output, but discard COM markers unless keep_COM is true.
- */
-
-static int
-scan_JPEG_header (int keep_COM)
-{
- int marker;
-
- /* Expect SOI at start of file */
- if (first_marker() != M_SOI)
- ERREXIT("Expected SOI marker first");
- write_marker(M_SOI);
-
- /* Scan miscellaneous markers until we reach SOFn. */
- for (;;) {
- marker = next_marker();
- switch (marker) {
- /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,
- * treated as SOFn. C4 in particular is actually DHT.
- */
- case M_SOF0: /* Baseline */
- case M_SOF1: /* Extended sequential, Huffman */
- case M_SOF2: /* Progressive, Huffman */
- case M_SOF3: /* Lossless, Huffman */
- case M_SOF5: /* Differential sequential, Huffman */
- case M_SOF6: /* Differential progressive, Huffman */
- case M_SOF7: /* Differential lossless, Huffman */
- case M_SOF9: /* Extended sequential, arithmetic */
- case M_SOF10: /* Progressive, arithmetic */
- case M_SOF11: /* Lossless, arithmetic */
- case M_SOF13: /* Differential sequential, arithmetic */
- case M_SOF14: /* Differential progressive, arithmetic */
- case M_SOF15: /* Differential lossless, arithmetic */
- return marker;
-
- case M_SOS: /* should not see compressed data before SOF */
- ERREXIT("SOS without prior SOFn");
- break;
-
- case M_EOI: /* in case it's a tables-only JPEG stream */
- return marker;
-
- case M_COM: /* Existing COM: conditionally discard */
- if (keep_COM) {
- write_marker(marker);
- copy_variable();
- } else {
- skip_variable();
- }
- break;
-
- default: /* Anything else just gets copied */
- write_marker(marker);
- copy_variable(); /* we assume it has a parameter count... */
- break;
- }
- } /* end loop */
-}
-
-
-/* Command line parsing code */
-
-static const char * progname; /* program name for error messages */
-
-
-static void
-usage (void)
-/* complain about bad command line */
-{
- fprintf(stderr, "wrjpgcom inserts a textual comment in a JPEG file.\n");
- fprintf(stderr, "You can add to or replace any existing comment(s).\n");
-
- fprintf(stderr, "Usage: %s [switches] ", progname);
-#ifdef TWO_FILE_COMMANDLINE
- fprintf(stderr, "inputfile outputfile\n");
-#else
- fprintf(stderr, "[inputfile]\n");
-#endif
-
- fprintf(stderr, "Switches (names may be abbreviated):\n");
- fprintf(stderr, " -replace Delete any existing comments\n");
- fprintf(stderr, " -comment \"text\" Insert comment with given text\n");
- fprintf(stderr, " -cfile name Read comment from named file\n");
- fprintf(stderr, "Notice that you must put quotes around the comment text\n");
- fprintf(stderr, "when you use -comment.\n");
- fprintf(stderr, "If you do not give either -comment or -cfile on the command line,\n");
- fprintf(stderr, "then the comment text is read from standard input.\n");
- fprintf(stderr, "It can be multiple lines, up to %u characters total.\n",
- (unsigned int) MAX_COM_LENGTH);
-#ifndef TWO_FILE_COMMANDLINE
- fprintf(stderr, "You must specify an input JPEG file name when supplying\n");
- fprintf(stderr, "comment text from standard input.\n");
-#endif
-
- exit(EXIT_FAILURE);
-}
-
-
-static int
-keymatch (char * arg, const char * keyword, int minchars)
-/* Case-insensitive matching of (possibly abbreviated) keyword switches. */
-/* keyword is the constant keyword (must be lower case already), */
-/* minchars is length of minimum legal abbreviation. */
-{
- register int ca, ck;
- register int nmatched = 0;
-
- while ((ca = *arg++) != '\0') {
- if ((ck = *keyword++) == '\0')
- return 0; /* arg longer than keyword, no good */
- if (isupper(ca)) /* force arg to lcase (assume ck is already) */
- ca = tolower(ca);
- if (ca != ck)
- return 0; /* no good */
- nmatched++; /* count matched characters */
- }
- /* reached end of argument; fail if it's too short for unique abbrev */
- if (nmatched < minchars)
- return 0;
- return 1; /* A-OK */
-}
-
-
-/*
- * The main program.
- */
-
-int
-main (int argc, char **argv)
-{
- int argn;
- char * arg;
- int keep_COM = 1;
- char * comment_arg = NULL;
- FILE * comment_file = NULL;
- unsigned int comment_length = 0;
- int marker;
-
- /* On Mac, fetch a command line. */
-#ifdef USE_CCOMMAND
- argc = ccommand(&argv);
-#endif
-
- progname = argv[0];
- if (progname == NULL || progname[0] == 0)
- progname = "wrjpgcom"; /* in case C library doesn't provide it */
-
- /* Parse switches, if any */
- for (argn = 1; argn < argc; argn++) {
- arg = argv[argn];
- if (arg[0] != '-')
- break; /* not switch, must be file name */
- arg++; /* advance over '-' */
- if (keymatch(arg, "replace", 1)) {
- keep_COM = 0;
- } else if (keymatch(arg, "cfile", 2)) {
- if (++argn >= argc) usage();
- if ((comment_file = fopen(argv[argn], "r")) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
- exit(EXIT_FAILURE);
- }
- } else if (keymatch(arg, "comment", 1)) {
- if (++argn >= argc) usage();
- comment_arg = argv[argn];
- /* If the comment text starts with '"', then we are probably running
- * under MS-DOG and must parse out the quoted string ourselves. Sigh.
- */
- if (comment_arg[0] == '"') {
- comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH);
- if (comment_arg == NULL)
- ERREXIT("Insufficient memory");
- strcpy(comment_arg, argv[argn]+1);
- for (;;) {
- comment_length = (unsigned int) strlen(comment_arg);
- if (comment_length > 0 && comment_arg[comment_length-1] == '"') {
- comment_arg[comment_length-1] = '\0'; /* zap terminating quote */
- break;
- }
- if (++argn >= argc)
- ERREXIT("Missing ending quote mark");
- strcat(comment_arg, " ");
- strcat(comment_arg, argv[argn]);
- }
- }
- comment_length = (unsigned int) strlen(comment_arg);
- } else
- usage();
- }
-
- /* Cannot use both -comment and -cfile. */
- if (comment_arg != NULL && comment_file != NULL)
- usage();
- /* If there is neither -comment nor -cfile, we will read the comment text
- * from stdin; in this case there MUST be an input JPEG file name.
- */
- if (comment_arg == NULL && comment_file == NULL && argn >= argc)
- usage();
-
- /* Open the input file. */
- if (argn < argc) {
- if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
- exit(EXIT_FAILURE);
- }
- } else {
- /* default input file is stdin */
-#ifdef USE_SETMODE /* need to hack file mode? */
- setmode(fileno(stdin), O_BINARY);
-#endif
-#ifdef USE_FDOPEN /* need to re-open in binary mode? */
- if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open stdin\n", progname);
- exit(EXIT_FAILURE);
- }
-#else
- infile = stdin;
-#endif
- }
-
- /* Open the output file. */
-#ifdef TWO_FILE_COMMANDLINE
- /* Must have explicit output file name */
- if (argn != argc-2) {
- fprintf(stderr, "%s: must name one input and one output file\n",
- progname);
- usage();
- }
- if ((outfile = fopen(argv[argn+1], WRITE_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", progname, argv[argn+1]);
- exit(EXIT_FAILURE);
- }
-#else
- /* Unix style: expect zero or one file name */
- if (argn < argc-1) {
- fprintf(stderr, "%s: only one input file\n", progname);
- usage();
- }
- /* default output file is stdout */
-#ifdef USE_SETMODE /* need to hack file mode? */
- setmode(fileno(stdout), O_BINARY);
-#endif
-#ifdef USE_FDOPEN /* need to re-open in binary mode? */
- if ((outfile = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {
- fprintf(stderr, "%s: can't open stdout\n", progname);
- exit(EXIT_FAILURE);
- }
-#else
- outfile = stdout;
-#endif
-#endif /* TWO_FILE_COMMANDLINE */
-
- /* Collect comment text from comment_file or stdin, if necessary */
- if (comment_arg == NULL) {
- FILE * src_file;
- int c;
-
- comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH);
- if (comment_arg == NULL)
- ERREXIT("Insufficient memory");
- comment_length = 0;
- src_file = (comment_file != NULL ? comment_file : stdin);
- while ((c = getc(src_file)) != EOF) {
- if (comment_length >= (unsigned int) MAX_COM_LENGTH) {
- fprintf(stderr, "Comment text may not exceed %u bytes\n",
- (unsigned int) MAX_COM_LENGTH);
- exit(EXIT_FAILURE);
- }
- comment_arg[comment_length++] = (char) c;
- }
- if (comment_file != NULL)
- fclose(comment_file);
- }
-
- /* Copy JPEG headers until SOFn marker;
- * we will insert the new comment marker just before SOFn.
- * This (a) causes the new comment to appear after, rather than before,
- * existing comments; and (b) ensures that comments come after any JFIF
- * or JFXX markers, as required by the JFIF specification.
- */
- marker = scan_JPEG_header(keep_COM);
- /* Insert the new COM marker, but only if nonempty text has been supplied */
- if (comment_length > 0) {
- write_marker(M_COM);
- write_2_bytes(comment_length + 2);
- while (comment_length > 0) {
- write_1_byte(*comment_arg++);
- comment_length--;
- }
- }
- /* Duplicate the remainder of the source file.
- * Note that any COM markers occuring after SOF will not be touched.
- */
- write_marker(marker);
- copy_rest_of_file();
-
- /* All done. */
- exit(EXIT_SUCCESS);
- return 0; /* suppress no-return-value warnings */
-}
+/*
+ * wrjpgcom.c
+ *
+ * Copyright (C) 1994-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a very simple stand-alone application that inserts
+ * user-supplied text as a COM (comment) marker in a JFIF file.
+ * This may be useful as an example of the minimum logic needed to parse
+ * JPEG markers.
+ */
+
+#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
+#include "jinclude.h" /* get auto-config symbols, <stdio.h> */
+
+#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc() */
+extern void * malloc ();
+#endif
+#include <ctype.h> /* to declare isupper(), tolower() */
+#ifdef USE_SETMODE
+#include <fcntl.h> /* to declare setmode()'s parameter macros */
+/* If you have setmode() but not <io.h>, just delete this line: */
+#include <io.h> /* to declare setmode() */
+#endif
+
+#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
+#ifdef __MWERKS__
+#include <SIOUX.h> /* Metrowerks needs this */
+#include <console.h> /* ... and this */
+#endif
+#ifdef THINK_C
+#include <console.h> /* Think declares it here */
+#endif
+#endif
+
+#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
+#define READ_BINARY "r"
+#define WRITE_BINARY "w"
+#else
+#ifdef VMS /* VMS is very nonstandard */
+#define READ_BINARY "rb", "ctx=stm"
+#define WRITE_BINARY "wb", "ctx=stm"
+#else /* standard ANSI-compliant case */
+#define READ_BINARY "rb"
+#define WRITE_BINARY "wb"
+#endif
+#endif
+
+#ifndef EXIT_FAILURE /* define exit() codes if not provided */
+#define EXIT_FAILURE 1
+#endif
+#ifndef EXIT_SUCCESS
+#ifdef VMS
+#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
+#else
+#define EXIT_SUCCESS 0
+#endif
+#endif
+
+/* Reduce this value if your malloc() can't allocate blocks up to 64K.
+ * On DOS, compiling in large model is usually a better solution.
+ */
+
+#ifndef MAX_COM_LENGTH
+#define MAX_COM_LENGTH 65000L /* must be <= 65533 in any case */
+#endif
+
+
+/*
+ * These macros are used to read the input file and write the output file.
+ * To reuse this code in another application, you might need to change these.
+ */
+
+static FILE * infile; /* input JPEG file */
+
+/* Return next input byte, or EOF if no more */
+#define NEXTBYTE() getc(infile)
+
+static FILE * outfile; /* output JPEG file */
+
+/* Emit an output byte */
+#define PUTBYTE(x) putc((x), outfile)
+
+
+/* Error exit handler */
+#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE))
+
+
+/* Read one byte, testing for EOF */
+static int
+read_1_byte (void)
+{
+ int c;
+
+ c = NEXTBYTE();
+ if (c == EOF)
+ ERREXIT("Premature EOF in JPEG file");
+ return c;
+}
+
+/* Read 2 bytes, convert to unsigned int */
+/* All 2-byte quantities in JPEG markers are MSB first */
+static unsigned int
+read_2_bytes (void)
+{
+ int c1, c2;
+
+ c1 = NEXTBYTE();
+ if (c1 == EOF)
+ ERREXIT("Premature EOF in JPEG file");
+ c2 = NEXTBYTE();
+ if (c2 == EOF)
+ ERREXIT("Premature EOF in JPEG file");
+ return (((unsigned int) c1) << 8) + ((unsigned int) c2);
+}
+
+
+/* Routines to write data to output file */
+
+static void
+write_1_byte (int c)
+{
+ PUTBYTE(c);
+}
+
+static void
+write_2_bytes (unsigned int val)
+{
+ PUTBYTE((val >> 8) & 0xFF);
+ PUTBYTE(val & 0xFF);
+}
+
+static void
+write_marker (int marker)
+{
+ PUTBYTE(0xFF);
+ PUTBYTE(marker);
+}
+
+static void
+copy_rest_of_file (void)
+{
+ int c;
+
+ while ((c = NEXTBYTE()) != EOF)
+ PUTBYTE(c);
+}
+
+
+/*
+ * JPEG markers consist of one or more 0xFF bytes, followed by a marker
+ * code byte (which is not an FF). Here are the marker codes of interest
+ * in this program. (See jdmarker.c for a more complete list.)
+ */
+
+#define M_SOF0 0xC0 /* Start Of Frame N */
+#define M_SOF1 0xC1 /* N indicates which compression process */
+#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
+#define M_SOF3 0xC3
+#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
+#define M_SOF6 0xC6
+#define M_SOF7 0xC7
+#define M_SOF9 0xC9
+#define M_SOF10 0xCA
+#define M_SOF11 0xCB
+#define M_SOF13 0xCD
+#define M_SOF14 0xCE
+#define M_SOF15 0xCF
+#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
+#define M_EOI 0xD9 /* End Of Image (end of datastream) */
+#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
+#define M_COM 0xFE /* COMment */
+
+
+/*
+ * Find the next JPEG marker and return its marker code.
+ * We expect at least one FF byte, possibly more if the compressor used FFs
+ * to pad the file. (Padding FFs will NOT be replicated in the output file.)
+ * There could also be non-FF garbage between markers. The treatment of such
+ * garbage is unspecified; we choose to skip over it but emit a warning msg.
+ * NB: this routine must not be used after seeing SOS marker, since it will
+ * not deal correctly with FF/00 sequences in the compressed image data...
+ */
+
+static int
+next_marker (void)
+{
+ int c;
+ int discarded_bytes = 0;
+
+ /* Find 0xFF byte; count and skip any non-FFs. */
+ c = read_1_byte();
+ while (c != 0xFF) {
+ discarded_bytes++;
+ c = read_1_byte();
+ }
+ /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs
+ * are legal as pad bytes, so don't count them in discarded_bytes.
+ */
+ do {
+ c = read_1_byte();
+ } while (c == 0xFF);
+
+ if (discarded_bytes != 0) {
+ fprintf(stderr, "Warning: garbage data found in JPEG file\n");
+ }
+
+ return c;
+}
+
+
+/*
+ * Read the initial marker, which should be SOI.
+ * For a JFIF file, the first two bytes of the file should be literally
+ * 0xFF M_SOI. To be more general, we could use next_marker, but if the
+ * input file weren't actually JPEG at all, next_marker might read the whole
+ * file and then return a misleading error message...
+ */
+
+static int
+first_marker (void)
+{
+ int c1, c2;
+
+ c1 = NEXTBYTE();
+ c2 = NEXTBYTE();
+ if (c1 != 0xFF || c2 != M_SOI)
+ ERREXIT("Not a JPEG file");
+ return c2;
+}
+
+
+/*
+ * Most types of marker are followed by a variable-length parameter segment.
+ * This routine skips over the parameters for any marker we don't otherwise
+ * want to process.
+ * Note that we MUST skip the parameter segment explicitly in order not to
+ * be fooled by 0xFF bytes that might appear within the parameter segment;
+ * such bytes do NOT introduce new markers.
+ */
+
+static void
+copy_variable (void)
+/* Copy an unknown or uninteresting variable-length marker */
+{
+ unsigned int length;
+
+ /* Get the marker parameter length count */
+ length = read_2_bytes();
+ write_2_bytes(length);
+ /* Length includes itself, so must be at least 2 */
+ if (length < 2)
+ ERREXIT("Erroneous JPEG marker length");
+ length -= 2;
+ /* Skip over the remaining bytes */
+ while (length > 0) {
+ write_1_byte(read_1_byte());
+ length--;
+ }
+}
+
+static void
+skip_variable (void)
+/* Skip over an unknown or uninteresting variable-length marker */
+{
+ unsigned int length;
+
+ /* Get the marker parameter length count */
+ length = read_2_bytes();
+ /* Length includes itself, so must be at least 2 */
+ if (length < 2)
+ ERREXIT("Erroneous JPEG marker length");
+ length -= 2;
+ /* Skip over the remaining bytes */
+ while (length > 0) {
+ (void) read_1_byte();
+ length--;
+ }
+}
+
+
+/*
+ * Parse the marker stream until SOFn or EOI is seen;
+ * copy data to output, but discard COM markers unless keep_COM is true.
+ */
+
+static int
+scan_JPEG_header (int keep_COM)
+{
+ int marker;
+
+ /* Expect SOI at start of file */
+ if (first_marker() != M_SOI)
+ ERREXIT("Expected SOI marker first");
+ write_marker(M_SOI);
+
+ /* Scan miscellaneous markers until we reach SOFn. */
+ for (;;) {
+ marker = next_marker();
+ switch (marker) {
+ /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,
+ * treated as SOFn. C4 in particular is actually DHT.
+ */
+ case M_SOF0: /* Baseline */
+ case M_SOF1: /* Extended sequential, Huffman */
+ case M_SOF2: /* Progressive, Huffman */
+ case M_SOF3: /* Lossless, Huffman */
+ case M_SOF5: /* Differential sequential, Huffman */
+ case M_SOF6: /* Differential progressive, Huffman */
+ case M_SOF7: /* Differential lossless, Huffman */
+ case M_SOF9: /* Extended sequential, arithmetic */
+ case M_SOF10: /* Progressive, arithmetic */
+ case M_SOF11: /* Lossless, arithmetic */
+ case M_SOF13: /* Differential sequential, arithmetic */
+ case M_SOF14: /* Differential progressive, arithmetic */
+ case M_SOF15: /* Differential lossless, arithmetic */
+ return marker;
+
+ case M_SOS: /* should not see compressed data before SOF */
+ ERREXIT("SOS without prior SOFn");
+ break;
+
+ case M_EOI: /* in case it's a tables-only JPEG stream */
+ return marker;
+
+ case M_COM: /* Existing COM: conditionally discard */
+ if (keep_COM) {
+ write_marker(marker);
+ copy_variable();
+ } else {
+ skip_variable();
+ }
+ break;
+
+ default: /* Anything else just gets copied */
+ write_marker(marker);
+ copy_variable(); /* we assume it has a parameter count... */
+ break;
+ }
+ } /* end loop */
+}
+
+
+/* Command line parsing code */
+
+static const char * progname; /* program name for error messages */
+
+
+static void
+usage (void)
+/* complain about bad command line */
+{
+ fprintf(stderr, "wrjpgcom inserts a textual comment in a JPEG file.\n");
+ fprintf(stderr, "You can add to or replace any existing comment(s).\n");
+
+ fprintf(stderr, "Usage: %s [switches] ", progname);
+#ifdef TWO_FILE_COMMANDLINE
+ fprintf(stderr, "inputfile outputfile\n");
+#else
+ fprintf(stderr, "[inputfile]\n");
+#endif
+
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
+ fprintf(stderr, " -replace Delete any existing comments\n");
+ fprintf(stderr, " -comment \"text\" Insert comment with given text\n");
+ fprintf(stderr, " -cfile name Read comment from named file\n");
+ fprintf(stderr, "Notice that you must put quotes around the comment text\n");
+ fprintf(stderr, "when you use -comment.\n");
+ fprintf(stderr, "If you do not give either -comment or -cfile on the command line,\n");
+ fprintf(stderr, "then the comment text is read from standard input.\n");
+ fprintf(stderr, "It can be multiple lines, up to %u characters total.\n",
+ (unsigned int) MAX_COM_LENGTH);
+#ifndef TWO_FILE_COMMANDLINE
+ fprintf(stderr, "You must specify an input JPEG file name when supplying\n");
+ fprintf(stderr, "comment text from standard input.\n");
+#endif
+
+ exit(EXIT_FAILURE);
+}
+
+
+static int
+keymatch (char * arg, const char * keyword, int minchars)
+/* Case-insensitive matching of (possibly abbreviated) keyword switches. */
+/* keyword is the constant keyword (must be lower case already), */
+/* minchars is length of minimum legal abbreviation. */
+{
+ register int ca, ck;
+ register int nmatched = 0;
+
+ while ((ca = *arg++) != '\0') {
+ if ((ck = *keyword++) == '\0')
+ return 0; /* arg longer than keyword, no good */
+ if (isupper(ca)) /* force arg to lcase (assume ck is already) */
+ ca = tolower(ca);
+ if (ca != ck)
+ return 0; /* no good */
+ nmatched++; /* count matched characters */
+ }
+ /* reached end of argument; fail if it's too short for unique abbrev */
+ if (nmatched < minchars)
+ return 0;
+ return 1; /* A-OK */
+}
+
+
+/*
+ * The main program.
+ */
+
+int
+main (int argc, char **argv)
+{
+ int argn;
+ char * arg;
+ int keep_COM = 1;
+ char * comment_arg = NULL;
+ FILE * comment_file = NULL;
+ unsigned int comment_length = 0;
+ int marker;
+
+ /* On Mac, fetch a command line. */
+#ifdef USE_CCOMMAND
+ argc = ccommand(&argv);
+#endif
+
+ progname = argv[0];
+ if (progname == NULL || progname[0] == 0)
+ progname = "wrjpgcom"; /* in case C library doesn't provide it */
+
+ /* Parse switches, if any */
+ for (argn = 1; argn < argc; argn++) {
+ arg = argv[argn];
+ if (arg[0] != '-')
+ break; /* not switch, must be file name */
+ arg++; /* advance over '-' */
+ if (keymatch(arg, "replace", 1)) {
+ keep_COM = 0;
+ } else if (keymatch(arg, "cfile", 2)) {
+ if (++argn >= argc) usage();
+ if ((comment_file = fopen(argv[argn], "r")) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
+ exit(EXIT_FAILURE);
+ }
+ } else if (keymatch(arg, "comment", 1)) {
+ if (++argn >= argc) usage();
+ comment_arg = argv[argn];
+ /* If the comment text starts with '"', then we are probably running
+ * under MS-DOG and must parse out the quoted string ourselves. Sigh.
+ */
+ if (comment_arg[0] == '"') {
+ comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH);
+ if (comment_arg == NULL)
+ ERREXIT("Insufficient memory");
+ strcpy(comment_arg, argv[argn]+1);
+ for (;;) {
+ comment_length = (unsigned int) strlen(comment_arg);
+ if (comment_length > 0 && comment_arg[comment_length-1] == '"') {
+ comment_arg[comment_length-1] = '\0'; /* zap terminating quote */
+ break;
+ }
+ if (++argn >= argc)
+ ERREXIT("Missing ending quote mark");
+ strcat(comment_arg, " ");
+ strcat(comment_arg, argv[argn]);
+ }
+ }
+ comment_length = (unsigned int) strlen(comment_arg);
+ } else
+ usage();
+ }
+
+ /* Cannot use both -comment and -cfile. */
+ if (comment_arg != NULL && comment_file != NULL)
+ usage();
+ /* If there is neither -comment nor -cfile, we will read the comment text
+ * from stdin; in this case there MUST be an input JPEG file name.
+ */
+ if (comment_arg == NULL && comment_file == NULL && argn >= argc)
+ usage();
+
+ /* Open the input file. */
+ if (argn < argc) {
+ if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default input file is stdin */
+#ifdef USE_SETMODE /* need to hack file mode? */
+ setmode(fileno(stdin), O_BINARY);
+#endif
+#ifdef USE_FDOPEN /* need to re-open in binary mode? */
+ if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open stdin\n", progname);
+ exit(EXIT_FAILURE);
+ }
+#else
+ infile = stdin;
+#endif
+ }
+
+ /* Open the output file. */
+#ifdef TWO_FILE_COMMANDLINE
+ /* Must have explicit output file name */
+ if (argn != argc-2) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ if ((outfile = fopen(argv[argn+1], WRITE_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[argn+1]);
+ exit(EXIT_FAILURE);
+ }
+#else
+ /* Unix style: expect zero or one file name */
+ if (argn < argc-1) {
+ fprintf(stderr, "%s: only one input file\n", progname);
+ usage();
+ }
+ /* default output file is stdout */
+#ifdef USE_SETMODE /* need to hack file mode? */
+ setmode(fileno(stdout), O_BINARY);
+#endif
+#ifdef USE_FDOPEN /* need to re-open in binary mode? */
+ if ((outfile = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open stdout\n", progname);
+ exit(EXIT_FAILURE);
+ }
+#else
+ outfile = stdout;
+#endif
+#endif /* TWO_FILE_COMMANDLINE */
+
+ /* Collect comment text from comment_file or stdin, if necessary */
+ if (comment_arg == NULL) {
+ FILE * src_file;
+ int c;
+
+ comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH);
+ if (comment_arg == NULL)
+ ERREXIT("Insufficient memory");
+ comment_length = 0;
+ src_file = (comment_file != NULL ? comment_file : stdin);
+ while ((c = getc(src_file)) != EOF) {
+ if (comment_length >= (unsigned int) MAX_COM_LENGTH) {
+ fprintf(stderr, "Comment text may not exceed %u bytes\n",
+ (unsigned int) MAX_COM_LENGTH);
+ exit(EXIT_FAILURE);
+ }
+ comment_arg[comment_length++] = (char) c;
+ }
+ if (comment_file != NULL)
+ fclose(comment_file);
+ }
+
+ /* Copy JPEG headers until SOFn marker;
+ * we will insert the new comment marker just before SOFn.
+ * This (a) causes the new comment to appear after, rather than before,
+ * existing comments; and (b) ensures that comments come after any JFIF
+ * or JFXX markers, as required by the JFIF specification.
+ */
+ marker = scan_JPEG_header(keep_COM);
+ /* Insert the new COM marker, but only if nonempty text has been supplied */
+ if (comment_length > 0) {
+ write_marker(M_COM);
+ write_2_bytes(comment_length + 2);
+ while (comment_length > 0) {
+ write_1_byte(*comment_arg++);
+ comment_length--;
+ }
+ }
+ /* Duplicate the remainder of the source file.
+ * Note that any COM markers occuring after SOF will not be touched.
+ */
+ write_marker(marker);
+ copy_rest_of_file();
+
+ /* All done. */
+ exit(EXIT_SUCCESS);
+ return 0; /* suppress no-return-value warnings */
+}
diff --git a/test/monniaux/jpeg-6b/wrppm.c b/test/monniaux/jpeg-6b/wrppm.c
index 7c058d00..47dd19b4 100644
--- a/test/monniaux/jpeg-6b/wrppm.c
+++ b/test/monniaux/jpeg-6b/wrppm.c
@@ -194,7 +194,7 @@ start_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
default:
ERREXIT(cinfo, JERR_PPM_COLORSPACE);
}
- KILL_TAIL_CALL
+ KILL_TAIL_CALL();
}
@@ -209,7 +209,7 @@ finish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
fflush(dinfo->output_file);
if (ferror(dinfo->output_file))
ERREXIT(cinfo, JERR_FILE_WRITE);
- KILL_TAIL_CALL
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/jpeg-6b/wrtarga.c b/test/monniaux/jpeg-6b/wrtarga.c
index fb3264d8..7bfe2a44 100644
--- a/test/monniaux/jpeg-6b/wrtarga.c
+++ b/test/monniaux/jpeg-6b/wrtarga.c
@@ -200,7 +200,7 @@ start_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
} else {
ERREXIT(cinfo, JERR_TGA_COLORSPACE);
}
- KILL_TAIL_CALL
+ KILL_TAIL_CALL();
}
@@ -215,7 +215,7 @@ finish_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
fflush(dinfo->output_file);
if (ferror(dinfo->output_file))
ERREXIT(cinfo, JERR_FILE_WRITE);
- KILL_TAIL_CALL
+ KILL_TAIL_CALL();
}
diff --git a/test/monniaux/micro-bunzip/micro-bunzip.c b/test/monniaux/micro-bunzip/micro-bunzip.c
index 532fc7b5..7197ede5 100644
--- a/test/monniaux/micro-bunzip/micro-bunzip.c
+++ b/test/monniaux/micro-bunzip/micro-bunzip.c
@@ -520,8 +520,6 @@ extern char *uncompressStream(int src_fd, int dst_fd)
int main(int argc, char *argv[])
{
char *c=uncompressStream(0,1);
- extern FILE *fdopen(int fd, const char *mode);
- FILE *err = fdopen(2, "w");
- fprintf(err, "%s\ncycles=%lu\n", c ? c : "Completed OK", get_total_clock());
+ fprintf(stderr, "%s\ncycles=%lu\n", c ? c : "Completed OK", get_total_clock());
return 0;
}