summaryrefslogtreecommitdiff
path: root/packages/base
diff options
context:
space:
mode:
authorpeter <peter@3ad0048d-3df7-0310-abae-a5850022a9f2>2008-01-24 23:09:54 +0000
committerpeter <peter@3ad0048d-3df7-0310-abae-a5850022a9f2>2008-01-24 23:09:54 +0000
commit2b225f5bcbb5ca7fefda77935980d0b936a3f69e (patch)
tree65120c0063d6830b374f454a874d23ee52b1e84f /packages/base
parentf7167458d460e9d3cc07960d3180f0d6db9e5ee6 (diff)
downloadfpc-2b225f5bcbb5ca7fefda77935980d0b936a3f69e.tar.gz
* move pasjpeg
* add fpmake.pp for pasjpeg git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@9907 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/base')
-rw-r--r--packages/base/Makefile206
-rw-r--r--packages/base/Makefile.fpc2
-rw-r--r--packages/base/pasjpeg/Makefile2267
-rw-r--r--packages/base/pasjpeg/Makefile.fpc27
-rw-r--r--packages/base/pasjpeg/PasJpeg.raw0
-rw-r--r--packages/base/pasjpeg/buildpasjpeg.pp60
-rw-r--r--packages/base/pasjpeg/cderror.pas208
-rw-r--r--packages/base/pasjpeg/cdjpeg.pas279
-rw-r--r--packages/base/pasjpeg/cjpeg.pas748
-rw-r--r--packages/base/pasjpeg/cjpeg.resbin876 -> 0 bytes
-rw-r--r--packages/base/pasjpeg/demo.pas36
-rw-r--r--packages/base/pasjpeg/demo.resbin876 -> 0 bytes
-rw-r--r--packages/base/pasjpeg/djpeg.pas709
-rw-r--r--packages/base/pasjpeg/djpeg.resbin876 -> 0 bytes
-rw-r--r--packages/base/pasjpeg/example.pas478
-rw-r--r--packages/base/pasjpeg/fcache.pas192
-rw-r--r--packages/base/pasjpeg/fpmake.inc62
-rw-r--r--packages/base/pasjpeg/fpmake.pp17
-rw-r--r--packages/base/pasjpeg/jcapimin.pas401
-rw-r--r--packages/base/pasjpeg/jcapistd.pas222
-rw-r--r--packages/base/pasjpeg/jccoefct.pas522
-rw-r--r--packages/base/pasjpeg/jccolor.pas529
-rw-r--r--packages/base/pasjpeg/jcdctmgr.pas514
-rw-r--r--packages/base/pasjpeg/jchuff.pas1116
-rw-r--r--packages/base/pasjpeg/jcinit.pas95
-rw-r--r--packages/base/pasjpeg/jcmainct.pas343
-rw-r--r--packages/base/pasjpeg/jcmarker.pas724
-rw-r--r--packages/base/pasjpeg/jcmaster.pas702
-rw-r--r--packages/base/pasjpeg/jcomapi.pas130
-rw-r--r--packages/base/pasjpeg/jconfig.inc116
-rw-r--r--packages/base/pasjpeg/jconsts.pas11
-rw-r--r--packages/base/pasjpeg/jcparam.pas700
-rw-r--r--packages/base/pasjpeg/jcphuff.pas960
-rw-r--r--packages/base/pasjpeg/jcprepct.pas406
-rw-r--r--packages/base/pasjpeg/jcsample.pas631
-rw-r--r--packages/base/pasjpeg/jctrans.pas459
-rw-r--r--packages/base/pasjpeg/jdapimin.pas505
-rw-r--r--packages/base/pasjpeg/jdapistd.pas376
-rw-r--r--packages/base/pasjpeg/jdatadst.pas170
-rw-r--r--packages/base/pasjpeg/jdatasrc.pas224
-rw-r--r--packages/base/pasjpeg/jdcoefct.pas895
-rw-r--r--packages/base/pasjpeg/jdcolor.pas501
-rw-r--r--packages/base/pasjpeg/jdct.pas109
-rw-r--r--packages/base/pasjpeg/jddctmgr.pas329
-rw-r--r--packages/base/pasjpeg/jdeferr.pas497
-rw-r--r--packages/base/pasjpeg/jdhuff.pas1204
-rw-r--r--packages/base/pasjpeg/jdinput.pas416
-rw-r--r--packages/base/pasjpeg/jdmainct.pas610
-rw-r--r--packages/base/pasjpeg/jdmarker.pas2644
-rw-r--r--packages/base/pasjpeg/jdmaster.pas678
-rw-r--r--packages/base/pasjpeg/jdmerge.pas514
-rw-r--r--packages/base/pasjpeg/jdphuff.pas1058
-rw-r--r--packages/base/pasjpeg/jdpostct.pas342
-rw-r--r--packages/base/pasjpeg/jdsample.pas592
-rw-r--r--packages/base/pasjpeg/jdtrans.pas192
-rw-r--r--packages/base/pasjpeg/jerror.pas461
-rw-r--r--packages/base/pasjpeg/jfdctflt.pas176
-rw-r--r--packages/base/pasjpeg/jfdctfst.pas237
-rw-r--r--packages/base/pasjpeg/jfdctint.pas297
-rw-r--r--packages/base/pasjpeg/jidct2d.pas1048
-rw-r--r--packages/base/pasjpeg/jidctasm.pas793
-rw-r--r--packages/base/pasjpeg/jidctflt.pas286
-rw-r--r--packages/base/pasjpeg/jidctfst.pas410
-rw-r--r--packages/base/pasjpeg/jidctint.pas440
-rw-r--r--packages/base/pasjpeg/jidctred.pas525
-rw-r--r--packages/base/pasjpeg/jinclude.pas126
-rw-r--r--packages/base/pasjpeg/jmemdos.pas780
-rw-r--r--packages/base/pasjpeg/jmemdosa.pas365
-rw-r--r--packages/base/pasjpeg/jmemmgr.pas1282
-rw-r--r--packages/base/pasjpeg/jmemnobs.pas264
-rw-r--r--packages/base/pasjpeg/jmemsys.pas177
-rw-r--r--packages/base/pasjpeg/jmorecfg.pas247
-rw-r--r--packages/base/pasjpeg/jpeglib.pas1300
-rw-r--r--packages/base/pasjpeg/jpegtran.drc160
-rw-r--r--packages/base/pasjpeg/jpegtran.pas642
-rw-r--r--packages/base/pasjpeg/jpegtran.resbin876 -> 0 bytes
-rw-r--r--packages/base/pasjpeg/jquant1.pas1010
-rw-r--r--packages/base/pasjpeg/jquant2.pas1551
-rw-r--r--packages/base/pasjpeg/jutils.pas232
-rw-r--r--packages/base/pasjpeg/pasjpeg.pas1023
-rw-r--r--packages/base/pasjpeg/qtable1.ijg21
-rw-r--r--packages/base/pasjpeg/rdbmp.pas550
-rw-r--r--packages/base/pasjpeg/rdcolmap.pas279
-rw-r--r--packages/base/pasjpeg/rdjpgcom.pas381
-rw-r--r--packages/base/pasjpeg/rdppm.pas580
-rw-r--r--packages/base/pasjpeg/rdswitch.pas523
-rw-r--r--packages/base/pasjpeg/rdtarga.pas559
-rw-r--r--packages/base/pasjpeg/readme.txt381
-rw-r--r--packages/base/pasjpeg/script0.ijg5
-rw-r--r--packages/base/pasjpeg/script1.ijg12
-rw-r--r--packages/base/pasjpeg/script2.ijg32
-rw-r--r--packages/base/pasjpeg/test.pas148
-rw-r--r--packages/base/pasjpeg/test1.dfmbin2009 -> 0 bytes
-rw-r--r--packages/base/pasjpeg/test1.pas96
-rw-r--r--packages/base/pasjpeg/testproj.dpr13
-rw-r--r--packages/base/pasjpeg/testproj.resbin876 -> 0 bytes
-rw-r--r--packages/base/pasjpeg/transupp.pas1427
-rw-r--r--packages/base/pasjpeg/wrbmp.pas608
-rw-r--r--packages/base/pasjpeg/wrjpgcom.pas596
-rw-r--r--packages/base/pasjpeg/wrppm.pas335
-rw-r--r--packages/base/pasjpeg/wrtarga.pas285
101 files changed, 55 insertions, 46336 deletions
diff --git a/packages/base/Makefile b/packages/base/Makefile
index ce41434492..cbef581f4e 100644
--- a/packages/base/Makefile
+++ b/packages/base/Makefile
@@ -1,5 +1,5 @@
#
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2008/01/05]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2008/01/22]
#
default: all
MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded
@@ -241,163 +241,163 @@ UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
endif
PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages $(FPCDIR)/packages/base $(FPCDIR)/packages/extra)
ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd libc
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd libc
endif
ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint
+override TARGET_DIRS+=regexpr netdb gdbint
endif
ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase odbc sqlite postgres oracle imagemagick httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase odbc sqlite postgres oracle imagemagick httpd
endif
ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
endif
ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres odbc sqlite pthreads imagemagick
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres odbc sqlite pthreads imagemagick
endif
ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc imagemagick httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc imagemagick httpd
endif
ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_DIRS+=pasjpeg regexpr netdb mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
+override TARGET_DIRS+=regexpr netdb mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
endif
ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc imagemagick httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc imagemagick httpd
endif
ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_DIRS+=pasjpeg regexpr netdb mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
+override TARGET_DIRS+=regexpr netdb mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
endif
ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_DIRS+=pasjpeg regexpr netdb ibase sqlite postgres
+override TARGET_DIRS+=regexpr netdb ibase sqlite postgres
endif
ifeq ($(FULL_TARGET),i386-embedded)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),i386-symbian)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
endif
ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
endif
ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc imagemagick httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc imagemagick httpd
endif
ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc imagemagick httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc imagemagick httpd
endif
ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),m68k-embedded)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
endif
ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc imagemagick httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc imagemagick httpd
endif
ifeq ($(FULL_TARGET),powerpc-amiga)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_DIRS+=pasjpeg regexpr netdb mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
+override TARGET_DIRS+=regexpr netdb mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
endif
ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),powerpc-embedded)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
endif
ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc imagemagick httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc imagemagick httpd
endif
ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_DIRS+=pasjpeg regexpr netdb mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
+override TARGET_DIRS+=regexpr netdb mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
endif
ifeq ($(FULL_TARGET),sparc-embedded)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
endif
ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
endif
ifeq ($(FULL_TARGET),x86_64-darwin)
-override TARGET_DIRS+=pasjpeg regexpr netdb mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
+override TARGET_DIRS+=regexpr netdb mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
endif
ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_DIRS+=pasjpeg regexpr netdb mysql ibase odbc sqlite postgres oracle
+override TARGET_DIRS+=regexpr netdb mysql ibase odbc sqlite postgres oracle
endif
ifeq ($(FULL_TARGET),x86_64-embedded)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
endif
ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_DIRS+=pasjpeg regexpr netdb ibase sqlite postgres
+override TARGET_DIRS+=regexpr netdb ibase sqlite postgres
endif
ifeq ($(FULL_TARGET),arm-gba)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),arm-nds)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),arm-embedded)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),arm-symbian)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_DIRS+=pasjpeg regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
+override TARGET_DIRS+=regexpr netdb gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
endif
ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_DIRS+=pasjpeg regexpr netdb mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
+override TARGET_DIRS+=regexpr netdb mysql ibase postgres oracle odbc sqlite pthreads imagemagick httpd
endif
ifeq ($(FULL_TARGET),powerpc64-embedded)
-override TARGET_DIRS+=pasjpeg regexpr netdb
+override TARGET_DIRS+=regexpr netdb
endif
override INSTALL_FPCPACKAGE=y
override INSTALL_FPCSUBDIR=packages/base
@@ -1479,7 +1479,6 @@ fpc_makefile_sub2: $(addsuffix _makefile_dirs,$(TARGET_DIRS) $(TARGET_EXAMPLEDIR
fpc_makefile_dirs: fpc_makefile_sub1 fpc_makefile_sub2
fpc_makefiles: fpc_makefile fpc_makefile_dirs
ifeq ($(FULL_TARGET),i386-linux)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1496,13 +1495,11 @@ TARGET_DIRS_HTTPD=1
TARGET_DIRS_LIBC=1
endif
ifeq ($(FULL_TARGET),i386-go32v2)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
endif
ifeq ($(FULL_TARGET),i386-win32)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1516,12 +1513,10 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),i386-os2)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),i386-freebsd)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1536,7 +1531,6 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),i386-beos)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1549,7 +1543,6 @@ TARGET_DIRS_PTHREADS=1
TARGET_DIRS_IMAGEMAGICK=1
endif
ifeq ($(FULL_TARGET),i386-netbsd)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1562,7 +1555,6 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),i386-solaris)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_MYSQL=1
@@ -1576,17 +1568,14 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),i386-qnx)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),i386-netware)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),i386-openbsd)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1599,12 +1588,10 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),i386-wdosx)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),i386-darwin)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_MYSQL=1
@@ -1618,22 +1605,18 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),i386-emx)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),i386-watcom)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),i386-netwlibc)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),i386-wince)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_IBASE=1
@@ -1641,17 +1624,14 @@ TARGET_DIRS_SQLITE=1
TARGET_DIRS_POSTGRES=1
endif
ifeq ($(FULL_TARGET),i386-embedded)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),i386-symbian)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),m68k-linux)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1667,7 +1647,6 @@ TARGET_DIRS_DBUS=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),m68k-freebsd)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1682,7 +1661,6 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),m68k-netbsd)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1695,17 +1673,14 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),m68k-amiga)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),m68k-atari)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),m68k-openbsd)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1718,17 +1693,14 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),m68k-palmos)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),m68k-embedded)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),powerpc-linux)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1744,7 +1716,6 @@ TARGET_DIRS_DBUS=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),powerpc-netbsd)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1757,17 +1728,14 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),powerpc-amiga)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),powerpc-macos)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),powerpc-darwin)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_MYSQL=1
@@ -1781,17 +1749,14 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),powerpc-morphos)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),powerpc-embedded)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),sparc-linux)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1807,7 +1772,6 @@ TARGET_DIRS_DBUS=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),sparc-netbsd)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1820,7 +1784,6 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),sparc-solaris)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_MYSQL=1
@@ -1834,12 +1797,10 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),sparc-embedded)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),x86_64-linux)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1855,7 +1816,6 @@ TARGET_DIRS_DBUS=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),x86_64-freebsd)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1870,7 +1830,6 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),x86_64-darwin)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_MYSQL=1
@@ -1884,7 +1843,6 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),x86_64-win64)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_MYSQL=1
@@ -1895,12 +1853,10 @@ TARGET_DIRS_POSTGRES=1
TARGET_DIRS_ORACLE=1
endif
ifeq ($(FULL_TARGET),x86_64-embedded)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),arm-linux)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1916,12 +1872,10 @@ TARGET_DIRS_DBUS=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),arm-palmos)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),arm-wince)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_IBASE=1
@@ -1929,27 +1883,22 @@ TARGET_DIRS_SQLITE=1
TARGET_DIRS_POSTGRES=1
endif
ifeq ($(FULL_TARGET),arm-gba)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),arm-nds)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),arm-embedded)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),arm-symbian)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
ifeq ($(FULL_TARGET),powerpc64-linux)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_GDBINT=1
@@ -1965,7 +1914,6 @@ TARGET_DIRS_DBUS=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),powerpc64-darwin)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
TARGET_DIRS_MYSQL=1
@@ -1979,55 +1927,9 @@ TARGET_DIRS_IMAGEMAGICK=1
TARGET_DIRS_HTTPD=1
endif
ifeq ($(FULL_TARGET),powerpc64-embedded)
-TARGET_DIRS_PASJPEG=1
TARGET_DIRS_REGEXPR=1
TARGET_DIRS_NETDB=1
endif
-ifdef TARGET_DIRS_PASJPEG
-pasjpeg_all:
- $(MAKE) -C pasjpeg all
-pasjpeg_debug:
- $(MAKE) -C pasjpeg debug
-pasjpeg_smart:
- $(MAKE) -C pasjpeg smart
-pasjpeg_release:
- $(MAKE) -C pasjpeg release
-pasjpeg_units:
- $(MAKE) -C pasjpeg units
-pasjpeg_examples:
- $(MAKE) -C pasjpeg examples
-pasjpeg_shared:
- $(MAKE) -C pasjpeg shared
-pasjpeg_install:
- $(MAKE) -C pasjpeg install
-pasjpeg_sourceinstall:
- $(MAKE) -C pasjpeg sourceinstall
-pasjpeg_exampleinstall:
- $(MAKE) -C pasjpeg exampleinstall
-pasjpeg_distinstall:
- $(MAKE) -C pasjpeg distinstall
-pasjpeg_zipinstall:
- $(MAKE) -C pasjpeg zipinstall
-pasjpeg_zipsourceinstall:
- $(MAKE) -C pasjpeg zipsourceinstall
-pasjpeg_zipexampleinstall:
- $(MAKE) -C pasjpeg zipexampleinstall
-pasjpeg_zipdistinstall:
- $(MAKE) -C pasjpeg zipdistinstall
-pasjpeg_clean:
- $(MAKE) -C pasjpeg clean
-pasjpeg_distclean:
- $(MAKE) -C pasjpeg distclean
-pasjpeg_cleanall:
- $(MAKE) -C pasjpeg cleanall
-pasjpeg_info:
- $(MAKE) -C pasjpeg info
-pasjpeg_makefiles:
- $(MAKE) -C pasjpeg makefiles
-pasjpeg:
- $(MAKE) -C pasjpeg all
-.PHONY: pasjpeg_all pasjpeg_debug pasjpeg_smart pasjpeg_release pasjpeg_units pasjpeg_examples pasjpeg_shared pasjpeg_install pasjpeg_sourceinstall pasjpeg_exampleinstall pasjpeg_distinstall pasjpeg_zipinstall pasjpeg_zipsourceinstall pasjpeg_zipexampleinstall pasjpeg_zipdistinstall pasjpeg_clean pasjpeg_distclean pasjpeg_cleanall pasjpeg_info pasjpeg_makefiles pasjpeg
-endif
ifdef TARGET_DIRS_REGEXPR
regexpr_all:
$(MAKE) -C regexpr all
diff --git a/packages/base/Makefile.fpc b/packages/base/Makefile.fpc
index b786c92764..ecf4331b35 100644
--- a/packages/base/Makefile.fpc
+++ b/packages/base/Makefile.fpc
@@ -3,7 +3,7 @@
#
[target]
-dirs=pasjpeg regexpr netdb
+dirs=regexpr netdb
dirs_i386_linux=libc
dirs_linux=gdbint mysql ibase postgres oracle odbc pthreads sqlite imagemagick dbus httpd
dirs_win32=gdbint mysql ibase odbc sqlite postgres oracle imagemagick httpd
diff --git a/packages/base/pasjpeg/Makefile b/packages/base/pasjpeg/Makefile
deleted file mode 100644
index da3cf14c10..0000000000
--- a/packages/base/pasjpeg/Makefile
+++ /dev/null
@@ -1,2267 +0,0 @@
-#
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2007/11/08]
-#
-default: all
-MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded
-BSDs = freebsd netbsd openbsd darwin
-UNIXs = linux $(BSDs) solaris qnx
-LIMIT83fs = go32v2 os2 emx watcom
-OSNeedsComspecToRunBatch = go32v2 watcom
-FORCE:
-.PHONY: FORCE
-override PATH:=$(patsubst %/,%,$(subst \,/,$(PATH)))
-ifneq ($(findstring darwin,$(OSTYPE)),)
-inUnix=1 #darwin
-SEARCHPATH:=$(filter-out .,$(subst :, ,$(PATH)))
-else
-ifeq ($(findstring ;,$(PATH)),)
-inUnix=1
-SEARCHPATH:=$(filter-out .,$(subst :, ,$(PATH)))
-else
-SEARCHPATH:=$(subst ;, ,$(PATH))
-endif
-endif
-SEARCHPATH+=$(patsubst %/,%,$(subst \,/,$(dir $(MAKE))))
-PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(SEARCHPATH))))
-ifeq ($(PWD),)
-PWD:=$(strip $(wildcard $(addsuffix /pwd,$(SEARCHPATH))))
-ifeq ($(PWD),)
-$(error You need the GNU utils package to use this Makefile)
-else
-PWD:=$(firstword $(PWD))
-SRCEXEEXT=
-endif
-else
-PWD:=$(firstword $(PWD))
-SRCEXEEXT=.exe
-endif
-ifndef inUnix
-ifeq ($(OS),Windows_NT)
-inWinNT=1
-else
-ifdef OS2_SHELL
-inOS2=1
-endif
-endif
-else
-ifneq ($(findstring cygdrive,$(PATH)),)
-inCygWin=1
-endif
-endif
-ifdef inUnix
-SRCBATCHEXT=.sh
-else
-ifdef inOS2
-SRCBATCHEXT=.cmd
-else
-SRCBATCHEXT=.bat
-endif
-endif
-ifdef COMSPEC
-ifneq ($(findstring $(OS_SOURCE),$(OSNeedsComspecToRunBatch)),)
-RUNBATCH=$(COMSPEC) /C
-endif
-endif
-ifdef inUnix
-PATHSEP=/
-else
-PATHSEP:=$(subst /,\,/)
-ifdef inCygWin
-PATHSEP=/
-endif
-endif
-ifdef PWD
-BASEDIR:=$(subst \,/,$(shell $(PWD)))
-ifdef inCygWin
-ifneq ($(findstring /cygdrive/,$(BASEDIR)),)
-BASENODIR:=$(patsubst /cygdrive%,%,$(BASEDIR))
-BASEDRIVE:=$(firstword $(subst /, ,$(BASENODIR)))
-BASEDIR:=$(subst /cygdrive/$(BASEDRIVE)/,$(BASEDRIVE):/,$(BASEDIR))
-endif
-endif
-else
-BASEDIR=.
-endif
-ifdef inOS2
-ifndef ECHO
-ECHO:=$(strip $(wildcard $(addsuffix /gecho$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(ECHO),)
-ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(ECHO),)
-ECHO=echo
-else
-ECHO:=$(firstword $(ECHO))
-endif
-else
-ECHO:=$(firstword $(ECHO))
-endif
-endif
-export ECHO
-endif
-override DEFAULT_FPCDIR=../../..
-ifndef FPC
-ifdef PP
-FPC=$(PP)
-endif
-endif
-ifndef FPC
-FPCPROG:=$(strip $(wildcard $(addsuffix /fpc$(SRCEXEEXT),$(SEARCHPATH))))
-ifneq ($(FPCPROG),)
-FPCPROG:=$(firstword $(FPCPROG))
-ifneq ($(CPU_TARGET),)
-FPC:=$(shell $(FPCPROG) -P$(CPU_TARGET) -PB)
-else
-FPC:=$(shell $(FPCPROG) -PB)
-endif
-ifneq ($(findstring Error,$(FPC)),)
-override FPC=$(firstword $(strip $(wildcard $(addsuffix /ppc386$(SRCEXEEXT),$(SEARCHPATH)))))
-endif
-else
-override FPC=$(firstword $(strip $(wildcard $(addsuffix /ppc386$(SRCEXEEXT),$(SEARCHPATH)))))
-endif
-endif
-override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
-override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)
-FOUNDFPC:=$(strip $(wildcard $(FPC)))
-ifeq ($(FOUNDFPC),)
-FOUNDFPC=$(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))
-ifeq ($(FOUNDFPC),)
-$(error Compiler $(FPC) not found)
-endif
-endif
-ifndef FPC_COMPILERINFO
-FPC_COMPILERINFO:=$(shell $(FPC) -iVSPTPSOTO)
-endif
-ifndef FPC_VERSION
-FPC_VERSION:=$(word 1,$(FPC_COMPILERINFO))
-endif
-export FPC FPC_VERSION FPC_COMPILERINFO
-unexport CHECKDEPEND ALLDEPENDENCIES
-ifndef CPU_TARGET
-ifdef CPU_TARGET_DEFAULT
-CPU_TARGET=$(CPU_TARGET_DEFAULT)
-endif
-endif
-ifndef OS_TARGET
-ifdef OS_TARGET_DEFAULT
-OS_TARGET=$(OS_TARGET_DEFAULT)
-endif
-endif
-ifneq ($(words $(FPC_COMPILERINFO)),5)
-FPC_COMPILERINFO+=$(shell $(FPC) -iSP)
-FPC_COMPILERINFO+=$(shell $(FPC) -iTP)
-FPC_COMPILERINFO+=$(shell $(FPC) -iSO)
-FPC_COMPILERINFO+=$(shell $(FPC) -iTO)
-endif
-ifndef CPU_SOURCE
-CPU_SOURCE:=$(word 2,$(FPC_COMPILERINFO))
-endif
-ifndef CPU_TARGET
-CPU_TARGET:=$(word 3,$(FPC_COMPILERINFO))
-endif
-ifndef OS_SOURCE
-OS_SOURCE:=$(word 4,$(FPC_COMPILERINFO))
-endif
-ifndef OS_TARGET
-OS_TARGET:=$(word 5,$(FPC_COMPILERINFO))
-endif
-FULL_TARGET=$(CPU_TARGET)-$(OS_TARGET)
-FULL_SOURCE=$(CPU_SOURCE)-$(OS_SOURCE)
-ifneq ($(findstring $(OS_SOURCE),$(LIMIT83fs)),)
-TARGETSUFFIX=$(OS_TARGET)
-SOURCESUFFIX=$(OS_SOURCE)
-else
-TARGETSUFFIX=$(FULL_TARGET)
-SOURCESUFFIX=$(FULL_SOURCE)
-endif
-ifneq ($(FULL_TARGET),$(FULL_SOURCE))
-CROSSCOMPILE=1
-endif
-ifeq ($(findstring makefile,$(MAKECMDGOALS)),)
-ifeq ($(findstring $(FULL_TARGET),$(MAKEFILETARGETS)),)
-$(error The Makefile doesn't support target $(FULL_TARGET), please run fpcmake first)
-endif
-endif
-ifneq ($(findstring $(OS_TARGET),$(BSDs)),)
-BSDhier=1
-endif
-ifeq ($(OS_TARGET),linux)
-linuxHier=1
-endif
-export OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FULL_TARGET FULL_SOURCE TARGETSUFFIX SOURCESUFFIX CROSSCOMPILE
-ifdef FPCDIR
-override FPCDIR:=$(subst \,/,$(FPCDIR))
-ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
-override FPCDIR=wrong
-endif
-else
-override FPCDIR=wrong
-endif
-ifdef DEFAULT_FPCDIR
-ifeq ($(FPCDIR),wrong)
-override FPCDIR:=$(subst \,/,$(DEFAULT_FPCDIR))
-ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
-override FPCDIR=wrong
-endif
-endif
-endif
-ifeq ($(FPCDIR),wrong)
-ifdef inUnix
-override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)
-ifeq ($(wildcard $(FPCDIR)/units),)
-override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)
-endif
-else
-override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))))
-override FPCDIR:=$(FPCDIR)/..
-ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
-override FPCDIR:=$(FPCDIR)/..
-ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
-override FPCDIR:=$(BASEDIR)
-ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
-override FPCDIR=c:/pp
-endif
-endif
-endif
-endif
-endif
-ifndef CROSSBINDIR
-CROSSBINDIR:=$(wildcard $(FPCDIR)/bin/$(TARGETSUFFIX))
-endif
-ifndef BINUTILSPREFIX
-ifndef CROSSBINDIR
-ifdef CROSSCOMPILE
-BINUTILSPREFIX=$(CPU_TARGET)-$(OS_TARGET)-
-endif
-endif
-endif
-UNITSDIR:=$(wildcard $(FPCDIR)/units/$(TARGETSUFFIX))
-ifeq ($(UNITSDIR),)
-UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
-endif
-PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages $(FPCDIR)/packages/base $(FPCDIR)/packages/extra)
-override PACKAGE_NAME=pasjpeg
-override PACKAGE_VERSION=2.0.0
-ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-embedded)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-symbian)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),m68k-embedded)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),powerpc-amiga)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),powerpc-embedded)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),sparc-embedded)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),x86_64-darwin)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),x86_64-embedded)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),arm-gba)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),arm-nds)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),arm-embedded)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),arm-symbian)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),powerpc64-embedded)
-override TARGET_UNITS+=buildpasjpeg
-endif
-ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-embedded)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-symbian)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),m68k-embedded)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),powerpc-amiga)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),powerpc-embedded)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),sparc-embedded)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),x86_64-darwin)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),x86_64-embedded)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),arm-gba)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),arm-nds)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),arm-embedded)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),arm-symbian)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),powerpc64-embedded)
-override TARGET_IMPLICITUNITS+=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib jquant1 jquant2 jutils
-endif
-ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-embedded)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),i386-symbian)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),m68k-embedded)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),powerpc-amiga)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),powerpc-embedded)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),sparc-embedded)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),x86_64-darwin)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),x86_64-embedded)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),arm-gba)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),arm-nds)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),arm-embedded)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),arm-symbian)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-ifeq ($(FULL_TARGET),powerpc64-embedded)
-override TARGET_EXAMPLES+=cjpeg demo djpeg jpegtran rdjpgcom
-endif
-override INSTALL_FPCPACKAGE=y
-ifdef REQUIRE_UNITSDIR
-override UNITSDIR+=$(REQUIRE_UNITSDIR)
-endif
-ifdef REQUIRE_PACKAGESDIR
-override PACKAGESDIR+=$(REQUIRE_PACKAGESDIR)
-endif
-ifdef ZIPINSTALL
-ifneq ($(findstring $(OS_TARGET),$(UNIXs)),)
-UNIXHier=1
-endif
-else
-ifneq ($(findstring $(OS_SOURCE),$(UNIXs)),)
-UNIXHier=1
-endif
-endif
-ifndef INSTALL_PREFIX
-ifdef PREFIX
-INSTALL_PREFIX=$(PREFIX)
-endif
-endif
-ifndef INSTALL_PREFIX
-ifdef UNIXHier
-INSTALL_PREFIX=/usr/local
-else
-ifdef INSTALL_FPCPACKAGE
-INSTALL_BASEDIR:=/pp
-else
-INSTALL_BASEDIR:=/$(PACKAGE_NAME)
-endif
-endif
-endif
-export INSTALL_PREFIX
-ifdef INSTALL_FPCSUBDIR
-export INSTALL_FPCSUBDIR
-endif
-ifndef DIST_DESTDIR
-DIST_DESTDIR:=$(BASEDIR)
-endif
-export DIST_DESTDIR
-ifndef COMPILER_UNITTARGETDIR
-ifdef PACKAGEDIR_MAIN
-COMPILER_UNITTARGETDIR=$(PACKAGEDIR_MAIN)/units/$(TARGETSUFFIX)
-else
-COMPILER_UNITTARGETDIR=units/$(TARGETSUFFIX)
-endif
-endif
-ifndef COMPILER_TARGETDIR
-COMPILER_TARGETDIR=.
-endif
-ifndef INSTALL_BASEDIR
-ifdef UNIXHier
-ifdef INSTALL_FPCPACKAGE
-INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/fpc/$(FPC_VERSION)
-else
-INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/$(PACKAGE_NAME)
-endif
-else
-INSTALL_BASEDIR:=$(INSTALL_PREFIX)
-endif
-endif
-ifndef INSTALL_BINDIR
-ifdef UNIXHier
-INSTALL_BINDIR:=$(INSTALL_PREFIX)/bin
-else
-INSTALL_BINDIR:=$(INSTALL_BASEDIR)/bin
-ifdef INSTALL_FPCPACKAGE
-ifdef CROSSCOMPILE
-ifdef CROSSINSTALL
-INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(SOURCESUFFIX)
-else
-INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(TARGETSUFFIX)
-endif
-else
-INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(TARGETSUFFIX)
-endif
-endif
-endif
-endif
-ifndef INSTALL_UNITDIR
-INSTALL_UNITDIR:=$(INSTALL_BASEDIR)/units/$(TARGETSUFFIX)
-ifdef INSTALL_FPCPACKAGE
-ifdef PACKAGE_NAME
-INSTALL_UNITDIR:=$(INSTALL_UNITDIR)/$(PACKAGE_NAME)
-endif
-endif
-endif
-ifndef INSTALL_LIBDIR
-ifdef UNIXHier
-INSTALL_LIBDIR:=$(INSTALL_PREFIX)/lib
-else
-INSTALL_LIBDIR:=$(INSTALL_UNITDIR)
-endif
-endif
-ifndef INSTALL_SOURCEDIR
-ifdef UNIXHier
-ifdef BSDhier
-SRCPREFIXDIR=share/src
-else
-ifdef linuxHier
-SRCPREFIXDIR=share/src
-else
-SRCPREFIXDIR=src
-endif
-endif
-ifdef INSTALL_FPCPACKAGE
-ifdef INSTALL_FPCSUBDIR
-INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/$(SRCPREFIXDIR)/fpc-$(FPC_VERSION)/$(INSTALL_FPCSUBDIR)/$(PACKAGE_NAME)
-else
-INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/$(SRCPREFIXDIR)/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
-endif
-else
-INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/$(SRCPREFIXDIR)/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
-endif
-else
-ifdef INSTALL_FPCPACKAGE
-ifdef INSTALL_FPCSUBDIR
-INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source/$(INSTALL_FPCSUBDIR)/$(PACKAGE_NAME)
-else
-INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source/$(PACKAGE_NAME)
-endif
-else
-INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source
-endif
-endif
-endif
-ifndef INSTALL_DOCDIR
-ifdef UNIXHier
-ifdef BSDhier
-DOCPREFIXDIR=share/doc
-else
-ifdef linuxHier
-DOCPREFIXDIR=share/doc
-else
-DOCPREFIXDIR=doc
-endif
-endif
-ifdef INSTALL_FPCPACKAGE
-INSTALL_DOCDIR:=$(INSTALL_PREFIX)/$(DOCPREFIXDIR)/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
-else
-INSTALL_DOCDIR:=$(INSTALL_PREFIX)/$(DOCPREFIXDIR)/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
-endif
-else
-ifdef INSTALL_FPCPACKAGE
-INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc/$(PACKAGE_NAME)
-else
-INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc
-endif
-endif
-endif
-ifndef INSTALL_EXAMPLEDIR
-ifdef UNIXHier
-ifdef INSTALL_FPCPACKAGE
-ifdef BSDhier
-INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/share/examples/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
-else
-ifdef linuxHier
-INSTALL_EXAMPLEDIR:=$(INSTALL_DOCDIR)/examples
-else
-INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/examples/$(PACKAGE_NAME)
-endif
-endif
-else
-ifdef BSDhier
-INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/share/examples/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
-else
-ifdef linuxHier
-INSTALL_EXAMPLEDIR:=$(INSTALL_DOCDIR)/examples/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
-else
-INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
-endif
-endif
-endif
-else
-ifdef INSTALL_FPCPACKAGE
-INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples/$(PACKAGE_NAME)
-else
-INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples
-endif
-endif
-endif
-ifndef INSTALL_DATADIR
-INSTALL_DATADIR=$(INSTALL_BASEDIR)
-endif
-ifndef INSTALL_SHAREDDIR
-INSTALL_SHAREDDIR=$(INSTALL_PREFIX)/lib
-endif
-ifdef CROSSCOMPILE
-ifndef CROSSBINDIR
-CROSSBINDIR:=$(wildcard $(CROSSTARGETDIR)/bin/$(SOURCESUFFIX))
-ifeq ($(CROSSBINDIR),)
-CROSSBINDIR:=$(wildcard $(INSTALL_BASEDIR)/cross/$(TARGETSUFFIX)/bin/$(FULL_SOURCE))
-endif
-endif
-else
-CROSSBINDIR=
-endif
-BATCHEXT=.bat
-LOADEREXT=.as
-EXEEXT=.exe
-PPLEXT=.ppl
-PPUEXT=.ppu
-OEXT=.o
-ASMEXT=.s
-SMARTEXT=.sl
-STATICLIBEXT=.a
-SHAREDLIBEXT=.so
-SHAREDLIBPREFIX=libfp
-STATICLIBPREFIX=libp
-IMPORTLIBPREFIX=libimp
-RSTEXT=.rst
-ifeq ($(findstring 1.0.,$(FPC_VERSION)),)
-ifeq ($(OS_TARGET),go32v1)
-STATICLIBPREFIX=
-SHORTSUFFIX=v1
-endif
-ifeq ($(OS_TARGET),go32v2)
-STATICLIBPREFIX=
-SHORTSUFFIX=dos
-endif
-ifeq ($(OS_TARGET),watcom)
-STATICLIBPREFIX=
-OEXT=.obj
-ASMEXT=.asm
-SHAREDLIBEXT=.dll
-SHORTSUFFIX=wat
-endif
-ifeq ($(OS_TARGET),linux)
-BATCHEXT=.sh
-EXEEXT=
-HASSHAREDLIB=1
-SHORTSUFFIX=lnx
-endif
-ifeq ($(OS_TARGET),freebsd)
-BATCHEXT=.sh
-EXEEXT=
-HASSHAREDLIB=1
-SHORTSUFFIX=fbs
-endif
-ifeq ($(OS_TARGET),netbsd)
-BATCHEXT=.sh
-EXEEXT=
-HASSHAREDLIB=1
-SHORTSUFFIX=nbs
-endif
-ifeq ($(OS_TARGET),openbsd)
-BATCHEXT=.sh
-EXEEXT=
-HASSHAREDLIB=1
-SHORTSUFFIX=obs
-endif
-ifeq ($(OS_TARGET),win32)
-SHAREDLIBEXT=.dll
-SHORTSUFFIX=w32
-endif
-ifeq ($(OS_TARGET),os2)
-BATCHEXT=.cmd
-AOUTEXT=.out
-STATICLIBPREFIX=
-SHAREDLIBEXT=.dll
-SHORTSUFFIX=os2
-ECHO=echo
-endif
-ifeq ($(OS_TARGET),emx)
-BATCHEXT=.cmd
-AOUTEXT=.out
-STATICLIBPREFIX=
-SHAREDLIBEXT=.dll
-SHORTSUFFIX=emx
-ECHO=echo
-endif
-ifeq ($(OS_TARGET),amiga)
-EXEEXT=
-SHAREDLIBEXT=.library
-SHORTSUFFIX=amg
-endif
-ifeq ($(OS_TARGET),morphos)
-EXEEXT=
-SHAREDLIBEXT=.library
-SHORTSUFFIX=mos
-endif
-ifeq ($(OS_TARGET),atari)
-EXEEXT=.ttp
-SHORTSUFFIX=ata
-endif
-ifeq ($(OS_TARGET),beos)
-BATCHEXT=.sh
-EXEEXT=
-SHORTSUFFIX=be
-endif
-ifeq ($(OS_TARGET),solaris)
-BATCHEXT=.sh
-EXEEXT=
-SHORTSUFFIX=sun
-endif
-ifeq ($(OS_TARGET),qnx)
-BATCHEXT=.sh
-EXEEXT=
-SHORTSUFFIX=qnx
-endif
-ifeq ($(OS_TARGET),netware)
-EXEEXT=.nlm
-STATICLIBPREFIX=
-SHORTSUFFIX=nw
-endif
-ifeq ($(OS_TARGET),netwlibc)
-EXEEXT=.nlm
-STATICLIBPREFIX=
-SHORTSUFFIX=nwl
-endif
-ifeq ($(OS_TARGET),macos)
-BATCHEXT=
-EXEEXT=
-DEBUGSYMEXT=.xcoff
-SHORTSUFFIX=mac
-endif
-ifeq ($(OS_TARGET),darwin)
-BATCHEXT=.sh
-EXEEXT=
-HASSHAREDLIB=1
-SHORTSUFFIX=dwn
-endif
-ifeq ($(OS_TARGET),gba)
-EXEEXT=.gba
-SHAREDLIBEXT=.so
-SHORTSUFFIX=gba
-endif
-ifeq ($(OS_TARGET),symbian)
-SHAREDLIBEXT=.dll
-SHORTSUFFIX=symbian
-endif
-else
-ifeq ($(OS_TARGET),go32v1)
-PPUEXT=.pp1
-OEXT=.o1
-ASMEXT=.s1
-SMARTEXT=.sl1
-STATICLIBEXT=.a1
-SHAREDLIBEXT=.so1
-STATICLIBPREFIX=
-SHORTSUFFIX=v1
-endif
-ifeq ($(OS_TARGET),go32v2)
-STATICLIBPREFIX=
-SHORTSUFFIX=dos
-endif
-ifeq ($(OS_TARGET),watcom)
-STATICLIBPREFIX=
-SHORTSUFFIX=wat
-endif
-ifeq ($(OS_TARGET),linux)
-BATCHEXT=.sh
-EXEEXT=
-HASSHAREDLIB=1
-SHORTSUFFIX=lnx
-endif
-ifeq ($(OS_TARGET),freebsd)
-BATCHEXT=.sh
-EXEEXT=
-HASSHAREDLIB=1
-SHORTSUFFIX=fbs
-endif
-ifeq ($(OS_TARGET),netbsd)
-BATCHEXT=.sh
-EXEEXT=
-HASSHAREDLIB=1
-SHORTSUFFIX=nbs
-endif
-ifeq ($(OS_TARGET),openbsd)
-BATCHEXT=.sh
-EXEEXT=
-HASSHAREDLIB=1
-SHORTSUFFIX=obs
-endif
-ifeq ($(OS_TARGET),win32)
-PPUEXT=.ppw
-OEXT=.ow
-ASMEXT=.sw
-SMARTEXT=.slw
-STATICLIBEXT=.aw
-SHAREDLIBEXT=.dll
-SHORTSUFFIX=w32
-endif
-ifeq ($(OS_TARGET),os2)
-BATCHEXT=.cmd
-PPUEXT=.ppo
-ASMEXT=.so2
-OEXT=.oo2
-AOUTEXT=.out
-SMARTEXT=.sl2
-STATICLIBPREFIX=
-STATICLIBEXT=.ao2
-SHAREDLIBEXT=.dll
-SHORTSUFFIX=os2
-ECHO=echo
-endif
-ifeq ($(OS_TARGET),amiga)
-EXEEXT=
-PPUEXT=.ppu
-ASMEXT=.s
-OEXT=.o
-SMARTEXT=.sl
-STATICLIBEXT=.a
-SHAREDLIBEXT=.library
-SHORTSUFFIX=amg
-endif
-ifeq ($(OS_TARGET),atari)
-PPUEXT=.ppu
-ASMEXT=.s
-OEXT=.o
-SMARTEXT=.sl
-STATICLIBEXT=.a
-EXEEXT=.ttp
-SHORTSUFFIX=ata
-endif
-ifeq ($(OS_TARGET),beos)
-BATCHEXT=.sh
-PPUEXT=.ppu
-ASMEXT=.s
-OEXT=.o
-SMARTEXT=.sl
-STATICLIBEXT=.a
-EXEEXT=
-SHORTSUFFIX=be
-endif
-ifeq ($(OS_TARGET),solaris)
-BATCHEXT=.sh
-PPUEXT=.ppu
-ASMEXT=.s
-OEXT=.o
-SMARTEXT=.sl
-STATICLIBEXT=.a
-EXEEXT=
-SHORTSUFFIX=sun
-endif
-ifeq ($(OS_TARGET),qnx)
-BATCHEXT=.sh
-PPUEXT=.ppu
-ASMEXT=.s
-OEXT=.o
-SMARTEXT=.sl
-STATICLIBEXT=.a
-EXEEXT=
-SHORTSUFFIX=qnx
-endif
-ifeq ($(OS_TARGET),netware)
-STATICLIBPREFIX=
-PPUEXT=.ppu
-OEXT=.o
-ASMEXT=.s
-SMARTEXT=.sl
-STATICLIBEXT=.a
-SHAREDLIBEXT=.nlm
-EXEEXT=.nlm
-SHORTSUFFIX=nw
-endif
-ifeq ($(OS_TARGET),netwlibc)
-STATICLIBPREFIX=
-PPUEXT=.ppu
-OEXT=.o
-ASMEXT=.s
-SMARTEXT=.sl
-STATICLIBEXT=.a
-SHAREDLIBEXT=.nlm
-EXEEXT=.nlm
-SHORTSUFFIX=nwl
-endif
-ifeq ($(OS_TARGET),macos)
-BATCHEXT=
-PPUEXT=.ppu
-ASMEXT=.s
-OEXT=.o
-SMARTEXT=.sl
-STATICLIBEXT=.a
-EXEEXT=
-DEBUGSYMEXT=.xcoff
-SHORTSUFFIX=mac
-endif
-endif
-ifneq ($(findstring $(OS_SOURCE),$(LIMIT83fs)),)
-FPCMADE=fpcmade.$(SHORTSUFFIX)
-ZIPSUFFIX=$(SHORTSUFFIX)
-ZIPCROSSPREFIX=
-ZIPSOURCESUFFIX=src
-ZIPEXAMPLESUFFIX=exm
-else
-FPCMADE=fpcmade.$(TARGETSUFFIX)
-ZIPSOURCESUFFIX=.source
-ZIPEXAMPLESUFFIX=.examples
-ifdef CROSSCOMPILE
-ZIPSUFFIX=.$(SOURCESUFFIX)
-ZIPCROSSPREFIX=$(TARGETSUFFIX)-
-else
-ZIPSUFFIX=.$(TARGETSUFFIX)
-ZIPCROSSPREFIX=
-endif
-endif
-ifndef ECHO
-ECHO:=$(strip $(wildcard $(addsuffix /gecho$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(ECHO),)
-ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(ECHO),)
-ECHO= __missing_command_ECHO
-else
-ECHO:=$(firstword $(ECHO))
-endif
-else
-ECHO:=$(firstword $(ECHO))
-endif
-endif
-export ECHO
-ifndef DATE
-DATE:=$(strip $(wildcard $(addsuffix /gdate$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(DATE),)
-DATE:=$(strip $(wildcard $(addsuffix /date$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(DATE),)
-DATE= __missing_command_DATE
-else
-DATE:=$(firstword $(DATE))
-endif
-else
-DATE:=$(firstword $(DATE))
-endif
-endif
-export DATE
-ifndef GINSTALL
-GINSTALL:=$(strip $(wildcard $(addsuffix /ginstall$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(GINSTALL),)
-GINSTALL:=$(strip $(wildcard $(addsuffix /install$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(GINSTALL),)
-GINSTALL= __missing_command_GINSTALL
-else
-GINSTALL:=$(firstword $(GINSTALL))
-endif
-else
-GINSTALL:=$(firstword $(GINSTALL))
-endif
-endif
-export GINSTALL
-ifndef CPPROG
-CPPROG:=$(strip $(wildcard $(addsuffix /cp$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(CPPROG),)
-CPPROG= __missing_command_CPPROG
-else
-CPPROG:=$(firstword $(CPPROG))
-endif
-endif
-export CPPROG
-ifndef RMPROG
-RMPROG:=$(strip $(wildcard $(addsuffix /rm$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(RMPROG),)
-RMPROG= __missing_command_RMPROG
-else
-RMPROG:=$(firstword $(RMPROG))
-endif
-endif
-export RMPROG
-ifndef MVPROG
-MVPROG:=$(strip $(wildcard $(addsuffix /mv$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(MVPROG),)
-MVPROG= __missing_command_MVPROG
-else
-MVPROG:=$(firstword $(MVPROG))
-endif
-endif
-export MVPROG
-ifndef MKDIRPROG
-MKDIRPROG:=$(strip $(wildcard $(addsuffix /gmkdir$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(MKDIRPROG),)
-MKDIRPROG:=$(strip $(wildcard $(addsuffix /mkdir$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(MKDIRPROG),)
-MKDIRPROG= __missing_command_MKDIRPROG
-else
-MKDIRPROG:=$(firstword $(MKDIRPROG))
-endif
-else
-MKDIRPROG:=$(firstword $(MKDIRPROG))
-endif
-endif
-export MKDIRPROG
-ifndef ECHOREDIR
-ifndef inUnix
-ECHOREDIR=echo
-else
-ECHOREDIR=$(ECHO)
-endif
-endif
-ifndef COPY
-COPY:=$(CPPROG) -fp
-endif
-ifndef COPYTREE
-COPYTREE:=$(CPPROG) -Rfp
-endif
-ifndef MKDIRTREE
-MKDIRTREE:=$(MKDIRPROG) -p
-endif
-ifndef MOVE
-MOVE:=$(MVPROG) -f
-endif
-ifndef DEL
-DEL:=$(RMPROG) -f
-endif
-ifndef DELTREE
-DELTREE:=$(RMPROG) -rf
-endif
-ifndef INSTALL
-ifdef inUnix
-INSTALL:=$(GINSTALL) -c -m 644
-else
-INSTALL:=$(COPY)
-endif
-endif
-ifndef INSTALLEXE
-ifdef inUnix
-INSTALLEXE:=$(GINSTALL) -c -m 755
-else
-INSTALLEXE:=$(COPY)
-endif
-endif
-ifndef MKDIR
-MKDIR:=$(GINSTALL) -m 755 -d
-endif
-export ECHOREDIR COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR
-ifndef PPUMOVE
-PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(PPUMOVE),)
-PPUMOVE= __missing_command_PPUMOVE
-else
-PPUMOVE:=$(firstword $(PPUMOVE))
-endif
-endif
-export PPUMOVE
-ifndef FPCMAKE
-FPCMAKE:=$(strip $(wildcard $(addsuffix /fpcmake$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(FPCMAKE),)
-FPCMAKE= __missing_command_FPCMAKE
-else
-FPCMAKE:=$(firstword $(FPCMAKE))
-endif
-endif
-export FPCMAKE
-ifndef ZIPPROG
-ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(ZIPPROG),)
-ZIPPROG= __missing_command_ZIPPROG
-else
-ZIPPROG:=$(firstword $(ZIPPROG))
-endif
-endif
-export ZIPPROG
-ifndef TARPROG
-TARPROG:=$(strip $(wildcard $(addsuffix /gtar$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(TARPROG),)
-TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(TARPROG),)
-TARPROG= __missing_command_TARPROG
-else
-TARPROG:=$(firstword $(TARPROG))
-endif
-else
-TARPROG:=$(firstword $(TARPROG))
-endif
-endif
-export TARPROG
-ASNAME=$(BINUTILSPREFIX)as
-LDNAME=$(BINUTILSPREFIX)ld
-ARNAME=$(BINUTILSPREFIX)ar
-RCNAME=$(BINUTILSPREFIX)rc
-ifneq ($(findstring 1.0.,$(FPC_VERSION)),)
-ifeq ($(OS_TARGET),win32)
-ifeq ($(CROSSBINDIR),)
-ASNAME=asw
-LDNAME=ldw
-ARNAME=arw
-endif
-endif
-endif
-ifndef ASPROG
-ifdef CROSSBINDIR
-ASPROG=$(CROSSBINDIR)/$(ASNAME)$(SRCEXEEXT)
-else
-ASPROG=$(ASNAME)
-endif
-endif
-ifndef LDPROG
-ifdef CROSSBINDIR
-LDPROG=$(CROSSBINDIR)/$(LDNAME)$(SRCEXEEXT)
-else
-LDPROG=$(LDNAME)
-endif
-endif
-ifndef RCPROG
-ifdef CROSSBINDIR
-RCPROG=$(CROSSBINDIR)/$(RCNAME)$(SRCEXEEXT)
-else
-RCPROG=$(RCNAME)
-endif
-endif
-ifndef ARPROG
-ifdef CROSSBINDIR
-ARPROG=$(CROSSBINDIR)/$(ARNAME)$(SRCEXEEXT)
-else
-ARPROG=$(ARNAME)
-endif
-endif
-AS=$(ASPROG)
-LD=$(LDPROG)
-RC=$(RCPROG)
-AR=$(ARPROG)
-PPAS=ppas$(SRCBATCHEXT)
-ifdef inUnix
-LDCONFIG=ldconfig
-else
-LDCONFIG=
-endif
-ifdef DATE
-DATESTR:=$(shell $(DATE) +%Y%m%d)
-else
-DATESTR=
-endif
-ifndef UPXPROG
-ifeq ($(OS_TARGET),go32v2)
-UPXPROG:=1
-endif
-ifeq ($(OS_TARGET),win32)
-UPXPROG:=1
-endif
-ifdef UPXPROG
-UPXPROG:=$(strip $(wildcard $(addsuffix /upx$(SRCEXEEXT),$(SEARCHPATH))))
-ifeq ($(UPXPROG),)
-UPXPROG=
-else
-UPXPROG:=$(firstword $(UPXPROG))
-endif
-else
-UPXPROG=
-endif
-endif
-export UPXPROG
-ZIPOPT=-9
-ZIPEXT=.zip
-ifeq ($(USETAR),bz2)
-TAROPT=vj
-TAREXT=.tar.bz2
-else
-TAROPT=vz
-TAREXT=.tar.gz
-endif
-override REQUIRE_PACKAGES=rtl
-ifeq ($(FULL_TARGET),i386-linux)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-go32v2)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-win32)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-os2)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-freebsd)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-beos)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-netbsd)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-solaris)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-qnx)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-netware)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-openbsd)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-wdosx)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-darwin)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-emx)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-watcom)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-netwlibc)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-wince)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-embedded)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),i386-symbian)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),m68k-linux)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),m68k-freebsd)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),m68k-netbsd)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),m68k-amiga)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),m68k-atari)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),m68k-openbsd)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),m68k-palmos)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),m68k-embedded)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),powerpc-linux)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),powerpc-netbsd)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),powerpc-amiga)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),powerpc-macos)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),powerpc-darwin)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),powerpc-morphos)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),powerpc-embedded)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),sparc-linux)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),sparc-netbsd)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),sparc-solaris)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),sparc-embedded)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),x86_64-linux)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),x86_64-freebsd)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),x86_64-darwin)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),x86_64-win64)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),x86_64-embedded)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),arm-linux)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),arm-palmos)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),arm-wince)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),arm-gba)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),arm-nds)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),arm-embedded)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),arm-symbian)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),powerpc64-linux)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),powerpc64-darwin)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifeq ($(FULL_TARGET),powerpc64-embedded)
-REQUIRE_PACKAGES_RTL=1
-endif
-ifdef REQUIRE_PACKAGES_RTL
-PACKAGEDIR_RTL:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /rtl/Makefile.fpc,$(PACKAGESDIR))))))
-ifneq ($(PACKAGEDIR_RTL),)
-ifneq ($(wildcard $(PACKAGEDIR_RTL)/units/$(TARGETSUFFIX)),)
-UNITDIR_RTL=$(PACKAGEDIR_RTL)/units/$(TARGETSUFFIX)
-else
-UNITDIR_RTL=$(PACKAGEDIR_RTL)
-endif
-ifdef CHECKDEPEND
-$(PACKAGEDIR_RTL)/$(FPCMADE):
- $(MAKE) -C $(PACKAGEDIR_RTL) $(FPCMADE)
-override ALLDEPENDENCIES+=$(PACKAGEDIR_RTL)/$(FPCMADE)
-endif
-else
-PACKAGEDIR_RTL=
-UNITDIR_RTL:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /rtl/Package.fpc,$(UNITSDIR)))))
-ifneq ($(UNITDIR_RTL),)
-UNITDIR_RTL:=$(firstword $(UNITDIR_RTL))
-else
-UNITDIR_RTL=
-endif
-endif
-ifdef UNITDIR_RTL
-override COMPILER_UNITDIR+=$(UNITDIR_RTL)
-endif
-endif
-ifndef NOCPUDEF
-override FPCOPTDEF=$(CPU_TARGET)
-endif
-ifneq ($(OS_TARGET),$(OS_SOURCE))
-override FPCOPT+=-T$(OS_TARGET)
-endif
-ifneq ($(CPU_TARGET),$(CPU_SOURCE))
-override FPCOPT+=-P$(CPU_TARGET)
-endif
-ifeq ($(OS_SOURCE),openbsd)
-override FPCOPT+=-FD$(NEW_BINUTILS_PATH)
-endif
-ifndef CROSSBOOTSTRAP
-ifneq ($(BINUTILSPREFIX),)
-override FPCOPT+=-XP$(BINUTILSPREFIX)
-endif
-ifneq ($(BINUTILSPREFIX),)
-override FPCOPT+=-Xr$(RLINKPATH)
-endif
-endif
-ifdef UNITDIR
-override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
-endif
-ifdef LIBDIR
-override FPCOPT+=$(addprefix -Fl,$(LIBDIR))
-endif
-ifdef OBJDIR
-override FPCOPT+=$(addprefix -Fo,$(OBJDIR))
-endif
-ifdef INCDIR
-override FPCOPT+=$(addprefix -Fi,$(INCDIR))
-endif
-ifdef LINKSMART
-override FPCOPT+=-XX
-endif
-ifdef CREATESMART
-override FPCOPT+=-CX
-endif
-ifdef DEBUG
-override FPCOPT+=-gl
-override FPCOPTDEF+=DEBUG
-endif
-ifdef RELEASE
-ifneq ($(findstring 2.0.,$(FPC_VERSION)),)
-ifeq ($(CPU_TARGET),i386)
-FPCCPUOPT:=-OG2p3
-endif
-ifeq ($(CPU_TARGET),powerpc)
-FPCCPUOPT:=-O1r
-endif
-else
-FPCCPUOPT:=-O2
-endif
-override FPCOPT+=-Ur -Xs $(FPCCPUOPT) -n
-override FPCOPTDEF+=RELEASE
-endif
-ifdef STRIP
-override FPCOPT+=-Xs
-endif
-ifdef OPTIMIZE
-override FPCOPT+=-O2
-endif
-ifdef VERBOSE
-override FPCOPT+=-vwni
-endif
-ifdef COMPILER_OPTIONS
-override FPCOPT+=$(COMPILER_OPTIONS)
-endif
-ifdef COMPILER_UNITDIR
-override FPCOPT+=$(addprefix -Fu,$(COMPILER_UNITDIR))
-endif
-ifdef COMPILER_LIBRARYDIR
-override FPCOPT+=$(addprefix -Fl,$(COMPILER_LIBRARYDIR))
-endif
-ifdef COMPILER_OBJECTDIR
-override FPCOPT+=$(addprefix -Fo,$(COMPILER_OBJECTDIR))
-endif
-ifdef COMPILER_INCLUDEDIR
-override FPCOPT+=$(addprefix -Fi,$(COMPILER_INCLUDEDIR))
-endif
-ifdef CROSSBINDIR
-override FPCOPT+=-FD$(CROSSBINDIR)
-endif
-ifdef COMPILER_TARGETDIR
-override FPCOPT+=-FE$(COMPILER_TARGETDIR)
-ifeq ($(COMPILER_TARGETDIR),.)
-override TARGETDIRPREFIX=
-else
-override TARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
-endif
-endif
-ifdef COMPILER_UNITTARGETDIR
-override FPCOPT+=-FU$(COMPILER_UNITTARGETDIR)
-ifeq ($(COMPILER_UNITTARGETDIR),.)
-override UNITTARGETDIRPREFIX=
-else
-override UNITTARGETDIRPREFIX=$(COMPILER_UNITTARGETDIR)/
-endif
-else
-ifdef COMPILER_TARGETDIR
-override COMPILER_UNITTARGETDIR=$(COMPILER_TARGETDIR)
-override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)
-endif
-endif
-ifdef CREATESHARED
-override FPCOPT+=-Cg
-ifeq ($(CPU_TARGET),i386)
-override FPCOPT+=-Aas
-endif
-endif
-ifeq ($(findstring 2.0.,$(FPC_VERSION)),)
-ifeq ($(OS_TARGET),linux)
-ifeq ($(CPU_TARGET),x86_64)
-override FPCOPT+=-Cg
-endif
-endif
-endif
-ifdef LINKSHARED
-endif
-ifdef OPT
-override FPCOPT+=$(OPT)
-endif
-ifdef FPCOPTDEF
-override FPCOPT+=$(addprefix -d,$(FPCOPTDEF))
-endif
-ifdef CFGFILE
-override FPCOPT+=@$(CFGFILE)
-endif
-ifdef USEENV
-override FPCEXTCMD:=$(FPCOPT)
-override FPCOPT:=!FPCEXTCMD
-export FPCEXTCMD
-endif
-override AFULL_TARGET=$(CPU_TARGET)-$(OS_TARGET)
-override AFULL_SOURCE=$(CPU_SOURCE)-$(OS_SOURCE)
-ifneq ($(AFULL_TARGET),$(AFULL_SOURCE))
-override ACROSSCOMPILE=1
-endif
-ifdef ACROSSCOMPILE
-override FPCOPT+=$(CROSSOPT)
-endif
-override COMPILER:=$(FPC) $(FPCOPT)
-ifeq (,$(findstring -s ,$(COMPILER)))
-EXECPPAS=
-else
-ifeq ($(FULL_SOURCE),$(FULL_TARGET))
-ifdef RUNBATCH
-EXECPPAS:=@$(RUNBATCH) $(PPAS)
-else
-EXECPPAS:=@$(PPAS)
-endif
-endif
-endif
-.PHONY: fpc_units
-ifneq ($(TARGET_UNITS),)
-override ALLTARGET+=fpc_units
-override UNITPPUFILES=$(addsuffix $(PPUEXT),$(TARGET_UNITS))
-override IMPLICITUNITPPUFILES=$(addsuffix $(PPUEXT),$(TARGET_IMPLICITUNITS))
-override INSTALLPPUFILES+=$(UNITPPUFILES) $(IMPLICITUNITPPUFILES)
-override CLEANPPUFILES+=$(UNITPPUFILES) $(IMPLICITUNITPPUFILES)
-endif
-fpc_units: $(COMPILER_UNITTARGETDIR) $(UNITPPUFILES)
-ifdef TARGET_RSTS
-override RSTFILES=$(addsuffix $(RSTEXT),$(TARGET_RSTS))
-override CLEANRSTFILES+=$(RSTFILES)
-endif
-.PHONY: fpc_examples
-ifneq ($(TARGET_EXAMPLES),)
-HASEXAMPLES=1
-override EXAMPLESOURCEFILES:=$(wildcard $(addsuffix .pp,$(TARGET_EXAMPLES)) $(addsuffix .pas,$(TARGET_EXAMPLES)) $(addsuffix .lpr,$(TARGET_EXAMPLES)) $(addsuffix .dpr,$(TARGET_EXAMPLES)))
-override EXAMPLEFILES:=$(addsuffix $(EXEEXT),$(TARGET_EXAMPLES))
-override EXAMPLEOFILES:=$(addsuffix $(OEXT),$(TARGET_EXAMPLES)) $(addprefix $(STATICLIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_EXAMPLES))) $(addprefix $(IMPORTLIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_EXAMPLES)))
-override CLEANEXEFILES+=$(EXAMPLEFILES) $(EXAMPLEOFILES)
-ifeq ($(OS_TARGET),os2)
-override CLEANEXEFILES+=$(addsuffix $(AOUTEXT),$(TARGET_EXAMPLES))
-endif
-ifeq ($(OS_TARGET),emx)
-override CLEANEXEFILES+=$(addsuffix $(AOUTEXT),$(TARGET_EXAMPLES))
-endif
-endif
-ifneq ($(TARGET_EXAMPLEDIRS),)
-HASEXAMPLES=1
-endif
-fpc_examples: all $(EXAMPLEFILES) $(addsuffix _all,$(TARGET_EXAMPLEDIRS))
-.PHONY: fpc_all fpc_smart fpc_debug fpc_release fpc_shared
-$(FPCMADE): $(ALLDEPENDENCIES) $(ALLTARGET)
- @$(ECHOREDIR) Compiled > $(FPCMADE)
-fpc_all: $(FPCMADE)
-fpc_smart:
- $(MAKE) all LINKSMART=1 CREATESMART=1
-fpc_debug:
- $(MAKE) all DEBUG=1
-fpc_release:
- $(MAKE) all RELEASE=1
-.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .lpr .dpr .pp .rc .res
-$(COMPILER_UNITTARGETDIR):
- $(MKDIRTREE) $(COMPILER_UNITTARGETDIR)
-$(COMPILER_TARGETDIR):
- $(MKDIRTREE) $(COMPILER_TARGETDIR)
-%$(PPUEXT): %.pp
- $(COMPILER) $<
- $(EXECPPAS)
-%$(PPUEXT): %.pas
- $(COMPILER) $<
- $(EXECPPAS)
-%$(EXEEXT): %.pp
- $(COMPILER) $<
- $(EXECPPAS)
-%$(EXEEXT): %.pas
- $(COMPILER) $<
- $(EXECPPAS)
-%$(EXEEXT): %.lpr
- $(COMPILER) $<
- $(EXECPPAS)
-%$(EXEEXT): %.dpr
- $(COMPILER) $<
- $(EXECPPAS)
-%.res: %.rc
- windres -i $< -o $@
-vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
-vpath %.pas $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
-vpath %.lpr $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
-vpath %.dpr $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
-vpath %.inc $(COMPILER_INCLUDEDIR)
-vpath %$(OEXT) $(COMPILER_UNITTARGETDIR)
-vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR)
-.PHONY: fpc_shared
-override INSTALLTARGET+=fpc_shared_install
-ifndef SHARED_LIBVERSION
-SHARED_LIBVERSION=$(FPC_VERSION)
-endif
-ifndef SHARED_LIBNAME
-SHARED_LIBNAME=$(PACKAGE_NAME)
-endif
-ifndef SHARED_FULLNAME
-SHARED_FULLNAME=$(SHAREDLIBPREFIX)$(SHARED_LIBNAME)-$(SHARED_LIBVERSION)$(SHAREDLIBEXT)
-endif
-ifndef SHARED_LIBUNITS
-SHARED_LIBUNITS:=$(TARGET_UNITS) $(TARGET_IMPLICITUNITS)
-override SHARED_LIBUNITS:=$(filter-out $(INSTALL_BUILDUNIT),$(SHARED_LIBUNITS))
-endif
-fpc_shared:
-ifdef HASSHAREDLIB
- $(MAKE) all CREATESHARED=1 LINKSHARED=1 CREATESMART=1
-ifneq ($(SHARED_BUILD),n)
- $(PPUMOVE) -q $(SHARED_LIBUNITS) -i$(COMPILER_UNITTARGETDIR) -o$(SHARED_FULLNAME) -d$(COMPILER_UNITTARGETDIR)
-endif
-else
- @$(ECHO) Shared Libraries not supported
-endif
-fpc_shared_install:
-ifneq ($(SHARED_BUILD),n)
-ifneq ($(SHARED_LIBUNITS),)
-ifneq ($(wildcard $(COMPILER_UNITTARGETDIR)/$(SHARED_FULLNAME)),)
- $(INSTALL) $(COMPILER_UNITTARGETDIR)/$(SHARED_FULLNAME) $(INSTALL_SHAREDDIR)
-endif
-endif
-endif
-.PHONY: fpc_install fpc_sourceinstall fpc_exampleinstall
-ifdef INSTALL_UNITS
-override INSTALLPPUFILES+=$(addsuffix $(PPUEXT),$(INSTALL_UNITS))
-endif
-ifdef INSTALL_BUILDUNIT
-override INSTALLPPUFILES:=$(filter-out $(INSTALL_BUILDUNIT)$(PPUEXT),$(INSTALLPPUFILES))
-endif
-ifdef INSTALLPPUFILES
-override INSTALLPPULINKFILES:=$(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)) $(addprefix $(STATICLIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES))) $(addprefix $(IMPORTLIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES)))
-ifneq ($(UNITTARGETDIRPREFIX),)
-override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(notdir $(INSTALLPPUFILES)))
-override INSTALLPPULINKFILES:=$(wildcard $(addprefix $(UNITTARGETDIRPREFIX),$(notdir $(INSTALLPPULINKFILES))))
-endif
-override INSTALL_CREATEPACKAGEFPC=1
-endif
-ifdef INSTALLEXEFILES
-ifneq ($(TARGETDIRPREFIX),)
-override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(notdir $(INSTALLEXEFILES)))
-endif
-endif
-fpc_install: all $(INSTALLTARGET)
-ifdef INSTALLEXEFILES
- $(MKDIR) $(INSTALL_BINDIR)
-ifdef UPXPROG
- -$(UPXPROG) $(INSTALLEXEFILES)
-endif
- $(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR)
-endif
-ifdef INSTALL_CREATEPACKAGEFPC
-ifdef FPCMAKE
-ifdef PACKAGE_VERSION
-ifneq ($(wildcard Makefile.fpc),)
- $(FPCMAKE) -p -T$(CPU_TARGET)-$(OS_TARGET) Makefile.fpc
- $(MKDIR) $(INSTALL_UNITDIR)
- $(INSTALL) Package.fpc $(INSTALL_UNITDIR)
-endif
-endif
-endif
-endif
-ifdef INSTALLPPUFILES
- $(MKDIR) $(INSTALL_UNITDIR)
- $(INSTALL) $(INSTALLPPUFILES) $(INSTALL_UNITDIR)
-ifneq ($(INSTALLPPULINKFILES),)
- $(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR)
-endif
-ifneq ($(wildcard $(LIB_FULLNAME)),)
- $(MKDIR) $(INSTALL_LIBDIR)
- $(INSTALL) $(LIB_FULLNAME) $(INSTALL_LIBDIR)
-ifdef inUnix
- ln -sf $(LIB_FULLNAME) $(INSTALL_LIBDIR)/$(LIB_NAME)
-endif
-endif
-endif
-ifdef INSTALL_FILES
- $(MKDIR) $(INSTALL_DATADIR)
- $(INSTALL) $(INSTALL_FILES) $(INSTALL_DATADIR)
-endif
-fpc_sourceinstall: distclean
- $(MKDIR) $(INSTALL_SOURCEDIR)
- $(COPYTREE) $(BASEDIR)/* $(INSTALL_SOURCEDIR)
-fpc_exampleinstall: $(addsuffix _distclean,$(TARGET_EXAMPLEDIRS))
-ifdef HASEXAMPLES
- $(MKDIR) $(INSTALL_EXAMPLEDIR)
-endif
-ifdef EXAMPLESOURCEFILES
- $(COPY) $(EXAMPLESOURCEFILES) $(INSTALL_EXAMPLEDIR)
-endif
-ifdef TARGET_EXAMPLEDIRS
- $(COPYTREE) $(addsuffix /*,$(TARGET_EXAMPLEDIRS)) $(INSTALL_EXAMPLEDIR)
-endif
-.PHONY: fpc_distinstall
-fpc_distinstall: install exampleinstall
-.PHONY: fpc_zipinstall fpc_zipsourceinstall fpc_zipexampleinstall
-ifndef PACKDIR
-ifndef inUnix
-PACKDIR=$(BASEDIR)/../fpc-pack
-else
-PACKDIR=/tmp/fpc-pack
-endif
-endif
-ifndef ZIPNAME
-ifdef DIST_ZIPNAME
-ZIPNAME=$(DIST_ZIPNAME)
-else
-ZIPNAME=$(PACKAGE_NAME)
-endif
-endif
-ifndef FULLZIPNAME
-FULLZIPNAME=$(ZIPCROSSPREFIX)$(ZIPPREFIX)$(ZIPNAME)$(ZIPSUFFIX)
-endif
-ifndef ZIPTARGET
-ifdef DIST_ZIPTARGET
-ZIPTARGET=DIST_ZIPTARGET
-else
-ZIPTARGET=install
-endif
-endif
-ifndef USEZIP
-ifdef inUnix
-USETAR=1
-endif
-endif
-ifndef inUnix
-USEZIPWRAPPER=1
-endif
-ifdef USEZIPWRAPPER
-ZIPPATHSEP=$(PATHSEP)
-ZIPWRAPPER=$(subst /,$(PATHSEP),$(DIST_DESTDIR)/fpczip$(SRCBATCHEXT))
-else
-ZIPPATHSEP=/
-endif
-ZIPCMD_CDPACK:=cd $(subst /,$(ZIPPATHSEP),$(PACKDIR))
-ZIPCMD_CDBASE:=cd $(subst /,$(ZIPPATHSEP),$(BASEDIR))
-ifdef USETAR
-ZIPDESTFILE:=$(DIST_DESTDIR)/$(FULLZIPNAME)$(TAREXT)
-ZIPCMD_ZIP:=$(TARPROG) cf$(TAROPT) $(ZIPDESTFILE) *
-else
-ZIPDESTFILE:=$(DIST_DESTDIR)/$(FULLZIPNAME)$(ZIPEXT)
-ZIPCMD_ZIP:=$(subst /,$(ZIPPATHSEP),$(ZIPPROG)) -Dr $(ZIPOPT) $(ZIPDESTFILE) *
-endif
-fpc_zipinstall:
- $(MAKE) $(ZIPTARGET) INSTALL_PREFIX=$(PACKDIR) ZIPINSTALL=1
- $(MKDIR) $(DIST_DESTDIR)
- $(DEL) $(ZIPDESTFILE)
-ifdef USEZIPWRAPPER
-ifneq ($(ECHOREDIR),echo)
- $(ECHOREDIR) -e "$(subst \,\\,$(ZIPCMD_CDPACK))" > $(ZIPWRAPPER)
- $(ECHOREDIR) -e "$(subst \,\\,$(ZIPCMD_ZIP))" >> $(ZIPWRAPPER)
- $(ECHOREDIR) -e "$(subst \,\\,$(ZIPCMD_CDBASE))" >> $(ZIPWRAPPER)
-else
- echo $(ZIPCMD_CDPACK) > $(ZIPWRAPPER)
- echo $(ZIPCMD_ZIP) >> $(ZIPWRAPPER)
- echo $(ZIPCMD_CDBASE) >> $(ZIPWRAPPER)
-endif
-ifdef inUnix
- /bin/sh $(ZIPWRAPPER)
-else
-ifdef RUNBATCH
- $(RUNBATCH) (ZIPWRAPPER)
-else
- $(ZIPWRAPPER)
-endif
-endif
- $(DEL) $(ZIPWRAPPER)
-else
- $(ZIPCMD_CDPACK) ; $(ZIPCMD_ZIP) ; $(ZIPCMD_CDBASE)
-endif
- $(DELTREE) $(PACKDIR)
-fpc_zipsourceinstall:
- $(MAKE) fpc_zipinstall ZIPTARGET=sourceinstall ZIPSUFFIX=$(ZIPSOURCESUFFIX)
-fpc_zipexampleinstall:
-ifdef HASEXAMPLES
- $(MAKE) fpc_zipinstall ZIPTARGET=exampleinstall ZIPSUFFIX=$(ZIPEXAMPLESUFFIX)
-endif
-fpc_zipdistinstall:
- $(MAKE) fpc_zipinstall ZIPTARGET=distinstall
-.PHONY: fpc_clean fpc_cleanall fpc_distclean
-ifdef EXEFILES
-override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
-endif
-ifdef CLEAN_UNITS
-override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))
-endif
-ifdef CLEANPPUFILES
-override CLEANPPULINKFILES:=$(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)) $(addprefix $(STATICLIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES))) $(addprefix $(IMPORTLIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES)))
-ifdef DEBUGSYMEXT
-override CLEANPPULINKFILES+=$(subst $(PPUEXT),$(DEBUGSYMEXT),$(CLEANPPUFILES))
-endif
-override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPUFILES))
-override CLEANPPULINKFILES:=$(wildcard $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPULINKFILES)))
-endif
-fpc_clean: $(CLEANTARGET)
-ifdef CLEANEXEFILES
- -$(DEL) $(CLEANEXEFILES)
-endif
-ifdef CLEANPPUFILES
- -$(DEL) $(CLEANPPUFILES)
-endif
-ifneq ($(CLEANPPULINKFILES),)
- -$(DEL) $(CLEANPPULINKFILES)
-endif
-ifdef CLEANRSTFILES
- -$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
-endif
-ifdef CLEAN_FILES
- -$(DEL) $(CLEAN_FILES)
-endif
-ifdef LIB_NAME
- -$(DEL) $(LIB_NAME) $(LIB_FULLNAME)
-endif
- -$(DEL) $(FPCMADE) Package.fpc $(PPAS) script.res link.res $(FPCEXTFILE) $(REDIRFILE)
- -$(DEL) *$(ASMEXT) *_ppas$(BATCHEXT)
-fpc_cleanall: $(CLEANTARGET)
-ifdef CLEANEXEFILES
- -$(DEL) $(CLEANEXEFILES)
-endif
-ifdef COMPILER_UNITTARGETDIR
-ifdef CLEANPPUFILES
- -$(DEL) $(CLEANPPUFILES)
-endif
-ifneq ($(CLEANPPULINKFILES),)
- -$(DEL) $(CLEANPPULINKFILES)
-endif
-ifdef CLEANRSTFILES
- -$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
-endif
-endif
- -$(DELTREE) units
- -$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
-ifneq ($(PPUEXT),.ppu)
- -$(DEL) *.o *.ppu *.a
-endif
- -$(DELTREE) *$(SMARTEXT)
- -$(DEL) fpcmade.* Package.fpc $(PPAS) script.res link.res $(FPCEXTFILE) $(REDIRFILE)
- -$(DEL) *_ppas$(BATCHEXT)
-ifdef AOUTEXT
- -$(DEL) *$(AOUTEXT)
-endif
-ifdef DEBUGSYMEXT
- -$(DEL) *$(DEBUGSYMEXT)
-endif
-fpc_distclean: cleanall
-.PHONY: fpc_baseinfo
-override INFORULES+=fpc_baseinfo
-fpc_baseinfo:
- @$(ECHO)
- @$(ECHO) == Package info ==
- @$(ECHO) Package Name..... $(PACKAGE_NAME)
- @$(ECHO) Package Version.. $(PACKAGE_VERSION)
- @$(ECHO)
- @$(ECHO) == Configuration info ==
- @$(ECHO)
- @$(ECHO) FPC.......... $(FPC)
- @$(ECHO) FPC Version.. $(FPC_VERSION)
- @$(ECHO) Source CPU... $(CPU_SOURCE)
- @$(ECHO) Target CPU... $(CPU_TARGET)
- @$(ECHO) Source OS.... $(OS_SOURCE)
- @$(ECHO) Target OS.... $(OS_TARGET)
- @$(ECHO) Full Source.. $(FULL_SOURCE)
- @$(ECHO) Full Target.. $(FULL_TARGET)
- @$(ECHO) SourceSuffix. $(SOURCESUFFIX)
- @$(ECHO) TargetSuffix. $(TARGETSUFFIX)
- @$(ECHO)
- @$(ECHO) == Directory info ==
- @$(ECHO)
- @$(ECHO) Required pkgs... $(REQUIRE_PACKAGES)
- @$(ECHO)
- @$(ECHO) Basedir......... $(BASEDIR)
- @$(ECHO) FPCDir.......... $(FPCDIR)
- @$(ECHO) CrossBinDir..... $(CROSSBINDIR)
- @$(ECHO) UnitsDir........ $(UNITSDIR)
- @$(ECHO) PackagesDir..... $(PACKAGESDIR)
- @$(ECHO)
- @$(ECHO) GCC library..... $(GCCLIBDIR)
- @$(ECHO) Other library... $(OTHERLIBDIR)
- @$(ECHO)
- @$(ECHO) == Tools info ==
- @$(ECHO)
- @$(ECHO) As........ $(AS)
- @$(ECHO) Ld........ $(LD)
- @$(ECHO) Ar........ $(AR)
- @$(ECHO) Rc........ $(RC)
- @$(ECHO)
- @$(ECHO) Mv........ $(MVPROG)
- @$(ECHO) Cp........ $(CPPROG)
- @$(ECHO) Rm........ $(RMPROG)
- @$(ECHO) GInstall.. $(GINSTALL)
- @$(ECHO) Echo...... $(ECHO)
- @$(ECHO) Shell..... $(SHELL)
- @$(ECHO) Date...... $(DATE)
- @$(ECHO) FPCMake... $(FPCMAKE)
- @$(ECHO) PPUMove... $(PPUMOVE)
- @$(ECHO) Upx....... $(UPXPROG)
- @$(ECHO) Zip....... $(ZIPPROG)
- @$(ECHO)
- @$(ECHO) == Object info ==
- @$(ECHO)
- @$(ECHO) Target Loaders........ $(TARGET_LOADERS)
- @$(ECHO) Target Units.......... $(TARGET_UNITS)
- @$(ECHO) Target Implicit Units. $(TARGET_IMPLICITUNITS)
- @$(ECHO) Target Programs....... $(TARGET_PROGRAMS)
- @$(ECHO) Target Dirs........... $(TARGET_DIRS)
- @$(ECHO) Target Examples....... $(TARGET_EXAMPLES)
- @$(ECHO) Target ExampleDirs.... $(TARGET_EXAMPLEDIRS)
- @$(ECHO)
- @$(ECHO) Clean Units......... $(CLEAN_UNITS)
- @$(ECHO) Clean Files......... $(CLEAN_FILES)
- @$(ECHO)
- @$(ECHO) Install Units....... $(INSTALL_UNITS)
- @$(ECHO) Install Files....... $(INSTALL_FILES)
- @$(ECHO)
- @$(ECHO) == Install info ==
- @$(ECHO)
- @$(ECHO) DateStr.............. $(DATESTR)
- @$(ECHO) ZipName.............. $(ZIPNAME)
- @$(ECHO) ZipPrefix............ $(ZIPPREFIX)
- @$(ECHO) ZipCrossPrefix....... $(ZIPCROSSPREFIX)
- @$(ECHO) ZipSuffix............ $(ZIPSUFFIX)
- @$(ECHO) FullZipName.......... $(FULLZIPNAME)
- @$(ECHO) Install FPC Package.. $(INSTALL_FPCPACKAGE)
- @$(ECHO)
- @$(ECHO) Install base dir..... $(INSTALL_BASEDIR)
- @$(ECHO) Install binary dir... $(INSTALL_BINDIR)
- @$(ECHO) Install library dir.. $(INSTALL_LIBDIR)
- @$(ECHO) Install units dir.... $(INSTALL_UNITDIR)
- @$(ECHO) Install source dir... $(INSTALL_SOURCEDIR)
- @$(ECHO) Install doc dir...... $(INSTALL_DOCDIR)
- @$(ECHO) Install example dir.. $(INSTALL_EXAMPLEDIR)
- @$(ECHO) Install data dir..... $(INSTALL_DATADIR)
- @$(ECHO)
- @$(ECHO) Dist destination dir. $(DIST_DESTDIR)
- @$(ECHO) Dist zip name........ $(DIST_ZIPNAME)
- @$(ECHO)
-.PHONY: fpc_info
-fpc_info: $(INFORULES)
-.PHONY: fpc_makefile fpc_makefiles fpc_makefile_sub1 fpc_makefile_sub2 \
- fpc_makefile_dirs
-fpc_makefile:
- $(FPCMAKE) -w -T$(OS_TARGET) Makefile.fpc
-fpc_makefile_sub1:
-ifdef TARGET_DIRS
- $(FPCMAKE) -w -T$(OS_TARGET) $(addsuffix /Makefile.fpc,$(TARGET_DIRS))
-endif
-ifdef TARGET_EXAMPLEDIRS
- $(FPCMAKE) -w -T$(OS_TARGET) $(addsuffix /Makefile.fpc,$(TARGET_EXAMPLEDIRS))
-endif
-fpc_makefile_sub2: $(addsuffix _makefile_dirs,$(TARGET_DIRS) $(TARGET_EXAMPLEDIRS))
-fpc_makefile_dirs: fpc_makefile_sub1 fpc_makefile_sub2
-fpc_makefiles: fpc_makefile fpc_makefile_dirs
-all: fpc_all
-debug: fpc_debug
-smart: fpc_smart
-release: fpc_release
-units: fpc_units
-examples: fpc_examples
-shared: fpc_shared
-install: fpc_install
-sourceinstall: fpc_sourceinstall
-exampleinstall: fpc_exampleinstall
-distinstall: fpc_distinstall
-zipinstall: fpc_zipinstall
-zipsourceinstall: fpc_zipsourceinstall
-zipexampleinstall: fpc_zipexampleinstall
-zipdistinstall: fpc_zipdistinstall
-clean: fpc_clean
-distclean: fpc_distclean
-cleanall: fpc_cleanall
-info: fpc_info
-makefiles: fpc_makefiles
-.PHONY: all debug smart release units examples shared install sourceinstall exampleinstall distinstall zipinstall zipsourceinstall zipexampleinstall zipdistinstall clean distclean cleanall info makefiles
-ifneq ($(wildcard fpcmake.loc),)
-include fpcmake.loc
-endif
-.NOTPARALLEL:
diff --git a/packages/base/pasjpeg/Makefile.fpc b/packages/base/pasjpeg/Makefile.fpc
deleted file mode 100644
index c7c181d3ac..0000000000
--- a/packages/base/pasjpeg/Makefile.fpc
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# Makefile.fpc for PasJPEG
-#
-
-[package]
-name=pasjpeg
-version=2.0.0
-
-[target]
-units=buildpasjpeg
-implicitunits=jcapimin jcapistd jccoefct jccolor jcdctmgr jchuff jcinit jcmainct \
- jcmarker jcmaster jcomapi jcparam jcphuff jcprepct jcsample jdapimin \
- jdapistd jdatadst jdatasrc jdcoefct jdcolor jdct jddctmgr jdeferr \
- jdhuff jdinput jdmainct jdmarker jdmaster jdmerge jdphuff jdpostct \
- jdsample jerror jfdctflt jfdctfst jfdctint jidctflt jidctfst \
- jidctint jidctred jinclude jmemmgr jmemnobs jmorecfg jpeglib \
- jquant1 jquant2 jutils
-examples=cjpeg demo djpeg jpegtran rdjpgcom
-
-[install]
-fpcpackage=y
-
-[default]
-fpcdir=../../..
-
-[rules]
-.NOTPARALLEL:
diff --git a/packages/base/pasjpeg/PasJpeg.raw b/packages/base/pasjpeg/PasJpeg.raw
deleted file mode 100644
index e69de29bb2..0000000000
--- a/packages/base/pasjpeg/PasJpeg.raw
+++ /dev/null
diff --git a/packages/base/pasjpeg/buildpasjpeg.pp b/packages/base/pasjpeg/buildpasjpeg.pp
deleted file mode 100644
index cc2c694002..0000000000
--- a/packages/base/pasjpeg/buildpasjpeg.pp
+++ /dev/null
@@ -1,60 +0,0 @@
-{
-
- Unit to build all units of Pasjpeg
-}
-unit buildpasjpeg;
-interface
-uses
- jcapimin,
- jcapistd,
- jccoefct,
- jccolor,
- jcdctmgr,
- jchuff,
- jcinit,
- jcmainct,
- jcmarker,
- jcmaster,
- jcomapi,
- jcparam,
- jcphuff,
- jcprepct,
- jcsample,
- jdapimin,
- jdapistd,
- jdatadst,
- jdatasrc,
- jdcoefct,
- jdcolor,
- jdct,
- jddctmgr,
- jdeferr,
- jdhuff,
- jdinput,
- jdmainct,
- jdmarker,
- jdmaster,
- jdmerge,
- jdphuff,
- jdpostct,
- jdsample,
- jerror,
- jfdctflt,
- jfdctfst,
- jfdctint,
- jidctflt,
- jidctfst,
- jidctint,
- jidctred,
- jinclude,
- jmemmgr,
- jmemnobs,
- jmorecfg,
- jpeglib,
- jquant1,
- jquant2,
- jutils;
-
-implementation
-
-end.
diff --git a/packages/base/pasjpeg/cderror.pas b/packages/base/pasjpeg/cderror.pas
deleted file mode 100644
index 3ebb65f226..0000000000
--- a/packages/base/pasjpeg/cderror.pas
+++ /dev/null
@@ -1,208 +0,0 @@
-Unit CdError;
-
-{ This file defines the error and message codes for the cjpeg/djpeg
- applications. These strings are not needed as part of the JPEG library
- proper.
- Edit this file to add new codes, or to translate the message strings to
- some other language. }
-
-{ Original cderror.h ; Copyright (C) 1994, Thomas G. Lane. }
-
-interface
-
-{ To define the enum list of message codes, include this file without
- defining macro JMESSAGE. To create a message string table, include it
- again with a suitable JMESSAGE definition (see jerror.c for an example). }
-
-
-{$define TARGA_SUPPORTED}
-{$define BMP_SUPPORTED}
-{$define GIF_SUPPORTED}
-{$define PPM_SUPPORTED}
-{$define RLE_SUPPORTED}
-
-type
- ADDON_MESSAGE_CODE =(
-
- JMSG_FIRSTADDONCODE, { Must be first entry! }
-
- {$ifdef BMP_SUPPORTED}
- JERR_BMP_BADCMAP, { Unsupported BMP colormap format }
- JERR_BMP_BADDEPTH, { Only 8- and 24-bit BMP files are supported }
- JERR_BMP_BADHEADER, { Invalid BMP file: bad header length }
- JERR_BMP_BADPLANES, { Invalid BMP file: biPlanes not equal to 1 }
- JERR_BMP_COLORSPACE, { BMP output must be grayscale or RGB }
- JERR_BMP_COMPRESSED, { Sorry, compressed BMPs not yet supported }
- JERR_BMP_NOT, { Not a BMP file - does not start with BM }
- JTRC_BMP, { %ux%u 24-bit BMP image }
- JTRC_BMP_MAPPED, { %ux%u 8-bit colormapped BMP image }
- JTRC_BMP_OS2, { %ux%u 24-bit OS2 BMP image }
- JTRC_BMP_OS2_MAPPED, { %ux%u 8-bit colormapped OS2 BMP image }
- {$endif} { BMP_SUPPORTED }
-
- {$ifdef GIF_SUPPORTED}
- JERR_GIF_BUG, { GIF output got confused }
- JERR_GIF_CODESIZE, { Bogus GIF codesize %d }
- JERR_GIF_COLORSPACE, { GIF output must be grayscale or RGB }
- JERR_GIF_IMAGENOTFOUND, { Too few images in GIF file }
- JERR_GIF_NOT, { Not a GIF file }
- JTRC_GIF, { %ux%ux%d GIF image }
- JTRC_GIF_BADVERSION,
- { Warning: unexpected GIF version number '%c%c%c' }
- JTRC_GIF_EXTENSION, { Ignoring GIF extension block of type 0x%02x }
- JTRC_GIF_NONSQUARE, { Caution: nonsquare pixels in input }
- JWRN_GIF_BADDATA, { Corrupt data in GIF file }
- JWRN_GIF_CHAR, { Bogus char 0x%02x in GIF file, ignoring }
- JWRN_GIF_ENDCODE, { Premature end of GIF image }
- JWRN_GIF_NOMOREDATA, { Ran out of GIF bits }
- {$endif} { GIF_SUPPORTED }
-
- {$ifdef PPM_SUPPORTED}
- JERR_PPM_COLORSPACE, { PPM output must be grayscale or RGB }
- JERR_PPM_NONNUMERIC, { Nonnumeric data in PPM file }
- JERR_PPM_NOT, { Not a PPM file }
- JTRC_PGM, { %ux%u PGM image }
- JTRC_PGM_TEXT, { %ux%u text PGM image }
- JTRC_PPM, { %ux%u PPM image }
- JTRC_PPM_TEXT, { %ux%u text PPM image }
- {$endif} { PPM_SUPPORTED }
-
- {$ifdef RLE_SUPPORTED}
- JERR_RLE_BADERROR, { Bogus error code from RLE library }
- JERR_RLE_COLORSPACE, { RLE output must be grayscale or RGB }
- JERR_RLE_DIMENSIONS, { Image dimensions (%ux%u) too large for RLE }
- JERR_RLE_EMPTY, { Empty RLE file }
- JERR_RLE_EOF, { Premature EOF in RLE header }
- JERR_RLE_MEM, { Insufficient memory for RLE header }
- JERR_RLE_NOT, { Not an RLE file }
- JERR_RLE_TOOMANYCHANNELS, { Cannot handle %d output channels for RLE }
- JERR_RLE_UNSUPPORTED, { Cannot handle this RLE setup }
- JTRC_RLE, { %ux%u full-color RLE file }
- JTRC_RLE_FULLMAP, { %ux%u full-color RLE file with map of length %d }
- JTRC_RLE_GRAY, { %ux%u grayscale RLE file }
- JTRC_RLE_MAPGRAY, { %ux%u grayscale RLE file with map of length %d }
- JTRC_RLE_MAPPED, { %ux%u colormapped RLE file with map of length %d }
- {$endif} { RLE_SUPPORTED }
-
- {$ifdef TARGA_SUPPORTED}
- JERR_TGA_BADCMAP, { Unsupported Targa colormap format }
- JERR_TGA_BADPARMS, { Invalid or unsupported Targa file }
- JERR_TGA_COLORSPACE, { Targa output must be grayscale or RGB }
- JTRC_TGA, { %ux%u RGB Targa image }
- JTRC_TGA_GRAY, { %ux%u grayscale Targa image }
- JTRC_TGA_MAPPED, { %ux%u colormapped Targa image }
- {$else}
- JERR_TGA_NOTCOMP, { Targa support was not compiled }
- {$endif} { TARGA_SUPPORTED }
-
- JERR_BAD_CMAP_FILE,
- { Color map file is invalid or of unsupported format }
- JERR_TOO_MANY_COLORS,
- { Output file format cannot handle %d colormap entries }
- JERR_UNGETC_FAILED, { ungetc failed }
- {$ifdef TARGA_SUPPORTED}
- JERR_UNKNOWN_FORMAT,
- { Unrecognized input file format --- perhaps you need -targa }
- {$else}
- JERR_UNKNOWN_FORMAT, { Unrecognized input file format }
- {$endif}
- JERR_UNSUPPORTED_FORMAT, { Unsupported output file format }
-
- JMSG_LASTADDONCODE
- );
-
-type
- msg_table = Array[ADDON_MESSAGE_CODE] of string[80];
-const
- cdjpeg_message_table : msg_table = (
-
- { JMSG_FIRSTADDONCODE } '', { Must be first entry! }
-
-{$ifdef BMP_SUPPORTED}
- { JERR_BMP_BADCMAP } 'Unsupported BMP colormap format',
- { JERR_BMP_BADDEPTH } 'Only 8- and 24-bit BMP files are supported',
- { JERR_BMP_BADHEADER } 'Invalid BMP file: bad header length',
- { JERR_BMP_BADPLANES } 'Invalid BMP file: biPlanes not equal to 1',
- { JERR_BMP_COLORSPACE } 'BMP output must be grayscale or RGB',
- { JERR_BMP_COMPRESSED } 'Sorry, compressed BMPs not yet supported',
- { JERR_BMP_NOT } 'Not a BMP file - does not start with BM',
- { JTRC_BMP } '%ux%u 24-bit BMP image',
- { JTRC_BMP_MAPPED } '%ux%u 8-bit colormapped BMP image',
- { JTRC_BMP_OS2 } '%ux%u 24-bit OS2 BMP image',
- { JTRC_BMP_OS2_MAPPED } '%ux%u 8-bit colormapped OS2 BMP image',
-{$endif} { BMP_SUPPORTED }
-
-{$ifdef GIF_SUPPORTED}
- { JERR_GIF_BUG } 'GIF output got confused',
- { JERR_GIF_CODESIZE } 'Bogus GIF codesize %d',
- { JERR_GIF_COLORSPACE } 'GIF output must be grayscale or RGB',
- { JERR_GIF_IMAGENOTFOUND } 'Too few images in GIF file',
- { JERR_GIF_NOT } 'Not a GIF file',
- { JTRC_GIF } '%ux%ux%d GIF image',
- { JTRC_GIF_BADVERSION }
- 'Warning: unexpected GIF version number "%c%c%c"',
- { JTRC_GIF_EXTENSION } 'Ignoring GIF extension block of type 0x%02x',
- { JTRC_GIF_NONSQUARE } 'Caution: nonsquare pixels in input',
- { JWRN_GIF_BADDATA } 'Corrupt data in GIF file',
- { JWRN_GIF_CHAR } 'Bogus char 0x%02x in GIF file, ignoring',
- { JWRN_GIF_ENDCODE } 'Premature end of GIF image',
- { JWRN_GIF_NOMOREDATA } 'Ran out of GIF bits',
-{$endif} { GIF_SUPPORTED }
-
-{$ifdef PPM_SUPPORTED}
- { JERR_PPM_COLORSPACE } 'PPM output must be grayscale or RGB',
- { JERR_PPM_NONNUMERIC } 'Nonnumeric data in PPM file',
- { JERR_PPM_NOT } 'Not a PPM file',
- { JTRC_PGM } '%ux%u PGM image',
- { JTRC_PGM_TEXT } '%ux%u text PGM image',
- { JTRC_PPM } '%ux%u PPM image',
- { JTRC_PPM_TEXT } '%ux%u text PPM image',
-{$endif} { PPM_SUPPORTED }
-
-{$ifdef RLE_SUPPORTED}
- { JERR_RLE_BADERROR } 'Bogus error code from RLE library',
- { JERR_RLE_COLORSPACE } 'RLE output must be grayscale or RGB',
- { JERR_RLE_DIMENSIONS } 'Image dimensions (%ux%u) too large for RLE',
- { JERR_RLE_EMPTY } 'Empty RLE file',
- { JERR_RLE_EOF } 'Premature EOF in RLE header',
- { JERR_RLE_MEM } 'Insufficient memory for RLE header',
- { JERR_RLE_NOT } 'Not an RLE file',
- { JERR_RLE_TOOMANYCHANNELS } 'Cannot handle %d output channels for RLE',
- { JERR_RLE_UNSUPPORTED } 'Cannot handle this RLE setup',
- { JTRC_RLE } '%ux%u full-color RLE file',
- { JTRC_RLE_FULLMAP } '%ux%u full-color RLE file with map of length %d',
- { JTRC_RLE_GRAY } '%ux%u grayscale RLE file',
- { JTRC_RLE_MAPGRAY } '%ux%u grayscale RLE file with map of length %d',
- { JTRC_RLE_MAPPED } '%ux%u colormapped RLE file with map of length %d',
-{$endif} { RLE_SUPPORTED }
-
-{$ifdef TARGA_SUPPORTED}
- { JERR_TGA_BADCMAP } 'Unsupported Targa colormap format',
- { JERR_TGA_BADPARMS } 'Invalid or unsupported Targa file',
- { JERR_TGA_COLORSPACE } 'Targa output must be grayscale or RGB',
- { JTRC_TGA } '%ux%u RGB Targa image',
- { JTRC_TGA_GRAY } '%ux%u grayscale Targa image',
- { JTRC_TGA_MAPPED } '%ux%u colormapped Targa image',
-{$else}
- { JERR_TGA_NOTCOMP } 'Targa support was not compiled',
-{$endif} { TARGA_SUPPORTED }
-
- { JERR_BAD_CMAP_FILE }
- 'Color map file is invalid or of unsupported format',
- { JERR_TOO_MANY_COLORS }
- 'Output file format cannot handle %d colormap entries',
- { JERR_UNGETC_FAILED } 'ungetc failed',
-{$ifdef TARGA_SUPPORTED}
- { JERR_UNKNOWN_FORMAT }
- 'Unrecognized input file format --- perhaps you need -targa',
-{$else}
- { JERR_UNKNOWN_FORMAT } 'Unrecognized input file format',
-{$endif}
- { JERR_UNSUPPORTED_FORMAT } 'Unsupported output file format',
-
-
- { JMSG_LASTADDONCODE } '');
-
-implementation
-
-end.
diff --git a/packages/base/pasjpeg/cdjpeg.pas b/packages/base/pasjpeg/cdjpeg.pas
deleted file mode 100644
index edf4254e50..0000000000
--- a/packages/base/pasjpeg/cdjpeg.pas
+++ /dev/null
@@ -1,279 +0,0 @@
-Unit CdJpeg;
-
-{ OriginaL : cdjpeg.h+cdjpeg.c ; Copyright (C) 1994-1996, Thomas G. Lane.
-
- This file contains common support routines used by the IJG application
- programs (cjpeg, djpeg, jpegtran).
-
- This file contains common declarations for the sample applications
- cjpeg and djpeg. It is NOT used by the core JPEG library. }
-
-{$define JPEG_CJPEG_DJPEG} { define proper options in jconfig.h }
-{$define JPEG_INTERNAL_OPTIONS} { cjpeg.c,djpeg.c need to see xxx_SUPPORTED }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg, jinclude, jpeglib,
- jdeferr,
- {cderror,} { get application-specific error codes }
- jerror; { get library error codes too }
-
-
-const
- EXIT_SUCCESS = 0;
- EXIT_FAILURE = 1;
- EXIT_WARNING = 2;
-
-type { Nomssi }
- BGRptr = ^BGRtype;
- BGRtype = packed record
- b,g,r : byte;
- end;
-type { Nomssi }
- RGBptr = ^RGBtype;
- RGBtype = packed record
- r,g,b : JSAMPLE;
- end;
-
-{ Object interface for cjpeg's source file decoding modules }
-
-type
- cjpeg_source_ptr = ^cjpeg_source_struct;
- cjpeg_source_struct = record
- start_input : procedure (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr);
- get_pixel_rows : function (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION;
- finish_input : procedure (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr);
- input_file : FILEptr;
-
- buffer : JSAMPARRAY;
- buffer_height : JDIMENSION;
- end;
-
-
-{ Object interface for djpeg's output file encoding modules }
-
-type
- djpeg_dest_ptr = ^djpeg_dest_struct;
- djpeg_dest_struct = record
- { start_output is called after jpeg_start_decompress finishes.
- The color map will be ready at this time, if one is needed. }
-
- start_output : procedure (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr);
- { Emit the specified number of pixel rows from the buffer. }
- put_pixel_rows : procedure (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr;
- rows_supplied : JDIMENSION);
- { Finish up at the end of the image. }
- finish_output : procedure (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr);
-
- { Target file spec; filled in by djpeg.c after object is created. }
- output_file : FILEptr;
-
- { Output pixel-row buffer. Created by module init or start_output.
- Width is cinfo^.output_width * cinfo^.output_components;
- height is buffer_height. }
-
- buffer : JSAMPARRAY;
- buffer_height : JDIMENSION;
- end;
-
-
-{ cjpeg/djpeg may need to perform extra passes to convert to or from
- the source/destination file format. The JPEG library does not know
- about these passes, but we'd like them to be counted by the progress
- monitor. We use an expanded progress monitor object to hold the
- additional pass count. }
-
-type
- cd_progress_ptr = ^cdjpeg_progress_mgr;
- cdjpeg_progress_mgr = record
- pub : jpeg_progress_mgr; { fields known to JPEG library }
- completed_extra_passes : int; { extra passes completed }
- total_extra_passes : int; { total extra }
- { last printed percentage stored here to avoid multiple printouts }
- percent_done : int;
- end;
-
-{GLOBAL}
-procedure enable_signal_catcher (cinfo : j_common_ptr);
-
-{ 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}
-function keymatch (arg : string;
- const keyword : string;
- minchars : int) : boolean;
-
-{$ifdef PROGRESS_REPORT}
-
-{GLOBAL}
-procedure start_progress_monitor (cinfo : j_common_ptr;
- progress : cd_progress_ptr);
-
-{GLOBAL}
-procedure end_progress_monitor (cinfo : j_common_ptr);
-
-{$endif}
-
-implementation
-
-
-{GLOBAL}
-procedure enable_signal_catcher (cinfo : j_common_ptr);
-begin
- RunError(255); { not translated - Jacques Nomssi }
-end;
-
-{ Optional progress monitor: display a percent-done figure on stderr. }
-
-
-{$ifdef PROGRESS_REPORT}
-
-{METHODDEF}
-procedure progress_monitor (cinfo : j_common_ptr); far;
-var
- prog : cd_progress_ptr;
- total_passes : int;
- percent_done : int;
-begin
- prog := cd_progress_ptr (cinfo^.progress);
- total_passes := prog^.pub.total_passes + prog^.total_extra_passes;
- percent_done := int (prog^.pub.pass_counter*Long(100) div prog^.pub.pass_limit);
- if (percent_done <> prog^.percent_done) then
- begin
- prog^.percent_done := percent_done;
- if (total_passes > 1) then
- Write(output, #13'Pass ',
- prog^.pub.completed_passes + prog^.completed_extra_passes + 1,
- '/',total_passes,': ',percent_done:3,'% ')
- else
- Write(#13' ', percent_done,'% ');
- {fflush(stderr);}
- end;
-end;
-
-
-{GLOBAL}
-procedure start_progress_monitor (cinfo : j_common_ptr;
- progress : cd_progress_ptr);
-begin
- { Enable progress display, unless trace output is on }
- if (cinfo^.err^.trace_level = 0) then
- begin
- progress^.pub.progress_monitor := progress_monitor;
- progress^.completed_extra_passes := 0;
- progress^.total_extra_passes := 0;
- progress^.percent_done := -1;
- cinfo^.progress := @progress^.pub;
- end;
-end;
-
-
-{GLOBAL}
-procedure end_progress_monitor (cinfo : j_common_ptr);
-begin
- { Clear away progress display }
- if (cinfo^.err^.trace_level = 0) then
- begin
- WriteLn(#13' '#13);
- {fflush(stderr);}
- end;
-end;
-
-{$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}
-function keymatch (arg : string;
- const keyword : string;
- minchars : int) : boolean;
-var
- {register} i : int;
- ca, ck : char;
- {register} nmatched : int;
-begin
- nmatched := 0;
-
- i := 1;
- if length(arg) > length(keyword) then
- begin
- keymatch := FALSE; { arg longer than keyword, no good }
- exit;
- end;
- while (i <= length(arg)) do
- begin
- ca := UpCase(arg[i]);
- ck := UpCase(keyword[i]);
- Inc(i);
- if (ca <> ck) then
- begin
- keymatch := FALSE; { no good }
- exit;
- end;
- Inc(nmatched); { count matched characters }
- end;
- { reached end of argument; fail if it's too short for unique abbrev }
- keymatch := (nmatched >= minchars);
-end;
-
-{$IFDEF std I/O}
-
-{ 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}
-function read_stdin : FILEptr;
-var
- input_file : FILEptr;
-begin
- input_file := @input;
-
-{$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)) = NIL) then
- begin
- WriteLn(stderr, 'Cannot reopen stdin');
- Halt(EXIT_FAILURE);
- end;
-{$endif}
- read_stdin := input_file;
-end;
-
-
-{GLOBAL}
-function write_stdout : FILEptr;
-var
- output_file : FILEptr;
-begin
- output_file := @output;
-{$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)) = NIL) then
- begin
- WriteLn(stderr, 'Cannot reopen stdout');
- Halt(EXIT_FAILURE);
- end;
-{$endif}
- write_stdout := output_file;
-end;
-{$ENDIF}
-
-end.
diff --git a/packages/base/pasjpeg/cjpeg.pas b/packages/base/pasjpeg/cjpeg.pas
deleted file mode 100644
index dc6d987e07..0000000000
--- a/packages/base/pasjpeg/cjpeg.pas
+++ /dev/null
@@ -1,748 +0,0 @@
-Program cjpeg;
-
-{ Original: cjpeg.c ; Copyright (C) 1991-1996, Thomas G. Lane. }
-
-{ This file contains a command-line user interface for the JPEG compressor. }
-
-{ 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. }
-
-{$I jconfig.inc}
-{$undef PPM_SUPPORTED}
-
-uses
- jmorecfg,
- cdjpeg, { Common decls for cjpeg/djpeg applications }
- {jversion,} { for version message }
- jpeglib,
-
- jerror,
- jinclude, JDataDst,
- JcAPImin, JcAPIstd, JcParam,
-{$ifdef TARGA_SUPPORTED} rdtarga, {$endif}
-{$ifdef BMP_SUPPORTED} rdbmp, {$endif}
-{$ifdef EXT_SWITCH} rdswitch, {$endif}
- {cderror,}
- jdeferr;
-
-
-{ 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 $00, 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. }
-
-
-var
- is_targa : boolean; { records user -targa switch }
-
-function GetFirstChar(cinfo : j_compress_ptr;
- fptr : fileptr) : char;
-var
- c : char;
-begin
- if JFREAD(fptr, @c, 1) <> 1 then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EMPTY);
-
-{$ifndef delphi_stream}
- Seek(fptr^, 0); { Nomssi: probably not portable }
-{$else}
- Fptr^.Seek(0,0);
-{$endif}
- if (IOresult <> 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_UNGETC_FAILED);
- GetFirstChar := c;
-end;
-
-
-{LOCAL}
-function select_file_type (cinfo : j_compress_ptr;
- var infile : FILE) : cjpeg_source_ptr;
-var
- c : char;
-begin
- if (is_targa) then
- begin
-{$ifdef TARGA_SUPPORTED}
- select_file_type := jinit_read_targa(cinfo);
- exit;
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_TGA_NOTCOMP);
-{$endif}
- end;
-
- c := GetFirstChar(cinfo, @infile);
-
- select_file_type := NIL; { suppress compiler warnings }
- case c of
-{$ifdef BMP_SUPPORTED}
- 'B': select_file_type := jinit_read_bmp(cinfo);
-{$endif}
-{$ifdef GIF_SUPPORTED}
- 'G': select_file_type := jinit_read_gif(cinfo);
-{$endif}
-{$ifdef PPM_SUPPORTED}
- 'P': select_file_type := jinit_read_ppm(cinfo);
-{$endif}
-{$ifdef RLE_SUPPORTED}
- 'R': select_file_type := jinit_read_rle(cinfo);
-{$endif}
-{$ifdef TARGA_SUPPORTED}
- char($00): select_file_type := jinit_read_targa(cinfo);
-{$endif}
- else
- ERREXIT(j_common_ptr(cinfo), JERR_UNKNOWN_FORMAT);
- end;
-end;
-
-
-{ 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... }
-
-
-var
- progname, { program name for error messages }
- outfilename : string[79]; { for -outfile switch }
-
-
-{LOCAL}
-procedure usage;
-{ complain about bad command line }
-begin
- Write(output, 'usage: ', progname, ' [switches] ');
-{$ifdef TWO_FILE_COMMANDLINE}
- WriteLn(output, 'inputfile outputfile');
-{$else}
- WriteLn(output, '[inputfile]');
-{$endif}
-
- WriteLn(output, 'Switches (names may be abbreviated):');
- WriteLn(output, ' -quality N Compression quality (0..100; 5-95 is useful range)');
- WriteLn(output, ' -grayscale Create monochrome JPEG file');
-{$ifdef ENTROPY_OPT_SUPPORTED}
- WriteLn(output, ' -optimize Optimize Huffman table (smaller file, but slow compression)');
-{$endif}
-{$ifdef C_PROGRESSIVE_SUPPORTED}
- WriteLn(output, ' -progressive Create progressive JPEG file');
-{$endif}
-{$ifdef TARGA_SUPPORTED}
- WriteLn(output, ' -targa Input file is Targa format (usually not needed)');
-{$endif}
- WriteLn(output, 'Switches for advanced users:');
-{$ifdef DCT_ISLOW_SUPPORTED}
- if (JDCT_DEFAULT = JDCT_ISLOW) then
- WriteLn(output, ' -dct int Use integer DCT method (default)')
- else
- WriteLn(output, ' -dct int Use integer DCT method');
-{$endif}
-{$ifdef DCT_IFAST_SUPPORTED}
- if (JDCT_DEFAULT = JDCT_IFAST) then
- WriteLn(output, ' -dct fast Use fast integer DCT (less accurate) (default)')
- else
- WriteLn(output, ' -dct fast Use fast integer DCT (less accurate)');
-{$endif}
-{$ifdef DCT_FLOAT_SUPPORTED}
- if (JDCT_DEFAULT = JDCT_FLOAT) then
- WriteLn(output, ' -dct float Use floating-point DCT method (default)')
- else
- WriteLn(output, ' -dct float Use floating-point DCT method');
-{$endif}
- WriteLn(output, ' -restart N Set restart interval in rows, or in blocks with B');
-{$ifdef INPUT_SMOOTHING_SUPPORTED}
- WriteLn(output, ' -smooth N Smooth dithered input (N=1..100 is strength)');
-{$endif}
- WriteLn(output, ' -maxmemory N Maximum memory to use (in kbytes)');
- WriteLn(output, ' -outfile name Specify name for output file');
- WriteLn(output, ' -verbose or -debug Emit debug output');
-{$IFDEF EXT_SWITCH}
- WriteLn(output, 'Switches for wizards:');
-{$ifdef C_ARITH_CODING_SUPPORTED}
- WriteLn(output, ' -arithmetic Use arithmetic coding');
-{$endif}
- WriteLn(output, ' -baseline Force baseline output');
- WriteLn(output, ' -qtables file Use quantization tables given in file');
- WriteLn(output, ' -qslots N[,...] Set component quantization tables');
- WriteLn(output, ' -sample HxV[,...] Set component sampling factors');
-{$ifdef C_MULTISCAN_FILES_SUPPORTED}
- WriteLn(output, ' -scans file Create multi-scan JPEG per script file');
-{$endif}
-{$ENDIF}
- Halt(EXIT_FAILURE);
-end;
-
-
-{LOCAL}
-function parse_switches (cinfo : j_compress_ptr;
- last_file_arg_seen : int;
- for_real : boolean) : int;
-{ 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. }
-
-var
- argn,
- argc : int;
- arg : string;
-var
- value : int;
- code : integer;
-var
- quality : int; { -quality parameter }
- q_scale_factor : int; { scaling percentage for -qtables }
- force_baseline : boolean;
- simple_progressive : boolean;
- qtablefile, { saves -qtables filename if any }
- qslotsarg, { saves -qslots parm if any }
- samplearg, { saves -sample parm if any }
- scansarg : string; { saves -scans parm if any }
-var
- lval : long;
- ch : char;
-
-const
- printed_version : boolean = FALSE;
-begin
- qtablefile := '';
- qslotsarg := '';
- samplearg := '';
- scansarg := '';
-
- { 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 := '';
- cinfo^.err^.trace_level := 0;
-
- { Scan command line options, adjust parameters }
-
- argn := 0;
- argc := ParamCount;
-
- while argn < argc do
- begin
- Inc(argn);
- arg := ParamStr(argn);
- if (arg[1] <> '-') then
- begin
- { Not a switch, must be a file name argument }
- if (argn <= last_file_arg_seen) then
- begin
- outfilename := ''; { -outfile applies to just one input file }
- continue; { ignore this name if previously processed }
- end;
- break; { else done parsing switches }
- end;
- {Inc(arg); - advance past switch marker character }
-
- if (keymatch(arg, '-arithmetic', 2)) then
- begin
- { Use arithmetic coding. }
-{$ifdef C_ARITH_CODING_SUPPORTED}
- cinfo^.arith_code := TRUE;
-{$else}
- WriteLn(output, progname, ': sorry, arithmetic coding not supported');
- Halt(EXIT_FAILURE);
-{$endif}
-
- end
- else
- if (keymatch(arg, '-baseline', 2)) then
- begin
- { Force baseline output (8-bit quantizer values). }
- force_baseline := TRUE;
-
- end
- else
- if (keymatch(arg, '-dct', 3)) then
- begin
- { Select DCT algorithm. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- if (keymatch(ParamStr(argn), 'int', 1)) then
- begin
- cinfo^.dct_method := JDCT_ISLOW;
- end
- else
- if (keymatch(ParamStr(argn), 'fast', 2)) then
- begin
- cinfo^.dct_method := JDCT_IFAST;
- end
- else
- if (keymatch(ParamStr(argn), 'float', 2)) then
- begin
- cinfo^.dct_method := JDCT_FLOAT;
- end
- else
- usage;
-
- end
- else
- if keymatch(arg, '-debug', 2) or keymatch(arg, '-verbose', 2) then
- begin
- { Enable debug printouts. }
- { On first -d, print version identification }
-
- if (not printed_version) then
- begin
- WriteLn(output, 'Independent JPEG Group''s CJPEG, version ', JVERSION);
- WriteLn(output, JCOPYRIGHT);
- WriteLn(output, JNOTICE);
- printed_version := TRUE;
- end;
- Inc(cinfo^.err^.trace_level);
-
- end
- else
- if (keymatch(arg, '-grayscale', 3)) or (keymatch(arg, '-greyscale',3)) then
- begin
- { Force a monochrome JPEG file to be generated. }
- jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
-
- end
- else
- if (keymatch(arg, '-maxmemory', 4)) then
- begin
- ch := 'x';
-
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
-
- arg := ParamStr(argn);
- if (length(arg) > 1) and (arg[length(arg)] in ['m','M']) then
- begin
- ch := arg[length(arg)];
- arg := Copy(arg, 1, Length(arg)-1);
- end;
- Val(arg, lval, code);
- if (code <> 1) then
- usage;
- if (ch = 'm') or (ch = 'M') then
- lval := lval * long(1000);
- cinfo^.mem^.max_memory_to_use := lval * long(1000);
-
- end
- else
- if (keymatch(arg, '-optimize', 2)) or (keymatch(arg, '-optimise', 2)) then
- begin
- { Enable entropy parm optimization. }
- {$ifdef ENTROPY_OPT_SUPPORTED}
- cinfo^.optimize_coding := TRUE;
- {$else}
- WriteLn(output, progname, ': sorry, entropy optimization was not compiled');
- exit(EXIT_FAILURE);
- {$endif}
-
- end
- else
- if (keymatch(arg, '-outfile', 5)) then
- begin
- { Set output file name. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- outfilename := ParamStr(argn); { save it away for later use }
-
- end
- else
- if (keymatch(arg, '-progressive', 2)) then
- begin
- { Select simple progressive mode. }
- {$ifdef C_PROGRESSIVE_SUPPORTED}
- simple_progressive := TRUE;
- { We must postpone execution until num_components is known. }
- {$else}
- WriteLn(output, progname, ': sorry, progressive output was not compiled');
- Halt(EXIT_FAILURE);
- {$endif}
-
- end
- else
- if (keymatch(arg, '-quality', 2)) then
- begin
- { Quality factor (quantization table scaling factor). }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- Val(ParamStr(argn), quality, code);
- if code <> 0 then
- usage;
-
- { Change scale factor in case -qtables is present. }
- q_scale_factor := jpeg_quality_scaling(quality);
-
- end
- else
- if (keymatch(arg, '-qslots', 3)) then
- begin
- { Quantization table slot numbers. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- qslotsarg := ParamStr(argn);
- { Must delay setting qslots until after we have processed any
- colorspace-determining switches, since jpeg_set_colorspace sets
- default quant table numbers. }
-
- end
- else
- if (keymatch(arg, '-qtables', 3)) then
- begin
- { Quantization tables fetched from file. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- qtablefile := ParamStr(argn);
- { We postpone actually reading the file in case -quality comes later. }
-
- end
- else
- if (keymatch(arg, '-restart', 2)) then
- begin
- { Restart interval in MCU rows (or in MCUs with 'b'). }
- ch := 'x';
-
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
-
- arg := ParamStr(argn);
- if (length(arg) > 1) and (arg[length(arg)] in ['b','B']) then
- begin
- ch := arg[length(arg)];
- arg := Copy(arg, 1, Length(arg)-1);
- end;
-
- Val(arg, lval, Code);
- if (code <> 1) then
- usage;
- if (lval < 0) or (lval > long(65535)) then
- usage;
- if (ch = 'b') or (ch = 'B') then
- begin
- cinfo^.restart_interval := uInt (lval);
- cinfo^.restart_in_rows := 0; { else prior '-restart n' overrides me }
- end
- else
- begin
- cinfo^.restart_in_rows := int (lval);
- { restart_interval will be computed during startup }
- end;
- end
- else
- if (keymatch(arg, '-sample', 3)) then
- begin
- { Set sampling factors. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- samplearg := ParamStr(argn);
- { Must delay setting sample factors until after we have processed any
- colorspace-determining switches, since jpeg_set_colorspace sets
- default sampling factors. }
-
- end
- else
- if (keymatch(arg, '-scans', 3)) then
- begin
- { Set scan script. }
- {$ifdef C_MULTISCAN_FILES_SUPPORTED}
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- scansarg := ParamStr(argn);
- { We must postpone reading the file in case -progressive appears. }
- {$else}
- WriteLn(output, progname, ': sorry, multi-scan output was not compiled');
- Halt(EXIT_FAILURE);
- {$endif}
-
- end
- else
- if (keymatch(arg, '-smooth', 3)) then
- begin
- { Set input smoothing factor. }
-
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- Val(ParamStr(argn), value, code);
- if (value < 0) or (value > 100)
- or (code <> 0) then
- usage;
- cinfo^.smoothing_factor := value;
-
- end
- else
- if (keymatch(arg, '-targa', 2)) then
- begin
- { Input file is Targa format. }
- is_targa := TRUE;
-
- end
- else
- begin
- usage; { bogus switch }
- end;
- end;
-
- { Post-switch-scanning cleanup }
-
- if (for_real) then
- begin
-
- { Set quantization tables for selected quality. }
- { Some or all may be overridden if -qtables is present. }
- jpeg_set_quality(cinfo, quality, force_baseline);
-
-{$IFDEF EXT_SWITCH}
- if (qtablefile <> '') then { process -qtables if it was present }
- if (not read_quant_tables(cinfo, qtablefile,
- q_scale_factor, force_baseline)) then
- usage;
-
- if (qslotsarg <> '') then { process -qslots if it was present }
- if (not set_quant_slots(cinfo, qslotsarg)) then
- usage;
-
- if (samplearg <> '') then { process -sample if it was present }
- if (not set_sample_factors(cinfo, samplearg)) then
- usage;
-{$ENDIF}
-
-{$ifdef C_PROGRESSIVE_SUPPORTED}
- if (simple_progressive) then { process -progressive; -scans can override }
- jpeg_simple_progression(cinfo);
-{$endif}
-
-{$IFDEF EXT_SWITCH}
-{$ifdef C_MULTISCAN_FILES_SUPPORTED}
- if (scansarg <> '') then { process -scans if it was present }
- if (not read_scan_script(cinfo, scansarg)) then
- usage;
-{$endif}
-{$ENDIF}
- end;
-
- parse_switches := argn; { return index of next arg (file name) }
-end;
-
-
-{ The main program. }
-
-var
- cinfo : jpeg_compress_struct;
- jerr : jpeg_error_mgr;
-{$ifdef PROGRESS_REPORT}
- progress : cdjpeg_progress_mgr;
-{$endif}
- file_index : int;
- src_mgr : cjpeg_source_ptr;
- input_file : FILE;
- output_file : FILE;
- num_scanlines : JDIMENSION;
-var
- argc : int;
-begin
- argc := ParamCount;
-
- progname := ParamStr(0);
-
- { 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, 0, FALSE);
-
-{$ifdef TWO_FILE_COMMANDLINE}
- { Must have either -outfile switch or explicit output file name }
- if (outfilename = '') then
- begin
- if (file_index <> argc-2+1) then
- begin
- WriteLn(output, progname, ': must name one input and one output file');
- usage;
- end;
- outfilename := ParamStr(file_index+1);
- end
- else
- begin
- if (file_index <> argc-1) then
- begin
- WriteLn(output, progname, ': must name one input and one output file');
- usage;
- end;
- end;
-{$else}
- { Unix style: expect zero or one file name }
- if (file_index < argc-1) then
- begin
- WriteLn(output, progname, ': only one input file');
- usage;
- end;
-{$endif} { TWO_FILE_COMMANDLINE }
-
- { Open the input file. }
- if (file_index < argc) then
- begin
- Assign(input_file, ParamStr(file_index));
- {$I-}
- Reset(input_file, 1);
- {$ifdef IOcheck} {$I+} {$endif}
- if (IOresult <> 0) then
- begin
- WriteLn(output, progname, ': can''t open ', ParamStr(file_index));
- Halt(EXIT_FAILURE);
- end;
- end
- else
- begin
- WriteLn(output, progname, ': no input file');
- Halt(EXIT_FAILURE);
- end;
-
- { Open the output file. }
- if (outfilename <> '') then
- begin
- Assign(output_file, outfilename);
- {$I-}
- Reset(output_file, 1);
- {$ifdef IOcheck} {$I+} {$endif}
- if (IOresult = 0) then
- begin
- WriteLn(output, outfilename, ': already exists.');
- close(output_file);
- Halt(EXIT_FAILURE);
- end;
-
- {$I-}
- ReWrite(output_file, 1);
- {$ifdef IOcheck} {$I+} {$endif}
- if (IOresult <> 0) then
- begin
- WriteLn(output, progname, ': can''t create ', outfilename);
- Halt(EXIT_FAILURE);
- end;
- end
- else
- begin
- WriteLn(output, progname, ': no output file');
- Halt(EXIT_FAILURE);
- end;
-
-{$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, 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) do
- begin
- num_scanlines := src_mgr^.get_pixel_rows (@cinfo, src_mgr);
- {void} jpeg_write_scanlines(@cinfo, src_mgr^.buffer, num_scanlines);
- end;
-
- { 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 }
- close(input_file);
- close(output_file);
-
-{$ifdef PROGRESS_REPORT}
- end_progress_monitor(j_common_ptr (@cinfo));
-{$endif}
-
- { All done. }
- if jerr.num_warnings <> 0 then
- Halt(EXIT_WARNING)
- else
- Halt(EXIT_SUCCESS);
-end.
diff --git a/packages/base/pasjpeg/cjpeg.res b/packages/base/pasjpeg/cjpeg.res
deleted file mode 100644
index 40f19ef23c..0000000000
--- a/packages/base/pasjpeg/cjpeg.res
+++ /dev/null
Binary files differ
diff --git a/packages/base/pasjpeg/demo.pas b/packages/base/pasjpeg/demo.pas
deleted file mode 100644
index a675f35f4b..0000000000
--- a/packages/base/pasjpeg/demo.pas
+++ /dev/null
@@ -1,36 +0,0 @@
-Program Demo;
-{ for Delphi3 // same name as project }
-{ Test program - This program may hang your machine !! }
-uses
- test, example;
-var
- fname : string;
-begin
- WriteLn('PASJPEG Demo');
-
- define_image_params;
- write_JPEG_file ('PasJpeg.jpg', 75);
- WriteLn('JPEG encoding OK.');
-
- if ParamCount = 0 then
- begin
- Write('JFIF file name :');
- ReadLn(fname);
- end
- else
- begin
- fname := ParamStr(1);
- WriteLn('JFIF file name :', fname);
- end;
-
- pre_decode;
-
- if not read_JPEG_file (fname) then
- begin
- WriteLn('JPEG decoding error : ', fname);
- Halt(1);
- end;
- post_decode;
-
- WriteLn('JPEG decoding OK.');
-end.
diff --git a/packages/base/pasjpeg/demo.res b/packages/base/pasjpeg/demo.res
deleted file mode 100644
index 459bc4a1a4..0000000000
--- a/packages/base/pasjpeg/demo.res
+++ /dev/null
Binary files differ
diff --git a/packages/base/pasjpeg/djpeg.pas b/packages/base/pasjpeg/djpeg.pas
deleted file mode 100644
index ebfd3d7d28..0000000000
--- a/packages/base/pasjpeg/djpeg.pas
+++ /dev/null
@@ -1,709 +0,0 @@
-Program DJpeg;
-
-
-{ djpeg.c ; Copyright (C) 1991-1997, Thomas G. Lane. }
-
-{ 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. }
-
-{$I jconfig.inc}
-
-
-uses
- jmorecfg,
- jpeglib,
- jerror,
- RdColMap,
- jdeferr,
- jdapimin, jdapistd, jdatasrc,
-{$ifdef BMP_SUPPORTED} wrbmp, {$endif}
-{$ifdef PPM_SUPPORTED} wrppm, {$endif}
-{$ifdef TARGA_SUPPORTED} wrtarga, {$endif}
- jdmarker,
- cdjpeg; { Common decls for cjpeg/djpeg applications }
- { for version message }
-
-
-
-{ 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. }
-
-type
- IMAGE_FORMATS = (
- 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 }
-
-const
- DEFAULT_FMT = FMT_PPM;
-
-var
- requested_fmt : IMAGE_FORMATS;
-
-
-{ 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... }
-
-
-var
- progname, { program name for error messages }
- outfilename : string[127]; { for -outfile switch }
-
-
-{LOCAL}
-procedure usage;
-const
- default_txt : array[boolean] of string[30] = ('', ' (default)');
-{ complain about bad command line }
-begin
- Write (output, 'usage: ', progname, ' [switches] ');
-{$ifdef TWO_FILE_COMMANDLINE}
- WriteLn(output, 'inputfile outputfile');
-{$else}
- WriteLn(output, '[inputfile]');
-{$endif}
-
- WriteLn(output, 'Switches (names may be abbreviated):');
- WriteLn(output, ' -colors N Reduce image to no more than N colors');
- WriteLn(output, ' -fast Fast, low-quality processing');
- WriteLn(output, ' -grayscale Force grayscale output');
-{$ifdef IDCT_SCALING_SUPPORTED}
- WriteLn(output, ' -scale M/N Scale output image by fraction M/N, eg, 1/8');
-{$endif}
-{$ifdef BMP_SUPPORTED}
- WriteLn(output, ' -bmp Select BMP output format (Windows style)',
- default_txt[DEFAULT_FMT = FMT_BMP]);
-{$endif}
-{$ifdef GIF_SUPPORTED}
- WriteLn(output, ' -gif Select GIF output format',
- default_txt[DEFAULT_FMT = FMT_GIF]);
-{$endif}
-{$ifdef BMP_SUPPORTED}
- WriteLn(output, ' -os2 Select BMP output format (OS/2 style)',
- default_txt[DEFAULT_FMT = FMT_OS2]);
-{$endif}
-{$ifdef PPM_SUPPORTED}
- WriteLn(output, ' -pnm Select PBMPLUS (PPM/PGM) output format',
- default_txt[DEFAULT_FMT = FMT_PPM]);
-{$endif}
-{$ifdef RLE_SUPPORTED}
- WriteLn(output, ' -rle Select Utah RLE output format',
- default_txt[DEFAULT_FMT = FMT_RLE]);
-{$endif}
-{$ifdef TARGA_SUPPORTED}
- WriteLn(output, ' -targa Select Targa output format',
- default_txt[DEFAULT_FMT = FMT_TARGA]);
-{$endif}
- WriteLn(output, 'Switches for advanced users:');
-{$ifdef DCT_ISLOW_SUPPORTED}
- WriteLn(output, ' -dct int Use integer DCT method',
- default_txt[JDCT_DEFAULT = JDCT_ISLOW]);
-{$endif}
-{$ifdef DCT_IFAST_SUPPORTED}
- WriteLn(output, ' -dct fast Use fast integer DCT (less accurate)',
- default_txt[JDCT_DEFAULT = JDCT_IFAST]);
-{$endif}
-{$ifdef DCT_FLOAT_SUPPORTED}
- WriteLn(output, ' -dct float Use floating-point DCT method',
- default_txt[JDCT_DEFAULT = JDCT_FLOAT]);
-{$endif}
- WriteLn(output, ' -dither fs Use F-S dithering (default)');
- WriteLn(output, ' -dither none Don''t use dithering in quantization');
- WriteLn(output, ' -dither ordered Use ordered dither (medium speed, quality)');
-{$ifdef QUANT_2PASS_SUPPORTED}
- WriteLn(output, ' -map FILE Map to colors used in named image file');
-{$endif}
- WriteLn(output, ' -nosmooth Don''t use high-quality upsampling');
-{$ifdef QUANT_1PASS_SUPPORTED}
- WriteLn(output, ' -onepass Use 1-pass quantization (fast, low quality)');
-{$endif}
- WriteLn(output, ' -maxmemory N Maximum memory to use (in kbytes)');
- WriteLn(output, ' -outfile name Specify name for output file');
- WriteLn(output, ' -verbose or -debug Emit debug output');
- Halt(EXIT_FAILURE);
-end;
-
-
-{LOCAL}
-function parse_switches (cinfo : j_decompress_ptr;
- last_file_arg_seen : int;
- for_real : boolean) : int;
-{ 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. }
-var
- argn,
- argc : int;
- arg : string;
-var
- value : int;
- code : integer;
-{$ifdef QUANT_2PASS_SUPPORTED} { otherwise can't quantize to supplied map }
-var
- mapfile : file;
-{$endif}
-const
- printed_version : boolean = FALSE;
-var
- lval : long;
- ch : char;
-begin
- { Set up default JPEG parameters. }
- requested_fmt := DEFAULT_FMT; { set default output file format }
- outfilename := '';
- cinfo^.err^.trace_level := 0;
-
- { Scan command line options, adjust parameters }
-
- argn := 0;
- argc := ParamCount;
-
- while argn < argc do
- begin
- Inc(argn);
- arg := ParamStr(argn);
- if (arg[1] <> '-') then
- begin
- { Not a switch, must be a file name argument }
- if (argn <= last_file_arg_seen) then
- begin
- outfilename := ''; { -outfile applies to just one input file }
- continue; { ignore this name if previously processed }
- end;
- break; { else done parsing switches }
- end;
- {Inc(arg); - advance past switch marker character }
-
- if (keymatch(arg, '-bmp', 2)) then
- begin
- { BMP output format. }
- requested_fmt := FMT_BMP;
-
- end
- else
- if (keymatch(arg, '-colors', 2)) or (keymatch(arg, '-colours', 2)) or
- (keymatch(arg, '-quantize', 2)) or (keymatch(arg, '-quantise', 2)) then
- begin { Do color quantization. }
-
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- Val(ParamStr(argn), value, code);
- if code <> 0 then
- usage;
- cinfo^.desired_number_of_colors := value;
- cinfo^.quantize_colors := TRUE;
- end
- else
- if (keymatch(arg, '-dct', 3)) then
- begin { Select IDCT algorithm. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- if (keymatch(ParamStr(argn), 'int', 1)) then
- cinfo^.dct_method := JDCT_ISLOW
- else
- if (keymatch(ParamStr(argn), 'fast', 2)) then
- cinfo^.dct_method := JDCT_IFAST
- else
- if (keymatch(ParamStr(argn), 'float', 2)) then
- cinfo^.dct_method := JDCT_FLOAT
- else
- usage;
- end
- else
- if (keymatch(arg, '-dither', 3)) then
- begin { Select dithering algorithm. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- if (keymatch(ParamStr(argn), 'fs', 2)) then
- cinfo^.dither_mode := JDITHER_FS
- else
- if (keymatch(ParamStr(argn), 'none', 2)) then
- cinfo^.dither_mode := JDITHER_NONE
- else
- if (keymatch(ParamStr(argn), 'ordered', 2)) then
- cinfo^.dither_mode := JDITHER_ORDERED
- else
- usage;
- end
- else
- if (keymatch(arg, '-debug', 2)) or (keymatch(arg, '-verbose', 2)) then
- begin { Enable debug printouts. }
- { On first -d, print version identification }
-
- if (not printed_version) then
- begin
- WriteLn(output, 'PASJPEG Group''s DJPEG, version ',
- JVERSION);
- WriteLn(output, JCOPYRIGHT);
- WriteLn(output, JNOTICE);
- printed_version := TRUE;
- end;
- Inc(cinfo^.err^.trace_level);
- end
- else
- if (keymatch(arg, '-fast', 2)) then
- begin
- { Select recommended processing options for quick-and-dirty output. }
- cinfo^.two_pass_quantize := FALSE;
- cinfo^.dither_mode := JDITHER_ORDERED;
- if (not cinfo^.quantize_colors) then { don't override an earlier -colors }
- cinfo^.desired_number_of_colors := 216;
- cinfo^.dct_method := JDCT_FASTEST;
- cinfo^.do_fancy_upsampling := FALSE;
- end
- else
- if (keymatch(arg, '-gif', 2)) then
- begin { GIF output format. }
- requested_fmt := FMT_GIF;
- end
- else
- if (keymatch(arg, '-grayscale', 3)) or
- (keymatch(arg, '-greyscale',3)) then
- { Force monochrome output. }
- cinfo^.out_color_space := JCS_GRAYSCALE
- else
- if (keymatch(arg, '-map', 4)) then
- begin
- { Quantize to a color map taken from an input file. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- if (for_real) then
- begin { too expensive to do twice! }
-{$ifdef QUANT_2PASS_SUPPORTED} { otherwise can't quantize to supplied map }
- assign(mapfile, ParamStr(argn));
- {$I-}
- reset(mapfile, 1);
- {$IFDEF IoCheck} {$I+} {$ENDIF}
- if (IOresult <> 0) then
- begin
- WriteLn(output, progname, ': can''t open ', ParamStr(argn));
- Halt(EXIT_FAILURE);
- end;
- read_color_map(cinfo, mapfile);
- system.close(mapfile);
- cinfo^.quantize_colors := TRUE;
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end;
- end
- else
- if (keymatch(arg, '-maxmemory', 4)) then
- begin
- { Maximum memory in Kb (or Mb with 'm'). }
-
- ch := 'x';
-
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- arg := ParamStr(argn);
- if (length(arg) > 1) and (arg[length(arg)] in ['m','M']) then
- begin
- ch := arg[length(arg)];
- arg := Copy(arg, 1, Length(arg)-1);
- end;
-
- Val(arg, lval, code);
-
- if (code <> 0) then
- usage;
- if (ch = 'm') or (ch = 'M') then
- lval := lval * long(1000);
- cinfo^.mem^.max_memory_to_use := lval * long(1000);
-
- end
- else
- if (keymatch(arg, '-nosmooth', 4)) then
- begin
- { Suppress fancy upsampling }
- cinfo^.do_fancy_upsampling := FALSE;
-
- end
- else
- if (keymatch(arg, '-onepass', 4)) then
- begin
- { Use fast one-pass quantization. }
- cinfo^.two_pass_quantize := FALSE;
- end
- else
- if (keymatch(arg, '-os2', 4)) then
- begin
- { BMP output format (OS/2 flavor). }
- requested_fmt := FMT_OS2;
- end
- else
- if (keymatch(arg, '-outfile', 5)) then
- begin
- { Set output file name. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- outfilename := ParamStr(argn); { save it away for later use }
- end
- else
- if (keymatch(arg, '-pnm', 2)) or
- (keymatch(arg, '-ppm', 2)) then
- begin
- { PPM/PGM output format. }
- requested_fmt := FMT_PPM;
- end
- else
- if (keymatch(arg, '-rle', 2)) then
- begin
- { RLE output format. }
- requested_fmt := FMT_RLE;
- end
- else
- if (keymatch(arg, '-scale', 2)) then
- begin
- { Scale the output image by a fraction M/N. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- arg := ParamStr(argn);
- Val(copy(arg, 1, Pos('/', arg)-1),
- cinfo^.scale_num, code);
- if code = 0 then
- Val(copy(arg, Pos('/', arg)+1,
- length(arg)-Pos('/', arg)),
- cinfo^.scale_denom, code);
- if code <> 0 then
- usage;
- end
- else
- if (keymatch(arg, '-targa', 2)) then
- begin
- { Targa output format. }
- requested_fmt := FMT_TARGA;
- end
- else
- usage; { bogus switch }
- end;
-
- parse_switches := argn; { return index of next arg (file name) }
-end;
-
-
-{ 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}
-function jpeg_getc (cinfo : j_decompress_ptr) : char;
-{ Read next byte }
-var
- datasrc : jpeg_source_mgr_ptr;
-begin
- datasrc := cinfo^.src;
-
- if (datasrc^.bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer (cinfo)) then
- ERREXIT(j_common_ptr(cinfo), JERR_CANT_SUSPEND);
- end;
- Dec(datasrc^.bytes_in_buffer);
- jpeg_getc := char(GETJOCTET(datasrc^.next_input_byte^));
- Inc(datasrc^.next_input_byte);
-end;
-
-
-{METHODDEF}
-function print_text_marker (cinfo : j_decompress_ptr) : boolean; far;
-const
- LF = #10;
- CR = #13;
-var
- traceit : boolean;
- length : INT32;
- ch : char;
- lastch : char;
-begin
- traceit := (cinfo^.err^.trace_level >= 1);
- lastch := #0;
- length := byte(jpeg_getc(cinfo)) shl 8;
- Inc(length, byte(jpeg_getc(cinfo)));
- Dec(length, 2); { discount the length word itself }
-
- if (traceit) then
- begin
- if (cinfo^.unread_marker = JPEG_COM) then
- WriteLn('Comment, length ', long(length), ';')
- else { assume it is an APPn otherwise }
- WriteLn('APP', cinfo^.unread_marker - JPEG_APP0, ' length ',
- long(length),':');
- end;
-
- while (length > 0) do
- begin
- Dec(length);
- ch := jpeg_getc(cinfo);
- if (traceit) then
- begin
- { 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 = LF) then
- WriteLn(output)
- else
- if (ch = CR) then
- begin
- if (lastch <> LF) then
- WriteLn(output);
- end
- else
- if (ch >= ' ') and (ch <= #127) then
- Write(output, ch)
- else
- WriteLn(output, '\', byte(ch));
- lastch := ch;
- end;
- end;
-
- if (traceit) then
- WriteLn(output);
-
- print_text_marker := TRUE;
-end;
-
-
-{ The main program. }
-
-var
- cinfo : jpeg_decompress_struct;
- jerr : jpeg_error_mgr;
-{$ifdef PROGRESS_REPORT}
- progress : cdjpeg_progress_mgr;
-{$endif}
- file_index : int;
- dest_mgr : djpeg_dest_ptr;
- input_file : FILE;
- output_file : FILE;
- num_scanlines : JDIMENSION;
-var
- argc : int;
-begin
- dest_mgr := NIL;
- argc := ParamCount;
-
- progname := ParamStr(0);
-
- { 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, 0, FALSE);
-
-{$ifdef TWO_FILE_COMMANDLINE}
- { Must have either -outfile switch or explicit output file name }
- if (outfilename = '') then
- begin
- if (file_index <> argc-1) then
- begin
- WriteLn(output, progname, ': must name one input and one output file');
- usage;
- end;
- outfilename := ParamStr(file_index+1);
- end
- else
- begin
- if (file_index <> argc) then
- begin
- WriteLn(output, progname, ': must name one input and one output file');
- usage;
- end;
- end;
-{$else}
- { Unix style: expect zero or one file name }
- if (file_index < argc-1) then
- begin
- WriteLn(output, progname, ': only one input file');
- usage;
- end;
-{$endif} { TWO_FILE_COMMANDLINE }
-
- { Open the input file. }
- if (file_index < argc) then
- begin
- assign(input_file, ParamStr(file_index));
- {$I-}
- Reset(input_file, 1);
- {$I+}
- if (IOresult <> 0) then
- begin
- WriteLn(output, progname, ': can''t open ', ParamStr(file_index));
- Halt(EXIT_FAILURE);
- end;
- end
- else
- begin
- { default input file is stdin }
- Assign(input_file, '');
- Reset(input_file, 1);
- end;
-
- { Open the output file. }
- if (outfilename <> '') then
- begin
- assign(output_file, outfilename);
- {$I-}
- rewrite(output_file, 1);
- {$I+}
- if (IOresult <> 0) then
- begin
- WriteLn(output, progname, ': can''t open ', outfilename);
- Halt(EXIT_FAILURE);
- end;
- end
- else
- begin
- { default output file is stdout }
- assign(output_file, '');
- rewrite(output_file, 1);
- end;
-
-{$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, 0, TRUE);
-
- { Initialize the output module now to let it override any crucial
- option settings (for instance, GIF wants to force color quantization). }
-
- case (requested_fmt) of
-{$ifdef BMP_SUPPORTED}
- FMT_BMP:
- dest_mgr := jinit_write_bmp(@cinfo, FALSE);
- FMT_OS2:
- dest_mgr := jinit_write_bmp(@cinfo, TRUE);
-{$endif}
-{$ifdef GIF_SUPPORTED}
- FMT_GIF:
- dest_mgr := jinit_write_gif(@cinfo);
-{$endif}
-{$ifdef PPM_SUPPORTED}
- FMT_PPM:
- dest_mgr := jinit_write_ppm(@cinfo);
-{$endif}
-{$ifdef RLE_SUPPORTED}
- FMT_RLE:
- dest_mgr := jinit_write_rle(@cinfo);
-{$endif}
-{$ifdef TARGA_SUPPORTED}
- FMT_TARGA:
- dest_mgr := jinit_write_targa(@cinfo);
-{$endif}
- else
- ERREXIT(j_common_ptr(@cinfo), JERR_UNSUPPORTED_FORMAT);
- end;
- 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) do
- begin
- num_scanlines := jpeg_read_scanlines(@cinfo, dest_mgr^.buffer,
- dest_mgr^.buffer_height);
- dest_mgr^.put_pixel_rows (@cinfo, dest_mgr, num_scanlines);
- end;
-
-{$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 }
- system.close(input_file);
- system.close(output_file);
-
-{$ifdef PROGRESS_REPORT}
- end_progress_monitor(j_common_ptr (@cinfo));
-{$endif}
-
- { All done. }
- if jerr.num_warnings <> 0 then
- Halt(EXIT_WARNING)
- else
- Halt(EXIT_SUCCESS);
-end.
diff --git a/packages/base/pasjpeg/djpeg.res b/packages/base/pasjpeg/djpeg.res
deleted file mode 100644
index cd768b4293..0000000000
--- a/packages/base/pasjpeg/djpeg.res
+++ /dev/null
Binary files differ
diff --git a/packages/base/pasjpeg/example.pas b/packages/base/pasjpeg/example.pas
deleted file mode 100644
index c601758e20..0000000000
--- a/packages/base/pasjpeg/example.pas
+++ /dev/null
@@ -1,478 +0,0 @@
-Unit example;
-
-{ 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. }
-
-{ Original: example.c }
-
-Interface
-
-{ 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". }
-
-uses
- jmorecfg, jerror, jpeglib,
- jdatadst, jcparam, jcapimin, jcapistd, jdapimin, jdatasrc, jdapistd,
- test;
-
-
-{ Sample routine for JPEG compression. We assume that the target file name
- and a compression quality factor are passed in. }
-
-{GLOBAL}
-procedure write_JPEG_file (filename : string; quality : int);
-
-{ Sample routine for JPEG decompression. We assume that the source file name
- is passed in. We want to return TRUE on success, FALSE on error. }
-
-{GLOBAL}
-function read_JPEG_file (filename : string) : boolean;
-
-implementation
-
-{$IFOPT I+} {$DEFINE IoCheck} {$ENDIF}
-
-{ <setjmp.h> is used for the optional error recovery mechanism shown in
- the second part of the example. }
-
-
-{******************* 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: }
-
-{$IFDEF TEST}
-{extern}
-var
- image_buffer : JSAMPROW; { Points to large array of R,G,B-order data }
- image_height : int; { Number of rows in image }
- image_width : int; { Number of columns in image }
-
-{$ENDIF}
-
-{ Sample routine for JPEG compression. We assume that the target file name
- and a compression quality factor are passed in. }
-
-{GLOBAL}
-procedure write_JPEG_file (filename : string; quality : int);
-var
- { 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". }
- cinfo : jpeg_compress_struct;
- { 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. }
-
- jerr : jpeg_error_mgr;
- { More stuff }
- outfile : FILE; { target file }
- row_pointer : array[0..0] of JSAMPROW ; { pointer to JSAMPLE row[s] }
- row_stride : int; { physical row width in image buffer }
-begin
- { 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);
- { msg_level that will be displayed. (Nomssi) }
- jerr.trace_level := 3;
- { 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. }
-
- Assign(outfile, filename);
- {$I-}
- ReWrite(outfile, 1);
- {$IFDEF IoCheck} {$I+} {$ENDIF}
- if (IOresult <> 0) then
- begin
- WriteLn(output, 'can''t open ', filename);
- Halt(1);
- end;
- 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) do
- begin
- { 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] := JSAMPROW(@image_buffer^[cinfo.next_scanline * row_stride]);
- {void} jpeg_write_scanlines(@cinfo, JSAMPARRAY(@row_pointer), 1);
- end;
-
- { Step 6: Finish compression }
-
- jpeg_finish_compress(@cinfo);
- { After finish_compress, we can close the output file. }
- system.close(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! }
-end;
-
-
-{ 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.) }
-
-{$IFDEF TEST ---------------------------------------------------------------}
-
-{extern}
-type
- jmp_buf = pointer;
-
- { This routine does the output }
- procedure put_scanline_someplace(buffer : JSAMPROW; row_stride : int);
- forward;
-
- { define an error recovery point. Return 0 when OK }
- function setjmp(setjmp_buffer : jmp_buf) : int;
- forward;
-
- { Return control to the setjmp point }
- procedure longjmp(setjmp_buffer : jmp_buf; flag : int);
- forward;
-
-{$ENDIF --------------------------------------------------------------------}
-
-
-{ Here's the extended error handler struct: }
-type
- my_error_ptr = ^my_error_mgr;
- my_error_mgr = record
- pub : jpeg_error_mgr; { "public" fields }
-
- setjmp_buffer : jmp_buf; { for return to caller }
- end;
-
-
-{ Here's the routine that will replace the standard error_exit method: }
-
-{METHODDEF}
-procedure my_error_exit (cinfo : j_common_ptr); far;
-var
- myerr : my_error_ptr;
-begin
- { cinfo^.err really points to a my_error_mgr struct, so coerce pointer }
- 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);
-end;
-
-
-{ 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}
-function read_JPEG_file (filename : string) : boolean;
-var
- { This struct contains the JPEG decompression parameters and pointers to
- working space (which is allocated as needed by the JPEG library). }
-
- cinfo : jpeg_decompress_struct;
- { 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. }
-
- jerr : my_error_mgr;
- { More stuff }
- infile : FILE; { source file }
- buffer : JSAMPARRAY; { Output row buffer }
- row_stride : int; { physical row width in output buffer }
-begin
-
- { 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. }
-
- Assign(infile, filename);
- {$I-}
- Reset(infile, 1);
- {$IFDEF IoCheck} {$I+} {$ENDIF}
- if (IOresult <> 0) then
- begin
- WriteLn(output, 'can''t open ', filename);
- read_JPEG_file := FALSE;
- exit;
- end;
-
- { 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;
- jerr.pub.trace_level := 3; { I'm debbuging a lot (Nomssi) }
- { Establish the setjmp return context for my_error_exit to use. }
- if (setjmp(jerr.setjmp_buffer)<>0) then
- begin
- { 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. }
- { Nomssi: if we get here, we are in trouble, because e.g. cinfo.mem
- is not guaranted to be NIL }
- jpeg_destroy_decompress(@cinfo);
- system.close(infile);
- read_JPEG_file := FALSE;
- exit;
- end;
-
- { 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() }
-
- 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 }
-
- { the defaults are set by jpeg_read_header(),
- we could choose to do nothing here. }
- cinfo.scale_num := 1;
- cinfo.scale_denom := 1; { 1:1 scaling }
- cinfo.dct_method := JDCT_IFAST;
- cinfo.quantize_colors := TRUE;
- cinfo.two_pass_quantize := TRUE;
- cinfo.dither_mode := JDITHER_FS; { Floyd-Steinberg error diffusion dither }
-
- { Step 5: Start decompressor }
-
- 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) do
- begin
- { 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. }
-
- jpeg_read_scanlines(@cinfo, buffer, 1);
- { Assume put_scanline_someplace wants a pointer and sample count. }
- put_scanline_someplace(buffer^[0], row_stride);
- end;
-
- { Nomssi }
- save_color_map(@cinfo);
-
- { Step 7: Finish decompression }
-
- 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...) }
- system.close(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! }
- read_JPEG_file := TRUE;
-end;
-
-
-{ 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. }
-
-end.
diff --git a/packages/base/pasjpeg/fcache.pas b/packages/base/pasjpeg/fcache.pas
deleted file mode 100644
index 5404209b01..0000000000
--- a/packages/base/pasjpeg/fcache.pas
+++ /dev/null
@@ -1,192 +0,0 @@
-Unit FCache;
-
-interface
-
-
-{ ---------------------- File Cache -------------------------- }
-
-{ implements a simple file cache and mimic C getc and ungetc
- functions. }
-
-const
- BufMemSize = 4096;
- EOF = ^Z;
-
-type
- Cache = record
- active : boolean;
- BildOffset : LongInt;
- Buffer : array[0..BufMemSize-1] of byte;
- FVarPtr : ^file;
- FileOfs : LongInt;
- BufPos : integer;
- BufSize : integer;
- end;
-
-Procedure fc_Init(var fc : Cache;
- var f : file; FPos : LongInt);
-
-Procedure fc_Close(var fc : Cache);
-
-Procedure fc_Done(var fc : Cache;
- var f : file);
-
-Procedure fc_ReadBlock(var fc : Cache);
-
-Function fc_getc(var fc : Cache) : Byte;
-{ Read a byte at the current buffer read-index, increment the buffer
- read-index }
-
-function fc_ungetc (var fc : Cache; ch : char) : Byte;
-{ Read a byte at the current buffer read-index, increment the buffer
- read-index }
-
-procedure fc_WriteTo(var fc : Cache;
- var Buf; Count : Word);
-
-implementation
-
-{$IFDEF USE_DOS}
-uses
- Dos;
-{$ENDIF}
-
-
-Procedure fc_Init(var fc : Cache;
- var f : file; FPos : LongInt);
-begin
- with fc do
- begin
- active := false;
- FVarPtr := @f;
- FileOfs := FPos;
- BufSize := 0;
- BufPos := 0;
- {$IFDEF USE_DOS}
- if TFileRec(f).Mode <> fmClosed then
- {$ENDIF}
- begin
- {$IFOPT I+} {$DEFINE IOCheck} {$I-} {$ENDIF}
- Seek(f, FPos);
- BlockRead(f, Buffer, BufMemSize, BufSize);
- {$IFDEF IOCheck} {$I+} {$ENDIF}
- if (IOResult = 0) and (BufSize <> 0) then
- active := true;
- end;
- end;
-end;
-
-Procedure fc_Done(var fc : Cache;
- var f : file);
-begin
- with fc do
- if FVarPtr = @f then
- begin
- active := false;
- FVarPtr := NIL;
- FileOfs := 0;
- BufSize := 0;
- BufPos := 0;
- end;
-end;
-
-Procedure fc_Close(var fc : Cache);
-begin
- with fc do
- begin
- if Assigned(FVarPtr) then
- Close(FVarPtr^);
- fc_Done(fc, FVarPtr^);
- end;
-end;
-
-Procedure fc_ReadBlock(var fc : Cache);
-Begin
- with fc do
- if active then
- begin
- {$I-}
- Seek(FVarPtr^, FileOfs);
- BlockRead(FVarPtr^, Buffer, BufMemSize, BufSize);
- {$IFDEF IOCheck} {$I+} {$ENDIF}
- BufPos := 0;
- active := (IOResult = 0) and (BufSize <> 0);
- end;
-End;
-
-Function fc_getc(var fc : Cache) : Byte;
-{ Read a byte at the current buffer read-index, increment the buffer
- read-index }
-begin
- with fc do
- if active then
- begin
- fc_GetC := Buffer[BufPos];
- Inc(BufPos);
- if BufPos = BufSize then
- begin
- Inc(FileOfs, BufSize);
- fc_ReadBlock(fc);
- end;
- end
- else
- fc_getc := Byte(EOF);
-end;
-
-function fc_ungetc (var fc : Cache; ch : char) : Byte;
-{ Read a byte at the current buffer read-index, increment the buffer
- read-index }
-begin
- with fc do
- begin
- fc_UnGetC := Byte(EOF);
- if active and (FileOfs > 0) then
- begin
- if BufPos = 0 then
- begin
- Dec(FileOfs);
- fc_ReadBlock(fc);
- end;
-
- if BufPos > 0 then
- begin
- Dec(BufPos);
- fc_UnGetC := Buffer[BufPos];
- end;
- end;
- end;
-end;
-
-procedure fc_WriteTo(var fc : Cache;
- var Buf; Count : Word);
-type
- PByte = ^Byte;
-var
- ChunkSize : Word;
- DestPtr : PByte;
-Begin
- with fc do
- if active then
- begin
- ChunkSize := BufSize - BufPos;
- DestPtr := PByte(@Buf);
- if Count > ChunkSize then
- begin
- { the amount we need to read straddles a buffer boundary,
- we need two or more chunks. This implementation doesn't try
- to read more than two chunks. }
-
- Move(Buffer[BufPos], Buf, ChunkSize);
- Inc(DestPtr, ChunkSize);
- Dec(count, ChunkSize);
- Inc(FileOfs, BufSize);
- fc_ReadBlock(fc);
- end;
- { we are now completely within the buffer boundary,
- do a simple mem move }
- Move(Buffer[BufPos], DestPtr^, count);
- end;
-End;
-
-{ ---------------------- End File Cache -------------------------- }
-end.
diff --git a/packages/base/pasjpeg/fpmake.inc b/packages/base/pasjpeg/fpmake.inc
deleted file mode 100644
index ce8e937885..0000000000
--- a/packages/base/pasjpeg/fpmake.inc
+++ /dev/null
@@ -1,62 +0,0 @@
- StartPackage('pasjpeg');
- {$IF defined(ALLPACKAGES)}
- Directory:='base/pasjpeg';
- {$ELSEIF defined(BASEPACKAGES)}
- Directory:='pasjpeg';
- {$ENDIF}
- Version:='2.0.0';
- T:=Targets.AddUnit('jcapimin');
- T:=Targets.AddUnit('jcapistd');
- T:=Targets.AddUnit('jccoefct');
- T:=Targets.AddUnit('jccolor');
- T:=Targets.AddUnit('jcdctmgr');
- T:=Targets.AddUnit('jchuff');
- T:=Targets.AddUnit('jcinit');
- T:=Targets.AddUnit('jcmainct');
- T:=Targets.AddUnit('jcmarker');
- T:=Targets.AddUnit('jcmaster');
- T:=Targets.AddUnit('jcomapi');
- T:=Targets.AddUnit('jcparam');
- T:=Targets.AddUnit('jcphuff');
- T:=Targets.AddUnit('jcprepct');
- T:=Targets.AddUnit('jcsample');
- T:=Targets.AddUnit('jdapimin');
- T:=Targets.AddUnit('jdapistd');
- T:=Targets.AddUnit('jdatadst');
- T:=Targets.AddUnit('jdatasrc');
- T:=Targets.AddUnit('jdcoefct');
- T:=Targets.AddUnit('jdcolor');
- T:=Targets.AddUnit('jdct');
- T:=Targets.AddUnit('jddctmgr');
- T:=Targets.AddUnit('jdeferr');
- T:=Targets.AddUnit('jdhuff');
- T:=Targets.AddUnit('jdinput');
- T:=Targets.AddUnit('jdmainct');
- T:=Targets.AddUnit('jdmarker');
- T:=Targets.AddUnit('jdmaster');
- T:=Targets.AddUnit('jdmerge');
- T:=Targets.AddUnit('jdphuff');
- T:=Targets.AddUnit('jdpostct');
- T:=Targets.AddUnit('jdsample');
- T:=Targets.AddUnit('jerror');
- T:=Targets.AddUnit('jfdctflt');
- T:=Targets.AddUnit('jfdctfst');
- T:=Targets.AddUnit('jfdctint');
- T:=Targets.AddUnit('jidctflt');
- T:=Targets.AddUnit('jidctfst');
- T:=Targets.AddUnit('jidctint');
- T:=Targets.AddUnit('jidctred');
- T:=Targets.AddUnit('jinclude');
- T:=Targets.AddUnit('jmemmgr');
- T:=Targets.AddUnit('jmemnobs');
- T:=Targets.AddUnit('jmorecfg');
- T:=Targets.AddUnit('jpeglib');
- T:=Targets.AddUnit('jquant1');
- T:=Targets.AddUnit('jquant2');
- T:=Targets.AddUnit('jutils');
- T:=Targets.AddExampleunit('cjpeg');
- T:=Targets.AddExampleunit('demo');
- T:=Targets.AddExampleunit('djpeg');
- T:=Targets.AddExampleunit('jpegtran');
- T:=Targets.AddExampleunit('rdjpgcom');
- EndPackage;
diff --git a/packages/base/pasjpeg/fpmake.pp b/packages/base/pasjpeg/fpmake.pp
deleted file mode 100644
index d4b6178682..0000000000
--- a/packages/base/pasjpeg/fpmake.pp
+++ /dev/null
@@ -1,17 +0,0 @@
-{$mode objfpc}{$H+}
-program fpmake;
-
-uses fpmkunit;
-
-Var
- T : TTarget;
-
-begin
- With Installer do
- begin
- { Base packages }
- {$i fpmake.inc}
- Run;
- end;
-end.
-
diff --git a/packages/base/pasjpeg/jcapimin.pas b/packages/base/pasjpeg/jcapimin.pas
deleted file mode 100644
index 9603513b87..0000000000
--- a/packages/base/pasjpeg/jcapimin.pas
+++ /dev/null
@@ -1,401 +0,0 @@
-Unit JcAPImin;
-{$N+}
-{ This file contains application interface code for the compression half
- of the JPEG library. These are the "minimum" API routines that may be
- needed in either the normal full-compression case or the transcoding-only
- case.
-
- Most of the routines intended to be called directly by an application
- are in this file or in jcapistd.c. But also see jcparam.c for
- parameter-setup helper routines, jcomapi.c for routines shared by
- compression and decompression, and jctrans.c for the transcoding case. }
-
-{ jcapimin.c ; Copyright (C) 1994-1998, Thomas G. Lane. }
-
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jpeglib,
- jcomapi,
- jmemmgr,
- jcmarker;
-
-{ Initialization of JPEG compression objects.
- Nomssi: This is a macro in the original code.
-
- jpeg_create_compress() and jpeg_create_decompress() are the exported
- names that applications should call. These expand to calls on
- jpeg_CreateCompress and jpeg_CreateDecompress with additional information
- passed for version mismatch checking.
- NB: you must set up the error-manager BEFORE calling jpeg_create_xxx. }
-
-procedure jpeg_create_compress(cinfo : j_compress_ptr);
-
-
-{ Initialization of a JPEG compression object.
- The error manager must already be set up (in case memory manager fails). }
-
-{GLOBAL}
-procedure jpeg_CreateCompress (cinfo : j_compress_ptr;
- version : int;
- structsize : size_t);
-
-{ Destruction of a JPEG compression object }
-
-{GLOBAL}
-procedure jpeg_destroy_compress (cinfo : j_compress_ptr);
-
-
-{ Abort processing of a JPEG compression operation,
- but don't destroy the object itself. }
-
-{GLOBAL}
-procedure jpeg_abort_compress (cinfo : j_compress_ptr);
-
-
-{ Forcibly suppress or un-suppress all quantization and Huffman tables.
- Marks all currently defined tables as already written (if suppress)
- or not written (if !suppress). This will control whether they get emitted
- by a subsequent jpeg_start_compress call.
-
- This routine is exported for use by applications that want to produce
- abbreviated JPEG datastreams. It logically belongs in jcparam.c, but
- since it is called by jpeg_start_compress, we put it here --- otherwise
- jcparam.o would be linked whether the application used it or not. }
-
-{GLOBAL}
-procedure jpeg_suppress_tables (cinfo : j_compress_ptr;
- suppress : boolean);
-
-
-{ Finish JPEG compression.
-
- If a multipass operating mode was selected, this may do a great deal of
- work including most of the actual output. }
-
-{GLOBAL}
-procedure jpeg_finish_compress (cinfo : j_compress_ptr);
-
-{ Write a special marker.
- This is only recommended for writing COM or APPn markers.
- Must be called after jpeg_start_compress() and before
- first call to jpeg_write_scanlines() or jpeg_write_raw_data(). }
-
-{GLOBAL}
-procedure jpeg_write_marker (cinfo : j_compress_ptr;
- marker : int;
- dataptr : JOCTETptr;
- datalen : uInt);
-
-{GLOBAL}
-procedure jpeg_write_m_header (cinfo : j_compress_ptr;
- marker : int;
- datalen : uint);
-{GLOBAL}
-procedure jpeg_write_m_byte (cinfo : j_compress_ptr; val : int);
-
-{ Alternate compression function: just write an abbreviated table file.
- Before calling this, all parameters and a data destination must be set up.
-
- To produce a pair of files containing abbreviated tables and abbreviated
- image data, one would proceed as follows:
-
- initialize JPEG object
- set JPEG parameters
- set destination to table file
- jpeg_write_tables(cinfo);
- set destination to image file
- jpeg_start_compress(cinfo, FALSE);
- write data...
- jpeg_finish_compress(cinfo);
-
- jpeg_write_tables has the side effect of marking all tables written
- (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress
- will not re-emit the tables unless it is passed write_all_tables=TRUE. }
-
-
-
-{GLOBAL}
-procedure jpeg_write_tables (cinfo : j_compress_ptr);
-
-implementation
-
-procedure jpeg_create_compress(cinfo : j_compress_ptr);
-begin
- jpeg_CreateCompress(cinfo, JPEG_LIB_VERSION,
- size_t(sizeof(jpeg_compress_struct)));
-end;
-
-{ Initialization of a JPEG compression object.
- The error manager must already be set up (in case memory manager fails). }
-
-{GLOBAL}
-procedure jpeg_CreateCompress (cinfo : j_compress_ptr;
- version : int;
- structsize : size_t);
-var
- i : int;
-var
- err : jpeg_error_mgr_ptr;
- client_data : voidp;
-begin
-
- { Guard against version mismatches between library and caller. }
- cinfo^.mem := NIL; { so jpeg_destroy knows mem mgr not called }
- if (version <> JPEG_LIB_VERSION) then
- ERREXIT2(j_common_ptr(cinfo), JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
- if (structsize <> SIZEOF(jpeg_compress_struct)) then
- ERREXIT2(j_common_ptr(cinfo), JERR_BAD_STRUCT_SIZE,
- int(SIZEOF(jpeg_compress_struct)), int(structsize));
-
- { For debugging purposes, we zero the whole master structure.
- But the application has already set the err pointer, and may have set
- client_data, so we have to save and restore those fields.
- Note: if application hasn't set client_data, tools like Purify may
- complain here. }
-
- err := cinfo^.err;
- client_data := cinfo^.client_data; { ignore Purify complaint here }
- MEMZERO(cinfo, SIZEOF(jpeg_compress_struct));
- cinfo^.err := err;
- cinfo^.is_decompressor := FALSE;
-
- { Initialize a memory manager instance for this object }
- jinit_memory_mgr(j_common_ptr(cinfo));
-
- { Zero out pointers to permanent structures. }
- cinfo^.progress := NIL;
- cinfo^.dest := NIL;
-
- cinfo^.comp_info := NIL;
-
- for i := 0 to pred(NUM_QUANT_TBLS) do
- cinfo^.quant_tbl_ptrs[i] := NIL;
-
- for i := 0 to pred(NUM_HUFF_TBLS) do
- begin
- cinfo^.dc_huff_tbl_ptrs[i] := NIL;
- cinfo^.ac_huff_tbl_ptrs[i] := NIL;
- end;
-
- cinfo^.script_space := NIL;
-
- cinfo^.input_gamma := 1.0; { in case application forgets }
-
- { OK, I'm ready }
- cinfo^.global_state := CSTATE_START;
-end;
-
-
-{ Destruction of a JPEG compression object }
-
-{GLOBAL}
-procedure jpeg_destroy_compress (cinfo : j_compress_ptr);
-begin
- jpeg_destroy(j_common_ptr(cinfo)); { use common routine }
-end;
-
-
-{ Abort processing of a JPEG compression operation,
- but don't destroy the object itself. }
-
-{GLOBAL}
-procedure jpeg_abort_compress (cinfo : j_compress_ptr);
-begin
- jpeg_abort(j_common_ptr(cinfo)); { use common routine }
-end;
-
-
-{ Forcibly suppress or un-suppress all quantization and Huffman tables.
- Marks all currently defined tables as already written (if suppress)
- or not written (if !suppress). This will control whether they get emitted
- by a subsequent jpeg_start_compress call.
-
- This routine is exported for use by applications that want to produce
- abbreviated JPEG datastreams. It logically belongs in jcparam.c, but
- since it is called by jpeg_start_compress, we put it here --- otherwise
- jcparam.o would be linked whether the application used it or not. }
-
-{GLOBAL}
-procedure jpeg_suppress_tables (cinfo : j_compress_ptr;
- suppress : boolean);
-var
- i : int;
- qtbl : JQUANT_TBL_PTR;
- htbl : JHUFF_TBL_PTR;
-begin
- for i := 0 to pred(NUM_QUANT_TBLS) do
- begin
- qtbl := cinfo^.quant_tbl_ptrs[i];
- if (qtbl <> NIL) then
- qtbl^.sent_table := suppress;
- end;
-
- for i := 0 to pred(NUM_HUFF_TBLS) do
- begin
- htbl := cinfo^.dc_huff_tbl_ptrs[i];
- if (htbl <> NIL) then
- htbl^.sent_table := suppress;
- htbl := cinfo^.ac_huff_tbl_ptrs[i];
- if (htbl <> NIL) then
- htbl^.sent_table := suppress;
- end;
-end;
-
-
-{ Finish JPEG compression.
-
- If a multipass operating mode was selected, this may do a great deal of
- work including most of the actual output. }
-
-{GLOBAL}
-procedure jpeg_finish_compress (cinfo : j_compress_ptr);
-var
- iMCU_row : JDIMENSION;
-begin
- if (cinfo^.global_state = CSTATE_SCANNING) or
- (cinfo^.global_state = CSTATE_RAW_OK) then
- begin
- { Terminate first pass }
- if (cinfo^.next_scanline < cinfo^.image_height) then
- ERREXIT(j_common_ptr(cinfo), JERR_TOO_LITTLE_DATA);
- cinfo^.master^.finish_pass (cinfo);
- end
- else
- if (cinfo^.global_state <> CSTATE_WRCOEFS) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- { Perform any remaining passes }
- while (not cinfo^.master^.is_last_pass) do
- begin
- cinfo^.master^.prepare_for_pass (cinfo);
- for iMCU_row := 0 to pred(cinfo^.total_iMCU_rows) do
- begin
- if (cinfo^.progress <> NIL) then
- begin
- cinfo^.progress^.pass_counter := long (iMCU_row);
- cinfo^.progress^.pass_limit := long (cinfo^.total_iMCU_rows);
- cinfo^.progress^.progress_monitor (j_common_ptr(cinfo));
- end;
- { We bypass the main controller and invoke coef controller directly;
- all work is being done from the coefficient buffer. }
-
- if (not cinfo^.coef^.compress_data (cinfo, JSAMPIMAGE(NIL))) then
- ERREXIT(j_common_ptr(cinfo), JERR_CANT_SUSPEND);
- end;
- cinfo^.master^.finish_pass (cinfo);
- end;
- { Write EOI, do final cleanup }
- cinfo^.marker^.write_file_trailer (cinfo);
- cinfo^.dest^.term_destination (cinfo);
- { We can use jpeg_abort to release memory and reset global_state }
- jpeg_abort(j_common_ptr(cinfo));
-end;
-
-
-{ Write a special marker.
- This is only recommended for writing COM or APPn markers.
- Must be called after jpeg_start_compress() and before
- first call to jpeg_write_scanlines() or jpeg_write_raw_data(). }
-
-{GLOBAL}
-procedure jpeg_write_marker (cinfo : j_compress_ptr;
- marker : int;
- dataptr : JOCTETptr;
- datalen : uInt);
-var
- write_marker_byte : procedure(info : j_compress_ptr; val : int);
-begin
- if (cinfo^.next_scanline <> 0) or
- ((cinfo^.global_state <> CSTATE_SCANNING) and
- (cinfo^.global_state <> CSTATE_RAW_OK) and
- (cinfo^.global_state <> CSTATE_WRCOEFS)) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
-
- cinfo^.marker^.write_marker_header (cinfo, marker, datalen);
- write_marker_byte := cinfo^.marker^.write_marker_byte; { copy for speed }
- while (datalen <> 0) do
- begin
- Dec(datalen);
- write_marker_byte (cinfo, dataptr^);
- Inc(dataptr);
- end;
-end;
-
-{ Same, but piecemeal. }
-
-{GLOBAL}
-procedure jpeg_write_m_header (cinfo : j_compress_ptr;
- marker : int;
- datalen : uint);
-begin
- if (cinfo^.next_scanline <> 0) or
- ((cinfo^.global_state <> CSTATE_SCANNING) and
- (cinfo^.global_state <> CSTATE_RAW_OK) and
- (cinfo^.global_state <> CSTATE_WRCOEFS)) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
-
- cinfo^.marker^.write_marker_header (cinfo, marker, datalen);
-end;
-
-{GLOBAL}
-procedure jpeg_write_m_byte (cinfo : j_compress_ptr; val : int);
-begin
- cinfo^.marker^.write_marker_byte (cinfo, val);
-end;
-
-
-{ Alternate compression function: just write an abbreviated table file.
- Before calling this, all parameters and a data destination must be set up.
-
- To produce a pair of files containing abbreviated tables and abbreviated
- image data, one would proceed as follows:
-
- initialize JPEG object
- set JPEG parameters
- set destination to table file
- jpeg_write_tables(cinfo);
- set destination to image file
- jpeg_start_compress(cinfo, FALSE);
- write data...
- jpeg_finish_compress(cinfo);
-
- jpeg_write_tables has the side effect of marking all tables written
- (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress
- will not re-emit the tables unless it is passed write_all_tables=TRUE. }
-
-{GLOBAL}
-procedure jpeg_write_tables (cinfo : j_compress_ptr);
-begin
- if (cinfo^.global_state <> CSTATE_START) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
-
- { (Re)initialize error mgr and destination modules }
- cinfo^.err^.reset_error_mgr (j_common_ptr(cinfo));
- cinfo^.dest^.init_destination (cinfo);
- { Initialize the marker writer ... bit of a crock to do it here. }
- jinit_marker_writer(cinfo);
- { Write them tables! }
- cinfo^.marker^.write_tables_only (cinfo);
- { And clean up. }
- cinfo^.dest^.term_destination (cinfo);
-
- { In library releases up through v6a, we called jpeg_abort() here to free
- any working memory allocated by the destination manager and marker
- writer. Some applications had a problem with that: they allocated space
- of their own from the library memory manager, and didn't want it to go
- away during write_tables. So now we do nothing. This will cause a
- memory leak if an app calls write_tables repeatedly without doing a full
- compression cycle or otherwise resetting the JPEG object. However, that
- seems less bad than unexpectedly freeing memory in the normal case.
- An app that prefers the old behavior can call jpeg_abort for itself after
- each call to jpeg_write_tables(). }
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jcapistd.pas b/packages/base/pasjpeg/jcapistd.pas
deleted file mode 100644
index 422acc4b58..0000000000
--- a/packages/base/pasjpeg/jcapistd.pas
+++ /dev/null
@@ -1,222 +0,0 @@
-Unit JcAPIstd;
-
-{ Original : jcapistd.c ; Copyright (C) 1994-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 application interface code for the compression half
- of the JPEG library. These are the "standard" API routines that are
- used in the normal full-compression case. They are not used by a
- transcoding-only application. Note that if an application links in
- jpeg_start_compress, it will end up linking in the entire compressor.
- We thus must separate this file from jcapimin.c to avoid linking the
- whole compression library into a transcoder. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jpeglib,
- jcapimin, jcinit;
-
-
-
-{ Compression initialization.
- Before calling this, all parameters and a data destination must be set up.
-
- We require a write_all_tables parameter as a failsafe check when writing
- multiple datastreams from the same compression object. Since prior runs
- will have left all the tables marked sent_table=TRUE, a subsequent run
- would emit an abbreviated stream (no tables) by default. This may be what
- is wanted, but for safety's sake it should not be the default behavior:
- programmers should have to make a deliberate choice to emit abbreviated
- images. Therefore the documentation and examples should encourage people
- to pass write_all_tables=TRUE; then it will take active thought to do the
- wrong thing. }
-
-{GLOBAL}
-procedure jpeg_start_compress (cinfo : j_compress_ptr;
- write_all_tables : boolean);
-
-
-{ Write some scanlines of data to the JPEG compressor.
-
- The return value will be the number of lines actually written.
- This should be less than the supplied num_lines only in case that
- the data destination module has requested suspension of the compressor,
- or if more than image_height scanlines are passed in.
-
- Note: we warn about excess calls to jpeg_write_scanlines() since
- this likely signals an application programmer error. However,
- excess scanlines passed in the last valid call are *silently* ignored,
- so that the application need not adjust num_lines for end-of-image
- when using a multiple-scanline buffer. }
-
-{GLOBAL}
-function jpeg_write_scanlines (cinfo : j_compress_ptr;
- scanlines : JSAMPARRAY;
- num_lines : JDIMENSION) : JDIMENSION;
-
-{ Alternate entry point to write raw data.
- Processes exactly one iMCU row per call, unless suspended. }
-
-{GLOBAL}
-function jpeg_write_raw_data (cinfo : j_compress_ptr;
- data : JSAMPIMAGE;
- num_lines : JDIMENSION) : JDIMENSION;
-
-implementation
-
-{ Compression initialization.
- Before calling this, all parameters and a data destination must be set up.
-
- We require a write_all_tables parameter as a failsafe check when writing
- multiple datastreams from the same compression object. Since prior runs
- will have left all the tables marked sent_table=TRUE, a subsequent run
- would emit an abbreviated stream (no tables) by default. This may be what
- is wanted, but for safety's sake it should not be the default behavior:
- programmers should have to make a deliberate choice to emit abbreviated
- images. Therefore the documentation and examples should encourage people
- to pass write_all_tables=TRUE; then it will take active thought to do the
- wrong thing. }
-
-{GLOBAL}
-procedure jpeg_start_compress (cinfo : j_compress_ptr;
- write_all_tables : boolean);
-begin
- if (cinfo^.global_state <> CSTATE_START) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
-
- if (write_all_tables) then
- jpeg_suppress_tables(cinfo, FALSE); { mark all tables to be written }
-
- { (Re)initialize error mgr and destination modules }
- cinfo^.err^.reset_error_mgr (j_common_ptr(cinfo));
- cinfo^.dest^.init_destination (cinfo);
- { Perform master selection of active modules }
- jinit_compress_master(cinfo);
- { Set up for the first pass }
- cinfo^.master^.prepare_for_pass (cinfo);
- { Ready for application to drive first pass through jpeg_write_scanlines
- or jpeg_write_raw_data. }
-
- cinfo^.next_scanline := 0;
- if cinfo^.raw_data_in then
- cinfo^.global_state := CSTATE_RAW_OK
- else
- cinfo^.global_state := CSTATE_SCANNING;
-end;
-
-
-{ Write some scanlines of data to the JPEG compressor.
-
- The return value will be the number of lines actually written.
- This should be less than the supplied num_lines only in case that
- the data destination module has requested suspension of the compressor,
- or if more than image_height scanlines are passed in.
-
- Note: we warn about excess calls to jpeg_write_scanlines() since
- this likely signals an application programmer error. However,
- excess scanlines passed in the last valid call are *silently* ignored,
- so that the application need not adjust num_lines for end-of-image
- when using a multiple-scanline buffer. }
-
-{GLOBAL}
-function jpeg_write_scanlines (cinfo : j_compress_ptr;
- scanlines : JSAMPARRAY;
- num_lines : JDIMENSION) : JDIMENSION;
-var
- row_ctr, rows_left : JDIMENSION;
-begin
- if (cinfo^.global_state <> CSTATE_SCANNING) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- if (cinfo^.next_scanline >= cinfo^.image_height) then
- WARNMS(j_common_ptr(cinfo), JWRN_TOO_MUCH_DATA);
-
- { Call progress monitor hook if present }
- if (cinfo^.progress <> NIL) then
- begin
- cinfo^.progress^.pass_counter := long (cinfo^.next_scanline);
- cinfo^.progress^.pass_limit := long (cinfo^.image_height);
- cinfo^.progress^.progress_monitor (j_common_ptr(cinfo));
- end;
-
- { Give master control module another chance if this is first call to
- jpeg_write_scanlines. This lets output of the frame/scan headers be
- delayed so that application can write COM, etc, markers between
- jpeg_start_compress and jpeg_write_scanlines. }
- if (cinfo^.master^.call_pass_startup) then
- cinfo^.master^.pass_startup (cinfo);
-
- { Ignore any extra scanlines at bottom of image. }
- rows_left := cinfo^.image_height - cinfo^.next_scanline;
- if (num_lines > rows_left) then
- num_lines := rows_left;
-
- row_ctr := 0;
- cinfo^.main^.process_data (cinfo, scanlines, {var}row_ctr, num_lines);
- Inc(cinfo^.next_scanline, row_ctr);
- jpeg_write_scanlines := row_ctr;
-end;
-
-
-{ Alternate entry point to write raw data.
- Processes exactly one iMCU row per call, unless suspended. }
-
-{GLOBAL}
-function jpeg_write_raw_data (cinfo : j_compress_ptr;
- data : JSAMPIMAGE;
- num_lines : JDIMENSION) : JDIMENSION;
-var
- lines_per_iMCU_row : JDIMENSION;
-begin
- if (cinfo^.global_state <> CSTATE_RAW_OK) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- if (cinfo^.next_scanline >= cinfo^.image_height) then
- begin
- WARNMS(j_common_ptr(cinfo), JWRN_TOO_MUCH_DATA);
- jpeg_write_raw_data := 0;
- exit;
- end;
-
- { Call progress monitor hook if present }
- if (cinfo^.progress <> NIL) then
- begin
- cinfo^.progress^.pass_counter := long(cinfo^.next_scanline);
- cinfo^.progress^.pass_limit := long(cinfo^.image_height);
- cinfo^.progress^.progress_monitor (j_common_ptr(cinfo));
- end;
-
- { Give master control module another chance if this is first call to
- jpeg_write_raw_data. This lets output of the frame/scan headers be
- delayed so that application can write COM, etc, markers between
- jpeg_start_compress and jpeg_write_raw_data. }
-
- if (cinfo^.master^.call_pass_startup) then
- cinfo^.master^.pass_startup (cinfo);
-
- { Verify that at least one iMCU row has been passed. }
- lines_per_iMCU_row := cinfo^.max_v_samp_factor * DCTSIZE;
- if (num_lines < lines_per_iMCU_row) then
- ERREXIT(j_common_ptr(cinfo), JERR_BUFFER_SIZE);
-
- { Directly compress the row. }
- if (not cinfo^.coef^.compress_data (cinfo, data)) then
- begin
- { If compressor did not consume the whole row, suspend processing. }
- jpeg_write_raw_data := 0;
- exit;
- end;
-
- { OK, we processed one iMCU row. }
- Inc(cinfo^.next_scanline, lines_per_iMCU_row);
- jpeg_write_raw_data := lines_per_iMCU_row;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jccoefct.pas b/packages/base/pasjpeg/jccoefct.pas
deleted file mode 100644
index 5a0642e004..0000000000
--- a/packages/base/pasjpeg/jccoefct.pas
+++ /dev/null
@@ -1,522 +0,0 @@
-Unit JcCoefCt;
-
-{ This file contains the coefficient buffer controller for compression.
- This controller is the top level of the JPEG compressor proper.
- The coefficient buffer lies between forward-DCT and entropy encoding steps.}
-
-{ Original: jccoefct.c; Copyright (C) 1994-1997, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jerror,
- jdeferr,
- jutils,
- jpeglib;
-
-
-{ We use a full-image coefficient buffer when doing Huffman optimization,
- and also for writing multiple-scan JPEG files. In all cases, the DCT
- step is run during the first pass, and subsequent passes need only read
- the buffered coefficients. }
-{$ifdef ENTROPY_OPT_SUPPORTED}
- {$define FULL_COEF_BUFFER_SUPPORTED}
-{$else}
- {$ifdef C_MULTISCAN_FILES_SUPPORTED}
- {$define FULL_COEF_BUFFER_SUPPORTED}
- {$endif}
-{$endif}
-
-{ Initialize coefficient buffer controller. }
-
-{GLOBAL}
-procedure jinit_c_coef_controller (cinfo : j_compress_ptr;
- need_full_buffer : boolean);
-
-implementation
-
-{ Private buffer controller object }
-
-type
- my_coef_ptr = ^my_coef_controller;
- my_coef_controller = record
- pub : jpeg_c_coef_controller; { public fields }
-
- iMCU_row_num : JDIMENSION; { iMCU row # within image }
- mcu_ctr : JDIMENSION; { counts MCUs processed in current row }
- MCU_vert_offset : int; { counts MCU rows within iMCU row }
- MCU_rows_per_iMCU_row : int; { number of such rows needed }
-
- { For single-pass compression, it's sufficient to buffer just one MCU
- (although this may prove a bit slow in practice). We allocate a
- workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each
- MCU constructed and sent. (On 80x86, the workspace is FAR even though
- it's not really very big; this is to keep the module interfaces unchanged
- when a large coefficient buffer is necessary.)
- In multi-pass modes, this array points to the current MCU's blocks
- within the virtual arrays. }
-
- MCU_buffer : array[0..C_MAX_BLOCKS_IN_MCU-1] of JBLOCKROW;
-
- { In multi-pass modes, we need a virtual block array for each component. }
- whole_image : array[0..MAX_COMPONENTS-1] of jvirt_barray_ptr;
- end;
-
-
-{ Forward declarations }
-{METHODDEF}
-function compress_data(cinfo : j_compress_ptr;
- input_buf : JSAMPIMAGE) : boolean; far; forward;
-{$ifdef FULL_COEF_BUFFER_SUPPORTED
-{METHODDEF}
-function compress_first_pass(cinfo : j_compress_ptr;
- input_buf : JSAMPIMAGE) : boolean; far; forward;
-{METHODDEF}
-function compress_output(cinfo : j_compress_ptr;
- input_buf : JSAMPIMAGE) : boolean; far; forward;
-{$endif}
-
-
-{LOCAL}
-procedure start_iMCU_row (cinfo : j_compress_ptr);
-{ Reset within-iMCU-row counters for a new row }
-var
- coef : my_coef_ptr;
-begin
- coef := my_coef_ptr (cinfo^.coef);
-
- { In an interleaved scan, an MCU row is the same as an iMCU row.
- In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
- But at the bottom of the image, process only what's left. }
- if (cinfo^.comps_in_scan > 1) then
- begin
- coef^.MCU_rows_per_iMCU_row := 1;
- end
- else
- begin
- if (coef^.iMCU_row_num < (cinfo^.total_iMCU_rows-1)) then
- coef^.MCU_rows_per_iMCU_row := cinfo^.cur_comp_info[0]^.v_samp_factor
- else
- coef^.MCU_rows_per_iMCU_row := cinfo^.cur_comp_info[0]^.last_row_height;
- end;
-
- coef^.mcu_ctr := 0;
- coef^.MCU_vert_offset := 0;
-end;
-
-
-{ Initialize for a processing pass. }
-
-{METHODDEF}
-procedure start_pass_coef (cinfo : j_compress_ptr;
- pass_mode : J_BUF_MODE); far;
-var
- coef : my_coef_ptr;
-begin
- coef := my_coef_ptr (cinfo^.coef);
-
- coef^.iMCU_row_num := 0;
- start_iMCU_row(cinfo);
-
- case (pass_mode) of
- JBUF_PASS_THRU:
- begin
- if (coef^.whole_image[0] <> NIL) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
- coef^.pub.compress_data := compress_data;
- end;
-{$ifdef FULL_COEF_BUFFER_SUPPORTED}
- JBUF_SAVE_AND_PASS:
- begin
- if (coef^.whole_image[0] = NIL) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
- coef^.pub.compress_data := compress_first_pass;
- end;
- JBUF_CRANK_DEST:
- begin
- if (coef^.whole_image[0] = NIL) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
- coef^.pub.compress_data := compress_output;
- end;
-{$endif}
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
- end;
-end;
-
-
-{ Process some data in the single-pass case.
- We process the equivalent of one fully interleaved MCU row ("iMCU" row)
- per call, ie, v_samp_factor block rows for each component in the image.
- Returns TRUE if the iMCU row is completed, FALSE if suspended.
-
- NB: input_buf contains a plane for each component in image,
- which we index according to the component's SOF position. }
-
-
-{METHODDEF}
-function compress_data (cinfo : j_compress_ptr;
- input_buf : JSAMPIMAGE) : boolean;
-var
- coef : my_coef_ptr;
- MCU_col_num : JDIMENSION; { index of current MCU within row }
- last_MCU_col : JDIMENSION;
- last_iMCU_row : JDIMENSION;
- blkn, bi, ci, yindex, yoffset, blockcnt : int;
- ypos, xpos : JDIMENSION;
- compptr : jpeg_component_info_ptr;
-begin
- coef := my_coef_ptr (cinfo^.coef);
- last_MCU_col := cinfo^.MCUs_per_row - 1;
- last_iMCU_row := cinfo^.total_iMCU_rows - 1;
-
- { Loop to write as much as one whole iMCU row }
- for yoffset := coef^.MCU_vert_offset to pred(coef^.MCU_rows_per_iMCU_row) do
- begin
- for MCU_col_num := coef^.mcu_ctr to last_MCU_col do
- begin
- { Determine where data comes from in input_buf and do the DCT thing.
- Each call on forward_DCT processes a horizontal row of DCT blocks
- as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
- sequentially. Dummy blocks at the right or bottom edge are filled in
- specially. The data in them does not matter for image reconstruction,
- so we fill them with values that will encode to the smallest amount of
- data, viz: all zeroes in the AC entries, DC entries equal to previous
- block's DC value. (Thanks to Thomas Kinsman for this idea.) }
-
- blkn := 0;
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- if (MCU_col_num < last_MCU_col) then
- blockcnt := compptr^.MCU_width
- else
- blockcnt := compptr^.last_col_width;
- xpos := MCU_col_num * compptr^.MCU_sample_width;
- ypos := yoffset * DCTSIZE; { ypos = (yoffset+yindex) * DCTSIZE }
- for yindex := 0 to pred(compptr^.MCU_height) do
- begin
- if (coef^.iMCU_row_num < last_iMCU_row) or
- (yoffset+yindex < compptr^.last_row_height) then
- begin
- cinfo^.fdct^.forward_DCT (cinfo, compptr,
- input_buf^[compptr^.component_index],
- coef^.MCU_buffer[blkn],
- ypos, xpos, JDIMENSION (blockcnt));
-
- if (blockcnt < compptr^.MCU_width) then
- begin
- { Create some dummy blocks at the right edge of the image. }
- jzero_far({FAR}pointer(coef^.MCU_buffer[blkn + blockcnt]),
- (compptr^.MCU_width - blockcnt) * SIZEOF(JBLOCK));
- for bi := blockcnt to pred(compptr^.MCU_width) do
- begin
- coef^.MCU_buffer[blkn+bi]^[0][0] := coef^.MCU_buffer[blkn+bi-1]^[0][0];
- end;
- end;
- end
- else
- begin
- { Create a row of dummy blocks at the bottom of the image. }
- jzero_far({FAR}pointer(coef^.MCU_buffer[blkn]),
- compptr^.MCU_width * SIZEOF(JBLOCK));
- for bi := 0 to pred(compptr^.MCU_width) do
- begin
- coef^.MCU_buffer[blkn+bi]^[0][0] := coef^.MCU_buffer[blkn-1]^[0][0];
- end;
- end;
- Inc(blkn, compptr^.MCU_width);
- Inc(ypos, DCTSIZE);
- end;
- end;
- { Try to write the MCU. In event of a suspension failure, we will
- re-DCT the MCU on restart (a bit inefficient, could be fixed...) }
-
- if (not cinfo^.entropy^.encode_mcu (cinfo, JBLOCKARRAY(@coef^.MCU_buffer)^)) then
- begin
- { Suspension forced; update state counters and exit }
- coef^.MCU_vert_offset := yoffset;
- coef^.mcu_ctr := MCU_col_num;
- compress_data := FALSE;
- exit;
- end;
- end;
- { Completed an MCU row, but perhaps not an iMCU row }
- coef^.mcu_ctr := 0;
- end;
- { Completed the iMCU row, advance counters for next one }
- Inc(coef^.iMCU_row_num);
- start_iMCU_row(cinfo);
- compress_data := TRUE;
-end;
-
-
-{$ifdef FULL_COEF_BUFFER_SUPPORTED}
-
-{ Process some data in the first pass of a multi-pass case.
- We process the equivalent of one fully interleaved MCU row ("iMCU" row)
- per call, ie, v_samp_factor block rows for each component in the image.
- This amount of data is read from the source buffer, DCT'd and quantized,
- and saved into the virtual arrays. We also generate suitable dummy blocks
- as needed at the right and lower edges. (The dummy blocks are constructed
- in the virtual arrays, which have been padded appropriately.) This makes
- it possible for subsequent passes not to worry about real vs. dummy blocks.
-
- We must also emit the data to the entropy encoder. This is conveniently
- done by calling compress_output() after we've loaded the current strip
- of the virtual arrays.
-
- NB: input_buf contains a plane for each component in image. All
- components are DCT'd and loaded into the virtual arrays in this pass.
- However, it may be that only a subset of the components are emitted to
- the entropy encoder during this first pass; be careful about looking
- at the scan-dependent variables (MCU dimensions, etc). }
-
-{METHODDEF}
-function compress_first_pass (cinfo : j_compress_ptr;
- input_buf : JSAMPIMAGE) : boolean;
-var
- coef : my_coef_ptr;
- last_iMCU_row : JDIMENSION;
- blocks_across, MCUs_across, MCUindex : JDIMENSION;
- bi, ci, h_samp_factor, block_row, block_rows, ndummy : int;
- lastDC : JCOEF;
- compptr : jpeg_component_info_ptr;
- buffer : JBLOCKARRAY;
- thisblockrow, lastblockrow : JBLOCKROW;
-begin
- coef := my_coef_ptr (cinfo^.coef);
- last_iMCU_row := cinfo^.total_iMCU_rows - 1;
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- { Align the virtual buffer for this component. }
- buffer := cinfo^.mem^.access_virt_barray
- (j_common_ptr(cinfo), coef^.whole_image[ci],
- coef^.iMCU_row_num * compptr^.v_samp_factor,
- JDIMENSION (compptr^.v_samp_factor), TRUE);
- { Count non-dummy DCT block rows in this iMCU row. }
- if (coef^.iMCU_row_num < last_iMCU_row) then
- block_rows := compptr^.v_samp_factor
- else
- begin
- { NB: can't use last_row_height here, since may not be set! }
- block_rows := int (compptr^.height_in_blocks mod compptr^.v_samp_factor);
- if (block_rows = 0) then
- block_rows := compptr^.v_samp_factor;
- end;
- 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 (blocks_across mod h_samp_factor);
- if (ndummy > 0) then
- ndummy := h_samp_factor - ndummy;
- { Perform DCT for all non-dummy blocks in this iMCU row. Each call
- on forward_DCT processes a complete horizontal row of DCT blocks. }
-
- for block_row := 0 to pred(block_rows) do
- begin
- thisblockrow := buffer^[block_row];
- cinfo^.fdct^.forward_DCT (cinfo, compptr,
- input_buf^[ci],
- thisblockrow,
- JDIMENSION (block_row * DCTSIZE),
- JDIMENSION (0),
- blocks_across);
- if (ndummy > 0) then
- begin
- { Create dummy blocks at the right edge of the image. }
- Inc(JBLOCK_PTR(thisblockrow), blocks_across); { => first dummy block }
- jzero_far({FAR}pointer(thisblockrow), ndummy * SIZEOF(JBLOCK));
- {lastDC := thisblockrow^[-1][0];}
- { work around Range Checking }
- Dec(JBLOCK_PTR(thisblockrow));
- lastDC := thisblockrow^[0][0];
- Inc(JBLOCK_PTR(thisblockrow));
-
- for bi := 0 to pred(ndummy) do
- begin
- thisblockrow^[bi][0] := lastDC;
- end;
- end;
- end;
- { If at end of image, create dummy block rows as needed.
- The tricky part here is that within each MCU, we want the DC values
- of the dummy blocks to match the last real block's DC value.
- This squeezes a few more bytes out of the resulting file... }
-
- if (coef^.iMCU_row_num = last_iMCU_row) then
- begin
- Inc(blocks_across, ndummy); { include lower right corner }
- MCUs_across := blocks_across div h_samp_factor;
- for block_row := block_rows to pred(compptr^.v_samp_factor) do
- begin
- thisblockrow := buffer^[block_row];
- lastblockrow := buffer^[block_row-1];
- jzero_far({FAR} pointer(thisblockrow),
- size_t(blocks_across * SIZEOF(JBLOCK)));
- for MCUindex := 0 to pred(MCUs_across) do
- begin
- lastDC := lastblockrow^[h_samp_factor-1][0];
- for bi := 0 to pred(h_samp_factor) do
- begin
- thisblockrow^[bi][0] := lastDC;
- end;
- Inc(JBLOCK_PTR(thisblockrow), h_samp_factor); { advance to next MCU in row }
- Inc(JBLOCK_PTR(lastblockrow), h_samp_factor);
- end;
- end;
- end;
- Inc(compptr);
- end;
- { NB: compress_output will increment iMCU_row_num if successful.
- A suspension return will result in redoing all the work above next time.}
-
-
- { Emit data to the entropy encoder, sharing code with subsequent passes }
- compress_first_pass := compress_output(cinfo, input_buf);
-end;
-
-
-{ Process some data in subsequent passes of a multi-pass case.
- We process the equivalent of one fully interleaved MCU row ("iMCU" row)
- per call, ie, v_samp_factor block rows for each component in the scan.
- The data is obtained from the virtual arrays and fed to the entropy coder.
- Returns TRUE if the iMCU row is completed, FALSE if suspended.
-
- NB: input_buf is ignored; it is likely to be a NIL pointer. }
-
-{METHODDEF}
-function compress_output (cinfo : j_compress_ptr;
- input_buf : JSAMPIMAGE) : boolean;
-var
- coef : my_coef_ptr;
- MCU_col_num : JDIMENSION; { index of current MCU within row }
- blkn, ci, xindex, yindex, yoffset : int;
- start_col : JDIMENSION;
- buffer : array[0..MAX_COMPS_IN_SCAN-1] of JBLOCKARRAY;
- buffer_ptr : JBLOCKROW;
- compptr : jpeg_component_info_ptr;
-begin
- coef := my_coef_ptr (cinfo^.coef);
-
- { Align the virtual buffers for the components used in this scan.
- NB: during first pass, this is safe only because the buffers will
- already be aligned properly, so jmemmgr.c won't need to do any I/O. }
-
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- buffer[ci] := cinfo^.mem^.access_virt_barray (
- j_common_ptr(cinfo), coef^.whole_image[compptr^.component_index],
- coef^.iMCU_row_num * compptr^.v_samp_factor,
- JDIMENSION (compptr^.v_samp_factor), FALSE);
- end;
-
- { Loop to process one whole iMCU row }
- for yoffset := coef^.MCU_vert_offset to pred(coef^.MCU_rows_per_iMCU_row) do
- begin
- for MCU_col_num := coef^.mcu_ctr to pred(cinfo^.MCUs_per_row) do
- begin
- { Construct list of pointers to DCT blocks belonging to this MCU }
- blkn := 0; { index of current DCT block within MCU }
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- start_col := MCU_col_num * compptr^.MCU_width;
- for yindex := 0 to pred(compptr^.MCU_height) do
- begin
- buffer_ptr := JBLOCKROW(@ buffer[ci]^[yindex+yoffset]^[start_col]);
- for xindex := 0 to pred(compptr^.MCU_width) do
- begin
- coef^.MCU_buffer[blkn] := buffer_ptr;
- Inc(blkn);
- Inc(JBLOCK_PTR(buffer_ptr));
- end;
- end;
- end;
- { Try to write the MCU. }
- if (not cinfo^.entropy^.encode_mcu (cinfo, coef^.MCU_buffer)) then
- begin
- { Suspension forced; update state counters and exit }
- coef^.MCU_vert_offset := yoffset;
- coef^.mcu_ctr := MCU_col_num;
- compress_output := FALSE;
- exit;
- end;
- end;
- { Completed an MCU row, but perhaps not an iMCU row }
- coef^.mcu_ctr := 0;
- end;
- { Completed the iMCU row, advance counters for next one }
- Inc(coef^.iMCU_row_num);
- start_iMCU_row(cinfo);
- compress_output := TRUE;
-end;
-
-{$endif} { FULL_COEF_BUFFER_SUPPORTED }
-
-
-{ Initialize coefficient buffer controller. }
-
-{GLOBAL}
-procedure jinit_c_coef_controller (cinfo : j_compress_ptr;
- need_full_buffer : boolean);
-var
- coef : my_coef_ptr;
-var
- buffer : JBLOCKROW;
- i : int;
-var
- ci : int;
- compptr : jpeg_component_info_ptr;
-begin
- coef := my_coef_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_coef_controller)) );
- cinfo^.coef := jpeg_c_coef_controller_ptr(coef);
- coef^.pub.start_pass := start_pass_coef;
-
- { Create the coefficient buffer. }
- if (need_full_buffer) then
- begin
-{$ifdef FULL_COEF_BUFFER_SUPPORTED}
- { Allocate a full-image virtual array for each component, }
- { padded to a multiple of samp_factor DCT blocks in each direction. }
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- coef^.whole_image[ci] := cinfo^.mem^.request_virt_barray
- (j_common_ptr(cinfo), 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));
- Inc(compptr);
- end;
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
-{$endif}
- end
- else
- begin
- { We only need a single-MCU buffer. }
- buffer := JBLOCKROW (
- cinfo^.mem^.alloc_large (j_common_ptr(cinfo), JPOOL_IMAGE,
- C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)) );
- for i := 0 to pred(C_MAX_BLOCKS_IN_MCU) do
- begin
- coef^.MCU_buffer[i] := JBLOCKROW(@ buffer^[i]);
- end;
- coef^.whole_image[0] := NIL; { flag for no virtual arrays }
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jccolor.pas b/packages/base/pasjpeg/jccolor.pas
deleted file mode 100644
index 3c0b39c756..0000000000
--- a/packages/base/pasjpeg/jccolor.pas
+++ /dev/null
@@ -1,529 +0,0 @@
-Unit JcColor;
-
-{ This file contains input colorspace conversion routines. }
-
-{ Original : jccolor.c ; Copyright (C) 1991-1996, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jpeglib;
-
-{ Module initialization routine for input colorspace conversion. }
-
-{GLOBAL}
-procedure jinit_color_converter (cinfo : j_compress_ptr);
-
-implementation
-
-{ Private subobject }
-type
- jTInt32 = 0..Pred(MaxInt div SizeOf(INT32));
- INT32_FIELD = array[jTInt32] of INT32;
- INT32_FIELD_PTR = ^INT32_FIELD;
-
-type
- my_cconvert_ptr = ^my_color_converter;
- my_color_converter = record
- pub : jpeg_color_converter; { public fields }
-
- { Private state for RGB -> YCC conversion }
- rgb_ycc_tab : INT32_FIELD_PTR; { => table for RGB to YCbCr conversion }
- end; {my_color_converter;}
-
-
-{*************** RGB -> YCbCr conversion: most common case *************}
-
-{
- YCbCr is defined per CCIR 601-1, except that Cb and Cr are
- normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
- The conversion equations to be implemented are therefore
- Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
- Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
- Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
- (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
- Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
- rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
- negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
- were not represented exactly. Now we sacrifice exact representation of
- maximum red and maximum blue in order to get exact grayscales.
-
- To avoid floating-point arithmetic, we represent the fractional constants
- as integers scaled up by 2^16 (about 4 digits precision); we have to divide
- the products by 2^16, with appropriate rounding, to get the correct answer.
-
- For even more speed, we avoid doing any multiplications in the inner loop
- by precalculating the constants times R,G,B for all possible values.
- For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
- for 12-bit samples it is still acceptable. It's not very reasonable for
- 16-bit samples, but if you want lossless storage you shouldn't be changing
- colorspace anyway.
- The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
- in the tables to save adding them separately in the inner loop. }
-const
- SCALEBITS = 16; { speediest right-shift on some machines }
- CBCR_OFFSET = INT32(CENTERJSAMPLE shl SCALEBITS);
- ONE_HALF = INT32(1) shl (SCALEBITS-1);
-
-
-{ We allocate one big table and divide it up into eight parts, instead of
- doing eight alloc_small requests. This lets us use a single table base
- address, which can be held in a register in the inner loops on many
- machines (more than can hold all eight addresses, anyway). }
-
- R_Y_OFF = 0; { offset to R => Y section }
- G_Y_OFF = 1*(MAXJSAMPLE+1); { offset to G => Y section }
- B_Y_OFF = 2*(MAXJSAMPLE+1); { etc. }
- R_CB_OFF = 3*(MAXJSAMPLE+1);
- G_CB_OFF = 4*(MAXJSAMPLE+1);
- B_CB_OFF = 5*(MAXJSAMPLE+1);
- R_CR_OFF = B_CB_OFF; { B=>Cb, R=>Cr are the same }
- G_CR_OFF = 6*(MAXJSAMPLE+1);
- B_CR_OFF = 7*(MAXJSAMPLE+1);
- TABLE_SIZE = 8*(MAXJSAMPLE+1);
-
-
-{ Initialize for RGB->YCC colorspace conversion. }
-
-{METHODDEF}
-procedure rgb_ycc_start (cinfo : j_compress_ptr); far;
-const
- FIX_0_29900 = INT32(Round (0.29900 * (1 shl SCALEBITS)) );
- FIX_0_58700 = INT32(Round (0.58700 * (1 shl SCALEBITS)) );
- FIX_0_11400 = INT32(Round (0.11400 * (1 shl SCALEBITS)) );
- FIX_0_16874 = INT32(Round (0.16874 * (1 shl SCALEBITS)) );
- FIX_0_33126 = INT32(Round (0.33126 * (1 shl SCALEBITS)) );
- FIX_0_50000 = INT32(Round (0.50000 * (1 shl SCALEBITS)) );
- FIX_0_41869 = INT32(Round (0.41869 * (1 shl SCALEBITS)) );
- FIX_0_08131 = INT32(Round (0.08131 * (1 shl SCALEBITS)) );
-var
- cconvert : my_cconvert_ptr;
- rgb_ycc_tab : INT32_FIELD_PTR;
- i : INT32;
-begin
- cconvert := my_cconvert_ptr (cinfo^.cconvert);
-
- { Allocate and fill in the conversion tables. }
- rgb_ycc_tab := INT32_FIELD_PTR(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- (TABLE_SIZE * SIZEOF(INT32))) );
- cconvert^.rgb_ycc_tab := rgb_ycc_tab;
-
- for i := 0 to MAXJSAMPLE do
- begin
- rgb_ycc_tab^[i+R_Y_OFF] := FIX_0_29900 * i;
- rgb_ycc_tab^[i+G_Y_OFF] := FIX_0_58700 * i;
- rgb_ycc_tab^[i+B_Y_OFF] := FIX_0_11400 * i + ONE_HALF;
- rgb_ycc_tab^[i+R_CB_OFF] := (-FIX_0_16874) * i;
- rgb_ycc_tab^[i+G_CB_OFF] := (-FIX_0_33126) * i;
- { We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
- This ensures that the maximum output will round to MAXJSAMPLE
- not MAXJSAMPLE+1, and thus that we don't have to range-limit. }
-
- rgb_ycc_tab^[i+B_CB_OFF] := FIX_0_50000 * i + CBCR_OFFSET + ONE_HALF-1;
-{ B=>Cb and R=>Cr tables are the same
- rgb_ycc_tab^[i+R_CR_OFF] := FIX_0_50000 * i + CBCR_OFFSET + ONE_HALF-1;
-}
- rgb_ycc_tab^[i+G_CR_OFF] := (-FIX_0_41869) * i;
- rgb_ycc_tab^[i+B_CR_OFF] := (-FIX_0_08131) * i;
- end;
-end;
-
-
-{ Convert some rows of samples to the JPEG colorspace.
-
- Note that we change from the application's interleaved-pixel format
- to our internal noninterleaved, one-plane-per-component format.
- The input buffer is therefore three times as wide as the output buffer.
-
- A starting row offset is provided only for the output buffer. The caller
- can easily adjust the passed input_buf value to accommodate any row
- offset required on that side. }
-
-{METHODDEF}
-procedure rgb_ycc_convert (cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPIMAGE;
- output_row : JDIMENSION;
- num_rows : int); far;
-var
- cconvert : my_cconvert_ptr;
- {register} r, g, b : int;
- {register} ctab : INT32_FIELD_PTR;
- {register} inptr : JSAMPROW;
- {register} outptr0, outptr1, outptr2 : JSAMPROW;
- {register} col : JDIMENSION;
- num_cols : JDIMENSION;
-begin
- cconvert := my_cconvert_ptr (cinfo^.cconvert);
- ctab := cconvert^.rgb_ycc_tab;
- num_cols := cinfo^.image_width;
-
- while (num_rows > 0) do
- begin
- Dec(num_rows);
- inptr := input_buf^[0];
- Inc(JSAMPROW_PTR(input_buf));
- outptr0 := output_buf^[0]^[output_row];
- outptr1 := output_buf^[1]^[output_row];
- outptr2 := output_buf^[2]^[output_row];
- Inc(output_row);
- for col := 0 to pred(num_cols) do
- begin
- r := GETJSAMPLE(inptr^[RGB_RED]);
- g := GETJSAMPLE(inptr^[RGB_GREEN]);
- b := GETJSAMPLE(inptr^[RGB_BLUE]);
- Inc(JSAMPLE_PTR(inptr), RGB_PIXELSIZE);
- { If the inputs are 0..MAXJSAMPLE, the outputs of these equations
- must be too; we do not need an explicit range-limiting operation.
- Hence the value being shifted is never negative, and we don't
- need the general RIGHT_SHIFT macro. }
-
- { Y }
- outptr0^[col] := JSAMPLE(
- ((ctab^[r+R_Y_OFF] + ctab^[g+G_Y_OFF] + ctab^[b+B_Y_OFF])
- shr SCALEBITS) );
- { Cb }
- outptr1^[col] := JSAMPLE(
- ((ctab^[r+R_CB_OFF] + ctab^[g+G_CB_OFF] + ctab^[b+B_CB_OFF])
- shr SCALEBITS) );
- { Cr }
- outptr2^[col] := JSAMPLE(
- ((ctab^[r+R_CR_OFF] + ctab^[g+G_CR_OFF] + ctab^[b+B_CR_OFF])
- shr SCALEBITS) );
- end;
- end;
-end;
-
-
-{*************** Cases other than RGB -> YCbCr *************}
-
-
-{ Convert some rows of samples to the JPEG colorspace.
- This version handles RGB -> grayscale conversion, which is the same
- as the RGB -> Y portion of RGB -> YCbCr.
- We assume rgb_ycc_start has been called (we only use the Y tables). }
-
-{METHODDEF}
-procedure rgb_gray_convert (cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPIMAGE;
- output_row : JDIMENSION;
- num_rows : int); far;
-var
- cconvert : my_cconvert_ptr;
- {register} r, g, b : int;
- {register} ctab :INT32_FIELD_PTR;
- {register} inptr : JSAMPROW;
- {register} outptr : JSAMPROW;
- {register} col : JDIMENSION;
- num_cols : JDIMENSION;
-begin
- cconvert := my_cconvert_ptr (cinfo^.cconvert);
- ctab := cconvert^.rgb_ycc_tab;
- num_cols := cinfo^.image_width;
-
- while (num_rows > 0) do
- begin
- Dec(num_rows);
- inptr := input_buf^[0];
- Inc(JSAMPROW_PTR(input_buf));
- outptr := output_buf^[0]^[output_row];
- Inc(output_row);
- for col := 0 to pred(num_cols) do
- begin
- r := GETJSAMPLE(inptr^[RGB_RED]);
- g := GETJSAMPLE(inptr^[RGB_GREEN]);
- b := GETJSAMPLE(inptr^[RGB_BLUE]);
- Inc(JSAMPLE_PTR(inptr), RGB_PIXELSIZE);
- { Y }
- outptr^[col] := JSAMPLE (
- ((ctab^[r+R_Y_OFF] + ctab^[g+G_Y_OFF] + ctab^[b+B_Y_OFF])
- shr SCALEBITS) );
- end;
- end;
-end;
-
-
-{ Convert some rows of samples to the JPEG colorspace.
- This version handles Adobe-style CMYK -> YCCK conversion,
- where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
- conversion as above, while passing K (black) unchanged.
- We assume rgb_ycc_start has been called. }
-
-{METHODDEF}
-procedure cmyk_ycck_convert (cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPIMAGE;
- output_row : JDIMENSION;
- num_rows : int); far;
-var
- cconvert : my_cconvert_ptr;
- {register} r, g, b : int;
- {register} ctab : INT32_FIELD_PTR;
- {register} inptr : JSAMPROW;
- {register} outptr0, outptr1, outptr2, outptr3 : JSAMPROW;
- {register} col : JDIMENSION;
- num_cols : JDIMENSION;
-begin
- cconvert := my_cconvert_ptr (cinfo^.cconvert);
- ctab := cconvert^.rgb_ycc_tab;
- num_cols := cinfo^.image_width;
-
- while (num_rows > 0) do
- begin
- Dec(num_rows);
- inptr := input_buf^[0];
- Inc(JSAMPROW_PTR(input_buf));
- outptr0 := output_buf^[0]^[output_row];
- outptr1 := output_buf^[1]^[output_row];
- outptr2 := output_buf^[2]^[output_row];
- outptr3 := output_buf^[3]^[output_row];
- Inc(output_row);
- for col := 0 to pred(num_cols) do
- begin
- r := MAXJSAMPLE - GETJSAMPLE(inptr^[0]);
- g := MAXJSAMPLE - GETJSAMPLE(inptr^[1]);
- b := MAXJSAMPLE - GETJSAMPLE(inptr^[2]);
- { K passes through as-is }
- outptr3^[col] := inptr^[3]; { don't need GETJSAMPLE here }
- Inc(JSAMPLE_PTR(inptr), 4);
- { If the inputs are 0..MAXJSAMPLE, the outputs of these equations
- must be too; we do not need an explicit range-limiting operation.
- Hence the value being shifted is never negative, and we don't
- need the general RIGHT_SHIFT macro. }
-
- { Y }
- outptr0^[col] := JSAMPLE (
- ((ctab^[r+R_Y_OFF] + ctab^[g+G_Y_OFF] + ctab^[b+B_Y_OFF])
- shr SCALEBITS) );
- { Cb }
- outptr1^[col] := JSAMPLE(
- ((ctab^[r+R_CB_OFF] + ctab^[g+G_CB_OFF] + ctab^[b+B_CB_OFF])
- shr SCALEBITS) );
- { Cr }
- outptr2^[col] := JSAMPLE (
- ((ctab^[r+R_CR_OFF] + ctab^[g+G_CR_OFF] + ctab^[b+B_CR_OFF])
- shr SCALEBITS) );
- end;
- end;
-end;
-
-
-{ Convert some rows of samples to the JPEG colorspace.
- This version handles grayscale output with no conversion.
- The source can be either plain grayscale or YCbCr (since Y = gray). }
-
-{METHODDEF}
-procedure grayscale_convert (cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPIMAGE;
- output_row : JDIMENSION;
- num_rows: int); far;
-var
- {register} inptr : JSAMPROW;
- {register} outptr : JSAMPROW;
- {register} col : JDIMENSION;
- num_cols :JDIMENSION;
- instride : int;
-begin
- num_cols := cinfo^.image_width;
- instride := cinfo^.input_components;
-
- while (num_rows > 0) do
- begin
- Dec(num_rows);
- inptr := input_buf^[0];
- Inc(JSAMPROW_PTR(input_buf));
- outptr := output_buf^[0]^[output_row];
- Inc(output_row);
- for col := 0 to pred(num_cols) do
- begin
- outptr^[col] := inptr^[0]; { don't need GETJSAMPLE() here }
- Inc(JSAMPLE_PTR(inptr), instride);
- end;
- end;
-end;
-
-
-{ Convert some rows of samples to the JPEG colorspace.
- This version handles multi-component colorspaces without conversion.
- We assume input_components = num_components. }
-
-{METHODDEF}
-procedure null_convert (cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPIMAGE;
- output_row : JDIMENSION;
- num_rows : int); far;
-var
- {register} inptr : JSAMPROW;
- {register} outptr : JSAMPROW;
- {register} col : JDIMENSION;
- {register} ci : int;
- nc : int;
- num_cols : JDIMENSION;
-begin
- nc := cinfo^.num_components;
- num_cols := cinfo^.image_width;
-
- while (num_rows > 0) do
- begin
- Dec(num_rows);
- { It seems fastest to make a separate pass for each component. }
- for ci := 0 to pred(nc) do
- begin
- inptr := input_buf^[0];
- outptr := output_buf^[ci]^[output_row];
- for col := 0 to pred(num_cols) do
- begin
- outptr^[col] := inptr^[ci]; { don't need GETJSAMPLE() here }
- Inc(JSAMPLE_PTR(inptr), nc);
- end;
- end;
- Inc(JSAMPROW_PTR(input_buf));
- Inc(output_row);
- end;
-end;
-
-
-{ Empty method for start_pass. }
-
-{METHODDEF}
-procedure null_method (cinfo : j_compress_ptr); far;
-begin
- { no work needed }
-end;
-
-
-{ Module initialization routine for input colorspace conversion. }
-
-{GLOBAL}
-procedure jinit_color_converter (cinfo : j_compress_ptr);
-var
- cconvert : my_cconvert_ptr;
-begin
- cconvert := my_cconvert_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_color_converter)) );
- cinfo^.cconvert := jpeg_color_converter_ptr(cconvert);
- { set start_pass to null method until we find out differently }
- cconvert^.pub.start_pass := null_method;
-
- { Make sure input_components agrees with in_color_space }
- case (cinfo^.in_color_space) of
- JCS_GRAYSCALE:
- if (cinfo^.input_components <> 1) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_IN_COLORSPACE);
-
-{$ifdef RGB_PIXELSIZE <> 3}
- JCS_RGB:
- if (cinfo^.input_components <> RGB_PIXELSIZE) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_IN_COLORSPACE);
-{$else} { share code with YCbCr }
- JCS_RGB,
-{$endif}
- JCS_YCbCr:
- if (cinfo^.input_components <> 3) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_IN_COLORSPACE);
-
- JCS_CMYK,
- JCS_YCCK:
- if (cinfo^.input_components <> 4) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_IN_COLORSPACE);
-
- else { JCS_UNKNOWN can be anything }
- if (cinfo^.input_components < 1) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_IN_COLORSPACE);
- end;
-
- { Check num_components, set conversion method based on requested space }
- case (cinfo^.jpeg_color_space) of
- JCS_GRAYSCALE:
- begin
- if (cinfo^.num_components <> 1) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
- if (cinfo^.in_color_space = JCS_GRAYSCALE) then
- cconvert^.pub.color_convert := grayscale_convert
- else
- if (cinfo^.in_color_space = JCS_RGB) then
- begin
- cconvert^.pub.start_pass := rgb_ycc_start;
- cconvert^.pub.color_convert := rgb_gray_convert;
- end
- else
- if (cinfo^.in_color_space = JCS_YCbCr) then
- cconvert^.pub.color_convert := grayscale_convert
- else
- ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
- end;
-
- JCS_RGB:
- begin
- if (cinfo^.num_components <> 3) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
- if (cinfo^.in_color_space = JCS_RGB) and (RGB_PIXELSIZE = 3) then
- cconvert^.pub.color_convert := null_convert
- else
- ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
- end;
-
- JCS_YCbCr:
- begin
- if (cinfo^.num_components <> 3) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
- if (cinfo^.in_color_space = JCS_RGB) then
- begin
- cconvert^.pub.start_pass := rgb_ycc_start;
- cconvert^.pub.color_convert := rgb_ycc_convert;
- end
- else
- if (cinfo^.in_color_space = JCS_YCbCr) then
- cconvert^.pub.color_convert := null_convert
- else
- ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
- end;
-
- JCS_CMYK:
- begin
- if (cinfo^.num_components <> 4) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
- if (cinfo^.in_color_space = JCS_CMYK) then
- cconvert^.pub.color_convert := null_convert
- else
- ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
- end;
-
- JCS_YCCK:
- begin
- if (cinfo^.num_components <> 4) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
- if (cinfo^.in_color_space = JCS_CMYK) then
- begin
- cconvert^.pub.start_pass := rgb_ycc_start;
- cconvert^.pub.color_convert := cmyk_ycck_convert;
- end
- else
- if (cinfo^.in_color_space = JCS_YCCK) then
- cconvert^.pub.color_convert := null_convert
- else
- ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
- end;
-
- else { allow null conversion of JCS_UNKNOWN }
- begin
- if (cinfo^.jpeg_color_space <> cinfo^.in_color_space) or
- (cinfo^.num_components <> cinfo^.input_components) then
- ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
- cconvert^.pub.color_convert := null_convert;
- end;
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jcdctmgr.pas b/packages/base/pasjpeg/jcdctmgr.pas
deleted file mode 100644
index a4aedac73f..0000000000
--- a/packages/base/pasjpeg/jcdctmgr.pas
+++ /dev/null
@@ -1,514 +0,0 @@
-Unit JcDCTmgr;
-
-{ Original : jcdctmgr.c ; Copyright (C) 1994-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 the forward-DCT management logic.
- This code selects a particular DCT implementation to be used,
- and it performs related housekeeping chores including coefficient
- quantization. }
-
-interface
-
-{$N+}
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jpeglib,
- jdct, { Private declarations for DCT subsystem }
- jfdctint, jfdctfst, jfdctflt;
-
-{ Initialize FDCT manager. }
-
-{GLOBAL}
-procedure jinit_forward_dct (cinfo : j_compress_ptr);
-
-implementation
-
-
-{ Private subobject for this module }
-
-type
- my_fdct_ptr = ^my_fdct_controller;
- my_fdct_controller = record
- pub : jpeg_forward_dct; { public fields }
-
- { Pointer to the DCT routine actually in use }
- do_dct : forward_DCT_method_ptr;
-
- { The actual post-DCT divisors --- not identical to the quant table
- entries, because of scaling (especially for an unnormalized DCT).
- Each table is given in normal array order. }
-
- divisors : array[0..NUM_QUANT_TBLS-1] of DCTELEM_FIELD_PTR;
-
- {$ifdef DCT_FLOAT_SUPPORTED}
- { Same as above for the floating-point case. }
- do_float_dct : float_DCT_method_ptr;
- float_divisors : array[0..NUM_QUANT_TBLS-1] of FAST_FLOAT_FIELD_PTR;
- {$endif}
- end;
-
-
-{ Initialize for a processing pass.
- Verify that all referenced Q-tables are present, and set up
- the divisor table for each one.
- In the current implementation, DCT of all components is done during
- the first pass, even if only some components will be output in the
- first scan. Hence all components should be examined here. }
-
-{METHODDEF}
-procedure start_pass_fdctmgr (cinfo : j_compress_ptr); far;
-var
- fdct : my_fdct_ptr;
- ci, qtblno, i : int;
- compptr : jpeg_component_info_ptr;
- qtbl : JQUANT_TBL_PTR;
- dtbl : DCTELEM_FIELD_PTR;
-{$ifdef DCT_IFAST_SUPPORTED}
-const
- CONST_BITS = 14;
- aanscales : array[0..DCTSIZE2-1] of INT16 =
- ({ precomputed values scaled up by 14 bits }
- 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
- 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
- 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
- 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
- 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
- 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
- 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
- 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247);
- {SHIFT_TEMPS}
-
- { Descale and correctly round an INT32 value that's scaled by N bits.
- We assume RIGHT_SHIFT rounds towards minus infinity, so adding
- the fudge factor is correct for either sign of X. }
-
- function DESCALE(x : INT32; n : int) : INT32;
- var
- shift_temp : INT32;
- begin
- shift_temp := x + (INT32(1) shl (n-1));
- {$ifdef RIGHT_SHIFT_IS_UNSIGNED}
- if shift_temp < 0 then
- Descale := (shift_temp shr n) or ((not INT32(0)) shl (32-n))
- else
- {$endif}
- Descale := (shift_temp shr n);
- end;
-
-{$endif}
-{$ifdef DCT_FLOAT_SUPPORTED}
-var
- fdtbl : FAST_FLOAT_FIELD_PTR;
- row, col : int;
-const
- aanscalefactor : array[0..DCTSIZE-1] of double =
- (1.0, 1.387039845, 1.306562965, 1.175875602,
- 1.0, 0.785694958, 0.541196100, 0.275899379);
-{$endif}
-begin
- fdct := my_fdct_ptr (cinfo^.fdct);
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- qtblno := compptr^.quant_tbl_no;
- { Make sure specified quantization table is present }
- if (qtblno < 0) or (qtblno >= NUM_QUANT_TBLS) or
- (cinfo^.quant_tbl_ptrs[qtblno] = NIL) then
- ERREXIT1(j_common_ptr(cinfo), JERR_NO_QUANT_TABLE, qtblno);
- qtbl := cinfo^.quant_tbl_ptrs[qtblno];
- { Compute divisors for this quant table }
- { We may do this more than once for same table, but it's not a big deal }
- case (cinfo^.dct_method) of
-{$ifdef DCT_ISLOW_SUPPORTED}
- JDCT_ISLOW:
- begin
- { For LL&M IDCT method, divisors are equal to raw quantization
- coefficients multiplied by 8 (to counteract scaling). }
-
- if (fdct^.divisors[qtblno] = NIL) then
- begin
- fdct^.divisors[qtblno] := DCTELEM_FIELD_PTR(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- DCTSIZE2 * SIZEOF(DCTELEM)) );
- end;
- dtbl := fdct^.divisors[qtblno];
- for i := 0 to pred(DCTSIZE2) do
- begin
- dtbl^[i] := (DCTELEM(qtbl^.quantval[i])) shl 3;
- end;
- end;
-{$endif}
-{$ifdef DCT_IFAST_SUPPORTED}
- JDCT_IFAST:
- begin
- { For AA&N IDCT method, divisors are equal to quantization
- coefficients scaled by scalefactor[row]*scalefactor[col], where
- scalefactor[0] := 1
- scalefactor[k] := cos(k*PI/16) * sqrt(2) for k=1..7
- We apply a further scale factor of 8. }
-
-
- if (fdct^.divisors[qtblno] = NIL) then
- begin
- fdct^.divisors[qtblno] := DCTELEM_FIELD_PTR(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- DCTSIZE2 * SIZEOF(DCTELEM)) );
- end;
- dtbl := fdct^.divisors[qtblno];
- for i := 0 to pred(DCTSIZE2) do
- begin
- dtbl^[i] := DCTELEM(
- {MULTIPLY16V16}
- DESCALE( INT32(qtbl^.quantval[i]) * INT32 (aanscales[i]),
- CONST_BITS-3) );
- end;
- end;
-{$endif}
-{$ifdef DCT_FLOAT_SUPPORTED}
-
- JDCT_FLOAT:
- begin
- { For float AA&N IDCT method, divisors are equal to quantization
- coefficients scaled by scalefactor[row]*scalefactor[col], where
- scalefactor[0] := 1
- scalefactor[k] := cos(k*PI/16) * sqrt(2) for k=1..7
- We apply a further scale factor of 8.
- What's actually stored is 1/divisor so that the inner loop can
- use a multiplication rather than a division. }
-
- if (fdct^.float_divisors[qtblno] = NIL) then
- begin
- fdct^.float_divisors[qtblno] := FAST_FLOAT_FIELD_PTR(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- DCTSIZE2 * SIZEOF(FAST_FLOAT)) );
- end;
- fdtbl := fdct^.float_divisors[qtblno];
- i := 0;
- for row := 0 to pred(DCTSIZE) do
- begin
- for col := 0 to pred(DCTSIZE) do
- begin
- fdtbl^[i] := {FAST_FLOAT}
- (1.0 / (( {double}(qtbl^.quantval[i]) *
- aanscalefactor[row] * aanscalefactor[col] * 8.0)));
- Inc(i);
- end;
- end;
- end;
-{$endif}
- else
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
- end;
- Inc(compptr);
- end;
-end;
-
-
-{ Perform forward DCT on one or more blocks of a component.
-
- The input samples are taken from the sample_data[] array starting at
- position start_row/start_col, and moving to the right for any additional
- blocks. The quantized coefficients are returned in coef_blocks[]. }
-
-{METHODDEF}
-procedure forward_DCT (cinfo : j_compress_ptr;
- compptr : jpeg_component_info_ptr;
- sample_data : JSAMPARRAY;
- coef_blocks : JBLOCKROW;
- start_row : JDIMENSION;
- start_col : JDIMENSION;
- num_blocks : JDIMENSION); far;
-{ This version is used for integer DCT implementations. }
-var
- { This routine is heavily used, so it's worth coding it tightly. }
- fdct : my_fdct_ptr;
- do_dct : forward_DCT_method_ptr;
- divisors : DCTELEM_FIELD_PTR;
- workspace : array[0..DCTSIZE2-1] of DCTELEM; { work area for FDCT subroutine }
- bi : JDIMENSION;
-var
- {register} workspaceptr : DCTELEMPTR;
- {register} elemptr : JSAMPLE_PTR;
- {register} elemr : int;
-{$ifndef DCTSIZE_IS_8}
-var
- {register} elemc : int;
-{$endif}
-var
- {register} temp, qval : DCTELEM;
- {register} i : int;
- {register} output_ptr : JCOEFPTR;
-begin
- fdct := my_fdct_ptr (cinfo^.fdct);
- do_dct := fdct^.do_dct;
- divisors := fdct^.divisors[compptr^.quant_tbl_no];
-
- Inc(JSAMPROW_PTR(sample_data), start_row); { fold in the vertical offset once }
-
- for bi := 0 to pred(num_blocks) do
- begin
-
- { Load data into workspace, applying unsigned->signed conversion }
-
- workspaceptr := @workspace[0];
- for elemr := 0 to pred(DCTSIZE) do
- begin
- elemptr := @sample_data^[elemr]^[start_col];
-{$ifdef DCTSIZE_IS_8} { unroll the inner loop }
- workspaceptr^ := GETJSAMPLE(elemptr^) - CENTERJSAMPLE;
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := GETJSAMPLE(elemptr^) - CENTERJSAMPLE;
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := GETJSAMPLE(elemptr^) - CENTERJSAMPLE;
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := GETJSAMPLE(elemptr^) - CENTERJSAMPLE;
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := GETJSAMPLE(elemptr^) - CENTERJSAMPLE;
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := GETJSAMPLE(elemptr^) - CENTERJSAMPLE;
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := GETJSAMPLE(elemptr^) - CENTERJSAMPLE;
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := GETJSAMPLE(elemptr^) - CENTERJSAMPLE;
- Inc(workspaceptr);
- {Inc(elemptr); - Value never used }
-{$else}
- for elemc := pred(DCTSIZE) downto 0 do
- begin
- workspaceptr^ := GETJSAMPLE(elemptr^) - CENTERJSAMPLE;
- Inc(workspaceptr);
- Inc(elemptr);
- end;
-{$endif}
- end;
-
- { Perform the DCT }
- do_dct (workspace);
-
- { Quantize/descale the coefficients, and store into coef_blocks[] }
-
- output_ptr := JCOEFPTR(@coef_blocks^[bi]);
- for i := 0 to pred(DCTSIZE2) do
- begin
- qval := divisors^[i];
- temp := workspace[i];
- { Divide the coefficient value by qval, ensuring proper rounding.
- Since C does not specify the direction of rounding for negative
- quotients, we have to force the dividend positive for portability.
-
- In most files, at least half of the output values will be zero
- (at default quantization settings, more like three-quarters...)
- so we should ensure that this case is fast. On many machines,
- a comparison is enough cheaper than a divide to make a special test
- a win. Since both inputs will be nonnegative, we need only test
- for a < b to discover whether a/b is 0.
- If your machine's division is fast enough, define FAST_DIVIDE. }
-
- if (temp < 0) then
- begin
- temp := -temp;
- Inc(temp, qval shr 1); { for rounding }
- {DIVIDE_BY(temp, qval);}
- {$ifdef FAST_DIVIDE}
- temp := temp div qval;
- {$else}
- if (temp >= qval) then
- temp := temp div qval
- else
- temp := 0;
- {$endif}
- temp := -temp;
- end
- else
- begin
- Inc(temp, qval shr 1); { for rounding }
- {DIVIDE_BY(temp, qval);}
- {$ifdef FAST_DIVIDE}
- temp := temp div qval;
- {$else}
- if (temp >= qval) then
- temp := temp div qval
- else
- temp := 0;
- {$endif}
- end;
- output_ptr^[i] := JCOEF (temp);
- end;
- Inc(start_col, DCTSIZE);
- end;
-end;
-
-
-{$ifdef DCT_FLOAT_SUPPORTED}
-
-{METHODDEF}
-procedure forward_DCT_float (cinfo : j_compress_ptr;
- compptr : jpeg_component_info_ptr;
- sample_data : JSAMPARRAY;
- coef_blocks : JBLOCKROW;
- start_row : JDIMENSION;
- start_col : JDIMENSION;
- num_blocks : JDIMENSION); far;
-{ This version is used for floating-point DCT implementations. }
-var
- { This routine is heavily used, so it's worth coding it tightly. }
- fdct : my_fdct_ptr;
- do_dct : float_DCT_method_ptr;
- divisors : FAST_FLOAT_FIELD_PTR;
- workspace : array[0..DCTSIZE2-1] of FAST_FLOAT; { work area for FDCT subroutine }
- bi : JDIMENSION;
-var
- {register} workspaceptr : FAST_FLOAT_PTR;
- {register} elemptr : JSAMPLE_PTR;
- {register} elemr : int;
-{$ifndef DCTSIZE_IS_8}
-var
- {register} elemc : int;
-{$endif}
-var
- {register} temp : FAST_FLOAT;
- {register} i : int;
- {register} output_ptr : JCOEFPTR;
-begin
- fdct := my_fdct_ptr (cinfo^.fdct);
- do_dct := fdct^.do_float_dct;
- divisors := fdct^.float_divisors[compptr^.quant_tbl_no];
-
- Inc(JSAMPROW_PTR(sample_data), start_row); { fold in the vertical offset once }
-
- for bi := 0 to pred(num_blocks) do
- begin
- { Load data into workspace, applying unsigned->signed conversion }
-
- workspaceptr := @workspace[0];
- for elemr := 0 to pred(DCTSIZE) do
- begin
- elemptr := @(sample_data^[elemr]^[start_col]);
-{$ifdef DCTSIZE_IS_8} { unroll the inner loop }
- workspaceptr^ := {FAST_FLOAT}(GETJSAMPLE(elemptr^) - CENTERJSAMPLE);
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := {FAST_FLOAT}(GETJSAMPLE(elemptr^) - CENTERJSAMPLE);
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := {FAST_FLOAT}(GETJSAMPLE(elemptr^) - CENTERJSAMPLE);
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := {FAST_FLOAT}(GETJSAMPLE(elemptr^) - CENTERJSAMPLE);
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := {FAST_FLOAT}(GETJSAMPLE(elemptr^) - CENTERJSAMPLE);
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := {FAST_FLOAT}(GETJSAMPLE(elemptr^) - CENTERJSAMPLE);
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := {FAST_FLOAT}(GETJSAMPLE(elemptr^) - CENTERJSAMPLE);
- Inc(workspaceptr);
- Inc(elemptr);
- workspaceptr^ := {FAST_FLOAT}(GETJSAMPLE(elemptr^) - CENTERJSAMPLE);
- Inc(workspaceptr);
- {Inc(elemptr); - value never used }
-{$else}
- for elemc := pred(DCTSIZE) downto 0 do
- begin
- workspaceptr^ := {FAST_FLOAT}(
- (GETJSAMPLE(elemptr^) - CENTERJSAMPLE) );
- Inc(workspaceptr);
- Inc(elemptr);
- end;
-{$endif}
- end;
-
-
- { Perform the DCT }
- do_dct (workspace);
-
- { Quantize/descale the coefficients, and store into coef_blocks[] }
-
- output_ptr := JCOEFPTR(@(coef_blocks^[bi]));
-
- for i := 0 to pred(DCTSIZE2) do
- begin
- { Apply the quantization and scaling factor }
- temp := workspace[i] * divisors^[i];
- { Round to nearest integer.
- Since C does not specify the direction of rounding for negative
- quotients, we have to force the dividend positive for portability.
- The maximum coefficient size is +-16K (for 12-bit data), so this
- code should work for either 16-bit or 32-bit ints. }
- output_ptr^[i] := JCOEF ( int(Trunc (temp + {FAST_FLOAT}(16384.5))) - 16384);
- end;
- Inc(start_col, DCTSIZE);
- end;
-end;
-
-{$endif} { DCT_FLOAT_SUPPORTED }
-
-
-{ Initialize FDCT manager. }
-
-{GLOBAL}
-procedure jinit_forward_dct (cinfo : j_compress_ptr);
-var
- fdct : my_fdct_ptr;
- i : int;
-begin
- fdct := my_fdct_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_fdct_controller)) );
- cinfo^.fdct := jpeg_forward_dct_ptr (fdct);
- fdct^.pub.start_pass := start_pass_fdctmgr;
-
- case (cinfo^.dct_method) of
-{$ifdef DCT_ISLOW_SUPPORTED}
- JDCT_ISLOW:
- begin
- fdct^.pub.forward_DCT := forward_DCT;
- fdct^.do_dct := jpeg_fdct_islow;
- end;
-{$endif}
-{$ifdef DCT_IFAST_SUPPORTED}
- JDCT_IFAST:
- begin
- fdct^.pub.forward_DCT := forward_DCT;
- fdct^.do_dct := jpeg_fdct_ifast;
- end;
-{$endif}
-{$ifdef DCT_FLOAT_SUPPORTED}
- JDCT_FLOAT:
- begin
- fdct^.pub.forward_DCT := forward_DCT_float;
- fdct^.do_float_dct := jpeg_fdct_float;
- end;
-{$endif}
- else
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
- end;
-
- { Mark divisor tables unallocated }
- for i := 0 to pred(NUM_QUANT_TBLS) do
- begin
- fdct^.divisors[i] := NIL;
-{$ifdef DCT_FLOAT_SUPPORTED}
- fdct^.float_divisors[i] := NIL;
-{$endif}
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jchuff.pas b/packages/base/pasjpeg/jchuff.pas
deleted file mode 100644
index a632e76f72..0000000000
--- a/packages/base/pasjpeg/jchuff.pas
+++ /dev/null
@@ -1,1116 +0,0 @@
-Unit JcHuff;
-
-{ This file contains Huffman entropy encoding routines.
-
- Much of the complexity here has to do with supporting output suspension.
- If the data destination module demands suspension, we want to be able to
- back up to the start of the current MCU. To do this, we copy state
- variables into local working storage, and update them back to the
- permanent JPEG objects only upon successful completion of an MCU. }
-
-{ Original: jchuff.c; Copyright (C) 1991-1997, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg, { longptr definition missing }
- jpeglib,
- jdeferr,
- jerror,
- jutils,
- jinclude,
- jcomapi;
-
-{ The legal range of a DCT coefficient is
- -1024 .. +1023 for 8-bit data;
- -16384 .. +16383 for 12-bit data.
- Hence the magnitude should always fit in 10 or 14 bits respectively. }
-
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-const
- MAX_COEF_BITS = 10;
-{$else}
-const
- MAX_COEF_BITS = 14;
-{$endif}
-
-{ Derived data constructed for each Huffman table }
-{ Declarations shared with jcphuff.c }
-type
- c_derived_tbl_ptr = ^c_derived_tbl;
- c_derived_tbl = record
- ehufco : array[0..256-1] of uInt; { code for each symbol }
- ehufsi : array[0..256-1] of byte; { length of code for each symbol }
- { If no code has been allocated for a symbol S, ehufsi[S] contains 0 }
- end;
-{ for JCHUFF und JCPHUFF }
-type
- TLongTable = array[0..256] of long;
- TLongTablePtr = ^TLongTable;
-
-{ Compute the derived values for a Huffman table.
- Note this is also used by jcphuff.c. }
-
-{GLOBAL}
-procedure jpeg_make_c_derived_tbl (cinfo : j_compress_ptr;
- isDC : boolean;
- tblno : int;
- var pdtbl : c_derived_tbl_ptr);
-
-{ Generate the optimal coding for the given counts, fill htbl.
- Note this is also used by jcphuff.c. }
-
-{GLOBAL}
-procedure jpeg_gen_optimal_table (cinfo : j_compress_ptr;
- htbl : JHUFF_TBL_PTR;
- var freq : TLongTable); { Nomssi }
-
-{ Module initialization routine for Huffman entropy encoding. }
-
-{GLOBAL}
-procedure jinit_huff_encoder (cinfo : j_compress_ptr);
-
-implementation
-
-{ Expanded entropy encoder object for Huffman encoding.
-
- The savable_state subrecord contains fields that change within an MCU,
- but must not be updated permanently until we complete the MCU. }
-
-type
- savable_state = record
- put_buffer : INT32; { current bit-accumulation buffer }
- put_bits : int; { # of bits now in it }
- last_dc_val : array[0..MAX_COMPS_IN_SCAN-1] of int;
- { last DC coef for each component }
- end;
-
-
-type
- huff_entropy_ptr = ^huff_entropy_encoder;
- huff_entropy_encoder = record
- pub : jpeg_entropy_encoder; { public fields }
-
- saved : savable_state; { Bit buffer & DC state at start of MCU }
-
- { These fields are NOT loaded into local working state. }
- restarts_to_go : uInt; { MCUs left in this restart interval }
- next_restart_num : int; { next restart number to write (0-7) }
-
- { Pointers to derived tables (these workspaces have image lifespan) }
- dc_derived_tbls : array[0..NUM_HUFF_TBLS-1] of c_derived_tbl_ptr;
- ac_derived_tbls : array[0..NUM_HUFF_TBLS-1] of c_derived_tbl_ptr;
-
- {$ifdef ENTROPY_OPT_SUPPORTED} { Statistics tables for optimization }
- dc_count_ptrs : array[0..NUM_HUFF_TBLS-1] of TLongTablePtr;
- ac_count_ptrs : array[0..NUM_HUFF_TBLS-1] of TLongTablePtr;
- {$endif}
- end;
-
-
-
-{ Working state while writing an MCU.
- This struct contains all the fields that are needed by subroutines. }
-
-type
- working_state = record
- next_output_byte : JOCTETptr; { => next byte to write in buffer }
- free_in_buffer : size_t; { # of byte spaces remaining in buffer }
- cur : savable_state; { Current bit buffer & DC state }
- cinfo : j_compress_ptr; { dump_buffer needs access to this }
- end;
-
-
-{ Forward declarations }
-{METHODDEF}
-function encode_mcu_huff (cinfo : j_compress_ptr;
- const MCU_data : array of JBLOCKROW) : boolean; far;
- forward;
-{METHODDEF}
-procedure finish_pass_huff (cinfo : j_compress_ptr); far; forward;
-{$ifdef ENTROPY_OPT_SUPPORTED}
-{METHODDEF}
-function encode_mcu_gather (cinfo : j_compress_ptr;
- const MCU_data: array of JBLOCKROW) : boolean;
- far; forward;
-
-{METHODDEF}
-procedure finish_pass_gather (cinfo : j_compress_ptr); far; forward;
-{$endif}
-
-
-{ Initialize for a Huffman-compressed scan.
- If gather_statistics is TRUE, we do not output anything during the scan,
- just count the Huffman symbols used and generate Huffman code tables. }
-
-{METHODDEF}
-procedure start_pass_huff (cinfo : j_compress_ptr;
- gather_statistics : boolean); far;
-var
- entropy : huff_entropy_ptr;
- ci, dctbl, actbl : int;
- compptr : jpeg_component_info_ptr;
-begin
- entropy := huff_entropy_ptr (cinfo^.entropy);
-
- if (gather_statistics) then
- begin
-{$ifdef ENTROPY_OPT_SUPPORTED}
- entropy^.pub.encode_mcu := encode_mcu_gather;
- entropy^.pub.finish_pass := finish_pass_gather;
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end
- else
- begin
- entropy^.pub.encode_mcu := encode_mcu_huff;
- entropy^.pub.finish_pass := finish_pass_huff;
- end;
-
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- dctbl := compptr^.dc_tbl_no;
- actbl := compptr^.ac_tbl_no;
- if (gather_statistics) then
- begin
-{$ifdef ENTROPY_OPT_SUPPORTED}
- { Check for invalid table indexes }
- { (make_c_derived_tbl does this in the other path) }
- if (dctbl < 0) or (dctbl >= NUM_HUFF_TBLS) then
- ERREXIT1(j_common_ptr(cinfo), JERR_NO_HUFF_TABLE, dctbl);
- if (actbl < 0) or (actbl >= NUM_HUFF_TBLS) then
- ERREXIT1(j_common_ptr(cinfo), JERR_NO_HUFF_TABLE, actbl);
- { Allocate and zero the statistics tables }
- { Note that jpeg_gen_optimal_table expects 257 entries in each table! }
- if (entropy^.dc_count_ptrs[dctbl] = NIL) then
- entropy^.dc_count_ptrs[dctbl] := TLongTablePtr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- 257 * SIZEOF(long)) );
- MEMZERO(entropy^.dc_count_ptrs[dctbl], 257 * SIZEOF(long));
- if (entropy^.ac_count_ptrs[actbl] = NIL) then
- entropy^.ac_count_ptrs[actbl] := TLongTablePtr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- 257 * SIZEOF(long)) );
- MEMZERO(entropy^.ac_count_ptrs[actbl], 257 * SIZEOF(long));
-{$endif}
- end
- else
- begin
- { Compute derived values for Huffman tables }
- { We may do this more than once for a table, but it's not expensive }
- jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
- entropy^.dc_derived_tbls[dctbl]);
- jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
- entropy^.ac_derived_tbls[actbl]);
- end;
- { Initialize DC predictions to 0 }
- entropy^.saved.last_dc_val[ci] := 0;
- end;
-
- { Initialize bit buffer to empty }
- entropy^.saved.put_buffer := 0;
- entropy^.saved.put_bits := 0;
-
- { Initialize restart stuff }
- entropy^.restarts_to_go := cinfo^.restart_interval;
- entropy^.next_restart_num := 0;
-end;
-
-
-{ Compute the derived values for a Huffman table.
- This routine also performs some validation checks on the table.
-
- Note this is also used by jcphuff.c. }
-
-{GLOBAL}
-procedure jpeg_make_c_derived_tbl (cinfo : j_compress_ptr;
- isDC : boolean;
- tblno : int;
- var pdtbl : c_derived_tbl_ptr);
-var
- htbl : JHUFF_TBL_PTR;
- dtbl : c_derived_tbl_ptr;
- p, i, l, lastp, si, maxsymbol : int;
- huffsize : array[0..257-1] of byte;
- huffcode : array[0..257-1] of uInt;
- code : uInt;
-begin
- { Note that huffsize[] and huffcode[] are filled in code-length order,
- paralleling the order of the symbols themselves in htbl->huffval[]. }
-
- { Find the input Huffman table }
- if (tblno < 0) or (tblno >= NUM_HUFF_TBLS) then
- ERREXIT1(j_common_ptr(cinfo), JERR_NO_HUFF_TABLE, tblno);
- if isDC then
- htbl := cinfo^.dc_huff_tbl_ptrs[tblno]
- else
- htbl := cinfo^.ac_huff_tbl_ptrs[tblno];
- if (htbl = NIL) then
- ERREXIT1(j_common_ptr(cinfo), JERR_NO_HUFF_TABLE, tblno);
-
- { Allocate a workspace if we haven't already done so. }
- if (pdtbl = NIL) then
- pdtbl := c_derived_tbl_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(c_derived_tbl)) );
- dtbl := pdtbl;
-
- { Figure C.1: make table of Huffman code length for each symbol }
-
- p := 0;
- for l := 1 to 16 do
- begin
- i := int(htbl^.bits[l]);
- if (i < 0) and (p + i > 256) then { protect against table overrun }
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_HUFF_TABLE);
- while (i > 0) do
- begin
- huffsize[p] := byte(l);
- Inc(p);
- Dec(i);
- end;
- end;
- huffsize[p] := 0;
- lastp := p;
-
- { Figure C.2: generate the codes themselves }
- { We also validate that the counts represent a legal Huffman code tree. }
-
- code := 0;
- si := huffsize[0];
- p := 0;
- while (huffsize[p] <> 0) do
- begin
- while (( int(huffsize[p]) ) = si) do
- begin
- huffcode[p] := code;
- Inc(p);
- Inc(code);
- end;
- { code is now 1 more than the last code used for codelength si; but
- it must still fit in si bits, since no code is allowed to be all ones. }
-
- if (INT32(code) >= (INT32(1) shl si)) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_HUFF_TABLE);
- code := code shl 1;
- Inc(si);
- end;
-
- { Figure C.3: generate encoding tables }
- { These are code and size indexed by symbol value }
-
- { Set all codeless symbols to have code length 0;
- this lets us detect duplicate VAL entries here, and later
- allows emit_bits to detect any attempt to emit such symbols. }
-
- MEMZERO(@dtbl^.ehufsi, SIZEOF(dtbl^.ehufsi));
-
- { This is also a convenient place to check for out-of-range
- and duplicated VAL entries. We allow 0..255 for AC symbols
- but only 0..15 for DC. (We could constrain them further
- based on data depth and mode, but this seems enough.) }
-
- if isDC then
- maxsymbol := 15
- else
- maxsymbol := 255;
-
- for p := 0 to pred(lastp) do
- begin
- i := htbl^.huffval[p];
- if (i < 0) or (i > maxsymbol) or (dtbl^.ehufsi[i] <> 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_HUFF_TABLE);
- dtbl^.ehufco[i] := huffcode[p];
- dtbl^.ehufsi[i] := huffsize[p];
- end;
-end;
-
-
-{ Outputting bytes to the file }
-
-
-{LOCAL}
-function dump_buffer (var state : working_state) : boolean;
-{ Empty the output buffer; return TRUE if successful, FALSE if must suspend }
-var
- dest : jpeg_destination_mgr_ptr;
-begin
- dest := state.cinfo^.dest;
-
- if (not dest^.empty_output_buffer (state.cinfo)) then
- begin
- dump_buffer := FALSE;
- exit;
- end;
- { After a successful buffer dump, must reset buffer pointers }
- state.next_output_byte := dest^.next_output_byte;
- state.free_in_buffer := dest^.free_in_buffer;
- dump_buffer := TRUE;
-end;
-
-
-{ Outputting bits to the file }
-
-{ Only the right 24 bits of put_buffer are used; the valid bits are
- left-justified in this part. At most 16 bits can be passed to emit_bits
- in one call, and we never retain more than 7 bits in put_buffer
- between calls, so 24 bits are sufficient. }
-
-
-{LOCAL}
-function emit_bits (var state : working_state;
- code : uInt;
- size : int) : boolean; {INLINE}
-{ Emit some bits; return TRUE if successful, FALSE if must suspend }
-var
- { This routine is heavily used, so it's worth coding tightly. }
- {register} put_buffer : INT32;
- {register} put_bits : int;
-var
- c : int;
-begin
- put_buffer := INT32 (code);
- put_bits := state.cur.put_bits;
-
- { if size is 0, caller used an invalid Huffman table entry }
- if (size = 0) then
- ERREXIT(j_common_ptr(state.cinfo), JERR_HUFF_MISSING_CODE);
-
- put_buffer := put_buffer and pred(INT32(1) shl size);
- { mask off any extra bits in code }
-
- Inc(put_bits, size); { new number of bits in buffer }
-
- put_buffer := put_buffer shl (24 - put_bits);
- { align incoming bits }
- put_buffer := put_buffer or state.cur.put_buffer;
- { and merge with old buffer contents }
- while (put_bits >= 8) do
- begin
- c := int ((put_buffer shr 16) and $FF);
-
- {emit_byte(state, c, return FALSE);}
- { Emit a byte, return FALSE if must suspend. }
- state.next_output_byte^ := JOCTET (c);
- Inc(state.next_output_byte);
- Dec(state.free_in_buffer);
- if (state.free_in_buffer = 0) then
- if not dump_buffer(state) then
- begin
- emit_bits := FALSE;
- exit;
- end;
-
- if (c = $FF) then { need to stuff a zero byte? }
- begin
- {emit_byte(state, 0, return FALSE);}
- state.next_output_byte^ := JOCTET (0);
- Inc(state.next_output_byte);
- Dec(state.free_in_buffer);
- if (state.free_in_buffer = 0) then
- if not dump_buffer(state) then
- begin
- emit_bits := FALSE;
- exit;
- end;
-
- end;
- put_buffer := put_buffer shl 8;
- Dec(put_bits, 8);
- end;
-
- state.cur.put_buffer := put_buffer; { update state variables }
- state.cur.put_bits := put_bits;
-
- emit_bits := TRUE;
-end;
-
-
-{LOCAL}
-function flush_bits (var state : working_state) : boolean;
-begin
- if (not emit_bits(state, $7F, 7)) then { fill any partial byte with ones }
- begin
- flush_bits := FALSE;
- exit;
- end;
- state.cur.put_buffer := 0; { and reset bit-buffer to empty }
- state.cur.put_bits := 0;
- flush_bits := TRUE;
-end;
-
-
-{ Encode a single block's worth of coefficients }
-
-{LOCAL}
-function encode_one_block (var state : working_state;
- const block : JBLOCK;
- last_dc_val : int;
- dctbl : c_derived_tbl_ptr;
- actbl : c_derived_tbl_ptr) : boolean;
-var
- {register} temp, temp2 : int;
- {register} nbits : int;
- {register} k, r, i : int;
-begin
- { Encode the DC coefficient difference per section F.1.2.1 }
-
- temp2 := block[0] - last_dc_val;
- temp := temp2;
-
- if (temp < 0) then
- begin
- temp := -temp; { temp is abs value of input }
- { For a negative input, want temp2 := bitwise complement of abs(input) }
- { This code assumes we are on a two's complement machine }
- Dec(temp2);
- end;
-
- { Find the number of bits needed for the magnitude of the coefficient }
- nbits := 0;
- while (temp <> 0) do
- begin
- Inc(nbits);
- temp := temp shr 1;
- end;
-
- { Check for out-of-range coefficient values.
- Since we're encoding a difference, the range limit is twice as much. }
-
- if (nbits > MAX_COEF_BITS+1) then
- ERREXIT(j_common_ptr(state.cinfo), JERR_BAD_DCT_COEF);
-
- { Emit the Huffman-coded symbol for the number of bits }
- if not emit_bits(state, dctbl^.ehufco[nbits], dctbl^.ehufsi[nbits]) then
- begin
- encode_one_block := FALSE;
- exit;
- end;
-
- { Emit that number of bits of the value, if positive, }
- { or the complement of its magnitude, if negative. }
- if (nbits <> 0) then { emit_bits rejects calls with size 0 }
- if not emit_bits(state, uInt(temp2), nbits) then
- begin
- encode_one_block := FALSE;
- exit;
- end;
-
- { Encode the AC coefficients per section F.1.2.2 }
-
- r := 0; { r := run length of zeros }
-
- for k := 1 to pred(DCTSIZE2) do
- begin
- temp := block[jpeg_natural_order[k]];
- if (temp = 0) then
- begin
- Inc(r);
- end
- else
- begin
- { if run length > 15, must emit special run-length-16 codes ($F0) }
- while (r > 15) do
- begin
- if not emit_bits(state, actbl^.ehufco[$F0], actbl^.ehufsi[$F0]) then
- begin
- encode_one_block := FALSE;
- exit;
- end;
- Dec(r, 16);
- end;
-
- temp2 := temp;
- if (temp < 0) then
- begin
- temp := -temp; { temp is abs value of input }
- { This code assumes we are on a two's complement machine }
- Dec(temp2);
- end;
-
- { Find the number of bits needed for the magnitude of the coefficient }
- nbits := 0; { there must be at least one 1 bit }
- repeat
- Inc(nbits);
- temp := temp shr 1;
- until (temp = 0);
-
- { Check for out-of-range coefficient values }
- if (nbits > MAX_COEF_BITS) then
- ERREXIT(j_common_ptr(state.cinfo), JERR_BAD_DCT_COEF);
-
- { Emit Huffman symbol for run length / number of bits }
- i := (r shl 4) + nbits;
- if not emit_bits(state, actbl^.ehufco[i], actbl^.ehufsi[i]) then
- begin
- encode_one_block := FALSE;
- exit;
- end;
-
- { Emit that number of bits of the value, if positive, }
- { or the complement of its magnitude, if negative. }
- if not emit_bits(state, uInt(temp2), nbits) then
- begin
- encode_one_block := FALSE;
- exit;
- end;
-
- r := 0;
- end;
- end;
-
- { If the last coef(s) were zero, emit an end-of-block code }
- if (r > 0) then
- if not emit_bits(state, actbl^.ehufco[0], actbl^.ehufsi[0]) then
- begin
- encode_one_block := FALSE;
- exit;
- end;
-
- encode_one_block := TRUE;
-end;
-
-
-{ Emit a restart marker & resynchronize predictions. }
-
-{LOCAL}
-function emit_restart (var state : working_state;
- restart_num : int) : boolean;
-var
- ci : int;
-begin
- if (not flush_bits(state)) then
- begin
- emit_restart := FALSE;
- exit;
- end;
-
- {emit_byte(state, $FF, return FALSE);}
- { Emit a byte, return FALSE if must suspend. }
- state.next_output_byte^ := JOCTET ($FF);
- Inc(state.next_output_byte);
- Dec(state.free_in_buffer);
- if (state.free_in_buffer = 0) then
- if not dump_buffer(state) then
- begin
- emit_restart := FALSE;
- exit;
- end;
-
- {emit_byte(state, JPEG_RST0 + restart_num, return FALSE);}
- { Emit a byte, return FALSE if must suspend. }
- state.next_output_byte^ := JOCTET (JPEG_RST0 + restart_num);
- Inc(state.next_output_byte);
- Dec(state.free_in_buffer);
- if (state.free_in_buffer = 0) then
- if not dump_buffer(state) then
- begin
- emit_restart := FALSE;
- exit;
- end;
-
- { Re-initialize DC predictions to 0 }
- for ci := 0 to pred(state.cinfo^.comps_in_scan) do
- state.cur.last_dc_val[ci] := 0;
-
- { The restart counter is not updated until we successfully write the MCU. }
-
- emit_restart := TRUE;
-end;
-
-
-{ Encode and output one MCU's worth of Huffman-compressed coefficients. }
-
-{METHODDEF}
-function encode_mcu_huff (cinfo : j_compress_ptr;
- const MCU_data: array of JBLOCKROW) : boolean;
-var
- entropy : huff_entropy_ptr;
- state : working_state;
- blkn, ci : int;
- compptr : jpeg_component_info_ptr;
-begin
- entropy := huff_entropy_ptr (cinfo^.entropy);
- { Load up working state }
- state.next_output_byte := cinfo^.dest^.next_output_byte;
- state.free_in_buffer := cinfo^.dest^.free_in_buffer;
- {ASSIGN_STATE(state.cur, entropy^.saved);}
- state.cur := entropy^.saved;
- state.cinfo := cinfo;
-
- { Emit restart marker if needed }
- if (cinfo^.restart_interval <> 0) then
- begin
- if (entropy^.restarts_to_go = 0) then
- if not emit_restart(state, entropy^.next_restart_num) then
- begin
- encode_mcu_huff := FALSE;
- exit;
- end;
- end;
-
- { Encode the MCU data blocks }
- for blkn := 0 to pred(cinfo^.blocks_in_MCU) do
- begin
- ci := cinfo^.MCU_membership[blkn];
- compptr := cinfo^.cur_comp_info[ci];
- if not encode_one_block(state,
- MCU_data[blkn]^[0],
- state.cur.last_dc_val[ci],
- entropy^.dc_derived_tbls[compptr^.dc_tbl_no],
- entropy^.ac_derived_tbls[compptr^.ac_tbl_no]) then
- begin
- encode_mcu_huff := FALSE;
- exit;
- end;
- { Update last_dc_val }
- state.cur.last_dc_val[ci] := MCU_data[blkn]^[0][0];
- end;
-
- { Completed MCU, so update state }
- cinfo^.dest^.next_output_byte := state.next_output_byte;
- cinfo^.dest^.free_in_buffer := state.free_in_buffer;
- {ASSIGN_STATE(entropy^.saved, state.cur);}
- entropy^.saved := state.cur;
-
- { Update restart-interval state too }
- if (cinfo^.restart_interval <> 0) then
- begin
- if (entropy^.restarts_to_go = 0) then
- begin
- entropy^.restarts_to_go := cinfo^.restart_interval;
- Inc(entropy^.next_restart_num);
- with entropy^ do
- next_restart_num := next_restart_num and 7;
- end;
- Dec(entropy^.restarts_to_go);
- end;
-
- encode_mcu_huff := TRUE;
-end;
-
-
-{ Finish up at the end of a Huffman-compressed scan. }
-
-{METHODDEF}
-procedure finish_pass_huff (cinfo : j_compress_ptr);
-var
- entropy : huff_entropy_ptr;
- state : working_state;
-begin
- entropy := huff_entropy_ptr (cinfo^.entropy);
-
- { Load up working state ... flush_bits needs it }
- state.next_output_byte := cinfo^.dest^.next_output_byte;
- state.free_in_buffer := cinfo^.dest^.free_in_buffer;
- {ASSIGN_STATE(state.cur, entropy^.saved);}
- state.cur := entropy^.saved;
- state.cinfo := cinfo;
-
- { Flush out the last data }
- if not flush_bits(state) then
- ERREXIT(j_common_ptr(cinfo), JERR_CANT_SUSPEND);
-
- { Update state }
- cinfo^.dest^.next_output_byte := state.next_output_byte;
- cinfo^.dest^.free_in_buffer := state.free_in_buffer;
- {ASSIGN_STATE(entropy^.saved, state.cur);}
- entropy^.saved := state.cur;
-end;
-
-
-{ Huffman coding optimization.
-
- We first scan the supplied data and count the number of uses of each symbol
- that is to be Huffman-coded. (This process MUST agree with the code above.)
- Then we build a Huffman coding tree for the observed counts.
- Symbols which are not needed at all for the particular image are not
- assigned any code, which saves space in the DHT marker as well as in
- the compressed data. }
-
-{$ifdef ENTROPY_OPT_SUPPORTED}
-
-
-{ Process a single block's worth of coefficients }
-
-{LOCAL}
-procedure htest_one_block (cinfo : j_compress_ptr;
- const block : JBLOCK;
- last_dc_val : int;
- dc_counts : TLongTablePtr;
- ac_counts : TLongTablePtr);
-
-var
- {register} temp : int;
- {register} nbits : int;
- {register} k, r : int;
-begin
- { Encode the DC coefficient difference per section F.1.2.1 }
- temp := block[0] - last_dc_val;
- if (temp < 0) then
- temp := -temp;
-
- { Find the number of bits needed for the magnitude of the coefficient }
- nbits := 0;
- while (temp <> 0) do
- begin
- Inc(nbits);
- temp := temp shr 1;
- end;
-
- { Check for out-of-range coefficient values.
- Since we're encoding a difference, the range limit is twice as much. }
-
- if (nbits > MAX_COEF_BITS+1) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_DCT_COEF);
-
- { Count the Huffman symbol for the number of bits }
- Inc(dc_counts^[nbits]);
-
- { Encode the AC coefficients per section F.1.2.2 }
-
- r := 0; { r := run length of zeros }
-
- for k := 1 to pred(DCTSIZE2) do
- begin
- temp := block[jpeg_natural_order[k]];
- if (temp = 0) then
- begin
- Inc(r);
- end
- else
- begin
- { if run length > 15, must emit special run-length-16 codes ($F0) }
- while (r > 15) do
- begin
- Inc(ac_counts^[$F0]);
- Dec(r, 16);
- end;
-
- { Find the number of bits needed for the magnitude of the coefficient }
- if (temp < 0) then
- temp := -temp;
-
- { Find the number of bits needed for the magnitude of the coefficient }
- nbits := 0; { there must be at least one 1 bit }
- repeat
- Inc(nbits);
- temp := temp shr 1;
- until (temp = 0);
-
-
- { Count Huffman symbol for run length / number of bits }
- Inc(ac_counts^[(r shl 4) + nbits]);
-
- r := 0;
- end;
- end;
-
- { If the last coef(s) were zero, emit an end-of-block code }
- if (r > 0) then
- Inc(ac_counts^[0]);
-end;
-
-
-{ Trial-encode one MCU's worth of Huffman-compressed coefficients.
- No data is actually output, so no suspension return is possible. }
-
-{METHODDEF}
-function encode_mcu_gather (cinfo : j_compress_ptr;
- const MCU_data: array of JBLOCKROW) : boolean;
-var
- entropy : huff_entropy_ptr;
- blkn, ci : int;
- compptr : jpeg_component_info_ptr;
-begin
- entropy := huff_entropy_ptr (cinfo^.entropy);
- { Take care of restart intervals if needed }
- if (cinfo^.restart_interval <> 0) then
- begin
- if (entropy^.restarts_to_go = 0) then
- begin
- { Re-initialize DC predictions to 0 }
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- entropy^.saved.last_dc_val[ci] := 0;
- { Update restart state }
- entropy^.restarts_to_go := cinfo^.restart_interval;
- end;
- Dec(entropy^.restarts_to_go);
- end;
-
- for blkn := 0 to pred(cinfo^.blocks_in_MCU) do
- begin
- ci := cinfo^.MCU_membership[blkn];
- compptr := cinfo^.cur_comp_info[ci];
- htest_one_block(cinfo, MCU_data[blkn]^[0],
- entropy^.saved.last_dc_val[ci],
- entropy^.dc_count_ptrs[compptr^.dc_tbl_no],
- entropy^.ac_count_ptrs[compptr^.ac_tbl_no]);
- entropy^.saved.last_dc_val[ci] := MCU_data[blkn]^[0][0];
- end;
-
- encode_mcu_gather := TRUE;
-end;
-
-
-{ Generate the best Huffman code table for the given counts, fill htbl.
- Note this is also used by jcphuff.c.
-
- The JPEG standard requires that no symbol be assigned a codeword of all
- one bits (so that padding bits added at the end of a compressed segment
- can't look like a valid code). Because of the canonical ordering of
- codewords, this just means that there must be an unused slot in the
- longest codeword length category. Section K.2 of the JPEG spec suggests
- reserving such a slot by pretending that symbol 256 is a valid symbol
- with count 1. In theory that's not optimal; giving it count zero but
- including it in the symbol set anyway should give a better Huffman code.
- But the theoretically better code actually seems to come out worse in
- practice, because it produces more all-ones bytes (which incur stuffed
- zero bytes in the final file). In any case the difference is tiny.
-
- The JPEG standard requires Huffman codes to be no more than 16 bits long.
- If some symbols have a very small but nonzero probability, the Huffman tree
- must be adjusted to meet the code length restriction. We currently use
- the adjustment method suggested in JPEG section K.2. This method is *not*
- optimal; it may not choose the best possible limited-length code. But
- typically only very-low-frequency symbols will be given less-than-optimal
- lengths, so the code is almost optimal. Experimental comparisons against
- an optimal limited-length-code algorithm indicate that the difference is
- microscopic --- usually less than a hundredth of a percent of total size.
- So the extra complexity of an optimal algorithm doesn't seem worthwhile. }
-
-
-{GLOBAL}
-procedure jpeg_gen_optimal_table (cinfo : j_compress_ptr;
- htbl : JHUFF_TBL_PTR;
- var freq : TLongTable);
-const
- MAX_CLEN = 32; { assumed maximum initial code length }
-var
- bits : array[0..MAX_CLEN+1-1] of UINT8; { bits[k] := # of symbols with code length k }
- codesize : array[0..257-1] of int; { codesize[k] := code length of symbol k }
- others : array[0..257-1] of int; { next symbol in current branch of tree }
- c1, c2 : int;
- p, i, j : int;
- v : long;
-begin
- { This algorithm is explained in section K.2 of the JPEG standard }
-
- MEMZERO(@bits, SIZEOF(bits));
- MEMZERO(@codesize, SIZEOF(codesize));
- for i := 0 to 256 do
- others[i] := -1; { init links to empty }
-
- freq[256] := 1; { make sure 256 has a nonzero count }
- { Including the pseudo-symbol 256 in the Huffman procedure guarantees
- that no real symbol is given code-value of all ones, because 256
- will be placed last in the largest codeword category. }
-
- { Huffman's basic algorithm to assign optimal code lengths to symbols }
-
- while TRUE do
- begin
- { Find the smallest nonzero frequency, set c1 := its symbol }
- { In case of ties, take the larger symbol number }
- c1 := -1;
- v := long(1000000000);
- for i := 0 to 256 do
- begin
- if (freq[i] <> 0) and (freq[i] <= v) then
- begin
- v := freq[i];
- c1 := i;
- end;
- end;
-
- { Find the next smallest nonzero frequency, set c2 := its symbol }
- { In case of ties, take the larger symbol number }
- c2 := -1;
- v := long(1000000000);
- for i := 0 to 256 do
- begin
- if (freq[i] <> 0) and (freq[i] <= v) and (i <> c1) then
- begin
- v := freq[i];
- c2 := i;
- end;
- end;
-
- { Done if we've merged everything into one frequency }
- if (c2 < 0) then
- break;
-
- { Else merge the two counts/trees }
- Inc(freq[c1], freq[c2]);
- freq[c2] := 0;
-
- { Increment the codesize of everything in c1's tree branch }
- Inc(codesize[c1]);
- while (others[c1] >= 0) do
- begin
- c1 := others[c1];
- Inc(codesize[c1]);
- end;
-
- others[c1] := c2; { chain c2 onto c1's tree branch }
-
- { Increment the codesize of everything in c2's tree branch }
- Inc(codesize[c2]);
- while (others[c2] >= 0) do
- begin
- c2 := others[c2];
- Inc(codesize[c2]);
- end;
- end;
-
- { Now count the number of symbols of each code length }
- for i := 0 to 256 do
- begin
- if (codesize[i]<>0) then
- begin
- { The JPEG standard seems to think that this can't happen, }
- { but I'm paranoid... }
- if (codesize[i] > MAX_CLEN) then
- ERREXIT(j_common_ptr(cinfo), JERR_HUFF_CLEN_OVERFLOW);
-
- Inc(bits[codesize[i]]);
- end;
- end;
-
- { JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure
- Huffman procedure assigned any such lengths, we must adjust the coding.
- Here is what the JPEG spec says about how this next bit works:
- Since symbols are paired for the longest Huffman code, the symbols are
- removed from this length category two at a time. The prefix for the pair
- (which is one bit shorter) is allocated to one of the pair; then,
- skipping the BITS entry for that prefix length, a code word from the next
- shortest nonzero BITS entry is converted into a prefix for two code words
- one bit longer. }
-
- for i := MAX_CLEN downto 17 do
- begin
- while (bits[i] > 0) do
- begin
- j := i - 2; { find length of new prefix to be used }
- while (bits[j] = 0) do
- Dec(j);
-
- Dec(bits[i], 2); { remove two symbols }
- Inc(bits[i-1]); { one goes in this length }
- Inc(bits[j+1], 2); { two new symbols in this length }
- Dec(bits[j]); { symbol of this length is now a prefix }
- end;
- end;
-
- { Delphi 2: FOR-loop variable 'i' may be undefined after loop }
- i := 16; { Nomssi: work around }
-
- { Remove the count for the pseudo-symbol 256 from the largest codelength }
- while (bits[i] = 0) do { find largest codelength still in use }
- Dec(i);
- Dec(bits[i]);
-
- { Return final symbol counts (only for lengths 0..16) }
- MEMCOPY(@htbl^.bits, @bits, SIZEOF(htbl^.bits));
-
- { Return a list of the symbols sorted by code length }
- { It's not real clear to me why we don't need to consider the codelength
- changes made above, but the JPEG spec seems to think this works. }
-
- p := 0;
- for i := 1 to MAX_CLEN do
- begin
- for j := 0 to 255 do
- begin
- if (codesize[j] = i) then
- begin
- htbl^.huffval[p] := UINT8 (j);
- Inc(p);
- end;
- end;
- end;
-
- { Set sent_table FALSE so updated table will be written to JPEG file. }
- htbl^.sent_table := FALSE;
-end;
-
-
-{ Finish up a statistics-gathering pass and create the new Huffman tables. }
-
-{METHODDEF}
-procedure finish_pass_gather (cinfo : j_compress_ptr);
-var
- entropy : huff_entropy_ptr;
- ci, dctbl, actbl : int;
- compptr : jpeg_component_info_ptr;
- htblptr : ^JHUFF_TBL_PTR;
- did_dc : array[0..NUM_HUFF_TBLS-1] of boolean;
- did_ac : array[0..NUM_HUFF_TBLS-1] of boolean;
-begin
- entropy := huff_entropy_ptr (cinfo^.entropy);
-
- { It's important not to apply jpeg_gen_optimal_table more than once
- per table, because it clobbers the input frequency counts! }
-
- MEMZERO(@did_dc, SIZEOF(did_dc));
- MEMZERO(@did_ac, SIZEOF(did_ac));
-
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- dctbl := compptr^.dc_tbl_no;
- actbl := compptr^.ac_tbl_no;
- if (not did_dc[dctbl]) then
- begin
- htblptr := @(cinfo^.dc_huff_tbl_ptrs[dctbl]);
- if ( htblptr^ = NIL) then
- htblptr^ := jpeg_alloc_huff_table(j_common_ptr(cinfo));
- jpeg_gen_optimal_table(cinfo, htblptr^, entropy^.dc_count_ptrs[dctbl]^);
- did_dc[dctbl] := TRUE;
- end;
- if (not did_ac[actbl]) then
- begin
- htblptr := @(cinfo^.ac_huff_tbl_ptrs[actbl]);
- if ( htblptr^ = NIL) then
- htblptr^ := jpeg_alloc_huff_table(j_common_ptr(cinfo));
- jpeg_gen_optimal_table(cinfo, htblptr^, entropy^.ac_count_ptrs[actbl]^);
- did_ac[actbl] := TRUE;
- end;
- end;
-end;
-
-{$endif} { ENTROPY_OPT_SUPPORTED }
-
-
-{ Module initialization routine for Huffman entropy encoding. }
-
-{GLOBAL}
-procedure jinit_huff_encoder (cinfo : j_compress_ptr);
-var
- entropy : huff_entropy_ptr;
- i : int;
-begin
- entropy := huff_entropy_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(huff_entropy_encoder)) );
- cinfo^.entropy := jpeg_entropy_encoder_ptr (entropy);
- entropy^.pub.start_pass := start_pass_huff;
-
- { Mark tables unallocated }
- for i := 0 to pred(NUM_HUFF_TBLS) do
- begin
- entropy^.ac_derived_tbls[i] := NIL;
- entropy^.dc_derived_tbls[i] := NIL;
-{$ifdef ENTROPY_OPT_SUPPORTED}
- entropy^.ac_count_ptrs[i] := NIL;
- entropy^.dc_count_ptrs[i] := NIL;
-{$endif}
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jcinit.pas b/packages/base/pasjpeg/jcinit.pas
deleted file mode 100644
index 4c3016ed73..0000000000
--- a/packages/base/pasjpeg/jcinit.pas
+++ /dev/null
@@ -1,95 +0,0 @@
-Unit JcInit;
-
-{ Original: jcinit.c ; Copyright (C) 1991-1997, Thomas G. Lane. }
-
-{ This file contains initialization logic for the JPEG compressor.
- This routine is in charge of selecting the modules to be executed and
- making an initialization call to each one.
-
- Logically, this code belongs in jcmaster.c. It's split out because
- linking this routine implies linking the entire compression library.
- For a transcoding-only application, we want to be able to use jcmaster.c
- without linking in the whole library. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jinclude,
- jdeferr,
- jerror,
- jpeglib,
-{$ifdef C_PROGRESSIVE_SUPPORTED}
- jcphuff,
-{$endif}
- JcHuff, JcMaster, JcColor, JcSample, JcPrepCt,
- JcDCTMgr, JcCoefCT, JcMainCT, JcMarker;
-
-{ Master selection of compression modules.
- This is done once at the start of processing an image. We determine
- which modules will be used and give them appropriate initialization calls. }
-
-{GLOBAL}
-procedure jinit_compress_master (cinfo : j_compress_ptr);
-
-implementation
-
-
-
-{ Master selection of compression modules.
- This is done once at the start of processing an image. We determine
- which modules will be used and give them appropriate initialization calls. }
-
-{GLOBAL}
-procedure jinit_compress_master (cinfo : j_compress_ptr);
-begin
- { Initialize master control (includes parameter checking/processing) }
- jinit_c_master_control(cinfo, FALSE { full compression });
-
- { Preprocessing }
- if (not cinfo^.raw_data_in) then
- begin
- jinit_color_converter(cinfo);
- jinit_downsampler(cinfo);
- jinit_c_prep_controller(cinfo, FALSE { never need full buffer here });
- end;
- { Forward DCT }
- jinit_forward_dct(cinfo);
- { Entropy encoding: either Huffman or arithmetic coding. }
- if (cinfo^.arith_code) then
- begin
- ERREXIT(j_common_ptr(cinfo), JERR_ARITH_NOTIMPL);
- end
- else
- begin
- if (cinfo^.progressive_mode) then
- begin
-{$ifdef C_PROGRESSIVE_SUPPORTED}
- jinit_phuff_encoder(cinfo);
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end
- else
- jinit_huff_encoder(cinfo);
- end;
-
- { Need a full-image coefficient buffer in any multi-pass mode. }
- jinit_c_coef_controller(cinfo,
- (cinfo^.num_scans > 1) or (cinfo^.optimize_coding));
- jinit_c_main_controller(cinfo, FALSE { never need full buffer here });
-
- jinit_marker_writer(cinfo);
-
- { We can now tell the memory manager to allocate virtual arrays. }
- cinfo^.mem^.realize_virt_arrays (j_common_ptr(cinfo));
-
- { Write the datastream header (SOI) immediately.
- Frame and scan headers are postponed till later.
- This lets application insert special markers after the SOI. }
-
- cinfo^.marker^.write_file_header (cinfo);
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jcmainct.pas b/packages/base/pasjpeg/jcmainct.pas
deleted file mode 100644
index 46be3f1b89..0000000000
--- a/packages/base/pasjpeg/jcmainct.pas
+++ /dev/null
@@ -1,343 +0,0 @@
-Unit JcMainCt;
-
-{ This file contains the main buffer controller for compression.
- The main buffer lies between the pre-processor and the JPEG
- compressor proper; it holds downsampled data in the JPEG colorspace. }
-
-{ Original : jcmainct.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-{ Note: currently, there is no operating mode in which a full-image buffer
- is needed at this step. If there were, that mode could not be used with
- "raw data" input, since this module is bypassed in that case. However,
- we've left the code here for possible use in special applications. }
-
-{$undef FULL_MAIN_BUFFER_SUPPORTED}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
-{$ifdef FULL_MAIN_BUFFER_SUPPORTED}
- jutils,
-{$endif}
- jpeglib;
-
-{ Initialize main buffer controller. }
-
-{GLOBAL}
-procedure jinit_c_main_controller (cinfo : j_compress_ptr;
- need_full_buffer : boolean);
-
-implementation
-
-
-{ Private buffer controller object }
-
-type
- my_main_ptr = ^my_main_controller;
- my_main_controller = record
- pub : jpeg_c_main_controller; { public fields }
-
- cur_iMCU_row : JDIMENSION; { number of current iMCU row }
- rowgroup_ctr : JDIMENSION; { counts row groups received in iMCU row }
- suspended : boolean; { remember if we suspended output }
- pass_mode : J_BUF_MODE; { current operating mode }
-
- { If using just a strip buffer, this points to the entire set of buffers
- (we allocate one for each component). In the full-image case, this
- points to the currently accessible strips of the virtual arrays. }
-
- buffer : array[0..MAX_COMPONENTS-1] of JSAMPARRAY;
-
- {$ifdef FULL_MAIN_BUFFER_SUPPORTED}
- { If using full-image storage, this array holds pointers to virtual-array
- control blocks for each component. Unused if not full-image storage. }
-
- whole_image : array[0..MAX_COMPONENTS-1] of jvirt_sarray_ptr;
- {$endif}
- end; {my_main_controller}
-
-
-{ Forward declarations }
-{METHODDEF}
-procedure process_data_simple_main(cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- var in_row_ctr: JDIMENSION;
- in_rows_avail : JDIMENSION); far; forward;
-
-{$ifdef FULL_MAIN_BUFFER_SUPPORTED}
-{METHODDEF}
-procedure process_data_buffer_main(cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- var in_row_ctr : JDIMENSION;
- in_rows_avail : JDIMENSION); far; forward;
-{$endif}
-
-
-{ Initialize for a processing pass. }
-
-{METHODDEF}
-procedure start_pass_main (cinfo : j_compress_ptr;
- pass_mode : J_BUF_MODE); far;
-var
- main : my_main_ptr;
-begin
- main := my_main_ptr (cinfo^.main);
-
- { Do nothing in raw-data mode. }
- if (cinfo^.raw_data_in) then
- exit;
-
- main^.cur_iMCU_row := 0; { initialize counters }
- main^.rowgroup_ctr := 0;
- main^.suspended := FALSE;
- main^.pass_mode := pass_mode; { save mode for use by process_data }
-
- case (pass_mode) of
- JBUF_PASS_THRU:
- begin
-{$ifdef FULL_MAIN_BUFFER_SUPPORTED}
- if (main^.whole_image[0] <> NIL) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
-{$endif}
- main^.pub.process_data := process_data_simple_main;
- end;
-{$ifdef FULL_MAIN_BUFFER_SUPPORTED}
- JBUF_SAVE_SOURCE,
- JBUF_CRANK_DEST,
- JBUF_SAVE_AND_PASS:
- begin
- if (main^.whole_image[0] = NIL) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
- main^.pub.process_data := process_data_buffer_main;
- end;
-{$endif}
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
- end;
-end;
-
-
-{ Process some data.
- This routine handles the simple pass-through mode,
- where we have only a strip buffer. }
-
-{METHODDEF}
-procedure process_data_simple_main (cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- var in_row_ctr : JDIMENSION;
- in_rows_avail : JDIMENSION);
-var
- main : my_main_ptr;
-begin
- main := my_main_ptr (cinfo^.main);
-
- while (main^.cur_iMCU_row < cinfo^.total_iMCU_rows) do
- begin
- { Read input data if we haven't filled the main buffer yet }
- if (main^.rowgroup_ctr < DCTSIZE) then
- cinfo^.prep^.pre_process_data (cinfo,
- input_buf,
- in_row_ctr,
- in_rows_avail,
- JSAMPIMAGE(@main^.buffer),
- main^.rowgroup_ctr,
- JDIMENSION(DCTSIZE));
-
- { If we don't have a full iMCU row buffered, return to application for
- more data. Note that preprocessor will always pad to fill the iMCU row
- at the bottom of the image. }
- if (main^.rowgroup_ctr <> DCTSIZE) then
- exit;
-
- { Send the completed row to the compressor }
- if (not cinfo^.coef^.compress_data (cinfo, JSAMPIMAGE(@main^.buffer))) then
- begin
- { If compressor did not consume the whole row, then we must need to
- suspend processing and return to the application. In this situation
- we pretend we didn't yet consume the last input row; otherwise, if
- it happened to be the last row of the image, the application would
- think we were done. }
-
- if (not main^.suspended) then
- begin
- Dec(in_row_ctr);
- main^.suspended := TRUE;
- end;
- exit;
- end;
- { We did finish the row. Undo our little suspension hack if a previous
- call suspended; then mark the main buffer empty. }
-
- if (main^.suspended) then
- begin
- Inc(in_row_ctr);
- main^.suspended := FALSE;
- end;
- main^.rowgroup_ctr := 0;
- Inc(main^.cur_iMCU_row);
- end;
-end;
-
-
-{$ifdef FULL_MAIN_BUFFER_SUPPORTED}
-
-{ Process some data.
- This routine handles all of the modes that use a full-size buffer. }
-
-{METHODDEF}
-procedure process_data_buffer_main (cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- var in_row_ctr : JDIMENSION;
- in_rows_avail : JDIMENSION);
-var
- main : my_main_ptr;
- ci : int;
- compptr : jpeg_component_info_ptr;
- writing : boolean;
-begin
- main := my_main_ptr (cinfo^.main);
- writing := (main^.pass_mode <> JBUF_CRANK_DEST);
-
- while (main^.cur_iMCU_row < cinfo^.total_iMCU_rows) do
- begin
- { Realign the virtual buffers if at the start of an iMCU row. }
- if (main^.rowgroup_ctr = 0) then
- begin
- compptr := cinfo^.comp_info;
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- main^.buffer[ci] := cinfo^.mem^.access_virt_sarray
- (j_common_ptr (cinfo), main^.whole_image[ci],
- main^.cur_iMCU_row * (compptr^.v_samp_factor * DCTSIZE),
- JDIMENSION (compptr^.v_samp_factor * DCTSIZE), writing);
- Inc(compptr);
- end;
- { In a read pass, pretend we just read some source data. }
- if (not writing) then
- begin
- Inc(in_row_ctr, cinfo^.max_v_samp_factor * DCTSIZE);
- main^.rowgroup_ctr := DCTSIZE;
- end;
- end;
-
- { If a write pass, read input data until the current iMCU row is full. }
- { Note: preprocessor will pad if necessary to fill the last iMCU row. }
- if (writing) then
- begin
- cinfo^.prep^.pre_process_data (cinfo,
- input_buf, in_row_ctr, in_rows_avail,
- JSAMPIMAGE(@main^.buffer),
- main^.rowgroup_ctr,
- JDIMENSION (DCTSIZE));
-
- { Return to application if we need more data to fill the iMCU row. }
- if (main^.rowgroup_ctr < DCTSIZE) then
- exit;
- end;
-
- { Emit data, unless this is a sink-only pass. }
- if (main^.pass_mode <> JBUF_SAVE_SOURCE) then
- begin
- if (not cinfo^.coef^.compress_data (cinfo,
- JSAMPIMAGE(@main^.buffer))) then
- begin
- { If compressor did not consume the whole row, then we must need to
- suspend processing and return to the application. In this situation
- we pretend we didn't yet consume the last input row; otherwise, if
- it happened to be the last row of the image, the application would
- think we were done. }
-
- if (not main^.suspended) then
- begin
- Dec(in_row_ctr);
- main^.suspended := TRUE;
- end;
- exit;
- end;
- { We did finish the row. Undo our little suspension hack if a previous
- call suspended; then mark the main buffer empty. }
-
- if (main^.suspended) then
- begin
- Inc(in_row_ctr);
- main^.suspended := FALSE;
- end;
- end;
-
- { If get here, we are done with this iMCU row. Mark buffer empty. }
- main^.rowgroup_ctr := 0;
- Inc(main^.cur_iMCU_row);
- end;
-end;
-
-{$endif} { FULL_MAIN_BUFFER_SUPPORTED }
-
-
-{ Initialize main buffer controller. }
-
-{GLOBAL}
-procedure jinit_c_main_controller (cinfo : j_compress_ptr;
- need_full_buffer : boolean);
-var
- main : my_main_ptr;
- ci : int;
- compptr : jpeg_component_info_ptr;
-begin
- main := my_main_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_main_controller)) );
- cinfo^.main := jpeg_c_main_controller_ptr(main);
- main^.pub.start_pass := start_pass_main;
-
- { We don't need to create a buffer in raw-data mode. }
- if (cinfo^.raw_data_in) then
- exit;
-
- { Create the buffer. It holds downsampled data, so each component
- may be of a different size. }
-
- if (need_full_buffer) then
- begin
-{$ifdef FULL_MAIN_BUFFER_SUPPORTED}
- { Allocate a full-image virtual array for each component }
- { Note we pad the bottom to a multiple of the iMCU height }
- compptr := cinfo^.comp_info;
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- main^.whole_image[ci] := cinfo^.mem^.request_virt_sarray
- (j_common_ptr(cinfo), JPOOL_IMAGE, FALSE,
- compptr^.width_in_blocks * DCTSIZE,
- JDIMENSION (jround_up( long (compptr^.height_in_blocks),
- long (compptr^.v_samp_factor)) * DCTSIZE),
- JDIMENSION (compptr^.v_samp_factor * DCTSIZE));
- Inc(compptr);
- end;
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
-{$endif}
- end
- else
- begin
-{$ifdef FULL_MAIN_BUFFER_SUPPORTED}
- main^.whole_image[0] := NIL; { flag for no virtual arrays }
-{$endif}
- { Allocate a strip buffer for each component }
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- main^.buffer[ci] := cinfo^.mem^.alloc_sarray
- (j_common_ptr(cinfo), JPOOL_IMAGE,
- compptr^.width_in_blocks * DCTSIZE,
- JDIMENSION (compptr^.v_samp_factor * DCTSIZE));
- Inc(compptr);
- end;
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jcmarker.pas b/packages/base/pasjpeg/jcmarker.pas
deleted file mode 100644
index 038c235382..0000000000
--- a/packages/base/pasjpeg/jcmarker.pas
+++ /dev/null
@@ -1,724 +0,0 @@
-Unit jcmarker;
-
-{ This file contains routines to write JPEG datastream markers. }
-
-{ Original: jcmarker.c; Copyright (C) 1991-1998, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jinclude, jmorecfg, jerror,
- jdeferr, jpeglib, jutils;
-
-
-const
- { JPEG marker codes }
- M_SOF0 = $c0;
- M_SOF1 = $c1;
- M_SOF2 = $c2;
- M_SOF3 = $c3;
-
- M_SOF5 = $c5;
- M_SOF6 = $c6;
- M_SOF7 = $c7;
-
- M_JPG = $c8;
- M_SOF9 = $c9;
- M_SOF10 = $ca;
- M_SOF11 = $cb;
-
- M_SOF13 = $cd;
- M_SOF14 = $ce;
- M_SOF15 = $cf;
-
- M_DHT = $c4;
-
- M_DAC = $cc;
-
- M_RST0 = $d0;
- M_RST1 = $d1;
- M_RST2 = $d2;
- M_RST3 = $d3;
- M_RST4 = $d4;
- M_RST5 = $d5;
- M_RST6 = $d6;
- M_RST7 = $d7;
-
- M_SOI = $d8;
- M_EOI = $d9;
- M_SOS = $da;
- M_DQT = $db;
- M_DNL = $dc;
- M_DRI = $dd;
- M_DHP = $de;
- M_EXP = $df;
-
- M_APP0 = $e0;
- M_APP1 = $e1;
- M_APP2 = $e2;
- M_APP3 = $e3;
- M_APP4 = $e4;
- M_APP5 = $e5;
- M_APP6 = $e6;
- M_APP7 = $e7;
- M_APP8 = $e8;
- M_APP9 = $e9;
- M_APP10 = $ea;
- M_APP11 = $eb;
- M_APP12 = $ec;
- M_APP13 = $ed;
- M_APP14 = $ee;
- M_APP15 = $ef;
-
- M_JPG0 = $f0;
- M_JPG13 = $fd;
- M_COM = $fe;
-
- M_TEM = $01;
-
- M_ERROR = $100;
-
-type
- JPEG_MARKER = Word;
-
-{ Private state }
-
-type
- my_marker_ptr = ^my_marker_writer;
- my_marker_writer = record
- pub : jpeg_marker_writer; { public fields }
-
- last_restart_interval : uint; { last DRI value emitted; 0 after SOI }
- end;
-
-
-
-
-{GLOBAL}
-procedure jinit_marker_writer (cinfo : j_compress_ptr);
-
-implementation
-
-{ Basic output routines.
-
- Note that we do not support suspension while writing a marker.
- Therefore, an application using suspension must ensure that there is
- enough buffer space for the initial markers (typ. 600-700 bytes) before
- calling jpeg_start_compress, and enough space to write the trailing EOI
- (a few bytes) before calling jpeg_finish_compress. Multipass compression
- modes are not supported at all with suspension, so those two are the only
- points where markers will be written. }
-
-
-{LOCAL}
-procedure emit_byte (cinfo : j_compress_ptr; val : int);
-{ Emit a byte }
-var
- dest : jpeg_destination_mgr_ptr;
-begin
- dest := cinfo^.dest;
-
- dest^.next_output_byte^ := JOCTET(val);
- Inc(dest^.next_output_byte);
-
- Dec(dest^.free_in_buffer);
- if (dest^.free_in_buffer = 0) then
- begin
- if not dest^.empty_output_buffer(cinfo) then
- ERREXIT(j_common_ptr(cinfo), JERR_CANT_SUSPEND);
- end;
-end;
-
-
-{LOCAL}
-procedure emit_marker(cinfo : j_compress_ptr; mark : JPEG_MARKER);
-{ Emit a marker code }
-begin
- emit_byte(cinfo, $FF);
- emit_byte(cinfo, int(mark));
-end;
-
-
-{LOCAL}
-procedure emit_2bytes (cinfo : j_compress_ptr; value : int);
-{ Emit a 2-byte integer; these are always MSB first in JPEG files }
-begin
- emit_byte(cinfo, (value shr 8) and $FF);
- emit_byte(cinfo, value and $FF);
-end;
-
-
-{ Routines to write specific marker types. }
-
-{LOCAL}
-function emit_dqt (cinfo : j_compress_ptr; index : int) : int;
-{ Emit a DQT marker }
-{ Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking }
-var
- qtbl : JQUANT_TBL_PTR;
- prec : int;
- i : int;
-var
- qval : uint;
-begin
- qtbl := cinfo^.quant_tbl_ptrs[index];
- if (qtbl = NIL) then
- ERREXIT1(j_common_ptr(cinfo), JERR_NO_QUANT_TABLE, index);
-
- prec := 0;
- for i := 0 to Pred(DCTSIZE2) do
- begin
- if (qtbl^.quantval[i] > 255) then
- prec := 1;
- end;
-
- if not qtbl^.sent_table then
- begin
- emit_marker(cinfo, M_DQT);
-
- if (prec <> 0) then
- emit_2bytes(cinfo, DCTSIZE2*2 + 1 + 2)
- else
- emit_2bytes(cinfo, DCTSIZE2 + 1 + 2);
-
- emit_byte(cinfo, index + (prec shl 4));
-
- for i := 0 to Pred(DCTSIZE2) do
- begin
- { The table entries must be emitted in zigzag order. }
- qval := qtbl^.quantval[jpeg_natural_order[i]];
- if (prec <> 0) then
- emit_byte(cinfo, int(qval shr 8));
- emit_byte(cinfo, int(qval and $FF));
- end;
-
- qtbl^.sent_table := TRUE;
- end;
-
- emit_dqt := prec;
-end;
-
-
-{LOCAL}
-procedure emit_dht (cinfo : j_compress_ptr; index : int; is_ac : boolean);
-{ Emit a DHT marker }
-var
- htbl : JHUFF_TBL_PTR;
- length, i : int;
-begin
- if (is_ac) then
- begin
- htbl := cinfo^.ac_huff_tbl_ptrs[index];
- index := index + $10; { output index has AC bit set }
- end
- else
- begin
- htbl := cinfo^.dc_huff_tbl_ptrs[index];
- end;
-
- if (htbl = NIL) then
- ERREXIT1(j_common_ptr(cinfo), JERR_NO_HUFF_TABLE, index);
-
- if not htbl^.sent_table then
- begin
- emit_marker(cinfo, M_DHT);
-
- length := 0;
- for i := 1 to 16 do
- length := length + htbl^.bits[i];
-
- emit_2bytes(cinfo, length + 2 + 1 + 16);
- emit_byte(cinfo, index);
-
- for i := 1 to 16 do
- emit_byte(cinfo, htbl^.bits[i]);
-
- for i := 0 to Pred(length) do
- emit_byte(cinfo, htbl^.huffval[i]);
-
- htbl^.sent_table := TRUE;
- end;
-end;
-
-
-{LOCAL}
-procedure emit_dac (cinfo : j_compress_ptr);
-{ Emit a DAC marker }
-{ Since the useful info is so small, we want to emit all the tables in }
-{ one DAC marker. Therefore this routine does its own scan of the table. }
-{$ifdef C_ARITH_CODING_SUPPORTED}
-var
- dc_in_use : array[0..NUM_ARITH_TBLS] of byte;
- ac_in_use : array[0..NUM_ARITH_TBLS] of byte;
- length, i : int;
- compptr : jpeg_component_info_ptr;
-begin
- for i := 0 to pred(NUM_ARITH_TBLS) do
- begin
- dc_in_use[i] := 0;
- ac_in_use[i] := 0;
- end;
-
- for i := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[i];
- dc_in_use[compptr^.dc_tbl_no] := 1;
- ac_in_use[compptr^.ac_tbl_no] := 1;
- end;
-
- length := 0;
- for i := 0 to pred(NUM_ARITH_TBLS) do
- Inc(length, dc_in_use[i] + ac_in_use[i]);
-
- emit_marker(cinfo, M_DAC);
-
- emit_2bytes(cinfo, length*2 + 2);
-
- for i := 0 to pred(NUM_ARITH_TBLS) do
- begin
- if (dc_in_use[i] <> 0) then
- begin
- emit_byte(cinfo, i);
- emit_byte(cinfo, cinfo^.arith_dc_L[i] + (cinfo^.arith_dc_U[i] shl 4));
- end;
- if (ac_in_use[i] <> 0) then
- begin
- emit_byte(cinfo, i + $10);
- emit_byte(cinfo, cinfo^.arith_ac_K[i]);
- end;
- end;
-end;
-{$else}
-begin
-end;
-{$endif} {C_ARITH_CODING_SUPPORTED}
-
-
-{LOCAL}
-procedure emit_dri (cinfo : j_compress_ptr);
-{ Emit a DRI marker }
-begin
- emit_marker(cinfo, M_DRI);
-
- emit_2bytes(cinfo, 4); { fixed length }
-
- emit_2bytes(cinfo, int(cinfo^.restart_interval));
-end;
-
-
-{LOCAL}
-procedure emit_sof (cinfo : j_compress_ptr; code : JPEG_MARKER);
-{ Emit a SOF marker }
-var
- ci : int;
- compptr : jpeg_component_info_ptr;
-begin
- emit_marker(cinfo, code);
-
- emit_2bytes(cinfo, 3 * cinfo^.num_components + 2 + 5 + 1); { length }
-
- { Make sure image isn't bigger than SOF field can handle }
- if (long(cinfo^.image_height) > long(65535)) or
- (long(cinfo^.image_width) > long(65535)) then
- ERREXIT1(j_common_ptr(cinfo), JERR_IMAGE_TOO_BIG, uInt(65535));
-
- emit_byte(cinfo, cinfo^.data_precision);
- emit_2bytes(cinfo, int(cinfo^.image_height));
- emit_2bytes(cinfo, int(cinfo^.image_width));
-
- emit_byte(cinfo, cinfo^.num_components);
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to Pred(cinfo^.num_components) do
- begin
- emit_byte(cinfo, compptr^.component_id);
- emit_byte(cinfo, (compptr^.h_samp_factor shl 4) + compptr^.v_samp_factor);
- emit_byte(cinfo, compptr^.quant_tbl_no);
- Inc(compptr);
- end;
-end;
-
-
-{LOCAL}
-procedure emit_sos (cinfo : j_compress_ptr);
-{ Emit a SOS marker }
-var
- i, td, ta : int;
- compptr : jpeg_component_info_ptr;
-begin
- emit_marker(cinfo, M_SOS);
-
- emit_2bytes(cinfo, 2 * cinfo^.comps_in_scan + 2 + 1 + 3); { length }
-
- emit_byte(cinfo, cinfo^.comps_in_scan);
-
- for i := 0 to Pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[i];
- emit_byte(cinfo, compptr^.component_id);
- td := compptr^.dc_tbl_no;
- ta := compptr^.ac_tbl_no;
- if (cinfo^.progressive_mode) then
- begin
- { Progressive mode: only DC or only AC tables are used in one scan;
- furthermore, Huffman coding of DC refinement uses no table at all.
- We emit 0 for unused field(s); this is recommended by the P&M text
- but does not seem to be specified in the standard. }
-
- if (cinfo^.Ss = 0) then
- begin
- ta := 0; { DC scan }
- if (cinfo^.Ah <> 0) and not cinfo^.arith_code then
- td := 0; { no DC table either }
- end
- else
- begin
- td := 0; { AC scan }
- end;
- end;
- emit_byte(cinfo, (td shl 4) + ta);
- end;
-
- emit_byte(cinfo, cinfo^.Ss);
- emit_byte(cinfo, cinfo^.Se);
- emit_byte(cinfo, (cinfo^.Ah shl 4) + cinfo^.Al);
-end;
-
-
-{LOCAL}
-procedure emit_jfif_app0 (cinfo : j_compress_ptr);
-{ Emit a JFIF-compliant APP0 marker }
-{
- Length of APP0 block (2 bytes)
- Block ID (4 bytes - ASCII "JFIF")
- Zero byte (1 byte to terminate the ID string)
- Version Major, Minor (2 bytes - major first)
- Units (1 byte - $00 = none, $01 = inch, $02 = cm)
- Xdpu (2 bytes - dots per unit horizontal)
- Ydpu (2 bytes - dots per unit vertical)
- Thumbnail X size (1 byte)
- Thumbnail Y size (1 byte)
-}
-begin
- emit_marker(cinfo, M_APP0);
-
- emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); { length }
-
- emit_byte(cinfo, $4A); { Identifier: ASCII "JFIF" }
- emit_byte(cinfo, $46);
- emit_byte(cinfo, $49);
- emit_byte(cinfo, $46);
- emit_byte(cinfo, 0);
- emit_byte(cinfo, cinfo^.JFIF_major_version); { Version fields }
- emit_byte(cinfo, cinfo^.JFIF_minor_version);
- emit_byte(cinfo, cinfo^.density_unit); { Pixel size information }
- emit_2bytes(cinfo, int(cinfo^.X_density));
- emit_2bytes(cinfo, int(cinfo^.Y_density));
- emit_byte(cinfo, 0); { No thumbnail image }
- emit_byte(cinfo, 0);
-end;
-
-
-{LOCAL}
-procedure emit_adobe_app14 (cinfo : j_compress_ptr);
-{ Emit an Adobe APP14 marker }
-{
- Length of APP14 block (2 bytes)
- Block ID (5 bytes - ASCII "Adobe")
- Version Number (2 bytes - currently 100)
- Flags0 (2 bytes - currently 0)
- Flags1 (2 bytes - currently 0)
- Color transform (1 byte)
-
- Although Adobe TN 5116 mentions Version = 101, all the Adobe files
- now in circulation seem to use Version = 100, so that's what we write.
-
- We write the color transform byte as 1 if the JPEG color space is
- YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with
- whether the encoder performed a transformation, which is pretty useless.
-}
-begin
- emit_marker(cinfo, M_APP14);
-
- emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); { length }
-
- emit_byte(cinfo, $41); { Identifier: ASCII "Adobe" }
- emit_byte(cinfo, $64);
- emit_byte(cinfo, $6F);
- emit_byte(cinfo, $62);
- emit_byte(cinfo, $65);
- emit_2bytes(cinfo, 100); { Version }
- emit_2bytes(cinfo, 0); { Flags0 }
- emit_2bytes(cinfo, 0); { Flags1 }
- case (cinfo^.jpeg_color_space) of
- JCS_YCbCr:
- emit_byte(cinfo, 1); { Color transform = 1 }
- JCS_YCCK:
- emit_byte(cinfo, 2); { Color transform = 2 }
- else
- emit_byte(cinfo, 0); { Color transform = 0 }
- end;
-end;
-
-
-{ These routines allow writing an arbitrary marker with parameters.
- The only intended use is to emit COM or APPn markers after calling
- write_file_header and before calling write_frame_header.
- Other uses are not guaranteed to produce desirable results.
- Counting the parameter bytes properly is the caller's responsibility. }
-
-{METHODDEF}
-procedure write_marker_header (cinfo : j_compress_ptr;
- marker : int;
- datalen : uint); far;
-{ Emit an arbitrary marker header }
-begin
- if (datalen > uint(65533)) then { safety check }
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_LENGTH);
-
- emit_marker(cinfo, JPEG_MARKER(marker));
-
- emit_2bytes(cinfo, int(datalen + 2)); { total length }
-end;
-
-{METHODDEF}
-procedure write_marker_byte (cinfo : j_compress_ptr; val : int); far;
-{ Emit one byte of marker parameters following write_marker_header }
-begin
- emit_byte(cinfo, val);
-end;
-
-{ Write datastream header.
- This consists of an SOI and optional APPn markers.
- We recommend use of the JFIF marker, but not the Adobe marker,
- when using YCbCr or grayscale data. The JFIF marker should NOT
- be used for any other JPEG colorspace. The Adobe marker is helpful
- to distinguish RGB, CMYK, and YCCK colorspaces.
- Note that an application can write additional header markers after
- jpeg_start_compress returns. }
-
-
-{METHODDEF}
-procedure write_file_header (cinfo : j_compress_ptr); far;
-var
- marker : my_marker_ptr;
-begin
- marker := my_marker_ptr(cinfo^.marker);
-
- emit_marker(cinfo, M_SOI); { first the SOI }
-
- { SOI is defined to reset restart interval to 0 }
- marker^.last_restart_interval := 0;
-
- if (cinfo^.write_JFIF_header) then { next an optional JFIF APP0 }
- emit_jfif_app0(cinfo);
- if (cinfo^.write_Adobe_marker) then { next an optional Adobe APP14 }
- emit_adobe_app14(cinfo);
-end;
-
-
-{ Write frame header.
- This consists of DQT and SOFn markers.
- Note that we do not emit the SOF until we have emitted the DQT(s).
- This avoids compatibility problems with incorrect implementations that
- try to error-check the quant table numbers as soon as they see the SOF. }
-
-
-{METHODDEF}
-procedure write_frame_header (cinfo : j_compress_ptr); far;
-var
- ci, prec : int;
- is_baseline : boolean;
- compptr : jpeg_component_info_ptr;
-begin
- { Emit DQT for each quantization table.
- Note that emit_dqt() suppresses any duplicate tables. }
-
- prec := 0;
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to Pred(cinfo^.num_components) do
- begin
- prec := prec + emit_dqt(cinfo, compptr^.quant_tbl_no);
- Inc(compptr);
- end;
- { now prec is nonzero iff there are any 16-bit quant tables. }
-
- { Check for a non-baseline specification.
- Note we assume that Huffman table numbers won't be changed later. }
-
- if (cinfo^.arith_code) or (cinfo^.progressive_mode)
- or (cinfo^.data_precision <> 8) then
- begin
- is_baseline := FALSE;
- end
- else
- begin
- is_baseline := TRUE;
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to Pred(cinfo^.num_components) do
- begin
- if (compptr^.dc_tbl_no > 1) or (compptr^.ac_tbl_no > 1) then
- is_baseline := FALSE;
- Inc(compptr);
- end;
- if (prec <> 0) and (is_baseline) then
- begin
- is_baseline := FALSE;
- { If it's baseline except for quantizer size, warn the user }
- {$IFDEF DEBUG}
- TRACEMS(j_common_ptr(cinfo), 0, JTRC_16BIT_TABLES);
- {$ENDIF}
- end;
- end;
-
- { Emit the proper SOF marker }
- if (cinfo^.arith_code) then
- begin
- emit_sof(cinfo, M_SOF9); { SOF code for arithmetic coding }
- end
- else
- begin
- if (cinfo^.progressive_mode) then
- emit_sof(cinfo, M_SOF2) { SOF code for progressive Huffman }
- else if (is_baseline) then
- emit_sof(cinfo, M_SOF0) { SOF code for baseline implementation }
- else
- emit_sof(cinfo, M_SOF1); { SOF code for non-baseline Huffman file }
- end;
-end;
-
-
-{ Write scan header.
- This consists of DHT or DAC markers, optional DRI, and SOS.
- Compressed data will be written following the SOS. }
-
-{METHODDEF}
-procedure write_scan_header (cinfo : j_compress_ptr); far;
-var
- marker : my_marker_ptr;
- i : int;
- compptr : jpeg_component_info_ptr;
-begin
- marker := my_marker_ptr(cinfo^.marker);
- if (cinfo^.arith_code) then
- begin
- { Emit arith conditioning info. We may have some duplication
- if the file has multiple scans, but it's so small it's hardly
- worth worrying about. }
- emit_dac(cinfo);
- end
- else
- begin
- { Emit Huffman tables.
- Note that emit_dht() suppresses any duplicate tables. }
- for i := 0 to Pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[i];
- if (cinfo^.progressive_mode) then
- begin
- { Progressive mode: only DC or only AC tables are used in one scan }
- if (cinfo^.Ss = 0) then
- begin
- if (cinfo^.Ah = 0) then { DC needs no table for refinement scan }
- emit_dht(cinfo, compptr^.dc_tbl_no, FALSE);
- end
- else
- begin
- emit_dht(cinfo, compptr^.ac_tbl_no, TRUE);
- end;
- end
- else
- begin
- { Sequential mode: need both DC and AC tables }
- emit_dht(cinfo, compptr^.dc_tbl_no, FALSE);
- emit_dht(cinfo, compptr^.ac_tbl_no, TRUE);
- end;
- end;
- end;
-
- { Emit DRI if required --- note that DRI value could change for each scan.
- We avoid wasting space with unnecessary DRIs, however. }
-
- if (cinfo^.restart_interval <> marker^.last_restart_interval) then
- begin
- emit_dri(cinfo);
- marker^.last_restart_interval := cinfo^.restart_interval;
- end;
-
- emit_sos(cinfo);
-end;
-
-
-
-{ Write datastream trailer. }
-
-
-{METHODDEF}
-procedure write_file_trailer (cinfo : j_compress_ptr); far;
-begin
- emit_marker(cinfo, M_EOI);
-end;
-
-
-{ Write an abbreviated table-specification datastream.
- This consists of SOI, DQT and DHT tables, and EOI.
- Any table that is defined and not marked sent_table = TRUE will be
- emitted. Note that all tables will be marked sent_table = TRUE at exit. }
-
-
-{METHODDEF}
-procedure write_tables_only (cinfo : j_compress_ptr); far;
-var
- i : int;
-begin
- emit_marker(cinfo, M_SOI);
-
- for i := 0 to Pred(NUM_QUANT_TBLS) do
- begin
- if (cinfo^.quant_tbl_ptrs[i] <> NIL) then
- emit_dqt(cinfo, i); { dummy := ... }
- end;
-
- if (not cinfo^.arith_code) then
- begin
- for i := 0 to Pred(NUM_HUFF_TBLS) do
- begin
- if (cinfo^.dc_huff_tbl_ptrs[i] <> NIL) then
- emit_dht(cinfo, i, FALSE);
- if (cinfo^.ac_huff_tbl_ptrs[i] <> NIL) then
- emit_dht(cinfo, i, TRUE);
- end;
- end;
-
- emit_marker(cinfo, M_EOI);
-end;
-
-
-{ Initialize the marker writer module. }
-
-{GLOBAL}
-procedure jinit_marker_writer (cinfo : j_compress_ptr);
-var
- marker : my_marker_ptr;
-begin
- { Create the subobject }
- marker := my_marker_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_marker_writer)) );
- cinfo^.marker := jpeg_marker_writer_ptr(marker);
- { Initialize method pointers }
- marker^.pub.write_file_header := write_file_header;
- marker^.pub.write_frame_header := write_frame_header;
- marker^.pub.write_scan_header := write_scan_header;
- marker^.pub.write_file_trailer := write_file_trailer;
- marker^.pub.write_tables_only := write_tables_only;
- marker^.pub.write_marker_header := write_marker_header;
- marker^.pub.write_marker_byte := write_marker_byte;
- { Initialize private state }
- marker^.last_restart_interval := 0;
-end;
-
-
-end.
diff --git a/packages/base/pasjpeg/jcmaster.pas b/packages/base/pasjpeg/jcmaster.pas
deleted file mode 100644
index ee95fd58fd..0000000000
--- a/packages/base/pasjpeg/jcmaster.pas
+++ /dev/null
@@ -1,702 +0,0 @@
-Unit JcMaster;
-
-{ This file contains master control logic for the JPEG compressor.
- These routines are concerned with parameter validation, initial setup,
- and inter-pass control (determining the number of passes and the work
- to be done in each pass). }
-
-{ Original: jcmaster.c ; Copyright (C) 1991-1997, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jutils,
- jpeglib;
-
-
-{ Initialize master compression control. }
-
-{GLOBAL}
-procedure jinit_c_master_control (cinfo : j_compress_ptr;
- transcode_only : boolean);
-
-implementation
-
-{ Private state }
-
-type
- c_pass_type = (
- main_pass, { input data, also do first output step }
- huff_opt_pass, { Huffman code optimization pass }
- output_pass { data output pass }
- );
-
-type
- my_master_ptr = ^my_comp_master;
- my_comp_master = record
- pub : jpeg_comp_master; { public fields }
-
- pass_type : c_pass_type; { the type of the current pass }
-
- pass_number : int; { # of passes completed }
- total_passes : int; { total # of passes needed }
-
- scan_number : int; { current index in scan_info[] }
- end;
-
-
-{ Support routines that do various essential calculations. }
-
-{LOCAL}
-procedure initial_setup (cinfo : j_compress_ptr);
-{ Do computations that are needed before master selection phase }
-var
- ci : int;
- compptr : jpeg_component_info_ptr;
- samplesperrow : long;
- jd_samplesperrow : JDIMENSION;
-begin
-
- { Sanity check on image dimensions }
- if (cinfo^.image_height <= 0) or (cinfo^.image_width <= 0) or
- (cinfo^.num_components <= 0) or (cinfo^.input_components <= 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_EMPTY_IMAGE);
-
- { Make sure image isn't bigger than I can handle }
- if ( long(cinfo^.image_height) > long(JPEG_MAX_DIMENSION)) or
- ( long(cinfo^.image_width) > long(JPEG_MAX_DIMENSION)) then
- ERREXIT1(j_common_ptr(cinfo), JERR_IMAGE_TOO_BIG,
- uInt(JPEG_MAX_DIMENSION));
-
- { Width of an input scanline must be representable as JDIMENSION. }
- samplesperrow := long (cinfo^.image_width) * long (cinfo^.input_components);
- jd_samplesperrow := JDIMENSION (samplesperrow);
- if ( long(jd_samplesperrow) <> samplesperrow) then
- ERREXIT(j_common_ptr(cinfo), JERR_WIDTH_OVERFLOW);
-
- { For now, precision must match compiled-in value... }
- if (cinfo^.data_precision <> BITS_IN_JSAMPLE) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_PRECISION, cinfo^.data_precision);
-
- { Check that number of components won't exceed internal array sizes }
- if (cinfo^.num_components > MAX_COMPONENTS) then
- ERREXIT2(j_common_ptr(cinfo), JERR_COMPONENT_COUNT, cinfo^.num_components,
- MAX_COMPONENTS);
-
- { Compute maximum sampling factors; check factor validity }
- cinfo^.max_h_samp_factor := 1;
- cinfo^.max_v_samp_factor := 1;
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- if (compptr^.h_samp_factor<=0) or (compptr^.h_samp_factor>MAX_SAMP_FACTOR)
- or (compptr^.v_samp_factor<=0) or (compptr^.v_samp_factor>MAX_SAMP_FACTOR) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_SAMPLING);
- { MAX }
- if cinfo^.max_h_samp_factor > compptr^.h_samp_factor then
- cinfo^.max_h_samp_factor := cinfo^.max_h_samp_factor
- else
- cinfo^.max_h_samp_factor := compptr^.h_samp_factor;
- { MAX }
- if cinfo^.max_v_samp_factor > compptr^.v_samp_factor then
- cinfo^.max_v_samp_factor := cinfo^.max_v_samp_factor
- else
- cinfo^.max_v_samp_factor := compptr^.v_samp_factor;
- Inc(compptr);
- end;
-
- { Compute dimensions of components }
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- { Fill in the correct component_index value; don't rely on application }
- compptr^.component_index := ci;
- { For compression, we never do DCT scaling. }
- compptr^.DCT_scaled_size := DCTSIZE;
- { Size in DCT blocks }
- compptr^.width_in_blocks := JDIMENSION (
- jdiv_round_up(long (cinfo^.image_width) * long (compptr^.h_samp_factor),
- long (cinfo^.max_h_samp_factor * DCTSIZE)) );
- compptr^.height_in_blocks := JDIMENSION (
- jdiv_round_up(long (cinfo^.image_height) * long (compptr^.v_samp_factor),
- long (cinfo^.max_v_samp_factor * DCTSIZE)) );
- { Size in samples }
- compptr^.downsampled_width := JDIMENSION (
- jdiv_round_up(long(cinfo^.image_width) * long(compptr^.h_samp_factor),
- long(cinfo^.max_h_samp_factor)) );
- compptr^.downsampled_height := JDIMENSION (
- jdiv_round_up(long (cinfo^.image_height) * long(compptr^.v_samp_factor),
- long (cinfo^.max_v_samp_factor)) );
- { Mark component needed (this flag isn't actually used for compression) }
- compptr^.component_needed := TRUE;
- Inc(compptr);
- end;
-
- { Compute number of fully interleaved MCU rows (number of times that
- main controller will call coefficient controller). }
-
- cinfo^.total_iMCU_rows := JDIMENSION (
- jdiv_round_up(long (cinfo^.image_height),
- long (cinfo^.max_v_samp_factor*DCTSIZE)) );
-end;
-
-
-{$ifdef C_MULTISCAN_FILES_SUPPORTED}
-
-{LOCAL}
-procedure validate_script (cinfo : j_compress_ptr);
-{ Verify that the scan script in cinfo^.scan_info[] is valid; also
- determine whether it uses progressive JPEG, and set cinfo^.progressive_mode. }
-type
- IntRow = array[0..DCTSIZE2-1] of int;
- introw_ptr = ^IntRow;
-var
- {const}scanptr : jpeg_scan_info_ptr;
- scanno, ncomps, ci, coefi, thisi : int;
- Ss, Se, Ah, Al : int;
- component_sent : array[0..MAX_COMPONENTS-1] of boolean;
-{$ifdef C_PROGRESSIVE_SUPPORTED}
- last_bitpos_int_ptr : int_ptr;
- last_bitpos_ptr : introw_ptr;
- last_bitpos : array[0..MAX_COMPONENTS-1] of IntRow;
- { -1 until that coefficient has been seen; then last Al for it }
- { The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that
- seems wrong: the upper bound ought to depend on data precision.
- Perhaps they really meant 0..N+1 for N-bit precision.
- Here we allow 0..10 for 8-bit data; Al larger than 10 results in
- out-of-range reconstructed DC values during the first DC scan,
- which might cause problems for some decoders. }
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-const
- MAX_AH_AL = 10;
-{$else}
-const
- MAX_AH_AL = 13;
-{$endif}
-{$endif}
-begin
-
- if (cinfo^.num_scans <= 0) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_SCAN_SCRIPT, 0);
-
- { For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1;
- for progressive JPEG, no scan can have this. }
-
- scanptr := cinfo^.scan_info;
- if (scanptr^.Ss <> 0) or (scanptr^.Se <> DCTSIZE2-1) then
- begin
-{$ifdef C_PROGRESSIVE_SUPPORTED}
- cinfo^.progressive_mode := TRUE;
- last_bitpos_int_ptr := @(last_bitpos[0][0]);
- for ci := 0 to pred(cinfo^.num_components) do
- for coefi := 0 to pred(DCTSIZE2) do
- begin
- last_bitpos_int_ptr^ := -1;
- Inc(last_bitpos_int_ptr);
- end;
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end
- else
- begin
- cinfo^.progressive_mode := FALSE;
- for ci := 0 to pred(cinfo^.num_components) do
- component_sent[ci] := FALSE;
- end;
-
- for scanno := 1 to cinfo^.num_scans do
- begin
- { Validate component indexes }
- ncomps := scanptr^.comps_in_scan;
- if (ncomps <= 0) or (ncomps > MAX_COMPS_IN_SCAN) then
- ERREXIT2(j_common_ptr(cinfo), JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
- for ci := 0 to pred(ncomps) do
- begin
- thisi := scanptr^.component_index[ci];
- if (thisi < 0) or (thisi >= cinfo^.num_components) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_SCAN_SCRIPT, scanno);
- { Components must appear in SOF order within each scan }
- if (ci > 0) and (thisi <= scanptr^.component_index[ci-1]) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_SCAN_SCRIPT, scanno);
- end;
- { Validate progression parameters }
- Ss := scanptr^.Ss;
- Se := scanptr^.Se;
- Ah := scanptr^.Ah;
- Al := scanptr^.Al;
- if (cinfo^.progressive_mode) then
- begin
-{$ifdef C_PROGRESSIVE_SUPPORTED}
- if (Ss < 0) or (Ss >= DCTSIZE2) or (Se < Ss) or (Se >= DCTSIZE2) or
- (Ah < 0) or (Ah > MAX_AH_AL) or (Al < 0) or (Al > MAX_AH_AL) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_PROG_SCRIPT, scanno);
-
- if (Ss < 0) or (Ss >= DCTSIZE2) or (Se < Ss) or (Se >= DCTSIZE2)
- or (Ah < 0) or (Ah > MAX_AH_AL) or (Al < 0) or (Al > MAX_AH_AL) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_PROG_SCRIPT, scanno);
- if (Ss = 0) then
- begin
- if (Se <> 0) then { DC and AC together not OK }
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_PROG_SCRIPT, scanno);
- end
- else
- begin
- if (ncomps <> 1) then { AC scans must be for only one component }
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_PROG_SCRIPT, scanno);
- end;
- for ci := 0 to pred(ncomps) do
- begin
- last_bitpos_ptr := @( last_bitpos[scanptr^.component_index[ci]]);
- if (Ss <> 0) and (last_bitpos_ptr^[0] < 0) then { AC without prior DC scan }
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_PROG_SCRIPT, scanno);
- for coefi := Ss to Se do
- begin
- if (last_bitpos_ptr^[coefi] < 0) then
- begin
- { first scan of this coefficient }
- if (Ah <> 0) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_PROG_SCRIPT, scanno);
- end
- else
- begin
- { not first scan }
- if (Ah <> last_bitpos_ptr^[coefi]) or (Al <> Ah-1) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_PROG_SCRIPT, scanno);
- end;
- last_bitpos_ptr^[coefi] := Al;
- end;
- end;
-{$endif}
- end
- else
- begin
- { For sequential JPEG, all progression parameters must be these: }
- if (Ss <> 0) or (Se <> DCTSIZE2-1) or (Ah <> 0) or (Al <> 0) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_PROG_SCRIPT, scanno);
- { Make sure components are not sent twice }
- for ci := 0 to pred(ncomps) do
- begin
- thisi := scanptr^.component_index[ci];
- if (component_sent[thisi]) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_SCAN_SCRIPT, scanno);
- component_sent[thisi] := TRUE;
- end;
- end;
- Inc(scanptr);
- end;
-
- { Now verify that everything got sent. }
- if (cinfo^.progressive_mode) then
- begin
-{$ifdef C_PROGRESSIVE_SUPPORTED
- { For progressive mode, we only check that at least some DC data
- got sent for each component; the spec does not require that all bits
- of all coefficients be transmitted. Would it be wiser to enforce
- transmission of all coefficient bits?? }
-
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- if (last_bitpos[ci][0] < 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_MISSING_DATA);
- end;
-{$endif}
- end
- else
- begin
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- if (not component_sent[ci]) then
- ERREXIT(j_common_ptr(cinfo), JERR_MISSING_DATA);
- end;
- end;
-end;
-
-{$endif} { C_MULTISCAN_FILES_SUPPORTED }
-
-
-{LOCAL}
-procedure select_scan_parameters (cinfo : j_compress_ptr);
-{ Set up the scan parameters for the current scan }
-var
- master : my_master_ptr;
- {const} scanptr : jpeg_scan_info_ptr;
- ci : int;
-var
- comp_infos : jpeg_component_info_list_ptr;
-begin
-{$ifdef C_MULTISCAN_FILES_SUPPORTED}
- if (cinfo^.scan_info <> NIL) then
- begin
- { Prepare for current scan --- the script is already validated }
- master := my_master_ptr (cinfo^.master);
- scanptr := cinfo^.scan_info;
- Inc(scanptr, master^.scan_number);
-
- cinfo^.comps_in_scan := scanptr^.comps_in_scan;
- comp_infos := cinfo^.comp_info;
- for ci := 0 to pred(scanptr^.comps_in_scan) do
- begin
- cinfo^.cur_comp_info[ci] :=
- @(comp_infos^[scanptr^.component_index[ci]]);
- end;
- cinfo^.Ss := scanptr^.Ss;
- cinfo^.Se := scanptr^.Se;
- cinfo^.Ah := scanptr^.Ah;
- cinfo^.Al := scanptr^.Al;
- end
- else
-{$endif}
- begin
- { Prepare for single sequential-JPEG scan containing all components }
- if (cinfo^.num_components > MAX_COMPS_IN_SCAN) then
- ERREXIT2(j_common_ptr(cinfo), JERR_COMPONENT_COUNT, cinfo^.num_components,
- MAX_COMPS_IN_SCAN);
- cinfo^.comps_in_scan := cinfo^.num_components;
- comp_infos := cinfo^.comp_info;
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- cinfo^.cur_comp_info[ci] := @(comp_infos^[ci]);
- end;
- cinfo^.Ss := 0;
- cinfo^.Se := DCTSIZE2-1;
- cinfo^.Ah := 0;
- cinfo^.Al := 0;
- end;
-end;
-
-
-{LOCAL}
-procedure per_scan_setup (cinfo : j_compress_ptr);
-{ Do computations that are needed before processing a JPEG scan }
-{ cinfo^.comps_in_scan and cinfo^.cur_comp_info[] are already set }
-var
- ci, mcublks, tmp : int;
- compptr : jpeg_component_info_ptr;
- nominal : long;
-begin
- if (cinfo^.comps_in_scan = 1) then
- begin
-
- { Noninterleaved (single-component) scan }
- compptr := cinfo^.cur_comp_info[0];
-
- { Overall image size in MCUs }
- cinfo^.MCUs_per_row := compptr^.width_in_blocks;
- cinfo^.MCU_rows_in_scan := compptr^.height_in_blocks;
-
- { For noninterleaved scan, always one block per MCU }
- compptr^.MCU_width := 1;
- compptr^.MCU_height := 1;
- compptr^.MCU_blocks := 1;
- compptr^.MCU_sample_width := DCTSIZE;
- compptr^.last_col_width := 1;
- { 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 (compptr^.height_in_blocks mod compptr^.v_samp_factor);
- if (tmp = 0) then
- tmp := compptr^.v_samp_factor;
- compptr^.last_row_height := tmp;
-
- { Prepare array describing MCU composition }
- cinfo^.blocks_in_MCU := 1;
- cinfo^.MCU_membership[0] := 0;
-
- end
- else
- begin
-
- { Interleaved (multi-component) scan }
- if (cinfo^.comps_in_scan <= 0) or
- (cinfo^.comps_in_scan > MAX_COMPS_IN_SCAN) then
- ERREXIT2(j_common_ptr(cinfo), JERR_COMPONENT_COUNT,
- cinfo^.comps_in_scan, MAX_COMPS_IN_SCAN);
-
- { Overall image size in MCUs }
- cinfo^.MCUs_per_row := JDIMENSION (
- jdiv_round_up( long (cinfo^.image_width),
- long (cinfo^.max_h_samp_factor*DCTSIZE)) );
- cinfo^.MCU_rows_in_scan := JDIMENSION (
- jdiv_round_up( long (cinfo^.image_height),
- long (cinfo^.max_v_samp_factor*DCTSIZE)) );
-
- cinfo^.blocks_in_MCU := 0;
-
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- { Sampling factors give # of blocks of component in each MCU }
- compptr^.MCU_width := compptr^.h_samp_factor;
- compptr^.MCU_height := compptr^.v_samp_factor;
- 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 (compptr^.width_in_blocks mod compptr^.MCU_width);
- if (tmp = 0) then
- tmp := compptr^.MCU_width;
- compptr^.last_col_width := tmp;
- tmp := int (compptr^.height_in_blocks mod compptr^.MCU_height);
- if (tmp = 0) then
- tmp := compptr^.MCU_height;
- compptr^.last_row_height := tmp;
- { Prepare array describing MCU composition }
- mcublks := compptr^.MCU_blocks;
- if (cinfo^.blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_MCU_SIZE);
- while (mcublks > 0) do
- begin
- Dec(mcublks);
- cinfo^.MCU_membership[cinfo^.blocks_in_MCU] := ci;
- Inc(cinfo^.blocks_in_MCU);
- end;
- end;
-
- end;
-
- { Convert restart specified in rows to actual MCU count. }
- { Note that count must fit in 16 bits, so we provide limiting. }
- if (cinfo^.restart_in_rows > 0) then
- begin
- nominal := long(cinfo^.restart_in_rows) * long(cinfo^.MCUs_per_row);
- if nominal < long(65535) then
- cinfo^.restart_interval := uInt (nominal)
- else
- cinfo^.restart_interval := long(65535);
- end;
-end;
-
-
-{ Per-pass setup.
- This is called at the beginning of each pass. We determine which modules
- will be active during this pass and give them appropriate start_pass calls.
- We also set is_last_pass to indicate whether any more passes will be
- required. }
-
-{METHODDEF}
-procedure prepare_for_pass (cinfo : j_compress_ptr); far;
-var
- master : my_master_ptr;
-var
- fallthrough : boolean;
-begin
- master := my_master_ptr (cinfo^.master);
- fallthrough := true;
-
- case (master^.pass_type) of
- main_pass:
- begin
- { Initial pass: will collect input data, and do either Huffman
- optimization or data output for the first scan. }
- select_scan_parameters(cinfo);
- per_scan_setup(cinfo);
- if (not cinfo^.raw_data_in) then
- begin
- cinfo^.cconvert^.start_pass (cinfo);
- cinfo^.downsample^.start_pass (cinfo);
- cinfo^.prep^.start_pass (cinfo, JBUF_PASS_THRU);
- end;
- cinfo^.fdct^.start_pass (cinfo);
- cinfo^.entropy^.start_pass (cinfo, cinfo^.optimize_coding);
- if master^.total_passes > 1 then
- cinfo^.coef^.start_pass (cinfo, JBUF_SAVE_AND_PASS)
- else
- cinfo^.coef^.start_pass (cinfo, JBUF_PASS_THRU);
- cinfo^.main^.start_pass (cinfo, JBUF_PASS_THRU);
- if (cinfo^.optimize_coding) then
- begin
- { No immediate data output; postpone writing frame/scan headers }
- master^.pub.call_pass_startup := FALSE;
- end
- else
- begin
- { Will write frame/scan headers at first jpeg_write_scanlines call }
- master^.pub.call_pass_startup := TRUE;
- end;
- end;
-{$ifdef ENTROPY_OPT_SUPPORTED}
- huff_opt_pass,
- output_pass:
- begin
- if (master^.pass_type = huff_opt_pass) then
- begin
- { Do Huffman optimization for a scan after the first one. }
- select_scan_parameters(cinfo);
- per_scan_setup(cinfo);
- if (cinfo^.Ss <> 0) or (cinfo^.Ah = 0) or (cinfo^.arith_code) then
- begin
- cinfo^.entropy^.start_pass (cinfo, TRUE);
- cinfo^.coef^.start_pass (cinfo, JBUF_CRANK_DEST);
- master^.pub.call_pass_startup := FALSE;
- fallthrough := false;
- end;
- { Special case: Huffman DC refinement scans need no Huffman table
- and therefore we can skip the optimization pass for them. }
- if fallthrough then
- begin
- master^.pass_type := output_pass;
- Inc(master^.pass_number);
- {FALLTHROUGH}
- end;
- end;
-{$else}
- output_pass:
- begin
-{$endif}
- if fallthrough then
- begin
- { Do a data-output pass. }
- { We need not repeat per-scan setup if prior optimization pass did it. }
- if (not cinfo^.optimize_coding) then
- begin
- select_scan_parameters(cinfo);
- per_scan_setup(cinfo);
- end;
- cinfo^.entropy^.start_pass (cinfo, FALSE);
- cinfo^.coef^.start_pass (cinfo, JBUF_CRANK_DEST);
- { We emit frame/scan headers now }
- if (master^.scan_number = 0) then
- cinfo^.marker^.write_frame_header (cinfo);
- cinfo^.marker^.write_scan_header (cinfo);
- master^.pub.call_pass_startup := FALSE;
- end;
- end;
- else
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
- end;
-
- master^.pub.is_last_pass := (master^.pass_number = master^.total_passes-1);
-
- { Set up progress monitor's pass info if present }
- if (cinfo^.progress <> NIL) then
- begin
- cinfo^.progress^.completed_passes := master^.pass_number;
- cinfo^.progress^.total_passes := master^.total_passes;
- end;
-end;
-
-
-{ Special start-of-pass hook.
- This is called by jpeg_write_scanlines if call_pass_startup is TRUE.
- In single-pass processing, we need this hook because we don't want to
- write frame/scan headers during jpeg_start_compress; we want to let the
- application write COM markers etc. between jpeg_start_compress and the
- jpeg_write_scanlines loop.
- In multi-pass processing, this routine is not used. }
-
-{METHODDEF}
-procedure pass_startup (cinfo : j_compress_ptr); far;
-begin
- cinfo^.master^.call_pass_startup := FALSE; { reset flag so call only once }
-
- cinfo^.marker^.write_frame_header (cinfo);
- cinfo^.marker^.write_scan_header (cinfo);
-end;
-
-
-{ Finish up at end of pass. }
-
-{METHODDEF}
-procedure finish_pass_master (cinfo : j_compress_ptr); far;
-var
- master : my_master_ptr;
-begin
- master := my_master_ptr (cinfo^.master);
-
- { The entropy coder always needs an end-of-pass call,
- either to analyze statistics or to flush its output buffer. }
- cinfo^.entropy^.finish_pass (cinfo);
-
- { Update state for next pass }
- case (master^.pass_type) of
- main_pass:
- begin
- { next pass is either output of scan 0 (after optimization)
- or output of scan 1 (if no optimization). }
-
- master^.pass_type := output_pass;
- if (not cinfo^.optimize_coding) then
- Inc(master^.scan_number);
- end;
- huff_opt_pass:
- { next pass is always output of current scan }
- master^.pass_type := output_pass;
- output_pass:
- begin
- { next pass is either optimization or output of next scan }
- if (cinfo^.optimize_coding) then
- master^.pass_type := huff_opt_pass;
- Inc(master^.scan_number);
- end;
- end;
-
- Inc(master^.pass_number);
-end;
-
-
-{ Initialize master compression control. }
-
-{GLOBAL}
-procedure jinit_c_master_control (cinfo : j_compress_ptr;
- transcode_only : boolean);
-var
- master : my_master_ptr;
-begin
- master := my_master_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_comp_master)) );
- cinfo^.master := jpeg_comp_master_ptr(master);
- master^.pub.prepare_for_pass := prepare_for_pass;
- master^.pub.pass_startup := pass_startup;
- master^.pub.finish_pass := finish_pass_master;
- master^.pub.is_last_pass := FALSE;
-
- { Validate parameters, determine derived values }
- initial_setup(cinfo);
-
- if (cinfo^.scan_info <> NIL) then
- begin
-{$ifdef C_MULTISCAN_FILES_SUPPORTED}
- validate_script(cinfo);
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end
- else
- begin
- cinfo^.progressive_mode := FALSE;
- cinfo^.num_scans := 1;
- end;
-
- if (cinfo^.progressive_mode) then { TEMPORARY HACK ??? }
- cinfo^.optimize_coding := TRUE; { assume default tables no good for progressive mode }
-
- { Initialize my private state }
- if (transcode_only) then
- begin
- { no main pass in transcoding }
- if (cinfo^.optimize_coding) then
- master^.pass_type := huff_opt_pass
- else
- master^.pass_type := output_pass;
- end
- else
- begin
- { for normal compression, first pass is always this type: }
- master^.pass_type := main_pass;
- end;
- master^.scan_number := 0;
- master^.pass_number := 0;
- if (cinfo^.optimize_coding) then
- master^.total_passes := cinfo^.num_scans * 2
- else
- master^.total_passes := cinfo^.num_scans;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jcomapi.pas b/packages/base/pasjpeg/jcomapi.pas
deleted file mode 100644
index 40b2b3826f..0000000000
--- a/packages/base/pasjpeg/jcomapi.pas
+++ /dev/null
@@ -1,130 +0,0 @@
-Unit JCOMapi;
-
-{ This file contains application interface routines that are used for both
- compression and decompression. }
-
-{ Original: jcomapi.c; Copyright (C) 1994-1997, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jpeglib;
-
-{ Abort processing of a JPEG compression or decompression operation,
- but don't destroy the object itself. }
-
-{GLOBAL}
-procedure jpeg_abort (cinfo : j_common_ptr);
-
-
-{ Destruction of a JPEG object. }
-
-{GLOBAL}
-procedure jpeg_destroy (cinfo : j_common_ptr);
-
-{GLOBAL}
-function jpeg_alloc_quant_table (cinfo : j_common_ptr) : JQUANT_TBL_PTR;
-
-{GLOBAL}
-function jpeg_alloc_huff_table (cinfo : j_common_ptr) : JHUFF_TBL_PTR;
-
-implementation
-
-{ Abort processing of a JPEG compression or decompression operation,
- but don't destroy the object itself.
-
- For this, we merely clean up all the nonpermanent memory pools.
- Note that temp files (virtual arrays) are not allowed to belong to
- the permanent pool, so we will be able to close all temp files here.
- Closing a data source or destination, if necessary, is the application's
- responsibility. }
-
-
-{GLOBAL}
-procedure jpeg_abort (cinfo : j_common_ptr);
-var
- pool : int;
-begin
- { Do nothing if called on a not-initialized or destroyed JPEG object. }
- if (cinfo^.mem = NIL) then
- exit;
-
- { Releasing pools in reverse order might help avoid fragmentation
- with some (brain-damaged) malloc libraries. }
-
- for pool := JPOOL_NUMPOOLS-1 downto JPOOL_PERMANENT+1 do
- begin
- cinfo^.mem^.free_pool (cinfo, pool);
- end;
-
- { Reset overall state for possible reuse of object }
- if (cinfo^.is_decompressor) then
- begin
- cinfo^.global_state := DSTATE_START;
- { Try to keep application from accessing now-deleted marker list.
- A bit kludgy to do it here, but this is the most central place. }
- j_decompress_ptr(cinfo)^.marker_list := NIL;
- end
- else
- begin
- cinfo^.global_state := CSTATE_START;
- end;
-end;
-
-
-{ Destruction of a JPEG object.
-
- Everything gets deallocated except the master jpeg_compress_struct itself
- and the error manager struct. Both of these are supplied by the application
- and must be freed, if necessary, by the application. (Often they are on
- the stack and so don't need to be freed anyway.)
- Closing a data source or destination, if necessary, is the application's
- responsibility. }
-
-
-{GLOBAL}
-procedure jpeg_destroy (cinfo : j_common_ptr);
-begin
- { We need only tell the memory manager to release everything. }
- { NB: mem pointer is NIL if memory mgr failed to initialize. }
- if (cinfo^.mem <> NIL) then
- cinfo^.mem^.self_destruct (cinfo);
- cinfo^.mem := NIL; { be safe if jpeg_destroy is called twice }
- cinfo^.global_state := 0; { mark it destroyed }
-end;
-
-
-{ Convenience routines for allocating quantization and Huffman tables.
- (Would jutils.c be a more reasonable place to put these?) }
-
-
-{GLOBAL}
-function jpeg_alloc_quant_table (cinfo : j_common_ptr) : JQUANT_TBL_PTR;
-var
- tbl : JQUANT_TBL_PTR;
-begin
- tbl := JQUANT_TBL_PTR(
- cinfo^.mem^.alloc_small (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL))
- );
- tbl^.sent_table := FALSE; { make sure this is false in any new table }
- jpeg_alloc_quant_table := tbl;
-end;
-
-
-{GLOBAL}
-function jpeg_alloc_huff_table (cinfo : j_common_ptr) : JHUFF_TBL_PTR;
-var
- tbl : JHUFF_TBL_PTR;
-begin
- tbl := JHUFF_TBL_PTR(
- cinfo^.mem^.alloc_small (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL))
- );
- tbl^.sent_table := FALSE; { make sure this is false in any new table }
- jpeg_alloc_huff_table := tbl;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jconfig.inc b/packages/base/pasjpeg/jconfig.inc
deleted file mode 100644
index 356c1d0bbf..0000000000
--- a/packages/base/pasjpeg/jconfig.inc
+++ /dev/null
@@ -1,116 +0,0 @@
-{ ----------------------- JPEG_INTERNAL_OPTIONS ---------------------- }
-
-
-{ These defines indicate whether to include various optional functions.
- Undefining some of these symbols will produce a smaller but less capable
- library. Note that you can leave certain source files out of the
- compilation/linking process if you've #undef'd the corresponding symbols.
- (You may HAVE to do that if your compiler doesn't like null source files.)}
-
-
-{ Arithmetic coding is unsupported for legal reasons. Complaints to IBM. }
-
-{ Capability options common to encoder and decoder: }
-
-{$define DCT_ISLOW_SUPPORTED} { slow but accurate integer algorithm }
-{$define DCT_IFAST_SUPPORTED} { faster, less accurate integer method }
-{$define DCT_FLOAT_SUPPORTED} { floating-point: accurate, fast on fast HW }
-
-{ Encoder capability options: }
-
-{$undef C_ARITH_CODING_SUPPORTED} { Arithmetic coding back end? }
-{$define C_MULTISCAN_FILES_SUPPORTED} { Multiple-scan JPEG files? }
-{$define C_PROGRESSIVE_SUPPORTED} { Progressive JPEG? (Requires MULTISCAN)}
-{$define ENTROPY_OPT_SUPPORTED} { Optimization of entropy coding parms? }
-{ Note: if you selected 12-bit data precision, it is dangerous to turn off
- ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit
- precision, so jchuff.c normally uses entropy optimization to compute
- usable tables for higher precision. If you don't want to do optimization,
- you'll have to supply different default Huffman tables.
- The exact same statements apply for progressive JPEG: the default tables
- don't work for progressive mode. (This may get fixed, however.) }
-
-{$define INPUT_SMOOTHING_SUPPORTED} { Input image smoothing option? }
-
-{ Decoder capability options: }
-
-{$undef D_ARITH_CODING_SUPPORTED} { Arithmetic coding back end? }
-{$define D_MULTISCAN_FILES_SUPPORTED} { Multiple-scan JPEG files? }
-{$define D_PROGRESSIVE_SUPPORTED} { Progressive JPEG? (Requires MULTISCAN)}
-{$define SAVE_MARKERS_SUPPORTED} { jpeg_save_markers() needed? }
-{$define BLOCK_SMOOTHING_SUPPORTED} { Block smoothing? (Progressive only) }
-{$define IDCT_SCALING_SUPPORTED} { Output rescaling via IDCT? }
-{$undef UPSAMPLE_SCALING_SUPPORTED} { Output rescaling at upsample stage? }
-{$define UPSAMPLE_MERGING_SUPPORTED} { Fast path for sloppy upsampling? }
-{$define QUANT_1PASS_SUPPORTED} { 1-pass color quantization? }
-{$define QUANT_2PASS_SUPPORTED} { 2-pass color quantization? }
-
-{ If you happen not to want the image transform support, disable it here }
-{$define TRANSFORMS_SUPPORTED}
-
-{ more capability options later, no doubt }
-
-{$ifopt I+} {$define IOcheck} {$endif}
-
-{ ------------------------------------------------------------------------ }
-
-{$define USE_FMEM} { Borland has _fmemcpy() and _fmemset() }
-
-{$define FMEMCOPY}
-{$define FMEMZERO}
-
-{$define DCTSIZE_IS_8} { e.g. unroll the inner loop }
-{$define RIGHT_SHIFT_IS_UNSIGNED}
-{$undef AVOID_TABLES}
-{$undef FAST_DIVIDE}
-
-{$define BITS_IN_JSAMPLE_IS_8}
-
-{----------------------------------------------------------------}
-{ for test of 12 bit JPEG code only. !! }
-{-- $undef BITS_IN_JSAMPLE_IS_8}
-{----------------------------------------------------------------}
-
-{$define RGB_PIXELSIZE_IS_3}
-{$define SLOW_SHIFT_32}
-{$define RGB_RED_IS_0} { RGB byte order in JQUANT2 }
-
-{$undef NO_ZERO_ROW_TEST}
-
-{$define USE_MSDOS_MEMMGR} { Define this if you use jmemdos.c }
-{$define XMS_SUPPORTED}
-{$define EMS_SUPPORTED}
-
-{$undef MEM_STATS} { Write out memory usage }
-{$define AM_MEMORY_MANAGER} { we define jvirt_Xarray_control structs }
-
-{$undef FULL_MAIN_BUFFER_SUPPORTED}
-
-{$define PROGRESS_REPORT}
-{$define TWO_FILE_COMMANDLINE}
-{$define BMP_SUPPORTED}
-{$define PPM_SUPPORTED}
-{$undef GIF_SUPPORTED}
-{$undef RLE_SUPPORTED}
-{$define TARGA_SUPPORTED}
-{$define EXT_SWITCH}
-
-{$ifndef BITS_IN_JSAMPLE_IS_8} { for 12 bit samples }
-{$undef BMP_SUPPORTED}
-{$undef RLE_SUPPORTED}
-{$undef TARGA_SUPPORTED}
-{$endif}
-
-{$undef BASM16} { for TP7 - use BASM for fast multiply }
-{$ifdef Win32}
- {$ifndef FPC}
- {$define BASM} { jidctint with BASM for Delphi 2/3 }
- {$undef RGB_RED_IS_0} { BGR byte order in JQUANT2 }
- {$endif}
-{$endif}
-
-{$IFDEF FPC}
-{$MODE DELPHI}
-{$GOTO ON}
-{$DEFINE DELPHI_STREAM}
-{$ENDIF}
diff --git a/packages/base/pasjpeg/jconsts.pas b/packages/base/pasjpeg/jconsts.pas
deleted file mode 100644
index b7339e414a..0000000000
--- a/packages/base/pasjpeg/jconsts.pas
+++ /dev/null
@@ -1,11 +0,0 @@
-unit jconsts;
-
-interface
-
-resourcestring
- sChangeJPGSize = 'Cannot change the size of a JPEG image';
- sJPEGError = 'JPEG error #%d';
-
-implementation
-
-end.
diff --git a/packages/base/pasjpeg/jcparam.pas b/packages/base/pasjpeg/jcparam.pas
deleted file mode 100644
index 88a9e1967f..0000000000
--- a/packages/base/pasjpeg/jcparam.pas
+++ /dev/null
@@ -1,700 +0,0 @@
-Unit JcParam;
-
-{ This file contains optional default-setting code for the JPEG compressor.
- Applications do not have to use this file, but those that don't use it
- must know a lot more about the innards of the JPEG code. }
-
-{ Original: jcparam.c ; Copyright (C) 1991-1998, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jcomapi,
- jpeglib;
-
-{ Quantization table setup routines }
-
-{GLOBAL}
-procedure jpeg_add_quant_table (cinfo : j_compress_ptr;
- which_tbl : int;
- const basic_table : array of uInt;
- scale_factor : int;
- force_baseline : boolean);
-
-{GLOBAL}
-procedure jpeg_set_linear_quality (cinfo : j_compress_ptr;
- scale_factor : int;
- force_baseline : boolean);
-{ Set or change the 'quality' (quantization) setting, using default tables
- and a straight percentage-scaling quality scale. In most cases it's better
- to use jpeg_set_quality (below); this entry point is provided for
- applications that insist on a linear percentage scaling. }
-
-{GLOBAL}
-function jpeg_quality_scaling (quality : int) : int;
-{ Convert a user-specified quality rating to a percentage scaling factor
- for an underlying quantization table, using our recommended scaling curve.
- The input 'quality' factor should be 0 (terrible) to 100 (very good). }
-
-{GLOBAL}
-procedure jpeg_set_quality (cinfo : j_compress_ptr;
- quality : int;
- force_baseline : boolean);
-{ Set or change the 'quality' (quantization) setting, using default tables.
- This is the standard quality-adjusting entry point for typical user
- interfaces; only those who want detailed control over quantization tables
- would use the preceding three routines directly. }
-
-{GLOBAL}
-procedure jpeg_set_defaults (cinfo : j_compress_ptr);
-
-{ Create a recommended progressive-JPEG script.
- cinfo^.num_components and cinfo^.jpeg_color_space must be correct. }
-
-{ Set the JPEG colorspace, and choose colorspace-dependent default values. }
-
-{GLOBAL}
-procedure jpeg_set_colorspace (cinfo : j_compress_ptr;
- colorspace : J_COLOR_SPACE);
-
-{ Select an appropriate JPEG colorspace for in_color_space. }
-
-{GLOBAL}
-procedure jpeg_default_colorspace (cinfo : j_compress_ptr);
-
-{GLOBAL}
-procedure jpeg_simple_progression (cinfo : j_compress_ptr);
-
-
-implementation
-
-{ Quantization table setup routines }
-
-{GLOBAL}
-procedure jpeg_add_quant_table (cinfo : j_compress_ptr;
- which_tbl : int;
- const basic_table : array of uInt;
- scale_factor : int;
- force_baseline : boolean);
-{ Define a quantization table equal to the basic_table times
- a scale factor (given as a percentage).
- If force_baseline is TRUE, the computed quantization table entries
- are limited to 1..255 for JPEG baseline compatibility. }
-var
- qtblptr :^JQUANT_TBL_PTR;
- i : int;
- temp : long;
-begin
- { Safety check to ensure start_compress not called yet. }
- if (cinfo^.global_state <> CSTATE_START) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
-
- if (which_tbl < 0) or (which_tbl >= NUM_QUANT_TBLS) then
- ERREXIT1(j_common_ptr(cinfo), JERR_DQT_INDEX, which_tbl);
-
- qtblptr := @(cinfo^.quant_tbl_ptrs[which_tbl]);
-
- if (qtblptr^ = NIL) then
- qtblptr^ := jpeg_alloc_quant_table(j_common_ptr(cinfo));
-
- for i := 0 to pred(DCTSIZE2) do
- begin
- temp := (long(basic_table[i] * scale_factor) + long(50)) div long(100);
- { limit the values to the valid range }
- if (temp <= long(0)) then
- temp := long(1);
- if (temp > long(32767)) then
- temp := long(32767); { max quantizer needed for 12 bits }
- if (force_baseline) and (temp > long(255)) then
- temp := long(255); { limit to baseline range if requested }
- (qtblptr^)^.quantval[i] := UINT16 (temp);
- end;
-
- { Initialize sent_table FALSE so table will be written to JPEG file. }
- (qtblptr^)^.sent_table := FALSE;
-end;
-
-
-{GLOBAL}
-procedure jpeg_set_linear_quality (cinfo : j_compress_ptr;
- scale_factor : int;
- force_baseline : boolean);
-{ Set or change the 'quality' (quantization) setting, using default tables
- and a straight percentage-scaling quality scale. In most cases it's better
- to use jpeg_set_quality (below); this entry point is provided for
- applications that insist on a linear percentage scaling. }
-
-{ These are the sample quantization tables given in JPEG spec section K.1.
- The spec says that the values given produce "good" quality, and
- when divided by 2, "very good" quality. }
-
-const
- std_luminance_quant_tbl : array[0..DCTSIZE2-1] of uInt =
- (16, 11, 10, 16, 24, 40, 51, 61,
- 12, 12, 14, 19, 26, 58, 60, 55,
- 14, 13, 16, 24, 40, 57, 69, 56,
- 14, 17, 22, 29, 51, 87, 80, 62,
- 18, 22, 37, 56, 68, 109, 103, 77,
- 24, 35, 55, 64, 81, 104, 113, 92,
- 49, 64, 78, 87, 103, 121, 120, 101,
- 72, 92, 95, 98, 112, 100, 103, 99);
-
-const
- std_chrominance_quant_tbl : array[0..DCTSIZE2-1] of uInt =
- (17, 18, 24, 47, 99, 99, 99, 99,
- 18, 21, 26, 66, 99, 99, 99, 99,
- 24, 26, 56, 99, 99, 99, 99, 99,
- 47, 66, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99);
-begin
- { Set up two quantization tables using the specified scaling }
- jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
- scale_factor, force_baseline);
- jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
- scale_factor, force_baseline);
-end;
-
-
-{GLOBAL}
-function jpeg_quality_scaling (quality : int) : int;
-{ Convert a user-specified quality rating to a percentage scaling factor
- for an underlying quantization table, using our recommended scaling curve.
- The input 'quality' factor should be 0 (terrible) to 100 (very good). }
-begin
- { Safety limit on quality factor. Convert 0 to 1 to avoid zero divide. }
- if (quality <= 0) then
- quality := 1;
- if (quality > 100) then
- quality := 100;
-
- { The basic table is used as-is (scaling 100) for a quality of 50.
- Qualities 50..100 are converted to scaling percentage 200 - 2*Q;
- note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table
- to make all the table entries 1 (hence, minimum quantization loss).
- Qualities 1..50 are converted to scaling percentage 5000/Q. }
- if (quality < 50) then
- quality := 5000 div quality
- else
- quality := 200 - quality*2;
-
- jpeg_quality_scaling := quality;
-end;
-
-
-{GLOBAL}
-procedure jpeg_set_quality (cinfo : j_compress_ptr;
- quality : int;
- force_baseline : boolean);
-{ Set or change the 'quality' (quantization) setting, using default tables.
- This is the standard quality-adjusting entry point for typical user
- interfaces; only those who want detailed control over quantization tables
- would use the preceding three routines directly. }
-begin
- { Convert user 0-100 rating to percentage scaling }
- quality := jpeg_quality_scaling(quality);
-
- { Set up standard quality tables }
- jpeg_set_linear_quality(cinfo, quality, force_baseline);
-end;
-
-
-{ Huffman table setup routines }
-
-{LOCAL}
-procedure add_huff_table (cinfo : j_compress_ptr;
- var htblptr : JHUFF_TBL_PTR;
- var bits : array of UINT8;
- var val : array of UINT8);
-{ Define a Huffman table }
-var
- nsymbols, len : int;
-begin
- if (htblptr = NIL) then
- htblptr := jpeg_alloc_huff_table(j_common_ptr(cinfo));
-
- { Copy the number-of-symbols-of-each-code-length counts }
- MEMCOPY(@htblptr^.bits, @bits, SIZEOF(htblptr^.bits));
-
-
- { Validate the counts. We do this here mainly so we can copy the right
- number of symbols from the val[] array, without risking marching off
- the end of memory. jchuff.c will do a more thorough test later. }
-
- nsymbols := 0;
- for len := 1 to 16 do
- Inc(nsymbols, bits[len]);
- if (nsymbols < 1) or (nsymbols > 256) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_HUFF_TABLE);
-
- MEMCOPY(@htblptr^.huffval, @val, nsymbols * SIZEOF(UINT8));
-
- { Initialize sent_table FALSE so table will be written to JPEG file. }
- (htblptr)^.sent_table := FALSE;
-end;
-
-
-{LOCAL}
-procedure std_huff_tables (cinfo : j_compress_ptr);
-{ Set up the standard Huffman tables (cf. JPEG standard section K.3) }
-{ IMPORTANT: these are only valid for 8-bit data precision! }
- const bits_dc_luminance : array[0..17-1] of UINT8 =
- ({ 0-base } 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0);
- const val_dc_luminance : array[0..11] of UINT8 =
- (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
-
- const bits_dc_chrominance : array[0..17-1] of UINT8 =
- ( { 0-base } 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
- const val_dc_chrominance : array[0..11] of UINT8 =
- ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 );
-
- const bits_ac_luminance : array[0..17-1] of UINT8 =
- ( { 0-base } 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, $7d );
- const val_ac_luminance : array[0..161] of UINT8 =
- ( $01, $02, $03, $00, $04, $11, $05, $12,
- $21, $31, $41, $06, $13, $51, $61, $07,
- $22, $71, $14, $32, $81, $91, $a1, $08,
- $23, $42, $b1, $c1, $15, $52, $d1, $f0,
- $24, $33, $62, $72, $82, $09, $0a, $16,
- $17, $18, $19, $1a, $25, $26, $27, $28,
- $29, $2a, $34, $35, $36, $37, $38, $39,
- $3a, $43, $44, $45, $46, $47, $48, $49,
- $4a, $53, $54, $55, $56, $57, $58, $59,
- $5a, $63, $64, $65, $66, $67, $68, $69,
- $6a, $73, $74, $75, $76, $77, $78, $79,
- $7a, $83, $84, $85, $86, $87, $88, $89,
- $8a, $92, $93, $94, $95, $96, $97, $98,
- $99, $9a, $a2, $a3, $a4, $a5, $a6, $a7,
- $a8, $a9, $aa, $b2, $b3, $b4, $b5, $b6,
- $b7, $b8, $b9, $ba, $c2, $c3, $c4, $c5,
- $c6, $c7, $c8, $c9, $ca, $d2, $d3, $d4,
- $d5, $d6, $d7, $d8, $d9, $da, $e1, $e2,
- $e3, $e4, $e5, $e6, $e7, $e8, $e9, $ea,
- $f1, $f2, $f3, $f4, $f5, $f6, $f7, $f8,
- $f9, $fa );
-
- const bits_ac_chrominance : array[0..17-1] of UINT8 =
- ( { 0-base } 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, $77 );
- const val_ac_chrominance : array[0..161] of UINT8 =
- ( $00, $01, $02, $03, $11, $04, $05, $21,
- $31, $06, $12, $41, $51, $07, $61, $71,
- $13, $22, $32, $81, $08, $14, $42, $91,
- $a1, $b1, $c1, $09, $23, $33, $52, $f0,
- $15, $62, $72, $d1, $0a, $16, $24, $34,
- $e1, $25, $f1, $17, $18, $19, $1a, $26,
- $27, $28, $29, $2a, $35, $36, $37, $38,
- $39, $3a, $43, $44, $45, $46, $47, $48,
- $49, $4a, $53, $54, $55, $56, $57, $58,
- $59, $5a, $63, $64, $65, $66, $67, $68,
- $69, $6a, $73, $74, $75, $76, $77, $78,
- $79, $7a, $82, $83, $84, $85, $86, $87,
- $88, $89, $8a, $92, $93, $94, $95, $96,
- $97, $98, $99, $9a, $a2, $a3, $a4, $a5,
- $a6, $a7, $a8, $a9, $aa, $b2, $b3, $b4,
- $b5, $b6, $b7, $b8, $b9, $ba, $c2, $c3,
- $c4, $c5, $c6, $c7, $c8, $c9, $ca, $d2,
- $d3, $d4, $d5, $d6, $d7, $d8, $d9, $da,
- $e2, $e3, $e4, $e5, $e6, $e7, $e8, $e9,
- $ea, $f2, $f3, $f4, $f5, $f6, $f7, $f8,
- $f9, $fa );
-begin
- add_huff_table(cinfo, cinfo^.dc_huff_tbl_ptrs[0],
- bits_dc_luminance, val_dc_luminance);
- add_huff_table(cinfo, cinfo^.ac_huff_tbl_ptrs[0],
- bits_ac_luminance, val_ac_luminance);
- add_huff_table(cinfo, cinfo^.dc_huff_tbl_ptrs[1],
- bits_dc_chrominance, val_dc_chrominance);
- add_huff_table(cinfo, cinfo^.ac_huff_tbl_ptrs[1],
- bits_ac_chrominance, val_ac_chrominance);
-end;
-
-
-{ Default parameter setup for compression.
-
- Applications that don't choose to use this routine must do their
- own setup of all these parameters. Alternately, you can call this
- to establish defaults and then alter parameters selectively. This
- is the recommended approach since, if we add any new parameters,
- your code will still work (they'll be set to reasonable defaults). }
-
-{GLOBAL}
-procedure jpeg_set_defaults (cinfo : j_compress_ptr);
-var
- i : int;
-begin
- { Safety check to ensure start_compress not called yet. }
- if (cinfo^.global_state <> CSTATE_START) then
- ERREXIT1(J_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
-
- { Allocate comp_info array large enough for maximum component count.
- Array is made permanent in case application wants to compress
- multiple images at same param settings. }
-
- if (cinfo^.comp_info = NIL) then
- cinfo^.comp_info := jpeg_component_info_list_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_PERMANENT,
- MAX_COMPONENTS * SIZEOF(jpeg_component_info)) );
-
- { Initialize everything not dependent on the color space }
-
- cinfo^.data_precision := BITS_IN_JSAMPLE;
- { Set up two quantization tables using default quality of 75 }
- jpeg_set_quality(cinfo, 75, TRUE);
- { Set up two Huffman tables }
- std_huff_tables(cinfo);
-
- { Initialize default arithmetic coding conditioning }
- for i := 0 to pred(NUM_ARITH_TBLS) do
- begin
- cinfo^.arith_dc_L[i] := 0;
- cinfo^.arith_dc_U[i] := 1;
- cinfo^.arith_ac_K[i] := 5;
- end;
-
- { Default is no multiple-scan output }
- cinfo^.scan_info := NIL;
- cinfo^.num_scans := 0;
-
- { Expect normal source image, not raw downsampled data }
- cinfo^.raw_data_in := FALSE;
-
- { Use Huffman coding, not arithmetic coding, by default }
- cinfo^.arith_code := FALSE;
-
- { By default, don't do extra passes to optimize entropy coding }
- cinfo^.optimize_coding := FALSE;
- { The standard Huffman tables are only valid for 8-bit data precision.
- If the precision is higher, force optimization on so that usable
- tables will be computed. This test can be removed if default tables
- are supplied that are valid for the desired precision. }
-
- if (cinfo^.data_precision > 8) then
- cinfo^.optimize_coding := TRUE;
-
- { By default, use the simpler non-cosited sampling alignment }
- cinfo^.CCIR601_sampling := FALSE;
-
- { No input smoothing }
- cinfo^.smoothing_factor := 0;
-
- { DCT algorithm preference }
- cinfo^.dct_method := JDCT_DEFAULT;
-
- { No restart markers }
- cinfo^.restart_interval := 0;
- cinfo^.restart_in_rows := 0;
-
- { Fill in default JFIF marker parameters. Note that whether the marker
- will actually be written is determined by jpeg_set_colorspace.
-
- By default, the library emits JFIF version code 1.01.
- An application that wants to emit JFIF 1.02 extension markers should set
- JFIF_minor_version to 2. We could probably get away with just defaulting
- to 1.02, but there may still be some decoders in use that will complain
- about that; saying 1.01 should minimize compatibility problems. }
-
- cinfo^.JFIF_major_version := 1; { Default JFIF version = 1.01 }
- cinfo^.JFIF_minor_version := 1;
- cinfo^.density_unit := 0; { Pixel size is unknown by default }
- cinfo^.X_density := 1; { Pixel aspect ratio is square by default }
- cinfo^.Y_density := 1;
-
- { Choose JPEG colorspace based on input space, set defaults accordingly }
-
- jpeg_default_colorspace(cinfo);
-end;
-
-
-{ Select an appropriate JPEG colorspace for in_color_space. }
-
-{GLOBAL}
-procedure jpeg_default_colorspace (cinfo : j_compress_ptr);
-begin
- case (cinfo^.in_color_space) of
- JCS_GRAYSCALE:
- jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
- JCS_RGB:
- jpeg_set_colorspace(cinfo, JCS_YCbCr);
- JCS_YCbCr:
- jpeg_set_colorspace(cinfo, JCS_YCbCr);
- JCS_CMYK:
- jpeg_set_colorspace(cinfo, JCS_CMYK); { By default, no translation }
- JCS_YCCK:
- jpeg_set_colorspace(cinfo, JCS_YCCK);
- JCS_UNKNOWN:
- jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_IN_COLORSPACE);
- end;
-end;
-
-
-{ Set the JPEG colorspace, and choose colorspace-dependent default values. }
-
-{GLOBAL}
-procedure jpeg_set_colorspace (cinfo : j_compress_ptr;
- colorspace : J_COLOR_SPACE);
- { macro }
- procedure SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl : int);
- begin
- with cinfo^.comp_info^[index] do
- begin
- component_id := (id);
- h_samp_factor := (hsamp);
- v_samp_factor := (vsamp);
- quant_tbl_no := (quant);
- dc_tbl_no := (dctbl);
- ac_tbl_no := (actbl);
- end;
- end;
-
-var
- ci : int;
-begin
- { Safety check to ensure start_compress not called yet. }
- if (cinfo^.global_state <> CSTATE_START) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
-
- { For all colorspaces, we use Q and Huff tables 0 for luminance components,
- tables 1 for chrominance components. }
-
- cinfo^.jpeg_color_space := colorspace;
-
- cinfo^.write_JFIF_header := FALSE; { No marker for non-JFIF colorspaces }
- cinfo^.write_Adobe_marker := FALSE; { write no Adobe marker by default }
-
- case (colorspace) of
- JCS_GRAYSCALE:
- begin
- cinfo^.write_JFIF_header := TRUE; { Write a JFIF marker }
- cinfo^.num_components := 1;
- { JFIF specifies component ID 1 }
- SET_COMP(0, 1, 1,1, 0, 0,0);
- end;
- JCS_RGB:
- begin
- cinfo^.write_Adobe_marker := TRUE; { write Adobe marker to flag RGB }
- cinfo^.num_components := 3;
- SET_COMP(0, $52 { 'R' }, 1,1, 0, 0,0);
- SET_COMP(1, $47 { 'G' }, 1,1, 0, 0,0);
- SET_COMP(2, $42 { 'B' }, 1,1, 0, 0,0);
- end;
- JCS_YCbCr:
- begin
- cinfo^.write_JFIF_header := TRUE; { Write a JFIF marker }
- cinfo^.num_components := 3;
- { JFIF specifies component IDs 1,2,3 }
- { We default to 2x2 subsamples of chrominance }
- SET_COMP(0, 1, 2,2, 0, 0,0);
- SET_COMP(1, 2, 1,1, 1, 1,1);
- SET_COMP(2, 3, 1,1, 1, 1,1);
- end;
- JCS_CMYK:
- begin
- cinfo^.write_Adobe_marker := TRUE; { write Adobe marker to flag CMYK }
- cinfo^.num_components := 4;
- SET_COMP(0, $43 { 'C' }, 1,1, 0, 0,0);
- SET_COMP(1, $4D { 'M' }, 1,1, 0, 0,0);
- SET_COMP(2, $59 { 'Y' }, 1,1, 0, 0,0);
- SET_COMP(3, $4B { 'K' }, 1,1, 0, 0,0);
- end;
- JCS_YCCK:
- begin
- cinfo^.write_Adobe_marker := TRUE; { write Adobe marker to flag YCCK }
- cinfo^.num_components := 4;
- SET_COMP(0, 1, 2,2, 0, 0,0);
- SET_COMP(1, 2, 1,1, 1, 1,1);
- SET_COMP(2, 3, 1,1, 1, 1,1);
- SET_COMP(3, 4, 2,2, 0, 0,0);
- end;
- JCS_UNKNOWN:
- begin
- cinfo^.num_components := cinfo^.input_components;
- if (cinfo^.num_components < 1)
- or (cinfo^.num_components > MAX_COMPONENTS) then
- ERREXIT2(j_common_ptr(cinfo), JERR_COMPONENT_COUNT,
- cinfo^.num_components, MAX_COMPONENTS);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- SET_COMP(ci, ci, 1,1, 0, 0,0);
- end;
- end;
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
- end;
-end;
-
-
-{$ifdef C_PROGRESSIVE_SUPPORTED}
-
-{LOCAL}
-function fill_a_scan (scanptr : jpeg_scan_info_ptr;
- ci : int; Ss : int;
- Se : int; Ah : int;
- Al : int) : jpeg_scan_info_ptr;
-{ Support routine: generate one scan for specified component }
-begin
- scanptr^.comps_in_scan := 1;
- scanptr^.component_index[0] := ci;
- scanptr^.Ss := Ss;
- scanptr^.Se := Se;
- scanptr^.Ah := Ah;
- scanptr^.Al := Al;
- Inc(scanptr);
- fill_a_scan := scanptr;
-end;
-
-{LOCAL}
-function fill_scans (scanptr : jpeg_scan_info_ptr;
- ncomps : int;
- Ss : int; Se : int;
- Ah : int; Al : int) : jpeg_scan_info_ptr;
-{ Support routine: generate one scan for each component }
-var
- ci : int;
-begin
-
- for ci := 0 to pred(ncomps) do
- begin
- scanptr^.comps_in_scan := 1;
- scanptr^.component_index[0] := ci;
- scanptr^.Ss := Ss;
- scanptr^.Se := Se;
- scanptr^.Ah := Ah;
- scanptr^.Al := Al;
- Inc(scanptr);
- end;
- fill_scans := scanptr;
-end;
-
-{LOCAL}
-function fill_dc_scans (scanptr : jpeg_scan_info_ptr;
- ncomps : int;
- Ah : int; Al : int) : jpeg_scan_info_ptr;
-{ Support routine: generate interleaved DC scan if possible, else N scans }
-var
- ci : int;
-begin
-
- if (ncomps <= MAX_COMPS_IN_SCAN) then
- begin
- { Single interleaved DC scan }
- scanptr^.comps_in_scan := ncomps;
- for ci := 0 to pred(ncomps) do
- scanptr^.component_index[ci] := ci;
- scanptr^.Ss := 0;
- scanptr^.Se := 0;
- scanptr^.Ah := Ah;
- scanptr^.Al := Al;
- Inc(scanptr);
- end
- else
- begin
- { Noninterleaved DC scan for each component }
- scanptr := fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
- end;
- fill_dc_scans := scanptr;
-end;
-
-
-{ Create a recommended progressive-JPEG script.
- cinfo^.num_components and cinfo^.jpeg_color_space must be correct. }
-
-{GLOBAL}
-procedure jpeg_simple_progression (cinfo : j_compress_ptr);
-var
- ncomps : int;
- nscans : int;
- scanptr : jpeg_scan_info_ptr;
-begin
- ncomps := cinfo^.num_components;
-
- { Safety check to ensure start_compress not called yet. }
- if (cinfo^.global_state <> CSTATE_START) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
-
- { Figure space needed for script. Calculation must match code below! }
- if (ncomps = 3) and (cinfo^.jpeg_color_space = JCS_YCbCr) then
- begin
- { Custom script for YCbCr color images. }
- nscans := 10;
- end
- else
- begin
- { All-purpose script for other color spaces. }
- if (ncomps > MAX_COMPS_IN_SCAN) then
- nscans := 6 * ncomps { 2 DC + 4 AC scans per component }
- else
- nscans := 2 + 4 * ncomps; { 2 DC scans; 4 AC scans per component }
- end;
-
- { Allocate space for script.
- We need to put it in the permanent pool in case the application performs
- multiple compressions without changing the settings. To avoid a memory
- leak if jpeg_simple_progression is called repeatedly for the same JPEG
- object, we try to re-use previously allocated space, and we allocate
- enough space to handle YCbCr even if initially asked for grayscale. }
-
- if (cinfo^.script_space = NIL) or (cinfo^.script_space_size < nscans) then
- begin
- if nscans > 10 then
- cinfo^.script_space_size := nscans
- else
- cinfo^.script_space_size := 10;
-
- cinfo^.script_space := jpeg_scan_info_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_PERMANENT,
- cinfo^.script_space_size * SIZEOF(jpeg_scan_info)) );
- end;
- scanptr := cinfo^.script_space;
-
- cinfo^.scan_info := scanptr;
- cinfo^.num_scans := nscans;
-
- if (ncomps = 3) and (cinfo^.jpeg_color_space = JCS_YCbCr) then
- begin
- { Custom script for YCbCr color images. }
- { Initial DC scan }
- scanptr := fill_dc_scans(scanptr, ncomps, 0, 1);
- { Initial AC scan: get some luma data out in a hurry }
- scanptr := fill_a_scan(scanptr, 0, 1, 5, 0, 2);
- { Chroma data is too small to be worth expending many scans on }
- scanptr := fill_a_scan(scanptr, 2, 1, 63, 0, 1);
- scanptr := fill_a_scan(scanptr, 1, 1, 63, 0, 1);
- { Complete spectral selection for luma AC }
- scanptr := fill_a_scan(scanptr, 0, 6, 63, 0, 2);
- { Refine next bit of luma AC }
- scanptr := fill_a_scan(scanptr, 0, 1, 63, 2, 1);
- { Finish DC successive approximation }
- scanptr := fill_dc_scans(scanptr, ncomps, 1, 0);
- { Finish AC successive approximation }
- scanptr := fill_a_scan(scanptr, 2, 1, 63, 1, 0);
- scanptr := fill_a_scan(scanptr, 1, 1, 63, 1, 0);
- { Luma bottom bit comes last since it's usually largest scan }
- scanptr := fill_a_scan(scanptr, 0, 1, 63, 1, 0);
- end
- else
- begin
- { All-purpose script for other color spaces. }
- { Successive approximation first pass }
- scanptr := fill_dc_scans(scanptr, ncomps, 0, 1);
- scanptr := fill_scans(scanptr, ncomps, 1, 5, 0, 2);
- scanptr := fill_scans(scanptr, ncomps, 6, 63, 0, 2);
- { Successive approximation second pass }
- scanptr := fill_scans(scanptr, ncomps, 1, 63, 2, 1);
- { Successive approximation final pass }
- scanptr := fill_dc_scans(scanptr, ncomps, 1, 0);
- scanptr := fill_scans(scanptr, ncomps, 1, 63, 1, 0);
- end;
-end;
-
-{$endif}
-end.
diff --git a/packages/base/pasjpeg/jcphuff.pas b/packages/base/pasjpeg/jcphuff.pas
deleted file mode 100644
index a15d50d36e..0000000000
--- a/packages/base/pasjpeg/jcphuff.pas
+++ /dev/null
@@ -1,960 +0,0 @@
-Unit JcpHuff;
-
-{ This file contains Huffman entropy encoding routines for progressive JPEG.
-
- We do not support output suspension in this module, since the library
- currently does not allow multiple-scan files to be written with output
- suspension. }
-
-{ Original: jcphuff.c; Copyright (C) 1995-1997, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-uses
- jmorecfg,
- jinclude,
- jpeglib,
- jdeferr,
- jerror,
- jutils,
- jcomapi,
- jchuff; { Declarations shared with jchuff.c }
-
-
-{ Module initialization routine for progressive Huffman entropy encoding. }
-
-{GLOBAL}
-procedure jinit_phuff_encoder (cinfo : j_compress_ptr);
-
-implementation
-
-{ Expanded entropy encoder object for progressive Huffman encoding. }
-type
- phuff_entropy_ptr = ^phuff_entropy_encoder;
- phuff_entropy_encoder = record
- pub : jpeg_entropy_encoder; { public fields }
-
- { Mode flag: TRUE for optimization, FALSE for actual data output }
- gather_statistics : boolean;
-
- { Bit-level coding status.
- next_output_byte/free_in_buffer are local copies of cinfo^.dest fields.}
-
- next_output_byte : JOCTETptr; { => next byte to write in buffer }
- free_in_buffer : size_t; { # of byte spaces remaining in buffer }
- put_buffer : INT32; { current bit-accumulation buffer }
- put_bits : int; { # of bits now in it }
- cinfo : j_compress_ptr; { link to cinfo (needed for dump_buffer) }
-
- { Coding status for DC components }
- last_dc_val : array[0..MAX_COMPS_IN_SCAN-1] of int;
- { last DC coef for each component }
-
- { Coding status for AC components }
- ac_tbl_no : int; { the table number of the single component }
- EOBRUN : uInt; { run length of EOBs }
- BE : uInt; { # of buffered correction bits before MCU }
- bit_buffer : JBytePtr; { buffer for correction bits (1 per char) }
- { packing correction bits tightly would save some space but cost time... }
-
- restarts_to_go : uInt; { MCUs left in this restart interval }
- next_restart_num : int; { next restart number to write (0-7) }
-
- { Pointers to derived tables (these workspaces have image lifespan).
- Since any one scan codes only DC or only AC, we only need one set
- of tables, not one for DC and one for AC. }
-
- derived_tbls : array[0..NUM_HUFF_TBLS-1] of c_derived_tbl_ptr;
-
- { Statistics tables for optimization; again, one set is enough }
- count_ptrs : array[0..NUM_HUFF_TBLS-1] of TLongTablePtr;
- end;
-
-
-{ MAX_CORR_BITS is the number of bits the AC refinement correction-bit
- buffer can hold. Larger sizes may slightly improve compression, but
- 1000 is already well into the realm of overkill.
- The minimum safe size is 64 bits. }
-
-const
- MAX_CORR_BITS = 1000; { Max # of correction bits I can buffer }
-
-
-{ Forward declarations }
-{METHODDEF}
-function encode_mcu_DC_first (cinfo : j_compress_ptr;
- const MCU_data: array of JBLOCKROW) : boolean;
- far; forward;
-{METHODDEF}
-function encode_mcu_AC_first (cinfo : j_compress_ptr;
- const MCU_data: array of JBLOCKROW) : boolean;
- far; forward;
-{METHODDEF}
-function encode_mcu_DC_refine (cinfo : j_compress_ptr;
- const MCU_data: array of JBLOCKROW) : boolean;
- far; forward;
-{METHODDEF}
-function encode_mcu_AC_refine (cinfo : j_compress_ptr;
- const MCU_data: array of JBLOCKROW) : boolean;
- far; forward;
-
-{METHODDEF}
-procedure finish_pass_phuff (cinfo : j_compress_ptr); far; forward;
-
-{METHODDEF}
-procedure finish_pass_gather_phuff (cinfo : j_compress_ptr); far; forward;
-
-
-{ Initialize for a Huffman-compressed scan using progressive JPEG. }
-
-{METHODDEF}
-procedure start_pass_phuff (cinfo : j_compress_ptr;
- gather_statistics : boolean); far;
-var
- entropy : phuff_entropy_ptr;
- is_DC_band : boolean;
- ci, tbl : int;
- compptr : jpeg_component_info_ptr;
-begin
- entropy := phuff_entropy_ptr (cinfo^.entropy);
-
- entropy^.cinfo := cinfo;
- entropy^.gather_statistics := gather_statistics;
-
- is_DC_band := (cinfo^.Ss = 0);
-
- { We assume jcmaster.c already validated the scan parameters. }
-
- { Select execution routines }
- if (cinfo^.Ah = 0) then
- begin
- if (is_DC_band) then
- entropy^.pub.encode_mcu := encode_mcu_DC_first
- else
- entropy^.pub.encode_mcu := encode_mcu_AC_first;
- end
- else
- begin
- if (is_DC_band) then
- entropy^.pub.encode_mcu := encode_mcu_DC_refine
- else
- begin
- entropy^.pub.encode_mcu := encode_mcu_AC_refine;
- { AC refinement needs a correction bit buffer }
- if (entropy^.bit_buffer = NIL) then
- entropy^.bit_buffer := JBytePtr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- MAX_CORR_BITS * SIZEOF(byte)) );
- end;
- end;
- if (gather_statistics) then
- entropy^.pub.finish_pass := finish_pass_gather_phuff
- else
- entropy^.pub.finish_pass := finish_pass_phuff;
-
- { Only DC coefficients may be interleaved, so cinfo^.comps_in_scan = 1
- for AC coefficients. }
-
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- { Initialize DC predictions to 0 }
- entropy^.last_dc_val[ci] := 0;
- { Get table index }
- if (is_DC_band) then
- begin
- if (cinfo^.Ah <> 0) then { DC refinement needs no table }
- continue;
- tbl := compptr^.dc_tbl_no;
- end
- else
- begin
- tbl := compptr^.ac_tbl_no;
- entropy^.ac_tbl_no := tbl;
- end;
- if (gather_statistics) then
- begin
- { Check for invalid table index }
- { (make_c_derived_tbl does this in the other path) }
- if (tbl < 0) or (tbl >= NUM_HUFF_TBLS) then
- ERREXIT1(j_common_ptr(cinfo), JERR_NO_HUFF_TABLE, tbl);
- { Allocate and zero the statistics tables }
- { Note that jpeg_gen_optimal_table expects 257 entries in each table! }
- if (entropy^.count_ptrs[tbl] = NIL) then
- entropy^.count_ptrs[tbl] := TLongTablePtr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- 257 * SIZEOF(long)) );
- MEMZERO(entropy^.count_ptrs[tbl], 257 * SIZEOF(long));
- end else
- begin
- { Compute derived values for Huffman table }
- { We may do this more than once for a table, but it's not expensive }
- jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
- entropy^.derived_tbls[tbl]);
- end;
- end;
-
- { Initialize AC stuff }
- entropy^.EOBRUN := 0;
- entropy^.BE := 0;
-
- { Initialize bit buffer to empty }
- entropy^.put_buffer := 0;
- entropy^.put_bits := 0;
-
- { Initialize restart stuff }
- entropy^.restarts_to_go := cinfo^.restart_interval;
- entropy^.next_restart_num := 0;
-end;
-
-
-
-
-{LOCAL}
-procedure dump_buffer (entropy : phuff_entropy_ptr);
-{ Empty the output buffer; we do not support suspension in this module. }
-var
- dest : jpeg_destination_mgr_ptr;
-begin
- dest := entropy^.cinfo^.dest;
-
- if (not dest^.empty_output_buffer (entropy^.cinfo)) then
- ERREXIT(j_common_ptr(entropy^.cinfo), JERR_CANT_SUSPEND);
- { After a successful buffer dump, must reset buffer pointers }
- entropy^.next_output_byte := dest^.next_output_byte;
- entropy^.free_in_buffer := dest^.free_in_buffer;
-end;
-
-
-{ Outputting bits to the file }
-
-{ Only the right 24 bits of put_buffer are used; the valid bits are
- left-justified in this part. At most 16 bits can be passed to emit_bits
- in one call, and we never retain more than 7 bits in put_buffer
- between calls, so 24 bits are sufficient. }
-
-
-{LOCAL}
-procedure emit_bits (entropy : phuff_entropy_ptr;
- code : uInt;
- size : int); {INLINE}
-{ Emit some bits, unless we are in gather mode }
-var
- {register} put_buffer : INT32;
- {register} put_bits : int;
-var
- c : int;
-begin
- { This routine is heavily used, so it's worth coding tightly. }
- put_buffer := INT32 (code);
- put_bits := entropy^.put_bits;
-
- { if size is 0, caller used an invalid Huffman table entry }
- if (size = 0) then
- ERREXIT(j_common_ptr(entropy^.cinfo), JERR_HUFF_MISSING_CODE);
-
- if (entropy^.gather_statistics) then
- exit; { do nothing if we're only getting stats }
-
- put_buffer := put_buffer and ((INT32(1) shl size) - 1);
- { mask off any extra bits in code }
-
- Inc(put_bits, size); { new number of bits in buffer }
-
- put_buffer := put_buffer shl (24 - put_bits); { align incoming bits }
-
- put_buffer := put_buffer or entropy^.put_buffer;
- { and merge with old buffer contents }
-
- while (put_bits >= 8) do
- begin
- c := int ((put_buffer shr 16) and $FF);
-
- {emit_byte(entropy, c);}
- { Outputting bytes to the file.
- NB: these must be called only when actually outputting,
- that is, entropy^.gather_statistics = FALSE. }
- { Emit a byte }
- entropy^.next_output_byte^ := JOCTET(c);
- Inc(entropy^.next_output_byte);
- Dec(entropy^.free_in_buffer);
- if (entropy^.free_in_buffer = 0) then
- dump_buffer(entropy);
-
- if (c = $FF) then
- begin { need to stuff a zero byte? }
- {emit_byte(entropy, 0);}
- entropy^.next_output_byte^ := JOCTET(0);
- Inc(entropy^.next_output_byte);
- Dec(entropy^.free_in_buffer);
- if (entropy^.free_in_buffer = 0) then
- dump_buffer(entropy);
- end;
- put_buffer := put_buffer shl 8;
- Dec(put_bits, 8);
- end;
-
- entropy^.put_buffer := put_buffer; { update variables }
- entropy^.put_bits := put_bits;
-end;
-
-
-{LOCAL}
-procedure flush_bits (entropy : phuff_entropy_ptr);
-begin
- emit_bits(entropy, $7F, 7); { fill any partial byte with ones }
- entropy^.put_buffer := 0; { and reset bit-buffer to empty }
- entropy^.put_bits := 0;
-end;
-
-{ Emit (or just count) a Huffman symbol. }
-
-
-{LOCAL}
-procedure emit_symbol (entropy : phuff_entropy_ptr;
- tbl_no : int;
- symbol : int); {INLINE}
-var
- tbl : c_derived_tbl_ptr;
-begin
- if (entropy^.gather_statistics) then
- Inc(entropy^.count_ptrs[tbl_no]^[symbol])
- else
- begin
- tbl := entropy^.derived_tbls[tbl_no];
- emit_bits(entropy, tbl^.ehufco[symbol], tbl^.ehufsi[symbol]);
- end;
-end;
-
-
-{ Emit bits from a correction bit buffer. }
-
-{LOCAL}
-procedure emit_buffered_bits (entropy : phuff_entropy_ptr;
- bufstart : JBytePtr;
- nbits : uInt);
-var
- bufptr : byteptr;
-begin
- if (entropy^.gather_statistics) then
- exit; { no real work }
-
- bufptr := byteptr(bufstart);
- while (nbits > 0) do
- begin
- emit_bits(entropy, uInt(bufptr^), 1);
- Inc(bufptr);
- Dec(nbits);
- end;
-end;
-
-
-{ Emit any pending EOBRUN symbol. }
-
-{LOCAL}
-procedure emit_eobrun (entropy : phuff_entropy_ptr);
-var
- {register} temp, nbits : int;
-begin
- if (entropy^.EOBRUN > 0) then
- begin { if there is any pending EOBRUN }
- temp := entropy^.EOBRUN;
- nbits := 0;
- temp := temp shr 1;
- while (temp <> 0) do
- begin
- Inc(nbits);
- temp := temp shr 1;
- end;
-
- { safety check: shouldn't happen given limited correction-bit buffer }
- if (nbits > 14) then
- ERREXIT(j_common_ptr(entropy^.cinfo), JERR_HUFF_MISSING_CODE);
-
- emit_symbol(entropy, entropy^.ac_tbl_no, nbits shl 4);
- if (nbits <> 0) then
- emit_bits(entropy, entropy^.EOBRUN, nbits);
-
- entropy^.EOBRUN := 0;
-
- { Emit any buffered correction bits }
- emit_buffered_bits(entropy, entropy^.bit_buffer, entropy^.BE);
- entropy^.BE := 0;
- end;
-end;
-
-
-{ Emit a restart marker & resynchronize predictions. }
-
-{LOCAL}
-procedure emit_restart (entropy : phuff_entropy_ptr;
- restart_num : int);
-var
- ci : int;
-begin
- emit_eobrun(entropy);
-
- if (not entropy^.gather_statistics) then
- begin
- flush_bits(entropy);
- {emit_byte(entropy, $FF);}
- { Outputting bytes to the file.
- NB: these must be called only when actually outputting,
- that is, entropy^.gather_statistics = FALSE. }
-
- entropy^.next_output_byte^ := JOCTET($FF);
- Inc(entropy^.next_output_byte);
- Dec(entropy^.free_in_buffer);
- if (entropy^.free_in_buffer = 0) then
- dump_buffer(entropy);
-
- {emit_byte(entropy, JPEG_RST0 + restart_num);}
- entropy^.next_output_byte^ := JOCTET(JPEG_RST0 + restart_num);
- Inc(entropy^.next_output_byte);
- Dec(entropy^.free_in_buffer);
- if (entropy^.free_in_buffer = 0) then
- dump_buffer(entropy);
- end;
-
- if (entropy^.cinfo^.Ss = 0) then
- begin
- { Re-initialize DC predictions to 0 }
- for ci := 0 to pred(entropy^.cinfo^.comps_in_scan) do
- entropy^.last_dc_val[ci] := 0;
- end
- else
- begin
- { Re-initialize all AC-related fields to 0 }
- entropy^.EOBRUN := 0;
- entropy^.BE := 0;
- end;
-end;
-
-
-{ MCU encoding for DC initial scan (either spectral selection,
- or first pass of successive approximation). }
-
-{METHODDEF}
-function encode_mcu_DC_first (cinfo : j_compress_ptr;
- const MCU_data: array of JBLOCKROW) : boolean;
-var
- entropy : phuff_entropy_ptr;
- {register} temp, temp2 : int;
- {register} nbits : int;
- blkn, ci : int;
- Al : int;
- block : JBLOCK_PTR;
- compptr : jpeg_component_info_ptr;
- ishift_temp : int;
-begin
- entropy := phuff_entropy_ptr (cinfo^.entropy);
- Al := cinfo^.Al;
-
- entropy^.next_output_byte := cinfo^.dest^.next_output_byte;
- entropy^.free_in_buffer := cinfo^.dest^.free_in_buffer;
-
- { Emit restart marker if needed }
- if (cinfo^.restart_interval <> 0) then
- if (entropy^.restarts_to_go = 0) then
- emit_restart(entropy, entropy^.next_restart_num);
-
- { Encode the MCU data blocks }
- for blkn := 0 to pred(cinfo^.blocks_in_MCU) do
- begin
- block := JBLOCK_PTR(MCU_data[blkn]);
- ci := cinfo^.MCU_membership[blkn];
- compptr := cinfo^.cur_comp_info[ci];
-
- { Compute the DC value after the required point transform by Al.
- This is simply an arithmetic right shift. }
-
- {temp2 := IRIGHT_SHIFT( int(block^[0]), Al);}
- {IRIGHT_SHIFT_IS_UNSIGNED}
- ishift_temp := int(block^[0]);
- if ishift_temp < 0 then
- temp2 := (ishift_temp shr Al) or ((not 0) shl (16-Al))
- else
- temp2 := ishift_temp shr Al;
-
-
- { DC differences are figured on the point-transformed values. }
- temp := temp2 - entropy^.last_dc_val[ci];
- entropy^.last_dc_val[ci] := temp2;
-
- { Encode the DC coefficient difference per section G.1.2.1 }
- temp2 := temp;
- if (temp < 0) then
- begin
- temp := -temp; { temp is abs value of input }
- { For a negative input, want temp2 := bitwise complement of abs(input) }
- { This code assumes we are on a two's complement machine }
- Dec(temp2);
- end;
-
- { Find the number of bits needed for the magnitude of the coefficient }
- nbits := 0;
- while (temp <> 0) do
- begin
- Inc(nbits);
- temp := temp shr 1;
- end;
-
- { Check for out-of-range coefficient values.
- Since we're encoding a difference, the range limit is twice as much. }
-
- if (nbits > MAX_COEF_BITS+1) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_DCT_COEF);
-
- { Count/emit the Huffman-coded symbol for the number of bits }
- emit_symbol(entropy, compptr^.dc_tbl_no, nbits);
-
- { Emit that number of bits of the value, if positive, }
- { or the complement of its magnitude, if negative. }
- if (nbits <> 0) then { emit_bits rejects calls with size 0 }
- emit_bits(entropy, uInt(temp2), nbits);
- end;
-
- cinfo^.dest^.next_output_byte := entropy^.next_output_byte;
- cinfo^.dest^.free_in_buffer := entropy^.free_in_buffer;
-
- { Update restart-interval state too }
- if (cinfo^.restart_interval <> 0) then
- begin
- if (entropy^.restarts_to_go = 0) then
- begin
- entropy^.restarts_to_go := cinfo^.restart_interval;
- Inc(entropy^.next_restart_num);
- with entropy^ do
- next_restart_num := next_restart_num and 7;
- end;
- Dec(entropy^.restarts_to_go);
- end;
-
- encode_mcu_DC_first := TRUE;
-end;
-
-
-{ MCU encoding for AC initial scan (either spectral selection,
- or first pass of successive approximation). }
-
-{METHODDEF}
-function encode_mcu_AC_first (cinfo : j_compress_ptr;
- const MCU_data: array of JBLOCKROW) : boolean;
-var
- entropy : phuff_entropy_ptr;
- {register} temp, temp2 : int;
- {register} nbits : int;
- {register} r, k : int;
- Se : int;
- Al : int;
- block : JBLOCK_PTR;
-begin
- entropy := phuff_entropy_ptr (cinfo^.entropy);
- Se := cinfo^.Se;
- Al := cinfo^.Al;
-
- entropy^.next_output_byte := cinfo^.dest^.next_output_byte;
- entropy^.free_in_buffer := cinfo^.dest^.free_in_buffer;
-
- { Emit restart marker if needed }
- if (cinfo^.restart_interval <> 0) then
- if (entropy^.restarts_to_go = 0) then
- emit_restart(entropy, entropy^.next_restart_num);
-
- { Encode the MCU data block }
- block := JBLOCK_PTR(MCU_data[0]);
-
- { Encode the AC coefficients per section G.1.2.2, fig. G.3 }
-
- r := 0; { r := run length of zeros }
-
- for k := cinfo^.Ss to Se do
- begin
- temp := (block^[jpeg_natural_order[k]]);
- if (temp = 0) then
- begin
- Inc(r);
- continue;
- end;
- { We must apply the point transform by Al. For AC coefficients this
- is an integer division with rounding towards 0. To do this portably
- in C, we shift after obtaining the absolute value; so the code is
- interwoven with finding the abs value (temp) and output bits (temp2). }
-
- if (temp < 0) then
- begin
- temp := -temp; { temp is abs value of input }
- temp := temp shr Al; { apply the point transform }
- { For a negative coef, want temp2 := bitwise complement of abs(coef) }
- temp2 := not temp;
- end
- else
- begin
- temp := temp shr Al; { apply the point transform }
- temp2 := temp;
- end;
- { Watch out for case that nonzero coef is zero after point transform }
- if (temp = 0) then
- begin
- Inc(r);
- continue;
- end;
-
- { Emit any pending EOBRUN }
- if (entropy^.EOBRUN > 0) then
- emit_eobrun(entropy);
- { if run length > 15, must emit special run-length-16 codes ($F0) }
- while (r > 15) do
- begin
- emit_symbol(entropy, entropy^.ac_tbl_no, $F0);
- Dec(r, 16);
- end;
-
- { Find the number of bits needed for the magnitude of the coefficient }
- nbits := 0; { there must be at least one 1 bit }
- repeat
- Inc(nbits);
- temp := temp shr 1;
- until (temp = 0);
-
- { Check for out-of-range coefficient values }
- if (nbits > MAX_COEF_BITS) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_DCT_COEF);
-
- { Count/emit Huffman symbol for run length / number of bits }
- emit_symbol(entropy, entropy^.ac_tbl_no, (r shl 4) + nbits);
-
- { Emit that number of bits of the value, if positive, }
- { or the complement of its magnitude, if negative. }
- emit_bits(entropy, uInt(temp2), nbits);
-
- r := 0; { reset zero run length }
- end;
-
- if (r > 0) then
- begin { If there are trailing zeroes, }
- Inc(entropy^.EOBRUN); { count an EOB }
- if (entropy^.EOBRUN = $7FFF) then
- emit_eobrun(entropy); { force it out to avoid overflow }
- end;
-
- cinfo^.dest^.next_output_byte := entropy^.next_output_byte;
- cinfo^.dest^.free_in_buffer := entropy^.free_in_buffer;
-
- { Update restart-interval state too }
- if (cinfo^.restart_interval <> 0) then
- begin
- if (entropy^.restarts_to_go = 0) then
- begin
- entropy^.restarts_to_go := cinfo^.restart_interval;
- Inc(entropy^.next_restart_num);
- with entropy^ do
- next_restart_num := next_restart_num and 7;
- end;
- Dec(entropy^.restarts_to_go);
- end;
-
- encode_mcu_AC_first := TRUE;
-end;
-
-
-{ MCU encoding for DC successive approximation refinement scan.
- Note: we assume such scans can be multi-component, although the spec
- is not very clear on the point. }
-
-{METHODDEF}
-function encode_mcu_DC_refine (cinfo : j_compress_ptr;
- const MCU_data: array of JBLOCKROW) : boolean;
-var
- entropy : phuff_entropy_ptr;
- {register} temp : int;
- blkn : int;
- Al : int;
- block : JBLOCK_PTR;
-begin
- entropy := phuff_entropy_ptr (cinfo^.entropy);
- Al := cinfo^.Al;
-
- entropy^.next_output_byte := cinfo^.dest^.next_output_byte;
- entropy^.free_in_buffer := cinfo^.dest^.free_in_buffer;
-
- { Emit restart marker if needed }
- if (cinfo^.restart_interval <> 0) then
- if (entropy^.restarts_to_go = 0) then
- emit_restart(entropy, entropy^.next_restart_num);
-
- { Encode the MCU data blocks }
- for blkn := 0 to pred(cinfo^.blocks_in_MCU) do
- begin
- block := JBLOCK_PTR(MCU_data[blkn]);
-
- { We simply emit the Al'th bit of the DC coefficient value. }
- temp := block^[0];
- emit_bits(entropy, uInt(temp shr Al), 1);
- end;
-
- cinfo^.dest^.next_output_byte := entropy^.next_output_byte;
- cinfo^.dest^.free_in_buffer := entropy^.free_in_buffer;
-
- { Update restart-interval state too }
- if (cinfo^.restart_interval <> 0) then
- begin
- if (entropy^.restarts_to_go = 0) then
- begin
- entropy^.restarts_to_go := cinfo^.restart_interval;
- Inc(entropy^.next_restart_num);
- with entropy^ do
- next_restart_num := next_restart_num and 7;
- end;
- Dec(entropy^.restarts_to_go);
- end;
-
- encode_mcu_DC_refine := TRUE;
-end;
-
-
-{ MCU encoding for AC successive approximation refinement scan. }
-
-{METHODDEF}
-function encode_mcu_AC_refine (cinfo : j_compress_ptr;
- const MCU_data: array of JBLOCKROW) : boolean;
-
-var
- entropy : phuff_entropy_ptr;
- {register} temp : int;
- {register} r, k : int;
- EOB : int;
- BR_buffer : JBytePtr;
- BR : uInt;
- Se : int;
- Al : int;
- block : JBLOCK_PTR;
- absvalues : array[0..DCTSIZE2-1] of int;
-begin
- entropy := phuff_entropy_ptr(cinfo^.entropy);
- Se := cinfo^.Se;
- Al := cinfo^.Al;
-
- entropy^.next_output_byte := cinfo^.dest^.next_output_byte;
- entropy^.free_in_buffer := cinfo^.dest^.free_in_buffer;
-
- { Emit restart marker if needed }
- if (cinfo^.restart_interval <> 0) then
- if (entropy^.restarts_to_go = 0) then
- emit_restart(entropy, entropy^.next_restart_num);
-
- { Encode the MCU data block }
- block := JBLOCK_PTR(MCU_data[0]);
-
- { It is convenient to make a pre-pass to determine the transformed
- coefficients' absolute values and the EOB position. }
-
- EOB := 0;
- for k := cinfo^.Ss to Se do
- begin
- temp := block^[jpeg_natural_order[k]];
- { We must apply the point transform by Al. For AC coefficients this
- is an integer division with rounding towards 0. To do this portably
- in C, we shift after obtaining the absolute value. }
-
- if (temp < 0) then
- temp := -temp; { temp is abs value of input }
- temp := temp shr Al; { apply the point transform }
- absvalues[k] := temp; { save abs value for main pass }
- if (temp = 1) then
- EOB := k; { EOB := index of last newly-nonzero coef }
- end;
-
- { Encode the AC coefficients per section G.1.2.3, fig. G.7 }
-
- r := 0; { r := run length of zeros }
- BR := 0; { BR := count of buffered bits added now }
- BR_buffer := JBytePtr(@(entropy^.bit_buffer^[entropy^.BE]));
- { Append bits to buffer }
-
- for k := cinfo^.Ss to Se do
- begin
- temp := absvalues[k];
- if (temp = 0) then
- begin
- Inc(r);
- continue;
- end;
-
- { Emit any required ZRLs, but not if they can be folded into EOB }
- while (r > 15) and (k <= EOB) do
- begin
- { emit any pending EOBRUN and the BE correction bits }
- emit_eobrun(entropy);
- { Emit ZRL }
- emit_symbol(entropy, entropy^.ac_tbl_no, $F0);
- Dec(r, 16);
- { Emit buffered correction bits that must be associated with ZRL }
- emit_buffered_bits(entropy, BR_buffer, BR);
- BR_buffer := entropy^.bit_buffer; { BE bits are gone now }
- BR := 0;
- end;
-
- { If the coef was previously nonzero, it only needs a correction bit.
- NOTE: a straight translation of the spec's figure G.7 would suggest
- that we also need to test r > 15. But if r > 15, we can only get here
- if k > EOB, which implies that this coefficient is not 1. }
- if (temp > 1) then
- begin
- { The correction bit is the next bit of the absolute value. }
- BR_buffer^[BR] := byte (temp and 1);
- Inc(BR);
- continue;
- end;
-
- { Emit any pending EOBRUN and the BE correction bits }
- emit_eobrun(entropy);
-
- { Count/emit Huffman symbol for run length / number of bits }
- emit_symbol(entropy, entropy^.ac_tbl_no, (r shl 4) + 1);
-
- { Emit output bit for newly-nonzero coef }
- if (block^[jpeg_natural_order[k]] < 0) then
- temp := 0
- else
- temp := 1;
- emit_bits(entropy, uInt(temp), 1);
-
- { Emit buffered correction bits that must be associated with this code }
- emit_buffered_bits(entropy, BR_buffer, BR);
- BR_buffer := entropy^.bit_buffer; { BE bits are gone now }
- BR := 0;
- r := 0; { reset zero run length }
- end;
-
- if (r > 0) or (BR > 0) then
- begin { If there are trailing zeroes, }
- Inc(entropy^.EOBRUN); { count an EOB }
- Inc(entropy^.BE, BR); { concat my correction bits to older ones }
- { We force out the EOB if we risk either:
- 1. overflow of the EOB counter;
- 2. overflow of the correction bit buffer during the next MCU. }
-
- if (entropy^.EOBRUN = $7FFF) or
- (entropy^.BE > (MAX_CORR_BITS-DCTSIZE2+1)) then
- emit_eobrun(entropy);
- end;
-
- cinfo^.dest^.next_output_byte := entropy^.next_output_byte;
- cinfo^.dest^.free_in_buffer := entropy^.free_in_buffer;
-
- { Update restart-interval state too }
- if (cinfo^.restart_interval <> 0) then
- begin
- if (entropy^.restarts_to_go = 0) then
- begin
- entropy^.restarts_to_go := cinfo^.restart_interval;
- Inc(entropy^.next_restart_num);
- with entropy^ do
- next_restart_num := next_restart_num and 7;
- end;
- Dec(entropy^.restarts_to_go);
- end;
-
- encode_mcu_AC_refine := TRUE;
-end;
-
-
-{ Finish up at the end of a Huffman-compressed progressive scan. }
-
-{METHODDEF}
-procedure finish_pass_phuff (cinfo : j_compress_ptr);
-var
- entropy : phuff_entropy_ptr;
-begin
- entropy := phuff_entropy_ptr (cinfo^.entropy);
-
- entropy^.next_output_byte := cinfo^.dest^.next_output_byte;
- entropy^.free_in_buffer := cinfo^.dest^.free_in_buffer;
-
- { Flush out any buffered data }
- emit_eobrun(entropy);
- flush_bits(entropy);
-
- cinfo^.dest^.next_output_byte := entropy^.next_output_byte;
- cinfo^.dest^.free_in_buffer := entropy^.free_in_buffer;
-end;
-
-
-{ Finish up a statistics-gathering pass and create the new Huffman tables. }
-
-{METHODDEF}
-procedure finish_pass_gather_phuff (cinfo : j_compress_ptr);
-var
- entropy : phuff_entropy_ptr;
- is_DC_band : boolean;
- ci, tbl : int;
- compptr : jpeg_component_info_ptr;
- htblptr : ^JHUFF_TBL_PTR;
- did : array[0..NUM_HUFF_TBLS-1] of boolean;
-begin
- entropy := phuff_entropy_ptr (cinfo^.entropy);
-
- { Flush out buffered data (all we care about is counting the EOB symbol) }
- emit_eobrun(entropy);
-
- is_DC_band := (cinfo^.Ss = 0);
-
- { It's important not to apply jpeg_gen_optimal_table more than once
- per table, because it clobbers the input frequency counts! }
-
- MEMZERO(@did, SIZEOF(did));
-
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- if (is_DC_band) then
- begin
- if (cinfo^.Ah <> 0) then { DC refinement needs no table }
- continue;
- tbl := compptr^.dc_tbl_no;
- end
- else
- begin
- tbl := compptr^.ac_tbl_no;
- end;
- if (not did[tbl]) then
- begin
- if (is_DC_band) then
- htblptr := @(cinfo^.dc_huff_tbl_ptrs[tbl])
- else
- htblptr := @(cinfo^.ac_huff_tbl_ptrs[tbl]);
- if (htblptr^ = NIL) then
- htblptr^ := jpeg_alloc_huff_table(j_common_ptr(cinfo));
- jpeg_gen_optimal_table(cinfo, htblptr^, entropy^.count_ptrs[tbl]^);
- did[tbl] := TRUE;
- end;
- end;
-end;
-
-
-{ Module initialization routine for progressive Huffman entropy encoding. }
-
-{GLOBAL}
-procedure jinit_phuff_encoder (cinfo : j_compress_ptr);
-var
- entropy : phuff_entropy_ptr;
- i : int;
-begin
- entropy := phuff_entropy_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(phuff_entropy_encoder)) );
- cinfo^.entropy := jpeg_entropy_encoder_ptr(entropy);
- entropy^.pub.start_pass := start_pass_phuff;
-
- { Mark tables unallocated }
- for i := 0 to pred(NUM_HUFF_TBLS) do
- begin
- entropy^.derived_tbls[i] := NIL;
- entropy^.count_ptrs[i] := NIL;
- end;
- entropy^.bit_buffer := NIL; { needed only in AC refinement scan }
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jcprepct.pas b/packages/base/pasjpeg/jcprepct.pas
deleted file mode 100644
index 32adc6aec3..0000000000
--- a/packages/base/pasjpeg/jcprepct.pas
+++ /dev/null
@@ -1,406 +0,0 @@
-Unit JcPrepCT;
-
-{ Original : jcprepct.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-{ This file contains the compression preprocessing controller.
- This controller manages the color conversion, downsampling,
- and edge expansion steps.
-
- Most of the complexity here is associated with buffering input rows
- as required by the downsampler. See the comments at the head of
- jcsample.c for the downsampler's needs. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jpeglib,
- jdeferr,
- jerror,
- jinclude,
- jutils;
-
-{GLOBAL}
-procedure jinit_c_prep_controller (cinfo : j_compress_ptr;
- need_full_buffer : boolean);
-
-implementation
-
-
-{ At present, jcsample.c can request context rows only for smoothing.
- In the future, we might also need context rows for CCIR601 sampling
- or other more-complex downsampling procedures. The code to support
- context rows should be compiled only if needed. }
-
-{$ifdef INPUT_SMOOTHING_SUPPORTED}
- {$define CONTEXT_ROWS_SUPPORTED}
-{$endif}
-
-
-{ For the simple (no-context-row) case, we just need to buffer one
- row group's worth of pixels for the downsampling step. At the bottom of
- the image, we pad to a full row group by replicating the last pixel row.
- The downsampler's last output row is then replicated if needed to pad
- out to a full iMCU row.
-
- When providing context rows, we must buffer three row groups' worth of
- pixels. Three row groups are physically allocated, but the row pointer
- arrays are made five row groups high, with the extra pointers above and
- below "wrapping around" to point to the last and first real row groups.
- This allows the downsampler to access the proper context rows.
- At the top and bottom of the image, we create dummy context rows by
- copying the first or last real pixel row. This copying could be avoided
- by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the
- trouble on the compression side. }
-
-
-{ Private buffer controller object }
-
-type
- my_prep_ptr = ^my_prep_controller;
- my_prep_controller = record
- pub : jpeg_c_prep_controller; { public fields }
-
- { Downsampling input buffer. This buffer holds color-converted data
- until we have enough to do a downsample step. }
-
- color_buf : array[0..MAX_COMPONENTS-1] of JSAMPARRAY;
-
- rows_to_go : JDIMENSION; { counts rows remaining in source image }
- next_buf_row : int; { index of next row to store in color_buf }
-
- {$ifdef CONTEXT_ROWS_SUPPORTED} { only needed for context case }
- this_row_group : int; { starting row index of group to process }
- next_buf_stop : int; { downsample when we reach this index }
- {$endif}
- end; {my_prep_controller;}
-
-
-{ Initialize for a processing pass. }
-
-{METHODDEF}
-procedure start_pass_prep (cinfo : j_compress_ptr;
- pass_mode : J_BUF_MODE ); far;
-var
- prep : my_prep_ptr;
-begin
- prep := my_prep_ptr (cinfo^.prep);
-
- if (pass_mode <> JBUF_PASS_THRU) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
-
- { Initialize total-height counter for detecting bottom of image }
- prep^.rows_to_go := cinfo^.image_height;
- { Mark the conversion buffer empty }
- prep^.next_buf_row := 0;
-{$ifdef CONTEXT_ROWS_SUPPORTED}
- { Preset additional state variables for context mode.
- These aren't used in non-context mode, so we needn't test which mode. }
- prep^.this_row_group := 0;
- { Set next_buf_stop to stop after two row groups have been read in. }
- prep^.next_buf_stop := 2 * cinfo^.max_v_samp_factor;
-{$endif}
-end;
-
-
-{ Expand an image vertically from height input_rows to height output_rows,
- by duplicating the bottom row. }
-
-{LOCAL}
-procedure expand_bottom_edge (image_data : JSAMPARRAY;
- num_cols : JDIMENSION;
- input_rows : int;
- output_rows : int);
-var
- {register} row : int;
-begin
- for row := input_rows to pred(output_rows) do
- begin
- jcopy_sample_rows(image_data, input_rows-1, image_data, row,
- 1, num_cols);
- end;
-end;
-
-
-{ Process some data in the simple no-context case.
-
- Preprocessor output data is counted in "row groups". A row group
- is defined to be v_samp_factor sample rows of each component.
- Downsampling will produce this much data from each max_v_samp_factor
- input rows. }
-
-{METHODDEF}
-procedure pre_process_data (cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- var in_row_ctr : JDIMENSION;
- in_rows_avail : JDIMENSION;
- output_buf : JSAMPIMAGE;
- var out_row_group_ctr : JDIMENSION;
- out_row_groups_avail : JDIMENSION); far;
-var
- prep : my_prep_ptr;
- numrows, ci : int;
- inrows : JDIMENSION;
- compptr : jpeg_component_info_ptr;
-var
- local_input_buf : JSAMPARRAY;
-begin
- prep := my_prep_ptr (cinfo^.prep);
-
- while (in_row_ctr < in_rows_avail) and
- (out_row_group_ctr < out_row_groups_avail) do
- begin
- { Do color conversion to fill the conversion buffer. }
- inrows := in_rows_avail - in_row_ctr;
- numrows := cinfo^.max_v_samp_factor - prep^.next_buf_row;
- {numrows := int( MIN(JDIMENSION(numrows), inrows) );}
- if inrows < JDIMENSION(numrows) then
- numrows := int(inrows);
- local_input_buf := JSAMPARRAY(@(input_buf^[in_row_ctr]));
- cinfo^.cconvert^.color_convert (cinfo, local_input_buf,
- JSAMPIMAGE(@prep^.color_buf),
- JDIMENSION(prep^.next_buf_row),
- numrows);
- Inc(in_row_ctr, numrows);
- Inc(prep^.next_buf_row, numrows);
- Dec(prep^.rows_to_go, numrows);
- { If at bottom of image, pad to fill the conversion buffer. }
- if (prep^.rows_to_go = 0) and
- (prep^.next_buf_row < cinfo^.max_v_samp_factor) then
- begin
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- expand_bottom_edge(prep^.color_buf[ci], cinfo^.image_width,
- prep^.next_buf_row, cinfo^.max_v_samp_factor);
- end;
- prep^.next_buf_row := cinfo^.max_v_samp_factor;
- end;
- { If we've filled the conversion buffer, empty it. }
- if (prep^.next_buf_row = cinfo^.max_v_samp_factor) then
- begin
- cinfo^.downsample^.downsample (cinfo,
- JSAMPIMAGE(@prep^.color_buf),
- JDIMENSION (0),
- output_buf,
- out_row_group_ctr);
- prep^.next_buf_row := 0;
- Inc(out_row_group_ctr);;
- end;
- { If at bottom of image, pad the output to a full iMCU height.
- Note we assume the caller is providing a one-iMCU-height output buffer! }
- if (prep^.rows_to_go = 0) and
- (out_row_group_ctr < out_row_groups_avail) then
- begin
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- expand_bottom_edge(output_buf^[ci],
- compptr^.width_in_blocks * DCTSIZE,
- int (out_row_group_ctr * compptr^.v_samp_factor),
- int (out_row_groups_avail * compptr^.v_samp_factor));
- Inc(compptr);
- end;
- out_row_group_ctr := out_row_groups_avail;
- break; { can exit outer loop without test }
- end;
- end;
-end;
-
-
-{$ifdef CONTEXT_ROWS_SUPPORTED}
-
-{ Process some data in the context case. }
-
-{METHODDEF}
-procedure pre_process_context (cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- var in_row_ctr : JDIMENSION;
- in_rows_avail : JDIMENSION;
- output_buf : JSAMPIMAGE;
- var out_row_group_ctr : JDIMENSION;
- out_row_groups_avail : JDIMENSION); far;
-var
- prep : my_prep_ptr;
- numrows, ci : int;
- buf_height : int;
- inrows : JDIMENSION;
-var
- row : int;
-
-begin
- prep := my_prep_ptr (cinfo^.prep);
- buf_height := cinfo^.max_v_samp_factor * 3;
-
- while (out_row_group_ctr < out_row_groups_avail) do
- begin
- if (in_row_ctr < in_rows_avail) then
- begin
- { Do color conversion to fill the conversion buffer. }
- inrows := in_rows_avail - in_row_ctr;
- numrows := prep^.next_buf_stop - prep^.next_buf_row;
- {numrows := int ( MIN( JDIMENSION(numrows), inrows) );}
- if inrows < JDIMENSION(numrows) then
- numrows := int(inrows);
- cinfo^.cconvert^.color_convert (cinfo,
- JSAMPARRAY(@input_buf^[in_row_ctr]),
- JSAMPIMAGE(@prep^.color_buf),
- JDIMENSION (prep^.next_buf_row),
- numrows);
- { Pad at top of image, if first time through }
- if (prep^.rows_to_go = cinfo^.image_height) then
- begin
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- for row := 1 to cinfo^.max_v_samp_factor do
- begin
- jcopy_sample_rows(prep^.color_buf[ci], 0,
- prep^.color_buf[ci], -row,
- 1, cinfo^.image_width);
- end;
- end;
- end;
- Inc(in_row_ctr, numrows);
- Inc(prep^.next_buf_row, numrows);
- Dec(prep^.rows_to_go, numrows);
- end
- else
- begin
- { Return for more data, unless we are at the bottom of the image. }
- if (prep^.rows_to_go <> 0) then
- break;
- { When at bottom of image, pad to fill the conversion buffer. }
- if (prep^.next_buf_row < prep^.next_buf_stop) then
- begin
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- expand_bottom_edge(prep^.color_buf[ci], cinfo^.image_width,
- prep^.next_buf_row, prep^.next_buf_stop);
- end;
- prep^.next_buf_row := prep^.next_buf_stop;
- end;
- end;
- { If we've gotten enough data, downsample a row group. }
- if (prep^.next_buf_row = prep^.next_buf_stop) then
- begin
- cinfo^.downsample^.downsample (cinfo,
- JSAMPIMAGE(@prep^.color_buf),
- JDIMENSION(prep^.this_row_group),
- output_buf,
- out_row_group_ctr);
- Inc(out_row_group_ctr);
- { Advance pointers with wraparound as necessary. }
- Inc(prep^.this_row_group, cinfo^.max_v_samp_factor);
- if (prep^.this_row_group >= buf_height) then
- prep^.this_row_group := 0;
- if (prep^.next_buf_row >= buf_height) then
- prep^.next_buf_row := 0;
- prep^.next_buf_stop := prep^.next_buf_row + cinfo^.max_v_samp_factor;
- end;
- end;
-end;
-
-
-{ Create the wrapped-around downsampling input buffer needed for context mode. }
-
-{LOCAL}
-procedure create_context_buffer (cinfo : j_compress_ptr);
-var
- prep : my_prep_ptr;
- rgroup_height : int;
- ci, i : int;
- compptr : jpeg_component_info_ptr;
- true_buffer, fake_buffer : JSAMPARRAY;
-begin
- prep := my_prep_ptr (cinfo^.prep);
- rgroup_height := cinfo^.max_v_samp_factor;
- { Grab enough space for fake row pointers for all the components;
- we need five row groups' worth of pointers for each component. }
-
- fake_buffer := JSAMPARRAY(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- (cinfo^.num_components * 5 * rgroup_height) *
- SIZEOF(JSAMPROW)) );
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- { Allocate the actual buffer space (3 row groups) for this component.
- We make the buffer wide enough to allow the downsampler to edge-expand
- horizontally within the buffer, if it so chooses. }
- true_buffer := cinfo^.mem^.alloc_sarray
- (j_common_ptr(cinfo), JPOOL_IMAGE,
- JDIMENSION (( long(compptr^.width_in_blocks) * DCTSIZE *
- cinfo^.max_h_samp_factor) div compptr^.h_samp_factor),
- JDIMENSION (3 * rgroup_height));
- { Copy true buffer row pointers into the middle of the fake row array }
- MEMCOPY(JSAMPARRAY(@ fake_buffer^[rgroup_height]), true_buffer,
- 3 * rgroup_height * SIZEOF(JSAMPROW));
- { Fill in the above and below wraparound pointers }
- for i := 0 to pred(rgroup_height) do
- begin
- fake_buffer^[i] := true_buffer^[2 * rgroup_height + i];
- fake_buffer^[4 * rgroup_height + i] := true_buffer^[i];
- end;
- prep^.color_buf[ci] := JSAMPARRAY(@ fake_buffer^[rgroup_height]);
- Inc(JSAMPROW_PTR(fake_buffer), 5 * rgroup_height); { point to space for next component }
- Inc(compptr);
- end;
-end;
-
-{$endif} { CONTEXT_ROWS_SUPPORTED }
-
-
-{ Initialize preprocessing controller. }
-
-{GLOBAL}
-procedure jinit_c_prep_controller (cinfo : j_compress_ptr;
- need_full_buffer : boolean);
-var
- prep : my_prep_ptr;
- ci : int;
- compptr : jpeg_component_info_ptr;
-begin
-
- if (need_full_buffer) then { safety check }
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
-
- prep := my_prep_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_prep_controller)) );
- cinfo^.prep := jpeg_c_prep_controller_ptr(prep);
- prep^.pub.start_pass := start_pass_prep;
-
- { Allocate the color conversion buffer.
- We make the buffer wide enough to allow the downsampler to edge-expand
- horizontally within the buffer, if it so chooses. }
-
- if (cinfo^.downsample^.need_context_rows) then
- begin
- { Set up to provide context rows }
-{$ifdef CONTEXT_ROWS_SUPPORTED}
- prep^.pub.pre_process_data := pre_process_context;
- create_context_buffer(cinfo);
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end
- else
- begin
- { No context, just make it tall enough for one row group }
- prep^.pub.pre_process_data := pre_process_data;
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- prep^.color_buf[ci] := cinfo^.mem^.alloc_sarray
- (j_common_ptr(cinfo), JPOOL_IMAGE,
- JDIMENSION (( long(compptr^.width_in_blocks) * DCTSIZE *
- cinfo^.max_h_samp_factor) div compptr^.h_samp_factor),
- JDIMENSION(cinfo^.max_v_samp_factor) );
- Inc(compptr);
- end;
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jcsample.pas b/packages/base/pasjpeg/jcsample.pas
deleted file mode 100644
index 290f1cc82d..0000000000
--- a/packages/base/pasjpeg/jcsample.pas
+++ /dev/null
@@ -1,631 +0,0 @@
-Unit JcSample;
-
-{ This file contains downsampling routines.
-
- Downsampling input data is counted in "row groups". A row group
- is defined to be max_v_samp_factor pixel rows of each component,
- from which the downsampler produces v_samp_factor sample rows.
- A single row group is processed in each call to the downsampler module.
-
- The downsampler is responsible for edge-expansion of its output data
- to fill an integral number of DCT blocks horizontally. The source buffer
- may be modified if it is helpful for this purpose (the source buffer is
- allocated wide enough to correspond to the desired output width).
- The caller (the prep controller) is responsible for vertical padding.
-
- The downsampler may request "context rows" by setting need_context_rows
- during startup. In this case, the input arrays will contain at least
- one row group's worth of pixels above and below the passed-in data;
- the caller will create dummy rows at image top and bottom by replicating
- the first or last real pixel row.
-
- An excellent reference for image resampling is
- Digital Image Warping, George Wolberg, 1990.
- Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
-
- The downsampling algorithm used here is a simple average of the source
- pixels covered by the output pixel. The hi-falutin sampling literature
- refers to this as a "box filter". In general the characteristics of a box
- filter are not very good, but for the specific cases we normally use (1:1
- and 2:1 ratios) the box is equivalent to a "triangle filter" which is not
- nearly so bad. If you intend to use other sampling ratios, you'd be well
- advised to improve this code.
-
- A simple input-smoothing capability is provided. This is mainly intended
- for cleaning up color-dithered GIF input files (if you find it inadequate,
- we suggest using an external filtering program such as pnmconvol). When
- enabled, each input pixel P is replaced by a weighted sum of itself and its
- eight neighbors. P's weight is 1-8*SF and each neighbor's weight is SF,
- where SF := (smoothing_factor / 1024).
- Currently, smoothing is only supported for 2h2v sampling factors. }
-
-{ Original: jcsample.c ; Copyright (C) 1991-1996, Thomas G. Lane. }
-
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jutils,
- jdeferr,
- jerror,
- jpeglib;
-
-
-{ Module initialization routine for downsampling.
- Note that we must select a routine for each component. }
-
-{GLOBAL}
-procedure jinit_downsampler (cinfo : j_compress_ptr);
-
-implementation
-
-{ Pointer to routine to downsample a single component }
-type
- downsample1_ptr = procedure(cinfo : j_compress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- output_data : JSAMPARRAY);
-
-{ Private subobject }
-
-type
- my_downsample_ptr = ^my_downsampler;
- my_downsampler = record
- pub : jpeg_downsampler; { public fields }
-
- { Downsampling method pointers, one per component }
- methods : array[0..MAX_COMPONENTS-1] of downsample1_ptr;
- end;
-
-{ Initialize for a downsampling pass. }
-
-{METHODDEF}
-procedure start_pass_downsample (cinfo : j_compress_ptr); far;
-begin
- { no work for now }
-end;
-
-
-{ Expand a component horizontally from width input_cols to width output_cols,
- by duplicating the rightmost samples. }
-
-{LOCAL}
-procedure expand_right_edge (image_data : JSAMPARRAY;
- num_rows : int;
- input_cols : JDIMENSION;
- output_cols : JDIMENSION);
-var
- {register} ptr : JSAMPLE_PTR;
- {register} pixval : JSAMPLE;
- {register} count : int;
- row : int;
- numcols : int;
-begin
- numcols := int (output_cols - input_cols);
-
- if (numcols > 0) then
- begin
- for row := 0 to pred(num_rows) do
- begin
- ptr := JSAMPLE_PTR(@(image_data^[row]^[input_cols-1]));
- pixval := ptr^; { don't need GETJSAMPLE() here }
- for count := pred(numcols) downto 0 do
- begin
- Inc(ptr);
- ptr^ := pixval;
- end;
- end;
- end;
-end;
-
-
-{ Do downsampling for a whole row group (all components).
-
- In this version we simply downsample each component independently. }
-
-{METHODDEF}
-procedure sep_downsample (cinfo : j_compress_ptr;
- input_buf : JSAMPIMAGE;
- in_row_index : JDIMENSION;
- output_buf : JSAMPIMAGE;
- out_row_group_index : JDIMENSION); far;
-var
- downsample : my_downsample_ptr;
- ci : int;
- compptr : jpeg_component_info_ptr;
- in_ptr, out_ptr : JSAMPARRAY;
-begin
- downsample := my_downsample_ptr (cinfo^.downsample);
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- in_ptr := JSAMPARRAY(@ input_buf^[ci]^[in_row_index]);
- out_ptr := JSAMPARRAY(@ output_buf^[ci]^
- [out_row_group_index * compptr^.v_samp_factor]);
- downsample^.methods[ci] (cinfo, compptr, in_ptr, out_ptr);
- Inc(compptr);
- end;
-end;
-
-
-{ Downsample pixel values of a single component.
- One row group is processed per call.
- This version handles arbitrary integral sampling ratios, without smoothing.
- Note that this version is not actually used for customary sampling ratios. }
-
-{METHODDEF}
-procedure int_downsample (cinfo : j_compress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- output_data : JSAMPARRAY); far;
-var
- inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v : int;
- outcol, outcol_h : JDIMENSION; { outcol_h = outcol*h_expand }
- output_cols : JDIMENSION;
- inptr,
- outptr : JSAMPLE_PTR;
- outvalue : INT32;
-begin
- output_cols := compptr^.width_in_blocks * DCTSIZE;
-
- h_expand := cinfo^.max_h_samp_factor div compptr^.h_samp_factor;
- v_expand := cinfo^.max_v_samp_factor div compptr^.v_samp_factor;
- numpix := h_expand * v_expand;
- numpix2 := numpix div 2;
-
- { Expand input data enough to let all the output samples be generated
- by the standard loop. Special-casing padded output would be more
- efficient. }
-
- expand_right_edge(input_data, cinfo^.max_v_samp_factor,
- cinfo^.image_width, output_cols * h_expand);
-
- inrow := 0;
- for outrow := 0 to pred(compptr^.v_samp_factor) do
- begin
- outptr := JSAMPLE_PTR(output_data^[outrow]);
- outcol_h := 0;
- for outcol := 0 to pred(output_cols) do
- begin
- outvalue := 0;
- for v := 0 to pred(v_expand) do
- begin
- inptr := @(input_data^[inrow+v]^[outcol_h]);
- for h := 0 to pred(h_expand) do
- begin
- Inc(outvalue, INT32 (GETJSAMPLE(inptr^)) );
- Inc(inptr);
- end;
- end;
- outptr^ := JSAMPLE ((outvalue + numpix2) div numpix);
- Inc(outptr);
- Inc(outcol_h, h_expand);
- end;
- Inc(inrow, v_expand);
- end;
-end;
-
-
-{ Downsample pixel values of a single component.
- This version handles the special case of a full-size component,
- without smoothing. }
-
-{METHODDEF}
-procedure fullsize_downsample (cinfo : j_compress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- output_data : JSAMPARRAY); far;
-begin
- { Copy the data }
- jcopy_sample_rows(input_data, 0, output_data, 0,
- cinfo^.max_v_samp_factor, cinfo^.image_width);
- { Edge-expand }
- expand_right_edge(output_data, cinfo^.max_v_samp_factor,
- cinfo^.image_width, compptr^.width_in_blocks * DCTSIZE);
-end;
-
-
-{ Downsample pixel values of a single component.
- This version handles the common case of 2:1 horizontal and 1:1 vertical,
- without smoothing.
-
- A note about the "bias" calculations: when rounding fractional values to
- integer, we do not want to always round 0.5 up to the next integer.
- If we did that, we'd introduce a noticeable bias towards larger values.
- Instead, this code is arranged so that 0.5 will be rounded up or down at
- alternate pixel locations (a simple ordered dither pattern). }
-
-{METHODDEF}
-procedure h2v1_downsample (cinfo : j_compress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- output_data : JSAMPARRAY); far;
-var
- outrow : int;
- outcol : JDIMENSION;
- output_cols : JDIMENSION;
- {register} inptr, outptr : JSAMPLE_PTR;
- {register} bias : int;
-begin
- output_cols := compptr^.width_in_blocks * DCTSIZE;
-
- { Expand input data enough to let all the output samples be generated
- by the standard loop. Special-casing padded output would be more
- efficient. }
-
- expand_right_edge(input_data, cinfo^.max_v_samp_factor,
- cinfo^.image_width, output_cols * 2);
-
- for outrow := 0 to pred(compptr^.v_samp_factor) do
- begin
- outptr := JSAMPLE_PTR(output_data^[outrow]);
- inptr := JSAMPLE_PTR(input_data^[outrow]);
- bias := 0; { bias := 0,1,0,1,... for successive samples }
- for outcol := 0 to pred(output_cols) do
- begin
- outptr^ := JSAMPLE ((GETJSAMPLE(inptr^) +
- GETJSAMPLE(JSAMPROW(inptr)^[1]) + bias) shr 1);
- Inc(outptr);
- bias := bias xor 1; { 0=>1, 1=>0 }
- Inc(inptr, 2);
- end;
- end;
-end;
-
-
-{ Downsample pixel values of a single component.
- This version handles the standard case of 2:1 horizontal and 2:1 vertical,
- without smoothing. }
-
-{METHODDEF}
-procedure h2v2_downsample (cinfo : j_compress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- output_data : JSAMPARRAY); far;
-var
- inrow, outrow : int;
- outcol : JDIMENSION;
- output_cols : JDIMENSION;
- {register} inptr0, inptr1, outptr : JSAMPLE_PTR;
- {register} bias : int;
-begin
- output_cols := compptr^.width_in_blocks * DCTSIZE;
-
- { Expand input data enough to let all the output samples be generated
- by the standard loop. Special-casing padded output would be more
- efficient. }
-
- expand_right_edge(input_data, cinfo^.max_v_samp_factor,
- cinfo^.image_width, output_cols * 2);
-
- inrow := 0;
- for outrow := 0 to pred(compptr^.v_samp_factor) do
- begin
- outptr := JSAMPLE_PTR(output_data^[outrow]);
- inptr0 := JSAMPLE_PTR(input_data^[inrow]);
- inptr1 := JSAMPLE_PTR(input_data^[inrow+1]);
- bias := 1; { bias := 1,2,1,2,... for successive samples }
- for outcol := 0 to pred(output_cols) do
- begin
- outptr^ := JSAMPLE ((GETJSAMPLE(inptr0^) +
- GETJSAMPLE(JSAMPROW(inptr0)^[1]) +
- GETJSAMPLE(inptr1^) +
- GETJSAMPLE(JSAMPROW(inptr1)^[1]) + bias) shr 2);
- Inc(outptr);
- bias := bias xor 3; { 1=>2, 2=>1 }
- Inc(inptr0, 2);
- Inc(inptr1, 2);
- end;
- Inc(inrow, 2);
- end;
-end;
-
-
-{$ifdef INPUT_SMOOTHING_SUPPORTED}
-
-{ Downsample pixel values of a single component.
- This version handles the standard case of 2:1 horizontal and 2:1 vertical,
- with smoothing. One row of context is required. }
-
-{METHODDEF}
-procedure h2v2_smooth_downsample (cinfo : j_compress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- output_data : JSAMPARRAY); far;
-var
- inrow, outrow : int;
- colctr : JDIMENSION;
- output_cols : JDIMENSION;
- {register} inptr0, inptr1, above_ptr, below_ptr, outptr : JSAMPLE_PTR;
- membersum, neighsum, memberscale, neighscale : INT32;
-var
- prev_input_data : JSAMPARRAY;
- prev_inptr0, prev_inptr1, prev_above_ptr, prev_below_ptr : JSAMPLE_PTR;
-begin
- output_cols := compptr^.width_in_blocks * DCTSIZE;
-
- { Expand input data enough to let all the output samples be generated
- by the standard loop. Special-casing padded output would be more
- efficient. }
-
- prev_input_data := input_data;
- Dec(JSAMPROW_PTR(prev_input_data));
- expand_right_edge(prev_input_data, cinfo^.max_v_samp_factor + 2,
- cinfo^.image_width, output_cols * 2);
-
- { We don't bother to form the individual "smoothed" input pixel values;
- we can directly compute the output which is the average of the four
- smoothed values. Each of the four member pixels contributes a fraction
- (1-8*SF) to its own smoothed image and a fraction SF to each of the three
- other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final
- output. The four corner-adjacent neighbor pixels contribute a fraction
- SF to just one smoothed pixel, or SF/4 to the final output; while the
- eight edge-adjacent neighbors contribute SF to each of two smoothed
- pixels, or SF/2 overall. In order to use integer arithmetic, these
- factors are scaled by 2^16 := 65536.
- Also recall that SF := smoothing_factor / 1024. }
-
- memberscale := 16384 - cinfo^.smoothing_factor * 80; { scaled (1-5*SF)/4 }
- neighscale := cinfo^.smoothing_factor * 16; { scaled SF/4 }
-
- inrow := 0;
- for outrow := 0 to pred(compptr^.v_samp_factor) do
- begin
- outptr := JSAMPLE_PTR(output_data^[outrow]);
- inptr0 := JSAMPLE_PTR(input_data^[inrow]);
- inptr1 := JSAMPLE_PTR(input_data^[inrow+1]);
- above_ptr := JSAMPLE_PTR(input_data^[inrow-1]);
- below_ptr := JSAMPLE_PTR(input_data^[inrow+2]);
-
- { Special case for first column: pretend column -1 is same as column 0 }
- membersum := GETJSAMPLE(inptr0^) + GETJSAMPLE(JSAMPROW(inptr0)^[1]) +
- GETJSAMPLE(inptr1^) + GETJSAMPLE(JSAMPROW(inptr1)^[1]);
- neighsum := GETJSAMPLE(above_ptr^) + GETJSAMPLE(JSAMPROW(above_ptr)^[1]) +
- GETJSAMPLE(below_ptr^) + GETJSAMPLE(JSAMPROW(below_ptr)^[1]) +
- GETJSAMPLE(inptr0^) + GETJSAMPLE(JSAMPROW(inptr0)^[2]) +
- GETJSAMPLE(inptr1^) + GETJSAMPLE(JSAMPROW(inptr1)^[2]);
- Inc(neighsum, neighsum);
- Inc(neighsum, GETJSAMPLE(above_ptr^) +
- GETJSAMPLE(JSAMPROW(above_ptr)^[2]) +
- GETJSAMPLE(below_ptr^) +
- GETJSAMPLE(JSAMPROW(below_ptr)^[2]) );
- membersum := membersum * memberscale + neighsum * neighscale;
- outptr^ := JSAMPLE ((membersum + 32768) shr 16);
- Inc(outptr);
- prev_inptr0 := inptr0;
- prev_inptr1 := inptr1;
- Inc(prev_inptr0);
- Inc(prev_inptr1);
- Inc(inptr0, 2);
- Inc(inptr1, 2);
- prev_above_ptr := above_ptr;
- prev_below_ptr := below_ptr;
- Inc(above_ptr, 2);
- Inc(below_ptr, 2);
- Inc(prev_above_ptr, 1);
- Inc(prev_below_ptr, 1);
-
- for colctr := pred(output_cols - 2) downto 0 do
- begin
- { sum of pixels directly mapped to this output element }
- membersum := GETJSAMPLE(inptr0^) + GETJSAMPLE(JSAMPROW(inptr0)^[1]) +
- GETJSAMPLE(inptr1^) + GETJSAMPLE(JSAMPROW(inptr1)^[1]);
- { sum of edge-neighbor pixels }
- neighsum := GETJSAMPLE(above_ptr^) + GETJSAMPLE(JSAMPROW(above_ptr)^[1]) +
- GETJSAMPLE(below_ptr^) + GETJSAMPLE(JSAMPROW(below_ptr)^[1]) +
- GETJSAMPLE(prev_inptr0^) + GETJSAMPLE(JSAMPROW(inptr0)^[2]) +
- GETJSAMPLE(prev_inptr1^) + GETJSAMPLE(JSAMPROW(inptr1)^[2]);
- { The edge-neighbors count twice as much as corner-neighbors }
- Inc(neighsum, neighsum);
- { Add in the corner-neighbors }
- Inc(neighsum, GETJSAMPLE(prev_above_ptr^) +
- GETJSAMPLE(JSAMPROW(above_ptr)^[2]) +
- GETJSAMPLE(prev_below_ptr^) +
- GETJSAMPLE(JSAMPROW(below_ptr)^[2]) );
- { form final output scaled up by 2^16 }
- membersum := membersum * memberscale + neighsum * neighscale;
- { round, descale and output it }
- outptr^ := JSAMPLE ((membersum + 32768) shr 16);
- Inc(outptr);
- Inc(inptr0, 2);
- Inc(inptr1, 2);
- Inc(prev_inptr0, 2);
- Inc(prev_inptr1, 2);
- Inc(above_ptr, 2);
- Inc(below_ptr, 2);
- Inc(prev_above_ptr, 2);
- Inc(prev_below_ptr, 2);
- end;
-
- { Special case for last column }
- membersum := GETJSAMPLE(inptr0^) + GETJSAMPLE(JSAMPROW(inptr0)^[1]) +
- GETJSAMPLE(inptr1^) + GETJSAMPLE(JSAMPROW(inptr1)^[1]);
- neighsum := GETJSAMPLE(above_ptr^) + GETJSAMPLE(JSAMPROW(above_ptr)^[1]) +
- GETJSAMPLE(below_ptr^) + GETJSAMPLE(JSAMPROW(below_ptr)^[1]) +
- GETJSAMPLE(prev_inptr0^) + GETJSAMPLE(JSAMPROW(inptr0)^[1]) +
- GETJSAMPLE(prev_inptr1^) + GETJSAMPLE(JSAMPROW(inptr1)^[1]);
- Inc(neighsum, neighsum);
- Inc(neighsum, GETJSAMPLE(prev_above_ptr^) +
- GETJSAMPLE(JSAMPROW(above_ptr)^[1]) +
- GETJSAMPLE(prev_below_ptr^) +
- GETJSAMPLE(JSAMPROW(below_ptr)^[1]) );
- membersum := membersum * memberscale + neighsum * neighscale;
- outptr^ := JSAMPLE ((membersum + 32768) shr 16);
-
- Inc(inrow, 2);
- end;
-end;
-
-
-{ Downsample pixel values of a single component.
- This version handles the special case of a full-size component,
- with smoothing. One row of context is required. }
-
-{METHODDEF}
-procedure fullsize_smooth_downsample (cinfo : j_compress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- output_data : JSAMPARRAY); far;
-var
- outrow : int;
- colctr : JDIMENSION;
- output_cols : JDIMENSION;
- {register} inptr, above_ptr, below_ptr, outptr : JSAMPLE_PTR;
- membersum, neighsum, memberscale, neighscale : INT32;
- colsum, lastcolsum, nextcolsum : int;
-var
- prev_input_data : JSAMPARRAY;
-begin
- output_cols := compptr^.width_in_blocks * DCTSIZE;
-
- { Expand input data enough to let all the output samples be generated
- by the standard loop. Special-casing padded output would be more
- efficient. }
-
- prev_input_data := input_data;
- Dec(JSAMPROW_PTR(prev_input_data));
- expand_right_edge(prev_input_data, cinfo^.max_v_samp_factor + 2,
- cinfo^.image_width, output_cols);
-
- { Each of the eight neighbor pixels contributes a fraction SF to the
- smoothed pixel, while the main pixel contributes (1-8*SF). In order
- to use integer arithmetic, these factors are multiplied by 2^16 := 65536.
- Also recall that SF := smoothing_factor / 1024. }
-
- memberscale := long(65536) - cinfo^.smoothing_factor * long(512); { scaled 1-8*SF }
- neighscale := cinfo^.smoothing_factor * 64; { scaled SF }
-
- for outrow := 0 to pred(compptr^.v_samp_factor) do
- begin
- outptr := JSAMPLE_PTR(output_data^[outrow]);
- inptr := JSAMPLE_PTR(input_data^[outrow]);
- above_ptr := JSAMPLE_PTR(input_data^[outrow-1]);
- below_ptr := JSAMPLE_PTR(input_data^[outrow+1]);
-
- { Special case for first column }
- colsum := GETJSAMPLE(above_ptr^) + GETJSAMPLE(below_ptr^) +
- GETJSAMPLE(inptr^);
- Inc(above_ptr);
- Inc(below_ptr);
- membersum := GETJSAMPLE(inptr^);
- Inc(inptr);
- nextcolsum := GETJSAMPLE(above_ptr^) + GETJSAMPLE(below_ptr^) +
- GETJSAMPLE(inptr^);
- neighsum := colsum + (colsum - membersum) + nextcolsum;
- membersum := membersum * memberscale + neighsum * neighscale;
- outptr^ := JSAMPLE ((membersum + 32768) shr 16);
- Inc(outptr);
- lastcolsum := colsum; colsum := nextcolsum;
-
- for colctr := pred(output_cols - 2) downto 0 do
- begin
- membersum := GETJSAMPLE(inptr^);
- Inc(inptr);
- Inc(above_ptr);
- Inc(below_ptr);
- nextcolsum := GETJSAMPLE(above_ptr^) + GETJSAMPLE(below_ptr^) +
- GETJSAMPLE(inptr^);
- neighsum := lastcolsum + (colsum - membersum) + nextcolsum;
- membersum := membersum * memberscale + neighsum * neighscale;
- outptr^ := JSAMPLE ((membersum + 32768) shr 16);
- Inc(outptr);
- lastcolsum := colsum; colsum := nextcolsum;
- end;
-
- { Special case for last column }
- membersum := GETJSAMPLE(inptr^);
- neighsum := lastcolsum + (colsum - membersum) + colsum;
- membersum := membersum * memberscale + neighsum * neighscale;
- outptr^ := JSAMPLE ((membersum + 32768) shr 16);
- end;
-end;
-
-{$endif} { INPUT_SMOOTHING_SUPPORTED }
-
-
-{ Module initialization routine for downsampling.
- Note that we must select a routine for each component. }
-
-{GLOBAL}
-procedure jinit_downsampler (cinfo : j_compress_ptr);
-var
- downsample : my_downsample_ptr;
- ci : int;
- compptr : jpeg_component_info_ptr;
- smoothok : boolean;
-begin
- smoothok := TRUE;
-
- downsample := my_downsample_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_downsampler)) );
- cinfo^.downsample := jpeg_downsampler_ptr (downsample);
- downsample^.pub.start_pass := start_pass_downsample;
- downsample^.pub.downsample := sep_downsample;
- downsample^.pub.need_context_rows := FALSE;
-
- if (cinfo^.CCIR601_sampling) then
- ERREXIT(j_common_ptr(cinfo), JERR_CCIR601_NOTIMPL);
-
- { Verify we can handle the sampling factors, and set up method pointers }
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- if (compptr^.h_samp_factor = cinfo^.max_h_samp_factor) and
- (compptr^.v_samp_factor = cinfo^.max_v_samp_factor) then
- begin
-{$ifdef INPUT_SMOOTHING_SUPPORTED}
- if (cinfo^.smoothing_factor <> 0) then
- begin
- downsample^.methods[ci] := fullsize_smooth_downsample;
- downsample^.pub.need_context_rows := TRUE;
- end
- else
-{$endif}
- downsample^.methods[ci] := fullsize_downsample;
- end
- else
- if (compptr^.h_samp_factor * 2 = cinfo^.max_h_samp_factor) and
- (compptr^.v_samp_factor = cinfo^.max_v_samp_factor) then
- begin
- smoothok := FALSE;
- downsample^.methods[ci] := h2v1_downsample;
- end
- else
- if (compptr^.h_samp_factor * 2 = cinfo^.max_h_samp_factor) and
- (compptr^.v_samp_factor * 2 = cinfo^.max_v_samp_factor) then
- begin
- {$ifdef INPUT_SMOOTHING_SUPPORTED}
- if (cinfo^.smoothing_factor <> 0) then
- begin
- downsample^.methods[ci] := h2v2_smooth_downsample;
- downsample^.pub.need_context_rows := TRUE;
- end
- else
- {$endif}
- downsample^.methods[ci] := h2v2_downsample;
- end
- else
- if ((cinfo^.max_h_samp_factor mod compptr^.h_samp_factor) = 0) and
- ((cinfo^.max_v_samp_factor mod compptr^.v_samp_factor) = 0) then
- begin
- smoothok := FALSE;
- downsample^.methods[ci] := int_downsample;
- end
- else
- ERREXIT(j_common_ptr(cinfo), JERR_FRACT_SAMPLE_NOTIMPL);
- Inc(compptr);
- end;
-
-{$ifdef INPUT_SMOOTHING_SUPPORTED}
- if (cinfo^.smoothing_factor <> 0) and (not smoothok) then
- TRACEMS(j_common_ptr(cinfo), 0, JTRC_SMOOTH_NOTIMPL);
-{$endif}
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jctrans.pas b/packages/base/pasjpeg/jctrans.pas
deleted file mode 100644
index e95f8f5989..0000000000
--- a/packages/base/pasjpeg/jctrans.pas
+++ /dev/null
@@ -1,459 +0,0 @@
-Unit JcTrans;
-
-{ This file contains library routines for transcoding compression,
- that is, writing raw DCT coefficient arrays to an output JPEG file.
- The routines in jcapimin.c will also be needed by a transcoder. }
-
-{ Original : jctrans.c - Copyright (C) 1995-1998, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jutils,
- jpeglib,
- jcapimin, jcparam, jcomapi, jcmaster, jchuff, jcphuff, jcmarker;
-
-{ Compression initialization for writing raw-coefficient data.
- Before calling this, all parameters and a data destination must be set up.
- Call jpeg_finish_compress() to actually write the data.
-
- The number of passed virtual arrays must match cinfo^.num_components.
- Note that the virtual arrays need not be filled or even realized at
- the time write_coefficients is called; indeed, if the virtual arrays
- were requested from this compression object's memory manager, they
- typically will be realized during this routine and filled afterwards. }
-
-{GLOBAL}
-procedure jpeg_write_coefficients (cinfo : j_compress_ptr;
- coef_arrays : jvirt_barray_tbl_ptr);
-
-{ Initialize the compression object with default parameters,
- then copy from the source object all parameters needed for lossless
- transcoding. Parameters that can be varied without loss (such as
- scan script and Huffman optimization) are left in their default states. }
-
-{GLOBAL}
-procedure jpeg_copy_critical_parameters (srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr);
-
-
-implementation
-
-{ Forward declarations }
-{LOCAL}
-procedure transencode_master_selection(cinfo : j_compress_ptr;
- coef_arrays : jvirt_barray_tbl_ptr);
- forward;
-{LOCAL}
-procedure transencode_coef_controller(cinfo : j_compress_ptr;
- coef_arrays : jvirt_barray_tbl_ptr);
- forward;
-
-
-{ Compression initialization for writing raw-coefficient data.
- Before calling this, all parameters and a data destination must be set up.
- Call jpeg_finish_compress() to actually write the data.
-
- The number of passed virtual arrays must match cinfo^.num_components.
- Note that the virtual arrays need not be filled or even realized at
- the time write_coefficients is called; indeed, if the virtual arrays
- were requested from this compression object's memory manager, they
- typically will be realized during this routine and filled afterwards. }
-
-{GLOBAL}
-procedure jpeg_write_coefficients (cinfo : j_compress_ptr;
- coef_arrays : jvirt_barray_tbl_ptr);
-begin
- if (cinfo^.global_state <> CSTATE_START) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- { Mark all tables to be written }
- jpeg_suppress_tables(cinfo, FALSE);
- { (Re)initialize error mgr and destination modules }
- cinfo^.err^.reset_error_mgr (j_common_ptr(cinfo));
- cinfo^.dest^.init_destination (cinfo);
- { Perform master selection of active modules }
- transencode_master_selection(cinfo, coef_arrays);
- { Wait for jpeg_finish_compress() call }
- cinfo^.next_scanline := 0; { so jpeg_write_marker works }
- cinfo^.global_state := CSTATE_WRCOEFS;
-end;
-
-
-{ Initialize the compression object with default parameters,
- then copy from the source object all parameters needed for lossless
- transcoding. Parameters that can be varied without loss (such as
- scan script and Huffman optimization) are left in their default states. }
-
-{GLOBAL}
-procedure jpeg_copy_critical_parameters (srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr);
-var
- qtblptr : ^JQUANT_TBL_PTR;
- incomp, outcomp : jpeg_component_info_ptr;
- c_quant, slot_quant : JQUANT_TBL_PTR;
- tblno, ci, coefi : int;
-begin
-
- { Safety check to ensure start_compress not called yet. }
- if (dstinfo^.global_state <> CSTATE_START) then
- ERREXIT1(j_common_ptr(dstinfo), JERR_BAD_STATE, dstinfo^.global_state);
- { Copy fundamental image dimensions }
- dstinfo^.image_width := srcinfo^.image_width;
- dstinfo^.image_height := srcinfo^.image_height;
- dstinfo^.input_components := srcinfo^.num_components;
- dstinfo^.in_color_space := srcinfo^.jpeg_color_space;
- { Initialize all parameters to default values }
- jpeg_set_defaults(dstinfo);
- { jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB.
- Fix it to get the right header markers for the image colorspace. }
-
- jpeg_set_colorspace(dstinfo, srcinfo^.jpeg_color_space);
- dstinfo^.data_precision := srcinfo^.data_precision;
- dstinfo^.CCIR601_sampling := srcinfo^.CCIR601_sampling;
- { Copy the source's quantization tables. }
- for tblno := 0 to pred(NUM_QUANT_TBLS) do
- begin
- if (srcinfo^.quant_tbl_ptrs[tblno] <> NIL) then
- begin
- qtblptr := @dstinfo^.quant_tbl_ptrs[tblno];
- if (qtblptr^ = NIL) then
- qtblptr^ := jpeg_alloc_quant_table(j_common_ptr(dstinfo));
- MEMCOPY(@(qtblptr^)^.quantval,
- @srcinfo^.quant_tbl_ptrs[tblno]^.quantval,
- SIZEOF((qtblptr^)^.quantval));
- (qtblptr^)^.sent_table := FALSE;
- end;
- end;
- { Copy the source's per-component info.
- Note we assume jpeg_set_defaults has allocated the dest comp_info array. }
-
- dstinfo^.num_components := srcinfo^.num_components;
- if (dstinfo^.num_components < 1) or
- (dstinfo^.num_components > MAX_COMPONENTS) then
- ERREXIT2(j_common_ptr(dstinfo), JERR_COMPONENT_COUNT,
- dstinfo^.num_components, MAX_COMPONENTS);
- incomp := jpeg_component_info_ptr(srcinfo^.comp_info);
- outcomp := jpeg_component_info_ptr(dstinfo^.comp_info);
- for ci := 0 to pred(dstinfo^.num_components) do
- begin
-
- outcomp^.component_id := incomp^.component_id;
- outcomp^.h_samp_factor := incomp^.h_samp_factor;
- outcomp^.v_samp_factor := incomp^.v_samp_factor;
- outcomp^.quant_tbl_no := incomp^.quant_tbl_no;
- { Make sure saved quantization table for component matches the qtable
- slot. If not, the input file re-used this qtable slot.
- IJG encoder currently cannot duplicate this. }
-
- tblno := outcomp^.quant_tbl_no;
- if (tblno < 0) or (tblno >= NUM_QUANT_TBLS) or
- (srcinfo^.quant_tbl_ptrs[tblno] = NIL) then
- ERREXIT1(j_common_ptr(dstinfo), JERR_NO_QUANT_TABLE, tblno);
- slot_quant := srcinfo^.quant_tbl_ptrs[tblno];
- c_quant := incomp^.quant_table;
- if (c_quant <> NIL) then
- begin
- for coefi := 0 to pred(DCTSIZE2) do
- begin
- if (c_quant^.quantval[coefi] <> slot_quant^.quantval[coefi]) then
- ERREXIT1(j_common_ptr(dstinfo), JERR_MISMATCHED_QUANT_TABLE, tblno);
- end;
- end;
- { Note: we do not copy the source's Huffman table assignments;
- instead we rely on jpeg_set_colorspace to have made a suitable choice. }
- Inc(incomp);
- Inc(outcomp);
- end;
- { Also copy JFIF version and resolution information, if available.
- Strictly speaking this isn't "critical" info, but it's nearly
- always appropriate to copy it if available. In particular,
- if the application chooses to copy JFIF 1.02 extension markers from
- the source file, we need to copy the version to make sure we don't
- emit a file that has 1.02 extensions but a claimed version of 1.01.
- We will *not*, however, copy version info from mislabeled "2.01" files. }
-
- if (srcinfo^.saw_JFIF_marker) then
- begin
- if (srcinfo^.JFIF_major_version = 1) then
- begin
- dstinfo^.JFIF_major_version := srcinfo^.JFIF_major_version;
- dstinfo^.JFIF_minor_version := srcinfo^.JFIF_minor_version;
- end;
- dstinfo^.density_unit := srcinfo^.density_unit;
- dstinfo^.X_density := srcinfo^.X_density;
- dstinfo^.Y_density := srcinfo^.Y_density;
- end;
-end;
-
-
-{ Master selection of compression modules for transcoding.
- This substitutes for jcinit.c's initialization of the full compressor. }
-
-{LOCAL}
-procedure transencode_master_selection (cinfo : j_compress_ptr;
- coef_arrays : jvirt_barray_tbl_ptr);
-begin
- { Although we don't actually use input_components for transcoding,
- jcmaster.c's initial_setup will complain if input_components is 0. }
-
- cinfo^.input_components := 1;
- { Initialize master control (includes parameter checking/processing) }
- jinit_c_master_control(cinfo, TRUE { transcode only });
-
- { Entropy encoding: either Huffman or arithmetic coding. }
- if (cinfo^.arith_code) then
- begin
- ERREXIT(j_common_ptr(cinfo), JERR_ARITH_NOTIMPL);
- end
- else
- begin
- if (cinfo^.progressive_mode) then
- begin
-{$ifdef C_PROGRESSIVE_SUPPORTED}
- jinit_phuff_encoder(cinfo);
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end
- else
- jinit_huff_encoder(cinfo);
- end;
-
- { We need a special coefficient buffer controller. }
- transencode_coef_controller(cinfo, coef_arrays);
-
- jinit_marker_writer(cinfo);
-
- { We can now tell the memory manager to allocate virtual arrays. }
- cinfo^.mem^.realize_virt_arrays (j_common_ptr(cinfo));
-
- { Write the datastream header (SOI, JFIF) immediately.
- Frame and scan headers are postponed till later.
- This lets application insert special markers after the SOI. }
-
- cinfo^.marker^.write_file_header (cinfo);
-end;
-
-
-{ The rest of this file is a special implementation of the coefficient
- buffer controller. This is similar to jccoefct.c, but it handles only
- output from presupplied virtual arrays. Furthermore, we generate any
- dummy padding blocks on-the-fly rather than expecting them to be present
- in the arrays. }
-
-{ Private buffer controller object }
-
-type
- my_coef_ptr = ^my_coef_controller;
- my_coef_controller = record
- pub : jpeg_c_coef_controller; { public fields }
-
- iMCU_row_num : JDIMENSION; { iMCU row # within image }
- mcu_ctr : JDIMENSION; { counts MCUs processed in current row }
- MCU_vert_offset : int; { counts MCU rows within iMCU row }
- MCU_rows_per_iMCU_row : int; { number of such rows needed }
-
- { Virtual block array for each component. }
- whole_image : jvirt_barray_tbl_ptr;
-
- { Workspace for constructing dummy blocks at right/bottom edges. }
- dummy_buffer : array[0..C_MAX_BLOCKS_IN_MCU-1] of JBLOCKROW;
- end; {my_coef_controller;}
-
-
-{LOCAL}
-procedure start_iMCU_row (cinfo : j_compress_ptr);
-{ Reset within-iMCU-row counters for a new row }
-var
- coef : my_coef_ptr;
-begin
- coef := my_coef_ptr (cinfo^.coef);
-
- { In an interleaved scan, an MCU row is the same as an iMCU row.
- In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
- But at the bottom of the image, process only what's left. }
-
- if (cinfo^.comps_in_scan > 1) then
- begin
- coef^.MCU_rows_per_iMCU_row := 1;
- end
- else
- begin
- if (coef^.iMCU_row_num < (cinfo^.total_iMCU_rows-1)) then
- coef^.MCU_rows_per_iMCU_row := cinfo^.cur_comp_info[0]^.v_samp_factor
- else
- coef^.MCU_rows_per_iMCU_row := cinfo^.cur_comp_info[0]^.last_row_height;
- end;
-
- coef^.mcu_ctr := 0;
- coef^.MCU_vert_offset := 0;
-end;
-
-
-{ Initialize for a processing pass. }
-
-{METHODDEF}
-procedure start_pass_coef (cinfo : j_compress_ptr;
- pass_mode : J_BUF_MODE); far;
-var
- coef : my_coef_ptr;
-begin
- coef := my_coef_ptr (cinfo^.coef);
-
- if (pass_mode <> JBUF_CRANK_DEST) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
-
- coef^.iMCU_row_num := 0;
- start_iMCU_row(cinfo);
-end;
-
-
-{ Process some data.
- We process the equivalent of one fully interleaved MCU row ("iMCU" row)
- per call, ie, v_samp_factor block rows for each component in the scan.
- The data is obtained from the virtual arrays and fed to the entropy coder.
- Returns TRUE if the iMCU row is completed, FALSE if suspended.
-
- NB: input_buf is ignored; it is likely to be a NIL pointer. }
-
-{METHODDEF}
-function compress_output (cinfo : j_compress_ptr;
- input_buf : JSAMPIMAGE) : boolean; far;
-var
- coef : my_coef_ptr;
- MCU_col_num : JDIMENSION; { index of current MCU within row }
- last_MCU_col : JDIMENSION;
- last_iMCU_row : JDIMENSION;
- blkn, ci, xindex, yindex, yoffset, blockcnt : int;
- start_col : JDIMENSION;
- buffer : array[0..MAX_COMPS_IN_SCAN-1] of JBLOCKARRAY;
- MCU_buffer : array[0..C_MAX_BLOCKS_IN_MCU-1] of JBLOCKROW;
- buffer_ptr : JBLOCKROW;
- compptr : jpeg_component_info_ptr;
-begin
- coef := my_coef_ptr (cinfo^.coef);
- last_MCU_col := cinfo^.MCUs_per_row - 1;
- last_iMCU_row := cinfo^.total_iMCU_rows - 1;
-
- { Align the virtual buffers for the components used in this scan. }
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- buffer[ci] := cinfo^.mem^.access_virt_barray
- (j_common_ptr(cinfo), coef^.whole_image^[compptr^.component_index],
- coef^.iMCU_row_num * compptr^.v_samp_factor,
- JDIMENSION(compptr^.v_samp_factor), FALSE);
- end;
-
- { Loop to process one whole iMCU row }
- for yoffset := coef^.MCU_vert_offset to pred(coef^.MCU_rows_per_iMCU_row) do
- begin
- for MCU_col_num := coef^.mcu_ctr to pred(cinfo^.MCUs_per_row) do
- begin
- { Construct list of pointers to DCT blocks belonging to this MCU }
- blkn := 0; { index of current DCT block within MCU }
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- start_col := MCU_col_num * compptr^.MCU_width;
- if (MCU_col_num < last_MCU_col) then
- blockcnt := compptr^.MCU_width
- else
- blockcnt := compptr^.last_col_width;
- for yindex := 0 to pred(compptr^.MCU_height) do
- begin
- if (coef^.iMCU_row_num < last_iMCU_row) or
- (yindex+yoffset < compptr^.last_row_height) then
- begin
- { Fill in pointers to real blocks in this row }
- buffer_ptr := JBLOCKROW(@ buffer[ci]^[yindex+yoffset]^[start_col]);
- for xindex := 0 to pred(blockcnt) do
- begin
- MCU_buffer[blkn] := buffer_ptr;
- Inc(blkn);
- Inc(JBLOCK_PTR(buffer_ptr));
- end;
- xindex := blockcnt;
- end
- else
- begin
- { At bottom of image, need a whole row of dummy blocks }
- xindex := 0;
- end;
- { Fill in any dummy blocks needed in this row.
- Dummy blocks are filled in the same way as in jccoefct.c:
- all zeroes in the AC entries, DC entries equal to previous
- block's DC value. The init routine has already zeroed the
- AC entries, so we need only set the DC entries correctly. }
-
- while (xindex < compptr^.MCU_width) do
- begin
- MCU_buffer[blkn] := coef^.dummy_buffer[blkn];
- MCU_buffer[blkn]^[0][0] := MCU_buffer[blkn-1]^[0][0];
- Inc(xindex);
- Inc(blkn);
- end;
- end;
- end;
- { Try to write the MCU. }
- if (not cinfo^.entropy^.encode_mcu (cinfo, MCU_buffer)) then
- begin
- { Suspension forced; update state counters and exit }
- coef^.MCU_vert_offset := yoffset;
- coef^.mcu_ctr := MCU_col_num;
- compress_output := FALSE;
- exit;
- end;
- end;
- { Completed an MCU row, but perhaps not an iMCU row }
- coef^.mcu_ctr := 0;
- end;
- { Completed the iMCU row, advance counters for next one }
- Inc(coef^.iMCU_row_num);
- start_iMCU_row(cinfo);
- compress_output := TRUE;
-end;
-
-
-{ Initialize coefficient buffer controller.
-
- Each passed coefficient array must be the right size for that
- coefficient: width_in_blocks wide and height_in_blocks high,
- with unitheight at least v_samp_factor. }
-
-{LOCAL}
-procedure transencode_coef_controller (cinfo : j_compress_ptr;
- coef_arrays : jvirt_barray_tbl_ptr);
-var
- coef : my_coef_ptr;
- buffer : JBLOCKROW;
- i : int;
-begin
- coef := my_coef_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_coef_controller)));
- cinfo^.coef := jpeg_c_coef_controller_ptr (coef);
- coef^.pub.start_pass := start_pass_coef;
- coef^.pub.compress_data := compress_output;
-
- { Save pointer to virtual arrays }
- coef^.whole_image := coef_arrays;
-
- { Allocate and pre-zero space for dummy DCT blocks. }
- buffer := JBLOCKROW(
- cinfo^.mem^.alloc_large (j_common_ptr(cinfo), JPOOL_IMAGE,
- C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)) );
- jzero_far({FAR} voidp(buffer), C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
- for i := 0 to pred(C_MAX_BLOCKS_IN_MCU) do
- begin
- coef^.dummy_buffer[i] := JBLOCKROW(@ buffer^[i]);
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdapimin.pas b/packages/base/pasjpeg/jdapimin.pas
deleted file mode 100644
index d1930c0358..0000000000
--- a/packages/base/pasjpeg/jdapimin.pas
+++ /dev/null
@@ -1,505 +0,0 @@
-Unit JdAPImin;
-
-{$N+} { Nomssi: cinfo^.output_gamma }
-
-{ This file contains application interface code for the decompression half
- of the JPEG library. These are the "minimum" API routines that may be
- needed in either the normal full-decompression case or the
- transcoding-only case.
-
- Most of the routines intended to be called directly by an application
- are in this file or in jdapistd.c. But also see jcomapi.c for routines
- shared by compression and decompression, and jdtrans.c for the transcoding
- case. }
-
-{ Original : jdapimin.c ; Copyright (C) 1994-1998, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jpeglib,
- jmemmgr, jdmarker, jdinput, jcomapi;
-
-{ Nomssi }
-procedure jpeg_create_decompress(cinfo : j_decompress_ptr);
-
-{ Initialization of a JPEG decompression object.
- The error manager must already be set up (in case memory manager fails). }
-
-{GLOBAL}
-procedure jpeg_CreateDecompress (cinfo : j_decompress_ptr;
- version : int;
- structsize : size_t);
-
-{ Destruction of a JPEG decompression object }
-
-{GLOBAL}
-procedure jpeg_destroy_decompress (cinfo : j_decompress_ptr);
-
-
-{ Decompression startup: read start of JPEG datastream to see what's there.
- Need only initialize JPEG object and supply a data source before calling.
-
- This routine will read as far as the first SOS marker (ie, actual start of
- compressed data), and will save all tables and parameters in the JPEG
- object. It will also initialize the decompression parameters to default
- values, and finally return JPEG_HEADER_OK. On return, the application may
- adjust the decompression parameters and then call jpeg_start_decompress.
- (Or, if the application only wanted to determine the image parameters,
- the data need not be decompressed. In that case, call jpeg_abort or
- jpeg_destroy to release any temporary space.)
- If an abbreviated (tables only) datastream is presented, the routine will
- return JPEG_HEADER_TABLES_ONLY upon reaching EOI. The application may then
- re-use the JPEG object to read the abbreviated image datastream(s).
- It is unnecessary (but OK) to call jpeg_abort in this case.
- The JPEG_SUSPENDED return code only occurs if the data source module
- requests suspension of the decompressor. In this case the application
- should load more source data and then re-call jpeg_read_header to resume
- processing.
- If a non-suspending data source is used and require_image is TRUE, then the
- return code need not be inspected since only JPEG_HEADER_OK is possible.
-
- This routine is now just a front end to jpeg_consume_input, with some
- extra error checking. }
-
-{GLOBAL}
-function jpeg_read_header (cinfo : j_decompress_ptr;
- require_image : boolean) : int;
-
-{ Consume data in advance of what the decompressor requires.
- This can be called at any time once the decompressor object has
- been created and a data source has been set up.
-
- This routine is essentially a state machine that handles a couple
- of critical state-transition actions, namely initial setup and
- transition from header scanning to ready-for-start_decompress.
- All the actual input is done via the input controller's consume_input
- method. }
-
-{GLOBAL}
-function jpeg_consume_input (cinfo : j_decompress_ptr) : int;
-
-{ Have we finished reading the input file? }
-
-{GLOBAL}
-function jpeg_input_complete (cinfo : j_decompress_ptr) : boolean;
-
-{ Is there more than one scan? }
-
-{GLOBAL}
-function jpeg_has_multiple_scans (cinfo : j_decompress_ptr) : boolean;
-
-
-{ Finish JPEG decompression.
-
- This will normally just verify the file trailer and release temp storage.
-
- Returns FALSE if suspended. The return value need be inspected only if
- a suspending data source is used. }
-
-{GLOBAL}
-function jpeg_finish_decompress (cinfo : j_decompress_ptr) : boolean;
-
-implementation
-
-procedure jpeg_create_decompress(cinfo : j_decompress_ptr);
-begin
- jpeg_CreateDecompress(cinfo, JPEG_LIB_VERSION,
- size_t(sizeof(jpeg_decompress_struct)));
-end;
-
-{ Initialization of a JPEG decompression object.
- The error manager must already be set up (in case memory manager fails). }
-
-{GLOBAL}
-procedure jpeg_CreateDecompress (cinfo : j_decompress_ptr;
- version : int;
- structsize : size_t);
-var
- i : int;
-var
- err : jpeg_error_mgr_ptr;
- client_data : voidp;
-begin
- { Guard against version mismatches between library and caller. }
- cinfo^.mem := NIL; { so jpeg_destroy knows mem mgr not called }
- if (version <> JPEG_LIB_VERSION) then
- ERREXIT2(j_common_ptr(cinfo), JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
- if (structsize <> SIZEOF(jpeg_decompress_struct)) then
- ERREXIT2(j_common_ptr(cinfo), JERR_BAD_STRUCT_SIZE,
- int(SIZEOF(jpeg_decompress_struct)), int(structsize));
-
- { For debugging purposes, we zero the whole master structure.
- But the application has already set the err pointer, and may have set
- client_data, so we have to save and restore those fields.
- Note: if application hasn't set client_data, tools like Purify may
- complain here. }
- begin
- err := cinfo^.err;
- client_data := cinfo^.client_data; { ignore Purify complaint here }
- MEMZERO(j_common_ptr(cinfo), SIZEOF(jpeg_decompress_struct));
- cinfo^.err := err;
- cinfo^.client_data := client_data;
- end;
- cinfo^.is_decompressor := TRUE;
-
- { Initialize a memory manager instance for this object }
- jinit_memory_mgr(j_common_ptr(cinfo));
-
- { Zero out pointers to permanent structures. }
- cinfo^.progress := NIL;
- cinfo^.src := NIL;
-
- for i := 0 to pred(NUM_QUANT_TBLS) do
- cinfo^.quant_tbl_ptrs[i] := NIL;
-
- for i := 0 to pred(NUM_HUFF_TBLS) do
- begin
- cinfo^.dc_huff_tbl_ptrs[i] := NIL;
- cinfo^.ac_huff_tbl_ptrs[i] := NIL;
- end;
-
- { Initialize marker processor so application can override methods
- for COM, APPn markers before calling jpeg_read_header. }
- cinfo^.marker_list := NIL;
- jinit_marker_reader(cinfo);
-
- { And initialize the overall input controller. }
- jinit_input_controller(cinfo);
-
- { OK, I'm ready }
- cinfo^.global_state := DSTATE_START;
-end;
-
-
-{ Destruction of a JPEG decompression object }
-
-{GLOBAL}
-procedure jpeg_destroy_decompress (cinfo : j_decompress_ptr);
-begin
- jpeg_destroy(j_common_ptr(cinfo)); { use common routine }
-end;
-
-
-{ Abort processing of a JPEG decompression operation,
- but don't destroy the object itself. }
-
-{GLOBAL}
-procedure jpeg_abort_decompress (cinfo : j_decompress_ptr);
-begin
- jpeg_abort(j_common_ptr(cinfo)); { use common routine }
-end;
-
-
-{ Set default decompression parameters. }
-
-{LOCAL}
-procedure default_decompress_parms (cinfo : j_decompress_ptr);
-var
- cid0 : int;
- cid1 : int;
- cid2 : int;
-begin
- { 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. }
- case (cinfo^.num_components) of
- 1: begin
- cinfo^.jpeg_color_space := JCS_GRAYSCALE;
- cinfo^.out_color_space := JCS_GRAYSCALE;
- end;
-
- 3: begin
- if (cinfo^.saw_JFIF_marker) then
- begin
- cinfo^.jpeg_color_space := JCS_YCbCr; { JFIF implies YCbCr }
- end
- else
- if (cinfo^.saw_Adobe_marker) then
- begin
- case (cinfo^.Adobe_transform) of
- 0: cinfo^.jpeg_color_space := JCS_RGB;
- 1: cinfo^.jpeg_color_space := JCS_YCbCr;
- else
- begin
- WARNMS1(j_common_ptr(cinfo), JWRN_ADOBE_XFORM, cinfo^.Adobe_transform);
- cinfo^.jpeg_color_space := JCS_YCbCr; { assume it's YCbCr }
- end;
- end;
- end
- else
- begin
- { Saw no special markers, try to guess from the component IDs }
- cid0 := cinfo^.comp_info^[0].component_id;
- cid1 := cinfo^.comp_info^[1].component_id;
- cid2 := cinfo^.comp_info^[2].component_id;
-
- if (cid0 = 1) and (cid1 = 2) and (cid2 = 3) then
- cinfo^.jpeg_color_space := JCS_YCbCr { assume JFIF w/out marker }
- else
- if (cid0 = 82) and (cid1 = 71) and (cid2 = 66) then
- cinfo^.jpeg_color_space := JCS_RGB { ASCII 'R', 'G', 'B' }
- else
- begin
- {$IFDEF DEBUG}
- TRACEMS3(j_common_ptr(cinfo), 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
- {$ENDIF}
- cinfo^.jpeg_color_space := JCS_YCbCr; { assume it's YCbCr }
- end;
- end;
- { Always guess RGB is proper output colorspace. }
- cinfo^.out_color_space := JCS_RGB;
- end;
-
- 4: begin
- if (cinfo^.saw_Adobe_marker) then
- begin
- case (cinfo^.Adobe_transform) of
- 0: cinfo^.jpeg_color_space := JCS_CMYK;
- 2: cinfo^.jpeg_color_space := JCS_YCCK;
- else
- begin
- WARNMS1(j_common_ptr(cinfo), JWRN_ADOBE_XFORM, cinfo^.Adobe_transform);
- cinfo^.jpeg_color_space := JCS_YCCK; { assume it's YCCK }
- end;
- end;
- end
- else
- begin
- { No special markers, assume straight CMYK. }
- cinfo^.jpeg_color_space := JCS_CMYK;
- end;
- cinfo^.out_color_space := JCS_CMYK;
- end;
-
- else
- begin
- cinfo^.jpeg_color_space := JCS_UNKNOWN;
- cinfo^.out_color_space := JCS_UNKNOWN;
- end;
- end;
-
- { Set defaults for other decompression parameters. }
- cinfo^.scale_num := 1; { 1:1 scaling }
- cinfo^.scale_denom := 1;
- cinfo^.output_gamma := 1.0;
- cinfo^.buffered_image := FALSE;
- cinfo^.raw_data_out := FALSE;
- cinfo^.dct_method := JDCT_DEFAULT;
- cinfo^.do_fancy_upsampling := TRUE;
- cinfo^.do_block_smoothing := TRUE;
- cinfo^.quantize_colors := FALSE;
- { We set these in case application only sets quantize_colors. }
- cinfo^.dither_mode := JDITHER_FS;
-{$ifdef QUANT_2PASS_SUPPORTED}
- cinfo^.two_pass_quantize := TRUE;
-{$else}
- cinfo^.two_pass_quantize := FALSE;
-{$endif}
- cinfo^.desired_number_of_colors := 256;
- cinfo^.colormap := NIL;
- { Initialize for no mode change in buffered-image mode. }
- cinfo^.enable_1pass_quant := FALSE;
- cinfo^.enable_external_quant := FALSE;
- cinfo^.enable_2pass_quant := FALSE;
-end;
-
-
-{ Decompression startup: read start of JPEG datastream to see what's there.
- Need only initialize JPEG object and supply a data source before calling.
-
- This routine will read as far as the first SOS marker (ie, actual start of
- compressed data), and will save all tables and parameters in the JPEG
- object. It will also initialize the decompression parameters to default
- values, and finally return JPEG_HEADER_OK. On return, the application may
- adjust the decompression parameters and then call jpeg_start_decompress.
- (Or, if the application only wanted to determine the image parameters,
- the data need not be decompressed. In that case, call jpeg_abort or
- jpeg_destroy to release any temporary space.)
- If an abbreviated (tables only) datastream is presented, the routine will
- return JPEG_HEADER_TABLES_ONLY upon reaching EOI. The application may then
- re-use the JPEG object to read the abbreviated image datastream(s).
- It is unnecessary (but OK) to call jpeg_abort in this case.
- The JPEG_SUSPENDED return code only occurs if the data source module
- requests suspension of the decompressor. In this case the application
- should load more source data and then re-call jpeg_read_header to resume
- processing.
- If a non-suspending data source is used and require_image is TRUE, then the
- return code need not be inspected since only JPEG_HEADER_OK is possible.
-
- This routine is now just a front end to jpeg_consume_input, with some
- extra error checking. }
-
-{GLOBAL}
-function jpeg_read_header (cinfo : j_decompress_ptr;
- require_image : boolean) : int;
-var
- retcode : int;
-begin
- if (cinfo^.global_state <> DSTATE_START) and
- (cinfo^.global_state <> DSTATE_INHEADER) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
-
- retcode := jpeg_consume_input(cinfo);
-
- case (retcode) of
- JPEG_REACHED_SOS:
- retcode := JPEG_HEADER_OK;
- JPEG_REACHED_EOI:
- begin
- if (require_image) then { Complain if application wanted an image }
- ERREXIT(j_common_ptr(cinfo), JERR_NO_IMAGE);
- { Reset to start state; it would be safer to require the application to
- call jpeg_abort, but we can't change it now for compatibility reasons.
- A side effect is to free any temporary memory (there shouldn't be any). }
-
- jpeg_abort(j_common_ptr(cinfo)); { sets state := DSTATE_START }
- retcode := JPEG_HEADER_TABLES_ONLY;
- end;
- JPEG_SUSPENDED: ; { no work }
- end;
-
- jpeg_read_header := retcode;
-end;
-
-
-{ Consume data in advance of what the decompressor requires.
- This can be called at any time once the decompressor object has
- been created and a data source has been set up.
-
- This routine is essentially a state machine that handles a couple
- of critical state-transition actions, namely initial setup and
- transition from header scanning to ready-for-start_decompress.
- All the actual input is done via the input controller's consume_input
- method. }
-
-{GLOBAL}
-function jpeg_consume_input (cinfo : j_decompress_ptr) : int;
-var
- retcode : int;
-begin
- retcode := JPEG_SUSPENDED;
-
- { NB: every possible DSTATE value should be listed in this switch }
-
- if (cinfo^.global_state) = DSTATE_START then
- begin {work around the FALLTHROUGH}
- { 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;
- end;
-
- case (cinfo^.global_state) of
- DSTATE_START,
- DSTATE_INHEADER:
- begin
- retcode := cinfo^.inputctl^.consume_input (cinfo);
- if (retcode = JPEG_REACHED_SOS) then
- begin { Found SOS, prepare to decompress }
- { Set up default parameters based on header data }
- default_decompress_parms(cinfo);
- { Set global state: ready for start_decompress }
- cinfo^.global_state := DSTATE_READY;
- end;
- end;
- DSTATE_READY:
- { Can't advance past first SOS until start_decompress is called }
- retcode := JPEG_REACHED_SOS;
-
- DSTATE_PRELOAD,
- DSTATE_PRESCAN,
- DSTATE_SCANNING,
- DSTATE_RAW_OK,
- DSTATE_BUFIMAGE,
- DSTATE_BUFPOST,
- DSTATE_STOPPING:
- retcode := cinfo^.inputctl^.consume_input (cinfo);
- else
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- end;
- jpeg_consume_input := retcode;
-end;
-
-
-{ Have we finished reading the input file? }
-
-{GLOBAL}
-function jpeg_input_complete (cinfo : j_decompress_ptr) : boolean;
-begin
- { Check for valid jpeg object }
- if (cinfo^.global_state < DSTATE_START) or
- (cinfo^.global_state > DSTATE_STOPPING) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- jpeg_input_complete := cinfo^.inputctl^.eoi_reached;
-end;
-
-
-{ Is there more than one scan? }
-
-{GLOBAL}
-function jpeg_has_multiple_scans (cinfo : j_decompress_ptr) : boolean;
-begin
- { Only valid after jpeg_read_header completes }
- if (cinfo^.global_state < DSTATE_READY) or
- (cinfo^.global_state > DSTATE_STOPPING) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- jpeg_has_multiple_scans := cinfo^.inputctl^.has_multiple_scans;
-end;
-
-
-{ Finish JPEG decompression.
-
- This will normally just verify the file trailer and release temp storage.
-
- Returns FALSE if suspended. The return value need be inspected only if
- a suspending data source is used. }
-
-{GLOBAL}
-function jpeg_finish_decompress (cinfo : j_decompress_ptr) : boolean;
-begin
- if ((cinfo^.global_state = DSTATE_SCANNING) or
- (cinfo^.global_state = DSTATE_RAW_OK) and (not cinfo^.buffered_image)) then
- begin
- { Terminate final pass of non-buffered mode }
- if (cinfo^.output_scanline < cinfo^.output_height) then
- ERREXIT(j_common_ptr(cinfo), JERR_TOO_LITTLE_DATA);
- cinfo^.master^.finish_output_pass (cinfo);
- cinfo^.global_state := DSTATE_STOPPING;
- end
- else
- if (cinfo^.global_state = DSTATE_BUFIMAGE) then
- begin
- { Finishing after a buffered-image operation }
- cinfo^.global_state := DSTATE_STOPPING;
- end
- else
- if (cinfo^.global_state <> DSTATE_STOPPING) then
- begin
- { STOPPING := repeat call after a suspension, anything else is error }
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- end;
- { Read until EOI }
- while (not cinfo^.inputctl^.eoi_reached) do
- begin
- if (cinfo^.inputctl^.consume_input (cinfo) = JPEG_SUSPENDED) then
- begin
- jpeg_finish_decompress := FALSE; { Suspend, come back later }
- exit;
- end;
- end;
- { Do final cleanup }
- cinfo^.src^.term_source (cinfo);
- { We can use jpeg_abort to release memory and reset global_state }
- jpeg_abort(j_common_ptr(cinfo));
- jpeg_finish_decompress := TRUE;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdapistd.pas b/packages/base/pasjpeg/jdapistd.pas
deleted file mode 100644
index b816ff8308..0000000000
--- a/packages/base/pasjpeg/jdapistd.pas
+++ /dev/null
@@ -1,376 +0,0 @@
-Unit JdAPIstd;
-
-{ Original : jdapistd.c ; Copyright (C) 1994-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 application interface code for the decompression half
- of the JPEG library. These are the "standard" API routines that are
- used in the normal full-decompression case. They are not used by a
- transcoding-only application. Note that if an application links in
- jpeg_start_decompress, it will end up linking in the entire decompressor.
- We thus must separate this file from jdapimin.c to avoid linking the
- whole decompression library into a transcoder. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jpeglib,
- jdmaster;
-
-{ Read some scanlines of data from the JPEG decompressor.
-
- The return value will be the number of lines actually read.
- This may be less than the number requested in several cases,
- including bottom of image, data source suspension, and operating
- modes that emit multiple scanlines at a time.
-
- Note: we warn about excess calls to jpeg_read_scanlines() since
- this likely signals an application programmer error. However,
- an oversize buffer (max_lines > scanlines remaining) is not an error. }
-
-{GLOBAL}
-function jpeg_read_scanlines (cinfo : j_decompress_ptr;
- scanlines : JSAMPARRAY;
- max_lines : JDIMENSION) : JDIMENSION;
-
-
-{ Alternate entry point to read raw data.
- Processes exactly one iMCU row per call, unless suspended. }
-
-{GLOBAL}
-function jpeg_read_raw_data (cinfo : j_decompress_ptr;
- data : JSAMPIMAGE;
- max_lines : JDIMENSION) : JDIMENSION;
-
-{$ifdef D_MULTISCAN_FILES_SUPPORTED}
-
-{ Initialize for an output pass in buffered-image mode. }
-
-{GLOBAL}
-function jpeg_start_output (cinfo : j_decompress_ptr;
- scan_number : int) : boolean;
-
-{ Finish up after an output pass in buffered-image mode.
-
- Returns FALSE if suspended. The return value need be inspected only if
- a suspending data source is used. }
-
-{GLOBAL}
-function jpeg_finish_output (cinfo : j_decompress_ptr) : boolean;
-
-{$endif} { D_MULTISCAN_FILES_SUPPORTED }
-
-{ Decompression initialization.
- jpeg_read_header must be completed before calling this.
-
- If a multipass operating mode was selected, this will do all but the
- last pass, and thus may take a great deal of time.
-
- Returns FALSE if suspended. The return value need be inspected only if
- a suspending data source is used. }
-
-{GLOBAL}
-function jpeg_start_decompress (cinfo : j_decompress_ptr) : boolean;
-
-
-implementation
-
-{ Forward declarations }
-{LOCAL}
-function output_pass_setup (cinfo : j_decompress_ptr) : boolean; forward;
-
-{ Decompression initialization.
- jpeg_read_header must be completed before calling this.
-
- If a multipass operating mode was selected, this will do all but the
- last pass, and thus may take a great deal of time.
-
- Returns FALSE if suspended. The return value need be inspected only if
- a suspending data source is used. }
-
-{GLOBAL}
-function jpeg_start_decompress (cinfo : j_decompress_ptr) : boolean;
-var
- retcode : int;
-begin
- if (cinfo^.global_state = DSTATE_READY) then
- begin
- { First call: initialize master control, select active modules }
- jinit_master_decompress(cinfo);
- if (cinfo^.buffered_image) then
- begin
- { No more work here; expecting jpeg_start_output next }
- cinfo^.global_state := DSTATE_BUFIMAGE;
- jpeg_start_decompress := TRUE;
- exit;
- end;
- cinfo^.global_state := DSTATE_PRELOAD;
- end;
- if (cinfo^.global_state = DSTATE_PRELOAD) then
- begin
- { If file has multiple scans, absorb them all into the coef buffer }
- if (cinfo^.inputctl^.has_multiple_scans) then
- begin
-{$ifdef D_MULTISCAN_FILES_SUPPORTED}
- while TRUE do
- begin
-
- { Call progress monitor hook if present }
- if (cinfo^.progress <> NIL) then
- cinfo^.progress^.progress_monitor (j_common_ptr(cinfo));
- { Absorb some more input }
- retcode := cinfo^.inputctl^.consume_input (cinfo);
- if (retcode = JPEG_SUSPENDED) then
- begin
- jpeg_start_decompress := FALSE;
- exit;
- end;
- if (retcode = JPEG_REACHED_EOI) then
- break;
- { Advance progress counter if appropriate }
- if (cinfo^.progress <> NIL) and
- ((retcode = JPEG_ROW_COMPLETED) or (retcode = JPEG_REACHED_SOS)) then
- begin
- Inc(cinfo^.progress^.pass_counter);
- if (cinfo^.progress^.pass_counter >= cinfo^.progress^.pass_limit) then
- begin
- { jdmaster underestimated number of scans; ratchet up one scan }
- Inc(cinfo^.progress^.pass_limit, long(cinfo^.total_iMCU_rows));
- end;
- end;
- end;
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif} { D_MULTISCAN_FILES_SUPPORTED }
- end;
- cinfo^.output_scan_number := cinfo^.input_scan_number;
- end
- else
- if (cinfo^.global_state <> DSTATE_PRESCAN) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- { Perform any dummy output passes, and set up for the final pass }
- jpeg_start_decompress := output_pass_setup(cinfo);
-end;
-
-
-{ Set up for an output pass, and perform any dummy pass(es) needed.
- Common subroutine for jpeg_start_decompress and jpeg_start_output.
- Entry: global_state := DSTATE_PRESCAN only if previously suspended.
- Exit: If done, returns TRUE and sets global_state for proper output mode.
- If suspended, returns FALSE and sets global_state := DSTATE_PRESCAN. }
-
-{LOCAL}
-function output_pass_setup (cinfo : j_decompress_ptr) : boolean;
-var
- last_scanline : JDIMENSION;
-begin
- if (cinfo^.global_state <> DSTATE_PRESCAN) then
- begin
- { First call: do pass setup }
- cinfo^.master^.prepare_for_output_pass (cinfo);
- cinfo^.output_scanline := 0;
- cinfo^.global_state := DSTATE_PRESCAN;
- end;
- { Loop over any required dummy passes }
- while (cinfo^.master^.is_dummy_pass) do
- begin
-{$ifdef QUANT_2PASS_SUPPORTED}
- { Crank through the dummy pass }
- while (cinfo^.output_scanline < cinfo^.output_height) do
- begin
- { Call progress monitor hook if present }
- if (cinfo^.progress <> NIL) then
- begin
- cinfo^.progress^.pass_counter := long (cinfo^.output_scanline);
- cinfo^.progress^.pass_limit := long (cinfo^.output_height);
- cinfo^.progress^.progress_monitor (j_common_ptr(cinfo));
- end;
- { Process some data }
- last_scanline := cinfo^.output_scanline;
- cinfo^.main^.process_data (cinfo, JSAMPARRAY(NIL),
- cinfo^.output_scanline, {var}
- JDIMENSION(0));
- if (cinfo^.output_scanline = last_scanline) then
- begin
- output_pass_setup := FALSE; { No progress made, must suspend }
- exit;
- end;
- end;
- { Finish up dummy pass, and set up for another one }
- cinfo^.master^.finish_output_pass (cinfo);
- cinfo^.master^.prepare_for_output_pass (cinfo);
- cinfo^.output_scanline := 0;
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif} { QUANT_2PASS_SUPPORTED }
- end;
- { Ready for application to drive output pass through
- jpeg_read_scanlines or jpeg_read_raw_data. }
- if cinfo^.raw_data_out then
- cinfo^.global_state := DSTATE_RAW_OK
- else
- cinfo^.global_state := DSTATE_SCANNING;
- output_pass_setup := TRUE;
-end;
-
-
-{ Read some scanlines of data from the JPEG decompressor.
-
- The return value will be the number of lines actually read.
- This may be less than the number requested in several cases,
- including bottom of image, data source suspension, and operating
- modes that emit multiple scanlines at a time.
-
- Note: we warn about excess calls to jpeg_read_scanlines() since
- this likely signals an application programmer error. However,
- an oversize buffer (max_lines > scanlines remaining) is not an error. }
-
-{GLOBAL}
-function jpeg_read_scanlines (cinfo : j_decompress_ptr;
- scanlines : JSAMPARRAY;
- max_lines : JDIMENSION) : JDIMENSION;
-var
- row_ctr : JDIMENSION;
-begin
- if (cinfo^.global_state <> DSTATE_SCANNING) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- if (cinfo^.output_scanline >= cinfo^.output_height) then
- begin
- WARNMS(j_common_ptr(cinfo), JWRN_TOO_MUCH_DATA);
- jpeg_read_scanlines := 0;
- exit;
- end;
-
- { Call progress monitor hook if present }
- if (cinfo^.progress <> NIL) then
- begin
- cinfo^.progress^.pass_counter := long (cinfo^.output_scanline);
- cinfo^.progress^.pass_limit := long (cinfo^.output_height);
- cinfo^.progress^.progress_monitor (j_common_ptr(cinfo));
- end;
-
- { Process some data }
- row_ctr := 0;
- cinfo^.main^.process_data (cinfo, scanlines, {var}row_ctr, max_lines);
- Inc(cinfo^.output_scanline, row_ctr);
- jpeg_read_scanlines := row_ctr;
-end;
-
-
-{ Alternate entry point to read raw data.
- Processes exactly one iMCU row per call, unless suspended. }
-
-{GLOBAL}
-function jpeg_read_raw_data (cinfo : j_decompress_ptr;
- data : JSAMPIMAGE;
- max_lines : JDIMENSION) : JDIMENSION;
-var
- lines_per_iMCU_row : JDIMENSION;
-begin
- if (cinfo^.global_state <> DSTATE_RAW_OK) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- if (cinfo^.output_scanline >= cinfo^.output_height) then
- begin
- WARNMS(j_common_ptr(cinfo), JWRN_TOO_MUCH_DATA);
- jpeg_read_raw_data := 0;
- exit;
- end;
-
- { Call progress monitor hook if present }
- if (cinfo^.progress <> NIL) then
- begin
- cinfo^.progress^.pass_counter := long (cinfo^.output_scanline);
- cinfo^.progress^.pass_limit := long (cinfo^.output_height);
- cinfo^.progress^.progress_monitor (j_common_ptr(cinfo));
- end;
-
- { Verify that at least one iMCU row can be returned. }
- lines_per_iMCU_row := cinfo^.max_v_samp_factor * cinfo^.min_DCT_scaled_size;
- if (max_lines < lines_per_iMCU_row) then
- ERREXIT(j_common_ptr(cinfo), JERR_BUFFER_SIZE);
-
- { Decompress directly into user's buffer. }
- if (cinfo^.coef^.decompress_data (cinfo, data) = 0) then
- begin
- jpeg_read_raw_data := 0; { suspension forced, can do nothing more }
- exit;
- end;
-
- { OK, we processed one iMCU row. }
- Inc(cinfo^.output_scanline, lines_per_iMCU_row);
- jpeg_read_raw_data := lines_per_iMCU_row;
-end;
-
-
-{ Additional entry points for buffered-image mode. }
-
-{$ifdef D_MULTISCAN_FILES_SUPPORTED}
-
-{ Initialize for an output pass in buffered-image mode. }
-
-{GLOBAL}
-function jpeg_start_output (cinfo : j_decompress_ptr;
- scan_number : int) : boolean;
-begin
- if (cinfo^.global_state <> DSTATE_BUFIMAGE) and
- (cinfo^.global_state <> DSTATE_PRESCAN) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- { Limit scan number to valid range }
- if (scan_number <= 0) then
- scan_number := 1;
- if (cinfo^.inputctl^.eoi_reached) and
- (scan_number > cinfo^.input_scan_number) then
- scan_number := cinfo^.input_scan_number;
- cinfo^.output_scan_number := scan_number;
- { Perform any dummy output passes, and set up for the real pass }
- jpeg_start_output := output_pass_setup(cinfo);
-end;
-
-
-{ Finish up after an output pass in buffered-image mode.
-
- Returns FALSE if suspended. The return value need be inspected only if
- a suspending data source is used. }
-
-{GLOBAL}
-function jpeg_finish_output (cinfo : j_decompress_ptr) : boolean;
-begin
- if ((cinfo^.global_state = DSTATE_SCANNING) or
- (cinfo^.global_state = DSTATE_RAW_OK) and cinfo^.buffered_image) then
- begin
- { Terminate this pass. }
- { We do not require the whole pass to have been completed. }
- cinfo^.master^.finish_output_pass (cinfo);
- cinfo^.global_state := DSTATE_BUFPOST;
- end
- else
- if (cinfo^.global_state <> DSTATE_BUFPOST) then
- begin
- { BUFPOST := repeat call after a suspension, anything else is error }
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- end;
- { Read markers looking for SOS or EOI }
- while (cinfo^.input_scan_number <= cinfo^.output_scan_number) and
- (not cinfo^.inputctl^.eoi_reached) do
- begin
- if (cinfo^.inputctl^.consume_input (cinfo) = JPEG_SUSPENDED) then
- begin
- jpeg_finish_output := FALSE; { Suspend, come back later }
- exit;
- end;
- end;
- cinfo^.global_state := DSTATE_BUFIMAGE;
- jpeg_finish_output := TRUE;
-end;
-
-{$endif} { D_MULTISCAN_FILES_SUPPORTED }
-
-end.
diff --git a/packages/base/pasjpeg/jdatadst.pas b/packages/base/pasjpeg/jdatadst.pas
deleted file mode 100644
index 8b153bd1ae..0000000000
--- a/packages/base/pasjpeg/jdatadst.pas
+++ /dev/null
@@ -1,170 +0,0 @@
-Unit JDataDst;
-
-{ This file contains compression data destination routines for the case of
- emitting JPEG data to a file (or any stdio stream). While these routines
- are sufficient for most applications, some will want to use a different
- destination manager.
- IMPORTANT: we assume that fwrite() will correctly transcribe an array of
- JOCTETs into 8-bit-wide elements on external storage. If char is wider
- than 8 bits on your machine, you may need to do some tweaking. }
-
-{ Original : jdatadst.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-{ this is not a core library module, so it doesn't define JPEG_INTERNALS }
-uses
- jmorecfg,
- jpeglib,
- jinclude,
- jdeferr,
- jerror;
-
-{ Prepare for output to a stdio stream.
- The caller must have already opened the stream, and is responsible
- for closing it after finishing compression. }
-
-{GLOBAL}
-procedure jpeg_stdio_dest (cinfo : j_compress_ptr; outfile : FILEptr);
-
-implementation
-
-{ Expanded data destination object for stdio output }
-
-type
- my_dest_ptr = ^my_destination_mgr;
- my_destination_mgr = record
- pub : jpeg_destination_mgr; { public fields }
-
- outfile : FILEPTR; { target stream }
- buffer : JOCTET_FIELD_PTR; { start of buffer }
- end; {my_destination_mgr;}
-
-
-const
- OUTPUT_BUF_SIZE = 4096; { choose an efficiently fwrite'able size }
-
-
-{ Initialize destination --- called by jpeg_start_compress
- before any data is actually written. }
-
-{METHODDEF}
-procedure init_destination (cinfo : j_compress_ptr); far;
-var
- dest : my_dest_ptr;
-begin
- dest := my_dest_ptr(cinfo^.dest);
-
- { Allocate the output buffer --- it will be released when done with image }
- dest^.buffer := JOCTET_FIELD_PTR(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- OUTPUT_BUF_SIZE * SIZEOF(JOCTET)) );
-
- dest^.pub.next_output_byte := JOCTETptr(dest^.buffer);
- dest^.pub.free_in_buffer := OUTPUT_BUF_SIZE;
-end;
-
-
-{ Empty the output buffer --- called whenever buffer fills up.
-
- In typical applications, this should write the entire output buffer
- (ignoring the current state of next_output_byte & free_in_buffer),
- reset the pointer & count to the start of the buffer, and return TRUE
- indicating that the buffer has been dumped.
-
- In applications that need to be able to suspend compression due to output
- overrun, a FALSE return indicates that the buffer cannot be emptied now.
- In this situation, the compressor will return to its caller (possibly with
- an indication that it has not accepted all the supplied scanlines). The
- application should resume compression after it has made more room in the
- output buffer. Note that there are substantial restrictions on the use of
- suspension --- see the documentation.
-
- When suspending, the compressor will back up to a convenient restart point
- (typically the start of the current MCU). next_output_byte & free_in_buffer
- indicate where the restart point will be if the current call returns FALSE.
- Data beyond this point will be regenerated after resumption, so do not
- write it out when emptying the buffer externally. }
-
-{METHODDEF}
-function empty_output_buffer (cinfo : j_compress_ptr) : boolean; far;
-var
- dest : my_dest_ptr;
-begin
- dest := my_dest_ptr(cinfo^.dest);
-
- if (JFWRITE(dest^.outfile, dest^.buffer, OUTPUT_BUF_SIZE) <>
- size_t(OUTPUT_BUF_SIZE)) then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
-
- dest^.pub.next_output_byte := JOCTETptr(dest^.buffer);
- dest^.pub.free_in_buffer := OUTPUT_BUF_SIZE;
-
- empty_output_buffer := TRUE;
-end;
-
-
-{ Terminate destination --- called by jpeg_finish_compress
- after all data has been written. Usually needs to flush buffer.
-
- NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
- application must deal with any cleanup that should happen even
- for error exit. }
-
-{METHODDEF}
-procedure term_destination (cinfo : j_compress_ptr); far;
-var
- dest : my_dest_ptr;
- datacount : size_t;
-begin
- dest := my_dest_ptr (cinfo^.dest);
- datacount := OUTPUT_BUF_SIZE - dest^.pub.free_in_buffer;
-
- { Write any data remaining in the buffer }
- if (datacount > 0) then
- begin
- if (JFWRITE(dest^.outfile, dest^.buffer, datacount) <> datacount) then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
- end;
- {fflush(dest^.outfile^);}
-
- { Make sure we wrote the output file OK }
- {if (ferror(dest^.outfile))
- ERREXIT(cinfo, JERR_FILE_WRITE);}
- if IOresult <> 0 then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
-end;
-
-
-{ Prepare for output to a stdio stream.
- The caller must have already opened the stream, and is responsible
- for closing it after finishing compression. }
-
-{GLOBAL}
-procedure jpeg_stdio_dest (cinfo : j_compress_ptr; outfile : FILEptr);
-var
- dest : my_dest_ptr;
-begin
- { The destination object is made permanent so that multiple JPEG images
- can be written to the same file without re-executing jpeg_stdio_dest.
- This makes it dangerous to use this manager and a different destination
- manager serially with the same JPEG object, because their private object
- sizes may be different. Caveat programmer. }
-
- if (cinfo^.dest = NIL) then
- begin { first time for this JPEG object? }
- cinfo^.dest := jpeg_destination_mgr_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_PERMANENT,
- SIZEOF(my_destination_mgr)) );
- end;
-
- dest := my_dest_ptr (cinfo^.dest);
- dest^.pub.init_destination := init_destination;
- dest^.pub.empty_output_buffer := empty_output_buffer;
- dest^.pub.term_destination := term_destination;
- dest^.outfile := outfile;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdatasrc.pas b/packages/base/pasjpeg/jdatasrc.pas
deleted file mode 100644
index 7408abfdcd..0000000000
--- a/packages/base/pasjpeg/jdatasrc.pas
+++ /dev/null
@@ -1,224 +0,0 @@
-Unit JDataSrc;
-
-{ This file contains decompression data source routines for the case of
- reading JPEG data from a file (or any stdio stream). While these routines
- are sufficient for most applications, some will want to use a different
- source manager.
- IMPORTANT: we assume that fread() will correctly transcribe an array of
- JOCTETs from 8-bit-wide elements on external storage. If char is wider
- than 8 bits on your machine, you may need to do some tweaking. }
-
-{ jdatasrc.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-{ this is not a core library module, so it doesn't define JPEG_INTERNALS }
-uses
- jmorecfg,
- jinclude,
- jpeglib,
- jdmarker,
- jdeferr,
- jerror;
-
-
-{ Prepare for input from a stdio stream.
- The caller must have already opened the stream, and is responsible
- for closing it after finishing decompression. }
-
-{GLOBAL}
-procedure jpeg_stdio_src (cinfo : j_decompress_ptr; infile : FILEptr);
-
-implementation
-
-{ Expanded data source object for stdio input }
-
-type
- my_src_ptr = ^my_source_mgr;
- my_source_mgr = record
- pub : jpeg_source_mgr; { public fields }
-
- infile : FILEPTR; { source stream }
- buffer : JOCTET_FIELD_PTR; { start of buffer }
- start_of_file : boolean; { have we gotten any data yet? }
- end; {my_source_mgr;}
-
-const
- INPUT_BUF_SIZE = 4096; { choose an efficiently fread'able size }
-
-
-{ Initialize source --- called by jpeg_read_header
- before any data is actually read. }
-
-{METHODDEF}
-procedure init_source (cinfo : j_decompress_ptr); far;
-var
- src : my_src_ptr;
-begin
- src := my_src_ptr (cinfo^.src);
-
- { We reset the empty-input-file flag for each image,
- but we don't clear the input buffer.
- This is correct behavior for reading a series of images from one source. }
- src^.start_of_file := TRUE;
-end;
-
-
-{ Fill the input buffer --- called whenever buffer is emptied.
-
- In typical applications, this should read fresh data into the buffer
- (ignoring the current state of next_input_byte & bytes_in_buffer),
- reset the pointer & count to the start of the buffer, and return TRUE
- indicating that the buffer has been reloaded. It is not necessary to
- fill the buffer entirely, only to obtain at least one more byte.
-
- There is no such thing as an EOF return. If the end of the file has been
- reached, the routine has a choice of ERREXIT() or inserting fake data into
- the buffer. In most cases, generating a warning message and inserting a
- fake EOI marker is the best course of action --- this will allow the
- decompressor to output however much of the image is there. However,
- the resulting error message is misleading if the real problem is an empty
- input file, so we handle that case specially.
-
- In applications that need to be able to suspend compression due to input
- not being available yet, a FALSE return indicates that no more data can be
- obtained right now, but more may be forthcoming later. In this situation,
- the decompressor will return to its caller (with an indication of the
- number of scanlines it has read, if any). The application should resume
- decompression after it has loaded more data into the input buffer. Note
- that there are substantial restrictions on the use of suspension --- see
- the documentation.
-
- When suspending, the decompressor will back up to a convenient restart point
- (typically the start of the current MCU). next_input_byte & bytes_in_buffer
- indicate where the restart point will be if the current call returns FALSE.
- Data beyond this point must be rescanned after resumption, so move it to
- the front of the buffer rather than discarding it. }
-
-{METHODDEF}
-function fill_input_buffer (cinfo : j_decompress_ptr) : boolean; far;
-var
- src : my_src_ptr;
- nbytes : size_t;
-begin
- src := my_src_ptr(cinfo^.src);
- nbytes := JFREAD(src^.infile, src^.buffer, INPUT_BUF_SIZE);
-
- if (nbytes <= 0) then
- begin
- if (src^.start_of_file) then { Treat empty input file as fatal error }
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EMPTY);
- WARNMS(j_common_ptr(cinfo), JWRN_JPEG_EOF);
- { Insert a fake EOI marker }
- src^.buffer^[0] := JOCTET ($FF);
- src^.buffer^[1] := JOCTET (JPEG_EOI);
- nbytes := 2;
- end;
-
- src^.pub.next_input_byte := JOCTETptr(src^.buffer);
- src^.pub.bytes_in_buffer := nbytes;
- src^.start_of_file := FALSE;
-
- fill_input_buffer := TRUE;
-end;
-
-
-{ Skip data --- used to skip over a potentially large amount of
- uninteresting data (such as an APPn marker).
-
- Writers of suspendable-input applications must note that skip_input_data
- is not granted the right to give a suspension return. If the skip extends
- beyond the data currently in the buffer, the buffer can be marked empty so
- that the next read will cause a fill_input_buffer call that can suspend.
- Arranging for additional bytes to be discarded before reloading the input
- buffer is the application writer's problem. }
-
-{METHODDEF}
-procedure skip_input_data (cinfo : j_decompress_ptr;
- num_bytes : long); far;
-var
- src : my_src_ptr;
-begin
- src := my_src_ptr (cinfo^.src);
-
- { Just a dumb implementation for now. Could use fseek() except
- it doesn't work on pipes. Not clear that being smart is worth
- any trouble anyway --- large skips are infrequent. }
-
- if (num_bytes > 0) then
- begin
- while (num_bytes > long(src^.pub.bytes_in_buffer)) do
- begin
- Dec(num_bytes, long(src^.pub.bytes_in_buffer));
- {void} fill_input_buffer(cinfo);
- { note we assume that fill_input_buffer will never return FALSE,
- so suspension need not be handled. }
- end;
- Inc( src^.pub.next_input_byte, size_t(num_bytes) );
- Dec( src^.pub.bytes_in_buffer, size_t(num_bytes) );
- end;
-end;
-
-
-{ An additional method that can be provided by data source modules is the
- resync_to_restart method for error recovery in the presence of RST markers.
- For the moment, this source module just uses the default resync method
- provided by the JPEG library. That method assumes that no backtracking
- is possible. }
-
-
-{ Terminate source --- called by jpeg_finish_decompress
- after all data has been read. Often a no-op.
-
- NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
- application must deal with any cleanup that should happen even
- for error exit. }
-
-{METHODDEF}
-procedure term_source (cinfo : j_decompress_ptr); far;
-begin
- { no work necessary here }
-end;
-
-
-{ Prepare for input from a stdio stream.
- The caller must have already opened the stream, and is responsible
- for closing it after finishing decompression. }
-
-{GLOBAL}
-procedure jpeg_stdio_src (cinfo : j_decompress_ptr; infile : FILEptr);
-var
- src : my_src_ptr;
-begin
- { The source object and input buffer are made permanent so that a series
- of JPEG images can be read from the same file by calling jpeg_stdio_src
- only before the first one. (If we discarded the buffer at the end of
- one image, we'd likely lose the start of the next one.)
- This makes it unsafe to use this manager and a different source
- manager serially with the same JPEG object. Caveat programmer. }
-
- if (cinfo^.src = NIL) then
- begin { first time for this JPEG object? }
- cinfo^.src := jpeg_source_mgr_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_PERMANENT,
- SIZEOF(my_source_mgr)) );
- src := my_src_ptr (cinfo^.src);
- src^.buffer := JOCTET_FIELD_PTR(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_PERMANENT,
- INPUT_BUF_SIZE * SIZEOF(JOCTET)) );
- end;
-
- src := my_src_ptr (cinfo^.src);
- src^.pub.init_source := init_source;
- src^.pub.fill_input_buffer := fill_input_buffer;
- src^.pub.skip_input_data := skip_input_data;
- src^.pub.resync_to_restart := jpeg_resync_to_restart; { use default method }
- src^.pub.term_source := term_source;
- src^.infile := infile;
- src^.pub.bytes_in_buffer := 0; { forces fill_input_buffer on first read }
- src^.pub.next_input_byte := NIL; { until buffer loaded }
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdcoefct.pas b/packages/base/pasjpeg/jdcoefct.pas
deleted file mode 100644
index c6e0d47796..0000000000
--- a/packages/base/pasjpeg/jdcoefct.pas
+++ /dev/null
@@ -1,895 +0,0 @@
-Unit JDCoefCt;
-
-{ This file contains the coefficient buffer controller for decompression.
- This controller is the top level of the JPEG decompressor proper.
- The coefficient buffer lies between entropy decoding and inverse-DCT steps.
-
- In buffered-image mode, this controller is the interface between
- input-oriented processing and output-oriented processing.
- Also, the input side (only) is used when reading a file for transcoding. }
-
-{ Original: jdcoefct.c ; Copyright (C) 1994-1997, Thomas G. Lane. }
-{$I jconfig.inc}
-
-interface
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jutils,
- jpeglib;
-
-
-{GLOBAL}
-procedure jinit_d_coef_controller (cinfo : j_decompress_ptr;
- need_full_buffer : boolean);
-
-
-implementation
-
-
-{ Block smoothing is only applicable for progressive JPEG, so: }
-{$ifndef D_PROGRESSIVE_SUPPORTED}
-{$undef BLOCK_SMOOTHING_SUPPORTED}
-{$endif}
-
-{ Private buffer controller object }
-
-{$ifdef BLOCK_SMOOTHING_SUPPORTED}
-const
- SAVED_COEFS = 6; { we save coef_bits[0..5] }
-type
- Latch = array[0..SAVED_COEFS-1] of int;
- Latch_ptr = ^Latch;
-{$endif}
-
-type
- my_coef_ptr = ^my_coef_controller;
- my_coef_controller = record
- pub : jpeg_d_coef_controller; { public fields }
-
- { These variables keep track of the current location of the input side. }
- { cinfo^.input_iMCU_row is also used for this. }
- MCU_ctr : JDIMENSION; { counts MCUs processed in current row }
- MCU_vert_offset : int; { counts MCU rows within iMCU row }
- MCU_rows_per_iMCU_row : int; { number of such rows needed }
-
- { The output side's location is represented by cinfo^.output_iMCU_row. }
-
- { In single-pass modes, it's sufficient to buffer just one MCU.
- We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks,
- and let the entropy decoder write into that workspace each time.
- (On 80x86, the workspace is FAR even though it's not really very big;
- this is to keep the module interfaces unchanged when a large coefficient
- buffer is necessary.)
- In multi-pass modes, this array points to the current MCU's blocks
- within the virtual arrays; it is used only by the input side. }
-
- MCU_buffer : array[0..D_MAX_BLOCKS_IN_MCU-1] of JBLOCKROW;
-
- {$ifdef D_MULTISCAN_FILES_SUPPORTED}
- { In multi-pass modes, we need a virtual block array for each component. }
- whole_image : jvirt_barray_tbl;
- {$endif}
-
- {$ifdef BLOCK_SMOOTHING_SUPPORTED}
- { When doing block smoothing, we latch coefficient Al values here }
- coef_bits_latch : Latch_Ptr;
- {$endif}
- end;
-
-{ Forward declarations }
-{METHODDEF}
-function decompress_onepass (cinfo : j_decompress_ptr;
- output_buf : JSAMPIMAGE) : int; far; forward;
-{$ifdef D_MULTISCAN_FILES_SUPPORTED}
-{METHODDEF}
-function decompress_data (cinfo : j_decompress_ptr;
- output_buf : JSAMPIMAGE) : int; far; forward;
-{$endif}
-{$ifdef BLOCK_SMOOTHING_SUPPORTED}
-{LOCAL}
-function smoothing_ok (cinfo : j_decompress_ptr) : boolean; forward;
-
-{METHODDEF}
-function decompress_smooth_data (cinfo : j_decompress_ptr;
- output_buf : JSAMPIMAGE) : int; far; forward;
-{$endif}
-
-
-{LOCAL}
-procedure start_iMCU_row (cinfo : j_decompress_ptr);
-{ Reset within-iMCU-row counters for a new row (input side) }
-var
- coef : my_coef_ptr;
-begin
- coef := my_coef_ptr (cinfo^.coef);
-
- { In an interleaved scan, an MCU row is the same as an iMCU row.
- In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
- But at the bottom of the image, process only what's left. }
-
- if (cinfo^.comps_in_scan > 1) then
- begin
- coef^.MCU_rows_per_iMCU_row := 1;
- end
- else
- begin
- if (cinfo^.input_iMCU_row < (cinfo^.total_iMCU_rows-1)) then
- coef^.MCU_rows_per_iMCU_row := cinfo^.cur_comp_info[0]^.v_samp_factor
- else
- coef^.MCU_rows_per_iMCU_row := cinfo^.cur_comp_info[0]^.last_row_height;
- end;
-
- coef^.MCU_ctr := 0;
- coef^.MCU_vert_offset := 0;
-end;
-
-
-{ Initialize for an input processing pass. }
-
-{METHODDEF}
-procedure start_input_pass (cinfo : j_decompress_ptr); far;
-begin
- cinfo^.input_iMCU_row := 0;
- start_iMCU_row(cinfo);
-end;
-
-
-{ Initialize for an output processing pass. }
-
-{METHODDEF}
-procedure start_output_pass (cinfo : j_decompress_ptr); far;
-var
- coef : my_coef_ptr;
-begin
-{$ifdef BLOCK_SMOOTHING_SUPPORTED}
- coef := my_coef_ptr (cinfo^.coef);
-
- { If multipass, check to see whether to use block smoothing on this pass }
- if (coef^.pub.coef_arrays <> NIL) then
- begin
- if (cinfo^.do_block_smoothing) and smoothing_ok(cinfo) then
- coef^.pub.decompress_data := decompress_smooth_data
- else
- coef^.pub.decompress_data := decompress_data;
- end;
-{$endif}
- cinfo^.output_iMCU_row := 0;
-end;
-
-
-{ Decompress and return some data in the single-pass case.
- Always attempts to emit one fully interleaved MCU row ("iMCU" row).
- Input and output must run in lockstep since we have only a one-MCU buffer.
- Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
-
- NB: output_buf contains a plane for each component in image,
- which we index according to the component's SOF position.}
-
-{METHODDEF}
-function decompress_onepass (cinfo : j_decompress_ptr;
- output_buf : JSAMPIMAGE) : int;
-var
- coef : my_coef_ptr;
- MCU_col_num : JDIMENSION; { index of current MCU within row }
- last_MCU_col : JDIMENSION;
- last_iMCU_row : JDIMENSION;
- blkn, ci, xindex, yindex, yoffset, useful_width : int;
- output_ptr : JSAMPARRAY;
- start_col, output_col : JDIMENSION;
- compptr : jpeg_component_info_ptr;
- inverse_DCT : inverse_DCT_method_ptr;
-begin
- coef := my_coef_ptr (cinfo^.coef);
- last_MCU_col := cinfo^.MCUs_per_row - 1;
- last_iMCU_row := cinfo^.total_iMCU_rows - 1;
-
- { Loop to process as much as one whole iMCU row }
- for yoffset := coef^.MCU_vert_offset to pred(coef^.MCU_rows_per_iMCU_row) do
- begin
- for MCU_col_num := coef^.MCU_ctr to last_MCU_col do
- begin
- { Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. }
- jzero_far( coef^.MCU_buffer[0],
- size_t (cinfo^.blocks_in_MCU * SIZEOF(JBLOCK)));
- if (not cinfo^.entropy^.decode_mcu (cinfo, coef^.MCU_buffer)) then
- begin
- { Suspension forced; update state counters and exit }
- coef^.MCU_vert_offset := yoffset;
- coef^.MCU_ctr := MCU_col_num;
- decompress_onepass := JPEG_SUSPENDED;
- exit;
- end;
- { Determine where data should go in output_buf and do the IDCT thing.
- We skip dummy blocks at the right and bottom edges (but blkn gets
- incremented past them!). Note the inner loop relies on having
- allocated the MCU_buffer[] blocks sequentially. }
-
- blkn := 0; { index of current DCT block within MCU }
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- { Don't bother to IDCT an uninteresting component. }
- if (not compptr^.component_needed) then
- begin
- Inc(blkn, compptr^.MCU_blocks);
- continue;
- end;
- inverse_DCT := cinfo^.idct^.inverse_DCT[compptr^.component_index];
- if (MCU_col_num < last_MCU_col) then
- useful_width := compptr^.MCU_width
- else
- useful_width := compptr^.last_col_width;
-
- output_ptr := JSAMPARRAY(@ output_buf^[compptr^.component_index]^
- [yoffset * compptr^.DCT_scaled_size]);
- start_col := MCU_col_num * compptr^.MCU_sample_width;
- for yindex := 0 to pred(compptr^.MCU_height) do
- begin
- if (cinfo^.input_iMCU_row < last_iMCU_row) or
- (yoffset+yindex < compptr^.last_row_height) then
- begin
- output_col := start_col;
- for xindex := 0 to pred(useful_width) do
- begin
- inverse_DCT (cinfo, compptr,
- JCOEFPTR(coef^.MCU_buffer[blkn+xindex]),
- output_ptr, output_col);
- Inc(output_col, compptr^.DCT_scaled_size);
- end;
- end;
- Inc(blkn, compptr^.MCU_width);
- Inc(JSAMPROW_PTR(output_ptr), compptr^.DCT_scaled_size);
- end;
- end;
- end;
- { Completed an MCU row, but perhaps not an iMCU row }
- coef^.MCU_ctr := 0;
- end;
- { Completed the iMCU row, advance counters for next one }
- Inc(cinfo^.output_iMCU_row);
-
- Inc(cinfo^.input_iMCU_row);
- if (cinfo^.input_iMCU_row < cinfo^.total_iMCU_rows) then
- begin
- start_iMCU_row(cinfo);
- decompress_onepass := JPEG_ROW_COMPLETED;
- exit;
- end;
- { Completed the scan }
- cinfo^.inputctl^.finish_input_pass (cinfo);
- decompress_onepass := JPEG_SCAN_COMPLETED;
-end;
-
-{ Dummy consume-input routine for single-pass operation. }
-
-{METHODDEF}
-function dummy_consume_data (cinfo : j_decompress_ptr) : int; far;
-begin
- dummy_consume_data := JPEG_SUSPENDED; { Always indicate nothing was done }
-end;
-
-
-{$ifdef D_MULTISCAN_FILES_SUPPORTED}
-
-{ Consume input data and store it in the full-image coefficient buffer.
- We read as much as one fully interleaved MCU row ("iMCU" row) per call,
- ie, v_samp_factor block rows for each component in the scan.
- Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.}
-
-{METHODDEF}
-function consume_data (cinfo : j_decompress_ptr) : int; far;
-var
- coef : my_coef_ptr;
- MCU_col_num : JDIMENSION; { index of current MCU within row }
- blkn, ci, xindex, yindex, yoffset : int;
- start_col : JDIMENSION;
- buffer : array[0..MAX_COMPS_IN_SCAN-1] of JBLOCKARRAY;
- buffer_ptr : JBLOCKROW;
- compptr : jpeg_component_info_ptr;
-begin
- coef := my_coef_ptr (cinfo^.coef);
-
- { Align the virtual buffers for the components used in this scan. }
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- buffer[ci] := cinfo^.mem^.access_virt_barray
- (j_common_ptr (cinfo), coef^.whole_image[compptr^.component_index],
- cinfo^.input_iMCU_row * compptr^.v_samp_factor,
- JDIMENSION (compptr^.v_samp_factor), TRUE);
- { Note: entropy decoder expects buffer to be zeroed,
- but this is handled automatically by the memory manager
- because we requested a pre-zeroed array. }
-
- end;
-
- { Loop to process one whole iMCU row }
- for yoffset := coef^.MCU_vert_offset to pred(coef^.MCU_rows_per_iMCU_row) do
- begin
- for MCU_col_num := coef^.MCU_ctr to pred(cinfo^.MCUs_per_row) do
- begin
- { Construct list of pointers to DCT blocks belonging to this MCU }
- blkn := 0; { index of current DCT block within MCU }
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- start_col := MCU_col_num * compptr^.MCU_width;
- for yindex := 0 to pred(compptr^.MCU_height) do
- begin
- buffer_ptr := JBLOCKROW(@ buffer[ci]^[yindex+yoffset]^[start_col]);
- for xindex := 0 to pred(compptr^.MCU_width) do
- begin
- coef^.MCU_buffer[blkn] := buffer_ptr;
- Inc(blkn);
- Inc(JBLOCK_PTR(buffer_ptr));
- end;
- end;
- end;
- { Try to fetch the MCU. }
- if (not cinfo^.entropy^.decode_mcu (cinfo, coef^.MCU_buffer)) then
- begin
- { Suspension forced; update state counters and exit }
- coef^.MCU_vert_offset := yoffset;
- coef^.MCU_ctr := MCU_col_num;
- consume_data := JPEG_SUSPENDED;
- exit;
- end;
- end;
- { Completed an MCU row, but perhaps not an iMCU row }
- coef^.MCU_ctr := 0;
- end;
- { Completed the iMCU row, advance counters for next one }
- Inc(cinfo^.input_iMCU_row);
- if (cinfo^.input_iMCU_row < cinfo^.total_iMCU_rows) then
- begin
- start_iMCU_row(cinfo);
- consume_data := JPEG_ROW_COMPLETED;
- exit;
- end;
- { Completed the scan }
- cinfo^.inputctl^.finish_input_pass (cinfo);
- consume_data := JPEG_SCAN_COMPLETED;
-end;
-
-
-{ Decompress and return some data in the multi-pass case.
- Always attempts to emit one fully interleaved MCU row ("iMCU" row).
- Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
-
- NB: output_buf contains a plane for each component in image. }
-
-{METHODDEF}
-function decompress_data (cinfo : j_decompress_ptr;
- output_buf : JSAMPIMAGE) : int;
-var
- coef : my_coef_ptr;
- last_iMCU_row : JDIMENSION;
- block_num : JDIMENSION;
- ci, block_row, block_rows : int;
- buffer : JBLOCKARRAY;
- buffer_ptr : JBLOCKROW;
- output_ptr : JSAMPARRAY;
- output_col : JDIMENSION;
- compptr : jpeg_component_info_ptr;
- inverse_DCT : inverse_DCT_method_ptr;
-begin
- coef := my_coef_ptr (cinfo^.coef);
- last_iMCU_row := cinfo^.total_iMCU_rows - 1;
-
- { Force some input to be done if we are getting ahead of the input. }
- while (cinfo^.input_scan_number < cinfo^.output_scan_number) or
- ((cinfo^.input_scan_number = cinfo^.output_scan_number) and
- (cinfo^.input_iMCU_row <= cinfo^.output_iMCU_row)) do
- begin
- if (cinfo^.inputctl^.consume_input(cinfo) = JPEG_SUSPENDED) then
- begin
- decompress_data := JPEG_SUSPENDED;
- exit;
- end;
- end;
-
- { OK, output from the virtual arrays. }
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- { Don't bother to IDCT an uninteresting component. }
- if (not compptr^.component_needed) then
- continue;
- { Align the virtual buffer for this component. }
- buffer := cinfo^.mem^.access_virt_barray
- (j_common_ptr (cinfo), coef^.whole_image[ci],
- cinfo^.output_iMCU_row * compptr^.v_samp_factor,
- JDIMENSION (compptr^.v_samp_factor), FALSE);
- { Count non-dummy DCT block rows in this iMCU row. }
- if (cinfo^.output_iMCU_row < last_iMCU_row) then
- block_rows := compptr^.v_samp_factor
- else
- begin
- { NB: can't use last_row_height here; it is input-side-dependent! }
- block_rows := int(compptr^.height_in_blocks mod compptr^.v_samp_factor);
- if (block_rows = 0) then
- block_rows := compptr^.v_samp_factor;
- end;
- inverse_DCT := cinfo^.idct^.inverse_DCT[ci];
- output_ptr := output_buf^[ci];
- { Loop over all DCT blocks to be processed. }
- for block_row := 0 to pred(block_rows) do
- begin
- buffer_ptr := buffer^[block_row];
- output_col := 0;
- for block_num := 0 to pred(compptr^.width_in_blocks) do
- begin
- inverse_DCT (cinfo, compptr, JCOEFPTR (buffer_ptr),
- output_ptr, output_col);
- Inc(JBLOCK_PTR(buffer_ptr));
- Inc(output_col, compptr^.DCT_scaled_size);
- end;
- Inc(JSAMPROW_PTR(output_ptr), compptr^.DCT_scaled_size);
- end;
- Inc(compptr);
- end;
-
- Inc(cinfo^.output_iMCU_row);
- if (cinfo^.output_iMCU_row < cinfo^.total_iMCU_rows) then
- begin
- decompress_data := JPEG_ROW_COMPLETED;
- exit;
- end;
- decompress_data := JPEG_SCAN_COMPLETED;
-end;
-
-{$endif} { D_MULTISCAN_FILES_SUPPORTED }
-
-
-{$ifdef BLOCK_SMOOTHING_SUPPORTED}
-
-{ This code applies interblock smoothing as described by section K.8
- of the JPEG standard: the first 5 AC coefficients are estimated from
- the DC values of a DCT block and its 8 neighboring blocks.
- We apply smoothing only for progressive JPEG decoding, and only if
- the coefficients it can estimate are not yet known to full precision. }
-
-{ Natural-order array positions of the first 5 zigzag-order coefficients }
-const
- Q01_POS = 1;
- Q10_POS = 8;
- Q20_POS = 16;
- Q11_POS = 9;
- Q02_POS = 2;
-
-{ Determine whether block smoothing is applicable and safe.
- We also latch the current states of the coef_bits[] entries for the
- AC coefficients; otherwise, if the input side of the decompressor
- advances into a new scan, we might think the coefficients are known
- more accurately than they really are. }
-
-{LOCAL}
-function smoothing_ok (cinfo : j_decompress_ptr) : boolean;
-var
- coef : my_coef_ptr;
- smoothing_useful : boolean;
- ci, coefi : int;
- compptr : jpeg_component_info_ptr;
- qtable : JQUANT_TBL_PTR;
- coef_bits : coef_bits_ptr;
- coef_bits_latch : Latch_Ptr;
-begin
- coef := my_coef_ptr (cinfo^.coef);
- smoothing_useful := FALSE;
-
- if (not cinfo^.progressive_mode) or (cinfo^.coef_bits = NIL) then
- begin
- smoothing_ok := FALSE;
- exit;
- end;
-
- { Allocate latch area if not already done }
- if (coef^.coef_bits_latch = NIL) then
- coef^.coef_bits_latch := Latch_Ptr(
- cinfo^.mem^.alloc_small (j_common_ptr (cinfo), JPOOL_IMAGE,
- cinfo^.num_components *
- (SAVED_COEFS * SIZEOF(int))) );
- coef_bits_latch := (coef^.coef_bits_latch);
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- { All components' quantization values must already be latched. }
- qtable := compptr^.quant_table;
- if (qtable = NIL) then
- begin
- smoothing_ok := FALSE;
- exit;
- end;
- { Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. }
- if (qtable^.quantval[0] = 0) or
- (qtable^.quantval[Q01_POS] = 0) or
- (qtable^.quantval[Q10_POS] = 0) or
- (qtable^.quantval[Q20_POS] = 0) or
- (qtable^.quantval[Q11_POS] = 0) or
- (qtable^.quantval[Q02_POS] = 0) then
- begin
- smoothing_ok := FALSE;
- exit;
- end;
- { DC values must be at least partly known for all components. }
- coef_bits := @cinfo^.coef_bits^[ci]; { Nomssi }
- if (coef_bits^[0] < 0) then
- begin
- smoothing_ok := FALSE;
- exit;
- end;
- { Block smoothing is helpful if some AC coefficients remain inaccurate. }
- for coefi := 1 to 5 do
- begin
- coef_bits_latch^[coefi] := coef_bits^[coefi];
- if (coef_bits^[coefi] <> 0) then
- smoothing_useful := TRUE;
- end;
- Inc(coef_bits_latch {SAVED_COEFS});
- Inc(compptr);
- end;
-
- smoothing_ok := smoothing_useful;
-end;
-
-
-{ Variant of decompress_data for use when doing block smoothing. }
-
-{METHODDEF}
-function decompress_smooth_data (cinfo : j_decompress_ptr;
- output_buf : JSAMPIMAGE) : int;
-var
- coef : my_coef_ptr;
- last_iMCU_row : JDIMENSION;
- block_num, last_block_column : JDIMENSION;
- ci, block_row, block_rows, access_rows : int;
- buffer : JBLOCKARRAY;
- buffer_ptr, prev_block_row, next_block_row : JBLOCKROW;
- output_ptr : JSAMPARRAY;
- output_col : JDIMENSION;
- compptr : jpeg_component_info_ptr;
- inverse_DCT : inverse_DCT_method_ptr;
- first_row, last_row : boolean;
- workspace : JBLOCK;
- coef_bits : Latch_Ptr; { coef_bits_ptr; }
- quanttbl : JQUANT_TBL_PTR;
- Q00,Q01,Q02,Q10,Q11,Q20, num : INT32;
- DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9 : int;
- Al, pred : int;
-var
- delta : JDIMENSION;
-begin
- coef := my_coef_ptr (cinfo^.coef);
- last_iMCU_row := cinfo^.total_iMCU_rows - 1;
-
- { Force some input to be done if we are getting ahead of the input. }
- while (cinfo^.input_scan_number <= cinfo^.output_scan_number) and
- (not cinfo^.inputctl^.eoi_reached) do
- begin
- if (cinfo^.input_scan_number = cinfo^.output_scan_number) then
- begin
- { If input is working on current scan, we ordinarily want it to
- have completed the current row. But if input scan is DC,
- we want it to keep one row ahead so that next block row's DC
- values are up to date. }
-
- if (cinfo^.Ss = 0) then
- delta := 1
- else
- delta := 0;
- if (cinfo^.input_iMCU_row > cinfo^.output_iMCU_row+delta) then
- break;
- end;
- if (cinfo^.inputctl^.consume_input(cinfo) = JPEG_SUSPENDED) then
- begin
- decompress_smooth_data := JPEG_SUSPENDED;
- exit;
- end;
- end;
-
- { OK, output from the virtual arrays. }
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to (cinfo^.num_components-1) do
- begin
- { Don't bother to IDCT an uninteresting component. }
- if (not compptr^.component_needed) then
- continue;
- { Count non-dummy DCT block rows in this iMCU row. }
- if (cinfo^.output_iMCU_row < last_iMCU_row) then
- begin
- block_rows := compptr^.v_samp_factor;
- access_rows := block_rows * 2; { this and next iMCU row }
- last_row := FALSE;
- end
- else
- begin
- { NB: can't use last_row_height here; it is input-side-dependent! }
- block_rows := int (compptr^.height_in_blocks mod compptr^.v_samp_factor);
- if (block_rows = 0) then
- block_rows := compptr^.v_samp_factor;
- access_rows := block_rows; { this iMCU row only }
- last_row := TRUE;
- end;
- { Align the virtual buffer for this component. }
- if (cinfo^.output_iMCU_row > 0) then
- begin
- Inc(access_rows, compptr^.v_samp_factor); { prior iMCU row too }
- buffer := cinfo^.mem^.access_virt_barray
- (j_common_ptr (cinfo), coef^.whole_image[ci],
- (cinfo^.output_iMCU_row - 1) * compptr^.v_samp_factor,
- JDIMENSION (access_rows), FALSE);
- Inc(JBLOCKROW_PTR(buffer), compptr^.v_samp_factor); { point to current iMCU row }
- first_row := FALSE;
- end
- else
- begin
- buffer := cinfo^.mem^.access_virt_barray
- (j_common_ptr (cinfo), coef^.whole_image[ci],
- JDIMENSION (0), JDIMENSION (access_rows), FALSE);
- first_row := TRUE;
- end;
- { Fetch component-dependent info }
- coef_bits := coef^.coef_bits_latch;
- Inc(coef_bits, ci); { ci * SAVED_COEFS}
- quanttbl := compptr^.quant_table;
- Q00 := quanttbl^.quantval[0];
- Q01 := quanttbl^.quantval[Q01_POS];
- Q10 := quanttbl^.quantval[Q10_POS];
- Q20 := quanttbl^.quantval[Q20_POS];
- Q11 := quanttbl^.quantval[Q11_POS];
- Q02 := quanttbl^.quantval[Q02_POS];
- inverse_DCT := cinfo^.idct^.inverse_DCT[ci];
- output_ptr := output_buf^[ci];
- { Loop over all DCT blocks to be processed. }
- for block_row := 0 to (block_rows-1) do
- begin
- buffer_ptr := buffer^[block_row];
- if (first_row) and (block_row = 0) then
- prev_block_row := buffer_ptr
- else
- prev_block_row := buffer^[block_row-1];
- if (last_row) and (block_row = block_rows-1) then
- next_block_row := buffer_ptr
- else
- next_block_row := buffer^[block_row+1];
- { We fetch the surrounding DC values using a sliding-register approach.
- Initialize all nine here so as to do the right thing on narrow pics.}
-
- DC3 := int(prev_block_row^[0][0]);
- DC2 := DC3;
- DC1 := DC2;
- DC6 := int(buffer_ptr^[0][0]);
- DC5 := DC6;
- DC4 := DC5;
- DC9 := int(next_block_row^[0][0]);
- DC8 := DC9;
- DC7 := DC8 ;
- output_col := 0;
- last_block_column := compptr^.width_in_blocks - 1;
- for block_num := 0 to last_block_column do
- begin
- { Fetch current DCT block into workspace so we can modify it. }
- jcopy_block_row(buffer_ptr, JBLOCKROW (@workspace), JDIMENSION(1));
- { Update DC values }
- if (block_num < last_block_column) then
- begin
- DC3 := int (prev_block_row^[1][0]);
- DC6 := int (buffer_ptr^[1][0]);
- DC9 := int (next_block_row^[1][0]);
- end;
- { Compute coefficient estimates per K.8.
- An estimate is applied only if coefficient is still zero,
- and is not known to be fully accurate. }
-
- { AC01 }
- Al := coef_bits^[1];
- if (Al <> 0) and (workspace[1] = 0) then
- begin
- num := 36 * Q00 * (DC4 - DC6);
- if (num >= 0) then
- begin
- pred := int (((Q01 shl 7) + num) div (Q01 shl 8));
- if (Al > 0) and (pred >= (1 shl Al)) then
- pred := (1 shl Al)-1;
- end
- else
- begin
- pred := int (((Q01 shl 7) - num) div (Q01 shl 8));
- if (Al > 0) and (pred >= (1 shl Al)) then
- pred := (1 shl Al)-1;
- pred := -pred;
- end;
- workspace[1] := JCOEF (pred);
- end;
- { AC10 }
- Al := coef_bits^[2];
- if (Al <> 0) and (workspace[8] = 0) then
- begin
- num := 36 * Q00 * (DC2 - DC8);
- if (num >= 0) then
- begin
- pred := int (((Q10 shl 7) + num) div (Q10 shl 8));
- if (Al > 0) and (pred >= (1 shl Al)) then
- pred := (1 shl Al)-1;
- end
- else
- begin
- pred := int (((Q10 shl 7) - num) div (Q10 shl 8));
- if (Al > 0) and (pred >= (1 shl Al)) then
- pred := (1 shl Al)-1;
- pred := -pred;
- end;
- workspace[8] := JCOEF (pred);
- end;
- { AC20 }
- Al := coef_bits^[3];
- if (Al <> 0) and (workspace[16] = 0) then
- begin
- num := 9 * Q00 * (DC2 + DC8 - 2*DC5);
- if (num >= 0) then
- begin
- pred := int (((Q20 shl 7) + num) div (Q20 shl 8));
- if (Al > 0) and (pred >= (1 shl Al)) then
- pred := (1 shl Al)-1;
- end
- else
- begin
- pred := int (((Q20 shl 7) - num) div (Q20 shl 8));
- if (Al > 0) and (pred >= (1 shl Al)) then
- pred := (1 shl Al)-1;
- pred := -pred;
- end;
- workspace[16] := JCOEF (pred);
- end;
- { AC11 }
- Al := coef_bits^[4];
- if (Al <> 0) and (workspace[9] = 0) then
- begin
- num := 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
- if (num >= 0) then
- begin
- pred := int (((Q11 shl 7) + num) div (Q11 shl 8));
- if (Al > 0) and (pred >= (1 shl Al)) then
- pred := (1 shl Al)-1;
- end
- else
- begin
- pred := int (((Q11 shl 7) - num) div (Q11 shl 8));
- if (Al > 0) and (pred >= (1 shl Al)) then
- pred := (1 shl Al)-1;
- pred := -pred;
- end;
- workspace[9] := JCOEF (pred);
- end;
- { AC02 }
- Al := coef_bits^[5];
- if (Al <> 0) and (workspace[2] = 0) then
- begin
- num := 9 * Q00 * (DC4 + DC6 - 2*DC5);
- if (num >= 0) then
- begin
- pred := int (((Q02 shl 7) + num) div (Q02 shl 8));
- if (Al > 0) and (pred >= (1 shl Al)) then
- pred := (1 shl Al)-1;
- end
- else
- begin
- pred := int (((Q02 shl 7) - num) div (Q02 shl 8));
- if (Al > 0) and (pred >= (1 shl Al)) then
- pred := (1 shl Al)-1;
- pred := -pred;
- end;
- workspace[2] := JCOEF (pred);
- end;
- { OK, do the IDCT }
- inverse_DCT (cinfo, compptr, JCOEFPTR (@workspace),
- output_ptr, output_col);
- { Advance for next column }
- DC1 := DC2; DC2 := DC3;
- DC4 := DC5; DC5 := DC6;
- DC7 := DC8; DC8 := DC9;
- Inc(JBLOCK_PTR(buffer_ptr));
- Inc(JBLOCK_PTR(prev_block_row));
- Inc(JBLOCK_PTR(next_block_row));
- Inc(output_col, compptr^.DCT_scaled_size);
- end;
- Inc(JSAMPROW_PTR(output_ptr), compptr^.DCT_scaled_size);
- end;
- Inc(compptr);
- end;
-
- Inc(cinfo^.output_iMCU_row);
- if (cinfo^.output_iMCU_row < cinfo^.total_iMCU_rows) then
- begin
- decompress_smooth_data := JPEG_ROW_COMPLETED;
- exit;
- end;
- decompress_smooth_data := JPEG_SCAN_COMPLETED;
-end;
-
-{$endif} { BLOCK_SMOOTHING_SUPPORTED }
-
-
-{ Initialize coefficient buffer controller. }
-
-{GLOBAL}
-procedure jinit_d_coef_controller (cinfo : j_decompress_ptr;
- need_full_buffer : boolean);
-var
- coef : my_coef_ptr;
-{$ifdef D_MULTISCAN_FILES_SUPPORTED}
-var
- ci, access_rows : int;
- compptr : jpeg_component_info_ptr;
-{$endif}
-var
- buffer : JBLOCK_PTR;
- i : int;
-begin
- coef := my_coef_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr (cinfo), JPOOL_IMAGE,
- SIZEOF(my_coef_controller)) );
- cinfo^.coef := jpeg_d_coef_controller_ptr(coef);
- coef^.pub.start_input_pass := start_input_pass;
- coef^.pub.start_output_pass := start_output_pass;
-{$ifdef BLOCK_SMOOTHING_SUPPORTED}
- coef^.coef_bits_latch := NIL;
-{$endif}
-
- { Create the coefficient buffer. }
- if (need_full_buffer) then
- begin
-{$ifdef D_MULTISCAN_FILES_SUPPORTED}
- { Allocate a full-image virtual array for each component, }
- { padded to a multiple of samp_factor DCT blocks in each direction. }
- { Note we ask for a pre-zeroed array. }
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- access_rows := compptr^.v_samp_factor;
-{$ifdef BLOCK_SMOOTHING_SUPPORTED}
- { If block smoothing could be used, need a bigger window }
- if (cinfo^.progressive_mode) then
- access_rows := access_rows * 3;
-{$endif}
- coef^.whole_image[ci] := cinfo^.mem^.request_virt_barray
- (j_common_ptr (cinfo), JPOOL_IMAGE, TRUE,
- 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 (access_rows));
- Inc(compptr);
- end;
- coef^.pub.consume_data := consume_data;
- coef^.pub.decompress_data := decompress_data;
- coef^.pub.coef_arrays := @(coef^.whole_image);
- { link to virtual arrays }
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end
- else
- begin
- { We only need a single-MCU buffer. }
- buffer := JBLOCK_PTR (
- cinfo^.mem^.alloc_large (j_common_ptr (cinfo), JPOOL_IMAGE,
- D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)) );
- for i := 0 to pred(D_MAX_BLOCKS_IN_MCU) do
- begin
- coef^.MCU_buffer[i] := JBLOCKROW(buffer);
- Inc(buffer);
- end;
- coef^.pub.consume_data := dummy_consume_data;
- coef^.pub.decompress_data := decompress_onepass;
- coef^.pub.coef_arrays := NIL; { flag for no virtual arrays }
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdcolor.pas b/packages/base/pasjpeg/jdcolor.pas
deleted file mode 100644
index 3356e59e1d..0000000000
--- a/packages/base/pasjpeg/jdcolor.pas
+++ /dev/null
@@ -1,501 +0,0 @@
-Unit JdColor;
-
-{ This file contains output colorspace conversion routines. }
-
-{ Original: jdcolor.c ; Copyright (C) 1991-1997, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jutils,
- jdeferr,
- jerror,
- jpeglib;
-
-{ Module initialization routine for output colorspace conversion. }
-
-{GLOBAL}
-procedure jinit_color_deconverter (cinfo : j_decompress_ptr);
-
-implementation
-
-{ Private subobject }
-type
- int_Color_Table = array[0..MAXJSAMPLE+1-1] of int;
- int_table_ptr = ^int_Color_Table;
- INT32_Color_Table = array[0..MAXJSAMPLE+1-1] of INT32;
- INT32_table_ptr = ^INT32_Color_Table;
-type
- my_cconvert_ptr = ^my_color_deconverter;
- my_color_deconverter = record
- pub : jpeg_color_deconverter; { public fields }
-
- { Private state for YCC^.RGB conversion }
- Cr_r_tab : int_table_ptr; { => table for Cr to R conversion }
- Cb_b_tab : int_table_ptr; { => table for Cb to B conversion }
- Cr_g_tab : INT32_table_ptr; { => table for Cr to G conversion }
- Cb_g_tab : INT32_table_ptr; { => table for Cb to G conversion }
- end;
-
-
-
-
-{*************** YCbCr ^. RGB conversion: most common case *************}
-
-{ YCbCr is defined per CCIR 601-1, except that Cb and Cr are
- normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
- The conversion equations to be implemented are therefore
- R = Y + 1.40200 * Cr
- G = Y - 0.34414 * Cb - 0.71414 * Cr
- B = Y + 1.77200 * Cb
- where Cb and Cr represent the incoming values less CENTERJSAMPLE.
- (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
-
- To avoid floating-point arithmetic, we represent the fractional constants
- as integers scaled up by 2^16 (about 4 digits precision); we have to divide
- the products by 2^16, with appropriate rounding, to get the correct answer.
- Notice that Y, being an integral input, does not contribute any fraction
- so it need not participate in the rounding.
-
- For even more speed, we avoid doing any multiplications in the inner loop
- by precalculating the constants times Cb and Cr for all possible values.
- For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
- for 12-bit samples it is still acceptable. It's not very reasonable for
- 16-bit samples, but if you want lossless storage you shouldn't be changing
- colorspace anyway.
- The Cr=>R and Cb=>B values can be rounded to integers in advance; the
- values for the G calculation are left scaled up, since we must add them
- together before rounding. }
-
-const
- SCALEBITS = 16; { speediest right-shift on some machines }
- ONE_HALF = (INT32(1) shl (SCALEBITS-1));
-
-
-{ Initialize tables for YCC->RGB colorspace conversion. }
-
-{LOCAL}
-procedure build_ycc_rgb_table (cinfo : j_decompress_ptr);
-const
- FIX_1_40200 = INT32(Round( 1.40200 * (1 shl SCALEBITS)));
- FIX_1_77200 = INT32(Round( 1.77200 * (1 shl SCALEBITS)));
- FIX_0_71414 = INT32(Round( 0.71414 * (1 shl SCALEBITS)));
- FIX_0_34414 = INT32(Round( 0.34414 * (1 shl SCALEBITS)));
-
-var
- cconvert : my_cconvert_ptr;
- i : int;
- x : INT32;
-var
- shift_temp : INT32;
-begin
- cconvert := my_cconvert_ptr (cinfo^.cconvert);
-
-
- cconvert^.Cr_r_tab := int_table_ptr(
- cinfo^.mem^.alloc_small ( j_common_ptr(cinfo), JPOOL_IMAGE,
- (MAXJSAMPLE+1) * SIZEOF(int)) );
- cconvert^.Cb_b_tab := int_table_ptr (
- cinfo^.mem^.alloc_small ( j_common_ptr(cinfo), JPOOL_IMAGE,
- (MAXJSAMPLE+1) * SIZEOF(int)) );
- cconvert^.Cr_g_tab := INT32_table_ptr (
- cinfo^.mem^.alloc_small ( j_common_ptr(cinfo), JPOOL_IMAGE,
- (MAXJSAMPLE+1) * SIZEOF(INT32)) );
- cconvert^.Cb_g_tab := INT32_table_ptr (
- cinfo^.mem^.alloc_small ( j_common_ptr(cinfo), JPOOL_IMAGE,
- (MAXJSAMPLE+1) * SIZEOF(INT32)) );
-
-
- x := -CENTERJSAMPLE;
- for i := 0 to MAXJSAMPLE do
- begin
- { i is the actual input pixel value, in the range 0..MAXJSAMPLE }
- { The Cb or Cr value we are thinking of is x := i - CENTERJSAMPLE }
- { Cr=>R value is nearest int to 1.40200 * x }
-
- shift_temp := FIX_1_40200 * x + ONE_HALF;
- if shift_temp < 0 then { SHIFT arithmetic RIGHT }
- cconvert^.Cr_r_tab^[i] := int((shift_temp shr SCALEBITS)
- or ( (not INT32(0)) shl (32-SCALEBITS)))
- else
- cconvert^.Cr_r_tab^[i] := int(shift_temp shr SCALEBITS);
-
- { Cb=>B value is nearest int to 1.77200 * x }
- shift_temp := FIX_1_77200 * x + ONE_HALF;
- if shift_temp < 0 then { SHIFT arithmetic RIGHT }
- cconvert^.Cb_b_tab^[i] := int((shift_temp shr SCALEBITS)
- or ( (not INT32(0)) shl (32-SCALEBITS)))
- else
- cconvert^.Cb_b_tab^[i] := int(shift_temp shr SCALEBITS);
-
- { Cr=>G value is scaled-up -0.71414 * x }
- cconvert^.Cr_g_tab^[i] := (- FIX_0_71414 ) * x;
- { Cb=>G value is scaled-up -0.34414 * x }
- { We also add in ONE_HALF so that need not do it in inner loop }
- cconvert^.Cb_g_tab^[i] := (- FIX_0_34414 ) * x + ONE_HALF;
- Inc(x);
- end;
-end;
-
-
-{ Convert some rows of samples to the output colorspace.
-
- Note that we change from noninterleaved, one-plane-per-component format
- to interleaved-pixel format. The output buffer is therefore three times
- as wide as the input buffer.
- A starting row offset is provided only for the input buffer. The caller
- can easily adjust the passed output_buf value to accommodate any row
- offset required on that side. }
-
-{METHODDEF}
-procedure ycc_rgb_convert (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- input_row : JDIMENSION;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-var
- cconvert : my_cconvert_ptr;
- {register} y, cb, cr : int;
- {register} outptr : JSAMPROW;
- {register} inptr0, inptr1, inptr2 : JSAMPROW;
- {register} col : JDIMENSION;
- num_cols : JDIMENSION;
- { copy these pointers into registers if possible }
- {register} range_limit : range_limit_table_ptr;
- {register} Crrtab : int_table_ptr;
- {register} Cbbtab : int_table_ptr;
- {register} Crgtab : INT32_table_ptr;
- {register} Cbgtab : INT32_table_ptr;
-var
- shift_temp : INT32;
-begin
- cconvert := my_cconvert_ptr (cinfo^.cconvert);
- num_cols := cinfo^.output_width;
- range_limit := cinfo^.sample_range_limit;
- Crrtab := cconvert^.Cr_r_tab;
- Cbbtab := cconvert^.Cb_b_tab;
- Crgtab := cconvert^.Cr_g_tab;
- Cbgtab := cconvert^.Cb_g_tab;
-
- while (num_rows > 0) do
- begin
- Dec(num_rows);
- inptr0 := input_buf^[0]^[input_row];
- inptr1 := input_buf^[1]^[input_row];
- inptr2 := input_buf^[2]^[input_row];
- Inc(input_row);
- outptr := output_buf^[0];
- Inc(JSAMPROW_PTR(output_buf));
- for col := 0 to pred(num_cols) do
- begin
- y := GETJSAMPLE(inptr0^[col]);
- cb := GETJSAMPLE(inptr1^[col]);
- cr := GETJSAMPLE(inptr2^[col]);
- { Range-limiting is essential due to noise introduced by DCT losses. }
- outptr^[RGB_RED] := range_limit^[y + Crrtab^[cr]];
- shift_temp := Cbgtab^[cb] + Crgtab^[cr];
- if shift_temp < 0 then { SHIFT arithmetic RIGHT }
- outptr^[RGB_GREEN] := range_limit^[y + int((shift_temp shr SCALEBITS)
- or ( (not INT32(0)) shl (32-SCALEBITS)))]
- else
- outptr^[RGB_GREEN] := range_limit^[y + int(shift_temp shr SCALEBITS)];
-
- outptr^[RGB_BLUE] := range_limit^[y + Cbbtab^[cb]];
- Inc(JSAMPLE_PTR(outptr), RGB_PIXELSIZE);
- end;
- end;
-end;
-
-
-{*************** Cases other than YCbCr -> RGB *************}
-
-
-{ Color conversion for no colorspace change: just copy the data,
- converting from separate-planes to interleaved representation. }
-
-{METHODDEF}
-procedure null_convert (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- input_row : JDIMENSION;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-var
- {register} inptr,
- outptr : JSAMPLE_PTR;
- {register} count : JDIMENSION;
- {register} num_components : int;
- num_cols : JDIMENSION;
- ci : int;
-begin
- num_components := cinfo^.num_components;
- num_cols := cinfo^.output_width;
-
- while (num_rows > 0) do
- begin
- Dec(num_rows);
- for ci := 0 to pred(num_components) do
- begin
- inptr := JSAMPLE_PTR(input_buf^[ci]^[input_row]);
- outptr := JSAMPLE_PTR(@(output_buf^[0]^[ci]));
-
- for count := pred(num_cols) downto 0 do
- begin
- outptr^ := inptr^; { needn't bother with GETJSAMPLE() here }
- Inc(inptr);
- Inc(outptr, num_components);
- end;
- end;
- Inc(input_row);
- Inc(JSAMPROW_PTR(output_buf));
- end;
-end;
-
-
-{ Color conversion for grayscale: just copy the data.
- This also works for YCbCr -> grayscale conversion, in which
- we just copy the Y (luminance) component and ignore chrominance. }
-
-{METHODDEF}
-procedure grayscale_convert (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- input_row : JDIMENSION;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-begin
- jcopy_sample_rows(input_buf^[0], int(input_row), output_buf, 0,
- num_rows, cinfo^.output_width);
-end;
-
-{ Convert grayscale to RGB: just duplicate the graylevel three times.
- This is provided to support applications that don't want to cope
- with grayscale as a separate case. }
-
-{METHODDEF}
-procedure gray_rgb_convert (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- input_row : JDIMENSION;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-var
- {register} inptr, outptr : JSAMPLE_PTR;
- {register} col : JDIMENSION;
- num_cols : JDIMENSION;
-begin
- num_cols := cinfo^.output_width;
- while (num_rows > 0) do
- begin
- inptr := JSAMPLE_PTR(input_buf^[0]^[input_row]);
- Inc(input_row);
- outptr := JSAMPLE_PTR(@output_buf^[0]);
- Inc(JSAMPROW_PTR(output_buf));
- for col := 0 to pred(num_cols) do
- begin
- { We can dispense with GETJSAMPLE() here }
- JSAMPROW(outptr)^[RGB_RED] := inptr^;
- JSAMPROW(outptr)^[RGB_GREEN] := inptr^;
- JSAMPROW(outptr)^[RGB_BLUE] := inptr^;
- Inc(inptr);
- Inc(outptr, RGB_PIXELSIZE);
- end;
- Dec(num_rows);
- end;
-end;
-
-
-{ Adobe-style YCCK -> CMYK conversion.
- We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same
- conversion as above, while passing K (black) unchanged.
- We assume build_ycc_rgb_table has been called. }
-
-{METHODDEF}
-procedure ycck_cmyk_convert (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- input_row : JDIMENSION;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-var
- cconvert : my_cconvert_ptr;
- {register} y, cb, cr : int;
- {register} outptr : JSAMPROW;
- {register} inptr0, inptr1, inptr2, inptr3 : JSAMPROW;
- {register} col : JDIMENSION;
- num_cols : JDIMENSION;
- { copy these pointers into registers if possible }
- {register} range_limit : range_limit_table_ptr;
- {register} Crrtab : int_table_ptr;
- {register} Cbbtab : int_table_ptr;
- {register} Crgtab : INT32_table_ptr;
- {register} Cbgtab : INT32_table_ptr;
-var
- shift_temp : INT32;
-begin
- cconvert := my_cconvert_ptr (cinfo^.cconvert);
- num_cols := cinfo^.output_width;
- { copy these pointers into registers if possible }
- range_limit := cinfo^.sample_range_limit;
- Crrtab := cconvert^.Cr_r_tab;
- Cbbtab := cconvert^.Cb_b_tab;
- Crgtab := cconvert^.Cr_g_tab;
- Cbgtab := cconvert^.Cb_g_tab;
-
- while (num_rows > 0) do
- begin
- Dec(num_rows);
- inptr0 := input_buf^[0]^[input_row];
- inptr1 := input_buf^[1]^[input_row];
- inptr2 := input_buf^[2]^[input_row];
- inptr3 := input_buf^[3]^[input_row];
- Inc(input_row);
- outptr := output_buf^[0];
- Inc(JSAMPROW_PTR(output_buf));
- for col := 0 to pred(num_cols) do
- begin
- y := GETJSAMPLE(inptr0^[col]);
- cb := GETJSAMPLE(inptr1^[col]);
- cr := GETJSAMPLE(inptr2^[col]);
- { Range-limiting is essential due to noise introduced by DCT losses. }
- outptr^[0] := range_limit^[MAXJSAMPLE - (y + Crrtab^[cr])]; { red }
- shift_temp := Cbgtab^[cb] + Crgtab^[cr];
- if shift_temp < 0 then
- outptr^[1] := range_limit^[MAXJSAMPLE - (y + int(
- (shift_temp shr SCALEBITS) or ((not INT32(0)) shl (32-SCALEBITS))
- ) )]
- else
- outptr^[1] := range_limit^[MAXJSAMPLE - { green }
- (y + int(shift_temp shr SCALEBITS) )];
- outptr^[2] := range_limit^[MAXJSAMPLE - (y + Cbbtab^[cb])]; { blue }
- { K passes through unchanged }
- outptr^[3] := inptr3^[col]; { don't need GETJSAMPLE here }
- Inc(JSAMPLE_PTR(outptr), 4);
- end;
- end;
-end;
-
-
-{ Empty method for start_pass. }
-
-{METHODDEF}
-procedure start_pass_dcolor (cinfo : j_decompress_ptr); far;
-begin
- { no work needed }
-end;
-
-
-{ Module initialization routine for output colorspace conversion. }
-
-{GLOBAL}
-procedure jinit_color_deconverter (cinfo : j_decompress_ptr);
-var
- cconvert : my_cconvert_ptr;
- ci : int;
-begin
- cconvert := my_cconvert_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_color_deconverter)) );
- cinfo^.cconvert := jpeg_color_deconverter_ptr (cconvert);
- cconvert^.pub.start_pass := start_pass_dcolor;
-
- { Make sure num_components agrees with jpeg_color_space }
- case (cinfo^.jpeg_color_space) of
- JCS_GRAYSCALE:
- if (cinfo^.num_components <> 1) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
-
- JCS_RGB,
- JCS_YCbCr:
- if (cinfo^.num_components <> 3) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
-
- JCS_CMYK,
- JCS_YCCK:
- if (cinfo^.num_components <> 4) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
-
- else { JCS_UNKNOWN can be anything }
- if (cinfo^.num_components < 1) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
- end;
-
- { Set out_color_components and conversion method based on requested space.
- Also clear the component_needed flags for any unused components,
- so that earlier pipeline stages can avoid useless computation. }
-
- case (cinfo^.out_color_space) of
- JCS_GRAYSCALE:
- begin
- cinfo^.out_color_components := 1;
- if (cinfo^.jpeg_color_space = JCS_GRAYSCALE)
- or (cinfo^.jpeg_color_space = JCS_YCbCr) then
- begin
- cconvert^.pub.color_convert := grayscale_convert;
- { For color -> grayscale conversion, only the
- Y (0) component is needed }
- for ci := 1 to pred(cinfo^.num_components) do
- cinfo^.comp_info^[ci].component_needed := FALSE;
- end
- else
- ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
- end;
-
- JCS_RGB:
- begin
- cinfo^.out_color_components := RGB_PIXELSIZE;
- if (cinfo^.jpeg_color_space = JCS_YCbCr) then
- begin
- cconvert^.pub.color_convert := ycc_rgb_convert;
- build_ycc_rgb_table(cinfo);
- end
- else
- if (cinfo^.jpeg_color_space = JCS_GRAYSCALE) then
- begin
- cconvert^.pub.color_convert := gray_rgb_convert;
- end
- else
- if (cinfo^.jpeg_color_space = JCS_RGB) and (RGB_PIXELSIZE = 3) then
- begin
- cconvert^.pub.color_convert := null_convert;
- end
- else
- ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
- end;
-
- JCS_CMYK:
- begin
- cinfo^.out_color_components := 4;
- if (cinfo^.jpeg_color_space = JCS_YCCK) then
- begin
- cconvert^.pub.color_convert := ycck_cmyk_convert;
- build_ycc_rgb_table(cinfo);
- end
- else
- if (cinfo^.jpeg_color_space = JCS_CMYK) then
- begin
- cconvert^.pub.color_convert := null_convert;
- end
- else
- ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
- end;
-
- else
- begin { Permit null conversion to same output space }
- if (cinfo^.out_color_space = cinfo^.jpeg_color_space) then
- begin
- cinfo^.out_color_components := cinfo^.num_components;
- cconvert^.pub.color_convert := null_convert;
- end
- else { unsupported non-null conversion }
- ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
- end;
- end;
-
- if (cinfo^.quantize_colors) then
- cinfo^.output_components := 1 { single colormapped output component }
- else
- cinfo^.output_components := cinfo^.out_color_components;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdct.pas b/packages/base/pasjpeg/jdct.pas
deleted file mode 100644
index 2983e6fa0d..0000000000
--- a/packages/base/pasjpeg/jdct.pas
+++ /dev/null
@@ -1,109 +0,0 @@
-Unit Jdct;
-
-{ Orignal: jdct.h; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-{ This include file contains common declarations for the forward and
- inverse DCT modules. These declarations are private to the DCT managers
- (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms.
- The individual DCT algorithms are kept in separate files to ease
- machine-dependent tuning (e.g., assembly coding). }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg;
-
-
-{ A forward DCT routine is given a pointer to a work area of type DCTELEM[];
- the DCT is to be performed in-place in that buffer. Type DCTELEM is int
- for 8-bit samples, INT32 for 12-bit samples. (NOTE: Floating-point DCT
- implementations use an array of type FAST_FLOAT, instead.)
- The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).
- The DCT outputs are returned scaled up by a factor of 8; they therefore
- have a range of +-8K for 8-bit data, +-128K for 12-bit data. This
- convention improves accuracy in integer implementations and saves some
- work in floating-point ones.
- Quantization of the output coefficients is done by jcdctmgr.c. }
-
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-type
- DCTELEM = int; { 16 or 32 bits is fine }
-{$else}
-type { must have 32 bits }
- DCTELEM = INT32;
-{$endif}
-type
- jTDctElem = 0..(MaxInt div SizeOf(DCTELEM))-1;
- DCTELEM_FIELD = array[jTDctElem] of DCTELEM;
- DCTELEM_FIELD_PTR = ^DCTELEM_FIELD;
- DCTELEMPTR = ^DCTELEM;
-
-type
- forward_DCT_method_ptr = procedure(var data : array of DCTELEM);
- float_DCT_method_ptr = procedure(var data : array of FAST_FLOAT);
-
-
-{ An inverse DCT routine is given a pointer to the input JBLOCK and a pointer
- to an output sample array. The routine must dequantize the input data as
- well as perform the IDCT; for dequantization, it uses the multiplier table
- pointed to by compptr->dct_table. The output data is to be placed into the
- sample array starting at a specified column. (Any row offset needed will
- be applied to the array pointer before it is passed to the IDCT code.)
- Note that the number of samples emitted by the IDCT routine is
- DCT_scaled_size * DCT_scaled_size. }
-
-
-{ typedef inverse_DCT_method_ptr is declared in jpegint.h }
-
-
-{ Each IDCT routine has its own ideas about the best dct_table element type. }
-
-
-type
- ISLOW_MULT_TYPE = MULTIPLIER; { short or int, whichever is faster }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-type
- IFAST_MULT_TYPE = MULTIPLIER; { 16 bits is OK, use short if faster }
-const
- IFAST_SCALE_BITS = 2; { fractional bits in scale factors }
-{$else}
-type
- IFAST_MULT_TYPE = INT32; { need 32 bits for scaled quantizers }
-const
- IFAST_SCALE_BITS = 13; { fractional bits in scale factors }
-{$endif}
-type
- FLOAT_MULT_TYPE = FAST_FLOAT; { preferred floating type }
-
-const
- RANGE_MASK = (MAXJSAMPLE * 4 + 3); { 2 bits wider than legal samples }
-
-type
- jTMultType = 0..(MaxInt div SizeOf(ISLOW_MULT_TYPE))-1;
- ISLOW_MULT_TYPE_FIELD = array[jTMultType] of ISLOW_MULT_TYPE;
- ISLOW_MULT_TYPE_FIELD_PTR = ^ISLOW_MULT_TYPE_FIELD;
- ISLOW_MULT_TYPE_PTR = ^ISLOW_MULT_TYPE;
-
- jTFloatType = 0..(MaxInt div SizeOf(FLOAT_MULT_TYPE))-1;
- FLOAT_MULT_TYPE_FIELD = array[jTFloatType] of FLOAT_MULT_TYPE;
- FLOAT_MULT_TYPE_FIELD_PTR = ^FLOAT_MULT_TYPE_FIELD;
- FLOAT_MULT_TYPE_PTR = ^FLOAT_MULT_TYPE;
-
- jTFastType = 0..(MaxInt div SizeOf(IFAST_MULT_TYPE))-1;
- IFAST_MULT_TYPE_FIELD = array[jTFastType] of IFAST_MULT_TYPE;
- IFAST_MULT_TYPE_FIELD_PTR = ^IFAST_MULT_TYPE_FIELD;
- IFAST_MULT_TYPE_PTR = ^IFAST_MULT_TYPE;
-
-type
- jTFastFloat = 0..(MaxInt div SizeOf(FAST_FLOAT))-1;
- FAST_FLOAT_FIELD = array[jTFastFloat] of FAST_FLOAT;
- FAST_FLOAT_FIELD_PTR = ^FAST_FLOAT_FIELD;
- FAST_FLOAT_PTR = ^FAST_FLOAT;
-
-implementation
-
-end.
diff --git a/packages/base/pasjpeg/jddctmgr.pas b/packages/base/pasjpeg/jddctmgr.pas
deleted file mode 100644
index babfc16f0d..0000000000
--- a/packages/base/pasjpeg/jddctmgr.pas
+++ /dev/null
@@ -1,329 +0,0 @@
-Unit JdDctMgr;
-
-{ Original : jddctmgr.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-{ This file contains the inverse-DCT management logic.
- This code selects a particular IDCT implementation to be used,
- and it performs related housekeeping chores. No code in this file
- is executed per IDCT step, only during output pass setup.
-
- Note that the IDCT routines are responsible for performing coefficient
- dequantization as well as the IDCT proper. This module sets up the
- dequantization multiplier table needed by the IDCT routine. }
-
-interface
-
-{$I jconfig.inc}
-
-{$N+}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jpeglib,
- jdct, { Private declarations for DCT subsystem }
- jidctfst,
- {$IFDEF BASM}
- jidctasm,
- {$ELSE}
- jidctint,
- {$ENDIF}
- jidctflt, JIDctRed;
-
-
-
-{ Initialize IDCT manager. }
-
-{GLOBAL}
-procedure jinit_inverse_dct (cinfo : j_decompress_ptr);
-
-
-implementation
-
-{ The decompressor input side (jdinput.c) saves away the appropriate
- quantization table for each component at the start of the first scan
- involving that component. (This is necessary in order to correctly
- decode files that reuse Q-table slots.)
- When we are ready to make an output pass, the saved Q-table is converted
- to a multiplier table that will actually be used by the IDCT routine.
- The multiplier table contents are IDCT-method-dependent. To support
- application changes in IDCT method between scans, we can remake the
- multiplier tables if necessary.
- In buffered-image mode, the first output pass may occur before any data
- has been seen for some components, and thus before their Q-tables have
- been saved away. To handle this case, multiplier tables are preset
- to zeroes; the result of the IDCT will be a neutral gray level. }
-
-
-{ Private subobject for this module }
-
-type
- my_idct_ptr = ^my_idct_controller;
- my_idct_controller = record
- pub : jpeg_inverse_dct; { public fields }
-
- { This array contains the IDCT method code that each multiplier table
- is currently set up for, or -1 if it's not yet set up.
- The actual multiplier tables are pointed to by dct_table in the
- per-component comp_info structures. }
-
- cur_method : array[0..MAX_COMPONENTS-1] of int;
- end; {my_idct_controller;}
-
-
-{ Allocated multiplier tables: big enough for any supported variant }
-
-type
- multiplier_table = record
- case byte of
- 0:(islow_array : array[0..DCTSIZE2-1] of ISLOW_MULT_TYPE);
- {$ifdef DCT_IFAST_SUPPORTED}
- 1:(ifast_array : array[0..DCTSIZE2-1] of IFAST_MULT_TYPE);
- {$endif}
- {$ifdef DCT_FLOAT_SUPPORTED}
- 2:(float_array : array[0..DCTSIZE2-1] of FLOAT_MULT_TYPE);
- {$endif}
- end;
-
-
-{ The current scaled-IDCT routines require ISLOW-style multiplier tables,
- so be sure to compile that code if either ISLOW or SCALING is requested. }
-
-{$ifdef DCT_ISLOW_SUPPORTED}
- {$define PROVIDE_ISLOW_TABLES}
-{$else}
- {$ifdef IDCT_SCALING_SUPPORTED}
- {$define PROVIDE_ISLOW_TABLES}
- {$endif}
-{$endif}
-
-
-{ Prepare for an output pass.
- Here we select the proper IDCT routine for each component and build
- a matching multiplier table. }
-
-{METHODDEF}
-procedure start_pass (cinfo : j_decompress_ptr); far;
-var
- idct : my_idct_ptr;
- ci, i : int;
- compptr : jpeg_component_info_ptr;
- method : J_DCT_METHOD;
- method_ptr : inverse_DCT_method_ptr;
- qtbl : JQUANT_TBL_PTR;
-{$ifdef PROVIDE_ISLOW_TABLES}
-var
- ismtbl : ISLOW_MULT_TYPE_FIELD_PTR;
-{$endif}
-{$ifdef DCT_IFAST_SUPPORTED}
-const
- CONST_BITS = 14;
-const
- aanscales : array[0..DCTSIZE2-1] of INT16 =
- ({ precomputed values scaled up by 14 bits }
- 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
- 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
- 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
- 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
- 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
- 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
- 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
- 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247);
-var
- ifmtbl : IFAST_MULT_TYPE_FIELD_PTR;
- {SHIFT_TEMPS}
-
- { Descale and correctly round an INT32 value that's scaled by N bits.
- We assume RIGHT_SHIFT rounds towards minus infinity, so adding
- the fudge factor is correct for either sign of X. }
-
- function DESCALE(x : INT32; n : int) : INT32;
- var
- shift_temp : INT32;
- begin
- {$ifdef RIGHT_SHIFT_IS_UNSIGNED}
- shift_temp := x + (INT32(1) shl (n-1));
- if shift_temp < 0 then
- Descale := (shift_temp shr n) or ((not INT32(0)) shl (32-n))
- else
- Descale := (shift_temp shr n);
- {$else}
- Descale := (x + (INT32(1) shl (n-1)) shr n;
- {$endif}
- end;
-
-{$endif}
-{$ifdef DCT_FLOAT_SUPPORTED}
-const
- aanscalefactor : array[0..DCTSIZE-1] of double =
- (1.0, 1.387039845, 1.306562965, 1.175875602,
- 1.0, 0.785694958, 0.541196100, 0.275899379);
-var
- fmtbl : FLOAT_MULT_TYPE_FIELD_PTR;
- row, col : int;
-{$endif}
-begin
- idct := my_idct_ptr (cinfo^.idct);
- method := J_DCT_METHOD(0);
- method_ptr := NIL;
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
-
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- { Select the proper IDCT routine for this component's scaling }
- case (compptr^.DCT_scaled_size) of
-{$ifdef IDCT_SCALING_SUPPORTED}
- 1:begin
- method_ptr := jpeg_idct_1x1;
- method := JDCT_ISLOW; { jidctred uses islow-style table }
- end;
- 2:begin
- method_ptr := jpeg_idct_2x2;
- method := JDCT_ISLOW; { jidctred uses islow-style table }
- end;
- 4:begin
- method_ptr := jpeg_idct_4x4;
- method := JDCT_ISLOW; { jidctred uses islow-style table }
- end;
-{$endif}
- DCTSIZE:
- case (cinfo^.dct_method) of
-{$ifdef DCT_ISLOW_SUPPORTED}
- JDCT_ISLOW:
- begin
- method_ptr := jpeg_idct_islow;
- method := JDCT_ISLOW;
- end;
-{$endif}
-{$ifdef DCT_IFAST_SUPPORTED}
- JDCT_IFAST:
- begin
- method_ptr := jpeg_idct_ifast;
- method := JDCT_IFAST;
- end;
-{$endif}
-{$ifdef DCT_FLOAT_SUPPORTED}
- JDCT_FLOAT:
- begin
- method_ptr := jpeg_idct_float;
- method := JDCT_FLOAT;
- end;
-{$endif}
- else
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
- end;
- else
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_DCTSIZE, compptr^.DCT_scaled_size);
- end;
- idct^.pub.inverse_DCT[ci] := method_ptr;
- { Create multiplier table from quant table.
- However, we can skip this if the component is uninteresting
- or if we already built the table. Also, if no quant table
- has yet been saved for the component, we leave the
- multiplier table all-zero; we'll be reading zeroes from the
- coefficient controller's buffer anyway. }
-
- if (not compptr^.component_needed) or (idct^.cur_method[ci] = int(method)) then
- continue;
- qtbl := compptr^.quant_table;
- if (qtbl = NIL) then { happens if no data yet for component }
- continue;
- idct^.cur_method[ci] := int(method);
- case (method) of
-{$ifdef PROVIDE_ISLOW_TABLES}
- JDCT_ISLOW:
- begin
- { For LL&M IDCT method, multipliers are equal to raw quantization
- coefficients, but are stored as ints to ensure access efficiency. }
-
- ismtbl := ISLOW_MULT_TYPE_FIELD_PTR (compptr^.dct_table);
- for i := 0 to pred(DCTSIZE2) do
- begin
- ismtbl^[i] := ISLOW_MULT_TYPE (qtbl^.quantval[i]);
- end;
- end;
-{$endif}
-{$ifdef DCT_IFAST_SUPPORTED}
- JDCT_IFAST:
- begin
- { For AA&N IDCT method, multipliers are equal to quantization
- coefficients scaled by scalefactor[row]*scalefactor[col], where
- scalefactor[0] := 1
- scalefactor[k] := cos(k*PI/16) * sqrt(2) for k=1..7
- For integer operation, the multiplier table is to be scaled by
- IFAST_SCALE_BITS. }
-
- ifmtbl := IFAST_MULT_TYPE_FIELD_PTR (compptr^.dct_table);
-
- for i := 0 to pred(DCTSIZE2) do
- begin
- ifmtbl^[i] := IFAST_MULT_TYPE(
- DESCALE( INT32 (qtbl^.quantval[i]) * INT32 (aanscales[i]),
- CONST_BITS-IFAST_SCALE_BITS) );
- end;
- end;
-{$endif}
-{$ifdef DCT_FLOAT_SUPPORTED}
- JDCT_FLOAT:
- begin
- { For float AA&N IDCT method, multipliers are equal to quantization
- coefficients scaled by scalefactor[row]*scalefactor[col], where
- scalefactor[0] := 1
- scalefactor[k] := cos(k*PI/16) * sqrt(2) for k=1..7 }
-
- fmtbl := FLOAT_MULT_TYPE_FIELD_PTR(compptr^.dct_table);
-
- i := 0;
- for row := 0 to pred(DCTSIZE) do
- begin
- for col := 0 to pred(DCTSIZE) do
- begin
- fmtbl^[i] := {FLOAT_MULT_TYPE} (
- {double} qtbl^.quantval[i] *
- aanscalefactor[row] * aanscalefactor[col] );
- Inc(i);
- end;
- end;
- end;
-{$endif}
- else
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
- break;
- end;
- Inc(compptr);
- end;
-end;
-
-
-{ Initialize IDCT manager. }
-
-{GLOBAL}
-procedure jinit_inverse_dct (cinfo : j_decompress_ptr);
-var
- idct : my_idct_ptr;
- ci : int;
- compptr : jpeg_component_info_ptr;
-begin
- idct := my_idct_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_idct_controller)) );
- cinfo^.idct := jpeg_inverse_dct_ptr (idct);
- idct^.pub.start_pass := start_pass;
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- { Allocate and pre-zero a multiplier table for each component }
- compptr^.dct_table :=
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(multiplier_table));
- MEMZERO(compptr^.dct_table, SIZEOF(multiplier_table));
- { Mark multiplier table not yet set up for any method }
- idct^.cur_method[ci] := -1;
- Inc(compptr);
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdeferr.pas b/packages/base/pasjpeg/jdeferr.pas
deleted file mode 100644
index f1f0c693ca..0000000000
--- a/packages/base/pasjpeg/jdeferr.pas
+++ /dev/null
@@ -1,497 +0,0 @@
-Unit JdefErr;
-
-{ This file defines the error and message codes for the cjpeg/djpeg
- applications. These strings are not needed as part of the JPEG library
- proper.
- Edit this file to add new codes, or to translate the message strings to
- some other language. }
-
-{ Original cderror.h ; Copyright (C) 1994, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-{ To define the enum list of message codes, include this file without
- defining macro JMESSAGE. To create a message string table, include it
- again with a suitable JMESSAGE definition (see jerror.c for an example). }
-
-
-{ Original: jversion.h ; Copyright (C) 1991-1996, Thomas G. Lane. }
-{ This file contains software version identification. }
-
-const
- JVERSION = '6a 7-Feb-96';
-
- JCOPYRIGHT = 'Copyright (C) 1996, Thomas G. Lane';
-
- JNOTICE = 'Pascal Translation, Copyright (C) 1996, Jacques Nomssi Nzali';
-
-{ 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. }
-
-type
- J_MESSAGE_CODE =(
- 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_COUNTS,
- 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_FIRSTADDONCODE, { Must be first entry! }
-
- {$ifdef BMP_SUPPORTED}
- JERR_BMP_BADCMAP, { Unsupported BMP colormap format }
- JERR_BMP_BADDEPTH, { Only 8- and 24-bit BMP files are supported }
- JERR_BMP_BADHEADER, { Invalid BMP file: bad header length }
- JERR_BMP_BADPLANES, { Invalid BMP file: biPlanes not equal to 1 }
- JERR_BMP_COLORSPACE, { BMP output must be grayscale or RGB }
- JERR_BMP_COMPRESSED, { Sorry, compressed BMPs not yet supported }
- JERR_BMP_NOT, { Not a BMP file - does not start with BM }
- JTRC_BMP, { %dx%d 24-bit BMP image }
- JTRC_BMP_MAPPED, { %dx%d 8-bit colormapped BMP image }
- JTRC_BMP_OS2, { %dx%d 24-bit OS2 BMP image }
- JTRC_BMP_OS2_MAPPED, { %dx%d 8-bit colormapped OS2 BMP image }
- {$endif} { BMP_SUPPORTED }
-
- {$ifdef GIF_SUPPORTED}
- JERR_GIF_BUG, { GIF output got confused }
- JERR_GIF_CODESIZE, { Bogus GIF codesize %d }
- JERR_GIF_COLORSPACE, { GIF output must be grayscale or RGB }
- JERR_GIF_IMAGENOTFOUND, { Too few images in GIF file }
- JERR_GIF_NOT, { Not a GIF file }
- JTRC_GIF, { %dx%dx%d GIF image }
- JTRC_GIF_BADVERSION,
- { Warning: unexpected GIF version number '%c%c%c' }
- JTRC_GIF_EXTENSION, { Ignoring GIF extension block of type 0x%02x }
- JTRC_GIF_NONSQUARE, { Caution: nonsquare pixels in input }
- JWRN_GIF_BADDATA, { Corrupt data in GIF file }
- JWRN_GIF_CHAR, { Bogus char 0x%02x in GIF file, ignoring }
- JWRN_GIF_ENDCODE, { Premature end of GIF image }
- JWRN_GIF_NOMOREDATA, { Ran out of GIF bits }
- {$endif} { GIF_SUPPORTED }
-
- {$ifdef PPM_SUPPORTED}
- JERR_PPM_COLORSPACE, { PPM output must be grayscale or RGB }
- JERR_PPM_NONNUMERIC, { Nonnumeric data in PPM file }
- JERR_PPM_NOT, { Not a PPM file }
- JTRC_PGM, { %dx%d PGM image }
- JTRC_PGM_TEXT, { %dx%d text PGM image }
- JTRC_PPM, { %dx%d PPM image }
- JTRC_PPM_TEXT, { %dx%d text PPM image }
- {$endif} { PPM_SUPPORTED }
-
- {$ifdef RLE_SUPPORTED}
- JERR_RLE_BADERROR, { Bogus error code from RLE library }
- JERR_RLE_COLORSPACE, { RLE output must be grayscale or RGB }
- JERR_RLE_DIMENSIONS, { Image dimensions (%dx%d) too large for RLE }
- JERR_RLE_EMPTY, { Empty RLE file }
- JERR_RLE_EOF, { Premature EOF in RLE header }
- JERR_RLE_MEM, { Insufficient memory for RLE header }
- JERR_RLE_NOT, { Not an RLE file }
- JERR_RLE_TOOMANYCHANNELS, { Cannot handle %d output channels for RLE }
- JERR_RLE_UNSUPPORTED, { Cannot handle this RLE setup }
- JTRC_RLE, { %dx%d full-color RLE file }
- JTRC_RLE_FULLMAP, { %dx%d full-color RLE file with map of length %d }
- JTRC_RLE_GRAY, { %dx%d grayscale RLE file }
- JTRC_RLE_MAPGRAY, { %dx%d grayscale RLE file with map of length %d }
- JTRC_RLE_MAPPED, { %dx%d colormapped RLE file with map of length %d }
- {$endif} { RLE_SUPPORTED }
-
- {$ifdef TARGA_SUPPORTED}
- JERR_TGA_BADCMAP, { Unsupported Targa colormap format }
- JERR_TGA_BADPARMS, { Invalid or unsupported Targa file }
- JERR_TGA_COLORSPACE, { Targa output must be grayscale or RGB }
- JTRC_TGA, { %dx%d RGB Targa image }
- JTRC_TGA_GRAY, { %dx%d grayscale Targa image }
- JTRC_TGA_MAPPED, { %dx%d colormapped Targa image }
- {$else}
- JERR_TGA_NOTCOMP, { Targa support was not compiled }
- {$endif} { TARGA_SUPPORTED }
-
- JERR_BAD_CMAP_FILE,
- { Color map file is invalid or of unsupported format }
- JERR_TOO_MANY_COLORS,
- { Output file format cannot handle %d colormap entries }
- JERR_UNGETC_FAILED, { ungetc failed }
- {$ifdef TARGA_SUPPORTED}
- JERR_UNKNOWN_FORMAT,
- { Unrecognized input file format --- perhaps you need -targa }
- {$else}
- JERR_UNKNOWN_FORMAT, { Unrecognized input file format }
- {$endif}
- JERR_UNSUPPORTED_FORMAT, { Unsupported output file format }
-
- JMSG_LASTADDONCODE
- );
-
-
-const
- JMSG_LASTMSGCODE : J_MESSAGE_CODE = JMSG_LASTADDONCODE;
-
-type
- msg_table = Array[J_MESSAGE_CODE] of string[80];
-const
- jpeg_std_message_table : msg_table = (
-
- { JMSG_NOMESSAGE } 'Bogus message code %d', { Must be first entry! }
-
-{ For maintenance convenience, list is alphabetical by message code name }
- { JERR_ARITH_NOTIMPL }
- 'Sorry, there are legal restrictions on arithmetic coding',
- { JERR_BAD_ALIGN_TYPE } 'ALIGN_TYPE is wrong, please fix',
- { JERR_BAD_ALLOC_CHUNK } 'MAX_ALLOC_CHUNK is wrong, please fix',
- { JERR_BAD_BUFFER_MODE } 'Bogus buffer control mode',
- { JERR_BAD_COMPONENT_ID } 'Invalid component ID %d in SOS',
- { JERR_BAD_DCT_COEF } 'DCT coefficient out of range',
- { JERR_BAD_DCTSIZE } 'IDCT output block size %d not supported',
- { JERR_BAD_HUFF_TABLE } 'Bogus Huffman table definition',
- { JERR_BAD_IN_COLORSPACE } 'Bogus input colorspace',
- { JERR_BAD_J_COLORSPACE } 'Bogus JPEG colorspace',
- { JERR_BAD_LENGTH } 'Bogus marker length',
- { JERR_BAD_LIB_VERSION }
- 'Wrong JPEG library version: library is %d, caller expects %d',
- { JERR_BAD_MCU_SIZE } 'Sampling factors too large for interleaved scan',
- { JERR_BAD_POOL_ID } 'Invalid memory pool code %d',
- { JERR_BAD_PRECISION } 'Unsupported JPEG data precision %d',
- { JERR_BAD_PROGRESSION }
- 'Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d',
- { JERR_BAD_PROG_SCRIPT }
- 'Invalid progressive parameters at scan script entry %d',
- { JERR_BAD_SAMPLING } 'Bogus sampling factors',
- { JERR_BAD_SCAN_SCRIPT } 'Invalid scan script at entry %d',
- { JERR_BAD_STATE } 'Improper call to JPEG library in state %d',
- { JERR_BAD_STRUCT_SIZE }
- 'JPEG parameter struct mismatch: library thinks size is %d, caller expects %d',
- { JERR_BAD_VIRTUAL_ACCESS } 'Bogus virtual array access',
- { JERR_BUFFER_SIZE } 'Buffer passed to JPEG library is too small',
- { JERR_CANT_SUSPEND } 'Suspension not allowed here',
- { JERR_CCIR601_NOTIMPL } 'CCIR601 sampling not implemented yet',
- { JERR_COMPONENT_COUNT } 'Too many color components: %d, max %d',
- { JERR_CONVERSION_NOTIMPL } 'Unsupported color conversion request',
- { JERR_DAC_INDEX } 'Bogus DAC index %d',
- { JERR_DAC_VALUE } 'Bogus DAC value $%x',
- { JERR_DHT_COUNTS } 'Bogus DHT counts',
- { JERR_DHT_INDEX } 'Bogus DHT index %d',
- { JERR_DQT_INDEX } 'Bogus DQT index %d',
- { JERR_EMPTY_IMAGE } 'Empty JPEG image (DNL not supported)',
- { JERR_EMS_READ } 'Read from EMS failed',
- { JERR_EMS_WRITE } 'Write to EMS failed',
- { JERR_EOI_EXPECTED } 'Didn''t expect more than one scan',
- { JERR_FILE_READ } 'Input file read error',
- { JERR_FILE_WRITE } 'Output file write error --- out of disk space?',
- { JERR_FRACT_SAMPLE_NOTIMPL } 'Fractional sampling not implemented yet',
- { JERR_HUFF_CLEN_OVERFLOW } 'Huffman code size table overflow',
- { JERR_HUFF_MISSING_CODE } 'Missing Huffman code table entry',
- { JERR_IMAGE_TOO_BIG } 'Maximum supported image dimension is %d pixels',
- { JERR_INPUT_EMPTY } 'Empty input file',
- { JERR_INPUT_EOF } 'Premature end of input file',
- { JERR_MISMATCHED_QUANT_TABLE }
- 'Cannot transcode due to multiple use of quantization table %d',
- { JERR_MISSING_DATA } 'Scan script does not transmit all data',
- { JERR_MODE_CHANGE } 'Invalid color quantization mode change',
- { JERR_NOTIMPL } 'Not implemented yet',
- { JERR_NOT_COMPILED } 'Requested feature was omitted at compile time',
- { JERR_NO_BACKING_STORE } 'Backing store not supported',
- { JERR_NO_HUFF_TABLE } 'Huffman table $%02x was not defined',
- { JERR_NO_IMAGE } 'JPEG datastream contains no image',
- { JERR_NO_QUANT_TABLE } 'Quantization table $%02x was not defined',
- { JERR_NO_SOI } 'Not a JPEG file: starts with $%02x $%02x',
- { JERR_OUT_OF_MEMORY } 'Insufficient memory (case %d)',
- { JERR_QUANT_COMPONENTS }
- 'Cannot quantize more than %d color components',
- { JERR_QUANT_FEW_COLORS } 'Cannot quantize to fewer than %d colors',
- { JERR_QUANT_MANY_COLORS } 'Cannot quantize to more than %d colors',
- { JERR_SOF_DUPLICATE } 'Invalid JPEG file structure: two SOF markers',
- { JERR_SOF_NO_SOS } 'Invalid JPEG file structure: missing SOS marker',
- { JERR_SOF_UNSUPPORTED } 'Unsupported JPEG process: SOF type $%02x',
- { JERR_SOI_DUPLICATE } 'Invalid JPEG file structure: two SOI markers',
- { JERR_SOS_NO_SOF } 'Invalid JPEG file structure: SOS before SOF',
- { JERR_TFILE_CREATE } 'Failed to create temporary file %s',
- { JERR_TFILE_READ } 'Read failed on temporary file',
- { JERR_TFILE_SEEK } 'Seek failed on temporary file',
- { JERR_TFILE_WRITE }
- 'Write failed on temporary file --- out of disk space?',
- { JERR_TOO_LITTLE_DATA } 'Application transferred too few scanlines',
- { JERR_UNKNOWN_MARKER } 'Unsupported marker type $%02x',
- { JERR_VIRTUAL_BUG } 'Virtual array controller messed up',
- { JERR_WIDTH_OVERFLOW } 'Image too wide for this implementation',
- { JERR_XMS_READ } 'Read from XMS failed',
- { JERR_XMS_WRITE } 'Write to XMS failed',
- { JMSG_COPYRIGHT } JCOPYRIGHT,
- { JMSG_VERSION } JVERSION,
- { JTRC_16BIT_TABLES }
- 'Caution: quantization tables are too coarse for baseline JPEG',
- { JTRC_ADOBE }
- 'Adobe APP14 marker: version %d, flags $%04x $%04x, transform %d',
- { JTRC_APP0 } 'Unknown APP0 marker (not JFIF), length %d',
- { JTRC_APP14 } 'Unknown APP14 marker (not Adobe), length %d',
- { JTRC_DAC } 'Define Arithmetic Table $%02x: $%02x',
- { JTRC_DHT } 'Define Huffman Table $%02x',
- { JTRC_DQT } 'Define Quantization Table %d precision %d',
- { JTRC_DRI } 'Define Restart Interval %d',
- { JTRC_EMS_CLOSE } 'Freed EMS handle %d',
- { JTRC_EMS_OPEN } 'Obtained EMS handle %d',
- { JTRC_EOI } 'End Of Image',
- { JTRC_HUFFBITS } ' %3d %3d %3d %3d %3d %3d %3d %3d',
- { JTRC_JFIF } 'JFIF APP0 marker, density %dx%d %d',
- { JTRC_JFIF_BADTHUMBNAILSIZE }
- 'Warning: thumbnail image size does not match data length %d',
- { JTRC_JFIF_EXTENSION } 'JFIF extension marker: type 0x%02x, length %u',
- { JTRC_JFIF_THUMBNAIL } ' with %d x %d thumbnail image',
- { JTRC_MISC_MARKER } 'Skipping marker $%02x, length %d',
- { JTRC_PARMLESS_MARKER } 'Unexpected marker $%02x',
- { JTRC_QUANTVALS } ' %4d %4d %4d %4d %4d %4d %4d %4d',
- { JTRC_QUANT_3_NCOLORS } 'Quantizing to %d = %d*%d*%d colors',
- { JTRC_QUANT_NCOLORS } 'Quantizing to %d colors',
- { JTRC_QUANT_SELECTED } 'Selected %d colors for quantization',
- { JTRC_RECOVERY_ACTION } 'At marker $%02x, recovery action %d',
- { JTRC_RST } 'RST%d',
- { JTRC_SMOOTH_NOTIMPL }
- 'Smoothing not supported with nonstandard sampling ratios',
- { JTRC_SOF } 'Start Of Frame $%02x: width=%d, height=%d, components=%d',
- { JTRC_SOF_COMPONENT } ' Component %d: %dhx%dv q=%d',
- { JTRC_SOI } 'Start of Image',
- { JTRC_SOS } 'Start Of Scan: %d components',
- { JTRC_SOS_COMPONENT } ' Component %d: dc=%d ac=%d',
- { JTRC_SOS_PARAMS } ' Ss=%d, Se=%d, Ah=%d, Al=%d',
- { JTRC_TFILE_CLOSE } 'Closed temporary file %s',
- { JTRC_TFILE_OPEN } 'Opened temporary file %s',
- { JTRC_THUMB_JPEG }
- 'JFIF extension marker: JPEG-compressed thumbnail image, length %u',
- { JMESSAGE(JTRC_THUMB_PALETTE }
- 'JFIF extension marker: palette thumbnail image, length %u',
- { JMESSAGE(JTRC_THUMB_RGB }
- 'JFIF extension marker: RGB thumbnail image, length %u',
- { JTRC_UNKNOWN_IDS }
- 'Unrecognized component IDs %d %d %d, assuming YCbCr',
- { JTRC_XMS_CLOSE } 'Freed XMS handle %d',
- { JTRC_XMS_OPEN } 'Obtained XMS handle %d',
- { JWRN_ADOBE_XFORM } 'Unknown Adobe color transform code %d',
- { JWRN_BOGUS_PROGRESSION }
- 'Inconsistent progression sequence for component %d coefficient %d',
- { JWRN_EXTRANEOUS_DATA }
- 'Corrupt JPEG data: %d extraneous bytes before marker $%02x',
- { JWRN_HIT_MARKER } 'Corrupt JPEG data: premature end of data segment',
- { JWRN_HUFF_BAD_CODE } 'Corrupt JPEG data: bad Huffman code',
- { JWRN_JFIF_MAJOR } 'Warning: unknown JFIF revision number %d.%02d',
- { JWRN_JPEG_EOF } 'Premature end of JPEG file',
- { JWRN_MUST_RESYNC }
- 'Corrupt JPEG data: found marker $%02x instead of RST%d',
- { JWRN_NOT_SEQUENTIAL } 'Invalid SOS parameters for sequential JPEG',
- { JWRN_TOO_MUCH_DATA } 'Application transferred too many scanlines',
-
- { JMSG_FIRSTADDONCODE } '', { Must be first entry! }
-
-{$ifdef BMP_SUPPORTED}
- { JERR_BMP_BADCMAP } 'Unsupported BMP colormap format',
- { JERR_BMP_BADDEPTH } 'Only 8- and 24-bit BMP files are supported',
- { JERR_BMP_BADHEADER } 'Invalid BMP file: bad header length',
- { JERR_BMP_BADPLANES } 'Invalid BMP file: biPlanes not equal to 1',
- { JERR_BMP_COLORSPACE } 'BMP output must be grayscale or RGB',
- { JERR_BMP_COMPRESSED } 'Sorry, compressed BMPs not yet supported',
- { JERR_BMP_NOT } 'Not a BMP file - does not start with BM',
- { JTRC_BMP } '%dx%d 24-bit BMP image',
- { JTRC_BMP_MAPPED } '%dx%d 8-bit colormapped BMP image',
- { JTRC_BMP_OS2 } '%dx%d 24-bit OS2 BMP image',
- { JTRC_BMP_OS2_MAPPED } '%dx%d 8-bit colormapped OS2 BMP image',
-{$endif} { BMP_SUPPORTED }
-
-{$ifdef GIF_SUPPORTED}
- { JERR_GIF_BUG } 'GIF output got confused',
- { JERR_GIF_CODESIZE } 'Bogus GIF codesize %d',
- { JERR_GIF_COLORSPACE } 'GIF output must be grayscale or RGB',
- { JERR_GIF_IMAGENOTFOUND } 'Too few images in GIF file',
- { JERR_GIF_NOT } 'Not a GIF file',
- { JTRC_GIF } '%dx%dx%d GIF image',
- { JTRC_GIF_BADVERSION }
- 'Warning: unexpected GIF version number "%c%c%c"',
- { JTRC_GIF_EXTENSION } 'Ignoring GIF extension block of type 0x%02x',
- { JTRC_GIF_NONSQUARE } 'Caution: nonsquare pixels in input',
- { JWRN_GIF_BADDATA } 'Corrupt data in GIF file',
- { JWRN_GIF_CHAR } 'Bogus char 0x%02x in GIF file, ignoring',
- { JWRN_GIF_ENDCODE } 'Premature end of GIF image',
- { JWRN_GIF_NOMOREDATA } 'Ran out of GIF bits',
-{$endif} { GIF_SUPPORTED }
-
-{$ifdef PPM_SUPPORTED}
- { JERR_PPM_COLORSPACE } 'PPM output must be grayscale or RGB',
- { JERR_PPM_NONNUMERIC } 'Nonnumeric data in PPM file',
- { JERR_PPM_NOT } 'Not a PPM file',
- { JTRC_PGM } '%dx%d PGM image',
- { JTRC_PGM_TEXT } '%dx%d text PGM image',
- { JTRC_PPM } '%dx%d PPM image',
- { JTRC_PPM_TEXT } '%dx%d text PPM image',
-{$endif} { PPM_SUPPORTED }
-
-{$ifdef RLE_SUPPORTED}
- { JERR_RLE_BADERROR } 'Bogus error code from RLE library',
- { JERR_RLE_COLORSPACE } 'RLE output must be grayscale or RGB',
- { JERR_RLE_DIMENSIONS } 'Image dimensions (%dx%d) too large for RLE',
- { JERR_RLE_EMPTY } 'Empty RLE file',
- { JERR_RLE_EOF } 'Premature EOF in RLE header',
- { JERR_RLE_MEM } 'Insufficient memory for RLE header',
- { JERR_RLE_NOT } 'Not an RLE file',
- { JERR_RLE_TOOMANYCHANNELS } 'Cannot handle %d output channels for RLE',
- { JERR_RLE_UNSUPPORTED } 'Cannot handle this RLE setup',
- { JTRC_RLE } '%dx%d full-color RLE file',
- { JTRC_RLE_FULLMAP } '%dx%d full-color RLE file with map of length %d',
- { JTRC_RLE_GRAY } '%dx%d grayscale RLE file',
- { JTRC_RLE_MAPGRAY } '%dx%d grayscale RLE file with map of length %d',
- { JTRC_RLE_MAPPED } '%dx%d colormapped RLE file with map of length %d',
-{$endif} { RLE_SUPPORTED }
-
-{$ifdef TARGA_SUPPORTED}
- { JERR_TGA_BADCMAP } 'Unsupported Targa colormap format',
- { JERR_TGA_BADPARMS } 'Invalid or unsupported Targa file',
- { JERR_TGA_COLORSPACE } 'Targa output must be grayscale or RGB',
- { JTRC_TGA } '%dx%d RGB Targa image',
- { JTRC_TGA_GRAY } '%dx%d grayscale Targa image',
- { JTRC_TGA_MAPPED } '%dx%d colormapped Targa image',
-{$else}
- { JERR_TGA_NOTCOMP } 'Targa support was not compiled',
-{$endif} { TARGA_SUPPORTED }
-
- { JERR_BAD_CMAP_FILE }
- 'Color map file is invalid or of unsupported format',
- { JERR_TOO_MANY_COLORS }
- 'Output file format cannot handle %d colormap entries',
- { JERR_UNGETC_FAILED } 'ungetc failed',
-{$ifdef TARGA_SUPPORTED}
- { JERR_UNKNOWN_FORMAT }
- 'Unrecognized input file format --- perhaps you need -targa',
-{$else}
- { JERR_UNKNOWN_FORMAT } 'Unrecognized input file format',
-{$endif}
- { JERR_UNSUPPORTED_FORMAT } 'Unsupported output file format',
-
-
- { JMSG_LASTADDONCODE } '');
-
-implementation
-
-end.
diff --git a/packages/base/pasjpeg/jdhuff.pas b/packages/base/pasjpeg/jdhuff.pas
deleted file mode 100644
index 5001406d9e..0000000000
--- a/packages/base/pasjpeg/jdhuff.pas
+++ /dev/null
@@ -1,1204 +0,0 @@
-Unit JdHuff;
-
-{ This file contains declarations for Huffman entropy decoding routines
- that are shared between the sequential decoder (jdhuff.c) and the
- progressive decoder (jdphuff.c). No other modules need to see these. }
-
-{ This file contains Huffman entropy decoding routines.
-
- Much of the complexity here has to do with supporting input suspension.
- If the data source module demands suspension, we want to be able to back
- up to the start of the current MCU. To do this, we copy state variables
- into local working storage, and update them back to the permanent
- storage only upon successful completion of an MCU. }
-
-{ Original: jdhuff.h+jdhuff.c; Copyright (C) 1991-1997, Thomas G. Lane. }
-
-
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jutils,
- jpeglib;
-
-
-{ Declarations shared with jdphuff.c }
-
-
-
-{ Derived data constructed for each Huffman table }
-
-const
- HUFF_LOOKAHEAD = 8; { # of bits of lookahead }
-
-type
- d_derived_tbl_ptr = ^d_derived_tbl;
- d_derived_tbl = record
- { Basic tables: (element [0] of each array is unused) }
- maxcode : array[0..18-1] of INT32; { largest code of length k (-1 if none) }
- { (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) }
- valoffset : array[0..17-1] of INT32; { huffval[] offset for codes of length k }
- { valoffset[k] = huffval[] index of 1st symbol of code length k, less
- the smallest code of length k; so given a code of length k, the
- corresponding symbol is huffval[code + valoffset[k]] }
-
- { Link to public Huffman table (needed only in jpeg_huff_decode) }
- pub : JHUFF_TBL_PTR;
-
- { Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of
- the input data stream. If the next Huffman code is no more
- than HUFF_LOOKAHEAD bits long, we can obtain its length and
- the corresponding symbol directly from these tables. }
-
- look_nbits : array[0..(1 shl HUFF_LOOKAHEAD)-1] of int;
- { # bits, or 0 if too long }
- look_sym : array[0..(1 shl HUFF_LOOKAHEAD)-1] of UINT8;
- { symbol, or unused }
- end;
-
-{ Fetching the next N bits from the input stream is a time-critical operation
- for the Huffman decoders. We implement it with a combination of inline
- macros and out-of-line subroutines. Note that N (the number of bits
- demanded at one time) never exceeds 15 for JPEG use.
-
- We read source bytes into get_buffer and dole out bits as needed.
- If get_buffer already contains enough bits, they are fetched in-line
- by the macros CHECK_BIT_BUFFER and GET_BITS. When there aren't enough
- bits, jpeg_fill_bit_buffer is called; it will attempt to fill get_buffer
- as full as possible (not just to the number of bits needed; this
- prefetching reduces the overhead cost of calling jpeg_fill_bit_buffer).
- Note that jpeg_fill_bit_buffer may return FALSE to indicate suspension.
- On TRUE return, jpeg_fill_bit_buffer guarantees that get_buffer contains
- at least the requested number of bits --- dummy zeroes are inserted if
- necessary. }
-
-
-type
- bit_buf_type = INT32 ; { type of bit-extraction buffer }
-const
- BIT_BUF_SIZE = 32; { size of buffer in bits }
-
-{ If long is > 32 bits on your machine, and shifting/masking longs is
- reasonably fast, making bit_buf_type be long and setting BIT_BUF_SIZE
- appropriately should be a win. Unfortunately we can't define the size
- with something like #define BIT_BUF_SIZE (sizeof(bit_buf_type)*8)
- because not all machines measure sizeof in 8-bit bytes. }
-
-type
- bitread_perm_state = record { Bitreading state saved across MCUs }
- get_buffer : bit_buf_type; { current bit-extraction buffer }
- bits_left : int; { # of unused bits in it }
- end;
-
-type
- bitread_working_state = record
- { Bitreading working state within an MCU }
- { current data source location }
- { We need a copy, rather than munging the original, in case of suspension }
- next_input_byte : JOCTETptr; { => next byte to read from source }
- bytes_in_buffer : size_t; { # of bytes remaining in source buffer }
- { Bit input buffer --- note these values are kept in register variables,
- not in this struct, inside the inner loops. }
-
- get_buffer : bit_buf_type; { current bit-extraction buffer }
- bits_left : int; { # of unused bits in it }
- { Pointer needed by jpeg_fill_bit_buffer }
- cinfo : j_decompress_ptr; { back link to decompress master record }
- end;
-
-{ Module initialization routine for Huffman entropy decoding. }
-
-{GLOBAL}
-procedure jinit_huff_decoder (cinfo : j_decompress_ptr);
-
-{GLOBAL}
-function jpeg_huff_decode(var state : bitread_working_state;
- get_buffer : bit_buf_type; {register}
- bits_left : int; {register}
- htbl : d_derived_tbl_ptr;
- min_bits : int) : int;
-
-{ Compute the derived values for a Huffman table.
- Note this is also used by jdphuff.c. }
-
-{GLOBAL}
-procedure jpeg_make_d_derived_tbl (cinfo : j_decompress_ptr;
- isDC : boolean;
- tblno : int;
- var pdtbl : d_derived_tbl_ptr);
-
-{ Load up the bit buffer to a depth of at least nbits }
-
-function jpeg_fill_bit_buffer (var state : bitread_working_state;
- get_buffer : bit_buf_type; {register}
- bits_left : int; {register}
- nbits : int) : boolean;
-
-implementation
-
-{$IFDEF MACRO}
-
-{ Macros to declare and load/save bitread local variables. }
-{$define BITREAD_STATE_VARS}
- get_buffer : bit_buf_type ; {register}
- bits_left : int; {register}
- br_state : bitread_working_state;
-
-{$define BITREAD_LOAD_STATE(cinfop,permstate)}
- br_state.cinfo := cinfop;
- br_state.next_input_byte := cinfop^.src^.next_input_byte;
- br_state.bytes_in_buffer := cinfop^.src^.bytes_in_buffer;
- get_buffer := permstate.get_buffer;
- bits_left := permstate.bits_left;
-
-{$define BITREAD_SAVE_STATE(cinfop,permstate) }
- cinfop^.src^.next_input_byte := br_state.next_input_byte;
- cinfop^.src^.bytes_in_buffer := br_state.bytes_in_buffer;
- permstate.get_buffer := get_buffer;
- permstate.bits_left := bits_left;
-
-
-{ These macros provide the in-line portion of bit fetching.
- Use CHECK_BIT_BUFFER to ensure there are N bits in get_buffer
- before using GET_BITS, PEEK_BITS, or DROP_BITS.
- The variables get_buffer and bits_left are assumed to be locals,
- but the state struct might not be (jpeg_huff_decode needs this).
- CHECK_BIT_BUFFER(state,n,action);
- Ensure there are N bits in get_buffer; if suspend, take action.
- val = GET_BITS(n);
- Fetch next N bits.
- val = PEEK_BITS(n);
- Fetch next N bits without removing them from the buffer.
- DROP_BITS(n);
- Discard next N bits.
- The value N should be a simple variable, not an expression, because it
- is evaluated multiple times. }
-
-
-{$define CHECK_BIT_BUFFER(state,nbits,action)}
- if (bits_left < (nbits)) then
- begin
- if (not jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) then
- begin
- action;
- exit;
- end;
- get_buffer := state.get_buffer;
- bits_left := state.bits_left;
- end;
-
-
-{$define GET_BITS(nbits)}
- Dec(bits_left, (nbits));
- ( (int(get_buffer shr bits_left)) and ( pred(1 shl (nbits)) ) )
-
-{$define PEEK_BITS(nbits)}
- int(get_buffer shr (bits_left - (nbits))) and pred(1 shl (nbits))
-
-{$define DROP_BITS(nbits)}
- Dec(bits_left, nbits);
-
-
-
-
-{ Code for extracting next Huffman-coded symbol from input bit stream.
- Again, this is time-critical and we make the main paths be macros.
-
- We use a lookahead table to process codes of up to HUFF_LOOKAHEAD bits
- without looping. Usually, more than 95% of the Huffman codes will be 8
- or fewer bits long. The few overlength codes are handled with a loop,
- which need not be inline code.
-
- Notes about the HUFF_DECODE macro:
- 1. Near the end of the data segment, we may fail to get enough bits
- for a lookahead. In that case, we do it the hard way.
- 2. If the lookahead table contains no entry, the next code must be
- more than HUFF_LOOKAHEAD bits long.
- 3. jpeg_huff_decode returns -1 if forced to suspend. }
-
-
-
-
-macro HUFF_DECODE(s,br_state,htbl,return FALSE,slowlabel);
-label showlabel;
-var
- nb, look : int; {register}
-begin
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) then
- begin
- decode_mcu := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- nb := 1;
- goto slowlabel;
- end;
- end;
- {look := PEEK_BITS(HUFF_LOOKAHEAD);}
- look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
- pred(1 shl HUFF_LOOKAHEAD);
-
- nb := htbl^.look_nbits[look];
- if (nb <> 0) then
- begin
- {DROP_BITS(nb);}
- Dec(bits_left, nb);
-
- s := htbl^.look_sym[look];
- end
- else
- begin
- nb := HUFF_LOOKAHEAD+1;
-slowlabel:
- s := jpeg_huff_decode(br_state,get_buffer,bits_left,htbl,nb));
- if (s < 0) then
- begin
- result := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-end;
-
-
-{$ENDIF} {MACRO}
-
-{ Expanded entropy decoder object for Huffman decoding.
-
- The savable_state subrecord contains fields that change within an MCU,
- but must not be updated permanently until we complete the MCU. }
-
-type
- savable_state = record
- last_dc_val : array[0..MAX_COMPS_IN_SCAN-1] of int; { last DC coef for each component }
- end;
-
-
-type
- huff_entropy_ptr = ^huff_entropy_decoder;
- huff_entropy_decoder = record
- pub : jpeg_entropy_decoder; { public fields }
-
- { These fields are loaded into local variables at start of each MCU.
- In case of suspension, we exit WITHOUT updating them. }
-
- bitstate : bitread_perm_state; { Bit buffer at start of MCU }
- saved : savable_state; { Other state at start of MCU }
-
- { These fields are NOT loaded into local working state. }
- restarts_to_go : uInt; { MCUs left in this restart interval }
-
- { Pointers to derived tables (these workspaces have image lifespan) }
- dc_derived_tbls : array[0..NUM_HUFF_TBLS] of d_derived_tbl_ptr;
- ac_derived_tbls : array[0..NUM_HUFF_TBLS] of d_derived_tbl_ptr;
-
- { Precalculated info set up by start_pass for use in decode_mcu: }
-
- { Pointers to derived tables to be used for each block within an MCU }
- dc_cur_tbls : array[0..D_MAX_BLOCKS_IN_MCU-1] of d_derived_tbl_ptr;
- ac_cur_tbls : array[0..D_MAX_BLOCKS_IN_MCU-1] of d_derived_tbl_ptr;
- { Whether we care about the DC and AC coefficient values for each block }
- dc_needed : array[0..D_MAX_BLOCKS_IN_MCU-1] of boolean;
- ac_needed : array[0..D_MAX_BLOCKS_IN_MCU-1] of boolean;
- end;
-
-
-
-{ Initialize for a Huffman-compressed scan. }
-
-{METHODDEF}
-procedure start_pass_huff_decoder (cinfo : j_decompress_ptr); far;
-var
- entropy : huff_entropy_ptr;
- ci, blkn, dctbl, actbl : int;
- compptr : jpeg_component_info_ptr;
-begin
- entropy := huff_entropy_ptr (cinfo^.entropy);
-
- { Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
- This ought to be an error condition, but we make it a warning because
- there are some baseline files out there with all zeroes in these bytes. }
-
- if (cinfo^.Ss <> 0) or (cinfo^.Se <> DCTSIZE2-1) or
- (cinfo^.Ah <> 0) or (cinfo^.Al <> 0) then
- WARNMS(j_common_ptr(cinfo), JWRN_NOT_SEQUENTIAL);
-
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- dctbl := compptr^.dc_tbl_no;
- actbl := compptr^.ac_tbl_no;
- { Compute derived values for Huffman tables }
- { We may do this more than once for a table, but it's not expensive }
- jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
- entropy^.dc_derived_tbls[dctbl]);
- jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
- entropy^.ac_derived_tbls[actbl]);
- { Initialize DC predictions to 0 }
- entropy^.saved.last_dc_val[ci] := 0;
- end;
-
- { Precalculate decoding info for each block in an MCU of this scan }
- for blkn := 0 to pred(cinfo^.blocks_in_MCU) do
- begin
- ci := cinfo^.MCU_membership[blkn];
- compptr := cinfo^.cur_comp_info[ci];
- { Precalculate which table to use for each block }
- entropy^.dc_cur_tbls[blkn] := entropy^.dc_derived_tbls[compptr^.dc_tbl_no];
- entropy^.ac_cur_tbls[blkn] := entropy^.ac_derived_tbls[compptr^.ac_tbl_no];
- { Decide whether we really care about the coefficient values }
- if (compptr^.component_needed) then
- begin
- entropy^.dc_needed[blkn] := TRUE;
- { we don't need the ACs if producing a 1/8th-size image }
- entropy^.ac_needed[blkn] := (compptr^.DCT_scaled_size > 1);
- end
- else
- begin
- entropy^.ac_needed[blkn] := FALSE;
- entropy^.dc_needed[blkn] := FALSE;
- end;
- end;
-
- { Initialize bitread state variables }
- entropy^.bitstate.bits_left := 0;
- entropy^.bitstate.get_buffer := 0; { unnecessary, but keeps Purify quiet }
- entropy^.pub.insufficient_data := FALSE;
-
- { Initialize restart counter }
- entropy^.restarts_to_go := cinfo^.restart_interval;
-end;
-
-
-{ Compute the derived values for a Huffman table.
- This routine also performs some validation checks on the table.
-
- Note this is also used by jdphuff.c. }
-
-{GLOBAL}
-procedure jpeg_make_d_derived_tbl (cinfo : j_decompress_ptr;
- isDC : boolean;
- tblno : int;
- var pdtbl : d_derived_tbl_ptr);
-var
- htbl : JHUFF_TBL_PTR;
- dtbl : d_derived_tbl_ptr;
- p, i, l, si, numsymbols : int;
- lookbits, ctr : int;
- huffsize : array[0..257-1] of byte;
- huffcode : array[0..257-1] of uInt;
- code : uInt;
-var
- sym : int;
-begin
- { Note that huffsize[] and huffcode[] are filled in code-length order,
- paralleling the order of the symbols themselves in htbl^.huffval[]. }
-
- { Find the input Huffman table }
- if (tblno < 0) or (tblno >= NUM_HUFF_TBLS) then
- ERREXIT1(j_common_ptr(cinfo), JERR_NO_HUFF_TABLE, tblno);
- if isDC then
- htbl := cinfo^.dc_huff_tbl_ptrs[tblno]
- else
- htbl := cinfo^.ac_huff_tbl_ptrs[tblno];
- if (htbl = NIL) then
- ERREXIT1(j_common_ptr(cinfo), JERR_NO_HUFF_TABLE, tblno);
-
- { Allocate a workspace if we haven't already done so. }
- if (pdtbl = NIL) then
- pdtbl := d_derived_tbl_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(d_derived_tbl)) );
- dtbl := pdtbl;
- dtbl^.pub := htbl; { fill in back link }
-
- { Figure C.1: make table of Huffman code length for each symbol }
-
- p := 0;
- for l := 1 to 16 do
- begin
- i := int(htbl^.bits[l]);
- if (i < 0) or (p + i > 256) then { protect against table overrun }
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_HUFF_TABLE);
- while (i > 0) do
- begin
- huffsize[p] := byte(l);
- Inc(p);
- Dec(i);
- end;
- end;
- huffsize[p] := 0;
- numsymbols := p;
-
- { Figure C.2: generate the codes themselves }
- { We also validate that the counts represent a legal Huffman code tree. }
-
- code := 0;
- si := huffsize[0];
- p := 0;
- while (huffsize[p] <> 0) do
- begin
- while (( int (huffsize[p]) ) = si) do
- begin
- huffcode[p] := code;
- Inc(p);
- Inc(code);
- end;
- { code is now 1 more than the last code used for codelength si; but
- it must still fit in si bits, since no code is allowed to be all ones. }
-
- if (INT32(code) >= (INT32(1) shl si)) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_HUFF_TABLE);
-
- code := code shl 1;
- Inc(si);
- end;
-
- { Figure F.15: generate decoding tables for bit-sequential decoding }
-
- p := 0;
- for l := 1 to 16 do
- begin
- if (htbl^.bits[l] <> 0) then
- begin
- { valoffset[l] = huffval[] index of 1st symbol of code length l,
- minus the minimum code of length l }
-
- dtbl^.valoffset[l] := INT32(p) - INT32(huffcode[p]);
- Inc(p, htbl^.bits[l]);
- dtbl^.maxcode[l] := huffcode[p-1]; { maximum code of length l }
- end
- else
- begin
- dtbl^.maxcode[l] := -1; { -1 if no codes of this length }
- end;
- end;
- dtbl^.maxcode[17] := long($FFFFF); { ensures jpeg_huff_decode terminates }
-
- { Compute lookahead tables to speed up decoding.
- First we set all the table entries to 0, indicating "too long";
- then we iterate through the Huffman codes that are short enough and
- fill in all the entries that correspond to bit sequences starting
- with that code. }
-
- MEMZERO(@dtbl^.look_nbits, SIZEOF(dtbl^.look_nbits));
-
- p := 0;
- for l := 1 to HUFF_LOOKAHEAD do
- begin
- for i := 1 to int (htbl^.bits[l]) do
- begin
- { l := current code's length, p := its index in huffcode[] & huffval[]. }
- { Generate left-justified code followed by all possible bit sequences }
- lookbits := huffcode[p] shl (HUFF_LOOKAHEAD-l);
- for ctr := pred(1 shl (HUFF_LOOKAHEAD-l)) downto 0 do
- begin
- dtbl^.look_nbits[lookbits] := l;
- dtbl^.look_sym[lookbits] := htbl^.huffval[p];
- Inc(lookbits);
- end;
- Inc(p);
- end;
- end;
-
- { Validate symbols as being reasonable.
- For AC tables, we make no check, but accept all byte values 0..255.
- For DC tables, we require the symbols to be in range 0..15.
- (Tighter bounds could be applied depending on the data depth and mode,
- but this is sufficient to ensure safe decoding.) }
-
- if (isDC) then
- begin
- for i := 0 to pred(numsymbols) do
- begin
- sym := htbl^.huffval[i];
- if (sym < 0) or (sym > 15) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_HUFF_TABLE);
- end;
- end;
-end;
-
-
-{ Out-of-line code for bit fetching (shared with jdphuff.c).
- See jdhuff.h for info about usage.
- Note: current values of get_buffer and bits_left are passed as parameters,
- but are returned in the corresponding fields of the state struct.
-
- On most machines MIN_GET_BITS should be 25 to allow the full 32-bit width
- of get_buffer to be used. (On machines with wider words, an even larger
- buffer could be used.) However, on some machines 32-bit shifts are
- quite slow and take time proportional to the number of places shifted.
- (This is true with most PC compilers, for instance.) In this case it may
- be a win to set MIN_GET_BITS to the minimum value of 15. This reduces the
- average shift distance at the cost of more calls to jpeg_fill_bit_buffer. }
-
-{$ifdef SLOW_SHIFT_32}
-const
- MIN_GET_BITS = 15; { minimum allowable value }
-{$else}
-const
- MIN_GET_BITS = (BIT_BUF_SIZE-7);
-{$endif}
-
-
-{GLOBAL}
-function jpeg_fill_bit_buffer (var state : bitread_working_state;
- {register} get_buffer : bit_buf_type;
- {register} bits_left : int;
- nbits : int) : boolean;
-label
- no_more_bytes;
-{ Load up the bit buffer to a depth of at least nbits }
-var
- { Copy heavily used state fields into locals (hopefully registers) }
- {register} next_input_byte : {const} JOCTETptr;
- {register} bytes_in_buffer : size_t;
-var
- {register} c : int;
-var
- cinfo : j_decompress_ptr;
-begin
- next_input_byte := state.next_input_byte;
- bytes_in_buffer := state.bytes_in_buffer;
- cinfo := state.cinfo;
-
- { Attempt to load at least MIN_GET_BITS bits into get_buffer. }
- { (It is assumed that no request will be for more than that many bits.) }
- { We fail to do so only if we hit a marker or are forced to suspend. }
-
- if (cinfo^.unread_marker = 0) then { cannot advance past a marker }
- begin
- while (bits_left < MIN_GET_BITS) do
- begin
- { Attempt to read a byte }
- if (bytes_in_buffer = 0) then
- begin
- if not cinfo^.src^.fill_input_buffer(cinfo) then
- begin
- jpeg_fill_bit_buffer := FALSE;
- exit;
- end;
- next_input_byte := cinfo^.src^.next_input_byte;
- bytes_in_buffer := cinfo^.src^.bytes_in_buffer;
- end;
- Dec(bytes_in_buffer);
- c := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
-
- { If it's $FF, check and discard stuffed zero byte }
- if (c = $FF) then
- begin
- { Loop here to discard any padding FF's on terminating marker,
- so that we can save a valid unread_marker value. NOTE: we will
- accept multiple FF's followed by a 0 as meaning a single FF data
- byte. This data pattern is not valid according to the standard. }
-
- repeat
- if (bytes_in_buffer = 0) then
- begin
- if (not state.cinfo^.src^.fill_input_buffer (state.cinfo)) then
- begin
- jpeg_fill_bit_buffer := FALSE;
- exit;
- end;
- next_input_byte := state.cinfo^.src^.next_input_byte;
- bytes_in_buffer := state.cinfo^.src^.bytes_in_buffer;
- end;
- Dec(bytes_in_buffer);
- c := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
- Until (c <> $FF);
-
- if (c = 0) then
- begin
- { Found FF/00, which represents an FF data byte }
- c := $FF;
- end
- else
- begin
- { Oops, it's actually a marker indicating end of compressed data.
- Save the marker code for later use.
- Fine point: it might appear that we should save the marker into
- bitread working state, not straight into permanent state. But
- once we have hit a marker, we cannot need to suspend within the
- current MCU, because we will read no more bytes from the data
- source. So it is OK to update permanent state right away. }
-
- cinfo^.unread_marker := c;
- { See if we need to insert some fake zero bits. }
- goto no_more_bytes;
- end;
- end;
-
- { OK, load c into get_buffer }
- get_buffer := (get_buffer shl 8) or c;
- Inc(bits_left, 8);
- end { end while }
- end
- else
- begin
- no_more_bytes:
- { We get here if we've read the marker that terminates the compressed
- data segment. There should be enough bits in the buffer register
- to satisfy the request; if so, no problem. }
-
- if (nbits > bits_left) then
- begin
- { Uh-oh. Report corrupted data to user and stuff zeroes into
- the data stream, so that we can produce some kind of image.
- We use a nonvolatile flag to ensure that only one warning message
- appears per data segment. }
-
- if not cinfo^.entropy^.insufficient_data then
- begin
- WARNMS(j_common_ptr(cinfo), JWRN_HIT_MARKER);
- cinfo^.entropy^.insufficient_data := TRUE;
- end;
- { Fill the buffer with zero bits }
- get_buffer := get_buffer shl (MIN_GET_BITS - bits_left);
- bits_left := MIN_GET_BITS;
- end;
- end;
-
- { Unload the local registers }
- state.next_input_byte := next_input_byte;
- state.bytes_in_buffer := bytes_in_buffer;
- state.get_buffer := get_buffer;
- state.bits_left := bits_left;
-
- jpeg_fill_bit_buffer := TRUE;
-end;
-
-
-{ Out-of-line code for Huffman code decoding.
- See jdhuff.h for info about usage. }
-
-{GLOBAL}
-function jpeg_huff_decode (var state : bitread_working_state;
- {register} get_buffer : bit_buf_type;
- {register} bits_left : int;
- htbl : d_derived_tbl_ptr;
- min_bits : int) : int;
-var
- {register} l : int;
- {register} code : INT32;
-begin
- l := min_bits;
-
- { HUFF_DECODE has determined that the code is at least min_bits }
- { bits long, so fetch that many bits in one swoop. }
-
- {CHECK_BIT_BUFFER(state, l, return -1);}
- if (bits_left < l) then
- begin
- if (not jpeg_fill_bit_buffer(state, get_buffer, bits_left, l)) then
- begin
- jpeg_huff_decode := -1;
- exit;
- end;
- get_buffer := state.get_buffer;
- bits_left := state.bits_left;
- end;
-
- {code := GET_BITS(l);}
- Dec(bits_left, l);
- code := (int(get_buffer shr bits_left)) and ( pred(1 shl l) );
-
- { Collect the rest of the Huffman code one bit at a time. }
- { This is per Figure F.16 in the JPEG spec. }
-
- while (code > htbl^.maxcode[l]) do
- begin
- code := code shl 1;
- {CHECK_BIT_BUFFER(state, 1, return -1);}
- if (bits_left < 1) then
- begin
- if (not jpeg_fill_bit_buffer(state, get_buffer, bits_left, 1)) then
- begin
- jpeg_huff_decode := -1;
- exit;
- end;
- get_buffer := state.get_buffer;
- bits_left := state.bits_left;
- end;
-
- {code := code or GET_BITS(1);}
- Dec(bits_left);
- code := code or ( (int(get_buffer shr bits_left)) and pred(1 shl 1) );
-
- Inc(l);
- end;
-
- { Unload the local registers }
- state.get_buffer := get_buffer;
- state.bits_left := bits_left;
-
- { With garbage input we may reach the sentinel value l := 17. }
-
- if (l > 16) then
- begin
- WARNMS(j_common_ptr(state.cinfo), JWRN_HUFF_BAD_CODE);
- jpeg_huff_decode := 0; { fake a zero as the safest result }
- exit;
- end;
-
- jpeg_huff_decode := htbl^.pub^.huffval[ int (code + htbl^.valoffset[l]) ];
-end;
-
-
-{ Figure F.12: extend sign bit.
- On some machines, a shift and add will be faster than a table lookup. }
-
-{$ifdef AVOID_TABLES}
-
-#define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
-
-{$else}
-
-{$define HUFF_EXTEND(x,s)
- if (x < extend_test[s]) then
- := x + extend_offset[s]
- else
- x;}
-
-const
- extend_test : array[0..16-1] of int = { entry n is 2**(n-1) }
- ($0000, $0001, $0002, $0004, $0008, $0010, $0020, $0040,
- $0080, $0100, $0200, $0400, $0800, $1000, $2000, $4000);
-
-const
- extend_offset : array[0..16-1] of int = { entry n is (-1 << n) + 1 }
-(0, ((-1) shl 1) + 1, ((-1) shl 2) + 1, ((-1) shl 3) + 1, ((-1) shl 4) + 1,
- ((-1) shl 5) + 1, ((-1) shl 6) + 1, ((-1) shl 7) + 1, ((-1) shl 8) + 1,
- ((-1) shl 9) + 1, ((-1) shl 10) + 1, ((-1) shl 11) + 1,((-1) shl 12) + 1,
- ((-1) shl 13) + 1, ((-1) shl 14) + 1, ((-1) shl 15) + 1);
-
-{$endif} { AVOID_TABLES }
-
-
-{ Check for a restart marker & resynchronize decoder.
- Returns FALSE if must suspend. }
-
-{LOCAL}
-function process_restart (cinfo : j_decompress_ptr) : boolean;
-var
- entropy : huff_entropy_ptr;
- ci : int;
-begin
- entropy := huff_entropy_ptr (cinfo^.entropy);
-
- { Throw away any unused bits remaining in bit buffer; }
- { include any full bytes in next_marker's count of discarded bytes }
- Inc(cinfo^.marker^.discarded_bytes, entropy^.bitstate.bits_left div 8);
- entropy^.bitstate.bits_left := 0;
-
- { Advance past the RSTn marker }
- if (not cinfo^.marker^.read_restart_marker (cinfo)) then
- begin
- process_restart := FALSE;
- exit;
- end;
-
- { Re-initialize DC predictions to 0 }
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- entropy^.saved.last_dc_val[ci] := 0;
-
- { Reset restart counter }
- entropy^.restarts_to_go := cinfo^.restart_interval;
-
- { Reset out-of-data flag, unless read_restart_marker left us smack up
- against a marker. In that case we will end up treating the next data
- segment as empty, and we can avoid producing bogus output pixels by
- leaving the flag set. }
-
- if (cinfo^.unread_marker = 0) then
- entropy^.pub.insufficient_data := FALSE;
-
- process_restart := TRUE;
-end;
-
-
-{ Decode and return one MCU's worth of Huffman-compressed coefficients.
- The coefficients are reordered from zigzag order into natural array order,
- but are not dequantized.
-
- The i'th block of the MCU is stored into the block pointed to by
- MCU_data[i]. WE ASSUME THIS AREA HAS BEEN ZEROED BY THE CALLER.
- (Wholesale zeroing is usually a little faster than retail...)
-
- Returns FALSE if data source requested suspension. In that case no
- changes have been made to permanent state. (Exception: some output
- coefficients may already have been assigned. This is harmless for
- this module, since we'll just re-assign them on the next call.) }
-
-{METHODDEF}
-function decode_mcu (cinfo : j_decompress_ptr;
- var MCU_data : array of JBLOCKROW) : boolean; far;
-label
- label1, label2, label3;
-var
- entropy : huff_entropy_ptr;
- {register} s, k, r : int;
- blkn, ci : int;
- block : JBLOCK_PTR;
- {BITREAD_STATE_VARS}
- get_buffer : bit_buf_type ; {register}
- bits_left : int; {register}
- br_state : bitread_working_state;
-
- state : savable_state;
- dctbl : d_derived_tbl_ptr;
- actbl : d_derived_tbl_ptr;
-var
- nb, look : int; {register}
-begin
- entropy := huff_entropy_ptr (cinfo^.entropy);
-
- { Process restart marker if needed; may have to suspend }
- if (cinfo^.restart_interval <> 0) then
- begin
- if (entropy^.restarts_to_go = 0) then
- if (not process_restart(cinfo)) then
- begin
- decode_mcu := FALSE;
- exit;
- end;
- end;
-
- { If we've run out of data, just leave the MCU set to zeroes.
- This way, we return uniform gray for the remainder of the segment. }
-
- if not entropy^.pub.insufficient_data then
- begin
-
- { Load up working state }
- {BITREAD_LOAD_STATE(cinfo,entropy^.bitstate);}
- br_state.cinfo := cinfo;
- br_state.next_input_byte := cinfo^.src^.next_input_byte;
- br_state.bytes_in_buffer := cinfo^.src^.bytes_in_buffer;
- get_buffer := entropy^.bitstate.get_buffer;
- bits_left := entropy^.bitstate.bits_left;
-
- {ASSIGN_STATE(state, entropy^.saved);}
- state := entropy^.saved;
-
- { Outer loop handles each block in the MCU }
-
- for blkn := 0 to pred(cinfo^.blocks_in_MCU) do
- begin
- block := JBLOCK_PTR(MCU_data[blkn]);
- dctbl := entropy^.dc_cur_tbls[blkn];
- actbl := entropy^.ac_cur_tbls[blkn];
-
- { Decode a single block's worth of coefficients }
-
- { Section F.2.2.1: decode the DC coefficient difference }
- {HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);}
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) then
- begin
- decode_mcu := False;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- nb := 1;
- goto label1;
- end;
- end;
- {look := PEEK_BITS(HUFF_LOOKAHEAD);}
- look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
- pred(1 shl HUFF_LOOKAHEAD);
-
- nb := dctbl^.look_nbits[look];
- if (nb <> 0) then
- begin
- {DROP_BITS(nb);}
- Dec(bits_left, nb);
-
- s := dctbl^.look_sym[look];
- end
- else
- begin
- nb := HUFF_LOOKAHEAD+1;
- label1:
- s := jpeg_huff_decode(br_state,get_buffer,bits_left,dctbl,nb);
- if (s < 0) then
- begin
- decode_mcu := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- if (s <> 0) then
- begin
- {CHECK_BIT_BUFFER(br_state, s, return FALSE);}
- if (bits_left < s) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) then
- begin
- decode_mcu := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- {r := GET_BITS(s);}
- Dec(bits_left, s);
- r := ( int(get_buffer shr bits_left)) and ( pred(1 shl s) );
-
- {s := HUFF_EXTEND(r, s);}
- if (r < extend_test[s]) then
- s := r + extend_offset[s]
- else
- s := r;
- end;
-
- if (entropy^.dc_needed[blkn]) then
- begin
- { Convert DC difference to actual value, update last_dc_val }
- ci := cinfo^.MCU_membership[blkn];
- Inc(s, state.last_dc_val[ci]);
- state.last_dc_val[ci] := s;
- { Output the DC coefficient (assumes jpeg_natural_order[0] := 0) }
- block^[0] := JCOEF (s);
- end;
-
- if (entropy^.ac_needed[blkn]) then
- begin
-
- { Section F.2.2.2: decode the AC coefficients }
- { Since zeroes are skipped, output area must be cleared beforehand }
- k := 1;
- while (k < DCTSIZE2) do { Nomssi: k is incr. in the loop }
- begin
- {HUFF_DECODE(s, br_state, actbl, return FALSE, label2);}
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) then
- begin
- decode_mcu := False;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- nb := 1;
- goto label2;
- end;
- end;
- {look := PEEK_BITS(HUFF_LOOKAHEAD);}
- look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
- pred(1 shl HUFF_LOOKAHEAD);
-
- nb := actbl^.look_nbits[look];
- if (nb <> 0) then
- begin
- {DROP_BITS(nb);}
- Dec(bits_left, nb);
-
- s := actbl^.look_sym[look];
- end
- else
- begin
- nb := HUFF_LOOKAHEAD+1;
- label2:
- s := jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb);
- if (s < 0) then
- begin
- decode_mcu := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- r := s shr 4;
- s := s and 15;
-
- if (s <> 0) then
- begin
- Inc(k, r);
- {CHECK_BIT_BUFFER(br_state, s, return FALSE);}
- if (bits_left < s) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) then
- begin
- decode_mcu := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- {r := GET_BITS(s);}
- Dec(bits_left, s);
- r := (int(get_buffer shr bits_left)) and ( pred(1 shl s) );
-
- {s := HUFF_EXTEND(r, s);}
- if (r < extend_test[s]) then
- s := r + extend_offset[s]
- else
- s := r;
- { Output coefficient in natural (dezigzagged) order.
- Note: the extra entries in jpeg_natural_order[] will save us
- if k >= DCTSIZE2, which could happen if the data is corrupted. }
-
- block^[jpeg_natural_order[k]] := JCOEF (s);
- end
- else
- begin
- if (r <> 15) then
- break;
- Inc(k, 15);
- end;
- Inc(k);
- end;
- end
- else
- begin
-
- { Section F.2.2.2: decode the AC coefficients }
- { In this path we just discard the values }
- k := 1;
- while (k < DCTSIZE2) do
- begin
- {HUFF_DECODE(s, br_state, actbl, return FALSE, label3);}
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) then
- begin
- decode_mcu := False;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- nb := 1;
- goto label3;
- end;
- end;
- {look := PEEK_BITS(HUFF_LOOKAHEAD);}
- look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
- pred(1 shl HUFF_LOOKAHEAD);
-
- nb := actbl^.look_nbits[look];
- if (nb <> 0) then
- begin
- {DROP_BITS(nb);}
- Dec(bits_left, nb);
-
- s := actbl^.look_sym[look];
- end
- else
- begin
- nb := HUFF_LOOKAHEAD+1;
- label3:
- s := jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb);
- if (s < 0) then
- begin
- decode_mcu := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- r := s shr 4;
- s := s and 15;
-
- if (s <> 0) then
- begin
- Inc(k, r);
- {CHECK_BIT_BUFFER(br_state, s, return FALSE);}
- if (bits_left < s) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) then
- begin
- decode_mcu := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- {DROP_BITS(s);}
- Dec(bits_left, s);
- end
- else
- begin
- if (r <> 15) then
- break;
- Inc(k, 15);
- end;
- Inc(k);
- end;
-
- end;
- end;
-
- { Completed MCU, so update state }
- {BITREAD_SAVE_STATE(cinfo,entropy^.bitstate);}
- cinfo^.src^.next_input_byte := br_state.next_input_byte;
- cinfo^.src^.bytes_in_buffer := br_state.bytes_in_buffer;
- entropy^.bitstate.get_buffer := get_buffer;
- entropy^.bitstate.bits_left := bits_left;
-
- {ASSIGN_STATE(entropy^.saved, state);}
- entropy^.saved := state;
-
- end;
-
- { Account for restart interval (no-op if not using restarts) }
- Dec(entropy^.restarts_to_go);
-
- decode_mcu := TRUE;
-end;
-
-
-{ Module initialization routine for Huffman entropy decoding. }
-
-{GLOBAL}
-procedure jinit_huff_decoder (cinfo : j_decompress_ptr);
-var
- entropy : huff_entropy_ptr;
- i : int;
-begin
- entropy := huff_entropy_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(huff_entropy_decoder)) );
- cinfo^.entropy := jpeg_entropy_decoder_ptr (entropy);
- entropy^.pub.start_pass := start_pass_huff_decoder;
- entropy^.pub.decode_mcu := decode_mcu;
-
- { Mark tables unallocated }
- for i := 0 to pred(NUM_HUFF_TBLS) do
- begin
- entropy^.dc_derived_tbls[i] := NIL;
- entropy^.ac_derived_tbls[i] := NIL;
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdinput.pas b/packages/base/pasjpeg/jdinput.pas
deleted file mode 100644
index 9cc2abfad2..0000000000
--- a/packages/base/pasjpeg/jdinput.pas
+++ /dev/null
@@ -1,416 +0,0 @@
-Unit JdInput;
-
-{ Original: jdinput.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 input control logic for the JPEG decompressor.
- These routines are concerned with controlling the decompressor's input
- processing (marker reading and coefficient decoding). The actual input
- reading is done in jdmarker.c, jdhuff.c, and jdphuff.c. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jpeglib,
- jdeferr,
- jerror,
- jinclude, jutils;
-
-{ Initialize the input controller module.
- This is called only once, when the decompression object is created. }
-
-{GLOBAL}
-procedure jinit_input_controller (cinfo : j_decompress_ptr);
-
-implementation
-
-{ Private state }
-
-type
- my_inputctl_ptr = ^my_input_controller;
- my_input_controller = record
- pub : jpeg_input_controller; { public fields }
-
- inheaders : boolean; { TRUE until first SOS is reached }
- end; {my_input_controller;}
-
-
-
-{ Forward declarations }
-{METHODDEF}
-function consume_markers (cinfo : j_decompress_ptr) : int; far; forward;
-
-
-{ Routines to calculate various quantities related to the size of the image. }
-
-{LOCAL}
-procedure initial_setup (cinfo : j_decompress_ptr);
-{ Called once, when first SOS marker is reached }
-var
- ci : int;
- compptr : jpeg_component_info_ptr;
-begin
- { Make sure image isn't bigger than I can handle }
- if (long(cinfo^.image_height) > long (JPEG_MAX_DIMENSION)) or
- (long(cinfo^.image_width) > long(JPEG_MAX_DIMENSION)) then
- ERREXIT1(j_common_ptr(cinfo), JERR_IMAGE_TOO_BIG, uInt(JPEG_MAX_DIMENSION));
-
- { For now, precision must match compiled-in value... }
- if (cinfo^.data_precision <> BITS_IN_JSAMPLE) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_PRECISION, cinfo^.data_precision);
-
- { Check that number of components won't exceed internal array sizes }
- if (cinfo^.num_components > MAX_COMPONENTS) then
- ERREXIT2(j_common_ptr(cinfo), JERR_COMPONENT_COUNT, cinfo^.num_components,
- MAX_COMPONENTS);
-
- { Compute maximum sampling factors; check factor validity }
- cinfo^.max_h_samp_factor := 1;
- cinfo^.max_v_samp_factor := 1;
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- if (compptr^.h_samp_factor<=0) or (compptr^.h_samp_factor>MAX_SAMP_FACTOR) or
- (compptr^.v_samp_factor<=0) or (compptr^.v_samp_factor>MAX_SAMP_FACTOR) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_SAMPLING);
- {cinfo^.max_h_samp_factor := MAX(cinfo^.max_h_samp_factor,
- compptr^.h_samp_factor);
- cinfo^.max_v_samp_factor := MAX(cinfo^.max_v_samp_factor,
- compptr^.v_samp_factor);}
- if cinfo^.max_h_samp_factor < compptr^.h_samp_factor then
- cinfo^.max_h_samp_factor := compptr^.h_samp_factor;
- if cinfo^.max_v_samp_factor < compptr^.v_samp_factor then
- cinfo^.max_v_samp_factor := compptr^.v_samp_factor;
- Inc(compptr);
- end;
-
- { We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
- In the full decompressor, this will be overridden by jdmaster.c;
- but in the transcoder, jdmaster.c is not used, so we must do it here. }
-
- cinfo^.min_DCT_scaled_size := DCTSIZE;
-
- { Compute dimensions of components }
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- compptr^.DCT_scaled_size := DCTSIZE;
- { Size in DCT blocks }
- compptr^.width_in_blocks := JDIMENSION(
- jdiv_round_up( long(cinfo^.image_width) * long(compptr^.h_samp_factor),
- long(cinfo^.max_h_samp_factor * DCTSIZE)) );
- compptr^.height_in_blocks := JDIMENSION (
- jdiv_round_up(long (cinfo^.image_height) * long(compptr^.v_samp_factor),
- long (cinfo^.max_v_samp_factor * DCTSIZE)) );
- { downsampled_width and downsampled_height will also be overridden by
- jdmaster.c if we are doing full decompression. The transcoder library
- doesn't use these values, but the calling application might. }
-
- { Size in samples }
- compptr^.downsampled_width := JDIMENSION (
- jdiv_round_up(long (cinfo^.image_width) * long(compptr^.h_samp_factor),
- long (cinfo^.max_h_samp_factor)) );
- compptr^.downsampled_height := JDIMENSION (
- jdiv_round_up(long (cinfo^.image_height) * long(compptr^.v_samp_factor),
- long (cinfo^.max_v_samp_factor)) );
- { Mark component needed, until color conversion says otherwise }
- compptr^.component_needed := TRUE;
- { Mark no quantization table yet saved for component }
- compptr^.quant_table := NIL;
- Inc(compptr);
- end;
-
- { Compute number of fully interleaved MCU rows. }
- cinfo^.total_iMCU_rows := JDIMENSION(
- jdiv_round_up(long(cinfo^.image_height),
- long(cinfo^.max_v_samp_factor*DCTSIZE)) );
-
- { Decide whether file contains multiple scans }
- if (cinfo^.comps_in_scan < cinfo^.num_components) or
- (cinfo^.progressive_mode) then
- cinfo^.inputctl^.has_multiple_scans := TRUE
- else
- cinfo^.inputctl^.has_multiple_scans := FALSE;
-end;
-
-
-{LOCAL}
-procedure per_scan_setup (cinfo : j_decompress_ptr);
-{ Do computations that are needed before processing a JPEG scan }
-{ cinfo^.comps_in_scan and cinfo^.cur_comp_info[] were set from SOS marker }
-var
- ci, mcublks, tmp : int;
- compptr : jpeg_component_info_ptr;
-begin
- if (cinfo^.comps_in_scan = 1) then
- begin
- { Noninterleaved (single-component) scan }
- compptr := cinfo^.cur_comp_info[0];
-
- { Overall image size in MCUs }
- cinfo^.MCUs_per_row := compptr^.width_in_blocks;
- cinfo^.MCU_rows_in_scan := compptr^.height_in_blocks;
-
- { For noninterleaved scan, always one block per MCU }
- compptr^.MCU_width := 1;
- compptr^.MCU_height := 1;
- compptr^.MCU_blocks := 1;
- compptr^.MCU_sample_width := compptr^.DCT_scaled_size;
- compptr^.last_col_width := 1;
- { 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 (compptr^.height_in_blocks mod compptr^.v_samp_factor);
- if (tmp = 0) then
- tmp := compptr^.v_samp_factor;
- compptr^.last_row_height := tmp;
-
- { Prepare array describing MCU composition }
- cinfo^.blocks_in_MCU := 1;
- cinfo^.MCU_membership[0] := 0;
-
- end
- else
- begin
-
- { Interleaved (multi-component) scan }
- if (cinfo^.comps_in_scan <= 0) or (cinfo^.comps_in_scan > MAX_COMPS_IN_SCAN) then
- ERREXIT2(j_common_ptr(cinfo), JERR_COMPONENT_COUNT, cinfo^.comps_in_scan,
- MAX_COMPS_IN_SCAN);
-
- { Overall image size in MCUs }
- cinfo^.MCUs_per_row := JDIMENSION (
- jdiv_round_up(long (cinfo^.image_width),
- long (cinfo^.max_h_samp_factor*DCTSIZE)) );
- cinfo^.MCU_rows_in_scan := JDIMENSION (
- jdiv_round_up(long (cinfo^.image_height),
- long (cinfo^.max_v_samp_factor*DCTSIZE)) );
-
- cinfo^.blocks_in_MCU := 0;
-
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- { Sampling factors give # of blocks of component in each MCU }
- compptr^.MCU_width := compptr^.h_samp_factor;
- compptr^.MCU_height := compptr^.v_samp_factor;
- 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 (compptr^.width_in_blocks mod compptr^.MCU_width);
- if (tmp = 0) then
- tmp := compptr^.MCU_width;
- compptr^.last_col_width := tmp;
- tmp := int (compptr^.height_in_blocks mod compptr^.MCU_height);
- if (tmp = 0) then
- tmp := compptr^.MCU_height;
- compptr^.last_row_height := tmp;
- { Prepare array describing MCU composition }
- mcublks := compptr^.MCU_blocks;
- if (cinfo^.blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_MCU_SIZE);
- while (mcublks > 0) do
- begin
- Dec(mcublks);
- cinfo^.MCU_membership[cinfo^.blocks_in_MCU] := ci;
- Inc(cinfo^.blocks_in_MCU);
- end;
- end;
-
- end;
-end;
-
-
-{ Save away a copy of the Q-table referenced by each component present
- in the current scan, unless already saved during a prior scan.
-
- In a multiple-scan JPEG file, the encoder could assign different components
- the same Q-table slot number, but change table definitions between scans
- so that each component uses a different Q-table. (The IJG encoder is not
- currently capable of doing this, but other encoders might.) Since we want
- to be able to dequantize all the components at the end of the file, this
- means that we have to save away the table actually used for each component.
- We do this by copying the table at the start of the first scan containing
- the component.
- The JPEG spec prohibits the encoder from changing the contents of a Q-table
- slot between scans of a component using that slot. If the encoder does so
- anyway, this decoder will simply use the Q-table values that were current
- at the start of the first scan for the component.
-
- The decompressor output side looks only at the saved quant tables,
- not at the current Q-table slots. }
-
-{LOCAL}
-procedure latch_quant_tables (cinfo : j_decompress_ptr);
-var
- ci, qtblno : int;
- compptr : jpeg_component_info_ptr;
- qtbl : JQUANT_TBL_PTR;
-begin
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- { No work if we already saved Q-table for this component }
- if (compptr^.quant_table <> NIL) then
- continue;
- { Make sure specified quantization table is present }
- qtblno := compptr^.quant_tbl_no;
- if (qtblno < 0) or (qtblno >= NUM_QUANT_TBLS) or
- (cinfo^.quant_tbl_ptrs[qtblno] = NIL) then
- ERREXIT1(j_common_ptr(cinfo), JERR_NO_QUANT_TABLE, qtblno);
- { OK, save away the quantization table }
- qtbl := JQUANT_TBL_PTR(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(JQUANT_TBL)) );
- MEMCOPY(qtbl, cinfo^.quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
- compptr^.quant_table := qtbl;
- end;
-end;
-
-
-{ Initialize the input modules to read a scan of compressed data.
- The first call to this is done by jdmaster.c after initializing
- the entire decompressor (during jpeg_start_decompress).
- Subsequent calls come from consume_markers, below. }
-
-{METHODDEF}
-procedure start_input_pass (cinfo : j_decompress_ptr); far;
-begin
- per_scan_setup(cinfo);
- latch_quant_tables(cinfo);
- cinfo^.entropy^.start_pass (cinfo);
- cinfo^.coef^.start_input_pass (cinfo);
- cinfo^.inputctl^.consume_input := cinfo^.coef^.consume_data;
-end;
-
-
-{ Finish up after inputting a compressed-data scan.
- This is called by the coefficient controller after it's read all
- the expected data of the scan. }
-
-{METHODDEF}
-procedure finish_input_pass (cinfo : j_decompress_ptr); far;
-begin
- cinfo^.inputctl^.consume_input := consume_markers;
-end;
-
-
-{ Read JPEG markers before, between, or after compressed-data scans.
- Change state as necessary when a new scan is reached.
- Return value is JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
-
- The consume_input method pointer points either here or to the
- coefficient controller's consume_data routine, depending on whether
- we are reading a compressed data segment or inter-segment markers. }
-
-{METHODDEF}
-function consume_markers (cinfo : j_decompress_ptr) : int;
-var
- val : int;
- inputctl : my_inputctl_ptr;
-begin
- inputctl := my_inputctl_ptr (cinfo^.inputctl);
-
- if (inputctl^.pub.eoi_reached) then { After hitting EOI, read no further }
- begin
- consume_markers := JPEG_REACHED_EOI;
- exit;
- end;
-
- val := cinfo^.marker^.read_markers (cinfo);
-
- case (val) of
- JPEG_REACHED_SOS: { Found SOS }
- begin
- if (inputctl^.inheaders) then
- begin { 1st SOS }
- initial_setup(cinfo);
- inputctl^.inheaders := FALSE;
- { Note: start_input_pass must be called by jdmaster.c
- before any more input can be consumed. jdapimin.c is
- responsible for enforcing this sequencing. }
- end
- else
- begin { 2nd or later SOS marker }
- if (not inputctl^.pub.has_multiple_scans) then
- ERREXIT(j_common_ptr(cinfo), JERR_EOI_EXPECTED); { Oops, I wasn't expecting this! }
- start_input_pass(cinfo);
- end;
- end;
- JPEG_REACHED_EOI: { Found EOI }
- begin
- inputctl^.pub.eoi_reached := TRUE;
- if (inputctl^.inheaders) then
- begin { Tables-only datastream, apparently }
- if (cinfo^.marker^.saw_SOF) then
- ERREXIT(j_common_ptr(cinfo), JERR_SOF_NO_SOS);
- end
- else
- begin
- { Prevent infinite loop in coef ctlr's decompress_data routine
- if user set output_scan_number larger than number of scans. }
-
- if (cinfo^.output_scan_number > cinfo^.input_scan_number) then
- cinfo^.output_scan_number := cinfo^.input_scan_number;
- end;
- end;
- JPEG_SUSPENDED:;
- end;
-
- consume_markers := val;
-end;
-
-
-{ Reset state to begin a fresh datastream. }
-
-{METHODDEF}
-procedure reset_input_controller (cinfo : j_decompress_ptr); far;
-var
- inputctl : my_inputctl_ptr;
-begin
- inputctl := my_inputctl_ptr (cinfo^.inputctl);
-
- inputctl^.pub.consume_input := consume_markers;
- inputctl^.pub.has_multiple_scans := FALSE; { "unknown" would be better }
- inputctl^.pub.eoi_reached := FALSE;
- inputctl^.inheaders := TRUE;
- { Reset other modules }
- cinfo^.err^.reset_error_mgr (j_common_ptr(cinfo));
- cinfo^.marker^.reset_marker_reader (cinfo);
- { Reset progression state -- would be cleaner if entropy decoder did this }
- cinfo^.coef_bits := NIL;
-end;
-
-
-{ Initialize the input controller module.
- This is called only once, when the decompression object is created. }
-
-{GLOBAL}
-procedure jinit_input_controller (cinfo : j_decompress_ptr);
-var
- inputctl : my_inputctl_ptr;
-begin
- { Create subobject in permanent pool }
- inputctl := my_inputctl_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_PERMANENT,
- SIZEOF(my_input_controller)) );
- cinfo^.inputctl := jpeg_input_controller_ptr(inputctl);
- { Initialize method pointers }
- inputctl^.pub.consume_input := consume_markers;
- inputctl^.pub.reset_input_controller := reset_input_controller;
- inputctl^.pub.start_input_pass := start_input_pass;
- inputctl^.pub.finish_input_pass := finish_input_pass;
- { Initialize state: can't use reset_input_controller since we don't
- want to try to reset other modules yet. }
-
- inputctl^.pub.has_multiple_scans := FALSE; { "unknown" would be better }
- inputctl^.pub.eoi_reached := FALSE;
- inputctl^.inheaders := TRUE;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdmainct.pas b/packages/base/pasjpeg/jdmainct.pas
deleted file mode 100644
index 2cbd7eb9f9..0000000000
--- a/packages/base/pasjpeg/jdmainct.pas
+++ /dev/null
@@ -1,610 +0,0 @@
-Unit JdMainCt;
-
-
-{ 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 main buffer controller for decompression.
- The main buffer lies between the JPEG decompressor proper and the
- post-processor; it holds downsampled data in the JPEG colorspace.
-
- Note that this code is bypassed in raw-data mode, since the application
- supplies the equivalent of the main buffer in that case. }
-
-{ Original: jdmainct.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-
-{ In the current system design, the main buffer need never be a full-image
- buffer; any full-height buffers will be found inside the coefficient or
- postprocessing controllers. Nonetheless, the main controller is not
- trivial. Its responsibility is to provide context rows for upsampling/
- rescaling, and doing this in an efficient fashion is a bit tricky.
-
- Postprocessor input data is counted in "row groups". A row group
- is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
- sample rows of each component. (We require DCT_scaled_size values to be
- chosen such that these numbers are integers. In practice DCT_scaled_size
- values will likely be powers of two, so we actually have the stronger
- condition that DCT_scaled_size / min_DCT_scaled_size is an integer.)
- Upsampling will typically produce max_v_samp_factor pixel rows from each
- row group (times any additional scale factor that the upsampler is
- applying).
-
- The coefficient controller will deliver data to us one iMCU row at a time;
- each iMCU row contains v_samp_factor * DCT_scaled_size sample rows, or
- exactly min_DCT_scaled_size row groups. (This amount of data corresponds
- to one row of MCUs when the image is fully interleaved.) Note that the
- number of sample rows varies across components, but the number of row
- groups does not. Some garbage sample rows may be included in the last iMCU
- row at the bottom of the image.
-
- Depending on the vertical scaling algorithm used, the upsampler may need
- access to the sample row(s) above and below its current input row group.
- The upsampler is required to set need_context_rows TRUE at global
- selection
- time if so. When need_context_rows is FALSE, this controller can simply
- obtain one iMCU row at a time from the coefficient controller and dole it
- out as row groups to the postprocessor.
-
- When need_context_rows is TRUE, this controller guarantees that the buffer
- passed to postprocessing contains at least one row group's worth of samples
- above and below the row group(s) being processed. Note that the context
- rows "above" the first passed row group appear at negative row offsets in
- the passed buffer. At the top and bottom of the image, the required
- context rows are manufactured by duplicating the first or last real sample
- row; this avoids having special cases in the upsampling inner loops.
-
- The amount of context is fixed at one row group just because that's a
- convenient number for this controller to work with. The existing
- upsamplers really only need one sample row of context. An upsampler
- supporting arbitrary output rescaling might wish for more than one row
- group of context when shrinking the image; tough, we don't handle that.
- (This is justified by the assumption that downsizing will be handled mostly
- by adjusting the DCT_scaled_size values, so that the actual scale factor at
- the upsample step needn't be much less than one.)
-
- To provide the desired context, we have to retain the last two row groups
- of one iMCU row while reading in the next iMCU row. (The last row group
- can't be processed until we have another row group for its below-context,
- and so we have to save the next-to-last group too for its above-context.)
- We could do this most simply by copying data around in our buffer, but
- that'd be very slow. We can avoid copying any data by creating a rather
- strange pointer structure. Here's how it works. We allocate a workspace
- consisting of M+2 row groups (where M = min_DCT_scaled_size is the number
- of row groups per iMCU row). We create two sets of redundant pointers to
- the workspace. Labeling the physical row groups 0 to M+1, the synthesized
- pointer lists look like this:
- M+1 M-1
- master pointer --> 0 master pointer --> 0
- 1 1
- ... ...
- M-3 M-3
- M-2 M
- M-1 M+1
- M M-2
- M+1 M-1
- 0 0
- We read alternate iMCU rows using each master pointer; thus the last two
- row groups of the previous iMCU row remain un-overwritten in the workspace.
- The pointer lists are set up so that the required context rows appear to
- be adjacent to the proper places when we pass the pointer lists to the
- upsampler.
-
- The above pictures describe the normal state of the pointer lists.
- At top and bottom of the image, we diddle the pointer lists to duplicate
- the first or last sample row as necessary (this is cheaper than copying
- sample rows around).
-
- This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1. In that
- situation each iMCU row provides only one row group so the buffering logic
- must be different (eg, we must read two iMCU rows before we can emit the
- first row group). For now, we simply do not support providing context
- rows when min_DCT_scaled_size is 1. That combination seems unlikely to
- be worth providing --- if someone wants a 1/8th-size preview, they probably
- want it quick and dirty, so a context-free upsampler is sufficient. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
-{$ifdef QUANT_2PASS_SUPPORTED}
- jquant2,
-{$endif}
- jdeferr,
- jerror,
- jpeglib;
-
-
-{GLOBAL}
-procedure jinit_d_main_controller (cinfo : j_decompress_ptr;
- need_full_buffer : boolean);
-
-
-implementation
-
-{ Private buffer controller object }
-
-type
- my_main_ptr = ^my_main_controller;
- my_main_controller = record
- pub : jpeg_d_main_controller; { public fields }
-
- { Pointer to allocated workspace (M or M+2 row groups). }
- buffer : array[0..MAX_COMPONENTS-1] of JSAMPARRAY;
-
- buffer_full : boolean; { Have we gotten an iMCU row from decoder? }
- rowgroup_ctr : JDIMENSION ; { counts row groups output to postprocessor }
-
- { Remaining fields are only used in the context case. }
-
- { These are the master pointers to the funny-order pointer lists. }
- xbuffer : array[0..2-1] of JSAMPIMAGE; { pointers to weird pointer lists }
-
- whichptr : int; { indicates which pointer set is now in use }
- context_state : int; { process_data state machine status }
- rowgroups_avail : JDIMENSION; { row groups available to postprocessor }
- iMCU_row_ctr : JDIMENSION; { counts iMCU rows to detect image top/bot }
- end; { my_main_controller; }
-
-
-{ context_state values: }
-const
- CTX_PREPARE_FOR_IMCU = 0; { need to prepare for MCU row }
- CTX_PROCESS_IMCU = 1; { feeding iMCU to postprocessor }
- CTX_POSTPONED_ROW = 2; { feeding postponed row group }
-
-
-{ Forward declarations }
-{METHODDEF}
-procedure process_data_simple_main(cinfo : j_decompress_ptr;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION); far; forward;
-{METHODDEF}
-procedure process_data_context_main (cinfo : j_decompress_ptr;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION); far; forward;
-
-{$ifdef QUANT_2PASS_SUPPORTED}
-{METHODDEF}
-procedure process_data_crank_post (cinfo : j_decompress_ptr;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION); far; forward;
-{$endif}
-
-
-{LOCAL}
-procedure alloc_funny_pointers (cinfo : j_decompress_ptr);
-{ Allocate space for the funny pointer lists.
- This is done only once, not once per pass. }
-var
- main : my_main_ptr;
- ci, rgroup : int;
- M : int;
- compptr : jpeg_component_info_ptr;
- xbuf : JSAMPARRAY;
-begin
- main := my_main_ptr (cinfo^.main);
- M := cinfo^.min_DCT_scaled_size;
-
- { Get top-level space for component array pointers.
- We alloc both arrays with one call to save a few cycles. }
-
- main^.xbuffer[0] := JSAMPIMAGE (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- cinfo^.num_components * 2 * SIZEOF(JSAMPARRAY)) );
- main^.xbuffer[1] := JSAMPIMAGE(@( main^.xbuffer[0]^[cinfo^.num_components] ));
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- rgroup := (compptr^.v_samp_factor * compptr^.DCT_scaled_size) div
- 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. }
-
- xbuf := JSAMPARRAY (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW)) );
- Inc(JSAMPROW_PTR(xbuf), rgroup); { want one row group at negative offsets }
- main^.xbuffer[0]^[ci] := xbuf;
- Inc(JSAMPROW_PTR(xbuf), rgroup * (M + 4));
- main^.xbuffer[1]^[ci] := xbuf;
- Inc(compptr);
- end;
-end;
-
-{LOCAL}
-procedure make_funny_pointers (cinfo : j_decompress_ptr);
-{ Create the funny pointer lists discussed in the comments above.
- The actual workspace is already allocated (in main^.buffer),
- and the space for the pointer lists is allocated too.
- This routine just fills in the curiously ordered lists.
- This will be repeated at the beginning of each pass. }
-var
- main : my_main_ptr;
- ci, i, rgroup : int;
- M : int;
- compptr : jpeg_component_info_ptr;
- buf, xbuf0, xbuf1 : JSAMPARRAY;
-var
- help_xbuf0 : JSAMPARRAY; { work around negative offsets }
-begin
- main := my_main_ptr (cinfo^.main);
- M := cinfo^.min_DCT_scaled_size;
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- rgroup := (compptr^.v_samp_factor * compptr^.DCT_scaled_size) div
- 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 }
- buf := main^.buffer[ci];
- for i := 0 to pred(rgroup * (M + 2)) do
- begin
- xbuf0^[i] := buf^[i];
- xbuf1^[i] := buf^[i];
- end;
- { In the second list, put the last four row groups in swapped order }
- for i := 0 to pred(rgroup * 2) do
- begin
- xbuf1^[rgroup*(M-2) + i] := buf^[rgroup*M + i];
- xbuf1^[rgroup*M + i] := buf^[rgroup*(M-2) + i];
- end;
- { The wraparound pointers at top and bottom will be filled later
- (see set_wraparound_pointers, below). Initially we want the "above"
- pointers to duplicate the first actual data line. This only needs
- to happen in xbuffer[0]. }
-
- help_xbuf0 := xbuf0;
- Dec(JSAMPROW_PTR(help_xbuf0), rgroup);
-
- for i := 0 to pred(rgroup) do
- begin
- {xbuf0^[i - rgroup] := xbuf0^[0];}
- help_xbuf0^[i] := xbuf0^[0];
- end;
- Inc(compptr);
- end;
-end;
-
-
-{LOCAL}
-procedure set_wraparound_pointers (cinfo : j_decompress_ptr);
-{ Set up the "wraparound" pointers at top and bottom of the pointer lists.
- This changes the pointer list state from top-of-image to the normal state. }
-var
- main : my_main_ptr;
- ci, i, rgroup : int;
- M : int;
- compptr : jpeg_component_info_ptr;
- xbuf0, xbuf1 : JSAMPARRAY;
-var
- help_xbuf0,
- help_xbuf1 : JSAMPARRAY; { work around negative offsets }
-begin
- main := my_main_ptr (cinfo^.main);
- M := cinfo^.min_DCT_scaled_size;
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- rgroup := (compptr^.v_samp_factor * compptr^.DCT_scaled_size) div
- cinfo^.min_DCT_scaled_size; { height of a row group of component }
- xbuf0 := main^.xbuffer[0]^[ci];
- xbuf1 := main^.xbuffer[1]^[ci];
-
- help_xbuf0 := xbuf0;
- Dec(JSAMPROW_PTR(help_xbuf0), rgroup);
- help_xbuf1 := xbuf1;
- Dec(JSAMPROW_PTR(help_xbuf1), rgroup);
-
- for i := 0 to pred(rgroup) do
- begin
- {xbuf0^[i - rgroup] := xbuf0^[rgroup*(M+1) + i];
- xbuf1^[i - rgroup] := xbuf1^[rgroup*(M+1) + i];}
-
- help_xbuf0^[i] := xbuf0^[rgroup*(M+1) + i];
- help_xbuf1^[i] := xbuf1^[rgroup*(M+1) + i];
-
- xbuf0^[rgroup*(M+2) + i] := xbuf0^[i];
- xbuf1^[rgroup*(M+2) + i] := xbuf1^[i];
- end;
- Inc(compptr);
- end;
-end;
-
-
-{LOCAL}
-procedure set_bottom_pointers (cinfo : j_decompress_ptr);
-{ Change the pointer lists to duplicate the last sample row at the bottom
- of the image. whichptr indicates which xbuffer holds the final iMCU row.
- Also sets rowgroups_avail to indicate number of nondummy row groups in row. }
-var
- main : my_main_ptr;
- ci, i, rgroup, iMCUheight, rows_left : int;
- compptr : jpeg_component_info_ptr;
- xbuf : JSAMPARRAY;
-begin
- main := my_main_ptr (cinfo^.main);
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- { Count sample rows in one iMCU row and in one row group }
- iMCUheight := compptr^.v_samp_factor * compptr^.DCT_scaled_size;
- rgroup := iMCUheight div cinfo^.min_DCT_scaled_size;
- { Count nondummy sample rows remaining for this component }
- rows_left := int (compptr^.downsampled_height mod JDIMENSION (iMCUheight));
- if (rows_left = 0) then
- rows_left := iMCUheight;
- { Count nondummy row groups. Should get same answer for each component,
- so we need only do it once. }
- if (ci = 0) then
- begin
- main^.rowgroups_avail := JDIMENSION ((rows_left-1) div rgroup + 1);
- end;
- { 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. }
-
- xbuf := main^.xbuffer[main^.whichptr]^[ci];
- for i := 0 to pred(rgroup * 2) do
- begin
- xbuf^[rows_left + i] := xbuf^[rows_left-1];
- end;
- Inc(compptr);
- end;
-end;
-
-
-{ Initialize for a processing pass. }
-
-{METHODDEF}
-procedure start_pass_main (cinfo : j_decompress_ptr;
- pass_mode : J_BUF_MODE); far;
-var
- main : my_main_ptr;
-begin
- main := my_main_ptr (cinfo^.main);
-
- case (pass_mode) of
- JBUF_PASS_THRU:
- begin
- if (cinfo^.upsample^.need_context_rows) then
- begin
- main^.pub.process_data := process_data_context_main;
- make_funny_pointers(cinfo); { Create the xbuffer[] lists }
- main^.whichptr := 0; { Read first iMCU row into xbuffer[0] }
- main^.context_state := CTX_PREPARE_FOR_IMCU;
- main^.iMCU_row_ctr := 0;
- end
- else
- begin
- { Simple case with no context needed }
- main^.pub.process_data := process_data_simple_main;
- end;
- main^.buffer_full := FALSE; { Mark buffer empty }
- main^.rowgroup_ctr := 0;
- end;
-{$ifdef QUANT_2PASS_SUPPORTED}
- JBUF_CRANK_DEST:
- { For last pass of 2-pass quantization, just crank the postprocessor }
- main^.pub.process_data := process_data_crank_post;
-{$endif}
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
- end;
-end;
-
-
-{ Process some data.
- This handles the simple case where no context is required. }
-
-{METHODDEF}
-procedure process_data_simple_main (cinfo : j_decompress_ptr;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION);
-var
- main : my_main_ptr;
- rowgroups_avail : JDIMENSION;
-var
- main_buffer_ptr : JSAMPIMAGE;
-begin
- main := my_main_ptr (cinfo^.main);
- main_buffer_ptr := JSAMPIMAGE(@(main^.buffer));
-
- { Read input data if we haven't filled the main buffer yet }
- if (not main^.buffer_full) then
- begin
- if (cinfo^.coef^.decompress_data (cinfo, main_buffer_ptr)=0) then
- exit; { suspension forced, can do nothing more }
- main^.buffer_full := TRUE; { OK, we have an iMCU row to work with }
- end;
-
- { There are always min_DCT_scaled_size row groups in an iMCU row. }
- rowgroups_avail := JDIMENSION (cinfo^.min_DCT_scaled_size);
- { Note: at the bottom of the image, we may pass extra garbage row groups
- to the postprocessor. The postprocessor has to check for bottom
- of image anyway (at row resolution), so no point in us doing it too. }
-
- { Feed the postprocessor }
- cinfo^.post^.post_process_data (cinfo, main_buffer_ptr,
- main^.rowgroup_ctr, rowgroups_avail,
- output_buf, out_row_ctr, out_rows_avail);
-
- { Has postprocessor consumed all the data yet? If so, mark buffer empty }
- if (main^.rowgroup_ctr >= rowgroups_avail) then
- begin
- main^.buffer_full := FALSE;
- main^.rowgroup_ctr := 0;
- end;
-end;
-
-
-{ Process some data.
- This handles the case where context rows must be provided. }
-
-{METHODDEF}
-procedure process_data_context_main (cinfo : j_decompress_ptr;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION);
-var
- main : my_main_ptr;
-begin
- main := my_main_ptr (cinfo^.main);
-
- { Read input data if we haven't filled the main buffer yet }
- if (not main^.buffer_full) then
- begin
- if (cinfo^.coef^.decompress_data (cinfo,
- main^.xbuffer[main^.whichptr])=0) then
- exit; { suspension forced, can do nothing more }
- main^.buffer_full := TRUE; { OK, we have an iMCU row to work with }
- Inc(main^.iMCU_row_ctr); { count rows received }
- end;
-
- { Postprocessor typically will not swallow all the input data it is handed
- in one call (due to filling the output buffer first). Must be prepared
- to exit and restart. This switch lets us keep track of how far we got.
- Note that each case falls through to the next on successful completion. }
-
- case (main^.context_state) of
- CTX_POSTPONED_ROW:
- begin
- { Call postprocessor using previously set pointers for postponed row }
- cinfo^.post^.post_process_data (cinfo, main^.xbuffer[main^.whichptr],
- main^.rowgroup_ctr, main^.rowgroups_avail,
- output_buf, out_row_ctr, out_rows_avail);
- if (main^.rowgroup_ctr < main^.rowgroups_avail) then
- exit; { Need to suspend }
- main^.context_state := CTX_PREPARE_FOR_IMCU;
- if (out_row_ctr >= out_rows_avail) then
- exit; { Postprocessor exactly filled output buf }
- end;
- end;
- case (main^.context_state) of
- CTX_POSTPONED_ROW,
- CTX_PREPARE_FOR_IMCU: {FALLTHROUGH}
- begin
- { Prepare to process first M-1 row groups of this iMCU row }
- main^.rowgroup_ctr := 0;
- main^.rowgroups_avail := JDIMENSION (cinfo^.min_DCT_scaled_size - 1);
- { Check for bottom of image: if so, tweak pointers to "duplicate"
- the last sample row, and adjust rowgroups_avail to ignore padding rows. }
-
- if (main^.iMCU_row_ctr = cinfo^.total_iMCU_rows) then
- set_bottom_pointers(cinfo);
- main^.context_state := CTX_PROCESS_IMCU;
-
- end;
- end;
- case (main^.context_state) of
- CTX_POSTPONED_ROW,
- CTX_PREPARE_FOR_IMCU, {FALLTHROUGH}
- CTX_PROCESS_IMCU:
- begin
- { Call postprocessor using previously set pointers }
- cinfo^.post^.post_process_data (cinfo, main^.xbuffer[main^.whichptr],
- main^.rowgroup_ctr, main^.rowgroups_avail,
- output_buf, out_row_ctr, out_rows_avail);
- if (main^.rowgroup_ctr < main^.rowgroups_avail) then
- exit; { Need to suspend }
- { After the first iMCU, change wraparound pointers to normal state }
- if (main^.iMCU_row_ctr = 1) then
- set_wraparound_pointers(cinfo);
- { Prepare to load new iMCU row using other xbuffer list }
- main^.whichptr := main^.whichptr xor 1; { 0=>1 or 1=>0 }
- main^.buffer_full := FALSE;
- { Still need to process last row group of this iMCU row, }
- { which is saved at index M+1 of the other xbuffer }
- main^.rowgroup_ctr := JDIMENSION (cinfo^.min_DCT_scaled_size + 1);
- main^.rowgroups_avail := JDIMENSION (cinfo^.min_DCT_scaled_size + 2);
- main^.context_state := CTX_POSTPONED_ROW;
- end;
- end;
-end;
-
-
-{ Process some data.
- Final pass of two-pass quantization: just call the postprocessor.
- Source data will be the postprocessor controller's internal buffer. }
-
-{$ifdef QUANT_2PASS_SUPPORTED}
-
-{METHODDEF}
-procedure process_data_crank_post (cinfo : j_decompress_ptr;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION);
-var
- in_row_group_ctr : JDIMENSION;
-begin
- in_row_group_ctr := 0;
- cinfo^.post^.post_process_data (cinfo, JSAMPIMAGE (NIL),
- in_row_group_ctr,
- JDIMENSION(0),
- output_buf,
- out_row_ctr,
- out_rows_avail);
-end;
-
-{$endif} { QUANT_2PASS_SUPPORTED }
-
-
-{ Initialize main buffer controller. }
-
-{GLOBAL}
-procedure jinit_d_main_controller (cinfo : j_decompress_ptr;
- need_full_buffer : boolean);
-var
- main : my_main_ptr;
- ci, rgroup, ngroups : int;
- compptr : jpeg_component_info_ptr;
-begin
- main := my_main_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_main_controller)) );
- cinfo^.main := jpeg_d_main_controller_ptr(main);
- main^.pub.start_pass := start_pass_main;
-
- if (need_full_buffer) then { shouldn't happen }
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
-
- { Allocate the workspace.
- ngroups is the number of row groups we need.}
-
- if (cinfo^.upsample^.need_context_rows) then
- begin
- if (cinfo^.min_DCT_scaled_size < 2) then { unsupported, see comments above }
- ERREXIT(j_common_ptr(cinfo), JERR_NOTIMPL);
- alloc_funny_pointers(cinfo); { Alloc space for xbuffer[] lists }
- ngroups := cinfo^.min_DCT_scaled_size + 2;
- end
- else
- begin
- ngroups := cinfo^.min_DCT_scaled_size;
- end;
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- rgroup := (compptr^.v_samp_factor * compptr^.DCT_scaled_size) div
- 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,
- JDIMENSION (rgroup * ngroups));
- Inc(compptr);
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdmarker.pas b/packages/base/pasjpeg/jdmarker.pas
deleted file mode 100644
index ee6430fbee..0000000000
--- a/packages/base/pasjpeg/jdmarker.pas
+++ /dev/null
@@ -1,2644 +0,0 @@
-Unit JdMarker;
-
-{ This file contains routines to decode JPEG datastream markers.
- Most of the complexity arises from our desire to support input
- suspension: if not all of the data for a marker is available;
- we must exit back to the application. On resumption; we reprocess
- the marker. }
-
-{ Original: jdmarker.c; Copyright (C) 1991-1998; Thomas G. Lane. }
-{ History
- 9.7.96 Conversion to pascal started jnn
- 22.3.98 updated to 6b jnn }
-
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jcomapi,
- jpeglib;
-
-const { JPEG marker codes }
- M_SOF0 = $c0;
- M_SOF1 = $c1;
- M_SOF2 = $c2;
- M_SOF3 = $c3;
-
- M_SOF5 = $c5;
- M_SOF6 = $c6;
- M_SOF7 = $c7;
-
- M_JPG = $c8;
- M_SOF9 = $c9;
- M_SOF10 = $ca;
- M_SOF11 = $cb;
-
- M_SOF13 = $cd;
- M_SOF14 = $ce;
- M_SOF15 = $cf;
-
- M_DHT = $c4;
-
- M_DAC = $cc;
-
- M_RST0 = $d0;
- M_RST1 = $d1;
- M_RST2 = $d2;
- M_RST3 = $d3;
- M_RST4 = $d4;
- M_RST5 = $d5;
- M_RST6 = $d6;
- M_RST7 = $d7;
-
- M_SOI = $d8;
- M_EOI = $d9;
- M_SOS = $da;
- M_DQT = $db;
- M_DNL = $dc;
- M_DRI = $dd;
- M_DHP = $de;
- M_EXP = $df;
-
- M_APP0 = $e0;
- M_APP1 = $e1;
- M_APP2 = $e2;
- M_APP3 = $e3;
- M_APP4 = $e4;
- M_APP5 = $e5;
- M_APP6 = $e6;
- M_APP7 = $e7;
- M_APP8 = $e8;
- M_APP9 = $e9;
- M_APP10 = $ea;
- M_APP11 = $eb;
- M_APP12 = $ec;
- M_APP13 = $ed;
- M_APP14 = $ee;
- M_APP15 = $ef;
-
- M_JPG0 = $f0;
- M_JPG13 = $fd;
- M_COM = $fe;
-
- M_TEM = $01;
-
- M_ERROR = $100;
-
-type
- JPEG_MARKER = uint; { JPEG marker codes }
-
-{ Private state }
-
-type
- my_marker_ptr = ^my_marker_reader;
- my_marker_reader = record
- pub : jpeg_marker_reader; { public fields }
-
- { Application-overridable marker processing methods }
- process_COM : jpeg_marker_parser_method;
- process_APPn : array[0..16-1] of jpeg_marker_parser_method;
-
- { Limit on marker data length to save for each marker type }
- length_limit_COM : uint;
- length_limit_APPn : array[0..16-1] of uint;
-
- { Status of COM/APPn marker saving }
- cur_marker : jpeg_saved_marker_ptr; { NIL if not processing a marker }
- bytes_read : uint; { data bytes read so far in marker }
- { Note: cur_marker is not linked into marker_list until it's all read. }
- end;
-
-{GLOBAL}
-function jpeg_resync_to_restart(cinfo : j_decompress_ptr;
- desired : int) : boolean;
-{GLOBAL}
-procedure jinit_marker_reader (cinfo : j_decompress_ptr);
-
-{$ifdef SAVE_MARKERS_SUPPORTED}
-
-{GLOBAL}
-procedure jpeg_save_markers (cinfo : j_decompress_ptr;
- marker_code : int;
- length_limit : uint);
-{$ENDIF}
-
-{GLOBAL}
-procedure jpeg_set_marker_processor (cinfo : j_decompress_ptr;
- marker_code : int;
- routine : jpeg_marker_parser_method);
-
-implementation
-
-uses
- jutils;
-
-{ At all times, cinfo1.src.next_input_byte and .bytes_in_buffer reflect
- the current restart point; we update them only when we have reached a
- suitable place to restart if a suspension occurs. }
-
-
-{ Routines to process JPEG markers.
-
- Entry condition: JPEG marker itself has been read and its code saved
- in cinfo^.unread_marker; input restart point is just after the marker.
-
- Exit: if return TRUE, have read and processed any parameters, and have
- updated the restart point to point after the parameters.
- If return FALSE, was forced to suspend before reaching end of
- marker parameters; restart point has not been moved. Same routine
- will be called again after application supplies more input data.
-
- This approach to suspension assumes that all of a marker's parameters
- can fit into a single input bufferload. This should hold for "normal"
- markers. Some COM/APPn markers might have large parameter segments
- that might not fit. If we are simply dropping such a marker, we use
- skip_input_data to get past it, and thereby put the problem on the
- source manager's shoulders. If we are saving the marker's contents
- into memory, we use a slightly different convention: when forced to
- suspend, the marker processor updates the restart point to the end of
- what it's consumed (ie, the end of the buffer) before returning FALSE.
- On resumption, cinfo->unread_marker still contains the marker code,
- but the data source will point to the next chunk of marker data.
- The marker processor must retain internal state to deal with this.
-
- Note that we don't bother to avoid duplicate trace messages if a
- suspension occurs within marker parameters. Other side effects
- require more care. }
-
-{LOCAL}
-function get_soi (cinfo : j_decompress_ptr) : boolean;
-{ Process an SOI marker }
-var
- i : int;
-begin
- {$IFDEF DEBUG}
- TRACEMS(j_common_ptr(cinfo), 1, JTRC_SOI);
- {$ENDIF}
-
- if (cinfo^.marker^.saw_SOI) then
- ERREXIT(j_common_ptr(cinfo), JERR_SOI_DUPLICATE);
-
- { Reset all parameters that are defined to be reset by SOI }
-
- for i := 0 to Pred(NUM_ARITH_TBLS) do
- with cinfo^ do
- begin
- arith_dc_L[i] := 0;
- arith_dc_U[i] := 1;
- arith_ac_K[i] := 5;
- end;
- cinfo^.restart_interval := 0;
-
- { Set initial assumptions for colorspace etc }
-
- with cinfo^ do
- begin
- jpeg_color_space := JCS_UNKNOWN;
- CCIR601_sampling := FALSE; { Assume non-CCIR sampling??? }
-
- saw_JFIF_marker := FALSE;
- JFIF_major_version := 1; { set default JFIF APP0 values }
- JFIF_minor_version := 1;
- density_unit := 0;
- X_density := 1;
- Y_density := 1;
- saw_Adobe_marker := FALSE;
- Adobe_transform := 0;
-
- marker^.saw_SOI := TRUE;
- end;
- get_soi := TRUE;
-end; { get_soi }
-
-
-{LOCAL}
-function get_sof(cinfo : j_decompress_ptr;
- is_prog : boolean;
- is_arith : boolean) : boolean;
-{ Process a SOFn marker }
-var
- length : INT32;
- c, ci : int;
- compptr : jpeg_component_info_ptr;
-{ Declare and initialize local copies of input pointer/count }
-var
- datasrc : jpeg_source_mgr_ptr;
- next_input_byte : JOCTETptr;
- bytes_in_buffer : size_t;
-begin
- datasrc := cinfo^.src;
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
-{}
- cinfo^.progressive_mode := is_prog;
- cinfo^.arith_code := is_arith;
-
-{ Read two bytes interpreted as an unsigned 16-bit integer.
- length should be declared unsigned int or perhaps INT32. }
-
-{ make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sof := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- length := (uint( GETJOCTET(next_input_byte^)) shl 8);
- Inc( next_input_byte );
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sof := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( length, GETJOCTET( next_input_byte^));
- Inc( next_input_byte );
-
-
- { Read a byte into variable cinfo^.data_precision.
- If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sof := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- cinfo^.data_precision := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
-{ Read two bytes interpreted as an unsigned 16-bit integer.
- cinfo^.image_height should be declared unsigned int or perhaps INT32. }
-
-{ make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sof := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- cinfo^.image_height := (uint( GETJOCTET(next_input_byte^)) shl 8);
- Inc( next_input_byte );
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sof := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( cinfo^.image_height, GETJOCTET( next_input_byte^));
- Inc( next_input_byte );
-
-{ Read two bytes interpreted as an unsigned 16-bit integer.
- cinfo^.image_width should be declared unsigned int or perhaps INT32. }
-
-{ make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sof := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- cinfo^.image_width := (uint( GETJOCTET(next_input_byte^)) shl 8);
- Inc( next_input_byte );
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sof := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( cinfo^.image_width, GETJOCTET( next_input_byte^));
- Inc( next_input_byte );
-
- { Read a byte into variable cinfo^.num_components.
- If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sof := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- cinfo^.num_components := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- Dec(length, 8);
-
- {$IFDEF DEBUG}
- TRACEMS4(j_common_ptr(cinfo), 1, JTRC_SOF, cinfo^.unread_marker,
- int(cinfo^.image_width), int(cinfo^.image_height),
- cinfo^.num_components);
- {$ENDIF}
-
- if (cinfo^.marker^.saw_SOF) then
- ERREXIT(j_common_ptr(cinfo), JERR_SOF_DUPLICATE);
-
- { We don't support files in which the image height is initially specified }
- { as 0 and is later redefined by DNL. As long as we have to check that, }
- { might as well have a general sanity check. }
- if (cinfo^.image_height <= 0) or (cinfo^.image_width <= 0)
- or (cinfo^.num_components <= 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_EMPTY_IMAGE);
-
- if (length <> (cinfo^.num_components * 3)) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_LENGTH);
-
- if (cinfo^.comp_info = NIL) then { do only once, even if suspend }
- cinfo^.comp_info := jpeg_component_info_list_ptr(
- cinfo^.mem^.alloc_small(j_common_ptr(cinfo), JPOOL_IMAGE,
- cinfo^.num_components * SIZEOF(jpeg_component_info)));
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- compptr^.component_index := ci;
-
- { Read a byte into variable compptr^.component_id.
- If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sof := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- compptr^.component_id := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- { Read a byte into variable c. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sof := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- c := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- compptr^.h_samp_factor := (c shr 4) and 15;
- compptr^.v_samp_factor := (c ) and 15;
-
- { Read a byte into variable compptr^.quant_tbl_no.
- If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sof := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- compptr^.quant_tbl_no := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- {$IFDEF DEBUG}
- TRACEMS4(j_common_ptr(cinfo), 1, JTRC_SOF_COMPONENT,
- compptr^.component_id, compptr^.h_samp_factor,
- compptr^.v_samp_factor, compptr^.quant_tbl_no);
- {$ENDIF}
-
- Inc(compptr);
- end;
-
- cinfo^.marker^.saw_SOF := TRUE;
-
- { Unload the local copies --- do this only at a restart boundary }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- get_sof := TRUE;
-end; { get_sof }
-
-
-{LOCAL}
-function get_sos (cinfo : j_decompress_ptr) : boolean;
-{ Process a SOS marker }
-label
- id_found;
-var
- length : INT32;
- i, ci, n, c, cc : int;
- compptr : jpeg_component_info_ptr;
-{ Declare and initialize local copies of input pointer/count }
-var
- datasrc : jpeg_source_mgr_ptr;
- next_input_byte : JOCTETptr; { Array[] of JOCTET; }
- bytes_in_buffer : size_t;
-begin
- datasrc := cinfo^.src;
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
-
-{}
-
- if not cinfo^.marker^.saw_SOF then
- ERREXIT(j_common_ptr(cinfo), JERR_SOS_NO_SOF);
-
-{ Read two bytes interpreted as an unsigned 16-bit integer.
- length should be declared unsigned int or perhaps INT32. }
-
-{ make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sos := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- length := (uint( GETJOCTET(next_input_byte^)) shl 8);
- Inc( next_input_byte );
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sos := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( length, GETJOCTET( next_input_byte^));
- Inc( next_input_byte );
-
-
- { Read a byte into variable n (Number of components).
- If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sos := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- n := GETJOCTET(next_input_byte^); { Number of components }
- Inc(next_input_byte);
-
- {$IFDEF DEBUG}
- TRACEMS1(j_common_ptr(cinfo), 1, JTRC_SOS, n);
- {$ENDIF}
-
- if ((length <> (n * 2 + 6)) or (n < 1) or (n > MAX_COMPS_IN_SCAN)) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_LENGTH);
-
- cinfo^.comps_in_scan := n;
-
- { Collect the component-spec parameters }
-
- for i := 0 to Pred(n) do
- begin
- { Read a byte into variable cc. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sos := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- cc := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- { Read a byte into variable c. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sos := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- c := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to Pred(cinfo^.num_components) do
- begin
- if (cc = compptr^.component_id) then
- goto id_found;
- Inc(compptr);
- end;
-
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_COMPONENT_ID, cc);
-
- id_found:
-
- cinfo^.cur_comp_info[i] := compptr;
- compptr^.dc_tbl_no := (c shr 4) and 15;
- compptr^.ac_tbl_no := (c ) and 15;
-
- {$IFDEF DEBUG}
- TRACEMS3(j_common_ptr(cinfo), 1, JTRC_SOS_COMPONENT, cc,
- compptr^.dc_tbl_no, compptr^.ac_tbl_no);
- {$ENDIF}
- end;
-
- { Collect the additional scan parameters Ss, Se, Ah/Al. }
- { Read a byte into variable c. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sos := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- c := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- cinfo^.Ss := c;
-
- { Read a byte into variable c. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sos := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- c := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- cinfo^.Se := c;
-
- { Read a byte into variable c. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_sos := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- c := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- cinfo^.Ah := (c shr 4) and 15;
- cinfo^.Al := (c ) and 15;
-
- {$IFDEF DEBUG}
- TRACEMS4(j_common_ptr(cinfo), 1, JTRC_SOS_PARAMS, cinfo^.Ss, cinfo^.Se,
- cinfo^.Ah, cinfo^.Al);
- {$ENDIF}
-
- { Prepare to scan data & restart markers }
- cinfo^.marker^.next_restart_num := 0;
-
- { Count another SOS marker }
- Inc( cinfo^.input_scan_number );
-
- { Unload the local copies --- do this only at a restart boundary }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- get_sos := TRUE;
-end; { get_sos }
-
-
-{METHODDEF}
-function skip_variable (cinfo : j_decompress_ptr) : boolean; far;
-{ Skip over an unknown or uninteresting variable-length marker }
-var
- length : INT32;
-var
- datasrc : jpeg_source_mgr_ptr;
- next_input_byte : JOCTETptr; { Array[] of JOCTET; }
- bytes_in_buffer : size_t;
-begin
- datasrc := cinfo^.src;
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
-
-{ Read two bytes interpreted as an unsigned 16-bit integer.
- length should be declared unsigned int or perhaps INT32. }
-
-{ make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- skip_variable := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- length := uint(GETJOCTET(next_input_byte^)) shl 8;
- Inc( next_input_byte );
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- skip_variable := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( length, GETJOCTET(next_input_byte^));
- Inc( next_input_byte );
-
- Dec(length, 2);
-
- {$IFDEF DEBUG}
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_MISC_MARKER,
- cinfo^.unread_marker, int(length));
- {$ENDIF}
-
- { Unload the local copies --- do this only at a restart boundary }
- { do before skip_input_data }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- if (length > 0) then
- cinfo^.src^.skip_input_data(cinfo, long(length));
-
- skip_variable := TRUE;
-end; { skip_variable }
-
-
-{$IFDEF D_ARITH_CODING_SUPPORTED}
-
-{LOCAL}
-function get_dac (cinfo : j_decompress_ptr) : boolean;
-{ Process a DAC marker }
-var
- length : INT32;
- index, val : int;
-var
- datasrc : jpeg_source_mgr_ptr;
- next_input_byte : JOCTETptr;
- bytes_in_buffer : size_t;
-begin
- datasrc := cinfo^.src;
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
-
-{ Read two bytes interpreted as an unsigned 16-bit integer.
- length should be declared unsigned int or perhaps INT32. }
-
-{ make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dac := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- length := (uint( GETJOCTET(next_input_byte^)) shl 8);
- Inc( next_input_byte );
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dac := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( length, GETJOCTET( next_input_byte^));
- Inc( next_input_byte );
-
- Dec(length, 2);
-
- while (length > 0) do
- begin
- { Read a byte into variable index. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dac := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- index := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- { Read a byte into variable val. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dac := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- val := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- Dec( length, 2);
-
- {$IFDEF DEBUG}
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_DAC, index, val);
- {$ENDIF}
-
- if (index < 0) or (index >= (2*NUM_ARITH_TBLS)) then
- ERREXIT1(j_common_ptr(cinfo) , JERR_DAC_INDEX, index);
-
- if (index >= NUM_ARITH_TBLS) then
- begin { define AC table }
- cinfo^.arith_ac_K[index-NUM_ARITH_TBLS] := UINT8(val);
- end
- else
- begin { define DC table }
- cinfo^.arith_dc_L[index] := UINT8(val and $0F);
- cinfo^.arith_dc_U[index] := UINT8(val shr 4);
- if (cinfo^.arith_dc_L[index] > cinfo^.arith_dc_U[index]) then
- ERREXIT1(j_common_ptr(cinfo) , JERR_DAC_VALUE, val);
- end;
- end;
-
- if (length <> 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_LENGTH);
-
- { Unload the local copies --- do this only at a restart boundary }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- get_dac := TRUE;
-end; { get_dac }
-
-{$ELSE}
-
-{LOCAL}
-function get_dac (cinfo : j_decompress_ptr) : boolean;
-begin
- get_dac := skip_variable(cinfo);
-end;
-
-{$ENDIF}
-
-{LOCAL}
-function get_dht (cinfo : j_decompress_ptr) : boolean;
-{ Process a DHT marker }
-var
- length : INT32;
- bits : Array[0..17-1] of UINT8;
- huffval : Array[0..256-1] of UINT8;
- i, index, count : int;
- htblptr : ^JHUFF_TBL_PTR;
-var
- datasrc : jpeg_source_mgr_ptr;
- next_input_byte : JOCTETptr;
- bytes_in_buffer : size_t;
-begin
- datasrc := cinfo^.src;
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
-
-{ Read two bytes interpreted as an unsigned 16-bit integer.
- length should be declared unsigned int or perhaps INT32. }
-
-{ make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dht := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- length := (uint( GETJOCTET(next_input_byte^)) shl 8);
- Inc( next_input_byte );
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dht := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( length, GETJOCTET( next_input_byte^));
- Inc( next_input_byte );
-
- Dec(length, 2);
-
- while (length > 16) do
- begin
- { Read a byte into variable index. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dht := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- index := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- {$IFDEF DEBUG}
- TRACEMS1(j_common_ptr(cinfo), 1, JTRC_DHT, index);
- {$ENDIF}
-
- bits[0] := 0;
- count := 0;
- for i := 1 to 16 do
- begin
- { Read a byte into variable bits[i]. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dht := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- bits[i] := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- Inc( count, bits[i] );
- end;
-
- Dec( length, (1 + 16) );
-
- {$IFDEF DEBUG}
- TRACEMS8(j_common_ptr(cinfo), 2, JTRC_HUFFBITS,
- bits[1], bits[2], bits[3], bits[4],
- bits[5], bits[6], bits[7], bits[8]);
- TRACEMS8(j_common_ptr(cinfo), 2, JTRC_HUFFBITS,
- bits[9], bits[10], bits[11], bits[12],
- bits[13], bits[14], bits[15], bits[16]);
- {$ENDIF}
-
- { Here we just do minimal validation of the counts to avoid walking
- off the end of our table space. jdhuff.c will check more carefully. }
-
- if (count > 256) or (INT32(count) > length) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_HUFF_TABLE);
-
- for i := 0 to Pred(count) do
- begin
- { Read a byte into variable huffval[i]. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dht := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- huffval[i] := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
- end;
-
- Dec( length, count );
-
- if (index and $10)<>0 then
- begin { AC table definition }
- Dec( index, $10 );
- htblptr := @cinfo^.ac_huff_tbl_ptrs[index];
- end
- else
- begin { DC table definition }
- htblptr := @cinfo^.dc_huff_tbl_ptrs[index];
- end;
-
- if (index < 0) or (index >= NUM_HUFF_TBLS) then
- ERREXIT1(j_common_ptr(cinfo), JERR_DHT_INDEX, index);
-
- if (htblptr^ = NIL) then
- htblptr^ := jpeg_alloc_huff_table(j_common_ptr(cinfo));
-
- MEMCOPY(@(htblptr^)^.bits, @bits, SIZEOF((htblptr^)^.bits));
- MEMCOPY(@(htblptr^)^.huffval, @huffval, SIZEOF((htblptr^)^.huffval));
- end;
-
- if (length <> 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_LENGTH);
-
- { Unload the local copies --- do this only at a restart boundary }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- get_dht := TRUE;
-end; { get_dht }
-
-
-{LOCAL}
-function get_dqt (cinfo : j_decompress_ptr) : boolean;
-{ Process a DQT marker }
-var
- length : INT32;
- n, i, prec : int;
- tmp : uint;
- quant_ptr : JQUANT_TBL_PTR;
-var
- datasrc : jpeg_source_mgr_ptr;
- next_input_byte : JOCTETptr;
- bytes_in_buffer : size_t;
-begin
- datasrc := cinfo^.src;
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
-
-{ Read two bytes interpreted as an unsigned 16-bit integer.
- length should be declared unsigned int or perhaps INT32. }
-
-{ make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dqt := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- length := (uint( GETJOCTET(next_input_byte^)) shl 8);
- Inc( next_input_byte );
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dqt := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( length, GETJOCTET( next_input_byte^));
- Inc( next_input_byte );
-
- Dec( length, 2 );
-
- while (length > 0) do
- begin
- { Read a byte into variable n. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dqt := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- n := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- prec := n shr 4;
- n := n and $0F;
-
- {$IFDEF DEBUG}
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_DQT, n, prec);
- {$ENDIF}
-
- if (n >= NUM_QUANT_TBLS) then
- ERREXIT1(j_common_ptr(cinfo) , JERR_DQT_INDEX, n);
-
- if (cinfo^.quant_tbl_ptrs[n] = NIL) then
- cinfo^.quant_tbl_ptrs[n] := jpeg_alloc_quant_table(j_common_ptr(cinfo));
- quant_ptr := cinfo^.quant_tbl_ptrs[n];
-
- for i := 0 to Pred(DCTSIZE2) do
- begin
- if (prec <> 0) then
- begin
- { Read two bytes interpreted as an unsigned 16-bit integer.
- tmp should be declared unsigned int or perhaps INT32. }
-
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dqt := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- tmp := (uint( GETJOCTET(next_input_byte^)) shl 8);
- Inc( next_input_byte );
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dqt := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( tmp, GETJOCTET( next_input_byte^));
- Inc( next_input_byte );
-
- end
- else
- begin
- { Read a byte into variable tmp. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dqt := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- tmp := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
- end;
-
- { We convert the zigzag-order table to natural array order. }
- quant_ptr^.quantval[jpeg_natural_order[i]] := UINT16(tmp);
- end;
-
- if (cinfo^.err^.trace_level >= 2) then
- begin
- i := 0;
- while i < Pred(DCTSIZE2) do
- begin
- {$IFDEF DEBUG}
- TRACEMS8(j_common_ptr(cinfo), 2, JTRC_QUANTVALS,
- quant_ptr^.quantval[i], quant_ptr^.quantval[i+1],
- quant_ptr^.quantval[i+2], quant_ptr^.quantval[i+3],
- quant_ptr^.quantval[i+4], quant_ptr^.quantval[i+5],
- quant_ptr^.quantval[i+6], quant_ptr^.quantval[i+7]);
- {$ENDIF}
- Inc(i, 8);
- end;
- end;
-
- Dec( length, DCTSIZE2+1 );
- if (prec <> 0) then
- Dec( length, DCTSIZE2 );
- end;
-
- if (length <> 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_LENGTH);
-
- { Unload the local copies --- do this only at a restart boundary }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- get_dqt := TRUE;
-end; { get_dqt }
-
-
-{LOCAL}
-function get_dri (cinfo : j_decompress_ptr) : boolean;
-{ Process a DRI marker }
-var
- length : INT32;
- tmp : uint;
-var
- datasrc : jpeg_source_mgr_ptr;
- next_input_byte : JOCTETptr;
- bytes_in_buffer : size_t;
-begin
- datasrc := cinfo^.src;
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
-
-{ Read two bytes interpreted as an unsigned 16-bit integer.
- length should be declared unsigned int or perhaps INT32. }
-
-{ make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dri := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- length := (uint( GETJOCTET(next_input_byte^)) shl 8);
- Inc( next_input_byte );
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dri := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( length, GETJOCTET( next_input_byte^));
- Inc( next_input_byte );
-
- if (length <> 4) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_LENGTH);
-
-{ Read two bytes interpreted as an unsigned 16-bit integer.
- tmp should be declared unsigned int or perhaps INT32. }
-
-{ make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dri := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- tmp := (uint( GETJOCTET(next_input_byte^)) shl 8);
- Inc( next_input_byte );
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_dri := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( tmp, GETJOCTET( next_input_byte^));
- Inc( next_input_byte );
-
- {$IFDEF DEBUG}
- TRACEMS1(j_common_ptr(cinfo), 1, JTRC_DRI, tmp);
- {$ENDIF}
-
- cinfo^.restart_interval := tmp;
-
- { Unload the local copies --- do this only at a restart boundary }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- get_dri := TRUE;
-end; { get_dri }
-
-
-{ Routines for processing APPn and COM markers.
- These are either saved in memory or discarded, per application request.
- APP0 and APP14 are specially checked to see if they are
- JFIF and Adobe markers, respectively. }
-
-const
- APP0_DATA_LEN = 14; { Length of interesting data in APP0 }
- APP14_DATA_LEN = 12; { Length of interesting data in APP14 }
- APPN_DATA_LEN = 14; { Must be the largest of the above!! }
-
-
-{LOCAL}
-procedure examine_app0 (cinfo : j_decompress_ptr;
- var data : array of JOCTET;
- datalen : uint;
- remaining : INT32);
-
-{ Examine first few bytes from an APP0.
- Take appropriate action if it is a JFIF marker.
- datalen is # of bytes at data[], remaining is length of rest of marker data.
-}
-{$IFDEF DEBUG}
-var
- totallen : INT32;
-{$ENDIF}
-begin
- {$IFDEF DEBUG}
- totallen := INT32(datalen) + remaining;
- {$ENDIF}
- if (datalen >= APP0_DATA_LEN) and
- (GETJOCTET(data[0]) = $4A) and
- (GETJOCTET(data[1]) = $46) and
- (GETJOCTET(data[2]) = $49) and
- (GETJOCTET(data[3]) = $46) and
- (GETJOCTET(data[4]) = 0) then
- begin
- { Found JFIF APP0 marker: save info }
- cinfo^.saw_JFIF_marker := TRUE;
- cinfo^.JFIF_major_version := GETJOCTET(data[5]);
- cinfo^.JFIF_minor_version := GETJOCTET(data[6]);
- cinfo^.density_unit := GETJOCTET(data[7]);
- cinfo^.X_density := (GETJOCTET(data[8]) shl 8) + GETJOCTET(data[9]);
- cinfo^.Y_density := (GETJOCTET(data[10]) shl 8) + GETJOCTET(data[11]);
- { Check version.
- Major version must be 1, anything else signals an incompatible change.
- (We used to treat this as an error, but now it's a nonfatal warning,
- because some bozo at Hijaak couldn't read the spec.)
- Minor version should be 0..2, but process anyway if newer. }
-
- if (cinfo^.JFIF_major_version <> 1) then
- WARNMS2(j_common_ptr(cinfo), JWRN_JFIF_MAJOR,
- cinfo^.JFIF_major_version, cinfo^.JFIF_minor_version);
- { Generate trace messages }
- {$IFDEF DEBUG}
- TRACEMS5(j_common_ptr(cinfo), 1, JTRC_JFIF,
- cinfo^.JFIF_major_version, cinfo^.JFIF_minor_version,
- cinfo^.X_density, cinfo^.Y_density, cinfo^.density_unit);
- { Validate thumbnail dimensions and issue appropriate messages }
- if (GETJOCTET(data[12]) or GETJOCTET(data[13])) <> 0 then
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_JFIF_THUMBNAIL,
- GETJOCTET(data[12]), GETJOCTET(data[13]));
- Dec(totallen, APP0_DATA_LEN);
- if (totallen <>
- ( INT32(GETJOCTET(data[12])) * INT32(GETJOCTET(data[13])) * INT32(3) )) then
- TRACEMS1(j_common_ptr(cinfo), 1, JTRC_JFIF_BADTHUMBNAILSIZE, int(totallen));
- {$ENDIF}
- end
- else
- if (datalen >= 6) and
- (GETJOCTET(data[0]) = $4A) and
- (GETJOCTET(data[1]) = $46) and
- (GETJOCTET(data[2]) = $58) and
- (GETJOCTET(data[3]) = $58) and
- (GETJOCTET(data[4]) = 0) then
- begin
- { Found JFIF "JFXX" extension APP0 marker }
- { The library doesn't actually do anything with these,
- but we try to produce a helpful trace message. }
- {$IFDEF DEBUG}
- case (GETJOCTET(data[5])) of
- $10:
- TRACEMS1(j_common_ptr(cinfo), 1, JTRC_THUMB_JPEG, int(totallen));
- $11:
- TRACEMS1(j_common_ptr(cinfo), 1, JTRC_THUMB_PALETTE, int(totallen));
- $13:
- TRACEMS1(j_common_ptr(cinfo), 1, JTRC_THUMB_RGB, int(totallen));
- else
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_JFIF_EXTENSION,
- GETJOCTET(data[5]), int(totallen));
- end;
- {$ENDIF}
- end
- else
- begin
- { Start of APP0 does not match "JFIF" or "JFXX", or too short }
- {$IFDEF DEBUG}
- TRACEMS1(j_common_ptr(cinfo), 1, JTRC_APP0, int(totallen));
- {$ENDIF}
- end;
-end;
-
-
-{LOCAL}
-procedure examine_app14 (cinfo : j_decompress_ptr;
- var data : array of JOCTET;
- datalen : uint;
- remaining : INT32);
-{ Examine first few bytes from an APP14.
- Take appropriate action if it is an Adobe marker.
- datalen is # of bytes at data[], remaining is length of rest of marker data.
- }
-var
- {$IFDEF DEBUG}
- version, flags0, flags1,
- {$ENDIF}
- transform : uint;
-begin
- if (datalen >= APP14_DATA_LEN) and
- (GETJOCTET(data[0]) = $41) and
- (GETJOCTET(data[1]) = $64) and
- (GETJOCTET(data[2]) = $6F) and
- (GETJOCTET(data[3]) = $62) and
- (GETJOCTET(data[4]) = $65) then
- begin
- { Found Adobe APP14 marker }
- {$IFDEF DEBUG}
- version := (GETJOCTET(data[5]) shl 8) + GETJOCTET(data[6]);
- flags0 := (GETJOCTET(data[7]) shl 8) + GETJOCTET(data[8]);
- flags1 := (GETJOCTET(data[9]) shl 8) + GETJOCTET(data[10]);
- {$ENDIF}
- transform := GETJOCTET(data[11]);
- {$IFDEF DEBUG}
- TRACEMS4(j_common_ptr(cinfo), 1, JTRC_ADOBE, version, flags0, flags1, transform);
- {$ENDIF}
- cinfo^.saw_Adobe_marker := TRUE;
- cinfo^.Adobe_transform := UINT8 (transform);
- end
- else
- begin
- { Start of APP14 does not match "Adobe", or too short }
- {$IFDEF DEBUG}
- TRACEMS1(j_common_ptr(cinfo), 1, JTRC_APP14, int (datalen + remaining));
- {$ENDIF}
- end;
-end;
-
-
-{METHODDEF}
-function get_interesting_appn (cinfo : j_decompress_ptr) : boolean; far;
-{ Process an APP0 or APP14 marker without saving it }
-var
- length : INT32;
- b : array[0..APPN_DATA_LEN-1] of JOCTET;
- i, numtoread : uint;
-var
- datasrc : jpeg_source_mgr_ptr;
- next_input_byte : JOCTETptr;
- bytes_in_buffer : size_t;
-begin
- datasrc := cinfo^.src;
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
-
-{ Read two bytes interpreted as an unsigned 16-bit integer.
- length should be declared unsigned int or perhaps INT32. }
-
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_interesting_appn := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- length := (uint( GETJOCTET(next_input_byte^)) shl 8);
- Inc( next_input_byte );
-
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_interesting_appn := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( length, GETJOCTET(next_input_byte^));
- Inc( next_input_byte );
-
- Dec(length, 2);
-
- { get the interesting part of the marker data }
- if (length >= APPN_DATA_LEN) then
- numtoread := APPN_DATA_LEN
- else
- if (length > 0) then
- numtoread := uint(length)
- else
- numtoread := 0;
- for i := 0 to numtoread-1 do
- begin
- { Read a byte into b[i]. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- get_interesting_appn := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- b[i] := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
- end;
-
- Dec(length, numtoread);
-
- { process it }
- case (cinfo^.unread_marker) of
- M_APP0:
- examine_app0(cinfo, b, numtoread, length);
- M_APP14:
- examine_app14(cinfo, b, numtoread, length);
- else
- { can't get here unless jpeg_save_markers chooses wrong processor }
- ERREXIT1(j_common_ptr(cinfo), JERR_UNKNOWN_MARKER, cinfo^.unread_marker);
- end;
-
- { skip any remaining data -- could be lots }
-
- { Unload the local copies --- do this only at a restart boundary }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- if (length > 0) then
- cinfo^.src^.skip_input_data(cinfo, long(length));
-
- get_interesting_appn := TRUE;
-end;
-
-{$ifdef SAVE_MARKERS_SUPPORTED}
-
-{METHODDEF}
-function save_marker (cinfo : j_decompress_ptr) : boolean; far;
-{ Save an APPn or COM marker into the marker list }
-var
- marker : my_marker_ptr;
- cur_marker : jpeg_saved_marker_ptr;
- bytes_read, data_length : uint;
- data : JOCTET_FIELD_PTR;
- length : INT32;
-var
- datasrc : jpeg_source_mgr_ptr;
- next_input_byte : JOCTETptr;
- bytes_in_buffer : size_t;
-var
- limit : uint;
-var
- prev : jpeg_saved_marker_ptr;
-begin
- { local copies of input pointer/count }
- datasrc := cinfo^.src;
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
-
- marker := my_marker_ptr(cinfo^.marker);
- cur_marker := marker^.cur_marker;
- length := 0;
-
- if (cur_marker = NIL) then
- begin
- { begin reading a marker }
- { Read two bytes interpreted as an unsigned 16-bit integer. }
-
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- save_marker := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- length := (uint( GETJOCTET(next_input_byte^)) shl 8);
- Inc( next_input_byte );
-
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- save_marker := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- Inc( length, GETJOCTET(next_input_byte^));
- Inc( next_input_byte );
-
- Dec(length, 2);
- if (length >= 0) then
- begin { watch out for bogus length word }
- { figure out how much we want to save }
-
- if (cinfo^.unread_marker = int(M_COM)) then
- limit := marker^.length_limit_COM
- else
- limit := marker^.length_limit_APPn[cinfo^.unread_marker - int(M_APP0)];
- if (uint(length) < limit) then
- limit := uint(length);
- { allocate and initialize the marker item }
- cur_marker := jpeg_saved_marker_ptr(
- cinfo^.mem^.alloc_large (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(jpeg_marker_struct) + limit) );
- cur_marker^.next := NIL;
- cur_marker^.marker := UINT8 (cinfo^.unread_marker);
- cur_marker^.original_length := uint(length);
- cur_marker^.data_length := limit;
- { data area is just beyond the jpeg_marker_struct }
- cur_marker^.data := JOCTET_FIELD_PTR(cur_marker);
- Inc(jpeg_saved_marker_ptr(cur_marker^.data));
- data := cur_marker^.data;
-
- marker^.cur_marker := cur_marker;
- marker^.bytes_read := 0;
- bytes_read := 0;
- data_length := limit;
- end
- else
- begin
- { deal with bogus length word }
- data_length := 0;
- bytes_read := 0;
- data := NIL;
- end
- end
- else
- begin
- { resume reading a marker }
- bytes_read := marker^.bytes_read;
- data_length := cur_marker^.data_length;
- data := cur_marker^.data;
- Inc(data, bytes_read);
- end;
-
- while (bytes_read < data_length) do
- begin
- { move the restart point to here }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- marker^.bytes_read := bytes_read;
- { If there's not at least one byte in buffer, suspend }
- if (bytes_in_buffer = 0) then
- begin
- if not datasrc^.fill_input_buffer (cinfo) then
- begin
- save_marker := FALSE;
- exit;
- end;
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
-
- { Copy bytes with reasonable rapidity }
- while (bytes_read < data_length) and (bytes_in_buffer > 0) do
- begin
- JOCTETPTR(data)^ := next_input_byte^;
- Inc(JOCTETPTR(data));
- Inc(next_input_byte);
- Dec(bytes_in_buffer);
- Inc(bytes_read);
- end;
- end;
-
- { Done reading what we want to read }
- if (cur_marker <> NIL) then
- begin { will be NIL if bogus length word }
- { Add new marker to end of list }
- if (cinfo^.marker_list = NIL) then
- begin
- cinfo^.marker_list := cur_marker
- end
- else
- begin
- prev := cinfo^.marker_list;
- while (prev^.next <> NIL) do
- prev := prev^.next;
- prev^.next := cur_marker;
- end;
- { Reset pointer & calc remaining data length }
- data := cur_marker^.data;
- length := cur_marker^.original_length - data_length;
- end;
- { Reset to initial state for next marker }
- marker^.cur_marker := NIL;
-
- { Process the marker if interesting; else just make a generic trace msg }
- case (cinfo^.unread_marker) of
- M_APP0:
- examine_app0(cinfo, data^, data_length, length);
- M_APP14:
- examine_app14(cinfo, data^, data_length, length);
- else
- {$IFDEF DEBUG}
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_MISC_MARKER, cinfo^.unread_marker,
- int(data_length + length));
- {$ENDIF}
- end;
-
- { skip any remaining data -- could be lots }
- { do before skip_input_data }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- if (length > 0) then
- cinfo^.src^.skip_input_data (cinfo, long(length) );
-
- save_marker := TRUE;
-end;
-
-{$endif} { SAVE_MARKERS_SUPPORTED }
-
-
-{ Find the next JPEG marker, save it in cinfo^.unread_marker.
- Returns FALSE if had to suspend before reaching a marker;
- in that case cinfo^.unread_marker is unchanged.
-
- Note that the result might not be a valid marker code,
- but it will never be 0 or FF. }
-
-{LOCAL}
-function next_marker (cinfo : j_decompress_ptr) : boolean;
-var
- c : int;
-var
- datasrc : jpeg_source_mgr_ptr;
- next_input_byte : JOCTETptr;
- bytes_in_buffer : size_t;
-begin
- datasrc := cinfo^.src;
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
-
- {while TRUE do}
- repeat
- { Read a byte into variable c. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- next_marker := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- c := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- { Skip any non-FF bytes.
- This may look a bit inefficient, but it will not occur in a valid file.
- We sync after each discarded byte so that a suspending data source
- can discard the byte from its buffer. }
-
- while (c <> $FF) do
- begin
- Inc(cinfo^.marker^.discarded_bytes);
- { Unload the local copies --- do this only at a restart boundary }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- { Read a byte into variable c. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- next_marker := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- c := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- end;
- { This loop swallows any duplicate FF bytes. Extra FFs are legal as
- pad bytes, so don't count them in discarded_bytes. We assume there
- will not be so many consecutive FF bytes as to overflow a suspending
- data source's input buffer. }
-
- repeat
- { Read a byte into variable c. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- next_marker := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- c := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
- Until (c <> $FF);
- if (c <> 0) then
- break; { found a valid marker, exit loop }
- { Reach here if we found a stuffed-zero data sequence (FF/00).
- Discard it and loop back to try again. }
-
- Inc(cinfo^.marker^.discarded_bytes, 2);
- { Unload the local copies --- do this only at a restart boundary }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
- Until False;
-
- if (cinfo^.marker^.discarded_bytes <> 0) then
- begin
- WARNMS2(j_common_ptr(cinfo), JWRN_EXTRANEOUS_DATA,
- cinfo^.marker^.discarded_bytes, c);
- cinfo^.marker^.discarded_bytes := 0;
- end;
-
- cinfo^.unread_marker := c;
-
- { Unload the local copies --- do this only at a restart boundary }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- next_marker := TRUE;
-end; { next_marker }
-
-
-{LOCAL}
-function first_marker (cinfo : j_decompress_ptr) : boolean;
-{ Like next_marker, but used to obtain the initial SOI marker. }
-{ For this marker, we do not allow preceding garbage or fill; otherwise,
- we might well scan an entire input file before realizing it ain't JPEG.
- If an application wants to process non-JFIF files, it must seek to the
- SOI before calling the JPEG library. }
-var
- c, c2 : int;
-var
- datasrc : jpeg_source_mgr_ptr;
- next_input_byte : JOCTETptr;
- bytes_in_buffer : size_t;
-begin
- datasrc := cinfo^.src;
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
-
- { Read a byte into variable c. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- first_marker := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- c := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- { Read a byte into variable c2. If must suspend, return FALSE. }
- { make a byte available.
- Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
- but we must reload the local copies after a successful fill. }
- if (bytes_in_buffer = 0) then
- begin
- if (not datasrc^.fill_input_buffer(cinfo)) then
- begin
- first_marker := FALSE;
- exit;
- end;
- { Reload the local copies }
- next_input_byte := datasrc^.next_input_byte;
- bytes_in_buffer := datasrc^.bytes_in_buffer;
- end;
- Dec( bytes_in_buffer );
-
- c2 := GETJOCTET(next_input_byte^);
- Inc(next_input_byte);
-
- if (c <> $FF) or (c2 <> int(M_SOI)) then
- ERREXIT2(j_common_ptr(cinfo), JERR_NO_SOI, c, c2);
-
- cinfo^.unread_marker := c2;
-
- { Unload the local copies --- do this only at a restart boundary }
- datasrc^.next_input_byte := next_input_byte;
- datasrc^.bytes_in_buffer := bytes_in_buffer;
-
- first_marker := TRUE;
-end; { first_marker }
-
-
-{ Read markers until SOS or EOI.
-
- Returns same codes as are defined for jpeg_consume_input:
- JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. }
-
-{METHODDEF}
-function read_markers (cinfo : j_decompress_ptr) : int; far;
-begin
- { Outer loop repeats once for each marker. }
- repeat
- { Collect the marker proper, unless we already did. }
- { NB: first_marker() enforces the requirement that SOI appear first. }
- if (cinfo^.unread_marker = 0) then
- begin
- if not cinfo^.marker^.saw_SOI then
- begin
- if not first_marker(cinfo) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
- end
- else
- begin
- if not next_marker(cinfo) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
- end;
- end;
- { At this point cinfo^.unread_marker contains the marker code and the
- input point is just past the marker proper, but before any parameters.
- A suspension will cause us to return with this state still true. }
-
- case (cinfo^.unread_marker) of
- M_SOI:
- if not get_soi(cinfo) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
-
- M_SOF0, { Baseline }
- M_SOF1: { Extended sequential, Huffman }
- if not get_sof(cinfo, FALSE, FALSE) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
- M_SOF2: { Progressive, Huffman }
- if not get_sof(cinfo, TRUE, FALSE) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
-
- M_SOF9: { Extended sequential, arithmetic }
- if not get_sof(cinfo, FALSE, TRUE) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
-
- M_SOF10: { Progressive, arithmetic }
- if not get_sof(cinfo, TRUE, TRUE) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
-
- { Currently unsupported SOFn types }
- M_SOF3, { Lossless, Huffman }
- M_SOF5, { Differential sequential, Huffman }
- M_SOF6, { Differential progressive, Huffman }
- M_SOF7, { Differential lossless, Huffman }
- M_JPG, { Reserved for JPEG extensions }
- M_SOF11, { Lossless, arithmetic }
- M_SOF13, { Differential sequential, arithmetic }
- M_SOF14, { Differential progressive, arithmetic }
- M_SOF15: { Differential lossless, arithmetic }
- ERREXIT1(j_common_ptr(cinfo), JERR_SOF_UNSUPPORTED, cinfo^.unread_marker);
-
- M_SOS:
- begin
- if not get_sos(cinfo) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
- cinfo^.unread_marker := 0; { processed the marker }
- read_markers := JPEG_REACHED_SOS;
- exit;
- end;
-
- M_EOI:
- begin
- {$IFDEF DEBUG}
- TRACEMS(j_common_ptr(cinfo), 1, JTRC_EOI);
- {$ENDIF}
- cinfo^.unread_marker := 0; { processed the marker }
- read_markers := JPEG_REACHED_EOI;
- exit;
- end;
-
- M_DAC:
- if not get_dac(cinfo) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
-
- M_DHT:
- if not get_dht(cinfo) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
-
- M_DQT:
- if not get_dqt(cinfo) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
-
- M_DRI:
- if not get_dri(cinfo) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
-
- M_APP0,
- M_APP1,
- M_APP2,
- M_APP3,
- M_APP4,
- M_APP5,
- M_APP6,
- M_APP7,
- M_APP8,
- M_APP9,
- M_APP10,
- M_APP11,
- M_APP12,
- M_APP13,
- M_APP14,
- M_APP15:
- if not my_marker_ptr(cinfo^.marker)^.
- process_APPn[cinfo^.unread_marker - int(M_APP0)](cinfo) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
-
- M_COM:
- if not my_marker_ptr(cinfo^.marker)^.process_COM (cinfo) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
-
- M_RST0, { these are all parameterless }
- M_RST1,
- M_RST2,
- M_RST3,
- M_RST4,
- M_RST5,
- M_RST6,
- M_RST7,
- M_TEM:
- {$IFDEF DEBUG}
- TRACEMS1(j_common_ptr(cinfo), 1, JTRC_PARMLESS_MARKER,
- cinfo^.unread_marker)
- {$ENDIF}
- ;
-
- M_DNL: { Ignore DNL ... perhaps the wrong thing }
- if not skip_variable(cinfo) then
- begin
- read_markers := JPEG_SUSPENDED;
- exit;
- end;
-
- else { must be DHP, EXP, JPGn, or RESn }
- { For now, we treat the reserved markers as fatal errors since they are
- likely to be used to signal incompatible JPEG Part 3 extensions.
- Once the JPEG 3 version-number marker is well defined, this code
- ought to change! }
- ERREXIT1(j_common_ptr(cinfo) , JERR_UNKNOWN_MARKER,
- cinfo^.unread_marker);
- end; { end of case }
- { Successfully processed marker, so reset state variable }
- cinfo^.unread_marker := 0;
- Until false;
-end; { read_markers }
-
-
-{ Read a restart marker, which is expected to appear next in the datastream;
- if the marker is not there, take appropriate recovery action.
- Returns FALSE if suspension is required.
-
- This is called by the entropy decoder after it has read an appropriate
- number of MCUs. cinfo^.unread_marker may be nonzero if the entropy decoder
- has already read a marker from the data source. Under normal conditions
- cinfo^.unread_marker will be reset to 0 before returning; if not reset,
- it holds a marker which the decoder will be unable to read past. }
-
-{METHODDEF}
-function read_restart_marker (cinfo : j_decompress_ptr) :boolean; far;
-begin
- { Obtain a marker unless we already did. }
- { Note that next_marker will complain if it skips any data. }
- if (cinfo^.unread_marker = 0) then
- begin
- if not next_marker(cinfo) then
- begin
- read_restart_marker := FALSE;
- exit;
- end;
- end;
-
- if (cinfo^.unread_marker = (int(M_RST0) + cinfo^.marker^.next_restart_num)) then
- begin
- { Normal case --- swallow the marker and let entropy decoder continue }
- {$IFDEF DEBUG}
- TRACEMS1(j_common_ptr(cinfo), 3, JTRC_RST,
- cinfo^.marker^.next_restart_num);
- {$ENDIF}
- cinfo^.unread_marker := 0;
- end
- else
- begin
- { Uh-oh, the restart markers have been messed up. }
- { Let the data source manager determine how to resync. }
- if not cinfo^.src^.resync_to_restart(cinfo,
- cinfo^.marker^.next_restart_num) then
- begin
- read_restart_marker := FALSE;
- exit;
- end;
- end;
-
- { Update next-restart state }
- with cinfo^.marker^ do
- next_restart_num := (next_restart_num + 1) and 7;
-
- read_restart_marker := TRUE;
-end; { read_restart_marker }
-
-
-{ This is the default resync_to_restart method for data source managers
- to use if they don't have any better approach. Some data source managers
- may be able to back up, or may have additional knowledge about the data
- which permits a more intelligent recovery strategy; such managers would
- presumably supply their own resync method.
-
- read_restart_marker calls resync_to_restart if it finds a marker other than
- the restart marker it was expecting. (This code is *not* used unless
- a nonzero restart interval has been declared.) cinfo^.unread_marker is
- the marker code actually found (might be anything, except 0 or FF).
- The desired restart marker number (0..7) is passed as a parameter.
- This routine is supposed to apply whatever error recovery strategy seems
- appropriate in order to position the input stream to the next data segment.
- Note that cinfo^.unread_marker is treated as a marker appearing before
- the current data-source input point; usually it should be reset to zero
- before returning.
- Returns FALSE if suspension is required.
-
- This implementation is substantially constrained by wanting to treat the
- input as a data stream; this means we can't back up. Therefore, we have
- only the following actions to work with:
- 1. Simply discard the marker and let the entropy decoder resume at next
- byte of file.
- 2. Read forward until we find another marker, discarding intervening
- data. (In theory we could look ahead within the current bufferload,
- without having to discard data if we don't find the desired marker.
- This idea is not implemented here, in part because it makes behavior
- dependent on buffer size and chance buffer-boundary positions.)
- 3. Leave the marker unread (by failing to zero cinfo^.unread_marker).
- This will cause the entropy decoder to process an empty data segment,
- inserting dummy zeroes, and then we will reprocess the marker.
-
- #2 is appropriate if we think the desired marker lies ahead, while #3 is
- appropriate if the found marker is a future restart marker (indicating
- that we have missed the desired restart marker, probably because it got
- corrupted).
- We apply #2 or #3 if the found marker is a restart marker no more than
- two counts behind or ahead of the expected one. We also apply #2 if the
- found marker is not a legal JPEG marker code (it's certainly bogus data).
- If the found marker is a restart marker more than 2 counts away, we do #1
- (too much risk that the marker is erroneous; with luck we will be able to
- resync at some future point).
- For any valid non-restart JPEG marker, we apply #3. This keeps us from
- overrunning the end of a scan. An implementation limited to single-scan
- files might find it better to apply #2 for markers other than EOI, since
- any other marker would have to be bogus data in that case. }
-
-
-{GLOBAL}
-function jpeg_resync_to_restart(cinfo : j_decompress_ptr;
- desired : int) : boolean;
-var
- marker : int;
- action : int;
-begin
- marker := cinfo^.unread_marker;
- action := 1; { never used }
- { Always put up a warning. }
- WARNMS2(j_common_ptr(cinfo), JWRN_MUST_RESYNC, marker, desired);
-
- { Outer loop handles repeated decision after scanning forward. }
- repeat
- if (marker < int(M_SOF0)) then
- action := 2 { invalid marker }
- else
- if (marker < int(M_RST0)) or (marker > int(M_RST7)) then
- action := 3 { valid non-restart marker }
- else
- begin
- if (marker = (int(M_RST0) + ((desired+1) and 7))) or
- (marker = (int(M_RST0) + ((desired+2) and 7))) then
- action := 3 { one of the next two expected restarts }
- else
- if (marker = (int(M_RST0) + ((desired-1) and 7))) or
- (marker = (int(M_RST0) + ((desired-2) and 7))) then
- action := 2 { a prior restart, so advance }
- else
- action := 1; { desired restart or too far away }
- end;
-
- {$IFDEF DEBUG}
- TRACEMS2(j_common_ptr(cinfo), 4, JTRC_RECOVERY_ACTION, marker, action);
- {$ENDIF}
- case action of
- 1:
- { Discard marker and let entropy decoder resume processing. }
- begin
- cinfo^.unread_marker := 0;
- jpeg_resync_to_restart := TRUE;
- exit;
- end;
- 2:
- { Scan to the next marker, and repeat the decision loop. }
- begin
- if not next_marker(cinfo) then
- begin
- jpeg_resync_to_restart := FALSE;
- exit;
- end;
- marker := cinfo^.unread_marker;
- end;
- 3:
- { Return without advancing past this marker. }
- { Entropy decoder will be forced to process an empty segment. }
- begin
- jpeg_resync_to_restart := TRUE;
- exit;
- end;
- end; { case }
- Until false; { end loop }
-end; { jpeg_resync_to_restart }
-
-
-{ Reset marker processing state to begin a fresh datastream. }
-
-{METHODDEF}
-procedure reset_marker_reader (cinfo : j_decompress_ptr); far;
-var
- marker : my_marker_ptr;
-begin
- marker := my_marker_ptr (cinfo^.marker);
- with cinfo^ do
- begin
- comp_info := NIL; { until allocated by get_sof }
- input_scan_number := 0; { no SOS seen yet }
- unread_marker := 0; { no pending marker }
- end;
- marker^.pub.saw_SOI := FALSE; { set internal state too }
- marker^.pub.saw_SOF := FALSE;
- marker^.pub.discarded_bytes := 0;
- marker^.cur_marker := NIL;
-end; { reset_marker_reader }
-
-
-{ Initialize the marker reader module.
- This is called only once, when the decompression object is created. }
-
-{GLOBAL}
-procedure jinit_marker_reader (cinfo : j_decompress_ptr);
-var
- marker : my_marker_ptr;
- i : int;
-begin
- { Create subobject in permanent pool }
- marker := my_marker_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_PERMANENT,
- SIZEOF(my_marker_reader))
- );
- cinfo^.marker := jpeg_marker_reader_ptr(marker);
- { Initialize method pointers }
- marker^.pub.reset_marker_reader := reset_marker_reader;
- marker^.pub.read_markers := read_markers;
- marker^.pub.read_restart_marker := read_restart_marker;
- { Initialize COM/APPn processing.
- By default, we examine and then discard APP0 and APP14,
- but simply discard COM and all other APPn. }
-
- marker^.process_COM := skip_variable;
- marker^.length_limit_COM := 0;
- for i := 0 to 16-1 do
- begin
- marker^.process_APPn[i] := skip_variable;
- marker^.length_limit_APPn[i] := 0;
- end;
- marker^.process_APPn[0] := get_interesting_appn;
- marker^.process_APPn[14] := get_interesting_appn;
- { Reset marker processing state }
- reset_marker_reader(cinfo);
-end; { jinit_marker_reader }
-
-
-{ Control saving of COM and APPn markers into marker_list. }
-
-
-{$ifdef SAVE_MARKERS_SUPPORTED}
-
-{GLOBAL}
-procedure jpeg_save_markers (cinfo : j_decompress_ptr;
- marker_code : int;
- length_limit : uint);
-var
- marker : my_marker_ptr;
- maxlength : long;
- processor : jpeg_marker_parser_method;
-begin
- marker := my_marker_ptr (cinfo^.marker);
-
- { Length limit mustn't be larger than what we can allocate
- (should only be a concern in a 16-bit environment). }
-
- maxlength := cinfo^.mem^.max_alloc_chunk - SIZEOF(jpeg_marker_struct);
- if (long(length_limit) > maxlength) then
- length_limit := uint(maxlength);
-
- { Choose processor routine to use.
- APP0/APP14 have special requirements. }
-
- if (length_limit <> 0) then
- begin
- processor := save_marker;
- { If saving APP0/APP14, save at least enough for our internal use. }
- if (marker_code = int(M_APP0)) and (length_limit < APP0_DATA_LEN) then
- length_limit := APP0_DATA_LEN
- else
- if (marker_code = int(M_APP14)) and (length_limit < APP14_DATA_LEN) then
- length_limit := APP14_DATA_LEN;
- end
- else
- begin
- processor := skip_variable;
- { If discarding APP0/APP14, use our regular on-the-fly processor. }
- if (marker_code = int(M_APP0)) or (marker_code = int(M_APP14)) then
- processor := get_interesting_appn;
- end;
-
- if (marker_code = int(M_COM)) then
- begin
- marker^.process_COM := processor;
- marker^.length_limit_COM := length_limit;
- end
- else
- if (marker_code >= int(M_APP0)) and (marker_code <= int(M_APP15)) then
- begin
- marker^.process_APPn[marker_code - int(M_APP0)] := processor;
- marker^.length_limit_APPn[marker_code - int(M_APP0)] := length_limit;
- end
- else
- ERREXIT1(j_common_ptr(cinfo), JERR_UNKNOWN_MARKER, marker_code);
-end;
-
-{$endif} { SAVE_MARKERS_SUPPORTED }
-
-{ Install a special processing method for COM or APPn markers. }
-
-{GLOBAL}
-
-procedure jpeg_set_marker_processor (cinfo : j_decompress_ptr;
- marker_code : int;
- routine : jpeg_marker_parser_method);
-var
- marker : my_marker_ptr;
-begin
- marker := my_marker_ptr (cinfo^.marker);
- if (marker_code = int(M_COM)) then
- marker^.process_COM := routine
- else
- if (marker_code >= int(M_APP0)) and (marker_code <= int(M_APP15)) then
- marker^.process_APPn[marker_code - int(M_APP0)] := routine
- else
- ERREXIT1(j_common_ptr(cinfo), JERR_UNKNOWN_MARKER, marker_code);
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdmaster.pas b/packages/base/pasjpeg/jdmaster.pas
deleted file mode 100644
index 0206c48211..0000000000
--- a/packages/base/pasjpeg/jdmaster.pas
+++ /dev/null
@@ -1,678 +0,0 @@
-Unit JdMaster;
-
-{ This file contains master control logic for the JPEG decompressor.
- These routines are concerned with selecting the modules to be executed
- and with determining the number of passes and the work to be done in each
- pass. }
-
-{ Original: jdmaster.c ; Copyright (C) 1991-1998, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jutils,
- jerror,
- jdeferr,
- jdcolor, jdsample, jdpostct, jddctmgr, jdphuff, jdhuff, jdcoefct, jdmainct,
-{$ifdef QUANT_1PASS_SUPPORTED}
- jquant1,
-{$endif}
-{$ifdef QUANT_2PASS_SUPPORTED}
- jquant2,
-{$endif}
-{$ifdef UPSAMPLE_MERGING_SUPPORTED}
- jdmerge,
-{$endif}
- jpeglib;
-
-
-{ Compute output image dimensions and related values.
- NOTE: this is exported for possible use by application.
- Hence it mustn't do anything that can't be done twice.
- Also note that it may be called before the master module is initialized! }
-
-{GLOBAL}
-procedure jpeg_calc_output_dimensions (cinfo : j_decompress_ptr);
-{ Do computations that are needed before master selection phase }
-
-
-{$ifdef D_MULTISCAN_FILES_SUPPORTED}
-
-{GLOBAL}
-procedure jpeg_new_colormap (cinfo : j_decompress_ptr);
-
-{$endif}
-
-{ Initialize master decompression control and select active modules.
- This is performed at the start of jpeg_start_decompress. }
-
-{GLOBAL}
-procedure jinit_master_decompress (cinfo : j_decompress_ptr);
-
-implementation
-
-{ Private state }
-
-type
- my_master_ptr = ^my_decomp_master;
- my_decomp_master = record
- pub : jpeg_decomp_master; { public fields }
-
- pass_number : int; { # of passes completed }
-
- using_merged_upsample : boolean; { TRUE if using merged upsample/cconvert }
-
- { Saved references to initialized quantizer modules,
- in case we need to switch modes. }
-
- quantizer_1pass : jpeg_color_quantizer_ptr;
- quantizer_2pass : jpeg_color_quantizer_ptr;
- end;
-
-{ Determine whether merged upsample/color conversion should be used.
- CRUCIAL: this must match the actual capabilities of jdmerge.c! }
-
-{LOCAL}
-function use_merged_upsample (cinfo : j_decompress_ptr) : boolean;
-var
- compptr : jpeg_component_info_list_ptr;
-begin
- compptr := cinfo^.comp_info;
-
-{$ifdef UPSAMPLE_MERGING_SUPPORTED}
- { Merging is the equivalent of plain box-filter upsampling }
- if (cinfo^.do_fancy_upsampling) or (cinfo^.CCIR601_sampling) then
- begin
- use_merged_upsample := FALSE;
- exit;
- end;
- { jdmerge.c only supports YCC=>RGB color conversion }
- if (cinfo^.jpeg_color_space <> JCS_YCbCr) or (cinfo^.num_components <> 3)
- or (cinfo^.out_color_space <> JCS_RGB)
- or (cinfo^.out_color_components <> RGB_PIXELSIZE) then
- begin
- use_merged_upsample := FALSE;
- exit;
- end;
-
- { and it only handles 2h1v or 2h2v sampling ratios }
- if (compptr^[0].h_samp_factor <> 2) or
- (compptr^[1].h_samp_factor <> 1) or
- (compptr^[2].h_samp_factor <> 1) or
- (compptr^[0].v_samp_factor > 2) or
- (compptr^[1].v_samp_factor <> 1) or
- (compptr^[2].v_samp_factor <> 1) then
- begin
- use_merged_upsample := FALSE;
- exit;
- end;
- { furthermore, it doesn't work if we've scaled the IDCTs differently }
- if (compptr^[0].DCT_scaled_size <> cinfo^.min_DCT_scaled_size) or
- (compptr^[1].DCT_scaled_size <> cinfo^.min_DCT_scaled_size) or
- (compptr^[2].DCT_scaled_size <> cinfo^.min_DCT_scaled_size) then
- begin
- use_merged_upsample := FALSE;
- exit;
- end;
- { ??? also need to test for upsample-time rescaling, when & if supported }
- use_merged_upsample := TRUE; { by golly, it'll work... }
-{$else}
- use_merged_upsample := FALSE;
-{$endif}
-end;
-
-
-{ Compute output image dimensions and related values.
- NOTE: this is exported for possible use by application.
- Hence it mustn't do anything that can't be done twice.
- Also note that it may be called before the master module is initialized! }
-
-{GLOBAL}
-procedure jpeg_calc_output_dimensions (cinfo : j_decompress_ptr);
-{ Do computations that are needed before master selection phase }
-{$ifdef IDCT_SCALING_SUPPORTED}
-var
- ci : int;
- compptr : jpeg_component_info_ptr;
-{$endif}
-var
- ssize : int;
-begin
- { Prevent application from calling me at wrong times }
- if (cinfo^.global_state <> DSTATE_READY) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
-
-{$ifdef IDCT_SCALING_SUPPORTED}
-
- { Compute actual output image dimensions and DCT scaling choices. }
- if (cinfo^.scale_num * 8 <= cinfo^.scale_denom) then
- begin
- { Provide 1/8 scaling }
- cinfo^.output_width := JDIMENSION (
- jdiv_round_up( long(cinfo^.image_width), long(8)) );
- cinfo^.output_height := JDIMENSION (
- jdiv_round_up( long(cinfo^.image_height), long(8)) );
- cinfo^.min_DCT_scaled_size := 1;
- end
- else
- if (cinfo^.scale_num * 4 <= cinfo^.scale_denom) then
- begin
- { Provide 1/4 scaling }
- cinfo^.output_width := JDIMENSION (
- jdiv_round_up( long (cinfo^.image_width), long(4)) );
- cinfo^.output_height := JDIMENSION (
- jdiv_round_up( long (cinfo^.image_height), long(4)) );
- cinfo^.min_DCT_scaled_size := 2;
- end
- else
- if (cinfo^.scale_num * 2 <= cinfo^.scale_denom) then
- begin
- { Provide 1/2 scaling }
- cinfo^.output_width := JDIMENSION (
- jdiv_round_up( long(cinfo^.image_width), long(2)) );
- cinfo^.output_height := JDIMENSION (
- jdiv_round_up( long(cinfo^.image_height), long(2)) );
- cinfo^.min_DCT_scaled_size := 4;
- end
- else
- begin
- { Provide 1/1 scaling }
- cinfo^.output_width := cinfo^.image_width;
- cinfo^.output_height := cinfo^.image_height;
- cinfo^.min_DCT_scaled_size := DCTSIZE;
- end;
- { In selecting the actual DCT scaling for each component, we try to
- scale up the chroma components via IDCT scaling rather than upsampling.
- This saves time if the upsampler gets to use 1:1 scaling.
- Note this code assumes that the supported DCT scalings are powers of 2. }
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- ssize := cinfo^.min_DCT_scaled_size;
- while (ssize < DCTSIZE) and
- ((compptr^.h_samp_factor * ssize * 2 <=
- cinfo^.max_h_samp_factor * cinfo^.min_DCT_scaled_size) and
- (compptr^.v_samp_factor * ssize * 2 <=
- cinfo^.max_v_samp_factor * cinfo^.min_DCT_scaled_size)) do
- begin
- ssize := ssize * 2;
- end;
- compptr^.DCT_scaled_size := ssize;
- Inc(compptr);
- end;
-
- { Recompute downsampled dimensions of components;
- application needs to know these if using raw downsampled data. }
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- { Size in samples, after IDCT scaling }
- compptr^.downsampled_width := JDIMENSION (
- jdiv_round_up(long (cinfo^.image_width) *
- long (compptr^.h_samp_factor * compptr^.DCT_scaled_size),
- long (cinfo^.max_h_samp_factor * DCTSIZE)) );
- compptr^.downsampled_height := JDIMENSION (
- jdiv_round_up(long (cinfo^.image_height) *
- long (compptr^.v_samp_factor * compptr^.DCT_scaled_size),
- long (cinfo^.max_v_samp_factor * DCTSIZE)) );
- Inc(compptr);
- end;
-
-{$else} { !IDCT_SCALING_SUPPORTED }
-
- { Hardwire it to "no scaling" }
- cinfo^.output_width := cinfo^.image_width;
- cinfo^.output_height := cinfo^.image_height;
- { jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
- and has computed unscaled downsampled_width and downsampled_height. }
-
-{$endif} { IDCT_SCALING_SUPPORTED }
-
- { Report number of components in selected colorspace. }
- { Probably this should be in the color conversion module... }
- case (cinfo^.out_color_space) of
- JCS_GRAYSCALE:
- cinfo^.out_color_components := 1;
-{$ifndef RGB_PIXELSIZE_IS_3}
- JCS_RGB:
- cinfo^.out_color_components := RGB_PIXELSIZE;
-{$else}
- JCS_RGB,
-{$endif} { else share code with YCbCr }
- JCS_YCbCr:
- cinfo^.out_color_components := 3;
- JCS_CMYK,
- JCS_YCCK:
- cinfo^.out_color_components := 4;
- else { else must be same colorspace as in file }
- cinfo^.out_color_components := cinfo^.num_components;
- end;
- if (cinfo^.quantize_colors) then
- cinfo^.output_components := 1
- else
- cinfo^.output_components := cinfo^.out_color_components;
-
- { See if upsampler will want to emit more than one row at a time }
- if (use_merged_upsample(cinfo)) then
- cinfo^.rec_outbuf_height := cinfo^.max_v_samp_factor
- else
- cinfo^.rec_outbuf_height := 1;
-end;
-
-
-{ Several decompression processes need to range-limit values to the range
- 0..MAXJSAMPLE; the input value may fall somewhat outside this range
- due to noise introduced by quantization, roundoff error, etc. These
- processes are inner loops and need to be as fast as possible. On most
- machines, particularly CPUs with pipelines or instruction prefetch,
- a (subscript-check-less) C table lookup
- x := sample_range_limit[x];
- is faster than explicit tests
- if (x < 0) x := 0;
- else if (x > MAXJSAMPLE) x := MAXJSAMPLE;
- These processes all use a common table prepared by the routine below.
-
- For most steps we can mathematically guarantee that the initial value
- of x is within MAXJSAMPLE+1 of the legal range, so a table running from
- -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial
- limiting step (just after the IDCT), a wildly out-of-range value is
- possible if the input data is corrupt. To avoid any chance of indexing
- off the end of memory and getting a bad-pointer trap, we perform the
- post-IDCT limiting thus:
- x := range_limit[x & MASK];
- where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit
- samples. Under normal circumstances this is more than enough range and
- a correct output will be generated; with bogus input data the mask will
- cause wraparound, and we will safely generate a bogus-but-in-range output.
- For the post-IDCT step, we want to convert the data from signed to unsigned
- representation by adding CENTERJSAMPLE at the same time that we limit it.
- So the post-IDCT limiting table ends up looking like this:
- CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE,
- MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
- 0 (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
- 0,1,...,CENTERJSAMPLE-1
- Negative inputs select values from the upper half of the table after
- masking.
-
- We can save some space by overlapping the start of the post-IDCT table
- with the simpler range limiting table. The post-IDCT table begins at
- sample_range_limit + CENTERJSAMPLE.
-
- Note that the table is allocated in near data space on PCs; it's small
- enough and used often enough to justify this. }
-
-{LOCAL}
-procedure prepare_range_limit_table (cinfo : j_decompress_ptr);
-{ Allocate and fill in the sample_range_limit table }
-var
- table : range_limit_table_ptr;
- idct_table : JSAMPROW;
- i : int;
-begin
- table := range_limit_table_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE)) );
-
- { First segment of "simple" table: limit[x] := 0 for x < 0 }
- MEMZERO(table, (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
-
- cinfo^.sample_range_limit := (table);
- { allow negative subscripts of simple table }
- { is noop, handled via type definition (Nomssi) }
- { Main part of "simple" table: limit[x] := x }
- for i := 0 to MAXJSAMPLE do
- table^[i] := JSAMPLE (i);
- idct_table := JSAMPROW(@ table^[CENTERJSAMPLE]);
- { Point to where post-IDCT table starts }
- { End of simple table, rest of first half of post-IDCT table }
- for i := CENTERJSAMPLE to pred(2*(MAXJSAMPLE+1)) do
- idct_table^[i] := MAXJSAMPLE;
- { Second half of post-IDCT table }
- MEMZERO(@(idct_table^[2 * (MAXJSAMPLE+1)]),
- (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
- MEMCOPY(@(idct_table^[(4 * (MAXJSAMPLE+1) - CENTERJSAMPLE)]),
- @cinfo^.sample_range_limit^[0], CENTERJSAMPLE * SIZEOF(JSAMPLE));
-
-end;
-
-
-{ Master selection of decompression modules.
- This is done once at jpeg_start_decompress time. We determine
- which modules will be used and give them appropriate initialization calls.
- We also initialize the decompressor input side to begin consuming data.
-
- Since jpeg_read_header has finished, we know what is in the SOF
- and (first) SOS markers. We also have all the application parameter
- settings. }
-
-{LOCAL}
-procedure master_selection (cinfo : j_decompress_ptr);
-var
- master : my_master_ptr;
- use_c_buffer : boolean;
- samplesperrow : long;
- jd_samplesperrow : JDIMENSION;
-var
- nscans : int;
-begin
- master := my_master_ptr (cinfo^.master);
-
- { Initialize dimensions and other stuff }
- jpeg_calc_output_dimensions(cinfo);
- prepare_range_limit_table(cinfo);
-
- { Width of an output scanline must be representable as JDIMENSION. }
- samplesperrow := long(cinfo^.output_width) * long (cinfo^.out_color_components);
- jd_samplesperrow := JDIMENSION (samplesperrow);
- if (long(jd_samplesperrow) <> samplesperrow) then
- ERREXIT(j_common_ptr(cinfo), JERR_WIDTH_OVERFLOW);
-
- { Initialize my private state }
- master^.pass_number := 0;
- master^.using_merged_upsample := use_merged_upsample(cinfo);
-
- { Color quantizer selection }
- master^.quantizer_1pass := NIL;
- master^.quantizer_2pass := NIL;
- { No mode changes if not using buffered-image mode. }
- if (not cinfo^.quantize_colors) or (not cinfo^.buffered_image) then
- begin
- cinfo^.enable_1pass_quant := FALSE;
- cinfo^.enable_external_quant := FALSE;
- cinfo^.enable_2pass_quant := FALSE;
- end;
- if (cinfo^.quantize_colors) then
- begin
- if (cinfo^.raw_data_out) then
- ERREXIT(j_common_ptr(cinfo), JERR_NOTIMPL);
- { 2-pass quantizer only works in 3-component color space. }
- if (cinfo^.out_color_components <> 3) then
- begin
- cinfo^.enable_1pass_quant := TRUE;
- cinfo^.enable_external_quant := FALSE;
- cinfo^.enable_2pass_quant := FALSE;
- cinfo^.colormap := NIL;
- end
- else
- if (cinfo^.colormap <> NIL) then
- begin
- cinfo^.enable_external_quant := TRUE;
- end
- else
- if (cinfo^.two_pass_quantize) then
- begin
- cinfo^.enable_2pass_quant := TRUE;
- end
- else
- begin
- cinfo^.enable_1pass_quant := TRUE;
- end;
-
- if (cinfo^.enable_1pass_quant) then
- begin
-{$ifdef QUANT_1PASS_SUPPORTED}
- jinit_1pass_quantizer(cinfo);
- master^.quantizer_1pass := cinfo^.cquantize;
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end;
-
- { We use the 2-pass code to map to external colormaps. }
- if (cinfo^.enable_2pass_quant) or (cinfo^.enable_external_quant) then
- begin
-{$ifdef QUANT_2PASS_SUPPORTED}
- jinit_2pass_quantizer(cinfo);
- master^.quantizer_2pass := cinfo^.cquantize;
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end;
- { If both quantizers are initialized, the 2-pass one is left active;
- this is necessary for starting with quantization to an external map. }
- end;
-
- { Post-processing: in particular, color conversion first }
- if (not cinfo^.raw_data_out) then
- begin
- if (master^.using_merged_upsample) then
- begin
-{$ifdef UPSAMPLE_MERGING_SUPPORTED}
- jinit_merged_upsampler(cinfo); { does color conversion too }
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end
- else
- begin
- jinit_color_deconverter(cinfo);
- jinit_upsampler(cinfo);
- end;
- jinit_d_post_controller(cinfo, cinfo^.enable_2pass_quant);
- end;
- { Inverse DCT }
- jinit_inverse_dct(cinfo);
- { Entropy decoding: either Huffman or arithmetic coding. }
- if (cinfo^.arith_code) then
- begin
- ERREXIT(j_common_ptr(cinfo), JERR_ARITH_NOTIMPL);
- end
- else
- begin
- if (cinfo^.progressive_mode) then
- begin
-{$ifdef D_PROGRESSIVE_SUPPORTED}
- jinit_phuff_decoder(cinfo);
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end
- else
- jinit_huff_decoder(cinfo);
- end;
-
- { Initialize principal buffer controllers. }
- use_c_buffer := cinfo^.inputctl^.has_multiple_scans or cinfo^.buffered_image;
- jinit_d_coef_controller(cinfo, use_c_buffer);
-
- if (not cinfo^.raw_data_out) then
- jinit_d_main_controller(cinfo, FALSE { never need full buffer here });
-
- { We can now tell the memory manager to allocate virtual arrays. }
- cinfo^.mem^.realize_virt_arrays (j_common_ptr(cinfo));
-
- { Initialize input side of decompressor to consume first scan. }
- cinfo^.inputctl^.start_input_pass (cinfo);
-
-{$ifdef D_MULTISCAN_FILES_SUPPORTED}
- { If jpeg_start_decompress will read the whole file, initialize
- progress monitoring appropriately. The input step is counted
- as one pass. }
-
- if (cinfo^.progress <> NIL) and (not cinfo^.buffered_image) and
- (cinfo^.inputctl^.has_multiple_scans) then
- begin
-
- { Estimate number of scans to set pass_limit. }
- if (cinfo^.progressive_mode) then
- begin
- { Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. }
- nscans := 2 + 3 * cinfo^.num_components;
- end
- else
- begin
- { For a nonprogressive multiscan file, estimate 1 scan per component. }
- nscans := cinfo^.num_components;
- end;
- cinfo^.progress^.pass_counter := Long(0);
- cinfo^.progress^.pass_limit := long (cinfo^.total_iMCU_rows) * nscans;
- cinfo^.progress^.completed_passes := 0;
- if cinfo^.enable_2pass_quant then
- cinfo^.progress^.total_passes := 3
- else
- cinfo^.progress^.total_passes := 2;
- { Count the input pass as done }
- Inc(master^.pass_number);
- end;
-{$endif} { D_MULTISCAN_FILES_SUPPORTED }
-end;
-
-
-{ Per-pass setup.
- This is called at the beginning of each output pass. We determine which
- modules will be active during this pass and give them appropriate
- start_pass calls. We also set is_dummy_pass to indicate whether this
- is a "real" output pass or a dummy pass for color quantization.
- (In the latter case, jdapistd.c will crank the pass to completion.) }
-
-{METHODDEF}
-procedure prepare_for_output_pass (cinfo : j_decompress_ptr); far;
-var
- master : my_master_ptr;
-begin
- master := my_master_ptr (cinfo^.master);
-
- if (master^.pub.is_dummy_pass) then
- begin
-{$ifdef QUANT_2PASS_SUPPORTED}
- { Final pass of 2-pass quantization }
- master^.pub.is_dummy_pass := FALSE;
- cinfo^.cquantize^.start_pass (cinfo, FALSE);
- cinfo^.post^.start_pass (cinfo, JBUF_CRANK_DEST);
- cinfo^.main^.start_pass (cinfo, JBUF_CRANK_DEST);
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif} { QUANT_2PASS_SUPPORTED }
- end
- else
- begin
- if (cinfo^.quantize_colors) and (cinfo^.colormap = NIL) then
- begin
- { Select new quantization method }
- if (cinfo^.two_pass_quantize) and (cinfo^.enable_2pass_quant) then
- begin
- cinfo^.cquantize := master^.quantizer_2pass;
- master^.pub.is_dummy_pass := TRUE;
- end
- else
- if (cinfo^.enable_1pass_quant) then
- begin
- cinfo^.cquantize := master^.quantizer_1pass;
- end
- else
- begin
- ERREXIT(j_common_ptr(cinfo), JERR_MODE_CHANGE);
- end;
- end;
- cinfo^.idct^.start_pass (cinfo);
- cinfo^.coef^.start_output_pass (cinfo);
- if (not cinfo^.raw_data_out) then
- begin
- if (not master^.using_merged_upsample) then
- cinfo^.cconvert^.start_pass (cinfo);
- cinfo^.upsample^.start_pass (cinfo);
- if (cinfo^.quantize_colors) then
- cinfo^.cquantize^.start_pass (cinfo, master^.pub.is_dummy_pass);
- if master^.pub.is_dummy_pass then
- cinfo^.post^.start_pass (cinfo, JBUF_SAVE_AND_PASS)
- else
- cinfo^.post^.start_pass (cinfo, JBUF_PASS_THRU);
- cinfo^.main^.start_pass (cinfo, JBUF_PASS_THRU);
- end;
- end;
-
- { Set up progress monitor's pass info if present }
- if (cinfo^.progress <> NIL) then
- begin
- cinfo^.progress^.completed_passes := master^.pass_number;
- if master^.pub.is_dummy_pass then
- cinfo^.progress^.total_passes := master^.pass_number + 2
- else
- cinfo^.progress^.total_passes := master^.pass_number + 1;
- { In buffered-image mode, we assume one more output pass if EOI not
- yet reached, but no more passes if EOI has been reached. }
-
- if (cinfo^.buffered_image) and (not cinfo^.inputctl^.eoi_reached) then
- begin
- if cinfo^.enable_2pass_quant then
- Inc(cinfo^.progress^.total_passes, 2)
- else
- Inc(cinfo^.progress^.total_passes, 1);
- end;
- end;
-end;
-
-
-{ Finish up at end of an output pass. }
-
-{METHODDEF}
-procedure finish_output_pass (cinfo : j_decompress_ptr); far;
-var
- master : my_master_ptr;
-begin
- master := my_master_ptr (cinfo^.master);
-
- if (cinfo^.quantize_colors) then
- cinfo^.cquantize^.finish_pass (cinfo);
- Inc(master^.pass_number);
-end;
-
-
-{$ifdef D_MULTISCAN_FILES_SUPPORTED}
-
-{ Switch to a new external colormap between output passes. }
-
-{GLOBAL}
-procedure jpeg_new_colormap (cinfo : j_decompress_ptr);
-var
- master : my_master_ptr;
-begin
- master := my_master_ptr (cinfo^.master);
-
- { Prevent application from calling me at wrong times }
- if (cinfo^.global_state <> DSTATE_BUFIMAGE) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
-
- if (cinfo^.quantize_colors) and (cinfo^.enable_external_quant) and
- (cinfo^.colormap <> NIL) then
- begin
- { Select 2-pass quantizer for external colormap use }
- cinfo^.cquantize := master^.quantizer_2pass;
- { Notify quantizer of colormap change }
- cinfo^.cquantize^.new_color_map (cinfo);
- master^.pub.is_dummy_pass := FALSE; { just in case }
- end
- else
- ERREXIT(j_common_ptr(cinfo), JERR_MODE_CHANGE);
-end;
-
-{$endif} { D_MULTISCAN_FILES_SUPPORTED }
-
-
-{ Initialize master decompression control and select active modules.
- This is performed at the start of jpeg_start_decompress. }
-
-{GLOBAL}
-procedure jinit_master_decompress (cinfo : j_decompress_ptr);
-var
- master : my_master_ptr;
-begin
- master := my_master_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_decomp_master)) );
- cinfo^.master := jpeg_decomp_master_ptr(master);
- master^.pub.prepare_for_output_pass := prepare_for_output_pass;
- master^.pub.finish_output_pass := finish_output_pass;
-
- master^.pub.is_dummy_pass := FALSE;
-
- master_selection(cinfo);
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdmerge.pas b/packages/base/pasjpeg/jdmerge.pas
deleted file mode 100644
index 3062be5b20..0000000000
--- a/packages/base/pasjpeg/jdmerge.pas
+++ /dev/null
@@ -1,514 +0,0 @@
-Unit JdMerge;
-
-{ This file contains code for merged upsampling/color conversion.
-
- This file combines functions from jdsample.c and jdcolor.c;
- read those files first to understand what's going on.
-
- When the chroma components are to be upsampled by simple replication
- (ie, box filtering), we can save some work in color conversion by
- calculating all the output pixels corresponding to a pair of chroma
- samples at one time. In the conversion equations
- R := Y + K1 * Cr
- G := Y + K2 * Cb + K3 * Cr
- B := Y + K4 * Cb
- only the Y term varies among the group of pixels corresponding to a pair
- of chroma samples, so the rest of the terms can be calculated just once.
- At typical sampling ratios, this eliminates half or three-quarters of the
- multiplications needed for color conversion.
-
- This file currently provides implementations for the following cases:
- YCbCr => RGB color conversion only.
- Sampling ratios of 2h1v or 2h2v.
- No scaling needed at upsample time.
- Corner-aligned (non-CCIR601) sampling alignment.
- Other special cases could be added, but in most applications these are
- the only common cases. (For uncommon cases we fall back on the more
- general code in jdsample.c and jdcolor.c.) }
-
-{ Original: jdmerge.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jpeglib,
- jutils;
-
-{ Module initialization routine for merged upsampling/color conversion.
-
- NB: this is called under the conditions determined by use_merged_upsample()
- in jdmaster.c. That routine MUST correspond to the actual capabilities
- of this module; no safety checks are made here. }
-
-{GLOBAL}
-procedure jinit_merged_upsampler (cinfo : j_decompress_ptr);
-
-implementation
-
-
-{ Private subobject }
-
-type { the same definition as in JdColor }
- int_Color_Table = array[0..MAXJSAMPLE+1-1] of int;
- int_CConvertPtr = ^int_Color_Table;
- INT32_Color_Table = array[0..MAXJSAMPLE+1-1] of INT32;
- INT32_CConvertPtr = ^INT32_Color_Table;
-
-type
- my_upsample_ptr = ^my_upsampler;
- my_upsampler = record
- pub : jpeg_upsampler; { public fields }
-
- { Pointer to routine to do actual upsampling/conversion of one row group }
- upmethod : procedure (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- in_row_group_ctr : JDIMENSION;
- output_buf : JSAMPARRAY);
-
- { Private state for YCC->RGB conversion }
- Cr_r_tab : int_CConvertPtr; { => table for Cr to R conversion }
- Cb_b_tab : int_CConvertPtr; { => table for Cb to B conversion }
- Cr_g_tab : INT32_CConvertPtr; { => table for Cr to G conversion }
- Cb_g_tab : INT32_CConvertPtr; { => table for Cb to G conversion }
-
- { For 2:1 vertical sampling, we produce two output rows at a time.
- We need a "spare" row buffer to hold the second output row if the
- application provides just a one-row buffer; we also use the spare
- to discard the dummy last row if the image height is odd. }
-
- spare_row : JSAMPROW;
- spare_full : boolean; { TRUE if spare buffer is occupied }
-
- out_row_width : JDIMENSION; { samples per output row }
- rows_to_go : JDIMENSION; { counts rows remaining in image }
- end; {my_upsampler;}
-
-
-const
- SCALEBITS = 16; { speediest right-shift on some machines }
- ONE_HALF = (INT32(1) shl (SCALEBITS-1));
-
-
-{ Initialize tables for YCC->RGB colorspace conversion.
- This is taken directly from jdcolor.c; see that file for more info. }
-
-{LOCAL}
-procedure build_ycc_rgb_table (cinfo : j_decompress_ptr);
-const
- FIX_1_40200 = INT32( Round(1.40200 * (INT32(1) shl SCALEBITS)) );
- FIX_1_77200 = INT32( Round(1.77200 * (INT32(1) shl SCALEBITS)) );
- FIX_0_71414 = INT32( Round(0.71414 * (INT32(1) shl SCALEBITS)) );
- FIX_0_34414 = INT32( Round(0.34414 * (INT32(1) shl SCALEBITS)) );
-var
- upsample : my_upsample_ptr;
- i : int;
- x : INT32;
-var
- shift_temp : INT32;
-begin
- upsample := my_upsample_ptr (cinfo^.upsample);
-
- upsample^.Cr_r_tab := int_CConvertPtr (
- cinfo^.mem^.alloc_small (j_common_ptr (cinfo), JPOOL_IMAGE,
- (MAXJSAMPLE+1) * SIZEOF(int)) );
- upsample^.Cb_b_tab := int_CConvertPtr (
- cinfo^.mem^.alloc_small (j_common_ptr (cinfo), JPOOL_IMAGE,
- (MAXJSAMPLE+1) * SIZEOF(int)) );
- upsample^.Cr_g_tab := INT32_CConvertPtr (
- cinfo^.mem^.alloc_small (j_common_ptr (cinfo), JPOOL_IMAGE,
- (MAXJSAMPLE+1) * SIZEOF(INT32)) );
- upsample^.Cb_g_tab := INT32_CConvertPtr (
- cinfo^.mem^.alloc_small (j_common_ptr (cinfo), JPOOL_IMAGE,
- (MAXJSAMPLE+1) * SIZEOF(INT32)) );
-
- x := -CENTERJSAMPLE;
- for i := 0 to pred(MAXJSAMPLE) do
- begin
- { i is the actual input pixel value, in the range 0..MAXJSAMPLE }
- { The Cb or Cr value we are thinking of is x := i - CENTERJSAMPLE }
- { Cr=>R value is nearest int to 1.40200 * x }
- {upsample^.Cr_r_tab^[i] := int(
- RIGHT_SHIFT(FIX_1_40200 * x + ONE_HALF, SCALEBITS) );}
- shift_temp := FIX_1_40200 * x + ONE_HALF;
- if shift_temp < 0 then { SHIFT arithmetic RIGHT }
- upsample^.Cr_r_tab^[i] := int((shift_temp shr SCALEBITS)
- or ( (not INT32(0)) shl (32-SCALEBITS)))
- else
- upsample^.Cr_r_tab^[i] := int(shift_temp shr SCALEBITS);
-
-
- { Cb=>B value is nearest int to 1.77200 * x }
- {upsample^.Cb_b_tab^[i] := int(
- RIGHT_SHIFT(FIX_1_77200 * x + ONE_HALF, SCALEBITS) );}
- shift_temp := FIX_1_77200 * x + ONE_HALF;
- if shift_temp < 0 then { SHIFT arithmetic RIGHT }
- upsample^.Cb_b_tab^[i] := int((shift_temp shr SCALEBITS)
- or ( (not INT32(0)) shl (32-SCALEBITS)))
- else
- upsample^.Cb_b_tab^[i] := int(shift_temp shr SCALEBITS);
-
- { Cr=>G value is scaled-up -0.71414 * x }
- upsample^.Cr_g_tab^[i] := (- FIX_0_71414) * x;
- { Cb=>G value is scaled-up -0.34414 * x }
- { We also add in ONE_HALF so that need not do it in inner loop }
- upsample^.Cb_g_tab^[i] := (- FIX_0_34414) * x + ONE_HALF;
- Inc(x);
- end;
-end;
-
-
-{ Initialize for an upsampling pass. }
-
-{METHODDEF}
-procedure start_pass_merged_upsample (cinfo : j_decompress_ptr); far;
-var
- upsample : my_upsample_ptr;
-begin
- upsample := my_upsample_ptr (cinfo^.upsample);
-
- { Mark the spare buffer empty }
- upsample^.spare_full := FALSE;
- { Initialize total-height counter for detecting bottom of image }
- upsample^.rows_to_go := cinfo^.output_height;
-end;
-
-
-{ Control routine to do upsampling (and color conversion).
-
- The control routine just handles the row buffering considerations. }
-
-{METHODDEF}
-procedure merged_2v_upsample (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- var in_row_group_ctr : JDIMENSION;
- in_row_groups_avail : JDIMENSION;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION); far;
-{ 2:1 vertical sampling case: may need a spare row. }
-var
- upsample : my_upsample_ptr;
- work_ptrs : array[0..2-1] of JSAMPROW;
- num_rows : JDIMENSION; { number of rows returned to caller }
-begin
- upsample := my_upsample_ptr (cinfo^.upsample);
-
- if (upsample^.spare_full) then
- begin
- { If we have a spare row saved from a previous cycle, just return it. }
- jcopy_sample_rows(JSAMPARRAY(@upsample^.spare_row),
- 0,
- JSAMPARRAY(@ output_buf^[out_row_ctr]),
- 0, 1, upsample^.out_row_width);
- num_rows := 1;
- upsample^.spare_full := FALSE;
- end
- else
- begin
- { Figure number of rows to return to caller. }
- num_rows := 2;
- { Not more than the distance to the end of the image. }
- if (num_rows > upsample^.rows_to_go) then
- num_rows := upsample^.rows_to_go;
- { And not more than what the client can accept: }
- Dec(out_rows_avail, {var} out_row_ctr);
- if (num_rows > out_rows_avail) then
- num_rows := out_rows_avail;
- { Create output pointer array for upsampler. }
- work_ptrs[0] := output_buf^[out_row_ctr];
- if (num_rows > 1) then
- begin
- work_ptrs[1] := output_buf^[out_row_ctr + 1];
- end
- else
- begin
- work_ptrs[1] := upsample^.spare_row;
- upsample^.spare_full := TRUE;
- end;
- { Now do the upsampling. }
- upsample^.upmethod (cinfo, input_buf, {var}in_row_group_ctr,
- JSAMPARRAY(@work_ptrs));
- end;
-
- { Adjust counts }
- Inc(out_row_ctr, num_rows);
- Dec(upsample^.rows_to_go, num_rows);
- { When the buffer is emptied, declare this input row group consumed }
- if (not upsample^.spare_full) then
- Inc(in_row_group_ctr);
-end;
-
-
-{METHODDEF}
-procedure merged_1v_upsample (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- var in_row_group_ctr : JDIMENSION;
- in_row_groups_avail : JDIMENSION;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION); far;
-{ 1:1 vertical sampling case: much easier, never need a spare row. }
-var
- upsample : my_upsample_ptr;
-begin
- upsample := my_upsample_ptr (cinfo^.upsample);
-
- { Just do the upsampling. }
- upsample^.upmethod (cinfo, input_buf, in_row_group_ctr,
- JSAMPARRAY(@ output_buf^[out_row_ctr]));
- { Adjust counts }
- Inc(out_row_ctr);
- Inc(in_row_group_ctr);
-end;
-
-
-{ These are the routines invoked by the control routines to do
- the actual upsampling/conversion. One row group is processed per call.
-
- Note: since we may be writing directly into application-supplied buffers,
- we have to be honest about the output width; we can't assume the buffer
- has been rounded up to an even width. }
-
-
-{ Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. }
-
-{METHODDEF}
-procedure h2v1_merged_upsample (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- in_row_group_ctr : JDIMENSION;
- output_buf : JSAMPARRAY); far;
-var
- upsample : my_upsample_ptr;
- {register} y, cred, cgreen, cblue : int;
- cb, cr : int;
- {register} outptr : JSAMPROW;
- inptr0, inptr1, inptr2 : JSAMPLE_PTR;
- col : JDIMENSION;
- { copy these pointers into registers if possible }
- {register} range_limit : range_limit_table_ptr;
- Crrtab : int_CConvertPtr;
- Cbbtab : int_CConvertPtr;
- Crgtab : INT32_CConvertPtr;
- Cbgtab : INT32_CConvertPtr;
-var
- shift_temp : INT32;
-begin
- upsample := my_upsample_ptr (cinfo^.upsample);
- range_limit := cinfo^.sample_range_limit;
- Crrtab := upsample^.Cr_r_tab;
- Cbbtab := upsample^.Cb_b_tab;
- Crgtab := upsample^.Cr_g_tab;
- Cbgtab := upsample^.Cb_g_tab;
-
- inptr0 := JSAMPLE_PTR(input_buf^[0]^[in_row_group_ctr]);
- inptr1 := JSAMPLE_PTR(input_buf^[1]^[in_row_group_ctr]);
- inptr2 := JSAMPLE_PTR(input_buf^[2]^[in_row_group_ctr]);
- outptr := output_buf^[0];
- { Loop for each pair of output pixels }
- for col := pred(cinfo^.output_width shr 1) downto 0 do
- begin
- { Do the chroma part of the calculation }
- cb := GETJSAMPLE(inptr1^);
- Inc(inptr1);
- cr := GETJSAMPLE(inptr2^);
- Inc(inptr2);
- cred := Crrtab^[cr];
- {cgreen := int( RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS) );}
- shift_temp := Cbgtab^[cb] + Crgtab^[cr];
- if shift_temp < 0 then { SHIFT arithmetic RIGHT }
- cgreen := int((shift_temp shr SCALEBITS)
- or ( (not INT32(0)) shl (32-SCALEBITS)))
- else
- cgreen := int(shift_temp shr SCALEBITS);
-
- cblue := Cbbtab^[cb];
- { Fetch 2 Y values and emit 2 pixels }
- y := GETJSAMPLE(inptr0^);
- Inc(inptr0);
- outptr^[RGB_RED] := range_limit^[y + cred];
- outptr^[RGB_GREEN] := range_limit^[y + cgreen];
- outptr^[RGB_BLUE] := range_limit^[y + cblue];
- Inc(JSAMPLE_PTR(outptr), RGB_PIXELSIZE);
- y := GETJSAMPLE(inptr0^);
- Inc(inptr0);
- outptr^[RGB_RED] := range_limit^[y + cred];
- outptr^[RGB_GREEN] := range_limit^[y + cgreen];
- outptr^[RGB_BLUE] := range_limit^[y + cblue];
- Inc(JSAMPLE_PTR(outptr), RGB_PIXELSIZE);
- end;
- { If image width is odd, do the last output column separately }
- if Odd(cinfo^.output_width) then
- begin
- cb := GETJSAMPLE(inptr1^);
- cr := GETJSAMPLE(inptr2^);
- cred := Crrtab^[cr];
- {cgreen := int ( RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS) );}
- shift_temp := Cbgtab^[cb] + Crgtab^[cr];
- if shift_temp < 0 then { SHIFT arithmetic RIGHT }
- cgreen := int((shift_temp shr SCALEBITS)
- or ( (not INT32(0)) shl (32-SCALEBITS)))
- else
- cgreen := int(shift_temp shr SCALEBITS);
-
- cblue := Cbbtab^[cb];
- y := GETJSAMPLE(inptr0^);
- outptr^[RGB_RED] := range_limit^[y + cred];
- outptr^[RGB_GREEN] := range_limit^[y + cgreen];
- outptr^[RGB_BLUE] := range_limit^[y + cblue];
- end;
-end;
-
-
-{ Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. }
-
-{METHODDEF}
-procedure h2v2_merged_upsample (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- in_row_group_ctr : JDIMENSION;
- output_buf : JSAMPARRAY); far;
-var
- upsample : my_upsample_ptr;
- {register} y, cred, cgreen, cblue : int;
- cb, cr : int;
- {register} outptr0, outptr1 : JSAMPROW;
- inptr00, inptr01, inptr1, inptr2 : JSAMPLE_PTR;
- col : JDIMENSION;
- { copy these pointers into registers if possible }
- {register} range_limit : range_limit_table_ptr;
- Crrtab : int_CConvertPtr;
- Cbbtab : int_CConvertPtr;
- Crgtab : INT32_CConvertPtr;
- Cbgtab : INT32_CConvertPtr;
-var
- shift_temp : INT32;
-begin
- upsample := my_upsample_ptr (cinfo^.upsample);
- range_limit := cinfo^.sample_range_limit;
- Crrtab := upsample^.Cr_r_tab;
- Cbbtab := upsample^.Cb_b_tab;
- Crgtab := upsample^.Cr_g_tab;
- Cbgtab := upsample^.Cb_g_tab;
-
- inptr00 := JSAMPLE_PTR(input_buf^[0]^[in_row_group_ctr*2]);
- inptr01 := JSAMPLE_PTR(input_buf^[0]^[in_row_group_ctr*2 + 1]);
- inptr1 := JSAMPLE_PTR(input_buf^[1]^[in_row_group_ctr]);
- inptr2 := JSAMPLE_PTR(input_buf^[2]^[in_row_group_ctr]);
- outptr0 := output_buf^[0];
- outptr1 := output_buf^[1];
- { Loop for each group of output pixels }
- for col := pred(cinfo^.output_width shr 1) downto 0 do
- begin
- { Do the chroma part of the calculation }
- cb := GETJSAMPLE(inptr1^);
- Inc(inptr1);
- cr := GETJSAMPLE(inptr2^);
- Inc(inptr2);
- cred := Crrtab^[cr];
- {cgreen := int( RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS) );}
- shift_temp := Cbgtab^[cb] + Crgtab^[cr];
- if shift_temp < 0 then { SHIFT arithmetic RIGHT }
- cgreen := int((shift_temp shr SCALEBITS)
- or ( (not INT32(0)) shl (32-SCALEBITS)))
- else
- cgreen := int(shift_temp shr SCALEBITS);
-
- cblue := Cbbtab^[cb];
- { Fetch 4 Y values and emit 4 pixels }
- y := GETJSAMPLE(inptr00^);
- Inc(inptr00);
- outptr0^[RGB_RED] := range_limit^[y + cred];
- outptr0^[RGB_GREEN] := range_limit^[y + cgreen];
- outptr0^[RGB_BLUE] := range_limit^[y + cblue];
- Inc(JSAMPLE_PTR(outptr0), RGB_PIXELSIZE);
- y := GETJSAMPLE(inptr00^);
- Inc(inptr00);
- outptr0^[RGB_RED] := range_limit^[y + cred];
- outptr0^[RGB_GREEN] := range_limit^[y + cgreen];
- outptr0^[RGB_BLUE] := range_limit^[y + cblue];
- Inc(JSAMPLE_PTR(outptr0), RGB_PIXELSIZE);
- y := GETJSAMPLE(inptr01^);
- Inc(inptr01);
- outptr1^[RGB_RED] := range_limit^[y + cred];
- outptr1^[RGB_GREEN] := range_limit^[y + cgreen];
- outptr1^[RGB_BLUE] := range_limit^[y + cblue];
- Inc(JSAMPLE_PTR(outptr1), RGB_PIXELSIZE);
- y := GETJSAMPLE(inptr01^);
- Inc(inptr01);
- outptr1^[RGB_RED] := range_limit^[y + cred];
- outptr1^[RGB_GREEN] := range_limit^[y + cgreen];
- outptr1^[RGB_BLUE] := range_limit^[y + cblue];
- Inc(JSAMPLE_PTR(outptr1), RGB_PIXELSIZE);
- end;
- { If image width is odd, do the last output column separately }
- if Odd(cinfo^.output_width) then
- begin
- cb := GETJSAMPLE(inptr1^);
- cr := GETJSAMPLE(inptr2^);
- cred := Crrtab^[cr];
- {cgreen := int (RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS));}
- shift_temp := Cbgtab^[cb] + Crgtab^[cr];
- if shift_temp < 0 then { SHIFT arithmetic RIGHT }
- cgreen := int((shift_temp shr SCALEBITS)
- or ( (not INT32(0)) shl (32-SCALEBITS)))
- else
- cgreen := int(shift_temp shr SCALEBITS);
-
- cblue := Cbbtab^[cb];
- y := GETJSAMPLE(inptr00^);
- outptr0^[RGB_RED] := range_limit^[y + cred];
- outptr0^[RGB_GREEN] := range_limit^[y + cgreen];
- outptr0^[RGB_BLUE] := range_limit^[y + cblue];
- y := GETJSAMPLE(inptr01^);
- outptr1^[RGB_RED] := range_limit^[y + cred];
- outptr1^[RGB_GREEN] := range_limit^[y + cgreen];
- outptr1^[RGB_BLUE] := range_limit^[y + cblue];
- end;
-end;
-
-
-{ Module initialization routine for merged upsampling/color conversion.
-
- NB: this is called under the conditions determined by use_merged_upsample()
- in jdmaster.c. That routine MUST correspond to the actual capabilities
- of this module; no safety checks are made here. }
-
-
-{GLOBAL}
-procedure jinit_merged_upsampler (cinfo : j_decompress_ptr);
-var
- upsample : my_upsample_ptr;
-begin
- upsample := my_upsample_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_upsampler)) );
- cinfo^.upsample := jpeg_upsampler_ptr (upsample);
- upsample^.pub.start_pass := start_pass_merged_upsample;
- upsample^.pub.need_context_rows := FALSE;
-
- upsample^.out_row_width := cinfo^.output_width * cinfo^.out_color_components;
-
- if (cinfo^.max_v_samp_factor = 2) then
- begin
- upsample^.pub.upsample := merged_2v_upsample;
- upsample^.upmethod := h2v2_merged_upsample;
- { Allocate a spare row buffer }
- upsample^.spare_row := JSAMPROW(
- cinfo^.mem^.alloc_large ( j_common_ptr(cinfo), JPOOL_IMAGE,
- size_t (upsample^.out_row_width * SIZEOF(JSAMPLE))) );
- end
- else
- begin
- upsample^.pub.upsample := merged_1v_upsample;
- upsample^.upmethod := h2v1_merged_upsample;
- { No spare row needed }
- upsample^.spare_row := NIL;
- end;
-
- build_ycc_rgb_table(cinfo);
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdphuff.pas b/packages/base/pasjpeg/jdphuff.pas
deleted file mode 100644
index f608d4921c..0000000000
--- a/packages/base/pasjpeg/jdphuff.pas
+++ /dev/null
@@ -1,1058 +0,0 @@
-Unit JdpHuff;
-
-{ This file contains Huffman entropy decoding routines for progressive JPEG.
-
- Much of the complexity here has to do with supporting input suspension.
- If the data source module demands suspension, we want to be able to back
- up to the start of the current MCU. To do this, we copy state variables
- into local working storage, and update them back to the permanent
- storage only upon successful completion of an MCU. }
-
-{ Original: jdphuff.c ; Copyright (C) 1995-1997, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jpeglib,
- jdeferr,
- jerror,
- jutils,
- jdhuff; { Declarations shared with jdhuff.c }
-
-
-{GLOBAL}
-procedure jinit_phuff_decoder (cinfo : j_decompress_ptr);
-
-implementation
-
-{ Expanded entropy decoder object for progressive Huffman decoding.
-
- The savable_state subrecord contains fields that change within an MCU,
- but must not be updated permanently until we complete the MCU. }
-
-type
- savable_state = record
- EOBRUN : uInt; { remaining EOBs in EOBRUN }
- last_dc_val : array[00..MAX_COMPS_IN_SCAN-1] of int;
- { last DC coef for each component }
- end;
-
-
-type
- phuff_entropy_ptr = ^phuff_entropy_decoder;
- phuff_entropy_decoder = record
- pub : jpeg_entropy_decoder; { public fields }
-
- { These fields are loaded into local variables at start of each MCU.
- In case of suspension, we exit WITHOUT updating them. }
-
- bitstate : bitread_perm_state; { Bit buffer at start of MCU }
- saved : savable_state; { Other state at start of MCU }
-
- { These fields are NOT loaded into local working state. }
- restarts_to_go : uInt; { MCUs left in this restart interval }
-
- { Pointers to derived tables (these workspaces have image lifespan) }
- derived_tbls : array[0..NUM_HUFF_TBLS-1] of d_derived_tbl_ptr;
-
- ac_derived_tbl : d_derived_tbl_ptr; { active table during an AC scan }
- end;
-
-
-
-{ Forward declarations }
-{METHODDEF}
-function decode_mcu_DC_first (cinfo : j_decompress_ptr;
- var MCU_data : array of JBLOCKROW) : boolean;
- far; forward;
-{METHODDEF}
-function decode_mcu_AC_first (cinfo : j_decompress_ptr;
- var MCU_data : array of JBLOCKROW) : boolean;
- far; forward;
-{METHODDEF}
-function decode_mcu_DC_refine (cinfo : j_decompress_ptr;
- var MCU_data : array of JBLOCKROW) : boolean;
- far; forward;
-{METHODDEF}
-function decode_mcu_AC_refine (cinfo : j_decompress_ptr;
- var MCU_data : array of JBLOCKROW) : boolean;
- far; forward;
-
-{ Initialize for a Huffman-compressed scan. }
-
-{METHODDEF}
-procedure start_pass_phuff_decoder (cinfo : j_decompress_ptr); far;
-var
- entropy : phuff_entropy_ptr;
- is_DC_band, bad : boolean;
- ci, coefi, tbl : int;
- coef_bit_ptr : coef_bits_ptr;
- compptr : jpeg_component_info_ptr;
-var
- cindex : int;
- expected : int;
-begin
- entropy := phuff_entropy_ptr (cinfo^.entropy);
-
- is_DC_band := (cinfo^.Ss = 0);
-
- { Validate scan parameters }
- bad := FALSE;
- if (is_DC_band) then
- begin
- if (cinfo^.Se <> 0) then
- bad := TRUE;
- end
- else
- begin
- { need not check Ss/Se < 0 since they came from unsigned bytes }
- if (cinfo^.Ss > cinfo^.Se) or (cinfo^.Se >= DCTSIZE2) then
- bad := TRUE;
- { AC scans may have only one component }
- if (cinfo^.comps_in_scan <> 1) then
- bad := TRUE;
- end;
- if (cinfo^.Ah <> 0) then
- begin
- { Successive approximation refinement scan: must have Al = Ah-1. }
- if (cinfo^.Al <> cinfo^.Ah-1) then
- bad := TRUE;
- end;
- if (cinfo^.Al > 13) then { need not check for < 0 }
- bad := TRUE;
- { Arguably the maximum Al value should be less than 13 for 8-bit precision,
- but the spec doesn't say so, and we try to be liberal about what we
- accept. Note: large Al values could result in out-of-range DC
- coefficients during early scans, leading to bizarre displays due to
- overflows in the IDCT math. But we won't crash. }
-
- if (bad) then
- ERREXIT4(j_common_ptr(cinfo), JERR_BAD_PROGRESSION,
- cinfo^.Ss, cinfo^.Se, cinfo^.Ah, cinfo^.Al);
- { Update progression status, and verify that scan order is legal.
- Note that inter-scan inconsistencies are treated as warnings
- not fatal errors ... not clear if this is right way to behave. }
-
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- cindex := cinfo^.cur_comp_info[ci]^.component_index;
- coef_bit_ptr := coef_bits_ptr(@(cinfo^.coef_bits^[cindex])); {^[0] ???
- Nomssi }
- if (not is_DC_band) and (coef_bit_ptr^[0] < 0) then
- { AC without prior DC scan }
- WARNMS2(j_common_ptr(cinfo), JWRN_BOGUS_PROGRESSION, cindex, 0);
- for coefi := cinfo^.Ss to cinfo^.Se do
- begin
- if (coef_bit_ptr^[coefi] < 0) then
- expected := 0
- else
- expected := coef_bit_ptr^[coefi];
- if (cinfo^.Ah <> expected) then
- WARNMS2(j_common_ptr(cinfo), JWRN_BOGUS_PROGRESSION, cindex, coefi);
- coef_bit_ptr^[coefi] := cinfo^.Al;
- end;
- end;
-
- { Select MCU decoding routine }
- if (cinfo^.Ah = 0) then
- begin
- if (is_DC_band) then
- entropy^.pub.decode_mcu := decode_mcu_DC_first
- else
- entropy^.pub.decode_mcu := decode_mcu_AC_first;
- end
- else
- begin
- if (is_DC_band) then
- entropy^.pub.decode_mcu := decode_mcu_DC_refine
- else
- entropy^.pub.decode_mcu := decode_mcu_AC_refine;
- end;
-
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- begin
- compptr := cinfo^.cur_comp_info[ci];
- { Make sure requested tables are present, and compute derived tables.
- We may build same derived table more than once, but it's not expensive. }
-
- if (is_DC_band) then
- begin
- if (cinfo^.Ah = 0) then
- begin { DC refinement needs no table }
- tbl := compptr^.dc_tbl_no;
- jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
- entropy^.derived_tbls[tbl]);
- end;
- end
- else
- begin
- tbl := compptr^.ac_tbl_no;
- jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
- entropy^.derived_tbls[tbl]);
- { remember the single active table }
- entropy^.ac_derived_tbl := entropy^.derived_tbls[tbl];
- end;
- { Initialize DC predictions to 0 }
- entropy^.saved.last_dc_val[ci] := 0;
- end;
-
- { Initialize bitread state variables }
- entropy^.bitstate.bits_left := 0;
- entropy^.bitstate.get_buffer := 0; { unnecessary, but keeps Purify quiet }
- entropy^.pub.insufficient_data := FALSE;
-
- { Initialize private state variables }
- entropy^.saved.EOBRUN := 0;
-
- { Initialize restart counter }
- entropy^.restarts_to_go := cinfo^.restart_interval;
-end;
-
-
-{ Figure F.12: extend sign bit.
- On some machines, a shift and add will be faster than a table lookup. }
-
-{$ifdef AVOID_TABLES}
-
-#define HUFF_EXTEND(x,s)
- ((x) < (1shl((s)-1)) ? (x) + (((-1)shl(s)) + 1) : (x))
-
-{$else}
-
-{ #define HUFF_EXTEND(x,s)
- if (x) < extend_test[s] then
- (x) + extend_offset[s]
- else
- (x)}
-
-const
- extend_test : Array[0..16-1] of int = { entry n is 2**(n-1) }
- ($0000, $0001, $0002, $0004, $0008, $0010, $0020, $0040,
- $0080, $0100, $0200, $0400, $0800, $1000, $2000, $4000);
-
-const
- extend_offset : array[0..16-1] of int = { entry n is (-1 shl n) + 1 }
- ( 0, ((-1) shl 1) + 1, ((-1) shl 2) + 1, ((-1) shl 3) + 1, ((-1) shl 4) + 1,
- ((-1) shl 5) + 1, ((-1) shl 6) + 1, ((-1) shl 7) + 1, ((-1) shl 8) + 1,
- ((-1) shl 9) + 1, ((-1) shl 10) + 1, ((-1) shl 11) + 1, ((-1) shl 12) + 1,
- ((-1) shl 13) + 1, ((-1) shl 14) + 1, ((-1) shl 15) + 1 );
-
-{$endif} { AVOID_TABLES }
-
-
-{ Check for a restart marker & resynchronize decoder.
- return:=s FALSE if must suspend. }
-
-{LOCAL}
-function process_restart (cinfo : j_decompress_ptr) : boolean;
-var
- entropy : phuff_entropy_ptr;
- ci : int;
-begin
- entropy := phuff_entropy_ptr (cinfo^.entropy);
-
- { Throw away any unused bits remaining in bit buffer; }
- { include any full bytes in next_marker's count of discarded bytes }
- Inc(cinfo^.marker^.discarded_bytes, entropy^.bitstate.bits_left div 8);
- entropy^.bitstate.bits_left := 0;
-
- { Advance past the RSTn marker }
- if (not cinfo^.marker^.read_restart_marker (cinfo)) then
- begin
- process_restart := FALSE;
- exit;
- end;
-
- { Re-initialize DC predictions to 0 }
- for ci := 0 to pred(cinfo^.comps_in_scan) do
- entropy^.saved.last_dc_val[ci] := 0;
- { Re-init EOB run count, too }
- entropy^.saved.EOBRUN := 0;
-
- { Reset restart counter }
- entropy^.restarts_to_go := cinfo^.restart_interval;
-
- { Reset out-of-data flag, unless read_restart_marker left us smack up
- against a marker. In that case we will end up treating the next data
- segment as empty, and we can avoid producing bogus output pixels by
- leaving the flag set. }
- if (cinfo^.unread_marker = 0) then
- entropy^.pub.insufficient_data := FALSE;
-
- process_restart := TRUE;
-end;
-
-
-{ Huffman MCU decoding.
- Each of these routines decodes and returns one MCU's worth of
- Huffman-compressed coefficients.
- The coefficients are reordered from zigzag order into natural array order,
- but are not dequantized.
-
- The i'th block of the MCU is stored into the block pointed to by
- MCU_data[i]. WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER.
-
- We return FALSE if data source requested suspension. In that case no
- changes have been made to permanent state. (Exception: some output
- coefficients may already have been assigned. This is harmless for
- spectral selection, since we'll just re-assign them on the next call.
- Successive approximation AC refinement has to be more careful, however.) }
-
-
-{ MCU decoding for DC initial scan (either spectral selection,
- or first pass of successive approximation). }
-
-{METHODDEF}
-function decode_mcu_DC_first (cinfo : j_decompress_ptr;
- var MCU_data : array of JBLOCKROW) : boolean;
-label
- label1;
-var
- entropy : phuff_entropy_ptr;
- Al : int;
- {register} s, r : int;
- blkn, ci : int;
- block : JBLOCK_PTR;
- {BITREAD_STATE_VARS;}
- get_buffer : bit_buf_type ; {register}
- bits_left : int; {register}
- br_state : bitread_working_state;
-
- state : savable_state;
- tbl : d_derived_tbl_ptr;
- compptr : jpeg_component_info_ptr;
-var
- nb, look : int; {register}
-begin
- entropy := phuff_entropy_ptr (cinfo^.entropy);
- Al := cinfo^.Al;
-
- { Process restart marker if needed; may have to suspend }
- if (cinfo^.restart_interval <> 0) then
- begin
- if (entropy^.restarts_to_go = 0) then
- if (not process_restart(cinfo)) then
- begin
- decode_mcu_DC_first := FALSE;
- exit;
- end;
- end;
-
- { If we've run out of data, just leave the MCU set to zeroes.
- This way, we return uniform gray for the remainder of the segment. }
-
- if not entropy^.pub.insufficient_data then
- begin
-
- { Load up working state }
- {BITREAD_LOAD_STATE(cinfo,entropy^.bitstate);}
- br_state.cinfo := cinfo;
- br_state.next_input_byte := cinfo^.src^.next_input_byte;
- br_state.bytes_in_buffer := cinfo^.src^.bytes_in_buffer;
- get_buffer := entropy^.bitstate.get_buffer;
- bits_left := entropy^.bitstate.bits_left;
-
- {ASSIGN_STATE(state, entropy^.saved);}
- state := entropy^.saved;
-
- { Outer loop handles each block in the MCU }
-
- for blkn := 0 to pred(cinfo^.blocks_in_MCU) do
- begin
- block := JBLOCK_PTR(MCU_data[blkn]);
- ci := cinfo^.MCU_membership[blkn];
- compptr := cinfo^.cur_comp_info[ci];
- tbl := entropy^.derived_tbls[compptr^.dc_tbl_no];
-
- { Decode a single block's worth of coefficients }
-
- { Section F.2.2.1: decode the DC coefficient difference }
- {HUFF_DECODE(s, br_state, tbl, return FALSE, label1);}
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) then
- begin
- decode_mcu_DC_first := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- nb := 1;
- goto label1;
- end;
- end;
- {look := PEEK_BITS(HUFF_LOOKAHEAD);}
- look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
- pred(1 shl HUFF_LOOKAHEAD);
-
- nb := tbl^.look_nbits[look];
- if (nb <> 0) then
- begin
- {DROP_BITS(nb);}
- Dec(bits_left, nb);
-
- s := tbl^.look_sym[look];
- end
- else
- begin
- nb := HUFF_LOOKAHEAD+1;
- label1:
- s := jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb);
- if (s < 0) then
- begin
- decode_mcu_DC_first := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- if (s <> 0) then
- begin
- {CHECK_BIT_BUFFER(br_state, s, return FALSE);}
- if (bits_left < s) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) then
- begin
- decode_mcu_DC_first := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- {r := GET_BITS(s);}
- Dec(bits_left, s);
- r := (int(get_buffer shr bits_left)) and ( pred(1 shl s) );
-
- {s := HUFF_EXTEND(r, s);}
- if (r < extend_test[s]) then
- s := r + extend_offset[s]
- else
- s := r;
- end;
-
- { Convert DC difference to actual value, update last_dc_val }
- Inc(s, state.last_dc_val[ci]);
- state.last_dc_val[ci] := s;
- { Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) }
- block^[0] := JCOEF (s shl Al);
- end;
-
- { Completed MCU, so update state }
- {BITREAD_SAVE_STATE(cinfo,entropy^.bitstate);}
- cinfo^.src^.next_input_byte := br_state.next_input_byte;
- cinfo^.src^.bytes_in_buffer := br_state.bytes_in_buffer;
- entropy^.bitstate.get_buffer := get_buffer;
- entropy^.bitstate.bits_left := bits_left;
-
- {ASSIGN_STATE(entropy^.saved, state);}
- entropy^.saved := state;
- end;
-
- { Account for restart interval (no-op if not using restarts) }
- Dec(entropy^.restarts_to_go);
-
- decode_mcu_DC_first := TRUE;
-end;
-
-
-{ MCU decoding for AC initial scan (either spectral selection,
- or first pass of successive approximation). }
-
-{METHODDEF}
-function decode_mcu_AC_first (cinfo : j_decompress_ptr;
- var MCU_data : array of JBLOCKROW) : boolean;
-label
- label2;
-var
- entropy : phuff_entropy_ptr;
- Se : int;
- Al : int;
- {register} s, k, r : int;
- EOBRUN : uInt;
- block : JBLOCK_PTR;
- {BITREAD_STATE_VARS;}
- get_buffer : bit_buf_type ; {register}
- bits_left : int; {register}
- br_state : bitread_working_state;
-
- tbl : d_derived_tbl_ptr;
-var
- nb, look : int; {register}
-begin
- entropy := phuff_entropy_ptr (cinfo^.entropy);
- Se := cinfo^.Se;
- Al := cinfo^.Al;
-
- { Process restart marker if needed; may have to suspend }
- if (cinfo^.restart_interval <> 0) then
- begin
- if (entropy^.restarts_to_go = 0) then
- if (not process_restart(cinfo)) then
- begin
- decode_mcu_AC_first := FALSE;
- exit;
- end;
- end;
-
- { If we've run out of data, just leave the MCU set to zeroes.
- This way, we return uniform gray for the remainder of the segment. }
- if not entropy^.pub.insufficient_data then
- begin
-
- { Load up working state.
- We can avoid loading/saving bitread state if in an EOB run. }
-
- EOBRUN := entropy^.saved.EOBRUN; { only part of saved state we care about }
-
- { There is always only one block per MCU }
-
- if (EOBRUN > 0) then { if it's a band of zeroes... }
- Dec(EOBRUN) { ...process it now (we do nothing) }
- else
- begin
- {BITREAD_LOAD_STATE(cinfo,entropy^.bitstate);}
- br_state.cinfo := cinfo;
- br_state.next_input_byte := cinfo^.src^.next_input_byte;
- br_state.bytes_in_buffer := cinfo^.src^.bytes_in_buffer;
- get_buffer := entropy^.bitstate.get_buffer;
- bits_left := entropy^.bitstate.bits_left;
-
- block := JBLOCK_PTR(MCU_data[0]);
- tbl := entropy^.ac_derived_tbl;
-
- k := cinfo^.Ss;
- while (k <= Se) do
- begin
- {HUFF_DECODE(s, br_state, tbl, return FALSE, label2);}
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) then
- begin
- decode_mcu_AC_first := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- nb := 1;
- goto label2;
- end;
- end;
- {look := PEEK_BITS(HUFF_LOOKAHEAD);}
- look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
- pred(1 shl HUFF_LOOKAHEAD);
-
- nb := tbl^.look_nbits[look];
- if (nb <> 0) then
- begin
- {DROP_BITS(nb);}
- Dec(bits_left, nb);
-
- s := tbl^.look_sym[look];
- end
- else
- begin
- nb := HUFF_LOOKAHEAD+1;
- label2:
- s := jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb);
- if (s < 0) then
- begin
- decode_mcu_AC_first := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- r := s shr 4;
- s := s and 15;
- if (s <> 0) then
- begin
- Inc(k, r);
- {CHECK_BIT_BUFFER(br_state, s, return FALSE);}
- if (bits_left < s) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) then
- begin
- decode_mcu_AC_first := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- {r := GET_BITS(s);}
- Dec(bits_left, s);
- r := (int(get_buffer shr bits_left)) and ( pred(1 shl s) );
-
- {s := HUFF_EXTEND(r, s);}
- if (r < extend_test[s]) then
- s := r + extend_offset[s]
- else
- s := r;
-
- { Scale and output coefficient in natural (dezigzagged) order }
- block^[jpeg_natural_order[k]] := JCOEF (s shl Al);
- end
- else
- begin
- if (r = 15) then
- begin { ZRL }
- Inc(k, 15); { skip 15 zeroes in band }
- end
- else
- begin { EOBr, run length is 2^r + appended bits }
- EOBRUN := 1 shl r;
- if (r <> 0) then
- begin { EOBr, r > 0 }
- {CHECK_BIT_BUFFER(br_state, r, return FALSE);}
- if (bits_left < r) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,r)) then
- begin
- decode_mcu_AC_first := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- {r := GET_BITS(r);}
- Dec(bits_left, r);
- r := (int(get_buffer shr bits_left)) and ( pred(1 shl r) );
-
- Inc(EOBRUN, r);
- end;
- Dec(EOBRUN); { this band is processed at this moment }
- break; { force end-of-band }
- end;
- end;
- Inc(k);
- end;
-
- {BITREAD_SAVE_STATE(cinfo,entropy^.bitstate);}
- cinfo^.src^.next_input_byte := br_state.next_input_byte;
- cinfo^.src^.bytes_in_buffer := br_state.bytes_in_buffer;
- entropy^.bitstate.get_buffer := get_buffer;
- entropy^.bitstate.bits_left := bits_left;
- end;
-
- { Completed MCU, so update state }
- entropy^.saved.EOBRUN := EOBRUN; { only part of saved state we care about }
- end;
-
- { Account for restart interval (no-op if not using restarts) }
- Dec(entropy^.restarts_to_go);
-
- decode_mcu_AC_first := TRUE;
-end;
-
-
-{ MCU decoding for DC successive approximation refinement scan.
- Note: we assume such scans can be multi-component, although the spec
- is not very clear on the point. }
-
-{METHODDEF}
-function decode_mcu_DC_refine (cinfo : j_decompress_ptr;
- var MCU_data : array of JBLOCKROW) : boolean;
-
-var
- entropy : phuff_entropy_ptr;
- p1 : int; { 1 in the bit position being coded }
- blkn : int;
- block : JBLOCK_PTR;
- {BITREAD_STATE_VARS;}
- get_buffer : bit_buf_type ; {register}
- bits_left : int; {register}
- br_state : bitread_working_state;
-begin
- entropy := phuff_entropy_ptr (cinfo^.entropy);
- p1 := 1 shl cinfo^.Al;
-
- { Process restart marker if needed; may have to suspend }
- if (cinfo^.restart_interval <> 0) then
- begin
- if (entropy^.restarts_to_go = 0) then
- if (not process_restart(cinfo)) then
- begin
- decode_mcu_DC_refine := FALSE;
- exit;
- end;
- end;
-
- { Not worth the cycles to check insufficient_data here,
- since we will not change the data anyway if we read zeroes. }
-
- { Load up working state }
- {BITREAD_LOAD_STATE(cinfo,entropy^.bitstate);}
- br_state.cinfo := cinfo;
- br_state.next_input_byte := cinfo^.src^.next_input_byte;
- br_state.bytes_in_buffer := cinfo^.src^.bytes_in_buffer;
- get_buffer := entropy^.bitstate.get_buffer;
- bits_left := entropy^.bitstate.bits_left;
-
- { Outer loop handles each block in the MCU }
-
- for blkn := 0 to pred(cinfo^.blocks_in_MCU) do
- begin
- block := JBLOCK_PTR(MCU_data[blkn]);
-
- { Encoded data is simply the next bit of the two's-complement DC value }
- {CHECK_BIT_BUFFER(br_state, 1, return FALSE);}
- if (bits_left < 1) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) then
- begin
- decode_mcu_DC_refine := FALSE;
- exit;
- end;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- {if (GET_BITS(1)) then}
- Dec(bits_left);
- if (int(get_buffer shr bits_left)) and ( pred(1 shl 1) ) <> 0 then
- block^[0] := block^[0] or p1;
- { Note: since we use OR, repeating the assignment later is safe }
- end;
-
- { Completed MCU, so update state }
- {BITREAD_SAVE_STATE(cinfo,entropy^.bitstate);}
- cinfo^.src^.next_input_byte := br_state.next_input_byte;
- cinfo^.src^.bytes_in_buffer := br_state.bytes_in_buffer;
- entropy^.bitstate.get_buffer := get_buffer;
- entropy^.bitstate.bits_left := bits_left;
-
- { Account for restart interval (no-op if not using restarts) }
- Dec(entropy^.restarts_to_go);
-
- decode_mcu_DC_refine := TRUE;
-end;
-
-
-{ MCU decoding for AC successive approximation refinement scan. }
-
-{METHODDEF}
-function decode_mcu_AC_refine (cinfo : j_decompress_ptr;
- var MCU_data : array of JBLOCKROW) : boolean;
-label
- undoit, label3;
-var
- entropy : phuff_entropy_ptr;
- Se : int;
- p1 : int; { 1 in the bit position being coded }
- m1 : int; { -1 in the bit position being coded }
- {register} s, k, r : int;
- EOBRUN : uInt;
- block : JBLOCK_PTR;
- thiscoef : JCOEF_PTR;
- {BITREAD_STATE_VARS;}
- get_buffer : bit_buf_type ; {register}
- bits_left : int; {register}
- br_state : bitread_working_state;
-
- tbl : d_derived_tbl_ptr;
- num_newnz : int;
- newnz_pos : array[0..DCTSIZE2-1] of int;
-var
- pos : int;
-var
- nb, look : int; {register}
-begin
- entropy := phuff_entropy_ptr (cinfo^.entropy);
- Se := cinfo^.Se;
- p1 := 1 shl cinfo^.Al; { 1 in the bit position being coded }
- m1 := (-1) shl cinfo^.Al; { -1 in the bit position being coded }
-
- { Process restart marker if needed; may have to suspend }
- if (cinfo^.restart_interval <> 0) then
- begin
- if (entropy^.restarts_to_go = 0) then
- if (not process_restart(cinfo)) then
- begin
- decode_mcu_AC_refine := FALSE;
- exit;
- end;
- end;
-
- { If we've run out of data, don't modify the MCU. }
- if not entropy^.pub.insufficient_data then
- begin
-
- { Load up working state }
- {BITREAD_LOAD_STATE(cinfo,entropy^.bitstate);}
- br_state.cinfo := cinfo;
- br_state.next_input_byte := cinfo^.src^.next_input_byte;
- br_state.bytes_in_buffer := cinfo^.src^.bytes_in_buffer;
- get_buffer := entropy^.bitstate.get_buffer;
- bits_left := entropy^.bitstate.bits_left;
-
- EOBRUN := entropy^.saved.EOBRUN; { only part of saved state we care about }
-
- { There is always only one block per MCU }
- block := JBLOCK_PTR(MCU_data[0]);
- tbl := entropy^.ac_derived_tbl;
-
- { If we are forced to suspend, we must undo the assignments to any newly
- nonzero coefficients in the block, because otherwise we'd get confused
- next time about which coefficients were already nonzero.
- But we need not undo addition of bits to already-nonzero coefficients;
- instead, we can test the current bit position to see if we already did it.}
-
- num_newnz := 0;
-
- { initialize coefficient loop counter to start of band }
- k := cinfo^.Ss;
-
- if (EOBRUN = 0) then
- begin
- while (k <= Se) do
- begin
- {HUFF_DECODE(s, br_state, tbl, goto undoit, label3);}
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) then
- goto undoit;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) then
- begin
- nb := 1;
- goto label3;
- end;
- end;
- {look := PEEK_BITS(HUFF_LOOKAHEAD);}
- look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
- pred(1 shl HUFF_LOOKAHEAD);
-
- nb := tbl^.look_nbits[look];
- if (nb <> 0) then
- begin
- {DROP_BITS(nb);}
- Dec(bits_left, nb);
-
- s := tbl^.look_sym[look];
- end
- else
- begin
- nb := HUFF_LOOKAHEAD+1;
- label3:
- s := jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb);
- if (s < 0) then
- goto undoit;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- r := s shr 4;
- s := s and 15;
- if (s <> 0) then
- begin
- if (s <> 1) then { size of new coef should always be 1 }
- WARNMS(j_common_ptr(cinfo), JWRN_HUFF_BAD_CODE);
- {CHECK_BIT_BUFFER(br_state, 1, goto undoit);}
- if (bits_left < 1) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) then
- goto undoit;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- {if (GET_BITS(1)) then}
- Dec(bits_left);
- if (int(get_buffer shr bits_left)) and ( pred(1 shl 1) )<>0 then
- s := p1 { newly nonzero coef is positive }
- else
- s := m1; { newly nonzero coef is negative }
- end
- else
- begin
- if (r <> 15) then
- begin
- EOBRUN := 1 shl r; { EOBr, run length is 2^r + appended bits }
- if (r <> 0) then
- begin
- {CHECK_BIT_BUFFER(br_state, r, goto undoit);}
- if (bits_left < r) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,r)) then
- goto undoit;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- {r := GET_BITS(r);}
- Dec(bits_left, r);
- r := (int(get_buffer shr bits_left)) and ( pred(1 shl r) );
-
- Inc(EOBRUN, r);
- end;
- break; { rest of block is handled by EOB logic }
- end;
- { note s := 0 for processing ZRL }
- end;
- { Advance over already-nonzero coefs and r still-zero coefs,
- appending correction bits to the nonzeroes. A correction bit is 1
- if the absolute value of the coefficient must be increased. }
-
- repeat
- thiscoef :=@(block^[jpeg_natural_order[k]]);
- if (thiscoef^ <> 0) then
- begin
- {CHECK_BIT_BUFFER(br_state, 1, goto undoit);}
- if (bits_left < 1) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) then
- goto undoit;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- {if (GET_BITS(1)) then}
- Dec(bits_left);
- if (int(get_buffer shr bits_left)) and ( pred(1 shl 1) )<>0 then
- begin
- if ((thiscoef^ and p1) = 0) then
- begin { do nothing if already set it }
- if (thiscoef^ >= 0) then
- Inc(thiscoef^, p1)
- else
- Inc(thiscoef^, m1);
- end;
- end;
- end
- else
- begin
- Dec(r);
- if (r < 0) then
- break; { reached target zero coefficient }
- end;
- Inc(k);
- until (k > Se);
- if (s <> 0) then
- begin
- pos := jpeg_natural_order[k];
- { Output newly nonzero coefficient }
- block^[pos] := JCOEF (s);
- { Remember its position in case we have to suspend }
- newnz_pos[num_newnz] := pos;
- Inc(num_newnz);
- end;
- Inc(k);
- end;
- end;
-
- if (EOBRUN > 0) then
- begin
- { Scan any remaining coefficient positions after the end-of-band
- (the last newly nonzero coefficient, if any). Append a correction
- bit to each already-nonzero coefficient. A correction bit is 1
- if the absolute value of the coefficient must be increased. }
-
- while (k <= Se) do
- begin
- thiscoef := @(block^[jpeg_natural_order[k]]);
- if (thiscoef^ <> 0) then
- begin
- {CHECK_BIT_BUFFER(br_state, 1, goto undoit);}
- if (bits_left < 1) then
- begin
- if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) then
- goto undoit;
- get_buffer := br_state.get_buffer;
- bits_left := br_state.bits_left;
- end;
-
- {if (GET_BITS(1)) then}
- Dec(bits_left);
- if (int(get_buffer shr bits_left)) and ( pred(1 shl 1) )<>0 then
- begin
- if ((thiscoef^ and p1) = 0) then
- begin { do nothing if already changed it }
- if (thiscoef^ >= 0) then
- Inc(thiscoef^, p1)
- else
- Inc(thiscoef^, m1);
- end;
- end;
- end;
- Inc(k);
- end;
- { Count one block completed in EOB run }
- Dec(EOBRUN);
- end;
-
- { Completed MCU, so update state }
- {BITREAD_SAVE_STATE(cinfo,entropy^.bitstate);}
- cinfo^.src^.next_input_byte := br_state.next_input_byte;
- cinfo^.src^.bytes_in_buffer := br_state.bytes_in_buffer;
- entropy^.bitstate.get_buffer := get_buffer;
- entropy^.bitstate.bits_left := bits_left;
-
- entropy^.saved.EOBRUN := EOBRUN; { only part of saved state we care about }
- end;
-
- { Account for restart interval (no-op if not using restarts) }
- Dec(entropy^.restarts_to_go);
-
- decode_mcu_AC_refine := TRUE;
- exit;
-
-undoit:
- { Re-zero any output coefficients that we made newly nonzero }
- while (num_newnz > 0) do
- begin
- Dec(num_newnz);
- block^[newnz_pos[num_newnz]] := 0;
- end;
-
- decode_mcu_AC_refine := FALSE;
-end;
-
-
-{ Module initialization routine for progressive Huffman entropy decoding. }
-
-{GLOBAL}
-procedure jinit_phuff_decoder (cinfo : j_decompress_ptr);
-var
- entropy : phuff_entropy_ptr;
- coef_bit_ptr : int_ptr;
- ci, i : int;
-begin
- entropy := phuff_entropy_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr (cinfo), JPOOL_IMAGE,
- SIZEOF(phuff_entropy_decoder)) );
- cinfo^.entropy := jpeg_entropy_decoder_ptr (entropy);
- entropy^.pub.start_pass := start_pass_phuff_decoder;
-
- { Mark derived tables unallocated }
- for i := 0 to pred(NUM_HUFF_TBLS) do
- begin
- entropy^.derived_tbls[i] := NIL;
- end;
-
- { Create progression status table }
- cinfo^.coef_bits := coef_bits_ptrrow (
- cinfo^.mem^.alloc_small ( j_common_ptr (cinfo), JPOOL_IMAGE,
- cinfo^.num_components*DCTSIZE2*SIZEOF(int)) );
- coef_bit_ptr := @cinfo^.coef_bits^[0][0];
- for ci := 0 to pred(cinfo^.num_components) do
- for i := 0 to pred(DCTSIZE2) do
- begin
- coef_bit_ptr^ := -1;
- Inc(coef_bit_ptr);
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdpostct.pas b/packages/base/pasjpeg/jdpostct.pas
deleted file mode 100644
index d125b6ed51..0000000000
--- a/packages/base/pasjpeg/jdpostct.pas
+++ /dev/null
@@ -1,342 +0,0 @@
-Unit JdPostCt;
-
-{ Original: jdpostct.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-{ This file contains the decompression postprocessing controller.
- This controller manages the upsampling, color conversion, and color
- quantization/reduction steps; specifically, it controls the buffering
- between upsample/color conversion and color quantization/reduction.
-
- If no color quantization/reduction is required, then this module has no
- work to do, and it just hands off to the upsample/color conversion code.
- An integrated upsample/convert/quantize process would replace this module
- entirely. }
-
-{$I jconfig.inc}
-
-interface
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jutils,
- jpeglib;
-
-
-{ Initialize postprocessing controller. }
-
-{GLOBAL}
-procedure jinit_d_post_controller (cinfo : j_decompress_ptr;
- need_full_buffer : boolean);
-implementation
-
-
-{ Private buffer controller object }
-
-type
- my_post_ptr = ^my_post_controller;
- my_post_controller = record
- pub : jpeg_d_post_controller; { public fields }
-
- { Color quantization source buffer: this holds output data from
- the upsample/color conversion step to be passed to the quantizer.
- For two-pass color quantization, we need a full-image buffer;
- for one-pass operation, a strip buffer is sufficient. }
-
- whole_image : jvirt_sarray_ptr; { virtual array, or NIL if one-pass }
- buffer : JSAMPARRAY; { strip buffer, or current strip of virtual }
- strip_height : JDIMENSION; { buffer size in rows }
- { for two-pass mode only: }
- starting_row : JDIMENSION; { row # of first row in current strip }
- next_row : JDIMENSION; { index of next row to fill/empty in strip }
- end;
-
-{ Forward declarations }
-{METHODDEF}
-procedure post_process_1pass(cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- var in_row_group_ctr : JDIMENSION;
- in_row_groups_avail : JDIMENSION;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION); far; forward;
-{$ifdef QUANT_2PASS_SUPPORTED}
-{METHODDEF}
-procedure post_process_prepass(cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- var in_row_group_ctr : JDIMENSION;
- in_row_groups_avail : JDIMENSION;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION); far; forward;
-{METHODDEF}
-procedure post_process_2pass(cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- var in_row_group_ctr : JDIMENSION;
- in_row_groups_avail : JDIMENSION;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION); far; forward;
-{$endif}
-
-
-{ Initialize for a processing pass. }
-
-{METHODDEF}
-procedure start_pass_dpost (cinfo : j_decompress_ptr;
- pass_mode : J_BUF_MODE); far;
-var
- post : my_post_ptr;
-begin
- post := my_post_ptr(cinfo^.post);
-
- case (pass_mode) of
- JBUF_PASS_THRU:
- if (cinfo^.quantize_colors) then
- begin
- { Single-pass processing with color quantization. }
- post^.pub.post_process_data := post_process_1pass;
- { We could be doing buffered-image output before starting a 2-pass
- color quantization; in that case, jinit_d_post_controller did not
- allocate a strip buffer. Use the virtual-array buffer as workspace. }
- if (post^.buffer = NIL) then
- begin
- post^.buffer := cinfo^.mem^.access_virt_sarray
- (j_common_ptr(cinfo), post^.whole_image,
- JDIMENSION(0), post^.strip_height, TRUE);
- end;
- end
- else
- begin
- { For single-pass processing without color quantization,
- I have no work to do; just call the upsampler directly. }
-
- post^.pub.post_process_data := cinfo^.upsample^.upsample;
- end;
-
-{$ifdef QUANT_2PASS_SUPPORTED}
- JBUF_SAVE_AND_PASS:
- begin
- { First pass of 2-pass quantization }
- if (post^.whole_image = NIL) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
- post^.pub.post_process_data := post_process_prepass;
- end;
- JBUF_CRANK_DEST:
- begin
- { Second pass of 2-pass quantization }
- if (post^.whole_image = NIL) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
- post^.pub.post_process_data := post_process_2pass;
- end;
-{$endif} { QUANT_2PASS_SUPPORTED }
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
- end;
- post^.next_row := 0;
- post^.starting_row := 0;
-end;
-
-
-{ Process some data in the one-pass (strip buffer) case.
- This is used for color precision reduction as well as one-pass quantization. }
-
-{METHODDEF}
-procedure post_process_1pass (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- var in_row_group_ctr : JDIMENSION;
- in_row_groups_avail : JDIMENSION;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION);
-var
- post : my_post_ptr;
- num_rows, max_rows : JDIMENSION;
-begin
- post := my_post_ptr (cinfo^.post);
-
- { Fill the buffer, but not more than what we can dump out in one go. }
- { Note we rely on the upsampler to detect bottom of image. }
- max_rows := out_rows_avail - out_row_ctr;
- if (max_rows > post^.strip_height) then
- max_rows := post^.strip_height;
- num_rows := 0;
- cinfo^.upsample^.upsample (cinfo,
- input_buf,
- in_row_group_ctr,
- in_row_groups_avail,
- post^.buffer,
- num_rows, { var }
- max_rows);
- { Quantize and emit data. }
-
- cinfo^.cquantize^.color_quantize (cinfo,
- post^.buffer,
- JSAMPARRAY(@ output_buf^[out_row_ctr]),
- int(num_rows));
-
- Inc(out_row_ctr, num_rows);
-end;
-
-
-{$ifdef QUANT_2PASS_SUPPORTED}
-
-{ Process some data in the first pass of 2-pass quantization. }
-
-{METHODDEF}
-procedure post_process_prepass (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- var in_row_group_ctr : JDIMENSION;
- in_row_groups_avail : JDIMENSION;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail:JDIMENSION);
-var
- post : my_post_ptr;
- old_next_row, num_rows : JDIMENSION;
-begin
- post := my_post_ptr(cinfo^.post);
-
- { Reposition virtual buffer if at start of strip. }
- if (post^.next_row = 0) then
- begin
- post^.buffer := cinfo^.mem^.access_virt_sarray
- (j_common_ptr(cinfo), post^.whole_image,
- post^.starting_row, post^.strip_height, TRUE);
- end;
-
- { Upsample some data (up to a strip height's worth). }
- old_next_row := post^.next_row;
- cinfo^.upsample^.upsample (cinfo,
- input_buf, in_row_group_ctr, in_row_groups_avail,
- post^.buffer, post^.next_row, post^.strip_height);
-
- { Allow quantizer to scan new data. No data is emitted, }
- { but we advance out_row_ctr so outer loop can tell when we're done. }
- if (post^.next_row > old_next_row) then
- begin
- num_rows := post^.next_row - old_next_row;
-
-
- cinfo^.cquantize^.color_quantize (cinfo,
- JSAMPARRAY(@ post^.buffer^[old_next_row]),
- JSAMPARRAY(NIL),
- int(num_rows));
- Inc(out_row_ctr, num_rows);
- end;
-
- { Advance if we filled the strip. }
- if (post^.next_row >= post^.strip_height) then
- begin
- Inc(post^.starting_row, post^.strip_height);
- post^.next_row := 0;
- end;
-end;
-
-
-{ Process some data in the second pass of 2-pass quantization. }
-
-{METHODDEF}
-procedure post_process_2pass (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- var in_row_group_ctr : JDIMENSION;
- in_row_groups_avail : JDIMENSION;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION);
-var
- post : my_post_ptr;
- num_rows, max_rows : JDIMENSION;
-begin
- post := my_post_ptr(cinfo^.post);
-
- { Reposition virtual buffer if at start of strip. }
- if (post^.next_row = 0) then
- begin
- post^.buffer := cinfo^.mem^.access_virt_sarray
- (j_common_ptr(cinfo), post^.whole_image,
- post^.starting_row, post^.strip_height, FALSE);
- end;
-
- { Determine number of rows to emit. }
- num_rows := post^.strip_height - post^.next_row; { available in strip }
- max_rows := out_rows_avail - out_row_ctr; { available in output area }
- if (num_rows > max_rows) then
- num_rows := max_rows;
- { We have to check bottom of image here, can't depend on upsampler. }
- max_rows := cinfo^.output_height - post^.starting_row;
- if (num_rows > max_rows) then
- num_rows := max_rows;
-
- { Quantize and emit data. }
- cinfo^.cquantize^.color_quantize (cinfo,
- JSAMPARRAY(@ post^.buffer^[post^.next_row]),
- JSAMPARRAY(@ output_buf^[out_row_ctr]),
- int(num_rows));
- Inc(out_row_ctr, num_rows);
-
- { Advance if we filled the strip. }
- Inc(post^.next_row, num_rows);
- if (post^.next_row >= post^.strip_height) then
- begin
- Inc(post^.starting_row, post^.strip_height);
- post^.next_row := 0;
- end;
-end;
-
-{$endif} { QUANT_2PASS_SUPPORTED }
-
-
-{ Initialize postprocessing controller. }
-
-{GLOBAL}
-procedure jinit_d_post_controller (cinfo : j_decompress_ptr;
- need_full_buffer : boolean);
-var
- post : my_post_ptr;
-begin
- post := my_post_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_post_controller)) );
- cinfo^.post := jpeg_d_post_controller_ptr (post);
- post^.pub.start_pass := start_pass_dpost;
- post^.whole_image := NIL; { flag for no virtual arrays }
- post^.buffer := NIL; { flag for no strip buffer }
-
- { Create the quantization buffer, if needed }
- if (cinfo^.quantize_colors) then
- begin
- { The buffer strip height is max_v_samp_factor, which is typically
- an efficient number of rows for upsampling to return.
- (In the presence of output rescaling, we might want to be smarter?) }
-
- post^.strip_height := JDIMENSION (cinfo^.max_v_samp_factor);
- if (need_full_buffer) then
- begin
- { Two-pass color quantization: need full-image storage. }
- { We round up the number of rows to a multiple of the strip height. }
-{$ifdef QUANT_2PASS_SUPPORTED}
- post^.whole_image := cinfo^.mem^.request_virt_sarray
- (j_common_ptr(cinfo), JPOOL_IMAGE, FALSE,
- cinfo^.output_width * cinfo^.out_color_components,
- JDIMENSION (jround_up( long(cinfo^.output_height),
- long(post^.strip_height)) ),
- post^.strip_height);
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_BUFFER_MODE);
-{$endif} { QUANT_2PASS_SUPPORTED }
- end
- else
- begin
- { One-pass color quantization: just make a strip buffer. }
- post^.buffer := cinfo^.mem^.alloc_sarray
- (j_common_ptr (cinfo), JPOOL_IMAGE,
- cinfo^.output_width * cinfo^.out_color_components,
- post^.strip_height);
- end;
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdsample.pas b/packages/base/pasjpeg/jdsample.pas
deleted file mode 100644
index e1f457409e..0000000000
--- a/packages/base/pasjpeg/jdsample.pas
+++ /dev/null
@@ -1,592 +0,0 @@
-Unit JdSample;
-
-{ Original: jdsample.c; Copyright (C) 1991-1996, Thomas G. Lane. }
-
-{ This file contains upsampling routines.
-
- Upsampling input data is counted in "row groups". A row group
- is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
- sample rows of each component. Upsampling will normally produce
- max_v_samp_factor pixel rows from each row group (but this could vary
- if the upsampler is applying a scale factor of its own).
-
- An excellent reference for image resampling is
- Digital Image Warping, George Wolberg, 1990.
- Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.}
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jutils,
- jpeglib,
- jdeferr,
- jerror;
-
-
-{ Pointer to routine to upsample a single component }
-type
- upsample1_ptr = procedure (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- var output_data_ptr : JSAMPARRAY);
-
-{ Module initialization routine for upsampling. }
-
-{GLOBAL}
-procedure jinit_upsampler (cinfo : j_decompress_ptr);
-
-implementation
-
-{ Private subobject }
-
-type
- my_upsample_ptr = ^my_upsampler;
- my_upsampler = record
- pub : jpeg_upsampler; { public fields }
-
- { Color conversion buffer. When using separate upsampling and color
- conversion steps, this buffer holds one upsampled row group until it
- has been color converted and output.
- Note: we do not allocate any storage for component(s) which are full-size,
- ie do not need rescaling. The corresponding entry of color_buf[] is
- simply set to point to the input data array, thereby avoiding copying.}
-
- color_buf : array[0..MAX_COMPONENTS-1] of JSAMPARRAY;
-
- { Per-component upsampling method pointers }
- methods : array[0..MAX_COMPONENTS-1] of upsample1_ptr;
-
- next_row_out : int; { counts rows emitted from color_buf }
- rows_to_go : JDIMENSION; { counts rows remaining in image }
-
- { Height of an input row group for each component. }
- rowgroup_height : array[0..MAX_COMPONENTS-1] of int;
-
- { These arrays save pixel expansion factors so that int_expand need not
- recompute them each time. They are unused for other upsampling methods.}
- h_expand : array[0..MAX_COMPONENTS-1] of UINT8 ;
- v_expand : array[0..MAX_COMPONENTS-1] of UINT8 ;
- end;
-
-
-{ Initialize for an upsampling pass. }
-
-{METHODDEF}
-procedure start_pass_upsample (cinfo : j_decompress_ptr); far;
-var
- upsample : my_upsample_ptr;
-begin
- upsample := my_upsample_ptr (cinfo^.upsample);
-
- { Mark the conversion buffer empty }
- upsample^.next_row_out := cinfo^.max_v_samp_factor;
- { Initialize total-height counter for detecting bottom of image }
- upsample^.rows_to_go := cinfo^.output_height;
-end;
-
-
-{ Control routine to do upsampling (and color conversion).
-
- In this version we upsample each component independently.
- We upsample one row group into the conversion buffer, then apply
- color conversion a row at a time. }
-
-{METHODDEF}
-procedure sep_upsample (cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- var in_row_group_ctr : JDIMENSION;
- in_row_groups_avail : JDIMENSION;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION); far;
-var
- upsample : my_upsample_ptr;
- ci : int;
- compptr : jpeg_component_info_ptr;
- num_rows : JDIMENSION;
-begin
- upsample := my_upsample_ptr (cinfo^.upsample);
-
- { Fill the conversion buffer, if it's empty }
- if (upsample^.next_row_out >= cinfo^.max_v_samp_factor) then
- begin
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- { Invoke per-component upsample method. Notice we pass a POINTER
- to color_buf[ci], so that fullsize_upsample can change it. }
-
- upsample^.methods[ci] (cinfo, compptr,
- JSAMPARRAY(@ input_buf^[ci]^
- [in_row_group_ctr * upsample^.rowgroup_height[ci]]),
- upsample^.color_buf[ci]);
-
- Inc(compptr);
- end;
- upsample^.next_row_out := 0;
- end;
-
- { Color-convert and emit rows }
-
- { How many we have in the buffer: }
- num_rows := JDIMENSION (cinfo^.max_v_samp_factor - upsample^.next_row_out);
- { Not more than the distance to the end of the image. Need this test
- in case the image height is not a multiple of max_v_samp_factor: }
-
- if (num_rows > upsample^.rows_to_go) then
- num_rows := upsample^.rows_to_go;
- { And not more than what the client can accept: }
- Dec(out_rows_avail, out_row_ctr);
- if (num_rows > out_rows_avail) then
- num_rows := out_rows_avail;
-
- cinfo^.cconvert^.color_convert (cinfo,
- JSAMPIMAGE(@(upsample^.color_buf)),
- JDIMENSION (upsample^.next_row_out),
- JSAMPARRAY(@(output_buf^[out_row_ctr])),
- int (num_rows));
-
- { Adjust counts }
- Inc(out_row_ctr, num_rows);
- Dec(upsample^.rows_to_go, num_rows);
- Inc(upsample^.next_row_out, num_rows);
- { When the buffer is emptied, declare this input row group consumed }
- if (upsample^.next_row_out >= cinfo^.max_v_samp_factor) then
- Inc(in_row_group_ctr);
-end;
-
-
-{ These are the routines invoked by sep_upsample to upsample pixel values
- of a single component. One row group is processed per call. }
-
-
-{ For full-size components, we just make color_buf[ci] point at the
- input buffer, and thus avoid copying any data. Note that this is
- safe only because sep_upsample doesn't declare the input row group
- "consumed" until we are done color converting and emitting it. }
-
-{METHODDEF}
-procedure fullsize_upsample (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- var output_data_ptr : JSAMPARRAY); far;
-begin
- output_data_ptr := input_data;
-end;
-
-
-{ This is a no-op version used for "uninteresting" components.
- These components will not be referenced by color conversion. }
-
-{METHODDEF}
-procedure noop_upsample (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- var output_data_ptr : JSAMPARRAY); far;
-begin
- output_data_ptr := NIL; { safety check }
-end;
-
-
-{ This version handles any integral sampling ratios.
- This is not used for typical JPEG files, so it need not be fast.
- Nor, for that matter, is it particularly accurate: the algorithm is
- simple replication of the input pixel onto the corresponding output
- pixels. The hi-falutin sampling literature refers to this as a
- "box filter". A box filter tends to introduce visible artifacts,
- so if you are actually going to use 3:1 or 4:1 sampling ratios
- you would be well advised to improve this code. }
-
-{METHODDEF}
-procedure int_upsample (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- var output_data_ptr : JSAMPARRAY); far;
-var
- upsample : my_upsample_ptr;
- output_data : JSAMPARRAY;
- {register} inptr, outptr : JSAMPLE_PTR;
- {register} invalue : JSAMPLE;
- {register} h : int;
- {outend}
- h_expand, v_expand : int;
- inrow, outrow : int;
-var
- outcount : int; { Nomssi: avoid pointer arithmetic }
-begin
- upsample := my_upsample_ptr (cinfo^.upsample);
- output_data := output_data_ptr;
-
- h_expand := upsample^.h_expand[compptr^.component_index];
- v_expand := upsample^.v_expand[compptr^.component_index];
-
- inrow := 0;
- outrow := 0;
- while (outrow < cinfo^.max_v_samp_factor) do
- begin
- { Generate one output row with proper horizontal expansion }
- inptr := JSAMPLE_PTR(input_data^[inrow]);
- outptr := JSAMPLE_PTR(output_data^[outrow]);
- outcount := cinfo^.output_width;
- while (outcount > 0) do { Nomssi }
- begin
- invalue := inptr^; { don't need GETJSAMPLE() here }
- Inc(inptr);
- for h := pred(h_expand) downto 0 do
- begin
- outptr^ := invalue;
- inc(outptr); { <-- fix: this was left out in PasJpeg 1.0 }
- Dec(outcount); { thanks to Jannie Gerber for the report }
- end;
- end;
-
- { Generate any additional output rows by duplicating the first one }
- if (v_expand > 1) then
- begin
- jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
- v_expand-1, cinfo^.output_width);
- end;
- Inc(inrow);
- Inc(outrow, v_expand);
- end;
-end;
-
-
-{ Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
- It's still a box filter. }
-
-{METHODDEF}
-procedure h2v1_upsample (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- var output_data_ptr : JSAMPARRAY); far;
-var
- output_data : JSAMPARRAY;
- {register} inptr, outptr : JSAMPLE_PTR;
- {register} invalue : JSAMPLE;
- {outend : JSAMPROW;}
- outcount : int;
- inrow : int;
-begin
- output_data := output_data_ptr;
-
- for inrow := 0 to pred(cinfo^.max_v_samp_factor) do
- begin
- inptr := JSAMPLE_PTR(input_data^[inrow]);
- outptr := JSAMPLE_PTR(output_data^[inrow]);
- {outend := outptr + cinfo^.output_width;}
- outcount := cinfo^.output_width;
- while (outcount > 0) do
- begin
- invalue := inptr^; { don't need GETJSAMPLE() here }
- Inc(inptr);
- outptr^ := invalue;
- Inc(outptr);
- outptr^ := invalue;
- Inc(outptr);
- Dec(outcount, 2); { Nomssi: to avoid pointer arithmetic }
- end;
- end;
-end;
-
-
-{ Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
- It's still a box filter. }
-
-{METHODDEF}
-procedure h2v2_upsample (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- var output_data_ptr : JSAMPARRAY); far;
-var
- output_data : JSAMPARRAY;
- {register} inptr, outptr : JSAMPLE_PTR;
- {register} invalue : JSAMPLE;
- {outend : JSAMPROW;}
- outcount : int;
- inrow, outrow : int;
-begin
- output_data := output_data_ptr;
-
- inrow := 0;
- outrow := 0;
- while (outrow < cinfo^.max_v_samp_factor) do
- begin
- inptr := JSAMPLE_PTR(input_data^[inrow]);
- outptr := JSAMPLE_PTR(output_data^[outrow]);
- {outend := outptr + cinfo^.output_width;}
- outcount := cinfo^.output_width;
- while (outcount > 0) do
- begin
- invalue := inptr^; { don't need GETJSAMPLE() here }
- Inc(inptr);
- outptr^ := invalue;
- Inc(outptr);
- outptr^ := invalue;
- Inc(outptr);
- Dec(outcount, 2);
- end;
- jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
- 1, cinfo^.output_width);
- Inc(inrow);
- Inc(outrow, 2);
- end;
-end;
-
-
-{ Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
-
- The upsampling algorithm is linear interpolation between pixel centers,
- also known as a "triangle filter". This is a good compromise between
- speed and visual quality. The centers of the output pixels are 1/4 and 3/4
- of the way between input pixel centers.
-
- A note about the "bias" calculations: when rounding fractional values to
- integer, we do not want to always round 0.5 up to the next integer.
- If we did that, we'd introduce a noticeable bias towards larger values.
- Instead, this code is arranged so that 0.5 will be rounded up or down at
- alternate pixel locations (a simple ordered dither pattern). }
-
-{METHODDEF}
-procedure h2v1_fancy_upsample (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- var output_data_ptr : JSAMPARRAY); far;
-var
- output_data : JSAMPARRAY;
- {register} pre_inptr, inptr, outptr : JSAMPLE_PTR;
- {register} invalue : int;
- {register} colctr : JDIMENSION;
- inrow : int;
-begin
- output_data := output_data_ptr;
-
- for inrow := 0 to pred(cinfo^.max_v_samp_factor) do
- begin
- inptr := JSAMPLE_PTR(input_data^[inrow]);
- outptr := JSAMPLE_PTR(output_data^[inrow]);
- { Special case for first column }
- pre_inptr := inptr;
- invalue := GETJSAMPLE(inptr^);
- Inc(inptr);
- outptr^ := JSAMPLE (invalue);
- Inc(outptr);
- outptr^ := JSAMPLE ((invalue * 3 + GETJSAMPLE(inptr^) + 2) shr 2);
- Inc(outptr);
-
- for colctr := pred(compptr^.downsampled_width - 2) downto 0 do
- begin
- { General case: 3/4 * nearer pixel + 1/4 * further pixel }
- invalue := GETJSAMPLE(inptr^) * 3;
- Inc(inptr);
- outptr^ := JSAMPLE ((invalue + GETJSAMPLE(pre_inptr^) + 1) shr 2);
- Inc(pre_inptr);
- Inc(outptr);
- outptr^ := JSAMPLE ((invalue + GETJSAMPLE(inptr^) + 2) shr 2);
- Inc(outptr);
- end;
-
- { Special case for last column }
- invalue := GETJSAMPLE(inptr^);
- outptr^ := JSAMPLE ((invalue * 3 + GETJSAMPLE(pre_inptr^) + 1) shr 2);
- Inc(outptr);
- outptr^ := JSAMPLE (invalue);
- {Inc(outptr); - value never used }
- end;
-end;
-
-
-{ Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
- Again a triangle filter; see comments for h2v1 case, above.
-
- It is OK for us to reference the adjacent input rows because we demanded
- context from the main buffer controller (see initialization code). }
-
-{METHODDEF}
-procedure h2v2_fancy_upsample (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- input_data : JSAMPARRAY;
- var output_data_ptr : JSAMPARRAY); far;
-var
- output_data : JSAMPARRAY;
- {register} inptr0, inptr1, outptr : JSAMPLE_PTR;
-{$ifdef BITS_IN_JSAMPLE_IS_8}
- {register} thiscolsum, lastcolsum, nextcolsum : int;
-{$else}
- {register} thiscolsum, lastcolsum, nextcolsum : INT32;
-{$endif}
- {register} colctr : JDIMENSION;
- inrow, outrow, v : int;
-var
- prev_input_data : JSAMPARRAY; { Nomssi work around }
-begin
- output_data := output_data_ptr;
-
- outrow := 0;
- inrow := 0;
- while (outrow < cinfo^.max_v_samp_factor) do
- begin
- for v := 0 to pred(2) do
- begin
- { inptr0 points to nearest input row, inptr1 points to next nearest }
- inptr0 := JSAMPLE_PTR(input_data^[inrow]);
- if (v = 0) then { next nearest is row above }
- begin
- {inptr1 := JSAMPLE_PTR(input_data^[inrow-1]);}
- prev_input_data := input_data; { work around }
- Dec(JSAMPROW_PTR(prev_input_data)); { negative offsets }
- inptr1 := JSAMPLE_PTR(prev_input_data^[inrow]);
- end
- else { next nearest is row below }
- inptr1 := JSAMPLE_PTR(input_data^[inrow+1]);
- outptr := JSAMPLE_PTR(output_data^[outrow]);
- Inc(outrow);
-
- { Special case for first column }
- thiscolsum := GETJSAMPLE(inptr0^) * 3 + GETJSAMPLE(inptr1^);
- Inc(inptr0);
- Inc(inptr1);
- nextcolsum := GETJSAMPLE(inptr0^) * 3 + GETJSAMPLE(inptr1^);
- Inc(inptr0);
- Inc(inptr1);
-
- outptr^ := JSAMPLE ((thiscolsum * 4 + 8) shr 4);
- Inc(outptr);
- outptr^ := JSAMPLE ((thiscolsum * 3 + nextcolsum + 7) shr 4);
- Inc(outptr);
- lastcolsum := thiscolsum; thiscolsum := nextcolsum;
-
- for colctr := pred(compptr^.downsampled_width - 2) downto 0 do
- begin
- { General case: 3/4 * nearer pixel + 1/4 * further pixel in each }
- { dimension, thus 9/16, 3/16, 3/16, 1/16 overall }
- nextcolsum := GETJSAMPLE(inptr0^) * 3 + GETJSAMPLE(inptr1^);
- Inc(inptr0);
- Inc(inptr1);
- outptr^ := JSAMPLE ((thiscolsum * 3 + lastcolsum + 8) shr 4);
- Inc(outptr);
- outptr^ := JSAMPLE ((thiscolsum * 3 + nextcolsum + 7) shr 4);
- Inc(outptr);
- lastcolsum := thiscolsum;
- thiscolsum := nextcolsum;
- end;
-
- { Special case for last column }
- outptr^ := JSAMPLE ((thiscolsum * 3 + lastcolsum + 8) shr 4);
- Inc(outptr);
- outptr^ := JSAMPLE ((thiscolsum * 4 + 7) shr 4);
- {Inc(outptr); - value never used }
- end;
- Inc(inrow);
- end;
-end;
-
-
-{ Module initialization routine for upsampling. }
-
-{GLOBAL}
-procedure jinit_upsampler (cinfo : j_decompress_ptr);
-var
- upsample : my_upsample_ptr;
- ci : int;
- compptr : jpeg_component_info_ptr;
- need_buffer, do_fancy : boolean;
- h_in_group, v_in_group, h_out_group, v_out_group : int;
-begin
- upsample := my_upsample_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_upsampler)) );
- cinfo^.upsample := jpeg_upsampler_ptr (upsample);
- upsample^.pub.start_pass := start_pass_upsample;
- upsample^.pub.upsample := sep_upsample;
- upsample^.pub.need_context_rows := FALSE; { until we find out differently }
-
- if (cinfo^.CCIR601_sampling) then { this isn't supported }
- ERREXIT(j_common_ptr(cinfo), JERR_CCIR601_NOTIMPL);
-
- { jdmainct.c doesn't support context rows when min_DCT_scaled_size := 1,
- so don't ask for it. }
-
- do_fancy := cinfo^.do_fancy_upsampling and (cinfo^.min_DCT_scaled_size > 1);
-
- { Verify we can handle the sampling factors, select per-component methods,
- and create storage as needed. }
-
- compptr := jpeg_component_info_ptr(cinfo^.comp_info);
- for ci := 0 to pred(cinfo^.num_components) do
- begin
- { 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 := (compptr^.h_samp_factor * compptr^.DCT_scaled_size) div
- cinfo^.min_DCT_scaled_size;
- v_in_group := (compptr^.v_samp_factor * compptr^.DCT_scaled_size) div
- 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 }
- need_buffer := TRUE;
- if (not compptr^.component_needed) then
- begin
- { Don't bother to upsample an uninteresting component. }
- upsample^.methods[ci] := noop_upsample;
- need_buffer := FALSE;
- end
- else
- if (h_in_group = h_out_group) and (v_in_group = v_out_group) then
- begin
- { Fullsize components can be processed without any work. }
- upsample^.methods[ci] := fullsize_upsample;
- need_buffer := FALSE;
- end
- else
- if (h_in_group * 2 = h_out_group) and
- (v_in_group = v_out_group) then
- begin
- { Special cases for 2h1v upsampling }
- if (do_fancy) and (compptr^.downsampled_width > 2) then
- upsample^.methods[ci] := h2v1_fancy_upsample
- else
- upsample^.methods[ci] := h2v1_upsample;
- end
- else
- if (h_in_group * 2 = h_out_group) and
- (v_in_group * 2 = v_out_group) then
- begin
- { Special cases for 2h2v upsampling }
- if (do_fancy) and (compptr^.downsampled_width > 2) then
- begin
- upsample^.methods[ci] := h2v2_fancy_upsample;
- upsample^.pub.need_context_rows := TRUE;
- end
- else
- upsample^.methods[ci] := h2v2_upsample;
- end
- else
- if ((h_out_group mod h_in_group) = 0) and
- ((v_out_group mod v_in_group) = 0) then
- begin
- { Generic integral-factors upsampling method }
- upsample^.methods[ci] := int_upsample;
- upsample^.h_expand[ci] := UINT8 (h_out_group div h_in_group);
- upsample^.v_expand[ci] := UINT8 (v_out_group div v_in_group);
- end
- else
- ERREXIT(j_common_ptr(cinfo), JERR_FRACT_SAMPLE_NOTIMPL);
- if (need_buffer) then
- begin
- upsample^.color_buf[ci] := cinfo^.mem^.alloc_sarray
- (j_common_ptr(cinfo), JPOOL_IMAGE,
- JDIMENSION (jround_up( long (cinfo^.output_width),
- long (cinfo^.max_h_samp_factor))),
- JDIMENSION (cinfo^.max_v_samp_factor));
- end;
- Inc(compptr);
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jdtrans.pas b/packages/base/pasjpeg/jdtrans.pas
deleted file mode 100644
index 044e339f6e..0000000000
--- a/packages/base/pasjpeg/jdtrans.pas
+++ /dev/null
@@ -1,192 +0,0 @@
-Unit JdTrans;
-
-{ This file contains library routines for transcoding decompression,
- that is, reading raw DCT coefficient arrays from an input JPEG file.
- The routines in jdapimin.c will also be needed by a transcoder. }
-
-{ Original : jdtrans.c ; Copyright (C) 1995-1997, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jpeglib,
- jdhuff, jdphuff, jdcoefct;
-
-{ Read the coefficient arrays from a JPEG file.
- jpeg_read_header must be completed before calling this.
-
- The entire image is read into a set of virtual coefficient-block arrays,
- one per component. The return value is a pointer to the array of
- virtual-array descriptors. These can be manipulated directly via the
- JPEG memory manager, or handed off to jpeg_write_coefficients().
- To release the memory occupied by the virtual arrays, call
- jpeg_finish_decompress() when done with the data.
-
- An alternative usage is to simply obtain access to the coefficient arrays
- during a buffered-image-mode decompression operation. This is allowed
- after any jpeg_finish_output() call. The arrays can be accessed until
- jpeg_finish_decompress() is called. (Note that any call to the library
- may reposition the arrays, so don't rely on access_virt_barray() results
- to stay valid across library calls.)
-
- Returns NIL if suspended. This case need be checked only if
- a suspending data source is used. }
-
-{GLOBAL}
-function jpeg_read_coefficients
- (cinfo : j_decompress_ptr) : jvirt_barray_tbl_ptr;
-
-implementation
-
-
-{ Forward declarations }
-{LOCAL}
-procedure transdecode_master_selection (cinfo : j_decompress_ptr); forward;
-
-
-{ Read the coefficient arrays from a JPEG file.
- jpeg_read_header must be completed before calling this.
-
- The entire image is read into a set of virtual coefficient-block arrays,
- one per component. The return value is a pointer to the array of
- virtual-array descriptors. These can be manipulated directly via the
- JPEG memory manager, or handed off to jpeg_write_coefficients().
- To release the memory occupied by the virtual arrays, call
- jpeg_finish_decompress() when done with the data.
-
- Returns NIL if suspended. This case need be checked only if
- a suspending data source is used. }
-
-{GLOBAL}
-function jpeg_read_coefficients
- (cinfo : j_decompress_ptr) : jvirt_barray_tbl_ptr;
-var
- retcode : int;
-begin
- if (cinfo^.global_state = DSTATE_READY) then
- begin
- { First call: initialize active modules }
- transdecode_master_selection(cinfo);
- cinfo^.global_state := DSTATE_RDCOEFS;
- end;
-
- if (cinfo^.global_state = DSTATE_RDCOEFS) then
- begin
- { Absorb whole file into the coef buffer }
- while TRUE do
- begin
- { Call progress monitor hook if present }
- if (cinfo^.progress <> NIL) then
- cinfo^.progress^.progress_monitor (j_common_ptr(cinfo));
- { Absorb some more input }
- retcode := cinfo^.inputctl^.consume_input (cinfo);
- if (retcode = JPEG_SUSPENDED) then
- begin
- jpeg_read_coefficients := NIL;
- exit;
- end;
- if (retcode = JPEG_REACHED_EOI) then
- break;
- { Advance progress counter if appropriate }
- if (cinfo^.progress <> NIL) and
- ((retcode = JPEG_ROW_COMPLETED) or (retcode = JPEG_REACHED_SOS)) then
- begin
- Inc(cinfo^.progress^.pass_counter);
- if (cinfo^.progress^.pass_counter >= cinfo^.progress^.pass_limit) then
- begin
- { startup underestimated number of scans; ratchet up one scan }
- Inc(cinfo^.progress^.pass_limit, long(cinfo^.total_iMCU_rows));
- end;
- end;
- end;
- { Set state so that jpeg_finish_decompress does the right thing }
- cinfo^.global_state := DSTATE_STOPPING;
- end;
- { At this point we should be in state DSTATE_STOPPING if being used
- standalone, or in state DSTATE_BUFIMAGE if being invoked to get access
- to the coefficients during a full buffered-image-mode decompression. }
-
- if ((cinfo^.global_state = DSTATE_STOPPING) or
- (cinfo^.global_state = DSTATE_BUFIMAGE)) and (cinfo^.buffered_image) then
- begin
- jpeg_read_coefficients := cinfo^.coef^.coef_arrays;
- exit;
- end;
- { Oops, improper usage }
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
- jpeg_read_coefficients := NIL; { keep compiler happy }
-end;
-
-
-{ Master selection of decompression modules for transcoding.
- This substitutes for jdmaster.c's initialization of the full decompressor. }
-
-{LOCAL}
-procedure transdecode_master_selection (cinfo : j_decompress_ptr);
-var
- nscans : int;
-begin
- { This is effectively a buffered-image operation. }
- cinfo^.buffered_image := TRUE;
-
- { Entropy decoding: either Huffman or arithmetic coding. }
- if (cinfo^.arith_code) then
- begin
- ERREXIT(j_common_ptr(cinfo), JERR_ARITH_NOTIMPL);
- end
- else
- begin
- if (cinfo^.progressive_mode) then
- begin
-{$ifdef D_PROGRESSIVE_SUPPORTED}
- jinit_phuff_decoder(cinfo);
-{$else}
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
-{$endif}
- end
- else
- jinit_huff_decoder(cinfo);
- end;
-
- { Always get a full-image coefficient buffer. }
- jinit_d_coef_controller(cinfo, TRUE);
-
- { We can now tell the memory manager to allocate virtual arrays. }
- cinfo^.mem^.realize_virt_arrays (j_common_ptr(cinfo));
-
- { Initialize input side of decompressor to consume first scan. }
- cinfo^.inputctl^.start_input_pass (cinfo);
-
- { Initialize progress monitoring. }
- if (cinfo^.progress <> NIL) then
- begin
- { Estimate number of scans to set pass_limit. }
- if (cinfo^.progressive_mode) then
- begin
- { Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. }
- nscans := 2 + 3 * cinfo^.num_components;
- end
- else
- if (cinfo^.inputctl^.has_multiple_scans) then
- begin
- { For a nonprogressive multiscan file, estimate 1 scan per component. }
- nscans := cinfo^.num_components;
- end
- else
- begin
- nscans := 1;
- end;
- cinfo^.progress^.pass_counter := long(0);
- cinfo^.progress^.pass_limit := long(cinfo^.total_iMCU_rows * nscans);
- cinfo^.progress^.completed_passes := 0;
- cinfo^.progress^.total_passes := 1;
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jerror.pas b/packages/base/pasjpeg/jerror.pas
deleted file mode 100644
index bde4b672cf..0000000000
--- a/packages/base/pasjpeg/jerror.pas
+++ /dev/null
@@ -1,461 +0,0 @@
-Unit Jerror;
-
-{ 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.
-
- These routines are used by both the compression and decompression code. }
-
-{ Source: jerror.c; Copyright (C) 1991-1996, Thomas G. Lane. }
-{ note: format_message still contains a hack }
-{$i jconfig.inc}
-interface
-
-uses
- jmorecfg,
- jdeferr,
- jpeglib;
-{
- jversion;
-}
-
-const
- EXIT_FAILURE = 1; { define halt() codes if not provided }
-
-{GLOBAL}
-function jpeg_std_error (var err : jpeg_error_mgr) : jpeg_error_mgr_ptr;
-
-
-
-procedure ERREXIT(cinfo : j_common_ptr; code : J_MESSAGE_CODE);
-
-procedure ERREXIT1(cinfo : j_common_ptr; code : J_MESSAGE_CODE; p1 : uInt);
-
-procedure ERREXIT2(cinfo : j_common_ptr; code : J_MESSAGE_CODE; p1 : int; p2 : int);
-
-procedure ERREXIT3(cinfo : j_common_ptr; code : J_MESSAGE_CODE;
- p1 : int; p2 : int; p3 : int);
-
-procedure ERREXIT4(cinfo : j_common_ptr; code : J_MESSAGE_CODE;
- p1 : int; p2 : int; p3 : int; p4 : int);
-
-procedure ERREXITS(cinfo : j_common_ptr;code : J_MESSAGE_CODE;
- str : string);
-{ Nonfatal errors (we can keep going, but the data is probably corrupt) }
-
-procedure WARNMS(cinfo : j_common_ptr; code : J_MESSAGE_CODE);
-
-procedure WARNMS1(cinfo : j_common_ptr;code : J_MESSAGE_CODE; p1 : int);
-
-procedure WARNMS2(cinfo : j_common_ptr; code : J_MESSAGE_CODE;
- p1 : int; p2 : int);
-
-{ Informational/debugging messages }
-procedure TRACEMS(cinfo : j_common_ptr; lvl : int; code : J_MESSAGE_CODE);
-
-procedure TRACEMS1(cinfo : j_common_ptr; lvl : int;
- code : J_MESSAGE_CODE; p1 : long);
-
-procedure TRACEMS2(cinfo : j_common_ptr; lvl : int; code : J_MESSAGE_CODE;
- p1 : int;
- p2 : int);
-
-procedure TRACEMS3(cinfo : j_common_ptr;
- lvl : int;
- code : J_MESSAGE_CODE;
- p1 : int; p2 : int; p3 : int);
-
-procedure TRACEMS4(cinfo : j_common_ptr; lvl : int; code : J_MESSAGE_CODE;
- p1 : int; p2 : int; p3 : int; p4 : int);
-
-procedure TRACEMS5(cinfo : j_common_ptr; lvl : int; code : J_MESSAGE_CODE;
- p1 : int; p2 : int; p3 : int; p4 : int; p5 : int);
-
-procedure TRACEMS8(cinfo : j_common_ptr; lvl : int; code : J_MESSAGE_CODE;
- p1 : int; p2 : int; p3 : int; p4 : int;
- p5 : int; p6 : int; p7 : int; p8 : int);
-
-procedure TRACEMSS(cinfo : j_common_ptr; lvl : int;
- code : J_MESSAGE_CODE; str : string);
-
-implementation
-
-
-{ How to format a message string, in format_message() ? }
-
-{$IFDEF OS2}
- {$DEFINE NO_FORMAT}
-{$ENDIF}
-{$IFDEF FPC}
- {$DEFINE NO_FORMAT}
-{$ENDIF}
-
-uses
-{$IFNDEF NO_FORMAT}
- {$IFDEF VER70}
- drivers, { Turbo Vision unit with FormatStr }
- {$ELSE}
- sysutils, { Delphi Unit with Format() }
- {$ENDIF}
-{$ENDIF}
- jcomapi;
-
-{ 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}
-procedure error_exit (cinfo : j_common_ptr); far;
-begin
- { Always display the message }
- cinfo^.err^.output_message(cinfo);
-
- { Let the memory manager delete any temp files before we die }
- jpeg_destroy(cinfo);
-
- halt(EXIT_FAILURE);
-end;
-
-
-{ Actual output of an error or trace message.
- Applications may override this method to send JPEG messages somewhere
- other than stderr. }
-
-{ Macros to simplify using the error and trace message stuff }
-{ The first parameter is either type of cinfo pointer }
-
-{ Fatal errors (print message and exit) }
-procedure ERREXIT(cinfo : j_common_ptr; code : J_MESSAGE_CODE);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.error_exit(cinfo);
-end;
-
-procedure ERREXIT1(cinfo : j_common_ptr; code : J_MESSAGE_CODE; p1 : uInt);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.msg_parm.i[0] := p1;
- cinfo^.err^.error_exit (cinfo);
-end;
-
-procedure ERREXIT2(cinfo : j_common_ptr; code : J_MESSAGE_CODE;
- p1 : int; p2 : int);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.msg_parm.i[0] := p1;
- cinfo^.err^.msg_parm.i[1] := p2;
- cinfo^.err^.error_exit (cinfo);
-end;
-
-procedure ERREXIT3(cinfo : j_common_ptr; code : J_MESSAGE_CODE;
- p1 : int; p2 : int; p3 : int);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.msg_parm.i[0] := p1;
- cinfo^.err^.msg_parm.i[1] := p2;
- cinfo^.err^.msg_parm.i[2] := p3;
- cinfo^.err^.error_exit (cinfo);
-end;
-
-procedure ERREXIT4(cinfo : j_common_ptr; code : J_MESSAGE_CODE;
- p1 : int; p2 : int; p3 : int; p4 : int);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.msg_parm.i[0] := p1;
- cinfo^.err^.msg_parm.i[1] := p2;
- cinfo^.err^.msg_parm.i[2] := p3;
- cinfo^.err^.msg_parm.i[3] := p4;
- cinfo^.err^.error_exit (cinfo);
-end;
-
-procedure ERREXITS(cinfo : j_common_ptr;code : J_MESSAGE_CODE;
- str : string);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.msg_parm.s := str; { string[JMSG_STR_PARM_MAX] }
- cinfo^.err^.error_exit (cinfo);
-end;
-
-{ Nonfatal errors (we can keep going, but the data is probably corrupt) }
-
-procedure WARNMS(cinfo : j_common_ptr; code : J_MESSAGE_CODE);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.emit_message(cinfo, -1);
-end;
-
-procedure WARNMS1(cinfo : j_common_ptr;code : J_MESSAGE_CODE; p1 : int);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.msg_parm.i[0] := p1;
- cinfo^.err^.emit_message (cinfo, -1);
-end;
-
-procedure WARNMS2(cinfo : j_common_ptr; code : J_MESSAGE_CODE;
- p1 : int; p2 : int);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.msg_parm.i[0] := p1;
- cinfo^.err^.msg_parm.i[1] := p2;
- cinfo^.err^.emit_message (cinfo, -1);
-end;
-
-{ Informational/debugging messages }
-procedure TRACEMS(cinfo : j_common_ptr; lvl : int; code : J_MESSAGE_CODE);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.emit_message(cinfo, lvl);
-end;
-
-procedure TRACEMS1(cinfo : j_common_ptr; lvl : int;
- code : J_MESSAGE_CODE; p1 : long);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.msg_parm.i[0] := p1;
- cinfo^.err^.emit_message (cinfo, lvl);
-end;
-
-procedure TRACEMS2(cinfo : j_common_ptr; lvl : int; code : J_MESSAGE_CODE;
- p1 : int;
- p2 : int);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.msg_parm.i[0] := p1;
- cinfo^.err^.msg_parm.i[1] := p2;
- cinfo^.err^.emit_message (cinfo, lvl);
-end;
-
-procedure TRACEMS3(cinfo : j_common_ptr;
- lvl : int;
- code : J_MESSAGE_CODE;
- p1 : int; p2 : int; p3 : int);
-var
- _mp : int8array;
-begin
- _mp[0] := p1; _mp[1] := p2; _mp[2] := p3;
- cinfo^.err^.msg_parm.i := _mp;
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.emit_message (cinfo, lvl);
-end;
-
-
-procedure TRACEMS4(cinfo : j_common_ptr; lvl : int; code : J_MESSAGE_CODE;
- p1 : int; p2 : int; p3 : int; p4 : int);
-var
- _mp : int8array;
-begin
- _mp[0] := p1; _mp[1] := p2; _mp[2] := p3; _mp[3] := p4;
- cinfo^.err^.msg_parm.i := _mp;
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.emit_message (cinfo, lvl);
-end;
-
-procedure TRACEMS5(cinfo : j_common_ptr; lvl : int; code : J_MESSAGE_CODE;
- p1 : int; p2 : int; p3 : int; p4 : int; p5 : int);
-var
- _mp : ^int8array;
-begin
- _mp := @cinfo^.err^.msg_parm.i;
- _mp^[0] := p1; _mp^[1] := p2; _mp^[2] := p3;
- _mp^[3] := p4; _mp^[5] := p5;
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.emit_message (cinfo, lvl);
-end;
-
-procedure TRACEMS8(cinfo : j_common_ptr; lvl : int; code : J_MESSAGE_CODE;
- p1 : int; p2 : int; p3 : int; p4 : int;
- p5 : int; p6 : int; p7 : int; p8 : int);
-var
- _mp : int8array;
-begin
- _mp[0] := p1; _mp[1] := p2; _mp[2] := p3; _mp[3] := p4;
- _mp[4] := p5; _mp[5] := p6; _mp[6] := p7; _mp[7] := p8;
- cinfo^.err^.msg_parm.i := _mp;
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.emit_message (cinfo, lvl);
-end;
-
-procedure TRACEMSS(cinfo : j_common_ptr; lvl : int;
- code : J_MESSAGE_CODE; str : string);
-begin
- cinfo^.err^.msg_code := ord(code);
- cinfo^.err^.msg_parm.s := str; { string JMSG_STR_PARM_MAX }
- cinfo^.err^.emit_message (cinfo, lvl);
-end;
-
-{METHODDEF}
-procedure output_message (cinfo : j_common_ptr); far;
-var
- buffer : string; {[JMSG_LENGTH_MAX];}
-begin
- { Create the message }
- cinfo^.err^.format_message (cinfo, buffer);
-
- { Send it to stderr, adding a newline }
- WriteLn(output, buffer);
-end;
-
-
-
-{ 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}
-procedure emit_message (cinfo : j_common_ptr; msg_level : int); far;
-var
- err : jpeg_error_mgr_ptr;
-begin
- err := cinfo^.err;
- if (msg_level < 0) then
- begin
- { 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) or (err^.trace_level >= 3) then
- err^.output_message(cinfo);
- { Always count warnings in num_warnings. }
- Inc( err^.num_warnings );
- end
- else
- begin
- { It's a trace message. Show it if trace_level >= msg_level. }
- if (err^.trace_level >= msg_level) then
- err^.output_message (cinfo);
- end;
-end;
-
-
-{ 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}
-procedure format_message (cinfo : j_common_ptr; var buffer : string); far;
-var
- err : jpeg_error_mgr_ptr;
- msg_code : J_MESSAGE_CODE;
- msgtext : string;
- isstring : boolean;
-begin
- err := cinfo^.err;
- msg_code := J_MESSAGE_CODE(err^.msg_code);
- msgtext := '';
-
- { Look up message string in proper table }
- if (msg_code > JMSG_NOMESSAGE)
- and (msg_code <= J_MESSAGE_CODE(err^.last_jpeg_message)) then
- begin
- msgtext := err^.jpeg_message_table^[msg_code];
- end
- else
- if (err^.addon_message_table <> NIL) and
- (msg_code >= err^.first_addon_message) and
- (msg_code <= err^.last_addon_message) then
- begin
- msgtext := err^.addon_message_table^[J_MESSAGE_CODE
- (ord(msg_code) - ord(err^.first_addon_message))];
- end;
-
- { Defend against bogus message number }
- if (msgtext = '') then
- begin
- err^.msg_parm.i[0] := int(msg_code);
- msgtext := err^.jpeg_message_table^[JMSG_NOMESSAGE];
- end;
-
- { Check for string parameter, as indicated by %s in the message text }
- isstring := Pos('%s', msgtext) > 0;
-
- { Format the message into the passed buffer }
- if (isstring) then
- buffer := Concat(msgtext, err^.msg_parm.s)
- else
- begin
- {$IFDEF VER70}
- FormatStr(buffer, msgtext, err^.msg_parm.i);
- {$ELSE}
- {$IFDEF NO_FORMAT}
- buffer := msgtext;
- {$ELSE}
- buffer := Format(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] ]);
- {$ENDIF}
- {$ENDIF}
- end;
-end;
-
-
-
-{ 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}
-procedure reset_error_mgr (cinfo : j_common_ptr); far;
-begin
- 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" }
-end;
-
-
-{ Fill in the standard error-handling methods in a jpeg_error_mgr object.
- Typical call is:
- cinfo : jpeg_compress_struct;
- err : jpeg_error_mgr;
-
- cinfo.err := jpeg_std_error(@err);
- after which the application may override some of the methods. }
-
-
-{GLOBAL}
-function jpeg_std_error (var err : jpeg_error_mgr) : jpeg_error_mgr_ptr;
-begin
- 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 := pred(JMSG_LASTMSGCODE);
-
- err.addon_message_table := NIL;
- err.first_addon_message := JMSG_NOMESSAGE; { for safety }
- err.last_addon_message := JMSG_NOMESSAGE;
-
- jpeg_std_error := @err;
-end;
-
-
-end.
diff --git a/packages/base/pasjpeg/jfdctflt.pas b/packages/base/pasjpeg/jfdctflt.pas
deleted file mode 100644
index 9dddb4fb25..0000000000
--- a/packages/base/pasjpeg/jfdctflt.pas
+++ /dev/null
@@ -1,176 +0,0 @@
-Unit JFDctFlt;
-
-{$N+}
-{ This file contains a floating-point implementation of the
- forward DCT (Discrete Cosine Transform).
-
- This implementation should be more accurate than either of the integer
- DCT implementations. However, it may not give the same results on all
- machines because of differences in roundoff behavior. Speed will depend
- on the hardware's floating point capacity.
-
- A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
- on each column. Direct algorithms are also available, but they are
- much more complex and seem not to be any faster when reduced to code.
-
- This implementation is based on Arai, Agui, and Nakajima's algorithm for
- scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
- Japanese, but the algorithm is described in the Pennebaker & Mitchell
- JPEG textbook (see REFERENCES section in file README). The following code
- is based directly on figure 4-8 in P&M.
- While an 8-point DCT cannot be done in less than 11 multiplies, it is
- possible to arrange the computation so that many of the multiplies are
- simple scalings of the final outputs. These multiplies can then be
- folded into the multiplications or divisions by the JPEG quantization
- table entries. The AA&N method leaves only 5 multiplies and 29 adds
- to be done in the DCT itself.
- The primary disadvantage of this method is that with a fixed-point
- implementation, accuracy is lost due to imprecise representation of the
- scaled quantization values. However, that problem does not arise if
- we use floating point arithmetic. }
-
-{ Original : jfdctflt.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jpeglib,
- jdct; { Private declarations for DCT subsystem }
-
-
-{ Perform the forward DCT on one block of samples.}
-
-{GLOBAL}
-procedure jpeg_fdct_float (var data : array of FAST_FLOAT);
-
-implementation
-
-{ This module is specialized to the case DCTSIZE = 8. }
-
-{$ifndef DCTSIZE_IS_8}
- Sorry, this code only copes with 8x8 DCTs. { deliberate syntax err }
-{$endif}
-
-
-{ Perform the forward DCT on one block of samples.}
-
-{GLOBAL}
-procedure jpeg_fdct_float (var data : array of FAST_FLOAT);
-type
- PWorkspace = ^TWorkspace;
- TWorkspace = array [0..DCTSIZE2-1] of FAST_FLOAT;
-var
- tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7 : FAST_FLOAT;
- tmp10, tmp11, tmp12, tmp13 : FAST_FLOAT;
- z1, z2, z3, z4, z5, z11, z13 : FAST_FLOAT;
- dataptr : PWorkspace;
- ctr : int;
-begin
- { Pass 1: process rows. }
-
- dataptr := PWorkspace(@data);
- for ctr := DCTSIZE-1 downto 0 do
- begin
- tmp0 := dataptr^[0] + dataptr^[7];
- tmp7 := dataptr^[0] - dataptr^[7];
- tmp1 := dataptr^[1] + dataptr^[6];
- tmp6 := dataptr^[1] - dataptr^[6];
- tmp2 := dataptr^[2] + dataptr^[5];
- tmp5 := dataptr^[2] - dataptr^[5];
- tmp3 := dataptr^[3] + dataptr^[4];
- tmp4 := dataptr^[3] - dataptr^[4];
-
- { Even part }
-
- tmp10 := tmp0 + tmp3; { phase 2 }
- tmp13 := tmp0 - tmp3;
- tmp11 := tmp1 + tmp2;
- tmp12 := tmp1 - tmp2;
-
- dataptr^[0] := tmp10 + tmp11; { phase 3 }
- dataptr^[4] := tmp10 - tmp11;
-
- z1 := (tmp12 + tmp13) * ({FAST_FLOAT}(0.707106781)); { c4 }
- dataptr^[2] := tmp13 + z1; { phase 5 }
- dataptr^[6] := tmp13 - z1;
-
- { Odd part }
-
- tmp10 := tmp4 + tmp5; { phase 2 }
- tmp11 := tmp5 + tmp6;
- tmp12 := tmp6 + tmp7;
-
- { The rotator is modified from fig 4-8 to avoid extra negations. }
- z5 := (tmp10 - tmp12) * ( {FAST_FLOAT}(0.382683433)); { c6 }
- z2 := {FAST_FLOAT}(0.541196100) * tmp10 + z5; { c2-c6 }
- z4 := {FAST_FLOAT}(1.306562965) * tmp12 + z5; { c2+c6 }
- z3 := tmp11 * {FAST_FLOAT} (0.707106781); { c4 }
-
- z11 := tmp7 + z3; { phase 5 }
- z13 := tmp7 - z3;
-
- dataptr^[5] := z13 + z2; { phase 6 }
- dataptr^[3] := z13 - z2;
- dataptr^[1] := z11 + z4;
- dataptr^[7] := z11 - z4;
-
- Inc(FAST_FLOAT_PTR(dataptr), DCTSIZE); { advance pointer to next row }
- end;
-
- { Pass 2: process columns. }
-
- dataptr := PWorkspace(@data);
- for ctr := DCTSIZE-1 downto 0 do
- begin
- tmp0 := dataptr^[DCTSIZE*0] + dataptr^[DCTSIZE*7];
- tmp7 := dataptr^[DCTSIZE*0] - dataptr^[DCTSIZE*7];
- tmp1 := dataptr^[DCTSIZE*1] + dataptr^[DCTSIZE*6];
- tmp6 := dataptr^[DCTSIZE*1] - dataptr^[DCTSIZE*6];
- tmp2 := dataptr^[DCTSIZE*2] + dataptr^[DCTSIZE*5];
- tmp5 := dataptr^[DCTSIZE*2] - dataptr^[DCTSIZE*5];
- tmp3 := dataptr^[DCTSIZE*3] + dataptr^[DCTSIZE*4];
- tmp4 := dataptr^[DCTSIZE*3] - dataptr^[DCTSIZE*4];
-
- { Even part }
-
- tmp10 := tmp0 + tmp3; { phase 2 }
- tmp13 := tmp0 - tmp3;
- tmp11 := tmp1 + tmp2;
- tmp12 := tmp1 - tmp2;
-
- dataptr^[DCTSIZE*0] := tmp10 + tmp11; { phase 3 }
- dataptr^[DCTSIZE*4] := tmp10 - tmp11;
-
- z1 := (tmp12 + tmp13) * {FAST_FLOAT} (0.707106781); { c4 }
- dataptr^[DCTSIZE*2] := tmp13 + z1; { phase 5 }
- dataptr^[DCTSIZE*6] := tmp13 - z1;
-
- { Odd part }
-
- tmp10 := tmp4 + tmp5; { phase 2 }
- tmp11 := tmp5 + tmp6;
- tmp12 := tmp6 + tmp7;
-
- { The rotator is modified from fig 4-8 to avoid extra negations. }
- z5 := (tmp10 - tmp12) * {FAST_FLOAT} (0.382683433); { c6 }
- z2 := {FAST_FLOAT} (0.541196100) * tmp10 + z5; { c2-c6 }
- z4 := {FAST_FLOAT} (1.306562965) * tmp12 + z5; { c2+c6 }
- z3 := tmp11 * {FAST_FLOAT} (0.707106781); { c4 }
-
- z11 := tmp7 + z3; { phase 5 }
- z13 := tmp7 - z3;
-
- dataptr^[DCTSIZE*5] := z13 + z2; { phase 6 }
- dataptr^[DCTSIZE*3] := z13 - z2;
- dataptr^[DCTSIZE*1] := z11 + z4;
- dataptr^[DCTSIZE*7] := z11 - z4;
-
- Inc(FAST_FLOAT_PTR(dataptr)); { advance pointer to next column }
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jfdctfst.pas b/packages/base/pasjpeg/jfdctfst.pas
deleted file mode 100644
index faf4121bc7..0000000000
--- a/packages/base/pasjpeg/jfdctfst.pas
+++ /dev/null
@@ -1,237 +0,0 @@
-Unit JFDctFst;
-
-{ This file contains a fast, not so accurate integer implementation of the
- forward DCT (Discrete Cosine Transform).
-
- A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
- on each column. Direct algorithms are also available, but they are
- much more complex and seem not to be any faster when reduced to code.
-
- This implementation is based on Arai, Agui, and Nakajima's algorithm for
- scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
- Japanese, but the algorithm is described in the Pennebaker & Mitchell
- JPEG textbook (see REFERENCES section in file README). The following code
- is based directly on figure 4-8 in P&M.
- While an 8-point DCT cannot be done in less than 11 multiplies, it is
- possible to arrange the computation so that many of the multiplies are
- simple scalings of the final outputs. These multiplies can then be
- folded into the multiplications or divisions by the JPEG quantization
- table entries. The AA&N method leaves only 5 multiplies and 29 adds
- to be done in the DCT itself.
- The primary disadvantage of this method is that with fixed-point math,
- accuracy is lost due to imprecise representation of the scaled
- quantization values. The smaller the quantization table entry, the less
- precise the scaled value, so this implementation does worse with high-
- quality-setting files than with low-quality ones. }
-
-{ Original: jfdctfst.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jpeglib,
- jdct; { Private declarations for DCT subsystem }
-
-
-{ Perform the forward DCT on one block of samples. }
-
-{GLOBAL}
-procedure jpeg_fdct_ifast (var data : array of DCTELEM);
-
-implementation
-
-{ This module is specialized to the case DCTSIZE = 8. }
-
-{$ifndef DCTSIZE_IS_8}
- Sorry, this code only copes with 8x8 DCTs. { deliberate syntax err }
-{$endif}
-
-
-{ Scaling decisions are generally the same as in the LL&M algorithm;
- see jfdctint.c for more details. However, we choose to descale
- (right shift) multiplication products as soon as they are formed,
- rather than carrying additional fractional bits into subsequent additions.
- This compromises accuracy slightly, but it lets us save a few shifts.
- More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)
- everywhere except in the multiplications proper; this saves a good deal
- of work on 16-bit-int machines.
-
- Again to save a few shifts, the intermediate results between pass 1 and
- pass 2 are not upscaled, but are represented only to integral precision.
-
- A final compromise is to represent the multiplicative constants to only
- 8 fractional bits, rather than 13. This saves some shifting work on some
- machines, and may also reduce the cost of multiplication (since there
- are fewer one-bits in the constants). }
-
-const
- CONST_BITS = 8;
-const
- CONST_SCALE = (INT32(1) shl CONST_BITS);
-
-
-const
- FIX_0_382683433 = INT32(Round(CONST_SCALE * 0.382683433)); {98}
- FIX_0_541196100 = INT32(Round(CONST_SCALE * 0.541196100)); {139}
- FIX_0_707106781 = INT32(Round(CONST_SCALE * 0.707106781)); {181}
- FIX_1_306562965 = INT32(Round(CONST_SCALE * 1.306562965)); {334}
-
-{ Descale and correctly round an INT32 value that's scaled by N bits.
- We assume RIGHT_SHIFT rounds towards minus infinity, so adding
- the fudge factor is correct for either sign of X. }
-
-function DESCALE(x : INT32; n : int) : INT32;
-var
- shift_temp : INT32;
-begin
-{ We can gain a little more speed, with a further compromise in accuracy,
- by omitting the addition in a descaling shift. This yields an incorrectly
- rounded result half the time... }
-{$ifndef USE_ACCURATE_ROUNDING}
- shift_temp := x;
-{$else}
- shift_temp := x + (INT32(1) shl (n-1));
-{$endif}
-
-{$ifdef RIGHT_SHIFT_IS_UNSIGNED}
- if shift_temp < 0 then
- Descale := (shift_temp shr n) or ((not INT32(0)) shl (32-n))
- else
-{$endif}
- Descale := (shift_temp shr n);
-end;
-
-{ Multiply a DCTELEM variable by an INT32 constant, and immediately
- descale to yield a DCTELEM result. }
-
-
- function MULTIPLY(X : DCTELEM; Y: INT32): DCTELEM;
- begin
- Multiply := DeScale((X) * (Y), CONST_BITS);
- end;
-
-
-{ Perform the forward DCT on one block of samples. }
-
-{GLOBAL}
-procedure jpeg_fdct_ifast (var data : array of DCTELEM);
-type
- PWorkspace = ^TWorkspace;
- TWorkspace = array [0..DCTSIZE2-1] of DCTELEM;
-var
- tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7 : DCTELEM;
- tmp10, tmp11, tmp12, tmp13 : DCTELEM;
- z1, z2, z3, z4, z5, z11, z13 : DCTELEM;
- dataptr : PWorkspace;
- ctr : int;
- {SHIFT_TEMPS}
-begin
- { Pass 1: process rows. }
-
- dataptr := PWorkspace(@data);
- for ctr := DCTSIZE-1 downto 0 do
- begin
- tmp0 := dataptr^[0] + dataptr^[7];
- tmp7 := dataptr^[0] - dataptr^[7];
- tmp1 := dataptr^[1] + dataptr^[6];
- tmp6 := dataptr^[1] - dataptr^[6];
- tmp2 := dataptr^[2] + dataptr^[5];
- tmp5 := dataptr^[2] - dataptr^[5];
- tmp3 := dataptr^[3] + dataptr^[4];
- tmp4 := dataptr^[3] - dataptr^[4];
-
- { Even part }
-
- tmp10 := tmp0 + tmp3; { phase 2 }
- tmp13 := tmp0 - tmp3;
- tmp11 := tmp1 + tmp2;
- tmp12 := tmp1 - tmp2;
-
- dataptr^[0] := tmp10 + tmp11; { phase 3 }
- dataptr^[4] := tmp10 - tmp11;
-
- z1 := MULTIPLY(tmp12 + tmp13, FIX_0_707106781); { c4 }
- dataptr^[2] := tmp13 + z1; { phase 5 }
- dataptr^[6] := tmp13 - z1;
-
- { Odd part }
-
- tmp10 := tmp4 + tmp5; { phase 2 }
- tmp11 := tmp5 + tmp6;
- tmp12 := tmp6 + tmp7;
-
- { The rotator is modified from fig 4-8 to avoid extra negations. }
- z5 := MULTIPLY(tmp10 - tmp12, FIX_0_382683433); { c6 }
- z2 := MULTIPLY(tmp10, FIX_0_541196100) + z5; { c2-c6 }
- z4 := MULTIPLY(tmp12, FIX_1_306562965) + z5; { c2+c6 }
- z3 := MULTIPLY(tmp11, FIX_0_707106781); { c4 }
-
- z11 := tmp7 + z3; { phase 5 }
- z13 := tmp7 - z3;
-
- dataptr^[5] := z13 + z2; { phase 6 }
- dataptr^[3] := z13 - z2;
- dataptr^[1] := z11 + z4;
- dataptr^[7] := z11 - z4;
-
- Inc(DCTELEMPTR(dataptr), DCTSIZE); { advance pointer to next row }
- end;
-
- { Pass 2: process columns. }
-
- dataptr := PWorkspace(@data);
- for ctr := DCTSIZE-1 downto 0 do
- begin
- tmp0 := dataptr^[DCTSIZE*0] + dataptr^[DCTSIZE*7];
- tmp7 := dataptr^[DCTSIZE*0] - dataptr^[DCTSIZE*7];
- tmp1 := dataptr^[DCTSIZE*1] + dataptr^[DCTSIZE*6];
- tmp6 := dataptr^[DCTSIZE*1] - dataptr^[DCTSIZE*6];
- tmp2 := dataptr^[DCTSIZE*2] + dataptr^[DCTSIZE*5];
- tmp5 := dataptr^[DCTSIZE*2] - dataptr^[DCTSIZE*5];
- tmp3 := dataptr^[DCTSIZE*3] + dataptr^[DCTSIZE*4];
- tmp4 := dataptr^[DCTSIZE*3] - dataptr^[DCTSIZE*4];
-
- { Even part }
-
- tmp10 := tmp0 + tmp3; { phase 2 }
- tmp13 := tmp0 - tmp3;
- tmp11 := tmp1 + tmp2;
- tmp12 := tmp1 - tmp2;
-
- dataptr^[DCTSIZE*0] := tmp10 + tmp11; { phase 3 }
- dataptr^[DCTSIZE*4] := tmp10 - tmp11;
-
- z1 := MULTIPLY(tmp12 + tmp13, FIX_0_707106781); { c4 }
- dataptr^[DCTSIZE*2] := tmp13 + z1; { phase 5 }
- dataptr^[DCTSIZE*6] := tmp13 - z1;
-
- { Odd part }
-
- tmp10 := tmp4 + tmp5; { phase 2 }
- tmp11 := tmp5 + tmp6;
- tmp12 := tmp6 + tmp7;
-
- { The rotator is modified from fig 4-8 to avoid extra negations. }
- z5 := MULTIPLY(tmp10 - tmp12, FIX_0_382683433); { c6 }
- z2 := MULTIPLY(tmp10, FIX_0_541196100) + z5; { c2-c6 }
- z4 := MULTIPLY(tmp12, FIX_1_306562965) + z5; { c2+c6 }
- z3 := MULTIPLY(tmp11, FIX_0_707106781); { c4 }
-
- z11 := tmp7 + z3; { phase 5 }
- z13 := tmp7 - z3;
-
- dataptr^[DCTSIZE*5] := z13 + z2; { phase 6 }
- dataptr^[DCTSIZE*3] := z13 - z2;
- dataptr^[DCTSIZE*1] := z11 + z4;
- dataptr^[DCTSIZE*7] := z11 - z4;
-
- Inc(DCTELEMPTR(dataptr)); { advance pointer to next column }
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jfdctint.pas b/packages/base/pasjpeg/jfdctint.pas
deleted file mode 100644
index 22bc63aace..0000000000
--- a/packages/base/pasjpeg/jfdctint.pas
+++ /dev/null
@@ -1,297 +0,0 @@
-Unit JFDctInt;
-
-
-{ This file contains a slow-but-accurate integer implementation of the
- forward DCT (Discrete Cosine Transform).
-
- A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
- on each column. Direct algorithms are also available, but they are
- much more complex and seem not to be any faster when reduced to code.
-
- This implementation is based on an algorithm described in
- C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
- Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
- Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
- The primary algorithm described there uses 11 multiplies and 29 adds.
- We use their alternate method with 12 multiplies and 32 adds.
- The advantage of this method is that no data path contains more than one
- multiplication; this allows a very simple and accurate implementation in
- scaled fixed-point arithmetic, with a minimal number of shifts. }
-
-{ Original : jfdctint.c ; Copyright (C) 1991-1996, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jutils,
- jpeglib,
- jdct; { Private declarations for DCT subsystem }
-
-
-{ Perform the forward DCT on one block of samples. }
-
-{GLOBAL}
-procedure jpeg_fdct_islow (var data : array of DCTELEM);
-
-implementation
-
-{ This module is specialized to the case DCTSIZE = 8. }
-
-{$ifndef DCTSIZE_IS_8}
- Sorry, this code only copes with 8x8 DCTs. { deliberate syntax err }
-{$endif}
-
-
-{ The poop on this scaling stuff is as follows:
-
- Each 1-D DCT step produces outputs which are a factor of sqrt(N)
- larger than the true DCT outputs. The final outputs are therefore
- a factor of N larger than desired; since N=8 this can be cured by
- a simple right shift at the end of the algorithm. The advantage of
- this arrangement is that we save two multiplications per 1-D DCT,
- because the y0 and y4 outputs need not be divided by sqrt(N).
- In the IJG code, this factor of 8 is removed by the quantization step
- (in jcdctmgr.c), NOT in this module.
-
- We have to do addition and subtraction of the integer inputs, which
- is no problem, and multiplication by fractional constants, which is
- a problem to do in integer arithmetic. We multiply all the constants
- by CONST_SCALE and convert them to integer constants (thus retaining
- CONST_BITS bits of precision in the constants). After doing a
- multiplication we have to divide the product by CONST_SCALE, with proper
- rounding, to produce the correct output. This division can be done
- cheaply as a right shift of CONST_BITS bits. We postpone shifting
- as long as possible so that partial sums can be added together with
- full fractional precision.
-
- The outputs of the first pass are scaled up by PASS1_BITS bits so that
- they are represented to better-than-integral precision. These outputs
- require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
- with the recommended scaling. (For 12-bit sample data, the intermediate
- array is INT32 anyway.)
-
- To avoid overflow of the 32-bit intermediate results in pass 2, we must
- have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
- shows that the values given below are the most effective. }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-const
- CONST_BITS = 13;
- PASS1_BITS = 2;
-{$else}
-const
- CONST_BITS = 13;
- PASS1_BITS = 1; { lose a little precision to avoid overflow }
-{$endif}
-
-const
- CONST_SCALE = (INT32(1) shl CONST_BITS);
-
-const
- FIX_0_298631336 = INT32(Round(CONST_SCALE * 0.298631336)); {2446}
- FIX_0_390180644 = INT32(Round(CONST_SCALE * 0.390180644)); {3196}
- FIX_0_541196100 = INT32(Round(CONST_SCALE * 0.541196100)); {4433}
- FIX_0_765366865 = INT32(Round(CONST_SCALE * 0.765366865)); {6270}
- FIX_0_899976223 = INT32(Round(CONST_SCALE * 0.899976223)); {7373}
- FIX_1_175875602 = INT32(Round(CONST_SCALE * 1.175875602)); {9633}
- FIX_1_501321110 = INT32(Round(CONST_SCALE * 1.501321110)); {12299}
- FIX_1_847759065 = INT32(Round(CONST_SCALE * 1.847759065)); {15137}
- FIX_1_961570560 = INT32(Round(CONST_SCALE * 1.961570560)); {16069}
- FIX_2_053119869 = INT32(Round(CONST_SCALE * 2.053119869)); {16819}
- FIX_2_562915447 = INT32(Round(CONST_SCALE * 2.562915447)); {20995}
- FIX_3_072711026 = INT32(Round(CONST_SCALE * 3.072711026)); {25172}
-
-
-{ Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
- For 8-bit samples with the recommended scaling, all the variable
- and constant values involved are no more than 16 bits wide, so a
- 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
- For 12-bit samples, a full 32-bit multiplication will be needed. }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-
- {MULTIPLY16C16(var,const)}
- function Multiply(X, Y: int): INT32;
- begin
- Multiply := int(X) * INT32(Y);
- end;
-
-{$else}
- function Multiply(X, Y: INT32): INT32;
- begin
- Multiply := X * Y;
- end;
-{$endif}
-
-{ Descale and correctly round an INT32 value that's scaled by N bits.
- We assume RIGHT_SHIFT rounds towards minus infinity, so adding
- the fudge factor is correct for either sign of X. }
-
-function DESCALE(x : INT32; n : int) : INT32;
-var
- shift_temp : INT32;
-begin
-{$ifdef RIGHT_SHIFT_IS_UNSIGNED}
- shift_temp := x + (INT32(1) shl (n-1));
- if shift_temp < 0 then
- Descale := (shift_temp shr n) or ((not INT32(0)) shl (32-n))
- else
- Descale := (shift_temp shr n);
-{$else}
- Descale := (x + (INT32(1) shl (n-1)) shr n;
-{$endif}
-end;
-
-
-{ Perform the forward DCT on one block of samples. }
-
-{GLOBAL}
-procedure jpeg_fdct_islow (var data : array of DCTELEM);
-type
- PWorkspace = ^TWorkspace;
- TWorkspace = array [0..DCTSIZE2-1] of DCTELEM;
-var
- tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7 : INT32;
- tmp10, tmp11, tmp12, tmp13 : INT32;
- z1, z2, z3, z4, z5 : INT32;
- dataptr : PWorkspace;
- ctr : int;
- {SHIFT_TEMPS}
-begin
-
- { Pass 1: process rows. }
- { Note results are scaled up by sqrt(8) compared to a true DCT; }
- { furthermore, we scale the results by 2**PASS1_BITS. }
-
- dataptr := PWorkspace(@data);
- for ctr := DCTSIZE-1 downto 0 do
- begin
- tmp0 := dataptr^[0] + dataptr^[7];
- tmp7 := dataptr^[0] - dataptr^[7];
- tmp1 := dataptr^[1] + dataptr^[6];
- tmp6 := dataptr^[1] - dataptr^[6];
- tmp2 := dataptr^[2] + dataptr^[5];
- tmp5 := dataptr^[2] - dataptr^[5];
- tmp3 := dataptr^[3] + dataptr^[4];
- tmp4 := dataptr^[3] - dataptr^[4];
-
- { Even part per LL&M figure 1 --- note that published figure is faulty;
- rotator "sqrt(2)*c1" should be "sqrt(2)*c6". }
-
- tmp10 := tmp0 + tmp3;
- tmp13 := tmp0 - tmp3;
- tmp11 := tmp1 + tmp2;
- tmp12 := tmp1 - tmp2;
-
- dataptr^[0] := DCTELEM ((tmp10 + tmp11) shl PASS1_BITS);
- dataptr^[4] := DCTELEM ((tmp10 - tmp11) shl PASS1_BITS);
-
- z1 := MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
- dataptr^[2] := DCTELEM (DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
- CONST_BITS-PASS1_BITS));
- dataptr^[6] := DCTELEM (DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
- CONST_BITS-PASS1_BITS));
-
- { Odd part per figure 8 --- note paper omits factor of sqrt(2).
- cK represents cos(K*pi/16).
- i0..i3 in the paper are tmp4..tmp7 here. }
-
- z1 := tmp4 + tmp7;
- z2 := tmp5 + tmp6;
- z3 := tmp4 + tmp6;
- z4 := tmp5 + tmp7;
- z5 := MULTIPLY(z3 + z4, FIX_1_175875602); { sqrt(2) * c3 }
-
- tmp4 := MULTIPLY(tmp4, FIX_0_298631336); { sqrt(2) * (-c1+c3+c5-c7) }
- tmp5 := MULTIPLY(tmp5, FIX_2_053119869); { sqrt(2) * ( c1+c3-c5+c7) }
- tmp6 := MULTIPLY(tmp6, FIX_3_072711026); { sqrt(2) * ( c1+c3+c5-c7) }
- tmp7 := MULTIPLY(tmp7, FIX_1_501321110); { sqrt(2) * ( c1+c3-c5-c7) }
- z1 := MULTIPLY(z1, - FIX_0_899976223); { sqrt(2) * (c7-c3) }
- z2 := MULTIPLY(z2, - FIX_2_562915447); { sqrt(2) * (-c1-c3) }
- z3 := MULTIPLY(z3, - FIX_1_961570560); { sqrt(2) * (-c3-c5) }
- z4 := MULTIPLY(z4, - FIX_0_390180644); { sqrt(2) * (c5-c3) }
-
- Inc(z3, z5);
- Inc(z4, z5);
-
- dataptr^[7] := DCTELEM(DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS));
- dataptr^[5] := DCTELEM(DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS));
- dataptr^[3] := DCTELEM(DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS));
- dataptr^[1] := DCTELEM(DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS));
-
- Inc(DCTELEMPTR(dataptr), DCTSIZE); { advance pointer to next row }
- end;
-
- { Pass 2: process columns.
- We remove the PASS1_BITS scaling, but leave the results scaled up
- by an overall factor of 8. }
-
- dataptr := PWorkspace(@data);
- for ctr := DCTSIZE-1 downto 0 do
- begin
- tmp0 := dataptr^[DCTSIZE*0] + dataptr^[DCTSIZE*7];
- tmp7 := dataptr^[DCTSIZE*0] - dataptr^[DCTSIZE*7];
- tmp1 := dataptr^[DCTSIZE*1] + dataptr^[DCTSIZE*6];
- tmp6 := dataptr^[DCTSIZE*1] - dataptr^[DCTSIZE*6];
- tmp2 := dataptr^[DCTSIZE*2] + dataptr^[DCTSIZE*5];
- tmp5 := dataptr^[DCTSIZE*2] - dataptr^[DCTSIZE*5];
- tmp3 := dataptr^[DCTSIZE*3] + dataptr^[DCTSIZE*4];
- tmp4 := dataptr^[DCTSIZE*3] - dataptr^[DCTSIZE*4];
-
- { Even part per LL&M figure 1 --- note that published figure is faulty;
- rotator "sqrt(2)*c1" should be "sqrt(2)*c6". }
-
- tmp10 := tmp0 + tmp3;
- tmp13 := tmp0 - tmp3;
- tmp11 := tmp1 + tmp2;
- tmp12 := tmp1 - tmp2;
-
- dataptr^[DCTSIZE*0] := DCTELEM (DESCALE(tmp10 + tmp11, PASS1_BITS));
- dataptr^[DCTSIZE*4] := DCTELEM (DESCALE(tmp10 - tmp11, PASS1_BITS));
-
- z1 := MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
- dataptr^[DCTSIZE*2] := DCTELEM (DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
- CONST_BITS+PASS1_BITS));
- dataptr^[DCTSIZE*6] := DCTELEM (DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
- CONST_BITS+PASS1_BITS));
-
- { Odd part per figure 8 --- note paper omits factor of sqrt(2).
- cK represents cos(K*pi/16).
- i0..i3 in the paper are tmp4..tmp7 here. }
-
- z1 := tmp4 + tmp7;
- z2 := tmp5 + tmp6;
- z3 := tmp4 + tmp6;
- z4 := tmp5 + tmp7;
- z5 := MULTIPLY(z3 + z4, FIX_1_175875602); { sqrt(2) * c3 }
-
- tmp4 := MULTIPLY(tmp4, FIX_0_298631336); { sqrt(2) * (-c1+c3+c5-c7) }
- tmp5 := MULTIPLY(tmp5, FIX_2_053119869); { sqrt(2) * ( c1+c3-c5+c7) }
- tmp6 := MULTIPLY(tmp6, FIX_3_072711026); { sqrt(2) * ( c1+c3+c5-c7) }
- tmp7 := MULTIPLY(tmp7, FIX_1_501321110); { sqrt(2) * ( c1+c3-c5-c7) }
- z1 := MULTIPLY(z1, - FIX_0_899976223); { sqrt(2) * (c7-c3) }
- z2 := MULTIPLY(z2, - FIX_2_562915447); { sqrt(2) * (-c1-c3) }
- z3 := MULTIPLY(z3, - FIX_1_961570560); { sqrt(2) * (-c3-c5) }
- z4 := MULTIPLY(z4, - FIX_0_390180644); { sqrt(2) * (c5-c3) }
-
- Inc(z3, z5);
- Inc(z4, z5);
-
- dataptr^[DCTSIZE*7] := DCTELEM (DESCALE(tmp4 + z1 + z3,
- CONST_BITS+PASS1_BITS));
- dataptr^[DCTSIZE*5] := DCTELEM (DESCALE(tmp5 + z2 + z4,
- CONST_BITS+PASS1_BITS));
- dataptr^[DCTSIZE*3] := DCTELEM (DESCALE(tmp6 + z2 + z3,
- CONST_BITS+PASS1_BITS));
- dataptr^[DCTSIZE*1] := DCTELEM (DESCALE(tmp7 + z1 + z4,
- CONST_BITS+PASS1_BITS));
-
- Inc(DCTELEMPTR(dataptr)); { advance pointer to next column }
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jidct2d.pas b/packages/base/pasjpeg/jidct2d.pas
deleted file mode 100644
index bd277502af..0000000000
--- a/packages/base/pasjpeg/jidct2d.pas
+++ /dev/null
@@ -1,1048 +0,0 @@
-Unit JIDct2D;
-
-{ This file contains a fast, not so accurate integer implementation of the
- inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
- must also perform dequantization of the input coefficients.
-
-
- A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
- on each row (or vice versa, but it's more convenient to emit a row at
- a time). Direct algorithms are also available, but they are much more
- complex and seem not to be any faster when reduced to code.
-
- The Feig direct 2D scaled Discrete Cosine Transform extends Arai, Agui
- and Nakajima fast scaled DCT to 2D (464 adds and 80 mult.) with further
- computational saving (462 adds, 54 mults and 6 shits).
-
- The forward DCT is described with flow diagrams from the Pennebaker&
- Mitchell JPEG book. The inverse DCT flow diagrams are obtained
- from the inverse matrices. Scaling must be done accordingly.
-
- Jacques NOMSSI NZALI, May 16th 1995 }
-
-
-interface
-
-uses
- jmorecfg,
- jinclude,
- jpeglib,
- jdct; { Private declarations for DCT subsystem }
-
-{$I jconfig.inc}
-
-{ Perform dequantization and inverse DCT on one block of coefficients. }
-
-{GLOBAL}
-procedure jpeg_idct_i2d (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-
-implementation
-
-{ This module is specialized to the case DCTSIZE = 8. }
-
-{$ifndef DCTSIZE_IS_8}
- Sorry, this code only copes with 8x8 DCTs. { deliberate syntax err }
-{$endif}
-
-{ Scaling decisions are generally the same as in the LL&M algorithm;
- see jidctint.c for more details. However, we choose to descale
- (right shift) multiplication products as soon as they are formed,
- rather than carrying additional fractional bits into subsequent additions.
- This compromises accuracy slightly, but it lets us save a few shifts.
- More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)
- everywhere except in the multiplications proper; this saves a good deal
- of work on 16-bit-int machines.
-
- The dequantized coefficients are not integers because the AA&N scaling
- factors have been incorporated. We represent them scaled up by PASS1_BITS,
- so that the first and second IDCT rounds have the same input scaling.
- For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to
- avoid a descaling shift; this compromises accuracy rather drastically
- for small quantization table entries, but it saves a lot of shifts.
- For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway,
- so we use a much larger scaling factor to preserve accuracy.
-
- A final compromise is to represent the multiplicative constants to only
- 8 fractional bits, rather than 13. This saves some shifting work on some
- machines, and may also reduce the cost of multiplication (since there
- are fewer one-bits in the constants). }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-const
- CONST_BITS = 8;
- PASS1_BITS = 2;
-{$else}
- CONST_BITS = 8;
- PASS1_BITS = 1; { lose a little precision to avoid overflow }
-{$endif}
-
-
-{ Convert a positive real constant to an integer scaled by CONST_SCALE. }
-const
- CONST_SCALE = (INT32(1) shl CONST_BITS);
-const
- FIX_1_082392200 = INT32(Round(CONST_SCALE*1.082392200)); {277}
- FIX_1_414213562 = INT32(Round(CONST_SCALE*1.414213562)); {362}
- FIX_1_847759065 = INT32(Round(CONST_SCALE*1.847759065)); {473}
- FIX_2_613125930 = INT32(Round(CONST_SCALE*2.613125930)); {669}
-
-
-{ Descale and correctly round an INT32 value that's scaled by N bits.
- We assume RIGHT_SHIFT rounds towards minus infinity, so adding
- the fudge factor is correct for either sign of X. }
-
-function DESCALE(x : INT32; n : int) : INT32;
-var
- shift_temp : INT32;
-begin
-{$ifdef USE_ACCURATE_ROUNDING}
- shift_temp := x + (INT32(1) shl (n-1));
-{$else}
-{ We can gain a little more speed, with a further compromise in accuracy,
- by omitting the addition in a descaling shift. This yields an incorrectly
- rounded result half the time... }
- shift_temp := x;
-{$endif}
-
-{$ifdef RIGHT_SHIFT_IS_UNSIGNED}
- if shift_temp < 0 then
- Descale := (shift_temp shr n) or ((not INT32(0)) shl (32-n))
- else
-{$endif}
- Descale := (shift_temp shr n);
-
-end;
-
-
-{ Multiply a DCTELEM variable by an INT32 constant, and immediately
- descale to yield a DCTELEM result. }
-
- {(DCTELEM( DESCALE((var) * (const), CONST_BITS))}
- function Multiply(Avar, Aconst: Integer): DCTELEM;
- begin
- Multiply := DCTELEM( Avar*INT32(Aconst) div CONST_SCALE);
- end;
-
-
-
-{ Dequantize a coefficient by multiplying it by the multiplier-table
- entry; produce a DCTELEM result. For 8-bit data a 16x16->16
- multiplication will do. For 12-bit data, the multiplier table is
- declared INT32, so a 32-bit multiply will be used. }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
- function DEQUANTIZE(coef,quantval : int) : int;
- begin
- Dequantize := ( IFAST_MULT_TYPE(coef) * quantval);
- end;
-
-{$else}
-#define DEQUANTIZE(coef,quantval) \
- DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
-{$endif}
-
-
-{ Like DESCALE, but applies to a DCTELEM and produces an int.
- We assume that int right shift is unsigned if INT32 right shift is. }
-
-function IDESCALE(x : DCTELEM; n : int) : int;
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-const
- DCTELEMBITS = 16; { DCTELEM may be 16 or 32 bits }
-{$else}
-const
- DCTELEMBITS = 32; { DCTELEM must be 32 bits }
-{$endif}
-var
- ishift_temp : DCTELEM;
-begin
-{$ifndef USE_ACCURATE_ROUNDING}
- ishift_temp := x + (INT32(1) shl (n-1));
-{$else}
-{ We can gain a little more speed, with a further compromise in accuracy,
- by omitting the addition in a descaling shift. This yields an incorrectly
- rounded result half the time... }
- ishift_temp := x;
-{$endif}
-
-{$ifdef RIGHT_SHIFT_IS_UNSIGNED}
- if ishift_temp < 0 then
- IDescale := (ishift_temp shr n)
- or ((not DCTELEM(0)) shl (DCTELEMBITS-n))
- else
-{$endif}
- IDescale := (ishift_temp shr n);
-end;
-
-
-
-{ Perform dequantization and inverse DCT on one block of coefficients. }
-
-{GLOBAL}
-procedure jpeg_idct_i2d (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-Const
- CONST_IC4 = 1.414213562; { 1/0.707106781; }
- FP_IC4 = FIX_1_414213562;
- FP_I_C4_2 = FP_IC4;
-
-type
- PWorkspace = ^TWorkspace;
- TWorkspace = coef_bits_field; { buffers data between passes }
-
- Procedure N1(var x, y : integer); { rotator 1 }
- Const
- FP_a5 = FIX_1_847759065;
- FP_a4 = FIX_2_613125930;
- FP_a2 = FIX_1_082392200;
- var
- z5, tmp : integer;
- begin
- tmp := x;
-
- z5 := Multiply(tmp + y, FP_a5); { c6 }
- x := Multiply(y, FP_a2) - z5; { c2-c6 }
- y := Multiply(tmp, -FP_a4) + z5; { c2+c6 }
- end;
-
- Procedure N2(var x, y : integer); { N1 scaled by c4 }
- Const
- FP_b5 = Integer(Round(CONST_SCALE*1.847759065*CONST_IC4));
- FP_b4 = Integer(Round(CONST_SCALE*2.613125930*CONST_IC4));
- FP_b2 = Integer(Round(CONST_SCALE*1.082392200*CONST_IC4));
- var
- z5, tmp : integer;
- begin
- tmp := x;
-
- z5 := Multiply(tmp + y, FP_b5);
- x := Multiply(y, FP_b2) - z5;
- y := Multiply(tmp,-FP_b4) + z5;
- end;
-
-var
- column, row : byte;
-
-var
- tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7 : DCTELEM;
- tmp10, tmp11, tmp12, tmp13 : DCTELEM;
- z10, z11, z12, z13 : DCTELEM;
- inptr : JCOEFPTR;
-
- quantptr : IFAST_MULT_TYPE_FIELD_PTR;
- wsptr : PWorkspace;
- outptr : JSAMPROW;
- range_limit : JSAMPROW;
- ctr : int;
- workspace : TWorkspace; { buffers data between passes }
- {SHIFT_TEMPS { for DESCALE }
- {ISHIFT_TEMPS { for IDESCALE }
-var
- dcval : int;
-var
- dcval_ : JSAMPLE;
-begin
-{ Each IDCT routine is responsible for range-limiting its results and
- converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
- be quite far out of range if the input data is corrupt, so a bulletproof
- range-limiting step is required. We use a mask-and-table-lookup method
- to do the combined operations quickly. See the comments with
- prepare_range_limit_table (in jdmaster.c) for more info. }
-
- range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));
- { Pass 1: process columns from input, store into work array. }
-
- inptr := coef_block;
- quantptr := IFAST_MULT_TYPE_FIELD_PTR(compptr^.dct_table);
- wsptr := @workspace;
- for ctr := pred(DCTSIZE) downto 0 do
- begin
- { short-circuiting is not easily done here }
- // bbo := @outptr;
- for num := 0 to Pred(count) do
- begin
- { R1 x R1 }
- for column := 7 downto 0 do
- BEGIN
- tmp5 := inptr^[1*RowSize + column];
-
- inptr^[1*RowSize + column] := inptr^[4*RowSize + column];
-
- tmp7 := inptr^[3*RowSize + column];
-
- a := inptr^[2*RowSize + column];
- b := inptr^[6*RowSize + column];
- inptr^[2*RowSize + column] := a - b;
- inptr^[3*RowSize + column] := a + b;
-
- a := inptr^[5*RowSize + column];
- inptr^[4*RowSize + column] := a - tmp7;
- z13 := a + tmp7;
-
- b := inptr^[7*RowSize + column];
- inptr^[6*RowSize + column] := tmp5 - b;
- z11 := tmp5 + b;
-
- inptr^[5*RowSize + column] := z11 - z13;
- inptr^[7*RowSize + column] := z11 + z13;
- END;
-
- { Even part }
-
- tmp0 := DEQUANTIZE(inptr^[DCTSIZE*0], quantptr^[DCTSIZE*0]);
- tmp1 := DEQUANTIZE(inptr^[DCTSIZE*2], quantptr^[DCTSIZE*2]);
- tmp2 := DEQUANTIZE(inptr^[DCTSIZE*4], quantptr^[DCTSIZE*4]);
- tmp3 := DEQUANTIZE(inptr^[DCTSIZE*6], quantptr^[DCTSIZE*6]);
-
- tmp10 := tmp0 + tmp2; { phase 3 }
- tmp11 := tmp0 - tmp2;
-
- tmp13 := tmp1 + tmp3; { phases 5-3 }
- tmp12 := MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; { 2*c4 }
-
- tmp0 := tmp10 + tmp13; { phase 2 }
- tmp3 := tmp10 - tmp13;
- tmp1 := tmp11 + tmp12;
- tmp2 := tmp11 - tmp12;
-
- { Odd part }
-
- tmp4 := DEQUANTIZE(inptr^[DCTSIZE*1], quantptr^[DCTSIZE*1]);
- tmp5 := DEQUANTIZE(inptr^[DCTSIZE*3], quantptr^[DCTSIZE*3]);
- tmp6 := DEQUANTIZE(inptr^[DCTSIZE*5], quantptr^[DCTSIZE*5]);
- tmp7 := DEQUANTIZE(inptr^[DCTSIZE*7], quantptr^[DCTSIZE*7]);
-
- z13 := tmp6 + tmp5; { phase 6 }
- z10 := tmp6 - tmp5;
- z11 := tmp4 + tmp7;
- z12 := tmp4 - tmp7;
-
- tmp7 := z11 + z13; { phase 5 }
- tmp11 := MULTIPLY(z11 - z13, FIX_1_414213562); { 2*c4 }
-
- z5 := MULTIPLY(z10 + z12, FIX_1_847759065); { 2*c2 }
- tmp10 := MULTIPLY(z12, FIX_1_082392200) - z5; { 2*(c2-c6) }
- tmp12 := MULTIPLY(z10, - FIX_2_613125930) + z5; { -2*(c2+c6) }
-
- tmp6 := tmp12 - tmp7; { phase 2 }
- tmp5 := tmp11 - tmp6;
- tmp4 := tmp10 + tmp5;
-
- wsptr^[DCTSIZE*0] := int (tmp0 + tmp7);
- wsptr^[DCTSIZE*7] := int (tmp0 - tmp7);
- wsptr^[DCTSIZE*1] := int (tmp1 + tmp6);
- wsptr^[DCTSIZE*6] := int (tmp1 - tmp6);
- wsptr^[DCTSIZE*2] := int (tmp2 + tmp5);
- wsptr^[DCTSIZE*5] := int (tmp2 - tmp5);
- wsptr^[DCTSIZE*4] := int (tmp3 + tmp4);
- wsptr^[DCTSIZE*3] := int (tmp3 - tmp4);
-
- Inc(JCOEF_PTR(inptr)); { advance pointers to next column }
- Inc(IFAST_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
- end;
-
- { Pass 2: process rows from work array, store into output array. }
- { Note that we must descale the results by a factor of 8 == 2**3, }
- { and also undo the PASS1_BITS scaling. }
-
- wsptr := @workspace;
- for ctr := 0 to pred(DCTSIZE) do
- begin
- outptr := JSAMPROW(@output_buf^[ctr]^[output_col]);
- { Rows of zeroes can be exploited in the same way as we did with columns.
- However, the column calculation has created many nonzero AC terms, so
- the simplification applies less often (typically 5% to 10% of the time).
- On machines with very fast multiplication, it's possible that the
- test takes more time than it's worth. In that case this section
- may be commented out. }
-
-{$ifndef NO_ZERO_ROW_TEST}
- if ((wsptr^[1]) or (wsptr^[2]) or (wsptr^[3]) or (wsptr^[4]) or (wsptr^[5]) or
- (wsptr^[6]) or (wsptr^[7]) = 0) then
- begin
- { AC terms all zero }
- JSAMPLE(dcval_) := range_limit^[IDESCALE(wsptr^[0], PASS1_BITS+3)
- and RANGE_MASK];
-
- outptr^[0] := dcval_;
- outptr^[1] := dcval_;
- outptr^[2] := dcval_;
- outptr^[3] := dcval_;
- outptr^[4] := dcval_;
- outptr^[5] := dcval_;
- outptr^[6] := dcval_;
- outptr^[7] := dcval_;
-
- Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- continue;
- end;
-{$endif}
-
- { Even part }
-
- tmp10 := (DCTELEM(wsptr^[0]) + DCTELEM(wsptr^[4]));
- tmp11 := (DCTELEM(wsptr^[0]) - DCTELEM(wsptr^[4]));
-
- tmp13 := (DCTELEM(wsptr^[2]) + DCTELEM(wsptr^[6]));
- tmp12 := MULTIPLY(DCTELEM(wsptr^[2]) - DCTELEM(wsptr^[6]), FIX_1_414213562)
- - tmp13;
-
- tmp0 := tmp10 + tmp13;
- tmp3 := tmp10 - tmp13;
- tmp1 := tmp11 + tmp12;
- tmp2 := tmp11 - tmp12;
-
- { Odd part }
-
- z13 := DCTELEM(wsptr^[5]) + DCTELEM(wsptr^[3]);
- z10 := DCTELEM(wsptr^[5]) - DCTELEM(wsptr^[3]);
- z11 := DCTELEM(wsptr^[1]) + DCTELEM(wsptr^[7]);
- z12 := DCTELEM(wsptr^[1]) - DCTELEM(wsptr^[7]);
-
- tmp7 := z11 + z13; { phase 5 }
- tmp11 := MULTIPLY(z11 - z13, FIX_1_414213562); { 2*c4 }
-
- z5 := MULTIPLY(z10 + z12, FIX_1_847759065); { 2*c2 }
- tmp10 := MULTIPLY(z12, FIX_1_082392200) - z5; { 2*(c2-c6) }
- tmp12 := MULTIPLY(z10, - FIX_2_613125930) + z5; { -2*(c2+c6) }
-
- tmp6 := tmp12 - tmp7; { phase 2 }
- tmp5 := tmp11 - tmp6;
- tmp4 := tmp10 + tmp5;
-
- { Final output stage: scale down by a factor of 8 and range-limit }
-
- outptr^[0] := range_limit^[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[7] := range_limit^[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[1] := range_limit^[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[6] := range_limit^[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[2] := range_limit^[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[5] := range_limit^[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[4] := range_limit^[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[3] := range_limit^[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
- and RANGE_MASK];
-
- Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- end;
-end;
-
-end.
-----------------------------------------------------------
-type
- matasm = array[0..DCTSIZE2-1] of integer;
- bmatrix = array[0..DCTSIZE2-1] of byte;
- bmatrixptr = ^bmatrix;
-procedure ANN_IDCT(var coef_block :matasm;
- var outptr :bmatrix);
-
- var coeffs :matasm; = coef_block
- var outptr :bmatrix); output_buf
-
-Const
- CONST_IC4 = 1.414213562; { 1/0.707106781; }
- FP_IC4 = FIX_1_414213562;
- FP_I_C4_2 = FP_IC4;
-
- Function Descale(x : integer):byte;
- var y : integer;
- begin
- y := (x + (1 shl (16-1))+ (4 shl PASS_BITS)) div (8 shl PASS_BITS);
- { DeScale := x sar (3 + PASS_BITS);
- Borland Pascal SHR is unsigned }
- if y < 0 then
- descale := 0
- else
- if y > $ff then
- descale := $ff
- else
- descale := y;
- end;
-
- function Multiply(X, Y: Integer): integer; assembler;
- asm
- mov ax, X
- imul Y
- mov al, ah
- mov ah, dl
- end;
-
-
-Const
- RowSize = 8;
-var
- a, b : integer;
-
- inptr : JCOEFPTR;
-
- outptr : bmatrixptr;
-
- num : integer;
-begin
-{ Each IDCT routine is responsible for range-limiting its results and
- converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
- be quite far out of range if the input data is corrupt, so a bulletproof
- range-limiting step is required. We use a mask-and-table-lookup method
- to do the combined operations quickly. See the comments with
- prepare_range_limit_table (in jdmaster.c) for more info. }
-
- range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));
- { Pass 1: process columns from input, store into work array. }
-
- inptr := @coef_block; + ctr*RowSize
- quantptr := IFAST_MULT_TYPE_FIELD_PTR(compptr^.dct_table);
-
- for ctr := pred(DCTSIZE) downto 0 do
- BEGIN
- tmp5 := inptr^[1];
-
- inptr^[1] := inptr^[4];
-
- tmp7 := inptr^[3];
-
- a := inptr^[2];
- b := inptr^[6];
- inptr^[2] := a - b;
- inptr^[3] := a + b;
-
- a := inptr^[5];
- inptr^[+ 4] := a - tmp7;
- z13 := a + tmp7;
-
- b := inptr^[7];
- inptr^[6] := tmp5 - b;
- z11 := tmp5 + b;
-
- inptr^[5] := z11 - z13;
- inptr^[7] := z11 + z13;
- END;
-
- { M x M tensor }
- for row := 0 to 7 do
- Case row of
- 0,1,3,7: { M1 }
- begin
- inptr^[row*RowSize + 2] := Multiply(inptr^[row*RowSize + 2], FP_IC4); { 2/c4 }
- inptr^[row*RowSize + 5] := Multiply(inptr^[row*RowSize + 5], FP_IC4); { 2/c4 }
-
- N1(inptr^[row*RowSize + 4], inptr^[row*RowSize + 6]);
- end;
- 2,5: { M2 }
- begin
- inptr^[row*RowSize + 0] := Multiply(inptr^[row*RowSize + 0], FP_IC4);
- inptr^[row*RowSize + 1] := Multiply(inptr^[row*RowSize + 1], FP_IC4);
- inptr^[row*RowSize + 3] := Multiply(inptr^[row*RowSize + 3], FP_IC4);
- inptr^[row*RowSize + 7] := Multiply(inptr^[row*RowSize + 7], FP_IC4);
-
- inptr^[row*RowSize + 2] := inptr^[row*RowSize + 2] * 2; { shift }
- inptr^[row*RowSize + 5] := inptr^[row*RowSize + 5] * 2;
-
- N2(inptr^[row*RowSize + 4], inptr^[row*RowSize + 6]);
- end;
- end; { Case }
-
- { M x N tensor }
- { rows 4,6 }
- begin
- N1(inptr^[4*RowSize + 0], inptr^[6*RowSize + 0]);
- N1(inptr^[4*RowSize + 1], inptr^[6*RowSize + 1]);
- N1(inptr^[4*RowSize + 3], inptr^[6*RowSize + 3]);
- N1(inptr^[4*RowSize + 7], inptr^[6*RowSize + 7]);
-
- N2(inptr^[4*RowSize + 2], inptr^[6*RowSize + 2]);
- N2(inptr^[4*RowSize + 5], inptr^[6*RowSize + 5]);
-
- { N3 }
- { two inverse matrices => same as FDCT }
- tmp0 := inptr^[4*RowSize + 4];
- tmp3 := inptr^[6*RowSize + 6];
- tmp12 := (tmp0 + tmp3) * 2;
- z10 := tmp0 - tmp3;
-
- tmp1 := inptr^[6*RowSize + 4];
- tmp2 := inptr^[4*RowSize + 6];
- tmp13 :=-(tmp1 - tmp2)*2;
- z11 := tmp1 + tmp2;
-
- tmp0 := Multiply(z10 + z11, FP_I_C4_2);
- tmp1 := Multiply(z10 - z11, FP_I_C4_2);
-
-
- inptr^[4*RowSize + 4] := tmp12 + tmp0;
- inptr^[6*RowSize + 4] := tmp1 + tmp13;
-
- inptr^[4*RowSize + 6] := tmp1 - tmp13;
- inptr^[6*RowSize + 6] := tmp12 - tmp0;
- end;
-
- { R2 x R2 }
-
- for row := 0 to 7 do
- BEGIN
- { Odd part }
- tmp7 := inptr^[row*RowSize + 7];
- tmp6 := inptr^[row*RowSize + 6] - tmp7;
- tmp5 := inptr^[row*RowSize + 5] - tmp6;
- tmp4 :=-inptr^[row*RowSize + 4] - tmp5;
-
- { even part }
- tmp0 := inptr^[row*RowSize + 0];
- tmp1 := inptr^[row*RowSize + 1];
- tmp10 := tmp0 + tmp1;
- tmp11 := tmp0 - tmp1;
-
- tmp2 := inptr^[row*RowSize + 2];
- tmp13 := inptr^[row*RowSize + 3];
- tmp12 := tmp2 - tmp13;
-
- tmp0 := tmp10 + tmp13;
- tmp3 := tmp10 - tmp13;
- inptr^[row*RowSize + 0] := (tmp0 + tmp7);
- inptr^[row*RowSize + 7] := (tmp0 - tmp7);
-
- inptr^[row*RowSize + 3] := (tmp3 + tmp4);
- inptr^[row*RowSize + 4] := (tmp3 - tmp4);
-
- tmp1 := tmp11 + tmp12;
- tmp2 := tmp11 - tmp12;
-
- inptr^[row*RowSize + 1] := (tmp1 + tmp6);
- inptr^[row*RowSize + 6] := (tmp1 - tmp6);
-
- inptr^[row*RowSize + 2] := (tmp2 + tmp5);
- inptr^[row*RowSize + 5] := (tmp2 - tmp5);
- END;
-
- for ctr := 0 to pred(DCTSIZE) do
- BEGIN
- outptr := JSAMPROW(@output_buf^[ctr]^[output_col]);
- { even part }
- tmp0 := inptr^[0*RowSize + ctr];
- tmp1 := inptr^[1*RowSize + ctr];
- tmp2 := inptr^[2*RowSize + ctr];
- tmp3 := inptr^[3*RowSize + ctr];
-
- tmp10 := tmp0 + tmp1;
- tmp11 := tmp0 - tmp1;
-
- tmp13 := tmp3;
- tmp12 := tmp2 - tmp3;
-
- tmp0 := tmp10 + tmp13;
- tmp3 := tmp10 - tmp13;
-
- tmp1 := tmp11 + tmp12;
- tmp2 := tmp11 - tmp12;
-
- { Odd part }
- tmp4 := inptr^[4*RowSize + ctr];
- tmp5 := inptr^[5*RowSize + ctr];
- tmp6 := inptr^[6*RowSize + ctr];
- tmp7 := inptr^[7*RowSize + ctr];
-
- tmp6 := tmp6 - tmp7;
- tmp5 := tmp5 - tmp6;
- tmp4 :=-tmp4 - tmp5;
-
- outptr^[0*RowSize + ctr] := DeScale(tmp0 + tmp7);
- outptr^[7*RowSize + ctr] := DeScale(tmp0 - tmp7);
-
- outptr^[1*RowSize + ctr] := DeScale(tmp1 + tmp6);
- outptr^[6*RowSize + ctr] := DeScale(tmp1 - tmp6);
-
- outptr^[2*RowSize + ctr] := DeScale(tmp2 + tmp5);
- outptr^[5*RowSize + ctr] := DeScale(tmp2 - tmp5);
-
- outptr^[3*RowSize + ctr] := DeScale(tmp3 + tmp4);
- outptr^[4*RowSize + ctr] := DeScale(tmp3 - tmp4);
-
-
- { Final output stage: scale down by a factor of 8 and range-limit }
-
- outptr^[0] := range_limit^[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[7] := range_limit^[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[1] := range_limit^[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[6] := range_limit^[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[2] := range_limit^[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[5] := range_limit^[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[4] := range_limit^[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[3] := range_limit^[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
- and RANGE_MASK];
- END;
-
- Inc(bbo);
- Inc(inptr);
- End;
-End; {----------------------------------------}
-
-
-{GLOBAL}
-procedure jpeg_idct_i2d (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-
-procedure Feig_2D_IDCT(coef_block :imatrix;
- output_buf : JSAMPARRAY);
-Const
- CONST_IC4 = 1.414213562; { 1/0.707106781; }
- FP_IC4 = Integer(Round(IFX_CONST*CONST_IC4));
- FP_I_C4_2 = FP_IC4;
-
- Function Descale(x : integer):integer;
- begin
- DeScale := (x+ (4 shl PASS_BITS)) div (8 shl PASS_BITS);
- { DeScale := x sar (3 + PASS_BITS);
- Borland Pascal SHR is unsigned }
- end;
- {
- function Multiply(X, Y: Integer): integer;
- begin
- Multiply := Integer( X*LongInt(Y) div IFX_CONST);
- end;
- }
- function Multiply(X, Y: Integer): integer; assembler;
- asm
- mov ax, X
- imul Y
- mov al, ah
- mov ah, dl
- end;
-
-
-var
- z10, z11, z12, z13,
- tmp0,tmp1,tmp2,tmp3,
- tmp4,tmp5,tmp6,tmp7,
- tmp10,tmp11,
- tmp12,tmp13 : integer;
- column, row : byte;
-
- Procedure N1(var x, y : integer); { rotator 1 }
- Const
- FP_a5 = Integer(Round(IFX_CONST*1.847759065));
- FP_a4 = Integer(Round(IFX_CONST*2.613125930));
- FP_a2 = Integer(Round(IFX_CONST*1.082392200));
- var
- z5, tmp : integer;
- begin
- tmp := x;
-
- z5 := Multiply(tmp + y, FP_a5); { c6 }
- x := Multiply(y, FP_a2) - z5; { c2-c6 }
- y := Multiply(tmp, -FP_a4) + z5; { c2+c6 }
- end;
-
- Procedure N2(var x, y : integer); { N1 scaled by c4 }
- Const
- FP_b5 = Integer(Round(IFX_CONST*1.847759065*CONST_IC4));
- FP_b4 = Integer(Round(IFX_CONST*2.613125930*CONST_IC4));
- FP_b2 = Integer(Round(IFX_CONST*1.082392200*CONST_IC4));
- var
- z5, tmp : integer;
- begin
- tmp := x;
-
- z5 := Multiply(tmp + y, FP_b5);
- x := Multiply(y, FP_b2) - z5;
- y := Multiply(tmp,-FP_b4) + z5;
- end;
-
-var
- tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7 : DCTELEM;
- tmp10, tmp11, tmp12, tmp13 : DCTELEM;
- z10, z11, z12, z13 : DCTELEM;
- inptr : JCOEFPTR;
-
- quantptr : IFAST_MULT_TYPE_FIELD_PTR;
- wsptr : PWorkspace;
- outptr : JSAMPROW;
- range_limit : JSAMPROW;
- ctr : int;
- workspace : TWorkspace; { buffers data between passes }
- {SHIFT_TEMPS { for DESCALE }
- {ISHIFT_TEMPS { for IDESCALE }
-var
- dcval : int;
-var
- dcval_ : JSAMPLE;
-begin
-{ Each IDCT routine is responsible for range-limiting its results and
- converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
- be quite far out of range if the input data is corrupt, so a bulletproof
- range-limiting step is required. We use a mask-and-table-lookup method
- to do the combined operations quickly. See the comments with
- prepare_range_limit_table (in jdmaster.c) for more info. }
-
- range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));
- { Pass 1: process columns from input, store into work array. }
-
- inptr := coef_block;
- quantptr := IFAST_MULT_TYPE_FIELD_PTR(compptr^.dct_table);
- wsptr := @workspace;
-
- { R1 x R1 }
- for ctr := pred(DCTSIZE) downto 0 do
- BEGIN
- { even part }
- tmp1 := DEQUANTIZE(inptr^[DCTSIZE*2], quantptr^[DCTSIZE*2]);
- tmp3 := DEQUANTIZE(inptr^[DCTSIZE*6], quantptr^[DCTSIZE*6]);
-
- wsptr^[DCTSIZE*0] := int (DEQUANTIZE(inptr^[DCTSIZE*0], quantptr^[DCTSIZE*0]));
- wsptr^[DCTSIZE*1] := int (DEQUANTIZE(inptr^[DCTSIZE*4], quantptr^[DCTSIZE*4]);
-
- { Odd part }
-
- tmp6 := DEQUANTIZE(inptr^[DCTSIZE*5], quantptr^[DCTSIZE*5]);
- tmp4 := DEQUANTIZE(inptr^[DCTSIZE*1], quantptr^[DCTSIZE*1]);
- tmp7 := DEQUANTIZE(inptr^[DCTSIZE*7], quantptr^[DCTSIZE*7]);
- tmp5 := DEQUANTIZE(inptr^[DCTSIZE*3], quantptr^[DCTSIZE*3]);
-
-
- z13 := tmp6 + tmp5;
- wsptr^[DCTSIZE*4] := int (tmp6 - tmp5);
-
- z11 := tmp4 + tmp7;
- wsptr^[DCTSIZE*6] := int (tmp4 - tmp7);
-
- wsptr^[DCTSIZE*7] := int (z11 + z13);
- wsptr^[DCTSIZE*5] := int (z11 - z13);
-
- wsptr^[DCTSIZE*3] := int (tmp1 + tmp3);
- wsptr^[DCTSIZE*2] := int (tmp1 - tmp3);
-
- Inc(JCOEF_PTR(inptr)); { advance pointers to next column }
- Inc(IFAST_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
- END;
-
- wsptr := @workspace[DCTSIZE*pred(DCTSIZE)];
- for row := pred(DCTSIZE) downto 0 do
- BEGIN
- { Odd part }
- tmp5 := DCTELEM(wsptr^[1]);
- tmp7 := DCTELEM(wsptr^[3]);
-
- { even part }
-
- {noop:
- tmp0 := DCTELEM(wsptr^[0]);
- wsptr^[0] := DCTELEM(tmp0);}
-
- {tmp2 := DCTELEM(wsptr^[4]);}
- wsptr^[1] := wsptr^[4];
-
- tmp1 := DCTELEM(wsptr^[2]);
- tmp3 := DCTELEM(wsptr^[6]);
-
- wsptr^[2] := DCTELEM(tmp1 - tmp3);
- wsptr^[3] := DCTELEM(tmp1 + tmp3);
-
- { Odd part }
- tmp4 := DCTELEM(wsptr^[5]);
- tmp6 := DCTELEM(wsptr^[7]);
-
- z13 := tmp4 + tmp7;
- wsptr^[4] := DCTELEM(tmp4 - tmp7);
-
- z11 := tmp5 + tmp6;
- wsptr^[6] := DCTELEM(tmp5 - tmp6);
-
- wsptr^[7] := DCTELEM(z11 + z13);
- wsptr^[5] := DCTELEM(z11 - z13);
- Dec(int_ptr(wsptr), DCTSIZE); { advance pointer to previous row }
- END;
-
- { M x M tensor }
- wsptr := @workspace[DCTSIZE*0];
- for row := 0 to pred(DCTSIZE) do
- begin
- Case row of
- 0,1,3,7: { M1 }
- begin
- wsptr^[2] := Multiply(wsptr^[2], FP_IC4); { 2/c4 }
- wsptr^[5] := Multiply(wsptr^[5], FP_IC4); { 2/c4 }
-
- N1(wsptr^[ 4], wsptr^[ 6]);
- end;
- 2,5: { M2 }
- begin
- wsptr^[0] := Multiply(wsptr^[0], FP_IC4);
- wsptr^[1] := Multiply(wsptr^[1], FP_IC4);
- wsptr^[3] := Multiply(wsptr^[3], FP_IC4);
- wsptr^[7] := Multiply(wsptr^[7], FP_IC4);
-
- wsptr^[2] := wsptr^[2] * 2; { shift }
- wsptr^[5] := wsptr^[5] * 2;
-
- N2(wsptr^[4], wsptr^[6]);
- end;
- end; { Case }
- Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- end;
-
- { M x N tensor }
- { rows 4,6 }
- begin
- N1(workspace[DCTSIZE*4+0], workspace[DCTSIZE*6+0]);
- N1(workspace[DCTSIZE*4+1], workspace[DCTSIZE*6+1]);
- N1(workspace[DCTSIZE*4+3], workspace[DCTSIZE*6+3]);
- N1(workspace[DCTSIZE*4+7], workspace[DCTSIZE*6+7]);
-
- N2(workspace[DCTSIZE*4+2], workspace[DCTSIZE*6+2]);
- N2(workspace[DCTSIZE*4+5], workspace[DCTSIZE*6+5]);
-
- { N3 }
- tmp0 := workspace[DCTSIZE*4,4];
- tmp1 := workspace[DCTSIZE*6,4];
- tmp2 := workspace[DCTSIZE*4,6];
- tmp3 := workspace[DCTSIZE*6,6];
-
- { two inverse matrices => same as FDCT }
- z10 := tmp0 - tmp3;
- z11 := tmp1 + tmp2;
-
- z12 := tmp0 + tmp3;
- z13 := tmp1 - tmp2;
-
- tmp0 := Multiply(z10 + z11, FP_I_C4_2);
- tmp1 := Multiply(z10 - z11, FP_I_C4_2);
-
- tmp2 := z12 * 2; { shifts }
- tmp3 := z13 * (-2);
-
-
- workspace[DCTSIZE*4,4] := tmp2 + tmp0;
- workspace[DCTSIZE*6,4] := tmp1 + tmp3;
-
- workspace[DCTSIZE*4,6] := tmp1 - tmp3;
- workspace[DCTSIZE*6,6] := tmp2 - tmp0;
- end;
-
- { R2 x R2 }
-
- wsptr := @workspace;
- for row := 0 to pred(DCTSIZE) do
- BEGIN
- { even part }
- tmp0 := wsptr^[0];
- tmp2 := wsptr^[1];
- tmp1 := wsptr^[2];
- tmp3 := wsptr^[3];
-
- tmp10 := tmp0 + tmp2;
- tmp11 := tmp0 - tmp2;
-
- tmp12 := tmp1 - tmp3;
- tmp13 := tmp3;
-
- tmp0 := tmp10 + tmp13;
- tmp3 := tmp10 - tmp13;
-
- tmp2 := tmp11 + tmp12;
- tmp1 := tmp11 - tmp12;
-
- { Odd part }
- tmp4 := wsptr^[4];
- tmp5 := wsptr^[5];
- tmp6 := wsptr^[6];
- tmp7 := wsptr^[7];
-
- tmp6 := tmp6 - tmp7;
- tmp5 := tmp5 - tmp6;
- tmp4 :=-tmp4 - tmp5;
-
- wsptr^[0] := (tmp0 + tmp7);
- wsptr^[7] := (tmp0 - tmp7);
-
- wsptr^[1] := (tmp2 + tmp6);
- wsptr^[6] := (tmp2 - tmp6);
-
- wsptr^[2] := (tmp1 + tmp5);
- wsptr^[5] := (tmp1 - tmp5);
-
- wsptr^[3] := (tmp3 + tmp4);
- wsptr^[4] := (tmp3 - tmp4);
-
- Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- END;
-
- wsptr := @workspace;
- for ctr := 0 to pred(DCTSIZE) do
- BEGIN
- outptr := JSAMPROW(@output_buf^[ctr]^[output_col]);
- { even part }
- tmp0 := wsptr[0];
- tmp1 := wsptr[1];
- tmp2 := wsptr[2];
- tmp3 := wsptr[3];
-
- tmp10 := tmp0 + tmp1;
- tmp11 := tmp0 - tmp1;
-
- tmp13 := tmp3;
- tmp12 := tmp2 - tmp3;
-
- tmp0 := tmp10 + tmp13;
- tmp3 := tmp10 - tmp13;
-
- tmp1 := tmp11 + tmp12;
- tmp2 := tmp11 - tmp12;
-
- { Odd part }
- tmp4 := wsptr[4];
- tmp5 := wsptr[5];
- tmp6 := wsptr[6];
- tmp7 := wsptr[7];
-
- tmp6 := tmp6 - tmp7;
- tmp5 := tmp5 - tmp6;
- tmp4 :=-tmp4 - tmp5;
-
- { Final output stage: scale down by a factor of 8 and range-limit }
-
- outptr^[0] := range_limit^[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[7] := range_limit^[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[1] := range_limit^[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[6] := range_limit^[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[2] := range_limit^[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[5] := range_limit^[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[4] := range_limit^[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[3] := range_limit^[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
- and RANGE_MASK];
- Inc(int_ptr(wsptr));
- END;
-End; {----------------------------------------}
-
-
-{----------------------------------------------------------------------}
-
diff --git a/packages/base/pasjpeg/jidctasm.pas b/packages/base/pasjpeg/jidctasm.pas
deleted file mode 100644
index 7272d31d77..0000000000
--- a/packages/base/pasjpeg/jidctasm.pas
+++ /dev/null
@@ -1,793 +0,0 @@
-Unit JIDctAsm;
-
-{ This file contains a slow-but-accurate integer implementation of the
- inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
- must also perform dequantization of the input coefficients.
-
- A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
- on each row (or vice versa, but it's more convenient to emit a row at
- a time). Direct algorithms are also available, but they are much more
- complex and seem not to be any faster when reduced to code.
-
- This implementation is based on an algorithm described in
- C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
- Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
- Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
- The primary algorithm described there uses 11 multiplies and 29 adds.
- We use their alternate method with 12 multiplies and 32 adds.
- The advantage of this method is that no data path contains more than one
- multiplication; this allows a very simple and accurate implementation in
- scaled fixed-point arithmetic, with a minimal number of shifts. }
-
-{ Original : jidctint.c ; Copyright (C) 1991-1996, Thomas G. Lane. }
-{ ;-------------------------------------------------------------------------
- ; JIDCTINT.ASM
- ; 80386 protected mode assembly translation of JIDCTINT.C
- ; **** Optimized to all hell by Jason M. Felice (jasonf@apk.net) ****
- ; **** E-mail welcome ****
- ;
- ; ** This code does not make O/S calls -- use it for OS/2, Win95, WinNT,
- ; ** DOS prot. mode., Linux, whatever... have fun.
- ;
- ; ** Note, this code is dependant on the structure member order in the .h
- ; ** files for the following structures:
- ; -- amazingly NOT j_decompress_struct... cool.
- ; -- jpeg_component_info (dependant on position of dct_table element)
- ;
- ; Originally created with the /Fa option of MSVC 4.0 (why work when you
- ; don't have to?)
- ;
- ; (this code, when compiled is 1K bytes smaller than the optimized MSVC
- ; release build, not to mention 120-130 ms faster in my profile test with 1
- ; small color and and 1 medium black-and-white jpeg: stats using TASM 4.0
- ; and MSVC 4.0 to create a non-console app; jpeg_idct_islow accumulated
- ; 5,760 hits on all trials)
- ;
- ; TASM -t -ml -os jidctint.asm, jidctint.obj
- ;-------------------------------------------------------------------------
- Converted to Delphi 2.0 BASM for PasJPEG
- by Jacques NOMSSI NZALI <nomssi@physik.tu-chemnitz.de>
- October 13th 1996
- * assumes Delphi "register" calling convention
- first 3 parameter are in EAX,EDX,ECX
- * register allocation revised
-}
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jpeglib,
- jdct; { Private declarations for DCT subsystem }
-
-{ Perform dequantization and inverse DCT on one block of coefficients. }
-
-{GLOBAL}
-procedure jpeg_idct_islow (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-
-implementation
-
-{ This module is specialized to the case DCTSIZE = 8. }
-
-{$ifndef DCTSIZE_IS_8}
- Sorry, this code only copes with 8x8 DCTs. { deliberate syntax err }
-{$endif}
-
-{ The poop on this scaling stuff is as follows:
-
- Each 1-D IDCT step produces outputs which are a factor of sqrt(N)
- larger than the true IDCT outputs. The final outputs are therefore
- a factor of N larger than desired; since N=8 this can be cured by
- a simple right shift at the end of the algorithm. The advantage of
- this arrangement is that we save two multiplications per 1-D IDCT,
- because the y0 and y4 inputs need not be divided by sqrt(N).
-
- We have to do addition and subtraction of the integer inputs, which
- is no problem, and multiplication by fractional constants, which is
- a problem to do in integer arithmetic. We multiply all the constants
- by CONST_SCALE and convert them to integer constants (thus retaining
- CONST_BITS bits of precision in the constants). After doing a
- multiplication we have to divide the product by CONST_SCALE, with proper
- rounding, to produce the correct output. This division can be done
- cheaply as a right shift of CONST_BITS bits. We postpone shifting
- as long as possible so that partial sums can be added together with
- full fractional precision.
-
- The outputs of the first pass are scaled up by PASS1_BITS bits so that
- they are represented to better-than-integral precision. These outputs
- require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
- with the recommended scaling. (To scale up 12-bit sample data further, an
- intermediate INT32 array would be needed.)
-
- To avoid overflow of the 32-bit intermediate results in pass 2, we must
- have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
- shows that the values given below are the most effective. }
-
-const
- CONST_BITS = 13;
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-const
- PASS1_BITS = 2;
-{$else}
-const
- PASS1_BITS = 1; { lose a little precision to avoid overflow }
-{$endif}
-
-const
- CONST_SCALE = (INT32(1) shl CONST_BITS);
-
-const
- FIX_0_298631336 = INT32(Round(CONST_SCALE * 0.298631336)); {2446}
- FIX_0_390180644 = INT32(Round(CONST_SCALE * 0.390180644)); {3196}
- FIX_0_541196100 = INT32(Round(CONST_SCALE * 0.541196100)); {4433}
- FIX_0_765366865 = INT32(Round(CONST_SCALE * 0.765366865)); {6270}
- FIX_0_899976223 = INT32(Round(CONST_SCALE * 0.899976223)); {7373}
- FIX_1_175875602 = INT32(Round(CONST_SCALE * 1.175875602)); {9633}
- FIX_1_501321110 = INT32(Round(CONST_SCALE * 1.501321110)); {12299}
- FIX_1_847759065 = INT32(Round(CONST_SCALE * 1.847759065)); {15137}
- FIX_1_961570560 = INT32(Round(CONST_SCALE * 1.961570560)); {16069}
- FIX_2_053119869 = INT32(Round(CONST_SCALE * 2.053119869)); {16819}
- FIX_2_562915447 = INT32(Round(CONST_SCALE * 2.562915447)); {20995}
- FIX_3_072711026 = INT32(Round(CONST_SCALE * 3.072711026)); {25172}
-
-
-{ for DESCALE }
-const
- ROUND_CONST = (INT32(1) shl (CONST_BITS-PASS1_BITS-1));
-const
- ROUND_CONST_2 = (INT32(1) shl (CONST_BITS+PASS1_BITS+3-1));
-
-{ Perform dequantization and inverse DCT on one block of coefficients. }
-
-{GLOBAL}
-procedure jpeg_idct_islow (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-type
- PWorkspace = ^TWorkspace;
- TWorkspace = coef_bits_field; { buffers data between passes }
-const
- coefDCTSIZE = DCTSIZE*SizeOf(JCOEF);
- wrkDCTSIZE = DCTSIZE*SizeOf(int);
-var
- tmp0, tmp1, tmp2, tmp3 : INT32;
- tmp10, tmp11, tmp12, tmp13 : INT32;
- z1, z2, z3, z4, z5 : INT32;
-var
- inptr : JCOEFPTR;
- quantptr : ISLOW_MULT_TYPE_FIELD_PTR;
- wsptr : PWorkspace;
- outptr : JSAMPROW;
-var
- range_limit : JSAMPROW;
- ctr : int;
- workspace : TWorkspace;
-var
- dcval : int;
-var
- dcval_ : JSAMPLE;
-asm
- push edi
- push esi
- push ebx
-
- cld { The only direction we use, might as well set it now, as opposed }
- { to inside 2 loops. }
-
-{ Each IDCT routine is responsible for range-limiting its results and
- converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
- be quite far out of range if the input data is corrupt, so a bulletproof
- range-limiting step is required. We use a mask-and-table-lookup method
- to do the combined operations quickly. See the comments with
- prepare_range_limit_table (in jdmaster.c) for more info. }
-
- {range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));}
- mov eax, [eax].jpeg_decompress_struct.sample_range_limit {eax=cinfo}
- add eax, (MAXJSAMPLE+1 + CENTERJSAMPLE)*(Type JSAMPLE)
- mov range_limit, eax
-
- { Pass 1: process columns from input, store into work array. }
- { Note results are scaled up by sqrt(8) compared to a true IDCT; }
- { furthermore, we scale the results by 2**PASS1_BITS. }
-
- {inptr := coef_block;}
- mov esi, ecx { ecx=coef_block }
- {quantptr := ISLOW_MULT_TYPE_FIELD_PTR (compptr^.dct_table);}
- mov edi, [edx].jpeg_component_info.dct_table { edx=compptr }
-
- {wsptr := PWorkspace(@workspace);}
- lea ecx, workspace
-
- {for ctr := pred(DCTSIZE) downto 0 do
- begin}
- mov ctr, DCTSIZE
-@loop518:
- { Due to quantization, we will usually find that many of the input
- coefficients are zero, especially the AC terms. We can exploit this
- by short-circuiting the IDCT calculation for any column in which all
- the AC terms are zero. In that case each output is equal to the
- DC coefficient (with scale factor as needed).
- With typical images and quantization tables, half or more of the
- column DCT calculations can be simplified this way. }
-
- {if ((inptr^[DCTSIZE*1]) or (inptr^[DCTSIZE*2]) or (inptr^[DCTSIZE*3]) or
- (inptr^[DCTSIZE*4]) or (inptr^[DCTSIZE*5]) or (inptr^[DCTSIZE*6]) or
- (inptr^[DCTSIZE*7]) = 0) then
- begin}
- mov eax, DWORD PTR [esi+coefDCTSIZE*1]
- or eax, DWORD PTR [esi+coefDCTSIZE*2]
- or eax, DWORD PTR [esi+coefDCTSIZE*3]
- mov edx, DWORD PTR [esi+coefDCTSIZE*4]
- or eax, edx
- or eax, DWORD PTR [esi+coefDCTSIZE*5]
- or eax, DWORD PTR [esi+coefDCTSIZE*6]
- or eax, DWORD PTR [esi+coefDCTSIZE*7]
- jne @loop520
-
- { AC terms all zero }
- {dcval := ISLOW_MULT_TYPE(inptr^[DCTSIZE*0]) *
- (quantptr^[DCTSIZE*0]) shl PASS1_BITS;}
- mov eax, DWORD PTR [esi+coefDCTSIZE*0]
- imul eax, DWORD PTR [edi+wrkDCTSIZE*0]
- shl eax, PASS1_BITS
-
- {wsptr^[DCTSIZE*0] := dcval;
- wsptr^[DCTSIZE*1] := dcval;
- wsptr^[DCTSIZE*2] := dcval;
- wsptr^[DCTSIZE*3] := dcval;
- wsptr^[DCTSIZE*4] := dcval;
- wsptr^[DCTSIZE*5] := dcval;
- wsptr^[DCTSIZE*6] := dcval;
- wsptr^[DCTSIZE*7] := dcval;}
-
- mov DWORD PTR [ecx+ wrkDCTSIZE*0], eax
- mov DWORD PTR [ecx+ wrkDCTSIZE*1], eax
- mov DWORD PTR [ecx+ wrkDCTSIZE*2], eax
- mov DWORD PTR [ecx+ wrkDCTSIZE*3], eax
- mov DWORD PTR [ecx+ wrkDCTSIZE*4], eax
- mov DWORD PTR [ecx+ wrkDCTSIZE*5], eax
- mov DWORD PTR [ecx+ wrkDCTSIZE*6], eax
- mov DWORD PTR [ecx+ wrkDCTSIZE*7], eax
-
- {Inc(JCOEF_PTR(inptr)); { advance pointers to next column }
- {Inc(ISLOW_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
- continue;}
- dec ctr
- je @loop519
-
- add esi, Type JCOEF
- add edi, Type ISLOW_MULT_TYPE
- add ecx, Type int { int_ptr }
- jmp @loop518
-
-@loop520:
-
- {end;}
-
- { Even part: reverse the even part of the forward DCT. }
- { The rotator is sqrt(2)*c(-6). }
-
- {z2 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*2]) * quantptr^[DCTSIZE*2];
- z3 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*6]) * quantptr^[DCTSIZE*6];
-
- z1 := (z2 + z3) * INT32(FIX_0_541196100);
- tmp2 := z1 + INT32(z3) * INT32(- FIX_1_847759065);
- tmp3 := z1 + INT32(z2) * INT32(FIX_0_765366865);}
-
- mov edx, DWORD PTR [esi+coefDCTSIZE*2]
- imul edx, DWORD PTR [edi+wrkDCTSIZE*2] {z2}
-
- mov eax, DWORD PTR [esi+coefDCTSIZE*6]
- imul eax, DWORD PTR [edi+wrkDCTSIZE*6] {z3}
-
- lea ebx, [eax+edx]
- imul ebx, FIX_0_541196100 {z1}
-
- imul eax, (-FIX_1_847759065)
- add eax, ebx
- mov tmp2, eax
-
- imul edx, FIX_0_765366865
- add edx, ebx
- mov tmp3, edx
-
- {z2 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*0]) * quantptr^[DCTSIZE*0];
- z3 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*4]) * quantptr^[DCTSIZE*4];}
-
- mov edx, DWORD PTR [esi+coefDCTSIZE*4]
- imul edx, DWORD PTR [edi+wrkDCTSIZE*4] { z3 = edx }
-
- mov eax, DWORD PTR [esi+coefDCTSIZE*0]
- imul eax, DWORD PTR [edi+wrkDCTSIZE*0] { z2 = eax }
-
- {tmp0 := (z2 + z3) shl CONST_BITS;
- tmp1 := (z2 - z3) shl CONST_BITS;}
- lea ebx,[eax+edx]
- sub eax, edx
- shl ebx, CONST_BITS { tmp0 = ebx }
- shl eax, CONST_BITS { tmp1 = eax }
-
- {tmp10 := tmp0 + tmp3;
- tmp13 := tmp0 - tmp3;}
- mov edx, tmp3
- sub ebx, edx
- mov tmp13, ebx
- add edx, edx
- add ebx, edx
- mov tmp10, ebx
-
- {tmp11 := tmp1 + tmp2;
- tmp12 := tmp1 - tmp2;}
- mov ebx, tmp2
- sub eax, ebx
- mov tmp12, eax
- add ebx, ebx
- add eax, ebx
- mov tmp11, eax
-
- { Odd part per figure 8; the matrix is unitary and hence its
- transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. }
-
- {tmp0 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*7]) * quantptr^[DCTSIZE*7];}
- mov eax, DWORD PTR [esi+coefDCTSIZE*7]
- imul eax, DWORD PTR [edi+wrkDCTSIZE*7]
- mov edx, eax { edx = tmp0 }
- {tmp0 := (tmp0) * INT32(FIX_0_298631336); { sqrt(2) * (-c1+c3+c5-c7) }
- imul eax, FIX_0_298631336
- mov tmp0, eax
-
- {tmp3 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*1]) * quantptr^[DCTSIZE*1];}
- mov eax, DWORD PTR [esi+coefDCTSIZE*1]
- imul eax, DWORD PTR [edi+wrkDCTSIZE*1]
- mov tmp3, eax
-
- {z1 := tmp0 + tmp3;}
- {z1 := (z1) * INT32(- FIX_0_899976223); { sqrt(2) * (c7-c3) }
- add eax, edx
- imul eax, (-FIX_0_899976223)
- mov z1, eax
-
- {tmp1 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*5]) * quantptr^[DCTSIZE*5];}
- mov eax, DWORD PTR [esi+coefDCTSIZE*5]
- imul eax, DWORD PTR [edi+wrkDCTSIZE*5]
- mov ebx, eax { ebx = tmp1 }
- {tmp1 := (tmp1) * INT32(FIX_2_053119869); { sqrt(2) * ( c1+c3-c5+c7) }
- imul eax, FIX_2_053119869
- mov tmp1, eax
-
- {tmp2 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*3]) * quantptr^[DCTSIZE*3];}
- mov eax, DWORD PTR [esi+coefDCTSIZE*3]
- imul eax, DWORD PTR [edi+wrkDCTSIZE*3]
- mov tmp2, eax
-
- {z3 := tmp0 + tmp2;}
- add edx, eax { edx = z3 }
-
- {z2 := tmp1 + tmp2;}
- {z2 := (z2) * INT32(- FIX_2_562915447); { sqrt(2) * (-c1-c3) }
- add eax, ebx
- imul eax, (-FIX_2_562915447)
- mov z2, eax
-
- {z4 := tmp1 + tmp3;}
- add ebx, tmp3 { ebx = z4 }
-
- {z5 := INT32(z3 + z4) * INT32(FIX_1_175875602); { sqrt(2) * c3 }
- lea eax, [edx+ebx]
- imul eax, FIX_1_175875602 { eax = z5 }
-
- {z4 := (z4) * INT32(- FIX_0_390180644); { sqrt(2) * (c5-c3) }
- {Inc(z4, z5);}
- imul ebx, (-FIX_0_390180644)
- add ebx, eax
- mov z4, ebx
-
- {z3 := (z3) * INT32(- FIX_1_961570560); { sqrt(2) * (-c3-c5) }
- {Inc(z3, z5);}
- imul edx, (-FIX_1_961570560)
- add eax, edx { z3 = eax }
-
- {Inc(tmp0, z1 + z3);}
- mov ebx, z1
- add ebx, eax
- add tmp0, ebx
-
- {tmp2 := (tmp2) * INT32(FIX_3_072711026); { sqrt(2) * ( c1+c3+c5-c7) }
- {Inc(tmp2, z2 + z3);}
- mov ebx, tmp2
- imul ebx, FIX_3_072711026
- mov edx, z2 { z2 = edx }
- add ebx, edx
- add eax, ebx
- mov tmp2, eax
-
- {Inc(tmp1, z2 + z4);}
- mov eax, z4 { z4 = eax }
- add edx, eax
- add tmp1, edx
-
- {tmp3 := (tmp3) * INT32(FIX_1_501321110); { sqrt(2) * ( c1+c3-c5-c7) }
- {Inc(tmp3, z1 + z4);}
- mov edx, tmp3
- imul edx, FIX_1_501321110
-
- add edx, eax
- add edx, z1 { tmp3 = edx }
-
- { Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 }
-
- {wsptr^[DCTSIZE*0] := int (DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS));}
- {wsptr^[DCTSIZE*7] := int (DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS));}
- mov eax, tmp10
- add eax, ROUND_CONST
- lea ebx, [eax+edx]
- sar ebx, CONST_BITS-PASS1_BITS
- mov DWORD PTR [ecx+wrkDCTSIZE*0], ebx
-
- sub eax, edx
- sar eax, CONST_BITS-PASS1_BITS
- mov DWORD PTR [ecx+wrkDCTSIZE*7], eax
-
- {wsptr^[DCTSIZE*1] := int (DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS));}
- {wsptr^[DCTSIZE*6] := int (DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS));}
- mov eax, tmp11
- add eax, ROUND_CONST
- mov edx, tmp2
- lea ebx, [eax+edx]
- sar ebx, CONST_BITS-PASS1_BITS
- mov DWORD PTR [ecx+wrkDCTSIZE*1], ebx
-
- sub eax, edx
- sar eax, CONST_BITS-PASS1_BITS
- mov DWORD PTR [ecx+wrkDCTSIZE*6], eax
-
- {wsptr^[DCTSIZE*2] := int (DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS));}
- {wsptr^[DCTSIZE*5] := int (DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS));}
- mov eax, tmp12
- add eax, ROUND_CONST
- mov edx, tmp1
- lea ebx, [eax+edx]
- sar ebx, CONST_BITS-PASS1_BITS
- mov DWORD PTR [ecx+wrkDCTSIZE*2], ebx
-
- sub eax, edx
- sar eax, CONST_BITS-PASS1_BITS
- mov DWORD PTR [ecx+wrkDCTSIZE*5], eax
-
- {wsptr^[DCTSIZE*3] := int (DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS));}
- {wsptr^[DCTSIZE*4] := int (DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS));}
- mov eax, tmp13
- add eax, ROUND_CONST
- mov edx, tmp0
- lea ebx, [eax+edx]
- sar ebx, CONST_BITS-PASS1_BITS
- mov DWORD PTR [ecx+wrkDCTSIZE*3], ebx
-
- sub eax, edx
- sar eax, CONST_BITS-PASS1_BITS
- mov DWORD PTR [ecx+wrkDCTSIZE*4], eax
-
- {Inc(JCOEF_PTR(inptr)); { advance pointers to next column }
- {Inc(ISLOW_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));}
- dec ctr
- je @loop519
-
- add esi, Type JCOEF
- add edi, Type ISLOW_MULT_TYPE
- add ecx, Type int { int_ptr }
- {end;}
- jmp @loop518
-@loop519:
- { Save to memory what we've registerized for the preceding loop. }
-
- { Pass 2: process rows from work array, store into output array. }
- { Note that we must descale the results by a factor of 8 == 2**3, }
- { and also undo the PASS1_BITS scaling. }
-
- {wsptr := @workspace;}
- lea esi, workspace
-
- {for ctr := 0 to pred(DCTSIZE) do
- begin}
- mov ctr, 0
-@loop523:
-
- {outptr := output_buf^[ctr];}
- mov eax, ctr
- mov ebx, output_buf
- mov edi, DWORD PTR [ebx+eax*4] { 4 = SizeOf(pointer) }
-
- {Inc(JSAMPLE_PTR(outptr), output_col);}
- add edi, output_col
-
- { Rows of zeroes can be exploited in the same way as we did with columns.
- However, the column calculation has created many nonzero AC terms, so
- the simplification applies less often (typically 5% to 10% of the time).
- On machines with very fast multiplication, it's possible that the
- test takes more time than it's worth. In that case this section
- may be commented out. }
-
-{$ifndef NO_ZERO_ROW_TEST}
- {if ((wsptr^[1]) or (wsptr^[2]) or (wsptr^[3]) or (wsptr^[4]) or
- (wsptr^[5]) or (wsptr^[6]) or (wsptr^[7]) = 0) then
- begin}
- mov eax, DWORD PTR [esi+4*1]
- or eax, DWORD PTR [esi+4*2]
- or eax, DWORD PTR [esi+4*3]
- jne @loop525 { Nomssi: early exit path may help }
- or eax, DWORD PTR [esi+4*4]
- or eax, DWORD PTR [esi+4*5]
- or eax, DWORD PTR [esi+4*6]
- or eax, DWORD PTR [esi+4*7]
- jne @loop525
-
- { AC terms all zero }
- {JSAMPLE(dcval_) := range_limit^[int(DESCALE(INT32(wsptr^[0]),
- PASS1_BITS+3)) and RANGE_MASK];}
- mov eax, DWORD PTR [esi+4*0]
- add eax, (INT32(1) shl (PASS1_BITS+3-1))
- sar eax, PASS1_BITS+3
- and eax, RANGE_MASK
- mov ebx, range_limit
- mov al, BYTE PTR [ebx+eax]
- mov ah, al
-
- {outptr^[0] := dcval_;
- outptr^[1] := dcval_;
- outptr^[2] := dcval_;
- outptr^[3] := dcval_;
- outptr^[4] := dcval_;
- outptr^[5] := dcval_;
- outptr^[6] := dcval_;
- outptr^[7] := dcval_;}
-
- stosw
- stosw
- stosw
- stosw
-
- {Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- {continue;}
- add esi, wrkDCTSIZE
- inc ctr
- cmp ctr, DCTSIZE
- jl @loop523
- jmp @loop524
- {end;}
-@loop525:
-{$endif}
-
-
- { Even part: reverse the even part of the forward DCT. }
- { The rotator is sqrt(2)*c(-6). }
-
- {z2 := INT32 (wsptr^[2]);}
- mov edx, DWORD PTR [esi+4*2] { z2 = edx }
-
- {z3 := INT32 (wsptr^[6]);}
- mov ecx, DWORD PTR [esi+4*6] { z3 = ecx }
-
- {z1 := (z2 + z3) * INT32(FIX_0_541196100);}
- lea eax, [edx+ecx]
- imul eax, FIX_0_541196100
- mov ebx, eax { z1 = ebx }
-
- {tmp2 := z1 + (z3) * INT32(- FIX_1_847759065);}
- imul ecx, (-FIX_1_847759065)
- add ecx, ebx { tmp2 = ecx }
-
- {tmp3 := z1 + (z2) * INT32(FIX_0_765366865);}
- imul edx, FIX_0_765366865
- add ebx, edx { tmp3 = ebx }
-
- {tmp0 := (INT32(wsptr^[0]) + INT32(wsptr^[4])) shl CONST_BITS;}
- {tmp1 := (INT32(wsptr^[0]) - INT32(wsptr^[4])) shl CONST_BITS;}
- mov edx, DWORD PTR [esi+4*4]
- mov eax, DWORD PTR [esi+4*0]
- sub eax, edx
- add edx, edx
- add edx, eax
- shl edx, CONST_BITS { tmp0 = edx }
- shl eax, CONST_BITS { tmp1 = eax }
-
- {tmp10 := tmp0 + tmp3;}
- {tmp13 := tmp0 - tmp3;}
- sub edx, ebx
- mov tmp13, edx
- add ebx, ebx
- add edx, ebx
- mov tmp10, edx
-
- {tmp11 := tmp1 + tmp2;}
- {tmp12 := tmp1 - tmp2;}
- lea ebx, [ecx+eax]
- mov tmp11, ebx
- sub eax, ecx
- mov tmp12, eax
-
- { Odd part per figure 8; the matrix is unitary and hence its
- transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. }
-
-{ The following lines no longer produce code, since wsptr has been
- optimized to esi, it is more efficient to access these values
- directly.
- tmp0 := INT32(wsptr^[7]);
- tmp1 := INT32(wsptr^[5]);
- tmp2 := INT32(wsptr^[3]);
- tmp3 := INT32(wsptr^[1]); }
-
- {z2 := tmp1 + tmp2;}
- {z2 := (z2) * INT32(- FIX_2_562915447); { sqrt(2) * (-c1-c3) }
- mov ebx, DWORD PTR [esi+4*3] { tmp2 }
- mov ecx, DWORD PTR [esi+4*5] { tmp1 }
- lea eax, [ebx+ecx]
- imul eax, (-FIX_2_562915447)
- mov z2, eax
-
- {z3 := tmp0 + tmp2;}
- mov edx, DWORD PTR [esi+4*7] { tmp0 }
- add ebx, edx { old z3 = ebx }
- mov eax, ebx
- {z3 := (z3) * INT32(- FIX_1_961570560); { sqrt(2) * (-c3-c5) }
- imul eax, (-FIX_1_961570560)
- mov z3, eax
-
- {z1 := tmp0 + tmp3;}
- {z1 := (z1) * INT32(- FIX_0_899976223); { sqrt(2) * (c7-c3) }
- mov eax, DWORD PTR [esi+4*1] { tmp3 }
- add edx, eax
- imul edx, (-FIX_0_899976223) { z1 = edx }
-
- {z4 := tmp1 + tmp3;}
- add eax, ecx { +tmp1 }
- add ebx, eax { z3 + z4 = ebx }
- {z4 := (z4) * INT32(- FIX_0_390180644); { sqrt(2) * (c5-c3) }
- imul eax, (-FIX_0_390180644) { z4 = eax }
-
- {z5 := (z3 + z4) * INT32(FIX_1_175875602); { sqrt(2) * c3 }
- {Inc(z3, z5);}
- imul ebx, FIX_1_175875602
- mov ecx, z3
- add ecx, ebx { ecx = z3 }
-
- {Inc(z4, z5);}
- add ebx, eax { z4 = ebx }
-
- {tmp0 := (tmp0) * INT32(FIX_0_298631336); { sqrt(2) * (-c1+c3+c5-c7) }
- {Inc(tmp0, z1 + z3);}
- mov eax, DWORD PTR [esi+4*7]
- imul eax, FIX_0_298631336
- add eax, edx
- add eax, ecx
- mov tmp0, eax
-
- {tmp1 := (tmp1) * INT32(FIX_2_053119869); { sqrt(2) * ( c1+c3-c5+c7) }
- {Inc(tmp1, z2 + z4);}
- mov eax, DWORD PTR [esi+4*5]
- imul eax, FIX_2_053119869
- add eax, z2
- add eax, ebx
- mov tmp1, eax
-
- {tmp2 := (tmp2) * INT32(FIX_3_072711026); { sqrt(2) * ( c1+c3+c5-c7) }
- {Inc(tmp2, z2 + z3);}
- mov eax, DWORD PTR [esi+4*3]
- imul eax, FIX_3_072711026
- add eax, z2
- add ecx, eax { ecx = tmp2 }
-
- {tmp3 := (tmp3) * INT32(FIX_1_501321110); { sqrt(2) * ( c1+c3-c5-c7) }
- {Inc(tmp3, z1 + z4);}
- mov eax, DWORD PTR [esi+4*1]
- imul eax, FIX_1_501321110
- add eax, edx
- add ebx, eax { ebx = tmp3 }
-
- { Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 }
-
- {outptr^[0] := range_limit^[ int(DESCALE(tmp10 + tmp3,
- CONST_BITS+PASS1_BITS+3)) and RANGE_MASK]; }
- {outptr^[7] := range_limit^[ int(DESCALE(tmp10 - tmp3,
- CONST_BITS+PASS1_BITS+3)) and RANGE_MASK];}
-
- mov edx, tmp10
- add edx, ROUND_CONST_2
- lea eax, [ebx+edx]
- sub edx, ebx
-
- shr eax, CONST_BITS+PASS1_BITS+3
- and eax, RANGE_MASK
- mov ebx, range_limit { once for all }
- mov al, BYTE PTR [ebx+eax]
- mov [edi+0], al
-
- shr edx, CONST_BITS+PASS1_BITS+3
- and edx, RANGE_MASK
- mov al, BYTE PTR [ebx+edx]
- mov [edi+7], al
-
- {outptr^[1] := range_limit^[ int(DESCALE(tmp11 + tmp2,
- CONST_BITS+PASS1_BITS+3)) and RANGE_MASK];}
- mov eax, tmp11
- add eax, ROUND_CONST_2
- lea edx, [eax+ecx]
- shr edx, CONST_BITS+PASS1_BITS+3
- and edx, RANGE_MASK
- mov dl, BYTE PTR [ebx+edx]
- mov [edi+1], dl
-
- {outptr^[6] := range_limit^[ int(DESCALE(tmp11 - tmp2,
- CONST_BITS+PASS1_BITS+3)) and RANGE_MASK];}
- sub eax, ecx
- shr eax, CONST_BITS+PASS1_BITS+3
- and eax, RANGE_MASK
- mov al, BYTE PTR [ebx+eax]
- mov [edi+6], al
-
- {outptr^[2] := range_limit^[ int(DESCALE(tmp12 + tmp1,
- CONST_BITS+PASS1_BITS+3)) and RANGE_MASK];}
- mov eax, tmp12
- add eax, ROUND_CONST_2
- mov ecx, tmp1
- lea edx, [eax+ecx]
- shr edx, CONST_BITS+PASS1_BITS+3
- and edx, RANGE_MASK
- mov dl, BYTE PTR [ebx+edx]
- mov [edi+2], dl
-
- {outptr^[5] := range_limit^[ int(DESCALE(tmp12 - tmp1,
- CONST_BITS+PASS1_BITS+3)) and RANGE_MASK];}
- sub eax, ecx
- shr eax, CONST_BITS+PASS1_BITS+3
- and eax, RANGE_MASK
- mov al, BYTE PTR [ebx+eax]
- mov [edi+5], al
-
- {outptr^[3] := range_limit^[ int(DESCALE(tmp13 + tmp0,
- CONST_BITS+PASS1_BITS+3)) and RANGE_MASK];}
- mov eax, tmp13
- add eax, ROUND_CONST_2
- mov ecx, tmp0
- lea edx, [eax+ecx]
- shr edx, CONST_BITS+PASS1_BITS+3
- and edx, RANGE_MASK
- mov dl, BYTE PTR [ebx+edx]
- mov [edi+3], dl
-
- {outptr^[4] := range_limit^[ int(DESCALE(tmp13 - tmp0,
- CONST_BITS+PASS1_BITS+3)) and RANGE_MASK];}
- sub eax, ecx
- shr eax, CONST_BITS+PASS1_BITS+3
- and eax, RANGE_MASK
- mov al, BYTE PTR [ebx+eax]
- mov [edi+4], al
-
- {Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- add esi, wrkDCTSIZE
- add edi, DCTSIZE
-
- {end;}
- inc ctr
- cmp ctr, DCTSIZE
- jl @loop523
-
-@loop524:
-@loop496:
- pop ebx
- pop esi
- pop edi
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jidctflt.pas b/packages/base/pasjpeg/jidctflt.pas
deleted file mode 100644
index b570aacfd5..0000000000
--- a/packages/base/pasjpeg/jidctflt.pas
+++ /dev/null
@@ -1,286 +0,0 @@
-Unit JIDctFlt;
-
-{$N+}
-{ This file contains a floating-point implementation of the
- inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
- must also perform dequantization of the input coefficients.
-
- This implementation should be more accurate than either of the integer
- IDCT implementations. However, it may not give the same results on all
- machines because of differences in roundoff behavior. Speed will depend
- on the hardware's floating point capacity.
-
- A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
- on each row (or vice versa, but it's more convenient to emit a row at
- a time). Direct algorithms are also available, but they are much more
- complex and seem not to be any faster when reduced to code.
-
- This implementation is based on Arai, Agui, and Nakajima's algorithm for
- scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
- Japanese, but the algorithm is described in the Pennebaker & Mitchell
- JPEG textbook (see REFERENCES section in file README). The following code
- is based directly on figure 4-8 in P&M.
- While an 8-point DCT cannot be done in less than 11 multiplies, it is
- possible to arrange the computation so that many of the multiplies are
- simple scalings of the final outputs. These multiplies can then be
- folded into the multiplications or divisions by the JPEG quantization
- table entries. The AA&N method leaves only 5 multiplies and 29 adds
- to be done in the DCT itself.
- The primary disadvantage of this method is that with a fixed-point
- implementation, accuracy is lost due to imprecise representation of the
- scaled quantization values. However, that problem does not arise if
- we use floating point arithmetic. }
-
-{ Original: jidctflt.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jpeglib,
- jdct; { Private declarations for DCT subsystem }
-
-{ Perform dequantization and inverse DCT on one block of coefficients. }
-
-{GLOBAL}
-procedure jpeg_idct_float (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-
-implementation
-
-{ This module is specialized to the case DCTSIZE = 8. }
-
-{$ifndef DCTSIZE_IS_8}
- Sorry, this code only copes with 8x8 DCTs. { deliberate syntax err }
-{$endif}
-
-
-{ Dequantize a coefficient by multiplying it by the multiplier-table
- entry; produce a float result. }
-
-function DEQUANTIZE(coef : int; quantval : FAST_FLOAT) : FAST_FLOAT;
-begin
- Dequantize := ( (coef) * quantval);
-end;
-
-{ Descale and correctly round an INT32 value that's scaled by N bits.
- We assume RIGHT_SHIFT rounds towards minus infinity, so adding
- the fudge factor is correct for either sign of X. }
-
-function DESCALE(x : INT32; n : int) : INT32;
-var
- shift_temp : INT32;
-begin
-{$ifdef RIGHT_SHIFT_IS_UNSIGNED}
- shift_temp := x + (INT32(1) shl (n-1));
- if shift_temp < 0 then
- Descale := (shift_temp shr n) or ((not INT32(0)) shl (32-n))
- else
- Descale := (shift_temp shr n);
-{$else}
- Descale := (x + (INT32(1) shl (n-1)) shr n;
-{$endif}
-end;
-
-
-{ Perform dequantization and inverse DCT on one block of coefficients. }
-
-{GLOBAL}
-procedure jpeg_idct_float (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-type
- PWorkspace = ^TWorkspace;
- TWorkspace = array[0..DCTSIZE2-1] of FAST_FLOAT;
-var
- tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7 : FAST_FLOAT;
- tmp10, tmp11, tmp12, tmp13 : FAST_FLOAT;
- z5, z10, z11, z12, z13 : FAST_FLOAT;
- inptr : JCOEFPTR;
- quantptr : FLOAT_MULT_TYPE_FIELD_PTR;
- wsptr : PWorkSpace;
- outptr : JSAMPROW;
- range_limit : JSAMPROW;
- ctr : int;
- workspace : TWorkspace; { buffers data between passes }
- {SHIFT_TEMPS}
-var
- dcval : FAST_FLOAT;
-begin
-{ Each IDCT routine is responsible for range-limiting its results and
- converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
- be quite far out of range if the input data is corrupt, so a bulletproof
- range-limiting step is required. We use a mask-and-table-lookup method
- to do the combined operations quickly. See the comments with
- prepare_range_limit_table (in jdmaster.c) for more info. }
-
- range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));
-
- { Pass 1: process columns from input, store into work array. }
-
- inptr := coef_block;
- quantptr := FLOAT_MULT_TYPE_FIELD_PTR (compptr^.dct_table);
- wsptr := @workspace;
- for ctr := pred(DCTSIZE) downto 0 do
- begin
- { Due to quantization, we will usually find that many of the input
- coefficients are zero, especially the AC terms. We can exploit this
- by short-circuiting the IDCT calculation for any column in which all
- the AC terms are zero. In that case each output is equal to the
- DC coefficient (with scale factor as needed).
- With typical images and quantization tables, half or more of the
- column DCT calculations can be simplified this way. }
-
- if (inptr^[DCTSIZE*1]=0) and (inptr^[DCTSIZE*2]=0) and
- (inptr^[DCTSIZE*3]=0) and (inptr^[DCTSIZE*4]=0) and
- (inptr^[DCTSIZE*5]=0) and (inptr^[DCTSIZE*6]=0) and
- (inptr^[DCTSIZE*7]=0) then
- begin
- { AC terms all zero }
- FAST_FLOAT(dcval) := DEQUANTIZE(inptr^[DCTSIZE*0], quantptr^[DCTSIZE*0]);
-
- wsptr^[DCTSIZE*0] := dcval;
- wsptr^[DCTSIZE*1] := dcval;
- wsptr^[DCTSIZE*2] := dcval;
- wsptr^[DCTSIZE*3] := dcval;
- wsptr^[DCTSIZE*4] := dcval;
- wsptr^[DCTSIZE*5] := dcval;
- wsptr^[DCTSIZE*6] := dcval;
- wsptr^[DCTSIZE*7] := dcval;
-
- Inc(JCOEF_PTR(inptr)); { advance pointers to next column }
- Inc(FLOAT_MULT_TYPE_PTR(quantptr));
- Inc(FAST_FLOAT_PTR(wsptr));
- continue;
- end;
-
- { Even part }
-
- tmp0 := DEQUANTIZE(inptr^[DCTSIZE*0], quantptr^[DCTSIZE*0]);
- tmp1 := DEQUANTIZE(inptr^[DCTSIZE*2], quantptr^[DCTSIZE*2]);
- tmp2 := DEQUANTIZE(inptr^[DCTSIZE*4], quantptr^[DCTSIZE*4]);
- tmp3 := DEQUANTIZE(inptr^[DCTSIZE*6], quantptr^[DCTSIZE*6]);
-
- tmp10 := tmp0 + tmp2; { phase 3 }
- tmp11 := tmp0 - tmp2;
-
- tmp13 := tmp1 + tmp3; { phases 5-3 }
- tmp12 := (tmp1 - tmp3) * ({FAST_FLOAT}(1.414213562)) - tmp13; { 2*c4 }
-
- tmp0 := tmp10 + tmp13; { phase 2 }
- tmp3 := tmp10 - tmp13;
- tmp1 := tmp11 + tmp12;
- tmp2 := tmp11 - tmp12;
-
- { Odd part }
-
- tmp4 := DEQUANTIZE(inptr^[DCTSIZE*1], quantptr^[DCTSIZE*1]);
- tmp5 := DEQUANTIZE(inptr^[DCTSIZE*3], quantptr^[DCTSIZE*3]);
- tmp6 := DEQUANTIZE(inptr^[DCTSIZE*5], quantptr^[DCTSIZE*5]);
- tmp7 := DEQUANTIZE(inptr^[DCTSIZE*7], quantptr^[DCTSIZE*7]);
-
- z13 := tmp6 + tmp5; { phase 6 }
- z10 := tmp6 - tmp5;
- z11 := tmp4 + tmp7;
- z12 := tmp4 - tmp7;
-
- tmp7 := z11 + z13; { phase 5 }
- tmp11 := (z11 - z13) * ({FAST_FLOAT}(1.414213562)); { 2*c4 }
-
- z5 := (z10 + z12) * ({FAST_FLOAT}(1.847759065)); { 2*c2 }
- tmp10 := ({FAST_FLOAT}(1.082392200)) * z12 - z5; { 2*(c2-c6) }
- tmp12 := ({FAST_FLOAT}(-2.613125930)) * z10 + z5; { -2*(c2+c6) }
-
- tmp6 := tmp12 - tmp7; { phase 2 }
- tmp5 := tmp11 - tmp6;
- tmp4 := tmp10 + tmp5;
-
- wsptr^[DCTSIZE*0] := tmp0 + tmp7;
- wsptr^[DCTSIZE*7] := tmp0 - tmp7;
- wsptr^[DCTSIZE*1] := tmp1 + tmp6;
- wsptr^[DCTSIZE*6] := tmp1 - tmp6;
- wsptr^[DCTSIZE*2] := tmp2 + tmp5;
- wsptr^[DCTSIZE*5] := tmp2 - tmp5;
- wsptr^[DCTSIZE*4] := tmp3 + tmp4;
- wsptr^[DCTSIZE*3] := tmp3 - tmp4;
-
- Inc(JCOEF_PTR(inptr)); { advance pointers to next column }
- Inc(FLOAT_MULT_TYPE_PTR(quantptr));
- Inc(FAST_FLOAT_PTR(wsptr));
- end;
-
- { Pass 2: process rows from work array, store into output array. }
- { Note that we must descale the results by a factor of 8 = 2**3. }
-
- wsptr := @workspace;
- for ctr := 0 to pred(DCTSIZE) do
- begin
- outptr := JSAMPROW(@(output_buf^[ctr]^[output_col]));
- { Rows of zeroes can be exploited in the same way as we did with columns.
- However, the column calculation has created many nonzero AC terms, so
- the simplification applies less often (typically 5% to 10% of the time).
- And testing floats for zero is relatively expensive, so we don't bother. }
-
- { Even part }
-
- tmp10 := wsptr^[0] + wsptr^[4];
- tmp11 := wsptr^[0] - wsptr^[4];
-
- tmp13 := wsptr^[2] + wsptr^[6];
- tmp12 := (wsptr^[2] - wsptr^[6]) * ({FAST_FLOAT}(1.414213562)) - tmp13;
-
- tmp0 := tmp10 + tmp13;
- tmp3 := tmp10 - tmp13;
- tmp1 := tmp11 + tmp12;
- tmp2 := tmp11 - tmp12;
-
- { Odd part }
-
- z13 := wsptr^[5] + wsptr^[3];
- z10 := wsptr^[5] - wsptr^[3];
- z11 := wsptr^[1] + wsptr^[7];
- z12 := wsptr^[1] - wsptr^[7];
-
- tmp7 := z11 + z13;
- tmp11 := (z11 - z13) * ({FAST_FLOAT}(1.414213562));
-
- z5 := (z10 + z12) * ({FAST_FLOAT}(1.847759065)); { 2*c2 }
- tmp10 := ({FAST_FLOAT}(1.082392200)) * z12 - z5; { 2*(c2-c6) }
- tmp12 := ({FAST_FLOAT}(-2.613125930)) * z10 + z5; { -2*(c2+c6) }
-
- tmp6 := tmp12 - tmp7;
- tmp5 := tmp11 - tmp6;
- tmp4 := tmp10 + tmp5;
-
- { Final output stage: scale down by a factor of 8 and range-limit }
-
- outptr^[0] := range_limit^[ int(DESCALE( INT32(Round((tmp0 + tmp7))), 3))
- and RANGE_MASK];
- outptr^[7] := range_limit^[ int(DESCALE( INT32(Round((tmp0 - tmp7))), 3))
- and RANGE_MASK];
- outptr^[1] := range_limit^[ int(DESCALE( INT32(Round((tmp1 + tmp6))), 3))
- and RANGE_MASK];
- outptr^[6] := range_limit^[ int(DESCALE( INT32(Round((tmp1 - tmp6))), 3))
- and RANGE_MASK];
- outptr^[2] := range_limit^[ int(DESCALE( INT32(Round((tmp2 + tmp5))), 3))
- and RANGE_MASK];
- outptr^[5] := range_limit^[ int(DESCALE( INT32(Round((tmp2 - tmp5))), 3))
- and RANGE_MASK];
- outptr^[4] := range_limit^[ int(DESCALE( INT32(Round((tmp3 + tmp4))), 3))
- and RANGE_MASK];
- outptr^[3] := range_limit^[ int(DESCALE( INT32(Round((tmp3 - tmp4))), 3))
- and RANGE_MASK];
-
- Inc(FAST_FLOAT_PTR(wsptr), DCTSIZE); { advance pointer to next row }
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jidctfst.pas b/packages/base/pasjpeg/jidctfst.pas
deleted file mode 100644
index 18b3448887..0000000000
--- a/packages/base/pasjpeg/jidctfst.pas
+++ /dev/null
@@ -1,410 +0,0 @@
-Unit JIDctFst;
-
-{ This file contains a fast, not so accurate integer implementation of the
- inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
- must also perform dequantization of the input coefficients.
-
- A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
- on each row (or vice versa, but it's more convenient to emit a row at
- a time). Direct algorithms are also available, but they are much more
- complex and seem not to be any faster when reduced to code.
-
- This implementation is based on Arai, Agui, and Nakajima's algorithm for
- scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
- Japanese, but the algorithm is described in the Pennebaker & Mitchell
- JPEG textbook (see REFERENCES section in file README). The following code
- is based directly on figure 4-8 in P&M.
- While an 8-point DCT cannot be done in less than 11 multiplies, it is
- possible to arrange the computation so that many of the multiplies are
- simple scalings of the final outputs. These multiplies can then be
- folded into the multiplications or divisions by the JPEG quantization
- table entries. The AA&N method leaves only 5 multiplies and 29 adds
- to be done in the DCT itself.
- The primary disadvantage of this method is that with fixed-point math,
- accuracy is lost due to imprecise representation of the scaled
- quantization values. The smaller the quantization table entry, the less
- precise the scaled value, so this implementation does worse with high-
- quality-setting files than with low-quality ones. }
-
-{ Original : jidctfst.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jpeglib,
- jdct; { Private declarations for DCT subsystem }
-
-
-{ Perform dequantization and inverse DCT on one block of coefficients. }
-
-{GLOBAL}
-procedure jpeg_idct_ifast (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-
-implementation
-
-{ This module is specialized to the case DCTSIZE = 8. }
-
-{$ifndef DCTSIZE_IS_8}
- Sorry, this code only copes with 8x8 DCTs. { deliberate syntax err }
-{$endif}
-
-{ Scaling decisions are generally the same as in the LL&M algorithm;
- see jidctint.c for more details. However, we choose to descale
- (right shift) multiplication products as soon as they are formed,
- rather than carrying additional fractional bits into subsequent additions.
- This compromises accuracy slightly, but it lets us save a few shifts.
- More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)
- everywhere except in the multiplications proper; this saves a good deal
- of work on 16-bit-int machines.
-
- The dequantized coefficients are not integers because the AA&N scaling
- factors have been incorporated. We represent them scaled up by PASS1_BITS,
- so that the first and second IDCT rounds have the same input scaling.
- For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to
- avoid a descaling shift; this compromises accuracy rather drastically
- for small quantization table entries, but it saves a lot of shifts.
- For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway,
- so we use a much larger scaling factor to preserve accuracy.
-
- A final compromise is to represent the multiplicative constants to only
- 8 fractional bits, rather than 13. This saves some shifting work on some
- machines, and may also reduce the cost of multiplication (since there
- are fewer one-bits in the constants). }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-const
- CONST_BITS = 8;
- PASS1_BITS = 2;
-{$else}
-const
- CONST_BITS = 8;
- PASS1_BITS = 1; { lose a little precision to avoid overflow }
-{$endif}
-
-
-const
- FIX_1_082392200 = INT32(Round((INT32(1) shl CONST_BITS)*1.082392200)); {277}
- FIX_1_414213562 = INT32(Round((INT32(1) shl CONST_BITS)*1.414213562)); {362}
- FIX_1_847759065 = INT32(Round((INT32(1) shl CONST_BITS)*1.847759065)); {473}
- FIX_2_613125930 = INT32(Round((INT32(1) shl CONST_BITS)*2.613125930)); {669}
-
-
-{ Descale and correctly round an INT32 value that's scaled by N bits.
- We assume RIGHT_SHIFT rounds towards minus infinity, so adding
- the fudge factor is correct for either sign of X. }
-
-function DESCALE(x : INT32; n : int) : INT32;
-var
- shift_temp : INT32;
-begin
-{$ifdef USE_ACCURATE_ROUNDING}
- shift_temp := x + (INT32(1) shl (n-1));
-{$else}
-{ We can gain a little more speed, with a further compromise in accuracy,
- by omitting the addition in a descaling shift. This yields an incorrectly
- rounded result half the time... }
- shift_temp := x;
-{$endif}
-
-{$ifdef RIGHT_SHIFT_IS_UNSIGNED}
- if shift_temp < 0 then
- Descale := (shift_temp shr n) or ((not INT32(0)) shl (32-n))
- else
-{$endif}
- Descale := (shift_temp shr n);
-end;
-
-
-{ Multiply a DCTELEM variable by an INT32 constant, and immediately
- descale to yield a DCTELEM result. }
-
- {(DCTELEM( DESCALE((var) * (const), CONST_BITS))}
- function Multiply(Avar, Aconst: Integer): DCTELEM;
- begin
- Multiply := DCTELEM( Avar*INT32(Aconst) div (INT32(1) shl CONST_BITS));
- end;
-
-
-{ Dequantize a coefficient by multiplying it by the multiplier-table
- entry; produce a DCTELEM result. For 8-bit data a 16x16->16
- multiplication will do. For 12-bit data, the multiplier table is
- declared INT32, so a 32-bit multiply will be used. }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
- function DEQUANTIZE(coef,quantval : int) : int;
- begin
- Dequantize := ( IFAST_MULT_TYPE(coef) * quantval);
- end;
-{$else}
- function DEQUANTIZE(coef,quantval : INT32) : int;
- begin
- Dequantize := DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS);
- end;
-{$endif}
-
-
-{ Like DESCALE, but applies to a DCTELEM and produces an int.
- We assume that int right shift is unsigned if INT32 right shift is. }
-
-function IDESCALE(x : DCTELEM; n : int) : int;
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-const
- DCTELEMBITS = 16; { DCTELEM may be 16 or 32 bits }
-{$else}
-const
- DCTELEMBITS = 32; { DCTELEM must be 32 bits }
-{$endif}
-var
- ishift_temp : DCTELEM;
-begin
-{$ifndef USE_ACCURATE_ROUNDING}
- ishift_temp := x + (INT32(1) shl (n-1));
-{$else}
-{ We can gain a little more speed, with a further compromise in accuracy,
- by omitting the addition in a descaling shift. This yields an incorrectly
- rounded result half the time... }
- ishift_temp := x;
-{$endif}
-
-{$ifdef RIGHT_SHIFT_IS_UNSIGNED}
- if ishift_temp < 0 then
- IDescale := (ishift_temp shr n)
- or ((not DCTELEM(0)) shl (DCTELEMBITS-n))
- else
-{$endif}
- IDescale := (ishift_temp shr n);
-end;
-
-
-
-{ Perform dequantization and inverse DCT on one block of coefficients. }
-
-{GLOBAL}
-procedure jpeg_idct_ifast (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-type
- PWorkspace = ^TWorkspace;
- TWorkspace = coef_bits_field; { buffers data between passes }
-var
- tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7 : DCTELEM;
- tmp10, tmp11, tmp12, tmp13 : DCTELEM;
- z5, z10, z11, z12, z13 : DCTELEM;
- inptr : JCOEFPTR;
- quantptr : IFAST_MULT_TYPE_FIELD_PTR;
- wsptr : PWorkspace;
- outptr : JSAMPROW;
- range_limit : JSAMPROW;
- ctr : int;
- workspace : TWorkspace; { buffers data between passes }
- {SHIFT_TEMPS} { for DESCALE }
- {ISHIFT_TEMPS} { for IDESCALE }
-var
- dcval : int;
-var
- dcval_ : JSAMPLE;
-begin
-{ Each IDCT routine is responsible for range-limiting its results and
- converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
- be quite far out of range if the input data is corrupt, so a bulletproof
- range-limiting step is required. We use a mask-and-table-lookup method
- to do the combined operations quickly. See the comments with
- prepare_range_limit_table (in jdmaster.c) for more info. }
-
- range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));
- { Pass 1: process columns from input, store into work array. }
-
- inptr := coef_block;
- quantptr := IFAST_MULT_TYPE_FIELD_PTR(compptr^.dct_table);
- wsptr := @workspace;
- for ctr := pred(DCTSIZE) downto 0 do
- begin
- { Due to quantization, we will usually find that many of the input
- coefficients are zero, especially the AC terms. We can exploit this
- by short-circuiting the IDCT calculation for any column in which all
- the AC terms are zero. In that case each output is equal to the
- DC coefficient (with scale factor as needed).
- With typical images and quantization tables, half or more of the
- column DCT calculations can be simplified this way. }
-
- if (inptr^[DCTSIZE*1]=0) and (inptr^[DCTSIZE*2]=0) and (inptr^[DCTSIZE*3]=0) and
- (inptr^[DCTSIZE*4]=0) and (inptr^[DCTSIZE*5]=0) and (inptr^[DCTSIZE*6]=0) and
- (inptr^[DCTSIZE*7]=0) then
- begin
- { AC terms all zero }
- dcval := int(DEQUANTIZE(inptr^[DCTSIZE*0], quantptr^[DCTSIZE*0]));
-
- wsptr^[DCTSIZE*0] := dcval;
- wsptr^[DCTSIZE*1] := dcval;
- wsptr^[DCTSIZE*2] := dcval;
- wsptr^[DCTSIZE*3] := dcval;
- wsptr^[DCTSIZE*4] := dcval;
- wsptr^[DCTSIZE*5] := dcval;
- wsptr^[DCTSIZE*6] := dcval;
- wsptr^[DCTSIZE*7] := dcval;
-
- Inc(JCOEF_PTR(inptr)); { advance pointers to next column }
- Inc(IFAST_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
- continue;
- end;
-
- { Even part }
-
- tmp0 := DEQUANTIZE(inptr^[DCTSIZE*0], quantptr^[DCTSIZE*0]);
- tmp1 := DEQUANTIZE(inptr^[DCTSIZE*2], quantptr^[DCTSIZE*2]);
- tmp2 := DEQUANTIZE(inptr^[DCTSIZE*4], quantptr^[DCTSIZE*4]);
- tmp3 := DEQUANTIZE(inptr^[DCTSIZE*6], quantptr^[DCTSIZE*6]);
-
- tmp10 := tmp0 + tmp2; { phase 3 }
- tmp11 := tmp0 - tmp2;
-
- tmp13 := tmp1 + tmp3; { phases 5-3 }
- tmp12 := MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; { 2*c4 }
-
- tmp0 := tmp10 + tmp13; { phase 2 }
- tmp3 := tmp10 - tmp13;
- tmp1 := tmp11 + tmp12;
- tmp2 := tmp11 - tmp12;
-
- { Odd part }
-
- tmp4 := DEQUANTIZE(inptr^[DCTSIZE*1], quantptr^[DCTSIZE*1]);
- tmp5 := DEQUANTIZE(inptr^[DCTSIZE*3], quantptr^[DCTSIZE*3]);
- tmp6 := DEQUANTIZE(inptr^[DCTSIZE*5], quantptr^[DCTSIZE*5]);
- tmp7 := DEQUANTIZE(inptr^[DCTSIZE*7], quantptr^[DCTSIZE*7]);
-
- z13 := tmp6 + tmp5; { phase 6 }
- z10 := tmp6 - tmp5;
- z11 := tmp4 + tmp7;
- z12 := tmp4 - tmp7;
-
- tmp7 := z11 + z13; { phase 5 }
- tmp11 := MULTIPLY(z11 - z13, FIX_1_414213562); { 2*c4 }
-
- z5 := MULTIPLY(z10 + z12, FIX_1_847759065); { 2*c2 }
- tmp10 := MULTIPLY(z12, FIX_1_082392200) - z5; { 2*(c2-c6) }
- tmp12 := MULTIPLY(z10, - FIX_2_613125930) + z5; { -2*(c2+c6) }
-
- tmp6 := tmp12 - tmp7; { phase 2 }
- tmp5 := tmp11 - tmp6;
- tmp4 := tmp10 + tmp5;
-
- wsptr^[DCTSIZE*0] := int (tmp0 + tmp7);
- wsptr^[DCTSIZE*7] := int (tmp0 - tmp7);
- wsptr^[DCTSIZE*1] := int (tmp1 + tmp6);
- wsptr^[DCTSIZE*6] := int (tmp1 - tmp6);
- wsptr^[DCTSIZE*2] := int (tmp2 + tmp5);
- wsptr^[DCTSIZE*5] := int (tmp2 - tmp5);
- wsptr^[DCTSIZE*4] := int (tmp3 + tmp4);
- wsptr^[DCTSIZE*3] := int (tmp3 - tmp4);
-
- Inc(JCOEF_PTR(inptr)); { advance pointers to next column }
- Inc(IFAST_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
- end;
-
- { Pass 2: process rows from work array, store into output array. }
- { Note that we must descale the results by a factor of 8 == 2**3, }
- { and also undo the PASS1_BITS scaling. }
-
- wsptr := @workspace;
- for ctr := 0 to pred(DCTSIZE) do
- begin
- outptr := JSAMPROW(@output_buf^[ctr]^[output_col]);
- { Rows of zeroes can be exploited in the same way as we did with columns.
- However, the column calculation has created many nonzero AC terms, so
- the simplification applies less often (typically 5% to 10% of the time).
- On machines with very fast multiplication, it's possible that the
- test takes more time than it's worth. In that case this section
- may be commented out. }
-
-{$ifndef NO_ZERO_ROW_TEST}
- if (wsptr^[1]=0) and (wsptr^[2]=0) and (wsptr^[3]=0) and (wsptr^[4]=0) and
- (wsptr^[5]=0) and (wsptr^[6]=0) and (wsptr^[7]=0) then
- begin
- { AC terms all zero }
- dcval_ := range_limit^[IDESCALE(wsptr^[0], PASS1_BITS+3)
- and RANGE_MASK];
-
- outptr^[0] := dcval_;
- outptr^[1] := dcval_;
- outptr^[2] := dcval_;
- outptr^[3] := dcval_;
- outptr^[4] := dcval_;
- outptr^[5] := dcval_;
- outptr^[6] := dcval_;
- outptr^[7] := dcval_;
-
- Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- continue;
- end;
-{$endif}
-
- { Even part }
-
- tmp10 := (DCTELEM(wsptr^[0]) + DCTELEM(wsptr^[4]));
- tmp11 := (DCTELEM(wsptr^[0]) - DCTELEM(wsptr^[4]));
-
- tmp13 := (DCTELEM(wsptr^[2]) + DCTELEM(wsptr^[6]));
- tmp12 := MULTIPLY(DCTELEM(wsptr^[2]) - DCTELEM(wsptr^[6]), FIX_1_414213562)
- - tmp13;
-
- tmp0 := tmp10 + tmp13;
- tmp3 := tmp10 - tmp13;
- tmp1 := tmp11 + tmp12;
- tmp2 := tmp11 - tmp12;
-
- { Odd part }
-
- z13 := DCTELEM(wsptr^[5]) + DCTELEM(wsptr^[3]);
- z10 := DCTELEM(wsptr^[5]) - DCTELEM(wsptr^[3]);
- z11 := DCTELEM(wsptr^[1]) + DCTELEM(wsptr^[7]);
- z12 := DCTELEM(wsptr^[1]) - DCTELEM(wsptr^[7]);
-
- tmp7 := z11 + z13; { phase 5 }
- tmp11 := MULTIPLY(z11 - z13, FIX_1_414213562); { 2*c4 }
-
- z5 := MULTIPLY(z10 + z12, FIX_1_847759065); { 2*c2 }
- tmp10 := MULTIPLY(z12, FIX_1_082392200) - z5; { 2*(c2-c6) }
- tmp12 := MULTIPLY(z10, - FIX_2_613125930) + z5; { -2*(c2+c6) }
-
- tmp6 := tmp12 - tmp7; { phase 2 }
- tmp5 := tmp11 - tmp6;
- tmp4 := tmp10 + tmp5;
-
- { Final output stage: scale down by a factor of 8 and range-limit }
-
- outptr^[0] := range_limit^[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[7] := range_limit^[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[1] := range_limit^[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[6] := range_limit^[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[2] := range_limit^[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[5] := range_limit^[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[4] := range_limit^[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
- and RANGE_MASK];
- outptr^[3] := range_limit^[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
- and RANGE_MASK];
-
- Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jidctint.pas b/packages/base/pasjpeg/jidctint.pas
deleted file mode 100644
index 74fadc62a1..0000000000
--- a/packages/base/pasjpeg/jidctint.pas
+++ /dev/null
@@ -1,440 +0,0 @@
-Unit JIDctInt;
-{$Q+}
-
-{ This file contains a slow-but-accurate integer implementation of the
- inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
- must also perform dequantization of the input coefficients.
-
- A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
- on each row (or vice versa, but it's more convenient to emit a row at
- a time). Direct algorithms are also available, but they are much more
- complex and seem not to be any faster when reduced to code.
-
- This implementation is based on an algorithm described in
- C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
- Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
- Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
- The primary algorithm described there uses 11 multiplies and 29 adds.
- We use their alternate method with 12 multiplies and 32 adds.
- The advantage of this method is that no data path contains more than one
- multiplication; this allows a very simple and accurate implementation in
- scaled fixed-point arithmetic, with a minimal number of shifts. }
-
-{ Original : jidctint.c ; Copyright (C) 1991-1998, Thomas G. Lane. }
-
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jpeglib,
- jdct; { Private declarations for DCT subsystem }
-
-{ Perform dequantization and inverse DCT on one block of coefficients. }
-
-{GLOBAL}
-procedure jpeg_idct_islow (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-
-implementation
-
-{ This module is specialized to the case DCTSIZE = 8. }
-
-{$ifndef DCTSIZE_IS_8}
- Sorry, this code only copes with 8x8 DCTs. { deliberate syntax err }
-{$endif}
-
-{ The poop on this scaling stuff is as follows:
-
- Each 1-D IDCT step produces outputs which are a factor of sqrt(N)
- larger than the true IDCT outputs. The final outputs are therefore
- a factor of N larger than desired; since N=8 this can be cured by
- a simple right shift at the end of the algorithm. The advantage of
- this arrangement is that we save two multiplications per 1-D IDCT,
- because the y0 and y4 inputs need not be divided by sqrt(N).
-
- We have to do addition and subtraction of the integer inputs, which
- is no problem, and multiplication by fractional constants, which is
- a problem to do in integer arithmetic. We multiply all the constants
- by CONST_SCALE and convert them to integer constants (thus retaining
- CONST_BITS bits of precision in the constants). After doing a
- multiplication we have to divide the product by CONST_SCALE, with proper
- rounding, to produce the correct output. This division can be done
- cheaply as a right shift of CONST_BITS bits. We postpone shifting
- as long as possible so that partial sums can be added together with
- full fractional precision.
-
- The outputs of the first pass are scaled up by PASS1_BITS bits so that
- they are represented to better-than-integral precision. These outputs
- require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
- with the recommended scaling. (To scale up 12-bit sample data further, an
- intermediate INT32 array would be needed.)
-
- To avoid overflow of the 32-bit intermediate results in pass 2, we must
- have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
- shows that the values given below are the most effective. }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-const
- CONST_BITS = 13;
- PASS1_BITS = 2;
-{$else}
-const
- CONST_BITS = 13;
- PASS1_BITS = 1; { lose a little precision to avoid overflow }
-{$endif}
-
-const
- CONST_SCALE = (INT32(1) shl CONST_BITS);
-
-const
- FIX_0_298631336 = INT32(Round(CONST_SCALE * 0.298631336)); {2446}
- FIX_0_390180644 = INT32(Round(CONST_SCALE * 0.390180644)); {3196}
- FIX_0_541196100 = INT32(Round(CONST_SCALE * 0.541196100)); {4433}
- FIX_0_765366865 = INT32(Round(CONST_SCALE * 0.765366865)); {6270}
- FIX_0_899976223 = INT32(Round(CONST_SCALE * 0.899976223)); {7373}
- FIX_1_175875602 = INT32(Round(CONST_SCALE * 1.175875602)); {9633}
- FIX_1_501321110 = INT32(Round(CONST_SCALE * 1.501321110)); {12299}
- FIX_1_847759065 = INT32(Round(CONST_SCALE * 1.847759065)); {15137}
- FIX_1_961570560 = INT32(Round(CONST_SCALE * 1.961570560)); {16069}
- FIX_2_053119869 = INT32(Round(CONST_SCALE * 2.053119869)); {16819}
- FIX_2_562915447 = INT32(Round(CONST_SCALE * 2.562915447)); {20995}
- FIX_3_072711026 = INT32(Round(CONST_SCALE * 3.072711026)); {25172}
-
-
-
-{ Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
- For 8-bit samples with the recommended scaling, all the variable
- and constant values involved are no more than 16 bits wide, so a
- 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
- For 12-bit samples, a full 32-bit multiplication will be needed. }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-
- {$IFDEF BASM16}
- {$IFNDEF WIN32}
- {MULTIPLY16C16(var,const)}
- function Multiply(X, Y: Integer): integer; assembler;
- asm
- mov ax, X
- imul Y
- mov al, ah
- mov ah, dl
- end;
- {$ENDIF}
- {$ENDIF}
-
- function Multiply(X, Y: INT32): INT32;
- begin
- Multiply := INT32(X) * INT32(Y);
- end;
-
-
-{$else}
- {#define MULTIPLY(var,const) ((var) * (const))}
- function Multiply(X, Y: INT32): INT32;
- begin
- Multiply := INT32(X) * INT32(Y);
- end;
-{$endif}
-
-
-{ Dequantize a coefficient by multiplying it by the multiplier-table
- entry; produce an int result. In this module, both inputs and result
- are 16 bits or less, so either int or short multiply will work. }
-
-function DEQUANTIZE(coef,quantval : int) : int;
-begin
- Dequantize := ( ISLOW_MULT_TYPE(coef) * quantval);
-end;
-
-{ Descale and correctly round an INT32 value that's scaled by N bits.
- We assume RIGHT_SHIFT rounds towards minus infinity, so adding
- the fudge factor is correct for either sign of X. }
-
-function DESCALE(x : INT32; n : int) : INT32;
-var
- shift_temp : INT32;
-begin
-{$ifdef RIGHT_SHIFT_IS_UNSIGNED}
- shift_temp := x + (INT32(1) shl (n-1));
- if shift_temp < 0 then
- Descale := (shift_temp shr n) or ((not INT32(0)) shl (32-n))
- else
- Descale := (shift_temp shr n);
-{$else}
- Descale := (x + (INT32(1) shl (n-1)) shr n;
-{$endif}
-end;
-
-{ Perform dequantization and inverse DCT on one block of coefficients. }
-
-{GLOBAL}
-procedure jpeg_idct_islow (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-type
- PWorkspace = ^TWorkspace;
- TWorkspace = coef_bits_field; { buffers data between passes }
-var
- tmp0, tmp1, tmp2, tmp3 : INT32;
- tmp10, tmp11, tmp12, tmp13 : INT32;
- z1, z2, z3, z4, z5 : INT32;
- inptr : JCOEFPTR;
- quantptr : ISLOW_MULT_TYPE_FIELD_PTR;
- wsptr : PWorkspace;
- outptr : JSAMPROW;
- range_limit : JSAMPROW;
- ctr : int;
- workspace : TWorkspace;
- {SHIFT_TEMPS}
-var
- dcval : int;
-var
- dcval_ : JSAMPLE;
-begin
-{ Each IDCT routine is responsible for range-limiting its results and
- converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
- be quite far out of range if the input data is corrupt, so a bulletproof
- range-limiting step is required. We use a mask-and-table-lookup method
- to do the combined operations quickly. See the comments with
- prepare_range_limit_table (in jdmaster.c) for more info. }
-
- range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));
-
-
- { Pass 1: process columns from input, store into work array. }
- { Note results are scaled up by sqrt(8) compared to a true IDCT; }
- { furthermore, we scale the results by 2**PASS1_BITS. }
-
- inptr := coef_block;
- quantptr := ISLOW_MULT_TYPE_FIELD_PTR (compptr^.dct_table);
- wsptr := PWorkspace(@workspace);
- for ctr := pred(DCTSIZE) downto 0 do
- begin
- { Due to quantization, we will usually find that many of the input
- coefficients are zero, especially the AC terms. We can exploit this
- by short-circuiting the IDCT calculation for any column in which all
- the AC terms are zero. In that case each output is equal to the
- DC coefficient (with scale factor as needed).
- With typical images and quantization tables, half or more of the
- column DCT calculations can be simplified this way. }
-
- if ((inptr^[DCTSIZE*1]=0) and (inptr^[DCTSIZE*2]=0) and
- (inptr^[DCTSIZE*3]=0) and (inptr^[DCTSIZE*4]=0) and
- (inptr^[DCTSIZE*5]=0) and (inptr^[DCTSIZE*6]=0) and
- (inptr^[DCTSIZE*7]=0)) then
- begin
- { AC terms all zero }
- dcval := DEQUANTIZE(inptr^[DCTSIZE*0], quantptr^[DCTSIZE*0]) shl PASS1_BITS;
-
- wsptr^[DCTSIZE*0] := dcval;
- wsptr^[DCTSIZE*1] := dcval;
- wsptr^[DCTSIZE*2] := dcval;
- wsptr^[DCTSIZE*3] := dcval;
- wsptr^[DCTSIZE*4] := dcval;
- wsptr^[DCTSIZE*5] := dcval;
- wsptr^[DCTSIZE*6] := dcval;
- wsptr^[DCTSIZE*7] := dcval;
-
- Inc(JCOEF_PTR(inptr)); { advance pointers to next column }
- Inc(ISLOW_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
- continue;
- end;
-
- { Even part: reverse the even part of the forward DCT. }
- { The rotator is sqrt(2)*c(-6). }
-
- z2 := DEQUANTIZE(inptr^[DCTSIZE*2], quantptr^[DCTSIZE*2]);
- z3 := DEQUANTIZE(inptr^[DCTSIZE*6], quantptr^[DCTSIZE*6]);
-
- z1 := MULTIPLY(z2 + z3, FIX_0_541196100);
- tmp2 := z1 + MULTIPLY(z3, - FIX_1_847759065);
- tmp3 := z1 + MULTIPLY(z2, FIX_0_765366865);
-
- z2 := DEQUANTIZE(inptr^[DCTSIZE*0], quantptr^[DCTSIZE*0]);
- z3 := DEQUANTIZE(inptr^[DCTSIZE*4], quantptr^[DCTSIZE*4]);
-
- tmp0 := (z2 + z3) shl CONST_BITS;
- tmp1 := (z2 - z3) shl CONST_BITS;
-
- tmp10 := tmp0 + tmp3;
- tmp13 := tmp0 - tmp3;
- tmp11 := tmp1 + tmp2;
- tmp12 := tmp1 - tmp2;
-
- { Odd part per figure 8; the matrix is unitary and hence its
- transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. }
-
- tmp0 := DEQUANTIZE(inptr^[DCTSIZE*7], quantptr^[DCTSIZE*7]);
- tmp1 := DEQUANTIZE(inptr^[DCTSIZE*5], quantptr^[DCTSIZE*5]);
- tmp2 := DEQUANTIZE(inptr^[DCTSIZE*3], quantptr^[DCTSIZE*3]);
- tmp3 := DEQUANTIZE(inptr^[DCTSIZE*1], quantptr^[DCTSIZE*1]);
-
- z1 := tmp0 + tmp3;
- z2 := tmp1 + tmp2;
- z3 := tmp0 + tmp2;
- z4 := tmp1 + tmp3;
- z5 := MULTIPLY(z3 + z4, FIX_1_175875602); { sqrt(2) * c3 }
-
- tmp0 := MULTIPLY(tmp0, FIX_0_298631336); { sqrt(2) * (-c1+c3+c5-c7) }
- tmp1 := MULTIPLY(tmp1, FIX_2_053119869); { sqrt(2) * ( c1+c3-c5+c7) }
- tmp2 := MULTIPLY(tmp2, FIX_3_072711026); { sqrt(2) * ( c1+c3+c5-c7) }
- tmp3 := MULTIPLY(tmp3, FIX_1_501321110); { sqrt(2) * ( c1+c3-c5-c7) }
- z1 := MULTIPLY(z1, - FIX_0_899976223); { sqrt(2) * (c7-c3) }
- z2 := MULTIPLY(z2, - FIX_2_562915447); { sqrt(2) * (-c1-c3) }
- z3 := MULTIPLY(z3, - FIX_1_961570560); { sqrt(2) * (-c3-c5) }
- z4 := MULTIPLY(z4, - FIX_0_390180644); { sqrt(2) * (c5-c3) }
-
- Inc(z3, z5);
- Inc(z4, z5);
-
- Inc(tmp0, z1 + z3);
- Inc(tmp1, z2 + z4);
- Inc(tmp2, z2 + z3);
- Inc(tmp3, z1 + z4);
-
- { Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 }
-
- wsptr^[DCTSIZE*0] := int (DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS));
- wsptr^[DCTSIZE*7] := int (DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS));
- wsptr^[DCTSIZE*1] := int (DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS));
- wsptr^[DCTSIZE*6] := int (DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS));
- wsptr^[DCTSIZE*2] := int (DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS));
- wsptr^[DCTSIZE*5] := int (DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS));
- wsptr^[DCTSIZE*3] := int (DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS));
- wsptr^[DCTSIZE*4] := int (DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS));
-
- Inc(JCOEF_PTR(inptr)); { advance pointers to next column }
- Inc(ISLOW_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
- end;
-
- { Pass 2: process rows from work array, store into output array. }
- { Note that we must descale the results by a factor of 8 == 2**3, }
- { and also undo the PASS1_BITS scaling. }
-
- wsptr := @workspace;
- for ctr := 0 to pred(DCTSIZE) do
- begin
- outptr := output_buf^[ctr];
- Inc(JSAMPLE_PTR(outptr), output_col);
- { Rows of zeroes can be exploited in the same way as we did with columns.
- However, the column calculation has created many nonzero AC terms, so
- the simplification applies less often (typically 5% to 10% of the time).
- On machines with very fast multiplication, it's possible that the
- test takes more time than it's worth. In that case this section
- may be commented out. }
-
-{$ifndef NO_ZERO_ROW_TEST}
- if ((wsptr^[1]=0) and (wsptr^[2]=0) and (wsptr^[3]=0) and (wsptr^[4]=0)
- and (wsptr^[5]=0) and (wsptr^[6]=0) and (wsptr^[7]=0)) then
- begin
- { AC terms all zero }
- JSAMPLE(dcval_) := range_limit^[int(DESCALE(INT32(wsptr^[0]),
- PASS1_BITS+3)) and RANGE_MASK];
-
- outptr^[0] := dcval_;
- outptr^[1] := dcval_;
- outptr^[2] := dcval_;
- outptr^[3] := dcval_;
- outptr^[4] := dcval_;
- outptr^[5] := dcval_;
- outptr^[6] := dcval_;
- outptr^[7] := dcval_;
-
- Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- continue;
- end;
-{$endif}
-
- { Even part: reverse the even part of the forward DCT. }
- { The rotator is sqrt(2)*c(-6). }
-
- z2 := INT32 (wsptr^[2]);
- z3 := INT32 (wsptr^[6]);
-
- z1 := MULTIPLY(z2 + z3, FIX_0_541196100);
- tmp2 := z1 + MULTIPLY(z3, - FIX_1_847759065);
- tmp3 := z1 + MULTIPLY(z2, FIX_0_765366865);
-
- tmp0 := (INT32(wsptr^[0]) + INT32(wsptr^[4])) shl CONST_BITS;
- tmp1 := (INT32(wsptr^[0]) - INT32(wsptr^[4])) shl CONST_BITS;
-
- tmp10 := tmp0 + tmp3;
- tmp13 := tmp0 - tmp3;
- tmp11 := tmp1 + tmp2;
- tmp12 := tmp1 - tmp2;
-
- { Odd part per figure 8; the matrix is unitary and hence its
- transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. }
-
- tmp0 := INT32(wsptr^[7]);
- tmp1 := INT32(wsptr^[5]);
- tmp2 := INT32(wsptr^[3]);
- tmp3 := INT32(wsptr^[1]);
-
- z1 := tmp0 + tmp3;
- z2 := tmp1 + tmp2;
- z3 := tmp0 + tmp2;
- z4 := tmp1 + tmp3;
- z5 := MULTIPLY(z3 + z4, FIX_1_175875602); { sqrt(2) * c3 }
-
- tmp0 := MULTIPLY(tmp0, FIX_0_298631336); { sqrt(2) * (-c1+c3+c5-c7) }
- tmp1 := MULTIPLY(tmp1, FIX_2_053119869); { sqrt(2) * ( c1+c3-c5+c7) }
- tmp2 := MULTIPLY(tmp2, FIX_3_072711026); { sqrt(2) * ( c1+c3+c5-c7) }
- tmp3 := MULTIPLY(tmp3, FIX_1_501321110); { sqrt(2) * ( c1+c3-c5-c7) }
- z1 := MULTIPLY(z1, - FIX_0_899976223); { sqrt(2) * (c7-c3) }
- z2 := MULTIPLY(z2, - FIX_2_562915447); { sqrt(2) * (-c1-c3) }
- z3 := MULTIPLY(z3, - FIX_1_961570560); { sqrt(2) * (-c3-c5) }
- z4 := MULTIPLY(z4, - FIX_0_390180644); { sqrt(2) * (c5-c3) }
-
- Inc(z3, z5);
- Inc(z4, z5);
-
- Inc(tmp0, z1 + z3);
- Inc(tmp1, z2 + z4);
- Inc(tmp2, z2 + z3);
- Inc(tmp3, z1 + z4);
-
- { Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 }
-
- outptr^[0] := range_limit^[ int(DESCALE(tmp10 + tmp3,
- CONST_BITS+PASS1_BITS+3))
- and RANGE_MASK];
- outptr^[7] := range_limit^[ int(DESCALE(tmp10 - tmp3,
- CONST_BITS+PASS1_BITS+3))
- and RANGE_MASK];
- outptr^[1] := range_limit^[ int(DESCALE(tmp11 + tmp2,
- CONST_BITS+PASS1_BITS+3))
- and RANGE_MASK];
- outptr^[6] := range_limit^[ int(DESCALE(tmp11 - tmp2,
- CONST_BITS+PASS1_BITS+3))
- and RANGE_MASK];
- outptr^[2] := range_limit^[ int(DESCALE(tmp12 + tmp1,
- CONST_BITS+PASS1_BITS+3))
- and RANGE_MASK];
- outptr^[5] := range_limit^[ int(DESCALE(tmp12 - tmp1,
- CONST_BITS+PASS1_BITS+3))
- and RANGE_MASK];
- outptr^[3] := range_limit^[ int(DESCALE(tmp13 + tmp0,
- CONST_BITS+PASS1_BITS+3))
- and RANGE_MASK];
- outptr^[4] := range_limit^[ int(DESCALE(tmp13 - tmp0,
- CONST_BITS+PASS1_BITS+3))
- and RANGE_MASK];
-
- Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jidctred.pas b/packages/base/pasjpeg/jidctred.pas
deleted file mode 100644
index f7818d7d83..0000000000
--- a/packages/base/pasjpeg/jidctred.pas
+++ /dev/null
@@ -1,525 +0,0 @@
-Unit JIDctRed;
-
-
-{ This file contains inverse-DCT routines that produce reduced-size output:
- either 4x4, 2x2, or 1x1 pixels from an 8x8 DCT block.
-
- The implementation is based on the Loeffler, Ligtenberg and Moschytz (LL&M)
- algorithm used in jidctint.c. We simply replace each 8-to-8 1-D IDCT step
- with an 8-to-4 step that produces the four averages of two adjacent outputs
- (or an 8-to-2 step producing two averages of four outputs, for 2x2 output).
- These steps were derived by computing the corresponding values at the end
- of the normal LL&M code, then simplifying as much as possible.
-
- 1x1 is trivial: just take the DC coefficient divided by 8.
-
- See jidctint.c for additional comments. }
-
-
-{ Original : jidctred.c ; Copyright (C) 1994-1998, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jpeglib,
- jdct; { Private declarations for DCT subsystem }
-
-{ Perform dequantization and inverse DCT on one block of coefficients,
- producing a reduced-size 1x1 output block. }
-
-{GLOBAL}
-procedure jpeg_idct_1x1 (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-
-{ Perform dequantization and inverse DCT on one block of coefficients,
- producing a reduced-size 2x2 output block. }
-
-{GLOBAL}
-procedure jpeg_idct_2x2 (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-
-{ Perform dequantization and inverse DCT on one block of coefficients,
- producing a reduced-size 4x4 output block. }
-
-{GLOBAL}
-procedure jpeg_idct_4x4 (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-
-implementation
-
-{ This module is specialized to the case DCTSIZE = 8. }
-
-{$ifndef DCTSIZE_IS_8}
- Sorry, this code only copes with 8x8 DCTs. { deliberate syntax err }
-{$endif}
-
-
-{ Scaling is the same as in jidctint.c. }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-const
- CONST_BITS = 13;
- PASS1_BITS = 2;
-{$else}
-const
- CONST_BITS = 13;
- PASS1_BITS = 1; { lose a little precision to avoid overflow }
-{$endif}
-
-const
- FIX_0_211164243 = INT32(Round((INT32(1) shl CONST_BITS) * 0.211164243)); {1730}
- FIX_0_509795579 = INT32(Round((INT32(1) shl CONST_BITS) * 0.509795579)); {4176}
- FIX_0_601344887 = INT32(Round((INT32(1) shl CONST_BITS) * 0.601344887)); {4926}
- FIX_0_720959822 = INT32(Round((INT32(1) shl CONST_BITS) * 0.720959822)); {5906}
- FIX_0_765366865 = INT32(Round((INT32(1) shl CONST_BITS) * 0.765366865)); {6270}
- FIX_0_850430095 = INT32(Round((INT32(1) shl CONST_BITS) * 0.850430095)); {6967}
- FIX_0_899976223 = INT32(Round((INT32(1) shl CONST_BITS) * 0.899976223)); {7373}
- FIX_1_061594337 = INT32(Round((INT32(1) shl CONST_BITS) * 1.061594337)); {8697}
- FIX_1_272758580 = INT32(Round((INT32(1) shl CONST_BITS) * 1.272758580)); {10426}
- FIX_1_451774981 = INT32(Round((INT32(1) shl CONST_BITS) * 1.451774981)); {11893}
- FIX_1_847759065 = INT32(Round((INT32(1) shl CONST_BITS) * 1.847759065)); {15137}
- FIX_2_172734803 = INT32(Round((INT32(1) shl CONST_BITS) * 2.172734803)); {17799}
- FIX_2_562915447 = INT32(Round((INT32(1) shl CONST_BITS) * 2.562915447)); {20995}
- FIX_3_624509785 = INT32(Round((INT32(1) shl CONST_BITS) * 3.624509785)); {29692}
-
-
-{ Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
- For 8-bit samples with the recommended scaling, all the variable
- and constant values involved are no more than 16 bits wide, so a
- 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
- For 12-bit samples, a full 32-bit multiplication will be needed. }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-
- {function Multiply(X, Y: Integer): integer; assembler;
- asm
- mov ax, X
- imul Y
- mov al, ah
- mov ah, dl
- end;}
-
- {MULTIPLY16C16(var,const)}
- function Multiply(X, Y: Integer): INT32;
- begin
- Multiply := X*INT32(Y);
- end;
-
-
-{$else}
- function Multiply(X, Y: INT32): INT32;
- begin
- Multiply := X*Y;
- end;
-{$endif}
-
-
-{ Dequantize a coefficient by multiplying it by the multiplier-table
- entry; produce an int result. In this module, both inputs and result
- are 16 bits or less, so either int or short multiply will work. }
-
-function DEQUANTIZE(coef,quantval : int) : int;
-begin
- Dequantize := ( ISLOW_MULT_TYPE(coef) * quantval);
-end;
-
-
-{ Descale and correctly round an INT32 value that's scaled by N bits.
- We assume RIGHT_SHIFT rounds towards minus infinity, so adding
- the fudge factor is correct for either sign of X. }
-
-function DESCALE(x : INT32; n : int) : INT32;
-var
- shift_temp : INT32;
-begin
-{$ifdef RIGHT_SHIFT_IS_UNSIGNED}
- shift_temp := x + (INT32(1) shl (n-1));
- if shift_temp < 0 then
- Descale := (shift_temp shr n) or ((not INT32(0)) shl (32-n))
- else
- Descale := (shift_temp shr n);
-{$else}
- Descale := (x + (INT32(1) shl (n-1)) shr n;
-{$endif}
-end;
-
-{ Perform dequantization and inverse DCT on one block of coefficients,
- producing a reduced-size 4x4 output block. }
-
-{GLOBAL}
-procedure jpeg_idct_4x4 (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-type
- PWorkspace = ^TWorkspace;
- TWorkspace = array[0..(DCTSIZE*4)-1] of int; { buffers data between passes }
-var
- tmp0, tmp2, tmp10, tmp12 : INT32;
- z1, z2, z3, z4 : INT32;
- inptr : JCOEFPTR;
- quantptr : ISLOW_MULT_TYPE_FIELD_PTR;
- wsptr : PWorkspace;
- outptr : JSAMPROW;
- range_limit : JSAMPROW;
- ctr : int;
- workspace : TWorkspace; { buffers data between passes }
- {SHIFT_TEMPS}
-var
- dcval : int;
-var
- dcval_ : JSAMPLE;
-begin
-{ Each IDCT routine is responsible for range-limiting its results and
- converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
- be quite far out of range if the input data is corrupt, so a bulletproof
- range-limiting step is required. We use a mask-and-table-lookup method
- to do the combined operations quickly. See the comments with
- prepare_range_limit_table (in jdmaster.c) for more info. }
-
- range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));
-
- { Pass 1: process columns from input, store into work array. }
-
- inptr := coef_block;
- quantptr := ISLOW_MULT_TYPE_FIELD_PTR (compptr^.dct_table);
- wsptr := @workspace;
- for ctr := DCTSIZE downto 1 do
- begin
- { Don't bother to process column 4, because second pass won't use it }
- if (ctr = DCTSIZE-4) then
- begin
- Inc(JCOEF_PTR(inptr));
- Inc(ISLOW_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
-
- continue;
- end;
- if (inptr^[DCTSIZE*1]=0) and (inptr^[DCTSIZE*2]=0) and (inptr^[DCTSIZE*3]=0) and
- (inptr^[DCTSIZE*5]=0) and (inptr^[DCTSIZE*6]=0) and (inptr^[DCTSIZE*7]=0) then
- begin
- { AC terms all zero; we need not examine term 4 for 4x4 output }
- dcval := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*0]) *
- quantptr^[DCTSIZE*0]) shl PASS1_BITS;
-
- wsptr^[DCTSIZE*0] := dcval;
- wsptr^[DCTSIZE*1] := dcval;
- wsptr^[DCTSIZE*2] := dcval;
- wsptr^[DCTSIZE*3] := dcval;
-
- Inc(JCOEF_PTR(inptr));
- Inc(ISLOW_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
-
- continue;
- end;
-
- { Even part }
-
- tmp0 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*0]) * quantptr^[DCTSIZE*0]);
-
- tmp0 := tmp0 shl (CONST_BITS+1);
-
- z2 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*2]) * quantptr^[DCTSIZE*2]);
- z3 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*6]) * quantptr^[DCTSIZE*6]);
-
- tmp2 := MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
-
- tmp10 := tmp0 + tmp2;
- tmp12 := tmp0 - tmp2;
-
- { Odd part }
-
- z1 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*7]) * quantptr^[DCTSIZE*7];
- z2 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*5]) * quantptr^[DCTSIZE*5];
- z3 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*3]) * quantptr^[DCTSIZE*3];
- z4 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*1]) * quantptr^[DCTSIZE*1];
-
- tmp0 := MULTIPLY(z1, - FIX_0_211164243) { sqrt(2) * (c3-c1) }
- + MULTIPLY(z2, FIX_1_451774981) { sqrt(2) * (c3+c7) }
- + MULTIPLY(z3, - FIX_2_172734803) { sqrt(2) * (-c1-c5) }
- + MULTIPLY(z4, FIX_1_061594337); { sqrt(2) * (c5+c7) }
-
- tmp2 := MULTIPLY(z1, - FIX_0_509795579) { sqrt(2) * (c7-c5) }
- + MULTIPLY(z2, - FIX_0_601344887) { sqrt(2) * (c5-c1) }
- + MULTIPLY(z3, FIX_0_899976223) { sqrt(2) * (c3-c7) }
- + MULTIPLY(z4, FIX_2_562915447); { sqrt(2) * (c1+c3) }
-
- { Final output stage }
-
- wsptr^[DCTSIZE*0] := int(DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1));
- wsptr^[DCTSIZE*3] := int(DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1));
- wsptr^[DCTSIZE*1] := int(DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1));
- wsptr^[DCTSIZE*2] := int(DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1));
-
- Inc(JCOEF_PTR(inptr));
- Inc(ISLOW_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
- end;
-
- { Pass 2: process 4 rows from work array, store into output array. }
-
- wsptr := @workspace;
- for ctr := 0 to pred(4) do
- begin
- outptr := JSAMPROW(@ output_buf^[ctr]^[output_col]);
- { It's not clear whether a zero row test is worthwhile here ... }
-
-{$ifndef NO_ZERO_ROW_TEST}
- if (wsptr^[1]=0) and (wsptr^[2]=0) and (wsptr^[3]=0) and
- (wsptr^[5]=0) and (wsptr^[6]=0) and (wsptr^[7]=0) then
- begin
- { AC terms all zero }
- dcval_ := range_limit^[int(DESCALE(INT32(wsptr^[0]), PASS1_BITS+3))
- and RANGE_MASK];
-
- outptr^[0] := dcval_;
- outptr^[1] := dcval_;
- outptr^[2] := dcval_;
- outptr^[3] := dcval_;
-
- Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- continue;
- end;
-{$endif}
-
- { Even part }
-
- tmp0 := (INT32(wsptr^[0])) shl (CONST_BITS+1);
-
- tmp2 := MULTIPLY(INT32(wsptr^[2]), FIX_1_847759065)
- + MULTIPLY(INT32(wsptr^[6]), - FIX_0_765366865);
-
- tmp10 := tmp0 + tmp2;
- tmp12 := tmp0 - tmp2;
-
- { Odd part }
-
- z1 := INT32(wsptr^[7]);
- z2 := INT32(wsptr^[5]);
- z3 := INT32(wsptr^[3]);
- z4 := INT32(wsptr^[1]);
-
- tmp0 := MULTIPLY(z1, - FIX_0_211164243) { sqrt(2) * (c3-c1) }
- + MULTIPLY(z2, FIX_1_451774981) { sqrt(2) * (c3+c7) }
- + MULTIPLY(z3, - FIX_2_172734803) { sqrt(2) * (-c1-c5) }
- + MULTIPLY(z4, FIX_1_061594337); { sqrt(2) * (c5+c7) }
-
- tmp2 := MULTIPLY(z1, - FIX_0_509795579) { sqrt(2) * (c7-c5) }
- + MULTIPLY(z2, - FIX_0_601344887) { sqrt(2) * (c5-c1) }
- + MULTIPLY(z3, FIX_0_899976223) { sqrt(2) * (c3-c7) }
- + MULTIPLY(z4, FIX_2_562915447); { sqrt(2) * (c1+c3) }
-
- { Final output stage }
-
- outptr^[0] := range_limit^[ int(DESCALE(tmp10 + tmp2,
- CONST_BITS+PASS1_BITS+3+1))
- and RANGE_MASK];
- outptr^[3] := range_limit^[ int(DESCALE(tmp10 - tmp2,
- CONST_BITS+PASS1_BITS+3+1))
- and RANGE_MASK];
- outptr^[1] := range_limit^[ int(DESCALE(tmp12 + tmp0,
- CONST_BITS+PASS1_BITS+3+1))
- and RANGE_MASK];
- outptr^[2] := range_limit^[ int(DESCALE(tmp12 - tmp0,
- CONST_BITS+PASS1_BITS+3+1))
- and RANGE_MASK];
-
- Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- end;
-end;
-
-
-{ Perform dequantization and inverse DCT on one block of coefficients,
- producing a reduced-size 2x2 output block. }
-
-{GLOBAL}
-procedure jpeg_idct_2x2 (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-type
- PWorkspace = ^TWorkspace;
- TWorkspace = array[0..(DCTSIZE*2)-1] of int; { buffers data between passes }
-var
- tmp0, tmp10, z1 : INT32;
- inptr : JCOEFPTR;
- quantptr : ISLOW_MULT_TYPE_FIELD_PTR;
- wsptr : PWorkspace;
- outptr : JSAMPROW;
- range_limit : JSAMPROW;
- ctr : int;
- workspace : TWorkspace; { buffers data between passes }
- {SHIFT_TEMPS}
-var
- dcval : int;
-var
- dcval_ : JSAMPLE;
-begin
-{ Each IDCT routine is responsible for range-limiting its results and
- converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
- be quite far out of range if the input data is corrupt, so a bulletproof
- range-limiting step is required. We use a mask-and-table-lookup method
- to do the combined operations quickly. See the comments with
- prepare_range_limit_table (in jdmaster.c) for more info. }
-
- range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));
- { Pass 1: process columns from input, store into work array. }
-
- inptr := coef_block;
- quantptr := ISLOW_MULT_TYPE_FIELD_PTR (compptr^.dct_table);
- wsptr := @workspace;
- for ctr := DCTSIZE downto 1 do
- begin
- { Don't bother to process columns 2,4,6 }
- if (ctr = DCTSIZE-2) or (ctr = DCTSIZE-4) or (ctr = DCTSIZE-6) then
- begin
- Inc(JCOEF_PTR(inptr));
- Inc(ISLOW_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
-
- continue;
- end;
- if (inptr^[DCTSIZE*1]=0) and (inptr^[DCTSIZE*3]=0) and
- (inptr^[DCTSIZE*5]=0) and (inptr^[DCTSIZE*7]=0) then
- begin
- { AC terms all zero; we need not examine terms 2,4,6 for 2x2 output }
- dcval := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*0]) *
- quantptr^[DCTSIZE*0]) shl PASS1_BITS;
-
- wsptr^[DCTSIZE*0] := dcval;
- wsptr^[DCTSIZE*1] := dcval;
-
- Inc(JCOEF_PTR(inptr));
- Inc(ISLOW_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
-
- continue;
- end;
-
- { Even part }
-
- z1 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*0]) * quantptr^[DCTSIZE*0]);
-
- tmp10 := z1 shl (CONST_BITS+2);
-
- { Odd part }
-
- z1 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*7]) * quantptr^[DCTSIZE*7]);
- tmp0 := MULTIPLY(z1, - FIX_0_720959822); { sqrt(2) * (c7-c5+c3-c1) }
- z1 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*5]) * quantptr^[DCTSIZE*5]);
- Inc(tmp0, MULTIPLY(z1, FIX_0_850430095)); { sqrt(2) * (-c1+c3+c5+c7) }
- z1 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*3]) * quantptr^[DCTSIZE*3]);
- Inc(tmp0, MULTIPLY(z1, - FIX_1_272758580)); { sqrt(2) * (-c1+c3-c5-c7) }
- z1 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*1]) * quantptr^[DCTSIZE*1]);
- Inc(tmp0, MULTIPLY(z1, FIX_3_624509785)); { sqrt(2) * (c1+c3+c5+c7) }
-
- { Final output stage }
-
- wsptr^[DCTSIZE*0] := int (DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2));
- wsptr^[DCTSIZE*1] := int (DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2));
-
- Inc(JCOEF_PTR(inptr));
- Inc(ISLOW_MULT_TYPE_PTR(quantptr));
- Inc(int_ptr(wsptr));
- end;
-
- { Pass 2: process 2 rows from work array, store into output array. }
-
- wsptr := @workspace;
- for ctr := 0 to pred(2) do
- begin
- outptr := JSAMPROW(@ output_buf^[ctr]^[output_col]);
- { It's not clear whether a zero row test is worthwhile here ... }
-
-{$ifndef NO_ZERO_ROW_TEST}
- if (wsptr^[1]=0) and (wsptr^[3]=0) and (wsptr^[5]=0) and (wsptr^[7]= 0) then
- begin
- { AC terms all zero }
- dcval_ := range_limit^[ int(DESCALE(INT32(wsptr^[0]), PASS1_BITS+3))
- and RANGE_MASK];
-
- outptr^[0] := dcval_;
- outptr^[1] := dcval_;
-
- Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- continue;
- end;
-{$endif}
-
- { Even part }
-
- tmp10 := (INT32 (wsptr^[0])) shl (CONST_BITS+2);
-
- { Odd part }
-
- tmp0 := MULTIPLY( INT32(wsptr^[7]), - FIX_0_720959822) { sqrt(2) * (c7-c5+c3-c1) }
- + MULTIPLY( INT32(wsptr^[5]), FIX_0_850430095) { sqrt(2) * (-c1+c3+c5+c7) }
- + MULTIPLY( INT32(wsptr^[3]), - FIX_1_272758580) { sqrt(2) * (-c1+c3-c5-c7) }
- + MULTIPLY( INT32(wsptr^[1]), FIX_3_624509785); { sqrt(2) * (c1+c3+c5+c7) }
-
- { Final output stage }
-
- outptr^[0] := range_limit^[ int(DESCALE(tmp10 + tmp0,
- CONST_BITS+PASS1_BITS+3+2))
- and RANGE_MASK];
- outptr^[1] := range_limit^[ int(DESCALE(tmp10 - tmp0,
- CONST_BITS+PASS1_BITS+3+2))
- and RANGE_MASK];
-
- Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
- end;
-end;
-
-
-{ Perform dequantization and inverse DCT on one block of coefficients,
- producing a reduced-size 1x1 output block. }
-
-{GLOBAL}
-procedure jpeg_idct_1x1 (cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY;
- output_col : JDIMENSION);
-var
- dcval : int;
- quantptr : ISLOW_MULT_TYPE_FIELD_PTR;
- range_limit : JSAMPROW;
- {SHIFT_TEMPS}
-begin
-{ Each IDCT routine is responsible for range-limiting its results and
- converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
- be quite far out of range if the input data is corrupt, so a bulletproof
- range-limiting step is required. We use a mask-and-table-lookup method
- to do the combined operations quickly. See the comments with
- prepare_range_limit_table (in jdmaster.c) for more info. }
-
- range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));
- { Pass 1: process columns from input, store into work array. }
-
- { We hardly need an inverse DCT routine for this: just take the
- average pixel value, which is one-eighth of the DC coefficient. }
-
- quantptr := ISLOW_MULT_TYPE_FIELD_PTR (compptr^.dct_table);
- dcval := (ISLOW_MULT_TYPE(coef_block^[0]) * quantptr^[0]);
- dcval := int (DESCALE( INT32(dcval), 3));
-
- output_buf^[0]^[output_col] := range_limit^[dcval and RANGE_MASK];
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jinclude.pas b/packages/base/pasjpeg/jinclude.pas
deleted file mode 100644
index fac33006bd..0000000000
--- a/packages/base/pasjpeg/jinclude.pas
+++ /dev/null
@@ -1,126 +0,0 @@
-Unit jinclude;
-
-{ This file exists to provide a single place to fix any problems with
- including the wrong system include files. (Common problems are taken
- care of by the standard jconfig symbols, but on really weird systems
- you may have to edit this file.)
-
- NOTE: this file is NOT intended to be included by applications using the
- JPEG library. Most applications need only include jpeglib.h. }
-
-{ Original: jinclude.h Copyright (C) 1991-1994, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-{ Include auto-config file to find out which system include files we need. }
-
-uses
-{$ifdef Delphi_Stream}
- classes,
-{$endif}
- jmorecfg;
-
-{ Nomssi:
- To write a dest/source manager that handle streams rather than files,
- you can edit the FILEptr definition and the JFREAD() and JFWRITE()
- functions in this unit, you don't need to change the default managers
- JDATASRC and JDATADST. }
-
-{$ifdef Delphi_Stream}
-type
- FILEptr = ^TStream;
-{$else}
- {$ifdef Delphi_Jpeg}
- type
- FILEptr = TCustomMemoryStream;
- {$else}
- type
- FILEptr = ^File;
- {$endif}
-{$endif}
-
-{ We need the NULL macro and size_t typedef.
- On an ANSI-conforming system it is sufficient to include <stddef.h>.
- Otherwise, we get them from <stdlib.h> or <stdio.h>; we may have to
- pull in <sys/types.h> as well.
- Note that the core JPEG library does not require <stdio.h>;
- only the default error handler and data source/destination modules do.
- But we must pull it in because of the references to FILE in jpeglib.h.
- You can remove those references if you want to compile without <stdio.h>.}
-
-
-
-{ We need memory copying and zeroing functions, plus strncpy().
- ANSI and System V implementations declare these in <string.h>.
- BSD doesn't have the mem() functions, but it does have bcopy()/bzero().
- Some systems may declare memset and memcpy in <memory.h>.
-
- NOTE: we assume the size parameters to these functions are of type size_t.
- Change the casts in these macros if not! }
-
-procedure MEMZERO(target : pointer; size : size_t);
-
-procedure MEMCOPY(dest, src : pointer; size : size_t);
-
-{function SIZEOF(object) : size_t;}
-
-function JFREAD(fp : FILEptr; buf : pointer; sizeofbuf : size_t) : size_t;
-
-function JFWRITE(fp : FILEptr; buf : pointer; sizeofbuf : size_t) : size_t;
-
-implementation
-
-procedure MEMZERO(target : pointer; size : size_t);
-begin
- FillChar(target^, size, 0);
-end;
-
-procedure MEMCOPY(dest, src : pointer; size : size_t);
-begin
- Move(src^, dest^, size);
-end;
-
-{ In ANSI C, and indeed any rational implementation, size_t is also the
- type returned by sizeof(). However, it seems there are some irrational
- implementations out there, in which sizeof() returns an int even though
- size_t is defined as long or unsigned long. To ensure consistent results
- we always use this SIZEOF() macro in place of using sizeof() directly. }
-
-
-{#define
- SIZEOF(object) (size_t(sizeof(object))}
-
-
-{ The modules that use fread() and fwrite() always invoke them through
- these macros. On some systems you may need to twiddle the argument casts.
- CAUTION: argument order is different from underlying functions! }
-
-
-function JFREAD(fp : FILEptr; buf : pointer; sizeofbuf : size_t) : size_t;
-var
- count : uint;
-begin
- {$ifdef Delphi_Stream}
- count := fp^.Read(buf^, sizeofbuf);
- {$else}
- blockread(fp^, buf^, sizeofbuf, count);
- {$endif}
- JFREAD := size_t(count);
-end;
-
-function JFWRITE(fp : FILEptr; buf : pointer; sizeofbuf : size_t) : size_t;
-var
- count : uint;
-begin
- {$ifdef Delphi_Stream}
- count := fp^.Write(buf^, sizeofbuf);
- {$else}
- blockwrite(fp^, buf^, sizeofbuf, count);
- {$endif}
- JFWRITE := size_t(count);
-end;
-
-
-end.
diff --git a/packages/base/pasjpeg/jmemdos.pas b/packages/base/pasjpeg/jmemdos.pas
deleted file mode 100644
index c56dad1982..0000000000
--- a/packages/base/pasjpeg/jmemdos.pas
+++ /dev/null
@@ -1,780 +0,0 @@
-Unit JmemDos;
-
-
-{ This file provides an MS-DOS-compatible implementation of the system-
- dependent portion of the JPEG memory manager. Temporary data can be
- stored in extended or expanded memory as well as in regular DOS files.
-
- If you use this file, you must be sure that NEED_FAR_POINTERS is defined
- if you compile in a small-data memory model; it should NOT be defined if
- you use a large-data memory model. This file is not recommended if you
- are using a flat-memory-space 386 environment such as DJGCC or Watcom C.
- Also, this code will NOT work if struct fields are aligned on greater than
- 2-byte boundaries.
-
- Based on code contributed by Ge' Weijers. }
-
-{ Original: jmemdos.c; Copyright (C) 1992-1996, Thomas G. Lane. }
-
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jpeglib;
-
-{ If you have both extended and expanded memory, you may want to change the
- order in which they are tried in jopen_backing_store. On a 286 machine
- expanded memory is usually faster, since extended memory access involves
- an expensive protected-mode-and-back switch. On 386 and better, extended
- memory is usually faster. As distributed, the code tries extended memory
- first (what? not everyone has a 386? :-).
-
- You can disable use of extended/expanded memory entirely by altering these
- definitions or overriding them from the Makefile (eg, -DEMS_SUPPORTED=0).}
-
-{GLOBAL}
-procedure jpeg_open_backing_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- total_bytes_needed : long);
-
-{ These routines take care of any system-dependent initialization and
- cleanup required. }
-
-{GLOBAL}
-function jpeg_mem_init (cinfo : j_common_ptr) : long;
-
-{GLOBAL}
-procedure jpeg_mem_term (cinfo : j_common_ptr);
-
-{ These two functions are used to allocate and release small chunks of
- memory. (Typically the total amount requested through jpeg_get_small is
- no more than 20K or so; this will be requested in chunks of a few K each.)
- Behavior should be the same as for the standard library functions malloc
- and free; in particular, jpeg_get_small must return NIL on failure.
- On most systems, these ARE malloc and free. jpeg_free_small is passed the
- size of the object being freed, just in case it's needed.
- On an 80x86 machine using small-data memory model, these manage near heap. }
-
-
-{ Near-memory allocation and freeing are controlled by the regular library
- routines malloc() and free(). }
-
-{GLOBAL}
-function jpeg_get_small (cinfo : j_common_ptr;
- sizeofobject : size_t) : pointer;
-
-{GLOBAL}
-{object is a reserved word in Borland Pascal }
-procedure jpeg_free_small (cinfo : j_common_ptr;
- an_object : pointer;
- sizeofobject : size_t);
-
-{ These two functions are used to allocate and release large chunks of
- memory (up to the total free space designated by jpeg_mem_available).
- The interface is the same as above, except that on an 80x86 machine,
- far pointers are used. On most other machines these are identical to
- the jpeg_get/free_small routines; but we keep them separate anyway,
- in case a different allocation strategy is desirable for large chunks. }
-
-
-{ "Large" objects are allocated in far memory, if possible }
-
-
-{GLOBAL}
-function jpeg_get_large (cinfo : j_common_ptr;
- sizeofobject : size_t) : voidp; {far}
-
-{GLOBAL}
-procedure jpeg_free_large (cinfo : j_common_ptr;
- {var?} an_object : voidp; {FAR}
- sizeofobject : size_t);
-
-{ This routine computes the total memory space available for allocation.
- It's impossible to do this in a portable way; our current solution is
- to make the user tell us (with a default value set at compile time).
- If you can actually get the available space, it's a good idea to subtract
- a slop factor of 5% or so. }
-
-{GLOBAL}
-function jpeg_mem_available (cinfo : j_common_ptr;
- min_bytes_needed : long;
- max_bytes_needed : long;
- already_allocated : long) : long;
-
-
-{ The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
- be requested in a single call to jpeg_get_large (and jpeg_get_small for that
- matter, but that case should never come into play). This macro is needed
- to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
- On those machines, we expect that jconfig.h will provide a proper value.
- On machines with 32-bit flat address spaces, any large constant may be used.
-
- NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
- size_t and will be a multiple of sizeof(align_type). }
-
-
-{$ifdef USE_MSDOS_MEMMGR} { Define this if you use jmemdos.c }
-const
- MAX_ALLOC_CHUNK = long(32752); {65520} { Maximum request to malloc() }
- { MAX_ALLOC_CHUNK should be less than 64K. }
-{$else}
-const
- MAX_ALLOC_CHUNK = long(1000000000);
-{$endif}
-
-implementation
-
-uses
- dos,
- jmemdosa,
- jdeferr,
- jerror;
-
-
-
-{ Selection of a file name for a temporary file.
- This is highly system-dependent, and you may want to customize it. }
-
-var
- next_file_num : int; { to distinguish among several temp files }
-
-{LOCAL}
-procedure select_file_name (var fname : TEMP_STRING);
-var
- env : string;
- suffix,
- prefix : TEMP_STRING;
- tfile : FILE;
- l : byte;
-begin
- { Keep generating file names till we find one that's not in use }
- while TRUE do
- begin
- { Get temp directory name from environment TMP or TEMP variable;
- if none, use "." }
- env := getenv('TMP');
- if (env = '') then
- begin
- env := getenv('TEMP');
- if (env = '') then { null string means "." }
- env := '.';
- end;
- prefix := env; { copy name to fname }
- { length(fname) > 0 !! }
- if (prefix[length(prefix)] <> '\')
- and (prefix[length(prefix)] <> '/') then
- prefix := prefix + '\'; { append backslash if not in env variable }
- { Append a suitable file name }
- Inc(next_file_num); { advance counter }
-
- Str(next_file_num, suffix);
- for l := Length(suffix)+1 to 3 do
- suffix := '0' + suffix;
- fname := prefix + 'JPG' + suffix + '.TMP';
- { Probe to see if file name is already in use }
- system.assign(tfile, fname);
- {$ifdef IoCheck} {$I-} {$endif}
- system.reset(tfile, 1);
- {$ifdef IoCheck} {$I+} {$endif}
- if (IOresult <> 0) then
- begin
- fname := fname + #0;
- break;
- end;
- system.close(tfile); { oops, it's there; close tfile & try again }
- end;
-end;
-
-{ These two functions are used to allocate and release small chunks of
- memory. (Typically the total amount requested through jpeg_get_small is
- no more than 20K or so; this will be requested in chunks of a few K each.)
- Behavior should be the same as for the standard library functions malloc
- and free; in particular, jpeg_get_small must return NIL on failure.
- On most systems, these ARE malloc and free. jpeg_free_small is passed the
- size of the object being freed, just in case it's needed.
- On an 80x86 machine using small-data memory model, these manage near heap. }
-
-
-{ Near-memory allocation and freeing are controlled by the regular library
- routines malloc() and free(). }
-
-{GLOBAL}
-function jpeg_get_small (cinfo : j_common_ptr;
- sizeofobject : size_t) : pointer;
-var
- p : pointer;
-begin
- getmem(p, sizeofobject);
- jpeg_get_small := p;
-end;
-
-{GLOBAL}
-{object is a reserved word in Borland Pascal }
-procedure jpeg_free_small (cinfo : j_common_ptr;
- an_object : pointer;
- sizeofobject : size_t);
-begin
- freemem(an_object, sizeofobject);
-end;
-
-{ These two functions are used to allocate and release large chunks of
- memory (up to the total free space designated by jpeg_mem_available).
- The interface is the same as above, except that on an 80x86 machine,
- far pointers are used. On most other machines these are identical to
- the jpeg_get/free_small routines; but we keep them separate anyway,
- in case a different allocation strategy is desirable for large chunks. }
-
-
-{GLOBAL}
-function jpeg_get_large (cinfo : j_common_ptr;
- sizeofobject : size_t) : voidp; {far}
-var
- p : voidp; {FAR}
-begin
- {far_malloc;}
- getmem(p, sizeofobject);
- jpeg_get_large := p;
-end;
-
-{GLOBAL}
-procedure jpeg_free_large (cinfo : j_common_ptr;
- {var?} an_object : voidp; {FAR}
- sizeofobject : size_t);
-begin
- {far_free(an_object);}
- FreeMem(an_object, sizeofobject);
-end;
-
-{ This routine computes the total space still available for allocation by
- jpeg_get_large. If more space than this is needed, backing store will be
- used. NOTE: any memory already allocated must not be counted.
-
- There is a minimum space requirement, corresponding to the minimum
- feasible buffer sizes; jmemmgr.c will request that much space even if
- jpeg_mem_available returns zero. The maximum space needed, enough to hold
- all working storage in memory, is also passed in case it is useful.
- Finally, the total space already allocated is passed. If no better
- method is available, cinfo->mem->max_memory_to_use - already_allocated
- is often a suitable calculation.
-
- It is OK for jpeg_mem_available to underestimate the space available
- (that'll just lead to more backing-store access than is really necessary).
- However, an overestimate will lead to failure. Hence it's wise to subtract
- a slop factor from the true available space. 5% should be enough.
-
- On machines with lots of virtual memory, any large constant may be returned.
- Conversely, zero may be returned to always use the minimum amount of memory.}
-
-
-
-{ This routine computes the total memory space available for allocation.
- It's impossible to do this in a portable way; our current solution is
- to make the user tell us (with a default value set at compile time).
- If you can actually get the available space, it's a good idea to subtract
- a slop factor of 5% or so. }
-
-const
- DEFAULT_MAX_MEM = long(300000); { for total usage about 450K }
-
-{GLOBAL}
-function jpeg_mem_available (cinfo : j_common_ptr;
- min_bytes_needed : long;
- max_bytes_needed : long;
- already_allocated : long) : long;
-begin
- {jpeg_mem_available := cinfo^.mem^.max_memory_to_use - already_allocated;}
- jpeg_mem_available := MaxAvail*95 div 100; { 95% }
-
- { Nomssi: limit the available memory for test purpose }
- {jpeg_mem_available := 30000;}
-end;
-
-
-{ Backing store (temporary file) management.
- Backing store objects are only used when the value returned by
- jpeg_mem_available is less than the total space needed. You can dispense
- with these routines if you have plenty of virtual memory; see jmemnobs.c. }
-
-
-{ For MS-DOS we support three types of backing storage:
- 1. Conventional DOS files. We access these by direct DOS calls rather
- than via the stdio package. This provides a bit better performance,
- but the real reason is that the buffers to be read or written are FAR.
- The stdio library for small-data memory models can't cope with that.
- 2. Extended memory, accessed per the XMS V2.0 specification.
- 3. Expanded memory, accessed per the LIM/EMS 4.0 specification.
- You'll need copies of those specs to make sense of the related code.
- The specs are available by Internet FTP from the SIMTEL archives
- (oak.oakland.edu and its various mirror sites). See files
- pub/msdos/microsoft/xms20.arc and pub/msdos/info/limems41.zip. }
-
-
-
-{ Access methods for a DOS file. }
-
-
-{METHODDEF}
-procedure read_file_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- buffer_address : pointer; {FAR}
- file_offset : long;
- byte_count : long); far;
-begin
- if jdos_seek(info^.handle.file_handle, file_offset) <> 0 then
- ERREXIT(cinfo, JERR_TFILE_SEEK);
- { Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. }
- if (byte_count > long(65535)) then { safety check }
- ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
- if jdos_read(info^.handle.file_handle, buffer_address,
- ushort(byte_count)) <> 0 then
- ERREXIT(cinfo, JERR_TFILE_READ);
-end;
-
-
-{METHODDEF}
-procedure write_file_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- buffer_address : pointer; {FAR}
- file_offset : long;
- byte_count : long); far;
-begin
- if (jdos_seek(info^.handle.file_handle, file_offset)) <> 0 then
- ERREXIT(cinfo, JERR_TFILE_SEEK);
- { Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. }
- if (byte_count > long(65535)) then { safety check }
- ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
- if jdos_write(info^.handle.file_handle, buffer_address,
- ushort(byte_count)) <> 0 then
- ERREXIT(cinfo, JERR_TFILE_WRITE);
-end;
-
-
-{METHODDEF}
-procedure close_file_store (cinfo : j_common_ptr;
- info : backing_store_ptr); far;
-var
- f : FILE;
-begin
- jdos_close(info^.handle.file_handle); { close the file }
-
- system.assign(f, info^.temp_name);
- system.erase(f); { delete the file }
-{ If your system doesn't have remove(), try unlink() instead.
- remove() is the ANSI-standard name for this function, but
- unlink() was more common in pre-ANSI systems. }
-
- TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info^.temp_name);
-end;
-
-
-{LOCAL}
-function open_file_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- total_bytes_needed : long): boolean; far;
-var
- handle : short;
-begin
- select_file_name(info^.temp_name);
- if jdos_open(handle, info^.temp_name[1]) <> 0 then
- begin
- { might as well exit since jpeg_open_backing_store will fail anyway }
- ERREXITS(cinfo, JERR_TFILE_CREATE, info^.temp_name);
- open_file_store := FALSE;
- exit;
- end;
- info^.handle.file_handle := handle;
- info^.read_backing_store := read_file_store;
- info^.write_backing_store := write_file_store;
- info^.close_backing_store := close_file_store;
- TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info^.temp_name);
- open_file_store := TRUE; { succeeded }
-end;
-
-
-{ Access methods for extended memory. }
-
-{$ifdef XMS_SUPPORTED}
-
-var
- xms_driver : XMSDRIVER; { saved address of XMS driver }
-
-type
- XMSPTR = record { either long offset or real-mode pointer }
- case byte of
- 0:(offset : long);
- 1:(ptr : pointer {FAR});
- end;
-
-type
- XMSspec = record { XMS move specification structure }
- length : long;
- src_handle : XMSH;
- src : XMSPTR;
- dst_handle : XMSH;
- dst : XMSPTR;
- end;
-type
- TByteArray = Array[0..MAX_ALLOC_CHUNK-1] of byte;
-
-{METHODDEF}
-procedure read_xms_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- buffer_address : pointer; {FAR}
- file_offset : long;
- byte_count : long); far;
-var
- ctx : XMScontext;
- spec : XMSspec;
- endbuffer : packed array[0..1] of byte;
-begin
- { The XMS driver can't cope with an odd length, so handle the last byte
- specially if byte_count is odd. We don't expect this to be common. }
-
-
- spec.length := byte_count and (not long(1));
- spec.src_handle := info^.handle.xms_handle;
- spec.src.offset := file_offset;
- spec.dst_handle := 0;
- spec.dst.ptr := buffer_address;
-
- ctx.ds_si := addr(spec);
- ctx.ax := $0b00; { EMB move }
- jxms_calldriver(xms_driver, ctx);
- if (ctx.ax <> 1) then
- ERREXIT(cinfo, JERR_XMS_READ);
-
- if odd(byte_count) then
- begin
- read_xms_store(cinfo, info, pointer(@endbuffer) {FAR},
- file_offset + byte_count - long(1), long(2));
- TByteArray(buffer_address^)[byte_count - long(1)] := endbuffer[0];
- end;
-end;
-
-
-{METHODDEF}
-procedure write_xms_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- buffer_address : pointer; {FAR}
- file_offset : long;
- byte_count : long); far;
-var
- ctx : XMScontext;
- spec : XMSspec;
- endbuffer : packed array[0..1] of byte;
-begin
- { The XMS driver can't cope with an odd length, so handle the last byte
- specially if byte_count is odd. We don't expect this to be common. }
-
- spec.length := byte_count and (not long(1));
- spec.src_handle := 0;
- spec.src.ptr := buffer_address;
- spec.dst_handle := info^.handle.xms_handle;
- spec.dst.offset := file_offset;
-
- ctx.ds_si := addr(spec);
- ctx.ax := $0b00; { EMB move }
- jxms_calldriver(xms_driver, ctx);
- if (ctx.ax <> 1) then
- ERREXIT(cinfo, JERR_XMS_WRITE);
-
- if odd(byte_count) then
- begin
- read_xms_store(cinfo, info, pointer(@endbuffer) {FAR},
- file_offset + byte_count - long(1), long(2));
- endbuffer[0] := TByteArray(buffer_address^)[byte_count - long(1)];
- write_xms_store(cinfo, info, pointer(@endbuffer) {FAR},
- file_offset + byte_count - long(1), long(2));
- end;
-end;
-
-
-{METHODDEF}
-procedure close_xms_store (cinfo : j_common_ptr;
- info : backing_store_ptr); far;
-var
- ctx : XMScontext;
-begin
- ctx.dx := info^.handle.xms_handle;
- ctx.ax := $0a00;
- jxms_calldriver(xms_driver, ctx);
- TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info^.handle.xms_handle);
- { we ignore any error return from the driver }
-end;
-
-
-{LOCAL}
-function open_xms_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- total_bytes_needed : long) : boolean;
-var
- ctx : XMScontext;
-begin
- { Get address of XMS driver }
- jxms_getdriver(xms_driver);
- if (xms_driver = NIL) then
- begin
- open_xms_store := FALSE; { no driver to be had }
- exit;
- end;
-
- { Get version number, must be >= 2.00 }
- ctx.ax := $0000;
- jxms_calldriver(xms_driver, ctx);
- if (ctx.ax < ushort($0200)) then
- begin
- open_xms_store := FALSE;
- exit;
- end;
-
- { Try to get space (expressed in kilobytes) }
- ctx.dx := ushort ((total_bytes_needed + long(1023)) shr 10);
- ctx.ax := $0900;
- jxms_calldriver(xms_driver, ctx);
- if (ctx.ax <> 1) then
- begin
- open_xms_store := FALSE;
- exit;
- end;
-
- { Succeeded, save the handle and away we go }
- info^.handle.xms_handle := ctx.dx;
- info^.read_backing_store := read_xms_store;
- info^.write_backing_store := write_xms_store;
- info^.close_backing_store := close_xms_store;
- TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx);
- open_xms_store := TRUE; { succeeded }
-end;
-
-{$endif} { XMS_SUPPORTED }
-
-
-{ Access methods for expanded memory. }
-
-{$ifdef EMS_SUPPORTED}
-
-{ The EMS move specification structure requires word and long fields aligned
- at odd byte boundaries. Some compilers will align struct fields at even
- byte boundaries. While it's usually possible to force byte alignment,
- that causes an overall performance penalty and may pose problems in merging
- JPEG into a larger application. Instead we accept some rather dirty code
- here. Note this code would fail if the hardware did not allow odd-byte
- word & long accesses, but all 80x86 CPUs do. }
-
-
-type
- EMSPTR = pointer; {FAR}
-
-
-{ types for accessing misaligned fields }
-type
- EMSAddrStruct = packed record {Size }
- MemType : byte; { emsConventional, emsExpanded } { 1 }
- Handle : word; { TEMSHandle; } { 2 }
- case integer of {union}
- 0 : (Offs : word; { 2 }
- Page : word); { 2 }
- 1 : (Ptr : pointer); {or 4 }
- end;
- { EMS move specification structure }
- EMSspec = packed record
- length : longint; { 4 }
- src : EMSAddrStruct; { 7 }
- dst : EMSAddrStruct; { 7 }
- end;
-
-
-const
- EMSPAGESIZE = long(16384); { gospel, see the EMS specs }
-
-
-{METHODDEF}
-procedure read_ems_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- buffer_address : pointer; {FAR}
- file_offset : long;
- byte_count : long); far;
-var
- ctx : EMScontext;
- spec : EMSspec;
-begin
- spec.length := byte_count;
- spec.src.memtype := 1;
- spec.src.handle := info^.handle.ems_handle;
- spec.src.page := ushort (file_offset div EMSPAGESIZE);
- spec.src.offs := ushort (file_offset mod EMSPAGESIZE);
- spec.dst.memtype := 0;
- spec.dst.handle := 0;
- spec.dst.ptr := buffer_address;
-
- ctx.ds_si := addr(spec);
- ctx.ax := $5700; { move memory region }
- jems_calldriver(ctx);
- if (hi(ctx.ax) <> 0) then
- ERREXIT(cinfo, JERR_EMS_READ);
-end;
-
-
-{METHODDEF}
-procedure write_ems_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- buffer_address : pointer; {FAR}
- file_offset : long;
- byte_count : long); far;
-var
- ctx : EMScontext;
- spec : EMSspec;
-begin
- spec.length := byte_count;
- spec.src.memtype := 0;
- spec.src.handle := 0;
- spec.src.ptr := buffer_address;
- spec.dst.memtype := 1;
- spec.dst.handle := info^.handle.ems_handle;
- spec.dst.page := ushort (file_offset div EMSPAGESIZE);
- spec.dst.offs := ushort (file_offset mod EMSPAGESIZE);
-
- ctx.ds_si := addr(spec);
- ctx.ax := $5700; { move memory region }
- jems_calldriver(ctx);
- if (hi(ctx.ax) <> 0) then
- ERREXIT(cinfo, JERR_EMS_WRITE);
-end;
-
-
-{METHODDEF}
-procedure close_ems_store (cinfo : j_common_ptr;
- info : backing_store_ptr); far;
-var
- ctx : EMScontext;
-begin
- ctx.ax := $4500;
- ctx.dx := info^.handle.ems_handle;
- jems_calldriver(ctx);
- TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info^.handle.ems_handle);
- { we ignore any error return from the driver }
-end;
-
-
-{LOCAL}
-function open_ems_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- total_bytes_needed : long) : boolean;
-var
- ctx : EMScontext;
-begin
- { Is EMS driver there? }
- if (jems_available = 0) then
- begin
- open_ems_store := FALSE;
- exit;
- end;
-
- { Get status, make sure EMS is OK }
- ctx.ax := $4000;
- jems_calldriver(ctx);
- if (hi(ctx.ax) <> 0) then
- begin
- open_ems_store := FALSE;
- exit;
- end;
-
- { Get version, must be >= 4.0 }
- ctx.ax := $4600;
- jems_calldriver(ctx);
- if (hi(ctx.ax) <> 0) or (lo(ctx.ax) < $40) then
- begin
- open_ems_store := FALSE;
- exit;
- end;
-
- { Try to allocate requested space }
- ctx.ax := $4300;
- ctx.bx := ushort ((total_bytes_needed +
- EMSPAGESIZE-long(1)) div EMSPAGESIZE);
- jems_calldriver(ctx);
- if (hi(ctx.ax) <> 0) then
- begin
- open_ems_store := FALSE;
- exit;
- end;
-
- { Succeeded, save the handle and away we go }
- info^.handle.ems_handle := ctx.dx;
- info^.read_backing_store := read_ems_store;
- info^.write_backing_store := write_ems_store;
- info^.close_backing_store := close_ems_store;
- TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx);
- open_ems_store := TRUE; { succeeded }
-end;
-
-{$endif} { EMS_SUPPORTED }
-
-{ Initial opening of a backing-store object. This must fill in the
- read/write/close pointers in the object. The read/write routines
- may take an error exit if the specified maximum file size is exceeded.
- (If jpeg_mem_available always returns a large value, this routine can
- just take an error exit.) }
-
-
-
-
-{ Initial opening of a backing-store object. }
-
-{GLOBAL}
-procedure jpeg_open_backing_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- total_bytes_needed : long);
-begin
- { Try extended memory, then expanded memory, then regular file. }
-{$ifdef XMS_SUPPORTED}
- if (open_xms_store(cinfo, info, total_bytes_needed)) then
- exit;
-{$endif}
-{$ifdef EMS_SUPPORTED}
- if (open_ems_store(cinfo, info, total_bytes_needed)) then
- exit;
-{$endif}
- if (open_file_store(cinfo, info, total_bytes_needed)) then
- exit;
- ERREXITS(cinfo, JERR_TFILE_CREATE, '');
-end;
-
-{ These routines take care of any system-dependent initialization and
- cleanup required. jpeg_mem_init will be called before anything is
- allocated (and, therefore, nothing in cinfo is of use except the error
- manager pointer). It should return a suitable default value for
- max_memory_to_use; this may subsequently be overridden by the surrounding
- application. (Note that max_memory_to_use is only important if
- jpeg_mem_available chooses to consult it ... no one else will.)
- jpeg_mem_term may assume that all requested memory has been freed and that
- all opened backing-store objects have been closed. }
-
-
-{ These routines take care of any system-dependent initialization and
- cleanup required. }
-
-
-{GLOBAL}
-function jpeg_mem_init (cinfo : j_common_ptr) : long;
-begin
- next_file_num := 0; { initialize temp file name generator }
- jpeg_mem_init := DEFAULT_MAX_MEM; { default for max_memory_to_use }
-end;
-
-{GLOBAL}
-procedure jpeg_mem_term (cinfo : j_common_ptr);
-begin
- { Microsoft C, at least in v6.00A, will not successfully reclaim freed
- blocks of size > 32Kbytes unless we give it a kick in the rear,
- like so: }
-
-{$ifdef NEED_FHEAPMIN}
- _fheapmin();
-{$endif}
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jmemdosa.pas b/packages/base/pasjpeg/jmemdosa.pas
deleted file mode 100644
index 593d409cc3..0000000000
--- a/packages/base/pasjpeg/jmemdosa.pas
+++ /dev/null
@@ -1,365 +0,0 @@
-Unit jmemdosa;
-
-{$G+} {enable 286/287 instructions }
-
-{ Original: jmemdosa.asm ; Copyright (C) 1992, Thomas G. Lane.
- Based on code contributed by Ge' Weijers. }
-
-{ This file contains low-level interface routines to support the MS-DOS
- backing store manager (jmemdos.c). Routines are provided to access disk
- files through direct DOS calls, and to access XMS and EMS drivers. }
-
-interface
-
-uses
- jmorecfg;
-
-type
- XMSDRIVER = pointer; {far} { actually a pointer to code }
-type
- XMScontext = packed record { registers for calling XMS driver }
- ax, dx, bx : ushort;
- ds_si : pointer; {far}
- end;
-type
- EMScontext = packed record { registers for calling EMS driver }
- ax, dx, bx : ushort;
- ds_si : pointer; {far}
- end;
-{ offset is a reserved word in BASM }
-
-function jdos_open (var handle : short {far}; const filename {: PChar}) : short;
-
-function jdos_close (handle : short) : short;
-
-function jdos_seek (handle : short; offs : long) : short;
-
-function jdos_read (handle : short; buffer : pointer; {FAR}
- count : ushort) : short;
-function jdos_write (handle : short; buffer : pointer; {FAR}
- count : ushort) : short;
-
-procedure jxms_getdriver (var driver : XMSDRIVER);
-
-procedure jxms_calldriver (driver : XMSDRIVER;
- var ctx : XMScontext);
-function jems_available : short;
-
-procedure jems_calldriver (var ctx : EMScontext);
-
-
-implementation
-
-
-function jdos_open (var handle : short {far};
- const filename {: PChar}) : short; assembler;
-{ Create and open a temporary file }
-label
- open_err;
-asm
- push si { save all registers for safety }
- push di
- push bx
- push cx
- push dx
- push es
- push ds
- mov cx,0 { normal file attributes }
- lds dx, filename { get filename pointer }
- mov ah,3ch { create file }
- int 21h
- jc open_err { if failed, return error code }
- lds bx, handle { get handle pointer }
- mov word ptr [bx],ax { save the handle }
- xor ax,ax { return zero for OK }
-open_err:
- pop ds { restore registers and exit }
- pop es
- pop dx
- pop cx
- pop bx
- pop di
- pop si
-end; { jdos_open }
-
-
-function jdos_close (handle : short) : short; assembler;
-{ Close the file handle }
-label
- close_err;
-asm
- push si { save all registers for safety }
- push di
- push bx
- push cx
- push dx
- push es
- push ds
- mov bx, handle { file handle }
- mov ah,3eh { close file }
- int 21h
- jc close_err { if failed, return error code }
- xor ax,ax { return zero for OK }
-close_err:
- pop ds { restore registers and exit }
- pop es
- pop dx
- pop cx
- pop bx
- pop di
- pop si
-end; { jdos_close }
-
-
-
-function jdos_seek (handle : short; offs : long) : short; assembler;
-{ Set file position }
-label
- seek_err;
-asm
- push si { save all registers for safety }
- push di
- push bx
- push cx
- push dx
- push es
- push ds
- mov bx, handle { file handle }
- mov dx, offs.word { LS offset }
- mov cx, offs.word[2] { MS offset }
- mov ax,4200h { absolute seek }
- int 21h
- jc seek_err { if failed, return error code }
- xor ax,ax { return zero for OK }
-seek_err:
- pop ds { restore registers and exit }
- pop es
- pop dx
- pop cx
- pop bx
- pop di
- pop si
-end; { jdos_seek }
-
-
-function jdos_read (handle : short; buffer : pointer; {FAR}
- count : ushort) : short; assembler;
-{ Read from file }
-label
- read_ok, read_err;
-asm
- push si { save all registers for safety }
- push di
- push bx
- push cx
- push dx
- push es
- push ds
- mov bx, handle { file handle }
- lds dx, buffer { buffer address }
- mov cx, count { number of bytes }
- mov ah,3fh { read file }
- int 21h
- jc read_err { if failed, return error code }
- cmp ax, count { make sure all bytes were read }
- je read_ok
- mov ax,1 { else return 1 for not OK }
- jmp read_err
-read_ok:
- xor ax,ax { return zero for OK }
-read_err:
- pop ds { restore registers and exit }
- pop es
- pop dx
- pop cx
- pop bx
- pop di
- pop si
-end; { jdos_read }
-
-
-
-function jdos_write (handle : short; buffer : pointer; {FAR}
- count : ushort) : short; assembler;
-{ Write to file }
-label
- write_ok, write_err;
-asm
- push si { save all registers for safety }
- push di
- push bx
- push cx
- push dx
- push es
- push ds
- mov bx, handle { file handle }
- lds dx, buffer { buffer address }
- mov cx, count { number of bytes }
- mov ah,40h { write file }
- int 21h
- jc write_err { if failed, return error code }
- cmp ax, count { make sure all bytes written }
- je write_ok
- mov ax,1 { else return 1 for not OK }
- jmp write_err
-write_ok:
- xor ax,ax { return zero for OK }
-write_err:
- pop ds { restore registers and exit }
- pop es
- pop dx
- pop cx
- pop bx
- pop di
- pop si
-end; { jdos_write }
-
-
-
-procedure jxms_getdriver (var driver : XMSDRIVER); assembler;
-{ Get the address of the XMS driver, or NIL if not available }
-label
- xmsavail, xmsavail_done;
-asm
- push si { save all registers for safety }
- push di
- push bx
- push cx
- push dx
- push es
- push ds
- mov ax,4300h { call multiplex interrupt with }
- int 2fh { a magic cookie, hex 4300 }
- cmp al,80h { AL should contain hex 80 }
- je xmsavail
- xor dx,dx { no XMS driver available }
- xor ax,ax { return a nil pointer }
- jmp xmsavail_done
-xmsavail:
- mov ax,4310h { fetch driver address with }
- int 2fh { another magic cookie }
- mov dx,es { copy address to dx:ax }
- mov ax,bx
-xmsavail_done:
- les bx,dword ptr [bp+6] { get pointer to return value }
- mov word ptr es:[bx],ax
- mov word ptr es:[bx+2],dx
- pop ds { restore registers and exit }
- pop es
- pop dx
- pop cx
- pop bx
- pop di
- pop si
-end; { jxms_getdriver }
-
-procedure jxms_calldriver (driver : XMSDRIVER;
- var ctx : XMScontext); assembler;
-{ The XMScontext structure contains values for the AX,DX,BX,SI,DS registers.}
-{ These are loaded, the XMS call is performed, and the new values of the }
-{ AX,DX,BX registers are written back to the context structure. }
-asm
- push si { save all registers for safety }
- push di
- push bx
- push cx
- push dx
- push es
- push ds
- les bx, ctx { get XMScontext pointer }
- mov ax,word ptr es:[bx] { load registers }
- mov dx,word ptr es:[bx+2]
- mov si,word ptr es:[bx+6]
- mov ds,word ptr es:[bx+8]
- mov bx,word ptr es:[bx+4]
- call dword ptr driver { call the driver }
- mov cx,bx { save returned BX for a sec }
- les bx, ctx { get XMScontext pointer }
- mov word ptr es:[bx],ax { put back ax,dx,bx }
- mov word ptr es:[bx+2],dx
- mov word ptr es:[bx+4],cx
- pop ds { restore registers and exit }
- pop es
- pop dx
- pop cx
- pop bx
- pop di
- pop si
-end; { jxms_calldriver }
-
-
-
-function jems_available : short; assembler;
-{ Have we got an EMS driver? (this comes straight from the EMS 4.0 specs)}
-label
- no_ems, avail_done;
-const
- ASCII_device_name : packed array[0..7] of char = 'EMMXXXX0';
-asm
- push si { save all registers for safety }
- push di
- push bx
- push cx
- push dx
- push es
- push ds
- mov ax,3567h { get interrupt vector 67h }
- int 21h
- push cs
- pop ds
- mov di,000ah { check offs 10 in returned seg }
- lea si, ASCII_device_name { against literal string }
- mov cx,8
- cld
- repe cmpsb
- jne no_ems
- mov ax,1 { match, it's there }
- jmp avail_done
-no_ems: xor ax,ax { it's not there }
-avail_done:
- pop ds { restore registers and exit }
- pop es
- pop dx
- pop cx
- pop bx
- pop di
- pop si
-end; { jems_available }
-
-
-procedure jems_calldriver (var ctx : EMScontext); assembler;
-{ The EMScontext structure contains values for the AX,DX,BX,SI,DS registers. }
-{ These are loaded, the EMS trap is performed, and the new values of the }
-{ AX,DX,BX registers are written back to the context structure. }
-asm
- push si { save all registers for safety }
- push di
- push bx
- push cx
- push dx
- push es
- push ds
-
- les bx, ctx { get EMScontext pointer }
- mov ax, es:[bx].EMScontext.&ax { load registers }
- mov dx, es:[bx].EMScontext.&dx
- mov si, es:[bx].EMScontext.&ds_si.word
- mov ds, es:[bx].EMScontext.&ds_si.word[2]
- mov bx, es:[bx].EMScontext.&bx
- int 67h { call the EMS driver }
- mov cx,bx { save returned BX for a sec }
- les bx, ctx { get EMScontext pointer }
- mov es:[bx].EMScontext.&ax, ax { put back ax,dx,bx }
- mov es:[bx].EMScontext.&dx, dx
- mov es:[bx].EMScontext.&bx, cx
-
- pop ds { restore registers and exit }
- pop es
- pop dx
- pop cx
- pop bx
- pop di
- pop si
-end; { jems_calldriver }
-
-end.
diff --git a/packages/base/pasjpeg/jmemmgr.pas b/packages/base/pasjpeg/jmemmgr.pas
deleted file mode 100644
index 600d3fbbb2..0000000000
--- a/packages/base/pasjpeg/jmemmgr.pas
+++ /dev/null
@@ -1,1282 +0,0 @@
-Unit JMemMgr;
-
-{ 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...) }
-
-{ Original : jmemmgr.c ; Copyright (C) 1991-1997, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jdeferr,
- jerror,
- jpeglib,
- jutils,
-{$IFDEF VER70}
-{$ifndef NO_GETENV}
- Dos, { DOS unit should declare getenv() }
- { function GetEnv(name : string) : string; }
-{$endif}
- jmemdos; { import the system-dependent declarations }
-{$ELSE}
- jmemnobs;
- {$DEFINE NO_GETENV}
-{$ENDIF}
-
-{ Memory manager initialization.
- When this is called, only the error manager pointer is valid in cinfo! }
-
-{GLOBAL}
-procedure jinit_memory_mgr (cinfo : j_common_ptr);
-
-implementation
-
-
-{ Some important notes:
- The allocation routines provided here must never return NIL.
- 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 }
-type
- 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. }
-
-type
- small_pool_ptr = ^small_pool_hdr;
- small_pool_hdr = record
- case byte of
- 0:(hdr : record
- next : small_pool_ptr; { next in list of pools }
- bytes_used : size_t; { how many bytes already used within pool }
- bytes_left : size_t; { bytes still available in this pool }
- end);
- 1:(dummy : ALIGN_TYPE); { included in union to ensure alignment }
- end; {small_pool_hdr;}
-
-type
- large_pool_ptr = ^large_pool_hdr; {FAR}
- large_pool_hdr = record
- case byte of
- 0:(hdr : record
- next : large_pool_ptr; { next in list of pools }
- bytes_used : size_t; { how many bytes already used within pool }
- bytes_left : size_t; { bytes still available in this pool }
- end);
- 1:(dummy : ALIGN_TYPE); { included in union to ensure alignment }
- end; {large_pool_hdr;}
-
-
-{ Here is the full definition of a memory manager object. }
-
-type
- my_mem_ptr = ^my_memory_mgr;
- my_memory_mgr = record
- pub : jpeg_memory_mgr; { public fields }
-
- { Each pool identifier (lifetime class) names a linked list of pools. }
- small_list : array[0..JPOOL_NUMPOOLS-1] of small_pool_ptr ;
- large_list : array[0..JPOOL_NUMPOOLS-1] of large_pool_ptr ;
-
- { 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. }
-
- virt_sarray_list : jvirt_sarray_ptr;
- virt_barray_list : jvirt_barray_ptr;
-
- { This counts total space obtained from jpeg_get_small/large }
- total_space_allocated : long;
-
- { alloc_sarray and alloc_barray set this value for use by virtual
- array routines. }
-
- last_rowsperchunk : JDIMENSION; { from most recent alloc_sarray/barray }
- end; {my_memory_mgr;}
-
- {$ifndef AM_MEMORY_MANAGER} { only jmemmgr.c defines these }
-
-{ 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. }
-type
- jvirt_sarray_control = record
- mem_buffer : JSAMPARRAY; { => the in-memory buffer }
- rows_in_array : JDIMENSION; { total virtual array height }
- samplesperrow : JDIMENSION; { width of array (and of memory buffer) }
- maxaccess : JDIMENSION; { max rows accessed by access_virt_sarray }
- rows_in_mem : JDIMENSION; { height of memory buffer }
- rowsperchunk : JDIMENSION; { allocation chunk size in mem_buffer }
- cur_start_row : JDIMENSION; { first logical row # in the buffer }
- first_undef_row : JDIMENSION; { row # of first uninitialized row }
- pre_zero : boolean; { pre-zero mode requested? }
- dirty : boolean; { do current buffer contents need written? }
- b_s_open : boolean; { is backing-store data valid? }
- next : jvirt_sarray_ptr; { link to next virtual sarray control block }
- b_s_info : backing_store_info; { System-dependent control info }
- end;
-
- jvirt_barray_control = record
- mem_buffer : JBLOCKARRAY; { => the in-memory buffer }
- rows_in_array : JDIMENSION; { total virtual array height }
- blocksperrow : JDIMENSION; { width of array (and of memory buffer) }
- maxaccess : JDIMENSION; { max rows accessed by access_virt_barray }
- rows_in_mem : JDIMENSION; { height of memory buffer }
- rowsperchunk : JDIMENSION; { allocation chunk size in mem_buffer }
- cur_start_row : JDIMENSION; { first logical row # in the buffer }
- first_undef_row : JDIMENSION; { row # of first uninitialized row }
- pre_zero : boolean; { pre-zero mode requested? }
- dirty : boolean; { do current buffer contents need written? }
- b_s_open : boolean; { is backing-store data valid? }
- next : jvirt_barray_ptr; { link to next virtual barray control block }
- b_s_info : backing_store_info; { System-dependent control info }
- end;
- {$endif} { AM_MEMORY_MANAGER}
-
-{$ifdef MEM_STATS} { optional extra stuff for statistics }
-
-{LOCAL}
-procedure print_mem_stats (cinfo : j_common_ptr; pool_id : int);
-var
- mem : my_mem_ptr;
- shdr_ptr : small_pool_ptr;
- lhdr_ptr : large_pool_ptr;
-begin
- mem := my_mem_ptr (cinfo^.mem);
-
- { 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. }
-
- WriteLn(output, 'Freeing pool ', pool_id,', total space := ',
- mem^.total_space_allocated);
-
- lhdr_ptr := mem^.large_list[pool_id];
- while (lhdr_ptr <> NIL) do
- begin
- WriteLn(output, ' Large chunk used ',
- long (lhdr_ptr^.hdr.bytes_used));
- lhdr_ptr := lhdr_ptr^.hdr.next;
- end;
-
- shdr_ptr := mem^.small_list[pool_id];
-
- while (shdr_ptr <> NIL) do
- begin
- WriteLn(output, ' Small chunk used ',
- long (shdr_ptr^.hdr.bytes_used), ' free ',
- long (shdr_ptr^.hdr.bytes_left) );
- shdr_ptr := shdr_ptr^.hdr.next;
- end;
-end;
-
-{$endif} { MEM_STATS }
-
-
-{LOCAL}
-procedure out_of_memory (cinfo : j_common_ptr; which : int);
-{ Report an out-of-memory error and stop execution }
-{ If we compiled MEM_STATS support, report alloc requests before dying }
-begin
-{$ifdef MEM_STATS}
- cinfo^.err^.trace_level := 2; { force self_destruct to report stats }
-{$endif}
- ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
-end;
-
-
-{ 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. }
-
-const
- first_pool_slop : array[0..JPOOL_NUMPOOLS-1] of size_t =
- (1600, { first PERMANENT pool }
- 16000); { first IMAGE pool }
-
-const
- extra_pool_slop : array[0..JPOOL_NUMPOOLS-1] of size_t =
- (0, { additional PERMANENT pools }
- 5000); { additional IMAGE pools }
-
-const
- MIN_SLOP = 50; { greater than 0 to avoid futile looping }
-
-
-{METHODDEF}
-function alloc_small (cinfo : j_common_ptr;
- pool_id : int;
- sizeofobject : size_t) : pointer; far;
-type
- byteptr = ^byte;
-{ Allocate a "small" object }
-var
- mem : my_mem_ptr;
- hdr_ptr, prev_hdr_ptr : small_pool_ptr;
- data_ptr : byteptr;
- odd_bytes, min_request, slop : size_t;
-begin
- mem := my_mem_ptr (cinfo^.mem);
-
- { Check for unsatisfiable request (do now to ensure no overflow below) }
- if (sizeofobject > size_t(MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr))) then
- 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 mod SIZEOF(ALIGN_TYPE);
- if (odd_bytes > 0) then
- Inc(sizeofobject, SIZEOF(ALIGN_TYPE) - odd_bytes);
-
- { See if space is available in any existing pool }
- if (pool_id < 0) or (pool_id >= JPOOL_NUMPOOLS) then
- ERREXIT1(j_common_ptr(cinfo), JERR_BAD_POOL_ID, pool_id); { safety check }
- prev_hdr_ptr := NIL;
- hdr_ptr := mem^.small_list[pool_id];
- while (hdr_ptr <> NIL) do
- begin
- if (hdr_ptr^.hdr.bytes_left >= sizeofobject) then
- break; { found pool with enough space }
- prev_hdr_ptr := hdr_ptr;
- hdr_ptr := hdr_ptr^.hdr.next;
- end;
-
- { Time to make a new pool? }
- if (hdr_ptr = NIL) then
- begin
- { min_request is what we need now, slop is what will be leftover }
- min_request := sizeofobject + SIZEOF(small_pool_hdr);
- if (prev_hdr_ptr = NIL) then { 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)) then
- slop := size_t (MAX_ALLOC_CHUNK-min_request);
- { Try to get space, if fail reduce slop and try again }
- while TRUE do
- begin
- hdr_ptr := small_pool_ptr(jpeg_get_small(cinfo, min_request + slop));
- if (hdr_ptr <> NIL) then
- break;
- slop := slop div 2;
- if (slop < MIN_SLOP) then { give up when it gets real small }
- out_of_memory(cinfo, 2); { jpeg_get_small failed }
- end;
- Inc(mem^.total_space_allocated, min_request + slop);
- { Success, initialize the new pool header and add to end of list }
- hdr_ptr^.hdr.next := NIL;
- hdr_ptr^.hdr.bytes_used := 0;
- hdr_ptr^.hdr.bytes_left := sizeofobject + slop;
- if (prev_hdr_ptr = NIL) then { first pool in class? }
- mem^.small_list[pool_id] := hdr_ptr
- else
- prev_hdr_ptr^.hdr.next := hdr_ptr;
- end;
-
- { OK, allocate the object from the current pool }
- data_ptr := byteptr (hdr_ptr);
- Inc(small_pool_ptr(data_ptr)); { point to first data byte in pool }
- Inc(data_ptr, hdr_ptr^.hdr.bytes_used); { point to place for object }
- Inc(hdr_ptr^.hdr.bytes_used, sizeofobject);
- Dec(hdr_ptr^.hdr.bytes_left, sizeofobject);
-
- alloc_small := pointer(data_ptr);
-end;
-
-
-{ 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}
-function alloc_large (cinfo : j_common_ptr;
- pool_id : int;
- sizeofobject : size_t) : pointer; FAR;
-{ Allocate a "large" object }
-var
- mem : my_mem_ptr;
- hdr_ptr : large_pool_ptr;
- odd_bytes : size_t;
-var
- dest_ptr : large_pool_ptr;
-begin
- mem := my_mem_ptr (cinfo^.mem);
-
- { Check for unsatisfiable request (do now to ensure no overflow below) }
- if (sizeofobject > size_t (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr))) then
- 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 mod SIZEOF(ALIGN_TYPE);
- if (odd_bytes > 0) then
- Inc(sizeofobject, SIZEOF(ALIGN_TYPE) - odd_bytes);
-
- { Always make a new pool }
- if (pool_id < 0) or (pool_id >= JPOOL_NUMPOOLS) then
- 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 = NIL) then
- out_of_memory(cinfo, 4); { jpeg_get_large failed }
- Inc(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;
-
- {alloc_large := pointerFAR (hdr_ptr + 1); - point to first data byte in pool }
- dest_ptr := hdr_ptr;
- Inc(large_pool_ptr(dest_ptr));
- alloc_large := dest_ptr;
-end;
-
-
-{ 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}
-function alloc_sarray (cinfo : j_common_ptr;
- pool_id : int;
- samplesperrow : JDIMENSION;
- numrows : JDIMENSION) : JSAMPARRAY; far;
-{ Allocate a 2-D sample array }
-var
- mem : my_mem_ptr;
- the_result : JSAMPARRAY;
- workspace : JSAMPROW;
- rowsperchunk, currow, i : JDIMENSION;
- ltemp : long;
-begin
- mem := my_mem_ptr(cinfo^.mem);
-
- { Calculate max # of rows allowed in one allocation chunk }
- ltemp := (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) div
- (long(samplesperrow) * SIZEOF(JSAMPLE));
- if (ltemp <= 0) then
- ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
- if (ltemp < long(numrows)) then
- rowsperchunk := JDIMENSION (ltemp)
- else
- rowsperchunk := numrows;
- mem^.last_rowsperchunk := rowsperchunk;
-
- { Get space for row pointers (small object) }
- the_result := JSAMPARRAY (alloc_small(cinfo, pool_id,
- size_t (numrows * SIZEOF(JSAMPROW))));
-
- { Get the rows themselves (large objects) }
- currow := 0;
- while (currow < numrows) do
- begin
- {rowsperchunk := MIN(rowsperchunk, numrows - currow);}
- if rowsperchunk > numrows - currow then
- rowsperchunk := numrows - currow;
-
- workspace := JSAMPROW (alloc_large(cinfo, pool_id,
- size_t (size_t(rowsperchunk) * size_t(samplesperrow)
- * SIZEOF(JSAMPLE))) );
- for i := pred(rowsperchunk) downto 0 do
- begin
- the_result^[currow] := workspace;
- Inc(currow);
- Inc(JSAMPLE_PTR(workspace), samplesperrow);
- end;
- end;
-
- alloc_sarray := the_result;
-end;
-
-
-{ Creation of 2-D coefficient-block arrays.
- This is essentially the same as the code for sample arrays, above. }
-
-{METHODDEF}
-function alloc_barray (cinfo : j_common_ptr;
- pool_id : int;
- blocksperrow : JDIMENSION;
- numrows : JDIMENSION) : JBLOCKARRAY; far;
-{ Allocate a 2-D coefficient-block array }
-var
- mem : my_mem_ptr;
- the_result : JBLOCKARRAY;
- workspace : JBLOCKROW;
- rowsperchunk, currow, i : JDIMENSION;
- ltemp : long;
-begin
- mem := my_mem_ptr(cinfo^.mem);
-
- { Calculate max # of rows allowed in one allocation chunk }
- ltemp := (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) div
- (long(blocksperrow) * SIZEOF(JBLOCK));
- if (ltemp <= 0) then
- ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
- if (ltemp < long(numrows)) then
- rowsperchunk := JDIMENSION (ltemp)
- else
- rowsperchunk := numrows;
- mem^.last_rowsperchunk := rowsperchunk;
-
- { Get space for row pointers (small object) }
- the_result := JBLOCKARRAY (alloc_small(cinfo, pool_id,
- size_t (numrows * SIZEOF(JBLOCKROW))) );
-
- { Get the rows themselves (large objects) }
- currow := 0;
- while (currow < numrows) do
- begin
- {rowsperchunk := MIN(rowsperchunk, numrows - currow);}
- if rowsperchunk > numrows - currow then
- rowsperchunk := numrows - currow;
-
- workspace := JBLOCKROW (alloc_large(cinfo, pool_id,
- size_t (size_t(rowsperchunk) * size_t(blocksperrow)
- * SIZEOF(JBLOCK))) );
- for i := rowsperchunk downto 1 do
- begin
- the_result^[currow] := workspace;
- Inc(currow);
- Inc(JBLOCK_PTR(workspace), blocksperrow);
- end;
- end;
-
- alloc_barray := the_result;
-end;
-
-
-{ 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}
-function request_virt_sarray (cinfo : j_common_ptr;
- pool_id : int;
- pre_zero : boolean;
- samplesperrow : JDIMENSION;
- numrows : JDIMENSION;
- maxaccess : JDIMENSION) : jvirt_sarray_ptr; far;
-{ Request a virtual 2-D sample array }
-var
- mem : my_mem_ptr;
- the_result : jvirt_sarray_ptr;
-begin
- mem := my_mem_ptr (cinfo^.mem);
-
- { Only IMAGE-lifetime virtual arrays are currently supported }
- if (pool_id <> JPOOL_IMAGE) then
- ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); { safety check }
-
- { get control block }
- the_result := jvirt_sarray_ptr (alloc_small(cinfo, pool_id,
- SIZEOF(jvirt_sarray_control)) );
-
- the_result^.mem_buffer := NIL; { marks array not yet realized }
- the_result^.rows_in_array := numrows;
- the_result^.samplesperrow := samplesperrow;
- the_result^.maxaccess := maxaccess;
- the_result^.pre_zero := pre_zero;
- the_result^.b_s_open := FALSE; { no associated backing-store object }
- the_result^.next := mem^.virt_sarray_list; { add to list of virtual arrays }
- mem^.virt_sarray_list := the_result;
-
- request_virt_sarray := the_result;
-end;
-
-
-{METHODDEF}
-function request_virt_barray (cinfo : j_common_ptr;
- pool_id : int;
- pre_zero : boolean;
- blocksperrow : JDIMENSION;
- numrows : JDIMENSION;
- maxaccess : JDIMENSION) : jvirt_barray_ptr; far;
-{ Request a virtual 2-D coefficient-block array }
-var
- mem : my_mem_ptr;
- the_result : jvirt_barray_ptr;
-begin
- mem := my_mem_ptr(cinfo^.mem);
-
- { Only IMAGE-lifetime virtual arrays are currently supported }
- if (pool_id <> JPOOL_IMAGE) then
- ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); { safety check }
-
- { get control block }
- the_result := jvirt_barray_ptr(alloc_small(cinfo, pool_id,
- SIZEOF(jvirt_barray_control)) );
-
- the_result^.mem_buffer := NIL; { marks array not yet realized }
- the_result^.rows_in_array := numrows;
- the_result^.blocksperrow := blocksperrow;
- the_result^.maxaccess := maxaccess;
- the_result^.pre_zero := pre_zero;
- the_result^.b_s_open := FALSE; { no associated backing-store object }
- the_result^.next := mem^.virt_barray_list; { add to list of virtual arrays }
- mem^.virt_barray_list := the_result;
-
- request_virt_barray := the_result;
-end;
-
-
-{METHODDEF}
-procedure realize_virt_arrays (cinfo : j_common_ptr); far;
-{ Allocate the in-memory buffers for any unrealized virtual arrays }
-var
- mem : my_mem_ptr;
- space_per_minheight, maximum_space, avail_mem : long;
- minheights, max_minheights : long;
- sptr : jvirt_sarray_ptr;
- bptr : jvirt_barray_ptr;
-begin
- mem := my_mem_ptr (cinfo^.mem);
- { 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;
- sptr := mem^.virt_sarray_list;
- while (sptr <> NIL) do
- begin
- if (sptr^.mem_buffer = NIL) then
- begin { if not realized yet }
- Inc(space_per_minheight, long(sptr^.maxaccess) *
- long(sptr^.samplesperrow) * SIZEOF(JSAMPLE));
- Inc(maximum_space, long(sptr^.rows_in_array) *
- long(sptr^.samplesperrow) * SIZEOF(JSAMPLE));
- end;
- sptr := sptr^.next;
- end;
- bptr := mem^.virt_barray_list;
- while (bptr <> NIL) do
- begin
- if (bptr^.mem_buffer = NIL) then
- begin { if not realized yet }
- Inc(space_per_minheight, long(bptr^.maxaccess) *
- long(bptr^.blocksperrow) * SIZEOF(JBLOCK));
- Inc(maximum_space, long(bptr^.rows_in_array) *
- long(bptr^.blocksperrow) * SIZEOF(JBLOCK));
- end;
- bptr := bptr^.next;
- end;
-
- if (space_per_minheight <= 0) then
- exit; { 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) then
- max_minheights := long(1000000000)
- else
- begin
- max_minheights := avail_mem div 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) then
- max_minheights := 1;
- end;
-
- { Allocate the in-memory buffers and initialize backing store as needed. }
-
- sptr := mem^.virt_sarray_list;
- while (sptr <> NIL) do
- begin
- if (sptr^.mem_buffer = NIL) then
- begin { if not realized yet }
- minheights := (long(sptr^.rows_in_array) - long(1)) div sptr^.maxaccess + long(1);
- if (minheights <= max_minheights) then
- begin
- { This buffer fits in memory }
- sptr^.rows_in_mem := sptr^.rows_in_array;
- end
- else
- begin
- { 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;
- end;
- 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;
- end;
- sptr := sptr^.next;
- end;
-
- bptr := mem^.virt_barray_list;
- while (bptr <> NIL) do
- begin
- if (bptr^.mem_buffer = NIL) then
- begin { if not realized yet }
- minheights := (long(bptr^.rows_in_array) - long(1)) div bptr^.maxaccess + long(1);
- if (minheights <= max_minheights) then
- begin
- { This buffer fits in memory }
- bptr^.rows_in_mem := bptr^.rows_in_array;
- end
- else
- begin
- { 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;
- end;
- 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;
- end;
- bptr := bptr^.next;
- end;
-end;
-
-
-{LOCAL}
-procedure do_sarray_io (cinfo : j_common_ptr;
- ptr : jvirt_sarray_ptr;
- writing : boolean);
-{ Do backing store read or write of a virtual sample array }
-var
- bytesperrow, file_offset, byte_count, rows, thisrow, i : long;
-begin
-
- bytesperrow := long(ptr^.samplesperrow * SIZEOF(JSAMPLE));
- file_offset := ptr^.cur_start_row * bytesperrow;
- { Loop to read or write each allocation chunk in mem_buffer }
- i := 0;
- while i < long(ptr^.rows_in_mem) do
- begin
-
- { One chunk, but check for short chunk at end of buffer }
- {rows := MIN(long(ptr^.rowsperchunk), long(ptr^.rows_in_mem - i));}
- rows := long(ptr^.rowsperchunk);
- if rows > long(ptr^.rows_in_mem - i) then
- rows := 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);}
- if (rows > long(ptr^.first_undef_row) - thisrow) then
- 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 > long(ptr^.rows_in_array) - thisrow) then
- rows := long(ptr^.rows_in_array) - thisrow;
-
- if (rows <= 0) then { this chunk might be past end of file! }
- break;
- byte_count := rows * bytesperrow;
- if (writing) then
- ptr^.b_s_info.write_backing_store (cinfo,
- @ptr^.b_s_info,
- pointer {FAR} (ptr^.mem_buffer^[i]),
- file_offset, byte_count)
- else
- ptr^.b_s_info.read_backing_store (cinfo,
- @ptr^.b_s_info,
- pointer {FAR} (ptr^.mem_buffer^[i]),
- file_offset, byte_count);
- Inc(file_offset, byte_count);
- Inc(i, ptr^.rowsperchunk);
- end;
-end;
-
-
-{LOCAL}
-procedure do_barray_io (cinfo : j_common_ptr;
- ptr : jvirt_barray_ptr;
- writing : boolean);
-{ Do backing store read or write of a virtual coefficient-block array }
-var
- bytesperrow, file_offset, byte_count, rows, thisrow, i : long;
-begin
- bytesperrow := long (ptr^.blocksperrow) * SIZEOF(JBLOCK);
- file_offset := ptr^.cur_start_row * bytesperrow;
- { Loop to read or write each allocation chunk in mem_buffer }
- i := 0;
- while (i < long(ptr^.rows_in_mem)) do
- begin
- { One chunk, but check for short chunk at end of buffer }
- {rows := MIN(long(ptr^.rowsperchunk), long(ptr^.rows_in_mem - i));}
- rows := long(ptr^.rowsperchunk);
- if rows >long(ptr^.rows_in_mem - i) then
- rows := 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));}
- if rows > long(ptr^.first_undef_row - thisrow) then
- 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 > long (ptr^.rows_in_array - thisrow)) then
- rows := long (ptr^.rows_in_array - thisrow);
-
- if (rows <= 0) then { this chunk might be past end of file! }
- break;
- byte_count := rows * bytesperrow;
- if (writing) then
- ptr^.b_s_info.write_backing_store (cinfo,
- @ptr^.b_s_info,
- {FAR} pointer(ptr^.mem_buffer^[i]),
- file_offset, byte_count)
- else
- ptr^.b_s_info.read_backing_store (cinfo,
- @ptr^.b_s_info,
- {FAR} pointer(ptr^.mem_buffer^[i]),
- file_offset, byte_count);
- Inc(file_offset, byte_count);
- Inc(i, ptr^.rowsperchunk);
- end;
-end;
-
-
-{METHODDEF}
-function access_virt_sarray (cinfo : j_common_ptr;
- ptr : jvirt_sarray_ptr;
- start_row : JDIMENSION;
- num_rows : JDIMENSION;
- writable : boolean ) : JSAMPARRAY; far;
-{ 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. }
-var
- end_row : JDIMENSION;
- undef_row : JDIMENSION;
-var
- bytesperrow : size_t;
-var
- ltemp : long;
-begin
- end_row := start_row + num_rows;
- { debugging check }
- if (end_row > ptr^.rows_in_array) or (num_rows > ptr^.maxaccess) or
- (ptr^.mem_buffer = NIL) then
- ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
-
- { Make the desired part of the virtual array accessible }
- if (start_row < ptr^.cur_start_row) or
- (end_row > ptr^.cur_start_row+ptr^.rows_in_mem) then
- begin
- if (not ptr^.b_s_open) then
- ERREXIT(cinfo, JERR_VIRTUAL_BUG);
- { Flush old buffer contents if necessary }
- if (ptr^.dirty) then
- begin
- do_sarray_io(cinfo, ptr, TRUE);
- ptr^.dirty := FALSE;
- end;
- { 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) then
- begin
- ptr^.cur_start_row := start_row;
- end
- else
- begin
- { use long arithmetic here to avoid overflow & unsigned problems }
-
-
- ltemp := long(end_row) - long(ptr^.rows_in_mem);
- if (ltemp < 0) then
- ltemp := 0; { don't fall off front end of file }
- ptr^.cur_start_row := JDIMENSION(ltemp);
- end;
- { 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);
- end;
- { 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) then
- begin
- if (ptr^.first_undef_row < start_row) then
- begin
- if (writable) then { writer skipped over a section of array }
- ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
- undef_row := start_row; { but reader is allowed to read ahead }
- end
- else
- begin
- undef_row := ptr^.first_undef_row;
- end;
- if (writable) then
- ptr^.first_undef_row := end_row;
- if (ptr^.pre_zero) then
- begin
- bytesperrow := size_t(ptr^.samplesperrow) * SIZEOF(JSAMPLE);
- Dec(undef_row, ptr^.cur_start_row); { make indexes relative to buffer }
- Dec(end_row, ptr^.cur_start_row);
- while (undef_row < end_row) do
- begin
- jzero_far({FAR} pointer(ptr^.mem_buffer^[undef_row]), bytesperrow);
- Inc(undef_row);
- end;
- end
- else
- begin
- if (not writable) then { reader looking at undefined data }
- ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
- end;
- end;
- { Flag the buffer dirty if caller will write in it }
- if (writable) then
- ptr^.dirty := TRUE;
- { Return address of proper part of the buffer }
- access_virt_sarray := JSAMPARRAY(@ ptr^.mem_buffer^[start_row - ptr^.cur_start_row]);
-end;
-
-
-{METHODDEF}
-function access_virt_barray (cinfo : j_common_ptr;
- ptr : jvirt_barray_ptr;
- start_row : JDIMENSION;
- num_rows : JDIMENSION;
- writable : boolean) : JBLOCKARRAY; far;
-{ 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. }
-var
- end_row : JDIMENSION;
- undef_row : JDIMENSION;
- ltemp : long;
-var
- bytesperrow : size_t;
-begin
- end_row := start_row + num_rows;
-
- { debugging check }
- if (end_row > ptr^.rows_in_array) or (num_rows > ptr^.maxaccess) or
- (ptr^.mem_buffer = NIL) then
- ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
-
- { Make the desired part of the virtual array accessible }
- if (start_row < ptr^.cur_start_row) or
- (end_row > ptr^.cur_start_row+ptr^.rows_in_mem) then
- begin
- if (not ptr^.b_s_open) then
- ERREXIT(cinfo, JERR_VIRTUAL_BUG);
- { Flush old buffer contents if necessary }
- if (ptr^.dirty) then
- begin
- do_barray_io(cinfo, ptr, TRUE);
- ptr^.dirty := FALSE;
- end;
- { 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) then
- begin
- ptr^.cur_start_row := start_row;
- end
- else
- begin
- { use long arithmetic here to avoid overflow & unsigned problems }
-
- ltemp := long(end_row) - long(ptr^.rows_in_mem);
- if (ltemp < 0) then
- ltemp := 0; { don't fall off front end of file }
- ptr^.cur_start_row := JDIMENSION (ltemp);
- end;
- { 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);
- end;
- { 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) then
- begin
- if (ptr^.first_undef_row < start_row) then
- begin
- if (writable) then { writer skipped over a section of array }
- ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
- undef_row := start_row; { but reader is allowed to read ahead }
- end
- else
- begin
- undef_row := ptr^.first_undef_row;
- end;
- if (writable) then
- ptr^.first_undef_row := end_row;
- if (ptr^.pre_zero) then
- begin
- bytesperrow := size_t (ptr^.blocksperrow) * SIZEOF(JBLOCK);
- Dec(undef_row, ptr^.cur_start_row); { make indexes relative to buffer }
- Dec(end_row, ptr^.cur_start_row);
- while (undef_row < end_row) do
- begin
- jzero_far({FAR}pointer(ptr^.mem_buffer^[undef_row]), bytesperrow);
- Inc(undef_row);
- end;
- end
- else
- begin
- if (not writable) then { reader looking at undefined data }
- ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
- end;
- end;
- { Flag the buffer dirty if caller will write in it }
- if (writable) then
- ptr^.dirty := TRUE;
- { Return address of proper part of the buffer }
- access_virt_barray := JBLOCKARRAY(@ ptr^.mem_buffer^[start_row - ptr^.cur_start_row]);
-end;
-
-
-{ Release all objects belonging to a specified pool. }
-
-{METHODDEF}
-procedure free_pool (cinfo : j_common_ptr; pool_id : int); far;
-var
- mem : my_mem_ptr;
- shdr_ptr : small_pool_ptr;
- lhdr_ptr : large_pool_ptr;
- space_freed : size_t;
-var
- sptr : jvirt_sarray_ptr;
- bptr : jvirt_barray_ptr;
-var
- next_lhdr_ptr : large_pool_ptr;
- next_shdr_ptr : small_pool_ptr;
-begin
- mem := my_mem_ptr(cinfo^.mem);
-
- if (pool_id < 0) or (pool_id >= JPOOL_NUMPOOLS) then
- ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); { safety check }
-
-{$ifdef MEM_STATS}
- if (cinfo^.err^.trace_level > 1) then
- 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) then
- begin
- sptr := mem^.virt_sarray_list;
- while (sptr <> NIL) do
- begin
- if (sptr^.b_s_open) then
- begin { 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);
- end;
- sptr := sptr^.next;
- end;
- mem^.virt_sarray_list := NIL;
- bptr := mem^.virt_barray_list;
- while (bptr <> NIL) do
- begin
- if (bptr^.b_s_open) then
- begin { 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);
- end;
- bptr := bptr^.next;
- end;
- mem^.virt_barray_list := NIL;
- end;
-
- { Release large objects }
- lhdr_ptr := mem^.large_list[pool_id];
- mem^.large_list[pool_id] := NIL;
-
- while (lhdr_ptr <> NIL) do
- begin
- 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, {FAR} pointer(lhdr_ptr), space_freed);
- Dec(mem^.total_space_allocated, space_freed);
- lhdr_ptr := next_lhdr_ptr;
- end;
-
- { Release small objects }
- shdr_ptr := mem^.small_list[pool_id];
- mem^.small_list[pool_id] := NIL;
-
- while (shdr_ptr <> NIL) do
- begin
- 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, pointer(shdr_ptr), space_freed);
- Dec(mem^.total_space_allocated, space_freed);
- shdr_ptr := next_shdr_ptr;
- end;
-end;
-
-
-{ Close up shop entirely.
- Note that this cannot be called unless cinfo^.mem is non-NIL. }
-
-{METHODDEF}
-procedure self_destruct (cinfo : j_common_ptr); far;
-var
- pool : int;
-begin
- { 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 downto JPOOL_PERMANENT do
- begin
- free_pool(cinfo, pool);
- end;
-
- { Release the memory manager control block too. }
- jpeg_free_small(cinfo, pointer(cinfo^.mem), SIZEOF(my_memory_mgr));
- cinfo^.mem := NIL; { ensures I will be called only once }
-
- jpeg_mem_term(cinfo); { system-dependent cleanup }
-end;
-
-
-{ Memory manager initialization.
- When this is called, only the error manager pointer is valid in cinfo! }
-
-{GLOBAL}
-procedure jinit_memory_mgr (cinfo : j_common_ptr);
-var
- mem : my_mem_ptr;
- max_to_use : long;
- pool : int;
- test_mac : size_t;
-{$ifndef NO_GETENV}
-var
- memenv : string;
- code : integer;
-{$endif}
-begin
- cinfo^.mem := NIL; { 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) and (SIZEOF(ALIGN_TYPE)-1)) <> 0) then
- 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) or
- ((MAX_ALLOC_CHUNK mod SIZEOF(ALIGN_TYPE)) <> 0) then
- 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 = NIL) then
- begin
- jpeg_mem_term(cinfo); { system-dependent cleanup }
- ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
- end;
-
- { 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 downto JPOOL_PERMANENT do
- begin
- mem^.small_list[pool] := NIL;
- mem^.large_list[pool] := NIL;
- end;
- mem^.virt_sarray_list := NIL;
- mem^.virt_barray_list := NIL;
-
- 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}
- memenv := getenv('JPEGMEM');
- if (memenv <> '') then
- begin
- Val(memenv, max_to_use, code);
- if (Code = 0) then
- begin
- max_to_use := max_to_use * long(1000);
- mem^.pub.max_memory_to_use := max_to_use * long(1000);
- end;
- end;
-{$endif}
-
-end;
-
-end.
diff --git a/packages/base/pasjpeg/jmemnobs.pas b/packages/base/pasjpeg/jmemnobs.pas
deleted file mode 100644
index 48ddacb892..0000000000
--- a/packages/base/pasjpeg/jmemnobs.pas
+++ /dev/null
@@ -1,264 +0,0 @@
-Unit jmemnobs;
-{ Delphi3 -- > jmemnobs from jmemwin }
-{ This file provides an Win32-compatible implementation of the system-
- dependent portion of the JPEG memory manager. }
-
-{ Check jmemnobs.c }
-{ Copyright (C) 1996, Jacques Nomssi Nzali }
-
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jdeferr,
- jerror,
- jpeglib;
-
-{ The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
- be requested in a single call to jpeg_get_large (and jpeg_get_small for that
- matter, but that case should never come into play). This macro is needed
- to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
- On those machines, we expect that jconfig.h will provide a proper value.
- On machines with 32-bit flat address spaces, any large constant may be used.
-
- NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
- size_t and will be a multiple of sizeof(align_type). }
-
-{$IFDEF WINDOWS}
-const
- MAX_ALLOC_CHUNK = long(32752);
-{$ELSE}
-const
- MAX_ALLOC_CHUNK = long(1000000000);
-{$ENDIF}
-
-{GLOBAL}
-procedure jpeg_open_backing_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- total_bytes_needed : long);
-
-{ These routines take care of any system-dependent initialization and
- cleanup required. }
-
-{GLOBAL}
-function jpeg_mem_init (cinfo : j_common_ptr) : long;
-
-{GLOBAL}
-procedure jpeg_mem_term (cinfo : j_common_ptr);
-
-{ These two functions are used to allocate and release small chunks of
- memory. (Typically the total amount requested through jpeg_get_small is
- no more than 20K or so; this will be requested in chunks of a few K each.)
- Behavior should be the same as for the standard library functions malloc
- and free; in particular, jpeg_get_small must return NIL on failure.
- On most systems, these ARE malloc and free. jpeg_free_small is passed the
- size of the object being freed, just in case it's needed.
- On an 80x86 machine using small-data memory model, these manage near heap. }
-
-
-{ Near-memory allocation and freeing are controlled by the regular library
- routines malloc() and free(). }
-
-{GLOBAL}
-function jpeg_get_small (cinfo : j_common_ptr;
- sizeofobject : size_t) : pointer;
-
-{GLOBAL}
-{object is a reserved word in Borland Pascal }
-procedure jpeg_free_small (cinfo : j_common_ptr;
- an_object : pointer;
- sizeofobject : size_t);
-
-{ These two functions are used to allocate and release large chunks of
- memory (up to the total free space designated by jpeg_mem_available).
- The interface is the same as above, except that on an 80x86 machine,
- far pointers are used. On most other machines these are identical to
- the jpeg_get/free_small routines; but we keep them separate anyway,
- in case a different allocation strategy is desirable for large chunks. }
-
-
-{ "Large" objects are allocated in far memory, if possible }
-
-
-{GLOBAL}
-function jpeg_get_large (cinfo : j_common_ptr;
- sizeofobject : size_t) : voidp; {far}
-
-{GLOBAL}
-procedure jpeg_free_large (cinfo : j_common_ptr;
- {var?} an_object : voidp; {FAR}
- sizeofobject : size_t);
-
-{ This routine computes the total memory space available for allocation.
- It's impossible to do this in a portable way; our current solution is
- to make the user tell us (with a default value set at compile time).
- If you can actually get the available space, it's a good idea to subtract
- a slop factor of 5% or so. }
-
-{GLOBAL}
-function jpeg_mem_available (cinfo : j_common_ptr;
- min_bytes_needed : long;
- max_bytes_needed : long;
- already_allocated : long) : long;
-
-
-implementation
-
-{ This structure holds whatever state is needed to access a single
- backing-store object. The read/write/close method pointers are called
- by jmemmgr.c to manipulate the backing-store object; all other fields
- are private to the system-dependent backing store routines. }
-
-
-
-{ These two functions are used to allocate and release small chunks of
- memory. (Typically the total amount requested through jpeg_get_small is
- no more than 20K or so; this will be requested in chunks of a few K each.)
- Behavior should be the same as for the standard library functions malloc
- and free; in particular, jpeg_get_small must return NIL on failure.
- On most systems, these ARE malloc and free. jpeg_free_small is passed the
- size of the object being freed, just in case it's needed.
- On an 80x86 machine using small-data memory model, these manage near heap. }
-
-
-{ Near-memory allocation and freeing are controlled by the regular library
- routines malloc() and free(). }
-
-{GLOBAL}
-function jpeg_get_small (cinfo : j_common_ptr;
- sizeofobject : size_t) : pointer;
-var
- p : pointer;
-begin
- GetMem(p, sizeofobject);
- jpeg_get_small := p;
-end;
-
-{GLOBAL}
-{object is a reserved word in Object Pascal }
-procedure jpeg_free_small (cinfo : j_common_ptr;
- an_object : pointer;
- sizeofobject : size_t);
-begin
- FreeMem(an_object, sizeofobject);
-end;
-
-{ These two functions are used to allocate and release large chunks of
- memory (up to the total free space designated by jpeg_mem_available).
- The interface is the same as above, except that on an 80x86 machine,
- far pointers are used. On most other machines these are identical to
- the jpeg_get/free_small routines; but we keep them separate anyway,
- in case a different allocation strategy is desirable for large chunks. }
-
-
-
-{GLOBAL}
-function jpeg_get_large (cinfo : j_common_ptr;
- sizeofobject : size_t) : voidp; {far}
-var
- p : pointer;
-begin
- GetMem(p, sizeofobject);
- jpeg_get_large := p;
-end;
-
-{GLOBAL}
-procedure jpeg_free_large (cinfo : j_common_ptr;
- {var?} an_object : voidp; {FAR}
- sizeofobject : size_t);
-begin
- Freemem(an_object, sizeofobject);
-end;
-
-{ This routine computes the total space still available for allocation by
- jpeg_get_large. If more space than this is needed, backing store will be
- used. NOTE: any memory already allocated must not be counted.
-
- There is a minimum space requirement, corresponding to the minimum
- feasible buffer sizes; jmemmgr.c will request that much space even if
- jpeg_mem_available returns zero. The maximum space needed, enough to hold
- all working storage in memory, is also passed in case it is useful.
- Finally, the total space already allocated is passed. If no better
- method is available, cinfo^.mem^.max_memory_to_use - already_allocated
- is often a suitable calculation.
-
- It is OK for jpeg_mem_available to underestimate the space available
- (that'll just lead to more backing-store access than is really necessary).
- However, an overestimate will lead to failure. Hence it's wise to subtract
- a slop factor from the true available space. 5% should be enough.
-
- On machines with lots of virtual memory, any large constant may be returned.
- Conversely, zero may be returned to always use the minimum amount of memory.}
-
-
-
-{ This routine computes the total memory space available for allocation.
- It's impossible to do this in a portable way; our current solution is
- to make the user tell us (with a default value set at compile time).
- If you can actually get the available space, it's a good idea to subtract
- a slop factor of 5% or so. }
-
-const
- DEFAULT_MAX_MEM = long(300000); { for total usage about 450K }
-
-{GLOBAL}
-function jpeg_mem_available (cinfo : j_common_ptr;
- min_bytes_needed : long;
- max_bytes_needed : long;
- already_allocated : long) : long;
-begin
- {jpeg_mem_available := cinfo^.mem^.max_memory_to_use - already_allocated;}
- jpeg_mem_available := max_bytes_needed;
-end;
-
-
-{ Initial opening of a backing-store object. This must fill in the
- read/write/close pointers in the object. The read/write routines
- may take an error exit if the specified maximum file size is exceeded.
- (If jpeg_mem_available always returns a large value, this routine can
- just take an error exit.) }
-
-
-
-{ Initial opening of a backing-store object. }
-
-{GLOBAL}
-procedure jpeg_open_backing_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- total_bytes_needed : long);
-begin
- ERREXIT(cinfo, JERR_NO_BACKING_STORE);
-end;
-
-{ These routines take care of any system-dependent initialization and
- cleanup required. jpeg_mem_init will be called before anything is
- allocated (and, therefore, nothing in cinfo is of use except the error
- manager pointer). It should return a suitable default value for
- max_memory_to_use; this may subsequently be overridden by the surrounding
- application. (Note that max_memory_to_use is only important if
- jpeg_mem_available chooses to consult it ... no one else will.)
- jpeg_mem_term may assume that all requested memory has been freed and that
- all opened backing-store objects have been closed. }
-
-
-{ These routines take care of any system-dependent initialization and
- cleanup required. }
-
-
-{GLOBAL}
-function jpeg_mem_init (cinfo : j_common_ptr) : long;
-begin
- jpeg_mem_init := DEFAULT_MAX_MEM; { default for max_memory_to_use }
-end;
-
-{GLOBAL}
-procedure jpeg_mem_term (cinfo : j_common_ptr);
-begin
-
-end;
-
-
-end.
diff --git a/packages/base/pasjpeg/jmemsys.pas b/packages/base/pasjpeg/jmemsys.pas
deleted file mode 100644
index 1218561eb3..0000000000
--- a/packages/base/pasjpeg/jmemsys.pas
+++ /dev/null
@@ -1,177 +0,0 @@
-Unit jmemsys;
-
-{ This is a skeleton you need to create a working system-dependent
- JPEG memory manager.
- No other modules need include it. (The system-independent portion is
- jmemmgr.c; there are several different versions of the system-dependent
- portion.)
-
- This code will not compile - Check JMEMDOS.PAS for an example }
-
-{ Original: jmemsys.h; Copyright (C) 1992-1996, Thomas G. Lane. }
-
-interface
-
-uses
- jmorecfg,
- jpeglib;
-
-{ The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
- be requested in a single call to jpeg_get_large (and jpeg_get_small for that
- matter, but that case should never come into play). This macro is needed
- to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
- On those machines, we expect that jconfig.h will provide a proper value.
- On machines with 32-bit flat address spaces, any large constant may be used.
-
- NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
- size_t and will be a multiple of sizeof(align_type). }
-
-{$ifdef USE_MSDOS_MEMMGR} { Define this if you use jmemdos.c }
-const
- MAX_ALLOC_CHUNK = long(65520); { Maximum request to malloc() }
-{$else}
-const
- MAX_ALLOC_CHUNK = long(1000000000);
-{$endif}
-
-
-
-{ Initial opening of a backing-store object. This must fill in the
- read/write/close pointers in the object. The read/write routines
- may take an error exit if the specified maximum file size is exceeded.
- (If jpeg_mem_available always returns a large value, this routine can
- just take an error exit.) }
-
-
-EXTERN procedure jpeg_open_backing_store (cinfo : j_common_ptr;
- info : backing_store_ptr;
- total_bytes_needed : long);
-
-
-{ These routines take care of any system-dependent initialization and
- cleanup required. jpeg_mem_init will be called before anything is
- allocated (and, therefore, nothing in cinfo is of use except the error
- manager pointer). It should return a suitable default value for
- max_memory_to_use; this may subsequently be overridden by the surrounding
- application. (Note that max_memory_to_use is only important if
- jpeg_mem_available chooses to consult it ... no one else will.)
- jpeg_mem_term may assume that all requested memory has been freed and that
- all opened backing-store objects have been closed. }
-
-
-EXTERN function jpeg_mem_init (cinfo : j_common_ptr) : long;
-EXTERN procedure jpeg_mem_term (cinfo : j_common_ptr);
-
-
-implementation
-
-{ This structure holds whatever state is needed to access a single
- backing-store object. The read/write/close method pointers are called
- by jmemmgr.c to manipulate the backing-store object; all other fields
- are private to the system-dependent backing store routines. }
-
-
-const
- TEMP_NAME_LENGTH = 64; { max length of a temporary file's name }
-
-{$ifdef USE_MSDOS_MEMMGR} { DOS-specific junk }
-type
- XMSH = ushort; { type of extended-memory handles }
- EMSH = ushort; { type of expanded-memory handles }
-
- handle_union = record
- case byte of
- 0:(file_handle : short); { DOS file handle if it's a temp file }
- 1:(xms_handle : XMSH); { handle if it's a chunk of XMS }
- 2:(ems_handle : EMSH); { handle if it's a chunk of EMS }
- end;
-{$endif - USE_MSDOS_MEMMGR }
-
-type
- backing_store_ptr = ^backing_store_info;
- backing_store_info = record
- { Methods for reading/writing/closing this backing-store object }
- read_backing_store : procedure (cinfo : j_common_ptr;
- info : backing_store_ptr;
- buffer_address : pointer; {far}
- file_offset : long;
- byte_count : long);
- write_backing_store : procedure (cinfo : j_common_ptr;
- info : backing_store_ptr;
- buffer_address : pointer; {far}
- file_offset : long;
- byte_count : long);
-
- close_backing_store : procedure (cinfo : j_common_ptr;
- info : backing_store_ptr);
-
- { Private fields for system-dependent backing-store management }
- {$ifdef USE_MSDOS_MEMMGR}
- { For the MS-DOS manager (jmemdos.c), we need: }
- handle : handle_union; { reference to backing-store storage object }
- temp_name : string[TEMP_NAME_LENGTH]; { name if it's a file }
- {$else}
- { For a typical implementation with temp files, we need: }
- temp_file : FILE; { stdio reference to temp file }
- temp_name : string[TEMP_NAME_LENGTH]; { name of temp file }
- {$endif}
- end;
-
-{ These two functions are used to allocate and release small chunks of
- memory. (Typically the total amount requested through jpeg_get_small is
- no more than 20K or so; this will be requested in chunks of a few K each.)
- Behavior should be the same as for the standard library functions malloc
- and free; in particular, jpeg_get_small must return NIL on failure.
- On most systems, these ARE malloc and free. jpeg_free_small is passed the
- size of the object being freed, just in case it's needed.
- On an 80x86 machine using small-data memory model, these manage near heap. }
-
-EXTERN function jpeg_get_small (cinfo : j_common_ptr;
- sizeofobject : size_t) : pointer;
-EXTERN procedure jpeg_free_small (cinfo : j_common_ptr;
- object : pointer;
- sizeofobject : size_t);
-
-{ These two functions are used to allocate and release large chunks of
- memory (up to the total free space designated by jpeg_mem_available).
- The interface is the same as above, except that on an 80x86 machine,
- far pointers are used. On most other machines these are identical to
- the jpeg_get/free_small routines; but we keep them separate anyway,
- in case a different allocation strategy is desirable for large chunks. }
-
-EXTERN function jpeg_get_large (cinfo : j_common_ptr cinfo;
- sizeofobject : size_t) : pointer; {far}
-
-EXTERN procedure jpeg_free_large (cinfo : j_common_ptr;
- object : pointer; {far}
- sizeofobject : size_t);
-
-
-{ This routine computes the total space still available for allocation by
- jpeg_get_large. If more space than this is needed, backing store will be
- used. NOTE: any memory already allocated must not be counted.
-
- There is a minimum space requirement, corresponding to the minimum
- feasible buffer sizes; jmemmgr.c will request that much space even if
- jpeg_mem_available returns zero. The maximum space needed, enough to hold
- all working storage in memory, is also passed in case it is useful.
- Finally, the total space already allocated is passed. If no better
- method is available, cinfo->mem->max_memory_to_use - already_allocated
- is often a suitable calculation.
-
- It is OK for jpeg_mem_available to underestimate the space available
- (that'll just lead to more backing-store access than is really necessary).
- However, an overestimate will lead to failure. Hence it's wise to subtract
- a slop factor from the true available space. 5% should be enough.
-
- On machines with lots of virtual memory, any large constant may be returned.
- Conversely, zero may be returned to always use the minimum amount of memory.}
-
-
-EXTERN function jpeg_mem_available (cinfo : j_common_ptr;
- min_bytes_needed : long;
- max_bytes_needed : long;
- already_allocated : long) : long;
-
-
-end.
diff --git a/packages/base/pasjpeg/jmorecfg.pas b/packages/base/pasjpeg/jmorecfg.pas
deleted file mode 100644
index 7bd76c95ff..0000000000
--- a/packages/base/pasjpeg/jmorecfg.pas
+++ /dev/null
@@ -1,247 +0,0 @@
-Unit JmoreCfg;
-
-{ This file contains additional configuration options that customize the
- JPEG software for special applications or support machine-dependent
- optimizations. Most users will not need to touch this file. }
-
-{ Source: jmorecfg.h; Copyright (C) 1991-1996, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-{$IFDEF FPC} { Free Pascal Compiler }
- type
- int = longint;
- uInt = Cardinal; { unsigned int }
- short = Integer;
- ushort = Word;
- long = longint;
-{$ELSE}
-{$IFDEF WIN32}
- { Delphi 2.0 }
- type
- int = Integer;
- uInt = Cardinal;
- short = SmallInt;
- ushort = Word;
- long = longint;
- {$ELSE}
- {$IFDEF VIRTUALPASCAL}
- type
- int = longint;
- uInt = longint; { unsigned int }
- short = system.Integer;
- ushort = system.Word;
- long = longint;
- {$ELSE}
- type
- int = Integer;
- uInt = Word; { unsigned int }
- short = Integer;
- ushort = Word;
- long = longint;
- {$ENDIF}
-{$ENDIF}
-{$ENDIF}
-type
- voidp = pointer;
-
-type
- int_ptr = ^int;
- size_t = int;
-
-{ Define BITS_IN_JSAMPLE as either
- 8 for 8-bit sample values (the usual setting)
- 12 for 12-bit sample values
- Only 8 and 12 are legal data precisions for lossy JPEG according to the
- JPEG standard, and the IJG code does not support anything else!
- We do not support run-time selection of data precision, sorry. }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8} { use 8 or 12 }
-const
- BITS_IN_JSAMPLE = 8;
-{$else}
-const
- BITS_IN_JSAMPLE = 12;
-{$endif}
-
-
-
-
-{ Maximum number of components (color channels) allowed in JPEG image.
- To meet the letter of the JPEG spec, set this to 255. However, darn
- few applications need more than 4 channels (maybe 5 for CMYK + alpha
- mask). We recommend 10 as a reasonable compromise; use 4 if you are
- really short on memory. (Each allowed component costs a hundred or so
- bytes of storage, whether actually used in an image or not.) }
-
-
-const
- MAX_COMPONENTS = 10; { maximum number of image components }
-
-
-{ Basic data types.
- You may need to change these if you have a machine with unusual data
- type sizes; for example, "char" not 8 bits, "short" not 16 bits,
- or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits,
- but it had better be at least 16. }
-
-
-{ Representation of a single sample (pixel element value).
- We frequently allocate large arrays of these, so it's important to keep
- them small. But if you have memory to burn and access to char or short
- arrays is very slow on your hardware, you might want to change these. }
-
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-{ JSAMPLE should be the smallest type that will hold the values 0..255.
- You can use a signed char by having GETJSAMPLE mask it with $FF. }
-
-{ CHAR_IS_UNSIGNED }
-type
- JSAMPLE = byte; { Pascal unsigned char }
- GETJSAMPLE = int;
-
-const
- MAXJSAMPLE = 255;
- CENTERJSAMPLE = 128;
-
-{$endif}
-
-{$ifndef BITS_IN_JSAMPLE_IS_8}
-{ JSAMPLE should be the smallest type that will hold the values 0..4095.
- On nearly all machines "short" will do nicely. }
-
-type
- JSAMPLE = short;
- GETJSAMPLE = int;
-
-const
- MAXJSAMPLE = 4095;
- CENTERJSAMPLE = 2048;
-
-{$endif} { BITS_IN_JSAMPLE = 12 }
-
-
-{ Representation of a DCT frequency coefficient.
- This should be a signed value of at least 16 bits; "short" is usually OK.
- Again, we allocate large arrays of these, but you can change to int
- if you have memory to burn and "short" is really slow. }
-type
- JCOEF = int;
- JCOEF_PTR = ^JCOEF;
-
-
-{ Compressed datastreams are represented as arrays of JOCTET.
- These must be EXACTLY 8 bits wide, at least once they are written to
- external storage. Note that when using the stdio data source/destination
- managers, this is also the data type passed to fread/fwrite. }
-
-
-type
- JOCTET = Byte;
- jTOctet = 0..(MaxInt div SizeOf(JOCTET))-1;
- JOCTET_FIELD = array[jTOctet] of JOCTET;
- JOCTET_FIELD_PTR = ^JOCTET_FIELD;
- JOCTETPTR = ^JOCTET;
-
- GETJOCTET = JOCTET; { A work around }
-
-
-{ These typedefs are used for various table entries and so forth.
- They must be at least as wide as specified; but making them too big
- won't cost a huge amount of memory, so we don't provide special
- extraction code like we did for JSAMPLE. (In other words, these
- typedefs live at a different point on the speed/space tradeoff curve.) }
-
-
-{ UINT8 must hold at least the values 0..255. }
-
-type
- UINT8 = byte;
-
-{ UINT16 must hold at least the values 0..65535. }
-
- UINT16 = Word;
-
-{ INT16 must hold at least the values -32768..32767. }
-
- INT16 = int;
-
-{ INT32 must hold at least signed 32-bit values. }
-
- INT32 = longint;
-type
- INT32PTR = ^INT32;
-
-{ Datatype used for image dimensions. The JPEG standard only supports
- images up to 64K*64K due to 16-bit fields in SOF markers. Therefore
- "unsigned int" is sufficient on all machines. However, if you need to
- handle larger images and you don't mind deviating from the spec, you
- can change this datatype. }
-
-type
- JDIMENSION = uInt;
-
-const
- JPEG_MAX_DIMENSION = 65500; { a tad under 64K to prevent overflows }
-
-
-{ Ordering of RGB data in scanlines passed to or from the application.
- If your application wants to deal with data in the order B,G,R, just
- change these macros. You can also deal with formats such as R,G,B,X
- (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing
- the offsets will also change the order in which colormap data is organized.
- RESTRICTIONS:
- 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats.
- 2. These macros only affect RGB<=>YCbCr color conversion, so they are not
- useful if you are using JPEG color spaces other than YCbCr or grayscale.
- 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE
- is not 3 (they don't understand about dummy color components!). So you
- can't use color quantization if you change that value. }
-
-{$ifdef RGB_RED_IS_0}
-const
- RGB_RED = 0; { Offset of Red in an RGB scanline element }
- RGB_GREEN = 1; { Offset of Green }
- RGB_BLUE = 2; { Offset of Blue }
-{$else}
-const
- RGB_RED = 2; { Offset of Red in an RGB scanline element }
- RGB_GREEN = 1; { Offset of Green }
- RGB_BLUE = 0; { Offset of Blue }
-{$endif}
-
-{$ifdef RGB_PIXELSIZE_IS_3}
-const
- RGB_PIXELSIZE = 3; { JSAMPLEs per RGB scanline element }
-{$else}
-const
- RGB_PIXELSIZE = ??; { Nomssi: deliberate syntax error. Set this value }
-{$endif}
-
-{ Definitions for speed-related optimizations. }
-
-{ On some machines (notably 68000 series) "int" is 32 bits, but multiplying
- two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER
- as short on such a machine. MULTIPLIER must be at least 16 bits wide. }
-type
- MULTIPLIER = int; { type for fastest integer multiply }
-
-
-{ FAST_FLOAT should be either float or double, whichever is done faster
- by your compiler. (Note that this type is only used in the floating point
- DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.)
- Typically, float is faster in ANSI C compilers, while double is faster in
- pre-ANSI compilers (because they insist on converting to double anyway).
- The code below therefore chooses float if we have ANSI-style prototypes. }
-
-type
- FAST_FLOAT = double; {float}
-
-
-implementation
-
-
-end.
diff --git a/packages/base/pasjpeg/jpeglib.pas b/packages/base/pasjpeg/jpeglib.pas
deleted file mode 100644
index 2ee4f17c8f..0000000000
--- a/packages/base/pasjpeg/jpeglib.pas
+++ /dev/null
@@ -1,1300 +0,0 @@
-Unit JPEGLib;
-
-{ This file defines the application interface for the JPEG library.
- Most applications using the library need only include this file,
- and perhaps jerror.h if they want to know the exact error codes. }
-
-{ Source:jpeglib.h+jpegint.h; Copyright (C) 1991-1998, Thomas G. Lane. }
-
-
-interface
-
-{$I jconfig.inc}
-
-{ First we include the configuration files that record how this
- installation of the JPEG library is set up. jconfig.h can be
- generated automatically for many systems. jmorecfg.h contains
- manual configuration options that most people need not worry about. }
-
-uses
- jdeferr,
- jmorecfg; { seldom changed options }
-
-{ Version ID for the JPEG library.
- Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". }
-
-
-Const
- JPEG_LIB_VERSION = 62; { Version 6b }
-
-
-{ These marker codes are exported since applications and data source modules
- are likely to want to use them. }
-
-const
- JPEG_RST0 = $D0; { RST0 marker code }
- JPEG_EOI = $D9; { EOI marker code }
- JPEG_APP0 = $E0; { APP0 marker code }
- JPEG_COM = $FE; { COM marker code }
-
-
-{ Various constants determining the sizes of things.
- All of these are specified by the JPEG standard, so don't change them
- if you want to be compatible. }
-
-const
- DCTSIZE = 8; { The basic DCT block is 8x8 samples }
- DCTSIZE2 = 64; { DCTSIZE squared; # of elements in a block }
- NUM_QUANT_TBLS = 4; { Quantization tables are numbered 0..3 }
- NUM_HUFF_TBLS = 4; { Huffman tables are numbered 0..3 }
- NUM_ARITH_TBLS = 16; { Arith-coding tables are numbered 0..15 }
- MAX_COMPS_IN_SCAN = 4; { JPEG limit on # of components in one scan }
- MAX_SAMP_FACTOR = 4; { JPEG limit on sampling factors }
-{ Unfortunately, some bozo at Adobe saw no reason to be bound by the standard;
- the PostScript DCT filter can emit files with many more than 10 blocks/MCU.
- If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU
- to handle it. We even let you do this from the jconfig.h file. However,
- we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe
- sometimes emits noncompliant files doesn't mean you should too. }
- C_MAX_BLOCKS_IN_MCU = 10; { compressor's limit on blocks per MCU }
- D_MAX_BLOCKS_IN_MCU = 10; { decompressor's limit on blocks per MCU }
-
-
-{ Data structures for images (arrays of samples and of DCT coefficients).
- On 80x86 machines, the image arrays are too big for near pointers,
- but the pointer arrays can fit in near memory. }
-
-type
-{ for typecasting }
- JSAMPLE_PTR = ^JSAMPLE;
- JSAMPROW_PTR = ^JSAMPROW;
- JBLOCKROW_PTR = ^JBLOCKROW;
-
- jTSample = 0..(MaxInt div SIZEOF(JSAMPLE))-1;
- JSAMPLE_ARRAY = Array[jTSample] of JSAMPLE; {far}
- JSAMPROW = ^JSAMPLE_ARRAY; { ptr to one image row of pixel samples. }
-
- jTRow = 0..(MaxInt div SIZEOF(JSAMPROW))-1;
- JSAMPROW_ARRAY = Array[jTRow] of JSAMPROW;
- JSAMPARRAY = ^JSAMPROW_ARRAY; { ptr to some rows (a 2-D sample array) }
-
- jTArray = 0..(MaxInt div SIZEOF(JSAMPARRAY))-1;
- JSAMP_ARRAY = Array[jTArray] of JSAMPARRAY;
- JSAMPIMAGE = ^JSAMP_ARRAY; { a 3-D sample array: top index is color }
-
- JBLOCK = Array[0..DCTSIZE2-1] of JCOEF; { one block of coefficients }
- JBLOCK_PTR = ^JBLOCK;
-
- jTBlockRow = 0..(MaxInt div SIZEOF(JBLOCK))-1;
- JBLOCK_ROWS = Array[jTBlockRow] of JBLOCK;
- JBLOCKROW = ^JBLOCK_ROWS; {far} { pointer to one row of coefficient blocks }
-
-
- jTBlockArray = 0..(MaxInt div SIZEOF(JBLOCKROW))-1;
- JBLOCK_ARRAY = Array[jTBlockArray] of JBLOCKROW;
- JBLOCKARRAY = ^JBLOCK_ARRAY; { a 2-D array of coefficient blocks }
-
- jTBlockImage = 0..(MaxInt div SIZEOF(JBLOCKARRAY))-1;
- JBLOCK_IMAGE = Array[jTBlockImage] of JBLOCKARRAY;
- JBLOCKIMAGE = ^JBLOCK_IMAGE; { a 3-D array of coefficient blocks }
-
- jTCoef = 0..(MaxInt div SIZEOF(JCOEF))-1;
- JCOEF_ROW = Array[jTCoef] of JCOEF;
- JCOEFPTR = ^JCOEF_ROW; {far} { useful in a couple of places }
-
-
-type
- jTByte = 0..(MaxInt div SIZEOF(byte))-1;
- JByteArray = Array[jTByte] of byte;
- JBytePtr = ^JByteArray;
-type
- byteptr = ^byte;
-
-{ Types for JPEG compression parameters and working tables. }
-
-
-{ DCT coefficient quantization tables. }
-
-type
- JQUANT_TBL_PTR = ^JQUANT_TBL;
- JQUANT_TBL = record
- { This array gives the coefficient quantizers in natural array order
- (not the zigzag order in which they are stored in a JPEG DQT marker).
- CAUTION: IJG versions prior to v6a kept this array in zigzag order. }
- quantval : Array[0..DCTSIZE2-1] of UINT16;
- { quantization step for each coefficient }
- { This field is used only during compression. It's initialized FALSE when
- the table is created, and set TRUE when it's been output to the file.
- You could suppress output of a table by setting this to TRUE.
- (See jpeg_suppress_tables for an example.) }
- sent_table : boolean; { TRUE when table has been output }
- end;
- JQUANT_TBL_FIELD = Array[0..(MaxInt div SizeOf(JQUANT_TBL))-1] of JQUANT_TBL;
-
-{ Huffman coding tables. }
-
-type
- JHUFF_TBL_PTR = ^JHUFF_TBL;
- JHUFF_TBL = record
- { These two fields directly represent the contents of a JPEG DHT marker }
- bits : Array[0..17-1] of UINT8; { bits[k] = # of symbols with codes of }
- { length k bits; bits[0] is unused }
- huffval : Array[0..256-1] of UINT8;
- { The symbols, in order of incr code length }
- { This field is used only during compression. It's initialized FALSE when
- the table is created, and set TRUE when it's been output to the file.
- You could suppress output of a table by setting this to TRUE.
- (See jpeg_suppress_tables for an example.) }
- sent_table : boolean; { TRUE when table has been output }
- end;
- JHUFF_TBL_FIELD = Array[0..(MaxInt div SizeOf(JHUFF_TBL))-1] of JHUFF_TBL;
-
-{ Declarations for both compression & decompression }
-
-type
- J_BUF_MODE = ( { Operating modes for buffer controllers }
- JBUF_PASS_THRU, { Plain stripwise operation }
- { Remaining modes require a full-image buffer to have been created }
- JBUF_SAVE_SOURCE, { Run source subobject only, save output }
- JBUF_CRANK_DEST, { Run dest subobject only, using saved data }
- JBUF_SAVE_AND_PASS { Run both subobjects, save output }
- );
-
-{ Values of global_state field (jdapi.c has some dependencies on ordering!) }
-const
- CSTATE_START = 100; { after create_compress }
- CSTATE_SCANNING = 101; { start_compress done, write_scanlines OK }
- CSTATE_RAW_OK = 102; { start_compress done, write_raw_data OK }
- CSTATE_WRCOEFS = 103; { jpeg_write_coefficients done }
- DSTATE_START = 200; { after create_decompress }
- DSTATE_INHEADER = 201; { reading header markers, no SOS yet }
- DSTATE_READY = 202; { found SOS, ready for start_decompress }
- DSTATE_PRELOAD = 203; { reading multiscan file in start_decompress}
- DSTATE_PRESCAN = 204; { performing dummy pass for 2-pass quant }
- DSTATE_SCANNING = 205; { start_decompress done, read_scanlines OK }
- DSTATE_RAW_OK = 206; { start_decompress done, read_raw_data OK }
- DSTATE_BUFIMAGE = 207; { expecting jpeg_start_output }
- DSTATE_BUFPOST = 208; { looking for SOS/EOI in jpeg_finish_output }
- DSTATE_RDCOEFS = 209; { reading file in jpeg_read_coefficients }
- DSTATE_STOPPING = 210; { looking for EOI in jpeg_finish_decompress }
-
-
-
-{ Basic info about one component (color channel). }
-
-type
- jpeg_component_info_ptr = ^jpeg_component_info;
- jpeg_component_info = record
- { These values are fixed over the whole image. }
- { For compression, they must be supplied by parameter setup; }
- { for decompression, they are read from the SOF marker. }
- component_id : int; { identifier for this component (0..255) }
- component_index : int; { its index in SOF or cinfo^.comp_info[] }
- h_samp_factor : int; { horizontal sampling factor (1..4) }
- v_samp_factor : int; { vertical sampling factor (1..4) }
- quant_tbl_no : int; { quantization table selector (0..3) }
- { These values may vary between scans. }
- { For compression, they must be supplied by parameter setup; }
- { for decompression, they are read from the SOS marker. }
- { The decompressor output side may not use these variables. }
- dc_tbl_no : int; { DC entropy table selector (0..3) }
- ac_tbl_no : int; { AC entropy table selector (0..3) }
-
- { Remaining fields should be treated as private by applications. }
-
- { These values are computed during compression or decompression startup: }
- { Component's size in DCT blocks.
- Any dummy blocks added to complete an MCU are not counted; therefore
- these values do not depend on whether a scan is interleaved or not. }
- width_in_blocks : JDIMENSION;
- height_in_blocks : JDIMENSION;
- { Size of a DCT block in samples. Always DCTSIZE for compression.
- For decompression this is the size of the output from one DCT block,
- reflecting any scaling we choose to apply during the IDCT step.
- Values of 1,2,4,8 are likely to be supported. Note that different
- components may receive different IDCT scalings. }
-
- DCT_scaled_size : int;
- { The downsampled dimensions are the component's actual, unpadded number
- of samples at the main buffer (preprocessing/compression interface), thus
- downsampled_width = ceil(image_width * Hi/Hmax)
- and similarly for height. For decompression, IDCT scaling is included, so
- downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE)}
-
- downsampled_width : JDIMENSION; { actual width in samples }
- downsampled_height : JDIMENSION; { actual height in samples }
- { This flag is used only for decompression. In cases where some of the
- components will be ignored (eg grayscale output from YCbCr image),
- we can skip most computations for the unused components. }
-
- component_needed : boolean; { do we need the value of this component? }
-
- { These values are computed before starting a scan of the component. }
- { The decompressor output side may not use these variables. }
- MCU_width : int; { number of blocks per MCU, horizontally }
- MCU_height : int; { number of blocks per MCU, vertically }
- MCU_blocks : int; { MCU_width * MCU_height }
- MCU_sample_width : int; { MCU width in samples, MCU_width*DCT_scaled_size }
- last_col_width : int; { # of non-dummy blocks across in last MCU }
- last_row_height : int; { # of non-dummy blocks down in last MCU }
-
- { Saved quantization table for component; NIL if none yet saved.
- See jdinput.c comments about the need for this information.
- This field is currently used only for decompression. }
-
- quant_table : JQUANT_TBL_PTR;
-
- { Private per-component storage for DCT or IDCT subsystem. }
- dct_table : pointer;
- end; { record jpeg_component_info }
-
- jTCinfo = 0..(MaxInt div SizeOf(jpeg_component_info))-1;
- jpeg_component_info_array = array[jTCinfo] of jpeg_component_info;
- jpeg_component_info_list_ptr = ^jpeg_component_info_array;
-
-
-{ The script for encoding a multiple-scan file is an array of these: }
-
-type
- jpeg_scan_info_ptr = ^jpeg_scan_info;
- jpeg_scan_info = record
- comps_in_scan : int; { number of components encoded in this scan }
- component_index : Array[0..MAX_COMPS_IN_SCAN-1] of int;
- { their SOF/comp_info[] indexes }
- Ss, Se : int; { progressive JPEG spectral selection parms }
- Ah, Al : int; { progressive JPEG successive approx. parms }
- end;
-
-{ The decompressor can save APPn and COM markers in a list of these: }
-
-type
- jpeg_saved_marker_ptr = ^jpeg_marker_struct;
- jpeg_marker_struct = record
- next : jpeg_saved_marker_ptr; { next in list, or NULL }
- marker : UINT8; { marker code: JPEG_COM, or JPEG_APP0+n }
- original_length : uint; { # bytes of data in the file }
- data_length : uint; { # bytes of data saved at data[] }
- data : JOCTET_FIELD_PTR; { the data contained in the marker }
- { the marker length word is not counted in data_length or original_length }
- end;
-
-{ Known color spaces. }
-
-type
- J_COLOR_SPACE = (
- JCS_UNKNOWN, { error/unspecified }
- JCS_GRAYSCALE, { monochrome }
- JCS_RGB, { red/green/blue }
- JCS_YCbCr, { Y/Cb/Cr (also known as YUV) }
- JCS_CMYK, { C/M/Y/K }
- JCS_YCCK { Y/Cb/Cr/K }
- );
-
-{ DCT/IDCT algorithm options. }
-
-type
- J_DCT_METHOD = (
- JDCT_ISLOW, { slow but accurate integer algorithm }
- JDCT_IFAST, { faster, less accurate integer method }
- JDCT_FLOAT { floating-point: accurate, fast on fast HW }
- );
-
-const
- JDCT_DEFAULT = JDCT_ISLOW;
- JDCT_FASTEST = JDCT_IFAST;
-
-{ Dithering options for decompression. }
-
-type
- J_DITHER_MODE = (
- JDITHER_NONE, { no dithering }
- JDITHER_ORDERED, { simple ordered dither }
- JDITHER_FS { Floyd-Steinberg error diffusion dither }
- );
-
-
-const
- JPOOL_PERMANENT = 0; { lasts until master record is destroyed }
- JPOOL_IMAGE = 1; { lasts until done with image/datastream }
- JPOOL_NUMPOOLS = 2;
-
-
-{ "Object" declarations for JPEG modules that may be supplied or called
- directly by the surrounding application.
- As with all objects in the JPEG library, these structs only define the
- publicly visible methods and state variables of a module. Additional
- private fields may exist after the public ones. }
-
-
-{ Error handler object }
-
-const
- JMSG_LENGTH_MAX = 200; { recommended size of format_message buffer }
- JMSG_STR_PARM_MAX = 80;
-
-const
- TEMP_NAME_LENGTH = 64; { max length of a temporary file's name }
-type
- TEMP_STRING = string[TEMP_NAME_LENGTH];
-
-{$ifdef USE_MSDOS_MEMMGR} { DOS-specific junk }
-type
- XMSH = ushort; { type of extended-memory handles }
- EMSH = ushort; { type of expanded-memory handles }
-
- handle_union = record
- case byte of
- 0:(file_handle : short); { DOS file handle if it's a temp file }
- 1:(xms_handle : XMSH); { handle if it's a chunk of XMS }
- 2:(ems_handle : EMSH); { handle if it's a chunk of EMS }
- end;
-{$endif} { USE_MSDOS_MEMMGR }
-
-type
- jpeg_error_mgr_ptr = ^jpeg_error_mgr;
- jpeg_memory_mgr_ptr = ^jpeg_memory_mgr;
- jpeg_progress_mgr_ptr = ^jpeg_progress_mgr;
-
-
-{$ifdef common}
-{ Common fields between JPEG compression and decompression master structs. }
- err : jpeg_error_mgr_ptr; { Error handler module }
- mem : jpeg_memory_mgr_ptr; { Memory manager module }
- progress : jpeg_progress_mgr_ptr; { Progress monitor, or NIL if none }
- client_data : voidp; { Available for use by application }
- is_decompressor : boolean; { so common code can tell which is which }
- global_state : int; { for checking call sequence validity }
-{$endif}
-
- j_common_ptr = ^jpeg_common_struct;
- j_compress_ptr = ^jpeg_compress_struct;
- j_decompress_ptr = ^jpeg_decompress_struct;
-
- {$ifdef AM_MEMORY_MANAGER} { only jmemmgr.c defines these }
-
-{ This structure holds whatever state is needed to access a single
- backing-store object. The read/write/close method pointers are called
- by jmemmgr.c to manipulate the backing-store object; all other fields
- are private to the system-dependent backing store routines. }
-
-
- backing_store_ptr = ^backing_store_info;
- backing_store_info = record
- { Methods for reading/writing/closing this backing-store object }
- read_backing_store : procedure (cinfo : j_common_ptr;
- info : backing_store_ptr;
- buffer_address : pointer; {far}
- file_offset : long;
- byte_count : long);
- write_backing_store : procedure (cinfo : j_common_ptr;
- info : backing_store_ptr;
- buffer_address : pointer; {far}
- file_offset : long;
- byte_count : long);
-
- close_backing_store : procedure (cinfo : j_common_ptr;
- info : backing_store_ptr);
-
- { Private fields for system-dependent backing-store management }
- {$ifdef USE_MSDOS_MEMMGR}
- { For the MS-DOS manager (jmemdos.c), we need: }
- handle : handle_union; { reference to backing-store storage object }
- temp_name : TEMP_STRING; { name if it's a file }
- {$else}
- { For a typical implementation with temp files, we need: }
- temp_file : file; { stdio reference to temp file }
- temp_name : TEMP_STRING; { name of temp file }
- {$endif}
- end;
-
-
-{ 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. }
-
- jvirt_sarray_ptr = ^jvirt_sarray_control;
- jvirt_sarray_control = record
- mem_buffer : JSAMPARRAY; { => the in-memory buffer }
- rows_in_array : JDIMENSION; { total virtual array height }
- samplesperrow : JDIMENSION; { width of array (and of memory buffer) }
- maxaccess : JDIMENSION; { max rows accessed by access_virt_sarray }
- rows_in_mem : JDIMENSION; { height of memory buffer }
- rowsperchunk : JDIMENSION; { allocation chunk size in mem_buffer }
- cur_start_row : JDIMENSION; { first logical row # in the buffer }
- first_undef_row : JDIMENSION; { row # of first uninitialized row }
- pre_zero : boolean; { pre-zero mode requested? }
- dirty : boolean; { do current buffer contents need written? }
- b_s_open : boolean; { is backing-store data valid? }
- next : jvirt_sarray_ptr; { link to next virtual sarray control block }
- b_s_info : backing_store_info; { System-dependent control info }
- end;
-
- jvirt_barray_ptr = ^jvirt_barray_control;
- jvirt_barray_control = record
- mem_buffer : JBLOCKARRAY; { => the in-memory buffer }
- rows_in_array : JDIMENSION; { total virtual array height }
- blocksperrow : JDIMENSION; { width of array (and of memory buffer) }
- maxaccess : JDIMENSION; { max rows accessed by access_virt_barray }
- rows_in_mem : JDIMENSION; { height of memory buffer }
- rowsperchunk : JDIMENSION; { allocation chunk size in mem_buffer }
- cur_start_row : JDIMENSION; { first logical row # in the buffer }
- first_undef_row : JDIMENSION; { row # of first uninitialized row }
- pre_zero : boolean; { pre-zero mode requested? }
- dirty : boolean; { do current buffer contents need written? }
- b_s_open : boolean; { is backing-store data valid? }
- next : jvirt_barray_ptr; { link to next virtual barray control block }
- b_s_info : backing_store_info; { System-dependent control info }
- end;
-
- {$endif} { AM_MEMORY_MANAGER }
-
-{ Declarations for compression modules }
-
-{ Master control module }
- jpeg_comp_master_ptr = ^jpeg_comp_master;
- jpeg_comp_master = record
- prepare_for_pass : procedure(cinfo : j_compress_ptr);
- pass_startup : procedure(cinfo : j_compress_ptr);
- finish_pass : procedure(cinfo : j_compress_ptr);
-
- { State variables made visible to other modules }
- call_pass_startup : Boolean; { True if pass_startup must be called }
- is_last_pass : Boolean; { True during last pass }
- end;
-
-{ Main buffer control (downsampled-data buffer) }
- jpeg_c_main_controller_ptr = ^jpeg_c_main_controller;
- jpeg_c_main_controller = record
- start_pass : procedure(cinfo : j_compress_ptr; pass_mode : J_BUF_MODE);
- process_data : procedure(cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- var in_row_ctr : JDIMENSION;
- in_rows_avail : JDIMENSION);
- end;
-
-{ Compression preprocessing (downsampling input buffer control) }
- jpeg_c_prep_controller_ptr = ^jpeg_c_prep_controller;
- jpeg_c_prep_controller = record
- start_pass : procedure(cinfo : j_compress_ptr; pass_mode : J_BUF_MODE);
- pre_process_data : procedure(cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- var in_row_ctr : JDIMENSION;
- in_rows_avail : JDIMENSION;
- output_buf : JSAMPIMAGE;
- var out_row_group_ctr : JDIMENSION;
- out_row_groups_avail : JDIMENSION);
- end;
-
-{ Coefficient buffer control }
- jpeg_c_coef_controller_ptr = ^jpeg_c_coef_controller;
- jpeg_c_coef_controller = record
- start_pass : procedure(cinfo : j_compress_ptr; pass_mode : J_BUF_MODE);
- compress_data : function(cinfo : j_compress_ptr;
- input_buf : JSAMPIMAGE) : boolean;
- end;
-
-{ Colorspace conversion }
- jpeg_color_converter_ptr = ^jpeg_color_converter;
- jpeg_color_converter = record
- start_pass : procedure(cinfo : j_compress_ptr);
- color_convert : procedure(cinfo : j_compress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPIMAGE;
- output_row : JDIMENSION;
- num_rows : int);
- end;
-
-{ Downsampling }
- jpeg_downsampler_ptr = ^jpeg_downsampler;
- jpeg_downsampler = record
- start_pass : procedure(cinfo : j_compress_ptr);
- downsample : procedure(cinfo : j_compress_ptr;
- input_buf : JSAMPIMAGE;
- in_row_index : JDIMENSION;
- output_buf : JSAMPIMAGE;
- out_row_group_index: JDIMENSION);
- need_context_rows : Boolean; { TRUE if need rows above & below }
- end;
-
-{ Forward DCT (also controls coefficient quantization) }
- jpeg_forward_dct_ptr = ^jpeg_forward_dct;
- jpeg_forward_dct = record
- start_pass : procedure(cinfo : j_compress_ptr);
- { perhaps this should be an array??? }
- forward_DCT : procedure(cinfo : j_compress_ptr;
- compptr : jpeg_component_info_ptr;
- sample_data : JSAMPARRAY;
- coef_blocks : JBLOCKROW;
- start_row : JDIMENSION;
- start_col : JDIMENSION;
- num_blocks : JDIMENSION);
- end;
-
-{ Entropy encoding }
-
- jpeg_entropy_encoder_ptr = ^jpeg_entropy_encoder;
- jpeg_entropy_encoder = record
- start_pass : procedure(cinfo : j_compress_ptr; gather_statistics : boolean);
- encode_mcu : function(cinfo : j_compress_ptr;
- const MCU_data: array of JBLOCKROW) : boolean;
- finish_pass : procedure(cinfo : j_compress_ptr);
- end;
-
-{ Marker writing }
- jpeg_marker_writer_ptr = ^jpeg_marker_writer;
- jpeg_marker_writer = record
- write_file_header : procedure(cinfo : j_compress_ptr);
- write_frame_header : procedure(cinfo : j_compress_ptr);
- write_scan_header : procedure(cinfo : j_compress_ptr);
- write_file_trailer : procedure(cinfo : j_compress_ptr);
- write_tables_only : procedure(cinfo : j_compress_ptr);
- { These routines are exported to allow insertion of extra markers }
- { Probably only COM and APPn markers should be written this way }
- write_marker_header : procedure (cinfo : j_compress_ptr;
- marker : int;
- datalen : uint);
- write_marker_byte : procedure (cinfo : j_compress_ptr; val : int);
- end;
-
-{ Declarations for decompression modules }
-
-{ Master control module }
- jpeg_decomp_master_ptr = ^jpeg_decomp_master;
- jpeg_decomp_master = record
- prepare_for_output_pass : procedure( cinfo : j_decompress_ptr);
- finish_output_pass : procedure(cinfo : j_decompress_ptr);
-
- { State variables made visible to other modules }
- is_dummy_pass : Boolean; { True during 1st pass for 2-pass quant }
- end;
-
-{ Input control module }
- jpeg_input_controller_ptr = ^jpeg_input_controller;
- jpeg_input_controller = record
- consume_input : function (cinfo : j_decompress_ptr) : int;
- reset_input_controller : procedure(cinfo : j_decompress_ptr);
- start_input_pass : procedure(cinfo : j_decompress_ptr);
- finish_input_pass : procedure(cinfo : j_decompress_ptr);
-
- { State variables made visible to other modules }
- has_multiple_scans : Boolean; { True if file has multiple scans }
- eoi_reached : Boolean; { True when EOI has been consumed }
- end;
-
-{ Main buffer control (downsampled-data buffer) }
-
- jpeg_d_main_controller_ptr = ^jpeg_d_main_controller;
- jpeg_d_main_controller = record
- start_pass : procedure(cinfo : j_decompress_ptr; pass_mode : J_BUF_MODE);
- process_data : procedure(cinfo : j_decompress_ptr;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION);
- end;
-
-{ Coefficient buffer control }
- jvirt_barray_tbl = array[0..MAX_COMPONENTS-1] of jvirt_barray_ptr;
- jvirt_barray_tbl_ptr = ^jvirt_barray_tbl;
- jpeg_d_coef_controller_ptr = ^jpeg_d_coef_controller;
- jpeg_d_coef_controller = record
- start_input_pass : procedure(cinfo : j_decompress_ptr);
- consume_data : function (cinfo : j_decompress_ptr) : int;
- start_output_pass : procedure(cinfo : j_decompress_ptr);
- decompress_data : function (cinfo : j_decompress_ptr;
- output_buf : JSAMPIMAGE) : int;
- { Pointer to array of coefficient virtual arrays, or NIL if none }
- coef_arrays : jvirt_barray_tbl_ptr;
- end;
-
-{ Decompression postprocessing (color quantization buffer control) }
- jpeg_d_post_controller_ptr = ^jpeg_d_post_controller;
- jpeg_d_post_controller = record
- start_pass : procedure(cinfo : j_decompress_ptr;
- pass_mode : J_BUF_MODE);
- post_process_data : procedure(cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- var in_row_group_ctr : JDIMENSION;
- in_row_groups_avail : JDIMENSION;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION);
- end;
-
-
-{ Routine signature for application-supplied marker processing methods.
- Need not pass marker code since it is stored in cinfo^.unread_marker. }
-
- jpeg_marker_parser_method = function(cinfo : j_decompress_ptr) : boolean;
-
-{ Marker reading & parsing }
- jpeg_marker_reader_ptr = ^jpeg_marker_reader;
- jpeg_marker_reader = record
- reset_marker_reader : procedure(cinfo : j_decompress_ptr);
- { Read markers until SOS or EOI.
- Returns same codes as are defined for jpeg_consume_input:
- JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. }
-
- read_markers : function (cinfo : j_decompress_ptr) : int;
- { Read a restart marker --- exported for use by entropy decoder only }
- read_restart_marker : jpeg_marker_parser_method;
-
- { State of marker reader --- nominally internal, but applications
- supplying COM or APPn handlers might like to know the state. }
-
- saw_SOI : boolean; { found SOI? }
- saw_SOF : boolean; { found SOF? }
- next_restart_num : int; { next restart number expected (0-7) }
- discarded_bytes : uint; { # of bytes skipped looking for a marker }
- end;
-
-{ Entropy decoding }
- jpeg_entropy_decoder_ptr = ^jpeg_entropy_decoder;
- jpeg_entropy_decoder = record
- start_pass : procedure(cinfo : j_decompress_ptr);
- decode_mcu : function(cinfo : j_decompress_ptr;
- var MCU_data : array of JBLOCKROW) : boolean;
- { This is here to share code between baseline and progressive decoders; }
- { other modules probably should not use it }
- insufficient_data : BOOLEAN; { set TRUE after emitting warning }
- end;
-
-{ Inverse DCT (also performs dequantization) }
- inverse_DCT_method_ptr = procedure(cinfo : j_decompress_ptr;
- compptr : jpeg_component_info_ptr;
- coef_block : JCOEFPTR;
- output_buf : JSAMPARRAY; output_col : JDIMENSION);
-
- jpeg_inverse_dct_ptr = ^jpeg_inverse_dct;
- jpeg_inverse_dct = record
- start_pass : procedure(cinfo : j_decompress_ptr);
- { It is useful to allow each component to have a separate IDCT method. }
- inverse_DCT : Array[0..MAX_COMPONENTS-1] of inverse_DCT_method_ptr;
- end;
-
-{ Upsampling (note that upsampler must also call color converter) }
- jpeg_upsampler_ptr = ^jpeg_upsampler;
- jpeg_upsampler = record
- start_pass : procedure(cinfo : j_decompress_ptr);
- upsample : procedure(cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- var in_row_group_ctr : JDIMENSION; { array of }
- in_row_groups_avail : JDIMENSION;
- output_buf : JSAMPARRAY;
- var out_row_ctr : JDIMENSION;
- out_rows_avail : JDIMENSION);
-
- need_context_rows : boolean; { TRUE if need rows above & below }
- end;
-
-{ Colorspace conversion }
- jpeg_color_deconverter_ptr = ^jpeg_color_deconverter;
- jpeg_color_deconverter = record
- start_pass : procedure(cinfo: j_decompress_ptr);
- color_convert : procedure(cinfo : j_decompress_ptr;
- input_buf : JSAMPIMAGE;
- input_row : JDIMENSION;
- output_buf : JSAMPARRAY;
- num_rows : int);
- end;
-
-{ Color quantization or color precision reduction }
- jpeg_color_quantizer_ptr = ^jpeg_color_quantizer;
- jpeg_color_quantizer = record
- start_pass : procedure(cinfo : j_decompress_ptr; is_pre_scan : boolean);
- color_quantize : procedure(cinfo : j_decompress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPARRAY;
- num_rows : int);
-
- finish_pass : procedure(cinfo : j_decompress_ptr);
- new_color_map : procedure(cinfo : j_decompress_ptr);
- end;
-
- {int8array = Array[0..8-1] of int;}
- int8array = Array[0..8-1] of longint; { for TP FormatStr }
-
- jpeg_error_mgr = record
- { Error exit handler: does not return to caller }
- error_exit : procedure (cinfo : j_common_ptr);
- { Conditionally emit a trace or warning message }
- emit_message : procedure (cinfo : j_common_ptr; msg_level : int);
- { Routine that actually outputs a trace or error message }
- output_message : procedure (cinfo : j_common_ptr);
- { Format a message string for the most recent JPEG error or message }
- format_message : procedure (cinfo : j_common_ptr; var buffer : string);
-
- { Reset error state variables at start of a new image }
- reset_error_mgr : procedure (cinfo : j_common_ptr);
-
- { The message ID code and any parameters are saved here.
- A message can have one string parameter or up to 8 int parameters. }
-
- msg_code : int;
-
- msg_parm : record
- case byte of
- 0:(i : int8array);
- 1:(s : string[JMSG_STR_PARM_MAX]);
- end;
-
- { Standard state variables for error facility }
-
- trace_level : int; { max msg_level that will be displayed }
-
- { For recoverable corrupt-data errors, we emit a warning message,
- but keep going unless emit_message chooses to abort. emit_message
- should count warnings in num_warnings. The surrounding application
- can check for bad data by seeing if num_warnings is nonzero at the
- end of processing. }
-
- num_warnings : long; { number of corrupt-data warnings }
-
- { These fields point to the table(s) of error message strings.
- An application can change the table pointer to switch to a different
- message list (typically, to change the language in which errors are
- reported). Some applications may wish to add additional error codes
- that will be handled by the JPEG library error mechanism; the second
- table pointer is used for this purpose.
-
- First table includes all errors generated by JPEG library itself.
- Error code 0 is reserved for a "no such error string" message. }
-
- {const char * const * jpeg_message_table; }
- jpeg_message_table : ^msg_table; { Library errors }
-
- last_jpeg_message : J_MESSAGE_CODE;
- { Table contains strings 0..last_jpeg_message }
- { Second table can be added by application (see cjpeg/djpeg for example).
- It contains strings numbered first_addon_message..last_addon_message. }
-
- {const char * const * addon_message_table; }
- addon_message_table : ^msg_table; { Non-library errors }
-
- first_addon_message : J_MESSAGE_CODE; { code for first string in addon table }
- last_addon_message : J_MESSAGE_CODE; { code for last string in addon table }
- end;
-
-
-{ Progress monitor object }
-
- jpeg_progress_mgr = record
- progress_monitor : procedure(cinfo : j_common_ptr);
-
- pass_counter : long; { work units completed in this pass }
- pass_limit : long; { total number of work units in this pass }
- completed_passes : int; { passes completed so far }
- total_passes : int; { total number of passes expected }
- end;
-
-
-{ Data destination object for compression }
- jpeg_destination_mgr_ptr = ^jpeg_destination_mgr;
- jpeg_destination_mgr = record
- next_output_byte : JOCTETptr; { => next byte to write in buffer }
- free_in_buffer : size_t; { # of byte spaces remaining in buffer }
-
- init_destination : procedure (cinfo : j_compress_ptr);
- empty_output_buffer : function (cinfo : j_compress_ptr) : boolean;
- term_destination : procedure (cinfo : j_compress_ptr);
- end;
-
-
-{ Data source object for decompression }
-
- jpeg_source_mgr_ptr = ^jpeg_source_mgr;
- jpeg_source_mgr = record
- {const JOCTET * next_input_byte;}
- next_input_byte : JOCTETptr; { => next byte to read from buffer }
- bytes_in_buffer : size_t; { # of bytes remaining in buffer }
-
- init_source : procedure (cinfo : j_decompress_ptr);
- fill_input_buffer : function (cinfo : j_decompress_ptr) : boolean;
- skip_input_data : procedure (cinfo : j_decompress_ptr; num_bytes : long);
- resync_to_restart : function (cinfo : j_decompress_ptr;
- desired : int) : boolean;
- term_source : procedure (cinfo : j_decompress_ptr);
- end;
-
-
-{ Memory manager object.
- Allocates "small" objects (a few K total), "large" objects (tens of K),
- and "really big" objects (virtual arrays with backing store if needed).
- The memory manager does not allow individual objects to be freed; rather,
- each created object is assigned to a pool, and whole pools can be freed
- at once. This is faster and more convenient than remembering exactly what
- to free, especially where malloc()/free() are not too speedy.
- NB: alloc routines never return NIL. They exit to error_exit if not
- successful. }
-
-
- jpeg_memory_mgr = record
- { Method pointers }
- alloc_small : function (cinfo : j_common_ptr; pool_id : int;
- sizeofobject : size_t) : pointer;
- alloc_large : function (cinfo : j_common_ptr; pool_id : int;
- sizeofobject : size_t) : pointer; {far}
- alloc_sarray : function (cinfo : j_common_ptr; pool_id : int;
- samplesperrow : JDIMENSION;
- numrows : JDIMENSION) : JSAMPARRAY;
-
- alloc_barray : function (cinfo : j_common_ptr; pool_id : int;
- blocksperrow : JDIMENSION;
- numrows : JDIMENSION) : JBLOCKARRAY;
-
- request_virt_sarray : function(cinfo : j_common_ptr;
- pool_id : int;
- pre_zero : boolean;
- samplesperrow : JDIMENSION;
- numrows : JDIMENSION;
- maxaccess : JDIMENSION) : jvirt_sarray_ptr;
-
- request_virt_barray : function(cinfo : j_common_ptr;
- pool_id : int;
- pre_zero : boolean;
- blocksperrow : JDIMENSION;
- numrows : JDIMENSION;
- maxaccess : JDIMENSION) : jvirt_barray_ptr;
-
- realize_virt_arrays : procedure (cinfo : j_common_ptr);
-
- access_virt_sarray : function (cinfo : j_common_ptr;
- ptr : jvirt_sarray_ptr;
- start_row : JDIMENSION;
- num_rows : JDIMENSION;
- writable : boolean) : JSAMPARRAY;
-
- access_virt_barray : function (cinfo : j_common_ptr;
- ptr : jvirt_barray_ptr;
- start_row : JDIMENSION;
- num_rows : JDIMENSION;
- writable : boolean) : JBLOCKARRAY;
-
- free_pool : procedure (cinfo : j_common_ptr; pool_id : int);
- self_destruct : procedure (cinfo : j_common_ptr);
-
- { Limit on memory allocation for this JPEG object. (Note that this is
- merely advisory, not a guaranteed maximum; it only affects the space
- used for virtual-array buffers.) May be changed by outer application
- after creating the JPEG object. }
- max_memory_to_use : long;
-
- { Maximum allocation request accepted by alloc_large. }
- max_alloc_chunk : long;
- end;
-
-{ Routines that are to be used by both halves of the library are declared
- to receive a pointer to this structure. There are no actual instances of
- jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct.}
- jpeg_common_struct = record
- { Fields common to both master struct types }
- err : jpeg_error_mgr_ptr; { Error handler module }
- mem : jpeg_memory_mgr_ptr; { Memory manager module }
- progress : jpeg_progress_mgr_ptr; { Progress monitor, or NIL if none }
- client_data : voidp; { Available for use by application }
- is_decompressor : boolean; { so common code can tell which is which }
- global_state : int; { for checking call sequence validity }
-
- { Additional fields follow in an actual jpeg_compress_struct or
- jpeg_decompress_struct. All three structs must agree on these
- initial fields! (This would be a lot cleaner in C++.) }
- end;
-
-
-{ Master record for a compression instance }
-
- jpeg_compress_struct = record
- { Fields shared with jpeg_decompress_struct }
- err : jpeg_error_mgr_ptr; { Error handler module }
- mem : jpeg_memory_mgr_ptr; { Memory manager module }
- progress : jpeg_progress_mgr_ptr; { Progress monitor, or NIL if none }
- client_data : voidp; { Available for use by application }
- is_decompressor : boolean; { so common code can tell which is which }
- global_state : int; { for checking call sequence validity }
-
- { Destination for compressed data }
- dest : jpeg_destination_mgr_ptr;
-
- { Description of source image --- these fields must be filled in by
- outer application before starting compression. in_color_space must
- be correct before you can even call jpeg_set_defaults(). }
-
-
- image_width : JDIMENSION; { input image width }
- image_height : JDIMENSION; { input image height }
- input_components : int; { # of color components in input image }
- in_color_space : J_COLOR_SPACE; { colorspace of input image }
-
- input_gamma : double; { image gamma of input image }
-
- { Compression parameters --- these fields must be set before calling
- jpeg_start_compress(). We recommend calling jpeg_set_defaults() to
- initialize everything to reasonable defaults, then changing anything
- the application specifically wants to change. That way you won't get
- burnt when new parameters are added. Also note that there are several
- helper routines to simplify changing parameters. }
-
- data_precision : int; { bits of precision in image data }
-
- num_components : int; { # of color components in JPEG image }
- jpeg_color_space : J_COLOR_SPACE; { colorspace of JPEG image }
-
- comp_info : jpeg_component_info_list_ptr;
- { comp_info^[i] describes component that appears i'th in SOF }
-
- quant_tbl_ptrs: Array[0..NUM_QUANT_TBLS-1] of JQUANT_TBL_PTR;
- { ptrs to coefficient quantization tables, or NIL if not defined }
-
- dc_huff_tbl_ptrs : Array[0..NUM_HUFF_TBLS-1] of JHUFF_TBL_PTR;
- ac_huff_tbl_ptrs : Array[0..NUM_HUFF_TBLS-1] of JHUFF_TBL_PTR;
- { ptrs to Huffman coding tables, or NIL if not defined }
-
- arith_dc_L : Array[0..NUM_ARITH_TBLS-1] of UINT8; { L values for DC arith-coding tables }
- arith_dc_U : Array[0..NUM_ARITH_TBLS-1] of UINT8; { U values for DC arith-coding tables }
- arith_ac_K : Array[0..NUM_ARITH_TBLS-1] of UINT8; { Kx values for AC arith-coding tables }
-
- num_scans : int; { # of entries in scan_info array }
- scan_info : jpeg_scan_info_ptr; { script for multi-scan file, or NIL }
- { The default value of scan_info is NIL, which causes a single-scan
- sequential JPEG file to be emitted. To create a multi-scan file,
- set num_scans and scan_info to point to an array of scan definitions. }
-
- raw_data_in : boolean; { TRUE=caller supplies downsampled data }
- arith_code : boolean; { TRUE=arithmetic coding, FALSE=Huffman }
- optimize_coding : boolean; { TRUE=optimize entropy encoding parms }
- CCIR601_sampling : boolean; { TRUE=first samples are cosited }
- smoothing_factor : int; { 1..100, or 0 for no input smoothing }
- dct_method : J_DCT_METHOD; { DCT algorithm selector }
-
- { The restart interval can be specified in absolute MCUs by setting
- restart_interval, or in MCU rows by setting restart_in_rows
- (in which case the correct restart_interval will be figured
- for each scan). }
-
- restart_interval : uint; { MCUs per restart, or 0 for no restart }
- restart_in_rows : int; { if > 0, MCU rows per restart interval }
-
- { Parameters controlling emission of special markers. }
-
- write_JFIF_header : boolean; { should a JFIF marker be written? }
- JFIF_major_version : UINT8; { What to write for the JFIF version number }
- JFIF_minor_version : UINT8;
- { These three values are not used by the JPEG code, merely copied }
- { into the JFIF APP0 marker. density_unit can be 0 for unknown, }
- { 1 for dots/inch, or 2 for dots/cm. Note that the pixel aspect }
- { ratio is defined by X_density/Y_density even when density_unit=0. }
- density_unit : UINT8; { JFIF code for pixel size units }
- X_density : UINT16; { Horizontal pixel density }
- Y_density : UINT16; { Vertical pixel density }
- write_Adobe_marker : boolean; { should an Adobe marker be written? }
-
- { State variable: index of next scanline to be written to
- jpeg_write_scanlines(). Application may use this to control its
- processing loop, e.g., "while (next_scanline < image_height)". }
-
- next_scanline : JDIMENSION; { 0 .. image_height-1 }
-
- { Remaining fields are known throughout compressor, but generally
- should not be touched by a surrounding application. }
-
- { These fields are computed during compression startup }
- progressive_mode : boolean; { TRUE if scan script uses progressive mode }
- max_h_samp_factor : int; { largest h_samp_factor }
- max_v_samp_factor : int; { largest v_samp_factor }
-
- total_iMCU_rows : JDIMENSION; { # of iMCU rows to be input to coef ctlr }
- { The coefficient controller receives data in units of MCU rows as defined
- for fully interleaved scans (whether the JPEG file is interleaved or not).
- There are v_samp_factor * DCTSIZE sample rows of each component in an
- "iMCU" (interleaved MCU) row. }
-
- { These fields are valid during any one scan.
- They describe the components and MCUs actually appearing in the scan. }
-
- comps_in_scan : int; { # of JPEG components in this scan }
- cur_comp_info : Array[0..MAX_COMPS_IN_SCAN-1] of jpeg_component_info_ptr;
- { cur_comp_info[i]^ describes component that appears i'th in SOS }
-
- MCUs_per_row : JDIMENSION; { # of MCUs across the image }
- MCU_rows_in_scan : JDIMENSION;{ # of MCU rows in the image }
-
- blocks_in_MCU : int; { # of DCT blocks per MCU }
- MCU_membership : Array[0..C_MAX_BLOCKS_IN_MCU-1] of int;
- { MCU_membership[i] is index in cur_comp_info of component owning }
- { i'th block in an MCU }
-
- Ss, Se, Ah, Al : int; { progressive JPEG parameters for scan }
-
- { Links to compression subobjects (methods and private variables of modules) }
- master : jpeg_comp_master_ptr;
- main : jpeg_c_main_controller_ptr;
- prep : jpeg_c_prep_controller_ptr;
- coef : jpeg_c_coef_controller_ptr;
- marker : jpeg_marker_writer_ptr;
- cconvert : jpeg_color_converter_ptr;
- downsample : jpeg_downsampler_ptr;
- fdct : jpeg_forward_dct_ptr;
- entropy : jpeg_entropy_encoder_ptr;
- script_space : jpeg_scan_info_ptr; { workspace for jpeg_simple_progression }
- script_space_size : int;
- end;
-
-
-{ Master record for a decompression instance }
-
- coef_bits_field = Array[0..DCTSIZE2-1] of int;
- coef_bits_ptr = ^coef_bits_field;
- coef_bits_ptrfield = Array[0..MAX_COMPS_IN_SCAN-1] of coef_bits_field;
- coef_bits_ptrrow = ^coef_bits_ptrfield;
-
- range_limit_table = array[-(MAXJSAMPLE+1)..4*(MAXJSAMPLE+1)
- + CENTERJSAMPLE -1] of JSAMPLE;
- range_limit_table_ptr = ^range_limit_table;
-
- jpeg_decompress_struct = record
- { Fields shared with jpeg_compress_struct }
- err : jpeg_error_mgr_ptr; { Error handler module }
- mem : jpeg_memory_mgr_ptr; { Memory manager module }
- progress : jpeg_progress_mgr_ptr; { Progress monitor, or NIL if none }
- client_data : voidp; { Available for use by application }
- is_decompressor : boolean; { so common code can tell which is which }
- global_state : int; { for checking call sequence validity }
-
- { Source of compressed data }
- src : jpeg_source_mgr_ptr;
-
- { Basic description of image --- filled in by jpeg_read_header(). }
- { Application may inspect these values to decide how to process image. }
-
- image_width : JDIMENSION; { nominal image width (from SOF marker) }
- image_height : JDIMENSION; { nominal image height }
- num_components : int; { # of color components in JPEG image }
- jpeg_color_space : J_COLOR_SPACE; { colorspace of JPEG image }
-
- { Decompression processing parameters --- these fields must be set before
- calling jpeg_start_decompress(). Note that jpeg_read_header()
- initializes them to default values. }
-
- out_color_space : J_COLOR_SPACE; { colorspace for output }
-
- scale_num, scale_denom : uint ; { fraction by which to scale image }
-
- output_gamma : double; { image gamma wanted in output }
-
- buffered_image : boolean; { TRUE=multiple output passes }
- raw_data_out : boolean; { TRUE=downsampled data wanted }
-
- dct_method : J_DCT_METHOD; { IDCT algorithm selector }
- do_fancy_upsampling : boolean; { TRUE=apply fancy upsampling }
- do_block_smoothing : boolean; { TRUE=apply interblock smoothing }
-
- quantize_colors : boolean; { TRUE=colormapped output wanted }
- { the following are ignored if not quantize_colors: }
- dither_mode : J_DITHER_MODE; { type of color dithering to use }
- two_pass_quantize : boolean; { TRUE=use two-pass color quantization }
- desired_number_of_colors : int; { max # colors to use in created colormap }
- { these are significant only in buffered-image mode: }
- enable_1pass_quant : boolean; { enable future use of 1-pass quantizer }
- enable_external_quant : boolean; { enable future use of external colormap }
- enable_2pass_quant : boolean; { enable future use of 2-pass quantizer }
-
- { Description of actual output image that will be returned to application.
- These fields are computed by jpeg_start_decompress().
- You can also use jpeg_calc_output_dimensions() to determine these values
- in advance of calling jpeg_start_decompress(). }
-
- output_width : JDIMENSION; { scaled image width }
- output_height: JDIMENSION; { scaled image height }
- out_color_components : int; { # of color components in out_color_space }
- output_components : int; { # of color components returned }
- { output_components is 1 (a colormap index) when quantizing colors;
- otherwise it equals out_color_components. }
-
- rec_outbuf_height : int; { min recommended height of scanline buffer }
- { If the buffer passed to jpeg_read_scanlines() is less than this many
- rows high, space and time will be wasted due to unnecessary data
- copying. Usually rec_outbuf_height will be 1 or 2, at most 4. }
-
- { When quantizing colors, the output colormap is described by these
- fields. The application can supply a colormap by setting colormap
- non-NIL before calling jpeg_start_decompress; otherwise a colormap
- is created during jpeg_start_decompress or jpeg_start_output. The map
- has out_color_components rows and actual_number_of_colors columns. }
-
- actual_number_of_colors : int; { number of entries in use }
- colormap : JSAMPARRAY; { The color map as a 2-D pixel array }
-
- { State variables: these variables indicate the progress of decompression.
- The application may examine these but must not modify them. }
-
- { Row index of next scanline to be read from jpeg_read_scanlines().
- Application may use this to control its processing loop, e.g.,
- "while (output_scanline < output_height)". }
-
- output_scanline : JDIMENSION; { 0 .. output_height-1 }
-
- { Current input scan number and number of iMCU rows completed in scan.
- These indicate the progress of the decompressor input side. }
-
- input_scan_number : int; { Number of SOS markers seen so far }
- input_iMCU_row : JDIMENSION; { Number of iMCU rows completed }
-
- { The "output scan number" is the notional scan being displayed by the
- output side. The decompressor will not allow output scan/row number
- to get ahead of input scan/row, but it can fall arbitrarily far behind.}
-
- output_scan_number : int; { Nominal scan number being displayed }
- output_iMCU_row : int; { Number of iMCU rows read }
-
- { Current progression status. coef_bits[c][i] indicates the precision
- with which component c's DCT coefficient i (in zigzag order) is known.
- It is -1 when no data has yet been received, otherwise it is the point
- transform (shift) value for the most recent scan of the coefficient
- (thus, 0 at completion of the progression).
- This pointer is NIL when reading a non-progressive file. }
-
- coef_bits : coef_bits_ptrrow;
- { -1 or current Al value for each coef }
-
- { Internal JPEG parameters --- the application usually need not look at
- these fields. Note that the decompressor output side may not use
- any parameters that can change between scans. }
-
- { Quantization and Huffman tables are carried forward across input
- datastreams when processing abbreviated JPEG datastreams. }
-
- quant_tbl_ptrs : Array[0..NUM_QUANT_TBLS-1] of JQUANT_TBL_PTR;
- { ptrs to coefficient quantization tables, or NIL if not defined }
-
- dc_huff_tbl_ptrs : Array[0..NUM_HUFF_TBLS-1] of JHUFF_TBL_PTR;
- ac_huff_tbl_ptrs : Array[0..NUM_HUFF_TBLS-1] of JHUFF_TBL_PTR;
- { ptrs to Huffman coding tables, or NIL if not defined }
-
- { These parameters are never carried across datastreams, since they
- are given in SOF/SOS markers or defined to be reset by SOI. }
-
- data_precision : int; { bits of precision in image data }
-
- comp_info : jpeg_component_info_list_ptr;
- { comp_info^[i] describes component that appears i'th in SOF }
-
- progressive_mode : boolean; { TRUE if SOFn specifies progressive mode }
- arith_code : boolean; { TRUE=arithmetic coding, FALSE=Huffman }
-
- arith_dc_L : Array[0..NUM_ARITH_TBLS-1] of UINT8; { L values for DC arith-coding tables }
- arith_dc_U : Array[0..NUM_ARITH_TBLS-1] of UINT8; { U values for DC arith-coding tables }
- arith_ac_K : Array[0..NUM_ARITH_TBLS-1] of UINT8; { Kx values for AC arith-coding tables }
-
- restart_interval : uint; { MCUs per restart interval, or 0 for no restart }
-
- { These fields record data obtained from optional markers recognized by
- the JPEG library. }
-
- saw_JFIF_marker : boolean; { TRUE iff a JFIF APP0 marker was found }
- { Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: }
- JFIF_major_version : UINT8; { JFIF version number }
- JFIF_minor_version : UINT8;
- density_unit : UINT8; { JFIF code for pixel size units }
- X_density : UINT16; { Horizontal pixel density }
- Y_density : UINT16; { Vertical pixel density }
- saw_Adobe_marker : boolean; { TRUE iff an Adobe APP14 marker was found }
- Adobe_transform : UINT8; { Color transform code from Adobe marker }
-
- CCIR601_sampling : boolean; { TRUE=first samples are cosited }
-
- { Aside from the specific data retained from APPn markers known to the
- library, the uninterpreted contents of any or all APPn and COM markers
- can be saved in a list for examination by the application. }
-
- marker_list : jpeg_saved_marker_ptr; { Head of list of saved markers }
-
- { Remaining fields are known throughout decompressor, but generally
- should not be touched by a surrounding application. }
-
-
- { These fields are computed during decompression startup }
-
- max_h_samp_factor : int; { largest h_samp_factor }
- max_v_samp_factor : int; { largest v_samp_factor }
-
- min_DCT_scaled_size : int; { smallest DCT_scaled_size of any component }
-
- total_iMCU_rows : JDIMENSION; { # of iMCU rows in image }
- { The coefficient controller's input and output progress is measured in
- units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows
- in fully interleaved JPEG scans, but are used whether the scan is
- interleaved or not. We define an iMCU row as v_samp_factor DCT block
- rows of each component. Therefore, the IDCT output contains
- v_samp_factor*DCT_scaled_size sample rows of a component per iMCU row.}
-
- sample_range_limit : range_limit_table_ptr; { table for fast range-limiting }
-
-
- { These fields are valid during any one scan.
- They describe the components and MCUs actually appearing in the scan.
- Note that the decompressor output side must not use these fields. }
-
- comps_in_scan : int; { # of JPEG components in this scan }
- cur_comp_info : Array[0..MAX_COMPS_IN_SCAN-1] of jpeg_component_info_ptr;
- { cur_comp_info[i]^ describes component that appears i'th in SOS }
-
- MCUs_per_row : JDIMENSION; { # of MCUs across the image }
- MCU_rows_in_scan : JDIMENSION; { # of MCU rows in the image }
-
- blocks_in_MCU : JDIMENSION; { # of DCT blocks per MCU }
- MCU_membership : Array[0..D_MAX_BLOCKS_IN_MCU-1] of int;
- { MCU_membership[i] is index in cur_comp_info of component owning }
- { i'th block in an MCU }
-
- Ss, Se, Ah, Al : int; { progressive JPEG parameters for scan }
-
- { This field is shared between entropy decoder and marker parser.
- It is either zero or the code of a JPEG marker that has been
- read from the data source, but has not yet been processed. }
-
- unread_marker : int;
-
- { Links to decompression subobjects
- (methods, private variables of modules) }
-
- master : jpeg_decomp_master_ptr;
- main : jpeg_d_main_controller_ptr;
- coef : jpeg_d_coef_controller_ptr;
- post : jpeg_d_post_controller_ptr;
- inputctl : jpeg_input_controller_ptr;
- marker : jpeg_marker_reader_ptr;
- entropy : jpeg_entropy_decoder_ptr;
- idct : jpeg_inverse_dct_ptr;
- upsample : jpeg_upsampler_ptr;
- cconvert : jpeg_color_deconverter_ptr;
- cquantize : jpeg_color_quantizer_ptr;
- end;
-
-{ Decompression startup: read start of JPEG datastream to see what's there
- function jpeg_read_header (cinfo : j_decompress_ptr;
- require_image : boolean) : int;
- Return value is one of: }
-const
- JPEG_SUSPENDED = 0; { Suspended due to lack of input data }
- JPEG_HEADER_OK = 1; { Found valid image datastream }
- JPEG_HEADER_TABLES_ONLY = 2; { Found valid table-specs-only datastream }
-{ If you pass require_image = TRUE (normal case), you need not check for
- a TABLES_ONLY return code; an abbreviated file will cause an error exit.
- JPEG_SUSPENDED is only possible if you use a data source module that can
- give a suspension return (the stdio source module doesn't). }
-
-
-{ function jpeg_consume_input (cinfo : j_decompress_ptr) : int;
- Return value is one of: }
-
- JPEG_REACHED_SOS = 1; { Reached start of new scan }
- JPEG_REACHED_EOI = 2; { Reached end of image }
- JPEG_ROW_COMPLETED = 3; { Completed one iMCU row }
- JPEG_SCAN_COMPLETED = 4; { Completed last iMCU row of a scan }
-
-
-
-
-implementation
-
-end.
diff --git a/packages/base/pasjpeg/jpegtran.drc b/packages/base/pasjpeg/jpegtran.drc
deleted file mode 100644
index 4ae64526ea..0000000000
--- a/packages/base/pasjpeg/jpegtran.drc
+++ /dev/null
@@ -1,160 +0,0 @@
-#define SysUtils_SShortDayNameSun 65456
-#define SysUtils_SShortDayNameMon 65457
-#define SysUtils_SShortDayNameTue 65458
-#define SysUtils_SShortDayNameWed 65459
-#define SysUtils_SShortDayNameThu 65460
-#define SysUtils_SShortDayNameFri 65461
-#define SysUtils_SShortDayNameSat 65462
-#define SysUtils_SLongDayNameSun 65463
-#define SysUtils_SLongDayNameMon 65464
-#define SysUtils_SLongDayNameTue 65465
-#define SysUtils_SLongDayNameWed 65466
-#define SysUtils_SLongDayNameThu 65467
-#define SysUtils_SLongDayNameFri 65468
-#define SysUtils_SLongDayNameSat 65469
-#define SysUtils_SShortMonthNameSep 65472
-#define SysUtils_SShortMonthNameOct 65473
-#define SysUtils_SShortMonthNameNov 65474
-#define SysUtils_SShortMonthNameDec 65475
-#define SysUtils_SLongMonthNameJan 65476
-#define SysUtils_SLongMonthNameFeb 65477
-#define SysUtils_SLongMonthNameMar 65478
-#define SysUtils_SLongMonthNameApr 65479
-#define SysUtils_SLongMonthNameMay 65480
-#define SysUtils_SLongMonthNameJun 65481
-#define SysUtils_SLongMonthNameJul 65482
-#define SysUtils_SLongMonthNameAug 65483
-#define SysUtils_SLongMonthNameSep 65484
-#define SysUtils_SLongMonthNameOct 65485
-#define SysUtils_SLongMonthNameNov 65486
-#define SysUtils_SLongMonthNameDec 65487
-#define SysUtils_SVarNotArray 65488
-#define SysUtils_SVarArrayBounds 65489
-#define SysUtils_SExternalException 65490
-#define SysUtils_SAssertionFailed 65491
-#define SysUtils_SIntfCastError 65492
-#define SysUtils_SAssertError 65493
-#define SysUtils_SAbstractError 65494
-#define SysUtils_SModuleAccessViolation 65495
-#define SysUtils_SShortMonthNameJan 65496
-#define SysUtils_SShortMonthNameFeb 65497
-#define SysUtils_SShortMonthNameMar 65498
-#define SysUtils_SShortMonthNameApr 65499
-#define SysUtils_SShortMonthNameMay 65500
-#define SysUtils_SShortMonthNameJun 65501
-#define SysUtils_SShortMonthNameJul 65502
-#define SysUtils_SShortMonthNameAug 65503
-#define SysUtils_SInvalidPointer 65504
-#define SysUtils_SInvalidCast 65505
-#define SysUtils_SAccessViolation 65506
-#define SysUtils_SStackOverflow 65507
-#define SysUtils_SControlC 65508
-#define SysUtils_SPrivilege 65509
-#define SysUtils_SException 65510
-#define SysUtils_SExceptTitle 65511
-#define SysUtils_SInvalidFormat 65512
-#define SysUtils_SArgumentMissing 65513
-#define SysUtils_SInvalidVarCast 65514
-#define SysUtils_SInvalidVarOp 65515
-#define SysUtils_SDispatchError 65516
-#define SysUtils_SReadAccess 65517
-#define SysUtils_SWriteAccess 65518
-#define SysUtils_SVarArrayCreate 65519
-#define SysUtils_SOutOfMemory 65520
-#define SysUtils_SInOutError 65521
-#define SysUtils_SFileNotFound 65522
-#define SysUtils_SInvalidFilename 65523
-#define SysUtils_STooManyOpenFiles 65524
-#define SysUtils_SAccessDenied 65525
-#define SysUtils_SEndOfFile 65526
-#define SysUtils_SDiskFull 65527
-#define SysUtils_SInvalidInput 65528
-#define SysUtils_SDivByZero 65529
-#define SysUtils_SRangeError 65530
-#define SysUtils_SIntOverflow 65531
-#define SysUtils_SInvalidOp 65532
-#define SysUtils_SZeroDivide 65533
-#define SysUtils_SOverflow 65534
-#define SysUtils_SUnderflow 65535
-STRINGTABLE
-BEGIN
- SysUtils_SShortDayNameSun, "So"
- SysUtils_SShortDayNameMon, "Mo"
- SysUtils_SShortDayNameTue, "Di"
- SysUtils_SShortDayNameWed, "Mi"
- SysUtils_SShortDayNameThu, "Do"
- SysUtils_SShortDayNameFri, "Fr"
- SysUtils_SShortDayNameSat, "Sa"
- SysUtils_SLongDayNameSun, "Sonntag"
- SysUtils_SLongDayNameMon, "Montag"
- SysUtils_SLongDayNameTue, "Dienstag"
- SysUtils_SLongDayNameWed, "Mittwoch"
- SysUtils_SLongDayNameThu, "Donnerstag"
- SysUtils_SLongDayNameFri, "Freitag"
- SysUtils_SLongDayNameSat, "Samstag"
- SysUtils_SShortMonthNameSep, "Sep"
- SysUtils_SShortMonthNameOct, "Okt"
- SysUtils_SShortMonthNameNov, "Nov"
- SysUtils_SShortMonthNameDec, "Dez"
- SysUtils_SLongMonthNameJan, "Januar"
- SysUtils_SLongMonthNameFeb, "Februar"
- SysUtils_SLongMonthNameMar, "M\xe4rz"
- SysUtils_SLongMonthNameApr, "April"
- SysUtils_SLongMonthNameMay, "Mai"
- SysUtils_SLongMonthNameJun, "Juni"
- SysUtils_SLongMonthNameJul, "Juli"
- SysUtils_SLongMonthNameAug, "August"
- SysUtils_SLongMonthNameSep, "September"
- SysUtils_SLongMonthNameOct, "Oktober"
- SysUtils_SLongMonthNameNov, "November"
- SysUtils_SLongMonthNameDec, "Dezember"
- SysUtils_SVarNotArray, "Variante ist kein Array"
- SysUtils_SVarArrayBounds, "Varianten-Array-Index au\xdferhalb des zul\xe4ssigen Bereichs"
- SysUtils_SExternalException, "Externe Exception %x"
- SysUtils_SAssertionFailed, "Bedingungsfehler"
- SysUtils_SIntfCastError, "Interface wird nicht unterst\xfctzt"
- SysUtils_SAssertError, "%s (%s, Zeile %d)"
- SysUtils_SAbstractError, "Abstrakter Fehler"
- SysUtils_SModuleAccessViolation, "Zugriffsverletzung bei Adresse %p in Modul '%s' %s von Adresse %p"
- SysUtils_SShortMonthNameJan, "Jan"
- SysUtils_SShortMonthNameFeb, "Feb"
- SysUtils_SShortMonthNameMar, "M\xe4r"
- SysUtils_SShortMonthNameApr, "Apr"
- SysUtils_SShortMonthNameMay, "Mai"
- SysUtils_SShortMonthNameJun, "Jun"
- SysUtils_SShortMonthNameJul, "Jul"
- SysUtils_SShortMonthNameAug, "Aug"
- SysUtils_SInvalidPointer, "Ung\xfcltige Zeigeroperation"
- SysUtils_SInvalidCast, "Ung\xfcltige Typumwandlung"
- SysUtils_SAccessViolation, "Zugriffsverletzung bei Adresse %p. %s von Adresse %p"
- SysUtils_SStackOverflow, "Stack-\xdcberlauf"
- SysUtils_SControlC, "Strg-C gedr\xfcckt"
- SysUtils_SPrivilege, "Priviligierte Instruktion"
- SysUtils_SException, "Exception %s im Modul %s bei %p.\n%s%s"
- SysUtils_SExceptTitle, "Anwendungsfehler"
- SysUtils_SInvalidFormat, "Format '%s' ung\xfcltig oder inkompatibel mit Argument"
- SysUtils_SArgumentMissing, "Kein Argument f\xfcr Format '%s'"
- SysUtils_SInvalidVarCast, "Typkonvertierung von Variant ung\xfcltig"
- SysUtils_SInvalidVarOp, "Ung\xfcltige Variantenoperation"
- SysUtils_SDispatchError, "Varianten-Methodenaufrufe werden nicht unterst\xfctzt"
- SysUtils_SReadAccess, "Lesen"
- SysUtils_SWriteAccess, "Schreiben"
- SysUtils_SVarArrayCreate, "Fehler beim Erzeugen von Varianten-Array"
- SysUtils_SOutOfMemory, "Speicher reicht nicht aus"
- SysUtils_SInOutError, "I/O-Fehler %d"
- SysUtils_SFileNotFound, "Datei nicht gefunden"
- SysUtils_SInvalidFilename, "Ung\xfcltiger Dateiname"
- SysUtils_STooManyOpenFiles, "Zu viele Dateien ge\xf6ffnet"
- SysUtils_SAccessDenied, "Dateizugriff verweigert"
- SysUtils_SEndOfFile, "Lesen nach Dateiende (EOF)"
- SysUtils_SDiskFull, "Kapazit\xe4t der Diskette/Festplatte ersch\xf6pft"
- SysUtils_SInvalidInput, "Ung\xfcltige numerische Eingabe"
- SysUtils_SDivByZero, "Division durch Null"
- SysUtils_SRangeError, "Bereichs\xfcberschreitung"
- SysUtils_SIntOverflow, "Integer-\xdcberlauf"
- SysUtils_SInvalidOp, "Fehler bei Flie\xdfkommaoperation"
- SysUtils_SZeroDivide, "Flie\xdfkommadivision durch Null"
- SysUtils_SOverflow, "\xdcberlauf bei Flie\xdfkommaoperation"
- SysUtils_SUnderflow, "Unterlauf bei Flie\xdfkommaoperation"
-END
-
diff --git a/packages/base/pasjpeg/jpegtran.pas b/packages/base/pasjpeg/jpegtran.pas
deleted file mode 100644
index c238d7966c..0000000000
--- a/packages/base/pasjpeg/jpegtran.pas
+++ /dev/null
@@ -1,642 +0,0 @@
-Program JpegTran;
-
-{ 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. }
-
-{ Original: jpegtran.c ; Copyright (C) 1995-1996, Thomas G. Lane. }
-
-{$define TWO_FILE_COMMANDLINE}
-
-{$I jconfig.inc}
-
-uses
- jdeferr,
- jerror,
- jmorecfg,
- jpeglib,
- cdjpeg, { Common decls for cjpeg/djpeg applications }
- jdatasrc, JDatadst, transupp, JCTrans, JDtrans,
- JdAPImin, JcAPImin, JcParam,
- RdSwitch;
-
-
-{ 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... }
-
-
-var
- progname, { program name for error messages }
- outfilename : string; { for -outfile switch }
- copyoption : JCOPY_OPTION; { -copy switch }
- transformoption : jpeg_transform_info; { image transformation options }
-
-procedure Stop(errcode : int);
-begin
- Halt(errcode);
-end;
-
-{LOCAL}
-procedure usage;
-{ complain about bad command line }
-begin
- Write(output, 'usage: ',progname,' [switches] ');
-{$ifdef TWO_FILE_COMMANDLINE}
- WriteLn(output, 'inputfile outputfile');
-{$else}
- WriteLn(output, '[inputfile]');
-{$endif}
-
- WriteLn(output, 'Switches (names may be abbreviated):');
- WriteLn(' -copy none Copy no extra markers from source file');
- WriteLn(' -copy comments Copy only comment markers (default)');
- WriteLn(' -copy all Copy all extra markers');
-{$ifdef ENTROPY_OPT_SUPPORTED}
- WriteLn(' -optimize Optimize Huffman table (smaller file, but slow compression)');
-{$endif}
-{$ifdef C_PROGRESSIVE_SUPPORTED}
- WriteLn(' -progressive Create progressive JPEG file');
-{$endif}
-{$ifdef TRANSFORMS_SUPPORTED}
- WriteLn('Switches for modifying the image:');
- WriteLn(' -grayscale Reduce to grayscale (omit color data)');
- WriteLn(' -flip [horizontal|vertical] Mirror image (left-right or top-bottom)');
- WriteLn(' -rotate [90|180|270] Rotate image (degrees clockwise)');
- WriteLn(' -transpose Transpose image');
- WriteLn(' -transverse Transverse transpose image');
- WriteLn(' -trim Drop non-transformable edge blocks');
- {$ifdef CROP_SUPPORTED}
- WriteLn(' -cut WxH+X+Y Cut out a subset of the image');
- {$endif}
-{$endif} { TRANSFORMS_SUPPORTED }
- WriteLn('Switches for advanced users:');
- WriteLn(' -restart N Set restart interval in rows, or in blocks with B');
- WriteLn(' -maxmemory N Maximum memory to use (in kbytes)');
- WriteLn(' -outfile name Specify name for output file');
- WriteLn(' -verbose or -debug Emit debug output');
- WriteLn('Switches for wizards:');
-{$ifdef C_ARITH_CODING_SUPPORTED}
- WriteLn(' -arithmetic Use arithmetic coding');
-{$endif}
-{$ifdef C_MULTISCAN_FILES_SUPPORTED}
- WriteLn(' -scans file Create multi-scan JPEG per script file');
-{$endif}
- Stop(EXIT_FAILURE);
-end;
-
-{LOCAL}
-procedure select_transform (transform : JXFORM_CODE);
-{ Silly little routine to detect multiple transform options,
- which we can't handle. }
-
-begin
-{$ifdef TRANSFORMS_SUPPORTED}
- if (transformoption.transform = JXFORM_NONE) or
- (transformoption.transform = transform) then
- transformoption.transform := transform
- else
- begin
- WriteLn(progname, ': can only do one image transformation at a time');
- usage;
- end;
-{$else}
- WriteLn(progname, ': sorry, image transformation was not compiled');
- exit(EXIT_FAILURE);
-{$endif}
-end;
-
-{LOCAL}
-function parse_switches (cinfo : j_compress_ptr;
- last_file_arg_seen: int;
- for_real : boolean ) : int;
-const
- printed_version : boolean = FALSE;
-
-{ 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. }
-var
- argn,
- argc : int;
- arg : string;
-
- simple_progressive : boolean;
-const
- scansarg : string = ''; { saves -scans parm if any }
-var
- lval : long;
- ch : char;
- code : integer;
-begin
- { Set up default JPEG parameters. }
- simple_progressive := FALSE;
- outfilename := '';
- cinfo^.err^.trace_level := 0;
- 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 }
-
- argn := 0;
- argc := ParamCount;
-
- while argn < argc do
- begin
- Inc(argn);
- arg := ParamStr(argn);
- if (arg[1] <> '-') then
- begin
- { Not a switch, must be a file name argument }
- if (argn <= last_file_arg_seen) then
- begin
- outfilename := ''; { -outfile applies to just one input file }
- continue; { ignore this name if previously processed }
- end;
- break; { else done parsing switches }
- end;
- {Inc(arg); - advance past switch marker character }
-
- if (keymatch(arg, '-arithmetic', 1)) then
- begin
- { Use arithmetic coding. }
-{$ifdef C_ARITH_CODING_SUPPORTED}
- cinfo^.arith_code := TRUE;
-{$else}
- WriteLn(output, progname, ': sorry, arithmetic coding not supported');
- Stop(EXIT_FAILURE);
-{$endif}
- end
- else
- if keymatch(arg, '-copy', 2) then
- begin { Select which extra markers to copy. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- if (keymatch(ParamStr(argn), 'none', 1)) then
- copyoption := JCOPYOPT_NONE
- else
- if (keymatch(ParamStr(argn), 'comments', 1)) then
- copyoption := JCOPYOPT_COMMENTS
- else
- if (keymatch(ParamStr(argn), 'all', 1)) then
- copyoption := JCOPYOPT_ALL
- else
- usage;
- end
- else
- if keymatch(arg, '-debug', 2) or keymatch(arg, '-verbose', 2) then
- begin
- { Enable debug printouts. }
- { On first -d, print version identification }
-
- if (not printed_version) then
- begin
- WriteLn('PASJPEG Group''s JPEGTRAN translation version ',
- JVERSION, JCOPYRIGHT, JNOTICE);
- printed_version := TRUE;
- end;
- Inc(cinfo^.err^.trace_level);
- end
- else
- {$ifdef CROP_SUPPORTED}
- if keymatch(arg, '-cut', 2) then
- begin
- { Cut out a region of the image specified by an X geometry-like string }
- p : PChar;
-
- Inc(argn);
- if (argn >= argc) then
- usage;
- select_transform(JXFORM_CUT);
-
- arg := ParamStr(argn);
- px := Pos('x', arg);
- if ( px = 'x') then
- usage;
- arg_w := Copy(arg, 1, px-1);
- Val(arg_w, lval, code);
- if (code <> 0) then
- usage;
-
- transformoption.newwidth := lval;
- arg_w := Copy(arg, px+1, Length(arg));
- Val(arg_w, lval, code);
- if (code <> 0) then
- usage;
-
- transformoption.newheight := lval;
- if (p^ <> '+') and (p^ <> '-') then
- usage;
- arg_w := Copy(arg, px+1, Length(arg));
- Val(arg_w, lval, code);
- if (code <> 0) then
- usage;
-
- transformoption.xoffs := lval;
- arg_w := Copy(arg, px+1, Length(arg));
- Val(arg_w, lval, code);
- if (code <> 0) then
- usage;
-
- if (p^ <> '+') and (p^ <> '-') then
- usage;
- transformoption.yoffs := lval;
-
- if (transformoption.newwidth=0) or (transformoption.newheight=0) then
- begin
- WriteLn(progname,': degenerate -cut size in ', argv[argn]);
- exit(EXIT_FAILURE);
- end
- end
- else
- {$endif}
- if keymatch(arg, '-flip', 2) then
- begin { Mirror left-right or top-bottom. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- if keymatch(ParamStr(argn), 'horizontal', 2) then
- select_transform(JXFORM_FLIP_H)
- else
- if keymatch(ParamStr(argn), 'vertical', 2) then
- select_transform(JXFORM_FLIP_V)
- else
- usage;
- end
- else
- if keymatch(arg, '-grayscale', 2) or
- keymatch(arg, '-greyscale',2) then
- begin { Force to grayscale. }
- {$ifdef TRANSFORMS_SUPPORTED}
- transformoption.force_grayscale := TRUE;
- {$else}
- select_transform(JXFORM_NONE); { force an error }
- {$endif}
- end
- else
- if keymatch(arg, '-maxmemory', 4) then
- begin
- { Maximum memory in Kb (or Mb with 'm'). }
- ch := 'x';
-
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
-
- arg := ParamStr(argn);
- if (length(arg) > 1) and (arg[length(arg)] in ['m','M']) then
- begin
- ch := arg[length(arg)];
- arg := Copy(arg, 1, Length(arg)-1);
- end;
- Val(arg, lval, code);
- if (code <> 0) then
- usage;
- if (ch = 'm') or (ch = 'M') then
- lval := lval * long(1000);
- cinfo^.mem^.max_memory_to_use := lval * long(1000);
- end
- else
- if keymatch(arg, '-optimize', 2) or
- keymatch(arg, '-optimise', 2) then
- begin
- { Enable entropy parm optimization. }
- {$ifdef ENTROPY_OPT_SUPPORTED}
- cinfo^.optimize_coding := TRUE;
- {$else}
- WriteLn(output, progname,
- ': sorry, entropy optimization was not compiled');
- Stop(EXIT_FAILURE);
- {$endif}
-
- end
- else
- if keymatch(arg, '-outfile', 5) then
- begin
- { Set output file name. }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- outfilename := ParamStr(argn); { save it away for later use }
- end
- else
- if keymatch(arg, '-progressive', 2) then
- begin
- { Select simple progressive mode. }
- {$ifdef C_PROGRESSIVE_SUPPORTED}
- simple_progressive := TRUE;
- { We must postpone execution until num_components is known. }
- {$else}
- WriteLn(output, progname,
- ': sorry, progressive output was not compiled');
- Stop(EXIT_FAILURE);
- {$endif}
- end
- else
- if keymatch(arg, '-restart', 2) then
- begin
- ch := 'x';
- { Restart interval in MCU rows (or in MCUs with 'b'). }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- arg := ParamStr(argn);
- if (length(arg) > 1) and (arg[length(arg)] in ['b','B']) then
- begin
- ch := arg[length(arg)];
- arg := Copy(arg, 1, Length(arg)-1);
- end;
-
- Val(arg, lval, code);
- if (code <> 1) or (lval < 0) or (lval > Long(65535)) then
- usage;
-
- if (ch = 'b') or (ch = 'B') then
- begin
- cinfo^.restart_interval := uint(lval);
- cinfo^.restart_in_rows := 0; { else prior '-restart n' overrides me }
- end
- else
- begin
- cinfo^.restart_in_rows := int(lval);
- { restart_interval will be computed during startup }
- end;
-
- end
- else
- if keymatch(arg, '-rotate', 3) then
- begin { Rotate 90, 180, or 270 degrees (measured clockwise). }
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- if (keymatch(ParamStr(argn), '90', 2)) then
- select_transform(JXFORM_ROT_90)
- else
- if keymatch(ParamStr(argn), '180', 3) then
- select_transform(JXFORM_ROT_180)
- else
- if keymatch(ParamStr(argn), '270', 3) then
- select_transform(JXFORM_ROT_270)
- else
- usage;
- end
- else
- if keymatch(arg, '-scans', 2) then
- begin
- { Set scan script. }
- {$ifdef C_MULTISCAN_FILES_SUPPORTED}
- Inc(argn);
- if (argn >= argc) then { advance to next argument }
- usage;
- scansarg := ParamStr(argn);
- { We must postpone reading the file in case -progressive appears. }
- {$else}
- WriteLn(output, progname,
- ': sorry, multi-scan output was not compiled');
- Stop(EXIT_FAILURE);
- {$endif}
- end
- else
- if keymatch(arg, '-transpose', 2) then
- { Transpose (across UL-to-LR axis). }
- select_transform(JXFORM_TRANSPOSE)
- else
- if keymatch(arg, '-transverse', 7) then
- { Transverse transpose (across UR-to-LL axis). }
- select_transform(JXFORM_TRANSVERSE)
- else
- if keymatch(arg, '-trim', 4) then
- { Trim off any partial edge MCUs that
- the transform can't handle. }
- transformoption.trim := TRUE
- else
- usage; { bogus switch }
- end;
-
- { Post-switch-scanning cleanup }
-
- if (for_real) then
- begin
-
-{$ifdef C_PROGRESSIVE_SUPPORTED}
- if (simple_progressive) then { process -progressive; -scans can override }
- jpeg_simple_progression(cinfo);
-{$endif}
-
-{$ifdef C_MULTISCAN_FILES_SUPPORTED}
- if (scansarg <> '') then { process -scans if it was present }
- begin
- WriteLn('Scripts are not supported in PasJPEG.');
- {if not read_scan_script(cinfo, scansarg) then
- usage;
- }
- end;
-{$endif}
- end;
-
- parse_switches := argn; { return index of next arg (file name) }
-end;
-
-
-{ The main program. }
-
-{main (int argc, char **argv)}
-var
- srcinfo : jpeg_decompress_struct;
- dstinfo : jpeg_compress_struct;
- jsrcerr, jdsterr : jpeg_error_mgr;
-{$ifdef PROGRESS_REPORT}
- progress : cdjpeg_progress_mgr;
-{$endif}
- src_coef_arrays,
- dst_coef_arrays : jvirt_barray_tbl_ptr;
- file_index : int;
- input_file : FILE;
- output_file : FILE;
-begin
- { On Mac, fetch a command line. }
-{$ifdef USE_CCOMMAND}
- argc := ccommand(@argv);
-{$endif}
-
- progname := ParamStr(0);
-
- { 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, 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 = '') then
- begin
- if (file_index <> ParamCount-1) then
- begin
- WriteLn(output, progname, ': must name one input and one output file');
- usage;
- end;
- outfilename := ParamStr(file_index+1);
- end
- else
- begin
- if (file_index <> ParamCount-1) then
- begin
- WriteLn(output, progname, ': must name one input and one output file');
- usage;
- end;
- end;
-{$else}
- { Unix style: expect zero or one file name }
- if (file_index < argc-1) then
- begin
- WriteLn(output, progname, ': only one input file');
- usage;
- end;
-{$endif} { TWO_FILE_COMMANDLINE }
-
- { Open the input file. }
- if (file_index < ParamCount) then
- begin
- assign(input_file, ParamStr(file_index));
- {$I-}
- reset(input_file, 1);
- {$IFDEF IoCheck} {$I+} {$ENDIF}
- if (IOresult <> 0) then
- begin
- WriteLn(output, progname, ': can''t open ', ParamStr(file_index));
- Stop(EXIT_FAILURE);
- end;
- end
- else
- begin
- { default input file is stdin }
- assign(input_file, '');
- reset(input_file, 1);
- end;
-
- { Open the output file. }
- if (outfilename <> '') then
- begin
- assign(output_file, outfilename);
- {$I-}
- rewrite(output_file, 1);
- {$IFDEF IoCheck} {$I+} {$ENDIF}
- if (IOresult <> 0) then
- begin
- WriteLn(output, progname, ': can''t open ', outfilename);
- Stop(EXIT_FAILURE);
- end;
- end
- else
- begin
- { default output file is stdout }
- assign(output_file, '');
- rewrite(output_file, 1);
- end;
-
-{$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. }
-
-{$ifdef 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. }
-
-{$ifdef 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, 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 }
-{$ifdef 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 }
- close(input_file);
- close(output_file);
-
-{$ifdef PROGRESS_REPORT}
- end_progress_monitor(j_common_ptr(@dstinfo));
-{$endif}
-
- { All done. }
- if jsrcerr.num_warnings + jdsterr.num_warnings <> 0 then
- Stop(EXIT_WARNING)
- else
- Stop(EXIT_SUCCESS);
-end.
diff --git a/packages/base/pasjpeg/jpegtran.res b/packages/base/pasjpeg/jpegtran.res
deleted file mode 100644
index 2d7e21e4fb..0000000000
--- a/packages/base/pasjpeg/jpegtran.res
+++ /dev/null
Binary files differ
diff --git a/packages/base/pasjpeg/jquant1.pas b/packages/base/pasjpeg/jquant1.pas
deleted file mode 100644
index 22d47d5a07..0000000000
--- a/packages/base/pasjpeg/jquant1.pas
+++ /dev/null
@@ -1,1010 +0,0 @@
-Unit JQuant1;
-
-{ This file contains 1-pass color quantization (color mapping) routines.
- These routines provide mapping to a fixed color map using equally spaced
- color values. Optional Floyd-Steinberg or ordered dithering is available. }
-
-{ Original: jquant1.c; Copyright (C) 1991-1996, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jpeglib;
-
-
-{GLOBAL}
-procedure jinit_1pass_quantizer (cinfo : j_decompress_ptr);
-
-implementation
-
-uses
- jmorecfg,
- jdeferr,
- jerror,
- jutils;
-
-{ The main purpose of 1-pass quantization is to provide a fast, if not very
- high quality, colormapped output capability. A 2-pass quantizer usually
- gives better visual quality; however, for quantized grayscale output this
- quantizer is perfectly adequate. Dithering is highly recommended with this
- quantizer, though you can turn it off if you really want to.
-
- In 1-pass quantization the colormap must be chosen in advance of seeing the
- image. We use a map consisting of all combinations of Ncolors[i] color
- values for the i'th component. The Ncolors[] values are chosen so that
- their product, the total number of colors, is no more than that requested.
- (In most cases, the product will be somewhat less.)
-
- Since the colormap is orthogonal, the representative value for each color
- component can be determined without considering the other components;
- then these indexes can be combined into a colormap index by a standard
- N-dimensional-array-subscript calculation. Most of the arithmetic involved
- can be precalculated and stored in the lookup table colorindex[].
- colorindex[i][j] maps pixel value j in component i to the nearest
- representative value (grid plane) for that component; this index is
- multiplied by the array stride for component i, so that the
- index of the colormap entry closest to a given pixel value is just
- sum( colorindex[component-number][pixel-component-value] )
- Aside from being fast, this scheme allows for variable spacing between
- representative values with no additional lookup cost.
-
- If gamma correction has been applied in color conversion, it might be wise
- to adjust the color grid spacing so that the representative colors are
- equidistant in linear space. At this writing, gamma correction is not
- implemented by jdcolor, so nothing is done here. }
-
-
-{ Declarations for ordered dithering.
-
- We use a standard 16x16 ordered dither array. The basic concept of ordered
- dithering is described in many references, for instance Dale Schumacher's
- chapter II.2 of Graphics Gems II (James Arvo, ed. Academic Press, 1991).
- In place of Schumacher's comparisons against a "threshold" value, we add a
- "dither" value to the input pixel and then round the result to the nearest
- output value. The dither value is equivalent to (0.5 - threshold) times
- the distance between output values. For ordered dithering, we assume that
- the output colors are equally spaced; if not, results will probably be
- worse, since the dither may be too much or too little at a given point.
-
- The normal calculation would be to form pixel value + dither, range-limit
- this to 0..MAXJSAMPLE, and then index into the colorindex table as usual.
- We can skip the separate range-limiting step by extending the colorindex
- table in both directions. }
-
-
-const
- ODITHER_SIZE = 16; { dimension of dither matrix }
-{ NB: if ODITHER_SIZE is not a power of 2, ODITHER_MASK uses will break }
- ODITHER_CELLS = (ODITHER_SIZE*ODITHER_SIZE); { # cells in matrix }
- ODITHER_MASK = (ODITHER_SIZE-1); { mask for wrapping around counters }
-
-type
- ODITHER_vector = Array[0..ODITHER_SIZE-1] of int;
- ODITHER_MATRIX = Array[0..ODITHER_SIZE-1] of ODITHER_vector;
- {ODITHER_MATRIX_PTR = ^array[0..ODITHER_SIZE-1] of int;}
- ODITHER_MATRIX_PTR = ^ODITHER_MATRIX;
-
-const
- base_dither_matrix : Array[0..ODITHER_SIZE-1,0..ODITHER_SIZE-1] of UINT8
- = (
- { Bayer's order-4 dither array. Generated by the code given in
- Stephen Hawley's article "Ordered Dithering" in Graphics Gems I.
- The values in this array must range from 0 to ODITHER_CELLS-1. }
-
- ( 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 ),
- ( 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 ),
- ( 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 ),
- ( 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 ),
- ( 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 ),
- ( 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 ),
- ( 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 ),
- ( 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 ),
- ( 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 ),
- ( 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 ),
- ( 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 ),
- ( 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 ),
- ( 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 ),
- ( 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 ),
- ( 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 ),
- ( 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 )
- );
-
-
-{ Declarations for Floyd-Steinberg dithering.
-
- Errors are accumulated into the array fserrors[], at a resolution of
- 1/16th of a pixel count. The error at a given pixel is propagated
- to its not-yet-processed neighbors using the standard F-S fractions,
- ... (here) 7/16
- 3/16 5/16 1/16
- We work left-to-right on even rows, right-to-left on odd rows.
-
- We can get away with a single array (holding one row's worth of errors)
- by using it to store the current row's errors at pixel columns not yet
- processed, but the next row's errors at columns already processed. We
- need only a few extra variables to hold the errors immediately around the
- current column. (If we are lucky, those variables are in registers, but
- even if not, they're probably cheaper to access than array elements are.)
-
- The fserrors[] array is indexed [component#][position].
- We provide (#columns + 2) entries per component; the extra entry at each
- end saves us from special-casing the first and last pixels.
-
- Note: on a wide image, we might not have enough room in a PC's near data
- segment to hold the error array; so it is allocated with alloc_large. }
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-type
- FSERROR = INT16; { 16 bits should be enough }
- LOCFSERROR = int; { use 'int' for calculation temps }
-{$else}
-type
- FSERROR = INT32; { may need more than 16 bits }
- LOCFSERROR = INT32; { be sure calculation temps are big enough }
-{$endif}
-
-type
- jFSError = 0..(MaxInt div SIZEOF(FSERROR))-1;
- FS_ERROR_FIELD = array[jFSError] of FSERROR;
- FS_ERROR_FIELD_PTR = ^FS_ERROR_FIELD;{far}
- { pointer to error array (in FAR storage!) }
- FSERRORPTR = ^FSERROR;
-
-
-{ Private subobject }
-
-const
- MAX_Q_COMPS = 4; { max components I can handle }
-
-type
- my_cquantize_ptr = ^my_cquantizer;
- my_cquantizer = record
- pub : jpeg_color_quantizer; { public fields }
-
- { Initially allocated colormap is saved here }
- sv_colormap : JSAMPARRAY; { The color map as a 2-D pixel array }
- sv_actual : int; { number of entries in use }
-
- colorindex : JSAMPARRAY; { Precomputed mapping for speed }
- { colorindex[i][j] = index of color closest to pixel value j in component i,
- premultiplied as described above. Since colormap indexes must fit into
- JSAMPLEs, the entries of this array will too. }
-
- is_padded : boolean; { is the colorindex padded for odither? }
-
- Ncolors : array[0..MAX_Q_COMPS-1] of int;
- { # of values alloced to each component }
-
- { Variables for ordered dithering }
- row_index : int; { cur row's vertical index in dither matrix }
- odither : array[0..MAX_Q_COMPS-1] of ODITHER_MATRIX_PTR;
- { one dither array per component }
- { Variables for Floyd-Steinberg dithering }
- fserrors : array[0..MAX_Q_COMPS-1] of FS_ERROR_FIELD_PTR;
- { accumulated errors }
- on_odd_row : boolean; { flag to remember which row we are on }
- end;
-
-
-{ Policy-making subroutines for create_colormap and create_colorindex.
- These routines determine the colormap to be used. The rest of the module
- only assumes that the colormap is orthogonal.
-
- * select_ncolors decides how to divvy up the available colors
- among the components.
- * output_value defines the set of representative values for a component.
- * largest_input_value defines the mapping from input values to
- representative values for a component.
- Note that the latter two routines may impose different policies for
- different components, though this is not currently done. }
-
-
-
-{LOCAL}
-function select_ncolors (cinfo : j_decompress_ptr;
- var Ncolors : array of int) : int;
-{ Determine allocation of desired colors to components, }
-{ and fill in Ncolors[] array to indicate choice. }
-{ Return value is total number of colors (product of Ncolors[] values). }
-var
- nc : int;
- max_colors : int;
- total_colors, iroot, i, j : int;
- changed : boolean;
- temp : long;
-const
- RGB_order:array[0..2] of int = (RGB_GREEN, RGB_RED, RGB_BLUE);
-begin
- nc := cinfo^.out_color_components; { number of color components }
- max_colors := cinfo^.desired_number_of_colors;
-
- { We can allocate at least the nc'th root of max_colors per component. }
- { Compute floor(nc'th root of max_colors). }
- iroot := 1;
- repeat
- Inc(iroot);
- temp := iroot; { set temp = iroot ** nc }
- for i := 1 to pred(nc) do
- temp := temp * iroot;
- until (temp > long(max_colors)); { repeat till iroot exceeds root }
- Dec(iroot); { now iroot = floor(root) }
-
- { Must have at least 2 color values per component }
- if (iroot < 2) then
- ERREXIT1(j_common_ptr(cinfo), JERR_QUANT_FEW_COLORS, int(temp));
-
- { Initialize to iroot color values for each component }
- total_colors := 1;
- for i := 0 to pred(nc) do
- begin
- Ncolors[i] := iroot;
- total_colors := total_colors * iroot;
- end;
-
- { We may be able to increment the count for one or more components without
- exceeding max_colors, though we know not all can be incremented.
- Sometimes, the first component can be incremented more than once!
- (Example: for 16 colors, we start at 2*2*2, go to 3*2*2, then 4*2*2.)
- In RGB colorspace, try to increment G first, then R, then B. }
-
- repeat
- changed := FALSE;
- for i := 0 to pred(nc) do
- begin
- if cinfo^.out_color_space = JCS_RGB then
- j := RGB_order[i]
- else
- j := i;
- { calculate new total_colors if Ncolors[j] is incremented }
- temp := total_colors div Ncolors[j];
- temp := temp * (Ncolors[j]+1); { done in long arith to avoid oflo }
- if (temp > long(max_colors)) then
- break; { won't fit, done with this pass }
- Inc(Ncolors[j]); { OK, apply the increment }
- total_colors := int(temp);
- changed := TRUE;
- end;
- until not changed;
-
- select_ncolors := total_colors;
-end;
-
-
-{LOCAL}
-function output_value (cinfo : j_decompress_ptr;
- ci : int; j : int; maxj : int) : int;
-{ Return j'th output value, where j will range from 0 to maxj }
-{ The output values must fall in 0..MAXJSAMPLE in increasing order }
-begin
- { We always provide values 0 and MAXJSAMPLE for each component;
- any additional values are equally spaced between these limits.
- (Forcing the upper and lower values to the limits ensures that
- dithering can't produce a color outside the selected gamut.) }
-
- output_value := int (( INT32(j) * MAXJSAMPLE + maxj div 2) div maxj);
-end;
-
-
-{LOCAL}
-function largest_input_value (cinfo : j_decompress_ptr;
- ci : int; j : int; maxj : int) : int;
-{ Return largest input value that should map to j'th output value }
-{ Must have largest(j=0) >= 0, and largest(j=maxj) >= MAXJSAMPLE }
-begin
- { Breakpoints are halfway between values returned by output_value }
- largest_input_value := int (( INT32(2*j + 1) * MAXJSAMPLE +
- maxj) div (2*maxj));
-end;
-
-
-{ Create the colormap. }
-
-{LOCAL}
-procedure create_colormap (cinfo : j_decompress_ptr);
-var
- cquantize : my_cquantize_ptr;
- colormap : JSAMPARRAY; { Created colormap }
-
- total_colors : int; { Number of distinct output colors }
- i,j,k, nci, blksize, blkdist, ptr, val : int;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
-
- { Select number of colors for each component }
- total_colors := select_ncolors(cinfo, cquantize^.Ncolors);
-
- { Report selected color counts }
- {$IFDEF DEBUG}
- if (cinfo^.out_color_components = 3) then
- TRACEMS4(j_common_ptr(cinfo), 1, JTRC_QUANT_3_NCOLORS,
- total_colors, cquantize^.Ncolors[0],
- cquantize^.Ncolors[1], cquantize^.Ncolors[2])
- else
- TRACEMS1(j_common_ptr(cinfo), 1, JTRC_QUANT_NCOLORS, total_colors);
- {$ENDIF}
-
- { Allocate and fill in the colormap. }
- { The colors are ordered in the map in standard row-major order, }
- { i.e. rightmost (highest-indexed) color changes most rapidly. }
-
- colormap := cinfo^.mem^.alloc_sarray(
- j_common_ptr(cinfo), JPOOL_IMAGE,
- JDIMENSION(total_colors), JDIMENSION(cinfo^.out_color_components));
-
- { blksize is number of adjacent repeated entries for a component }
- { blkdist is distance between groups of identical entries for a component }
- blkdist := total_colors;
-
- for i := 0 to pred(cinfo^.out_color_components) do
- begin
- { fill in colormap entries for i'th color component }
- nci := cquantize^.Ncolors[i]; { # of distinct values for this color }
- blksize := blkdist div nci;
- for j := 0 to pred(nci) do
- begin
- { Compute j'th output value (out of nci) for component }
- val := output_value(cinfo, i, j, nci-1);
- { Fill in all colormap entries that have this value of this component }
- ptr := j * blksize;
- while (ptr < total_colors) do
- begin
- { fill in blksize entries beginning at ptr }
- for k := 0 to pred(blksize) do
- colormap^[i]^[ptr+k] := JSAMPLE(val);
-
- Inc(ptr, blkdist);
- end;
- end;
- blkdist := blksize; { blksize of this color is blkdist of next }
- end;
-
- { Save the colormap in private storage,
- where it will survive color quantization mode changes. }
-
- cquantize^.sv_colormap := colormap;
- cquantize^.sv_actual := total_colors;
-end;
-
-{ Create the color index table. }
-
-{LOCAL}
-procedure create_colorindex (cinfo : j_decompress_ptr);
-var
- cquantize : my_cquantize_ptr;
- indexptr,
- help_indexptr : JSAMPROW; { for negative offsets }
- i,j,k, nci, blksize, val, pad : int;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- { For ordered dither, we pad the color index tables by MAXJSAMPLE in
- each direction (input index values can be -MAXJSAMPLE .. 2*MAXJSAMPLE).
- This is not necessary in the other dithering modes. However, we
- flag whether it was done in case user changes dithering mode. }
-
- if (cinfo^.dither_mode = JDITHER_ORDERED) then
- begin
- pad := MAXJSAMPLE*2;
- cquantize^.is_padded := TRUE;
- end
- else
- begin
- pad := 0;
- cquantize^.is_padded := FALSE;
- end;
-
- cquantize^.colorindex := cinfo^.mem^.alloc_sarray
- (j_common_ptr(cinfo), JPOOL_IMAGE,
- JDIMENSION(MAXJSAMPLE+1 + pad),
- JDIMENSION(cinfo^.out_color_components));
-
- { blksize is number of adjacent repeated entries for a component }
- blksize := cquantize^.sv_actual;
-
- for i := 0 to pred(cinfo^.out_color_components) do
- begin
- { fill in colorindex entries for i'th color component }
- nci := cquantize^.Ncolors[i]; { # of distinct values for this color }
- blksize := blksize div nci;
-
- { adjust colorindex pointers to provide padding at negative indexes. }
- if (pad <> 0) then
- Inc(JSAMPLE_PTR(cquantize^.colorindex^[i]), MAXJSAMPLE);
-
- { in loop, val = index of current output value, }
- { and k = largest j that maps to current val }
- indexptr := cquantize^.colorindex^[i];
- val := 0;
- k := largest_input_value(cinfo, i, 0, nci-1);
- for j := 0 to MAXJSAMPLE do
- begin
- while (j > k) do { advance val if past boundary }
- begin
- Inc(val);
- k := largest_input_value(cinfo, i, val, nci-1);
- end;
- { premultiply so that no multiplication needed in main processing }
- indexptr^[j] := JSAMPLE (val * blksize);
- end;
- { Pad at both ends if necessary }
- if (pad <> 0) then
- begin
- help_indexptr := indexptr;
- { adjust the help pointer to avoid negative offsets }
- Dec(JSAMPLE_PTR(help_indexptr), MAXJSAMPLE);
-
- for j := 1 to MAXJSAMPLE do
- begin
- {indexptr^[-j] := indexptr^[0];}
- help_indexptr^[MAXJSAMPLE-j] := indexptr^[0];
- indexptr^[MAXJSAMPLE+j] := indexptr^[MAXJSAMPLE];
- end;
- end;
- end;
-end;
-
-
-{ Create an ordered-dither array for a component having ncolors
- distinct output values. }
-
-{LOCAL}
-function make_odither_array (cinfo : j_decompress_ptr;
- ncolors : int) : ODITHER_MATRIX_PTR;
-var
- odither : ODITHER_MATRIX_PTR;
- j, k : int;
- num, den : INT32;
-begin
- odither := ODITHER_MATRIX_PTR (
- cinfo^.mem^.alloc_small(j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(ODITHER_MATRIX)));
- { The inter-value distance for this color is MAXJSAMPLE/(ncolors-1).
- Hence the dither value for the matrix cell with fill order f
- (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1).
- On 16-bit-int machine, be careful to avoid overflow. }
-
- den := 2 * ODITHER_CELLS * ( INT32(ncolors - 1));
- for j := 0 to pred(ODITHER_SIZE) do
- begin
- for k := 0 to pred(ODITHER_SIZE) do
- begin
- num := ( INT32(ODITHER_CELLS-1 - 2*( int(base_dither_matrix[j][k]))))
- * MAXJSAMPLE;
- { Ensure round towards zero despite C's lack of consistency
- about rounding negative values in integer division... }
-
- if num<0 then
- odither^[j][k] := int (-((-num) div den))
- else
- odither^[j][k] := int (num div den);
- end;
- end;
- make_odither_array := odither;
-end;
-
-
-{ Create the ordered-dither tables.
- Components having the same number of representative colors may
- share a dither table. }
-
-{LOCAL}
-procedure create_odither_tables (cinfo : j_decompress_ptr);
-var
- cquantize : my_cquantize_ptr;
- odither : ODITHER_MATRIX_PTR;
- i, j, nci : int;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
-
- for i := 0 to pred(cinfo^.out_color_components) do
- begin
- nci := cquantize^.Ncolors[i]; { # of distinct values for this color }
- odither := NIL; { search for matching prior component }
- for j := 0 to pred(i) do
- begin
- if (nci = cquantize^.Ncolors[j]) then
- begin
- odither := cquantize^.odither[j];
- break;
- end;
- end;
- if (odither = NIL) then { need a new table? }
- odither := make_odither_array(cinfo, nci);
- cquantize^.odither[i] := odither;
- end;
-end;
-
-
-{ Map some rows of pixels to the output colormapped representation. }
-
-{METHODDEF}
-procedure color_quantize (cinfo : j_decompress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-{ General case, no dithering }
-var
- cquantize : my_cquantize_ptr;
- colorindex : JSAMPARRAY;
- pixcode, ci : int; {register}
- ptrin, ptrout : JSAMPLE_PTR; {register}
- row : int;
- col : JDIMENSION;
- width : JDIMENSION;
- nc : int; {register}
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- colorindex := cquantize^.colorindex;
- width := cinfo^.output_width;
- nc := cinfo^.out_color_components;
-
- for row := 0 to pred(num_rows) do
- begin
- ptrin := JSAMPLE_PTR(input_buf^[row]);
- ptrout := JSAMPLE_PTR(output_buf^[row]);
- for col := pred(width) downto 0 do
- begin
- pixcode := 0;
- for ci := 0 to pred(nc) do
- begin
- Inc(pixcode, GETJSAMPLE(colorindex^[ci]^[GETJSAMPLE(ptrin^)]) );
- Inc(ptrin);
- end;
- ptrout^ := JSAMPLE (pixcode);
- Inc(ptrout);
- end;
- end;
-end;
-
-
-{METHODDEF}
-procedure color_quantize3 (cinfo : j_decompress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-{ Fast path for out_color_components=3, no dithering }
-var
- cquantize : my_cquantize_ptr;
- pixcode : int; {register}
- ptrin, ptrout : JSAMPLE_PTR; {register}
- colorindex0 : JSAMPROW;
- colorindex1 : JSAMPROW;
- colorindex2 : JSAMPROW;
- row : int;
- col : JDIMENSION;
- width : JDIMENSION;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- colorindex0 := (cquantize^.colorindex)^[0];
- colorindex1 := (cquantize^.colorindex)^[1];
- colorindex2 := (cquantize^.colorindex)^[2];
- width := cinfo^.output_width;
-
- for row := 0 to pred(num_rows) do
- begin
- ptrin := JSAMPLE_PTR(input_buf^[row]);
- ptrout := JSAMPLE_PTR(output_buf^[row]);
- for col := pred(width) downto 0 do
- begin
- pixcode := GETJSAMPLE((colorindex0)^[GETJSAMPLE(ptrin^)]);
- Inc(ptrin);
- Inc( pixcode, GETJSAMPLE((colorindex1)^[GETJSAMPLE(ptrin^)]) );
- Inc(ptrin);
- Inc( pixcode, GETJSAMPLE((colorindex2)^[GETJSAMPLE(ptrin^)]) );
- Inc(ptrin);
- ptrout^ := JSAMPLE (pixcode);
- Inc(ptrout);
- end;
- end;
-end;
-
-
-{METHODDEF}
-procedure quantize_ord_dither (cinfo : j_decompress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-{ General case, with ordered dithering }
-var
- cquantize : my_cquantize_ptr;
- input_ptr, {register}
- output_ptr : JSAMPLE_PTR; {register}
- colorindex_ci : JSAMPROW;
- dither : ^ODITHER_vector; { points to active row of dither matrix }
- row_index, col_index : int; { current indexes into dither matrix }
- nc : int;
- ci : int;
- row : int;
- col : JDIMENSION;
- width : JDIMENSION;
-var
- pad_offset : int;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- nc := cinfo^.out_color_components;
- width := cinfo^.output_width;
-
- { Nomssi: work around negative offset }
- if my_cquantize_ptr (cinfo^.cquantize)^.is_padded then
- pad_offset := MAXJSAMPLE
- else
- pad_offset := 0;
-
- for row := 0 to pred(num_rows) do
- begin
- { Initialize output values to 0 so can process components separately }
- jzero_far( {far} pointer(output_buf^[row]),
- size_t(width * SIZEOF(JSAMPLE)));
- row_index := cquantize^.row_index;
- for ci := 0 to pred(nc) do
- begin
- input_ptr := JSAMPLE_PTR(@ input_buf^[row]^[ci]);
- output_ptr := JSAMPLE_PTR(output_buf^[row]);
- colorindex_ci := cquantize^.colorindex^[ci];
- { Nomssi }
- Dec(JSAMPLE_PTR(colorindex_ci), pad_offset);
-
- dither := @(cquantize^.odither[ci]^[row_index]);
- col_index := 0;
-
- for col := pred(width) downto 0 do
- begin
- { Form pixel value + dither, range-limit to 0..MAXJSAMPLE,
- select output value, accumulate into output code for this pixel.
- Range-limiting need not be done explicitly, as we have extended
- the colorindex table to produce the right answers for out-of-range
- inputs. The maximum dither is +- MAXJSAMPLE; this sets the
- required amount of padding. }
-
- Inc(output_ptr^,
- colorindex_ci^[GETJSAMPLE(input_ptr^)+ pad_offset +
- dither^[col_index]]);
- Inc(output_ptr);
- Inc(input_ptr, nc);
- col_index := (col_index + 1) and ODITHER_MASK;
- end;
- end;
- { Advance row index for next row }
- row_index := (row_index + 1) and ODITHER_MASK;
- cquantize^.row_index := row_index;
- end;
-end;
-
-{METHODDEF}
-procedure quantize3_ord_dither (cinfo : j_decompress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-{ Fast path for out_color_components=3, with ordered dithering }
-var
- cquantize : my_cquantize_ptr;
- pixcode : int; {register}
- input_ptr : JSAMPLE_PTR; {register}
- output_ptr : JSAMPLE_PTR; {register}
- colorindex0 : JSAMPROW;
- colorindex1 : JSAMPROW;
- colorindex2 : JSAMPROW;
- dither0 : ^ODITHER_vector; { points to active row of dither matrix }
- dither1 : ^ODITHER_vector;
- dither2 : ^ODITHER_vector;
- row_index, col_index : int; { current indexes into dither matrix }
- row : int;
- col : JDIMENSION;
- width : JDIMENSION;
-var
- pad_offset : int;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- colorindex0 := (cquantize^.colorindex)^[0];
- colorindex1 := (cquantize^.colorindex)^[1];
- colorindex2 := (cquantize^.colorindex)^[2];
- width := cinfo^.output_width;
-
- { Nomssi: work around negative offset }
- if my_cquantize_ptr (cinfo^.cquantize)^.is_padded then
- pad_offset := MAXJSAMPLE
- else
- pad_offset := 0;
-
- Dec(JSAMPLE_PTR(colorindex0), pad_offset);
- Dec(JSAMPLE_PTR(colorindex1), pad_offset);
- Dec(JSAMPLE_PTR(colorindex2), pad_offset);
-
- for row := 0 to pred(num_rows) do
- begin
- row_index := cquantize^.row_index;
- input_ptr := JSAMPLE_PTR(input_buf^[row]);
- output_ptr := JSAMPLE_PTR(output_buf^[row]);
- dither0 := @(cquantize^.odither[0]^[row_index]);
- dither1 := @(cquantize^.odither[1]^[row_index]);
- dither2 := @(cquantize^.odither[2]^[row_index]);
- col_index := 0;
-
-
- for col := pred(width) downto 0 do
- begin
- pixcode := GETJSAMPLE(colorindex0^[GETJSAMPLE(input_ptr^) + pad_offset
- + dither0^[col_index]]);
- Inc(input_ptr);
- Inc(pixcode, GETJSAMPLE(colorindex1^[GETJSAMPLE(input_ptr^) + pad_offset
- + dither1^[col_index]]));
- Inc(input_ptr);
- Inc(pixcode, GETJSAMPLE(colorindex2^[GETJSAMPLE(input_ptr^) + pad_offset
- + dither2^[col_index]]));
- Inc(input_ptr);
- output_ptr^ := JSAMPLE (pixcode);
- Inc(output_ptr);
- col_index := (col_index + 1) and ODITHER_MASK;
- end;
- row_index := (row_index + 1) and ODITHER_MASK;
- cquantize^.row_index := row_index;
- end;
-end;
-
-
-{METHODDEF}
-procedure quantize_fs_dither (cinfo : j_decompress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-{ General case, with Floyd-Steinberg dithering }
-var
- cquantize : my_cquantize_ptr;
- cur : LOCFSERROR; {register} { current error or pixel value }
- belowerr : LOCFSERROR; { error for pixel below cur }
- bpreverr : LOCFSERROR; { error for below/prev col }
- bnexterr : LOCFSERROR; { error for below/next col }
- delta : LOCFSERROR;
- prev_errorptr,
- errorptr : FSERRORPTR; {register} { => fserrors[] at column before current }
- input_ptr, {register}
- output_ptr : JSAMPLE_PTR; {register}
- colorindex_ci : JSAMPROW;
- colormap_ci : JSAMPROW;
- pixcode : int;
- nc : int;
- dir : int; { 1 for left-to-right, -1 for right-to-left }
- dirnc : int; { dir * nc }
- ci : int;
- row : int;
- col : JDIMENSION;
- width : JDIMENSION;
- range_limit : range_limit_table_ptr;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- nc := cinfo^.out_color_components;
- width := cinfo^.output_width;
- range_limit := cinfo^.sample_range_limit;
-
- for row := 0 to pred(num_rows) do
- begin
- { Initialize output values to 0 so can process components separately }
- jzero_far( (output_buf)^[row],
- size_t(width * SIZEOF(JSAMPLE)));
- for ci := 0 to pred(nc) do
- begin
- input_ptr := JSAMPLE_PTR(@ input_buf^[row]^[ci]);
- output_ptr := JSAMPLE_PTR(output_buf^[row]);
- errorptr := FSERRORPTR(cquantize^.fserrors[ci]); { => entry before first column }
- if (cquantize^.on_odd_row) then
- begin
- { work right to left in this row }
- Inc(input_ptr, (width-1) * nc); { so point to rightmost pixel }
- Inc(output_ptr, width-1);
- dir := -1;
- dirnc := -nc;
- Inc(errorptr, (width+1)); { => entry after last column }
- end
- else
- begin
- { work left to right in this row }
- dir := 1;
- dirnc := nc;
- {errorptr := cquantize^.fserrors[ci];}
- end;
-
- colorindex_ci := cquantize^.colorindex^[ci];
-
- colormap_ci := (cquantize^.sv_colormap)^[ci];
- { Preset error values: no error propagated to first pixel from left }
- cur := 0;
- { and no error propagated to row below yet }
- belowerr := 0;
- bpreverr := 0;
-
- for col := pred(width) downto 0 do
- begin
- prev_errorptr := errorptr;
- Inc(errorptr, dir); { advance errorptr to current column }
-
- { cur holds the error propagated from the previous pixel on the
- current line. Add the error propagated from the previous line
- to form the complete error correction term for this pixel, and
- round the error term (which is expressed * 16) to an integer.
- RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct
- for either sign of the error value.
- Note: errorptr points to *previous* column's array entry. }
-
- cur := (cur + errorptr^ + 8) div 16;
-
- { Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
- The maximum error is +- MAXJSAMPLE; this sets the required size
- of the range_limit array. }
-
- Inc( cur, GETJSAMPLE(input_ptr^));
- cur := GETJSAMPLE(range_limit^[cur]);
- { Select output value, accumulate into output code for this pixel }
- pixcode := GETJSAMPLE(colorindex_ci^[cur]);
- Inc(output_ptr^, JSAMPLE (pixcode));
- { Compute actual representation error at this pixel }
- { Note: we can do this even though we don't have the final }
- { pixel code, because the colormap is orthogonal. }
- Dec(cur, GETJSAMPLE(colormap_ci^[pixcode]));
- { Compute error fractions to be propagated to adjacent pixels.
- Add these into the running sums, and simultaneously shift the
- next-line error sums left by 1 column. }
-
- bnexterr := cur;
- delta := cur * 2;
- Inc(cur, delta); { form error * 3 }
- prev_errorptr^ := FSERROR (bpreverr + cur);
- Inc(cur, delta); { form error * 5 }
- bpreverr := belowerr + cur;
- belowerr := bnexterr;
- Inc(cur, delta); { form error * 7 }
- { At this point cur contains the 7/16 error value to be propagated
- to the next pixel on the current line, and all the errors for the
- next line have been shifted over. We are therefore ready to move on. }
-
- Inc(input_ptr, dirnc); { advance input ptr to next column }
- Inc(output_ptr, dir); { advance output ptr to next column }
-
- end;
- { Post-loop cleanup: we must unload the final error value into the
- final fserrors[] entry. Note we need not unload belowerr because
- it is for the dummy column before or after the actual array. }
-
- errorptr^ := FSERROR (bpreverr); { unload prev err into array }
- { Nomssi : ?? }
- end;
- cquantize^.on_odd_row := not cquantize^.on_odd_row;
- end;
-end;
-
-
-{ Allocate workspace for Floyd-Steinberg errors. }
-
-{LOCAL}
-procedure alloc_fs_workspace (cinfo : j_decompress_ptr);
-var
- cquantize : my_cquantize_ptr;
- arraysize : size_t;
- i : int;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- arraysize := size_t ((cinfo^.output_width + 2) * SIZEOF(FSERROR));
- for i := 0 to pred(cinfo^.out_color_components) do
- begin
- cquantize^.fserrors[i] := FS_ERROR_FIELD_PTR(
- cinfo^.mem^.alloc_large(j_common_ptr(cinfo), JPOOL_IMAGE, arraysize));
- end;
-end;
-
-
-{ Initialize for one-pass color quantization. }
-
-{METHODDEF}
-procedure start_pass_1_quant (cinfo : j_decompress_ptr;
- is_pre_scan : boolean); far;
-var
- cquantize : my_cquantize_ptr;
- arraysize : size_t;
- i : int;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- { Install my colormap. }
- cinfo^.colormap := cquantize^.sv_colormap;
- cinfo^.actual_number_of_colors := cquantize^.sv_actual;
-
- { Initialize for desired dithering mode. }
- case (cinfo^.dither_mode) of
- JDITHER_NONE:
- if (cinfo^.out_color_components = 3) then
- cquantize^.pub.color_quantize := color_quantize3
- else
- cquantize^.pub.color_quantize := color_quantize;
- JDITHER_ORDERED:
- begin
- if (cinfo^.out_color_components = 3) then
- cquantize^.pub.color_quantize := quantize3_ord_dither
- else
- cquantize^.pub.color_quantize := quantize_ord_dither;
- cquantize^.row_index := 0; { initialize state for ordered dither }
- { If user changed to ordered dither from another mode,
- we must recreate the color index table with padding.
- This will cost extra space, but probably isn't very likely. }
-
- if (not cquantize^.is_padded) then
- create_colorindex(cinfo);
- { Create ordered-dither tables if we didn't already. }
- if (cquantize^.odither[0] = NIL) then
- create_odither_tables(cinfo);
- end;
- JDITHER_FS:
- begin
- cquantize^.pub.color_quantize := quantize_fs_dither;
- cquantize^.on_odd_row := FALSE; { initialize state for F-S dither }
- { Allocate Floyd-Steinberg workspace if didn't already. }
- if (cquantize^.fserrors[0] = NIL) then
- alloc_fs_workspace(cinfo);
- { Initialize the propagated errors to zero. }
- arraysize := size_t ((cinfo^.output_width + 2) * SIZEOF(FSERROR));
- for i := 0 to pred(cinfo^.out_color_components) do
- jzero_far({far} pointer( cquantize^.fserrors[i] ), arraysize);
- end;
- else
- ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
- end;
-end;
-
-
-{ Finish up at the end of the pass. }
-
-{METHODDEF}
-procedure finish_pass_1_quant (cinfo : j_decompress_ptr); far;
-begin
- { no work in 1-pass case }
-end;
-
-
-{ Switch to a new external colormap between output passes.
- Shouldn't get to this module! }
-
-{METHODDEF}
-procedure new_color_map_1_quant (cinfo : j_decompress_ptr); far;
-begin
- ERREXIT(j_common_ptr(cinfo), JERR_MODE_CHANGE);
-end;
-
-
-{ Module initialization routine for 1-pass color quantization. }
-
-{GLOBAL}
-procedure jinit_1pass_quantizer (cinfo : j_decompress_ptr);
-var
- cquantize : my_cquantize_ptr;
-begin
- cquantize := my_cquantize_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_cquantizer)));
- cinfo^.cquantize := jpeg_color_quantizer_ptr(cquantize);
- cquantize^.pub.start_pass := start_pass_1_quant;
- cquantize^.pub.finish_pass := finish_pass_1_quant;
- cquantize^.pub.new_color_map := new_color_map_1_quant;
- cquantize^.fserrors[0] := NIL; { Flag FS workspace not allocated }
- cquantize^.odither[0] := NIL; { Also flag odither arrays not allocated }
-
- { Make sure my internal arrays won't overflow }
- if (cinfo^.out_color_components > MAX_Q_COMPS) then
- ERREXIT1(j_common_ptr(cinfo), JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
- { Make sure colormap indexes can be represented by JSAMPLEs }
- if (cinfo^.desired_number_of_colors > (MAXJSAMPLE+1)) then
- ERREXIT1(j_common_ptr(cinfo), JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
-
- { Create the colormap and color index table. }
- create_colormap(cinfo);
- create_colorindex(cinfo);
-
- { Allocate Floyd-Steinberg workspace now if requested.
- We do this now since it is FAR storage and may affect the memory
- manager's space calculations. If the user changes to FS dither
- mode in a later pass, we will allocate the space then, and will
- possibly overrun the max_memory_to_use setting. }
-
- if (cinfo^.dither_mode = JDITHER_FS) then
- alloc_fs_workspace(cinfo);
-end;
-
-
-end.
diff --git a/packages/base/pasjpeg/jquant2.pas b/packages/base/pasjpeg/jquant2.pas
deleted file mode 100644
index 1cfd87b610..0000000000
--- a/packages/base/pasjpeg/jquant2.pas
+++ /dev/null
@@ -1,1551 +0,0 @@
-Unit JQuant2;
-
-
-{ This file contains 2-pass color quantization (color mapping) routines.
- These routines provide selection of a custom color map for an image,
- followed by mapping of the image to that color map, with optional
- Floyd-Steinberg dithering.
- It is also possible to use just the second pass to map to an arbitrary
- externally-given color map.
-
- Note: ordered dithering is not supported, since there isn't any fast
- way to compute intercolor distances; it's unclear that ordered dither's
- fundamental assumptions even hold with an irregularly spaced color map. }
-
-{ Original: jquant2.c; Copyright (C) 1991-1996, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jdeferr,
- jerror,
- jutils,
- jpeglib;
-
-{ Module initialization routine for 2-pass color quantization. }
-
-
-{GLOBAL}
-procedure jinit_2pass_quantizer (cinfo : j_decompress_ptr);
-
-implementation
-
-{ This module implements the well-known Heckbert paradigm for color
- quantization. Most of the ideas used here can be traced back to
- Heckbert's seminal paper
- Heckbert, Paul. "Color Image Quantization for Frame Buffer Display",
- Proc. SIGGRAPH '82, Computer Graphics v.16 #3 (July 1982), pp 297-304.
-
- In the first pass over the image, we accumulate a histogram showing the
- usage count of each possible color. To keep the histogram to a reasonable
- size, we reduce the precision of the input; typical practice is to retain
- 5 or 6 bits per color, so that 8 or 4 different input values are counted
- in the same histogram cell.
-
- Next, the color-selection step begins with a box representing the whole
- color space, and repeatedly splits the "largest" remaining box until we
- have as many boxes as desired colors. Then the mean color in each
- remaining box becomes one of the possible output colors.
-
- The second pass over the image maps each input pixel to the closest output
- color (optionally after applying a Floyd-Steinberg dithering correction).
- This mapping is logically trivial, but making it go fast enough requires
- considerable care.
-
- Heckbert-style quantizers vary a good deal in their policies for choosing
- the "largest" box and deciding where to cut it. The particular policies
- used here have proved out well in experimental comparisons, but better ones
- may yet be found.
-
- In earlier versions of the IJG code, this module quantized in YCbCr color
- space, processing the raw upsampled data without a color conversion step.
- This allowed the color conversion math to be done only once per colormap
- entry, not once per pixel. However, that optimization precluded other
- useful optimizations (such as merging color conversion with upsampling)
- and it also interfered with desired capabilities such as quantizing to an
- externally-supplied colormap. We have therefore abandoned that approach.
- The present code works in the post-conversion color space, typically RGB.
-
- To improve the visual quality of the results, we actually work in scaled
- RGB space, giving G distances more weight than R, and R in turn more than
- B. To do everything in integer math, we must use integer scale factors.
- The 2/3/1 scale factors used here correspond loosely to the relative
- weights of the colors in the NTSC grayscale equation.
- If you want to use this code to quantize a non-RGB color space, you'll
- probably need to change these scale factors. }
-
-const
- R_SCALE = 2; { scale R distances by this much }
- G_SCALE = 3; { scale G distances by this much }
- B_SCALE = 1; { and B by this much }
-
-{ Relabel R/G/B as components 0/1/2, respecting the RGB ordering defined
- in jmorecfg.h. As the code stands, it will do the right thing for R,G,B
- and B,G,R orders. If you define some other weird order in jmorecfg.h,
- you'll get compile errors until you extend this logic. In that case
- you'll probably want to tweak the histogram sizes too. }
-
-{$ifdef RGB_RED_IS_0}
-const
- C0_SCALE = R_SCALE;
- C1_SCALE = G_SCALE;
- C2_SCALE = B_SCALE;
-{$else}
-const
- C0_SCALE = B_SCALE;
- C1_SCALE = G_SCALE;
- C2_SCALE = R_SCALE;
-{$endif}
-
-
-{ First we have the histogram data structure and routines for creating it.
-
- The number of bits of precision can be adjusted by changing these symbols.
- We recommend keeping 6 bits for G and 5 each for R and B.
- If you have plenty of memory and cycles, 6 bits all around gives marginally
- better results; if you are short of memory, 5 bits all around will save
- some space but degrade the results.
- To maintain a fully accurate histogram, we'd need to allocate a "long"
- (preferably unsigned long) for each cell. In practice this is overkill;
- we can get by with 16 bits per cell. Few of the cell counts will overflow,
- and clamping those that do overflow to the maximum value will give close-
- enough results. This reduces the recommended histogram size from 256Kb
- to 128Kb, which is a useful savings on PC-class machines.
- (In the second pass the histogram space is re-used for pixel mapping data;
- in that capacity, each cell must be able to store zero to the number of
- desired colors. 16 bits/cell is plenty for that too.)
- Since the JPEG code is intended to run in small memory model on 80x86
- machines, we can't just allocate the histogram in one chunk. Instead
- of a true 3-D array, we use a row of pointers to 2-D arrays. Each
- pointer corresponds to a C0 value (typically 2^5 = 32 pointers) and
- each 2-D array has 2^6*2^5 = 2048 or 2^6*2^6 = 4096 entries. Note that
- on 80x86 machines, the pointer row is in near memory but the actual
- arrays are in far memory (same arrangement as we use for image arrays). }
-
-
-const
- MAXNUMCOLORS = (MAXJSAMPLE+1); { maximum size of colormap }
-
-{ These will do the right thing for either R,G,B or B,G,R color order,
- but you may not like the results for other color orders. }
-
-const
- HIST_C0_BITS = 5; { bits of precision in R/B histogram }
- HIST_C1_BITS = 6; { bits of precision in G histogram }
- HIST_C2_BITS = 5; { bits of precision in B/R histogram }
-
-{ Number of elements along histogram axes. }
-const
- HIST_C0_ELEMS = (1 shl HIST_C0_BITS);
- HIST_C1_ELEMS = (1 shl HIST_C1_BITS);
- HIST_C2_ELEMS = (1 shl HIST_C2_BITS);
-
-{ These are the amounts to shift an input value to get a histogram index. }
-const
- C0_SHIFT = (BITS_IN_JSAMPLE-HIST_C0_BITS);
- C1_SHIFT = (BITS_IN_JSAMPLE-HIST_C1_BITS);
- C2_SHIFT = (BITS_IN_JSAMPLE-HIST_C2_BITS);
-
-
-type { Nomssi }
- RGBptr = ^RGBtype;
- RGBtype = packed record
- r,g,b : JSAMPLE;
- end;
-type
- histcell = UINT16; { histogram cell; prefer an unsigned type }
-
-type
- histptr = ^histcell {FAR}; { for pointers to histogram cells }
-
-type
- hist1d = array[0..HIST_C2_ELEMS-1] of histcell; { typedefs for the array }
- {hist1d_ptr = ^hist1d;}
- hist1d_field = array[0..HIST_C1_ELEMS-1] of hist1d;
- { type for the 2nd-level pointers }
- hist2d = ^hist1d_field;
- hist2d_field = array[0..HIST_C0_ELEMS-1] of hist2d;
- hist3d = ^hist2d_field; { type for top-level pointer }
-
-
-{ Declarations for Floyd-Steinberg dithering.
-
- Errors are accumulated into the array fserrors[], at a resolution of
- 1/16th of a pixel count. The error at a given pixel is propagated
- to its not-yet-processed neighbors using the standard F-S fractions,
- ... (here) 7/16
- 3/16 5/16 1/16
- We work left-to-right on even rows, right-to-left on odd rows.
-
- We can get away with a single array (holding one row's worth of errors)
- by using it to store the current row's errors at pixel columns not yet
- processed, but the next row's errors at columns already processed. We
- need only a few extra variables to hold the errors immediately around the
- current column. (If we are lucky, those variables are in registers, but
- even if not, they're probably cheaper to access than array elements are.)
-
- The fserrors[] array has (#columns + 2) entries; the extra entry at
- each end saves us from special-casing the first and last pixels.
- Each entry is three values long, one value for each color component.
-
- Note: on a wide image, we might not have enough room in a PC's near data
- segment to hold the error array; so it is allocated with alloc_large. }
-
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-type
- FSERROR = INT16; { 16 bits should be enough }
- LOCFSERROR = int; { use 'int' for calculation temps }
-{$else}
-type
- FSERROR = INT32; { may need more than 16 bits }
- LOCFSERROR = INT32; { be sure calculation temps are big enough }
-{$endif}
-type { Nomssi }
- RGB_FSERROR_PTR = ^RGB_FSERROR;
- RGB_FSERROR = packed record
- r,g,b : FSERROR;
- end;
- LOCRGB_FSERROR = packed record
- r,g,b : LOCFSERROR;
- end;
-
-type
- FSERROR_PTR = ^FSERROR;
- jFSError = 0..(MaxInt div SIZEOF(RGB_FSERROR))-1;
- FS_ERROR_FIELD = array[jFSError] of RGB_FSERROR;
- FS_ERROR_FIELD_PTR = ^FS_ERROR_FIELD;{far}
- { pointer to error array (in FAR storage!) }
-
-type
- error_limit_array = array[-MAXJSAMPLE..MAXJSAMPLE] of int;
- { table for clamping the applied error }
- error_limit_ptr = ^error_limit_array;
-
-{ Private subobject }
-type
- my_cquantize_ptr = ^my_cquantizer;
- my_cquantizer = record
- pub : jpeg_color_quantizer; { public fields }
-
- { Space for the eventually created colormap is stashed here }
- sv_colormap : JSAMPARRAY; { colormap allocated at init time }
- desired : int; { desired # of colors = size of colormap }
-
- { Variables for accumulating image statistics }
- histogram : hist3d; { pointer to the histogram }
-
- needs_zeroed : boolean; { TRUE if next pass must zero histogram }
-
- { Variables for Floyd-Steinberg dithering }
- fserrors : FS_ERROR_FIELD_PTR; { accumulated errors }
- on_odd_row : boolean; { flag to remember which row we are on }
- error_limiter : error_limit_ptr; { table for clamping the applied error }
- end;
-
-
-
-{ Prescan some rows of pixels.
- In this module the prescan simply updates the histogram, which has been
- initialized to zeroes by start_pass.
- An output_buf parameter is required by the method signature, but no data
- is actually output (in fact the buffer controller is probably passing a
- NIL pointer). }
-
-{METHODDEF}
-procedure prescan_quantize (cinfo : j_decompress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-var
- cquantize : my_cquantize_ptr;
- {register} ptr : RGBptr;
- {register} histp : histptr;
- {register} histogram : hist3d;
- row : int;
- col : JDIMENSION;
- width : JDIMENSION;
-begin
- cquantize := my_cquantize_ptr(cinfo^.cquantize);
- histogram := cquantize^.histogram;
- width := cinfo^.output_width;
-
- for row := 0 to pred(num_rows) do
- begin
- ptr := RGBptr(input_buf^[row]);
- for col := pred(width) downto 0 do
- begin
- { get pixel value and index into the histogram }
- histp := @(histogram^[GETJSAMPLE(ptr^.r) shr C0_SHIFT]^
- [GETJSAMPLE(ptr^.g) shr C1_SHIFT]
- [GETJSAMPLE(ptr^.b) shr C2_SHIFT]);
- { increment, check for overflow and undo increment if so. }
- Inc(histp^);
- if (histp^ <= 0) then
- Dec(histp^);
- Inc(ptr);
- end;
- end;
-end;
-
-{ Next we have the really interesting routines: selection of a colormap
- given the completed histogram.
- These routines work with a list of "boxes", each representing a rectangular
- subset of the input color space (to histogram precision). }
-
-type
- box = record
- { The bounds of the box (inclusive); expressed as histogram indexes }
- c0min, c0max : int;
- c1min, c1max : int;
- c2min, c2max : int;
- { The volume (actually 2-norm) of the box }
- volume : INT32;
- { The number of nonzero histogram cells within this box }
- colorcount : long;
- end;
-
-type
- jBoxList = 0..(MaxInt div SizeOf(box))-1;
- box_field = array[jBoxlist] of box;
- boxlistptr = ^box_field;
- boxptr = ^box;
-
-{LOCAL}
-function find_biggest_color_pop (boxlist : boxlistptr; numboxes : int) : boxptr;
-{ Find the splittable box with the largest color population }
-{ Returns NIL if no splittable boxes remain }
-var
- boxp : boxptr ; {register}
- i : int; {register}
- maxc : long; {register}
- which : boxptr;
-begin
- which := NIL;
- boxp := @(boxlist^[0]);
- maxc := 0;
- for i := 0 to pred(numboxes) do
- begin
- if (boxp^.colorcount > maxc) and (boxp^.volume > 0) then
- begin
- which := boxp;
- maxc := boxp^.colorcount;
- end;
- Inc(boxp);
- end;
- find_biggest_color_pop := which;
-end;
-
-
-{LOCAL}
-function find_biggest_volume (boxlist : boxlistptr; numboxes : int) : boxptr;
-{ Find the splittable box with the largest (scaled) volume }
-{ Returns NULL if no splittable boxes remain }
-var
- {register} boxp : boxptr;
- {register} i : int;
- {register} maxv : INT32;
- which : boxptr;
-begin
- maxv := 0;
- which := NIL;
- boxp := @(boxlist^[0]);
- for i := 0 to pred(numboxes) do
- begin
- if (boxp^.volume > maxv) then
- begin
- which := boxp;
- maxv := boxp^.volume;
- end;
- Inc(boxp);
- end;
- find_biggest_volume := which;
-end;
-
-
-{LOCAL}
-procedure update_box (cinfo : j_decompress_ptr; var boxp : box);
-label
- have_c0min, have_c0max,
- have_c1min, have_c1max,
- have_c2min, have_c2max;
-{ Shrink the min/max bounds of a box to enclose only nonzero elements, }
-{ and recompute its volume and population }
-var
- cquantize : my_cquantize_ptr;
- histogram : hist3d;
- histp : histptr;
- c0,c1,c2 : int;
- c0min,c0max,c1min,c1max,c2min,c2max : int;
- dist0,dist1,dist2 : INT32;
- ccount : long;
-begin
- cquantize := my_cquantize_ptr(cinfo^.cquantize);
- histogram := cquantize^.histogram;
-
- c0min := boxp.c0min; c0max := boxp.c0max;
- c1min := boxp.c1min; c1max := boxp.c1max;
- c2min := boxp.c2min; c2max := boxp.c2max;
-
- if (c0max > c0min) then
- for c0 := c0min to c0max do
- for c1 := c1min to c1max do
- begin
- histp := @(histogram^[c0]^[c1][c2min]);
- for c2 := c2min to c2max do
- begin
- if (histp^ <> 0) then
- begin
- c0min := c0;
- boxp.c0min := c0min;
- goto have_c0min;
- end;
- Inc(histp);
- end;
- end;
- have_c0min:
- if (c0max > c0min) then
- for c0 := c0max downto c0min do
- for c1 := c1min to c1max do
- begin
- histp := @(histogram^[c0]^[c1][c2min]);
- for c2 := c2min to c2max do
- begin
- if ( histp^ <> 0) then
- begin
- c0max := c0;
- boxp.c0max := c0;
- goto have_c0max;
- end;
- Inc(histp);
- end;
- end;
- have_c0max:
- if (c1max > c1min) then
- for c1 := c1min to c1max do
- for c0 := c0min to c0max do
- begin
- histp := @(histogram^[c0]^[c1][c2min]);
- for c2 := c2min to c2max do
- begin
- if (histp^ <> 0) then
- begin
- c1min := c1;
- boxp.c1min := c1;
- goto have_c1min;
- end;
- Inc(histp);
- end;
- end;
- have_c1min:
- if (c1max > c1min) then
- for c1 := c1max downto c1min do
- for c0 := c0min to c0max do
- begin
- histp := @(histogram^[c0]^[c1][c2min]);
- for c2 := c2min to c2max do
- begin
- if (histp^ <> 0) then
- begin
- c1max := c1;
- boxp.c1max := c1;
- goto have_c1max;
- end;
- Inc(histp);
- end;
- end;
- have_c1max:
- if (c2max > c2min) then
- for c2 := c2min to c2max do
- for c0 := c0min to c0max do
- begin
- histp := @(histogram^[c0]^[c1min][c2]);
- for c1 := c1min to c1max do
- begin
- if (histp^ <> 0) then
- begin
- c2min := c2;
- boxp.c2min := c2min;
- goto have_c2min;
- end;
- Inc(histp, HIST_C2_ELEMS);
- end;
- end;
- have_c2min:
- if (c2max > c2min) then
- for c2 := c2max downto c2min do
- for c0 := c0min to c0max do
- begin
- histp := @(histogram^[c0]^[c1min][c2]);
- for c1 := c1min to c1max do
- begin
- if (histp^ <> 0) then
- begin
- c2max := c2;
- boxp.c2max := c2max;
- goto have_c2max;
- end;
- Inc(histp, HIST_C2_ELEMS);
- end;
- end;
- have_c2max:
-
- { Update box volume.
- We use 2-norm rather than real volume here; this biases the method
- against making long narrow boxes, and it has the side benefit that
- a box is splittable iff norm > 0.
- Since the differences are expressed in histogram-cell units,
- we have to shift back to JSAMPLE units to get consistent distances;
- after which, we scale according to the selected distance scale factors.}
-
- dist0 := ((c0max - c0min) shl C0_SHIFT) * C0_SCALE;
- dist1 := ((c1max - c1min) shl C1_SHIFT) * C1_SCALE;
- dist2 := ((c2max - c2min) shl C2_SHIFT) * C2_SCALE;
- boxp.volume := dist0*dist0 + dist1*dist1 + dist2*dist2;
-
- { Now scan remaining volume of box and compute population }
- ccount := 0;
- for c0 := c0min to c0max do
- for c1 := c1min to c1max do
- begin
- histp := @(histogram^[c0]^[c1][c2min]);
- for c2 := c2min to c2max do
- begin
- if (histp^ <> 0) then
- Inc(ccount);
- Inc(histp);
- end;
- end;
- boxp.colorcount := ccount;
-end;
-
-
-{LOCAL}
-function median_cut (cinfo : j_decompress_ptr; boxlist : boxlistptr;
- numboxes : int; desired_colors : int) : int;
-{ Repeatedly select and split the largest box until we have enough boxes }
-var
- n,lb : int;
- c0,c1,c2,cmax : int;
- {register} b1,b2 : boxptr;
-begin
- while (numboxes < desired_colors) do
- begin
- { Select box to split.
- Current algorithm: by population for first half, then by volume. }
-
- if (numboxes*2 <= desired_colors) then
- b1 := find_biggest_color_pop(boxlist, numboxes)
- else
- b1 := find_biggest_volume(boxlist, numboxes);
-
- if (b1 = NIL) then { no splittable boxes left! }
- break;
- b2 := @(boxlist^[numboxes]); { where new box will go }
- { Copy the color bounds to the new box. }
- b2^.c0max := b1^.c0max; b2^.c1max := b1^.c1max; b2^.c2max := b1^.c2max;
- b2^.c0min := b1^.c0min; b2^.c1min := b1^.c1min; b2^.c2min := b1^.c2min;
- { Choose which axis to split the box on.
- Current algorithm: longest scaled axis.
- See notes in update_box about scaling distances. }
-
- c0 := ((b1^.c0max - b1^.c0min) shl C0_SHIFT) * C0_SCALE;
- c1 := ((b1^.c1max - b1^.c1min) shl C1_SHIFT) * C1_SCALE;
- c2 := ((b1^.c2max - b1^.c2min) shl C2_SHIFT) * C2_SCALE;
- { We want to break any ties in favor of green, then red, blue last.
- This code does the right thing for R,G,B or B,G,R color orders only. }
-
-{$ifdef RGB_RED_IS_0}
- cmax := c1; n := 1;
- if (c0 > cmax) then
- begin
- cmax := c0;
- n := 0;
- end;
- if (c2 > cmax) then
- n := 2;
-{$else}
- cmax := c1;
- n := 1;
- if (c2 > cmax) then
- begin
- cmax := c2;
- n := 2;
- end;
- if (c0 > cmax) then
- n := 0;
-{$endif}
- { Choose split point along selected axis, and update box bounds.
- Current algorithm: split at halfway point.
- (Since the box has been shrunk to minimum volume,
- any split will produce two nonempty subboxes.)
- Note that lb value is max for lower box, so must be < old max. }
-
- case n of
- 0:begin
- lb := (b1^.c0max + b1^.c0min) div 2;
- b1^.c0max := lb;
- b2^.c0min := lb+1;
- end;
- 1:begin
- lb := (b1^.c1max + b1^.c1min) div 2;
- b1^.c1max := lb;
- b2^.c1min := lb+1;
- end;
- 2:begin
- lb := (b1^.c2max + b1^.c2min) div 2;
- b1^.c2max := lb;
- b2^.c2min := lb+1;
- end;
- end;
- { Update stats for boxes }
- update_box(cinfo, b1^);
- update_box(cinfo, b2^);
- Inc(numboxes);
- end;
- median_cut := numboxes;
-end;
-
-
-{LOCAL}
-procedure compute_color (cinfo : j_decompress_ptr;
- const boxp : box; icolor : int);
-{ Compute representative color for a box, put it in colormap[icolor] }
-var
- { Current algorithm: mean weighted by pixels (not colors) }
- { Note it is important to get the rounding correct! }
- cquantize : my_cquantize_ptr;
- histogram : hist3d;
- histp : histptr;
- c0,c1,c2 : int;
- c0min,c0max,c1min,c1max,c2min,c2max : int;
- count : long;
- total : long;
- c0total : long;
- c1total : long;
- c2total : long;
-begin
- cquantize := my_cquantize_ptr(cinfo^.cquantize);
- histogram := cquantize^.histogram;
- total := 0;
- c0total := 0;
- c1total := 0;
- c2total := 0;
-
- c0min := boxp.c0min; c0max := boxp.c0max;
- c1min := boxp.c1min; c1max := boxp.c1max;
- c2min := boxp.c2min; c2max := boxp.c2max;
-
- for c0 := c0min to c0max do
- for c1 := c1min to c1max do
- begin
- histp := @(histogram^[c0]^[c1][c2min]);
- for c2 := c2min to c2max do
- begin
- count := histp^;
- Inc(histp);
- if (count <> 0) then
- begin
- Inc(total, count);
- Inc(c0total, ((c0 shl C0_SHIFT) + ((1 shl C0_SHIFT) shr 1)) * count);
- Inc(c1total, ((c1 shl C1_SHIFT) + ((1 shl C1_SHIFT) shr 1)) * count);
- Inc(c2total, ((c2 shl C2_SHIFT) + ((1 shl C2_SHIFT) shr 1)) * count);
- end;
- end;
- end;
-
- cinfo^.colormap^[0]^[icolor] := JSAMPLE ((c0total + (total shr 1)) div total);
- cinfo^.colormap^[1]^[icolor] := JSAMPLE ((c1total + (total shr 1)) div total);
- cinfo^.colormap^[2]^[icolor] := JSAMPLE ((c2total + (total shr 1)) div total);
-end;
-
-
-{LOCAL}
-procedure select_colors (cinfo : j_decompress_ptr; desired_colors : int);
-{ Master routine for color selection }
-var
- boxlist : boxlistptr;
- numboxes : int;
- i : int;
-begin
- { Allocate workspace for box list }
- boxlist := boxlistptr(cinfo^.mem^.alloc_small(
- j_common_ptr(cinfo), JPOOL_IMAGE, desired_colors * SIZEOF(box)));
- { Initialize one box containing whole space }
- numboxes := 1;
- boxlist^[0].c0min := 0;
- boxlist^[0].c0max := MAXJSAMPLE shr C0_SHIFT;
- boxlist^[0].c1min := 0;
- boxlist^[0].c1max := MAXJSAMPLE shr C1_SHIFT;
- boxlist^[0].c2min := 0;
- boxlist^[0].c2max := MAXJSAMPLE shr C2_SHIFT;
- { Shrink it to actually-used volume and set its statistics }
- update_box(cinfo, boxlist^[0]);
- { Perform median-cut to produce final box list }
- numboxes := median_cut(cinfo, boxlist, numboxes, desired_colors);
- { Compute the representative color for each box, fill colormap }
- for i := 0 to pred(numboxes) do
- compute_color(cinfo, boxlist^[i], i);
- cinfo^.actual_number_of_colors := numboxes;
- {$IFDEF DEBUG}
- TRACEMS1(j_common_ptr(cinfo), 1, JTRC_QUANT_SELECTED, numboxes);
- {$ENDIF}
-end;
-
-
-{ These routines are concerned with the time-critical task of mapping input
- colors to the nearest color in the selected colormap.
-
- We re-use the histogram space as an "inverse color map", essentially a
- cache for the results of nearest-color searches. All colors within a
- histogram cell will be mapped to the same colormap entry, namely the one
- closest to the cell's center. This may not be quite the closest entry to
- the actual input color, but it's almost as good. A zero in the cache
- indicates we haven't found the nearest color for that cell yet; the array
- is cleared to zeroes before starting the mapping pass. When we find the
- nearest color for a cell, its colormap index plus one is recorded in the
- cache for future use. The pass2 scanning routines call fill_inverse_cmap
- when they need to use an unfilled entry in the cache.
-
- Our method of efficiently finding nearest colors is based on the "locally
- sorted search" idea described by Heckbert and on the incremental distance
- calculation described by Spencer W. Thomas in chapter III.1 of Graphics
- Gems II (James Arvo, ed. Academic Press, 1991). Thomas points out that
- the distances from a given colormap entry to each cell of the histogram can
- be computed quickly using an incremental method: the differences between
- distances to adjacent cells themselves differ by a constant. This allows a
- fairly fast implementation of the "brute force" approach of computing the
- distance from every colormap entry to every histogram cell. Unfortunately,
- it needs a work array to hold the best-distance-so-far for each histogram
- cell (because the inner loop has to be over cells, not colormap entries).
- The work array elements have to be INT32s, so the work array would need
- 256Kb at our recommended precision. This is not feasible in DOS machines.
-
- To get around these problems, we apply Thomas' method to compute the
- nearest colors for only the cells within a small subbox of the histogram.
- The work array need be only as big as the subbox, so the memory usage
- problem is solved. Furthermore, we need not fill subboxes that are never
- referenced in pass2; many images use only part of the color gamut, so a
- fair amount of work is saved. An additional advantage of this
- approach is that we can apply Heckbert's locality criterion to quickly
- eliminate colormap entries that are far away from the subbox; typically
- three-fourths of the colormap entries are rejected by Heckbert's criterion,
- and we need not compute their distances to individual cells in the subbox.
- The speed of this approach is heavily influenced by the subbox size: too
- small means too much overhead, too big loses because Heckbert's criterion
- can't eliminate as many colormap entries. Empirically the best subbox
- size seems to be about 1/512th of the histogram (1/8th in each direction).
-
- Thomas' article also describes a refined method which is asymptotically
- faster than the brute-force method, but it is also far more complex and
- cannot efficiently be applied to small subboxes. It is therefore not
- useful for programs intended to be portable to DOS machines. On machines
- with plenty of memory, filling the whole histogram in one shot with Thomas'
- refined method might be faster than the present code --- but then again,
- it might not be any faster, and it's certainly more complicated. }
-
-
-
-{ log2(histogram cells in update box) for each axis; this can be adjusted }
-const
- BOX_C0_LOG = (HIST_C0_BITS-3);
- BOX_C1_LOG = (HIST_C1_BITS-3);
- BOX_C2_LOG = (HIST_C2_BITS-3);
-
- BOX_C0_ELEMS = (1 shl BOX_C0_LOG); { # of hist cells in update box }
- BOX_C1_ELEMS = (1 shl BOX_C1_LOG);
- BOX_C2_ELEMS = (1 shl BOX_C2_LOG);
-
- BOX_C0_SHIFT = (C0_SHIFT + BOX_C0_LOG);
- BOX_C1_SHIFT = (C1_SHIFT + BOX_C1_LOG);
- BOX_C2_SHIFT = (C2_SHIFT + BOX_C2_LOG);
-
-
-{ The next three routines implement inverse colormap filling. They could
- all be folded into one big routine, but splitting them up this way saves
- some stack space (the mindist[] and bestdist[] arrays need not coexist)
- and may allow some compilers to produce better code by registerizing more
- inner-loop variables. }
-
-{LOCAL}
-function find_nearby_colors (cinfo : j_decompress_ptr;
- minc0 : int; minc1 : int; minc2 : int;
- var colorlist : array of JSAMPLE) : int;
-{ Locate the colormap entries close enough to an update box to be candidates
- for the nearest entry to some cell(s) in the update box. The update box
- is specified by the center coordinates of its first cell. The number of
- candidate colormap entries is returned, and their colormap indexes are
- placed in colorlist[].
- This routine uses Heckbert's "locally sorted search" criterion to select
- the colors that need further consideration. }
-
-var
- numcolors : int;
- maxc0, maxc1, maxc2 : int;
- centerc0, centerc1, centerc2 : int;
- i, x, ncolors : int;
- minmaxdist, min_dist, max_dist, tdist : INT32;
- mindist : array[0..MAXNUMCOLORS-1] of INT32;
- { min distance to colormap entry i }
-begin
- numcolors := cinfo^.actual_number_of_colors;
-
- { Compute true coordinates of update box's upper corner and center.
- Actually we compute the coordinates of the center of the upper-corner
- histogram cell, which are the upper bounds of the volume we care about.
- Note that since ">>" rounds down, the "center" values may be closer to
- min than to max; hence comparisons to them must be "<=", not "<". }
-
- maxc0 := minc0 + ((1 shl BOX_C0_SHIFT) - (1 shl C0_SHIFT));
- centerc0 := (minc0 + maxc0) shr 1;
- maxc1 := minc1 + ((1 shl BOX_C1_SHIFT) - (1 shl C1_SHIFT));
- centerc1 := (minc1 + maxc1) shr 1;
- maxc2 := minc2 + ((1 shl BOX_C2_SHIFT) - (1 shl C2_SHIFT));
- centerc2 := (minc2 + maxc2) shr 1;
-
- { For each color in colormap, find:
- 1. its minimum squared-distance to any point in the update box
- (zero if color is within update box);
- 2. its maximum squared-distance to any point in the update box.
- Both of these can be found by considering only the corners of the box.
- We save the minimum distance for each color in mindist[];
- only the smallest maximum distance is of interest. }
-
- minmaxdist := long($7FFFFFFF);
-
- for i := 0 to pred(numcolors) do
- begin
- { We compute the squared-c0-distance term, then add in the other two. }
- x := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- if (x < minc0) then
- begin
- tdist := (x - minc0) * C0_SCALE;
- min_dist := tdist*tdist;
- tdist := (x - maxc0) * C0_SCALE;
- max_dist := tdist*tdist;
- end
- else
- if (x > maxc0) then
- begin
- tdist := (x - maxc0) * C0_SCALE;
- min_dist := tdist*tdist;
- tdist := (x - minc0) * C0_SCALE;
- max_dist := tdist*tdist;
- end
- else
- begin
- { within cell range so no contribution to min_dist }
- min_dist := 0;
- if (x <= centerc0) then
- begin
- tdist := (x - maxc0) * C0_SCALE;
- max_dist := tdist*tdist;
- end
- else
- begin
- tdist := (x - minc0) * C0_SCALE;
- max_dist := tdist*tdist;
- end;
- end;
-
- x := GETJSAMPLE(cinfo^.colormap^[1]^[i]);
- if (x < minc1) then
- begin
- tdist := (x - minc1) * C1_SCALE;
- Inc(min_dist, tdist*tdist);
- tdist := (x - maxc1) * C1_SCALE;
- Inc(max_dist, tdist*tdist);
- end
- else
- if (x > maxc1) then
- begin
- tdist := (x - maxc1) * C1_SCALE;
- Inc(min_dist, tdist*tdist);
- tdist := (x - minc1) * C1_SCALE;
- Inc(max_dist, tdist*tdist);
- end
- else
- begin
- { within cell range so no contribution to min_dist }
- if (x <= centerc1) then
- begin
- tdist := (x - maxc1) * C1_SCALE;
- Inc(max_dist, tdist*tdist);
- end
- else
- begin
- tdist := (x - minc1) * C1_SCALE;
- Inc(max_dist, tdist*tdist);
- end
- end;
-
- x := GETJSAMPLE(cinfo^.colormap^[2]^[i]);
- if (x < minc2) then
- begin
- tdist := (x - minc2) * C2_SCALE;
- Inc(min_dist, tdist*tdist);
- tdist := (x - maxc2) * C2_SCALE;
- Inc(max_dist, tdist*tdist);
- end
- else
- if (x > maxc2) then
- begin
- tdist := (x - maxc2) * C2_SCALE;
- Inc(min_dist, tdist*tdist);
- tdist := (x - minc2) * C2_SCALE;
- Inc(max_dist, tdist*tdist);
- end
- else
- begin
- { within cell range so no contribution to min_dist }
- if (x <= centerc2) then
- begin
- tdist := (x - maxc2) * C2_SCALE;
- Inc(max_dist, tdist*tdist);
- end
- else
- begin
- tdist := (x - minc2) * C2_SCALE;
- Inc(max_dist, tdist*tdist);
- end;
- end;
-
- mindist[i] := min_dist; { save away the results }
- if (max_dist < minmaxdist) then
- minmaxdist := max_dist;
- end;
-
- { Now we know that no cell in the update box is more than minmaxdist
- away from some colormap entry. Therefore, only colors that are
- within minmaxdist of some part of the box need be considered. }
-
- ncolors := 0;
- for i := 0 to pred(numcolors) do
- begin
- if (mindist[i] <= minmaxdist) then
- begin
- colorlist[ncolors] := JSAMPLE(i);
- Inc(ncolors);
- end;
- end;
- find_nearby_colors := ncolors;
-end;
-
-
-{LOCAL}
-procedure find_best_colors (cinfo : j_decompress_ptr;
- minc0 : int; minc1 : int; minc2 : int;
- numcolors : int;
- var colorlist : array of JSAMPLE;
- var bestcolor : array of JSAMPLE);
-{ Find the closest colormap entry for each cell in the update box,
- given the list of candidate colors prepared by find_nearby_colors.
- Return the indexes of the closest entries in the bestcolor[] array.
- This routine uses Thomas' incremental distance calculation method to
- find the distance from a colormap entry to successive cells in the box. }
-const
- { Nominal steps between cell centers ("x" in Thomas article) }
- STEP_C0 = ((1 shl C0_SHIFT) * C0_SCALE);
- STEP_C1 = ((1 shl C1_SHIFT) * C1_SCALE);
- STEP_C2 = ((1 shl C2_SHIFT) * C2_SCALE);
-var
- ic0, ic1, ic2 : int;
- i, icolor : int;
- {register} bptr : INT32PTR; { pointer into bestdist[] array }
- cptr : JSAMPLE_PTR; { pointer into bestcolor[] array }
- dist0, dist1 : INT32; { initial distance values }
- {register} dist2 : INT32; { current distance in inner loop }
- xx0, xx1 : INT32; { distance increments }
- {register} xx2 : INT32;
- inc0, inc1, inc2 : INT32; { initial values for increments }
- { This array holds the distance to the nearest-so-far color for each cell }
- bestdist : array[0..BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS-1] of INT32;
-begin
- { Initialize best-distance for each cell of the update box }
- for i := BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1 downto 0 do
- bestdist[i] := $7FFFFFFF;
-
- { For each color selected by find_nearby_colors,
- compute its distance to the center of each cell in the box.
- If that's less than best-so-far, update best distance and color number. }
-
-
-
- for i := 0 to pred(numcolors) do
- begin
- icolor := GETJSAMPLE(colorlist[i]);
- { Compute (square of) distance from minc0/c1/c2 to this color }
- inc0 := (minc0 - GETJSAMPLE(cinfo^.colormap^[0]^[icolor])) * C0_SCALE;
- dist0 := inc0*inc0;
- inc1 := (minc1 - GETJSAMPLE(cinfo^.colormap^[1]^[icolor])) * C1_SCALE;
- Inc(dist0, inc1*inc1);
- inc2 := (minc2 - GETJSAMPLE(cinfo^.colormap^[2]^[icolor])) * C2_SCALE;
- Inc(dist0, inc2*inc2);
- { Form the initial difference increments }
- inc0 := inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
- inc1 := inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
- inc2 := inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
- { Now loop over all cells in box, updating distance per Thomas method }
- bptr := @bestdist[0];
- cptr := @bestcolor[0];
- xx0 := inc0;
- for ic0 := BOX_C0_ELEMS-1 downto 0 do
- begin
- dist1 := dist0;
- xx1 := inc1;
- for ic1 := BOX_C1_ELEMS-1 downto 0 do
- begin
- dist2 := dist1;
- xx2 := inc2;
- for ic2 := BOX_C2_ELEMS-1 downto 0 do
- begin
- if (dist2 < bptr^) then
- begin
- bptr^ := dist2;
- cptr^ := JSAMPLE (icolor);
- end;
- Inc(dist2, xx2);
- Inc(xx2, 2 * STEP_C2 * STEP_C2);
- Inc(bptr);
- Inc(cptr);
- end;
- Inc(dist1, xx1);
- Inc(xx1, 2 * STEP_C1 * STEP_C1);
- end;
- Inc(dist0, xx0);
- Inc(xx0, 2 * STEP_C0 * STEP_C0);
- end;
- end;
-end;
-
-
-{LOCAL}
-procedure fill_inverse_cmap (cinfo : j_decompress_ptr;
- c0 : int; c1 : int; c2 : int);
-{ Fill the inverse-colormap entries in the update box that contains }
-{ histogram cell c0/c1/c2. (Only that one cell MUST be filled, but }
-{ we can fill as many others as we wish.) }
-var
- cquantize : my_cquantize_ptr;
- histogram : hist3d;
- minc0, minc1, minc2 : int; { lower left corner of update box }
- ic0, ic1, ic2 : int;
- {register} cptr : JSAMPLE_PTR; { pointer into bestcolor[] array }
- {register} cachep : histptr; { pointer into main cache array }
- { This array lists the candidate colormap indexes. }
- colorlist : array[0..MAXNUMCOLORS-1] of JSAMPLE;
- numcolors : int; { number of candidate colors }
- { This array holds the actually closest colormap index for each cell. }
- bestcolor : array[0..BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS-1] of JSAMPLE;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- histogram := cquantize^.histogram;
-
- { Convert cell coordinates to update box ID }
- c0 := c0 shr BOX_C0_LOG;
- c1 := c1 shr BOX_C1_LOG;
- c2 := c2 shr BOX_C2_LOG;
-
- { Compute true coordinates of update box's origin corner.
- Actually we compute the coordinates of the center of the corner
- histogram cell, which are the lower bounds of the volume we care about.}
-
- minc0 := (c0 shl BOX_C0_SHIFT) + ((1 shl C0_SHIFT) shr 1);
- minc1 := (c1 shl BOX_C1_SHIFT) + ((1 shl C1_SHIFT) shr 1);
- minc2 := (c2 shl BOX_C2_SHIFT) + ((1 shl C2_SHIFT) shr 1);
-
- { Determine which colormap entries are close enough to be candidates
- for the nearest entry to some cell in the update box. }
-
- numcolors := find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
-
- { Determine the actually nearest colors. }
- find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
- bestcolor);
-
- { Save the best color numbers (plus 1) in the main cache array }
- c0 := c0 shl BOX_C0_LOG; { convert ID back to base cell indexes }
- c1 := c1 shl BOX_C1_LOG;
- c2 := c2 shl BOX_C2_LOG;
- cptr := @(bestcolor[0]);
- for ic0 := 0 to pred(BOX_C0_ELEMS) do
- for ic1 := 0 to pred(BOX_C1_ELEMS) do
- begin
- cachep := @(histogram^[c0+ic0]^[c1+ic1][c2]);
- for ic2 := 0 to pred(BOX_C2_ELEMS) do
- begin
- cachep^ := histcell (GETJSAMPLE(cptr^) + 1);
- Inc(cachep);
- Inc(cptr);
- end;
- end;
-end;
-
-
-{ Map some rows of pixels to the output colormapped representation. }
-
-{METHODDEF}
-procedure pass2_no_dither (cinfo : j_decompress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-{ This version performs no dithering }
-var
- cquantize : my_cquantize_ptr;
- histogram : hist3d;
- {register} inptr : RGBptr;
- outptr : JSAMPLE_PTR;
- {register} cachep : histptr;
- {register} c0, c1, c2 : int;
- row : int;
- col : JDIMENSION;
- width : JDIMENSION;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- histogram := cquantize^.histogram;
- width := cinfo^.output_width;
-
- for row := 0 to pred(num_rows) do
- begin
- inptr := RGBptr(input_buf^[row]);
- outptr := JSAMPLE_PTR(output_buf^[row]);
- for col := pred(width) downto 0 do
- begin
- { get pixel value and index into the cache }
- c0 := GETJSAMPLE(inptr^.r) shr C0_SHIFT;
- c1 := GETJSAMPLE(inptr^.g) shr C1_SHIFT;
- c2 := GETJSAMPLE(inptr^.b) shr C2_SHIFT;
- Inc(inptr);
- cachep := @(histogram^[c0]^[c1][c2]);
- { If we have not seen this color before, find nearest colormap entry }
- { and update the cache }
- if (cachep^ = 0) then
- fill_inverse_cmap(cinfo, c0,c1,c2);
- { Now emit the colormap index for this cell }
- outptr^ := JSAMPLE (cachep^ - 1);
- Inc(outptr);
- end;
- end;
-end;
-
-
-{METHODDEF}
-procedure pass2_fs_dither (cinfo : j_decompress_ptr;
- input_buf : JSAMPARRAY;
- output_buf : JSAMPARRAY;
- num_rows : int); far;
-{ This version performs Floyd-Steinberg dithering }
-var
- cquantize : my_cquantize_ptr;
- histogram : hist3d;
- {register} cur : LOCRGB_FSERROR; { current error or pixel value }
- belowerr : LOCRGB_FSERROR; { error for pixel below cur }
- bpreverr : LOCRGB_FSERROR; { error for below/prev col }
- prev_errorptr,
- {register} errorptr : RGB_FSERROR_PTR; { => fserrors[] at column before current }
- inptr : RGBptr; { => current input pixel }
- outptr : JSAMPLE_PTR; { => current output pixel }
- cachep : histptr;
- dir : int; { +1 or -1 depending on direction }
- row : int;
- col : JDIMENSION;
- width : JDIMENSION;
- range_limit : range_limit_table_ptr;
- error_limit : error_limit_ptr;
- colormap0 : JSAMPROW;
- colormap1 : JSAMPROW;
- colormap2 : JSAMPROW;
- {register} pixcode : int;
- {register} bnexterr, delta : LOCFSERROR;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- histogram := cquantize^.histogram;
- width := cinfo^.output_width;
- range_limit := cinfo^.sample_range_limit;
- error_limit := cquantize^.error_limiter;
- colormap0 := cinfo^.colormap^[0];
- colormap1 := cinfo^.colormap^[1];
- colormap2 := cinfo^.colormap^[2];
-
- for row := 0 to pred(num_rows) do
- begin
- inptr := RGBptr(input_buf^[row]);
- outptr := JSAMPLE_PTR(output_buf^[row]);
- errorptr := RGB_FSERROR_PTR(cquantize^.fserrors); { => entry before first real column }
- if (cquantize^.on_odd_row) then
- begin
- { work right to left in this row }
- Inc(inptr, (width-1)); { so point to rightmost pixel }
- Inc(outptr, width-1);
- dir := -1;
- Inc(errorptr, (width+1)); { => entry after last column }
- cquantize^.on_odd_row := FALSE; { flip for next time }
- end
- else
- begin
- { work left to right in this row }
- dir := 1;
- cquantize^.on_odd_row := TRUE; { flip for next time }
- end;
-
- { Preset error values: no error propagated to first pixel from left }
- cur.r := 0;
- cur.g := 0;
- cur.b := 0;
- { and no error propagated to row below yet }
- belowerr.r := 0;
- belowerr.g := 0;
- belowerr.b := 0;
- bpreverr.r := 0;
- bpreverr.g := 0;
- bpreverr.b := 0;
-
- for col := pred(width) downto 0 do
- begin
- prev_errorptr := errorptr;
- Inc(errorptr, dir); { advance errorptr to current column }
-
- { curN holds the error propagated from the previous pixel on the
- current line. Add the error propagated from the previous line
- to form the complete error correction term for this pixel, and
- round the error term (which is expressed * 16) to an integer.
- RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct
- for either sign of the error value.
- Note: prev_errorptr points to *previous* column's array entry. }
-
- { Nomssi Note: Borland Pascal SHR is unsigned }
- cur.r := (cur.r + errorptr^.r + 8) div 16;
- cur.g := (cur.g + errorptr^.g + 8) div 16;
- cur.b := (cur.b + errorptr^.b + 8) div 16;
- { Limit the error using transfer function set by init_error_limit.
- See comments with init_error_limit for rationale. }
-
- cur.r := error_limit^[cur.r];
- cur.g := error_limit^[cur.g];
- cur.b := error_limit^[cur.b];
- { Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
- The maximum error is +- MAXJSAMPLE (or less with error limiting);
- this sets the required size of the range_limit array. }
-
- Inc(cur.r, GETJSAMPLE(inptr^.r));
- Inc(cur.g, GETJSAMPLE(inptr^.g));
- Inc(cur.b, GETJSAMPLE(inptr^.b));
-
- cur.r := GETJSAMPLE(range_limit^[cur.r]);
- cur.g := GETJSAMPLE(range_limit^[cur.g]);
- cur.b := GETJSAMPLE(range_limit^[cur.b]);
- { Index into the cache with adjusted pixel value }
- cachep := @(histogram^[cur.r shr C0_SHIFT]^
- [cur.g shr C1_SHIFT][cur.b shr C2_SHIFT]);
- { If we have not seen this color before, find nearest colormap }
- { entry and update the cache }
- if (cachep^ = 0) then
- fill_inverse_cmap(cinfo, cur.r shr C0_SHIFT,
- cur.g shr C1_SHIFT,
- cur.b shr C2_SHIFT);
- { Now emit the colormap index for this cell }
-
- pixcode := cachep^ - 1;
- outptr^ := JSAMPLE (pixcode);
-
- { Compute representation error for this pixel }
- Dec(cur.r, GETJSAMPLE(colormap0^[pixcode]));
- Dec(cur.g, GETJSAMPLE(colormap1^[pixcode]));
- Dec(cur.b, GETJSAMPLE(colormap2^[pixcode]));
-
- { Compute error fractions to be propagated to adjacent pixels.
- Add these into the running sums, and simultaneously shift the
- next-line error sums left by 1 column. }
-
- bnexterr := cur.r; { Process component 0 }
- delta := cur.r * 2;
- Inc(cur.r, delta); { form error * 3 }
- prev_errorptr^.r := FSERROR (bpreverr.r + cur.r);
- Inc(cur.r, delta); { form error * 5 }
- bpreverr.r := belowerr.r + cur.r;
- belowerr.r := bnexterr;
- Inc(cur.r, delta); { form error * 7 }
- bnexterr := cur.g; { Process component 1 }
- delta := cur.g * 2;
- Inc(cur.g, delta); { form error * 3 }
- prev_errorptr^.g := FSERROR (bpreverr.g + cur.g);
- Inc(cur.g, delta); { form error * 5 }
- bpreverr.g := belowerr.g + cur.g;
- belowerr.g := bnexterr;
- Inc(cur.g, delta); { form error * 7 }
- bnexterr := cur.b; { Process component 2 }
- delta := cur.b * 2;
- Inc(cur.b, delta); { form error * 3 }
- prev_errorptr^.b := FSERROR (bpreverr.b + cur.b);
- Inc(cur.b, delta); { form error * 5 }
- bpreverr.b := belowerr.b + cur.b;
- belowerr.b := bnexterr;
- Inc(cur.b, delta); { form error * 7 }
-
- { At this point curN contains the 7/16 error value to be propagated
- to the next pixel on the current line, and all the errors for the
- next line have been shifted over. We are therefore ready to move on.}
-
- Inc(inptr, dir); { Advance pixel pointers to next column }
- Inc(outptr, dir);
- end;
- { Post-loop cleanup: we must unload the final error values into the
- final fserrors[] entry. Note we need not unload belowerrN because
- it is for the dummy column before or after the actual array. }
-
- errorptr^.r := FSERROR (bpreverr.r); { unload prev errs into array }
- errorptr^.g := FSERROR (bpreverr.g);
- errorptr^.b := FSERROR (bpreverr.b);
- end;
-end;
-
-
-{ Initialize the error-limiting transfer function (lookup table).
- The raw F-S error computation can potentially compute error values of up to
- +- MAXJSAMPLE. But we want the maximum correction applied to a pixel to be
- much less, otherwise obviously wrong pixels will be created. (Typical
- effects include weird fringes at color-area boundaries, isolated bright
- pixels in a dark area, etc.) The standard advice for avoiding this problem
- is to ensure that the "corners" of the color cube are allocated as output
- colors; then repeated errors in the same direction cannot cause cascading
- error buildup. However, that only prevents the error from getting
- completely out of hand; Aaron Giles reports that error limiting improves
- the results even with corner colors allocated.
- A simple clamping of the error values to about +- MAXJSAMPLE/8 works pretty
- well, but the smoother transfer function used below is even better. Thanks
- to Aaron Giles for this idea. }
-
-{LOCAL}
-procedure init_error_limit (cinfo : j_decompress_ptr);
-const
- STEPSIZE = ((MAXJSAMPLE+1) div 16);
-{ Allocate and fill in the error_limiter table }
-var
- cquantize : my_cquantize_ptr;
- table : error_limit_ptr;
- inp, out : int;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- table := error_limit_ptr (cinfo^.mem^.alloc_small
- (j_common_ptr (cinfo), JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int)));
- { not needed: Inc(table, MAXJSAMPLE);
- so can index -MAXJSAMPLE .. +MAXJSAMPLE }
- cquantize^.error_limiter := table;
- { Map errors 1:1 up to +- MAXJSAMPLE/16 }
- out := 0;
- for inp := 0 to pred(STEPSIZE) do
- begin
- table^[inp] := out;
- table^[-inp] := -out;
- Inc(out);
- end;
- { Map errors 1:2 up to +- 3*MAXJSAMPLE/16 }
- inp := STEPSIZE; { Nomssi: avoid problems with Delphi2 optimizer }
- while (inp < STEPSIZE*3) do
- begin
- table^[inp] := out;
- table^[-inp] := -out;
- Inc(inp);
- if Odd(inp) then
- Inc(out);
- end;
- { Clamp the rest to final out value (which is (MAXJSAMPLE+1)/8) }
- inp := STEPSIZE*3; { Nomssi: avoid problems with Delphi 2 optimizer }
- while inp <= MAXJSAMPLE do
- begin
- table^[inp] := out;
- table^[-inp] := -out;
- Inc(inp);
- end;
-end;
-
-{ Finish up at the end of each pass. }
-
-{METHODDEF}
-procedure finish_pass1 (cinfo : j_decompress_ptr); far;
-var
- cquantize : my_cquantize_ptr;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
-
- { Select the representative colors and fill in cinfo^.colormap }
- cinfo^.colormap := cquantize^.sv_colormap;
- select_colors(cinfo, cquantize^.desired);
- { Force next pass to zero the color index table }
- cquantize^.needs_zeroed := TRUE;
-end;
-
-
-{METHODDEF}
-procedure finish_pass2 (cinfo : j_decompress_ptr); far;
-begin
- { no work }
-end;
-
-
-{ Initialize for each processing pass. }
-
-{METHODDEF}
-procedure start_pass_2_quant (cinfo : j_decompress_ptr;
- is_pre_scan : boolean); far;
-var
- cquantize : my_cquantize_ptr;
- histogram : hist3d;
- i : int;
-var
- arraysize : size_t;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
- histogram := cquantize^.histogram;
- { Only F-S dithering or no dithering is supported. }
- { If user asks for ordered dither, give him F-S. }
- if (cinfo^.dither_mode <> JDITHER_NONE) then
- cinfo^.dither_mode := JDITHER_FS;
-
- if (is_pre_scan) then
- begin
- { Set up method pointers }
- cquantize^.pub.color_quantize := prescan_quantize;
- cquantize^.pub.finish_pass := finish_pass1;
- cquantize^.needs_zeroed := TRUE; { Always zero histogram }
- end
- else
- begin
- { Set up method pointers }
- if (cinfo^.dither_mode = JDITHER_FS) then
- cquantize^.pub.color_quantize := pass2_fs_dither
- else
- cquantize^.pub.color_quantize := pass2_no_dither;
- cquantize^.pub.finish_pass := finish_pass2;
-
- { Make sure color count is acceptable }
- i := cinfo^.actual_number_of_colors;
- if (i < 1) then
- ERREXIT1(j_common_ptr(cinfo), JERR_QUANT_FEW_COLORS, 1);
- if (i > MAXNUMCOLORS) then
- ERREXIT1(j_common_ptr(cinfo), JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
-
- if (cinfo^.dither_mode = JDITHER_FS) then
- begin
- arraysize := size_t ((cinfo^.output_width + 2) *
- (3 * SIZEOF(FSERROR)));
- { Allocate Floyd-Steinberg workspace if we didn't already. }
- if (cquantize^.fserrors = NIL) then
- cquantize^.fserrors := FS_ERROR_FIELD_PTR (cinfo^.mem^.alloc_large
- (j_common_ptr(cinfo), JPOOL_IMAGE, arraysize));
- { Initialize the propagated errors to zero. }
- jzero_far(cquantize^.fserrors, arraysize);
- { Make the error-limit table if we didn't already. }
- if (cquantize^.error_limiter = NIL) then
- init_error_limit(cinfo);
- cquantize^.on_odd_row := FALSE;
- end;
-
- end;
- { Zero the histogram or inverse color map, if necessary }
- if (cquantize^.needs_zeroed) then
- begin
- for i := 0 to pred(HIST_C0_ELEMS) do
- begin
- jzero_far( histogram^[i],
- HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
- end;
- cquantize^.needs_zeroed := FALSE;
- end;
-end;
-
-
-{ Switch to a new external colormap between output passes. }
-
-{METHODDEF}
-procedure new_color_map_2_quant (cinfo : j_decompress_ptr); far;
-var
- cquantize : my_cquantize_ptr;
-begin
- cquantize := my_cquantize_ptr (cinfo^.cquantize);
-
- { Reset the inverse color map }
- cquantize^.needs_zeroed := TRUE;
-end;
-
-
-{ Module initialization routine for 2-pass color quantization. }
-
-
-{GLOBAL}
-procedure jinit_2pass_quantizer (cinfo : j_decompress_ptr);
-var
- cquantize : my_cquantize_ptr;
- i : int;
-var
- desired : int;
-begin
- cquantize := my_cquantize_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(my_cquantizer)));
- cinfo^.cquantize := jpeg_color_quantizer_ptr(cquantize);
- cquantize^.pub.start_pass := start_pass_2_quant;
- cquantize^.pub.new_color_map := new_color_map_2_quant;
- cquantize^.fserrors := NIL; { flag optional arrays not allocated }
- cquantize^.error_limiter := NIL;
-
- { Make sure jdmaster didn't give me a case I can't handle }
- if (cinfo^.out_color_components <> 3) then
- ERREXIT(j_common_ptr(cinfo), JERR_NOTIMPL);
-
- { Allocate the histogram/inverse colormap storage }
- cquantize^.histogram := hist3d (cinfo^.mem^.alloc_small
- (j_common_ptr (cinfo), JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d)));
- for i := 0 to pred(HIST_C0_ELEMS) do
- begin
- cquantize^.histogram^[i] := hist2d (cinfo^.mem^.alloc_large
- (j_common_ptr (cinfo), JPOOL_IMAGE,
- HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell)));
- end;
- cquantize^.needs_zeroed := TRUE; { histogram is garbage now }
-
- { Allocate storage for the completed colormap, if required.
- We do this now since it is FAR storage and may affect
- the memory manager's space calculations. }
-
- if (cinfo^.enable_2pass_quant) then
- begin
- { Make sure color count is acceptable }
- desired := cinfo^.desired_number_of_colors;
- { Lower bound on # of colors ... somewhat arbitrary as long as > 0 }
- if (desired < 8) then
- ERREXIT1(j_common_ptr (cinfo), JERR_QUANT_FEW_COLORS, 8);
- { Make sure colormap indexes can be represented by JSAMPLEs }
- if (desired > MAXNUMCOLORS) then
- ERREXIT1(j_common_ptr (cinfo), JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
- cquantize^.sv_colormap := cinfo^.mem^.alloc_sarray
- (j_common_ptr (cinfo),JPOOL_IMAGE, JDIMENSION(desired), JDIMENSION(3));
- cquantize^.desired := desired;
- end
- else
- cquantize^.sv_colormap := NIL;
-
- { Only F-S dithering or no dithering is supported. }
- { If user asks for ordered dither, give him F-S. }
- if (cinfo^.dither_mode <> JDITHER_NONE) then
- cinfo^.dither_mode := JDITHER_FS;
-
- { Allocate Floyd-Steinberg workspace if necessary.
- This isn't really needed until pass 2, but again it is FAR storage.
- Although we will cope with a later change in dither_mode,
- we do not promise to honor max_memory_to_use if dither_mode changes. }
-
- if (cinfo^.dither_mode = JDITHER_FS) then
- begin
- cquantize^.fserrors := FS_ERROR_FIELD_PTR (cinfo^.mem^.alloc_large
- (j_common_ptr(cinfo), JPOOL_IMAGE,
- size_t ((cinfo^.output_width + 2) * (3 * SIZEOF(FSERROR))) ) );
- { Might as well create the error-limiting table too. }
- init_error_limit(cinfo);
- end;
-end;
-
-end. { QUANT_2PASS_SUPPORTED }
diff --git a/packages/base/pasjpeg/jutils.pas b/packages/base/pasjpeg/jutils.pas
deleted file mode 100644
index 1bbd57ec51..0000000000
--- a/packages/base/pasjpeg/jutils.pas
+++ /dev/null
@@ -1,232 +0,0 @@
-Unit jutils;
-
-{ This file contains tables and miscellaneous utility routines needed
- for both compression and decompression.
- Note we prefix all global names with "j" to minimize conflicts with
- a surrounding application. }
-
-{ Source: jutils.c; Copyright (C) 1991-1996, Thomas G. Lane. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jpeglib;
-
-
-{ jpeg_zigzag_order[i] is the zigzag-order position of the i'th element
- of a DCT block read in natural order (left to right, top to bottom). }
-
-
-{$ifdef FALSE} { This table is not actually needed in v6a }
-
-const
- jpeg_zigzag_order : array[0..DCTSIZE2] of int =
- (0, 1, 5, 6, 14, 15, 27, 28,
- 2, 4, 7, 13, 16, 26, 29, 42,
- 3, 8, 12, 17, 25, 30, 41, 43,
- 9, 11, 18, 24, 31, 40, 44, 53,
- 10, 19, 23, 32, 39, 45, 52, 54,
- 20, 22, 33, 38, 46, 51, 55, 60,
- 21, 34, 37, 47, 50, 56, 59, 61,
- 35, 36, 48, 49, 57, 58, 62, 63);
-
-{$endif}
-
-
-{ jpeg_natural_order[i] is the natural-order position of the i'th element
- of zigzag order.
-
- When reading corrupted data, the Huffman decoders could attempt
- to reference an entry beyond the end of this array (if the decoded
- zero run length reaches past the end of the block). To prevent
- wild stores without adding an inner-loop test, we put some extra
- "63"s after the real entries. This will cause the extra coefficient
- to be stored in location 63 of the block, not somewhere random.
- The worst case would be a run-length of 15, which means we need 16
- fake entries. }
-
-
-const
- jpeg_natural_order : array[0..DCTSIZE2+16-1] of int =
- (0, 1, 8, 16, 9, 2, 3, 10,
- 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34,
- 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36,
- 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46,
- 53, 60, 61, 54, 47, 55, 62, 63,
- 63, 63, 63, 63, 63, 63, 63, 63, { extra entries for safety in decoder }
- 63, 63, 63, 63, 63, 63, 63, 63);
-
-
-
-{ Arithmetic utilities }
-
-{GLOBAL}
-function jdiv_round_up (a : long; b : long) : long;
-
-{GLOBAL}
-function jround_up (a : long; b : long) : long;
-
-{GLOBAL}
-procedure jcopy_sample_rows (input_array : JSAMPARRAY;
- source_row : int;
- output_array : JSAMPARRAY; dest_row : int;
- num_rows : int; num_cols : JDIMENSION);
-
-{GLOBAL}
-procedure jcopy_block_row (input_row : JBLOCKROW;
- output_row : JBLOCKROW;
- num_blocks : JDIMENSION);
-
-{GLOBAL}
-procedure jzero_far (target : pointer;{far} bytestozero : size_t);
-
-procedure FMEMZERO(target : pointer; size : size_t);
-
-procedure FMEMCOPY(dest,src : pointer; size : size_t);
-
-implementation
-
-{GLOBAL}
-function jdiv_round_up (a : long; b : long) : long;
-{ Compute a/b rounded up to next integer, ie, ceil(a/b) }
-{ Assumes a >= 0, b > 0 }
-begin
- jdiv_round_up := (a + b - long(1)) div b;
-end;
-
-
-{GLOBAL}
-function jround_up (a : long; b : long) : long;
-{ Compute a rounded up to next multiple of b, ie, ceil(a/b)*b }
-{ Assumes a >= 0, b > 0 }
-begin
- Inc(a, b - long(1));
- jround_up := a - (a mod b);
-end;
-
-{ On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
- and coefficient-block arrays. This won't work on 80x86 because the arrays
- are FAR and we're assuming a small-pointer memory model. However, some
- DOS compilers provide far-pointer versions of memcpy() and memset() even
- in the small-model libraries. These will be used if USE_FMEM is defined.
- Otherwise, the routines below do it the hard way. (The performance cost
- is not all that great, because these routines aren't very heavily used.) }
-
-
-{$ifndef NEED_FAR_POINTERS} { normal case, same as regular macros }
-procedure FMEMZERO(target : pointer; size : size_t);
-begin
- FillChar(target^, size, 0);
-end;
-
-procedure FMEMCOPY(dest,src : pointer; size : size_t);
-begin
- Move(src^, dest^, size);
-end;
-
-
-{$else} { 80x86 case, define if we can }
- {$ifdef USE_FMEM}
- FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
- FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
- {$endif}
-{$endif}
-
-
-{GLOBAL}
-procedure jcopy_sample_rows (input_array : JSAMPARRAY; source_row : int;
- output_array : JSAMPARRAY; dest_row : int;
- num_rows : int; num_cols : JDIMENSION);
-{ Copy some rows of samples from one place to another.
- num_rows rows are copied from input_array[source_row++]
- to output_array[dest_row++]; these areas may overlap for duplication.
- The source and destination arrays must be at least as wide as num_cols. }
-var
- inptr, outptr : JSAMPLE_PTR; {register}
-{$ifdef FMEMCOPY}
- count : size_t; {register}
-{$else}
- count : JDIMENSION; {register}
-{$endif}
- row : int; {register}
-begin
-{$ifdef FMEMCOPY}
- count := size_t(num_cols * SIZEOF(JSAMPLE));
-{$endif}
- Inc(JSAMPROW_PTR(input_array), source_row);
- Inc(JSAMPROW_PTR(output_array), dest_row);
-
- for row := pred(num_rows) downto 0 do
- begin
- inptr := JSAMPLE_PTR(input_array^[0]);
- Inc(JSAMPROW_PTR(input_array));
- outptr := JSAMPLE_PTR(output_array^[0]);
- Inc(JSAMPROW_PTR(output_array));
-{$ifdef FMEMCOPY}
- FMEMCOPY(outptr, inptr, count);
-{$else}
- for count := pred(num_cols) downto 0 do
- begin
- outptr^ := inptr^; { needn't bother with GETJSAMPLE() here }
- Inc(inptr);
- Inc(outptr);
- end;
-{$endif}
- end;
-end;
-
-
-{GLOBAL}
-procedure jcopy_block_row (input_row : JBLOCKROW;
- output_row : JBLOCKROW;
- num_blocks : JDIMENSION);
-{ Copy a row of coefficient blocks from one place to another. }
-{$ifdef FMEMCOPY}
-begin
- FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
-{$else}
-var
- inptr, outptr : JCOEFPTR; {register}
- count : long; {register}
-begin
- inptr := JCOEFPTR (input_row);
- outptr := JCOEFPTR (output_row);
- for count := long(num_blocks) * DCTSIZE2 -1 downto 0 do
- begin
- outptr^ := inptr^;
- Inc(outptr);
- Inc(inptr);
- end;
-{$endif}
-end;
-
-
-{GLOBAL}
-procedure jzero_far (target : pointer;{far} bytestozero : size_t);
-{ Zero out a chunk of FAR memory. }
-{ This might be sample-array data, block-array data, or alloc_large data. }
-{$ifdef FMEMZERO}
-begin
- FMEMZERO(target, bytestozero);
-{$else}
-var
- ptr : byteptr;
- count : size_t; {register}
-begin
- ptr := target;
- for count := bytestozero-1 downto 0 do
- begin
- ptr^ := 0;
- Inc(ptr);
- end;
-{$endif}
-end;
-
-end.
diff --git a/packages/base/pasjpeg/pasjpeg.pas b/packages/base/pasjpeg/pasjpeg.pas
deleted file mode 100644
index a4d035f920..0000000000
--- a/packages/base/pasjpeg/pasjpeg.pas
+++ /dev/null
@@ -1,1023 +0,0 @@
-unit PasJPeg;
-
-{$I jconfig.inc}
-
-interface
-
-uses
- Classes, SysUtils;
-
-type
- EJPEG = class(Exception);
- JPEG_ProgressMonitor = procedure(Percent: Integer);
-
-procedure LoadJPEG(
- {streams:}
- const infile, outfile: TStream; inmemory: boolean;
- {decompression parameters:}
- numcolors: integer;
- {progress monitor}
- callback: JPEG_ProgressMonitor);
-
-procedure StoreJPEG(
- {streams}
- const infile, outfile: TStream; inmemory: boolean;
- {compression parameters:}
- quality: integer;
- {progress monitor}
- callback: JPEG_ProgressMonitor);
-
-implementation
-
-uses
-// WinTypes, Dialogs,
- {PASJPG10 library}
- jmorecfg,
- jpeglib,
- jerror,
- jdeferr,
- jdmarker,
- jdmaster,
- jdapimin,
- jdapistd,
- jcparam,
- jcapimin,
- jcapistd,
- jcomapi;
-
-{ ---------------------------------------------------------------------- }
-{ source manager to read compressed data }
-{ for reference: JDATASRC.PAS in PASJPG10 library }
-{ ---------------------------------------------------------------------- }
-
-type
- my_src_ptr = ^my_source_mgr;
- my_source_mgr = record
- pub : jpeg_source_mgr; {public fields}
- infile : TStream; {source stream}
- buffer : JOCTET_FIELD_PTR; {start of buffer}
- start_of_file : boolean; {have we gotten any data yet?}
- end;
-
-const
- INPUT_BUF_SIZE = 4096;
-
-procedure init_source(cinfo : j_decompress_ptr); far;
-var
- src : my_src_ptr;
-begin
- src := my_src_ptr(cinfo^.src);
- src^.start_of_file := TRUE;
-end;
-
-function fill_input_buffer(cinfo : j_decompress_ptr) : boolean; far;
-var
- src : my_src_ptr;
- nbytes : size_t;
-begin
- src := my_src_ptr(cinfo^.src);
- nbytes := src^.infile.Read(src^.buffer^, INPUT_BUF_SIZE);
- if (nbytes <= 0) then begin
- if (src^.start_of_file) then {Treat empty input file as fatal error}
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EMPTY);
- WARNMS(j_common_ptr(cinfo), JWRN_JPEG_EOF);
- {Insert a fake EOI marker}
- src^.buffer^[0] := JOCTET ($FF);
- src^.buffer^[1] := JOCTET (JPEG_EOI);
- nbytes := 2;
- end;
- src^.pub.next_input_byte := JOCTETptr(src^.buffer);
- src^.pub.bytes_in_buffer := nbytes;
- src^.start_of_file := FALSE;
- fill_input_buffer := TRUE;
-end;
-
-procedure skip_input_data(cinfo : j_decompress_ptr;
- num_bytes : long); far;
-var
- src : my_src_ptr;
-begin
- src := my_src_ptr (cinfo^.src);
- if (num_bytes > 0) then begin
- while (num_bytes > long(src^.pub.bytes_in_buffer)) do begin
- Dec(num_bytes, long(src^.pub.bytes_in_buffer));
- fill_input_buffer(cinfo);
- { note we assume that fill_input_buffer will never return FALSE,
- so suspension need not be handled. }
- end;
- Inc( src^.pub.next_input_byte, size_t(num_bytes) );
- Dec( src^.pub.bytes_in_buffer, size_t(num_bytes) );
- end;
-end;
-
-procedure term_source(cinfo : j_decompress_ptr); far;
-begin
- { no work necessary here }
-end;
-
-procedure jpeg_stream_src(cinfo : j_decompress_ptr; const infile: TStream);
-var
- src : my_src_ptr;
-begin
- if (cinfo^.src = nil) then begin {first time for this JPEG object?}
- cinfo^.src := jpeg_source_mgr_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_PERMANENT,
- SIZEOF(my_source_mgr)) );
- src := my_src_ptr (cinfo^.src);
- src^.buffer := JOCTET_FIELD_PTR(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_PERMANENT,
- INPUT_BUF_SIZE * SIZEOF(JOCTET)) );
- end;
- src := my_src_ptr (cinfo^.src);
- {override pub's method pointers}
- src^.pub.init_source := init_source;
- src^.pub.fill_input_buffer := fill_input_buffer;
- src^.pub.skip_input_data := skip_input_data;
- src^.pub.resync_to_restart := jpeg_resync_to_restart; {use default method}
- src^.pub.term_source := term_source;
- {define our fields}
- src^.infile := infile;
- src^.pub.bytes_in_buffer := 0; {forces fill_input_buffer on first read}
- src^.pub.next_input_byte := nil; {until buffer loaded}
-end;
-
-{ ---------------------------------------------------------------------- }
-{ destination manager to write compressed data }
-{ for reference: JDATADST.PAS in PASJPG10 library }
-{ ---------------------------------------------------------------------- }
-
-type
- my_dest_ptr = ^my_destination_mgr;
- my_destination_mgr = record
- pub : jpeg_destination_mgr; {public fields}
- outfile : TStream; {target stream}
- buffer : JOCTET_FIELD_PTR; {start of buffer}
- end;
-
-const
- OUTPUT_BUF_SIZE = 4096;
-
-procedure init_destination(cinfo : j_compress_ptr); far;
-var
- dest : my_dest_ptr;
-begin
- dest := my_dest_ptr(cinfo^.dest);
- dest^.buffer := JOCTET_FIELD_PTR(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- OUTPUT_BUF_SIZE * SIZEOF(JOCTET)) );
- dest^.pub.next_output_byte := JOCTETptr(dest^.buffer);
- dest^.pub.free_in_buffer := OUTPUT_BUF_SIZE;
-end;
-
-function empty_output_buffer(cinfo : j_compress_ptr) : boolean; far;
-var
- dest : my_dest_ptr;
-begin
- dest := my_dest_ptr(cinfo^.dest);
- if (dest^.outfile.Write(dest^.buffer^, OUTPUT_BUF_SIZE)
- <> size_t(OUTPUT_BUF_SIZE))
- then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
- dest^.pub.next_output_byte := JOCTETptr(dest^.buffer);
- dest^.pub.free_in_buffer := OUTPUT_BUF_SIZE;
- empty_output_buffer := TRUE;
-end;
-
-procedure term_destination(cinfo : j_compress_ptr); far;
-var
- dest : my_dest_ptr;
- datacount : size_t;
-begin
- dest := my_dest_ptr (cinfo^.dest);
- datacount := OUTPUT_BUF_SIZE - dest^.pub.free_in_buffer;
- {write any data remaining in the buffer}
- if (datacount > 0) then
- if dest^.outfile.Write(dest^.buffer^, datacount) <> datacount then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
-end;
-
-procedure jpeg_stream_dest(cinfo : j_compress_ptr; const outfile: TStream);
-var
- dest : my_dest_ptr;
-begin
- if (cinfo^.dest = nil) then begin {first time for this JPEG object?}
- cinfo^.dest := jpeg_destination_mgr_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_PERMANENT,
- SIZEOF(my_destination_mgr)) );
- end;
- dest := my_dest_ptr (cinfo^.dest);
- {override pub's method pointers}
- dest^.pub.init_destination := init_destination;
- dest^.pub.empty_output_buffer := empty_output_buffer;
- dest^.pub.term_destination := term_destination;
- {define our fields}
- dest^.outfile := outfile;
-end;
-
-{ ------------------------------------------------------------------------ }
-{ Bitmap writing routines }
-{ for reference: WRBMP.PAS in PASJPG10 library }
-{ ------------------------------------------------------------------------ }
-{ NOTE: we always write BMP's in Windows format, no OS/2 formats! }
-{ however, we read all bitmap flavors (see bitmap reading) }
-{ ------------------------------------------------------------------------ }
-
-{ To support 12-bit JPEG data, we'd have to scale output down to 8 bits.
- This is not yet implemented. }
-
-{$ifndef BITS_IN_JSAMPLE_IS_8}
- Sorry, this code only copes with 8-bit JSAMPLEs. { deliberate syntax err }
-{$endif}
-
-type
- BGRptr = ^BGRtype;
- BGRtype = packed record
- b,g,r : byte;
- end;
-
- RGBptr = ^RGBtype;
- RGBtype = packed record
- r,g,b : JSAMPLE;
- end;
-
- bmp_dest_ptr = ^bmp_dest_struct;
- bmp_dest_struct = record
- outfile : TStream; {Stream to write to}
- inmemory : boolean; {keep whole image in memory}
- {image info}
- data_width : JDIMENSION; {JSAMPLEs per row}
- row_width : JDIMENSION; {physical width of one row in the BMP file}
- pad_bytes : INT; {number of padding bytes needed per row}
- grayscale : boolean; {grayscale or quantized color table ?}
- {pixelrow buffer}
- buffer : JSAMPARRAY; {pixelrow buffer}
- buffer_height : JDIMENSION; {normally, we'll use 1}
- {image buffer}
- image_buffer : jvirt_sarray_ptr;{needed to reverse row order BMP<>JPG}
- image_buffer_height : JDIMENSION; {}
- cur_output_row : JDIMENSION; {next row# to write to virtual array}
- row_offset : INT32; {position of next row to write to BMP}
- end;
-
-procedure write_bmp_header (cinfo : j_decompress_ptr;
- dest : bmp_dest_ptr);
- {Write a Windows-style BMP file header, including colormap if needed}
-var
- bmpfileheader : TBitmapFileHeader;
- bmpinfoheader : TBitmapInfoHeader;
- headersize : INT32;
- bits_per_pixel, cmap_entries, num_colors, i : INT;
- output_ext_color_map : array[0..255] of record b,g,r,a: byte; end;
-begin
- {colormap size and total file size}
- if (cinfo^.out_color_space = JCS_RGB) then begin
- if (cinfo^.quantize_colors) then begin {colormapped RGB}
- bits_per_pixel := 8;
- cmap_entries := 256;
- end else begin {unquantized, full color RGB}
- bits_per_pixel := 24;
- cmap_entries := 0;
- end;
- end else begin {grayscale output. We need to fake a 256-entry colormap.}
- bits_per_pixel := 8;
- cmap_entries := 256;
- end;
- headersize := SizeOf(TBitmapFileHeader)+SizeOf(TBitmapInfoHeader)+
- cmap_entries * 4;
- {define headers}
- FillChar(bmpfileheader, SizeOf(bmpfileheader), $0);
- FillChar(bmpinfoheader, SizeOf(bmpinfoheader), $0);
- with bmpfileheader do begin
- bfType := $4D42; {BM}
- bfSize := headersize + INT32(dest^.row_width) * INT32(cinfo^.output_height);
- bfOffBits := headersize;
- end;
- with bmpinfoheader do begin
- biSize := SizeOf(TBitmapInfoHeader);
- biWidth := cinfo^.output_width;
- biHeight := cinfo^.output_height;
- biPlanes := 1;
- biBitCount := bits_per_pixel;
- if (cinfo^.density_unit = 2) then begin
- biXPelsPerMeter := INT32(cinfo^.X_density*100);
- biYPelsPerMeter := INT32(cinfo^.Y_density*100);
- end;
- biClrUsed := cmap_entries;
- end;
- if dest^.outfile.Write(bmpfileheader, SizeOf(bmpfileheader))
- <> size_t(SizeOf(bmpfileheader)) then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
- if dest^.outfile.Write(bmpinfoheader, SizeOf(bmpinfoheader))
- <> size_t(SizeOf(bmpinfoheader)) then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
- {colormap}
- if cmap_entries > 0 then begin
- num_colors := cinfo^.actual_number_of_colors;
- if cinfo^.colormap <> nil then begin
- if cinfo^.out_color_components = 3 then
- for i := 0 to pred(num_colors) do
- with output_ext_color_map[i] do begin
- b := GETJSAMPLE(cinfo^.colormap^[2]^[i]);
- g := GETJSAMPLE(cinfo^.colormap^[1]^[i]);
- r := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- a := 0;
- end
- else
- {grayscale colormap (only happens with grayscale quantization)}
- for i := 0 to pred(num_colors) do
- with output_ext_color_map[i] do begin
- b := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- g := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- r := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- a := 0;
- end;
- i := num_colors;
- end else begin
- {if no colormap, must be grayscale data. Generate a linear "map".}
- {Nomssi: do not use "num_colors" here, it should be 0}
- for i := 0 to pred(256) do
- with output_ext_color_map[i] do begin
- b := i;
- g := i;
- r := i;
- a := 0;
- end;
- i := 256;
- end;
- {pad colormap with zeros to ensure specified number of colormap entries}
- if i > cmap_entries then
- ERREXIT1(j_common_ptr(cinfo), JERR_TOO_MANY_COLORS, i);
- while i < cmap_entries do begin
- with output_ext_color_map[i] do begin
- b := 0;
- g := 0;
- r := 0;
- a := 0;
- end;
- Inc(i);
- end;
- if dest^.outfile.Write(output_ext_color_map, cmap_entries*4)
- <> cmap_entries*4 then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
- end;
- dest^.row_offset := bmpfileheader.bfSize;
-end;
-
-procedure write_bmp_pixelrow (cinfo : j_decompress_ptr;
- dest : bmp_dest_ptr;
- rows_supplied : JDIMENSION);
-var
- image_ptr : JSAMPARRAY;
- inptr, outptr : JSAMPLE_PTR;
- BGR : BGRptr;
- col,row : JDIMENSION;
- pad : int;
-begin
- if dest^.inmemory then begin
- row := dest^.cur_output_row;
- Inc(dest^.cur_output_row);
- end else begin
- row := 0;
- Dec(dest^.row_offset, dest^.row_width);
- end;
- image_ptr := cinfo^.mem^.access_virt_sarray ( j_common_ptr(cinfo),
- dest^.image_buffer, row, JDIMENSION (1), TRUE);
- inptr := JSAMPLE_PTR(dest^.buffer^[0]);
- if not dest^.grayscale then begin
- BGR := BGRptr(image_ptr^[0]);
- for col := pred(cinfo^.output_width) downto 0 do begin
- BGR^.r := inptr^;
- Inc(inptr);
- BGR^.g := inptr^;
- Inc(inptr);
- BGR^.b := inptr^;
- Inc(inptr);
- Inc(BGR);
- end;
- outptr := JSAMPLE_PTR(BGR);
- end else begin
- outptr := JSAMPLE_PTR(image_ptr^[0]);
- for col := pred(cinfo^.output_width) downto 0 do begin
- outptr^ := inptr^;
- Inc(outptr);
- Inc(inptr);
- end;
- end;
- {zero out the pad bytes}
- pad := dest^.pad_bytes;
- while (pad > 0) do begin
- Dec(pad);
- outptr^ := 0;
- Inc(outptr);
- end;
- if not dest^.inmemory then begin
- {store row in output stream}
- image_ptr := cinfo^.mem^.access_virt_sarray ( j_common_ptr(cinfo),
- dest^.image_buffer, 0, JDIMENSION(1), FALSE);
- outptr := JSAMPLE_PTR(image_ptr^[0]);
- if dest^.outfile.Seek(dest^.row_offset, 0) <> dest^.row_offset then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
- if dest^.outfile.Write(outptr^, dest^.row_width) <> dest^.row_width then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
- end;
-end;
-
-procedure write_bmp_image (cinfo : j_decompress_ptr;
- dest : bmp_dest_ptr);
-var
- row, col : JDIMENSION;
- image_ptr : JSAMPARRAY;
- data_ptr : JSAMPLE_PTR;
-begin
- if dest^.inmemory then {write the image data from our virtual array}
- for row := cinfo^.output_height downto 1 do begin
- image_ptr := cinfo^.mem^.access_virt_sarray( j_common_ptr(cinfo),
- dest^.image_buffer, row-1, JDIMENSION(1), FALSE);
- data_ptr := JSAMPLE_PTR(image_ptr^[0]);
- {Nomssi - This won't work for 12bit samples}
- if dest^.outfile.Write(data_ptr^, dest^.row_width) <> dest^.row_width then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
- end;
-end;
-
-function jinit_write_bmp (cinfo : j_decompress_ptr;
- outfile : TStream;
- inmemory : boolean) : bmp_dest_ptr;
-var
- dest : bmp_dest_ptr;
-begin
- dest := bmp_dest_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(bmp_dest_struct)) );
- dest^.outfile := outfile;
- dest^.inmemory := inmemory;
- {image info}
- jpeg_calc_output_dimensions(cinfo);
- dest^.data_width := cinfo^.output_width * cinfo^.output_components;
- dest^.row_width := dest^.data_width;
- while ((dest^.row_width and 3) <> 0) do
- Inc(dest^.row_width);
- dest^.pad_bytes := int(dest^.row_width-dest^.data_width);
- if (cinfo^.out_color_space = JCS_GRAYSCALE) then
- dest^.grayscale := True
- else if (cinfo^.out_color_space = JCS_RGB) then
- if (cinfo^.quantize_colors) then
- dest^.grayscale := True
- else
- dest^.grayscale := False
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_COLORSPACE);
- {decompress buffer}
- dest^.buffer := cinfo^.mem^.alloc_sarray
- (j_common_ptr(cinfo), JPOOL_IMAGE, dest^.row_width, JDIMENSION (1));
- dest^.buffer_height := 1;
- {image buffer}
- if inmemory then
- dest^.image_buffer_height := cinfo^.output_height
- else
- dest^.image_buffer_height := 1;
- dest^.image_buffer := cinfo^.mem^.request_virt_sarray (
- j_common_ptr(cinfo), JPOOL_IMAGE, FALSE, dest^.row_width,
- dest^.image_buffer_height, JDIMENSION (1) );
- dest^.cur_output_row := 0;
- {result}
- jinit_write_bmp := dest;
-end;
-
-{ ------------------------------------------------------------------------ }
-{ Bitmap reading routines }
-{ for reference: RDBMP.PAS in PASJPG10 library }
-{ ------------------------------------------------------------------------ }
-
-type
- bmp_source_ptr = ^bmp_source_struct;
- bmp_source_struct = record
- infile : TStream; {stream to read from}
- inmemory : boolean; {keep whole image in memory}
- {image info}
- bits_per_pixel : INT; {bit depth}
- colormap : JSAMPARRAY; {BMP colormap (converted to my format)}
- row_width : JDIMENSION; {physical width of one row in the BMP file}
- {pixelrow buffer}
- buffer : JSAMPARRAY; {pixelrow buffer}
- buffer_height : JDIMENSION; {normally, we'll use 1}
- {image buffer}
- image_buffer : jvirt_sarray_ptr; {needed to reverse order BMP<>JPG}
- image_buffer_height : JDIMENSION; {image_height}
- cur_input_row : JDIMENSION; {current source row number}
- row_offset : INT32; {position of next row to read from BMP}
- end;
-
-procedure read_bmp_header (cinfo : j_compress_ptr;
- source : bmp_source_ptr);
-var
- bmpfileheader : TBitmapFileHeader;
- bmpcoreheader : TBitmapCoreHeader;
- bmpinfoheader : TBitmapInfoHeader;
- i, cmap_entrysize : INT;
-
- function read_byte: INT;
- {Read next byte from BMP file}
- var
- c: byte;
- begin
- if source^.infile.Read(c, 1) <> size_t(1) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- read_byte := c;
- end;
-
-begin
- cmap_entrysize := 0; { 0 indicates no colormap }
-
- {bitmap file header:}
- if source^.infile.Read(bmpfileheader, SizeOf(bmpfileheader))
- <> size_t(SizeOf(bmpfileheader)) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- if bmpfileheader.bfType <> $4D42 then {'BM'}
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_NOT);
-
- {bitmap infoheader: might be 12 bytes (OS/2 1.x), 40 bytes (Windows),
- or 64 bytes (OS/2 2.x). Check the first 4 bytes to find out which}
- if source^.infile.Read(bmpinfoheader, SizeOf(INT32)) <> size_t(SizeOf(INT32)) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- {OS/2 1.x format}
- if bmpinfoheader.biSize = SizeOf(TBitmapCoreHeader) then begin
- bmpcoreheader.bcSize := bmpinfoheader.biSize;
- if source^.infile.Read(bmpcoreheader.bcWidth, bmpcoreheader.bcSize-SizeOf(INT32))
- <> size_t (bmpcoreheader.bcSize-SizeOf(INT32)) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- bmpinfoheader.biWidth := bmpcoreheader.bcWidth;
- bmpinfoheader.biHeight := bmpcoreheader.bcHeight;
- bmpinfoheader.biPlanes := bmpcoreheader.bcPlanes;
- bmpinfoheader.biBitCount := bmpcoreheader.bcBitCount;
- bmpinfoheader.biClrUsed := 0;
- source^.bits_per_pixel := bmpinfoheader.biBitCount;
- case source^.bits_per_pixel of
- 8: begin {colormapped image}
- cmap_entrysize := 3; {OS/2 uses RGBTRIPLE colormap}
- TRACEMS2( j_common_ptr(cinfo), 1, JTRC_BMP_OS2_MAPPED,
- int (bmpinfoheader.biWidth), int(bmpinfoheader.biHeight));
- end;
- 24: { RGB image }
- TRACEMS2( j_common_ptr(cinfo), 1, JTRC_BMP_OS2,
- int (bmpinfoheader.biWidth), int(bmpinfoheader.biHeight) );
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADDEPTH);
- end;
- if bmpinfoheader.biPlanes <> 1 then
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADPLANES);
- end else
- {Windows 3.x or OS/2 2.x header, which has additional fields that we ignore }
- if (bmpinfoheader.biSize = SizeOf(TBitmapInfoHeader)) or
- (bmpinfoheader.biSize = 64) then
- begin
- if source^.infile.Read(bmpinfoheader.biWidth, SizeOf(bmpinfoheader)-SizeOf(INT32))
- <> size_t (SizeOf(bmpinfoheader)-SizeOf(INT32)) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- if bmpinfoheader.biSize = 64 then
- source^.infile.Seek(64-SizeOf(TBitmapInfoHeader), 1);
- source^.bits_per_pixel := bmpinfoheader.biBitCount;
- case source^.bits_per_pixel of
- 8: begin {colormapped image}
- cmap_entrysize := 4; {Windows uses RGBQUAD colormap}
- TRACEMS2( j_common_ptr(cinfo), 1, JTRC_BMP_MAPPED,
- int (bmpinfoheader.biWidth), int(bmpinfoheader.biHeight) );
- end;
- 24: {RGB image}
- TRACEMS2( j_common_ptr(cinfo), 1, JTRC_BMP,
- int (bmpinfoheader.biWidth), int(bmpinfoheader.biHeight) );
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADDEPTH);
- end;
- if (bmpinfoheader.biPlanes <> 1) then
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADPLANES);
- if (bmpinfoheader.biCompression <> 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_COMPRESSED);
- if (bmpinfoheader.biXPelsPerMeter > 0) and (bmpinfoheader.biYPelsPerMeter > 0) then
- begin
- {Set JFIF density parameters from the BMP data}
- cinfo^.X_density := bmpinfoheader.biXPelsPerMeter div 100; {100 cm per meter}
- cinfo^.Y_density := bmpinfoheader.biYPelsPerMeter div 100;
- cinfo^.density_unit := 2; { dots/cm }
- end;
- end else
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADHEADER);
-
- {colormap}
- if cmap_entrysize > 0 then begin
- if bmpinfoheader.biClrUsed <= 0 then
- bmpinfoheader.biClrUsed := 256 {assume it's 256}
- else
- if bmpinfoheader.biClrUsed > 256 then
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADCMAP);
- {allocate colormap}
- source^.colormap := cinfo^.mem^.alloc_sarray( j_common_ptr (cinfo),
- JPOOL_IMAGE, JDIMENSION(bmpinfoheader.biClrUsed), JDIMENSION (3));
- {read it}
- case cmap_entrysize of
- 3: {BGR format (occurs in OS/2 files)}
- for i := 0 to pred(bmpinfoheader.biClrUsed) do begin
- source^.colormap^[2]^[i] := JSAMPLE (read_byte);
- source^.colormap^[1]^[i] := JSAMPLE (read_byte);
- source^.colormap^[0]^[i] := JSAMPLE (read_byte);
- end;
- 4: {BGR0 format (occurs in MS Windows files)}
- for i := 0 to pred(bmpinfoheader.biClrUsed) do begin
- source^.colormap^[2]^[i] := JSAMPLE (read_byte);
- source^.colormap^[1]^[i] := JSAMPLE (read_byte);
- source^.colormap^[0]^[i] := JSAMPLE (read_byte);
- read_byte;
- end;
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADCMAP);
- end;
- end;
-
- {initialize bmp_source_struc}
-
- {row width, including padding to 4-byte boundary}
- if source^.bits_per_pixel = 24 then
- source^.row_width := JDIMENSION(bmpinfoheader.biWidth*3)
- else
- source^.row_width := JDIMENSION (bmpinfoheader.biWidth);
- while ((source^.row_width and 3) <> 0) do
- Inc(source^.row_width);
-
- {allocate pixelrow buffer}
- source^.buffer := cinfo^.mem^.alloc_sarray( j_common_ptr (cinfo),
- JPOOL_IMAGE, JDIMENSION (bmpinfoheader.biWidth*3), JDIMENSION (1) );
- source^.buffer_height := 1;
-
- {allocate image buffer}
- if source^.inmemory then begin
- source^.image_buffer_height := bmpinfoheader.biHeight;
- source^.cur_input_row := bmpinfoheader.biHeight;
- end else begin
- source^.image_buffer_height := 1;
- source^.row_offset := bmpfileheader.bfSize;
- end;
- source^.image_buffer := cinfo^.mem^.request_virt_sarray (
- j_common_ptr (cinfo), JPOOL_IMAGE, FALSE, source^.row_width,
- JDIMENSION(source^.image_buffer_height), JDIMENSION (1) );
-
- {set decompress parameters}
- cinfo^.in_color_space := JCS_RGB;
- cinfo^.input_components := 3;
- cinfo^.data_precision := 8;
- cinfo^.image_width := JDIMENSION (bmpinfoheader.biWidth);
- cinfo^.image_height := JDIMENSION (bmpinfoheader.biHeight);
-end;
-
-function read_bmp_pixelrow (cinfo : j_compress_ptr;
- source : bmp_source_ptr) : JDIMENSION;
- { Read one row of pixels:
- the image has been read into the image_buffer array, but is otherwise
- unprocessed. we must read it out in top-to-bottom row order, and if
- it is an 8-bit image, we must expand colormapped pixels to 24bit format. }
-var
- col, row : JDIMENSION;
- image_ptr : JSAMPARRAY;
- inptr, outptr : JSAMPLE_PTR;
- outptr24 : JSAMPROW;
- t : INT;
-begin
- if source^.inmemory then begin
- Dec(source^.cur_input_row);
- row := source^.cur_input_row;
- end else begin
- Dec(source^.row_offset, source^.row_width);
- row := 0;
- end;
- if not source^.inmemory then begin
- image_ptr := cinfo^.mem^.access_virt_sarray ( j_common_ptr (cinfo),
- source^.image_buffer, row, JDIMENSION (1), TRUE);
- inptr := JSAMPLE_PTR(image_ptr^[0]);
- if source^.infile.Seek(source^.row_offset, 0) <> source^.row_offset then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- if source^.infile.Read(inptr^, source^.row_width)
- <> size_t(source^.row_width) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- end;
- image_ptr := cinfo^.mem^.access_virt_sarray ( j_common_ptr (cinfo),
- source^.image_buffer, row, JDIMENSION (1), FALSE);
- {}
- inptr := JSAMPLE_PTR(image_ptr^[0]);
- case source^.bits_per_pixel of
- 8: begin
- {expand the colormap indexes to real data}
- outptr := JSAMPLE_PTR(source^.buffer^[0]);
- for col := pred(cinfo^.image_width) downto 0 do begin
- t := GETJSAMPLE(inptr^);
- Inc(inptr);
- outptr^ := source^.colormap^[0]^[t];
- Inc(outptr);
- outptr^ := source^.colormap^[1]^[t];
- Inc(outptr);
- outptr^ := source^.colormap^[2]^[t];
- Inc(outptr);
- end;
- end;
- 24: begin
- outptr24 := source^.buffer^[0];
- for col := pred(cinfo^.image_width) downto 0 do begin
- outptr24^[2] := inptr^;
- Inc(inptr);
- outptr24^[1] := inptr^;
- Inc(inptr);
- outptr24^[0] := inptr^;
- Inc(inptr);
- Inc(JSAMPLE_PTR(outptr24), 3);
- end;
- end;
- end;
- read_bmp_pixelrow := 1;
-end;
-
-procedure read_bmp_image(cinfo : j_compress_ptr;
- source : bmp_source_ptr);
-var
- row, col : JDIMENSION;
- image_ptr : JSAMPARRAY;
- inptr : JSAMPLE_PTR;
-begin
- if source^.inmemory then
- for row := 0 to pred(cinfo^.image_height) do begin
- image_ptr := cinfo^.mem^.access_virt_sarray ( j_common_ptr (cinfo),
- source^.image_buffer, row, JDIMENSION (1), TRUE);
- inptr := JSAMPLE_PTR(image_ptr^[0]);
- if source^.infile.Read(inptr^, source^.row_width)
- <> size_t(source^.row_width)
- then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- end;
-end;
-
-function jinit_read_bmp (cinfo : j_compress_ptr;
- infile : TStream;
- inmemory : boolean) : bmp_source_ptr;
-var
- source : bmp_source_ptr;
-begin
- source := bmp_source_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(bmp_source_struct)) );
- source^.infile := infile;
- source^.inmemory := inmemory;
- jinit_read_bmp := source;
-end;
-
-{ ------------------------------------------------------------------------ }
-{ JPEG progress monitor support }
-{ for reference: LIPJPEG.DOC in \JPEG\C directory }
-{ ------------------------------------------------------------------------ }
-
-type
- my_progress_ptr = ^my_progress_mgr;
- my_progress_mgr = record
- pub : jpeg_progress_mgr;
- proc : JPEG_ProgressMonitor;
- percent_done : INT;
- completed_extra_passes : INT;
- total_extra_passes : INT;
- end;
-
-procedure progress_monitor(cinfo: j_common_ptr); far;
-var
- progress : my_progress_ptr;
- total_passes : INT;
- percent_done : INT;
-begin
- progress := my_progress_ptr(cinfo^.progress);
- total_passes :=
- progress^.pub.total_passes + progress^.total_extra_passes;
- percent_done :=
- ( ((progress^.pub.completed_passes+progress^.completed_extra_passes)*100) +
- ((progress^.pub.pass_counter*100) div progress^.pub.pass_limit)
- ) div total_passes;
- {}
- if percent_done <> progress^.percent_done then begin
- progress^.percent_done := percent_done;
- progress^.proc(percent_done);
- end;
-end;
-
-procedure jpeg_my_progress(cinfo : j_common_ptr;
- progress : my_progress_ptr;
- callback : JPEG_ProgressMonitor);
-begin
- if @callback = nil then
- Exit;
- {set method}
- progress^.pub.progress_monitor := progress_monitor;
- {set fields}
- progress^.proc := callback;
- progress^.percent_done := -1;
- progress^.completed_extra_passes := 0;
- progress^.total_extra_passes := 0;
- {link to cinfo}
- cinfo^.progress := @progress^.pub;
-end;
-
-procedure jpeg_finish_progress(cinfo : j_common_ptr);
-var
- progress : my_progress_ptr;
-begin
- progress := my_progress_ptr(cinfo^.progress);
- if progress^.percent_done <> 100 then begin
- progress^.percent_done := 100;
- progress^.proc(progress^.percent_done);
- end;
-end;
-
-{ ------------------------------------------------------------------------ }
-{ JPEG error handler }
-{ for reference: JERROR.PAS in PASJPG10 library }
-{ LIPJPEG.DOC in \JPEG\C directory }
-{ NOTE: we have replaced jpeg_std_error because it stores a static }
-{ message table (JDEFERR.PAS) in the jpeg_message_table field. }
-{ ------------------------------------------------------------------------ }
-
-type
- my_error_ptr = ^my_error_mgr;
- my_error_mgr = record
- pub: jpeg_error_mgr;
- end;
-
-procedure error_exit (cinfo : j_common_ptr); far;
-var
- buffer : string;
-begin
- cinfo^.err^.format_message(cinfo, buffer);
- raise EJPEG.Create(buffer);
-end;
-
-procedure emit_message (cinfo : j_common_ptr; msg_level : int); far;
-var
- err : jpeg_error_mgr_ptr;
-begin
- err := cinfo^.err;
- if (msg_level < 0) then begin
- {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) or (err^.trace_level >= 3) then
- err^.output_message(cinfo);
- {Always count warnings in num_warnings}
- Inc( err^.num_warnings );
- end else
- {It's a trace message. Show it if trace_level >= msg_level}
- if (err^.trace_level >= msg_level) then
- err^.output_message (cinfo);
-end;
-
-procedure output_message (cinfo : j_common_ptr); far;
-var
- buffer : string;
-begin
- cinfo^.err^.format_message (cinfo, buffer);
- {message dialog}
- ShowMessage(buffer);
-end;
-
-procedure format_message (cinfo : j_common_ptr; var buffer : string); far;
-begin
- buffer :=
- 'JPEG ERROR -- #' + IntToStr(cinfo^.err^.msg_code);
-end;
-
-procedure reset_error_mgr (cinfo : j_common_ptr); far;
-begin
- 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"}
-end;
-
-function jpeg_my_error (var err : my_error_mgr) : jpeg_error_mgr_ptr;
-begin
- {methods}
- err.pub.error_exit := error_exit;
- err.pub.emit_message := emit_message;
- err.pub.output_message := output_message;
- err.pub.format_message := format_message;
- err.pub.reset_error_mgr := reset_error_mgr;
- {fields}
- err.pub.trace_level := 0; {default := no tracing}
- err.pub.num_warnings := 0; {no warnings emitted yet}
- err.pub.msg_code := 0; {may be useful as a flag for "no error"}
- {message table(s)}
- err.pub.jpeg_message_table := nil; {we don't want to use a static table}
- err.pub.last_jpeg_message := pred(JMSG_LASTMSGCODE);
- err.pub.addon_message_table := nil;
- err.pub.first_addon_message := JMSG_NOMESSAGE; {for safety}
- err.pub.last_addon_message := JMSG_NOMESSAGE;
- {return result}
- jpeg_my_error := @err;
-end;
-
-{ ------------------------------------------------------------------------ }
-{ load JPEG stream and save as BITMAP stream }
-{ for reference: DJPEG.PAS in PASJPG10 library }
-{ ------------------------------------------------------------------------ }
-
-procedure LoadJPEG(const infile, outfile: TStream; inmemory: boolean;
- {decompression parameters:}
- numcolors: integer;
- {progress monitor}
- callback: JPEG_ProgressMonitor);
-var
- cinfo : jpeg_decompress_struct;
- err : my_error_mgr;
- dest : bmp_dest_ptr;
- progress : my_progress_mgr;
- num_scanlines : JDIMENSION;
-begin
- {initialize the JPEG decompression object with default error handling.}
- cinfo.err := jpeg_my_error(err);
- jpeg_create_decompress(@cinfo);
- try
- {specify the source of the compressed data}
- jpeg_stream_src(@cinfo, infile);
- {progress monitor}
- jpeg_my_progress(@cinfo, @progress, callback);
- {obtain image info from header, set default decompression parameters}
- jpeg_read_header(@cinfo, TRUE);
- {set parameters for decompression}
- if numcolors <> 0 then begin
- cinfo.desired_number_of_colors := numcolors;
- cinfo.quantize_colors := True;
- end;
- {...}
- {prepare for decompression, initialize internal state}
- dest := jinit_write_bmp(@cinfo, outfile, inmemory);
- jpeg_start_decompress(@cinfo);
- {process data}
- write_bmp_header(@cinfo, dest);
- while (cinfo.output_scanline < cinfo.output_height) do begin
- num_scanlines :=
- jpeg_read_scanlines(@cinfo, dest^.buffer, dest^.buffer_height);
- write_bmp_pixelrow(@cinfo, dest, num_scanlines);
- end;
- write_bmp_image(@cinfo, dest);
- {finish}
- jpeg_finish_decompress(@cinfo);
- jpeg_finish_progress(@cinfo);
- finally
- {destroy}
- jpeg_destroy_decompress(@cinfo);
- end;
-end;
-
-{ ------------------------------------------------------------------------ }
-{ read BITMAP stream and save as JPEG }
-{ for reference: CJPEG.PAS in PASJPG10 library }
-{ ------------------------------------------------------------------------ }
-
-procedure StoreJPEG(const infile, outfile: TStream; inmemory: boolean;
- {compression parameters:}
- quality: INT;
- {progress monitor}
- callback: JPEG_ProgressMonitor);
-var
- cinfo : jpeg_compress_struct;
- err : my_error_mgr;
- source : bmp_source_ptr;
- progress : my_progress_mgr;
- num_scanlines : JDIMENSION;
-begin
- {initialize the JPEG compression object with default error handling.}
- cinfo.err := jpeg_my_error(err);
- jpeg_create_compress(@cinfo);
- try
- {specify the destination for the compressed data}
- jpeg_stream_dest(@cinfo, outfile);
- {set jpeg defaults}
- cinfo.in_color_space := JCS_RGB; {arbitrary guess}
- jpeg_set_defaults(@cinfo);
- {progress monitor}
- jpeg_my_progress(@cinfo, @progress, callback);
- {obtain image info from bitmap header, set default compression parameters}
- source := jinit_read_bmp(@cinfo, infile, inmemory);
- read_bmp_header(@cinfo, source);
- {now we know input colorspace, fix colorspace-dependent defaults}
- jpeg_default_colorspace(@cinfo);
- {set parameters for compression (most likely only quality)}
- jpeg_set_quality(@cinfo, quality, TRUE);
- {...}
- {prepare for compression, initialize internal state}
- jpeg_start_compress(@cinfo, TRUE);
- {process data}
- read_bmp_image(@cinfo, source);
- while (cinfo.next_scanline < cinfo.image_height) do begin
- num_scanlines := read_bmp_pixelrow(@cinfo, source);
- jpeg_write_scanlines(@cinfo, source^.buffer, num_scanlines);
- end;
- {finish}
- jpeg_finish_compress(@cinfo);
- jpeg_finish_progress(@cinfo);
- finally
- {destroy}
- jpeg_destroy_compress(@cinfo);
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/qtable1.ijg b/packages/base/pasjpeg/qtable1.ijg
deleted file mode 100644
index 52f7fefa88..0000000000
--- a/packages/base/pasjpeg/qtable1.ijg
+++ /dev/null
@@ -1,21 +0,0 @@
- # Quantization tables given in JPEG spec, section K.1
-
- # This is table 0 (the luminance table):
- 16 11 10 16 24 40 51 61
- 12 12 14 19 26 58 60 55
- 14 13 16 24 40 57 69 56
- 14 17 22 29 51 87 80 62
- 18 22 37 56 68 109 103 77
- 24 35 55 64 81 104 113 92
- 49 64 78 87 103 121 120 101
- 72 92 95 98 112 100 103 99
-
- # This is table 1 (the chrominance table):
- 17 18 24 47 99 99 99 99
- 18 21 26 66 99 99 99 99
- 24 26 56 99 99 99 99 99
- 47 66 99 99 99 99 99 99
- 99 99 99 99 99 99 99 99
- 99 99 99 99 99 99 99 99
- 99 99 99 99 99 99 99 99
- 99 99 99 99 99 99 99 99
diff --git a/packages/base/pasjpeg/rdbmp.pas b/packages/base/pasjpeg/rdbmp.pas
deleted file mode 100644
index c443f53806..0000000000
--- a/packages/base/pasjpeg/rdbmp.pas
+++ /dev/null
@@ -1,550 +0,0 @@
-Unit RdBmp;
-
-{ rdbmp.c
-
- Copyright (C) 1994-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 read input images in Microsoft "BMP"
- format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors).
- Currently, only 8-bit and 24-bit images are supported, not 1-bit or
- 4-bit (feeding such low-depth images into JPEG would be silly anyway).
- Also, we don't support RLE-compressed files.
-
- These routines may need modification for non-Unix environments or
- specialized applications. As they stand, they assume input from
- an ordinary stdio stream. They further assume that reading begins
- at the start of the file; start_input may need work if the
- user interface has already read some data (e.g., to determine that
- the file is indeed BMP format).
-
- This code contributed by James Arthur Boucher. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jpeglib,
- jinclude,
- jdeferr,
- jerror,
- cdjpeg; { Common decls for cjpeg/djpeg applications }
-
-{ The module selection routine for BMP format input. }
-
-{GLOBAL}
-function jinit_read_bmp (cinfo : j_compress_ptr) : cjpeg_source_ptr;
-
-implementation
-
-{ Macros to deal with unsigned chars as efficiently as compiler allows }
-
-{$define HAVE_UNSIGNED_CHAR}
-{$ifdef HAVE_UNSIGNED_CHAR}
-type
- U_CHAR = byte;
- UCH = int;
-{$else} { !HAVE_UNSIGNED_CHAR }
- {$ifdef CHAR_IS_UNSIGNED}
- type
- U_CHAR = char;
- UCH = int;
- {$else}
- type
- U_CHAR = char;
- UCH = int(x) and $FF
- {$endif}
-{$endif} { HAVE_UNSIGNED_CHAR }
-
-
-{ Private version of data source object }
-
-type
- bmp_source_ptr = ^bmp_source_struct;
- bmp_source_struct = record
- pub : cjpeg_source_struct; { public fields }
-
- cinfo : j_compress_ptr; { back link saves passing separate parm }
-
- colormap : JSAMPARRAY; { BMP colormap (converted to my format) }
-
- whole_image : jvirt_sarray_ptr; { Needed to reverse row order }
- source_row : JDIMENSION; { Current source row number }
- row_width : JDIMENSION; { Physical width of scanlines in file }
-
- bits_per_pixel : int; { remembers 8- or 24-bit format }
- end; { bmp_source_struct }
-
-
-{LOCAL}
-function read_byte (sinfo : bmp_source_ptr) : int;
-{ Read next byte from BMP file }
-var
- {register} infile : FILEptr;
- {register} c : byte;
-begin
- infile := sinfo^.pub.input_file;
- if JFREAD(infile, @c, 1) <> size_t(1) then
- ERREXIT(j_common_ptr(sinfo^.cinfo), JERR_INPUT_EOF);
- read_byte := c;
-end;
-
-
-{LOCAL}
-procedure read_colormap (sinfo : bmp_source_ptr;
- cmaplen : int;
- mapentrysize : int);
-{ Read the colormap from a BMP file }
-var
- i : int;
-begin
- case (mapentrysize) of
- 3:{ BGR format (occurs in OS/2 files) }
- for i := 0 to pred(cmaplen) do
- begin
- sinfo^.colormap^[2]^[i] := JSAMPLE (read_byte(sinfo));
- sinfo^.colormap^[1]^[i] := JSAMPLE (read_byte(sinfo));
- sinfo^.colormap^[0]^[i] := JSAMPLE (read_byte(sinfo));
- end;
- 4:{ BGR0 format (occurs in MS Windows files) }
- for i := 0 to pred(cmaplen) do
- begin
- sinfo^.colormap^[2]^[i] := JSAMPLE (read_byte(sinfo));
- sinfo^.colormap^[1]^[i] := JSAMPLE (read_byte(sinfo));
- sinfo^.colormap^[0]^[i] := JSAMPLE (read_byte(sinfo));
- {void} read_byte(sinfo);
- end;
- else
- ERREXIT(j_common_ptr(sinfo^.cinfo), JERR_BMP_BADCMAP);
- end;
-end;
-
-
-{ Read one row of pixels.
- The image has been read into the whole_image array, but is otherwise
- unprocessed. We must read it out in top-to-bottom row order, and if
- it is an 8-bit image, we must expand colormapped pixels to 24bit format. }
-
-{METHODDEF}
-function get_8bit_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading 8-bit colormap indexes }
-var
- source : bmp_source_ptr;
- {register} colormap : JSAMPARRAY;
- image_ptr : JSAMPARRAY;
- {register} t : int;
- {register} inptr, outptr : JSAMPLE_PTR;
- {register} col : JDIMENSION;
-begin
- source := bmp_source_ptr (sinfo);
- colormap := source^.colormap;
- { Fetch next row from virtual array }
- Dec(source^.source_row);
- image_ptr := cinfo^.mem^.access_virt_sarray(
- j_common_ptr (cinfo), source^.whole_image,
- source^.source_row, JDIMENSION (1), FALSE);
-
- { Expand the colormap indexes to real data }
- inptr := JSAMPLE_PTR(image_ptr^[0]);
- outptr := JSAMPLE_PTR(source^.pub.buffer^[0]);
- for col := pred(cinfo^.image_width) downto 0 do
- begin
- t := GETJSAMPLE(inptr^);
- Inc(inptr);
- outptr^ := colormap^[0]^[t]; { can omit GETJSAMPLE() safely }
- Inc(outptr);
- outptr^ := colormap^[1]^[t];
- Inc(outptr);
- outptr^ := colormap^[2]^[t];
- Inc(outptr);
- end;
-
- get_8bit_row := 1;
-end;
-
-
-{METHODDEF}
-function get_24bit_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading 24-bit pixels }
-var
- source : bmp_source_ptr;
- image_ptr : JSAMPARRAY;
- {register} inptr : JSAMPLE_PTR;
- {register} outptr : JSAMPROW;
- {register} col : JDIMENSION;
-begin
- source := bmp_source_ptr (sinfo);
- { Fetch next row from virtual array }
- Dec(source^.source_row);
- image_ptr := cinfo^.mem^.access_virt_sarray (
- j_common_ptr (cinfo), source^.whole_image,
- source^.source_row, JDIMENSION (1), FALSE);
-
- { Transfer data. Note source values are in BGR order
- (even though Microsoft's own documents say the opposite). }
-
- inptr := JSAMPLE_PTR(image_ptr^[0]);
- outptr := source^.pub.buffer^[0];
- for col := pred(cinfo^.image_width) downto 0 do
- begin
- outptr^[2] := inptr^; { can omit GETJSAMPLE() safely }
- Inc(inptr);
- outptr^[1] := inptr^;
- Inc(inptr);
- outptr^[0] := inptr^;
- Inc(inptr);
- Inc(JSAMPLE_PTR(outptr), 3);
- end;
-
- get_24bit_row := 1;
-end;
-
-
-{ This method loads the image into whole_image during the first call on
- get_pixel_rows. The get_pixel_rows pointer is then adjusted to call
- get_8bit_row or get_24bit_row on subsequent calls. }
-
-{METHODDEF}
-function preload_image (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-var
- source : bmp_source_ptr;
- {register} infile : FILEptr;
- {$IFDEF Original}
- {register} c : int;
- {$ENDIF}
- {register} out_ptr : JSAMPLE_PTR;
- image_ptr : JSAMPARRAY;
- row : JDIMENSION;
- {$IFDEF Original}
- col : JDIMENSION;
- {$ENDIF}
- progress : cd_progress_ptr;
-begin
- source := bmp_source_ptr (sinfo);
- infile := source^.pub.input_file;
- progress := cd_progress_ptr (cinfo^.progress);
-
- { Read the data into a virtual array in input-file row order. }
- for row := 0 to pred(cinfo^.image_height) do
- begin
- if (progress <> NIL) then
- begin
- progress^.pub.pass_counter := long (row);
- progress^.pub.pass_limit := long (cinfo^.image_height);
- progress^.pub.progress_monitor (j_common_ptr (cinfo));
- end;
- image_ptr := cinfo^.mem^.access_virt_sarray (
- j_common_ptr (cinfo), source^.whole_image,
- row, JDIMENSION (1), TRUE);
- out_ptr := JSAMPLE_PTR(image_ptr^[0]);
- {$IFDEF Original}
- for col := pred(source^.row_width) downto 0 do
- begin
- { inline copy of read_byte() for speed }
- c := getc(infile);
- if (c = EOF) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- out_ptr^ := JSAMPLE (c);
- Inc(out_ptr);
- end;
- {$ELSE}
- if JFREAD(infile, out_ptr, source^.row_width) <>
- size_t(source^.row_width) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- {$ENDIF}
- end;
- if (progress <> NIL) then
- Inc(progress^.completed_extra_passes);
-
- { Set up to read from the virtual array in top-to-bottom order }
- case (source^.bits_per_pixel) of
- 8: source^.pub.get_pixel_rows := get_8bit_row;
- 24: source^.pub.get_pixel_rows := get_24bit_row;
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADDEPTH);
- end;
- source^.source_row := cinfo^.image_height;
-
- { And read the first row }
- preload_image := source^.pub.get_pixel_rows (cinfo, sinfo);
-end;
-
-
-{ Read the file header; return image size and component count. }
-
-{METHODDEF}
-procedure start_input_bmp (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr); far;
-var
- source : bmp_source_ptr;
-
- bmpfileheader : packed array[0..14-1] of U_CHAR;
- bmpinfoheader : packed array[0..64-1] of U_CHAR;
-
-
- bfOffBits : INT32 ;
- headerSize : INT32;
- biWidth : INT32; { initialize to avoid compiler warning }
- biHeight : INT32;
- biPlanes : uInt;
- biCompression : INT32;
- biXPelsPerMeter,biYPelsPerMeter : INT32;
- biClrUsed : INT32;
- mapentrysize : int;
- bPad : INT32;
- row_width : JDIMENSION;
-var
- progress : cd_progress_ptr;
-begin
- source := bmp_source_ptr (sinfo);
- biWidth := 0; { initialize to avoid compiler warning }
- biHeight := 0;
- biClrUsed := 0;
- mapentrysize := 0; { 0 indicates no colormap }
-
- { Read and verify the bitmap file header }
- if JFREAD(source^.pub.input_file, @bmpfileheader, 14) <> size_t (14) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
-
- { GET_2B(bmpfileheader, 0) }
- if (uInt(UCH(bmpfileheader[0]) +
- (uInt(UCH(bmpfileheader[0+1])) shl 8)) <> $4D42) then { 'BM' }
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_NOT);
-
- bfOffBits := {INT32 ( GET_4B(bmpfileheader,10) );}
- INT32( INT32(UCH(bmpfileheader[10])) +
- ((INT32(UCH(bmpfileheader[10+1])) shl 8)) +
- ((INT32(UCH(bmpfileheader[10+2])) shl 16)) +
- ((INT32(UCH(bmpfileheader[10+3])) shl 24)));
-
- { We ignore the remaining fileheader fields }
-
- { The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows),
- or 64 bytes (OS/2 2.x). Check the first 4 bytes to find out which. }
-
- if JFREAD(source^.pub.input_file, @bmpinfoheader, 4) <> size_t(4) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- headerSize := {INT32 (GET_4B(bmpinfoheader,0));}
- INT32( INT32(UCH(bmpinfoheader[0])) +
- ((INT32(UCH(bmpinfoheader[0+1])) shl 8)) +
- ((INT32(UCH(bmpinfoheader[0+2])) shl 16)) +
- ((INT32(UCH(bmpinfoheader[0+3])) shl 24)));
-
- if (headerSize < 12) or (headerSize > 64) then
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADHEADER);
-
- if JFREAD(source^.pub.input_file,@bmpinfoheader[4],headerSize-4) <>
- size_t (headerSize-4) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
-
- case int(headerSize) of
- 12:begin
- { Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) }
-
- biWidth := {INT32 (GET_2B(bmpinfoheader,4));}
- INT32( uInt(UCH(bmpinfoheader[4])) +
- (uInt(UCH(bmpinfoheader[4+1])) shl 8) );
-
- biHeight := {INT32 (GET_2B(bmpinfoheader,6));}
- INT32( uInt(UCH(bmpinfoheader[6])) +
- (uInt(UCH(bmpinfoheader[6+1])) shl 8) );
-
- biPlanes := {GET_2B(bmpinfoheader,8);}
- uInt(UCH(bmpinfoheader[8])) +
- (uInt(UCH(bmpinfoheader[8+1])) shl 8);
-
- source^.bits_per_pixel := {int (GET_2B(bmpinfoheader,10));}
- int( uInt(UCH(bmpinfoheader[10])) +
- (uInt(UCH(bmpinfoheader[10+1])) shl 8));
-
- case (source^.bits_per_pixel) of
- 8: begin { colormapped image }
- mapentrysize := 3; { OS/2 uses RGBTRIPLE colormap }
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_BMP_OS2_MAPPED, int (biWidth), int(biHeight));
- end;
- 24: { RGB image }
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_BMP_OS2, int (biWidth), int(biHeight));
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADDEPTH);
- end;
- if (biPlanes <> 1) then
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADPLANES);
- end;
- 40,
- 64:begin
- { Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) }
- { or OS/2 2.x header, which has additional fields that we ignore }
-
- biWidth := {GET_4B(bmpinfoheader,4);}
- ( INT32(UCH(bmpinfoheader[4])) +
- ((INT32(UCH(bmpinfoheader[4+1])) shl 8)) +
- ((INT32(UCH(bmpinfoheader[4+2])) shl 16)) +
- ((INT32(UCH(bmpinfoheader[4+3])) shl 24)));
- biHeight := {GET_4B(bmpinfoheader,8);}
- ( INT32(UCH(bmpinfoheader[8])) +
- ((INT32(UCH(bmpinfoheader[8+1])) shl 8)) +
- ((INT32(UCH(bmpinfoheader[8+2])) shl 16)) +
- ((INT32(UCH(bmpinfoheader[8+3])) shl 24)));
-
- biPlanes := {GET_2B(bmpinfoheader,12);}
- ( uInt(UCH(bmpinfoheader[12])) +
- (uInt(UCH(bmpinfoheader[12+1])) shl 8) );
-
- source^.bits_per_pixel := {int (GET_2B(bmpinfoheader,14));}
- int( uInt(UCH(bmpinfoheader[14])) +
- ( uInt(UCH(bmpinfoheader[14+1])) shl 8) );
-
- biCompression := {GET_4B(bmpinfoheader,16);}
- ( INT32(UCH(bmpinfoheader[16])) +
- ((INT32(UCH(bmpinfoheader[16+1])) shl 8)) +
- ((INT32(UCH(bmpinfoheader[16+2])) shl 16)) +
- ((INT32(UCH(bmpinfoheader[16+3])) shl 24)));
-
- biXPelsPerMeter := {GET_4B(bmpinfoheader,24);}
- ( INT32(UCH(bmpinfoheader[24])) +
- ((INT32(UCH(bmpinfoheader[24+1])) shl 8)) +
- ((INT32(UCH(bmpinfoheader[24+2])) shl 16)) +
- ((INT32(UCH(bmpinfoheader[24+3])) shl 24)));
-
- biYPelsPerMeter := {GET_4B(bmpinfoheader,28);}
- ( INT32(UCH(bmpinfoheader[28])) +
- ((INT32(UCH(bmpinfoheader[28+1])) shl 8)) +
- ((INT32(UCH(bmpinfoheader[28+2])) shl 16)) +
- ((INT32(UCH(bmpinfoheader[28+3])) shl 24)));
-
- biClrUsed := {GET_4B(bmpinfoheader,32);}
- ( INT32(UCH(bmpinfoheader[32])) +
- ((INT32(UCH(bmpinfoheader[32+1])) shl 8)) +
- ((INT32(UCH(bmpinfoheader[32+2])) shl 16)) +
- ((INT32(UCH(bmpinfoheader[32+3])) shl 24)));
-
- { biSizeImage, biClrImportant fields are ignored }
-
- case (source^.bits_per_pixel) of
- 8: begin { colormapped image }
- mapentrysize := 4; { Windows uses RGBQUAD colormap }
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_BMP_MAPPED, int (biWidth), int (biHeight));
- end;
- 24: { RGB image }
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_BMP, int (biWidth), int (biHeight));
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADDEPTH);
- end;
- if (biPlanes <> 1) then
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADPLANES);
- if (biCompression <> 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_COMPRESSED);
-
- if (biXPelsPerMeter > 0) and (biYPelsPerMeter > 0) then
- begin
- { Set JFIF density parameters from the BMP data }
- cinfo^.X_density := UINT16 (biXPelsPerMeter div 100); { 100 cm per meter }
- cinfo^.Y_density := UINT16 (biYPelsPerMeter div 100);
- cinfo^.density_unit := 2; { dots/cm }
- end;
- end;
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADHEADER);
- end;
-
- { Compute distance to bitmap data --- will adjust for colormap below }
- bPad := bfOffBits - (headerSize + 14);
-
- { Read the colormap, if any }
- if (mapentrysize > 0) then
- begin
- if (biClrUsed <= 0) then
- biClrUsed := 256 { assume it's 256 }
- else
- if (biClrUsed > 256) then
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADCMAP);
- { Allocate space to store the colormap }
- source^.colormap := cinfo^.mem^.alloc_sarray(
- j_common_ptr (cinfo), JPOOL_IMAGE,
- JDIMENSION (biClrUsed), JDIMENSION (3));
- { and read it from the file }
- read_colormap(source, int (biClrUsed), mapentrysize);
- { account for size of colormap }
- Dec(bPad, biClrUsed * mapentrysize);
- end;
-
- { Skip any remaining pad bytes }
- if (bPad < 0) then { incorrect bfOffBits value? }
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_BADHEADER);
-
- while (bPad > 0) do
- begin
- Dec(bPad);
- {void} read_byte(source);
- end;
-
- { Compute row width in file, including padding to 4-byte boundary }
- if (source^.bits_per_pixel = 24) then
- row_width := JDIMENSION (biWidth * 3)
- else
- row_width := JDIMENSION (biWidth);
- while ((row_width and 3) <> 0) do
- Inc(row_width);
- source^.row_width := row_width;
-
- { Allocate space for inversion array, prepare for preload pass }
- source^.whole_image := cinfo^.mem^.request_virt_sarray(
- j_common_ptr (cinfo), JPOOL_IMAGE, FALSE,
- row_width, JDIMENSION (biHeight), JDIMENSION (1));
- source^.pub.get_pixel_rows := preload_image;
- if (cinfo^.progress <> NIL) then
- begin
- progress := cd_progress_ptr (cinfo^.progress);
- Inc(progress^.total_extra_passes); { count file input as separate pass }
- end;
-
- { Allocate one-row buffer for returned data }
- source^.pub.buffer := cinfo^.mem^.alloc_sarray(
- j_common_ptr (cinfo), JPOOL_IMAGE,
- JDIMENSION (biWidth * 3), JDIMENSION (1) );
- source^.pub.buffer_height := 1;
-
- cinfo^.in_color_space := JCS_RGB;
- cinfo^.input_components := 3;
- cinfo^.data_precision := 8;
- cinfo^.image_width := JDIMENSION (biWidth);
- cinfo^.image_height := JDIMENSION (biHeight);
-end;
-
-
-{ Finish up at the end of the file. }
-
-{METHODDEF}
-procedure finish_input_bmp (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr); far;
-begin
- { no work }
-end;
-
-
-{ The module selection routine for BMP format input. }
-
-{GLOBAL}
-function jinit_read_bmp (cinfo : j_compress_ptr) : cjpeg_source_ptr;
-var
- source : bmp_source_ptr;
-begin
- { Create module interface object }
- source := bmp_source_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(bmp_source_struct)) );
- source^.cinfo := cinfo; { make back link for subroutines }
- { Fill in method ptrs, except get_pixel_rows which start_input sets }
- source^.pub.start_input := start_input_bmp;
- source^.pub.finish_input := finish_input_bmp;
-
- jinit_read_bmp := cjpeg_source_ptr (source);
-end;
-
-end.
diff --git a/packages/base/pasjpeg/rdcolmap.pas b/packages/base/pasjpeg/rdcolmap.pas
deleted file mode 100644
index 4b1ce96d78..0000000000
--- a/packages/base/pasjpeg/rdcolmap.pas
+++ /dev/null
@@ -1,279 +0,0 @@
-Unit RdColMap;
-
-{ rdcolmap.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
-
-{ This file implements djpeg's "-map file" switch. It reads a source image
- and constructs a colormap to be supplied to the JPEG decompressor.
-
- Currently, these file formats are supported for the map file:
- GIF: the contents of the GIF's global colormap are used.
- PPM (either text or raw flavor): the entire file is read and
- each unique pixel value is entered in the map.
- Note that reading a large PPM file will be horrendously slow.
- Typically, a PPM-format map file should contain just one pixel
- of each desired color. Such a file can be extracted from an
- ordinary image PPM file with ppmtomap(1).
-
- Rescaling a PPM that has a maxval unequal to MAXJSAMPLE is not
- currently implemented. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- cdjpeg, { Common decls for cjpeg/djpeg applications }
- jdeferr,
- jerror,
- jpeglib;
-
-{ Main entry point from djpeg.c.
- Input: opened input file (from file name argument on command line).
- Output: colormap and actual_number_of_colors fields are set in cinfo. }
-
-{GLOBAL}
-{$ifdef QUANT_2PASS_SUPPORTED}
-procedure read_color_map (cinfo : j_decompress_ptr; var infile : FILE);
-{$endif} { QUANT_2PASS_SUPPORTED }
-
-implementation
-
-{$ifdef QUANT_2PASS_SUPPORTED}
-{ otherwise can't quantize to supplied map }
-
-{ Portions of this code are based on the PBMPLUS library, which is:
-*
-* Copyright (C) 1988 by Jef Poskanzer.
-*
-* Permission to use, copy, modify, and distribute this software and its
-* documentation for any purpose and without fee is hereby granted, provided
-* that the above copyright notice appear in all copies and that both that
-* copyright notice and this permission notice appear in supporting
-* documentation. This software is provided "as is" without express or
-* implied warranty.
-}
-
-
-{ Add a (potentially) new color to the color map. }
-
-{LOCAL}
-procedure add_map_entry (cinfo : j_decompress_ptr;
- R : int; G : int; B : int);
-var
- colormap0 : JSAMPROW;
- colormap1 : JSAMPROW;
- colormap2 : JSAMPROW;
- ncolors : int;
- index : int;
-begin
- colormap0 := cinfo^.colormap^[0];
- colormap1 := cinfo^.colormap^[1];
- colormap2 := cinfo^.colormap^[2];
- ncolors := cinfo^.actual_number_of_colors;
-
- { Check for duplicate color. }
- for index := 0 to pred(ncolors) do
- begin
- if (GETJSAMPLE(colormap0^[index]) = R) and
- (GETJSAMPLE(colormap1^[index]) = G) and
- (GETJSAMPLE(colormap2^[index]) = B) then
- exit; { color is already in map }
- end;
-
- { Check for map overflow. }
- if (ncolors >= (MAXJSAMPLE+1)) then
- ERREXIT1(j_common_ptr(cinfo), JERR_QUANT_MANY_COLORS, (MAXJSAMPLE+1));
-
- { OK, add color to map. }
- colormap0^[ncolors] := JSAMPLE (R);
- colormap1^[ncolors] := JSAMPLE (G);
- colormap2^[ncolors] := JSAMPLE (B);
- Inc(cinfo^.actual_number_of_colors);
-end;
-
-
-{ Extract color map from a GIF file. }
-
-{LOCAL}
-procedure read_gif_map (cinfo : j_decompress_ptr; var infile : file);
-var
- header : packed array[1..13-1] of byte;
- i, colormaplen : int;
-var
- color : RGBtype;
-var
- count : int;
-begin
- { Initial 'G' has already been read by read_color_map }
- { Read the rest of the GIF header and logical screen descriptor }
- blockread(infile, header, 13-1, count);
- if (count <> 13-1) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_CMAP_FILE);
-
- { Verify GIF Header }
- if (header[1] <> byte('I')) or (header[2] <> byte('F')) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_CMAP_FILE);
-
- { There must be a global color map. }
- if ((header[10] and $80) = 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_CMAP_FILE);
-
- { OK, fetch it. }
- colormaplen := 2 shl (header[10] and $07);
-
- for i := 0 to pred(colormaplen) do
- begin
- blockread(infile, color, 3, count);
- if (count <> 3) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_CMAP_FILE);
- add_map_entry(cinfo,
- color.R shl (BITS_IN_JSAMPLE-8),
- color.G shl (BITS_IN_JSAMPLE-8),
- color.B shl (BITS_IN_JSAMPLE-8));
- end;
-end;
-
-
-{$IFDEF PPM}
-{ Support routines for reading PPM }
-
-
-{LOCAL}
-function pbm_getc (var infile : FILE) : int;
-{ Read next char, skipping over any comments }
-{ A comment/newline sequence is returned as a newline }
-var
- {register} ch : int;
-begin
- ch := getc(infile);
- if (ch = '#') then
- begin
- repeat
- ch := getc(infile);
- until not (ch <> '\n') and not EOF(infile);
- end;
- pbm_get := ch;
-end;
-
-
-{LOCAL}
-function read_pbm_integer (cinfo : j_decompress_ptr;
- var infile : FILE) : uInt;
-{ Read an unsigned decimal integer from the PPM file }
-{ Swallows one trailing character after the integer }
-{ Note that on a 16-bit-int machine, only values up to 64k can be read. }
-{ This should not be a problem in practice. }
-var
- {register} ch : int;
- {register} val : uInt;
-begin
- { Skip any leading whitespace }
- repeat
- ch := pbm_getc(infile);
- if EOF(infile) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_CMAP_FILE);
- until (ch <> ' ') and (ch <> '\t') and (ch <> '\n') and (ch <> '\r');
-
- if (ch < '0') or (ch > '9') then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_CMAP_FILE);
-
- val := ch - '0';
- ch := pbm_getc(infile);
- while (ch >= '0') and (ch <= '9') do
- begin
- val := val * 10;
- Inc(val, ch - '0');
- ch := pbm_getc(infile);
- end;
- read_pbm_integer := val;
-end;
-
-
-{ Extract color map from a PPM file. }
-
-{LOCAL}
-procedure read_ppm_map (cinfo : j_decompress_ptr; var infile : FILE);
-var
- c : int;
- w, h, maxval, row, col : uInt;
- R, G, B : int;
-begin
- { Initial 'P' has already been read by read_color_map }
- c := getc(infile); { save format discriminator for a sec }
-
- { while we fetch the remaining header info }
- w := read_pbm_integer(cinfo, infile);
- h := read_pbm_integer(cinfo, infile);
- maxval := read_pbm_integer(cinfo, infile);
-
- if (w <= 0) or (h <= 0) or (maxval <= 0) then { error check }
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_CMAP_FILE);
-
- { For now, we don't support rescaling from an unusual maxval. }
- if (maxval <> (unsigned int) MAXJSAMPLE) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_CMAP_FILE);
-
- case (c) of
- '3': { it's a text-format PPM file }
- for row := 0 to pred(h) do
- begin
- for col := 0 to pred(w) do
- begin
- R := read_pbm_integer(cinfo, infile);
- G := read_pbm_integer(cinfo, infile);
- B := read_pbm_integer(cinfo, infile);
- add_map_entry(cinfo, R, G, B);
- end;
- end;
-
- '6': { it's a raw-format PPM file }
- for row := 0 to pred(h) do
- begin
- for col := 0 to pred(w) do
- begin
- R := pbm_getc(infile);
- G := pbm_getc(infile);
- B := pbm_getc(infile);
- if (R = EOF) or (G = EOF) or (B = EOF) then
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_CMAP_FILE);
- add_map_entry(cinfo, R, G, B);
- end;
- end;
-
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_CMAP_FILE);
- end;
-end;
-{$ENDIF}
-
-{ Main entry point from djpeg.c.
- Input: opened input file (from file name argument on command line).
- Output: colormap and actual_number_of_colors fields are set in cinfo. }
-
-{GLOBAL}
-procedure read_color_map (cinfo : j_decompress_ptr;
- var infile : FILE);
-var
- ch : char;
-begin
- { Allocate space for a color map of maximum supported size. }
- cinfo^.colormap := cinfo^.mem^.alloc_sarray
- (j_common_ptr (cinfo), JPOOL_IMAGE,
- JDIMENSION (MAXJSAMPLE+1), JDIMENSION (3));
- cinfo^.actual_number_of_colors := 0; { initialize map to empty }
-
- { Read first byte to determine file format }
- BlockRead(infile, ch, 1);
- case ch of
- 'G': read_gif_map(cinfo, infile);
- {$IFDEF PPM}
- 'P': read_ppm_map(cinfo, infile);
- {$ENDIF}
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BAD_CMAP_FILE);
- end;
-end;
-
-{$endif} { QUANT_2PASS_SUPPORTED }
-end.
diff --git a/packages/base/pasjpeg/rdjpgcom.pas b/packages/base/pasjpeg/rdjpgcom.pas
deleted file mode 100644
index bbecb18752..0000000000
--- a/packages/base/pasjpeg/rdjpgcom.pas
+++ /dev/null
@@ -1,381 +0,0 @@
-Program rdjpgcom;
-
-{ 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. }
-
-{ Original: Copyright (C) 1994-1995, Thomas G. Lane. }
-uses
- Objects;
-
-const
- EXIT_FAILURE = 1;
- EXIT_SUCCESS = 0;
-type
- int = integer;
- uInt = word;
-
-{ These macros are used to read the input file.
- To reuse this code in another application, you might need to change these. }
-
-var
- infile : TBufStream; { input JPEG file }
-
-{ Return next input byte, or EOF if no more }
-
-function NEXTBYTE : byte;
-var
- c : Byte;
-begin
- infile.Read(c, 1);
- NEXTBYTE := c;
-end;
-
-{ Error exit handler }
-procedure ERREXIT(msg : string);
-begin
- WriteLn(output, msg);
- Halt(EXIT_FAILURE);
-end;
-
-
-{ Read one byte, testing for EOF }
-function read_1_byte : int;
-var
- c : int;
-begin
- c := NEXTBYTE;
- if (infile.Status <> stOK) then
- ERREXIT('Premature EOF in JPEG file');
- read_1_byte := c;
-end;
-
-{ Read 2 bytes, convert to unsigned int }
-{ All 2-byte quantities in JPEG markers are MSB first }
-function read_2_bytes : uInt;
-var
- c : word;
-begin
- infile.Read(c, 2);
- c := Swap(c);
- if (infile.Status <> stOK) then
- ERREXIT('Premature EOF in JPEG file');
- read_2_bytes := c;
-end;
-
-
-{ 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.) }
-
-const
- M_SOF0 = $C0; { Start Of Frame N }
- M_SOF1 = $C1; { N indicates which compression process }
- M_SOF2 = $C2; { Only SOF0-SOF2 are now in common use }
- M_SOF3 = $C3;
- M_SOF5 = $C5; { NB: codes C4 and CC are NOT SOF markers }
- M_SOF6 = $C6;
- M_SOF7 = $C7;
- M_SOF9 = $C9;
- M_SOF10 = $CA;
- M_SOF11 = $CB;
- M_SOF13 = $CD;
- M_SOF14 = $CE;
- M_SOF15 = $CF;
- M_SOI = $D8; { Start Of Image (beginning of datastream) }
- M_EOI = $D9; { End Of Image (end of datastream) }
- M_SOS = $DA; { Start Of Scan (begins compressed data) }
- M_COM = $FE; { 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... }
-
-function next_marker : int;
-var
- c : int;
- discarded_bytes : int;
-begin
- discarded_bytes := 0;
-
- { Find 0xFF byte; count and skip any non-FFs. }
- c := read_1_byte;
- while (c <> $FF) do
- begin
- Inc(discarded_bytes);
- c := read_1_byte;
- end;
- { Get marker code byte, swallowing any duplicate FF bytes. Extra FFs
- are legal as pad bytes, so don't count them in discarded_bytes. }
-
- repeat
- c := read_1_byte;
- until (c <> $FF);
-
- if (discarded_bytes <> 0) then
- begin
- WriteLn(output, 'Warning: garbage data found in JPEG file');
- end;
-
- next_marker := c;
-end;
-
-
-{ Read the initial marker, which should be SOI.
- For a JFIF file, the first two bytes of the file should be literally
- $FF 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... }
-
-function first_marker : int;
-var
- c1, c2 : int;
-begin
- c1 := NEXTBYTE;
- c2 := NEXTBYTE;
- if (c1 <> $FF) or (c2 <> M_SOI) then
- ERREXIT('Not a JPEG file');
- first_marker := c2;
-end;
-
-
-{ 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 $FF bytes that might appear within the parameter segment;
- such bytes do NOT introduce new markers. }
-
-procedure skip_variable;
-{ Skip over an unknown or uninteresting variable-length marker }
-var
- length : uInt;
-begin
- { Get the marker parameter length count }
- length := read_2_bytes;
- { Length includes itself, so must be at least 2 }
- if (length < 2) then
- ERREXIT('Erroneous JPEG marker length');
- Dec(length, 2);
- { Skip over the remaining bytes }
- while (length > 0) do
- begin
- read_1_byte;
- Dec(length);
- end;
-end;
-
-
-{ Process a COM marker.
- We want to print out the marker contents as legible text;
- we must guard against random junk and varying newline representations. }
-
-procedure process_COM;
-const
- CR = 13;
- LF = 10;
-var
- length : uInt;
- comment : string;
- lastch : byte;
-begin
- comment := '';
- { Get the marker parameter length count }
- length := read_2_bytes;
- { Length includes itself, so must be at least 2 }
- if (length < 2) then
- ERREXIT('Erroneous JPEG marker length');
- Dec(length, 2);
-
- comment := '';
- while (length > 0) do
- begin
- comment := comment + char(read_1_byte);
- Dec(length);
- end;
- WriteLn(comment);
-end;
-
-
-{ Process a SOFn marker.
- This code is only needed if you want to know the image dimensions... }
-
-procedure process_SOFn (marker : int);
-var
- length : uInt;
- image_height, image_width : uInt;
- data_precision, num_components : int;
- process : string;
- ci: int;
-begin
- 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;
-
- case marker of
- M_SOF0: process := 'Baseline';
- M_SOF1: process := 'Extended sequential';
- M_SOF2: process := 'Progressive';
- M_SOF3: process := 'Lossless';
- M_SOF5: process := 'Differential sequential';
- M_SOF6: process := 'Differential progressive';
- M_SOF7: process := 'Differential lossless';
- M_SOF9: process := 'Extended sequential, arithmetic coding';
- M_SOF10: process := 'Progressive, arithmetic coding';
- M_SOF11: process := 'Lossless, arithmetic coding';
- M_SOF13: process := 'Differential sequential, arithmetic coding';
- M_SOF14: process := 'Differential progressive, arithmetic coding';
- M_SOF15: process := 'Differential lossless, arithmetic coding';
- else
- process := 'Unknown';
- end;
-
- WriteLn('JPEG image is ',image_width,'w * ',image_height,'h, ',
- num_components, ' color components, ',data_precision,
- ' bits per sample');
- WriteLn('JPEG process: ', process);
-
- if (length <> uInt(8 + num_components * 3)) then
- ERREXIT('Bogus SOF marker length');
-
- for ci := 0 to pred(num_components) do
- begin
- read_1_byte; { Component ID code }
- read_1_byte; { H, V sampling factors }
- read_1_byte; { Quantization table number }
- end;
-end;
-
-
-{ 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.) }
-
-function scan_JPEG_header (verbose : boolean) : int;
-var
- marker : int;
-begin
- { Expect SOI at start of file }
- if (first_marker <> M_SOI) then
- ERREXIT('Expected SOI marker first');
-
- { Scan miscellaneous markers until we reach SOS. }
- repeat
- marker := next_marker;
- case marker of
- M_SOF0, { Baseline }
- M_SOF1, { Extended sequential, Huffman }
- M_SOF2, { Progressive, Huffman }
- M_SOF3, { Lossless, Huffman }
- M_SOF5, { Differential sequential, Huffman }
- M_SOF6, { Differential progressive, Huffman }
- M_SOF7, { Differential lossless, Huffman }
- M_SOF9, { Extended sequential, arithmetic }
- M_SOF10, { Progressive, arithmetic }
- M_SOF11, { Lossless, arithmetic }
- M_SOF13, { Differential sequential, arithmetic }
- M_SOF14, { Differential progressive, arithmetic }
- M_SOF15: { Differential lossless, arithmetic }
- if (verbose) then
- process_SOFn(marker)
- else
- skip_variable;
-
- M_SOS: { stop before hitting compressed data }
- begin
- scan_JPEG_header := marker;
- exit;
- end;
-
- M_EOI: { in case it's a tables-only JPEG stream }
- begin
- scan_JPEG_header := marker;
- exit;
- end;
-
- M_COM:
- process_COM;
-
- else { Anything else just gets skipped }
- skip_variable; { we assume it has a parameter count... }
- end;
- until false; { end loop }
-end;
-
-
-{ Command line parsing code }
-
-var
- progname : string[79]; { program name for error messages }
-
-
-procedure usage;
-{ complain about bad command line }
-begin
- WriteLn(output, 'rdjpgcom displays any textual comments in a JPEG file.');
-
- WriteLn(output, 'Usage: ',progname,' [switches] [inputfile]');
-
- WriteLn(output, 'Switches (names may be abbreviated):');
- WriteLn(output, ' -verbose Also display dimensions of JPEG image');
-
- Halt(EXIT_FAILURE);
-end;
-
-
-{ The main program. }
-
-var
- verbose : boolean;
- argn : int;
- arg : string;
-begin
- verbose := FALSE;
-
- progname := ParamStr(0);
- if (progname = '') then
- progname := 'rdjpgcom'; { in case C library doesn't provide it }
-
- { Parse switches, if any }
- for argn := 1 to Pred(ParamCount) do
- begin
- arg := ParamStr(argn);
- if arg[1] = '-' then
- if (Pos(arg, '-verbose') > 0) then
- begin
- verbose := TRUE;
- end
- else
- usage;
- end;
-
- { Open the input file. }
- arg := ParamStr(ParamCount);
-
- if not infile.Init(arg, stOpenRead, 4096) then
- begin
- WriteLn(output, 'can''t open ', arg);
- Halt(EXIT_FAILURE);
- end;
-
- { Scan the JPEG headers. }
- scan_JPEG_header(verbose);
-
- infile.done;
-
- { All done. }
- Halt(EXIT_SUCCESS);
-end.
diff --git a/packages/base/pasjpeg/rdppm.pas b/packages/base/pasjpeg/rdppm.pas
deleted file mode 100644
index bc59ab4500..0000000000
--- a/packages/base/pasjpeg/rdppm.pas
+++ /dev/null
@@ -1,580 +0,0 @@
-Unit rdppm;
-
-{ rdppm.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 PPM/PGM format.
- The extended 2-byte-per-sample raw PPM/PGM formats are supported.
- The PBMPLUS library is NOT required to compile this software
- (but it is highly useful as a set of PPM image manipulation programs).
-
- These routines may need modification for non-Unix environments or
- specialized applications. As they stand, they assume input from
- an ordinary stdio stream. They further assume that reading begins
- at the start of the file; start_input may need work if the
- user interface has already read some data (e.g., to determine that
- the file is indeed PPM format).
- }
-
-interface
-
-{$define CHAR_IS_UNSIGNED}
-
-{$I jconfig.inc}
-
-uses
- jdeferr,
- jmorecfg,
- jerror,
- jpeglib,
- jinclude,
- cdjpeg; { Common decls for cjpeg/djpeg applications }
-
-{GLOBAL}
-function jinit_read_ppm (cinfo : j_compress_ptr) : cjpeg_source_ptr;
-
-
-implementation
-
-{ Portions of this code are based on the PBMPLUS library, which is:
-*
-* Copyright (C) 1988 by Jef Poskanzer.
-*
-* Permission to use, copy, modify, and distribute this software and its
-* documentation for any purpose and without fee is hereby granted, provided
-* that the above copyright notice appear in all copies and that both that
-* copyright notice and this permission notice appear in supporting
-* documentation. This software is provided "as is" without express or
-* implied warranty.
-}
-
-
-{ Macros to deal with unsigned chars as efficiently as compiler allows }
-
-{$ifdef HAVE_UNSIGNED_CHAR}
-type
- U_CHAR = unsigned char;
- UCH = int;
-{$else} { !HAVE_UNSIGNED_CHAR }
- {$ifdef CHAR_IS_UNSIGNED}
- type
- U_CHAR = byte;
- U_CHARptr = ^U_CHAR;
- UCH = int;
- {$else}
- type
- U_CHAR = char;
- UCH(x) = int (x and $FF)
- {$endif}
-{$endif} { HAVE_UNSIGNED_CHAR }
-
-
-{ macro }
-function ReadOK(f : FILEptr; buffer : pointer; len : size_t) : boolean;
-begin
- ReadOK := JFREAD(f, buffer,len) = size_t(len);
-end;
-{
- On most systems, reading individual bytes with getc() is drastically less
- efficient than buffering a row at a time with fread(). On PCs, we must
- allocate the buffer in near data space, because we are assuming small-data
- memory model, wherein fread() can't reach far memory. If you need to
- process very wide images on a PC, you might have to compile in large-memory
- model, or else replace fread() with a getc() loop --- which will be much
- slower.
- }
-
-
-{ Private version of data source object }
-
-type
- ppm_source_ptr = ^ppm_source_struct;
- ppm_source_struct = record
- pub : cjpeg_source_struct; { public fields }
-
- iobuffer : U_CHARptr; { non-FAR pointer to I/O buffer }
- pixrow : JSAMPROW; { FAR pointer to same }
- buffer_width : size_t; { width of I/O buffer }
- rescale : JSAMPROW; { => maxval-remapping array, or NIL }
- end;
-const
- LF = #10;
- CR = #13;
-
-{LOCAL}
-function pbm_getc (var infile : file) : char;
-{ Read next char, skipping over any comments }
-{ A comment/newline sequence is returned as a newline }
-var
- {register} ch : char;
-begin
- {getch} BlockRead(infile, ch, 1);
- if (ch = '#') then
- begin
- repeat
- BlockRead(infile, ch, 1);
- until (ch = LF) or eof(infile);
- end;
- pbm_getc := ch;
-end;
-
-
-{LOCAL}
-
-function read_pbm_integer (cinfo : j_compress_ptr; var infile : file) : uint;
-{ Read an unsigned decimal integer from the PPM file }
-{ Swallows one trailing character after the integer }
-{ Note that on a 16-bit-int machine, only values up to 64k can be read. }
-{ This should not be a problem in practice. }
-const
- TAB = ^I;
-var
- {register} ch : char;
- {register} val : uint;
-begin
- { Skip any leading whitespace }
- repeat
- ch := pbm_getc(infile);
- if eof(infile) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- until (ch <> ' ') and (ch <> TAB) and (ch <> LF) and (ch <> CR);
-
- if (ch < '0') or (ch > '9') then
- ERREXIT(j_common_ptr(cinfo), JERR_PPM_NONNUMERIC);
-
- val := ord(ch) - ord('0');
- repeat
- ch := pbm_getc(infile);
- if (ch >= '0') and (ch <= '9') then
- begin
- val := val * 10;
- Inc(val, ord(ch) - ord('0'));
- end
- else
- break;
- until FALSE;
- read_pbm_integer := val;
-end;
-
-{ Read one row of pixels.
-
- We provide several different versions depending on input file format.
- In all cases, input is scaled to the size of JSAMPLE.
-
- A really fast path is provided for reading byte/sample raw files with
- maxval := MAXJSAMPLE, which is the normal case for 8-bit data. }
-
-
-{METHODDEF}
-function get_text_gray_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading text-format PGM files with any maxval }
-var
- source : ppm_source_ptr;
- infile : FILEptr;
- {register} ptr : JSAMPLE_PTR;
- {register} rescale : JSAMPROW;
- col : JDIMENSION;
-begin
- source := ppm_source_ptr(sinfo);
- infile := source^.pub.input_file;
- rescale := source^.rescale;
- ptr := JSAMPLE_PTR(source^.pub.buffer^[0]);
- for col := pred(cinfo^.image_width) downto 0 do
- begin
- ptr^ := rescale^[read_pbm_integer(cinfo, infile^)];
- Inc(ptr);
- end;
- get_text_gray_row := 1;
-end;
-
-
-{METHODDEF}
-function get_text_rgb_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading text-format PPM files with any maxval }
-var
- source : ppm_source_ptr;
- infile : FILEptr;
- {register} ptr : JSAMPLE_PTR;
- {register} rescale : JSAMPROW;
- col : JDIMENSION;
-begin
- source := ppm_source_ptr(sinfo);
- infile := source^.pub.input_file;
- rescale := source^.rescale;
- ptr := JSAMPLE_PTR(source^.pub.buffer^[0]);
- for col := pred(cinfo^.image_width) downto 0 do
- begin
- ptr^ := rescale^[read_pbm_integer(cinfo, infile^)];
- Inc(ptr);
- ptr^ := rescale^[read_pbm_integer(cinfo, infile^)];
- Inc(ptr);
- ptr^ := rescale^[read_pbm_integer(cinfo, infile^)];
- Inc(ptr);
- end;
- get_text_rgb_row := 1;
-end;
-
-
-{METHODDEF}
-function get_scaled_gray_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading raw-byte-format PGM files with any maxval }
-var
- source : ppm_source_ptr;
- {register} ptr : JSAMPLE_PTR;
- {register} bufferptr : U_CHARptr ;
- {register} rescale : JSAMPROW;
- col : JDIMENSION;
-begin
- source := ppm_source_ptr(sinfo);
- rescale := source^.rescale;
- if not ReadOK(source^.pub.input_file, source^.iobuffer,
- source^.buffer_width) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- ptr := JSAMPLE_PTR(source^.pub.buffer^[0]);
- bufferptr := source^.iobuffer;
- for col := pred(cinfo^.image_width) downto 0 do
- begin
- ptr^ := rescale^[UCH(bufferptr^)];
- Inc(ptr);
- Inc(bufferptr);
- end;
- get_scaled_gray_row := 1;
-end;
-
-
-{METHODDEF}
-function get_scaled_rgb_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading raw-byte-format PPM files with any maxval }
-var
- source : ppm_source_ptr;
- {register} ptr : JSAMPLE_PTR;
- {register} bufferptr : U_CHARptr ;
- {register} rescale : JSAMPROW;
- col : JDIMENSION;
-begin
- source := ppm_source_ptr (sinfo);
- rescale := source^.rescale;
-
- if not ReadOK(source^.pub.input_file, source^.iobuffer,
- source^.buffer_width) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- ptr := JSAMPLE_PTR(source^.pub.buffer^[0]);
- bufferptr := source^.iobuffer;
- for col := pred(cinfo^.image_width) downto 0 do
- begin
- ptr^ := rescale^[UCH(bufferptr^)];
- Inc(ptr);
- Inc(bufferptr);
- ptr^ := rescale^[UCH(bufferptr^)];
- Inc(ptr);
- Inc(bufferptr);
- ptr^ := rescale^[UCH(bufferptr^)];
- Inc(ptr);
- Inc(bufferptr);
- end;
- get_scaled_rgb_row := 1;
-end;
-
-
-{METHODDEF}
-function get_raw_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading raw-byte-format files with maxval := MAXJSAMPLE.
- In this case we just read right into the JSAMPLE buffer!
- Note that same code works for PPM and PGM files. }
-var
- source : ppm_source_ptr;
-begin
- source := ppm_source_ptr(sinfo);
-
- if not ReadOK(source^.pub.input_file, source^.iobuffer,
- source^.buffer_width) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- get_raw_row := 1;
-end;
-
-
-{METHODDEF}
-function get_word_gray_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading raw-word-format PGM files with any maxval }
-var
- source : ppm_source_ptr;
- {register} ptr : JSAMPLE_PTR;
- {register} bufferptr : U_CHARptr;
- {register} rescale : JSAMPROW;
- col : JDIMENSION;
-var
- {register} temp : int;
-begin
- source := ppm_source_ptr (sinfo);
- rescale := source^.rescale;
- if not ReadOK(source^.pub.input_file, source^.iobuffer,
- source^.buffer_width) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- ptr := JSAMPLE_PTR(source^.pub.buffer^[0]);
- bufferptr := source^.iobuffer;
- for col := pred(cinfo^.image_width) downto 0 do
- begin
- temp := UCH(bufferptr^);
- Inc(bufferptr);
- temp := temp or (UCH(bufferptr^) shl 8);
- Inc(bufferptr);
- ptr^ := rescale^[temp];
- Inc(ptr);
- end;
- get_word_gray_row := 1;
-end;
-
-
-{METHODDEF}
-function get_word_rgb_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading raw-word-format PPM files with any maxval }
-var
- source : ppm_source_ptr;
- {register} ptr : JSAMPLE_PTR;
- {register} bufferptr : U_CHARptr;
- {register} rescale : JSAMPROW;
- col : JDIMENSION;
-var
- {register} temp : int;
-begin
- source := ppm_source_ptr(sinfo);
- rescale := source^.rescale;
- if not ReadOK(source^.pub.input_file, source^.iobuffer,
- source^.buffer_width) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
- ptr := JSAMPLE_PTR(source^.pub.buffer^[0]);
- bufferptr := source^.iobuffer;
- for col := pred(cinfo^.image_width) downto 0 do
- begin
- temp := UCH(bufferptr^);
- Inc(bufferptr);
- temp := temp or (UCH(bufferptr^) shl 8);
- Inc(bufferptr);
- ptr^ := rescale^[temp];
- Inc(ptr);
- temp := UCH(bufferptr^);
- Inc(bufferptr);
- temp := temp or (UCH(bufferptr^) shl 8);
- Inc(bufferptr);
- ptr^ := rescale^[temp];
- Inc(ptr);
- temp := UCH(bufferptr^);
- Inc(bufferptr);
- temp := temp or (UCH(bufferptr^) shl 8);
- Inc(bufferptr);
- ptr^ := rescale^[temp];
- Inc(ptr);
- end;
- get_word_rgb_row := 1;
-end;
-
-
-{ Read the file header; return image size and component count. }
-
-{METHODDEF}
-procedure start_input_ppm (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr); far;
-var
- source : ppm_source_ptr;
- c : char;
- w, h, maxval : uint;
- need_iobuffer, use_raw_buffer, need_rescale : boolean;
-var
- val, half_maxval : INT32;
-begin
- source := ppm_source_ptr(sinfo);
- {getch} BlockRead(source^.pub.input_file^, c, 1);
- if (c <> 'P') then
- ERREXIT(j_common_ptr(cinfo), JERR_PPM_NOT);
-
- {getch} BlockRead(source^.pub.input_file^, c, 1);
- { subformat discriminator character }
-
- { detect unsupported variants (ie, PBM) before trying to read header }
- case (c) of
- '2', { it's a text-format PGM file }
- '3', { it's a text-format PPM file }
- '5', { it's a raw-format PGM file }
- '6':; { it's a raw-format PPM file }
- else
- ERREXIT(j_common_ptr(cinfo), JERR_PPM_NOT);
- end;
-
- { fetch the remaining header info }
- w := read_pbm_integer(cinfo, source^.pub.input_file^);
- h := read_pbm_integer(cinfo, source^.pub.input_file^);
- maxval := read_pbm_integer(cinfo, source^.pub.input_file^);
-
- if (w <= 0) or (h <= 0) or (maxval <= 0) then { error check }
- ERREXIT(j_common_ptr(cinfo), JERR_PPM_NOT);
-
- cinfo^.data_precision := BITS_IN_JSAMPLE; { we always rescale data to this }
- cinfo^.image_width := JDIMENSION (w);
- cinfo^.image_height := JDIMENSION (h);
-
- { initialize flags to most common settings }
- need_iobuffer := TRUE; { do we need an I/O buffer? }
- use_raw_buffer := FALSE; { do we map input buffer onto I/O buffer? }
- need_rescale := TRUE; { do we need a rescale array? }
-
- case (c) of
- '2': { it's a text-format PGM file }
- begin
- cinfo^.input_components := 1;
- cinfo^.in_color_space := JCS_GRAYSCALE;
- {$IFDEF DEBUG}
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_PGM_TEXT, w, h);
- {$ENDIF}
- source^.pub.get_pixel_rows := get_text_gray_row;
- need_iobuffer := FALSE;
- end;
-
- '3': { it's a text-format PPM file }
- begin
- cinfo^.input_components := 3;
- cinfo^.in_color_space := JCS_RGB;
- {$IFDEF DEBUG}
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_PPM_TEXT, w, h);
- {$ENDIF}
- source^.pub.get_pixel_rows := get_text_rgb_row;
- need_iobuffer := FALSE;
- end;
-
- '5': { it's a raw-format PGM file }
- begin
- cinfo^.input_components := 1;
- cinfo^.in_color_space := JCS_GRAYSCALE;
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_PGM, w, h);
- if (maxval > 255) then
- begin
- source^.pub.get_pixel_rows := get_word_gray_row;
- end
- else
- if (maxval = MAXJSAMPLE) and (SIZEOF(JSAMPLE) = SIZEOF(U_CHAR)) then
- begin
- source^.pub.get_pixel_rows := get_raw_row;
- use_raw_buffer := TRUE;
- need_rescale := FALSE;
- end
- else
- begin
- source^.pub.get_pixel_rows := get_scaled_gray_row;
- end;
- end;
-
- '6': { it's a raw-format PPM file }
- begin
- cinfo^.input_components := 3;
- cinfo^.in_color_space := JCS_RGB;
- {$IFDEF DEBUG}
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_PPM, w, h);
- {$ENDIF}
- if (maxval > 255) then
- begin
- source^.pub.get_pixel_rows := get_word_rgb_row;
- end
- else
- if (maxval = MAXJSAMPLE) and (SIZEOF(JSAMPLE) = SIZEOF(U_CHAR)) then
- begin
- source^.pub.get_pixel_rows := get_raw_row;
- use_raw_buffer := TRUE;
- need_rescale := FALSE;
- end
- else
- begin
- source^.pub.get_pixel_rows := get_scaled_rgb_row;
- end;
- end;
- end;
-
- { Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. }
- if (need_iobuffer) then
- begin
- if (maxval<=255) then
- source^.buffer_width := size_t ( w * cinfo^.input_components *
- SIZEOF(U_CHAR) )
- else
- source^.buffer_width := size_t ( w * cinfo^.input_components *
- (2*SIZEOF(U_CHAR)) );
-
- source^.iobuffer := U_CHARptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- source^.buffer_width) );
- end;
-
- { Create compressor input buffer. }
- if (use_raw_buffer) then
- begin
- { For unscaled raw-input case, we can just map it onto the I/O buffer. }
- { Synthesize a JSAMPARRAY pointer structure }
- { Cast here implies near^.far pointer conversion on PCs }
- source^.pixrow := JSAMPROW (source^.iobuffer);
- source^.pub.buffer := JSAMPARRAY(@source^.pixrow);
- source^.pub.buffer_height := 1;
- end
- else
- begin
- { Need to translate anyway, so make a separate sample buffer. }
- source^.pub.buffer := cinfo^.mem^.alloc_sarray
- (j_common_ptr(cinfo), JPOOL_IMAGE,
- JDIMENSION (w * cinfo^.input_components), JDIMENSION(1) );
- source^.pub.buffer_height := 1;
- end;
-
- { Compute the rescaling array if required. }
- if (need_rescale) then
- begin
- { On 16-bit-int machines we have to be careful of maxval := 65535 }
- source^.rescale := JSAMPROW (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- size_t ((long(maxval) + long(1)) * SIZEOF(JSAMPLE))) );
- half_maxval := maxval div 2;
- for val := 0 to INT32(maxval) do
- begin
- { The multiplication here must be done in 32 bits to avoid overflow }
- source^.rescale^[val] := JSAMPLE ((val*MAXJSAMPLE + half_maxval) div maxval);
- end;
- end;
-end;
-
-
-{ Finish up at the end of the file. }
-
-{METHODDEF}
-procedure finish_input_ppm (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr); far;
-begin
- { no work }
-end;
-
-
-{ The module selection routine for PPM format input. }
-
-{GLOBAL}
-function jinit_read_ppm (cinfo : j_compress_ptr) : cjpeg_source_ptr;
-var
- source : ppm_source_ptr;
-begin
- { Create module interface object }
- source := ppm_source_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(ppm_source_struct)) );
- { Fill in method ptrs, except get_pixel_rows which start_input sets }
- source^.pub.start_input := start_input_ppm;
- source^.pub.finish_input := finish_input_ppm;
-
- jinit_read_ppm := cjpeg_source_ptr(source);
-end;
-
-
-end.
diff --git a/packages/base/pasjpeg/rdswitch.pas b/packages/base/pasjpeg/rdswitch.pas
deleted file mode 100644
index 13c2a47a67..0000000000
--- a/packages/base/pasjpeg/rdswitch.pas
+++ /dev/null
@@ -1,523 +0,0 @@
-Unit RdSwitch;
-
-{ 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 }
-
-{ Original: rdswitch.c ; Copyright (C) 1991-1996, Thomas G. Lane. }
-
-
-interface
-
-{$I jconfig.inc}
-
-uses
- cdjpeg, { Common decls for cjpeg/djpeg applications }
- {ctype,} { to declare isdigit(), isspace() }
- jinclude,
- jmorecfg,
- jcparam,
- jpeglib;
-
-{GLOBAL}
-function set_quant_slots (cinfo : j_compress_ptr; argtxt : string) : boolean;
-{ Process a quantization-table-selectors parameter string, of the form
- N[,N,...]
- If there are more components than parameters, the last value is re0licated.
- }
-
-
-{GLOBAL}
-function set_sample_factors (cinfo : j_compress_ptr;
- argtxt : string) : boolean;
-{ Process a sample-factors parameter string, of the form
- HxV[,HxV,...]
- If there are more components than parameters, "1x1" is assumed for the rest.
- }
-
-{GLOBAL}
-function read_quant_tables (cinfo : j_compress_ptr;
- const filename : string;
- scale_factor : int;
- force_baseline : boolean) : boolean;
-
-{ 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. }
-
-{GLOBAL}
-function read_scan_script (cinfo : j_compress_ptr;
- const filename : string) : boolean;
-{ 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. }
-
-implementation
-
-uses
- fcache;
-
-const
- BLANK = ' ';
- TAB = ^I; { #9 }
- CR = #13; { ^M }
- LF = #10; { }
-
-{LOCAL}
-function text_getc (var fc : Cache) : char;
-{ Read next char, skipping over any comments (# to end of line) }
-{ A comment/newline sequence is returned as a newline }
-var
- ch : char; {register }
-begin
- ch := char(fc_GetC(fc));
- if (ch = '#') then
- repeat
- ch := char(fc_GetC(fc));
- Until (ch = #13) or (ch = EOF);
- text_getc := ch;
-end;
-
-{LOCAL}
-function read_text_integer (var f : Cache;
- var outval : long;
- var termchar : char) : boolean;
-{ Read an unsigned decimal integer from a file, store it in outval }
-{ Reads one trailing character after the integer; returns it in termchar }
-var
- {register} ch : char;
- {register} val : long;
-begin
- { Skip any leading whitespace, detect EOF }
- repeat
- ch := text_getc(f);
- if (ch = EOF) then
- begin
- termchar := EOF;
- read_text_integer := FALSE;
- exit;
- end;
- Until (ch <> BLANK) and (ch <> TAB) and (ch <> CR) and (ch <> LF);
-
- if not (ch in ['0'..'9']) then
- begin
- termchar := ch;
- read_text_integer := FALSE;
- exit;
- end;
-
- val := ord(ch) - ord('0');
- repeat
- ch := text_getc(f);
- if (ch <> EOF) then
- begin
- if not (ch in ['0'..'9']) then
- break;
- val := val * 10;
- Inc(val, ord(ch) - ord('0'));
- end;
- until ch = EOF;
- outval := val;
- termchar := ch;
- read_text_integer := TRUE;
-end;
-
-{GLOBAL}
-function read_quant_tables (cinfo : j_compress_ptr;
- const filename : string;
- scale_factor : int;
- force_baseline : boolean) : boolean;
-{ 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. }
-var
- f : file;
- fp : Cache;
- tblno, i : int;
- termchar : char;
- val : long;
- table : array[0..DCTSIZE2-1] of uInt;
-begin
- Assign(f, filename);
- {$I-}
- Reset(f, 1);
- {$IFDEF IoCheck} {$I+} {$ENDIF}
- if (IOresult <> 0) then
- begin
- WriteLn(output, 'Can''t open table file ', filename);
- read_quant_tables := FALSE;
- exit;
- end;
- fc_Init(fp, f, 0);
-
- tblno := 0;
-
- while (read_text_integer(fp, val, termchar)) do
- begin { read 1st element of table }
- if (tblno >= NUM_QUANT_TBLS) then
- begin
- WriteLn(output, 'Too many tables in file ', filename);
- fc_close(fp);
- read_quant_tables := FALSE;
- exit;
- end;
- table[0] := uInt (val);
- for i := 1 to pred(DCTSIZE2) do
- begin
- if (not read_text_integer(fp, val, termchar)) then
- begin
- WriteLn(output, 'Invalid table data in file ', filename);
- fc_close(fp);
- read_quant_tables := FALSE;
- exit;
- end;
- table[i] := uInt (val);
- end;
- jpeg_add_quant_table(cinfo, tblno, table, scale_factor, force_baseline);
- Inc(tblno);
- end;
-
- if (termchar <> EOF) then
- begin
- WriteLn(output, 'Non-numeric data in file ', filename);
- fc_close(fp);
- read_quant_tables := FALSE;
- exit;
- end;
-
- fc_close(fp);
- read_quant_tables := TRUE;
-end;
-
-
-{$ifdef C_MULTISCAN_FILES_SUPPORTED}
-
-{LOCAL}
-function read_scan_integer (var f : cache;
- var outval : long;
- var termchar : char) : boolean;
-{ Variant of read_text_integer that always looks for a non-space termchar;
- this simplifies parsing of punctuation in scan scripts. }
-var
- ch : char; { register }
-begin
- if not read_text_integer(f, outval, termchar) then
- begin
- read_scan_integer := FALSE;
- exit;
- end;
- ch := termchar;
- while (ch <> EOF) and (ch in [BLANK, TAB]) do
- ch := text_getc(f);
- if (ch in ['0'..'9']) then
- begin { oops, put it back }
- if fc_ungetc(f, ch) = Byte(EOF) then
- begin
- read_scan_integer := FALSE;
- exit;
- end;
- ch := BLANK;
- end
- else
- begin
- { Any separators other than ';' and ':' are ignored;
- this allows user to insert commas, etc, if desired. }
-
- if (ch <> EOF) and (ch <> ';') and (ch <> ':') then
- ch := BLANK;
- end;
- termchar := ch;
- read_scan_integer := TRUE;
-end;
-
-
-{GLOBAL}
-function read_scan_script (cinfo : j_compress_ptr;
- const filename : string) : boolean;
-{ 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. }
-label
- bogus;
-var
- f : file;
- fp : Cache;
- scanno, ncomps : int;
- termchar : char;
- val : long;
- scanptr : jpeg_scan_info_ptr;
-const
- MAX_SCANS = 100; { quite arbitrary limit }
-var
- scans : array[0..MAX_SCANS-1] of jpeg_scan_info;
-begin
- Assign(f,filename);
- {$I-}
- Reset(f, 1);
- {$IFDEF IoCheck} {$I+} {$ENDIF}
- if (IOresult <> 0) then
- begin
- WriteLn('Can''t open scan definition file ', filename);
- read_scan_script := FALSE;
- exit;
- end;
- fc_Init(fp, f, 0);
- scanptr := @scans[0];
- scanno := 0;
-
- while (read_scan_integer(fp, val, termchar)) do
- begin
- if (scanno >= MAX_SCANS) then
- begin
- WriteLn(output, 'Too many scans defined in file ', filename);
- fc_Close(fp);
- read_scan_script := FALSE;
- exit;
- end;
- scanptr^.component_index[0] := int(val);
- ncomps := 1;
- while (termchar = BLANK) do
- begin
- if (ncomps >= MAX_COMPS_IN_SCAN) then
- begin
- WriteLn(output, 'Too many components in one scan in file ',
- filename);
- fc_close(fp);
- read_scan_script := FALSE;
- exit;
- end;
- if (not read_scan_integer(fp, val, termchar)) then
- goto bogus;
- scanptr^.component_index[ncomps] := int (val);
- Inc(ncomps);
- end;
- scanptr^.comps_in_scan := ncomps;
- if (termchar = ':') then
- begin
- if (not read_scan_integer(fp, val, termchar)) or (termchar <> BLANK) then
- goto bogus;
- scanptr^.Ss := int (val);
- if (not read_scan_integer(fp, val, termchar)) or (termchar <> BLANK) then
- goto bogus;
- scanptr^.Se := int (val);
- if (not read_scan_integer(fp, val, termchar)) or (termchar <> BLANK) then
- goto bogus;
- scanptr^.Ah := int (val);
- if (not read_scan_integer(fp, val, termchar)) then
- goto bogus;
- scanptr^.Al := int (val);
- end
- else
- begin
- { set non-progressive parameters }
- scanptr^.Ss := 0;
- scanptr^.Se := DCTSIZE2-1;
- scanptr^.Ah := 0;
- scanptr^.Al := 0;
- end;
- if (termchar <> ';') and (termchar <> EOF) then
- begin
-bogus:
- WriteLn(output, 'Invalid scan entry format in file ', filename);
- fc_close(fp);
- read_scan_script := FALSE;
- exit;
- end;
- Inc(scanptr);
- Inc(scanno);
- end;
-
- if (termchar <> EOF) then
- begin
- WriteLn(output, 'Non-numeric data in file ', filename);
- fc_close(fp);
- read_scan_script := FALSE;
- exit;
- end;
-
- if (scanno > 0) then
- begin
- { 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_ptr (
- 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;
- end;
-
- fc_close(fp);
- read_scan_script := TRUE;
-end;
-
-{$endif} { C_MULTISCAN_FILES_SUPPORTED }
-
-function sscanf(var lineptr : PChar;
- var val : int;
- var ch : char) : boolean;
-var
- digits : int;
-begin
- digits := 0;
- while (lineptr^=BLANK) do { advance to next segment of the string }
- Inc(lineptr);
- val := 0;
- while lineptr^ in ['0'..'9'] do
- begin
- val := val * 10 + (ord(lineptr^) - ord('0'));
- Inc(lineptr);
- Inc(digits);
- end;
- if lineptr^<>#0 then
- begin
- ch := lineptr^;
- Inc(lineptr);
- end;
- sscanf := (digits > 0);
-end;
-
-{GLOBAL}
-function set_quant_slots (cinfo : j_compress_ptr;
- argtxt : string) : boolean;
-{ Process a quantization-table-selectors parameter string, of the form
- N[,N,...]
- If there are more components than parameters, the last value is replicated.
- }
-var
- val : int; { default table # }
- ci : int;
- ch : char;
-var
- arg_copy : string;
- arg : PChar;
-begin
- arg_copy := argtxt + #0;
- if arg_copy[Length(arg_copy)] <> #0 then
- arg_copy[Length(arg_copy)] := #0;
- arg := @arg_copy[1];
- val := 0;
- for ci := 0 to pred(MAX_COMPONENTS) do
- begin
- if (arg^ <> #0) then
- begin
- ch := ','; { if not set by sscanf, will be ',' }
- if not sscanf(arg, val, ch) then
- begin
- set_quant_slots := FALSE;
- exit;
- end;
- if (ch <> ',') then { syntax check }
- begin
- set_quant_slots := FALSE;
- exit;
- end;
- if (val < 0) or (val >= NUM_QUANT_TBLS) then
- begin
- WriteLn(output, 'JPEG quantization tables are numbered 0..',
- NUM_QUANT_TBLS-1);
- set_quant_slots := FALSE;
- exit;
- end;
- cinfo^.comp_info^[ci].quant_tbl_no := val;
- end
- else
- begin
- { reached end of parameter, set remaining components to last table }
- cinfo^.comp_info^[ci].quant_tbl_no := val;
- end;
- end;
- set_quant_slots := TRUE;
-end;
-
-
-{GLOBAL}
-function set_sample_factors (cinfo : j_compress_ptr;
- argtxt : string) : boolean;
-{ Process a sample-factors parameter string, of the form
- HxV[,HxV,...]
- If there are more components than parameters, "1x1" is assumed for the rest.
- }
-var
- ci, val1, val2 : int;
- ch1, ch2 : char;
-var
- arg_copy : string;
- arg : PChar;
-begin
- arg_copy := argtxt + #0;
- if arg_copy[Length(arg_copy)] <> #0 then
- arg_copy[Length(arg_copy)] := #0;
- arg := @arg_copy[1];
- for ci := 0 to pred(MAX_COMPONENTS) do
- begin
- if (arg^ <> #0) then
- begin
- ch2 := ','; { if not set by sscanf, will be ',' }
- if not (sscanf(arg, val1, ch1) and
- sscanf(arg, val2, ch2)) then
- begin
- set_sample_factors := FALSE;
- exit;
- end;
- if ((ch1 <> 'x') and (ch1 <> 'X')) or (ch2 <> ',') then { syntax check }
- begin
- set_sample_factors := FALSE;
- exit;
- end;
- if (val1 <= 0) or (val1 > 4) or (val2 <= 0) or (val2 > 4) then
- begin
- WriteLn(output, 'JPEG sampling factors must be 1..4');
- set_sample_factors := FALSE;
- exit;
- end;
- cinfo^.comp_info^[ci].h_samp_factor := val1;
- cinfo^.comp_info^[ci].v_samp_factor := val2;
- end
- else
- begin
- { 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;
- end;
- end;
- set_sample_factors := TRUE;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/rdtarga.pas b/packages/base/pasjpeg/rdtarga.pas
deleted file mode 100644
index ade0692081..0000000000
--- a/packages/base/pasjpeg/rdtarga.pas
+++ /dev/null
@@ -1,559 +0,0 @@
-Unit RdTarga;
-
-{ rdtarga.c ; Copyright (C) 1991-1996, Thomas G. Lane.
-
- These routines may need modification for non-Unix environments or
- specialized applications. As they stand, they assume input from
- an ordinary stdio stream. They further assume that reading begins
- at the start of the file; start_input may need work if the
- user interface has already read some data (e.g., to determine that
- the file is indeed Targa format).
-
- Based on code contributed by Lee Daniel Crocker. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jpeglib,
- jinclude,
- jdeferr,
- jerror,
- cdjpeg; { Common decls for cjpeg/djpeg applications }
-
-
-{ The module selection routine for Targa format input. }
-
-{GLOBAL}
-function jinit_read_targa (cinfo : j_compress_ptr) : cjpeg_source_ptr;
-
-implementation
-
-{ Macros to deal with unsigned chars as efficiently as compiler allows }
-
-type
- U_CHAR = byte;
- UCH = int;
-(*type
-{$ifdef CHAR_IS_UNSIGNED}
- UCH = int;
-{$else}
- UCH = int (x and $FF);
-{$endif}
-*)
-{ Private version of data source object }
-
-type
- tga_source_ptr = ^tga_source_struct;
- tga_source_struct = record
- pub : cjpeg_source_struct; { public fields }
-
- cinfo : j_compress_ptr; { back link saves passing separate parm }
-
- colormap : JSAMPARRAY; { Targa colormap (converted to my format) }
-
- whole_image : jvirt_sarray_ptr; { Needed if funny input row order }
- current_row : JDIMENSION; { Current logical row number to read }
-
- { Pointer to routine to extract next Targa pixel from input file }
- read_pixel : procedure (sinfo : tga_source_ptr);
-
- { Result of read_pixel is delivered here: }
- tga_pixel : array[0..4-1] of U_CHAR;
-
- pixel_size : int; { Bytes per Targa pixel (1 to 4) }
-
- { State info for reading RLE-coded pixels; both counts must be init to 0 }
- block_count : int; { # of pixels remaining in RLE block }
- dup_pixel_count : int; { # of times to duplicate previous pixel }
-
- { This saves the correct pixel-row-expansion method for preload_image }
- get_pixel_rows : function(cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION;
- end;
-
-{ For expanding 5-bit pixel values to 8-bit with best rounding }
-
-const
- c5to8bits : array[0..32-1] of UINT8 =
- ( 0, 8, 16, 25, 33, 41, 49, 58,
- 66, 74, 82, 90, 99, 107, 115, 123,
- 132, 140, 148, 156, 165, 173, 181, 189,
- 197, 206, 214, 222, 230, 239, 247, 255);
-
-function getc(f : fileptr) : byte;
-begin
- getc := 0;
-end;
-const
- EOF = byte(26); { ^Z }
-
-{LOCAL}
-function read_byte (sinfo : tga_source_ptr) : int;
-{ Read next byte from Targa file }
-var
- {register} infile : FILEptr;
- {register} c : int;
-begin
- infile := sinfo^.pub.input_file;
- c := getc(infile);
- if (c = EOF) then
- ERREXIT(j_common_ptr(sinfo^.cinfo), JERR_INPUT_EOF);
- read_byte := c;
-end;
-
-
-{LOCAL}
-procedure read_colormap (sinfo : tga_source_ptr;
- cmaplen : int;
- mapentrysize : int);
-{ Read the colormap from a Targa file }
-var
- i : int;
-begin
- { Presently only handles 24-bit BGR format }
- if (mapentrysize <> 24) then
- ERREXIT(j_common_ptr(sinfo^.cinfo), JERR_TGA_BADCMAP);
-
- for i := 0 to pred(cmaplen) do
- begin
- sinfo^.colormap^[2]^[i] := JSAMPLE (read_byte(sinfo));
- sinfo^.colormap^[1]^[i] := JSAMPLE (read_byte(sinfo));
- sinfo^.colormap^[0]^[i] := JSAMPLE (read_byte(sinfo));
- end;
-end;
-
-
-{ read_pixel methods: get a single pixel from Targa file into tga_pixel[] }
-
-{METHODDEF}
-procedure read_non_rle_pixel (sinfo : tga_source_ptr); far;
-{ Read one Targa pixel from the input file; no RLE expansion }
-var
- {register} infile : FILEptr;
- {register} i : int;
-begin
- infile := sinfo^.pub.input_file;
- for i := 0 to pred(sinfo^.pixel_size) do
- begin
- sinfo^.tga_pixel[i] := U_CHAR (getc(infile));
- end;
-end;
-
-
-{METHODDEF}
-procedure read_rle_pixel (sinfo : tga_source_ptr); far;
-{ Read one Targa pixel from the input file, expanding RLE data as needed }
-var
- {register} infile : FILEptr;
- {register} i : int;
-begin
- infile := sinfo^.pub.input_file;
-
- { Duplicate previously read pixel? }
- if (sinfo^.dup_pixel_count > 0) then
- begin
- Dec(sinfo^.dup_pixel_count);
- exit;
- end;
-
- { Time to read RLE block header? }
- Dec(sinfo^.block_count);
- if (sinfo^.block_count < 0) then
- begin { decrement pixels remaining in block }
- i := read_byte(sinfo);
- if (i and $80) <> 0 then
- begin { Start of duplicate-pixel block? }
- sinfo^.dup_pixel_count := i and $7F; { number of dups after this one }
- sinfo^.block_count := 0; { then read new block header }
- end
- else
- begin
- sinfo^.block_count := i and $7F; { number of pixels after this one }
- end;
- end;
-
- { Read next pixel }
- for i := 0 to pred(sinfo^.pixel_size) do
- begin
- sinfo^.tga_pixel[i] := U_CHAR (getc(infile));
- end;
-end;
-
-
-{ Read one row of pixels.
-
- We provide several different versions depending on input file format. }
-
-{METHODDEF}
-function get_8bit_gray_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading 8-bit grayscale pixels }
-var
- source : tga_source_ptr;
- {register} ptr : JSAMPLE_PTR;
- {register} col : JDIMENSION;
-begin
- source := tga_source_ptr (sinfo);
- ptr := JSAMPLE_PTR(source^.pub.buffer^[0]);
- for col := pred(cinfo^.image_width) downto 0 do
- begin
- source^.read_pixel (source); { Load next pixel into tga_pixel }
- ptr^ := JSAMPLE (UCH(source^.tga_pixel[0]));
- Inc(ptr);
- end;
- get_8bit_gray_row := 1;
-end;
-
-{METHODDEF}
-function get_8bit_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading 8-bit colormap indexes }
-var
- source : tga_source_ptr;
- {register} t : int;
- {register} ptr : JSAMPLE_PTR;
- {register} col : JDIMENSION;
- {register} colormap : JSAMPARRAY;
-begin
- source := tga_source_ptr (sinfo);
- colormap := source^.colormap;
-
- ptr := JSAMPLE_PTR(source^.pub.buffer^[0]);
- for col := pred(cinfo^.image_width) downto 0 do
- begin
- source^.read_pixel (source); { Load next pixel into tga_pixel }
- t := UCH(source^.tga_pixel[0]);
- ptr^ := colormap^[0]^[t];
- Inc(ptr);
- ptr^ := colormap^[1]^[t];
- Inc(ptr);
- ptr^ := colormap^[2]^[t];
- Inc(ptr);
- end;
- get_8bit_row := 1;
-end;
-
-{METHODDEF}
-function get_16bit_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading 16-bit pixels }
-var
- source : tga_source_ptr;
-
- {register} t : int;
- {register} ptr : JSAMPROW;
- {register} col : JDIMENSION;
-begin
- source := tga_source_ptr (sinfo);
-
- ptr := source^.pub.buffer^[0];
- for col := pred(cinfo^.image_width) downto 0 do
- begin
- source^.read_pixel (source); { Load next pixel into tga_pixel }
- t := UCH(source^.tga_pixel[0]);
- Inc(t, UCH(source^.tga_pixel[1]) shr 8);
- { We expand 5 bit data to 8 bit sample width.
- The format of the 16-bit (LSB first) input word is
- xRRRRRGGGGGBBBBB
- }
- ptr^[2] := JSAMPLE (c5to8bits[t and $1F]);
- t := t shr 5;
- ptr^[1] := JSAMPLE (c5to8bits[t and $1F]);
- t := t shr 5;
- ptr^[0] := JSAMPLE (c5to8bits[t and $1F]);
- Inc(JSAMPLE_PTR(ptr), 3);
- end;
- get_16bit_row :=1;
-end;
-
-{METHODDEF}
-function get_24bit_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-{ This version is for reading 24-bit pixels }
-var
- source : tga_source_ptr;
-
- {register} ptr : JSAMPLE_PTR;
- {register} col : JDIMENSION;
-begin
- source := tga_source_ptr (sinfo);
- ptr := JSAMPLE_PTR(source^.pub.buffer^[0]);
- for col := pred(cinfo^.image_width) downto 0 do
- begin
- source^.read_pixel (source); { Load next pixel into tga_pixel }
- ptr^ := JSAMPLE (UCH(source^.tga_pixel[2])); { change BGR to RGB order }
- Inc(ptr);
- ptr^ := JSAMPLE (UCH(source^.tga_pixel[1]));
- Inc(ptr);
- ptr^ := JSAMPLE (UCH(source^.tga_pixel[0]));
- Inc(ptr);
- end;
- get_24bit_row := 1;
-end;
-
-{ Targa also defines a 32-bit pixel format with order B,G,R,A.
- We presently ignore the attribute byte, so the code for reading
- these pixels is identical to the 24-bit routine above.
- This works because the actual pixel length is only known to read_pixel. }
-
-const
- get_32bit_row : function (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION
- = get_24bit_row;
-
-
-{ This method is for re-reading the input data in standard top-down
- row order. The entire image has already been read into whole_image
- with proper conversion of pixel format, but it's in a funny row order. }
-
-{METHODDEF}
-function get_memory_row (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-var
- source : tga_source_ptr;
- source_row : JDIMENSION;
-begin
- source := tga_source_ptr (sinfo);
- { Compute row of source that maps to current_row of normal order }
- { For now, assume image is bottom-up and not interlaced. }
- { NEEDS WORK to support interlaced images! }
- source_row := cinfo^.image_height - source^.current_row - 1;
-
- { Fetch that row from virtual array }
- source^.pub.buffer := cinfo^.mem^.access_virt_sarray
- (j_common_ptr (cinfo), source^.whole_image,
- source_row, JDIMENSION (1), FALSE);
-
- Inc(source^.current_row);
- get_memory_row := 1;
-end;
-
-
-{ This method loads the image into whole_image during the first call on
- get_pixel_rows. The get_pixel_rows pointer is then adjusted to call
- get_memory_row on subsequent calls. }
-
-{METHODDEF}
-function preload_image (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr) : JDIMENSION; far;
-var
- source : tga_source_ptr;
- row : JDIMENSION;
- progress : cd_progress_ptr;
-begin
- source := tga_source_ptr (sinfo);
- progress := cd_progress_ptr (cinfo^.progress);
-
- { Read the data into a virtual array in input-file row order. }
- for row := 0 to pred(cinfo^.image_height) do
- begin
- if (progress <> NIL) then
- begin
- progress^.pub.pass_counter := long (row);
- progress^.pub.pass_limit := long (cinfo^.image_height);
- progress^.pub.progress_monitor (j_common_ptr (cinfo));
- end;
- source^.pub.buffer := cinfo^.mem^.access_virt_sarray
- (j_common_ptr(cinfo), source^.whole_image, row, JDIMENSION(1), TRUE);
- source^.get_pixel_rows (cinfo, sinfo);
- end;
- if (progress <> NIL) then
- Inc(progress^.completed_extra_passes);
-
- { Set up to read from the virtual array in unscrambled order }
- source^.pub.get_pixel_rows := get_memory_row;
- source^.current_row := 0;
- { And read the first row }
- preload_image := get_memory_row(cinfo, sinfo);
-end;
-
-
-{ Read the file header; return image size and component count. }
-
-{METHODDEF}
-procedure start_input_tga (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr); far;
-var
- source : tga_source_ptr;
- targaheader : array[0..18-1] of U_CHAR;
- idlen, cmaptype, subtype, flags, interlace_type, components : int;
- width, height, maplen : uInt;
- is_bottom_up : boolean;
-var
- progress : cd_progress_ptr;
-begin
- source := tga_source_ptr (sinfo);
-
- if JFREAD(source^.pub.input_file, @targaheader, 18) <> size_t(18) then
- ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EOF);
-
- { Pretend "15-bit" pixels are 16-bit --- we ignore attribute bit anyway }
- if (targaheader[16] = 15) then
- targaheader[16] := 16;
-
- idlen := UCH(targaheader[0]);
- cmaptype := UCH(targaheader[1]);
- subtype := UCH(targaheader[2]);
- maplen := {GET_2B(5);}
- uInt (UCH(targaheader[5])) +
- ( uInt (UCH(targaheader[5+1])) ) shl 8;
- width := {GET_2B(12);}
- ( uInt(UCH(targaheader[12])) +
- ( uInt(UCH(targaheader[12+1])) ) shl 8);
- height := {GET_2B(14);}
- ( uInt(UCH(targaheader[14])) +
- ( uInt(UCH(targaheader[14+1])) ) shl 8);
-
- source^.pixel_size := UCH(targaheader[16]) shl 3;
- flags := UCH(targaheader[17]); { Image Descriptor byte }
-
- is_bottom_up := (flags and $20) = 0; { bit 5 set => top-down }
- interlace_type := flags shl 6; { bits 6/7 are interlace code }
-
- if (cmaptype > 1) or { cmaptype must be 0 or 1 }
- (source^.pixel_size < 1) or (source^.pixel_size > 4) or
- ((UCH(targaheader[16]) and 7) <> 0) or { bits/pixel must be multiple of 8 }
- (interlace_type <> 0) then { currently don't allow interlaced image }
- ERREXIT(j_common_ptr(cinfo), JERR_TGA_BADPARMS);
-
- if (subtype > 8) then
- begin
- { It's an RLE-coded file }
- source^.read_pixel := read_rle_pixel;
- source^.block_count := 0;
- source^.dup_pixel_count := 0;
- Dec(subtype, 8);
- end
- else
- begin
- { Non-RLE file }
- source^.read_pixel := read_non_rle_pixel;
- end;
-
- { Now should have subtype 1, 2, or 3 }
- components := 3; { until proven different }
- cinfo^.in_color_space := JCS_RGB;
-
- case (subtype) of
- 1:begin { Colormapped image }
- if (source^.pixel_size = 1) and (cmaptype = 1) then
- source^.get_pixel_rows := get_8bit_row
- else
- ERREXIT(j_common_ptr(cinfo), JERR_TGA_BADPARMS);
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_TGA_MAPPED, width, height);
- end;
- 2:begin { RGB image }
- case (source^.pixel_size) of
- 2: source^.get_pixel_rows := get_16bit_row;
- 3: source^.get_pixel_rows := get_24bit_row;
- 4: source^.get_pixel_rows := get_32bit_row;
- else
- ERREXIT(j_common_ptr(cinfo), JERR_TGA_BADPARMS);
- end;
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_TGA, width, height);
- end;
- 3:begin { Grayscale image }
- components := 1;
- cinfo^.in_color_space := JCS_GRAYSCALE;
- if (source^.pixel_size = 1) then
- source^.get_pixel_rows := get_8bit_gray_row
- else
- ERREXIT(j_common_ptr(cinfo), JERR_TGA_BADPARMS);
- TRACEMS2(j_common_ptr(cinfo), 1, JTRC_TGA_GRAY, width, height);
- end;
- else
- ERREXIT(j_common_ptr(cinfo), JERR_TGA_BADPARMS);
- end;
-
- if (is_bottom_up) then
- begin
- { Create a virtual array to buffer the upside-down image. }
- source^.whole_image := cinfo^.mem^.request_virt_sarray
- (j_common_ptr (cinfo), JPOOL_IMAGE, FALSE,
- JDIMENSION(width * components), JDIMENSION (height), JDIMENSION (1));
- if (cinfo^.progress <> NIL) then
- begin
- progress := cd_progress_ptr (cinfo^.progress);
- Inc(progress^.total_extra_passes); { count file input as separate pass }
- end;
- { source^.pub.buffer will point to the virtual array. }
- source^.pub.buffer_height := 1; { in case anyone looks at it }
- source^.pub.get_pixel_rows := preload_image;
- end
- else
- begin
- { Don't need a virtual array, but do need a one-row input buffer. }
- source^.whole_image := NIL;
- source^.pub.buffer := cinfo^.mem^.alloc_sarray (
- j_common_ptr (cinfo), JPOOL_IMAGE,
- JDIMENSION (width * components), JDIMENSION (1)) ;
- source^.pub.buffer_height := 1;
- source^.pub.get_pixel_rows := source^.get_pixel_rows;
- end;
-
- while (idlen > 0) do { Throw away ID field }
- begin
- Dec(idlen);
- {void} read_byte(source);
- end;
-
- if (maplen > 0) then
- begin
- if (maplen > 256) or {GET_2B(3) <> 0}
- ( (uInt (UCH(targaheader[3])) +
- (uInt (UCH(targaheader[3+1])) ) shl 8) <> 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_TGA_BADCMAP);
- { Allocate space to store the colormap }
- source^.colormap := cinfo^.mem^.alloc_sarray (
- j_common_ptr (cinfo), JPOOL_IMAGE,
- JDIMENSION (maplen), JDIMENSION (3));
- { and read it from the file }
- read_colormap(source, int (maplen), UCH(targaheader[7]));
- end
- else
- begin
- if (cmaptype <> 0) then { but you promised a cmap! }
- ERREXIT(j_common_ptr(cinfo), JERR_TGA_BADPARMS);
- source^.colormap := NIL;
- end;
-
- cinfo^.input_components := components;
- cinfo^.data_precision := 8;
- cinfo^.image_width := width;
- cinfo^.image_height := height;
-end;
-
-
-{ Finish up at the end of the file. }
-
-{METHODDEF}
-procedure finish_input_tga (cinfo : j_compress_ptr;
- sinfo : cjpeg_source_ptr); far;
-begin
- { no work }
-end;
-
-
-{ The module selection routine for Targa format input. }
-
-{GLOBAL}
-function jinit_read_targa (cinfo : j_compress_ptr) : cjpeg_source_ptr;
-var
- source : tga_source_ptr;
-begin
- { Create module interface object }
- source := tga_source_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr (cinfo), JPOOL_IMAGE,
- SIZEOF(tga_source_struct)) );
- source^.cinfo := cinfo; { make back link for subroutines }
- { Fill in method ptrs, except get_pixel_rows which start_input sets }
- source^.pub.start_input := start_input_tga;
- source^.pub.finish_input := finish_input_tga;
-
- jinit_read_targa := cjpeg_source_ptr (source);
-end;
-
-end. { TARGA_SUPPORTED }
diff --git a/packages/base/pasjpeg/readme.txt b/packages/base/pasjpeg/readme.txt
deleted file mode 100644
index 64391937ae..0000000000
--- a/packages/base/pasjpeg/readme.txt
+++ /dev/null
@@ -1,381 +0,0 @@
-_____________________________________________________________________________
-
-PASJPEG 1.1 May 29th, 1999
-
-Based on the Independent JPEG Group's JPEG software release 6b
-
-Copyright (C) 1996,1998,1999 by NOMSSI NZALI Jacques H. C.
-[kn&n DES] See "Legal issues" for conditions of distribution and use.
-_____________________________________________________________________________
-
-
-Information in this file
-========================
-
- o Introduction
- o Notes
- o File list
- o Translation
- o Legal issues
- o Archive Locations
-
-Introduction
-============
-
-PASJPEG is a port of the sixth public release of the IJG C source (release
-6b of 27-Mar-98) [3], that implements JPEG baseline, extended-sequential, and
-progressive compression processes to Turbo Pascal 7.0 for DOS (TP). The code
-has been tested under Delphi 3.0, it can be ported to other Pascal
-environments, since many compilers try to be compatible to TP.
-
-JPEG (pronounced "jay-peg") is a standardized familly of algorithms for
-compression of continous tone still images. Most JPEG processes are lossy,
-the output image is not exactly identical to the input image. However, on
-typical photographic images, very good compression levels can be obtained
-with no visible change, and remarkably high compression levels are possible
-if you can tolerate a low-quality image [1],[2]. The Independent JPEG Group
-(IJG) has created a free, portable C library for JPEG compression and
-decompression of JPEG images.
-
-The IJG documentation (system architecture, using the IJG JPEG library,
-usage and file list) is a must read. The files DEMO.PAS, TEST.PAS, CJPEG.PAS,
-DJPEG.PAS and EXAMPLE.PAS demonstrate the usage of the JPEG decompression
-and compression library. The RDJPGCOM application shows how to parse a JFIF
-file.
-
-Notes:
-======
-
-* Please report any errors/problems you may find in code and in the
- documentation (e.g. this README.TXT file).
-
-* The sample applications (CJPEG, DJPEG) doesn't support all the options
- of the original C code. WRJPGCOM is not ported.
-
-* Environment variable JPEGMEM syntax changed;
-
-* You can modify the jpeg.pas unit from the Delphi 3 distribution to
- use PasJPEG.
-
-Change log
-==========
-
-1. bugs fixed:
- * in procedure read_gif_map(), unit RDCOLMAP.PAS (used by DJPEG sample
- application). Davie Lee Reed <smatters@iquest.net>
- * -dct int and -dct fast now bytewise equal to the IJG output.
- * -dct float produced large files
-
-2. Support for scripts
-
-3. BASM version of JIDCTINT.PAS for Delphi 2 and 3.
-
-4. images with integral sampling ratios were not decoded correctly.
- Create a jpeg file with cjpeg and the option "-sample 4x1" and try to decode
- it with any software that uses PasJpeg. Thanks to Jannie Gerber for reporting
- this with a fix: In JDSAMPLE.PAS, procedure int_upsample(),
-
- for h := pred(h_expand) downto 0 do
- begin
- outptr^ := invalue;
- +=> inc(outptr); { this is the culprit that was left out!!! }
- Dec(outcount);
- end;
-
-File list
-=========
-
-Here is a road map to the files in the PasJPEG distribution. The
-distribution includes the JPEG library proper, plus two application
-programs ("cjpeg" and "djpeg") which use the library to convert JPEG
-files to and from some other popular image formats. A third application
-"jpegtran" uses the library to do lossless conversion between different
-variants of JPEG. There is also the stand-alone applications "rdjpgcom".
-
-Documentation(see README for a guide to the documentation files):
-
-readme.txt Introduction, Documentation
-
-Additional files
-
-demo.pas Demo program, uses example.pas
-example.pas Sample code for calling JPEG library.
-test.pas Sample application code for demo.pas
-
-Configuration/installation files and programs (see install.doc for more info):
-
-jconfig.inc Configuration declarations.
-
-*.ijg script files
-
-Pascal source code files:
-
-jinclude.pas Central include file used by all IJG .c files to reference
- system include files.
-jpeglib.pas JPEG library's internal data structures, exported data
- and function declarations.
-jmorecfg.pas Additional configuration declarations; need not be changed
- for a standard installation.
-jdeferr.pas defines the error and message text.
-jerror.pas Declares JPEG library's error and trace message codes.
-jinclude.pas the place to specify system depedent input/output code.
-jdct.pas Private declarations for forward & reverse DCT subsystems.
-
-These files contain most of the functions intended to be called directly by
-an application program:
-
-jcapimin.pas Application program interface: core routines for compression.
-jcapistd.pas Application program interface: standard compression.
-jdapimin.pas Application program interface: core routines for decompression.
-jdapistd.pas Application program interface: standard decompression.
-jcomapi.pas Application program interface routines common to compression
- and decompression.
-jcparam.pas Compression parameter setting helper routines.
-jctrans.pas API and library routines for transcoding compression.
-jdtrans.pas API and library routines for transcoding decompression.
-
-Compression side of the library:
-
-jcinit.pas Initialization: determines which other modules to use.
-jcmaster.pas Master control: setup and inter-pass sequencing logic.
-jcmainct.pas Main buffer controller (preprocessor => JPEG compressor).
-jcprepct.pas Preprocessor buffer controller.
-jccoefct.pas Buffer controller for DCT coefficient buffer.
-jccolor.pas Color space conversion.
-jcsample.pas Downsampling.
-jcdctmgr.pas DCT manager (DCT implementation selection & control).
-jfdctint.pas Forward DCT using slow-but-accurate integer method.
-jfdctfst.pas Forward DCT using faster, less accurate integer method.
-jfdctflt.pas Forward DCT using floating-point arithmetic.
-jchuff.pas Huffman entropy coding for sequential JPEG.
-jcphuff.pas Huffman entropy coding for progressive JPEG.
-jcmarker.pas JPEG marker writing.
-jdatadst.pas Data destination manager for stdio output.
-
-Decompression side of the library:
-
-jdmaster.pas Master control: determines which other modules to use.
-jdinput.pas Input controller: controls input processing modules.
-jdmainct.pas Main buffer controller (JPEG decompressor => postprocessor).
-jdcoefct.pas Buffer controller for DCT coefficient buffer.
-jdpostct.pas Postprocessor buffer controller.
-jdmarker.pas JPEG marker reading.
-jdhuff.pas Huffman entropy decoding for sequential JPEG.
-jdphuff.pas Huffman entropy decoding for progressive JPEG.
-jddctmgr.pas IDCT manager (IDCT implementation selection & control).
-jidctint.pas Inverse DCT using slow-but-accurate integer method.
-jidctasm.pas BASM specific version of jidctint.pas for 32bit Delphi.
-jidctfst.pas Inverse DCT using faster, less accurate integer method.
-jidctflt.pas Inverse DCT using floating-point arithmetic.
-jidctred.pas Inverse DCTs with reduced-size outputs.
-jidct2d.pas How to for a direct 2D Inverse DCT - not used
-jdsample.pas Upsampling.
-jdcolor.pas Color space conversion.
-jdmerge.pas Merged upsampling/color conversion (faster, lower quality).
-jquant1.pas One-pass color quantization using a fixed-spacing colormap.
-jquant2.pas Two-pass color quantization using a custom-generated colormap.
- Also handles one-pass quantization to an externally given map.
-jdatasrc.pas Data source manager for stdio input.
-
-Support files for both compression and decompression:
-
-jerror.pas Standard error handling routines (application replaceable).
-jmemmgr.pas System-independent (more or less) memory management code.
-jutils.pas Miscellaneous utility routines.
-
-jmemmgr.pas relies on a system-dependent memory management module. The
-PASJPEG distribution includes the following implementations of the system-
-dependent module:
-
-jmemnobs.pas "No backing store": assumes adequate virtual memory exists.
-jmemdos.pas Custom implementation for MS-DOS (16-bit environment only):
- can use extended and expanded memory as well as temporary
- files.
-jmemsys.pas A skeleton with all the declaration you need to create a
- working system-dependent JPEG memory manager on unusual
- systems.
-
-Exactly one of the system-dependent units should be used in jmemmgr.pas.
-
-jmemdosa.pas BASM 80x86 assembly code support for jmemdos.pas; used only
- in MS-DOS-specific configurations of the JPEG library.
-
-
-Applications using the library should use jmorecfg, jerror, jpeglib, and
-include jconfig.inc.
-
-CJPEG/DJPEG/JPEGTRAN
-
-Pascal source code files:
-
-cderror.pas Additional error and trace message codes for cjpeg/djpeg.
- Not used, Those errors have been added to jdeferr.
-cjpeg.pas Main program for cjpeg.
-djpeg.pas Main program for djpeg.
-jpegtran.pas Main program for jpegtran.
-cdjpeg.pas Utility routines used by all three programs.
-rdcolmap.pas Code to read a colormap file for djpeg's "-map" switch.
-rdswitch.pas Code to process some of cjpeg's more complex switches.
- Also used by jpegtran.
-transupp.pas Support code for jpegtran: lossless image manipulations.
-
-fcache.pas
-rdswitch.pas Code to process some of cjpeg's more complex switches.
- Also used by jpegtran.
-
-Image file writer modules for djpeg:
-
-wrbmp.pas BMP file output.
-wrppm.pas PPM/PGM file output.
-wrtarga.pas Targa file output.
-
-Image file reader modules for cjpeg:
-
-rdbmp.pas BMP file input.
-rdppm.pas PPM/PGM file input.
-rdtarga.pas Targa file input. - NOT READY YET
-
-This program does not depend on the JPEG library
-
-rdjpgcom.pas Stand-alone rdjpgcom application.
-
-
-Translation
-===========
-
-TP is unit-centric, exported type definitions and routines are declared
-in the "interface" part of the unit, "make" files are not needed.
-Macros are not supported, they were either copied as needed or translated
-to Pascal routines (procedure). The procedures will be replaced by code in
-later releases.
-Conditional defines that indicate whether to include various optional
-functions are defined in the file JCONFIG.INC. This file is included first
-in all source files.
-
-The base type definitions are in the unit JMORECFG.PAS. The error handling
-macros have been converted to procedures in JERROR.PAS. The error codes are
-in JDEFERR.PAS. jpegint.h and jpeglib.h were merged into one large unit
-JPEGLIB.PAS containing type definitions with global scope.
-
-The translation of the header file is the most sophisticated work, a good
-understanding of the syntax is required. Once the header files are done,
-the translation turns into a lot of editing work. Each C source file was
-converted to a unit by editing the syntax (separate variable definition
-and usage, define labels, group variable definitions, expanding macros, etc).
-
-The IJG source labels routines GLOBAL, METHODDEF and LOCAL. All globals
-routines are in the interface section of the units. The "far" directive is
-used for methods (METHODDEF).
-
-Some C -> Pascal examples.
-
-* "{" -> "begin" "->" -> "^." " = " -> " := " "<<" -> " shl "
- "}" -> "end;" "!=" -> "<>" " == " -> " = " ">>" -> " shr "
- "/*" -> "{" routine -> function "0x" -> "$"
- "*/" -> "}" (void) procedure "NULL" -> "NIL"
-
-* structs are records, Unions are variable records, pointers are always far,
- the operators && and || (and/or) have not the same priority in both
- languages, so parenthesis are important. The Pascal "case" doesn't have the
- falltrough option of the C "switch" statement, my work around is to split
- one "switch" statement into many case statements.
-* The pointer type in C is not readily interchangeable. It is used to address
- an array (Pascal pointer to an array) or in pointer arithmetic a pointer to
- a single element. I've used the Inc() statement with type casting to
- translate pointer arithmetic most of the time.
-
- C example:
- typedef JSAMPLE* JSAMPROW; /* ptr to one image row of pixel samples. */
-
- Pascal
- type
- JSAMPLE_PTR = ^JSAMPLE; { ptr to a single pixel sample. }
- jTSample = 0..(MaxInt div SIZEOF(JSAMPLE))-1;
- JSAMPLE_ARRAY = Array[jTSample] of JSAMPLE; {far}
- JSAMPROW = ^JSAMPLE_ARRAY; { ptr to one image row of pixel samples. }
-
- The following code
-
- JSAMPROW buffer0, buffer1; /* ptr to a JSAMPLE buffer. */
-
- ...
-
- buffer1 = buffer0 + i;
-
- can be translated to
-
- var
- buffer0, buffer1 : JSAMPROW;
-
- ...
-
- buffer1 := buffer0;
- Inc(JSAMPLE_PTR(buffer1), i);
-
- or
-
- buffer1 := JSAMPROW(@ buffer0^[i]);
-
- Declaring the variables as JSAMPLE_PTR may reduce type casting in some
- places. I use help pointers to handle negative array offsets.
-
-While translating the type of function parameter from C to Pascal, one can
-often use "var", "const", or "array of" parameters instead of pointers.
-
-While translating for(;;)-loops with more than one induction variable to
-Pascal "for to/downto do"-loops, the extra induction variables have to be
-manually updated at the end of the loop and before "continue"-statements.
-
-
-Legal issues
-============
-
-Copyright (C) 1996,1998 by Jacques Nomssi Nzali
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the author be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
-
-Archive Locations:
-==================
-
-[1] Thomas G. Lane, JPEG FAQ
-
- in comp.graphics.misc and related newsgroups
-
-[2] Wallace, Gregory K.: The JPEG Still Picture Compression Standard
-
- ftp.uu.net, graphics/jpeg/wallace.ps.Z
-
-[3] The Independent JPEG Group C library for JPEG encoding and decoding,
- rev 6b.
-
- ftp://ftp.uu.net/graphics/jpeg/
-
- or SimTel in msdos/graphics/
-
-[4] JPEG implementation, written by the PVRG group at Stanford,
- ftp havefun.stanford.edu:/pub/jpeg/JPEGv1.2.tar.Z.
-
-[5] PASJPEG.ZIP at NView ftp site
-
- ftp://druckfix.physik.tu-chemnitz.de/pub/nv/
- http://www.tu-chemnitz.de/~nomssi/pub/pasjpeg.zip
-
-[6] The PasJPEG home page with links
-
- http://www.tu-chemnitz.de/~nomssi/pasjpeg.html
-_____________________________________________________________________________
diff --git a/packages/base/pasjpeg/script0.ijg b/packages/base/pasjpeg/script0.ijg
deleted file mode 100644
index 8b4244e9ea..0000000000
--- a/packages/base/pasjpeg/script0.ijg
+++ /dev/null
@@ -1,5 +0,0 @@
-# Here is an example of a scan script that generates a
-# partially interleaved sequential JPEG file:
-
- 0; # Y only in first scan
- 1 2; # Cb and Cr in second scan
diff --git a/packages/base/pasjpeg/script1.ijg b/packages/base/pasjpeg/script1.ijg
deleted file mode 100644
index 2bdae3fa4a..0000000000
--- a/packages/base/pasjpeg/script1.ijg
+++ /dev/null
@@ -1,12 +0,0 @@
-# Here is an example of a progressive scan script using only
-# spectral selection (no successive approximation):
-
- # Interleaved DC scan for Y,Cb,Cr:
- 0,1,2: 0-0, 0, 0 ;
- # AC scans:
- 0: 1-2, 0, 0 ; # First two Y AC coefficients
- 0: 3-5, 0, 0 ; # Three more
- 1: 1-63, 0, 0 ; # All AC coefficients for Cb
- 2: 1-63, 0, 0 ; # All AC coefficients for Cr
- 0: 6-9, 0, 0 ; # More Y coefficients
- 0: 10-63, 0, 0 ; # Remaining Y coefficients
diff --git a/packages/base/pasjpeg/script2.ijg b/packages/base/pasjpeg/script2.ijg
deleted file mode 100644
index 1b2d547500..0000000000
--- a/packages/base/pasjpeg/script2.ijg
+++ /dev/null
@@ -1,32 +0,0 @@
-# Here is an example of a successive-approximation script.
-# This is equivalent to the default script used by
-# "cjpeg -progressive" for YCbCr images:
-
- # Initial DC scan for Y,Cb,Cr (lowest bit not sent)
- 0,1,2: 0-0, 0, 1 ;
- # First AC scan: send first 5 Y AC coefficients, minus 2 lowest bits:
- 0: 1-5, 0, 2 ;
- # Send all Cr,Cb AC coefficients, minus lowest bit:
- # (chroma data is usually too small to be worth subdividing further;
- # but note we send Cr first since eye is least sensitive to Cb)
- 2: 1-63, 0, 1 ;
- 1: 1-63, 0, 1 ;
- # Send remaining Y AC coefficients, minus 2 lowest bits:
- 0: 6-63, 0, 2 ;
- # Send next-to-lowest bit of all Y AC coefficients:
- 0: 1-63, 2, 1 ;
- # At this point we've sent all but the lowest bit of all coefficients.
- # Send lowest bit of DC coefficients
- 0,1,2: 0-0, 1, 0 ;
- # Send lowest bit of AC coefficients
- 2: 1-63, 1, 0 ;
- 1: 1-63, 1, 0 ;
- # Y AC lowest bit scan is last; it's usually the largest scan
- 0: 1-63, 1, 0 ;
-
-# It may be worth pointing out that this script is tuned for quality
-# settings of around 50 to 75. For lower quality settings, you'd
-# probably want to use a script with fewer stages of successive
-# approximation (otherwise the initial scans will be really bad).
-# For higher quality settings, you might want to use more stages of
-# successive approximation (so that the initial scans are not too large).
diff --git a/packages/base/pasjpeg/test.pas b/packages/base/pasjpeg/test.pas
deleted file mode 100644
index 2db8304f44..0000000000
--- a/packages/base/pasjpeg/test.pas
+++ /dev/null
@@ -1,148 +0,0 @@
-Unit Test;
-
-interface
-
-uses
- jmorecfg, jpeglib;
-
-const
- MaxWidth = 175;
- MaxLines = 4;
-type
- RGB_pixel = packed record
- Case byte of
- 0:(r,g,b : byte);
- 1:(color:array[0..2] of byte);
- 2:(cyan,magenta,yellow : byte);
- 3:(Y,Cb,Cr : byte);
- end;
-var
- image_line : array[0..MaxLines-1,0..MaxWidth-1] of RGB_pixel;
-var
- image_buffer : JSAMPROW; { Points to large array of R,G,B-order data }
- image_height : int; { Number of rows in image }
- image_width : int; { Number of columns in image }
-var
- current_line : int;
-type
- jmp_buf = pointer;
-
- { This routine does the output }
- procedure put_scanline_someplace(buffer : JSAMPROW; row_stride : int);
-
- { define an error recovery point. Return 0 when OK }
- function setjmp(setjmp_buffer : jmp_buf) : int;
-
- { Return control to the setjmp point }
- procedure longjmp(setjmp_buffer : jmp_buf; flag : int);
-
- procedure save_color_map(cinfo : j_decompress_ptr);
-
- procedure define_image_params;
-
- procedure pre_decode;
-
- procedure post_decode;
-
-implementation
-
-var
- outfile : file;
-
-{ This routine does the output }
-procedure put_scanline_someplace(buffer : JSAMPROW; row_stride : int);
-var
- line_size : int;
-begin
- WriteLn(output, current_line:3, '. line of image data read');
- line_size := 3 * MaxWidth;
-
- BlockWrite(outfile, buffer^, row_stride);
-
- if line_size > row_stride then
- line_size := row_stride;
-
- if current_line < MaxLines then
- Move(buffer^, image_line[current_line], line_size);
- Inc(current_line);
-end;
-
-{ define an error recovery point. Return 0 when OK }
-function setjmp(setjmp_buffer : jmp_buf) : int;
-begin
- setjmp := 0;
- current_line := 0;
-end;
-
-{ Return control to the setjmp point }
-procedure longjmp(setjmp_buffer : jmp_buf; flag : int);
-begin
- Halt(2);
-end;
-
-procedure define_image_params;
-var
- i, j : JDIMENSION;
- r0, b0, g0 : byte;
-begin
- r0 := 255;
- g0 := 255;
- b0 := 255;
- for j := 0 to pred(MaxLines) do
- begin
- for i := 0 to Pred(MaxWidth) do
- with image_line[j][i] do
- begin
- r := r0;
- Dec(r0);
- g := g0;
- b := b0;
- end;
- Dec(b0, 16);
- end;
- image_buffer := JSAMPROW(@image_line);
- image_height := MaxLines;
- image_width := MaxWidth;
-end;
-
-
-procedure pre_decode;
-begin
- Assign(outfile, 'PasJpeg.raw');
- ReWrite(outfile, 1);
-end;
-
-procedure save_color_map(cinfo : j_decompress_ptr);
-var
- VGAPalette : Array[0..255] of RGB_pixel;
- i, count : int;
-begin
- count := cinfo^.actual_number_of_colors;
- if (cinfo^.colormap <> NIL) and (count > 0) then
- begin
- if count > 256 then
- count := 256;
- if (cinfo^.out_color_components = 3) then
- for i := 0 to pred(count) do
- begin
- VGAPalette[i].r := cinfo^.colormap^[0]^[i];
- VGAPalette[i].g := cinfo^.colormap^[1]^[i];
- VGAPalette[i].b := cinfo^.colormap^[2]^[i];
- end
- else { Grayscale colormap (only happens with grayscale quantization) }
- for i := 0 to pred(count) do
- begin
- VGAPalette[i].r := cinfo^.colormap^[0]^[i];
- VGAPalette[i].g := cinfo^.colormap^[0]^[i];
- VGAPalette[i].b := cinfo^.colormap^[0]^[i];
- end;
- BlockWrite(outfile, VGAPalette, 3*count);
- end;
-end;
-
-procedure post_decode;
-begin
- Close(outfile);
-end;
-
-end.
diff --git a/packages/base/pasjpeg/test1.dfm b/packages/base/pasjpeg/test1.dfm
deleted file mode 100644
index 97ab473c23..0000000000
--- a/packages/base/pasjpeg/test1.dfm
+++ /dev/null
Binary files differ
diff --git a/packages/base/pasjpeg/test1.pas b/packages/base/pasjpeg/test1.pas
deleted file mode 100644
index 3fb6e41909..0000000000
--- a/packages/base/pasjpeg/test1.pas
+++ /dev/null
@@ -1,96 +0,0 @@
-unit test1;
-
-interface
-
-uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, jpeg, ExtCtrls, FileCtrl, ComCtrls;
-
-type
- TForm1 = class(TForm)
- Image1: TImage;
- Panel1: TPanel;
- DirectoryListBox1: TDirectoryListBox;
- FileListBox1: TFileListBox;
- Panel3: TPanel;
- DriveComboBox1: TDriveComboBox;
- Scale: TComboBox;
- PixelFormat: TComboBox;
- ColorSpace: TComboBox;
- Performance: TComboBox;
- ProgressiveDisplay: TCheckBox;
- IncrementalDisplay: TCheckBox;
- procedure FileListBox1DblClick(Sender: TObject);
- procedure SetJPEGOptions(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure ProgressUpdate(Sender: TObject; Stage: TProgressStage;
- PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
-var
- Form1: TForm1;
-
-implementation
-
-{$R *.DFM}
-
-procedure TForm1.FileListBox1DblClick(Sender: TObject);
-begin
- try
- Image1.Picture.LoadFromFile(FileListbox1.Filename);
- except
- on EInvalidGraphic do
- Image1.Picture.Graphic := nil;
- end;
- SetJPEGOptions(self);
-end;
-
-
-procedure TForm1.SetJPEGOptions(Sender: TObject);
-var
- Temp: Boolean;
-begin
- Temp := Image1.Picture.Graphic is TJPEGImage;
- if Temp then
- with TJPEGImage(Image1.Picture.Graphic) do
- begin
- PixelFormat := TJPEGPixelFormat(Self.PixelFormat.ItemIndex);
- Scale := TJPEGScale(Self.Scale.ItemIndex);
- Grayscale := Boolean(Colorspace.ItemIndex);
- Performance := TJPEGPerformance(Self.Performance.ItemIndex);
- ProgressiveDisplay := Self.ProgressiveDisplay.Checked;
- end;
- Scale.Enabled := Temp;
- PixelFormat.Enabled := Temp;
- Colorspace.Enabled := Temp;
- Performance.Enabled := Temp;
- ProgressiveDisplay.Enabled := Temp
- and TJPEGImage(Image1.Picture.Graphic).ProgressiveEncoding;
- Image1.IncrementalDisplay := IncrementalDisplay.Checked;
-end;
-
-procedure TForm1.FormCreate(Sender: TObject);
-begin
- Scale.ItemIndex := 0;
- PixelFormat.ItemIndex := 0;
- Colorspace.ItemIndex := 0;
- Performance.ItemIndex := 0;
- FileListbox1.Mask := '*.jpg;*.bmp;*.wmf;*.emf;*.ico';
- Image1.OnProgress := ProgressUpdate;
-end;
-
-procedure TForm1.ProgressUpdate(Sender: TObject; Stage: TProgressStage;
- PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
-begin
- if Stage = psRunning then
- Caption := Format('%d%%',[PercentDone])
- else
- Caption := 'Form1';
-end;
-
-
-end.
diff --git a/packages/base/pasjpeg/testproj.dpr b/packages/base/pasjpeg/testproj.dpr
deleted file mode 100644
index 237cfb608a..0000000000
--- a/packages/base/pasjpeg/testproj.dpr
+++ /dev/null
@@ -1,13 +0,0 @@
-program testproj;
-
-uses
- Forms,
- test1 in 'test1.pas' {Form1};
-
-{$R *.RES}
-
-begin
- Application.Initialize;
- Application.CreateForm(TForm1, Form1);
- Application.Run;
-end.
diff --git a/packages/base/pasjpeg/testproj.res b/packages/base/pasjpeg/testproj.res
deleted file mode 100644
index 4f53c2fe22..0000000000
--- a/packages/base/pasjpeg/testproj.res
+++ /dev/null
Binary files differ
diff --git a/packages/base/pasjpeg/transupp.pas b/packages/base/pasjpeg/transupp.pas
deleted file mode 100644
index 879de0d738..0000000000
--- a/packages/base/pasjpeg/transupp.pas
+++ /dev/null
@@ -1,1427 +0,0 @@
-Unit transupp;
-
-{* transupp.c
- * transupp.h
-
- Copyright (C) 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 image transformation routines and other utility code
- used by the jpegtran sample application. These are NOT part of the core
- JPEG library. But we keep these routines separate from jpegtran.c to
- ease the task of maintaining jpegtran-like programs that have other user
- interfaces.
-
- NOTE: all the routines declared here have very specific requirements
- about when they are to be executed during the reading and writing of the
- source and destination files. See the comments in transupp.c, or see
- jpegtran.c for an example of correct usage. }
-
-interface
-
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jinclude,
- jpeglib;
-
-
-{ Short forms of external names for systems with brain-damaged linkers. }
-
-{$ifdef NEED_SHORT_EXTERNAL_NAMES}
- jtransform_request_workspace jTrRequest
- jtransform_adjust_parameters jTrAdjust
- jtransform_execute_transformation jTrExec
- jcopy_markers_setup jCMrkSetup
- jcopy_markers_execute jCMrkExec
-{$endif} { NEED_SHORT_EXTERNAL_NAMES }
-
-
-{ Codes for supported types of image transformations. }
-
-type
- JXFORM_CODE = (
- JXFORM_NONE, { no transformation }
-{$ifdef CROP_SUPPORTED}
- JXFORM_CUT, { cut out part of the image }
-{$endif}
- JXFORM_FLIP_H, { horizontal flip }
- JXFORM_FLIP_V, { vertical flip }
- JXFORM_TRANSPOSE, { transpose across UL-to-LR axis }
- JXFORM_TRANSVERSE, { transpose across UR-to-LL axis }
- JXFORM_ROT_90, { 90-degree clockwise rotation }
- JXFORM_ROT_180, { 180-degree rotation }
- JXFORM_ROT_270 { 270-degree clockwise (or 90 ccw) }
- );
-
-{
- Although rotating and flipping data expressed as DCT coefficients is not
- hard, there is an asymmetry in the JPEG format specification for images
- whose dimensions aren't multiples of the iMCU size. The right and bottom
- image edges are padded out to the next iMCU boundary with junk data; but
- no padding is possible at the top and left edges. If we were to flip
- the whole image including the pad data, then pad garbage would become
- visible at the top and/or left, and real pixels would disappear into the
- pad margins --- perhaps permanently, since encoders & decoders may not
- bother to preserve DCT blocks that appear to be completely outside the
- nominal image area. So, we have to exclude any partial iMCUs from the
- basic transformation.
-
- Transpose is the only transformation that can handle partial iMCUs at the
- right and bottom edges completely cleanly. flip_h can flip partial iMCUs
- at the bottom, but leaves any partial iMCUs at the right edge untouched.
- Similarly flip_v leaves any partial iMCUs at the bottom edge untouched.
- The other transforms are defined as combinations of these basic transforms
- and process edge blocks in a way that preserves the equivalence.
-
- The "trim" option causes untransformable partial iMCUs to be dropped;
- this is not strictly lossless, but it usually gives the best-looking
- result for odd-size images. Note that when this option is active,
- the expected mathematical equivalences between the transforms may not hold.
- (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim
- followed by -rot 180 -trim trims both edges.)
-
- We also offer a "force to grayscale" option, which simply discards the
- chrominance channels of a YCbCr image. This is lossless in the sense that
- the luminance channel is preserved exactly. It's not the same kind of
- thing as the rotate/flip transformations, but it's convenient to handle it
- as part of this package, mainly because the transformation routines have to
- be aware of the option to know how many components to work on.
- }
-
-type
- jpeg_transform_info = record
- { Options: set by caller }
- transform : JXFORM_CODE; { image transform operator }
- trim : boolean; { if TRUE, trim partial MCUs as needed }
- force_grayscale : boolean; { if TRUE, convert color image to grayscale }
-{$ifdef CROP_SUPPORTED}
- xoffs, yoffs, newwidth, newheight : JDIMENSION;
-{$endif}
- { Internal workspace: caller should not touch these }
- num_components : int; { # of components in workspace }
- workspace_coef_arrays : jvirt_barray_tbl_ptr; { workspace for transformations }
- end;
-
-
-{$ifdef TRANSFORMS_SUPPORTED}
-
-{ Request any required workspace }
-procedure jtransform_request_workspace(srcinfo : j_decompress_ptr;
- var info : jpeg_transform_info);
-{ Adjust output image parameters }
-function jtransform_adjust_parameters(
- srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- src_coef_arrays : jvirt_barray_tbl_ptr;
- var info : jpeg_transform_info) : jvirt_barray_tbl_ptr;
-
-{ Execute the actual transformation, if any }
-procedure jtransform_execute_transformation(
- srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- src_coef_arrays : jvirt_barray_tbl_ptr;
- var info : jpeg_transform_info);
-
-{$endif} { TRANSFORMS_SUPPORTED }
-
-{ Support for copying optional markers from source to destination file. }
-
-type
- JCOPY_OPTION = (
- JCOPYOPT_NONE, { copy no optional markers }
- JCOPYOPT_COMMENTS, { copy only comment (COM) markers }
- JCOPYOPT_ALL { copy all optional markers }
- );
-
-const
- JCOPYOPT_DEFAULT = JCOPYOPT_COMMENTS; { recommended default }
-
-{ Setup decompression object to save desired markers in memory }
-procedure jcopy_markers_setup(srcinfo : j_decompress_ptr;
- option : JCOPY_OPTION);
-{ Copy markers saved in the given source object to the destination object }
-procedure jcopy_markers_execute(srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- option : JCOPY_OPTION);
-
-implementation
-
-{ Although this file really shouldn't have access to the library internals,
- it's helpful to let it call jround_up() and jcopy_block_row(). }
-uses
- jutils,
- jdeferr,
- jerror,
- {$ifdef SAVE_MARKERS_SUPPORTED}
- jdmarker,
- {$endif}
- jcapimin,
- jcparam; { set color space }
-
-{$ifdef TRANSFORMS_SUPPORTED}
-
-{ Lossless image transformation routines. These routines work on DCT
- coefficient arrays and thus do not require any lossy decompression
- or recompression of the image.
- Thanks to Guido Vollbeding for the initial design and code of this feature.
-
- Horizontal flipping is done in-place, using a single top-to-bottom
- pass through the virtual source array. It will thus be much the
- fastest option for images larger than main memory.
-
- The other routines require a set of destination virtual arrays, so they
- need twice as much memory as jpegtran normally does. The destination
- arrays are always written in normal scan order (top to bottom) because
- the virtual array manager expects this. The source arrays will be scanned
- in the corresponding order, which means multiple passes through the source
- arrays for most of the transforms. That could result in much thrashing
- if the image is larger than main memory.
-
- Some notes about the operating environment of the individual transform
- routines:
- 1. Both the source and destination virtual arrays are allocated from the
- source JPEG object, and therefore should be manipulated by calling the
- source's memory manager.
- 2. The destination's component count should be used. It may be smaller
- than the source's when forcing to grayscale.
- 3. Likewise the destination's sampling factors should be used. When
- forcing to grayscale the destination's sampling factors will be all 1,
- and we may as well take that as the effective iMCU size.
- 4. When "trim" is in effect, the destination's dimensions will be the
- trimmed values but the source's will be untrimmed.
- 5. All the routines assume that the source and destination buffers are
- padded out to a full iMCU boundary. This is true, although for the
- source buffer it is an undocumented property of jdcoefct.c.
- Notes 2,3,4 boil down to this: generally we should use the destination's
- dimensions and ignore the source's. }
-
-{LOCAL}
-procedure do_flip_h (srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- src_coef_arrays : jvirt_barray_tbl_ptr);
-{ Horizontal flip; done in-place, so no separate dest array is required }
-var
- MCU_cols, comp_width, blk_x, blk_y : JDIMENSION;
- ci, k, offset_y : int;
- buffer : JBLOCKARRAY;
- ptr1, ptr2 : JCOEF_PTR;
- temp1, temp2 : JCOEF;
- compptr : jpeg_component_info_ptr;
-begin
- { Horizontal mirroring of DCT blocks is accomplished by swapping
- pairs of blocks in-place. Within a DCT block, we perform horizontal
- mirroring by changing the signs of odd-numbered columns.
- Partial iMCUs at the right edge are left untouched. }
-
- MCU_cols := dstinfo^.image_width div (dstinfo^.max_h_samp_factor * DCTSIZE);
-
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- compptr := jpeg_component_info_ptr(dstinfo^.comp_info);
- Inc(compptr, ci);
- comp_width := MCU_cols * compptr^.h_samp_factor;
- blk_y := 0;
- while (blk_y < compptr^.height_in_blocks) do
- begin
- buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), src_coef_arrays^[ci], blk_y,
- JDIMENSION (compptr^.v_samp_factor), TRUE);
- for offset_y := 0 to compptr^.v_samp_factor-1 do
- begin
- blk_x := 0;
- while (blk_x * 2 < comp_width) do
- begin
- ptr1 := JCOEF_PTR(@(buffer^[offset_y]^[blk_x]));
- ptr2 := JCOEF_PTR(@(buffer^[offset_y]^[comp_width - blk_x - 1]));
- { this unrolled loop doesn't need to know which row it's on... }
- k := 0;
- while (k < DCTSIZE2) do
- begin
- temp1 := ptr1^; { swap even column }
- temp2 := ptr2^;
- ptr1^ := temp2;
- Inc(ptr1);
- ptr2^ := temp1;
- Inc(ptr2);
- temp1 := ptr1^; { swap odd column with sign change }
- temp2 := ptr2^;
- ptr1^ := -temp2;
- Inc(ptr1);
- ptr2^ := -temp1;
- Inc(ptr2);
- Inc(k, 2);
- end;
- Inc(blk_x);
- end;
- end;
- Inc(blk_y, compptr^.v_samp_factor);
- end; { while }
- end; { for ci }
-end; { do_flip_h }
-
-
-{LOCAL}
-procedure do_flip_v (srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- src_coef_arrays : jvirt_barray_tbl_ptr;
- dst_coef_arrays : jvirt_barray_tbl_ptr);
-{ Vertical flip }
-var
- MCU_rows, comp_height, dst_blk_x, dst_blk_y : JDIMENSION;
- ci, i, j, offset_y : int;
- src_buffer, dst_buffer : JBLOCKARRAY;
- src_row_ptr, dst_row_ptr : JBLOCKROW;
- src_ptr, dst_ptr : JCOEF_PTR;
- compptr : jpeg_component_info_ptr;
-begin
- { We output into a separate array because we can't touch different
- rows of the source virtual array simultaneously. Otherwise, this
- is a pretty straightforward analog of horizontal flip.
- Within a DCT block, vertical mirroring is done by changing the signs
- of odd-numbered rows.
- Partial iMCUs at the bottom edge are copied verbatim. }
-
- MCU_rows := dstinfo^.image_height div (dstinfo^.max_v_samp_factor * DCTSIZE);
-
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- compptr := jpeg_component_info_ptr(dstinfo^.comp_info);
- Inc(compptr, ci);
- comp_height := MCU_rows * compptr^.v_samp_factor;
- dst_blk_y := 0;
- while (dst_blk_y < compptr^.height_in_blocks) do
- begin
- dst_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), dst_coef_arrays^[ci], dst_blk_y,
- JDIMENSION(compptr^.v_samp_factor), TRUE);
- if (dst_blk_y < comp_height) then
- begin
- { Row is within the mirrorable area. }
- src_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), src_coef_arrays^[ci],
- comp_height - dst_blk_y - JDIMENSION(compptr^.v_samp_factor),
- JDIMENSION (compptr^.v_samp_factor), FALSE);
- end
- else
- begin
- { Bottom-edge blocks will be copied verbatim. }
- src_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), src_coef_arrays^[ci], dst_blk_y,
- JDIMENSION (compptr^.v_samp_factor), FALSE);
- end;
- for offset_y := 0 to compptr^.v_samp_factor-1 do
- begin
- if (dst_blk_y < comp_height) then
- begin
- { Row is within the mirrorable area. }
- dst_row_ptr := dst_buffer^[offset_y];
- src_row_ptr := src_buffer^[compptr^.v_samp_factor - offset_y - 1];
- for dst_blk_x := 0 to compptr^.width_in_blocks-1 do
- begin
- dst_ptr := JCOEF_PTR(@(dst_row_ptr^[dst_blk_x]));
- src_ptr := JCOEF_PTR(@(src_row_ptr^[dst_blk_x]));
- i := 0;
- while (i < DCTSIZE) do
- begin
- { copy even row }
- for j := 0 to DCTSIZE-1 do
- begin
- dst_ptr^ := src_ptr^;
- Inc(dst_ptr);
- Inc(src_ptr);
- end;
- { copy odd row with sign change }
- for j := 0 to DCTSIZE-1 do
- begin
- dst_ptr^ := - (src_ptr^);
- Inc(dst_ptr);
- Inc(src_ptr);
- end;
- Inc(i, 2);
- end;
- end;
- end
- else
- begin
- { Just copy row verbatim. }
- jcopy_block_row(src_buffer^[offset_y], dst_buffer^[offset_y],
- compptr^.width_in_blocks);
- end;
- end;
- Inc(dst_blk_y, compptr^.v_samp_factor);
- end; { while }
- end; { for ci }
-end; { do_flip_v }
-
-{$ifdef CROP_SUPPORTED}
-{LOCAL}
-procedure do_transform (srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- src_coef_arrays : jvirt_barray_tbl_ptr;
- dst_coef_arrays : jvirt_barray_tbl_ptr;
- xoffs : JDIMENSION;
- yoffs : JDIMENSION);
-{ transform src_coef_arrays so that the xoffs,yoffs (rounded to an even
- dct block) are the new origin of the image. copy rather than move because
- I'd never finish if I tried to understand the byzantine memory management.
-}
-var
- ci : int;
- compptr : jpeg_component_info_ptr;
- src_buffer, dst_buffer : JBLOCKARRAY;
- dst_blk_x, dst_blk_y : JDIMENSION;
-begin
- xoffs := xoffs div dstinfo^.max_h_samp_factor * DCTSIZE;
- yoffs := yoffs div dstinfo^.max_v_samp_factor * DCTSIZE;
-
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- compptr := jpeg_component_info_ptr(dstinfo^.comp_info);
- Inc(compptr, ci);
- dst_blk_y := 0;
- while (dst_blk_y < compptr^.height_in_blocks) do
- begin
- dst_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), dst_coef_arrays^[ci], dst_blk_y, 1, TRUE);
- src_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), src_coef_arrays^[ci],
- dst_blk_y + yoffs * JDIMENSION(compptr^.v_samp_factor), 1, FALSE);
- jcopy_block_row(JBLOCKROW(@src_buffer^[0]^[xoffs * compptr^.h_samp_factor]),
- dst_buffer^[0], compptr^.width_in_blocks);
- Inc(dst_blk_y);
- end;
- end;
-end; { do_transform }
-{$endif}
-
-{LOCAL}
-procedure do_transpose (srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- src_coef_arrays : jvirt_barray_tbl_ptr;
- dst_coef_arrays : jvirt_barray_tbl_ptr);
-{ Transpose source into destination }
-var
- dst_blk_x, dst_blk_y : JDIMENSION;
- ci, i, j, offset_x, offset_y : int;
- src_buffer, dst_buffer : JBLOCKARRAY;
- src_ptr, dst_ptr : JCOEFPTR;
- compptr : jpeg_component_info_ptr;
-begin
-
- { Transposing pixels within a block just requires transposing the
- DCT coefficients.
- Partial iMCUs at the edges require no special treatment; we simply
- process all the available DCT blocks for every component. }
-
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- compptr := jpeg_component_info_ptr(dstinfo^.comp_info);
- Inc(compptr, ci);
- dst_blk_y := 0;
- while (dst_blk_y < compptr^.height_in_blocks) do
- begin
- dst_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), dst_coef_arrays^[ci], dst_blk_y,
- JDIMENSION (compptr^.v_samp_factor), TRUE);
- for offset_y := 0 to compptr^.v_samp_factor-1 do
- begin
- dst_blk_x := 0;
- while (dst_blk_x < compptr^.width_in_blocks) do
- begin
- src_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), src_coef_arrays^[ci], dst_blk_x,
- JDIMENSION (compptr^.h_samp_factor), FALSE);
- for offset_x := 0 to compptr^.h_samp_factor-1 do
- begin
- src_ptr := JCOEFPTR(@(src_buffer^[offset_x]^
- [dst_blk_y + offset_y]));
- dst_ptr := JCOEFPTR(@(dst_buffer^[offset_y]^
- [dst_blk_x + offset_x]));
- for i := 0 to DCTSIZE-1 do
- for j := 0 to DCTSIZE-1 do
- dst_ptr^[j*DCTSIZE+i] := src_ptr^[i*DCTSIZE+j];
- end;
- Inc(dst_blk_x, compptr^.h_samp_factor);
- end;
- end;
- Inc(dst_blk_y, compptr^.v_samp_factor);
- end; { while }
- end; { for ci }
-end; { do_transpose }
-
-
-{LOCAL}
-procedure do_rot_90 (srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- src_coef_arrays : jvirt_barray_tbl_ptr;
- dst_coef_arrays : jvirt_barray_tbl_ptr);
-{ 90 degree rotation is equivalent to
- 1. Transposing the image;
- 2. Horizontal mirroring.
- These two steps are merged into a single processing routine. }
-var
- MCU_cols, comp_width, dst_blk_x, dst_blk_y : JDIMENSION;
- ci, i, j, offset_x, offset_y : int;
- src_buffer, dst_buffer : JBLOCKARRAY;
- src_ptr, dst_ptr : JCOEFPTR;
- compptr : jpeg_component_info_ptr;
-begin
- { Because of the horizontal mirror step, we can't process partial iMCUs
- at the (output) right edge properly. They just get transposed and
- not mirrored. }
-
- MCU_cols := dstinfo^.image_width div (dstinfo^.max_h_samp_factor * DCTSIZE);
-
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- compptr := jpeg_component_info_ptr(dstinfo^.comp_info);
- Inc(compptr, ci);
- comp_width := MCU_cols * compptr^.h_samp_factor;
- dst_blk_y := 0;
- while ( dst_blk_y < compptr^.height_in_blocks) do
- begin
- dst_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), dst_coef_arrays^[ci], dst_blk_y,
- JDIMENSION (compptr^.v_samp_factor), TRUE);
- for offset_y := 0 to compptr^.v_samp_factor-1 do
- begin
- dst_blk_x := 0;
- while (dst_blk_x < compptr^.width_in_blocks) do
- begin
- src_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), src_coef_arrays^[ci], dst_blk_x,
- JDIMENSION (compptr^.h_samp_factor), FALSE);
- for offset_x := 0 to compptr^.h_samp_factor-1 do
- begin
- src_ptr := JCOEFPTR(@(src_buffer^[offset_x]^
- [dst_blk_y + offset_y]));
- if (dst_blk_x < comp_width) then
- begin
- { Block is within the mirrorable area. }
- dst_ptr := JCOEFPTR(@(dst_buffer^[offset_y]^
- [comp_width - dst_blk_x - offset_x - 1]));
- i := 0;
- while (i < DCTSIZE) do
- begin
- for j := 0 to DCTSIZE-1 do
- dst_ptr^[j*DCTSIZE+i] := src_ptr^[i*DCTSIZE+j];
- Inc(i);
- for j := 0 to DCTSIZE-1 do
- dst_ptr^[j*DCTSIZE+i] := -src_ptr^[i*DCTSIZE+j];
- Inc(i);
- end;
- end
- else
- begin
- { Edge blocks are transposed but not mirrored. }
- dst_ptr := JCOEFPTR(@(dst_buffer^[offset_y]^
- [dst_blk_x + offset_x]));
- for i := 0 to DCTSIZE-1 do
- for j := 0 to DCTSIZE-1 do
- dst_ptr^[j*DCTSIZE+i] := src_ptr^[i*DCTSIZE+j];
- end;
- end;
- Inc(dst_blk_x, compptr^.h_samp_factor);
- end;
- end;
- Inc(dst_blk_y, compptr^.v_samp_factor);
- end; { while }
- end; { for ci }
-end; { do_rot_90 }
-
-
-{LOCAL}
-procedure do_rot_270 (srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- src_coef_arrays : jvirt_barray_tbl_ptr;
- dst_coef_arrays : jvirt_barray_tbl_ptr);
-{ 270 degree rotation is equivalent to
- 1. Horizontal mirroring;
- 2. Transposing the image.
- These two steps are merged into a single processing routine. }
-var
- MCU_rows, comp_height, dst_blk_x, dst_blk_y : JDIMENSION;
- ci, i, j, offset_x, offset_y : int;
- src_buffer, dst_buffer : JBLOCKARRAY;
- src_ptr, dst_ptr : JCOEFPTR;
- compptr : jpeg_component_info_ptr;
-begin
- { Because of the horizontal mirror step, we can't process partial iMCUs
- at the (output) bottom edge properly. They just get transposed and
- not mirrored. }
-
- MCU_rows := dstinfo^.image_height div (dstinfo^.max_v_samp_factor * DCTSIZE);
-
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- compptr := jpeg_component_info_ptr(dstinfo^.comp_info);
- Inc(compptr, ci);
- comp_height := MCU_rows * compptr^.v_samp_factor;
- dst_blk_y := 0;
- while (dst_blk_y < compptr^.height_in_blocks) do
- begin
- dst_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), dst_coef_arrays^[ci], dst_blk_y,
- JDIMENSION (compptr^.v_samp_factor), TRUE);
- for offset_y := 0 to compptr^.v_samp_factor-1 do
- begin
- dst_blk_x := 0;
- while (dst_blk_x < compptr^.width_in_blocks) do
- begin
- src_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), src_coef_arrays^[ci], dst_blk_x,
- JDIMENSION (compptr^.h_samp_factor), FALSE);
- for offset_x := 0 to compptr^.h_samp_factor-1 do
- begin
- dst_ptr := JCOEFPTR(@(dst_buffer^[offset_y]^
- [dst_blk_x + offset_x]));
- if (dst_blk_y < comp_height) then
- begin
- { Block is within the mirrorable area. }
- src_ptr := JCOEFPTR(@(src_buffer^[offset_x]^
- [comp_height - dst_blk_y - offset_y - 1]));
- for i := 0 to DCTSIZE-1 do
- begin
- j := 0;
- while (j < DCTSIZE) do
- begin
- dst_ptr^[j*DCTSIZE+i] := src_ptr^[i*DCTSIZE+j];
- Inc(j);
- dst_ptr^[j*DCTSIZE+i] := -src_ptr^[i*DCTSIZE+j];
- Inc(j);
- end;
- end;
- end
- else
- begin
- { Edge blocks are transposed but not mirrored. }
- src_ptr := JCOEFPTR(@(src_buffer^[offset_x]^
- [dst_blk_y + offset_y]));
- for i := 0 to DCTSIZE-1 do
- for j := 0 to DCTSIZE-1 do
- dst_ptr^[j*DCTSIZE+i] := src_ptr^[i*DCTSIZE+j];
- end;
- end;
- Inc(dst_blk_x, compptr^.h_samp_factor);
- end;
- end;
- Inc(dst_blk_y, compptr^.v_samp_factor);
- end; { while }
- end; { for ci }
-end; { do_rot_270 }
-
-
-{LOCAL}
-procedure do_rot_180 (srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- src_coef_arrays : jvirt_barray_tbl_ptr;
- dst_coef_arrays : jvirt_barray_tbl_ptr);
-{ 180 degree rotation is equivalent to
- 1. Vertical mirroring;
- 2. Horizontal mirroring.
- These two steps are merged into a single processing routine. }
-var
- MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y : JDIMENSION;
- ci, i, j, offset_y : int;
- src_buffer, dst_buffer : JBLOCKARRAY;
- src_row_ptr, dst_row_ptr : JBLOCKROW;
- src_ptr, dst_ptr : JCOEF_PTR;
- compptr : jpeg_component_info_ptr;
-begin
- MCU_cols := dstinfo^.image_width div (dstinfo^.max_h_samp_factor * DCTSIZE);
- MCU_rows := dstinfo^.image_height div (dstinfo^.max_v_samp_factor * DCTSIZE);
-
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- compptr := jpeg_component_info_ptr(dstinfo^.comp_info);
- Inc(compptr, ci);
- comp_width := MCU_cols * compptr^.h_samp_factor;
- comp_height := MCU_rows * compptr^.v_samp_factor;
- dst_blk_y := 0;
- while (dst_blk_y < compptr^.height_in_blocks) do
- begin
- dst_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), dst_coef_arrays^[ci], dst_blk_y,
- JDIMENSION (compptr^.v_samp_factor), TRUE);
- if (dst_blk_y < comp_height) then
- begin
- { Row is within the vertically mirrorable area. }
- src_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), src_coef_arrays^[ci],
- comp_height - dst_blk_y - JDIMENSION (compptr^.v_samp_factor),
- JDIMENSION (compptr^.v_samp_factor), FALSE);
- end
- else
- begin
- { Bottom-edge rows are only mirrored horizontally. }
- src_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), src_coef_arrays^[ci], dst_blk_y,
- JDIMENSION (compptr^.v_samp_factor), FALSE);
- end;
- for offset_y := 0 to compptr^.v_samp_factor-1 do
- begin
- if (dst_blk_y < comp_height) then
- begin
- { Row is within the mirrorable area. }
- dst_row_ptr := dst_buffer^[offset_y];
- src_row_ptr := src_buffer^[compptr^.v_samp_factor - offset_y - 1];
- { Process the blocks that can be mirrored both ways. }
- for dst_blk_x := 0 to comp_width-1 do
- begin
- dst_ptr := JCOEF_PTR(@(dst_row_ptr^[dst_blk_x]));
- src_ptr := JCOEF_PTR(@(src_row_ptr^[comp_width - dst_blk_x - 1]));
- i := 0;
- while (i < DCTSIZE) do
- begin
- { For even row, negate every odd column. }
- j := 0;
- while (j < DCTSIZE) do
- begin
- dst_ptr^ := src_ptr^;
- Inc(dst_ptr);
- Inc(src_ptr);
- dst_ptr^ := - src_ptr^;
- Inc(dst_ptr);
- Inc(src_ptr);
- Inc(j, 2);
- end;
- { For odd row, negate every even column. }
- j := 0;
- while (j < DCTSIZE) do
- begin
- dst_ptr^ := - src_ptr^;
- Inc(dst_ptr);
- Inc(src_ptr);
- dst_ptr^ := src_ptr^;
- Inc(dst_ptr);
- Inc(src_ptr);
- Inc(j, 2);
- end;
- Inc(i, 2);
- end; { while i }
- end;
- { Any remaining right-edge blocks are only mirrored vertically. }
- for dst_blk_x := comp_width to compptr^.width_in_blocks-1 do
- begin
- dst_ptr := JCOEF_PTR(@(dst_row_ptr^[dst_blk_x]));
- src_ptr := JCOEF_PTR(@(src_row_ptr^[dst_blk_x]));
- i := 0;
- while (i < DCTSIZE) do
- begin
- for j := 0 to DCTSIZE-1 do
- begin
- dst_ptr^ := src_ptr^;
- Inc(dst_ptr);
- Inc(src_ptr);
- end;
- for j := 0 to DCTSIZE-1 do
- begin
- dst_ptr^ := - src_ptr^;
- Inc(dst_ptr);
- Inc(src_ptr);
- end;
- Inc(i, 2);
- end
- end
- end
- else
- begin
- { Remaining rows are just mirrored horizontally. }
- dst_row_ptr := dst_buffer^[offset_y];
- src_row_ptr := src_buffer^[offset_y];
- { Process the blocks that can be mirrored. }
- for dst_blk_x := 0 to comp_width-1 do
- begin
- dst_ptr := JCOEF_PTR(@(dst_row_ptr^[dst_blk_x]));
- src_ptr := JCOEF_PTR(@(src_row_ptr^[comp_width - dst_blk_x - 1]));
- i := 0;
- while (i < DCTSIZE2) do
- begin
- dst_ptr^ := src_ptr^;
- Inc(dst_ptr);
- Inc(src_ptr);
- dst_ptr^ := - src_ptr^;
- Inc(dst_ptr);
- Inc(src_ptr);
- Inc(i, 2);
- end;
- end;
- { Any remaining right-edge blocks are only copied. }
- for dst_blk_x := comp_width to compptr^.width_in_blocks-1 do
- begin
- dst_ptr := JCOEF_PTR(@(dst_row_ptr^[dst_blk_x]));
- src_ptr := JCOEF_PTR(@(src_row_ptr^[dst_blk_x]));
- for i := 0 to DCTSIZE2-1 do
- begin
- dst_ptr^ := src_ptr^;
- Inc(dst_ptr);
- Inc(src_ptr);
- end;
- end;
- end;
- end;
- Inc(dst_blk_y, compptr^.v_samp_factor) ;
- end; { while }
- end; { for ci }
-end; { do_rot_180 }
-
-
-{LOCAL}
-procedure do_transverse (srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- src_coef_arrays : jvirt_barray_tbl_ptr;
- dst_coef_arrays : jvirt_barray_tbl_ptr);
-{ Transverse transpose is equivalent to
- 1. 180 degree rotation;
- 2. Transposition;
- or
- 1. Horizontal mirroring;
- 2. Transposition;
- 3. Horizontal mirroring.
- These steps are merged into a single processing routine. }
-var
- MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y : JDIMENSION;
- ci, i, j, offset_x, offset_y : int;
- src_buffer, dst_buffer : JBLOCKARRAY;
- src_ptr, dst_ptr : JCOEFPTR;
- compptr : jpeg_component_info_ptr;
-begin
- MCU_cols := dstinfo^.image_width div (dstinfo^.max_h_samp_factor * DCTSIZE);
- MCU_rows := dstinfo^.image_height div (dstinfo^.max_v_samp_factor * DCTSIZE);
-
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- compptr := jpeg_component_info_ptr(dstinfo^.comp_info);
- Inc(compptr, ci);
- comp_width := MCU_cols * compptr^.h_samp_factor;
- comp_height := MCU_rows * compptr^.v_samp_factor;
- dst_blk_y := 0;
- while (dst_blk_y < compptr^.height_in_blocks) do
- begin
- dst_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), dst_coef_arrays^[ci], dst_blk_y,
- JDIMENSION (compptr^.v_samp_factor), TRUE);
- for offset_y := 0 to compptr^.v_samp_factor-1 do
- begin
- dst_blk_x := 0;
- while ( dst_blk_x < compptr^.width_in_blocks) do
- begin
- src_buffer := srcinfo^.mem^.access_virt_barray
- (j_common_ptr(srcinfo), src_coef_arrays^[ci], dst_blk_x,
- JDIMENSION (compptr^.h_samp_factor), FALSE);
- for offset_x := 0 to compptr^.h_samp_factor-1 do
- begin
- if (dst_blk_y < comp_height) then
- begin
- src_ptr := JCOEFPTR(@(src_buffer^[offset_x]^
- [comp_height - dst_blk_y - offset_y - 1]));
- if (dst_blk_x < comp_width) then
- begin
- { Block is within the mirrorable area. }
- dst_ptr := JCOEFPTR(@(dst_buffer^[offset_y]^
- [comp_width - dst_blk_x - offset_x - 1]));
- i := 0;
- while (i < DCTSIZE) do
- begin
- j := 0;
- while (j < DCTSIZE) do
- begin
- dst_ptr^[j*DCTSIZE+i] := src_ptr^[i*DCTSIZE+j];
- Inc(j);
- dst_ptr^[j*DCTSIZE+i] := -src_ptr^[i*DCTSIZE+j];
- Inc(j);
- end;
- Inc(i);
- j := 0;
- while (j < DCTSIZE) do
- begin
- dst_ptr^[j*DCTSIZE+i] := -src_ptr^[i*DCTSIZE+j];
- Inc(j);
- dst_ptr^[j*DCTSIZE+i] := src_ptr^[i*DCTSIZE+j];
- Inc(j);
- end;
- Inc(i);
- end
- end
- else
- begin
- { Right-edge blocks are mirrored in y only }
- dst_ptr := JCOEFPTR(@(dst_buffer^[offset_y]^
- [dst_blk_x + offset_x]));
- for i := 0 to DCTSIZE-1 do
- begin
- j := 0;
- while (j < DCTSIZE) do
- begin
- dst_ptr^[j*DCTSIZE+i] := src_ptr^[i*DCTSIZE+j];
- Inc(j);
- dst_ptr^[j*DCTSIZE+i] := -src_ptr^[i*DCTSIZE+j];
- Inc(j);
- end;
- end;
- end;
- end
- else
- begin
- src_ptr := JCOEFPTR(@(src_buffer^[offset_x]^
- [dst_blk_y + offset_y]));
- if (dst_blk_x < comp_width) then
- begin
- { Bottom-edge blocks are mirrored in x only }
- dst_ptr := JCOEFPTR(@(dst_buffer^[offset_y]^
- [comp_width - dst_blk_x - offset_x - 1]));
- i := 0;
- while (i < DCTSIZE) do
- begin
- for j := 0 to DCTSIZE-1 do
- dst_ptr^[j*DCTSIZE+i] := src_ptr^[i*DCTSIZE+j];
- Inc(i);
- for j := 0 to DCTSIZE-1 do
- dst_ptr^[j*DCTSIZE+i] := -src_ptr^[i*DCTSIZE+j];
- Inc(i);
- end;
- end
- else
- begin
- { At lower right corner, just transpose, no mirroring }
- dst_ptr := JCOEFPTR(@(dst_buffer^[offset_y]^
- [dst_blk_x + offset_x]));
- for i := 0 to DCTSIZE-1 do
- for j := 0 to DCTSIZE-1 do
- dst_ptr^[j*DCTSIZE+i] := src_ptr^[i*DCTSIZE+j];
- end;
- end;
- end;
- Inc(dst_blk_x, compptr^.h_samp_factor);
- end;
- end;
- Inc(dst_blk_y, compptr^.v_samp_factor);
- end; { while }
- end; { for ci }
-end; { do_transverse }
-
-
-{ Request any required workspace.
-
- We allocate the workspace virtual arrays from the source decompression
- object, so that all the arrays (both the original data and the workspace)
- will be taken into account while making memory management decisions.
- Hence, this routine must be called after jpeg_read_header (which reads
- the image dimensions) and before jpeg_read_coefficients (which realizes
- the source's virtual arrays). }
-
-{GLOBAL}
-procedure jtransform_request_workspace (
- srcinfo : j_decompress_ptr;
- var info : jpeg_transform_info);
-var
- coef_arrays : jvirt_barray_tbl_ptr;
- compptr : jpeg_component_info_ptr;
- ci : int;
-begin
- coef_arrays := NIL;
- if (info.force_grayscale) and (srcinfo^.jpeg_color_space = JCS_YCbCr)
- and (srcinfo^.num_components = 3) then
- begin
- { We'll only process the first component }
- info.num_components := 1;
- end
- else
- begin
- { Process all the components }
- info.num_components := srcinfo^.num_components;
- end;
-
- case (info.transform) of
- JXFORM_NONE,
- JXFORM_FLIP_H:;
- { Don't need a workspace array }
-{$ifdef CROP_SUPPORTED}
- JXFORM_CUT,
- { really cut needs smaller arrays if you want to figure it out }
-{$endif}
- JXFORM_FLIP_V,
- JXFORM_ROT_180:
- begin
- { 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_tbl_ptr (
- srcinfo^.mem^.alloc_small (j_common_ptr(srcinfo), JPOOL_IMAGE,
- SIZEOF(jvirt_barray_ptr) * info.num_components) );
- for ci := 0 to info.num_components-1 do
- begin
- compptr := jpeg_component_info_ptr(srcinfo^.comp_info);
- Inc(compptr, 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));
- end;
- end;
- JXFORM_TRANSPOSE,
- JXFORM_TRANSVERSE,
- JXFORM_ROT_90,
- JXFORM_ROT_270:
- begin
- { 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_tbl_ptr(
- srcinfo^.mem^.alloc_small (j_common_ptr(srcinfo), JPOOL_IMAGE,
- SIZEOF(jvirt_barray_ptr) * info.num_components) );
- for ci := 0 to info.num_components-1 do
- begin
- compptr := jpeg_component_info_ptr(srcinfo^.comp_info);
- Inc(compptr, 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 ) );
- end;
- end;
- end;
- info.workspace_coef_arrays := coef_arrays;
-end;
-
-
-{ Transpose destination image parameters }
-
-{LOCAL}
-procedure transpose_critical_parameters (dstinfo : j_compress_ptr);
-var
- tblno, i, j, ci, itemp : int;
- compptr : jpeg_component_info_ptr;
- qtblptr : JQUANT_TBL_PTR;
- dtemp : JDIMENSION;
- qtemp : UINT16;
-begin
- { Transpose basic image dimensions }
- dtemp := dstinfo^.image_width;
- dstinfo^.image_width := dstinfo^.image_height;
- dstinfo^.image_height := dtemp;
-
- { Transpose sampling factors }
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- compptr := jpeg_component_info_ptr(dstinfo^.comp_info);
- Inc(compptr, ci);
- itemp := compptr^.h_samp_factor;
- compptr^.h_samp_factor := compptr^.v_samp_factor;
- compptr^.v_samp_factor := itemp;
- end;
-
- { Transpose quantization tables }
- for tblno := 0 to NUM_QUANT_TBLS-1 do
- begin
- qtblptr := dstinfo^.quant_tbl_ptrs[tblno];
- if (qtblptr <> NIL) then
- begin
- for i := 0 to DCTSIZE-1 do
- begin
- for j := 0 to i-1 do
- begin
- qtemp := qtblptr^.quantval[i*DCTSIZE+j];
- qtblptr^.quantval[i*DCTSIZE+j] := qtblptr^.quantval[j*DCTSIZE+i];
- qtblptr^.quantval[j*DCTSIZE+i] := qtemp;
- end;
- end;
- end;
- end;
-end;
-
-
-{ Trim off any partial iMCUs on the indicated destination edge }
-
-{LOCAL}
-procedure trim_right_edge (dstinfo : j_compress_ptr);
-var
- ci, max_h_samp_factor : int;
- MCU_cols : JDIMENSION;
-var
- h_samp_factor : int;
-begin
- { We have to compute max_h_samp_factor ourselves,
- because it hasn't been set yet in the destination
- (and we don't want to use the source's value). }
-
- max_h_samp_factor := 1;
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- h_samp_factor := dstinfo^.comp_info^[ci].h_samp_factor;
-
- {max_h_samp_factor := MAX(max_h_samp_factor, h_samp_factor);}
- if h_samp_factor > max_h_samp_factor then
- max_h_samp_factor := h_samp_factor;
- end;
- MCU_cols := dstinfo^.image_width div (max_h_samp_factor * DCTSIZE);
- if (MCU_cols > 0) then { can't trim to 0 pixels }
- dstinfo^.image_width := MCU_cols * (max_h_samp_factor * DCTSIZE);
-end;
-
-{LOCAL}
-procedure trim_bottom_edge (dstinfo : j_compress_ptr);
-var
- ci, max_v_samp_factor : int;
- MCU_rows : JDIMENSION;
-var
- v_samp_factor : int;
-begin
- { We have to compute max_v_samp_factor ourselves,
- because it hasn't been set yet in the destination
- (and we don't want to use the source's value). }
-
- max_v_samp_factor := 1;
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- v_samp_factor := dstinfo^.comp_info^[ci].v_samp_factor;
-
- {max_v_samp_factor := MAX(max_v_samp_factor, v_samp_factor);}
- if v_samp_factor > max_v_samp_factor then
- max_v_samp_factor := v_samp_factor;
- end;
- MCU_rows := dstinfo^.image_height div (max_v_samp_factor * DCTSIZE);
- if (MCU_rows > 0) then { can't trim to 0 pixels }
- dstinfo^.image_height := MCU_rows * (max_v_samp_factor * DCTSIZE);
-end;
-
-{$ifdef CROP_SUPPORTED}
-{ For cropping, realize and constrain the target area, and reshape the
- dstinfo to hold the resulting image.
-
- Input was supplied as WxH[+-]X[+-]Y offsets. Negative offsets are
- relative to the lower righthand corner of the image. The region is
- expanded so that all boundaries fall on even MCU blocks by rounding
- the offsets *down* (at the do_transform() step) and the size *up*. }
-
-{LOCAL}
-procedure set_dest_size(dstinfo : j_compress_ptr;
- var info : jpeg_transform_info);
-var
- ci, max_samp_factor : int;
- MCU_size, newsize, offset, factor : JDIMENSION;
-var
- samp_factor : int;
-begin
- { Initially the dstinfo is the same size as the srcinfo.
- Use it to constrain the offsets: }
- if (info.xoffs < 0) then
- Inc(info.xoffs, dstinfo^.image_width);
- if (info.yoffs < 0) then
- Inc(info.yoffs, dstinfo^.image_height);
- if (info.xoffs < 0) or (info.xoffs >= dstinfo^.image_width) or
- (info.yoffs < 0) or (info.yoffs >= dstinfo^.image_height) then
- begin
- {jpegtran_error('-cut offsets fall outside source image');}
- ERREXIT(j_common_ptr(dstinfo), JERR_CONVERSION_NOTIMPL);
- end;
-
- { use it to constrain the size: }
- if (info.newwidth + info.xoffs > dstinfo^.image_width) then
- info.newwidth := dstinfo^.image_width - info.xoffs;
- if (info.newheight + info.yoffs > dstinfo^.image_height) then
- info.newheight := dstinfo^.image_height - info.yoffs;
-
- { We have to compute max_v/h_samp_factors ourselves,
- because it hasn't been set yet in the destination
- (and we don't want to use the source's value). }
- max_samp_factor := 1;
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- samp_factor := dstinfo^.comp_info^[ci].v_samp_factor;
- {max_samp_factor := MAX(max_samp_factor, samp_factor);}
- if (max_samp_factor < samp_factor) then
- max_samp_factor := samp_factor;
- end;
- { Find original (rounded down) and new (rounded up) heights in full
- dct blocks, choose the smaller of the two. }
-
- factor := max_samp_factor * DCTSIZE;
- MCU_size := dstinfo^.image_height div factor;
- newsize := (info.newheight + (info.yoffs mod factor) + factor - 1) div factor;
- {MCU_size := MIN(MCU_size, newsize);}
- if (MCU_size > newsize) then
- MCU_size := newsize;
- if (MCU_size > 0) then { can't trim to 0 pixels }
- dstinfo^.image_height := MCU_size * factor
- else
- begin
- {jpegtran_error('degenerate -cut height');}
- ERREXIT(j_common_ptr(dstinfo), JERR_CONVERSION_NOTIMPL);
- end;
-
- max_samp_factor := 1;
- for ci := 0 to dstinfo^.num_components-1 do
- begin
- samp_factor := dstinfo^.comp_info^[ci].h_samp_factor;
- {max_samp_factor := MAX(max_samp_factor, samp_factor);}
- if (max_samp_factor < samp_factor) then
- max_samp_factor := samp_factor;
- end;
- { Find original (rounded down) and new (rounded up) heights in full
- dct blocks, choose the smaller of the two. }
-
- factor := max_samp_factor * DCTSIZE;
- MCU_size := dstinfo^.image_width div factor;
- newsize := (info.newwidth + (info.xoffs mod factor) + factor - 1) div factor;
- {MCU_size := MIN(MCU_size, newsize);}
- if (MCU_size > newsize) then
- MCU_size := newsize;
- if (MCU_size > 0) then { can't trim to 0 pixels }
- dstinfo^.image_width := MCU_size * factor
- else
- begin
- {jpegtran_error('degenerate -cut width');}
- ERREXIT(j_common_ptr(dstinfo), JERR_CONVERSION_NOTIMPL);
- end;
-end;
-{$endif}
-
-{ Adjust output image parameters as needed.
-
- This must be called after jpeg_copy_critical_parameters()
- and before jpeg_write_coefficients().
-
- The return value is the set of virtual coefficient arrays to be written
- (either the ones allocated by jtransform_request_workspace, or the
- original source data arrays). The caller will need to pass this value
- to jpeg_write_coefficients(). }
-
-{GLOBAL}
-function jtransform_adjust_parameters
- (srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- src_coef_arrays : jvirt_barray_tbl_ptr;
- var info : jpeg_transform_info) : jvirt_barray_tbl_ptr;
-var
- sv_quant_tbl_no : int;
-begin
- { If force-to-grayscale is requested, adjust destination parameters }
- if (info.force_grayscale) then
- begin
- { We use jpeg_set_colorspace to make sure subsidiary settings get fixed
- properly. Among other things, the target h_samp_factor & v_samp_factor
- will get set to 1, which typically won't match the source.
- In fact we do this even if the source is already grayscale; that
- provides an easy way of coercing a grayscale JPEG with funny sampling
- factors to the customary 1,1. (Some decoders fail on other factors.) }
-
- if ((dstinfo^.jpeg_color_space = JCS_YCbCr) and
- (dstinfo^.num_components = 3)) or
- ((dstinfo^.jpeg_color_space = JCS_GRAYSCALE) and
- (dstinfo^.num_components = 1)) then
- begin
- { We have to preserve the source's quantization table number. }
- sv_quant_tbl_no := dstinfo^.comp_info^[0].quant_tbl_no;
- jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
- dstinfo^.comp_info^[0].quant_tbl_no := sv_quant_tbl_no;
- end
- else
- begin
- { Sorry, can't do it }
- ERREXIT(j_common_ptr(dstinfo), JERR_CONVERSION_NOTIMPL);
- end;
- end;
-
- { Correct the destination's image dimensions etc if necessary }
- case (info.transform) of
- JXFORM_NONE:;
- { Nothing to do }
-{$ifdef CROP_SUPPORTED}
- JXFORM_CUT:
- set_dest_size(dstinfo, info);
-{$endif}
- JXFORM_FLIP_H:
- if (info.trim) then
- trim_right_edge(dstinfo);
- JXFORM_FLIP_V:
- if (info.trim) then
- trim_bottom_edge(dstinfo);
- JXFORM_TRANSPOSE:
- transpose_critical_parameters(dstinfo);
- { transpose does NOT have to trim anything }
- JXFORM_TRANSVERSE:
- begin
- transpose_critical_parameters(dstinfo);
- if (info.trim) then
- begin
- trim_right_edge(dstinfo);
- trim_bottom_edge(dstinfo);
- end;
- end;
- JXFORM_ROT_90:
- begin
- transpose_critical_parameters(dstinfo);
- if (info.trim) then
- trim_right_edge(dstinfo);
- end;
- JXFORM_ROT_180:
- if (info.trim) then
- begin
- trim_right_edge(dstinfo);
- trim_bottom_edge(dstinfo);
- end;
- JXFORM_ROT_270:
- begin
- transpose_critical_parameters(dstinfo);
- if (info.trim) then
- trim_bottom_edge(dstinfo);
- end;
- end;
-
- { Return the appropriate output data set }
- if (info.workspace_coef_arrays <> NIL) then
- jtransform_adjust_parameters := info.workspace_coef_arrays
- else
- jtransform_adjust_parameters := src_coef_arrays;
-end;
-
-
-{ Execute the actual transformation, if any.
-
- This must be called *after* jpeg_write_coefficients, because it depends
- on jpeg_write_coefficients to have computed subsidiary values such as
- the per-component width and height fields in the destination object.
-
- Note that some transformations will modify the source data arrays! }
-
-
-{GLOBAL}
-procedure jtransform_execute_transformation (
- srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- src_coef_arrays : jvirt_barray_tbl_ptr;
- var info : jpeg_transform_info);
-var
- dst_coef_arrays : jvirt_barray_tbl_ptr;
-begin
- dst_coef_arrays := info.workspace_coef_arrays;
-
- case (info.transform) of
- JXFORM_NONE:;
-{$ifdef CROP_SUPPORTED}
- JXFORM_CUT:
- do_transform(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays,
- info.xoffs, info.yoffs);
-{$endif}
- JXFORM_FLIP_H:
- do_flip_h(srcinfo, dstinfo, src_coef_arrays);
- JXFORM_FLIP_V:
- do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
- JXFORM_TRANSPOSE:
- do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
- JXFORM_TRANSVERSE:
- do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
- JXFORM_ROT_90:
- do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
- JXFORM_ROT_180:
- do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
- JXFORM_ROT_270:
- do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
- end;
-end;
-
-{$endif} { TRANSFORMS_SUPPORTED }
-
-
-{ Setup decompression object to save desired markers in memory.
- This must be called before jpeg_read_header() to have the desired effect. }
-
-{GLOBAL}
-procedure jcopy_markers_setup (srcinfo : j_decompress_ptr;
- option : JCOPY_OPTION);
-var
- m : int;
-begin
-{$ifdef SAVE_MARKERS_SUPPORTED}
- { Save comments except under NONE option }
- if (option <> JCOPYOPT_NONE) then
- begin
- jpeg_save_markers(srcinfo, JPEG_COM, $FFFF);
- end;
- { Save all types of APPn markers iff ALL option }
- if (option = JCOPYOPT_ALL) then
- begin
- for m := 0 to 16-1 do
- jpeg_save_markers(srcinfo, JPEG_APP0 + m, $FFFF);
- end;
-{$endif} { SAVE_MARKERS_SUPPORTED }
-end;
-
-{ Copy markers saved in the given source object to the destination object.
- This should be called just after jpeg_start_compress() or
- jpeg_write_coefficients().
- Note that those routines will have written the SOI, and also the
- JFIF APP0 or Adobe APP14 markers if selected. }
-
-{GLOBAL}
-procedure jcopy_markers_execute (srcinfo : j_decompress_ptr;
- dstinfo : j_compress_ptr;
- option : JCOPY_OPTION);
-var
- marker : jpeg_saved_marker_ptr;
-{$ifdef NEED_FAR_POINTERS}
-var
- i : uint;
-{$endif}
-begin
- { In the current implementation, we don't actually need to examine the
- option flag here; we just copy everything that got saved.
- But to avoid confusion, we do not output JFIF and Adobe APP14 markers
- if the encoder library already wrote one. }
-
- marker := srcinfo^.marker_list;
- while (marker <> NIL) do
- begin
- if (dstinfo^.write_JFIF_header) and
- (marker^.marker = JPEG_APP0) and
- (marker^.data_length >= 5) and
- ( GETJOCTET(marker^.data^[0]) = $4A ) and
- ( GETJOCTET(marker^.data^[1]) = $46 ) and
- ( GETJOCTET(marker^.data^[2]) = $49 ) and
- ( GETJOCTET(marker^.data^[3]) = $46 ) and
- ( GETJOCTET(marker^.data^[4]) = 0 ) then
- begin
- marker := marker^.next;
- continue; { reject duplicate JFIF }
- end;
- if (dstinfo^.write_Adobe_marker ) and
- ( marker^.marker = JPEG_APP0+14 ) and
- ( marker^.data_length >= 5 ) and
- ( GETJOCTET(marker^.data^[0]) = $41 ) and
- ( GETJOCTET(marker^.data^[1]) = $64 ) and
- ( GETJOCTET(marker^.data^[2]) = $6F ) and
- ( GETJOCTET(marker^.data^[3]) = $62 ) and
- ( GETJOCTET(marker^.data^[4]) = $65 ) then
- begin
- marker := marker^.next;
- continue; { reject duplicate Adobe }
- end;
-{$ifdef NEED_FAR_POINTERS}
- { We could use jpeg_write_marker if the data weren't FAR... }
- begin
- jpeg_write_m_header(dstinfo, marker^.marker, marker^.data_length);
- for i := 0 to marker^.data_length-1 do
- jpeg_write_m_byte(dstinfo, marker^.data^[i]);
- end;
-{$else}
- jpeg_write_marker(dstinfo, marker^.marker,
- JOCTETPTR(marker^.data), marker^.data_length);
-{$endif}
- marker := marker^.next;
- end;
-end;
-
-end.
diff --git a/packages/base/pasjpeg/wrbmp.pas b/packages/base/pasjpeg/wrbmp.pas
deleted file mode 100644
index 9e6e86d246..0000000000
--- a/packages/base/pasjpeg/wrbmp.pas
+++ /dev/null
@@ -1,608 +0,0 @@
-Unit wrbmp;
-
-{ Copyright (C) 1994-1996, Thomas G. Lane.
- This code contributed by James Arthur Boucher.
-
- This file contains routines to write output images in Microsoft "BMP"
- format (MS Windows 3.x and OS/2 1.x flavors).
- Either 8-bit colormapped or 24-bit full-color format can be written.
- No compression is supported. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jpeglib,
- jinclude,
- jdeferr,
- jerror,
- jdmaster,
- cdjpeg; { Common decls for cjpeg/djpeg applications }
-
-{ The module selection routine for BMP format output. }
-
-{GLOBAL}
-function jinit_write_bmp (cinfo : j_decompress_ptr;
- is_os2 : boolean) : djpeg_dest_ptr;
-
-implementation
-
-{ To support 12-bit JPEG data, we'd have to scale output down to 8 bits.
- This is not yet implemented. }
-
-{$ifndef BITS_IN_JSAMPLE_IS_8}
- Sorry, this code only copes with 8-bit JSAMPLEs. { deliberate syntax err }
-{$endif}
-
-{ Since BMP stores scanlines bottom-to-top, we have to invert the image
- from JPEG's top-to-bottom order. To do this, we save the outgoing data
- in a virtual array during put_pixel_row calls, then actually emit the
- BMP file during finish_output. The virtual array contains one JSAMPLE per
- pixel if the output is grayscale or colormapped, three if it is full color.}
-
-{ Private version of data destination object }
-
-type
- bmp_dest_ptr = ^bmp_dest_struct;
- bmp_dest_struct = record
- pub : djpeg_dest_struct; { public fields }
-
- is_os2 : boolean; { saves the OS2 format request flag }
-
- whole_image : jvirt_sarray_ptr; { needed to reverse row order }
- data_width : JDIMENSION; { JSAMPLEs per row }
- row_width : JDIMENSION; { physical width of one row in the BMP file }
- pad_bytes : int; { number of padding bytes needed per row }
- cur_output_row : JDIMENSION; { next row# to write to virtual array }
- end;
-
-{ Forward declarations }
-{LOCAL}
-procedure write_colormap(cinfo : j_decompress_ptr;
- dest : bmp_dest_ptr;
- map_colors : int;
- map_entry_size : int); forward;
-
-{ Write some pixel data.
- In this module rows_supplied will always be 1. }
-
-{METHODDEF}
-procedure put_pixel_rows (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr;
- rows_supplied : JDIMENSION); far;
-{ This version is for writing 24-bit pixels }
-var
- dest : bmp_dest_ptr;
- image_ptr : JSAMPARRAY;
- {register} inptr : JSAMPLE_PTR;
- outptr : BGRptr;
- {register} col : JDIMENSION;
- pad : int;
-begin
- dest := bmp_dest_ptr (dinfo);
-
- { Access next row in virtual array }
- image_ptr := cinfo^.mem^.access_virt_sarray
- (j_common_ptr(cinfo), dest^.whole_image,
- dest^.cur_output_row, JDIMENSION (1), TRUE);
- Inc(dest^.cur_output_row);
-
-
- { Transfer data. Note destination values must be in BGR order
- (even though Microsoft's own documents say the opposite). }
-
- inptr := JSAMPLE_PTR(dest^.pub.buffer^[0]);
- outptr := BGRptr(image_ptr^[0]);
- for col := pred(cinfo^.output_width) downto 0 do
- begin
- outptr^.r := inptr^; { can omit GETJSAMPLE() safely }
- Inc(inptr);
- outptr^.g := inptr^;
- Inc(inptr);
- outptr^.b := inptr^;
- Inc(inptr);
- Inc(outptr);
- end;
-
- { Zero out the pad bytes. }
- pad := dest^.pad_bytes;
- while (pad > 0) do
- begin
- Dec(pad);
- JSAMPLE_PTR(outptr)^ := 0;
- Inc(JSAMPLE_PTR(outptr));
- end;
-end;
-
-{METHODDEF}
-procedure put_gray_rows (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr;
- rows_supplied : JDIMENSION); far;
-{ This version is for grayscale OR quantized color output }
-var
- dest : bmp_dest_ptr;
- image_ptr : JSAMPARRAY;
- {register} inptr, outptr : JSAMPLE_PTR;
- {register} col : JDIMENSION;
- pad : int;
-begin
- dest := bmp_dest_ptr (dinfo);
-
- { Access next row in virtual array }
- image_ptr := cinfo^.mem^.access_virt_sarray
- (j_common_ptr(cinfo), dest^.whole_image,
- dest^.cur_output_row, JDIMENSION (1), TRUE);
- Inc(dest^.cur_output_row);
-
- { Transfer data. }
- inptr := JSAMPLE_PTR(dest^.pub.buffer^[0]);
- outptr := JSAMPLE_PTR(image_ptr^[0]);
- for col := pred(cinfo^.output_width) downto 0 do
- begin
- outptr^ := inptr^; { can omit GETJSAMPLE() safely }
- Inc(outptr);
- Inc(inptr);
- end;
-
- { Zero out the pad bytes. }
- pad := dest^.pad_bytes;
- while (pad > 0) do
- begin
- Dec(pad);
- outptr^ := 0;
- Inc(outptr);
- end;
-end;
-
-
-{ Startup: normally writes the file header.
- In this module we may as well postpone everything until finish_output. }
-
-{METHODDEF}
-procedure start_output_bmp (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr); far;
-begin
- { no work here }
-end;
-
-
-{ Finish up at the end of the file.
-
- Here is where we really output the BMP file.
-
- First, routines to write the Windows and OS/2 variants of the file header. }
-
-
-{LOCAL}
-procedure write_bmp_header (cinfo : j_decompress_ptr;
- dest : bmp_dest_ptr);
-{ Write a Windows-style BMP file header, including colormap if needed }
-var
- bmpfileheader : packed array[0..14-1] of byte;
- bmpinfoheader : packed array[0..40-1] of byte;
-var
- headersize, bfSize : INT32 ;
- bits_per_pixel, cmap_entries : int;
-begin
- { Compute colormap size and total file size }
- if (cinfo^.out_color_space = JCS_RGB) then
- begin
- if (cinfo^.quantize_colors) then
- begin
- { Colormapped RGB }
- bits_per_pixel := 8;
- cmap_entries := 256;
- end
- else
- begin
- { Unquantized, full color RGB }
- bits_per_pixel := 24;
- cmap_entries := 0;
- end;
- end
- else
- begin
- { Grayscale output. We need to fake a 256-entry colormap. }
- bits_per_pixel := 8;
- cmap_entries := 256;
- end;
- { File size }
- headersize := 14 + 40 + cmap_entries * 4; { Header and colormap }
- bfSize := headersize + INT32 (dest^.row_width) * INT32 (cinfo^.output_height);
-
- { Set unused fields of header to 0 }
- MEMZERO(@bmpfileheader, SIZEOF(bmpfileheader));
- MEMZERO(@bmpinfoheader, SIZEOF(bmpinfoheader));
-
- { Fill the file header }
- bmpfileheader[0] := $42; { first 2 bytes are ASCII 'B', 'M' }
- bmpfileheader[1] := $4D;
- {PUT_4B(bmpfileheader, 2, bfSize);} { bfSize }
- bmpfileheader[2] := byte ((bfSize) and $FF);
- bmpfileheader[2+1] := byte (((bfSize) shr 8) and $FF);
- bmpfileheader[2+2] := byte (((bfSize) shr 16) and $FF);
- bmpfileheader[2+3] := byte (((bfSize) shr 24) and $FF);
- { we leave bfReserved1 & bfReserved2 = 0 }
- {PUT_4B(bmpfileheader, 10, headersize);} { bfOffBits }
- bmpfileheader[10] := byte (headersize and $FF);
- bmpfileheader[10+1] := byte ((headersize shr 8) and $FF);
- bmpfileheader[10+2] := byte ((headersize shr 16) and $FF);
- bmpfileheader[10+3] := byte ((headersize shr 24) and $FF);
-
- { Fill the info header (Microsoft calls this a BITMAPINFOHEADER) }
- {PUT_2B(bmpinfoheader, 0, 40);} { biSize }
- bmpinfoheader[0] := byte ((40) and $FF);
- bmpinfoheader[0+1] := byte (((40) shr 8) and $FF);
-
- {PUT_4B(bmpinfoheader, 4, cinfo^.output_width);} { biWidth }
- bmpinfoheader[4] := byte ((cinfo^.output_width) and $FF);
- bmpinfoheader[4+1] := byte ((cinfo^.output_width shr 8) and $FF);
- bmpinfoheader[4+2] := byte ((cinfo^.output_width shr 16) and $FF);
- bmpinfoheader[4+3] := byte ((cinfo^.output_width shr 24) and $FF);
- {PUT_4B(bmpinfoheader, 8, cinfo^.output_height);} { biHeight }
- bmpinfoheader[8] := byte (cinfo^.output_height and $FF);
- bmpinfoheader[8+1] := byte ((cinfo^.output_height shr 8) and $FF);
- bmpinfoheader[8+2] := byte ((cinfo^.output_height shr 16) and $FF);
- bmpinfoheader[8+3] := byte ((cinfo^.output_height shr 24) and $FF);
- {PUT_2B(bmpinfoheader, 12, 1);} { biPlanes - must be 1 }
- bmpinfoheader[12] := byte (1 and $FF);
- bmpinfoheader[12+1] := byte ((1 shr 8) and $FF);
-
- {PUT_2B(bmpinfoheader, 14, bits_per_pixel);} { biBitCount }
- bmpinfoheader[14] := byte (bits_per_pixel and $FF);
- bmpinfoheader[14+1] := byte ((bits_per_pixel shr 8) and $FF);
- { we leave biCompression = 0, for none }
- { we leave biSizeImage = 0; this is correct for uncompressed data }
- if (cinfo^.density_unit = 2) then
- begin { if have density in dots/cm, then }
- {PUT_4B(bmpinfoheader, 24, INT32 (cinfo^.X_density*100));} { XPels/M }
- bmpinfoheader[24] := byte (INT32 (cinfo^.X_density*100) and $FF);
- bmpinfoheader[24+1] := byte ((INT32 (cinfo^.X_density*100) shr 8) and $FF);
- bmpinfoheader[24+2] := byte ((INT32 (cinfo^.X_density*100) shr 16) and $FF);
- bmpinfoheader[24+3] := byte ((INT32 (cinfo^.X_density*100) shr 24) and $FF);
- {PUT_4B(bmpinfoheader, 28, INT32 (cinfo^.Y_density*100));} { XPels/M }
- bmpinfoheader[28] := byte (INT32 (cinfo^.Y_density*100) and $FF);
- bmpinfoheader[28+1] := byte ((INT32 (cinfo^.Y_density*100) shr 8) and $FF);
- bmpinfoheader[28+2] := byte ((INT32 (cinfo^.Y_density*100) shr 16) and $FF);
- bmpinfoheader[28+3] := byte ((INT32 (cinfo^.Y_density*100) shr 24) and $FF);
- end;
- {PUT_2B(bmpinfoheader, 32, cmap_entries);} { biClrUsed }
- bmpinfoheader[32] := byte (cmap_entries and $FF);
- bmpinfoheader[32+1] := byte ((cmap_entries shr 8) and $FF);
- { we leave biClrImportant := 0 }
-
- if (JFWRITE(dest^.pub.output_file, @bmpfileheader, 14) <> size_t (14)) then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
- if (JFWRITE(dest^.pub.output_file, @bmpinfoheader, 40) <> size_t (40)) then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
-
- if (cmap_entries > 0) then
- write_colormap(cinfo, dest, cmap_entries, 4);
-end;
-
-
-{LOCAL}
-procedure write_os2_header (cinfo : j_decompress_ptr;
- dest : bmp_dest_ptr);
-{ Write an OS2-style BMP file header, including colormap if needed }
-var
- bmpfileheader : array[0..14-1] of byte;
- bmpcoreheader : array[0..12-1] of byte;
- headersize, bfSize : INT32;
- bits_per_pixel, cmap_entries : int;
-begin
- { Compute colormap size and total file size }
- if (cinfo^.out_color_space = JCS_RGB) then
- begin
- if (cinfo^.quantize_colors) then
- begin
- { Colormapped RGB }
- bits_per_pixel := 8;
- cmap_entries := 256;
- end
- else
- begin
- { Unquantized, full color RGB }
- bits_per_pixel := 24;
- cmap_entries := 0;
- end;
- end
- else
- begin
- { Grayscale output. We need to fake a 256-entry colormap. }
- bits_per_pixel := 8;
- cmap_entries := 256;
- end;
- { File size }
- headersize := 14 + 12 + cmap_entries * 3; { Header and colormap }
- bfSize := headersize + INT32 (dest^.row_width) * INT32 (cinfo^.output_height);
-
- { Set unused fields of header to 0 }
- MEMZERO(@bmpfileheader, SIZEOF(bmpfileheader));
- MEMZERO(@bmpcoreheader, SIZEOF(bmpcoreheader));
-
- { Fill the file header }
- bmpfileheader[0] := $42; { first 2 bytes are ASCII 'B', 'M' }
- bmpfileheader[1] := $4D;
- {PUT_4B(bmpfileheader, 2, bfSize);} { bfSize }
- bmpfileheader[2] := byte ((bfSize) and $FF);
- bmpfileheader[2+1] := byte (((bfSize) shr 8) and $FF);
- bmpfileheader[2+2] := byte (((bfSize) shr 16) and $FF);
- bmpfileheader[2+3] := byte (((bfSize) shr 24) and $FF);
- { we leave bfReserved1 & bfReserved2 := 0 }
- {PUT_4B(bmpfileheader, 10, headersize);} { bfOffBits }
- bmpfileheader[10] := byte ((headersize) and $FF);
- bmpfileheader[10+1] := byte (((headersize) shr 8) and $FF);
- bmpfileheader[10+2] := byte (((headersize) shr 16) and $FF);
- bmpfileheader[10+3] := byte (((headersize) shr 24) and $FF);
-
- { Fill the info header (Microsoft calls this a BITMAPCOREHEADER) }
- {PUT_2B(bmpcoreheader, 0, 12);} { bcSize }
- bmpcoreheader[0] := byte (12 and $FF);
- bmpcoreheader[0+1] := byte ((12 shr 8) and $FF);
- {PUT_2B(bmpcoreheader, 4, cinfo^.output_width);} { bcWidth }
- bmpcoreheader[4] := byte (cinfo^.output_width and $FF);
- bmpcoreheader[4+1] := byte ((cinfo^.output_width shr 8) and $FF);
- {PUT_2B(bmpcoreheader, 6, cinfo^.output_height);} { bcHeight }
- bmpcoreheader[6] := byte (cinfo^.output_height and $FF);
- bmpcoreheader[6+1] := byte ((cinfo^.output_height shr 8) and $FF);
- {PUT_2B(bmpcoreheader, 8, 1);} { bcPlanes - must be 1 }
- bmpcoreheader[8] := byte (1 and $FF);
- bmpcoreheader[8+1] := byte ((1 shr 8) and $FF);
- {PUT_2B(bmpcoreheader, 10, bits_per_pixel);} { bcBitCount }
- bmpcoreheader[10] := byte (bits_per_pixel and $FF);
- bmpcoreheader[10+1] := byte ((bits_per_pixel shr 8) and $FF);
-
- if (JFWRITE(dest^.pub.output_file, @bmpfileheader, 14) <> size_t (14)) then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
- if (JFWRITE(dest^.pub.output_file, @bmpcoreheader, 12) <> size_t (12)) then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
-
- if (cmap_entries > 0) then
- write_colormap(cinfo, dest, cmap_entries, 3);
-end;
-
-
-{ Write the colormap.
- Windows uses BGR0 map entries; OS/2 uses BGR entries. }
-
-{LOCAL}
-procedure write_colormap (cinfo : j_decompress_ptr;
- dest : bmp_dest_ptr;
- map_colors : int;
- map_entry_size : int);
-var
- colormap : JSAMPARRAY;
- num_colors : int;
- outfile : FILEptr;
- i : int;
-var
- output_color_map : Array[0..255] of BGRtype;
- output_ext_color_map : Array[0..255] of record
- b,g,r,a : byte;
- end;
-begin
- colormap := cinfo^.colormap;
- num_colors := cinfo^.actual_number_of_colors;
- outfile := dest^.pub.output_file;
-
- if (colormap <> NIL) then
- begin
- if (cinfo^.out_color_components = 3) then
- begin
- { Normal case with RGB colormap }
- if (map_entry_size = 4) then
- for i := 0 to pred(num_colors) do
- with output_ext_color_map[i] do
- begin
- b := GETJSAMPLE(cinfo^.colormap^[2]^[i]);
- g := GETJSAMPLE(cinfo^.colormap^[1]^[i]);
- r := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- a := 0;
- end
- else
- for i := 0 to pred(num_colors) do
- with output_color_map[i] do
- begin
- b := GETJSAMPLE(cinfo^.colormap^[2]^[i]);
- g := GETJSAMPLE(cinfo^.colormap^[1]^[i]);
- r := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- end;
- end
- else
- begin
- { Grayscale colormap (only happens with grayscale quantization) }
- if (map_entry_size = 4) then
- for i := 0 to pred(num_colors) do
- with output_ext_color_map[i] do
- begin
- b := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- g := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- r := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- a := 0;
- end
- else
- for i := 0 to pred(num_colors) do
- with output_color_map[i] do
- begin
- b := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- g := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- r := GETJSAMPLE(cinfo^.colormap^[0]^[i]);
- end;
- end;
- i := num_colors;
- end
- else
- begin
- { If no colormap, must be grayscale data. Generate a linear "map". }
- { Nomssi: do not use "num_colors" here, it should be 0 }
- if (map_entry_size = 4) then
- for i := 0 to pred(256) do
- with output_ext_color_map[i] do
- begin
- b := i;
- g := i;
- r := i;
- a := 0;
- end
- else
- for i := 0 to pred(256) do
- with output_color_map[i] do
- begin
- b := i;
- g := i;
- r := i;
- end;
- i := 256;
- end;
- { Pad colormap with zeros to ensure specified number of colormap entries }
-
- if (i > map_colors) then
- ERREXIT1(j_common_ptr(cinfo), JERR_TOO_MANY_COLORS, i);
- while (i < map_colors) do
- begin
- if (map_entry_size = 4) then
- with output_ext_color_map[i] do
- begin
- b := 0;
- g := 0;
- r := 0;
- a := 0;
- end
- else
- with output_color_map[i] do
- begin
- b := 0;
- g := 0;
- r := 0;
- end;
- Inc(i);
- end;
- if (map_entry_size = 4) then
- JFWRITE(outfile, @output_ext_color_map, map_colors*4)
- else
- JFWRITE(outfile, @output_color_map, map_colors*3);
-end;
-
-
-{METHODDEF}
-procedure finish_output_bmp (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr); far;
-var
- dest : bmp_dest_ptr;
- {register} outfile : FILEptr;
- image_ptr : JSAMPARRAY;
- {register} data_ptr : JSAMPLE_PTR;
- row : JDIMENSION;
- {register} { col : JDIMENSION; }
- progress : cd_progress_ptr;
-begin
- dest := bmp_dest_ptr (dinfo);
- outfile := dest^.pub.output_file;
- progress := cd_progress_ptr (cinfo^.progress);
-
- { Write the header and colormap }
- if (dest^.is_os2) then
- write_os2_header(cinfo, dest)
- else
- write_bmp_header(cinfo, dest);
-
- { Write the file body from our virtual array }
- for row := cinfo^.output_height downto 1 do
- begin
- if (progress <> NIL) then
- begin
- progress^.pub.pass_counter := long (cinfo^.output_height - row);
- progress^.pub.pass_limit := long (cinfo^.output_height);
- progress^.pub.progress_monitor (j_common_ptr(cinfo));
- end;
- image_ptr := cinfo^.mem^.access_virt_sarray
- (j_common_ptr(cinfo), dest^.whole_image, row-1, JDIMENSION(1), FALSE);
- data_ptr := JSAMPLE_PTR(image_ptr^[0]);
- { Nomssi - This won't work for 12bit samples }
- JFWRITE(outfile, data_ptr, dest^.row_width);
- {
- for col := pred(dest^.row_width) downto 0 do
- begin
- putc(GETJSAMPLE(data_ptr^), outfile);
- Inc(data_ptr);
- end;
- }
- end;
- if (progress <> NIL) then
- Inc(progress^.completed_extra_passes);
-
- { Make sure we wrote the output file OK }
- {fflush(outfile);
- if (ferror(outfile)) then
- ERREXIT(cinfo, JERR_FILE_WRITE);}
-end;
-
-
-{ The module selection routine for BMP format output. }
-
-{GLOBAL}
-function jinit_write_bmp (cinfo : j_decompress_ptr;
- is_os2 : boolean) : djpeg_dest_ptr;
-var
- dest : bmp_dest_ptr;
- row_width : JDIMENSION;
-var
- progress : cd_progress_ptr;
-begin
- { Create module interface object, fill in method pointers }
- dest := bmp_dest_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(bmp_dest_struct)) );
- dest^.pub.start_output := start_output_bmp;
- dest^.pub.finish_output := finish_output_bmp;
- dest^.is_os2 := is_os2;
-
- if (cinfo^.out_color_space = JCS_GRAYSCALE) then
- begin
- dest^.pub.put_pixel_rows := put_gray_rows;
- end
- else
- if (cinfo^.out_color_space = JCS_RGB) then
- begin
- if (cinfo^.quantize_colors) then
- dest^.pub.put_pixel_rows := put_gray_rows
- else
- dest^.pub.put_pixel_rows := put_pixel_rows;
- end
- else
- ERREXIT(j_common_ptr(cinfo), JERR_BMP_COLORSPACE);
-
- { Calculate output image dimensions so we can allocate space }
- jpeg_calc_output_dimensions(cinfo);
-
- { Determine width of rows in the BMP file (padded to 4-byte boundary). }
- row_width := cinfo^.output_width * cinfo^.output_components;
- dest^.data_width := row_width;
- while ((row_width and 3) <> 0) do
- Inc(row_width);
- dest^.row_width := row_width;
- dest^.pad_bytes := int (row_width - dest^.data_width);
-
- { Allocate space for inversion array, prepare for write pass }
- dest^.whole_image := cinfo^.mem^.request_virt_sarray
- (j_common_ptr(cinfo), JPOOL_IMAGE, FALSE,
- row_width, cinfo^.output_height, JDIMENSION (1));
- dest^.cur_output_row := 0;
- if (cinfo^.progress <> NIL) then
- begin
- progress := cd_progress_ptr (cinfo^.progress);
- Inc(progress^.total_extra_passes); { count file input as separate pass }
- end;
-
- { Create decompressor output buffer. }
- dest^.pub.buffer := cinfo^.mem^.alloc_sarray
- (j_common_ptr(cinfo), JPOOL_IMAGE, row_width, JDIMENSION (1));
- dest^.pub.buffer_height := 1;
-
- jinit_write_bmp := djpeg_dest_ptr(dest);
-end;
-
-end. { BMP_SUPPORTED }
diff --git a/packages/base/pasjpeg/wrjpgcom.pas b/packages/base/pasjpeg/wrjpgcom.pas
deleted file mode 100644
index cb8a453d1e..0000000000
--- a/packages/base/pasjpeg/wrjpgcom.pas
+++ /dev/null
@@ -1,596 +0,0 @@
-Program WrJpgCom;
-
-{ 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. }
-
-uses
- jmorecfg,
- jinclude,
- cdjpeg,
- strings,
- fcache;
-
-const
- EXIT_FAILURE = 1; { define Halt() codes if not provided }
- EXIT_SUCCESS = 0;
-
-{ Reduce this value if your malloc() can't allocate blocks up to 64K.
- On DOS, compiling in large model is usually a better solution. }
-
-const
- MAX_COM_LENGTH = Long(32000); { must be <= 65533 in any case }
-
-
-{ 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. }
-
-var
- infile : file; { input JPEG file }
-
-{ Return next input byte, or EOF if no more }
-
-var
- outfile : file; { output JPEG file }
-
-{ Emit an output byte }
-function NEXTBYTE : byte;
-
-var
- B : Byte;
-
-begin
- BlockRead(Infile,B,1);
- NEXTBYTE :=b;
- // fc_getc(var fc : Cache);
-{ Read a byte at the current buffer read-index, increment the buffer
- read-index }
-end;
-
-procedure PUTBYTE(c : int);
-begin
- BlockWrite(outfile,c, 1);
-end;
-
-{ Error exit handler }
-procedure ERREXIT(msg : string);
-begin
- WriteLn(msg);
- Halt(EXIT_FAILURE);
-end;
-
-
-{ Read one byte, testing for EOF }
-function read_1_byte : int;
-var
- c : byte;
-begin
- c := NEXTBYTE;
- if (c = int(EOF)) then
- ERREXIT('Premature EOF in JPEG file');
- read_1_byte := c;
-end;
-
-{ Read 2 bytes, convert to uint }
-{ All 2-byte quantities in JPEG markers are MSB first }
-function read_2_bytes : uint;
-var
- c1, c2 : int;
-begin
- c1 := NEXTBYTE;
- if (c1 = int(EOF)) then
- ERREXIT('Premature EOF in JPEG file');
- c2 := NEXTBYTE;
- if (c2 = int(EOF)) then
- ERREXIT('Premature EOF in JPEG file');
- read_2_bytes := ((uint(c1)) shl 8) + (uint(c2));
-end;
-
-
-{ Routines to write data to output file }
-
-procedure write_1_byte (c : int);
-begin
- PUTBYTE(c);
-end;
-
-procedure write_2_bytes (val : uint);
-begin
- PUTBYTE((val shr 8) and $FF);
- PUTBYTE(val and $FF);
-end;
-
-procedure write_marker (marker : int);
-begin
- PUTBYTE($FF);
- PUTBYTE(marker);
-end;
-
-procedure copy_rest_of_file;
-var
- c : int;
-begin
- repeat
- c := NEXTBYTE;
- if (c <> int(EOF)) then
- PUTBYTE(c);
- until (c = int(EOF));
-end;
-
-
-{ JPEG markers consist of one or more $FF 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.) }
-const
- M_SOF0 = $C0; { Start Of Frame N }
- M_SOF1 = $C1; { N indicates which compression process }
- M_SOF2 = $C2; { Only SOF0-SOF2 are now in common use }
- M_SOF3 = $C3;
- M_SOF5 = $C5; { NB: codes C4 and CC are NOT SOF markers }
- M_SOF6 = $C6;
- M_SOF7 = $C7;
- M_SOF9 = $C9;
- M_SOF10 = $CA;
- M_SOF11 = $CB;
- M_SOF13 = $CD;
- M_SOF14 = $CE;
- M_SOF15 = $CF;
- M_SOI = $D8; { Start Of Image (beginning of datastream) }
- M_EOI = $D9; { End Of Image (end of datastream) }
- M_SOS = $DA; { Start Of Scan (begins compressed data) }
- M_COM = $FE; { 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... }
-
-function next_marker : int;
-var
- c : int;
- discarded_bytes : int;
-begin
- discarded_bytes := 0;
-
- { Find $FF byte; count and skip any non-FFs. }
- c := read_1_byte;
- while (c <> $FF) do
- begin
- Inc(discarded_bytes);
- c := read_1_byte;
- end;
- { Get marker code byte, swallowing any duplicate FF bytes. Extra FFs
- are legal as pad bytes, so don't count them in discarded_bytes. }
- repeat
- c := read_1_byte;
- until (c <> $FF);
-
- if (discarded_bytes <> 0) then
- begin
- WriteLn('Warning: garbage data found in JPEG file');
- end;
-
- next_marker := c;
-end;
-
-
-{ Read the initial marker, which should be SOI.
- For a JFIF file, the first two bytes of the file should be literally
- $FF 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... }
-
-function first_marker : int;
-var
- c1, c2 : int;
-begin
- c1 := NEXTBYTE;
- c2 := NEXTBYTE;
- if (c1 <> $FF) or (c2 <> M_SOI) then
- ERREXIT('Not a JPEG file');
- first_marker := c2;
-end;
-
-
-{ 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 $FF bytes that might appear within the parameter segment;
- such bytes do NOT introduce new markers. }
-
-procedure copy_variable;
-{ Copy an unknown or uninteresting variable-length marker }
-var
- length : uint;
-begin
- { 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) then
- ERREXIT('Erroneous JPEG marker length');
- Dec(length, 2);
- { Skip over the remaining bytes }
- while (length > 0) do
- begin
- write_1_byte(read_1_byte);
- Dec(length);
- end;
-end;
-
-procedure skip_variable;
-{ Skip over an unknown or uninteresting variable-length marker }
-var
- length : uint;
-begin
- { Get the marker parameter length count }
- length := read_2_bytes;
- { Length includes itself, so must be at least 2 }
- if (length < 2) then
- ERREXIT('Erroneous JPEG marker length');
- Dec(length, 2);
- { Skip over the remaining bytes }
- while (length > 0) do
- begin
- read_1_byte;
- Dec(length);
- end;
-end;
-
-
-{ Parse the marker stream until SOFn or EOI is seen;
- copy data to output, but discard COM markers unless keep_COM is true. }
-
-function scan_JPEG_header (keep_COM : boolean) : int;
-var
- marker : int;
-begin
- { Expect SOI at start of file }
- if (first_marker <> M_SOI) then
- ERREXIT('Expected SOI marker first');
- write_marker(M_SOI);
-
- { Scan miscellaneous markers until we reach SOFn. }
- while TRUE do
- begin
- marker := next_marker;
- case marker of
- { Note that marker codes $C4, $C8, $CC are not, and must not be,
- treated as SOFn. C4 in particular is actually DHT. }
- M_SOF0, { Baseline }
- M_SOF1, { Extended sequential, Huffman }
- M_SOF2, { Progressive, Huffman }
- M_SOF3, { Lossless, Huffman }
- M_SOF5, { Differential sequential, Huffman }
- M_SOF6, { Differential progressive, Huffman }
- M_SOF7, { Differential lossless, Huffman }
- M_SOF9, { Extended sequential, arithmetic }
- M_SOF10, { Progressive, arithmetic }
- M_SOF11, { Lossless, arithmetic }
- M_SOF13, { Differential sequential, arithmetic }
- M_SOF14, { Differential progressive, arithmetic }
- M_SOF15: { Differential lossless, arithmetic }
- begin
- scan_JPEG_header := marker;
- exit;
- end;
-
- M_SOS: { should not see compressed data before SOF }
- ERREXIT('SOS without prior SOFn');
-
- M_EOI: { in case it's a tables-only JPEG stream }
- begin
- scan_JPEG_header := marker;
- exit;
- end;
-
- M_COM: { Existing COM: conditionally discard }
- if (keep_COM) then
- begin
- write_marker(marker);
- copy_variable;
- end
- else
- begin
- skip_variable;
- end;
-
- else { Anything else just gets copied }
- write_marker(marker);
- copy_variable; { we assume it has a parameter count... }
- end;
- end; { end loop }
-end;
-
-
-{ Command line parsing code }
-
-var
- progname : string; { program name for error messages }
-
-
-procedure usage;
-{ complain about bad command line }
-begin
- WriteLn('wrjpgcom inserts a textual comment in a JPEG file.');
- WriteLn('You can add to or replace any existing comment(s).');
-
- Write('Usage: ',progname,' [switches] ');
-{$ifdef TWO_FILE_COMMANDLINE
- WriteLn('inputfile outputfile');
-{$else}
- WriteLn('[inputfile]');
-{$endif}
-
- WriteLn('Switches (names may be abbreviated):');
- WriteLn(' -replace Delete any existing comments');
- WriteLn(' -comment "text" Insert comment with given text');
- WriteLn(' -cfile name Read comment from named file');
- WriteLn('Notice that you must put quotes around the comment text');
- WriteLn('when you use -comment.');
- WriteLn('If you do not give either -comment or -cfile on the command line,');
- WriteLn('then the comment text is read from standard input.');
- WriteLn('It can be multiple lines, up to ',
- uint(MAX_COM_LENGTH),' characters total.');
-{$ifndef TWO_FILE_COMMANDLINE}
- WriteLn('You must specify an input JPEG file name when supplying');
- WriteLn('comment text from standard input.');
-{$endif}
-
- Halt(EXIT_FAILURE);
-end;
-
-
-function keymatch (const arg : string;
- const keyword : string;
- minchars : int) : boolean;
-{ 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. }
-var
- {register} ca, ck : char;
- {register} nmatched : int;
- i, len : int;
-begin
- nmatched := 0;
- keymatch := FALSE;
- len := Length(keyword);
- if len >= Length(arg) then
- len := Length(arg)
- else
- exit;
- for i := 1 to len do
- begin
- if (UpCase(arg[i]) <> UpCase(keyword[i])) then
- exit;
- Inc(nmatched); { count matched characters }
- end;
- { reached end of argument; fail if it's too short for unique abbrev }
- if (nmatched >= minchars) then
- keymatch := TRUE; { A-OK }
-end;
-
-{ The main program. }
-var
- argc,
- argn : int;
- arg : string;
- keep_COM : boolean;
- comment_arg : string;
- comment_arg_0 : PChar;
- comment_file : TBufStream;
- comment_length : uint;
- marker : int;
-var
- src_file : PBufStream;
- c : int;
-begin
- keep_COM := TRUE;
- comment_arg := '';
- comment_length := 0;
-
- { On Mac, fetch a command line. }
- argc := ParamCount;
-
- progname := ParamStr(0);
-
- { Parse switches, if any }
- argn := 1;
- while (argn < argc) do
- begin
- arg := ParamStr(argn);
- if (arg[1] <> '-') then
- break; { not switch, must be file name }
- if (keymatch(arg, '-replace', 2)) then
- begin
- keep_COM := FALSE;
- end
- else
- if (keymatch(arg, '-cfile', 3)) then
- begin
- Inc(argn);
- if (argn >= argc) then
- usage;
- if not comment_file.Init(ParamStr(argn), stOpenRead, 2048) then
- begin
- WriteLn(progname, 'can''t open ', ParamStr(argn));
- Halt(EXIT_FAILURE);
- end;
- end
- else
- {$ifdef comment}
- if (keymatch(arg, '-comment', 2)) then
- begin
- Inc(argn);
- if (argn >= argc) then
- usage;
- comment_arg := ParamStr(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[1] = '"') then
- begin
- GetMem(comment_arg_0, size_t(MAX_COM_LENGTH) );
- if (comment_arg_0 = NIL) then
- ERREXIT('Insufficient memory');
- strcopy(comment_arg_0, ParamStr(argn)+1);
- while TRUE do
- begin
- comment_length := uint( strlen(comment_arg) );
- if (comment_length > 0) and
- (comment_arg[comment_length-1] = '"') then
- begin
- comment_arg[comment_length-1] := #0; { zap terminating quote }
- break;
- end;
- Inc(argn);
- if (argn >= argc) then
- ERREXIT('Missing ending quote mark');
- strcat(comment_arg, ' ');
- strcat(comment_arg, argv[argn]);
- end;
- end;
- comment_length := uint(strlen(comment_arg));
- end
- else
- usage;
- {$endif}
- Inc(argn);
- end;
-
- { Cannot use both -comment and -cfile. }
- if (comment_arg <> '') and (comment_file.status <> stOK) then
- 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 = '') and (comment_file.status <> stOK) and (argn >= argc) then
- usage;
-
- { Open the input file. }
- if (argn < argc) then
- begin
- infile.Init(ParamStr(argn), stOpenRead, 2048);
- if (infile.Status <> stOK) then
- begin
- WriteLn(progname, ': can''t open ', ParamStr(argn));
- Halt(EXIT_FAILURE);
- end;
- end
- else
- begin
- { default input file is stdin }
-{$ifdef USE_FDOPEN} { need to re-open in binary mode? }
- infile := TBufStream.Init('', stOpenRead, 2048);
- if (infile.Status <> stOK) then
- begin
- WriteLn(progname, ': can''t open stdin');
- Halt(EXIT_FAILURE);
- end;
-{$else}
- {infile := input;}
- RunError(255);
-{$endif}
- end;
-
- { Open the output file. }
-{$ifdef TWO_FILE_COMMANDLINE}
- { Must have explicit output file name }
- if (argn <> argc-2) then
- begin
- WriteLn(progname, ': must name one input and one output file');
- usage;
- end;
- outfile := TBufStream.Init(ParamStr(argn+1), stOpenWrite, 2048);
- if (outfile.Status <> stOK) then
- begin
- WriteLn(progname, ': can't open ', ParamStr(argn+1));
- Halt(EXIT_FAILURE);
- end;
-{$else}
- { Unix style: expect zero or one file name }
- if (argn < argc-1) then
- begin
- WriteLn(progname, ': only one input file');
- usage;
- end;
- { default output file is stdout }
-{$ifdef USE_FDOPEN} { need to re-open in binary mode? }
- outfile := TBufStream.Init('', stOpenWrite, 2048);
- if (outfile.Status <> stOK) then
- begin
- WriteLn(progname, ': can''t open stdout');
- Halt(EXIT_FAILURE);
- end;
-{$else}
- RunError(255);
- {outfile := stdout;}
-{$endif}
-{$endif} { TWO_FILE_COMMANDLINE }
-
- { Collect comment text from comment_file or stdin, if necessary }
- if (comment_arg_0 = NIL) then
- begin
-
- GetMem(comment_arg_0, size_t(MAX_COM_LENGTH) );
- if (comment_arg_0 = NIL) then
- ERREXIT('Insufficient memory');
- comment_length := 0;
- if comment_file.status = stOK then
- src_file := @comment_file
- else
- src_file := NIL;
- repeat
- c := getc(src_file);
- if (c <> EOF) do
- begin
- if (comment_length >= uint(MAX_COM_LENGTH)) then
- begin
- WriteLn('Comment text may not exceed ',
- uint(MAX_COM_LENGTH)),' bytes);
- Halt(EXIT_FAILURE);
- end;
- comment_arg[comment_length] := char(c);
- Inc(comment_length);
- end;
- until (c = EOF);
- if (comment_file <> '') then
- fclose(comment_file);
- end;
-
- { 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) then
- begin
- write_marker(M_COM);
- write_2_bytes(comment_length + 2);
- while (comment_length > 0) do
- begin
- write_1_byte(comment_arg^);
- Inc(comment_arg);
- Dec(comment_length);
- end;
- end;
- { 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. }
- Halt(EXIT_SUCCESS);
-end.
diff --git a/packages/base/pasjpeg/wrppm.pas b/packages/base/pasjpeg/wrppm.pas
deleted file mode 100644
index adc336243c..0000000000
--- a/packages/base/pasjpeg/wrppm.pas
+++ /dev/null
@@ -1,335 +0,0 @@
-Unit WrPPM;
-
-{ wrppm.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 write output images in PPM/PGM format.
- The extended 2-byte-per-sample raw PPM/PGM formats are supported.
- The PBMPLUS library is NOT required to compile this software
- (but it is highly useful as a set of PPM image manipulation programs).
-
- These routines may need modification for non-Unix environments or
- specialized applications. As they stand, they assume output to
- an ordinary stdio stream. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jdeferr,
- jmorecfg,
- jerror,
- jpeglib,
- jinclude,
- jdmaster,
- cdjpeg; { Common decls for cjpeg/djpeg applications }
-
-{GLOBAL}
-function jinit_write_ppm (cinfo : j_decompress_ptr) : djpeg_dest_ptr;
-
-implementation
-
-{ For 12-bit JPEG data, we either downscale the values to 8 bits
- (to write standard byte-per-sample PPM/PGM files), or output
- nonstandard word-per-sample PPM/PGM files. Downscaling is done
- if PPM_NORAWWORD is defined (this can be done in the Makefile
- or in jconfig.h).
- (When the core library supports data precision reduction, a cleaner
- implementation will be to ask for that instead.) }
-
-type
- CharPtr = ^char;
-
-
-{$ifdef BITS_IN_JSAMPLE_IS_8}
-
-procedure PUTPPMSAMPLE(var ptr : CharPtr; v : byte);
-begin
- ptr^ := char(v);
- Inc(ptr);
-end;
-
-const
- BYTESPERSAMPLE = 1;
- PPM_MAXVAL = 255;
-{$else}
- {$ifdef PPM_NORAWWORD}
-
-procedure PUTPPMSAMPLE(var ptr : CharPtr; v : byte);
-begin
- ptr^ := char (v shr (BITS_IN_JSAMPLE-8));
- Inc(ptr);
-end;
-
-const
- BYTESPERSAMPLE = 1;
- PPM_MAXVAL = 255;
-
- {$else}
- { The word-per-sample format always puts the LSB first. }
-
-procedure PUTPPMSAMPLE(var ptr : CharPtr; v : int);
-var
- {register} val_ : int;
-begin
- val_ := v;
- ptr^ := char (val_ and $FF);
- Inc(ptr);
- ptr^ := char ((val_ shr 8) and $FF);
- Inc(ptr);
-end;
-const
- BYTESPERSAMPLE = 2;
- PPM_MAXVAL = (1 shl BITS_IN_JSAMPLE)-1;
- {$endif}
-{$endif}
-
-
-{ When JSAMPLE is the same size as char, we can just fwrite() the
- decompressed data to the PPM or PGM file. On PCs, in order to make this
- work the output buffer must be allocated in near data space, because we are
- assuming small-data memory model wherein fwrite() can't reach far memory.
- If you need to process very wide images on a PC, you might have to compile
- in large-memory model, or else replace fwrite() with a putc() loop ---
- which will be much slower. }
-
-
-{ Private version of data destination object }
-
-type
- ppm_dest_ptr = ^ppm_dest_struct;
- ppm_dest_struct = record
- pub : djpeg_dest_struct; { public fields }
-
- { Usually these two pointers point to the same place: }
- iobuffer : CharPtr; { fwrite's I/O buffer }
- pixrow : JSAMPROW; { decompressor output buffer }
- buffer_width : size_t; { width of I/O buffer }
- samples_per_row : JDIMENSION; { JSAMPLEs per output row }
- end;
-
-
-{ Write some pixel data.
- In this module rows_supplied will always be 1.
-
- put_pixel_rows handles the "normal" 8-bit case where the decompressor
- output buffer is physically the same as the fwrite buffer. }
-
-{METHODDEF}
-procedure put_pixel_rows (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr;
- rows_supplied : JDIMENSION); far;
-var
- dest : ppm_dest_ptr;
-begin
- dest := ppm_dest_ptr(dinfo);
- {void} JFWRITE(dest^.pub.output_file, dest^.iobuffer, dest^.buffer_width);
-end;
-
-
-{ This code is used when we have to copy the data and apply a pixel
- format translation. Typically this only happens in 12-bit mode. }
-
-{METHODDEF}
-procedure copy_pixel_rows (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr;
- rows_supplied : JDIMENSION); far;
-var
- dest : ppm_dest_ptr;
- {register} bufferptr : CharPtr;
- {register} ptr : JSAMPLE_PTR;
- {register} col : JDIMENSION;
-begin
- dest := ppm_dest_ptr(dinfo);
- ptr := JSAMPLE_PTR(dest^.pub.buffer^[0]);
- bufferptr := dest^.iobuffer;
- for col := pred(dest^.samples_per_row) downto 0 do
- begin
- PUTPPMSAMPLE(bufferptr, GETJSAMPLE(ptr^));
- Inc(ptr);
- end;
- {void} JFWRITE(dest^.pub.output_file, dest^.iobuffer, dest^.buffer_width);
-end;
-
-
-{ Write some pixel data when color quantization is in effect.
- We have to demap the color index values to straight data. }
-
-{METHODDEF}
-procedure put_demapped_rgb (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr;
- rows_supplied : JDIMENSION); far;
-var
- dest : ppm_dest_ptr;
- {register} bufferptr : CharPtr;
- {register} ptr : JSAMPLE_PTR;
- {register} col : JDIMENSION;
-
- {register} pixval : int;
- {register} color_map0 : JSAMPROW;
- {register} color_map1 : JSAMPROW;
- {register} color_map2 : JSAMPROW;
-begin
- dest := ppm_dest_ptr(dinfo);
- ptr := JSAMPLE_PTR(dest^.pub.buffer^[0]);
- bufferptr := dest^.iobuffer;
- color_map0 := cinfo^.colormap^[0];
- color_map1 := cinfo^.colormap^[1];
- color_map2 := cinfo^.colormap^[2];
-
- for col := pred(cinfo^.output_width) downto 0 do
- begin
- pixval := GETJSAMPLE(ptr^);
- Inc(ptr);
- PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map0^[pixval]));
- PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map1^[pixval]));
- PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map2^[pixval]));
- end;
- {void} JFWRITE(dest^.pub.output_file, dest^.iobuffer, dest^.buffer_width);
-end;
-
-
-{METHODDEF}
-procedure put_demapped_gray (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr;
- rows_supplied : JDIMENSION); far;
-var
- dest : ppm_dest_ptr;
- {register} bufferptr : CharPtr;
- {register} ptr : JSAMPLE_PTR;
- {register} color_map : JSAMPROW;
- {register} col : JDIMENSION;
-begin
- dest := ppm_dest_ptr(dinfo);
- color_map := cinfo^.colormap^[0];
- ptr := JSAMPLE_PTR(dest^.pub.buffer^[0]);
- bufferptr := dest^.iobuffer;
- for col := pred(cinfo^.output_width) downto 0 do
- begin
- PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map^[GETJSAMPLE(ptr^)]));
- Inc(ptr);
- end;
- {void} JFWRITE(dest^.pub.output_file, dest^.iobuffer, dest^.buffer_width);
-end;
-
-
-{ Startup: write the file header. }
-
-{METHODDEF}
-procedure start_output_ppm (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr); far;
-const
- LF = #10;
-var
- dest : ppm_dest_ptr;
-var
- header : string[200];
-
- function LongToStr(l : long) : string;
- var
- helpstr : string[20];
- begin
- Str(l, helpstr);
- LongToStr := helpstr;
- end;
-
-begin
- dest := ppm_dest_ptr(dinfo);
- { Emit file header }
- case (cinfo^.out_color_space) of
- JCS_GRAYSCALE:
- begin
- { emit header for raw PGM format }
- header := 'P5'+LF+LongToStr(cinfo^.output_width)+' '+
- LongToStr(cinfo^.output_height)+LF+
- LongToStr(Long(PPM_MAXVAL)) + LF;
- JFWRITE(dest^.pub.output_file, @header[1], Length(header));
- end;
- JCS_RGB:
- begin
- { emit header for raw PPM format }
- header := 'P6'+LF+LongToStr(cinfo^.output_width)+' '+
- LongToStr(cinfo^.output_height)+LF+
- LongToStr(Long(PPM_MAXVAL)) + LF;
- JFWRITE(dest^.pub.output_file, @header[1], Length(header));
- end;
- else
- ERREXIT(j_common_ptr(cinfo), JERR_PPM_COLORSPACE);
- end;
-end;
-
-
-{ Finish up at the end of the file. }
-
-{METHODDEF}
-procedure finish_output_ppm (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr); far;
-begin
- { Make sure we wrote the output file OK }
- {Flush(dinfo^.output_file^);}
- if (IOresult <> 0) then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
-end;
-
-{ The module selection routine for PPM format output. }
-
-{GLOBAL}
-function jinit_write_ppm (cinfo : j_decompress_ptr) : djpeg_dest_ptr;
-var
- dest : ppm_dest_ptr;
-begin
- { Create module interface object, fill in method pointers }
- dest := ppm_dest_ptr (
- cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
- SIZEOF(ppm_dest_struct)) );
- dest^.pub.start_output := start_output_ppm;
- dest^.pub.finish_output := finish_output_ppm;
-
- { Calculate output image dimensions so we can allocate space }
- jpeg_calc_output_dimensions(cinfo);
-
- { Create physical I/O buffer. Note we make this near on a PC. }
- dest^.samples_per_row := cinfo^.output_width * cinfo^.out_color_components;
- dest^.buffer_width := dest^.samples_per_row * (BYTESPERSAMPLE * SIZEOF(char));
- dest^.iobuffer := CharPtr( cinfo^.mem^.alloc_small
- (j_common_ptr(cinfo), JPOOL_IMAGE, dest^.buffer_width) );
-
- if (cinfo^.quantize_colors) or (BITS_IN_JSAMPLE <> 8) or
- (SIZEOF(JSAMPLE) <> SIZEOF(char)) then
- begin
- { When quantizing, we need an output buffer for colormap indexes
- that's separate from the physical I/O buffer. We also need a
- separate buffer if pixel format translation must take place. }
-
- dest^.pub.buffer := cinfo^.mem^.alloc_sarray
- (j_common_ptr(cinfo), JPOOL_IMAGE,
- cinfo^.output_width * cinfo^.output_components, JDIMENSION(1));
- dest^.pub.buffer_height := 1;
- if (not cinfo^.quantize_colors) then
- dest^.pub.put_pixel_rows := copy_pixel_rows
- else
- if (cinfo^.out_color_space = JCS_GRAYSCALE) then
- dest^.pub.put_pixel_rows := put_demapped_gray
- else
- dest^.pub.put_pixel_rows := put_demapped_rgb;
- end
- else
- begin
- { We will fwrite() directly from decompressor output buffer. }
- { Synthesize a JSAMPARRAY pointer structure }
- { Cast here implies near^.far pointer conversion on PCs }
- dest^.pixrow := JSAMPROW(dest^.iobuffer);
- dest^.pub.buffer := JSAMPARRAY (@dest^.pixrow);
- dest^.pub.buffer_height := 1;
- dest^.pub.put_pixel_rows := put_pixel_rows;
- end;
-
- jinit_write_ppm := djpeg_dest_ptr(dest);
-end;
-
-
-end.
diff --git a/packages/base/pasjpeg/wrtarga.pas b/packages/base/pasjpeg/wrtarga.pas
deleted file mode 100644
index bb0ec28f9a..0000000000
--- a/packages/base/pasjpeg/wrtarga.pas
+++ /dev/null
@@ -1,285 +0,0 @@
-Unit wrtarga;
-
-{ Copyright (C) 1991-1996, Thomas G. Lane.
- Based on code contributed by Lee Daniel Crocker.
-
- This file contains routines to write output images in Targa format. }
-
-interface
-
-{$I jconfig.inc}
-
-uses
- jmorecfg,
- jpeglib,
- jdeferr,
- jerror,
- jinclude,
- jdmaster,
- cdjpeg; { Common decls for cjpeg/djpeg applications }
-
-function jinit_write_targa (cinfo : j_decompress_ptr) : djpeg_dest_ptr;
-
-implementation
-
-{ To support 12-bit JPEG data, we'd have to scale output down to 8 bits.
- This is not yet implemented. }
-
-{$ifndef BITS_IN_JSAMPLE_IS_8}
- Sorry, this code only copes with 8-bit JSAMPLEs. { deliberate syntax err }
-{$endif}
-
-{ The output buffer needs to be writable by fwrite(). On PCs, we must
- allocate the buffer in near data space, because we are assuming small-data
- memory model, wherein fwrite() can't reach far memory. If you need to
- process very wide images on a PC, you might have to compile in large-memory
- model, or else replace fwrite() with a putc() loop --- which will be much
- slower. }
-
-
-{ Private version of data destination object }
-
-type
- tga_dest_ptr = ^tga_dest_struct;
- tga_dest_struct = record
- pub : djpeg_dest_struct; { public fields }
-
- iobuffer : byteptr; { physical I/O buffer }
- buffer_width : JDIMENSION; { width of one row }
- end;
-
-{LOCAL}
-procedure write_header (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr;
- num_colors : int);
-{ Create and write a Targa header }
-var
- targaheader : array[0..18-1] of byte;
-begin
- { Set unused fields of header to 0 }
- MEMZERO(@targaheader, SIZEOF(targaheader));
-
- if (num_colors > 0) then
- begin
- targaheader[1] := 1; { color map type 1 }
- targaheader[5] := byte (num_colors and $FF);
- targaheader[6] := byte (num_colors shr 8);
- targaheader[7] := 24; { 24 bits per cmap entry }
- end;
-
- targaheader[12] := byte (cinfo^.output_width and $FF);
- targaheader[13] := byte (cinfo^.output_width shr 8);
- targaheader[14] := byte (cinfo^.output_height and $FF);
- targaheader[15] := byte (cinfo^.output_height shr 8);
- targaheader[17] := $20; { Top-down, non-interlaced }
-
- if (cinfo^.out_color_space = JCS_GRAYSCALE) then
- begin
- targaheader[2] := 3; { image type := uncompressed gray-scale }
- targaheader[16] := 8; { bits per pixel }
- end
- else
- begin { must be RGB }
- if (num_colors > 0) then
- begin
- targaheader[2] := 1; { image type = colormapped RGB }
- targaheader[16] := 8;
- end
- else
- begin
- targaheader[2] := 2; { image type = uncompressed RGB }
- targaheader[16] := 24;
- end;
- end;
-
- if (JFWRITE(dinfo^.output_file, @targaheader, 18) <> size_t (18)) then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
-end;
-
-{ Write some pixel data.
- In this module rows_supplied will always be 1. }
-
-{METHODDEF}
-procedure put_pixel_rows (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr;
- rows_supplied : JDIMENSION); far;
-{ used for unquantized full-color output }
-var
- dest : tga_dest_ptr;
- {register} inptr : RGBptr;
- {register} outptr : BGRptr;
- {register} col : JDIMENSION;
-begin
- dest := tga_dest_ptr (dinfo);
-
- inptr := RGBptr(dest^.pub.buffer^[0]);
- outptr := BGRptr(dest^.iobuffer);
- for col := pred(cinfo^.output_width) downto 0 do
- begin
- outptr^.b := byte (GETJSAMPLE(inptr^.b)); { RGB to BGR order }
- outptr^.g := byte (GETJSAMPLE(inptr^.g));
- outptr^.r := byte (GETJSAMPLE(inptr^.r));
- Inc(inptr);
- Inc(outptr);
- end;
- {void} JFWRITE(dest^.pub.output_file, dest^.iobuffer, dest^.buffer_width);
-end;
-
-{METHODDEF}
-procedure put_gray_rows (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr;
- rows_supplied : JDIMENSION); far;
-{ used for grayscale OR quantized color output }
-var
- dest : tga_dest_ptr;
- {register} inptr : JSAMPLE_PTR;
- {register} outptr : byteptr;
- {register} col : JDIMENSION;
-begin
- dest := tga_dest_ptr (dinfo);
-
- inptr := JSAMPLE_PTR(dest^.pub.buffer^[0]);
- outptr := dest^.iobuffer;
- for col := pred(cinfo^.output_width) downto 0 do
- begin
- outptr^ := byte( GETJSAMPLE(inptr^) );
- Inc(inptr);
- Inc(outptr);
- end;
- {void} JFWRITE(dest^.pub.output_file, dest^.iobuffer, dest^.buffer_width);
-end;
-
-
-{ Write some demapped pixel data when color quantization is in effect.
- For Targa, this is only applied to grayscale data. }
-
-{METHODDEF}
-procedure put_demapped_gray (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr;
- rows_supplied : JDIMENSION); far;
-var
- dest : tga_dest_ptr;
- {register} inptr : JSAMPLE_PTR;
- {register} outptr : byteptr;
- {register} color_map0 : JSAMPROW;
- {register} col : JDIMENSION;
-begin
- dest := tga_dest_ptr (dinfo);
- color_map0 := cinfo^.colormap^[0];
-
- inptr := JSAMPLE_PTR(dest^.pub.buffer^[0]);
- outptr := dest^.iobuffer;
- for col := pred(cinfo^.output_width) downto 0 do
- begin
- outptr^ := byte( GETJSAMPLE(color_map0^[GETJSAMPLE(inptr^)]) );
- Inc(inptr);
- Inc(outptr);
- end;
- {void} JFWRITE(dest^.pub.output_file, dest^.iobuffer, dest^.buffer_width);
-end;
-
-
-{ Startup: write the file header. }
-
-{METHODDEF}
-procedure start_output_tga (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr); far;
-var
- dest : tga_dest_ptr;
- num_colors, i : int;
- outfile : FILEptr;
-var
- output_color_map : Array[0..255] of BGRtype;
-begin
- dest := tga_dest_ptr (dinfo);
-
- if (cinfo^.out_color_space = JCS_GRAYSCALE) then
- begin
- { Targa doesn't have a mapped grayscale format, so we will }
- { demap quantized gray output. Never emit a colormap. }
- write_header(cinfo, dinfo, 0);
- if (cinfo^.quantize_colors) then
- dest^.pub.put_pixel_rows := put_demapped_gray
- else
- dest^.pub.put_pixel_rows := put_gray_rows;
- end
- else
- if (cinfo^.out_color_space = JCS_RGB) then
- begin
- if (cinfo^.quantize_colors) then
- begin
- { We only support 8-bit colormap indexes, so only 256 colors }
- num_colors := cinfo^.actual_number_of_colors;
- if (num_colors > 256) then
- ERREXIT1(j_common_ptr(cinfo), JERR_TOO_MANY_COLORS, num_colors);
- write_header(cinfo, dinfo, num_colors);
- { Write the colormap. Note Targa uses BGR byte order }
- outfile := dest^.pub.output_file;
- for i := 0 to pred(num_colors) do
- begin
- output_color_map[i].b := cinfo^.colormap^[2]^[i];
- output_color_map[i].g := cinfo^.colormap^[1]^[i];
- output_color_map[i].r := cinfo^.colormap^[0]^[i];
- end;
- JFWRITE(outfile, @output_color_map, num_colors*3);
- dest^.pub.put_pixel_rows := put_gray_rows;
- end
- else
- begin
- write_header(cinfo, dinfo, 0);
- dest^.pub.put_pixel_rows := put_pixel_rows;
- end;
- end
- else
- begin
- ERREXIT(j_common_ptr(cinfo), JERR_TGA_COLORSPACE);
- end;
-end;
-
-
-{ Finish up at the end of the file. }
-
-{METHODDEF}
-procedure finish_output_tga (cinfo : j_decompress_ptr;
- dinfo : djpeg_dest_ptr); far;
-begin
- { Make sure we wrote the output file OK }
- {fflush(dinfo^.output_file^);
- if (ferror(dinfo^.output_file)) then
- ERREXIT(j_common_ptr(cinfo), JERR_FILE_WRITE);
- }
-end;
-
-
-{ The module selection routine for Targa format output. }
-
-{GLOBAL}
-function jinit_write_targa (cinfo : j_decompress_ptr) : djpeg_dest_ptr;
-var
- dest : tga_dest_ptr;
-begin
- { Create module interface object, fill in method pointers }
- dest := tga_dest_ptr(
- cinfo^.mem^.alloc_small (j_common_ptr (cinfo), JPOOL_IMAGE,
- SIZEOF(tga_dest_struct)) );
- dest^.pub.start_output := start_output_tga;
- dest^.pub.finish_output := finish_output_tga;
-
- { Calculate output image dimensions so we can allocate space }
- jpeg_calc_output_dimensions(cinfo);
-
- { Create I/O buffer. Note we make this near on a PC. }
- dest^.buffer_width := cinfo^.output_width * cinfo^.output_components;
- dest^.iobuffer := byteptr(
- cinfo^.mem^.alloc_small (j_common_ptr (cinfo), JPOOL_IMAGE,
- size_t (dest^.buffer_width * SIZEOF(byte))));
-
- { Create decompressor output buffer. }
- dest^.pub.buffer := cinfo^.mem^.alloc_sarray
- (j_common_ptr (cinfo), JPOOL_IMAGE, dest^.buffer_width, JDIMENSION (1));
- dest^.pub.buffer_height := 1;
-
- jinit_write_targa := djpeg_dest_ptr (dest);
-end;
-
-end. { TARGA_SUPPORTED }