Преглед на файлове

* added multithreaded lzx compression for lzx. Must be enabled with -dLZX_USETHREADS
* Updated makefile.fpc and Makefile for packages/chm

git-svn-id: trunk@13819 -

andrew преди 16 години
родител
ревизия
8ebab7b2c1
променени са 7 файла, в които са добавени 657 реда и са изтрити 71 реда
  1. 1 0
      .gitattributes
  2. 59 59
      packages/chm/Makefile
  3. 1 1
      packages/chm/Makefile.fpc
  4. 6 1
      packages/chm/fpmake.pp
  5. 52 1
      packages/chm/src/chmwriter.pas
  6. 529 0
      packages/chm/src/lzxcompressthread.pas
  7. 9 9
      packages/chm/src/paslzxcomp.pas

+ 1 - 0
.gitattributes

@@ -977,6 +977,7 @@ packages/chm/src/chmwriter.pas svneol=native#text/plain
 packages/chm/src/fasthtmlparser.pas svneol=native#text/plain
 packages/chm/src/fasthtmlparser.pas svneol=native#text/plain
 packages/chm/src/htmlindexer.pas svneol=native#text/plain
 packages/chm/src/htmlindexer.pas svneol=native#text/plain
 packages/chm/src/htmlutil.pas svneol=native#text/plain
 packages/chm/src/htmlutil.pas svneol=native#text/plain
+packages/chm/src/lzxcompressthread.pas svneol=native#text/plain
 packages/chm/src/paslznonslide.pas svneol=native#text/plain
 packages/chm/src/paslznonslide.pas svneol=native#text/plain
 packages/chm/src/paslzx.pas svneol=native#text/plain
 packages/chm/src/paslzx.pas svneol=native#text/plain
 packages/chm/src/paslzxcomp.pas svneol=native#text/plain
 packages/chm/src/paslzxcomp.pas svneol=native#text/plain

+ 59 - 59
packages/chm/Makefile

@@ -1,5 +1,5 @@
 #
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/08/02]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/10/03]
 #
 #
 default: all
 default: all
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku 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-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku 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-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded
@@ -441,178 +441,178 @@ ifeq ($(FULL_TARGET),armeb-embedded)
 override TARGET_PROGRAMS+=chmcmd chmls
 override TARGET_PROGRAMS+=chmcmd chmls
 endif
 endif
 ifeq ($(FULL_TARGET),i386-linux)
 ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
 ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-win32)
 ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-os2)
 ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
 ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-beos)
 ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-haiku)
 ifeq ($(FULL_TARGET),i386-haiku)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-netbsd)
 ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-solaris)
 ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-qnx)
 ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-netware)
 ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-openbsd)
 ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-wdosx)
 ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-darwin)
 ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-emx)
 ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-watcom)
 ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-netwlibc)
 ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-wince)
 ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-embedded)
 ifeq ($(FULL_TARGET),i386-embedded)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),i386-symbian)
 ifeq ($(FULL_TARGET),i386-symbian)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
 ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
 ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
 ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-amiga)
 ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-atari)
 ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-openbsd)
 ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-palmos)
 ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-embedded)
 ifeq ($(FULL_TARGET),m68k-embedded)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
 ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
 ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-amiga)
 ifeq ($(FULL_TARGET),powerpc-amiga)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-macos)
 ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-darwin)
 ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-morphos)
 ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-embedded)
 ifeq ($(FULL_TARGET),powerpc-embedded)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
 ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
 ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),sparc-solaris)
 ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),sparc-embedded)
 ifeq ($(FULL_TARGET),sparc-embedded)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
 ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
 ifeq ($(FULL_TARGET),x86_64-darwin)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),x86_64-win64)
 ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),x86_64-embedded)
 ifeq ($(FULL_TARGET),x86_64-embedded)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),arm-linux)
 ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
 ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),arm-darwin)
 ifeq ($(FULL_TARGET),arm-darwin)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),arm-wince)
 ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),arm-gba)
 ifeq ($(FULL_TARGET),arm-gba)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),arm-nds)
 ifeq ($(FULL_TARGET),arm-nds)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),arm-embedded)
 ifeq ($(FULL_TARGET),arm-embedded)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),arm-symbian)
 ifeq ($(FULL_TARGET),arm-symbian)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
 ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc64-darwin)
 ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
 ifeq ($(FULL_TARGET),powerpc64-embedded)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),avr-embedded)
 ifeq ($(FULL_TARGET),avr-embedded)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),armeb-linux)
 ifeq ($(FULL_TARGET),armeb-linux)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 ifeq ($(FULL_TARGET),armeb-embedded)
 ifeq ($(FULL_TARGET),armeb-embedded)
-override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain
+override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread
 endif
 endif
 override INSTALL_FPCPACKAGE=y
 override INSTALL_FPCPACKAGE=y
 ifeq ($(FULL_TARGET),i386-linux)
 ifeq ($(FULL_TARGET),i386-linux)

+ 1 - 1
packages/chm/Makefile.fpc

@@ -9,7 +9,7 @@ version=2.5.1
 [target]
 [target]
 units=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes \
 units=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes \
       chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer \
       chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer \
-      chmfiftimain
+      chmfiftimain lzxcompressthread
 programs=chmcmd chmls
 programs=chmcmd chmls
 examples=
 examples=
 
 

+ 6 - 1
packages/chm/fpmake.pp

@@ -56,7 +56,7 @@ begin
         end;
         end;
     T:=P.Targets.AddUnit('chmtypes.pas');
     T:=P.Targets.AddUnit('chmtypes.pas');
       with T.Dependencies do
       with T.Dependencies do
-        begin
+       begin
           AddUnit('chmbase');
           AddUnit('chmbase');
         end;
         end;
     T:=P.Targets.AddUnit('htmlindexer.pas');
     T:=P.Targets.AddUnit('htmlindexer.pas');
@@ -74,6 +74,11 @@ begin
           AddUnit('paslzxcomp');
           AddUnit('paslzxcomp');
           AddUnit('chmfiftimain');
           AddUnit('chmfiftimain');
         end;
         end;
+    T:=P.Targets.AddUnit('lzxcompressthread');
+      with T.Dependencies do
+        begin
+          AddUnit('paslzxcomp');
+        end;
     T:=P.Targets.AddUnit('fasthtmlparser.pas');
     T:=P.Targets.AddUnit('fasthtmlparser.pas');
     T:=P.Targets.AddUnit('htmlutil.pas');
     T:=P.Targets.AddUnit('htmlutil.pas');
     T:=P.Targets.AddUnit('paslznonslide.pas');
     T:=P.Targets.AddUnit('paslznonslide.pas');

+ 52 - 1
packages/chm/src/chmwriter.pas

@@ -20,9 +20,10 @@
 }
 }
 unit chmwriter;
 unit chmwriter;
 {$MODE OBJFPC}{$H+}
 {$MODE OBJFPC}{$H+}
+{ $DEFINE LZX_USETHREADS}
 
 
 interface
 interface
-uses Classes, ChmBase, chmtypes, chmspecialfiles, HtmlIndexer, chmsitemap, Avl_Tree;
+uses Classes, ChmBase, chmtypes, chmspecialfiles, HtmlIndexer, chmsitemap, Avl_Tree{$IFDEF LZX_USETHREADS}, lzxcompressthread{$ENDIF};
 
 
 type
 type
 
 
@@ -129,6 +130,14 @@ Type
     function  WriteCompressedData(Count: Longint; Buffer: Pointer): LongInt;
     function  WriteCompressedData(Count: Longint; Buffer: Pointer): LongInt;
     procedure MarkFrame(UnCompressedTotal, CompressedTotal: LongWord);
     procedure MarkFrame(UnCompressedTotal, CompressedTotal: LongWord);
     // end callbacks
     // end callbacks
+    {$IFDEF LZX_USETHREADS}
+    // callbacks for lzx compress threads
+    function  LTGetData(Sender: TLZXCompressor; WantedByteCount: Integer; Buffer: Pointer): Integer;
+    function  LTIsEndOfFile(Sender: TLZXCompressor): Boolean;
+    procedure LTChunkDone(Sender: TLZXCompressor; CompressedSize: Integer; UncompressedSize: Integer; Buffer: Pointer);
+    procedure LTMarkFrame(Sender: TLZXCompressor; CompressedTotal: Integer; UncompressedTotal: Integer);
+    {$ENDIF}
+    // end callbacks
   public
   public
     constructor Create(OutStream: TStream; FreeStreamOnDestroy: Boolean);
     constructor Create(OutStream: TStream; FreeStreamOnDestroy: Boolean);
     destructor Destroy; override;
     destructor Destroy; override;
@@ -1091,6 +1100,33 @@ begin
   // We have to trim the last entry off when we are done because there is no next block in that case
   // We have to trim the last entry off when we are done because there is no next block in that case
 end;
 end;
 
 
+{$IFDEF LZX_USETHREADS}
+function TChmWriter.LTGetData(Sender: TLZXCompressor; WantedByteCount: Integer;
+  Buffer: Pointer): Integer;
+begin
+  Result := GetData(WantedByteCount, Buffer);
+  //WriteLn('Wanted ', WantedByteCount, ' got ', Result);
+end;
+
+function TChmWriter.LTIsEndOfFile(Sender: TLZXCompressor): Boolean;
+begin
+  Result := AtEndOfData;
+end;
+
+procedure TChmWriter.LTChunkDone(Sender: TLZXCompressor;
+  CompressedSize: Integer; UncompressedSize: Integer; Buffer: Pointer);
+begin
+  WriteCompressedData(CompressedSize, Buffer);
+end;
+
+procedure TChmWriter.LTMarkFrame(Sender: TLZXCompressor;
+  CompressedTotal: Integer; UncompressedTotal: Integer);
+begin
+  MarkFrame(UncompressedTotal, CompressedTotal);
+  //WriteLn('Mark Frame C = ', CompressedTotal, ' U = ', UncompressedTotal);
+end;
+{$ENDIF}
+
 procedure TChmWriter.CheckFileMakeSearchable(AStream: TStream; AFileEntry: TFileEntryRec);
 procedure TChmWriter.CheckFileMakeSearchable(AStream: TStream; AFileEntry: TFileEntryRec);
 
 
   var
   var
@@ -1487,9 +1523,14 @@ end;
 
 
 procedure TChmWriter.StartCompressingStream;
 procedure TChmWriter.StartCompressingStream;
 var
 var
+  {$IFNDEF LZX_USETHREADS}
   LZXdata: Plzx_data;
   LZXdata: Plzx_data;
   WSize: LongInt;
   WSize: LongInt;
+  {$ELSE}
+  Compressor: TLZXCompressor;
+  {$ENDIF}
 begin
 begin
+ {$IFNDEF LZX_USETHREADS}
   lzx_init(@LZXdata, LZX_WINDOW_SIZE, @_GetData, Self, @_AtEndOfData,
   lzx_init(@LZXdata, LZX_WINDOW_SIZE, @_GetData, Self, @_AtEndOfData,
               @_WriteCompressedData, Self, @_MarkFrame, Self);
               @_WriteCompressedData, Self, @_MarkFrame, Self);
 
 
@@ -1503,6 +1544,16 @@ begin
   MarkFrame(LZXdata^.len_uncompressed_input, LZXdata^.len_compressed_output);
   MarkFrame(LZXdata^.len_uncompressed_input, LZXdata^.len_compressed_output);
 
 
   lzx_finish(LZXdata, nil);
   lzx_finish(LZXdata, nil);
+  {$ELSE}
+  Compressor := TLZXCompressor.Create(10);
+  Compressor.OnChunkDone  :=@LTChunkDone;
+  Compressor.OnGetData    :=@LTGetData;
+  Compressor.OnIsEndOfFile:=@LTIsEndOfFile;
+  Compressor.OnMarkFrame  :=@LTMarkFrame;
+  Compressor.Execute(True);
+  //Sleep(20000);
+  Compressor.Free;
+  {$ENDIF}
 end;
 end;
 
 
 end.
 end.

+ 529 - 0
packages/chm/src/lzxcompressthread.pas

@@ -0,0 +1,529 @@
+{ Copyright (C) <2009> <Andrew Haines> lzxcompressthread.pas
+
+  This library is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Library General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or (at your
+  option) any later version.
+
+  This program is distributed in the hope that it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
+  for more details.
+
+  You should have received a copy of the GNU Library General Public License
+  along with this library; if not, write to the Free Software Foundation,
+  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+}
+{
+  See the file COPYING.FPC, included in this distribution,
+  for details about the copyright.
+}
+unit lzxcompressthread;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, paslzxcomp;
+
+type
+  TLZXCompressor = class;
+  TLZXMasterThread = class;
+  TLZXWorkerThread = class;
+
+  TLZXGetDataMethod = function(Sender: TLZXCompressor; WantedByteCount: Integer; Buffer: Pointer): Integer of object;
+  TLZXIsEndOfFileMethod = function(Sender: TLZXCompressor): Boolean  of object;
+  TLZXChunkDoneMethod = procedure(Sender: TLZXCompressor; CompressedSize: Integer; UncompressedSize: Integer; Buffer: Pointer) of object;
+  TLZXMarkFrameMethod = procedure(Sender: TLZXCompressor; CompressedSize: Integer; UncompressedSize: Integer) of object;
+
+  PLZXFinishedBlock = ^TLZXFinishedBlock;
+  TLZXFinishedBlock = record
+    CompressedSize: Integer;
+    UnCompressedSize: Integer;
+    Frame1CSize,
+    Frame1USize,
+    Frame2CSize,
+    Frame2USize: Integer;
+    Index: Integer;
+    Data: Pointer;
+  end;
+
+  { TLZXCompressor }
+
+  TLZXCompressor = class(TObject)
+  private
+    FOnMarkFrame: TLZXMarkFrameMethod;
+    FThreadCount: Integer;
+    FBlockSize: Integer;
+    FTotalCompressedSize: DWord;
+    FTotalUnCompressedSize: DWord;
+    FOnChunkDone: TLZXChunkDoneMethod;
+    FOnGetData: TLZXGetDataMethod;
+    FOnIsEndOfFile: TLZXIsEndOfFileMethod;
+    FWindowSizeCode: Integer;
+    FinishedBlocks: TFPList;
+    NextBlockNeeded: Integer;
+    FMasterThread: TLZXMasterThread;
+    procedure BlockIsFinished(ABlock: PLZXFinishedBlock);
+    function GetRunning: Boolean;
+  public
+    constructor Create(AThreadCount: Integer);
+    destructor  Destroy; override;
+
+    procedure   Execute(WaitForFinish: Boolean = True);
+
+    property BlockSize: Integer read FBlockSize write FBlockSize;
+    property Running: Boolean read GetRunning;
+    property WindowSizeCode: Integer read FWindowSizeCode write FWindowSizeCode;
+
+    // the following properties must all be assigned
+    property OnGetData: TLZXGetDataMethod read FOnGetData write FOnGetData;
+    property OnChunkDone: TLZXChunkDoneMethod read FOnChunkDone write FOnChunkDone;
+    property OnIsEndOfFile: TLZXIsEndOfFileMethod read FOnIsEndOfFile write FOnIsEndOfFile;
+    property OnMarkFrame: TLZXMarkFrameMethod read FOnMarkFrame write FOnMarkFrame;
+  end;
+
+  { TLZXMasterThread }
+
+  TLZXMasterThread = class(TThread)
+    FCompressor: TLZXCompressor;
+    FBusyThreads: TFPList;
+    FLockData: TRTLCriticalSection;
+    FLockQueueThread: TRTLCriticalSection;
+    FDataRemains: Boolean;
+    FBlockNumber: Integer;
+    FRunning: Boolean;
+    FMemList: TFPList;
+
+    // only used inside a critical section!!
+    // belongs to a Worker thread which will free it
+    FTmpData: Pointer;
+    FTmpDataSize: Integer;
+
+    procedure UpdateDataRemains;
+
+    function  BlockDone(Worker: TLZXWorkerThread; ABlock: PLZXFinishedBlock): Boolean;
+    procedure WorkerFinished(Sender: TObject);
+    function GetFreeMemoryChunk: Pointer;
+
+
+    procedure Lock;
+    Procedure UnLock;
+    procedure LockTmpData;
+    procedure UnLockTmpData;
+    function Working: Boolean;
+    function DataRemains: Boolean;
+    function Running: Boolean;
+    function QueueThread(Thread: TLZXWorkerThread): Boolean;
+
+  public
+    procedure   Execute; override;
+    constructor Create(Compressor: TLZXCompressor);
+    destructor  Destroy; override;
+  end;
+
+  { TLZXWorkerThread }
+
+  TLZXWorkerThread = class(TThread)
+  private
+    Data: PByte;
+    DataSize: Integer;
+    DataCursor: Integer;
+    Frame1C,
+    Frame1U,
+    Frame2C,
+    Frame2U: Integer;
+
+    LZXData: Plzx_data;
+
+    CompressedData: PByte;
+    CompressedDataSize: Integer; // compressed written size. not the size of the array
+
+    BlockNumber: Integer;
+
+    WindowSizeCode: Integer;
+    BlockSize: Integer;
+
+    MasterThread: TLZXMasterThread;
+    ShouldSuspend: Boolean;
+
+    // callbacks for lzxcomp
+    function    GetBytes(ACount: Longint; ABuffer: Pointer): LongInt; cdecl;
+    function    WriteBytes(ACount: LongInt; ABuffer: Pointer): LongInt; cdecl;
+    procedure   MarkFrame(UnCompressedSize: DWord; CompressedSize: DWord); cdecl;
+    function    IsEndOfFile: LongBool; cdecl;
+    // end callbacks
+    procedure   NotifyMasterDone;
+  protected
+    procedure   Execute; override;
+  public
+    procedure   CompressData(ABlockNumber: Integer);
+
+    constructor Create(AMaster: TLZXMasterThread; AWindowSizeCode: Integer; ABlockSize: Integer);
+    destructor  Destroy; override;
+  end;
+
+implementation
+uses
+  Sysutils; // for Sleep()
+
+{ TLZXCompressor }
+
+procedure TLZXCompressor.BlockIsFinished(ABlock: PLZXFinishedBlock);
+  procedure SendChunk(AChunk: PLZXFinishedBlock);
+  begin
+    if Assigned(FOnMarkFrame) then
+    begin
+      Inc(FTotalCompressedSize, AChunk^.Frame1CSize);
+      Inc(FTotalUnCompressedSize, AChunk^.Frame1USize);
+      Inc(NextBlockNeeded);
+
+      FOnMarkFrame(Self, FTotalCompressedSize, FTotalUnCompressedSize);
+
+      if AChunk^.Frame2CSize > 0 then
+      begin
+        Inc(FTotalCompressedSize, AChunk^.Frame2CSize);
+        Inc(FTotalUnCompressedSize, AChunk^.Frame2USize);
+        FOnMarkFrame(Self, FTotalCompressedSize, FTotalUnCompressedSize);
+      end;
+    end;
+
+    FOnChunkDone(Self, AChunk^.CompressedSize, AChunk^.UnCompressedSize, AChunk^.Data);
+    FMasterThread.FMemList.Add(AChunk^.Data);
+    Dispose(AChunk);
+  end;
+var
+  TmpBlock  : PLZXFinishedBlock;
+  FoundMatch: Boolean;
+  i: Integer;
+
+begin
+  if NextBlockNeeded = ABlock^.Index then
+    SendChunk(ABlock)
+  else
+    FinishedBlocks.Add(ABlock);
+
+  repeat
+    FoundMatch := False;
+    for i := FinishedBlocks.Count-1 downto 0 do
+    begin
+      TmpBlock := PLZXFinishedBlock(FinishedBlocks.Items[i]);
+      if TmpBlock^.Index = NextBlockNeeded then
+      begin
+        FoundMatch := True;
+        SendChunk(TmpBlock);
+        FinishedBlocks.Delete(i);
+      end;
+    end;
+  until not FoundMatch;
+end;
+
+function TLZXCompressor.GetRunning: Boolean;
+begin
+  Result := FMasterThread.Running;
+end;
+
+constructor TLZXCompressor.Create(AThreadCount: Integer);
+begin
+  inherited Create;
+  FThreadCount    := AThreadCount;
+  FBlockSize      := 1 shl 16 ; // $10000;
+  FWindowSizeCode := 16;
+  FMasterThread := TLZXMasterThread.Create(Self);
+  FinishedBlocks := TFPList.Create;
+end;
+
+destructor TLZXCompressor.Destroy;
+begin
+  FMasterThread.Free;
+  FinishedBlocks.Free;
+  inherited Destroy;
+end;
+
+procedure TLZXCompressor.Execute(WaitForFinish: Boolean = True);
+begin
+    FTotalCompressedSize := 0;
+    FTotalUnCompressedSize := 0;
+    FMasterThread.FRunning:=True;
+    FMasterThread.Resume;
+    if WaitForFinish then
+      While Running do
+        CheckSynchronize(50);
+end;
+
+{ TLZXMasterThread }
+
+procedure TLZXMasterThread.UpdateDataRemains;
+begin
+  FDataRemains := not FCompressor.FOnIsEndOfFile(FCompressor);
+end;
+
+function TLZXMasterThread.BlockDone(Worker: TLZXWorkerThread; ABlock: PLZXFinishedBlock): Boolean;
+begin
+  Lock;
+  REsult := True;
+  FCompressor.BlockIsFinished(ABlock);
+  if DataRemains then
+    QueueThread(Worker)
+  else
+  begin
+    Result := False;
+    FBusyThreads.Remove(Worker);
+    Worker.Terminate;
+    if FBusyThreads.Count = 0 then
+      Resume;
+  end;
+  Unlock;
+end;
+
+procedure TLZXMasterThread.WorkerFinished(Sender: TObject);
+begin
+  FBusyThreads.Remove(Sender);
+  if TThread(Sender).FatalException <> nil then
+    Raise Exception(TThread(Sender).FatalException);
+  Sender.Free;
+end;
+
+function TLZXMasterThread.GetFreeMemoryChunk: Pointer;
+begin
+  if FMemList.Count >0 then
+  begin
+    Result := FMemList.Items[0];
+    FMemList.Delete(0);
+  end
+  else
+    Result := Getmem(FCompressor.BlockSize);
+end;
+
+procedure TLZXMasterThread.Lock;
+begin
+  EnterCriticalsection(FLockData);
+end;
+
+procedure TLZXMasterThread.UnLock;
+begin
+  LeaveCriticalsection(FLockData);
+end;
+
+procedure TLZXMasterThread.LockTmpData;
+begin
+  EnterCriticalsection(FLockQueueThread);
+end;
+
+procedure TLZXMasterThread.UnLockTmpData;
+begin
+  LeaveCriticalsection(FLockQueueThread);
+end;
+
+function TLZXMasterThread.Working: Boolean;
+begin
+  Result := FBusyThreads.Count > 0;
+end;
+
+function TLZXMasterThread.DataRemains: Boolean;
+begin
+  UpdateDataRemains;
+  Result := FDataRemains;
+end;
+
+function TLZXMasterThread.Running: Boolean;
+begin
+  REsult := FRunning;
+end;
+
+function TLZXMasterThread.QueueThread(Thread: TLZXWorkerThread): Boolean;
+begin
+  LockTmpData;
+
+  Result := DataRemains;
+  if Not Result then
+  begin
+    UnLockTmpData;
+    Exit;
+  end;
+
+  FDataRemains := False;
+
+  Thread.DataSize := FCompressor.OnGetData(FCompressor, FCompressor.FBlockSize, Thread.Data);
+
+  Thread.CompressData(FBlockNumber);
+  Inc(FBlockNumber);
+  Thread.Resume;
+  UnLockTmpData;
+end;
+
+procedure TLZXMasterThread.Execute;
+var
+  i: Integer;
+  Thread: TLZXWorkerThread;
+begin
+  FRunning:= True;
+  for i := 0 to FCompressor.FThreadCount-1 do
+  begin
+    Thread := TLZXWorkerThread.Create(Self, FCompressor.WindowSizeCode, FCompressor.BlockSize);
+    Thread.FreeOnTerminate := True;
+    Thread.OnTerminate:= @WorkerFinished;
+    if QueueThread(Thread) then
+      FBusyThreads.Add(Thread);
+  end;
+  //Suspend;
+  while Working do
+  begin
+      Sleep(50);
+  end;
+  FRunning:= False;
+end;
+
+constructor TLZXMasterThread.Create(Compressor: TLZXCompressor);
+begin
+  Inherited Create(True);
+  FCompressor  := Compressor;
+  FDataRemains := True;
+  FBusyThreads := TFPList.Create;
+  FMemList := TFPList.Create;
+  InitCriticalSection(FLockData);
+  InitCriticalSection(FLockQueueThread);
+end;
+
+destructor TLZXMasterThread.Destroy;
+var
+  i: Integer;
+begin
+  DoneCriticalsection(FLockData);
+  DoneCriticalsection(FLockQueueThread);
+
+  for i := 0 to FBusyThreads.Count-1 do TObject(FBusyThreads.Items[i]).Free;
+  for i := 0 to FMemList.Count-1 do Freemem(FMemList.Items[i]);
+
+  FBusyThreads.Free;
+  FMemList.Free;
+
+  inherited Destroy;
+end;
+
+{ TLZXWorkerThread }
+
+function TLZXWorkerThread.GetBytes(ACount: Longint; ABuffer: Pointer): LongInt; cdecl;
+var
+  MaxBytes: Integer;
+begin
+  MaxBytes := DataSize - DataCursor;
+
+  if ACount > MaxBytes then
+    ACount := MaxBytes;
+
+  Move(Data[DataCursor], ABuffer^, ACount);
+  Inc(DataCursor, ACount);
+
+  Result := ACount;
+end;
+
+function TLZXWorkerThread.WriteBytes(ACount: LongInt; ABuffer: Pointer
+  ): LongInt; cdecl;
+begin
+  Move(ABuffer^, CompressedData[CompressedDataSize], ACount);
+  Inc(CompressedDataSize, ACount);
+  Result := ACount;
+end;
+
+procedure TLZXWorkerThread.MarkFrame(UnCompressedSize: DWord;
+  CompressedSize: DWord); cdecl;
+begin
+  if Frame1C = 0 then
+  begin
+    Frame1C := CompressedSize;
+    Frame1U := UnCompressedSize;
+  end
+  else
+  begin
+    Frame2C := CompressedSize;
+    Frame2U := UnCompressedSize;
+  end;
+end;
+
+function TLZXWorkerThread.IsEndOfFile: LongBool; cdecl;
+begin
+  Result := LongBool(DataSize - DataCursor <= 0);
+end;
+
+procedure TLZXWorkerThread.NotifyMasterDone;
+var
+  Block: PLZXFinishedBlock;
+begin
+  LZXData^.len_compressed_output:=0;
+  LZXData^.len_uncompressed_input:=0;
+
+  New(Block);
+  Block^.Data            :=  MasterThread.GetFreeMemoryChunk;
+  Move(CompressedData^, Block^.Data^, CompressedDataSize);
+  Block^.CompressedSize  := CompressedDataSize;
+  Block^.UnCompressedSize:= DataSize;
+  Block^.Index           := BlockNumber;
+  Block^.Frame1CSize      := Frame1C;
+  Block^.Frame2CSize      := Frame2C-Frame1C;
+  Block^.Frame1USize      := Frame1U;
+  Block^.Frame2USize      := Frame2U-Frame1U;
+
+  Frame1C := 0;
+  Frame2C := 0;
+  Frame1U := 0;
+  Frame2U := 0;
+
+  ShouldSuspend := not MasterThread.BlockDone(Self, Block);
+
+end;
+
+procedure TLZXWorkerThread.CompressData(ABlockNumber: Integer);
+begin
+  BlockNumber := ABlockNumber;
+  DataCursor := 0;
+  CompressedDataSize := 0;
+end;
+
+procedure TLZXWorkerThread.Execute;
+var
+  WSize: LongInt;
+begin
+  WSize := 1 shl WindowSizeCode;
+  while not Terminated do
+  begin
+    lzx_reset(LZXdata);
+    lzx_compress_block(LZXdata, WSize, True);
+
+    MasterThread.Synchronize(@NotifyMasterDone);
+
+    if ShouldSuspend then
+      Suspend;
+  end;
+end;
+
+constructor TLZXWorkerThread.Create(AMaster: TLZXMasterThread;
+  AWindowSizeCode: Integer; ABlockSize: Integer);
+begin
+  Inherited Create(True);
+  MasterThread := AMaster;
+  WindowSizeCode := AWindowSizeCode;
+  BlockSize     := ABlockSize;
+  FreeOnTerminate := True;
+
+  Data  := GetMem(ABlockSize);
+  CompressedData:=GetMem(ABlockSize);
+
+  lzx_init(@LZXdata, longint(WindowSizeCode),
+           TGetBytesFunc(@TLZXWorkerThread.GetBytes), Self,
+           TIsEndOfFileFunc(@TLZXWorkerThread.IsEndOfFile),
+           TWriteBytesFunc(@TLZXWorkerThread.WriteBytes), Self,
+           TMarkFrameFunc(@TLZXWorkerThread.MarkFrame), Self);
+end;
+
+destructor TLZXWorkerThread.Destroy;
+begin
+  lzx_finish(LZXdata, nil);
+  Freemem(Data);
+  FreeMem(CompressedData);
+  inherited Destroy;
+end;
+
+end.
+

+ 9 - 9
packages/chm/src/paslzxcomp.pas

@@ -710,11 +710,11 @@ begin
     end
     end
     else begin
     else begin
       mask_bits := (1 shl shift_bits) - 1;
       mask_bits := (1 shl shift_bits) - 1;
-      lzxd^.bit_buf := lzxd^.bit_buf shl shift_bits;
-      lzxd^.bit_buf := lzxd^.bit_buf or (bits shr rshift_bits) and mask_bits;
+      lzxd^.bit_buf := word(lzxd^.bit_buf shl shift_bits);
+      lzxd^.bit_buf := word(lzxd^.bit_buf or (bits shr rshift_bits) and mask_bits);
     end;
     end;
 {$IFDEF ENDIAN_BIG}
 {$IFDEF ENDIAN_BIG}
-    lzxd^.bit_buf := ((lzxd^.bit_buf and $FF)shl 8) or (lzxd^.bit_buf shr 8);
+    lzxd^.bit_buf := word(((lzxd^.bit_buf and $FF)shl 8) or (lzxd^.bit_buf shr 8));
 {$ENDIF}
 {$ENDIF}
     lzxd^.put_bytes(lzxd^.out_arg, sizeof(lzxd^.bit_buf), @lzxd^.bit_buf);
     lzxd^.put_bytes(lzxd^.out_arg, sizeof(lzxd^.bit_buf), @lzxd^.bit_buf);
     Inc(lzxd^.len_compressed_output, sizeof(lzxd^.bit_buf));
     Inc(lzxd^.len_compressed_output, sizeof(lzxd^.bit_buf));
@@ -726,8 +726,8 @@ begin
   //   otherwise move bits in */
   //   otherwise move bits in */
   shift_bits := nbits;
   shift_bits := nbits;
   mask_bits := (1 shl shift_bits) - 1;
   mask_bits := (1 shl shift_bits) - 1;
-  lzxd^.bit_buf := lzxd^.bit_buf shl shift_bits;
-  lzxd^.bit_buf := lzxd^.bit_buf or bits and mask_bits;
+  lzxd^.bit_buf := word(lzxd^.bit_buf shl shift_bits);
+  lzxd^.bit_buf := word(lzxd^.bit_buf or bits and mask_bits);
   Inc(cur_bits, nbits);
   Inc(cur_bits, nbits);
 
 
   lzxd^.bits_in_buf := cur_bits;
   lzxd^.bits_in_buf := cur_bits;
@@ -892,8 +892,8 @@ begin
 	  Inc(freqs[19]);
 	  Inc(freqs[19]);
 	  //* right, MS lies again.  Code is NOT
 	  //* right, MS lies again.  Code is NOT
 	  //   prev_len + len (mod 17), it's prev_len - len (mod 17)*/
 	  //   prev_len + len (mod 17), it's prev_len - len (mod 17)*/
-	  codep^ := prevlengths[i-cur_run] - last_len;
-	  if (codep^ > 16) then Inc(codep^, 17);
+	  codep^ := byte(prevlengths[i-cur_run] - last_len);
+	  if (codep^ > 16) then codep^ := byte(codep^ + 17); //Inc(codep^, 17);
 	  Inc(freqs[codep^]);
 	  Inc(freqs[codep^]);
           Inc(codep);
           Inc(codep);
 	  runp^ := 0; //* not necessary */
 	  runp^ := 0; //* not necessary */
@@ -901,8 +901,8 @@ begin
 	  Dec(cur_run, excess+4);
 	  Dec(cur_run, excess+4);
         end;
         end;
 	while (cur_run > 0) do begin
 	while (cur_run > 0) do begin
-	  codep^ := prevlengths[i-cur_run] - last_len;
-	  if (codep^ > 16) then Inc(codep^, 17);
+	  codep^ := byte(prevlengths[i-cur_run] - last_len);
+	  if (codep^ > 16) then codep^ := byte(codep^ + 17); //Inc(codep^, byte(17));
 	  runp^ := 0; //* not necessary */
 	  runp^ := 0; //* not necessary */
           Inc(runp);
           Inc(runp);
 	  Dec(cur_run);
 	  Dec(cur_run);