[sword-svn] r492 - in branches/BCB5: . TNGImage TNGImage/Docs TNGImage/Package stage

chrislit at crosswire.org chrislit at crosswire.org
Fri Feb 27 21:09:35 MST 2009


Author: chrislit
Date: 2009-02-27 21:09:35 -0700 (Fri, 27 Feb 2009)
New Revision: 492

Added:
   branches/BCB5/TNGImage/
   branches/BCB5/TNGImage/Docs/
   branches/BCB5/TNGImage/Docs/CHANGES.txt
   branches/BCB5/TNGImage/Docs/INSTALL.txt
   branches/BCB5/TNGImage/Docs/LATEBINDING.txt
   branches/BCB5/TNGImage/Docs/LIBMNG_DLL.txt
   branches/BCB5/TNGImage/Docs/LICENSE.txt
   branches/BCB5/TNGImage/Docs/MNGVIDEO.txt
   branches/BCB5/TNGImage/Docs/REDIST.txt
   branches/BCB5/TNGImage/Docs/USAGE.txt
   branches/BCB5/TNGImage/Package/
   branches/BCB5/TNGImage/Package/NGBitmap.pas
   branches/BCB5/TNGImage/Package/NGConst.pas
   branches/BCB5/TNGImage/Package/NGDefs.inc
   branches/BCB5/TNGImage/Package/NGImages.pas
   branches/BCB5/TNGImage/Package/NGJPEG.pas
   branches/BCB5/TNGImage/Package/NGTypes.pas
   branches/BCB5/TNGImage/Package/RegNG.pas
   branches/BCB5/TNGImage/TNGImage.bpk
   branches/BCB5/TNGImage/TNGImage.cpp
   branches/BCB5/TNGImage/TNGImage.res
   branches/BCB5/TNGImage/libmng.dll
   branches/BCB5/TNGImage/libmng.png
   branches/BCB5/stage/libmng.dll
Modified:
   branches/BCB5/RxRichEditX.cpp
   branches/BCB5/sword.bpr
   branches/BCB5/sword.cpp
   branches/BCB5/sword.res
   branches/BCB5/swordprj.bpg
Log:
added PNG support


Modified: branches/BCB5/RxRichEditX.cpp
===================================================================
--- branches/BCB5/RxRichEditX.cpp	2009-02-14 17:15:14 UTC (rev 491)
+++ branches/BCB5/RxRichEditX.cpp	2009-02-28 04:09:35 UTC (rev 492)
@@ -4,6 +4,7 @@
 #pragma hdrstop
 
 #include "TntSystem.hpp"
+#include "RegNG.hpp"
 #include "RxRichEditX.h"
 #include "PrintFrm.h"
 #include <clipbrd.hpp>
@@ -1089,10 +1090,11 @@
 //filePath=tmp;
 	TImage *image = new TImage(this);
 	TJPEGImage *ji = new TJPEGImage();
+    TNGImage *pi = new TNGImage();
 	Graphics::TBitmap *bitmap = new Graphics::TBitmap();
 	try {
 	int len = strlen(filePath);
-	if ((len > 4) && (!::stricmp(filePath+(len-4), ".jpg"))) {
+	if ((len > 4) && (!::stricmp(filePath+(len-4), ".jpg")) || (len > 5) && (!::stricmp(filePath+(len-5), ".jpeg"))) {
 //		ji->LoadFromFile(filePath);
 		TFileStream* imageFile;
 		imageFile = new TFileStream(filePath,fmOpenRead|fmShareCompat);
@@ -1107,12 +1109,23 @@
 		image->Canvas->Draw(0, 0, ji);
 //		image->Picture->Bitmap->Assign(ji);
 	}
+    else if ((len > 4) && (!::stricmp(filePath+(len-4), ".png"))) {
+// add .mng/.jng handling above, if desired, both are supported by TNGImage
+		TFileStream* imageFile;
+		imageFile = new TFileStream(filePath,fmOpenRead|fmShareCompat);
+		pi->LoadFromStream(imageFile);
+		bitmap->Assign(pi->CopyBitmap());
+ 		image->Picture->Assign(bitmap);
+		delete imageFile;
+        image->Canvas->Draw(0, 0, bitmap);
+    }
 	else	image->Picture->LoadFromFile(filePath);
 
 	insertRTF(bitmapToRTF(image->Picture->Bitmap));
 	}
 	catch (...){}
 	delete ji;
+    delete pi;
 	delete image;
 	delete bitmap;
 }

Added: branches/BCB5/TNGImage/Docs/CHANGES.txt
===================================================================
--- branches/BCB5/TNGImage/Docs/CHANGES.txt	                        (rev 0)
+++ branches/BCB5/TNGImage/Docs/CHANGES.txt	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,75 @@
+Changelog:                            * reverse chronological order *
+
+* 1.2.0  *
+2002/10/07 - GJU - Added more libmng events
+           - GJU - Fixed assign method to copy all TNGImage properties
+           - GJU - Added function to copy bitmap contents
+2002/10/03 - GJU - Updated to libmng 1.0.5
+2002/09/19 - GJU - Added LoadFromResource function
+2002/08/04 - GJU - Added PNGneeded & JNGneeded functions
+           - GJU - Added property to access the TNGBitmap mng_handle
+
+* 1.0.1 *
+2001/10/23 - GJU - Adapted to work with Kylix                           
+           - GJU - Added OnRefresh event                                
+
+* 1.0.0 *
+2001/09/18 - GJU - First public release
+                                                                        
+* 0.9.8c *
+2001/08/25 - SPR - Fixed Late Binding ZLIB method reference issue       
+                                                                        
+* 0.9.8b *                                                              
+2001/08/25 - GJU - Added BGImage property for assigning background-image
+           - GJU - Added OnProcessHeader event                          
+                                                                        
+* 0.9.8 *                                                               
+2001/08/12 - ALT - Added Delphi6 package                                
+           - GJU - Changed the fix for TOpenPictureDialog as Borland    
+                   changed its design in D6                             
+2001/07/23 - GJU - Added gamma control functions                        
+2001/07/22 - GJU - Fixed some formatting                                
+2001/07/21 - GJU - Added code to prevent 256->16 palette reduction bug  
+                   (really wondering if it'll work this way?!?!?)        
+                   (search for 'Phil Scadden')                          
+2001/06/26 - GJU - Changed most CheckLIBMNGLoaded to assigned/exception 
+           - GJU - Fixed 'Invalid Window Handle' in OpenPictureDialog   
+           - GJU - Added limit checking for JPEG quality setting        
+           - GJU - added TMNGVideo component (see mngvideo.txt)         
+                   (optimized for video-stream playback)                
+2001/06/23 - SPR - Added stuff for late binding (see latebinding.txt)   
+2001/06/16 - GJU - Moved all string-constants to NGConst.pas            
+2001/06/12 - SPR - Tidied up CreatePNG                                  
+           - SPR - Bracketed some if statements for easier debugging    
+2001/06/10 - PJH - Added 1 bit alpha mask for alpha color               
+           - PJH - BugFix 8 bit alpha mask for alpha color              
+           - PJH - Fixed D5 compiler warnings (signed/unsigned compare) 
+2001/05/08 - SPR - Restructured for Maintainability                     
+           - SPR - Seperated original NGImage.pas into multiple units   
+                                                                        
+* 0.9.and-a-bit *                                                               
+Changes by Scott Price (a zillion thanks, mate!)
+- Added packaging for D3,D4,D5
+- Tidied up some code (specifically CreatePNG)
+- Bracketed some if-statements for easier debugging
+- Some other stuff...
+
+* 0.9.2 *
+Third beta (added JPEG/ZLIB, PNG save, JNG save)
+2001/05/04 - Added version constants
+           - Added OnStatusChange event property to TNGImage
+           - Added JNG save support to TNGImage
+2001/05/03 - Added PNG save support to TNGImage
+           - Added transparency variables to TNGImage
+           - Added support to assign a TBitmap to TNGImage
+           - Added TJPEGImage
+           - Added external defs for ZLIB/JPEG (included in libmng!)
+           - Added properties to access libmng variables to TNGImage
+           - Added conditionals to include/register specific components
+
+* 0.9.1 *
+Second beta (small fixes)
+
+* 0.9.0 *
+First beta (basic setup)
+

Added: branches/BCB5/TNGImage/Docs/INSTALL.txt
===================================================================
--- branches/BCB5/TNGImage/Docs/INSTALL.txt	                        (rev 0)
+++ branches/BCB5/TNGImage/Docs/INSTALL.txt	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,26 @@
+1) Copy libmng.dll to your Windows system directory
+
+2) Open one of the Packages from the available distribution (Delphi 3 - 6), and 
+   press the Install button to Compile and Install the package.
+
+2a) If needing to create a package from scratch, use the Browse button to select 
+    the "RegNG.pas" as the Unit file name to include in the package.  This will
+    implicitly import the other required units.
+
+
+Note:  The component will not be visible on your palette as it is non-visual!
+       It provides additional functionality to any TImage in the unit when the 
+       "NGImages" unit is added to the USES clause of any other unit that wants 
+       to use the file formats supported by TNGImage.
+
+
+3) Now when you add a TImage to a form and open the Picture property dialog from
+   the Object Inspector, the "Load Picture" dialog should show entries for MNG,
+   JNG, PNG and JPEG files.
+   (depending on the included components during compile!)
+
+
+Enjoy!
+
+
+Gerard Juyn
\ No newline at end of file

Added: branches/BCB5/TNGImage/Docs/LATEBINDING.txt
===================================================================
--- branches/BCB5/TNGImage/Docs/LATEBINDING.txt	                        (rev 0)
+++ branches/BCB5/TNGImage/Docs/LATEBINDING.txt	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,44 @@
+The late binding option
+=======================
+
+Note that this is enabled by default!
+
+This option can be used to minimize the load-time of the application. The way
+it functions is that libmng.dll will only be loaded once it is needed. Eg. as
+soon as the first TNGImage (or descendant), TJPEGImage or one of the zlib
+functions gets created/called.
+
+The way this works is through a reference-counter. TNGImage and TJPEGImage
+will do this automatically. To use the zlib functions you'll need to put your
+code within the following construct:
+
+  uses NGTypes;
+
+  BeginUseZLib;
+  try
+    ... your zlib accessing code ...
+  finally
+    EndUseZLib;
+  end;
+
+(BTW. if you have a TImage with a PNG/JNG/MNG or JPEG loaded at designtime on
+the main form (or any auto-loaded forms), this feature is not for you!)
+
+The option adds a little overhead as the first call to a libmng function needs
+to load libmng.dll and query all the function entrypoints. But if you really
+want your app to open as fast as possible, this is the way to go.
+
+
+KYLIX!!
+=======
+
+Under Linux, zlib is a separate shared object. The same is true for lcms (if
+present) and the IJG JPEG code. Also, as Kylix offers automatic support for
+JPEG images natively, the TJPEGImage in this package is not made available.
+
+I have also noticed that with shared libraries a non-existant entry-point will
+cause the application to simply halt, without further messages or anything.
+This is important if you plan to use this component with any libmng.so supplied
+by default on many Linux distributions. Although this is perfectly valid, most
+of these distro's will have an older version of the lib, and dynamic linking
+may fail without any reasonable explanation.

Added: branches/BCB5/TNGImage/Docs/LIBMNG_DLL.txt
===================================================================
--- branches/BCB5/TNGImage/Docs/LIBMNG_DLL.txt	                        (rev 0)
+++ branches/BCB5/TNGImage/Docs/LIBMNG_DLL.txt	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,41 @@
+Standard Windows DLL
+====================
+
+The DLL provided in the BCB/win32dll directory is meant as the sole candidate
+for distributions, based on libmng.dll, that install the DLL into the public
+Windows system-directory. The outline herein defines the requirements to
+which such a distribution must comply. If you cannot comply with these
+requirements please install the dll in the same directory as your application
+and NOT in the Windows system-directory!!!
+
+
+1) Only the DLL already assembled in the libmng distribution may be used for
+   other distributions!
+
+2) Only stable public releases are eligible for distribution! A public release
+   is one where the y-value of the x.y.z version-code is an even number.
+   Eg. 1.0.0, 1.2.1, 2.4.7, etc.
+
+3) The installation program MUST store the DLL in the Windows system-directory!
+   Eg. C:\WinNT\System32, C:\Windows98\System
+   (Note: InstallShield users can use the <SYSDIR> variable;
+          InnoSetup users can use .. DestDir: "{sys}"; .. )
+
+3) The installation program MUST flag the file as a shared library!
+
+4) The installation program MUST NOT install the DLL if a newer version
+   already exists in the Windows system-directory! The standard DLL provided
+   contains the Windows-default version-numbering system. PLEASE USE IT!!
+   DO NOT rely on the date or size of the files.
+
+5) An uninstall procedure MAY NOT remove the DLL if other applications are
+   still linked to it! Proper handling as a shared library is imperitive.
+
+6) TEST IT, TEST IT, TEST IT!!! (I just can't stress this enough)
+   If you don't have enough time, let someone else test it BEFORE you
+   distribute!
+
+   
+The penalty for violating these rules is inclusion of your name in the list
+of endangered but useless species (just below the GIF entry!), and on my
+blacklist. YOU HAVE BEEN FOREWARNED!

Added: branches/BCB5/TNGImage/Docs/LICENSE.txt
===================================================================
--- branches/BCB5/TNGImage/Docs/LICENSE.txt	                        (rev 0)
+++ branches/BCB5/TNGImage/Docs/LICENSE.txt	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,39 @@
+COPYRIGHT NOTICE:
+
+Copyright (c) 2001,2002 Gerard Juyn, Scott Price
+[You may insert additional notices after this sentence if you modify
+ this source]
+
+For the purposes of this copyright and license, "Contributing Authors"
+is currently defined as the following set of individuals:
+
+   Gerard Juyn            GJU  (gerard at libmng.com)
+   Scott Price            SPR
+   Peter J. Haas          PJH
+   Alexander Tereschenko  ALT  (alex at plastiqueweb.com)
+
+This component is supplied "AS IS".  The Contributing Authors
+disclaim all warranties, expressed or implied, including, without
+limitation, the warranties of merchantability and of fitness for any
+purpose.  The Contributing Authors assume no liability for direct,
+indirect, incidental, special, exemplary, or consequential damages,
+which may result from the use of this component, even if advised of
+the possibility of such damage.
+
+Permission is hereby granted to use, copy, modify, and distribute this
+source code, or portions hereof, for any purpose, without fee, subject
+to the following restrictions:
+
+1. The origin of this source code must not be misrepresented;
+   you must not claim that you wrote the original software.
+
+2. Altered versions must be plainly marked as such and must not be
+   misrepresented as being the original source.
+
+3. This Copyright notice may not be removed or altered from any source
+   or altered source distribution.
+
+The Contributing Authors specifically permit, without fee, and
+encourage the use of this source code as a component to supporting
+the MNG/JNG and PNG file format in commercial products. If you use this
+source code in a product, acknowledgment would be highly appreciated.

Added: branches/BCB5/TNGImage/Docs/MNGVIDEO.txt
===================================================================
--- branches/BCB5/TNGImage/Docs/MNGVIDEO.txt	                        (rev 0)
+++ branches/BCB5/TNGImage/Docs/MNGVIDEO.txt	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,54 @@
+TMNGVIDEO
+=========
+
+This component is based on the memory-optimized feature of libmng specific for
+playback of long MNG videos. The saving is quite dramatic as no playback info
+is cached. However this does impose several restrictions.
+
+- TMNGVideo cannot do save operations
+  Nothing is stored so there's nothing to save!
+
+- TMNGVideo cannot be assigned to/from other types
+
+- TMNGVideo cannot rewind
+  Again, no playback info is stored so there's nothing to rewind to
+
+- The MNG cannot contain LOOP chunks
+  Again this is imposed by libmng as it doesn't cache anything which would be
+  required for loops to function in the first place!
+
+- The MNG may contain a TERM chunk, but this will not be processed
+  ...same reasons as above...
+
+- TMNGVideo can only be used at runtime
+  It has the same extension as a regular MNG, which is already registered for
+  the TMNGImage component
+
+  
+IOW if you're going to work with this thing you are limited in your options.
+
+Note also that using TOpenPictureDialog uses TMNGImage for MNG files, so if you
+point it to a long MNG video-stream it'll be loading the whole thing into memory
+which is exactly what you want to prevent with TMNGVideo. So in this case,
+please use the TOpenDialog.
+
+
+If you're still convinced this is what you want to be playing with then here's
+some code:
+
+
+procedure TMyForm.Button1Execute(Sender: TObject);
+var MyMNG: TMNGVideo;
+begin
+  if OpenDialog1.Execute then
+  begin
+    MyMNG := TMNGVideo.Create;
+    try
+      Image1.Picture.Assign(MyMNG);
+    finally
+      MyMNG.Free;
+    end;
+    Image1.Picture.Graphic.LoadFromFile(OpenDialog1.FileName);
+  end;
+end;
+

Added: branches/BCB5/TNGImage/Docs/REDIST.txt
===================================================================
--- branches/BCB5/TNGImage/Docs/REDIST.txt	                        (rev 0)
+++ branches/BCB5/TNGImage/Docs/REDIST.txt	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,41 @@
+Windows
+=======
+
+All files can be redistributed freely as long as their individual license notes
+are met. eg:
+
+- for NGImage.pas you need not worry about a thing. I'd appreciate an
+  acknowledgement but it's not a requirement.
+
+- For libmng.dll you should meet the requirements for LIBMNG, ZLIB, IJG Source
+  code and Little CMS. Visit respective sites for more info:
+  http://www.libmng.com/
+  http://www.zlib.org/
+  http://www.ijg.org/
+  http://www.littlecms.com/
+
+If you distribute libmng.dll with you Application, and you wish to install it
+into the user's Windows System folder (which is recommended), you *must* follow
+the guidelines as defined in the file LIBMNG_DLL.txt. This file is copied from
+the original libmng distribution and is provided here for convenience only.
+In case of discrepencies between this version and that in the original libmng
+distribution, the file in the original distribution will prevail.
+
+You may distribute the included binary libmng installation file. It has the
+same requirements as including libmng.dll by itself. If you want to point your
+users to the latest binary installation, please use the following URL:
+
+http://www.libmng.com/windows32.html
+
+
+Linux
+=====
+
+NGImage is freely distributable.
+
+Apart from usual Kylix requirements you will also need to distribute
+libz.so (1.1.3), libjpeg.so (6.2) & libmng.so (1.0.0+)
+There's a libmng.rpm included with at least RedHat7.1; check the RedHat site
+for details.
+
+The latest libmng source is freely available from http://www.libmng.com/

Added: branches/BCB5/TNGImage/Docs/USAGE.txt
===================================================================
--- branches/BCB5/TNGImage/Docs/USAGE.txt	                        (rev 0)
+++ branches/BCB5/TNGImage/Docs/USAGE.txt	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,161 @@
+===============================================================================
+
+I'll need to write a small help-file eventually.
+In the meantime this'll have to do.... :)
+
+===============================================================================
+
+Installation: read INSTALL.txt
+
+Distribution: read REDIST.txt and LIBMNG_DLL.txt
+
+License info: read LICENSE.txt and check NGImages.pas header comments
+
+===============================================================================
+
+Compiler options:
+
+You can toggle the $DEFINE's at the top of NGDefs.inc to enable/disable one or
+more of the optional components in the package.
+
+Windows: libmng.dll contains everything to display PNG, JNG, MNG and JPEG files,
+as well as handle any zlib functionality.
+
+Linux: libmng.so contains everything to display PNG, JNG & MNG files.
+(JPEG and zlib functionality are supplied by their respective libraries)
+
+Turning the options (which is the default) on will hardly increase the size of
+your executable! But if you prefer to use other libraries (eg. PNG or JPEG),
+you can disable their support here.
+
+Windows: if you are already using the 'standard' TJPEGImage it's a snap to
+switch to the implementation in NGImage.pas *and* it will save you about 75KB
+on the size of your executable!!!
+
+Note: the PNG decoder in libmng has been reported to be fairly faster than
+most other (native) Delphi-based PNG decoders.
+
+===============================================================================
+
+Displaying PNG, JNG, MNG:
+
+// Image1 : TImage;                       // defined on form
+
+procedure Form1.Display;
+var NG : TNGImage;
+begin
+  NG := TNGImage.Create;
+  try
+    NG.LoadFromFile('somefile.mng');      // select one...
+//    NG.LoadFromFile('somefile.png');
+//    NG.LoadFromFile('somefile.jng');
+    Image1.Picture.Assign(NG);
+  finally
+    NG.Free;
+  end;
+end;
+
+===============================================================================
+
+Displaying MNG with status-control:
+
+// Image1 : TImage;                       // defined on form
+// BtnPause : TButton;
+// BtnPlay : TButton;
+// procedure StatusChange(sender: TOBject);
+
+procedure Form1.Display;
+var NG : TNGImage;
+begin
+  NG := TNGImage.Create;
+  try
+    NG.LoadFromFile('somefile.mng');
+    Image1.Picture.Assign(NG);
+    TNGImage(Image1.Picture.Graphic).OnStatusChange := StatusChange;
+    StatusChange(nil);
+  finally
+    NG.Free;
+  end;
+end;
+
+procedure Form1.StatusChange;
+begin
+  BtnPause.Enabled := TNGImage(Image1.Picture.Graphic).StatusRunning;
+  BtnPlay.Enabled := not BtnPause.Enabled;
+end;
+
+===============================================================================
+
+Displaying JPEG:
+
+Just use TJPEGImage like you would otherwise
+
+===============================================================================
+
+Writing PNG:
+
+procedure BMP2PNG(Bitmap: TBitmap; Filename: string);
+var NG : TNGImage;
+begin
+  NG := TNGImage.Create;
+  try
+    NG.Assign (Bitmap);
+    NG.SaveToPNGfile (Filename);
+  finally
+    NG.Free;
+  end;
+end;
+
+===============================================================================
+
+Writing JNG:
+
+procedure BMP2JNG(Bitmap: TBitmap; Filename: string);
+var NG : TNGImage;
+begin
+  NG := TNGImage.Create;
+  try
+    NG.Assign(Bitmap);
+    NG.SaveToJNGfile(Filename);
+  finally
+    NG.Free;
+  end;
+end;
+
+===============================================================================
+
+Writing PNG with alpha:
+
+procedure BMP2PNGA (Bitmap: TBitmap; Color: TColor; Filename: string);
+var NG : TNGImage;
+begin
+  NG := TNGImage.Create;
+  try
+    NG.Assign(Bitmap);
+    NG.SetAlphaColor(Color);           // set single transparent color
+//    NG.SetAlphaBitmap(SomeBitmap);     // set complete alpha-channel
+    NG.SaveToPNGfile(Filename);
+  finally
+    NG.Free;
+  end;
+end;
+
+===============================================================================
+
+Writing JNG with alpha:
+
+procedure BMP2JNGA (Bitmap: TBitmap; Color: TColor; Filename: string);
+var NG : TNGImage;
+begin
+  NG := TNGImage.Create;
+  try
+    NG.Assign(Bitmap);
+    NG.SetAlphaColor(Color);           // set single transparent color
+//    NG.SetAlphaBitmap(SomeBitmap);     // set complete alpha-channel
+    NG.SaveToJNGfile(Filename);
+  finally
+    NG.Free;
+  end;
+end;
+
+===============================================================================

Added: branches/BCB5/TNGImage/Package/NGBitmap.pas
===================================================================
--- branches/BCB5/TNGImage/Package/NGBitmap.pas	                        (rev 0)
+++ branches/BCB5/TNGImage/Package/NGBitmap.pas	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,864 @@
+unit NGBitmap;
+
+{****************************************************************************}
+{*                                                                          *}
+{*  for copyright and version information see header in NGImages.pas        *}
+{*                                                                          *}
+{****************************************************************************}
+{*                                                                          *}
+{*  Changelog:                            * reverse chronological order *   *}
+{*                                                                          *}
+{*  * 1.0.1  *                                                              *}
+{*  2001/10/23 - GJU - Adapted to work with Kylix                           *}
+{*                                                                          *}
+{****************************************************************************}
+{*                                                                          *}
+{*  This unit is copied for 99.9% from QGraphics with only 1 objective:     *}
+{*  - to obtain public access to the FImage property of a TBitmap           *}
+{*                                                                          *}
+{****************************************************************************}
+
+
+{$INCLUDE NGDefs.inc}
+
+interface
+
+uses Types, Classes, SysUtils, Qt, QTypes, QGraphics, QControls;
+
+type
+  TNGBMP = class;
+
+  TNGCanvas = class(TCanvas)
+  end;
+
+  TNGBitmapCanvas = class(TNGCanvas)
+  private
+    FBitmap: TNGBMP;
+  protected
+    procedure BeginPainting; override;
+    procedure CreateHandle; override;
+  public
+    constructor Create(Bitmap: TNGBMP);
+  end;
+
+  TNGBMP = class(TGraphic)
+  private
+    FImage: QImageH;
+    FPixmap: QPixmapH;
+    FCanvas: TNGCanvas;
+    FStream: TStream;
+    FHeight: Integer;
+    FWidth: Integer;
+    FPixelFormat: TPixelFormat;
+    FFormat: string;
+    FTransparentColor: TColor;
+    FTransparentMode: TTransparentMode;
+    procedure Changing(Sender: TObject);
+    function GetCanvas: TNGCanvas;
+    function GetImage: QImageH;
+    function GetHandle: QPixmapH;
+    function GetMonochrome: Boolean;
+    procedure ResizeImage(NewWidth, NewHeight: Integer);
+    procedure SetMonochrome(const Value: Boolean);
+    procedure SetHandle(const Value: QPixmapH);
+    function GetTransparentColor: TColor;
+    procedure SetTransparentColor(const Value: TColor);
+    procedure SetTransparentMode(const Value: TTransparentMode);
+    function TransparentColorStored: Boolean;
+    function GetScanLine(Row: Integer): Pointer;
+    function GetPixelFormat: TPixelFormat;
+    procedure SetPixelFormat(const Value: TPixelFormat);
+  protected
+    procedure AssignTo(Dest: TPersistent); override;
+    procedure Draw(ACanvas: TCanvas; const Rect: TRect); override;
+    function GetEmpty: Boolean; override;
+    function GetHeight: Integer; override;
+    function GetTransparent: Boolean; override;
+    function GetWidth: Integer; override;
+    procedure ImageNeeded;
+    procedure HandleNeeded;
+    procedure ReadData(Stream: TStream); override;
+    procedure SetHeight(Value: Integer); override;
+    procedure SetTransparent(Value: Boolean); override;
+    procedure SetWidth(Value: Integer); override;
+    procedure TiledDraw(ACanvas: TCanvas; const Rect: TRect); override;
+    procedure WriteData(Stream: TStream); override;
+  public
+    constructor Create; override;
+    destructor Destroy; override;
+    procedure Assign(Source: TPersistent); override;
+    class function AssignsTo(Dest: TGraphicClass): Boolean; override;
+    function ColorTable: Pointer;
+    procedure Dormant;
+    procedure FreeImage;
+    procedure FreePixmap;
+    function ReleasePixmap: QPixmapH;
+    procedure LoadFromMimeSource(MimeSource: TMimeSource); override;
+    procedure SaveToMimeSource(MimeSource: TClxMimeSource); override;
+    procedure LoadFromResourceName(Instance: Cardinal; const ResName: string);
+    procedure LoadFromResourceID(Instance: Cardinal; ResID: Integer);
+    procedure LoadFromStream(Stream: TStream); override;
+    procedure Mask(TransparentColor: TColor);
+    procedure SaveToStream(Stream: TStream); override;
+    property Canvas: TNGCanvas read GetCanvas;
+    property Format: string read FFormat write FFormat;
+    property Image: QImageH read GetImage;
+    property Handle: QPixmapH read GetHandle write SetHandle;
+    property Monochrome: Boolean read GetMonochrome write SetMonochrome;
+    property PixelFormat: TPixelFormat read GetPixelFormat write SetPixelFormat;
+    property ScanLine[Row: Integer]: Pointer read GetScanLine;
+    property TransparentColor: TColor read GetTransparentColor
+      write SetTransparentColor stored TransparentColorStored;
+    property TransparentMode: TTransparentMode read FTransparentMode
+      write SetTransparentMode default tmAuto;
+  end;
+
+implementation
+
+type
+  EInvalidGraphic = class(Exception);
+  EInvalidGraphicOperation = class(Exception);
+
+const
+  SDelphiBitmap = 'image/delphi.bitmap';
+  
+resourcestring
+  SScanLine = 'Scan line index out of range';
+  SUnknownImageFormat = 'Image format not recognized';
+  SInvalidColorDepth = 'Color depth must be 1, 8 or 32 bpp';
+  SUnableToWrite = 'Unable to write bitmap';
+  SInvalidCanvasState = 'Invalid canvas state request';
+
+procedure InvalidOperation(Str: PResStringRec);
+begin
+  raise EInvalidGraphicOperation.CreateRes(Str);
+end;
+
+class function TNGBMP.AssignsTo(Dest: TGraphicClass): Boolean;
+begin
+  Result := inherited AssignsTo(Dest);// or Dest.InheritsFrom(TIcon);
+end;
+
+procedure TNGBMP.AssignTo(Dest: TPersistent);
+begin
+    inherited AssignTo(Dest);
+end;
+
+procedure TNGBMP.Assign(Source: TPersistent);
+begin
+  if (Source = nil) or (Source is TNGBMP) then
+  begin
+    FreeImage;
+    FreePixmap;
+    if Source <> nil then
+    begin
+      if (TNGBMP(Source).FImage = nil) and (TNGBMP(Source).FPixmap = nil) then
+      begin
+        FHeight := TNGBMP(Source).FHeight;
+        FWidth := TNGBMP(Source).FWidth;
+      end else
+      begin
+        if TNGBMP(Source).FImage <> nil then
+          FImage := QImage_create(TNGBMP(Source).FImage);
+        if TNGBMP(Source).FPixmap <> nil then
+          FPixmap := QPixmap_create(TNGBMP(Source).FPixmap);
+      end;
+    end;
+    Changed(Self);
+  end
+  else
+    inherited Assign(Source);
+end;
+
+function TNGBMP.ColorTable: Pointer;
+begin
+  Result := nil;
+  ImageNeeded;
+  if FImage <> nil then
+    Result := QImage_colorTable(FImage);
+end;
+
+constructor TNGBMP.Create;
+begin
+  inherited Create;
+  FFormat := 'BMP';
+  FTransparentColor := clDefault;
+  FTransparentMode := tmAuto;
+  FPixelFormat := pf32bit;
+end;
+
+destructor TNGBMP.Destroy;
+begin
+  FreeImage;
+  FreePixmap;
+  inherited Destroy;
+end;
+
+procedure TNGBMP.Changing(Sender: TObject);
+begin
+  HandleNeeded;
+  FreeImage;
+end;
+
+procedure TNGBMP.Dormant;
+begin
+  ImageNeeded;
+  FreePixmap;
+end;
+
+procedure TNGBMP.Draw(ACanvas: TCanvas; const Rect: TRect);
+var
+  NewMatrix: QWMatrixH;
+begin
+  TNGCanvas(ACanvas).RequiredState([csHandleValid]);
+  HandleNeeded;
+  if (Rect.Right - Rect.Left <> Width) or
+    (Rect.Bottom - Rect.Top <> Height) then
+  begin
+    // Image must be scaled
+    QPainter_saveWorldMatrix(ACanvas.Handle);
+    try
+      NewMatrix:= QWMatrix_create( (Rect.Right - Rect.Left) / Width ,
+        0, 0, (Rect.Bottom - Rect.Top) / Height, Rect.Left, Rect.Top );
+      try
+        QPainter_setWorldMatrix(ACanvas.Handle, NewMatrix, True);
+        QPainter_drawPixmap(ACanvas.Handle, 0, 0, FPixmap, 0, 0, Width, Height);
+      finally
+        QWMatrix_destroy(NewMatrix);
+      end;
+    finally
+      QPainter_restoreWorldMatrix(ACanvas.Handle);
+    end;
+  end
+  else
+    QPainter_drawPixmap(ACanvas.Handle, Rect.Left, Rect.Top, FPixmap, 0, 0,
+      Rect.Right - Rect.Left, Rect.Bottom - Rect.Top);
+end;
+
+procedure TNGBMP.FreeImage;
+begin
+  if FImage <> nil then
+  begin
+    QImage_destroy(FImage);
+    FImage := nil;
+    FreeAndNil(FStream);
+  end;
+end;
+
+procedure TNGBMP.FreePixmap;
+begin
+  if FPixmap <> nil then
+  begin
+    QPixmap_destroy(FPixmap);
+    FPixmap := nil;
+  end;
+end;
+
+function TNGBMP.GetCanvas: TNGCanvas;
+begin
+  if FCanvas = nil then
+  begin
+    FCanvas := TNGBitmapCanvas.Create(Self);
+    FCanvas.OnChanging := Changing;
+    FCanvas.OnChange := Changed;
+  end;
+  Result := FCanvas;
+end;
+
+function TNGBMP.GetEmpty: Boolean;
+begin
+  Result := ((FPixmap = nil) or QPixmap_isNull(FPixmap)) and (FImage = nil);
+end;
+
+function TNGBMP.GetImage: QImageH;
+begin
+  ImageNeeded;
+  Result := FImage;
+end;
+
+function TNGBMP.GetHandle: QPixmapH;
+begin
+  HandleNeeded;
+  Result := FPixmap;
+end;
+
+function TNGBMP.GetHeight: Integer;
+begin
+  if FPixmap <> nil then
+    Result := QPixmap_height(FPixmap)
+  else if FImage <> nil then
+    Result := QImage_height(FImage)
+  else
+    Result := FHeight;
+end;
+
+function TNGBMP.GetMonochrome: Boolean;
+begin
+  if FPixmap <> nil then
+    Result := QPixmap_isQBitmap(FPixmap)
+  else if FImage <> nil then
+    Result := PixelFormat = pf1bit
+  else
+    Result := False;
+end;
+
+function TNGBMP.GetPixelFormat: TPixelFormat;
+var
+  Depth: Integer;
+begin
+  ImageNeeded;
+  if FImage <> nil then
+  begin
+    Depth := QImage_depth(FImage);
+    case Depth of
+      1: Result := pf1bit;
+      8: Result := pf8bit;
+      16: Result := pf16bit;
+      32: Result := pf32bit;
+    else
+      Result := pfCustom;
+    end;
+  end
+  else
+    Result := FPixelFormat;
+end;
+
+const
+  PixelFormatMap: array[pf1bit..pf32bit] of Integer = (1, 8, 16, 32);
+
+procedure TNGBMP.SetPixelFormat(const Value: TPixelFormat);
+var
+  NewImage: QImageH;
+  Format: TPixelFormat;
+begin
+  Format := GetPixelFormat;
+  if Value = Format then Exit;
+  FPixelFormat := Value;
+  ImageNeeded;
+  HandleNeeded;
+  if FImage <> nil then
+  begin
+    NewImage := QImage_create;
+    QImage_convertDepth(FImage, NewImage, PixelFormatMap[Value]);
+    QImage_destroy(FImage);
+    FImage := NewImage;
+    QPixmap_convertFromImage(FPixmap, FImage, QPixmapColorMode(QPixmapColorMode_Auto));
+    Changed(Self);
+  end;
+end;
+
+function TNGBMP.GetScanLine(Row: Integer): Pointer;
+begin
+  if (Row < 0) or (Row > Height) then
+    InvalidOperation(@SScanLine);
+  ImageNeeded;
+  FreePixmap;
+  if FImage <> nil then
+    Result := QImage_scanLine(FImage, Row)
+  else Result := nil;
+end;
+
+
+function TNGBMP.GetWidth: Integer;
+begin
+  if FPixmap <> nil then
+    Result := QPixmap_width(FPixmap)
+  else if FImage <> nil then
+    Result := QImage_width(FImage)
+  else
+    Result := FWidth;
+end;
+
+procedure TNGBMP.HandleNeeded;
+begin
+  if FPixmap = nil then
+    if FImage <> nil then
+    begin
+      FPixmap := QPixmap_create;
+      QPixmap_convertFromImage(FPixmap, FImage, QPixmapColorMode(QPixmapColorMode_Auto));
+    end
+    else
+    begin
+      FPixmap := QPixmap_create(FWidth, FHeight, -1, QPixmapOptimization_DefaultOptim);
+      if (FWidth > 0) and (FHeight > 0) then
+        Canvas.FillRect(Rect(0, 0, FWidth, FHeight));
+    end;
+end;
+
+procedure TNGBMP.ImageNeeded;
+begin
+  if FImage = nil then
+    if FPixmap <> nil then
+    begin
+      FImage := QImage_create;
+      QPixmap_convertToImage(FPixmap, FImage);
+    end
+    else if (FWidth > 0) and (FHeight > 0) then
+      FImage := QImage_create(FWidth, FHeight, PixelFormatMap[FPixelFormat], 0,
+        QImageEndian_IgnoreEndian);
+end;
+
+procedure TNGBMP.LoadFromStream(Stream: TStream);
+var
+  IO: QImageIOH;
+  Device: QIODeviceH;
+  P, S: Int64;
+begin
+  FreeImage;
+  FreePixmap;
+  if Stream.Size - Stream.Position > 0 then
+  begin
+    P := Stream.Position;
+    Device := IODeviceFromStream(Stream);
+    Format := QImageIO_imageFormat(Device);
+    IO := QImageIO_create(Device, PChar(Format));
+    try
+      if not QImageIO_read(IO) then InvalidOperation(@SUnknownImageFormat);
+      FImage := QImage_create(QImageIO_image(IO));
+//      if FTransparent then Mask(FTransparentColor);
+    finally
+      QImageIO_destroy(IO);
+    end;
+    if ExactBitmaps and (P <> Stream.Position) then
+    begin
+      // Preserve the exact bytes we read.
+      S := Stream.Position - P;
+      FStream := TMemoryStream.Create;
+      Stream.Position := P;
+      FStream.CopyFrom(Stream, S);
+      Assert(Stream.Position = P + S);
+    end;
+  end;
+  Changed(Self);
+end;
+
+type
+  TColorTable = array[0..MaxInt div SizeOf(QRgb)-1] of QRgb;
+  PColorTable = ^TColorTable;
+  TIntArray = array[0..MaxInt div SizeOf(QRgb)-1] of Integer;
+  PIntArray = ^TIntArray;
+
+procedure TNGBMP.Mask(TransparentColor: TColor);
+var
+  MaskImage: QImageH;
+  MaskBitmap: QBitmapH;
+  X, Y: Integer;
+  C, TC: QRgb;
+  Black,
+  White: QRgb;
+  SLImage32: PIntArray;
+  SLImage,
+  SLMask: PByteArray;
+  ColorTable: PColorTable;
+  LittleEndian: Boolean;
+begin
+  ImageNeeded;
+  if FImage = nil then Exit; // Not enough information to create one.
+  Black := $FF000000;
+  White := $FFFFFFFF;
+  MaskImage := QImage_create(Width, Height, 8, 2, QImageEndian_IgnoreEndian);
+  try
+    if TransparentColor = clDefault then
+      QImage_pixel(FImage, @TC, 0, Height - 1)
+    else
+      QColor_rgb(QColor(TransparentColor), @TC);
+    QImage_setColor(MaskImage, 0, @QRgb(Black));
+    QImage_setColor(MaskImage, 1, @QRgb(White));
+    case PixelFormat of
+      pf1bit:
+        begin
+          ColorTable := PColorTable(QImage_colorTable(FImage));
+          LittleEndian := QImage_bitOrder(FImage) = QImageEndian_LittleEndian;
+          if LittleEndian then
+          begin
+            for Y := 0 to Height - 1 do
+            begin
+              SLImage := PByteArray(QImage_scanLine(FImage, Y));
+              SLMask := PByteArray(QImage_scanLine(MaskImage, Y));
+              for X := 0 to Width - 1 do
+              begin
+                C := ColorTable[(SLImage[x div 8] and (1 shl (x and 7))) shr (x mod 8)];
+                SLMask[x] := Ord(C = TC);
+              end;
+            end;
+          end
+          else
+          begin
+            for Y := 0 to Height - 1 do
+            begin
+              SLImage := PByteArray(QImage_scanLine(FImage, Y));
+              SLMask := PByteArray(QImage_scanLine(MaskImage, Y));
+              for X := 0 to Width - 1 do
+              begin
+                C := ColorTable[(SLImage[x div 8] and (1 shl (7 - x and 7))) shr (7 - (x mod 8))];
+                SLMask[x] := Ord(C = TC);
+              end;
+            end;
+          end;
+        end;
+      pf8bit: //pf16bit??
+        begin
+          ColorTable := PColorTable(QImage_colorTable(FImage));
+          for Y := 0 to Height - 1 do
+          begin
+            SLImage := PByteArray(QImage_scanLine(FImage, Y));
+            SLMask := PByteArray(QImage_scanLine(MaskImage, Y));
+            for X := 0 to Width - 1 do
+            begin
+              C := ColorTable[SLImage[x]];
+              SLMask[x] := Ord(C = TC);
+            end;
+          end;
+        end;
+      pf32bit:
+        begin
+          for Y := 0 to Height - 1 do
+          begin
+            SLImage32 := PIntArray(QImage_scanLine(FImage, Y));
+            SLMask := PByteArray(QImage_scanLine(MaskImage, Y));
+            for X := 0 to Width - 1 do
+            begin
+              C := QRgb(SLImage32[x]);
+              SLMask[x] := Ord(C = TC);
+            end;
+          end;
+        end;
+    else
+      InvalidOperation(@SInvalidColorDepth);
+    end;
+    MaskBitmap := QBitmap_create(Width, Height, True, QPixmapOptimization_NoOptim);
+    try
+      QPixmap_convertFromImage(MaskBitmap, MaskImage, QPixmapColorMode_Mono);
+      QPixmap_setMask(Handle, MaskBitmap);
+    finally
+      QBitmap_destroy(MaskBitmap);
+    end;
+  finally
+    QImage_destroy(MaskImage);
+  end;
+end;
+
+procedure TNGBMP.LoadFromResourceName(Instance: Cardinal; const ResName: string);
+var
+  Stream: TCustomMemoryStream;
+  TmpStream: TMemoryStream;
+  Header: TBitmapFileHeader;
+  BmpHeader: TBitmapInfoHeader;
+begin
+  Stream := TResourceStream.Create(Instance, ResName, RT_BITMAP);
+  try
+    TmpStream := TMemoryStream.Create;
+    try
+      // Reads bitmap header
+      Stream.ReadBuffer(BmpHeader, sizeof(BmpHeader));
+      Stream.Seek(0, soBeginning);
+
+      // Builds file header
+      FillChar(Header, SizeOf(Header), 0);
+      Header.bfType := $4D42;
+      Header.bfSize := Stream.Size;
+      Header.bfReserved1 := 0;
+      Header.bfReserved2 := 0;
+
+      if BmpHeader.biBitCount > 8 then
+        Header.bfOffBits := sizeof(Header) + sizeof(BmpHeader)
+      else
+        if BmpHeader.biClrUsed = 0 then
+          Header.bfOffBits := sizeof(Header) + sizeof(BmpHeader) + (1 shl BmpHeader.biBitCount) * 4
+        else
+          Header.bfOffBits := sizeof(Header) + sizeof(BmpHeader) + BmpHeader.biClrUsed * 4;
+
+      // Concatenates both in TmpStream
+      TmpStream.WriteBuffer(Header, SizeOf(Header));
+      TmpStream.CopyFrom(Stream, Stream.Size);
+      TmpStream.Position := 0;
+      LoadFromStream(TmpStream);
+    finally
+      TmpStream.Free;
+    end;
+  finally
+    Stream.Free;
+  end;
+end;
+
+procedure TNGBMP.LoadFromResourceID(Instance: Cardinal; ResID: Integer);
+var
+  Stream: TCustomMemoryStream;
+begin
+  Stream := TResourceStream.CreateFromID(Instance, ResID, RT_BITMAP);
+  try
+    LoadFromStream(Stream);
+  finally
+    Stream.Free;
+  end;
+end;
+
+procedure TNGBMP.ReadData(Stream: TStream);
+var
+  Dummy: Integer;
+begin
+  //for VCL stream compatibility
+  Stream.Read(Dummy, SizeOf(Dummy));
+  LoadFromStream(Stream);
+end;
+
+procedure TNGBMP.ResizeImage(NewWidth, NewHeight: Integer);
+var
+  NewImage: QImageH;
+begin
+  ImageNeeded;
+  FreePixmap;
+  NewImage := QImage_create;
+  QImage_copy(FImage, NewImage, 0, 0, NewWidth, NewHeight, 0);
+  QImage_destroy(FImage);
+  FImage := NewImage;
+end;
+
+procedure TNGBMP.SaveToStream(Stream: TStream);
+var
+  IO: QImageIOH;
+begin
+  if FStream <> nil then
+  begin
+    // If we have an exact image use that.
+    FStream.Position := 0;
+    Stream.CopyFrom(FStream, FStream.Size);
+  end
+  else
+  begin
+    // Otherwise ask the QImage to write out its contents.
+    ImageNeeded;
+    if FImage = nil then Exit; // Nothing to write
+    IO := QImageIO_create(IODeviceFromStream(Stream), nil);
+    try
+      ImageNeeded;
+      QImageIO_setImage(IO, FImage);
+      QImageIO_setFormat(IO, PChar(Format));
+      if not QImageIO_write(IO) then InvalidOperation(@SUnableToWrite);
+    finally
+      QImageIO_destroy(IO);
+    end;
+  end;
+end;
+
+procedure TNGBMP.SetHandle(const Value: QPixmapH);
+begin
+  if FPixmap <> Value then
+  begin
+    FreeImage;
+    FreePixmap;
+    FPixmap := Value;
+    FHeight := GetHeight;
+    FWidth := GetWidth;
+  end;
+end;
+
+procedure TNGBMP.SetHeight(Value: Integer);
+begin
+  if Value <> Height then
+  begin
+    if (FPixmap <> nil) or (FImage <> nil) then
+      ResizeImage(Width, Value)
+    else
+      FHeight := Value;
+  end;
+end;
+
+procedure TNGBMP.SetMonochrome(const Value: Boolean);
+const
+  Depth: array[Boolean] of Integer = (32, 1);
+var
+  NewImg: QImageH;
+begin
+  if Value <> GetMonochrome then
+  begin
+    HandleNeeded;
+    ImageNeeded;
+    if FImage = nil then
+      FPixelFormat := pf1bit
+    else
+    begin
+      NewImg := QImage_create;
+      try
+        QImage_convertDepth(FImage, NewImg, Depth[Value]);
+        QPixmap_convertFromImage(FPixmap, NewImg, Integer(ImageConversionFlags_AutoColor));
+      finally
+        QImage_destroy(NewImg);
+      end;
+    end;
+    Changed(Self);
+  end;
+end;
+
+procedure TNGBMP.SetWidth(Value: Integer);
+begin
+  if Value <> Width then
+  begin
+    if (FPixmap <> nil) or (FImage <> nil) then
+      ResizeImage(Value, Height)
+    else
+      FWidth := Value;
+  end;
+end;
+
+procedure TNGBMP.WriteData(Stream: TStream);
+var
+  StartPos, Size: Integer;
+begin
+  StartPos := Stream.Position;
+  Stream.Write(StartPos, SizeOf(StartPos));
+  SaveToStream(Stream);
+  Size := Stream.Position - StartPos;
+  Stream.Position := StartPos;
+  Stream.Write(Size, SizeOf(Size));
+  Stream.Position := StartPos + Size;
+end;
+
+function TNGBMP.GetTransparentColor: TColor;
+var
+  TempColor: QColorH;
+begin
+  if FTransparentColor = clDefault then
+  begin
+    if Monochrome then
+      Result := clWhite
+    else begin
+      ImageNeeded;
+      QImage_pixel(FImage, @Result, 0, Height - 1);
+      TempColor := QColor_create;
+      try
+        QColor_setRgb(TempColor, QRgbH(@Result));
+        Result := QColorColor(TempColor);
+      finally
+        QColor_destroy(TempColor);
+      end;
+    end;
+  end
+  else
+    Result := FTransparentColor;
+end;
+
+procedure TNGBMP.SetTransparentColor(const Value: TColor);
+begin
+  if Value <> FTransparentColor then
+  begin
+    if Value = clDefault then
+      FTransparentMode := tmAuto else
+      FTransparentMode := tmFixed;
+    FTransparentColor := Value;
+//    FTransparent := True;
+    if not Empty then
+    begin
+      Mask(Value);
+      Changed(Self);
+    end;
+  end;
+end;
+
+procedure TNGBMP.SetTransparentMode(const Value: TTransparentMode);
+begin
+  if Value <> FTransparentMode then
+    case Value of
+      tmAuto: SetTransparentColor(clDefault);
+      tmFixed: SetTransparentColor(GetTransparentColor);
+    end;
+end;
+
+function TNGBMP.TransparentColorStored: Boolean;
+begin
+  Result := FTransparentMode = tmFixed;
+end;
+
+procedure TNGBMP.SetTransparent(Value: Boolean);
+//var
+//  NullBitmap: QBitmapH;
+begin
+{  if Value <> FTransparent then
+  begin
+    inherited SetTransparent(Value);
+    if FTransparent and not Empty then
+      Mask(FTransparentColor)
+    else begin
+      NullBitmap := QBitmap_create;
+      try
+        QPixmap_setMask(Handle, NullBitmap);
+      finally
+        QBitmap_destroy(NullBitmap);
+      end;
+    end;
+  end; }
+end;
+
+function TNGBMP.GetTransparent: Boolean;
+begin
+//  Result := FTransparent;
+  Result := false;
+end;
+
+procedure TNGBMP.TiledDraw(ACanvas: TCanvas; const Rect: TRect);
+begin
+  QPainter_drawTiledPixmap(ACanvas.Handle, Rect.Left, Rect.Top, Rect.Right -
+    Rect.Left, Rect.Bottom - Rect.Top, Handle, 0, 0);
+end;
+
+procedure TNGBMP.LoadFromMimeSource(MimeSource: TMimeSource);
+var
+  Stream: TStream;
+begin
+  if MimeSource.Provides(SDelphiBitmap) then
+  begin
+    Stream := TMemoryStream.Create;
+    try
+      MimeSource.SaveToStream(SDelphiBitmap, Stream);
+      Stream.Position := 0;
+      LoadFromStream(Stream);
+    finally
+      Stream.Free;
+    end;
+  end;
+end;
+
+procedure TNGBMP.SaveToMimeSource(MimeSource: TClxMimeSource);
+var
+  Stream: TStream;
+begin
+  Stream := TMemoryStream.Create;
+  try
+    SaveToStream(Stream);
+    Stream.Position := 0;
+    MimeSource.LoadFromStream(Stream, SDelphiBitmap);
+  finally
+    Stream.Free;
+  end;
+end;
+
+function TNGBMP.ReleasePixmap: QPixmapH;
+begin
+  FreeImage;
+  Result := FPixmap;
+  FPixmap := nil;
+  FHeight := 0;
+  FWidth := 0;
+end;
+
+{ TBitmapCanvas }
+
+procedure TNGBitmapCanvas.BeginPainting;
+begin
+  if not QPainter_isActive(Handle) then
+    if not QPainter_begin(Handle, FBitmap.Handle) then
+      InvalidOperation(@SInvalidCanvasState);
+end;
+
+constructor TNGBitmapCanvas.Create(Bitmap: TNGBMP);
+begin
+  inherited Create;
+  FBitmap := Bitmap;
+end;
+
+procedure TNGBitmapCanvas.CreateHandle;
+begin
+  Handle := QPainter_create;
+end;
+
+end.

Added: branches/BCB5/TNGImage/Package/NGConst.pas
===================================================================
--- branches/BCB5/TNGImage/Package/NGConst.pas	                        (rev 0)
+++ branches/BCB5/TNGImage/Package/NGConst.pas	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,503 @@
+unit NGConst;
+
+{****************************************************************************}
+{*                                                                          *}
+{*  for copyright and version information see header in NGImages.pas        *}
+{*                                                                          *}
+{****************************************************************************}
+{*                                                                          *}
+{*  Changelog:                            * reverse chronological order *   *}
+{*                                                                          *}
+{*  * 1.2.0  *                                                              *}
+{*  2002/10/03 - GJU - Updated to libmng 1.0.5                              *}
+{*                                                                          *}
+{*  * 1.0.1  *                                                              *}
+{*  2001/10/23 - GJU - Adapted to work with Kylix                           *}
+{*                                                                          *}
+{*  * 0.9.8 *                                                               *}
+{*  2001/06/26 - GJU - Added stuff for late binding                         *}
+{*  2001/06/16 - GJU - Moved all string-constants here                      *}
+{*  2001/05/08 - SPR - Restructured for Maintainability                     *}
+{*             - SPR - Seperated original NGImage.pas into multiple units   *}
+{*                                                                          *}
+{****************************************************************************}
+
+
+{$INCLUDE NGDefs.inc}
+
+
+interface
+
+
+{****************************************************************************}
+
+const
+  { Library Name for early/late Binding }
+{$IFDEF LINUX}
+  mngdll              = 'libmng.so.1';                     // do not localize
+  zdll                = 'libz.so.1';                       // do not localize
+  jpegdll             = 'libjpeg.so.62';                   // do not localize
+{$ELSE}
+  mngdll              = 'libmng.dll';                      // do not localize
+{$ENDIF}
+
+  { Build Version Information - MODIFIED ON PUBLIC RELEASES ONLY! }
+  TNGVersionStr       = '1.2.0';                           // do not localize
+  TNGVersionMajor     = 1;
+  TNGVersionMinor     = 2;
+  TNGVersionRelease   = 0;
+
+  TNGLibmngRequired   = '1.0.5';                           // do not localize
+
+  { PNG & MNG spec constants }
+  MNG_PNG_VERSION     = '1.2';                             // do not localize
+  MNG_PNG_VERSION_MAJ = 1;
+  MNG_PNG_VERSION_MIN = 2;
+
+  MNG_MNG_VERSION     = '1.0';                             // do not localize
+  MNG_MNG_VERSION_MAJ = 1;
+  MNG_MNG_VERSION_MIN = 0;
+  MNG_MNG_DRAFT       = 99;            // deprecated
+
+  { Library Defined Constant Equivalents }
+  MNG_TRUE            = TRUE;
+  MNG_FALSE           = FALSE;
+  MNG_NULL            = nil;
+
+{****************************************************************************}
+{* local constants & types                                                  *}
+{****************************************************************************}
+
+resourcestring
+  SCClipboardNotSupported  = 'PNG/JNG/MNG clipboard not yet supported'; // do not localize
+  SCNGImageException       = 'PNG/JNG/MNG error %s '#13#10'in function %s'#13#10 + // do not localize
+                             'Code=%d; Severity=%d; Chunknr=%d; Extra=%d/%d'; // do not localize
+  SCNGSavePNGillegal       = 'PNG save not supported in this state'; // do not localize
+  SCNGSaveJNGillegal       = 'JNG save not supported in this state'; // do not localize
+  SCNGVideoNotSupported    = 'Function not supported in video playback mode'; // do not localize
+  SCNGVersionError         = 'NGImage %s requires libmng %s or later'; // do not localize
+
+  SCZLIBError              = 'Serious ZLIB error...';      // do not localize
+
+{$IFDEF LATE_BINDING}
+{$IFDEF LINUX}
+  SCDLLNotLoaded           = 'libmng.so was not loaded correctly'; // do not localize
+  SCDLLNotLoaded2          = 'zlib.so was not loaded correctly'; // do not localize
+{$ELSE}
+  SCDLLNotLoaded           = 'libmng.dll was not loaded correctly'; // do not localize
+{$ENDIF}
+  SCFuncUnknown            = 'Function not available in this version'; // do not localize
+{$ENDIF}
+
+const
+  SCPNGExt                 = 'PNG';                        // do not localize
+  SCJNGExt                 = 'JNG';                        // do not localize
+  SCMNGExt                 = 'MNG';                        // do not localize
+  SCJPEGExt1               = 'JPE';                        // do not localize
+  SCJPEGExt2               = 'JFIF';                       // do not localize
+  SCJPEGExt3               = 'JPEG';                       // do not localize
+  SCJPEGExt4               = 'JPG';                        // do not localize
+
+  SCPNGImageFile           = 'Portable Network Graphics';  // do not localize
+  SCJNGImageFile           = 'JPEG Network Graphics';      // do not localize
+  SCMNGImageFile           = 'Multiple-image Network Graphics'; // do not localize
+  SCJPEGImageFile          = 'JPEG image';                 // do not localize
+
+{****************************************************************************}
+
+  { function names for errormessages }
+const
+  SCCreate             = 'Create/';                        // do not localize
+  SCInitialize         = 'initialize';                     // do not localize
+  SCSetStoreChunks     = 'set_storechunks';                // do not localize
+  SCSetCBxxxx          = 'setcb_xxxx';                     // do not localize
+  SCSetCanvasStyle     = 'set_canvasstyle';                // do not localize
+  SCDestroy            = 'Destroy/';                       // do not localize
+  SCCleanup            = 'cleanup';                        // do not localize
+  SCLoadFromStream     = 'LoadFromStream/';                // do not localize
+  SCLoadFromFile       = 'LoadFromFile/';                  // do not localize
+  SCSaveToStream       = 'SaveToStream/';                  // do not localize
+  SCSaveToFile         = 'SaveToFile/';                    // do not localize
+  SCTrapEvent          = 'TrapEvent/trapevent';            // do not localize
+  SCLoadFromResource   = 'LoadFromResource/';              // do not localize
+  SCRead               = 'read';                           // do not localize
+  SCWrite              = 'write';                          // do not localize
+  SCDisplay            = 'display';                        // do not localize
+  SCProcessTimer       = 'ProcessTimer/';                  // do not localize
+  SCDisplayResume      = 'display_resume';                 // do not localize
+  SCRewind             = 'Rewind/';                        // do not localize
+  SCDisplayReset       = 'display_reset';                  // do not localize
+  SCPause              = 'Pause/';                         // do not localize
+  SCDisplayFreeze      = 'display_freeze';                 // do not localize
+  SCPlay               = 'Play/';                          // do not localize
+  SCReset              = 'Reset/';                         // do not localize
+  SCCreatePNG          = 'CreatePNG/';                     // do not localize
+  SCCreateJNG          = 'CreateJNG/';                     // do not localize
+  SCReset2             = 'reset';                          // do not localize
+  SCCreate2            = 'create';                         // do not localize
+  SCPutChunkIHDR       = 'putchunk_ihdr';                  // do not localize
+  SCPutChunkJHDR       = 'putchunk_jhdr';                  // do not localize
+  SCPutChunkSRGB       = 'putchunk_srgb';                  // do not localize
+  SCPutChunkPLTE       = 'putchunk_plte';                  // do not localize
+  SCPutChunkTRNS       = 'putchunk_trns';                  // do not localize
+  SCPutChunkIDAT       = 'putchunk_idat';                  // do not localize
+  SCPutChunkJDAT       = 'putchunk_jdat';                  // do not localize
+  SCPutChunkIEND       = 'putchunk_iend';                  // do not localize
+  SCSetCachePlayback   = 'set_cacheplayback';              // do not localize
+  SCReadDisplay        = 'readdisplay';                    // do not localize
+  SCSetBGImage         = 'setbgimage';                     // do not localize
+
+{****************************************************************************}
+
+  { Return Values }
+const
+  MNG_NOERROR          = 0;
+
+  MNG_OUTOFMEMORY      = 1;
+  MNG_INVALIDHANDLE    = 2;
+  MNG_NOCALLBACK       = 3;
+  MNG_UNEXPECTEDEOF    = 4;
+  MNG_ZLIBERROR        = 5;
+  MNG_JPEGERROR        = 6;
+  MNG_LCMSERROR        = 7;
+  MNG_NOOUTPUTPROFILE  = 8;
+  MNG_NOSRGBPROFILE    = 9;
+  MNG_BUFOVERFLOW      = 10;
+  MNG_FUNCTIONINVALID  = 11;
+  MNG_OUTPUTERROR      = 12;
+  MNG_JPEGBUFTOOSMALL  = 13;
+  MNG_NEEDMOREDATA     = 14;
+  MNG_NEEDTIMERWAIT    = 15;
+  MNG_NEEDSECTIONWAIT  = 16;
+  MNG_LOOPWITHCACHEOFF = 17;
+
+{$IFDEF LATE_BINDING}
+  MNG_DLLNOTLOADED     = 99;
+{$ENDIF}
+
+  MNG_APPIOERROR       = 901;
+  MNG_APPTIMERERROR    = 902;
+  MNG_APPCMSERROR      = 903;
+  MNG_APPMISCERROR     = 904;
+  MNG_APPTRACEABORT    = 905;
+
+  MNG_INTERNALERROR    = 999;
+
+  MNG_INVALIDSIG       = 1025;
+  MNG_INVALIDCRC       = 1027;
+  MNG_INVALIDLENGTH    = 1028;
+  MNG_SEQUENCEERROR    = 1029;
+  MNG_CHUNKNOTALLOWED  = 1030;
+  MNG_MULTIPLEERROR    = 1031;
+  MNG_PLTEMISSING      = 1032;
+  MNG_IDATMISSING      = 1033;
+  MNG_CANNOTBEEMPTY    = 1034;
+  MNG_GLOBALLENGTHERR  = 1035;
+  MNG_INVALIDBITDEPTH  = 1036;
+  MNG_INVALIDCOLORTYPE = 1037;
+  MNG_INVALIDCOMPRESS  = 1038;
+  MNG_INVALIDFILTER    = 1039;
+  MNG_INVALIDINTERLACE = 1040;
+  MNG_NOTENOUGHIDAT    = 1041;
+  MNG_PLTEINDEXERROR   = 1042;
+  MNG_NULLNOTFOUND     = 1043;
+  MNG_KEYWORDNULL      = 1044;
+  MNG_OBJECTUNKNOWN    = 1045;
+  MNG_OBJECTEXISTS     = 1046;
+  MNG_TOOMUCHIDAT      = 1047;
+  MNG_INVSAMPLEDEPTH   = 1048;
+  MNG_INVOFFSETSIZE    = 1049;
+  MNG_INVENTRYTYPE     = 1050;
+  MNG_ENDWITHNULL      = 1051;
+  MNG_INVIMAGETYPE     = 1052;
+  MNG_INVDELTATYPE     = 1053;
+  MNG_INVALIDINDEX     = 1054;
+  MNG_TOOMUCHJDAT      = 1055;
+  MNG_JPEGPARMSERR     = 1056;
+  MNG_INVFILLMETHOD    = 1057;
+  MNG_OBJNOTCONCRETE   = 1058;
+  MNG_TARGETNOALPHA    = 1059;
+  MNG_MNGTOOCOMPLEX    = 1060;
+  MNG_UNKNOWNCRITICAL  = 1061;
+  MNG_UNSUPPORTEDNEED  = 1062;
+  MNG_INVALIDDELTA     = 1063;
+  MNG_INVALIDMETHOD    = 1064;
+  MNG_IMPROBABLELENGTH = 1065;
+  MNG_INVALIDBLOCK     = 1066;
+  MNG_INVALIDEVENT     = 1067;
+  MNG_INVALIDMASK      = 1068;
+  MNG_NOMATCHINGLOOP   = 1069;
+  MNG_SEEKNOTFOUND     = 1070;
+  MNG_OBJNOTABSTRACT   = 1071;
+
+  MNG_INVALIDCNVSTYLE  = 2049;
+  MNG_WRONGCHUNK       = 2050;
+  MNG_INVALIDENTRYIX   = 2051;
+  MNG_NOHEADER         = 2052;
+  MNG_NOCORRCHUNK      = 2053;
+  MNG_NOMHDR           = 2054;
+
+  MNG_IMAGETOOLARGE    = 4097;
+  MNG_NOTANANIMATION   = 4098;
+  MNG_FRAMENRTOOHIGH   = 4099;
+  MNG_LAYERNRTOOHIGH   = 4100;
+  MNG_PLAYTIMETOOHIGH  = 4101;
+  MNG_FNNOTIMPLEMENTED = 4102;
+
+  MNG_IMAGEFROZEN      = 8193;
+
+  MNG_LCMS_NOHANDLE    = 1;
+  MNG_LCMS_NOMEM       = 2;
+  MNG_LCMS_NOTRANS     = 3;
+
+{****************************************************************************}
+
+const
+  MNG_CANVAS_RGB8                  = $00000000;
+  MNG_CANVAS_RGBA8                 = $00001000;
+  MNG_CANVAS_ARGB8                 = $00003000;
+  MNG_CANVAS_RGB8_A8               = $00005000;
+  MNG_CANVAS_BGR8                  = $00000001;
+  MNG_CANVAS_BGRA8                 = $00001001;
+  MNG_CANVAS_BGRX8                 = $00010001;
+  MNG_CANVAS_ABGR8                 = $00003001;
+
+  MNG_BITDEPTH_1                   = 1;       { IHDR, BASI, JHDR, PROM }
+  MNG_BITDEPTH_2                   = 2;
+  MNG_BITDEPTH_4                   = 4;
+  MNG_BITDEPTH_8                   = 8;       { sPLT }
+  MNG_BITDEPTH_16                  = 16;
+
+  MNG_COLORTYPE_GRAY               = 0;       { IHDR, BASI, PROM }
+  MNG_COLORTYPE_RGB                = 2;
+  MNG_COLORTYPE_INDEXED            = 3;
+  MNG_COLORTYPE_GRAYA              = 4;
+  MNG_COLORTYPE_RGBA               = 6;
+
+  MNG_COMPRESSION_DEFLATE          = 0;       { IHDR, zTXt, iTXt, iCCP,
+                                                BASI, JHDR }
+
+  MNG_FILTER_ADAPTIVE              = 0;       { IHDR, BASI, JHDR }
+
+  MNG_INTERLACE_NONE               = 0;       { IHDR, BASI, JHDR }
+  MNG_INTERLACE_ADAM7              = 1;
+
+  MNG_FILTER_NONE                  = 0;       { IDAT }
+  MNG_FILTER_SUB                   = 1;
+  MNG_FILTER_UP                    = 2;
+  MNG_FILTER_AVERAGE               = 3;
+  MNG_FILTER_PAETH                 = 4;
+
+  MNG_INTENT_PERCEPTUAL            = 0;       { sRGB }
+  MNG_INTENT_RELATIVECOLORIMETRIC  = 1;
+  MNG_INTENT_SATURATION            = 2;
+  MNG_INTENT_ABSOLUTECOLORIMETRIC  = 3;
+                                              { tEXt, zTXt, iTXt }
+  MNG_TEXT_TITLE                   = 'Title';              // do not localize
+  MNG_TEXT_AUTHOR                  = 'Author';             // do not localize
+  MNG_TEXT_DESCRIPTION             = 'Description';        // do not localize
+  MNG_TEXT_COPYRIGHT               = 'Copyright';          // do not localize
+  MNG_TEXT_CREATIONTIME            = 'Creation Time';      // do not localize
+  MNG_TEXT_SOFTWARE                = 'Software';           // do not localize
+  MNG_TEXT_DISCLAIMER              = 'Disclaimer';         // do not localize
+  MNG_TEXT_WARNING                 = 'Warning';            // do not localize
+  MNG_TEXT_SOURCE                  = 'Source';             // do not localize
+  MNG_TEXT_COMMENT                 = 'Comment';            // do not localize
+
+  MNG_FLAG_UNCOMPRESSED            = 0;       { iTXt }
+  MNG_FLAG_COMPRESSED              = 1;
+
+  MNG_UNIT_UNKNOWN                 = 0;       { pHYs, pHYg }
+  MNG_UNIT_METER                   = 1;
+                                              { MHDR }
+  MNG_SIMPLICITY_VALID             = $00000001;
+  MNG_SIMPLICITY_SIMPLEFEATURES    = $00000002;
+  MNG_SIMPLICITY_COMPLEXFEATURES   = $00000004;
+  MNG_SIMPLICITY_TRANSPARENCY      = $00000008;
+  MNG_SIMPLICITY_JNG               = $00000010;
+  MNG_SIMPLICITY_DELTAPNG          = $00000020;
+
+  MNG_TERMINATION_DECODER_NC       = 0;       { LOOP }
+  MNG_TERMINATION_USER_NC          = 1;
+  MNG_TERMINATION_EXTERNAL_NC      = 2;
+  MNG_TERMINATION_DETERMINISTIC_NC = 3;
+  MNG_TERMINATION_DECODER_C        = 4;
+  MNG_TERMINATION_USER_C           = 5;
+  MNG_TERMINATION_EXTERNAL_C       = 6;
+  MNG_TERMINATION_DETERMINISTIC_C  = 7;
+
+  MNG_DONOTSHOW_VISIBLE            = 0;       { DEFI }
+  MNG_DONOTSHOW_NOTVISIBLE         = 1;
+
+  MNG_ABSTRACT                     = 0;       { DEFI }
+  MNG_CONCRETE                     = 1;
+
+  MNG_NOTVIEWABLE                  = 0;       { BASI }
+  MNG_VIEWABLE                     = 1;
+
+  MNG_FULL_CLONE                   = 0;       { CLON }
+  MNG_PARTIAL_CLONE                = 1;
+  MNG_RENUMBER                     = 2;
+
+  MNG_CONCRETE_ASPARENT            = 0;       { CLON }
+  MNG_CONCRETE_MAKEABSTRACT        = 1;
+
+  MNG_LOCATION_ABSOLUTE            = 0;       { CLON, MOVE }
+  MNG_LOCATION_RELATIVE            = 1;
+
+  MNG_TARGET_ABSOLUTE              = 0;       { PAST }
+  MNG_TARGET_RELATIVE_SAMEPAST     = 1;
+  MNG_TARGET_RELATIVE_PREVPAST     = 2;
+
+  MNG_COMPOSITE_OVER               = 0;       { PAST }
+  MNG_COMPOSITE_REPLACE            = 1;
+  MNG_COMPOSITE_UNDER              = 2;
+
+  MNG_ORIENTATION_SAME             = 0;       { PAST }
+  MNG_ORIENTATION_180DEG           = 2;
+  MNG_ORIENTATION_FLIPHORZ         = 4;
+  MNG_ORIENTATION_FLIPVERT         = 6;
+  MNG_ORIENTATION_TILED            = 8;
+
+  MNG_OFFSET_ABSOLUTE              = 0;       { PAST }
+  MNG_OFFSET_RELATIVE              = 1;
+
+  MNG_BOUNDARY_ABSOLUTE            = 0;       { PAST, FRAM }
+  MNG_BOUNDARY_RELATIVE            = 1;
+
+  MNG_BACKGROUNDCOLOR_MANDATORY    = $01;     { BACK }
+  MNG_BACKGROUNDIMAGE_MANDATORY    = $02;     { BACK }
+
+  MNG_BACKGROUNDIMAGE_NOTILE       = 0;       { BACK }
+  MNG_BACKGROUNDIMAGE_TILE         = 1;
+
+  MNG_FRAMINGMODE_NOCHANGE         = 0;       { FRAM }
+  MNG_FRAMINGMODE_1                = 1;
+  MNG_FRAMINGMODE_2                = 2;
+  MNG_FRAMINGMODE_3                = 3;
+  MNG_FRAMINGMODE_4                = 4;
+
+  MNG_CHANGEDELAY_NO               = 0;       { FRAM }
+  MNG_CHANGEDELAY_NEXTSUBFRAME     = 1;
+  MNG_CHANGEDELAY_DEFAULT          = 2;
+
+  MNG_CHANGETIMOUT_NO              = 0;       { FRAM }
+  MNG_CHANGETIMOUT_DETERMINISTIC_1 = 1;
+  MNG_CHANGETIMOUT_DETERMINISTIC_2 = 2;
+  MNG_CHANGETIMOUT_DECODER_1       = 3;
+  MNG_CHANGETIMOUT_DECODER_2       = 4;
+  MNG_CHANGETIMOUT_USER_1          = 5;
+  MNG_CHANGETIMOUT_USER_2          = 6;
+  MNG_CHANGETIMOUT_EXTERNAL_1      = 7;
+  MNG_CHANGETIMOUT_EXTERNAL_2      = 8;
+
+  MNG_CHANGECLIPPING_NO            = 0;       { FRAM }
+  MNG_CHANGECLIPPING_NEXTSUBFRAME  = 1;
+  MNG_CHANGECLIPPING_DEFAULT       = 2;
+
+  MNG_CHANGESYNCID_NO              = 0;       { FRAM }
+  MNG_CHANGESYNCID_NEXTSUBFRAME    = 1;
+  MNG_CHANGESYNCID_DEFAULT         = 2;
+
+  MNG_CLIPPING_ABSOLUTE            = 0;       { CLIP }
+  MNG_CLIPPING_RELATIVE            = 1;
+
+  MNG_SHOWMODE_0                   = 0;       { SHOW }
+  MNG_SHOWMODE_1                   = 1;
+  MNG_SHOWMODE_2                   = 2;
+  MNG_SHOWMODE_3                   = 3;
+  MNG_SHOWMODE_4                   = 4;
+  MNG_SHOWMODE_5                   = 5;
+  MNG_SHOWMODE_6                   = 6;
+  MNG_SHOWMODE_7                   = 7;
+
+  MNG_TERMACTION_LASTFRAME         = 0;       { TERM }
+  MNG_TERMACTION_CLEAR             = 1;
+  MNG_TERMACTION_FIRSTFRAME        = 2;
+  MNG_TERMACTION_REPEAT            = 3;
+
+  MNG_ITERACTION_LASTFRAME         = 0;       { TERM }
+  MNG_ITERACTION_CLEAR             = 1;
+  MNG_ITERACTION_FIRSTFRAME        = 2;
+
+  MNG_SAVEOFFSET_4BYTE             = 4;       { SAVE }
+  MNG_SAVEOFFSET_8BYTE             = 8;
+
+  MNG_SAVEENTRY_SEGMENTFULL        = 0;       { SAVE }
+  MNG_SAVEENTRY_SEGMENT            = 1;
+  MNG_SAVEENTRY_SUBFRAME           = 2;
+  MNG_SAVEENTRY_EXPORTEDIMAGE      = 3;
+
+  MNG_PRIORITY_ABSOLUTE            = 0;       { fPRI }
+  MNG_PRIORITY_RELATIVE            = 1;
+
+  MNG_COLORTYPE_JPEGGRAY           = 8;       { JHDR }
+  MNG_COLORTYPE_JPEGCOLOR          = 10;
+  MNG_COLORTYPE_JPEGGRAYA          = 12;
+  MNG_COLORTYPE_JPEGCOLORA         = 14;
+
+  MNG_BITDEPTH_JPEG8               = 8;       { JHDR }
+  MNG_BITDEPTH_JPEG12              = 12;
+  MNG_BITDEPTH_JPEG8AND12          = 20;
+
+  MNG_COMPRESSION_BASELINEJPEG     = 8;       { JHDR }
+
+  MNG_INTERLACE_SEQUENTIAL         = 0;       { JHDR }
+  MNG_INTERLACE_PROGRESSIVE        = 8;
+
+  MNG_IMAGETYPE_UNKNOWN            = 0;       { DHDR }
+  MNG_IMAGETYPE_PNG                = 1;
+  MNG_IMAGETYPE_JNG                = 2;
+
+  MNG_DELTATYPE_REPLACE            = 0;       { DHDR }
+  MNG_DELTATYPE_BLOCKPIXELADD      = 1;
+  MNG_DELTATYPE_BLOCKALPHAADD      = 2;
+  MNG_DELTATYPE_BLOCKCOLORADD      = 3;
+  MNG_DELTATYPE_BLOCKPIXELREPLACE  = 4;
+  MNG_DELTATYPE_BLOCKALPHAREPLACE  = 5;
+  MNG_DELTATYPE_BLOCKCOLORREPLACE  = 6;
+  MNG_DELTATYPE_NOCHANGE           = 7;
+
+  MNG_FILLMETHOD_LEFTBITREPLICATE  = 0;       { PROM }
+  MNG_FILLMETHOD_ZEROFILL          = 1;
+
+  MNG_DELTATYPE_REPLACERGB         = 0;       { PPLT }
+  MNG_DELTATYPE_DELTARGB           = 1;
+  MNG_DELTATYPE_REPLACEALPHA       = 2;
+  MNG_DELTATYPE_DELTAALPHA         = 3;
+  MNG_DELTATYPE_REPLACERGBA        = 4;
+  MNG_DELTATYPE_DELTARGBA          = 5;
+
+  MNG_POLARITY_ONLY                = 0;       { DBYK }
+  MNG_POLARITY_ALLBUT              = 1;
+
+  MNG_EVENT_NONE                   = 0;       { EvNT }
+  MNG_EVENT_MOUSEENTER             = 1;
+  MNG_EVENT_MOUSEMOVE              = 2;
+  MNG_EVENT_MOUSEEXIT              = 3;
+  MNG_EVENT_MOUSEDOWN              = 4;
+  MNG_EVENT_MOUSEUP                = 5;
+
+  MNG_MASK_NONE                    = 0;       { EvNT }
+  MNG_MASK_BOX                     = 1;
+  MNG_MASK_OBJECT                  = 2;
+  MNG_MASK_OBJECTIX                = 3;
+  MNG_MASK_BOXOBJECT               = 4;
+  MNG_MASK_BOXOBJECTIX             = 5;
+
+  MNG_TYPE_TEXT                    = 0;
+  MNG_TYPE_ZTXT                    = 1;
+  MNG_TYPE_ITXT                    = 2;
+
+{****************************************************************************}
+
+implementation
+
+{****************************************************************************}
+
+end.
+
+
+
+
+

Added: branches/BCB5/TNGImage/Package/NGDefs.inc
===================================================================
--- branches/BCB5/TNGImage/Package/NGDefs.inc	                        (rev 0)
+++ branches/BCB5/TNGImage/Package/NGDefs.inc	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,41 @@
+// folowing directives can be turned off to exclude specific parts if needed
+// (note: TNGImage itself is always defined !)
+
+//{$DEFINE INCLUDE_PNG_SAVE}             // include PNG save support in TNGImage
+{$IFNDEF LINUX}              // eg. not supported yet under Kylix
+//{$DEFINE INCLUDE_JNG_SAVE}             // include JNG save support in TNGImage
+{$ENDIF}
+{$DEFINE INCLUDE_ZLIB}                 // include ZLIB support functions
+                                       // (needed for either PNG or JNG save!!)
+{$IFNDEF LINUX}              // eg. not supported yet under Kylix
+//{$DEFINE INCLUDE_JPEG}                 // include JPEG support & TJPEGImage
+{$ENDIF}                               // (needed for JNG save!!)
+
+{$DEFINE REGISTER_PNG}                 // include & register TPNGImage
+{$DEFINE REGISTER_JNG}                 // include & register TJNGImage
+{$DEFINE REGISTER_MNG}                 // include & register TMNGImage
+{$IFDEF INCLUDE_JPEG}
+//{$DEFINE REGISTER_JPEG}                // register TJPEGImage
+{$ENDIF}
+
+// added by Peter J. Haas
+// is AlphaColorTo1BitAlpha defined, AlphaColor will be stored as 1 bit mask
+// else as 8 bit alpha mask (0 or $FF) in the CreateJNG function.
+{$DEFINE AlphaColorTo1BitAlpha}
+
+// added by Scott Price
+// turn this on to load libmng.dll at the latest possible moment
+// (e.g. not at application load time but when first accessed)
+{$DEFINE LATE_BINDING}
+
+// \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
+// define internal dependencies (DO NOT MODIFY!!)
+
+{$IFDEF INCLUDE_PNG_SAVE}
+{$DEFINE INCLUDE_ZLIB}
+{$ENDIF}
+{$IFDEF INCLUDE_JNG_SAVE}
+{$DEFINE INCLUDE_ZLIB}
+{$DEFINE INCLUDE_JPEG}
+{$ENDIF}
+

Added: branches/BCB5/TNGImage/Package/NGImages.pas
===================================================================
--- branches/BCB5/TNGImage/Package/NGImages.pas	                        (rev 0)
+++ branches/BCB5/TNGImage/Package/NGImages.pas	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,3572 @@
+unit NGImages;
+
+{****************************************************************************}
+{*               This is version: 1.2.0                                     *}
+{****************************************************************************}
+{*                                                                          *}
+{*  COPYRIGHT NOTICE:                                                       *}
+{*                                                                          *}
+{*  Copyright (c) 2001-2002 Gerard Juyn, Scott Price                        *}
+{*  [You may insert additional notices after this sentence if you modify    *}
+{*   this source]                                                           *}
+{*                                                                          *}
+{*  For the purposes of this copyright and license, "Contributing Authors"  *}
+{*  is currently defined as the following set of individuals:               *}
+{*                                                                          *}
+{*     Gerard Juyn            GJU  (gerard at libmng.com)                   *}
+{*     Scott Price            SPR                                           *}
+{*     Peter J. Haas          PJH                                           *}
+{*     Alexander Tereschenko  ALT  (alex at plastiqueweb.com)               *}
+{*                                                                          *}
+{*  This component is supplied "AS IS".  The Contributing Authors           *}
+{*  disclaim all warranties, expressed or implied, including, without       *}
+{*  limitation, the warranties of merchantability and of fitness for any    *}
+{*  purpose.  The Contributing Authors assume no liability for direct,      *}
+{*  indirect, incidental, special, exemplary, or consequential damages,     *}
+{*  which may result from the use of this component, even if advised of     *}
+{*  the possibility of such damage.                                         *}
+{*                                                                          *}
+{*  Permission is hereby granted to use, copy, modify, and distribute this  *}
+{*  source code, or portions hereof, for any purpose, without fee, subject  *}
+{*  to the following restrictions:                                          *}
+{*                                                                          *}
+{*  1. The origin of this source code must not be misrepresented;           *}
+{*     you must not claim that you wrote the original software.             *}
+{*                                                                          *}
+{*  2. Altered versions must be plainly marked as such and must not be      *}
+{*     misrepresented as being the original source.                         *}
+{*                                                                          *}
+{*  3. This Copyright notice may not be removed or altered from any source  *}
+{*     or altered source distribution.                                      *}
+{*                                                                          *}
+{*  The Contributing Authors specifically permit, without fee, and          *}
+{*  encourage the use of this source code as a component to supporting      *}
+{*  the MNG/JNG and PNG file format in commercial products. If you use this *}
+{*  source code in a product, acknowledgment would be highly appreciated.   *}
+{*                                                                          *}
+{****************************************************************************}
+{*                                                                          *}
+{*  Copyrights & Trademarks                                                 *}
+{*                                                                          *}
+{*  Uses "libmng" - an open-source initiative by Gerard Juyn                *}
+{*  copyright (C) 2000-2002 G. Juyn                                         *}
+{*  http://www.libmng.com/                                                  *}
+{*                                                                          *}
+{*  Based in part on the works of the Independant JPEG Group (IJG)          *}
+{*  copyright (C) 1991-1998 Thomas G. Lane                                  *}
+{*  http://www.ijg.org/                                                     *}
+{*                                                                          *}
+{*  Uses "lcms" (little CMS) by Marti Maria Saguer                          *}
+{*  distributed under LGPL                                                  *}
+{*  http://www.littlecms.com/                                               *}
+{*                                                                          *}
+{*  Uses "zlib" - a mighty, patent-free(!) (de)compression-library          *}
+{*  copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler                 *}
+{*  http://www.zlib.org/                                                    *}
+{*                                                                          *}
+{*  The implementation of the TJPEGImage is based on sample code in the     *}
+{*  JPEG unit provided with Borland Delphi.                                 *}
+{*  Copyright (c) 1997 Borland International                                *}
+{*  (only adapted to work with ijgsrc6b in libmng.dll)                      *}
+{*                                                                          *}
+{*  Parts of the source-code are courtesy of Triple-T                       *}
+{*  http://www.3-t.com/                                                     *}
+{*                                                                          *}
+{****************************************************************************}
+{*                                                                          *}
+{*  Changelog:                            * reverse chronological order *   *}
+{*                                                                          *}
+{*  * 1.2.0  *                                                              *}
+{*  2002/10/07 - GJU - Added more libmng events                             *}
+{*             - GJU - Fixed assign method to copy all TNGImage properties  *}
+{*             - GJU - Added function to copy bitmap contents               *}
+{*  2002/10/03 - GJU - Updated to libmng 1.0.5                              *}
+{*  2002/09/19 - GJU - Added LoadFromResource function                      *}
+{*  2002/08/04 - GJU - Added PNGneeded & JNGneeded functions                *}
+{*             - GJU - Added property to access the TNGBitmap mng_handle    *}
+{*                                                                          *}
+{*  * 1.0.1  *                                                              *}
+{*  2001/10/23 - GJU - Adapted to work with Kylix                           *}
+{*             - GJU - Added OnRefresh event                                *}
+{*                                                                          *}
+{*  * 0.9.8c *                                                              *}
+{*  2001/08/25 - SPR - Fixed Late Binding ZLIB method reference issue       *}
+{*                                                                          *}
+{*  * 0.9.8b *                                                              *}
+{*  2001/08/25 - GJU - Added BGImage property for assigning background-image*}
+{*             - GJU - Added OnProcessHeader event                          *}
+{*                                                                          *}
+{*  * 0.9.8 *                                                               *}
+{*  2001/08/12 - ALT - Added Delphi6 package                                *}
+{*             - GJU - Changed the fix for TOpenPictureDialog as Borland    *}
+{*                     changed its design in D6                             *}
+{*  2001/07/23 - GJU - Added gamma control functions                        *}
+{*  2001/07/22 - GJU - Fixed some formatting                                *}
+{*  2001/07/21 - GJU - Added code to prevent 256->16 palette reduction bug  *}
+{*                     (really wondering if it'll work this way?!?!?)       *} // do not localize
+{*                     (search for 'Phil Scadden')                          *} // do not localize
+{*  2001/06/26 - GJU - Changed most CheckLIBMNGLoaded to assigned/exception *}
+{*             - GJU - Fixed 'Invalid Window Handle' in OpenPictureDialog   *} // do not localize
+{*             - GJU - Added limit checking for JPEG quality setting        *}
+{*             - GJU - added TMNGVideo component (see mngvideo.txt)         *}
+{*                     (optimized for video-stream playback)                *}
+{*  2001/06/23 - SPR - Added stuff for late binding (see latebinding.txt)   *}
+{*  2001/06/16 - GJU - Moved all string-constants to NGConst.pas            *}
+{*  2001/06/12 - SPR - Tidied up CreatePNG                                  *}
+{*             - SPR - Bracketed some if statements for easier debugging    *}
+{*  2001/06/10 - PJH - Added 1 bit alpha mask for alpha color               *}
+{*             - PJH - BugFix 8 bit alpha mask for alpha color              *}
+{*             - PJH - Fixed D5 compiler warnings (signed/unsigned compare) *}
+{*  2001/05/08 - SPR - Restructured for Maintainability                     *}
+{*             - SPR - Seperated original NGImage.pas into multiple units   *}
+{*                                                                          *}
+{****************************************************************************}
+{*                                                                          *}
+{*  TODO:                                                                   *}
+{*                                                                          *}
+{*  - several optimizations                                                 *}
+{*  - support for OnProgress                                                *}
+{*  - The number of timers available to the system is limited.              *}
+{*    Perhaps consider other options.                                       *}
+{*                                                                          *}
+{****************************************************************************}
+
+
+{$INCLUDE NGDefs.inc}
+
+
+
+interface
+
+
+
+uses { Own Units }
+     NGTypes, NGConst,
+{$IFDEF INCLUDE_JPEG}
+     NGJPEG,
+{$ENDIF}
+{$IFDEF LINUX}
+     NGBitmap,
+{$ENDIF}
+     { Borland Standard Units }
+{$IFDEF LINUX}
+     Qt, Types, QControls, QExtCtrls, QGraphics, QTypes, IdGlobal,
+{$ELSE}
+     Windows, Controls, ExtCtrls, Graphics,
+{$ENDIF}
+     Classes, SysUtils;
+
+
+{****************************************************************************}
+{* event types                                                              *}
+{****************************************************************************}
+
+type
+  TNGProcessText     = procedure (Sender         : TObject;
+                                  TextType       : mng_uint8;
+                                  Keyword        : string;
+                                  Text           : string;
+                                  Language       : string;
+                                  Translation    : string    ) of object;
+  TNGProcessSave     = procedure (Sender         : TObject   ) of object;
+  TNGProcessSeek     = procedure (Sender         : TObject;
+                                  Name           : string    ) of object;
+  TNGProcessNeed     = procedure (Sender         : TObject;
+                                  Keyword        : string;
+                                  var Allowed    : mng_bool  ) of object;
+  TNGProcessMend     = procedure (Sender         : TObject;
+                                  Iterationsdone : mng_uint32;
+                                  Iterationsleft : mng_uint32) of object;
+  TNGProcessUnknown  = procedure (Sender         : TObject;
+                                  Chunkid        : mng_chunkid;
+                                  Rawlen         : mng_uint32;
+                                  Rawdata        : mng_ptr   ) of object;
+  TNGProcessTerm     = procedure (Sender         : TObject;
+                                  Termaction     : mng_uint8;
+                                  Iteraction     : mng_uint8;
+                                  Delay          : mng_uint32;
+                                  Itermax        : mng_uint32) of object;
+                           
+{****************************************************************************}
+{* actual object definitions                                                *}
+{****************************************************************************}
+
+type
+  TNGImage  = class;
+
+{****************************************************************************}
+{* internal object to facilitate reference counting of a LIBMNG handle      *}
+{****************************************************************************}
+
+{$IFDEF LINUX}
+  TNGBitmap = class (TNGBMP)
+{$ELSE}
+  TNGBitmap = class (TBitmap)
+{$ENDIF}  
+  private
+    { Private declarations }
+    HFHandle          : mng_handle;         // libmng handle
+    OFImages          : TList;              // parent TNGImage objects
+    { TODO:  The number of timers available to the system is limited. Perhaps consider other options. }
+    OFTimer           : TTimer;             // timer for MNG animation
+    OFStream          : TStream;            // stream for load/save
+    BFFreeOnClose     : boolean;            // free the stream on load/save completed
+    BFHaveHeader      : boolean;            // processed PNG/JNG/MNG header chunk
+
+    IFAlphaColor      : integer;            // to add transparency after assigning
+    OFAlphaBitmap     : TBitmap;            // a TBitmap to TNGImage
+    OFBGImage         : TBitmap;            // background-image
+
+{$IFDEF INCLUDE_ZLIB}
+    IFZLIBLevel       : integer;            // ZLIB compression parameters
+    IFZLIBMethod      : integer;
+    IFZLIBWindowbits  : integer;
+    IFZLIBMemLevel    : integer;
+    IFZLIBStrategy    : integer;
+    IFZLIBMaxIDAT     : cardinal;
+{$ENDIF}
+
+{$IFDEF INCLUDE_JPEG}
+    IFJPEGQuality     : TJPEGQualityRange;  // JPEG compression parameters
+    BFJPEGProgressive : boolean;
+    IFJPEGMaxJDAT     : cardinal;
+{$ENDIF}
+
+    BFStatusCheck     : boolean;            // lock recursive status checks
+    BFCreating        : boolean;            // libmng status history
+    BFWriting         : boolean;
+    BFReading         : boolean;
+    BFDisplaying      : boolean;
+    BFRunning         : boolean;
+    BFDynamic         : boolean;
+
+    procedure SetBGImage      (OHImage   : TBitmap);
+
+    procedure CheckStatus;
+
+    procedure ProcessTimer    (Sender    : TObject);
+
+    procedure Refresh         (IHX, IHY  : integer;
+                               IHWidth   : integer;
+                               IHHeight  : integer);
+
+{$IFDEF INCLUDE_PNG_SAVE}              // PNG save support ?
+    function  CompressRawdata (SHRawdata : string) : string;
+    procedure CreatePNG;
+{$ENDIF}
+{$IFDEF INCLUDE_JNG_SAVE}              // JNG save support ?
+    procedure CreateJNG;
+{$ENDIF}
+
+    procedure LibMNG_Error    (SHMsg     : string);
+
+  protected
+    { Protected declarations }
+    procedure Rewind;                  // Restart from first frame
+    procedure Pause;                   // Pause at current frame
+    procedure Play;                    // Resume from current frame (after pause)
+    procedure Stop;                    // Stop animation (cannot resume in this case!)
+
+                                       // dynamic MNG support
+    procedure TrapEvent   (IHEventType : byte;
+                           IHX, IHY    : integer);
+
+    procedure AddImage    (OHImage : TNGImage);
+    procedure RemoveImage (OHImage : TNGImage);
+
+  public
+    { Public declarations }
+    constructor Create; override;
+    destructor Destroy; override;
+
+    procedure LoadFromStream (      Stream   : TStream); override;
+    procedure SaveToStream   (      Stream   : TStream); override;
+    procedure LoadFromFile   (const FileName : string ); override;
+    procedure SaveToFile     (const FileName : string ); override;
+
+{$IFNDEF LINUX}
+    procedure LoadFromClipboardFormat
+                             (      AFormat  : Word;
+                                    AData    : THandle;
+                                    APalette : HPALETTE); override;
+    procedure SaveToClipboardFormat
+                             (var   AFormat  : Word;
+                              var   AData    : THandle;
+                              var   APalette : HPALETTE); override;
+    procedure LoadFromResource
+                             (      Instance : THandle;
+                              const ResName  : string;
+                                    ResType  : PChar   );
+{$ENDIF}
+
+  end;
+
+{****************************************************************************}
+{* The PNG/JNG/MNG base class                                               *}
+{*                                                                          *}
+{* This will function like any other descendant of TGraphic, except that    *}
+{* not all functionality is (as of yet) supported.                          *}
+{* But basic operations such as LoadFromFile/LoadFromStream and Draw        *}
+{* are supported.                                                           *}
+{****************************************************************************}
+
+  TNGImage = class (TGraphic)
+  private
+    OFCanvas         : TCanvas;        // remembered from "draw" override
+    OFRect           : TRect;          // remembered from "draw" override
+{$IFNDEF LINUX}
+    HFCanvasParent   : HWND;           // window handle of canvas parent control
+{$ENDIF}
+    BFRefreshing     : boolean;        // lock recursive refreshes
+    OFBitmap         : TNGBitmap;      // actual bitmap data
+
+    // from here on down are external properties
+
+    OFStatusChange   : TNotifyEvent;   // triggered when libmng status changes
+    OFProcessHeader  : TNotifyEvent;   // triggered when libmng has read the
+                                       // image header chunk
+    OFRefresh        : TNotifyEvent;   // triggered when libmng requests a
+                                       // canvas refresh
+
+    OFProcessText    : TNGProcessText; // various libmng callback events
+    OFProcessSave    : TNGProcessSave;
+    OFProcessSeek    : TNGProcessSeek;
+    OFProcessNeed    : TNGProcessNeed;
+    OFProcessMend    : TNGProcessMend;
+    OFProcessUnknown : TNGProcessUnknown;
+    OFProcessTerm    : TNGProcessTerm;
+
+    // internal refresh (called from TNGBitmap before call to OnRefresh event)
+
+    procedure Refresh (IHX, IHY : integer;
+                       IHWidth  : integer;
+                       IHHeight : integer);
+
+    // bitmap reference juggling routines
+
+    procedure CreateBitmap;
+    procedure DestroyBitmap;
+    procedure AssignBitmap (OHBitmap : TNGBitmap);
+    procedure IsolateBitmap;
+
+    // libmng version control
+
+    function GetLIBMNGVersionText    : string;
+    function GetLIBMNGVersionDLL     : integer;
+    function GetLIBMNGVersionMajor   : integer;
+    function GetLIBMNGVersionMinor   : integer;
+    function GetLIBMNGVersionRelease : integer;
+    function GetLIBMNGVersionBeta    : boolean;
+
+    // libmng handle
+
+    function GetHandle               : mng_handle;
+    
+    // graphic properties
+
+    function GetSignatureType        : mng_imgtype;
+    function GetImageType            : mng_imgtype;
+    function GetTicks                : cardinal;           // MNG
+    function GetFrameCount           : cardinal;           // MNG
+    function GetLayerCount           : cardinal;           // MNG
+    function GetPlayTime             : cardinal;           // MNG
+    function GetSimplicity           : cardinal;           // MNG
+    function GetBitdepth             : byte;               // PNG+JNG
+    function GetColorType            : byte;               // PNG+JNG
+    function GetCompression          : byte;               // PNG+JNG
+    function GetFilter               : byte;               // PNG
+    function GetInterlaceMethod      : byte;               // PNG+JNG
+    function GetAlphaBitdepth        : byte;               // JNG
+    function GetAlphaCompression     : byte;               // JNG
+    function GetAlphaFilter          : byte;               // JNG
+    function GetAlphaInterlace       : byte;               // JNG
+
+    function GetAlphaDepth           : byte;
+
+    // libmng background control
+
+    function GetBGColor              : TColor;
+    function GetBGImage              : TBitmap;
+    function GetUseBKGD              : boolean;
+    procedure SetBGColor             (IHValue : TColor );
+    procedure SetBGImage             (OHValue : TBitmap);
+    procedure SetUseBKGD             (BHValue : boolean);
+
+    // libmng gamma correction control
+
+    function GetViewGamma            : single;             // default 1.0
+    function GetDisplayGamma         : single;             // default 2.2
+    function GetDfltImgGamma         : single;             // default 0.45455
+    procedure SetViewGamma           (IHValue : single);
+    procedure SetDisplayGamma        (IHValue : single);
+    procedure SetDfltImgGamma        (IHValue : single);
+
+    // libmng compression variables
+
+{$IFDEF INCLUDE_ZLIB}
+    function GetZLIBLevel            : integer;
+    function GetZLIBMethod           : integer;
+    function GetZLIBWindowbits       : integer;
+    function GetZLIBMemLevel         : integer;
+    function GetZLIBStrategy         : integer;
+    function GetZLIBMaxIDAT          : cardinal;
+    procedure SetZLIBLevel           (IHValue : integer );
+    procedure SetZLIBMethod          (IHValue : integer );
+    procedure SetZLIBWindowbits      (IHValue : integer );
+    procedure SetZLIBMemLevel        (IHValue : integer );
+    procedure SetZLIBStrategy        (IHValue : integer );
+    procedure SetZLIBMaxIDAT         (IHValue : cardinal);
+{$ENDIF}
+
+{$IFDEF INCLUDE_JPEG}
+    function GetJPEGQuality          : TJPEGQualityRange;           // 1..100
+    function GetJPEGProgressive      : boolean;
+    function GetJPEGMaxJDAT          : cardinal;
+    procedure SetJPEGQuality         (IHValue : TJPEGQualityRange); // 1..100
+    procedure SetJPEGprogressive     (BHValue : boolean );
+    procedure SetJPEGMaxJDAT         (IHValue : cardinal);
+{$ENDIF}
+
+    // libmng status control
+
+    function GetMNGStartTime         : cardinal;
+    function GetMNGRunTime           : cardinal;
+    function GetMNGCurrentFrame      : cardinal;
+    function GetMNGCurrentLayer      : cardinal;
+    function GetMNGCurrentPlaytime   : cardinal;
+
+    function GetStatusError          : boolean;
+    function GetStatusReading        : boolean;
+    function GetStatusCreating       : boolean;
+    function GetStatusWriting        : boolean;
+    function GetStatusDisplaying     : boolean;
+    function GetStatusRunning        : boolean;
+    function GetStatusDynamic        : boolean;
+
+    // Transparent support
+    // 2 methods added by Peter J. Haas
+    function GetTransparentColor: TColor;
+    procedure SetTransparentColor(Value: TColor);
+
+  protected
+    // Transparent support
+    // 2 methods added by Peter J. Haas
+    function GetTransparent: Boolean; override;
+    procedure SetTransparent(Value: Boolean); override;
+
+  public
+    constructor Create; override;
+    destructor Destroy; override;
+    procedure Free;
+
+    procedure LoadFromStream  (      Stream   : TStream); override;
+    procedure SaveToStream    (      Stream   : TStream); override;
+    procedure LoadFromFile    (const FileName : string ); override;
+    procedure SaveToFile      (const FileName : string ); override;
+
+{$IFDEF LINUX}
+    procedure LoadFromMimeSource(MimeSource: TMimeSource); override;
+    procedure SaveToMimeSource(MimeSource: TClxMimeSource); override;
+{$ENDIF}
+
+{$IFNDEF LINUX}
+    procedure LoadFromClipboardFormat  // not supported yet !!!
+                              (      AFormat  : Word;
+                                     AData    : THandle;
+                                     APalette : HPALETTE); override;
+    procedure SaveToClipboardFormat    // not supported yet !!!
+                              (var   AFormat  : Word;
+                               var   AData    : THandle;
+                               var   APalette : HPALETTE); override;
+    procedure LoadFromResource
+                              (      Instance : THandle;
+                               const ResName  : string;
+                                     ResType  : PChar   );
+{$ENDIF}
+
+    function  GetHeight  : integer; override;
+    function  GetWidth   : integer; override;
+    function  GetEmpty   : boolean; override;
+
+    procedure SetHeight       (      Value    : integer); override;
+    procedure SetWidth        (      Value    : integer); override;
+
+    procedure Assign          (      Source   : TPersistent); override;
+    procedure Draw            (      ACanvas  : TCanvas;
+                               const Rect     : TRect  ); override;
+
+    // this creates a new tbitmap and copies our current content to it
+    function  CopyBitmap : TBitmap;
+
+    procedure SetAlphaColor   (      Color    : TColor );
+    // this actually assigns the bitmap internally so it can be dropped afterwards
+    procedure SetAlphaBitmap  (      Bitmap   : TBitmap);
+
+{$IFDEF INCLUDE_PNG_SAVE}              // PNG save support ?
+    procedure PNGneeded;
+    procedure SaveToPNGstream (      Stream   : TStream);
+    procedure SaveToPNGfile   (const FileName : string );
+{$ENDIF}
+{$IFDEF INCLUDE_JNG_SAVE}              // JNG save support ?
+    procedure JNGneeded;
+    procedure SaveToJNGstream (      Stream   : TStream);
+    procedure SaveToJNGfile   (const FileName : string );
+{$ENDIF}
+
+    // libmng animation functions
+
+    procedure MNG_Rewind; virtual;     // Restart from first frame
+    procedure MNG_Pause;               // Pause at current frame
+    procedure MNG_Play;                // Resume from current frame (after pause)
+    procedure MNG_Stop;                // Stop animation (cannot resume in this case!)
+
+                                       // dynamic MNG support
+    procedure MNG_TrapEvent   (IHEventType : byte;
+                               IHX, IHY    : integer);
+
+    // libmng handle (use with extreme care !!!)
+
+    property MNGHandle            : mng_handle        read GetHandle;
+
+    // libmng version control
+
+    property LIBMNGVersionText    : string            read GetLIBMNGVersionText;
+    property LIBMNGVersionDLL     : integer           read GetLIBMNGVersionDLL;
+    property LIBMNGVersionMajor   : integer           read GetLIBMNGVersionMajor;
+    property LIBMNGVersionMinor   : integer           read GetLIBMNGVersionMinor;
+    property LIBMNGVersionRelease : integer           read GetLIBMNGVersionRelease;
+    property LIBMNGVersionBeta    : boolean           read GetLIBMNGVersionBeta;
+
+    // graphic properties
+
+    property SignatureType        : mng_imgtype       read GetSignatureType;
+    property ImageType            : mng_imgtype       read GetImageType;
+    property TicksPerSecond       : cardinal          read GetTicks;             // MNG
+    property FrameCount           : cardinal          read GetFrameCount;        // MNG
+    property LayerCount           : cardinal          read GetLayerCount;        // MNG
+    property PlayTime             : cardinal          read GetPlayTime;          // MNG
+    property Simplicity           : cardinal          read GetSimplicity;        // MNG
+    property BitDepth             : byte              read GetBitdepth;          // PNG+JNG
+    property ColorType            : byte              read GetColorType;         // PNG+JNG
+    property CompressionMethod    : byte              read GetCompression;       // PNG+JNG
+    property FilterMethod         : byte              read GetFilter;            // PNG
+    property InterlaceMethod      : byte              read GetInterlaceMethod;   // PNG+JNG
+    property AlphaBitdepth        : byte              read GetAlphaBitdepth;     // JNG
+    property AlphaCompression     : byte              read GetAlphaCompression;  // JNG
+    property AlphaFilter          : byte              read GetAlphaFilter;       // JNG
+    property AlphaInterlace       : byte              read GetAlphaInterlace;    // JNG
+
+    property AlphaDepth           : byte              read GetAlphaDepth;        
+
+    // libmng background control
+
+    property BGColor              : TColor            read GetBGColor          write SetBGColor;
+    property BGImage              : TBitmap           read GetBGImage          write SetBGImage;
+    property UseBKGD              : boolean           read GetUseBKGD          write SetUseBKGD;
+
+    // libmng gamma correction control
+
+    property ViewGamma            : single            read GetViewGamma        write SetViewGamma;    // 1.0
+    property DisplayGamma         : single            read GetDisplayGamma     write SetDisplayGamma; // 2.2
+    property DfltImgGamma         : single            read GetDfltImgGamma     write SetDfltImgGamma; // 0.45455
+
+    // Transparent support
+    // 2 properties added by Peter J. Haas
+    property Transparent          : boolean           read GetTransparent      write SetTransparent;
+    property TransparentColor     : TColor            read GetTransparentColor write SetTransparentColor;
+
+    // libmng compression variables
+
+{$IFDEF INCLUDE_ZLIB}
+    property ZLIBLevel            : integer           read GetZLIBLevel        write SetZLIBLevel;
+    property ZLIBMethod           : integer           read GetZLIBMethod       write SetZLIBMethod;
+    property ZLIBWindowbits       : integer           read GetZLIBWindowbits   write SetZLIBWindowbits;
+    property ZLIBMemLevel         : integer           read GetZLIBMemLevel     write SetZLIBMemLevel;
+    property ZLIBStrategy         : integer           read GetZLIBStrategy     write SetZLIBStrategy;
+    property ZLIBMaxIDAT          : cardinal          read GetZLIBMaxIDAT      write SetZLIBMaxIDAT;
+{$ENDIF}
+
+{$IFDEF INCLUDE_JPEG}
+    property JPEGQuality          : TJPEGQualityRange read GetJPEGQuality      write SetJPEGQuality;
+    property JPEGProgressive      : boolean           read GetJPEGProgressive  write SetJPEGprogressive;
+    property JPEGmaxJDAT          : cardinal          read GetJPEGMaxJDAT      write SetJPEGMaxJDAT;
+{$ENDIF}
+
+    // libmng status control
+
+    property MNGStartTime         : cardinal          read GetMNGStartTime;      // MNG
+    property MNGRunTime           : cardinal          read GetMNGRunTime;        // MNG
+    property MNGCurrentFrame      : cardinal          read GetMNGCurrentFrame;   // MNG
+    property MNGCurrentLayer      : cardinal          read GetMNGCurrentLayer;   // MNG
+    property MNGCurrentPlaytime   : cardinal          read GetMNGCurrentPlaytime;// MNG
+
+    property StatusError          : boolean           read GetStatusError;
+    property StatusReading        : boolean           read GetStatusReading;
+    property StatusCreating       : boolean           read GetStatusCreating;
+    property StatusWriting        : boolean           read GetStatusWriting;
+    property StatusDisplaying     : boolean           read GetStatusDisplaying;
+    property StatusRunning        : boolean           read GetStatusRunning;
+    property StatusDynamic        : boolean           read GetStatusDynamic;     // "dynamic MNG"
+
+    // general events
+
+    property OnStatusChange       : TNotifyEvent      read OFStatusChange      write OFStatusChange;
+    property OnProcessHeader      : TNotifyEvent      read OFProcessHeader     write OFProcessHeader;
+    property OnRefresh            : TNotifyEvent      read OFRefresh           write OFRefresh;
+
+    // libmng events for processing PNG/JNG/MNG
+
+    property OnProcessText        : TNGProcessText    read OFProcessText       write OFProcessText;
+    property OnProcessNeed        : TNGProcessNeed    read OFProcessNeed       write OFProcessNeed;
+    property OnProcessUnknown     : TNGProcessUnknown read OFProcessUnknown    write OFProcessUnknown;
+
+    // libmng events for processing MNG
+
+    property OnProcessSave        : TNGProcessSave    read OFProcessSave       write OFProcessSave;
+    property OnProcessSeek        : TNGProcessSeek    read OFProcessSeek       write OFProcessSeek;
+    property OnProcessMend        : TNGProcessMend    read OFProcessMend       write OFProcessMend;
+    property OnProcessTerm        : TNGProcessTerm    read OFProcessTerm       write OFProcessTerm;
+
+  end;
+
+{****************************************************************************}
+{* Derived classes to support all network graphics formats                  *}
+{****************************************************************************}
+
+type
+{$IFDEF REGISTER_PNG}
+  TPNGImage = class (TNGImage);
+{$ENDIF}
+{$IFDEF REGISTER_JNG}
+  TJNGImage = class (TNGImage);
+{$ENDIF}
+{$IFDEF REGISTER_MNG}
+  TMNGImage = class (TNGImage);
+{$ENDIF}
+
+{****************************************************************************}
+{* Special video-playback component                                         *}
+{****************************************************************************}
+// Use only to save memory on long video MNGs
+// MNG must *not* have LOOP constructs; TERM is not processed
+// Save & Rewind options are not supported
+// Can only assign to TMNGVideo
+
+type
+  TMNGVideo = class (TNGImage)
+  public
+    constructor Create; override;
+
+    procedure LoadFromStream  (      Stream   : TStream); override;
+    procedure SaveToStream    (      Stream   : TStream); override;      // not supported!!!
+    procedure LoadFromFile    (const FileName : string ); override;
+    procedure SaveToFile      (const FileName : string ); override;      // not supported!!!
+
+    procedure Assign          (      Source   : TPersistent); override;  // only supports TMNGVideo!!
+
+    procedure MNG_Rewind; override;                                      // Not supported
+  end;
+
+{****************************************************************************}
+
+
+
+implementation
+
+
+
+{****************************************************************************}
+{* local constants & types                                                  *}
+{****************************************************************************}
+type
+  TRGBpixel = record
+    B : byte;
+    G : byte;
+    R : byte;
+  end;
+  PRGBpixel = ^TRGBpixel;
+
+
+{****************************************************************************}
+{* local callback funtions to interface with LIBMNG                         *}
+{****************************************************************************}
+
+function XNG_alloc (IHSize : mng_size_t) : mng_ptr;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+begin
+  GetMem(Result, IHSize);
+  FillChar(Result^, IHSize, 0);
+end;
+
+{****************************************************************************}
+
+procedure XNG_free (PHPtr  : mng_ptr;
+                    IHSize : mng_size_t);
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+begin
+  FreeMem(PHPtr, IHSize);
+end;
+
+{****************************************************************************}
+
+function XNG_gettickcount (HHHandle : mng_handle) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+begin
+{$IFDEF LINUX}
+  Result := GetTickCount;
+{$ELSE}
+  Result := Windows.GetTickCount;
+{$ENDIF}
+end;
+
+{****************************************************************************}
+
+function XNG_openstream (HHHandle : mng_handle) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+begin
+  Result := MNG_TRUE;
+end;
+
+{****************************************************************************}
+
+function XNG_closestream (HHHandle : mng_handle) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage : TNGbitmap;
+
+begin
+  OHImage := TNGbitmap(mng_get_userdata(HHHandle));
+
+  if OHImage.BFFreeOnClose then
+  begin
+    OHImage.OFStream.Free;
+    OHImage.OFStream := nil;
+  end;
+
+  Result := MNG_TRUE;
+end;
+
+{****************************************************************************}
+
+function XNG_readdata (    HHHandle : mng_handle;
+                           PHBuf    : mng_ptr;
+                           IHBuflen : mng_uint32;
+                       var IHRead   : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage : TNGbitmap;
+
+begin
+  OHImage    := TNGbitmap(mng_get_userdata(HHHandle));
+
+  with OHImage do
+  begin
+    if OFStream.Position >= OFStream.Size then
+      IHRead := 0
+    else
+      IHRead := OHImage.OFStream.Read(PHBuf^, IHBuflen);
+
+  end;
+
+  Result     := MNG_TRUE;
+end;
+
+{****************************************************************************}
+
+function XNG_writedata (    HHHandle  : mng_handle;
+                            PHBuf     : mng_ptr;
+                            IHBuflen  : mng_uint32;
+                        var IHWritten : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage : TNGbitmap;
+
+begin
+  OHImage     := TNGbitmap(mng_get_userdata(HHHandle));
+
+  with OHImage do
+    IHWritten := OHImage.OFStream.Write(PHBuf^, IHBuflen);
+
+  Result      := MNG_TRUE;
+end;
+
+{****************************************************************************}
+
+function XNG_errorproc (HHHandle    : mng_handle;
+                        IHErrorcode : mng_retcode;
+                        IHSeverity  : mng_uint8;
+                        IHChunkname : mng_chunkid;
+                        IHChunkseq  : mng_uint32;
+                        IHExtra1    : mng_int32;
+                        IHExtra2    : mng_int32;
+                        SHErrortext : mng_pchar ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+begin
+  Result := MNG_FALSE;
+end;
+
+{****************************************************************************}
+
+function XNG_processheader (HHHandle : mng_handle;
+                            IHWidth  : mng_uint32;
+                            IHHeight : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage  : TNGbitmap;
+    OHList   : TList;
+    IHX      : integer;
+    IHY      : integer;
+    OHMaster : TNGImage;
+
+begin
+  OHImage := TNGbitmap(mng_get_userdata(HHHandle));
+
+  with OHImage do
+  begin
+    Width        := IHWidth;
+    Height       := IHHeight;
+{$IFNDEF LINUX}
+    HandleType   := bmDIB;
+    PixelFormat  := pf24bit;
+{$ELSE}
+    PixelFormat  := pf32bit;
+{$ENDIF}
+
+{$IFDEF LINUX}
+    ImageNeeded;                       // make sure it's BGRA (eg. with alpha!!)
+    QImage_setAlphaBuffer(Image, true);
+{$ENDIF}
+    
+    BFHaveHeader := true;
+
+    OHList       := TList.Create;
+    try                                // notify our parents
+      for IHX := OFImages.Count-1 downto 0 do
+        OHList.Add(OFImages.Items[IHX]);
+
+      IHX := OHList.Count;
+
+      while (IHX > 0) do
+      begin
+        dec(IHX);
+        OHMaster := TNGImage(OHList.Items[IHX]);
+        IHY      := OFImages.IndexOf(OHMaster);
+
+        if (IHY >= 0) and (assigned(OHMaster.OFProcessHeader)) then
+          OHMaster.OFProcessHeader(OHMaster);
+      end;
+      
+    finally
+      OHList.Free;
+    end;
+  end;
+
+  Result := MNG_TRUE;
+end;
+
+{****************************************************************************}
+
+function XNG_getcanvasline (HHHandle : mng_handle;
+                            IHLineNr : mng_uint32) : mng_ptr;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage : TNGbitmap;
+
+begin
+  OHImage := TNGbitmap(mng_get_userdata(HHHandle));
+  Result  := OHImage.ScanLine[IHLineNr];
+end;
+
+{****************************************************************************}
+
+function XNG_getbkgdline (HHHandle : mng_handle;
+                          IHLineNr : mng_uint32) : mng_ptr;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage : TNGbitmap;
+
+begin
+  OHImage := TNGbitmap(mng_get_userdata(HHHandle));
+  if assigned(OHImage.OFBGImage) then
+    Result := OHImage.OFBGImage.ScanLine[IHLineNr]
+  else
+    Result := MNG_NULL;
+end;
+
+{****************************************************************************}
+
+function XNG_refresh (HHHandle : mng_handle;
+                      IHX, IHY : mng_uint32;
+                      IHWidth  : mng_uint32;
+                      IHHeight : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage : TNGbitmap;
+
+begin
+  OHImage := TNGbitmap(mng_get_userdata(HHHandle));
+  OHImage.Refresh(IHX, IHY, IHWidth, IHHeight);
+  Result  := MNG_TRUE;
+end;
+
+{****************************************************************************}
+
+function XNG_settimer (HHHandle : mng_handle;
+                       IHMSecs  : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage : TNGbitmap;
+
+begin
+  OHImage                  := TNGbitmap(mng_get_userdata(HHHandle));
+  OHImage.OFTimer.Interval := IHMSecs;
+  OHImage.OFTimer.Enabled  := true;
+  Result                   := MNG_TRUE;
+end;
+
+{****************************************************************************}
+
+function XNG_processtext (HHHandle      : mng_handle;
+                          IHType        : mng_uint8;
+                          PHKeyword     : mng_pchar;
+                          PHText        : mng_pchar;
+                          PHLanguage    : mng_pchar;
+                          PHTranslation : mng_pchar) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage  : TNGbitmap;
+    OHList   : TList;
+    IHX      : integer;
+    IHY      : integer;
+    OHMaster : TNGImage;
+
+begin
+  OHImage := TNGbitmap(mng_get_userdata(HHHandle));
+
+  with OHImage do
+  begin
+    OHList := TList.Create;
+    try                                // notify the parents
+      for IHX := OFImages.Count-1 downto 0 do
+        OHList.Add(OFImages.Items[IHX]);
+
+      IHX := OHList.Count;
+
+      while (IHX > 0) do
+      begin
+        dec(IHX);
+        OHMaster := TNGImage(OHList.Items[IHX]);
+        IHY      := OFImages.IndexOf(OHMaster);
+
+        if (IHY >= 0) and (assigned(OHMaster.OFProcessText)) then
+          OHMaster.OFProcessText(OHMaster, IHType, PHKeyword, PHText, PHLanguage, PHTranslation);
+      end;
+
+    finally
+      OHList.Free;
+    end;
+  end;
+
+  Result := MNG_TRUE;
+end;
+
+{****************************************************************************}
+
+function XNG_processsave (HHHandle : mng_handle) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage  : TNGbitmap;
+    OHList   : TList;
+    IHX      : integer;
+    IHY      : integer;
+    OHMaster : TNGImage;
+
+begin
+  OHImage := TNGbitmap(mng_get_userdata(HHHandle));
+
+  with OHImage do
+  begin
+    OHList := TList.Create;
+    try                                // notify the parents
+      for IHX := OFImages.Count-1 downto 0 do
+        OHList.Add(OFImages.Items[IHX]);
+
+      IHX := OHList.Count;
+
+      while (IHX > 0) do
+      begin
+        dec(IHX);
+        OHMaster := TNGImage(OHList.Items[IHX]);
+        IHY      := OFImages.IndexOf(OHMaster);
+
+        if (IHY >= 0) and (assigned(OHMaster.OFProcessSave)) then
+          OHMaster.OFProcessSave(OHMaster);
+      end;
+
+    finally
+      OHList.Free;
+    end;
+  end;
+  
+  Result := MNG_TRUE;
+end;
+
+{****************************************************************************}
+
+function XNG_processseek (HHHandle : mng_handle;
+                          PHName   : mng_pchar) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage  : TNGbitmap;
+    OHList   : TList;
+    IHX      : integer;
+    IHY      : integer;
+    OHMaster : TNGImage;
+
+begin
+  OHImage := TNGbitmap(mng_get_userdata(HHHandle));
+
+  with OHImage do
+  begin
+    OHList := TList.Create;
+    try                                // notify the parents
+      for IHX := OFImages.Count-1 downto 0 do
+        OHList.Add(OFImages.Items[IHX]);
+
+      IHX := OHList.Count;
+
+      while (IHX > 0) do
+      begin
+        dec(IHX);
+        OHMaster := TNGImage(OHList.Items[IHX]);
+        IHY      := OFImages.IndexOf(OHMaster);
+
+        if (IHY >= 0) and (assigned(OHMaster.OFProcessSeek)) then
+          OHMaster.OFProcessSeek(OHMaster, PHName);
+      end;
+
+    finally
+      OHList.Free;
+    end;
+  end;
+  
+  Result := MNG_TRUE;
+end;
+
+{****************************************************************************}
+
+function XNG_processneed (HHHandle  : mng_handle;
+                          PHKeyword : mng_pchar) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage  : TNGbitmap;
+    OHList   : TList;
+    IHX      : integer;
+    IHY      : integer;
+    OHMaster : TNGImage;
+
+begin
+  Result  := MNG_FALSE;
+  OHImage := TNGbitmap(mng_get_userdata(HHHandle));
+
+  with OHImage do
+  begin
+    OHList := TList.Create;
+    try                                // notify the parents
+      for IHX := OFImages.Count-1 downto 0 do
+        OHList.Add(OFImages.Items[IHX]);
+
+      IHX := OHList.Count;
+
+      while (IHX > 0) do
+      begin
+        dec(IHX);
+        OHMaster := TNGImage(OHList.Items[IHX]);
+        IHY      := OFImages.IndexOf(OHMaster);
+
+        if (IHY >= 0) and (assigned(OHMaster.OFProcessNeed)) then
+          OHMaster.OFProcessNeed(OHMaster, PHKeyword, Result);
+      end;
+
+    finally
+      OHList.Free;
+    end;
+  end;
+end;
+
+{****************************************************************************}
+
+function XNG_processmend (HHHandle         : mng_handle;
+                          IHIterationsdone : mng_uint32;
+                          IHIterationsleft : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage  : TNGbitmap;
+    OHList   : TList;
+    IHX      : integer;
+    IHY      : integer;
+    OHMaster : TNGImage;
+
+begin
+  OHImage := TNGbitmap(mng_get_userdata(HHHandle));
+
+  with OHImage do
+  begin
+    OHList := TList.Create;
+    try                                // notify the parents
+      for IHX := OFImages.Count-1 downto 0 do
+        OHList.Add(OFImages.Items[IHX]);
+
+      IHX := OHList.Count;
+
+      while (IHX > 0) do
+      begin
+        dec(IHX);
+        OHMaster := TNGImage(OHList.Items[IHX]);
+        IHY      := OFImages.IndexOf(OHMaster);
+
+        if (IHY >= 0) and (assigned(OHMaster.OFProcessMend)) then
+          OHMaster.OFProcessMend(OHMaster, IHIterationsDone, IHIterationsLeft);
+      end;
+
+    finally
+      OHList.Free;
+    end;
+  end;
+  
+  Result := MNG_TRUE;
+end;
+
+{****************************************************************************}
+
+function XNG_processunknown (HHHandle  : mng_handle;
+                             IHChunkid : mng_chunkid;
+                             IHRawlen  : mng_uint32;
+                             PHRawdata : mng_ptr) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage  : TNGbitmap;
+    OHList   : TList;
+    IHX      : integer;
+    IHY      : integer;
+    OHMaster : TNGImage;
+
+begin
+  OHImage := TNGbitmap(mng_get_userdata(HHHandle));
+
+  with OHImage do
+  begin
+    OHList := TList.Create;
+    try                                // notify the parents
+      for IHX := OFImages.Count-1 downto 0 do
+        OHList.Add(OFImages.Items[IHX]);
+
+      IHX := OHList.Count;
+
+      while (IHX > 0) do
+      begin
+        dec(IHX);
+        OHMaster := TNGImage(OHList.Items[IHX]);
+        IHY      := OFImages.IndexOf(OHMaster);
+
+        if (IHY >= 0) and (assigned(OHMaster.OFProcessUnknown)) then
+          OHMaster.OFProcessUnknown(OHMaster, IHChunkId, IHRawLen, PHRawData);
+      end;
+
+    finally
+      OHList.Free;
+    end;
+  end;
+  
+  Result := MNG_TRUE;
+end;
+
+{****************************************************************************}
+
+function XNG_processterm (HHHandle     : mng_handle;
+                          IHTermaction : mng_uint8;
+                          IHIteraction : mng_uint8;
+                          IHDelay      : mng_uint32;
+                          IHItermax    : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+var OHImage  : TNGbitmap;
+    OHList   : TList;
+    IHX      : integer;
+    IHY      : integer;
+    OHMaster : TNGImage;
+
+begin
+  OHImage := TNGbitmap(mng_get_userdata(HHHandle));
+
+  with OHImage do
+  begin
+    OHList := TList.Create;
+    try                                // notify the parents
+      for IHX := OFImages.Count-1 downto 0 do
+        OHList.Add(OFImages.Items[IHX]);
+
+      IHX := OHList.Count;
+
+      while (IHX > 0) do
+      begin
+        dec(IHX);
+        OHMaster := TNGImage(OHList.Items[IHX]);
+        IHY      := OFImages.IndexOf(OHMaster);
+
+        if (IHY >= 0) and (assigned(OHMaster.OFProcessTerm)) then
+          OHMaster.OFProcessTerm(OHMaster, IHTermAction, IHIterAction, IHDelay, IHIterMax);
+      end;
+
+    finally
+      OHList.Free;
+    end;
+  end;
+
+  Result := MNG_TRUE;
+end;
+
+{****************************************************************************}
+{* internal object to facilitate reference counting of a LIBMNG handle      *}
+{****************************************************************************}
+
+constructor TNGBitmap.Create;
+begin
+  inherited;
+
+{$IFDEF LINUX}
+  PixelFormat       := pf32bit;                  // Kylix uses 32bit canvas!
+{$ELSE}
+  HandleType        := bmDIB;                    // we work with 24-bit DIBs only
+  PixelFormat       := pf24bit;                  // under Windoze
+{$ENDIF}
+
+  OFImages          := TList.Create;
+  OFTimer           := TTimer.Create(nil);
+  OFTimer.Enabled   := false;
+  OFTimer.OnTimer   := ProcessTimer;
+  BFHaveHeader      := false;
+
+  IFAlphaColor      := -1;                       // no transparency supplied yet
+  OFAlphaBitmap     := nil;
+  OFBGImage         := nil;
+
+{$IFDEF INCLUDE_ZLIB}
+  IFZLIBLevel       := Z_BEST_COMPRESSION;       // ZLIB compression parameters
+  IFZLIBMethod      := Z_DEFLATED;
+  IFZLIBWindowbits  := 15;
+  IFZLIBMemLevel    := Z_MAX_MEM_LEVEL;
+  IFZLIBStrategy    := Z_DEFAULT_STRATEGY;
+  IFZLIBMaxIDAT     := 65536;
+{$ENDIF}
+
+{$IFDEF INCLUDE_JPEG}
+  IFJPEGQuality     := 90;                       // JPEG compression parameters
+  BFJPEGProgressive := false;
+  IFJPEGMaxJDAT     := 65536;
+{$ENDIF}
+
+  BFStatusCheck     := false;                    // initial libmng status
+  BFCreating        := false;
+  BFWriting         := false;
+  BFReading         := false;
+  BFDisplaying      := false;
+  BFRunning         := false;
+
+  // initialize the LIBMNG library
+  HFHandle := mng_initialize(mng_ptr(self), XNG_alloc, XNG_free, nil);
+  if HFHandle = MNG_NULL then
+    LibMNG_Error(SCCreate + SCInitialize);
+
+  // make sure we can save the file later
+  if (mng_set_storechunks(HFHandle, MNG_TRUE) <> MNG_NOERROR) then
+    LibMNG_Error(SCCreate + SCSetStoreChunks);
+
+  // initialize the callback functions
+  if (mng_setcb_openstream    (HFHandle, XNG_openstream    ) <> MNG_NOERROR) or
+     (mng_setcb_closestream   (HFHandle, XNG_closestream   ) <> MNG_NOERROR) or
+     (mng_setcb_readdata      (HFHandle, XNG_readdata      ) <> MNG_NOERROR) or
+     (mng_setcb_writedata     (HFHandle, XNG_writedata     ) <> MNG_NOERROR) or
+     (mng_setcb_errorproc     (HFHandle, XNG_errorproc     ) <> MNG_NOERROR) or
+     (mng_setcb_processheader (HFHandle, XNG_processheader ) <> MNG_NOERROR) or
+     (mng_setcb_processtext   (HFHandle, XNG_processtext   ) <> MNG_NOERROR) or
+     (mng_setcb_processsave   (HFHandle, XNG_processsave   ) <> MNG_NOERROR) or
+     (mng_setcb_processseek   (HFHandle, XNG_processseek   ) <> MNG_NOERROR) or
+     (mng_setcb_processneed   (HFHandle, XNG_processneed   ) <> MNG_NOERROR) or
+     (mng_setcb_processmend   (HFHandle, XNG_processmend   ) <> MNG_NOERROR) or
+     (mng_setcb_processunknown(HFHandle, XNG_processunknown) <> MNG_NOERROR) or
+     (mng_setcb_processterm   (HFHandle, XNG_processterm   ) <> MNG_NOERROR) or
+     (mng_setcb_getcanvasline (HFHandle, XNG_getcanvasline ) <> MNG_NOERROR) or
+     (mng_setcb_refresh       (HFHandle, XNG_refresh       ) <> MNG_NOERROR) or
+     (mng_setcb_gettickcount  (HFHandle, XNG_gettickcount  ) <> MNG_NOERROR) or
+     (mng_setcb_settimer      (HFHandle, XNG_settimer      ) <> MNG_NOERROR) then
+    LibMNG_Error(SCCreate + SCSetCBxxxx);
+
+  // initialize the canvas layout
+{$IFDEF LINUX}
+  if (mng_set_canvasstyle     (HFHandle, MNG_CANVAS_BGRA8 ) <> MNG_NOERROR) or
+     (mng_set_bkgdstyle       (HFHandle, MNG_CANVAS_BGR8  ) <> MNG_NOERROR) then
+{$ELSE}
+  if (mng_set_canvasstyle     (HFHandle, MNG_CANVAS_BGR8  ) <> MNG_NOERROR) or
+     (mng_set_bkgdstyle       (HFHandle, MNG_CANVAS_BGR8  ) <> MNG_NOERROR) then
+{$ENDIF}
+    LibMNG_Error(SCCreate + SCSetCanvasStyle);
+
+  CheckStatus;
+end;
+
+{****************************************************************************}
+
+destructor TNGBitmap.Destroy;
+begin
+  // clean it up; let's start with the timer
+  OFTimer.Enabled := false;
+  if mng_cleanup(HFHandle) <> MNG_NOERROR then
+    LibMNG_Error(SCDestroy + SCCleanup);
+
+  OFBGImage.Free;  
+  OFAlphaBitmap.Free;
+  OFTimer.Free;
+  OFImages.Free;
+  inherited;
+end;
+
+{****************************************************************************}
+
+procedure TNGBitmap.AddImage(OHImage: TNGImage);
+begin
+  // OFImages.Count is our silent reference-counter :-)
+  OFImages.Add(OHImage);
+end;
+
+{****************************************************************************}
+
+procedure TNGBitmap.RemoveImage(OHImage: TNGImage);
+var
+  IHX: integer;
+begin
+  IHX := OFImages.IndexOf(OHImage);
+  if IHX >= 0 then
+    OFImages.Delete(IHX);
+end;
+
+{***************************************************************************}
+
+procedure TNGBitmap.SetBGImage;
+begin
+  if (OFBGImage <> OHImage) then
+  begin
+    if assigned(OFBGImage) then
+      OFBGImage.Free;
+
+    if assigned(OHImage) then
+    begin
+      OFBGImage := TBitmap.Create;
+      OFBGImage.Assign(OHImage);
+
+      if (mng_setcb_getbkgdline(HFHandle, XNG_getbkgdline) <> MNG_NOERROR) then
+        LibMNG_Error(SCSetBGImage + SCSetCBxxxx);
+    end
+    else
+    begin
+      OFBGImage := nil;
+
+      if (mng_setcb_getbkgdline(HFHandle, nil) <> MNG_NOERROR) then
+        LibMNG_Error(SCSetBGImage + SCSetCBxxxx);
+    end;
+  end;
+end;
+
+{***************************************************************************}
+
+procedure TNGBitmap.CheckStatus;
+var
+  BHChanged    : boolean;
+  BHReading    : boolean;
+  BHCreating   : boolean;
+  BHWriting    : boolean;
+  BHDisplaying : boolean;
+  BHRunning    : boolean;
+  BHDynamic    : boolean;
+  IHX, IHY     : integer;
+  OHImage      : TNGImage;
+  OHList       : TList;
+begin
+  if not BFStatusCheck then            // prevent recursion !!!
+  begin
+    BFStatusCheck  := true;
+
+    try                                // get all status variables
+      BHReading    := mng_status_reading(HFHandle);
+      BHCreating   := mng_status_creating(HFHandle);
+      BHWriting    := mng_status_writing(HFHandle);
+      BHDisplaying := mng_status_displaying(HFHandle);
+      BHRunning    := mng_status_running(HFHandle);
+      BHDynamic    := mng_status_dynamic(HFHandle);
+      BHChanged    := (BHReading <> BFReading) or (BHCreating   <> BFCreating  ) or
+                      (BHWriting <> BFWriting) or (BHDisplaying <> BFDisplaying) or
+                      (BHRunning <> BFRunning) or (BHDynamic    <> BFDynamic   );
+      BFReading    := BHReading;
+      BFCreating   := BHCreating;
+      BFWriting    := BHWriting;
+      BFDisplaying := BHDisplaying;
+      BFRunning    := BHRunning;
+      BFDynamic    := BHDynamic;
+
+      if BHChanged then                // status changed ?
+      begin
+        OHList := TList.Create;
+
+        try
+          for IHX := OFImages.Count-1 downto 0 do
+            OHList.Add(OFImages.Items[IHX]);
+
+          IHX := OHList.Count;
+                                       // notify our parents
+          while (IHX > 0) do
+          begin
+            dec(IHX);
+            OHImage := TNGImage(OHList.Items[IHX]);
+            IHY     := OFImages.IndexOf(OHImage);
+
+            if (IHY >= 0) and (assigned(OHImage.OFStatusChange)) then
+              OHImage.OFStatusChange(OHImage);
+          end;
+
+        finally
+          OHList.Free;
+        end;
+      end;
+
+    finally
+      BFStatusCheck := false;
+    end;
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TNGBitmap.LoadFromStream(Stream: TStream);
+var
+  IHRslt : mng_retcode;
+begin
+  OFStream      := Stream;
+  BFFreeOnClose := false;
+
+  // load it in a single go
+  IHRslt        := mng_read(HFHandle);
+  if (IHRslt <> MNG_NOERROR) then
+    LibMNG_Error(SCLoadFromStream + SCRead);
+
+  // now make sure the first frame is visible
+  IHRslt        := mng_display(HFHandle);
+  if (IHRslt <> MNG_NOERROR) and (IHRslt <> MNG_NEEDTIMERWAIT) then
+    LibMNG_Error(SCLoadFromStream + SCDisplay);
+
+  CheckStatus;
+end;
+
+{****************************************************************************}
+
+procedure TNGBitmap.SaveToStream(Stream: TStream);
+var
+  IHRslt : mng_retcode;
+begin
+  OFStream      := Stream;
+  BFFreeOnClose := false;
+
+  // doesn't get easier than this...
+  IHRslt        := mng_write(HFHandle);
+  if IHRslt <> MNG_NOERROR then
+    LibMNG_Error(SCSaveToStream + SCWrite);
+
+  CheckStatus;
+end;
+
+{****************************************************************************}
+
+procedure TNGBitmap.LoadFromFile(const FileName: string);
+var
+  IHRslt : mng_retcode;
+begin
+  OFStream      := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
+  BFFreeOnClose := true;
+
+  // load it in a single go
+  IHRslt        := mng_read(HFHandle);
+  if (IHRslt <> MNG_NOERROR) then
+    LibMNG_Error(SCLoadFromFile + SCRead);
+
+  // now make sure the first frame is visible
+  IHRslt        := mng_display(HFHandle);
+  if (IHRslt <> MNG_NOERROR) and (IHRslt <> MNG_NEEDTIMERWAIT) then
+    LibMNG_Error(SCLoadFromFile + SCDisplay);
+
+  CheckStatus;
+end;
+
+{****************************************************************************}
+
+procedure TNGBitmap.SaveToFile(const FileName: string);
+var
+  IHRslt : mng_retcode;
+begin
+  OFStream      := TFileStream.Create(FileName, fmCreate or fmShareExclusive);
+  BFFreeOnClose := true;
+
+  // doesn't get easier than this...
+  IHRslt        := mng_write(HFHandle);
+  if (IHRslt <> MNG_NOERROR) then
+    LibMNG_Error(SCSaveToFile + SCWrite);
+
+  CheckStatus;
+end;
+
+{****************************************************************************}
+
+{$IFNDEF LINUX}
+procedure TNGBitmap.LoadFromClipboardFormat(AFormat: Word; AData: THandle;
+  APalette: HPALETTE);
+begin
+  // sorry; future extension (maybe)
+  raise ENGImageException.Create(SCClipboardNotSupported);
+end;
+{$ENDIF}
+
+{****************************************************************************}
+
+{$IFNDEF LINUX}
+procedure TNGBitmap.SaveToClipboardFormat(var AFormat: Word;
+  var AData: THandle; var APalette: HPALETTE);
+begin
+  // sorry; future extension (maybe)
+  raise ENGImageException.Create(SCClipboardNotSupported);
+end;
+{$ENDIF}
+
+{****************************************************************************}
+
+{$IFNDEF LINUX}
+procedure TNGBitmap.LoadFromResource(Instance: THandle; const ResName: string; ResType: PChar);
+var
+  IHRslt : mng_retcode;
+begin
+  OFStream      := TResourceStream.Create(Instance, ResName, ResType);
+  BFFreeOnClose := true;
+
+  // load it in a single go
+  IHRslt        := mng_read(HFHandle);
+  if (IHRslt <> MNG_NOERROR) then
+    LibMNG_Error(SCLoadFromResource + SCRead);
+
+  // now make sure the first frame is visible
+  IHRslt        := mng_display(HFHandle);
+  if (IHRslt <> MNG_NOERROR) and (IHRslt <> MNG_NEEDTIMERWAIT) then
+    LibMNG_Error(SCLoadFromResource + SCDisplay);
+
+  CheckStatus;
+end;
+{$ENDIF}
+
+{****************************************************************************}
+
+procedure TNGBitmap.ProcessTimer(Sender: TObject);
+var
+  IHRslt : mng_retcode;
+begin
+  // reset the timer; LIBMNG will set it again if necessary
+  OFTimer.Enabled := false;
+  // tell LIBMNG to fill the next frame
+  IHRslt          := mng_display_resume(HFHandle);
+  if (IHRslt <> MNG_NOERROR) and (IHRslt <> MNG_NEEDTIMERWAIT) then
+    LibMNG_Error(SCProcessTimer + SCDisplayResume);
+
+  CheckStatus;
+end;
+
+{****************************************************************************}
+
+procedure TNGBitmap.Refresh(IHX, IHY: integer; IHWidth: integer;
+  IHHeight: integer);
+var
+  IHQ : integer;
+begin
+  CheckStatus;
+  // make sure all our referred images get updated
+  for IHQ := OFImages.Count-1 downto 0 do
+  begin
+    TNGImage(OFImages.Items[IHQ]).Refresh(IHX, IHY, IHWidth, IHHeight);
+
+    // OnRefresh event ?
+    if (assigned(TNGImage(OFImages.Items[IHQ]).OFRefresh)) and (BFRunning) then
+      TNGImage(OFImages.Items[IHQ]).OFRefresh(self);
+
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TNGBitmap.Rewind;
+var
+  IHRslt : mng_retcode;
+begin
+  OFTimer.Enabled := false;
+  if (mng_display_reset(HFHandle) <> MNG_NOERROR) then
+    LibMNG_Error(SCRewind + SCDisplayReset);
+
+  IHRslt := mng_display(HFHandle);
+  if (IHRslt <> MNG_NOERROR) and (IHRslt <> MNG_NEEDTIMERWAIT) then
+    LibMNG_Error(SCRewind + SCDisplay);
+
+  CheckStatus;
+end;
+
+{****************************************************************************}
+
+procedure TNGBitmap.Pause;
+begin
+  OFTimer.Enabled := false;
+  if (mng_display_freeze(HFHandle) <> MNG_NOERROR) then
+    LibMNG_Error(SCPause + SCDisplayFreeze);
+
+  CheckStatus;
+end;
+
+{****************************************************************************}
+
+procedure TNGBitmap.Play;
+var
+  IHRslt : mng_retcode;
+begin
+  OFTimer.Enabled := false;
+  IHRslt          := mng_display_resume(HFHandle);
+  if (IHRslt <> MNG_NOERROR) and (IHRslt <> MNG_NEEDTIMERWAIT) then
+    LibMNG_Error(SCPlay + SCDisplayResume);
+
+  CheckStatus;
+end;
+
+{****************************************************************************}
+
+procedure TNGBitmap.Stop;
+begin
+  OFTimer.Enabled := false;
+  if (mng_display_reset(HFHandle) <> MNG_NOERROR) then
+    LibMNG_Error(SCRewind + SCDisplayReset);
+
+  CheckStatus;
+end;
+
+{***************************************************************************}
+
+procedure TNGBitmap.TrapEvent;
+begin
+  if BFDynamic then
+    if (mng_trapevent(HFHandle, IHEventType, IHX, IHY) <> MNG_NOERROR) then
+      LibMNG_Error(SCTrapEvent);
+
+  CheckStatus;
+end;
+
+{***************************************************************************}
+
+{$IFDEF INCLUDE_PNG_SAVE}              // PNG save support ?
+function TNGBitmap.CompressRawData(SHRawdata: string): string;
+var
+  IHBufLen : integer;
+  IHRslt   : integer;
+begin
+  IHBufLen := length(SHRawData) + 1000;          // let's assume the worst
+
+  repeat
+    Result := StringOfChar(#0, IHBufLen);        // try a compress
+    IHRslt := DeflateString2(SHRawData, Result, IFZLIBLevel, IFZLIBMethod,
+                             IFZLIBWindowBits, IFZLIBMemLevel, IFZLIBStrategy);
+
+    if IHRslt = Z_BUF_ERROR then                 // not enough bufferspace ?
+      IHBufLen := IHBufLen + 1000;
+
+  until (IHRslt <> Z_BUF_ERROR);                 // until done or error
+
+  if IHRslt <> 0 then                            // just no result on error
+    Result := '';                                          // do not localize
+end;
+{$ENDIF}
+
+{****************************************************************************}
+
+{$IFDEF INCLUDE_PNG_SAVE}
+procedure TNGBitmap.CreatePNG;
+var
+  SHRawData   : string;
+  SHRawData1  : string;
+  SHRawData2  : string;
+  SHRawData4  : string;
+  SHRawData8  : string;
+  IHBitDepth  : byte;
+  IHColorType : byte;
+  BHHasAlpha  : boolean;
+  IHMaxCol    : integer;
+  AHPalette   : mng_palette8;
+  IHMaxAlpha  : integer;
+  AHAlpha     : mng_uint8arr;
+  AHCounts    : mng_uint32arr;
+  AHDummy     : mng_uint8arr;
+
+  { Start of Local Methods }
+  {===========================================================================}
+
+  function GetIndex (IHR, IHG, IHB, IHA : byte) : integer;
+  begin
+    Result := 0;
+
+    while (Result < IHMaxCol) and ((AHPalette[Result].iRed   <> IHR) or
+                                   (AHPalette[Result].iGreen <> IHG) or
+                                   (AHPalette[Result].iBlue  <> IHB) or
+                                   (AHAlpha[Result]          <> IHA)    ) do
+      inc(Result);
+
+    if (Result >= IHMaxCol) then
+      Result := -1;
+  end;
+
+  {===========================================================================}
+
+  function GetAlphaPixel (IHX, IHY : integer) : byte;
+  begin
+    if not OFAlphaBitmap.Monochrome then
+      OFAlphaBitmap.Monochrome := true;
+{$IFDEF LINUX}
+    Result := 0;   {TODO: FIX THIS !!!!!!}
+{$ELSE}
+    Result := OFAlphaBitmap.Canvas.Pixels[IHX, IHY] and $FF;
+{$ENDIF}    
+  end;
+
+  {===========================================================================}
+
+  function GetAlpha (PHPixel: PRGBpixel; IHX, IHY: integer): byte;
+  begin
+    if OFAlphaBitmap <> nil then
+      {TODO: this is really inefficient; optimize !!! }
+      Result := GetAlphaPixel(IHX, IHY)
+    else
+    if (IFAlphaColor >= 0) and (PHPixel^.R = (IFAlphaColor       ) and $FF) and
+                               (PHPixel^.G = (IFAlphaColor shr  8) and $FF) and
+                               (PHPixel^.B = (IFAlphaColor shr 16) and $FF) then
+      Result := 0
+    else
+      Result := 255;
+  end;
+
+  {===========================================================================}
+
+  procedure CalcNrOfUniques;
+  var
+    PHPixel  : PRGBpixel;
+    IHX, IHY : integer;
+    IHQ      : integer;
+    IHR, IHG : byte;
+    IHB, IHA : byte;
+  begin
+    BHHasAlpha := false;
+    IHMaxCol   := 0;
+
+    for IHY := 0 to pred(Height) do
+    begin
+      PHPixel := PRGBpixel(Scanline [IHY]);
+
+      for IHX := 0 to pred(Width) do
+      begin
+        IHR := PHPixel^.R;
+        IHG := PHPixel^.G;
+        IHB := PHPixel^.B;
+        IHA := GetAlpha(PHPixel, IHX, IHY);
+
+        if IHA < 255 then                // indicate if we encountered transparency
+          BHHasAlpha := true;
+
+        if IHMaxCol <= 256 then          // no need to count beyond 256 entries
+        begin
+          IHQ := GetIndex(IHR, IHG, IHB, IHA);
+
+          if (IHQ >= 0) and (IHQ < IHMaxCol) then
+          begin
+            AHCounts[IHQ] := AHCounts[IHQ] + 1;
+          end
+          else
+          begin
+            if IHMaxCol < 256 then
+            begin
+              AHPalette[IHMaxCol].iRed   := IHR;
+              AHPalette[IHMaxCol].iGreen := IHG;
+              AHPalette[IHMaxCol].iBlue  := IHB;
+              AHAlpha[IHMaxCol]          := IHA;
+              AHCounts[IHMaxCol]         := 1;
+            end;
+
+            inc(IHMaxCol);
+          end;
+        end;
+
+        PHPixel := PRGBpixel(integer(PHPixel) + 3);
+      end;
+    end;
+  end;
+
+  {===========================================================================}
+
+  procedure OptimizePalette;
+  var
+    IHX, IHY : integer;
+
+    {===========================================================================}
+    { Start of OptimizePalette Local Method }
+    procedure SwapEntry (IHX, IHY : integer);
+    var
+      IHB : byte;
+      IHI : mng_uint32;
+    begin
+      IHB                   := AHPalette[IHX].iRed;
+      AHPalette[IHX].iRed   := AHPalette[IHY].iRed;
+      AHPalette[IHY].iRed   := IHB;
+      IHB                   := AHPalette[IHX].iGreen;
+      AHPalette[IHX].iGreen := AHPalette[IHY].iGreen;
+      AHPalette[IHY].iGreen := IHB;
+      IHB                   := AHPalette[IHX].iBlue;
+      AHPalette[IHX].iBlue  := AHPalette[IHY].iBlue;
+      AHPalette[IHY].iBlue  := IHB;
+      IHB                   := AHAlpha[IHX];
+      AHAlpha[IHX]          := AHAlpha[IHY];
+      AHAlpha[IHY]          := IHB;
+      IHI                   := AHCounts[IHX];
+      AHCounts[IHX]         := AHCounts[IHY];
+      AHCounts[IHY]         := IHI;
+    end;
+
+    {===========================================================================}
+    { END of OptimizePalette Local Method }
+
+  begin
+    // optimizing the palette
+    // put transparent items first
+    // both opaque or both transparent sorts on decreasing hist-count
+    for IHX := 0 to pred(IHMaxCol) do
+    begin
+      for IHY := succ(IHX) to pred(IHMaxCol) do
+      begin
+        if (AHAlpha[IHX] = 255) and (AHAlpha[IHY] = 255) then
+        begin
+          if AHCounts[IHX] < AHCounts[IHY] then
+            SwapEntry(IHX, IHY);
+        end
+        else
+        if (AHAlpha[IHX] = 255) and (AHAlpha[IHY] < 255) then
+        begin
+          SwapEntry(IHX, IHY);
+        end
+        else
+        if (AHAlpha[IHX] < 255) and (AHAlpha[IHY] < 255) then
+        begin
+          if AHCounts[IHX] < AHCounts[IHY+1] then
+            SwapEntry(IHX, IHY);
+        end;
+      end;
+    end;
+
+    // since all transparent items are first in the palette
+    // we can safely discard the ones at the back which are fully opaque
+    IHMaxAlpha := IHMaxCol;
+    while (IHMaxAlpha > 0) and (AHAlpha[IHMaxAlpha-1] = 255) do
+      dec (IHMaxAlpha);
+  end;
+
+  {===========================================================================}
+
+  procedure CreateIndexedData1;
+  var
+    IHX, IHY : integer;
+    IHR      : integer;
+    IHQ      : integer;
+    PHPixel  : PRGBpixel;
+    IHLineW  : integer;
+  begin
+    IHLineW    := ((Width + 7) shr 3) + 1;
+    SHRawData1 := StringOfChar(#0, IHLineW * Height);
+
+    for IHY := 0 to pred(Height) do
+    begin
+      PHPixel := PRGBpixel(Scanline [IHY]);
+      IHR     := (IHY * IHLineW) + 2;
+
+      for IHX := 0 to pred(Width) do
+      begin
+        IHQ := GetIndex(PHPixel^.R, PHPixel^.G, PHPixel^.B, GetAlpha(PHPixel, IHX, IHY));
+
+        case (IHX mod 8) of
+          0 : SHRawData1[IHR] := chr((IHQ and $01) shl 7);
+          1 : SHRawData1[IHR] := chr(ord(SHRawData1[IHR]) + (IHQ and $01) shl 6);
+          2 : SHRawData1[IHR] := chr(ord(SHRawData1[IHR]) + (IHQ and $01) shl 5);
+          3 : SHRawData1[IHR] := chr(ord(SHRawData1[IHR]) + (IHQ and $01) shl 4);
+          4 : SHRawData1[IHR] := chr(ord(SHRawData1[IHR]) + (IHQ and $01) shl 3);
+          5 : SHRawData1[IHR] := chr(ord(SHRawData1[IHR]) + (IHQ and $01) shl 2);
+          6 : SHRawData1[IHR] := chr(ord(SHRawData1[IHR]) + (IHQ and $01) shl 1);
+        else  SHRawData1[IHR] := chr(ord(SHRawData1[IHR]) + (IHQ and $01));
+        end;
+
+        PHPixel := PRGBpixel(integer(PHPixel) + 3);
+
+        if (IHX mod 8) = 7 then
+          inc(IHR);
+      end;
+    end;
+
+    SHRawData1 := CompressRawData(SHRawData1);
+  end;
+
+  {===========================================================================}
+
+  procedure CreateIndexedData2;
+  var
+    IHX, IHY : integer;
+    IHR      : integer;
+    IHQ      : integer;
+    PHPixel  : PRGBpixel;
+    IHLineW  : integer;
+  begin
+    IHLineW     := ((Width + 3) shr 2) + 1;
+    SHRawData2  := StringOfChar(#0, IHLineW * Height);
+
+    for IHY := 0 to pred(Height) do
+    begin
+      PHPixel := PRGBpixel(Scanline[IHY]);
+      IHR     := (IHY * IHLineW) + 2;
+
+      for IHX := 0 to pred(Width) do
+      begin
+        IHQ := GetIndex(PHPixel^.R, PHPixel^.G, PHPixel^.B, GetAlpha(PHPixel, IHX, IHY));
+
+        case (IHX mod 4) of
+          0 : SHRawData2[IHR] := chr((IHQ and $03) shl 6);
+          1 : SHRawData2[IHR] := chr(ord(SHRawData2[IHR]) + (IHQ and $03) shl 4);
+          2 : SHRawData2[IHR] := chr(ord(SHRawData2[IHR]) + (IHQ and $03) shl 2);
+        else  SHRawData2[IHR] := chr(ord(SHRawData2[IHR]) + (IHQ and $03));
+        end;
+
+        PHPixel := PRGBpixel(integer(PHPixel) + 3);
+
+        if (IHX mod 4) = 3 then
+          inc(IHR);
+      end;
+    end;
+
+    SHRawData2 := CompressRawData(SHRawData2);
+  end;
+
+  {===========================================================================}
+
+  procedure CreateIndexedData4;
+  var
+    IHX, IHY : integer;
+    IHR      : integer;
+    IHQ      : integer;
+    PHPixel  : PRGBpixel;
+    IHLineW  : integer;
+  begin
+    IHLineW    := ((Width + 1) shr 1) + 1;
+    SHRawData4 := StringOfChar (#0, IHLineW * Height);
+
+    for IHY := 0 to pred(Height) do
+    begin
+      PHPixel := PRGBpixel(Scanline[IHY]);
+      IHR     := (IHY * IHLineW) + 2;
+
+      for IHX := 0 to pred(Width) do
+      begin
+        IHQ := GetIndex(PHPixel^.R, PHPixel^.G, PHPixel^.B, GetAlpha(PHPixel, IHX, IHY));
+
+        if (IHX mod 2) = 0 then
+          SHRawData4[IHR] := chr((IHQ and $0F) shl 4)
+        else
+          SHRawData4[IHR] := chr(ord(SHRawData4[IHR]) + (IHQ and $0F));
+
+        PHPixel := PRGBpixel(integer(PHPixel) + 3);
+
+        if (IHX mod 2) = 1 then
+          inc(IHR);
+      end;
+    end;
+
+    SHRawData4 := CompressRawData(SHRawData4);
+  end;
+
+  {===========================================================================}
+
+  procedure CreateIndexedData8;
+  var
+    IHX, IHY : integer;
+    IHR      : integer;
+    PHPixel  : PRGBpixel;
+  begin
+    SHRawData8 := StringOfChar(#0, (Width + 1) * Height);
+
+    for IHY := 0 to pred(Height) do
+    begin
+      PHPixel := PRGBpixel(Scanline[IHY]);
+      IHR     := (IHY * (Width + 1)) + 2;
+
+      for IHX := 0 to pred(Width) do
+      begin
+        SHRawData8[IHR] := chr(GetIndex(PHPixel^.R, PHPixel^.G, PHPixel^.B,
+                                        GetAlpha(PHPixel, IHX, IHY)));
+        PHPixel         := PRGBpixel(integer(PHPixel) + 3);
+        inc(IHR);
+      end;
+    end;
+
+    SHRawData8 := CompressRawData(SHRawData8);
+  end;
+
+  {===========================================================================}
+
+  procedure CreateRGBAdata8;
+  var
+    IHX, IHY : integer;
+    IHR      : integer;
+    PHPixel  : PRGBpixel;
+  begin
+    SHRawData   := StringOfChar(#0, ((Width shl 2) + 1) * Height);
+    IHBitDepth  := 8;                    // 8-bit RGBA
+    IHColorType := 6;
+
+    for IHY := 0 to pred(Height) do
+    begin
+      PHPixel := PRGBpixel(Scanline[IHY]);
+      IHR     := (IHY * ((Width shl 2) + 1)) + 2;
+
+      for IHX := 0 to pred(Width) do
+      begin
+        SHRawData[IHR] := chr(PHPixel^.R); inc(IHR);
+        SHRawData[IHR] := chr(PHPixel^.G); inc(IHR);
+        SHRawData[IHR] := chr(PHPixel^.B); inc(IHR);
+        SHRawData[IHR] := chr(GetAlpha(PHPixel, IHX, IHY)); inc(IHR);
+        PHPixel        := PRGBpixel(integer(PHPixel) + 3);
+      end;
+    end;
+  end;
+
+  {===========================================================================}
+
+  procedure CreateRGBdata8;
+  var
+    IHX, IHY : integer;
+    IHR      : integer;
+    PHPixel  : PRGBpixel;
+  begin
+    SHRawData   := StringOfChar(#0, ((Width * 3) + 1) * Height);
+    IHBitDepth  := 8;                    // 8-bit RGB
+    IHColorType := 2;
+
+    for IHY := 0 to pred(Height) do
+    begin
+      PHPixel := PRGBpixel(Scanline[IHY]);
+      IHR     := (IHY * ((Width * 3) + 1)) + 2;
+
+      for IHX := 0 to pred(Width) do
+      begin
+        SHRawData[IHR] := chr(PHPixel^.R); inc(IHR);
+        SHRawData[IHR] := chr(PHPixel^.G); inc(IHR);
+        SHRawData[IHR] := chr(PHPixel^.B); inc(IHR);
+        PHPixel        := PRGBpixel(integer(PHPixel) + 3);
+      end;
+    end;
+  end;
+
+  {===========================================================================}
+  { END of Local Methods }
+
+{ Start of TNGBitmap.CreatePNG Code }
+begin
+{$IFDEF LINUX}
+  PixelFormat := pf32bit;              // we always want it in this format !!
+{$ELSE}
+  PixelFormat := pf24bit;
+{$ENDIF}
+  CalcNrOfUniques;                     // let's see if we can optimize to indexed-color
+
+  if (IHMaxCol <= 256) then            // can we... can we ???
+  begin
+    OptimizePalette;                   // make it an optimum palette then
+    IHColorType := 3;                  // indexed color!
+
+    if (IHMaxCol <= 2) then
+    begin
+      CreateIndexedData1;              // determine best possible compression
+      CreateIndexedData2;
+      CreateIndexedData4;
+      CreateIndexedData8;
+
+      if (length(SHRawData1) < length(SHRawData2)) and
+         (length(SHRawData1) < length(SHRawData4)) and
+         (length(SHRawData1) < length(SHRawData8)) then
+      begin
+        SHRawData  := SHRawData1;
+        IHBitDepth := 1;
+      end
+      else
+      if (length(SHRawData2) < length(SHRawData4)) and
+         (length(SHRawData2) < length(SHRawData8)) then
+      begin
+        SHRawData  := SHRawData2;
+        IHBitDepth := 2;
+      end
+      else
+      if length(SHRawData4) < length(SHRawData8) then
+      begin
+        SHRawData  := SHRawData4;
+        IHBitDepth := 4;
+      end
+      else
+      begin
+        SHRawData  := SHRawData8;
+        IHBitDepth := 8;
+      end;
+    end
+    else
+    if IHMaxCol <= 4 then
+    begin
+      CreateIndexedData2;              // determine best possible compression
+      CreateIndexedData4;
+      CreateIndexedData8;
+
+      if (length(SHRawData2) < length(SHRawData4)) and
+         (length(SHRawData2) < length(SHRawData8)) then
+      begin
+        SHRawData  := SHRawData2;
+        IHBitDepth := 2;
+      end
+      else
+      if length(SHRawData4) < length(SHRawData8) then
+      begin
+        SHRawData  := SHRawData4;
+        IHBitDepth := 4;
+      end
+      else
+      begin
+        SHRawData  := SHRawData8;
+        IHBitDepth := 8;
+      end;
+    end
+    else
+    if IHMaxCol <= 16 then
+    begin
+      CreateIndexedData4;              // determine best possible compression
+      CreateIndexedData8;
+
+      if length(SHRawData4) < length(SHRawData8) then
+      begin
+        SHRawData  := SHRawData4;
+        IHBitDepth := 4;
+      end
+      else
+      begin
+        SHRawData  := SHRawData8;
+        IHBitDepth := 8;
+      end;
+    end
+    else
+    begin
+      CreateIndexedData8;              // always 8-bit here
+      SHRawData    := SHRawData8;
+      IHBitDepth   := 8;
+    end;
+  end
+  else
+  begin
+    if BHHasAlpha then                 // do we need the alpha channel ?
+      CreateRGBAdata8
+    else
+      CreateRGBdata8;
+
+    SHRawData := CompressRawData(SHRawData);
+  end;
+
+  if (SHRawData = '') then             // ZLIB got botched ? // do not localize
+    raise ENGImageException.Create(SCZLIBError);
+                                       // now create the PNG chunks
+  if (mng_reset(HFHandle) <> MNG_NOERROR) then
+    LibMNG_Error(SCCreatePNG + SCReset2);
+
+  if (mng_create(HFHandle) <> MNG_NOERROR) then
+    LibMNG_Error(SCCreatePNG + SCCreate2);
+
+  if (mng_putchunk_ihdr(HFHandle, Width, Height, IHBitdepth,
+                        IHColortype, 0, 0, 0) <> MNG_NOERROR) then
+    LibMNG_Error(SCCreatePNG + SCPutChunkIHDR);
+
+  if (mng_putchunk_srgb(HFHandle, MNG_FALSE, 0) <> MNG_NOERROR) then
+    LibMNG_Error(SCCreatePNG + SCPutChunkSRGB);
+
+  if (IHColorType = 3) then
+  begin
+    if (mng_putchunk_plte(HFHandle, IHMaxCol, AHPalette) <> MNG_NOERROR) then
+      LibMNG_Error(SCCreatePNG + SCPutChunkPLTE);
+
+    if (IHMaxAlpha > 0) then
+      if (mng_putchunk_trns(HFHandle, MNG_FALSE, MNG_FALSE, 3, IHMaxAlpha,
+                            AHAlpha, 0, 0, 0, 0, 0, AHDummy) <> MNG_NOERROR) then
+        LibMNG_Error(SCCreatePNG + SCPutChunkTRNS);
+  end;
+                                       // write approprietely sized data chunks
+  while (length(SHRawdata) > LongInt(IFZLIBMaxIDAT)) do
+  begin
+    if (mng_putchunk_idat(HFHandle, IFZLIBMaxIDAT, @SHRawdata [1]) <> MNG_NOERROR) then
+      LibMNG_Error(SCCreatePNG + SCPutChunkIDAT);
+    delete(SHRawData, 1, IFZLIBMaxIDAT);
+  end;
+
+  if (SHRawdata <> '') then                                // do not localize
+    if mng_putchunk_idat(HFHandle, length (SHRawdata), @SHRawdata [1]) <> MNG_NOERROR then
+      LibMNG_Error(SCCreatePNG + SCPutChunkIDAT);
+
+  if (mng_putchunk_iend(HFHandle) <> MNG_NOERROR) then
+    LibMNG_Error(SCCreatePNG + SCPutChunkIEND);
+
+  CheckStatus;
+end;
+{$ENDIF} // INCLUDE_PNG_SAVE
+
+{****************************************************************************}
+
+{$IFDEF INCLUDE_JNG_SAVE}
+procedure TNGBitmap.CreateJNG;
+var
+  SHJDAT        : string;
+  SHIDAT        : string;
+  IHColorType   : byte;
+  IHAlphaDepth  : byte;
+  OHJPEG        : TJPEGimage;
+  IHX, IHY      : integer;
+  IHZ           : integer;
+  OHBitmap      : TBitmap;
+  IHR, IHG, IHB : byte;
+  // added 4 lines by Peter J. Haas
+  SHIDATLineSize: Integer;
+  ImageLineSize : Integer;
+  ImageLinePtr  : PByte;
+  ImagePixelPtr : PRGBTriple;
+
+  {===========================================================================}
+  // function(s) added by Peter J. Haas
+  {$ifdef AlphaColorTo1BitAlpha}
+  procedure SetPixelToFullyTransparent(X, Y: Integer);
+  const
+    cBitMask8 : array[0..7] of Byte = ($7F, $BF, $DF, $EF, $F7, $FB, $FD, $FE);
+  var
+    p: PByte;
+  begin
+    p := Pointer(SHIDAT);
+    Inc(p, (SHIDATLineSize * Y) + (X shr 3) + 1);
+    p^ := p^ and cBitMask8[X and $07];
+  end;
+  {$else}
+  procedure SetPixelToFullyTransparent(X, Y: Integer);
+  var
+    p: PByte;
+  begin
+    p := Pointer(SHIDAT);
+    Inc(p, (SHIDATLineSize * Y) + X + 1);
+    p^ := $00;
+  end;
+  {$endif}
+  // end of added
+  {===========================================================================}
+
+begin
+{$IFDEF LINUX}
+  PixelFormat := pf32bit;              // we always want it in this format !!
+{$ELSE}
+  PixelFormat := pf24bit;
+{$ENDIF}
+  SHIDAT       := '';                  // assume no alpha  // do not localize
+  IHColorType  := 10;                  // and RGB format
+  // add 1 line by Peter J. Haas
+  IHAlphaDepth := 0;
+
+  OHJPEG := TJPEGimage.Create;
+  try
+    OHJPEG.Assign(self);               // let's get the JPEG data-stream
+    OHJPEG.ProgressiveEncoding := BFJPEGProgressive;
+    OHJPEG.CompressionQuality  := IFJPEGQuality;
+    OHJPEG.Compress;
+
+    SHJDAT := StringOfChar(#0, OHJPEG.PData.PData.Size);
+    move(OHJPEG.PData.PData.Memory^, SHJDAT[1], length(SHJDAT));
+
+  finally
+    OHJPEG.Free;
+  end;
+
+  if OFAlphaBitmap <> nil then         // do we have a transparency bitmap ?
+  begin
+    {TODO: this bit can really use some optimization !!! }
+    OHBitmap := TBitmap.Create;
+
+    try
+      OHBitmap.Width      := Width;
+      OHBitmap.Height     := Height;
+      OHBitmap.Monochrome := true;
+      OHBitmap.Canvas.StretchDraw(Rect(0, 0, Width, Height), OFAlphaBitmap);
+
+      IHColorType := IHColorType + 4;
+      // added 1 line by Peter J. Haas
+      IHAlphaDepth := 8;
+      SHIDAT      := StringOfChar(#0, (Width + 1) * Height);
+      IHZ         := 1;
+
+      for IHY := 0 to pred(Height) do
+      begin
+        inc(IHZ);
+        for IHX := 0 to pred(Width) do
+        begin
+          SHIDAT[IHZ] := chr(OHBitmap.Canvas.Pixels[IHX, IHY] and $FF);
+          inc(IHZ);
+        end;
+      end;
+
+    finally
+      OHBitmap.Free;
+    end;
+  end
+  else
+  if IFAlphaColor >= 0 then            // do we have a transparency color ?
+  begin
+    // changed by Peter J. Haas
+    IHColortype    := IHColorType + 4;         // add Alpha to Color type
+    {$ifdef AlphaColorTo1BitAlpha}
+    IHAlphaDepth   := 1;                       // 1 bit Alpha
+    SHIDATLineSize := ((Width + 7) div 8) + 1;
+    {$else}
+    IHAlphaDepth   := 8;                       // 8 bit Alpha
+    SHIDATLineSize := Width + 1;
+    {$endif}
+    ImageLineSize := ((Width * 24 + 31) div 32) * 4;
+
+    // Init alpha mask
+    SHIDAT := StringOfChar(#$FF, SHIDATLineSize * Height);  // fully opaque
+    // set PNG filter byte to 0
+    ImageLinePtr := Pointer(SHIDAT);
+    for IHY := 0 to Height-1 do
+    begin
+      ImageLinePtr^ := 0;
+      Inc(ImageLinePtr, SHIDATLineSize);
+    end;
+
+    // check image for TransparentColor
+    IHR := (IFAlphaColor       ) and $FF;
+    IHG := (IFAlphaColor shr  8) and $FF;
+    IHB := (IFAlphaColor shr 16) and $FF;
+
+    ImageLinePtr := Scanline[0];
+    for IHY := 0 to Height-1 do
+    begin
+      ImagePixelPtr := PRGBTriple(ImageLinePtr);
+      for IHX := 0 to Width-1 do
+      begin
+        if (ImagePixelPtr^.rgbtBlue  = IHB) and
+           (ImagePixelPtr^.rgbtGreen = IHG) and
+           (ImagePixelPtr^.rgbtRed   = IHR) then
+          SetPixelToFullyTransparent(IHX, IHY);
+        Inc(ImagePixelPtr);
+      end;
+      Dec(ImageLinePtr, ImageLineSize);
+    end;
+    // end of change by Peter J. Haas
+  end;
+
+  {TODO: optimize alpha-channel to 1-/2-/4-bit if possible}
+
+                                       // now create the JNG chunks
+  if (mng_reset(HFHandle) <> MNG_NOERROR) then
+    LibMNG_Error(SCCreateJNG + SCReset2);
+
+  if (mng_create(HFHandle) <> MNG_NOERROR) then
+    LibMNG_Error(SCCreateJNG + SCCreate2);
+
+  if (mng_putchunk_jhdr(HFHandle, Width, Height, IHColortype,
+                        8, 8, 0, IHAlphaDepth, 0, 0, 0) <> MNG_NOERROR) then
+    LibMNG_Error(SCCreateJNG + SCPutChunkJHDR);
+
+  if (mng_putchunk_srgb(HFHandle, MNG_FALSE, 0) <> MNG_NOERROR) then
+    LibMNG_Error(SCCreateJNG + SCPutChunkSRGB);
+
+  if (SHIDAT <> '') then               // transparency present ? // do not localize
+  begin
+    SHIDAT := CompressRawData(SHIDAT); // compress it
+    if (SHIDAT = '') then              // ZLIB got botched ? // do not localize
+      raise ENGImageException.Create(SCZLIBerror);
+                                       // now write approprietely sized chunks
+    while (length(SHIDAT) > LongInt(IFZLIBMaxIDAT)) do
+    begin
+      if (mng_putchunk_idat(HFHandle, IFZLIBMaxIDAT, @SHIDAT[1]) <> MNG_NOERROR) then
+        LibMNG_Error(SCCreateJNG + SCPutChunkIDAT);
+      delete(SHIDAT, 1, IFZLIBMaxIDAT);
+    end;
+
+    if (SHIDAT <> '') then                                 // do not localize
+      if (mng_putchunk_idat(HFHandle, length (SHIDAT), @SHIDAT[1]) <> MNG_NOERROR) then
+        LibMNG_Error(SCCreateJNG + SCPutChunkIDAT);
+  end;
+                                       // write approprietely sized data chunks
+  while (length(SHJDAT) > LongInt(IFJPEGMaxJDAT)) do
+  begin
+    if (mng_putchunk_jdat(HFHandle, IFJPEGMaxJDAT, @SHJDAT[1]) <> MNG_NOERROR) then
+      LibMNG_Error(SCCreateJNG + SCPutChunkJDAT);
+    delete(SHJDAT, 1, IFJPEGMaxJDAT);
+  end;
+
+  if (SHJDAT <> '') then                                   // do not localize
+    if (mng_putchunk_jdat(HFHandle, length (SHJDAT), @SHJDAT[1]) <> MNG_NOERROR) then
+      LibMNG_Error(SCCreateJNG + SCPutChunkJDAT);
+
+  if (mng_putchunk_iend(HFHandle) <> MNG_NOERROR) then
+    LibMNG_Error(SCCreateJNG + SCPutChunkIEND);
+
+  CheckStatus;
+end;
+{$ENDIF} // INCLUDE_JNG_SAVE
+
+{****************************************************************************}
+
+procedure TNGBitmap.LibMNG_Error(SHMsg: string);
+var
+  iErrorcode : mng_uint32;
+  iSeverity  : mng_uint8;
+  iChunkname : mng_chunkid;
+  iChunkseq  : mng_uint32;
+  iExtra1    : mng_int32;
+  iExtra2    : mng_int32;
+  zErrortext : mng_pchar;
+begin
+  // extract extended error information
+  iErrorcode := mng_getlasterror(HFHandle, iSeverity, iChunkname, iChunkseq,
+                                           iExtra1, iExtra2, zErrortext);
+  // and dump
+  raise ENGImageException.CreateFmt(SCNGImageException,
+                                    [zErrortext, SHMsg, iErrorcode, iSeverity,
+                                     iChunkseq, iExtra1, iExtra2]);
+end;
+
+{****************************************************************************}
+{* The PNG/JNG/MNG base class                                               *}
+{****************************************************************************}
+
+constructor TNGImage.Create;
+begin
+  inherited;
+  BeginUseLibmng;
+
+  OFCanvas       := nil;
+  OFRect         := rect(0,0,1,1);
+{$IFNDEF LINUX}
+  HFCanvasParent := 0;
+{$ENDIF}
+  BFRefreshing   := false;
+  OFBitmap       := nil;
+  OFStatusChange := nil;
+
+  if (mng_version_major < 1) or
+     ((mng_version_major = 1) and (mng_version_minor = 0) and (mng_version_release < 5)) then
+    raise ENGImageException.CreateFmt(SCNGVersionError, [TNGVersionStr, TNGLibmngRequired]);
+
+  CreateBitmap;
+end;
+
+{****************************************************************************}
+
+destructor TNGImage.Destroy;
+begin
+  // prevent animation redraws after we've been sentenced to die
+  OFCanvas := nil;
+  if assigned(OFBitmap) then
+    DestroyBitmap;
+  EndUseLibmng;
+  inherited;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.Free;
+begin
+  // prevent animation redraws after we've been sentenced to die
+  OFCanvas := nil;
+  if assigned(OFBitmap) then
+    OFBitmap.RemoveImage(self);
+  inherited;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.CreateBitmap;
+begin
+  // create a "reference-counter" object and sign myself up
+  OFBitmap := TNGBitmap.Create;
+  OFBitmap.AddImage(self);
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.DestroyBitmap;
+begin
+  // sign myself off from the "reference-counter" object
+  OFBitmap.RemoveImage(self);
+  // if the receference count has reached rockbottom clean up the object
+  if (OFBitmap.OFImages.Count <= 0) then
+    OFBitmap.Free;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.AssignBitmap(OHBitmap: TNGBitmap);
+begin
+  // detach from the original "reference-counter" object
+  DestroyBitmap;
+  // attach to the given object
+  OFBitmap := OHBitmap;
+  OFBitmap.AddImage(self);
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.IsolateBitmap;
+begin
+  // detach and create new "reference-counter" object if we're sharing it
+  if (OFBitmap.OFImages.Count > 1) then
+  begin
+    DestroyBitmap;
+    CreateBitmap;
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.LoadFromStream(Stream: TStream);
+begin
+  //detach and create new "reference-counter" object if we're sharing it
+  IsolateBitmap;
+  // let the object do it's work
+  OFBitmap.LoadFromStream(Stream);
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SaveToStream(Stream: TStream);
+begin
+  // let the object do it's work
+  OFBitmap.SaveToStream(Stream);
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.LoadFromFile(const FileName: string);
+begin
+  // detach and create new "reference-counter" object if we're sharing it
+  IsolateBitmap;
+  // let the object do it's work
+  OFBitmap.LoadFromFile(FileName);
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SaveToFile(const FileName: string);
+begin
+  // let the object do it's work
+  OFBitmap.SaveToFile(FileName);
+end;
+
+{****************************************************************************}
+
+{$IFDEF LINUX}
+procedure TNGImage.LoadFromMimeSource(MimeSource: TMimeSource);
+begin
+  // sorry; future extension (maybe)
+   raise ENGImageException.Create(SCClipboardNotSupported);
+end;
+{$ENDIF}
+
+{****************************************************************************}
+
+{$IFDEF LINUX}
+procedure TNGImage.SaveToMimeSource(MimeSource: TClxMimeSource);
+begin
+  // sorry; future extension (maybe)
+  raise ENGImageException.Create(SCClipboardNotSupported);
+end;
+{$ENDIF}
+
+{****************************************************************************}
+
+{$IFNDEF LINUX}
+procedure TNGImage.LoadFromClipboardFormat(AFormat: Word; AData: THandle;
+  APalette: HPALETTE);
+begin
+  // detach and create new "reference-counter" object if we're sharing it
+  IsolateBitmap;
+  // let the object do it's work
+  OFBitmap.LoadFromClipboardFormat(AFormat, AData, APalette);
+end;
+{$ENDIF}
+
+{****************************************************************************}
+
+{$IFNDEF LINUX}
+procedure TNGImage.SaveToClipboardFormat(var AFormat: Word;
+  var AData: THandle; var APalette: HPALETTE);
+begin
+  // let the object do it's work
+  OFBitmap.SaveToClipboardFormat(AFormat, AData, APalette);
+end;
+{$ENDIF}
+
+{****************************************************************************}
+
+{$IFNDEF LINUX}
+procedure TNGImage.LoadFromResource(Instance: THandle; const ResName: string; ResType: PChar);
+begin
+  // detach and create new "reference-counter" object if we're sharing it
+  IsolateBitmap;
+  // let the object do it's work
+  OFBitmap.LoadFromResource(Instance, ResName, ResType);
+end;
+{$ENDIF}
+
+{****************************************************************************}
+
+function TNGImage.GetHeight: integer;
+begin
+  // let the object do it's work
+  Result := OFBitmap.Height;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetWidth: integer;
+begin
+  // let the object do it's work
+  Result := OFBitmap.Width;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetEmpty: boolean;
+begin
+  // was LIBMNG initialized?
+  Result := (OFBitmap.HFHandle = nil);
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetHeight(Value: integer);
+begin
+  // let the object do it's work
+  OFBitmap.Height := Value;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetWidth(Value: integer);
+begin
+  // let the object do it's work
+  OFBitmap.Width := Value;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.Assign(Source: TPersistent);
+begin
+  // if it's family, let's do some reference counting and share the LIBMNG handle
+  if (Source is TNGImage) then
+  begin
+    AssignBitmap(TNGImage(Source).OFBitmap);
+
+    OFStatusChange   := TNGImage(Source).OFStatusChange;  
+    OFProcessHeader  := TNGImage(Source).OFProcessHeader;
+    OFRefresh        := TNGImage(Source).OFRefresh;
+    OFProcessText    := TNGImage(Source).OFProcessText;
+    OFProcessSave    := TNGImage(Source).OFProcessSave;
+    OFProcessSeek    := TNGImage(Source).OFProcessSeek;
+    OFProcessNeed    := TNGImage(Source).OFProcessNeed;
+    OFProcessMend    := TNGImage(Source).OFProcessMend;
+    OFProcessUnknown := TNGImage(Source).OFProcessUnknown;
+    OFProcessTerm    := TNGImage(Source).OFProcessTerm;
+  end
+  else
+  if (Source is TBitmap) then          // is it a TBitmap (or descendant) ?
+  begin
+    DestroyBitmap;                     // create virgin libmng handle!
+    CreateBitmap;
+    OFBitmap.Assign(Source);
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.Draw(ACanvas: TCanvas; const Rect: TRect);
+begin
+  // remember that sucker for animations
+  OFCanvas := ACanvas;
+  OFRect   := Rect;
+
+{$IFNDEF LINUX}
+  // this mockup to prevent 'Invalid Window Handle' on OpenPictureDialog (blergh)
+{$IFDEF VER140}     // Borland changed the TOpenPictureDialog design in D6 !!!
+  if ACanvas is TControlCanvas then
+    if TControlCanvas(ACanvas).Control is TImage then
+      if TImage(TControlCanvas(ACanvas).Control).Parent <> nil then
+        HFCanvasParent := TImage(TControlCanvas(ACanvas).Control).Parent.Handle;
+{$ELSE}
+  if ACanvas is TControlCanvas then
+    if TControlCanvas(ACanvas).Control is TPaintBox then
+      if TPaintBox(TControlCanvas(ACanvas).Control).Parent <> nil then
+        HFCanvasParent := TPaintBox(TControlCanvas(ACanvas).Control).Parent.Handle;
+{$ENDIF}
+  // ...can it get any uglier than this?....
+{$ENDIF}  
+
+  // all that's left is to refresh
+  Refresh(0, 0, Width, Height);
+end;
+
+{****************************************************************************}
+
+function TNGImage.CopyBitmap: TBitmap;
+begin
+  Result := TBitmap.Create;            // create new bitmap
+  Result.Assign(OFBitmap);             // copy our contents
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.Refresh(IHX, IHY: integer; IHWidth: integer;
+  IHHeight: integer);
+{$IFNDEF LINUX}
+var HHDC : HDC;
+{$ENDIF}
+begin
+  // be sure we have something to paint to and aren't repeating ourself
+  if (OFCanvas <> nil) and (not BFRefreshing) and
+     (OFBitmap.BFHaveHeader) {$IFNDEF LINUX} and
+     ( (HFCanvasParent = 0) or (IsWindow(HFCanvasParent)) ) {$ENDIF} then
+  begin
+    BFRefreshing := true;
+    try
+{$IFDEF LINUX}
+      OFCanvas.StretchDraw(OFRect, OFBitmap);
+{$ELSE}
+      // code by Phil Scadden to prevent 256->16 palette reduction bug
+      // (will this work??? OFBitmap doesn't have a palette IMHO...)
+      HHDC := OFBitmap.Handle;
+      RealizePalette(HHDC);
+      HHDC := OFCanvas.Handle;
+      SetStretchBltMode(HHDC, Stretch_deleteScans);
+      SelectPalette(HHDC, OFBitmap.Palette, false);
+      RealizePalette(HHDC);
+      OFCanvas.CopyRect(OFRect, OFBitmap.Canvas, OFBitmap.Canvas.ClipRect);
+      // end of code by Phil Scadden
+{$ENDIF}
+    finally
+      BFRefreshing := false;
+    end;
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.MNG_Rewind;
+begin
+  OFBitmap.Rewind;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.MNG_Pause;
+begin
+  OFBitmap.Pause;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.MNG_Play;
+begin
+  OFBitmap.Play;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.MNG_Stop;
+begin
+  OFBitmap.Stop;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.MNG_TrapEvent(IHEventType : byte; IHX, IHY: integer);
+begin
+  OFBitmap.TrapEvent(IHEventType, IHX, IHY);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetLIBMNGVersionText: String;
+begin
+  Result := StrPas(mng_version_text);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetLIBMNGVersionDLL: integer;
+begin
+  Result := mng_version_dll;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetLIBMNGVersionMajor: integer;
+begin
+  Result := mng_version_major;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetLIBMNGVersionMinor: integer;
+begin
+  Result := mng_version_minor;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetLIBMNGVersionRelease: integer;
+begin
+  Result := mng_version_release;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetLIBMNGVersionBeta: boolean;
+begin
+  Result := mng_version_beta;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetHandle: mng_handle;
+begin
+  Result := OFBitmap.HFHandle;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetSignatureType: mng_imgtype;
+begin
+  Result := mng_get_sigtype(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetImageType: mng_imgtype;
+begin
+  Result := mng_get_imagetype(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetTicks: cardinal;
+begin
+  Result := mng_get_ticks(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetFrameCount: cardinal;
+begin
+  Result := mng_get_framecount(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetLayerCount: cardinal;
+begin
+  Result := mng_get_layercount(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetPlayTime: cardinal;
+begin
+  Result := mng_get_playtime(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetSimplicity: cardinal;
+begin
+  Result := mng_get_simplicity(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetBitdepth: byte;
+begin
+  Result := mng_get_bitdepth(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetColorType: byte;
+begin
+  Result := mng_get_colortype(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetCompression: byte;
+begin
+  Result := mng_get_compression(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetFilter: byte;
+begin
+  Result := mng_get_filter(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetInterlaceMethod: byte;
+begin
+  Result := mng_get_interlace(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetAlphaBitdepth: byte;
+begin
+  Result := mng_get_alphabitdepth(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetAlphaCompression: byte;
+begin
+  Result := mng_get_alphacompression(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetAlphaFilter: byte;
+begin
+  Result := mng_get_alphafilter(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetAlphaInterlace: byte;
+begin
+  Result := mng_get_alphainterlace(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetAlphaDepth: byte;
+begin
+  Result := mng_get_alphadepth(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetBGColor: TColor;
+var
+  IHRed, IHGreen, IHBlue : word;
+begin
+  mng_get_bgcolor(OFBitmap.HFHandle, IHRed, IHGreen, IHBlue);
+  IHRed   := IHRed   shr 8;                 // shift down from 16-bit to 8-bit
+  IHGreen := IHGreen shr 8;
+  IHBlue  := IHBlue  shr 8;
+  Result  := (IHBlue shl 16) + (IHGreen shl 8) + IHRed;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetBGImage: TBitmap;
+begin
+  Result := OFBitmap.OFBGImage;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetUseBKGD: boolean;
+begin
+  Result := mng_get_usebkgd(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetBGColor(IHValue: TColor);
+var
+  IHRed, IHGreen, IHBlue : word;
+begin
+  IHRed   := (IHValue       ) and $FF;      // get individual components
+  IHGreen := (IHValue shr  8) and $FF;
+  IHBlue  := (IHValue shr 16) and $FF;
+  IHRed   := IHRed   shl 8 + IHRed;         // scale up from 8-bit to 16-bit
+  IHGreen := IHGreen shl 8 + IHGreen;
+  IHBlue  := IHBlue  shl 8 + IHBlue;
+
+  mng_set_bgcolor(OFBitmap.HFHandle, IHRed, IHGreen, IHBlue);
+  OFBitmap.CheckStatus;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetBGImage(OHValue: TBitmap);
+begin
+  OFBitmap.SetBGImage(OHValue);
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetUseBKGD(BHValue: boolean);
+begin
+  mng_set_usebkgd(OFBitmap.HFHandle, BHValue);
+  OFBitmap.CheckStatus;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetViewGamma : single;
+begin
+  Result := mng_get_viewgammaint(OFBitmap.HFHandle) / 100000;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetDisplayGamma : single;
+begin
+  Result := mng_get_displaygammaint(OFBitmap.HFHandle) / 100000;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetDfltImgGamma : single;
+begin
+  Result := mng_get_dfltimggammaint(OFBitmap.HFHandle) / 100000;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetViewGamma (IHValue : single);
+begin
+  mng_set_viewgammaint(OFBitmap.HFHandle, round(IHValue * 100000));
+  OFBitmap.CheckStatus;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetDisplayGamma (IHValue : single);
+begin
+  mng_set_displaygammaint(OFBitmap.HFHandle, round(IHValue * 100000));
+  OFBitmap.CheckStatus;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetDfltImgGamma (IHValue : single);
+begin
+  mng_set_dfltimggammaint(OFBitmap.HFHandle, round(IHValue * 100000));
+  OFBitmap.CheckStatus;
+end;
+
+{****************************************************************************}
+
+{$IFDEF INCLUDE_ZLIB}
+function TNGImage.GetZLIBLevel: integer;
+begin
+  Result := OFBitmap.IFZLIBLevel;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetZLIBMethod: integer;
+begin
+  Result := OFBitmap.IFZLIBMethod;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetZLIBWindowbits: integer;
+begin
+  Result := OFBitmap.IFZLIBWindowbits;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetZLIBMemLevel: integer;
+begin
+  Result := OFBitmap.IFZLIBMemLevel;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetZLIBStrategy: integer;
+begin
+  Result := OFBitmap.IFZLIBStrategy;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetZLIBMaxIDAT: cardinal;
+begin
+  Result := OFBitmap.IFZLIBMaxIDAT;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetZLIBLevel(IHValue: integer);
+begin
+  OFBitmap.IFZLIBLevel := IHValue;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetZLIBMethod(IHValue: integer);
+begin
+  OFBitmap.IFZLIBMethod := IHValue;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetZLIBWindowbits(IHValue: integer);
+begin
+  OFBitmap.IFZLIBWindowbits := IHValue;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetZLIBMemLevel(IHValue: integer);
+begin
+  OFBitmap.IFZLIBMemLevel := IHValue;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetZLIBStrategy(IHValue: integer);
+begin
+  OFBitmap.IFZLIBStrategy := IHValue;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetZLIBMaxIDAT(IHValue: cardinal);
+begin
+  OFBitmap.IFZLIBMaxIDAT := IHValue;
+end;
+{$ENDIF} // INCLUDE_ZLIB
+
+{****************************************************************************}
+
+{$IFDEF INCLUDE_JPEG}
+function TNGImage.GetJPEGQuality: TJPEGQualityRange;
+begin
+  Result := OFBitmap.IFJPEGQuality;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetJPEGProgressive: boolean;
+begin
+  Result := OFBitmap.BFJPEGProgressive;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetJPEGMaxJDAT: cardinal;
+begin
+  Result := OFBitmap.IFJPEGMaxJDAT;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetJPEGQuality(IHValue: TJPEGQualityRange);
+begin
+  { TODO:  Add limit checking }
+  OFBitmap.IFJPEGQuality := IHValue;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetJPEGprogressive(BHValue: boolean);
+begin
+  OFBitmap.BFJPEGProgressive := BHValue;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetJPEGMaxJDAT(IHValue: cardinal);
+begin
+  OFBitmap.IFJPEGMaxJDAT := IHValue;
+end;
+{$ENDIF} // INCLUDE_JPEG
+
+{****************************************************************************}
+
+function TNGImage.GetMNGStartTime: cardinal;
+begin
+  Result := mng_get_starttime(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetMNGRunTime: cardinal;
+begin
+  Result := mng_get_runtime(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetMNGCurrentFrame: cardinal;
+begin
+  Result := mng_get_currentframe(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetMNGCurrentLayer: cardinal;
+begin
+  Result := mng_get_currentlayer(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetMNGCurrentPlaytime: cardinal;
+begin
+  Result := mng_get_currentplaytime(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetStatusError: boolean;
+begin
+  Result := mng_status_error(OFBitmap.HFHandle);
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetStatusReading: boolean;
+begin
+  OFBitmap.CheckStatus;
+  Result := OFBitmap.BFReading;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetStatusCreating: boolean;
+begin
+  OFBitmap.CheckStatus;
+  Result := OFBitmap.BFCreating;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetStatusWriting: boolean;
+begin
+  OFBitmap.CheckStatus;
+  Result := OFBitmap.BFWriting;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetStatusDisplaying: boolean;
+begin
+  OFBitmap.CheckStatus;
+  Result := OFBitmap.BFDisplaying;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetStatusRunning: boolean;
+begin
+  OFBitmap.CheckStatus;
+  Result := OFBitmap.BFRunning;
+end;
+
+{****************************************************************************}
+
+function TNGImage.GetStatusDynamic: boolean;
+begin
+  OFBitmap.CheckStatus;
+  Result := OFBitmap.BFDynamic;
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetAlphaColor(Color: TColor);
+begin
+  OFBitmap.IFAlphaColor := ColorToRGB(Color);
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SetAlphaBitmap(Bitmap: TBitmap);
+begin
+  // added by Peter J. Haas
+  if not Assigned(OFBitmap.OFAlphaBitmap) then
+    OFBitmap.OFAlphaBitmap := TBitmap.Create;
+  OFBitmap.OFAlphaBitmap.Assign(Bitmap);
+end;
+
+{****************************************************************************}
+
+// function added by Peter J. Haas
+procedure TNGImage.SetTransparentColor(Value: TColor);
+var
+  RGBColor: TColor;
+begin
+  RGBColor := ColorToRGB(Value);
+  OFBitmap.IFAlphaColor := RGBColor;
+  OFBitmap.Transparent := True;
+  OFBitmap.TransparentColor := RGBColor;
+  BGColor := RGBColor;
+  UseBKGD := True;
+end;
+
+{****************************************************************************}
+
+// function added by Peter J. Haas
+function TNGImage.GetTransparentColor: TColor;
+begin
+  Result := OFBitmap.TransparentColor;
+end;
+
+{****************************************************************************}
+
+// function added by Peter J. Haas
+procedure TNGImage.SetTransparent(Value: Boolean);
+var
+  RGBColor: TColor;
+begin
+  if OFBitmap.Transparent <> Value then
+  begin
+    OFBitmap.Transparent := Value;
+    if Value then
+    begin
+      RGBColor := BGColor;
+      OFBitmap.IFAlphaColor := RGBColor;
+      OFBitmap.TransparentColor := RGBColor;
+    end;
+    UseBKGD := Value;
+  end;
+end;
+
+{****************************************************************************}
+
+// function added by Peter J. Haas
+function TNGImage.GetTransparent: Boolean;
+begin
+  Result := OFBitmap.Transparent;
+end;
+
+{****************************************************************************}
+{* Compression and save to PNG routines                                     *}
+{****************************************************************************}
+
+{$IFDEF INCLUDE_PNG_SAVE}
+procedure TNGImage.PNGNeeded;
+begin                                  // must be virgin libmng handle !
+  if (GetStatusWriting) or (GetStatusDisplaying) then
+    raise ENGImageException.Create(SCNGSavePNGillegal);
+  if not GetStatusCreating then
+    OFBitmap.CreatePNG;                // create chunks
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SaveToPNGstream(Stream: TStream);
+begin
+  PNGNeeded;                           // create chunks and then save it
+  SaveToStream(Stream);
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SaveToPNGfile(const FileName: string);
+begin
+  PNGNeeded;                           // create chunks and then save it
+  SaveToFile(FileName);
+end;
+{$ENDIF} // INCLUDE_PNG_SAVE
+
+{****************************************************************************}
+{* Compression & save to JNG routines                                       *}
+{****************************************************************************}
+
+{$IFDEF INCLUDE_JNG_SAVE}
+procedure TNGImage.JNGNeeded;
+begin                                  // must be virgin libmng handle !
+  if (GetStatusWriting) or (GetStatusDisplaying) then
+    raise ENGImageException.Create(SCNGSaveJNGillegal);
+  if not GetStatusCreating then
+    OFBitmap.CreateJNG;                // create chunks
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SaveToJNGstream(Stream: TStream);
+begin
+  JNGNeeded;                           // create chunks and then save it
+  SaveToStream(Stream);
+end;
+
+{****************************************************************************}
+
+procedure TNGImage.SaveToJNGfile(const FileName: string);
+begin
+  JNGNeeded;                           // create chunks and then save it
+  SaveToFile(FileName);
+end;
+{$ENDIF} // INCLUDE_JNG_SAVE
+
+
+
+{****************************************************************************}
+{* The MNGVideo component                                                   *}
+{****************************************************************************}
+
+constructor TMNGVideo.Create;
+begin
+  inherited;
+  // turn off memory-consuming features
+  if (mng_set_storechunks(OFBitmap.HFHandle, MNG_FALSE) <> MNG_NOERROR) then
+    OFBitmap.LibMNG_Error(SCCreate + SCSetStoreChunks);
+  if (mng_set_cacheplayback(OFBitmap.HFHandle, MNG_FALSE) <> MNG_NOERROR) then
+    OFBitmap.LibMNG_Error(SCCreate + SCSetCachePlayback);
+end;
+
+{****************************************************************************}
+
+procedure TMNGVideo.LoadFromStream(Stream: TStream);
+var
+  IHRslt : mng_retcode;
+begin
+  with OFBitmap do
+  begin
+    OFStream      := Stream;
+    BFFreeOnClose := false;
+
+    // read & display at the same time
+    IHRslt        := mng_readdisplay(HFHandle);
+    if (IHRslt <> MNG_NOERROR) and (IHRslt <> MNG_NEEDTIMERWAIT) then
+      LibMNG_Error(SCLoadFromStream + SCReadDisplay);
+
+    CheckStatus;
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TMNGVideo.SaveToStream(Stream: TStream); // not supported!!!
+begin
+  raise ENGImageException.Create(SCNGVideoNotSupported);
+end;
+
+{****************************************************************************}
+
+procedure TMNGVideo.LoadFromFile(const FileName : string);
+var
+  IHRslt : mng_retcode;
+begin
+  with OFBitmap do
+  begin
+    OFStream      := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
+    BFFreeOnClose := true;
+
+    // read & display at the same time
+    IHRslt        := mng_readdisplay(HFHandle);
+    if (IHRslt <> MNG_NOERROR) and (IHRslt <> MNG_NEEDTIMERWAIT) then
+      LibMNG_Error(SCLoadFromFile + SCReadDisplay);
+
+    CheckStatus;
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TMNGVideo.SaveToFile(const FileName : string); // not supported!!!
+begin
+  raise ENGImageException.Create(SCNGVideoNotSupported);
+end;
+
+{****************************************************************************}
+
+procedure TMNGVideo.Assign(Source: TPersistent); // only supports TMNGVideo!!
+begin
+  // if it's family, let's do some reference counting and share the LIBMNG handle
+  if (Source is TMNGVideo) then
+    AssignBitmap(TMNGVideo(Source).OFBitmap)
+  else
+    raise ENGImageException.Create(SCNGVideoNotSupported);
+end;
+
+{****************************************************************************}
+
+procedure TMNGVideo.MNG_Rewind; // Not supported
+begin
+  raise ENGImageException.Create(SCNGVideoNotSupported);
+end;
+
+{****************************************************************************}
+{* Register/Unregister our derived classes                                  *}
+{****************************************************************************}
+
+initialization
+{$IFDEF INCLUDE_JPEG}
+  NGJPEG.InitDefaults;
+{$IFDEF REGISTER_JPEG}
+  TPicture.RegisterFileFormat(SCJPEGExt1, SCJPEGImageFile, TJPEGImage);
+  TPicture.RegisterFileFormat(SCJPEGExt2, SCJPEGImageFile, TJPEGImage);
+  TPicture.RegisterFileFormat(SCJPEGExt3, SCJPEGImageFile, TJPEGImage);
+  TPicture.RegisterFileFormat(SCJPEGExt4, SCJPEGImageFile, TJPEGImage);
+{$ENDIF}
+{$ENDIF}
+{$IFDEF REGISTER_MNG}
+  TPicture.RegisterFileFormat(SCMNGExt, SCMNGImageFile, TMNGImage);
+{$ENDIF}
+{$IFDEF REGISTER_JNG}
+  TPicture.RegisterFileFormat(SCJNGExt, SCJNGImageFile, TJNGImage);
+{$ENDIF}
+{$IFDEF REGISTER_PNG}
+  TPicture.RegisterFileFormat(SCPNGExt, SCPNGImageFile, TPNGImage);
+{$ENDIF}
+
+{****************************************************************************}
+
+
+finalization
+{$IFDEF REGISTER_PNG}
+  TPicture.UnregisterGraphicClass(TPNGImage);
+{$ENDIF}
+{$IFDEF REGISTER_JNG}
+  TPicture.UnregisterGraphicClass(TJNGImage);
+{$ENDIF}
+{$IFDEF REGISTER_MNG}
+  TPicture.UnregisterGraphicClass(TMNGImage);
+{$ENDIF}
+{$IFDEF REGISTER_JPEG}
+  TPicture.UnregisterGraphicClass(TJPEGImage);
+{$ENDIF}
+
+{****************************************************************************}
+
+
+
+end.

Added: branches/BCB5/TNGImage/Package/NGJPEG.pas
===================================================================
--- branches/BCB5/TNGImage/Package/NGJPEG.pas	                        (rev 0)
+++ branches/BCB5/TNGImage/Package/NGJPEG.pas	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,2210 @@
+unit NGJPEG;
+
+{****************************************************************************}
+{*                                                                          *}
+{*  for copyright and version information see header in NGImages.pas        *}
+{*                                                                          *}
+{****************************************************************************}
+{*                                                                          *}
+{*  Changelog:                            * reverse chronological order *   *}
+{*                                                                          *}
+{*  * 0.9.8 *                                                               *}
+{*  2001/07/21 - GJU - Fixed late binding for JPEG                          *}
+{*  2001/07/16 - SPR - Added late binding for JPEG                          *}
+{*  2001/05/08 - SPR - Restructured for Maintainability                     *}
+{*             - SPR - Seperated original NGImage.pas into multiple units   *}
+{*                                                                          *}
+{****************************************************************************}
+
+
+{$INCLUDE NGDefs.inc}
+
+
+
+interface
+
+
+
+uses { Borland Standard Units }
+     { NOTE:  Graphics MUST be AFTER the "Windows" unit, as BOTH define a
+              Bitmap type, and only the Graphics One defines the required
+              properties used in some of the methods }
+     Classes, Windows, Graphics;
+
+
+{****************************************************************************}
+{* LIBMNG interface definitions for JPEG                                    *}
+{****************************************************************************}
+{*                                                                          *}
+{*  Based in part on the works of the Independant JPEG Group (IJG)          *}
+{*  copyright (C) 1991-1998 Thomas G. Lane                                  *}
+{*  http://www.ijg.org                                                      *}
+{*                                                                          *}
+{*  The implementation of the TJPEGImage is based on sample code in the     *}
+{*  JPEG unit provided with Borland Delphi.                                 *}
+{*  Copyright (c) 1997 Borland International                                *}
+{*  (only adapted to work with ijgsrc6b in libmng.dll)                      *}
+{*                                                                          *}
+{****************************************************************************}
+
+resourcestring
+  sChangeJPGSize = 'Cannot change the size of a JPEG image'; // do not localize
+  sJPEGError = 'JPEG error #%d';                           // do not localize
+
+{***************************************************************************}
+
+type
+  TJPEGQualityRange = 1..100;   // 100 = best quality, 25 = pretty awful
+  TJPEGPerformance = (jpBestQuality, jpBestSpeed);
+  TJPEGScale = (jsFullSize, jsHalf, jsQuarter, jsEighth);
+  TJPEGPixelFormat = (jf24Bit, jf8Bit);
+
+{***************************************************************************}
+
+type
+  { TJPEGData }
+
+  TJPEGData = class(TSharedImage)
+  private
+    { Private declarations }
+    FData: TCustomMemoryStream;
+    FHeight: Integer;
+    FWidth: Integer;
+    FGrayscale: Boolean;
+    FBuffer: Pointer;                  // added for JPEGLIB streaming support
+    FSize: Integer;                    // size of buffer
+  protected
+    { Protected declarations }
+    procedure FreeHandle; override;
+  public
+    { Public declarations }
+    constructor Create;
+    destructor Destroy; override;
+
+    property PData: TCustomMemoryStream read FData;
+  end;
+
+
+  { TJPEGImage }
+
+  TJPEGImage = class(TGraphic)
+  private
+    { Private declarations }
+    FImage: TJPEGData;
+    FBitmap: TBitmap;
+    FScaledWidth: Integer;
+    FScaledHeight: Integer;
+    FTempPal: HPalette;
+    FSmoothing: Boolean;
+    FGrayScale: Boolean;
+    FPixelFormat: TJPEGPixelFormat;
+    FQuality: TJPEGQualityRange;
+    FProgressiveDisplay: Boolean;
+    FProgressiveEncoding: Boolean;
+    FPerformance: TJPEGPerformance;
+    FScale: TJPEGScale;
+    FNeedRecalc: Boolean;
+
+    procedure CalcOutputDimensions;
+    function GetBitmap: TBitmap;
+    function GetGrayscale: Boolean;
+    procedure SetGrayscale(Value: Boolean);
+    procedure SetPerformance(Value: TJPEGPerformance);
+    procedure SetPixelFormat(Value: TJPEGPixelFormat);
+    procedure SetScale(Value: TJPEGScale);
+    procedure SetSmoothing(Value: Boolean);
+  protected
+    { Protected declarations }
+    procedure AssignTo(Dest: TPersistent); override;
+    procedure Changed(Sender: TObject); override;
+    procedure Draw(ACanvas: TCanvas; const Rect: TRect); override;
+    function Equals(Graphic: TGraphic): Boolean; override;
+    procedure FreeBitmap;
+    function GetEmpty: Boolean; override;
+    function GetHeight: Integer; override;
+    function GetPalette: HPALETTE; override;
+    function GetWidth: Integer; override;
+    procedure NewBitmap;
+    procedure NewImage;
+    procedure ReadData(Stream: TStream); override;
+    procedure ReadStream(Size: Longint; Stream: TStream);
+    procedure SetHeight(Value: Integer); override;
+    procedure SetPalette(Value: HPalette); override;
+    procedure SetWidth(Value: Integer); override;
+    procedure WriteData(Stream: TStream); override;
+  public
+    { Public declarations }
+    constructor Create; override;
+    destructor Destroy; override;
+    procedure Compress;
+    procedure DIBNeeded;
+    procedure JPEGNeeded;
+    procedure Assign(Source: TPersistent); override;
+    procedure LoadFromStream(Stream: TStream); override;
+    procedure SaveToStream(Stream: TStream); override;
+    procedure LoadFromClipboardFormat(AFormat: Word; AData: THandle;
+      APalette: HPALETTE); override;
+    procedure SaveToClipboardFormat(var AFormat: Word; var AData: THandle;
+      var APalette: HPALETTE); override;
+
+    property Bitmap: TBitmap read GetBitmap;  // volatile
+    property PData: TJPEGData read FImage;
+    // Options affecting / reflecting compression and decompression behavior
+    property Grayscale: Boolean read GetGrayscale write SetGrayscale;
+    property ProgressiveEncoding: Boolean read FProgressiveEncoding write FProgressiveEncoding;
+
+    // Compression options
+    property CompressionQuality: TJPEGQualityRange read FQuality write FQuality;
+
+    // Decompression options
+    property PixelFormat: TJPEGPixelFormat read FPixelFormat write SetPixelFormat;
+    property ProgressiveDisplay: Boolean read FProgressiveDisplay write FProgressiveDisplay;
+    property Performance: TJPEGPerformance read FPerformance write SetPerformance;
+    property Scale: TJPEGScale read FScale write SetScale;
+    property Smoothing: Boolean read FSmoothing write SetSmoothing;
+  end;
+
+{***************************************************************************}
+
+  { TJPEGDefaults }
+
+  TJPEGDefaults = record
+    CompressionQuality: TJPEGQualityRange;
+    Grayscale: Boolean;
+    Performance: TJPEGPerformance;
+    PixelFormat: TJPEGPixelFormat;
+    ProgressiveDisplay: Boolean;
+    ProgressiveEncoding: Boolean;
+    Scale: TJPEGScale;
+    Smoothing: Boolean;
+  end;
+
+{***************************************************************************}
+
+var   // Default settings for all new TJPEGImage instances
+  JPEGDefaults: TJPEGDefaults = (
+    CompressionQuality: 90;
+    Grayscale: False;
+    Performance: jpBestQuality;
+    PixelFormat: jf24Bit;         // initialized to match video mode
+    ProgressiveDisplay: False;
+    ProgressiveEncoding: False;
+    Scale: jsFullSize;
+    Smoothing: True;
+  );
+
+{***************************************************************************}
+
+{ The following types and external function declarations are used to
+  call into functions of the Independent JPEG Group's (IJG) implementation // do not localize
+  of the JPEG image compression/decompression public standard.  The IJG
+  library's C source code is compiled into OBJ files and linked into // do not localize
+  the Delphi application. Only types and functions needed by this unit
+  are declared; all IJG internal structures are stubbed out with
+  generic pointers to reduce internal source code congestion.
+
+  IJG source code copyright (C) 1991-1996, Thomas G. Lane. }
+
+{$Z4}  // Minimum enum size = dword
+
+const
+  JPEG_LIB_VERSION = 62;        { Version 6b }
+
+  JPEG_RST0     = $D0;  { RST0 marker code }
+  JPEG_EOI      = $D9;  { EOI marker code }
+  JPEG_APP0     = $E0;  { APP0 marker code }
+  JPEG_COM      = $FE;  { COM marker code }
+
+  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 }
+  C_MAX_BLOCKS_IN_MCU = 10;     { compressor's limit on blocks per MCU } // do not localize
+  D_MAX_BLOCKS_IN_MCU = 10;     { decompressor's limit on blocks per MCU } // do not localize
+  MAX_COMPONENTS = 10;          { maximum number of image components (color channels) }
+
+  MAXJSAMPLE = 255;
+  CENTERJSAMPLE = 128;
+
+type
+  JSAMPLE = byte;
+  GETJSAMPLE = integer;
+  JCOEF = word;
+  JCOEF_PTR = ^JCOEF;
+  UINT8 = byte;
+  UINT16 = Word;
+  UINT = Cardinal;
+  INT16 = SmallInt;
+  INT32 = Integer;
+  INT32PTR = ^INT32;
+  JDIMENSION = Cardinal;
+
+  JOCTET = Byte;
+  jTOctet = 0..(MaxInt div SizeOf(JOCTET))-1;
+  JOCTET_FIELD = array[jTOctet] of JOCTET;
+  JOCTET_FIELD_PTR = ^JOCTET_FIELD;
+  JOCTETPTR = ^JOCTET;
+
+  JSAMPLE_PTR = ^JSAMPLE;
+  JSAMPROW_PTR = ^JSAMPROW;
+
+  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 }
+
+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 }
+
+{ 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 (Pentium)}
+                 );
+
+{ Dithering options for decompression. }
+
+type
+  J_DITHER_MODE = (
+    JDITHER_NONE,               { no dithering }
+    JDITHER_ORDERED,            { simple ordered dither }
+    JDITHER_FS                  { Floyd-Steinberg error diffusion dither }
+                  );
+
+{ Error handler }
+
+const
+  JMSG_LENGTH_MAX  = 200;  { recommended size of format_message buffer }
+  JMSG_STR_PARM_MAX = 80;
+
+  JPOOL_PERMANENT = 0;  // lasts until master record is destroyed
+  JPOOL_IMAGE	    = 1;	 // lasts until done with image/datastream
+
+type
+  jpeg_error_mgr_ptr = ^jpeg_error_mgr;
+  jpeg_progress_mgr_ptr = ^jpeg_progress_mgr;
+
+  j_common_ptr = ^jpeg_common_struct;
+  j_compress_ptr = ^jpeg_compress_struct;
+  j_decompress_ptr = ^jpeg_decompress_struct;
+
+{ 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) : LongBool; stdcall;
+
+{ Marker reading & parsing }
+  jpeg_marker_reader_ptr = ^jpeg_marker_reader;
+  jpeg_marker_reader = packed record
+    reset_marker_reader : procedure(cinfo : j_decompress_ptr); stdcall;
+    { 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) : Integer; stdcall;
+    { Read a restart marker --- exported for use by entropy decoder only }
+    read_restart_marker : jpeg_marker_parser_method;
+    { Application-overridable marker processing methods }
+//    process_COM : jpeg_marker_parser_method;
+//    process_APPn : Array[0..16-1] of 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 : LongBool;            { found SOI? }
+    saw_SOF : LongBool;            { found SOF? }
+    next_restart_num : Integer;    { next restart number expected (0-7) }
+    discarded_bytes : UINT;        { # of bytes skipped looking for a marker }
+  end;
+
+  {int8array = Array[0..8-1] of int;}
+  int8array = Array[0..8-1] of Integer;
+
+  jpeg_error_mgr = record
+    { Error exit handler: does not return to caller }
+    error_exit : procedure  (cinfo : j_common_ptr); stdcall;
+    { Conditionally emit a trace or warning message }
+    emit_message : procedure (cinfo : j_common_ptr; msg_level : Integer); stdcall;
+    { Routine that actually outputs a trace or error message }
+    output_message : procedure (cinfo : j_common_ptr); stdcall;
+    { Format a message string for the most recent JPEG error or message }
+    format_message : procedure  (cinfo : j_common_ptr; buffer: PChar); stdcall;
+    { Reset error state variables at start of a new image }
+    reset_error_mgr : procedure (cinfo : j_common_ptr); stdcall;
+
+    { 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 : Integer;
+
+    msg_parm : record
+      case byte of
+      0:(i : int8array);
+      1:(s : string[JMSG_STR_PARM_MAX]);
+    end;
+    trace_level : Integer;     { max msg_level that will be displayed }
+    num_warnings : Integer;    { number of corrupt-data warnings }
+    jpeg_message_table : Pointer; { Library errors }
+    last_jpeg_message : Integer;    { 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. }
+    addon_message_table : Pointer; { Non-library errors }
+    first_addon_message : Integer;	{ code for first string in addon table }
+    last_addon_message : Integer;	{ code for last string in addon table }
+  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 : Longint;    { # of byte spaces remaining in buffer }
+
+    init_destination : procedure (cinfo : j_compress_ptr); stdcall;
+    empty_output_buffer : function (cinfo : j_compress_ptr) : LongBool; stdcall;
+    term_destination : procedure (cinfo : j_compress_ptr); stdcall;
+  end;
+
+
+{ Data source object for decompression }
+
+  jpeg_source_mgr_ptr = ^jpeg_source_mgr;
+  jpeg_source_mgr = record
+    next_input_byte : JOCTETptr;      { => next byte to read from buffer }
+    bytes_in_buffer : Longint;       { # of bytes remaining in buffer }
+
+    init_source : procedure  (cinfo : j_decompress_ptr); stdcall;
+    fill_input_buffer : function (cinfo : j_decompress_ptr) : LongBool; stdcall;
+    skip_input_data : procedure (cinfo : j_decompress_ptr; num_bytes : Longint); stdcall;
+    resync_to_restart : function (cinfo : j_decompress_ptr;
+                                  desired : Integer) : LongBool; stdcall;
+    term_source : procedure (cinfo : j_decompress_ptr); stdcall;
+  end;
+
+{ JPEG library memory manger routines }
+  jpeg_memory_mgr_ptr = ^jpeg_memory_mgr;
+  jpeg_memory_mgr = record
+    { Method pointers }
+    alloc_small : function (cinfo : j_common_ptr;
+                            pool_id, sizeofobject: Integer): pointer; stdcall;
+    alloc_large : function (cinfo : j_common_ptr;
+                            pool_id, sizeofobject: Integer): pointer; stdcall;
+    alloc_sarray : function (cinfo : j_common_ptr; pool_id : Integer;
+                             samplesperrow : JDIMENSION;
+                             numrows : JDIMENSION) : JSAMPARRAY; stdcall;
+    alloc_barray : pointer;
+    request_virt_sarray : pointer;
+    request_virt_barray : pointer;
+    realize_virt_arrays : pointer;
+    access_virt_sarray : pointer;
+    access_virt_barray : pointer;
+    free_pool : pointer;
+    self_destruct : pointer;
+    max_memory_to_use : Longint;
+    max_alloc_chunk : Longint;
+  end;
+
+    { Fields shared with jpeg_decompress_struct }
+  jpeg_common_struct = packed record
+    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 : Pointer;            { Available for use by application }
+    is_decompressor : LongBool;      { so common code can tell which is which }
+    global_state : Integer;          { for checking call sequence validity }
+  end;
+
+{ Progress monitor object }
+
+  jpeg_progress_mgr = record
+    progress_monitor : procedure(const cinfo : jpeg_common_struct); stdcall;
+    pass_counter : Integer;     { work units completed in this pass }
+    pass_limit : Integer;       { total number of work units in this pass }
+    completed_passes : Integer;	{ passes completed so far }
+    total_passes : Integer;     { total number of passes expected }
+    // extra Delphi info
+    instance: TJPEGImage;       // ptr to current TJPEGImage object
+    last_pass: Integer;
+    last_pct: Integer;
+    last_time: Integer;
+    last_scanline: Integer;
+  end;
+
+
+{ Master record for a compression instance }
+
+  jpeg_compress_struct = packed record
+    common: jpeg_common_struct;
+
+    dest : jpeg_destination_mgr_ptr; { Destination for compressed data }
+
+  { 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 : Integer;       { # 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
+    data_precision : Integer;             { bits of precision in image data }
+    num_components : Integer;             { # of color components in JPEG image }
+    jpeg_color_space : J_COLOR_SPACE;     { colorspace of JPEG image }
+    comp_info : Pointer;
+    quant_tbl_ptrs: Array[0..NUM_QUANT_TBLS-1] of Pointer;
+    dc_huff_tbl_ptrs : Array[0..NUM_HUFF_TBLS-1] of Pointer;
+    ac_huff_tbl_ptrs : Array[0..NUM_HUFF_TBLS-1] of Pointer;
+    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 : Integer;		 { # of entries in scan_info array }
+    scan_info : Pointer;     { script for multi-scan file, or NIL }
+    raw_data_in : LongBool;        { TRUE=caller supplies downsampled data }
+    arith_code : LongBool;         { TRUE=arithmetic coding, FALSE=Huffman }
+    optimize_coding : LongBool;    { TRUE=optimize entropy encoding parms }
+    CCIR601_sampling : LongBool;   { TRUE=first samples are cosited }
+    smoothing_factor : Integer;       { 1..100, or 0 for no input smoothing }
+    dct_method : J_DCT_METHOD;    { DCT algorithm selector }
+    restart_interval : UINT;      { MCUs per restart, or 0 for no restart }
+    restart_in_rows : Integer;        { if > 0, MCU rows per restart interval }
+
+    { Parameters controlling emission of special markers. }
+    write_JFIF_header : LongBool;  { 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 }
+    dummy1 : byte;
+    X_density : UINT16;           { Horizontal pixel density }
+    Y_density : UINT16;           { Vertical pixel density }
+    write_Adobe_marker : LongBool; { 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. }
+    progressive_mode : LongBool;   { TRUE if scan script uses progressive mode }
+    max_h_samp_factor : Integer;      { largest h_samp_factor }
+    max_v_samp_factor : Integer;      { largest v_samp_factor }
+    total_iMCU_rows : JDIMENSION; { # of iMCU rows to be input to coef ctlr }
+    comps_in_scan : Integer;          { # of JPEG components in this scan }
+    cur_comp_info : Array[0..MAX_COMPS_IN_SCAN-1] of Pointer;
+    MCUs_per_row : JDIMENSION;    { # of MCUs across the image }
+    MCU_rows_in_scan : JDIMENSION;{ # of MCU rows in the image }
+    blocks_in_MCU : Integer;          { # of DCT blocks per MCU }
+    MCU_membership : Array[0..C_MAX_BLOCKS_IN_MCU-1] of Integer;
+    Ss, Se, Ah, Al : Integer;         { progressive JPEG parameters for scan }
+
+    { Links to compression subobjects (methods and private variables of modules) }
+    master : Pointer;
+    main : Pointer;
+    prep : Pointer;
+    coef : Pointer;
+    marker : Pointer;
+    cconvert : Pointer;
+    downsample : Pointer;
+    fdct : Pointer;
+    entropy : Pointer;
+    script_space : Pointer; { workspace for jpeg_simple_progression }
+    script_space_size : Integer;
+  end;
+
+
+{ Master record for a decompression instance }
+
+  jpeg_decompress_struct = packed record
+    common: jpeg_common_struct;
+
+    { 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 : Integer;          { # of color components in JPEG image }
+    jpeg_color_space : J_COLOR_SPACE; { colorspace of JPEG image }
+
+    { Decompression processing parameters }
+    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 : LongBool;        { TRUE=multiple output passes }
+    raw_data_out : LongBool;          { TRUE=downsampled data wanted }
+    dct_method : J_DCT_METHOD;       { IDCT algorithm selector }
+    do_fancy_upsampling : LongBool;   { TRUE=apply fancy upsampling }
+    do_block_smoothing : LongBool;    { TRUE=apply interblock smoothing }
+    quantize_colors : LongBool;       { 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 : LongBool;     { TRUE=use two-pass color quantization }
+    desired_number_of_colors : Integer;  { max # colors to use in created colormap }
+    { these are significant only in buffered-image mode: }
+    enable_1pass_quant : LongBool;    { enable future use of 1-pass quantizer }
+    enable_external_quant : LongBool; { enable future use of external colormap }
+    enable_2pass_quant : LongBool;    { 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 : Integer;  { # of color components in out_color_space }
+    output_components : Integer;     { # of color components returned }
+    { output_components is 1 (a colormap index) when quantizing colors;
+      otherwise it equals out_color_components. }
+
+    rec_outbuf_height : Integer;     { 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 : Integer;      { 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 : Integer;      { 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 : Integer;     { Nominal scan number being displayed }
+    output_iMCU_row : JDIMENSION;        { Number of iMCU rows read }
+
+    coef_bits : Pointer;
+
+    { 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 Pointer;
+    dc_huff_tbl_ptrs : Array[0..NUM_HUFF_TBLS-1] of Pointer;
+    ac_huff_tbl_ptrs : Array[0..NUM_HUFF_TBLS-1] of Pointer;
+
+    { These parameters are never carried across datastreams, since they
+      are given in SOF/SOS markers or defined to be reset by SOI. }
+    data_precision : Integer;          { bits of precision in image data }
+    comp_info : Pointer;
+    progressive_mode : LongBool;    { TRUE if SOFn specifies progressive mode }
+    arith_code : LongBool;          { 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 : LongBool;  { TRUE iff a JFIF APP0 marker was found }
+    { Data copied from JFIF marker: }
+    JFIF_major_version : UINT8;	{ JFIF version number }
+    JFIF_minor_version : UINT8;
+    density_unit : UINT8;       { JFIF code for pixel size units }
+    dummy1 : byte;
+    X_density : UINT16;         { Horizontal pixel density }
+    Y_density : UINT16;         { Vertical pixel density }
+    saw_Adobe_marker : LongBool; { TRUE iff an Adobe APP14 marker was found }
+    Adobe_transform : UINT8;    { Color transform code from Adobe marker }
+    dummy2 : array [0 .. 2] of byte;
+
+    CCIR601_sampling : LongBool; { 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 : Pointer; { Head of list of saved markers }
+
+    { Remaining fields are known throughout decompressor, but generally
+      should not be touched by a surrounding application. }
+    max_h_samp_factor : Integer;    { largest h_samp_factor }
+    max_v_samp_factor : Integer;    { largest v_samp_factor }
+    min_DCT_scaled_size : Integer;  { smallest DCT_scaled_size of any component }
+    total_iMCU_rows : JDIMENSION; { # of iMCU rows in image }
+    sample_range_limit : Pointer;   { 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 : Integer;           { # of JPEG components in this scan }
+    cur_comp_info : Array[0..MAX_COMPS_IN_SCAN-1] of Pointer;
+    MCUs_per_row : JDIMENSION;     { # of MCUs across the image }
+    MCU_rows_in_scan : JDIMENSION; { # of MCU rows in the image }
+    blocks_in_MCU : Integer;    { # of DCT blocks per MCU }
+    MCU_membership : Array[0..D_MAX_BLOCKS_IN_MCU-1] of Integer;
+    Ss, Se, Ah, Al : Integer;          { 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 : Integer;
+
+    { Links to decompression subobjects
+      (methods, private variables of modules) }
+    master : Pointer;
+    main : Pointer;
+    coef : Pointer;
+    post : Pointer;
+    inputctl : Pointer;
+    marker : Pointer;
+    entropy : Pointer;
+    idct : Pointer;
+    upsample : Pointer;
+    cconvert : Pointer;
+    cquantize : Pointer;
+  end;
+
+  { TJPEGContext }
+
+  TJPEGContext = record
+    err: jpeg_error_mgr;
+    progress: jpeg_progress_mgr;
+    FinalDCT: J_DCT_METHOD;
+    FinalTwoPassQuant: Boolean;
+    FinalDitherMode: J_DITHER_MODE;
+    case byte of
+      0: (common: jpeg_common_struct);
+      1: (d: jpeg_decompress_struct);
+      2: (c: jpeg_compress_struct);
+  end;
+
+{ Decompression startup: read start of JPEG datastream to see what's there // do not localize
+   function jpeg_read_header (cinfo : j_decompress_ptr;
+                              require_image : LongBool) : Integer;
+  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). } // do not localize
+
+
+{ function jpeg_consume_input (cinfo : j_decompress_ptr) : Integer;
+  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 }
+
+{***************************************************************************}
+type
+  Tjpeg_CreateDecompress = procedure (var cinfo : jpeg_decompress_struct;
+    version : integer; structsize : integer); stdcall;
+  Tjpeg_stdio_src = procedure (var cinfo: jpeg_decompress_struct;
+    input_file: TStream); stdcall;
+  Tjpeg_read_header = procedure (var cinfo: jpeg_decompress_struct;
+    RequireImage: LongBool); stdcall;
+  Tjpeg_calc_output_dimensions = procedure (var cinfo: jpeg_decompress_struct); stdcall;
+  Tjpeg_start_decompress = function (var cinfo: jpeg_decompress_struct): Longbool; stdcall;
+  Tjpeg_read_scanlines = function (var cinfo: jpeg_decompress_struct;
+          scanlines: JSAMPARRAY; max_lines: JDIMENSION): JDIMENSION; stdcall;
+  Tjpeg_finish_decompress = function (var cinfo: jpeg_decompress_struct): Longbool; stdcall;
+  Tjpeg_destroy_decompress = procedure (var cinfo : jpeg_decompress_struct); stdcall;
+  Tjpeg_has_multiple_scans = function (var cinfo: jpeg_decompress_struct): Longbool; stdcall;
+  Tjpeg_consume_input = function (var cinfo: jpeg_decompress_struct): Integer; stdcall;
+  Tjpeg_start_output = function (var cinfo: jpeg_decompress_struct; scan_number: Integer): Longbool; stdcall;
+  Tjpeg_finish_output = function (var cinfo: jpeg_decompress_struct): LongBool; stdcall;
+  Tjpeg_destroy = procedure (var cinfo: jpeg_common_struct); stdcall;
+
+  Tjpeg_CreateCompress = procedure (var cinfo : jpeg_compress_struct;
+    version : integer; structsize : integer); stdcall;
+  Tjpeg_stdio_dest = procedure (var cinfo: jpeg_compress_struct;
+    output_file: TStream); stdcall;
+  Tjpeg_set_defaults = procedure (var cinfo: jpeg_compress_struct); stdcall;
+  Tjpeg_set_quality = procedure (var cinfo: jpeg_compress_struct; Quality: Integer;
+    Baseline: Longbool); stdcall;
+  Tjpeg_set_colorspace = procedure (var cinfo: jpeg_compress_struct;
+    colorspace: J_COLOR_SPACE); stdcall;
+  Tjpeg_simple_progression = procedure (var cinfo: jpeg_compress_struct); stdcall;
+  Tjpeg_start_compress = procedure (var cinfo: jpeg_compress_struct;
+    WriteAllTables: LongBool); stdcall;
+  Tjpeg_write_scanlines = function (var cinfo: jpeg_compress_struct;
+    scanlines: JSAMPARRAY; max_lines: JDIMENSION): JDIMENSION; stdcall;
+  Tjpeg_finish_compress = procedure (var cinfo: jpeg_compress_struct); stdcall;
+
+  Tjpeg_resync_to_restart = function (cinfo : j_decompress_ptr; desired : Integer) : LongBool; stdcall;
+
+{***************************************************************************
+
+  TInitContext = procedure (var jc: TJPEGContext); stdcall;
+  TReleaseContext = procedure (var jc: TJPEGContext); stdcall;
+
+{***************************************************************************}
+
+procedure jpeg_CreateDecompress (var cinfo : jpeg_decompress_struct;
+  version : integer; structsize : integer); stdcall;
+procedure jpeg_stdio_src(var cinfo: jpeg_decompress_struct;
+  input_file: TStream); stdcall;
+procedure jpeg_read_header(var cinfo: jpeg_decompress_struct;
+  RequireImage: LongBool); stdcall;
+procedure jpeg_calc_output_dimensions(var cinfo: jpeg_decompress_struct); stdcall;
+function jpeg_start_decompress(var cinfo: jpeg_decompress_struct): Longbool; stdcall;
+function jpeg_read_scanlines(var cinfo: jpeg_decompress_struct;
+	scanlines: JSAMPARRAY; max_lines: JDIMENSION): JDIMENSION; stdcall;
+function jpeg_finish_decompress(var cinfo: jpeg_decompress_struct): Longbool; stdcall;
+procedure jpeg_destroy_decompress (var cinfo : jpeg_decompress_struct); stdcall;
+function jpeg_has_multiple_scans(var cinfo: jpeg_decompress_struct): Longbool; stdcall;
+function jpeg_consume_input(var cinfo: jpeg_decompress_struct): Integer; stdcall;
+function jpeg_start_output(var cinfo: jpeg_decompress_struct; scan_number: Integer): Longbool; stdcall;
+function jpeg_finish_output(var cinfo: jpeg_decompress_struct): LongBool; stdcall;
+procedure jpeg_destroy(var cinfo: jpeg_common_struct); stdcall;
+
+procedure jpeg_CreateCompress (var cinfo : jpeg_compress_struct;
+  version : integer; structsize : integer); stdcall;
+procedure jpeg_stdio_dest(var cinfo: jpeg_compress_struct;
+  output_file: TStream); stdcall;
+procedure jpeg_set_defaults(var cinfo: jpeg_compress_struct); stdcall;
+procedure jpeg_set_quality(var cinfo: jpeg_compress_struct; Quality: Integer;
+  Baseline: Longbool); stdcall;
+procedure jpeg_set_colorspace(var cinfo: jpeg_compress_struct;
+  colorspace: J_COLOR_SPACE); stdcall;
+procedure jpeg_simple_progression(var cinfo: jpeg_compress_struct); stdcall;
+procedure jpeg_start_compress(var cinfo: jpeg_compress_struct;
+  WriteAllTables: LongBool); stdcall;
+function jpeg_write_scanlines(var cinfo: jpeg_compress_struct;
+  scanlines: JSAMPARRAY; max_lines: JDIMENSION): JDIMENSION; stdcall;
+procedure jpeg_finish_compress(var cinfo: jpeg_compress_struct); stdcall;
+
+function jpeg_resync_to_restart (cinfo : j_decompress_ptr; desired : Integer) : LongBool; stdcall;
+
+{***************************************************************************}
+
+procedure InitContext(var jc: TJPEGContext); stdcall;
+procedure ReleaseContext(var jc: TJPEGContext); stdcall;
+
+{****************************************************************************}
+procedure InitDefaults;
+
+
+
+implementation
+
+
+
+uses { Own Units }
+     NGConst, NGTypes,
+
+     { Borland Standard Units }
+     SysUtils;
+
+
+{$IFDEF LATE_BINDING}
+var
+  hLibmng: THandle;
+  _jpeg_CreateDecompress: Tjpeg_CreateDecompress;
+  _jpeg_stdio_src: Tjpeg_stdio_src;
+  _jpeg_read_header: Tjpeg_read_header;
+  _jpeg_calc_output_dimensions: Tjpeg_calc_output_dimensions;
+  _jpeg_start_decompress: Tjpeg_start_decompress;
+  _jpeg_read_scanlines: Tjpeg_read_scanlines;
+  _jpeg_finish_decompress: Tjpeg_finish_decompress;
+  _jpeg_destroy_decompress: Tjpeg_destroy_decompress;
+  _jpeg_has_multiple_scans: Tjpeg_has_multiple_scans;
+  _jpeg_consume_input: Tjpeg_consume_input;
+  _jpeg_start_output: Tjpeg_start_output;
+  _jpeg_finish_output: Tjpeg_finish_output;
+  _jpeg_destroy: Tjpeg_destroy;
+  _jpeg_CreateCompress: Tjpeg_CreateCompress;
+  _jpeg_stdio_dest: Tjpeg_stdio_dest;
+  _jpeg_set_defaults: Tjpeg_set_defaults;
+  _jpeg_set_quality: Tjpeg_set_quality;
+  _jpeg_set_colorspace: Tjpeg_set_colorspace;
+  _jpeg_simple_progression: Tjpeg_simple_progression;
+  _jpeg_start_compress: Tjpeg_start_compress;
+  _jpeg_write_scanlines: Tjpeg_write_scanlines;
+  _jpeg_finish_compress: Tjpeg_finish_compress;
+  _jpeg_resync_to_restart: Tjpeg_resync_to_restart;
+{$ENDIF}
+
+
+{****************************************************************************}
+{* local funtions to interface with LIBMNGs JPEG code                       *}
+{****************************************************************************}
+
+{$IFNDEF LATE_BINDING}
+procedure jpeg_CreateDecompress (var cinfo : jpeg_decompress_struct;
+  version : integer; structsize : integer); stdcall; external mngdll;
+procedure jpeg_stdio_src(var cinfo: jpeg_decompress_struct;
+  input_file: TStream); stdcall; external mngdll;
+procedure jpeg_read_header(var cinfo: jpeg_decompress_struct;
+  RequireImage: LongBool); stdcall; external mngdll;
+procedure jpeg_calc_output_dimensions(var cinfo: jpeg_decompress_struct); stdcall; external mngdll;
+function jpeg_start_decompress(var cinfo: jpeg_decompress_struct): Longbool; stdcall; external mngdll;
+function jpeg_read_scanlines(var cinfo: jpeg_decompress_struct;
+	scanlines: JSAMPARRAY; max_lines: JDIMENSION): JDIMENSION; stdcall; external mngdll;
+function jpeg_finish_decompress(var cinfo: jpeg_decompress_struct): Longbool; stdcall; external mngdll;
+procedure jpeg_destroy_decompress (var cinfo : jpeg_decompress_struct); stdcall; external mngdll;
+function jpeg_has_multiple_scans(var cinfo: jpeg_decompress_struct): Longbool; stdcall; external mngdll;
+function jpeg_consume_input(var cinfo: jpeg_decompress_struct): Integer; stdcall; external mngdll;
+function jpeg_start_output(var cinfo: jpeg_decompress_struct; scan_number: Integer): Longbool; stdcall; external mngdll;
+function jpeg_finish_output(var cinfo: jpeg_decompress_struct): LongBool; stdcall; external mngdll;
+procedure jpeg_destroy(var cinfo: jpeg_common_struct); stdcall; external mngdll;
+
+procedure jpeg_CreateCompress (var cinfo : jpeg_compress_struct;
+  version : integer; structsize : integer); stdcall; external mngdll;
+procedure jpeg_stdio_dest(var cinfo: jpeg_compress_struct;
+  output_file: TStream); stdcall; external mngdll;
+procedure jpeg_set_defaults(var cinfo: jpeg_compress_struct); stdcall; external mngdll;
+procedure jpeg_set_quality(var cinfo: jpeg_compress_struct; Quality: Integer;
+  Baseline: Longbool); stdcall; external mngdll;
+procedure jpeg_set_colorspace(var cinfo: jpeg_compress_struct;
+  colorspace: J_COLOR_SPACE); stdcall; external mngdll;
+procedure jpeg_simple_progression(var cinfo: jpeg_compress_struct); stdcall; external mngdll;
+procedure jpeg_start_compress(var cinfo: jpeg_compress_struct;
+  WriteAllTables: LongBool); stdcall; external mngdll;
+function jpeg_write_scanlines(var cinfo: jpeg_compress_struct;
+  scanlines: JSAMPARRAY; max_lines: JDIMENSION): JDIMENSION; stdcall; external mngdll;
+procedure jpeg_finish_compress(var cinfo: jpeg_compress_struct); stdcall; external mngdll;
+
+function jpeg_resync_to_restart (cinfo : j_decompress_ptr; desired : Integer) : LongBool; stdcall; external mngdll;
+{$ELSE}
+
+function CheckLIBMNGLoaded: Boolean;
+begin
+  if (hLibmng = 0) then begin
+     hLibmng:= LoadLibrary(mngdll);
+     if (hLibmng < HINSTANCE_ERROR) then begin
+       hLibmng:= 0;
+       Result:= False;
+       Exit;
+     end;
+
+     (* TODO:  REMOVE
+     @_EnumProcesses := GetProcAddress(hPSAPI, 'EnumProcesses'); // do not localize
+     @_EnumProcessModules := GetProcAddress(hPSAPI, 'EnumProcessModules'); // do not localize
+     {procedure}@_GetModuleBaseNameA := GetProcAddress(hPSAPI, 'GetModuleBaseNameA');*) // do not localize
+
+     {****************************************************************************}
+     {Functions without a preceeding marker.  Procedures prefixed with the following: }
+     {procedure}
+     {****************************************************************************}
+     {procedure}@_jpeg_CreateDecompress:= GetProcAddress(hLibmng, 'jpeg_CreateDecompress'); // do not localize
+     {procedure}@_jpeg_stdio_src:= GetProcAddress(hLibmng, 'jpeg_stdio_src'); // do not localize
+     {procedure}@_jpeg_read_header:= GetProcAddress(hLibmng, 'jpeg_read_header'); // do not localize
+     {procedure}@_jpeg_calc_output_dimensions:= GetProcAddress(hLibmng, 'jpeg_calc_output_dimensions'); // do not localize
+     @_jpeg_start_decompress:= GetProcAddress(hLibmng, 'jpeg_start_decompress'); // do not localize
+     @_jpeg_read_scanlines:= GetProcAddress(hLibmng, 'jpeg_read_scanlines'); // do not localize
+     @_jpeg_finish_decompress:= GetProcAddress(hLibmng, 'jpeg_finish_decompress'); // do not localize
+     {procedure}@_jpeg_destroy_decompress:= GetProcAddress(hLibmng, 'jpeg_destroy_decompress'); // do not localize
+     @_jpeg_has_multiple_scans:= GetProcAddress(hLibmng, 'jpeg_has_multiple_scans'); // do not localize
+     @_jpeg_consume_input:= GetProcAddress(hLibmng, 'jpeg_consume_input'); // do not localize
+     @_jpeg_start_output:= GetProcAddress(hLibmng, 'jpeg_start_output'); // do not localize
+     @_jpeg_finish_output:= GetProcAddress(hLibmng, 'jpeg_finish_output'); // do not localize
+     {procedure}@_jpeg_destroy:= GetProcAddress(hLibmng, 'jpeg_destroy'); // do not localize
+     {procedure}@_jpeg_CreateCompress:= GetProcAddress(hLibmng, 'jpeg_CreateCompress'); // do not localize
+     {procedure}@_jpeg_stdio_dest:= GetProcAddress(hLibmng, 'jpeg_stdio_dest'); // do not localize
+     {procedure}@_jpeg_set_defaults:= GetProcAddress(hLibmng, 'jpeg_set_defaults'); // do not localize
+     {procedure}@_jpeg_set_quality:= GetProcAddress(hLibmng, 'jpeg_set_quality'); // do not localize
+     {procedure}@_jpeg_set_colorspace:= GetProcAddress(hLibmng, 'jpeg_set_colorspace'); // do not localize
+     {procedure}@_jpeg_simple_progression:= GetProcAddress(hLibmng, 'jpeg_simple_progression'); // do not localize
+     {procedure}@_jpeg_start_compress:= GetProcAddress(hLibmng, 'jpeg_start_compress'); // do not localize
+     {procedure}@_jpeg_write_scanlines:= GetProcAddress(hLibmng, 'jpeg_write_scanlines'); // do not localize
+     {procedure}@_jpeg_finish_compress:= GetProcAddress(hLibmng, 'jpeg_finish_compress'); // do not localize
+     @_jpeg_resync_to_restart:= GetProcAddress(hLibmng, 'jpeg_resync_to_restart'); // do not localize
+  end;
+  Result:= True;
+end;
+
+procedure jpeg_CreateDecompress (var cinfo : jpeg_decompress_struct;
+  version : integer; structsize : integer); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_CreateDecompress(cinfo, version, structsize);
+end;
+
+procedure jpeg_stdio_src(var cinfo: jpeg_decompress_struct;
+  input_file: TStream); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_stdio_src(cinfo, input_file);
+end;
+
+procedure jpeg_read_header(var cinfo: jpeg_decompress_struct;
+  RequireImage: LongBool); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_read_header(cinfo, RequireImage);
+end;
+
+procedure jpeg_calc_output_dimensions(var cinfo: jpeg_decompress_struct); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_calc_output_dimensions(cinfo);
+end;
+
+function jpeg_start_decompress(var cinfo: jpeg_decompress_struct): Longbool; stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     Result:= _jpeg_start_decompress(cinfo)
+  else Result:= MNG_FALSE;
+end;
+
+function jpeg_read_scanlines(var cinfo: jpeg_decompress_struct;
+  scanlines: JSAMPARRAY; max_lines: JDIMENSION): JDIMENSION; stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     Result:= _jpeg_read_scanlines(cinfo, scanlines, max_lines)
+  else Result:= 0;
+end;
+
+function jpeg_finish_decompress(var cinfo: jpeg_decompress_struct): Longbool; stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     Result:= _jpeg_finish_decompress(cinfo)
+  else Result:= MNG_FALSE;
+end;
+
+procedure jpeg_destroy_decompress (var cinfo : jpeg_decompress_struct); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_destroy_decompress(cinfo);
+end;
+
+function jpeg_has_multiple_scans(var cinfo: jpeg_decompress_struct): Longbool; stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     Result:= _jpeg_has_multiple_scans(cinfo)
+  else Result:= MNG_FALSE;
+end;
+
+function jpeg_consume_input(var cinfo: jpeg_decompress_struct): Integer; stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     Result:= _jpeg_consume_input(cinfo)
+  else Result:= -1;
+end;
+
+function jpeg_start_output(var cinfo: jpeg_decompress_struct; scan_number: Integer): Longbool; stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     Result:= _jpeg_start_output(cinfo, scan_number)
+  else Result:= MNG_FALSE;
+end;
+
+function jpeg_finish_output(var cinfo: jpeg_decompress_struct): LongBool; stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     Result:= _jpeg_finish_decompress(cinfo)
+  else Result:= MNG_FALSE;
+end;
+
+procedure jpeg_destroy(var cinfo: jpeg_common_struct); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_destroy(cinfo);
+end;
+
+procedure jpeg_CreateCompress (var cinfo : jpeg_compress_struct;
+  version : integer; structsize : integer); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_CreateCompress(cinfo, version, structsize);
+end;
+
+procedure jpeg_stdio_dest(var cinfo: jpeg_compress_struct;
+  output_file: TStream); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_stdio_dest(cinfo, output_file);
+end;
+
+procedure jpeg_set_defaults(var cinfo: jpeg_compress_struct); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_set_defaults(cinfo);
+end;
+
+procedure jpeg_set_quality(var cinfo: jpeg_compress_struct; Quality: Integer;
+  Baseline: Longbool); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_set_quality(cinfo, Quality, Baseline);
+end;
+
+procedure jpeg_set_colorspace(var cinfo: jpeg_compress_struct;
+  colorspace: J_COLOR_SPACE); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_set_colorspace(cinfo, colorspace);
+end;
+
+procedure jpeg_simple_progression(var cinfo: jpeg_compress_struct); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_simple_progression(cinfo);
+end;
+
+procedure jpeg_start_compress(var cinfo: jpeg_compress_struct;
+  WriteAllTables: LongBool); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_start_compress(cinfo, WriteAllTables);
+end;
+
+function jpeg_write_scanlines(var cinfo: jpeg_compress_struct;
+  scanlines: JSAMPARRAY; max_lines: JDIMENSION): JDIMENSION; stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     Result:= _jpeg_write_scanlines(cinfo, scanlines, max_lines)
+  else Result:= 0;
+end;
+
+procedure jpeg_finish_compress(var cinfo: jpeg_compress_struct); stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     _jpeg_finish_compress(cinfo);
+end;
+
+function jpeg_resync_to_restart (cinfo : j_decompress_ptr; desired : Integer) : LongBool; stdcall;
+begin
+  if CheckLIBMNGLoaded then
+     Result:= _jpeg_resync_to_restart(cinfo, desired)
+  else Result:= MNG_FALSE;
+end;
+
+{$ENDIF}
+
+{****************************************************************************}
+
+procedure SwapRedBlueScanline (Line : pointer; Width : Integer);
+type
+  pbytes3 = ^tbytes3;
+  tbytes3 = array [0..2] of byte;
+var
+  ix : integer;
+  bLine : pbytes3;
+  bTemp : byte;
+begin
+  bLine := pbytes3(Line);
+  for ix := 0 to pred(Width) do
+  begin
+    bTemp := bLine[0];
+    bLine[0] := bLine[2];
+    bLine[2] := bTemp;
+    inc (bLine);
+  end;
+end;
+
+{****************************************************************************}
+
+procedure SwapRedBlue(Bitmap: TBitmap);
+var
+  ix, iHeight: Integer;
+begin
+  iHeight:= Bitmap.Height;
+  for ix := 0 to pred(iHeight) do
+    SwapRedBlueScanline(Bitmap.Scanline[ix], Bitmap.Width);
+end;
+
+{****************************************************************************}
+
+type
+  EJPEG = class(EInvalidGraphic);
+
+{****************************************************************************}
+
+procedure InvalidOperation(const Msg: string); near;
+begin
+  raise EInvalidGraphicOperation.Create(Msg);
+end;
+
+{****************************************************************************}
+
+procedure JpegError(cinfo: j_common_ptr); stdcall;
+begin
+  raise EJPEG.CreateFmt(sJPEGError,[cinfo^.err^.msg_code]);
+end;
+
+{****************************************************************************}
+
+procedure EmitMessage(cinfo: j_common_ptr; msg_level: Integer); stdcall;
+begin
+  //!!
+end;
+
+{****************************************************************************}
+
+procedure OutputMessage(cinfo: j_common_ptr); stdcall;
+begin
+  //!!
+end;
+
+{****************************************************************************}
+
+procedure FormatMessage(cinfo: j_common_ptr; buffer: PChar); stdcall;
+begin
+  //!!
+end;
+
+{****************************************************************************}
+
+procedure ResetErrorMgr(cinfo: j_common_ptr); stdcall;
+begin
+  cinfo^.err^.num_warnings := 0;
+  cinfo^.err^.msg_code := 0;
+end;
+
+{****************************************************************************}
+
+procedure SrcInit(cinfo: j_decompress_ptr); stdcall;
+var
+  Data : TJPEGData;
+begin
+  Data := TJPEGData(cinfo^.common.client_data);
+
+  cinfo^.src^.next_input_byte := Data.FData.Memory;
+  cinfo^.src^.bytes_in_buffer := Data.FData.Size;
+end;
+
+{****************************************************************************}
+
+function SrcFill(cinfo: j_decompress_ptr) : Longbool; stdcall;
+begin
+  Result := TRUE;
+end;
+
+{****************************************************************************}
+
+procedure SrcSkip(cinfo: j_decompress_ptr; num_bytes: Longint); stdcall;
+begin
+  if num_bytes > 0 then
+  begin
+    if cinfo^.src^.bytes_in_buffer > num_bytes then
+    begin
+      dec(cinfo^.src^.bytes_in_buffer, num_bytes);
+      inc(cinfo^.src^.next_input_byte, num_bytes);
+    end;
+  end;
+end;
+
+{****************************************************************************}
+
+procedure SrcTerm(cinfo: j_decompress_ptr); stdcall;
+begin
+  { dummy routine to satisfy IJG-code }
+end;
+
+{****************************************************************************}
+
+procedure DstInit(cinfo: j_compress_ptr); stdcall;
+var
+  Data : TJPEGData;
+begin
+  Data := TJPEGData(cinfo^.common.client_data);
+  Data.FSize := 4000;
+
+  GetMem(Data.FBuffer, Data.FSize);
+
+  cinfo^.dest^.next_output_byte := Data.FBuffer;
+  cinfo^.dest^.free_in_buffer := Data.FSize;
+end;
+
+{****************************************************************************}
+
+function DstEmpty(cinfo: j_compress_ptr) : Longbool; stdcall;
+var
+  Data : TJPEGData;
+begin
+  Data := TJPEGData(cinfo^.common.client_data);
+
+  Data.FData.Write(Data.FBuffer^, Data.FSize);
+
+  cinfo^.dest^.next_output_byte := Data.FBuffer;
+  cinfo^.dest^.free_in_buffer := Data.FSize;
+
+  Result := TRUE;
+end;
+
+{****************************************************************************}
+
+procedure DstTerm(cinfo: j_compress_ptr); stdcall;
+var
+  Data : TJPEGData;
+begin
+  Data := TJPEGData(cinfo^.common.client_data);
+
+  if cinfo^.dest^.free_in_buffer < Data.FSize then
+    Data.FData.Write(Data.FBuffer^, Data.FSize-cinfo^.dest^.free_in_buffer);
+
+  cinfo^.dest^.next_output_byte := nil;
+  cinfo^.dest^.free_in_buffer := 0;
+
+  if Data.FSize > 0 then
+    FreeMem(Data.FBuffer, Data.FSize);
+
+  Data.FBuffer := nil;
+  Data.FSize := 0;
+end;
+
+{****************************************************************************}
+{ TJPEGData                                                                  }
+{****************************************************************************}
+
+constructor TJPEGData.Create;
+begin
+  inherited Create;
+  FBuffer := nil;
+  FSize := 0;
+  BeginUseLibmng;
+end;
+
+{****************************************************************************}
+
+destructor TJPEGData.Destroy;
+begin
+  FData.Free;
+  EndUseLibmng;
+  inherited Destroy;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGData.FreeHandle;
+begin
+end;
+
+{****************************************************************************}
+{ TJPEGImage                                                                 }
+{****************************************************************************}
+
+constructor TJPEGImage.Create;
+begin
+  inherited Create;
+
+  NewImage;
+  FQuality := JPEGDefaults.CompressionQuality;
+  FGrayscale := JPEGDefaults.Grayscale;
+  FPerformance := JPEGDefaults.Performance;
+  FPixelFormat := JPEGDefaults.PixelFormat;
+  FProgressiveDisplay := JPEGDefaults.ProgressiveDisplay;
+  FProgressiveEncoding := JPEGDefaults.ProgressiveEncoding;
+  FScale := JPEGDefaults.Scale;
+  FSmoothing := JPEGDefaults.Smoothing;
+end;
+
+{****************************************************************************}
+
+destructor TJPEGImage.Destroy;
+begin
+  if (FTempPal <> 0) then
+     DeleteObject(FTempPal);
+     
+  FBitmap.Free;
+  FImage.Release;
+
+  inherited Destroy;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.Assign(Source: TPersistent);
+begin
+  if (Source is TJPEGImage) then
+  begin
+    FImage.Release;
+    FImage := TJPEGImage(Source).FImage;
+    FImage.Reference;
+    if (TJPEGImage(Source).FBitmap <> nil) then
+    begin
+      NewBitmap;
+      FBitmap.Assign(TJPEGImage(Source).FBitmap);
+    end;
+  end
+  else if (Source is TBitmap) then
+  begin
+    NewImage;
+    NewBitmap;
+    FBitmap.Assign(Source);
+  end
+  else
+    inherited Assign(Source);
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.AssignTo(Dest: TPersistent);
+begin
+  if (Dest is TBitmap) then
+    Dest.Assign(Bitmap)
+  else
+    inherited AssignTo(Dest);
+end;
+
+{****************************************************************************}
+
+const
+  jpeg_std_error: jpeg_error_mgr = (
+    error_exit: JpegError;
+    emit_message: EmitMessage;
+    output_message: OutputMessage;
+    format_message: FormatMessage;
+    reset_error_mgr: ResetErrorMgr);
+
+  jpeg_std_src: jpeg_source_mgr = (
+    next_input_byte: nil;
+    bytes_in_buffer: 0;
+    init_source: SrcInit;
+    fill_input_buffer: SrcFill;
+    skip_input_data: SrcSkip;
+    resync_to_restart: nil;
+    term_source: SrcTerm);
+
+  jpeg_std_dest: jpeg_destination_mgr = (
+    next_output_byte: nil;
+    free_in_buffer: 0;
+    init_destination: DstInit;
+    empty_output_buffer: DstEmpty;
+    term_destination: DstTerm);
+
+{****************************************************************************}
+
+procedure ProgressCallback(const cinfo: jpeg_common_struct); stdcall;
+var
+  Ticks: Integer;
+  R: TRect;
+  temp: Integer;
+begin
+  if (cinfo.progress = nil) or (cinfo.progress^.instance = nil) then Exit;
+  with cinfo.progress^ do
+  begin
+    Ticks := GetTickCount;
+    if ((Ticks - last_time) < 500) then Exit;
+    temp := last_time;
+    last_time := Ticks;
+    if temp = 0 then Exit;
+    if cinfo.is_decompressor then
+      with j_decompress_ptr(@cinfo)^ do
+      begin
+        R := Rect(0, last_scanline, output_width, output_scanline);
+        if R.Bottom < last_scanline then
+          R.Bottom := output_height;
+      end
+    else
+      R := Rect(0,0,0,0);
+    temp := Trunc(100.0*(completed_passes + (pass_counter/pass_limit))/total_passes);
+    if temp = last_pct then Exit;
+    last_pct := temp;
+    if cinfo.is_decompressor then
+      last_scanline := j_decompress_ptr(@cinfo)^.output_scanline;
+    instance.Progress(instance, psRunning, temp, (R.Bottom - R.Top) >= 4, R, ''); // do not localize
+  end;
+end;
+
+{****************************************************************************}
+
+procedure InitContext(var jc: TJPEGContext); stdcall;
+begin
+  FillChar (jc, sizeof (jc), 0);
+  jc.err        := jpeg_std_error;
+  jc.common.err := @jc.err;
+end;
+
+{****************************************************************************}
+
+procedure ReleaseContext(var jc: TJPEGContext); stdcall;
+begin
+  if jc.common.err = nil then
+    exit;
+
+  jpeg_destroy (jc.common);
+  jc.common.err := nil;
+end;
+
+{****************************************************************************}
+
+procedure InitDecompressor(Obj: TJPEGImage; var jc: TJPEGContext); stdcall;
+begin
+  FillChar(jc, sizeof(jc), 0);
+  jc.err := jpeg_std_error;
+  jc.common.err := @jc.err;
+
+  jpeg_CreateDecompress(jc.d, JPEG_LIB_VERSION, sizeof(jpeg_decompress_struct));
+  with Obj do
+  try
+    jc.progress.progress_monitor := @ProgressCallback;
+    jc.progress.instance := Obj;
+    jc.common.progress := @jc.progress;
+
+    Obj.FImage.FData.Position := 0;
+//    jpeg_stdio_src(jc.d, FImage.FData);
+    jc.d.common.client_data := FImage;
+    jc.d.src := @jpeg_std_src;
+    jc.d.src.resync_to_restart := jpeg_resync_to_restart;
+    jpeg_read_header(jc.d, TRUE);
+
+    jc.d.scale_num := 1;
+    jc.d.scale_denom := 1 shl Byte(FScale);
+    jc.d.do_block_smoothing := FSmoothing;
+
+    if FGrayscale then jc.d.out_color_space := JCS_GRAYSCALE;
+    if (PixelFormat = jf8Bit) or (jc.d.out_color_space = JCS_GRAYSCALE) then
+    begin
+      jc.d.quantize_colors := True;
+      jc.d.desired_number_of_colors := 236;
+    end;
+
+    if FPerformance = jpBestSpeed then
+    begin
+      jc.d.dct_method := JDCT_IFAST;
+      jc.d.two_pass_quantize := False;
+//      jc.d.do_fancy_upsampling := False;    !! AV inside jpeglib
+      jc.d.dither_mode := JDITHER_ORDERED;
+    end;
+
+    jc.FinalDCT := jc.d.dct_method;
+    jc.FinalTwoPassQuant := jc.d.two_pass_quantize;
+    jc.FinalDitherMode := jc.d.dither_mode;
+    if FProgressiveDisplay and jpeg_has_multiple_scans(jc.d) then
+    begin  // save requested settings, reset for fastest on all but last scan
+      jc.d.enable_2pass_quant := jc.d.two_pass_quantize;
+      jc.d.dct_method := JDCT_IFAST;
+      jc.d.two_pass_quantize := False;
+      jc.d.dither_mode := JDITHER_ORDERED;
+      jc.d.buffered_image := True;
+    end;
+  except
+    ReleaseContext(jc);
+    raise;
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.CalcOutputDimensions;
+var
+  jc: TJPEGContext;
+begin
+  if not FNeedRecalc then Exit;
+  InitDecompressor(Self, jc);
+  try
+    jc.common.progress := nil;
+    jpeg_calc_output_dimensions(jc.d);
+    // read output dimensions
+    FScaledWidth := jc.d.output_width;
+    FScaledHeight := jc.d.output_height;
+    FProgressiveEncoding := jpeg_has_multiple_scans(jc.d);
+  finally
+    ReleaseContext(jc);
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.Changed(Sender: TObject);
+begin
+  inherited Changed(Sender);
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.Compress;
+var
+  LinesWritten, LinesPerCall: Integer;
+  SrcScanLine: Pointer;
+  PtrInc: Integer;
+  jc: TJPEGContext;
+  Src: TBitmap;
+begin
+  FillChar(jc, sizeof(jc), 0);
+  jc.err := jpeg_std_error;
+  jc.common.err := @jc.err;
+
+  jpeg_CreateCompress(jc.c, JPEG_LIB_VERSION, sizeof(jpeg_compress_struct));
+  try
+    try
+      jc.progress.progress_monitor := @ProgressCallback;
+      jc.progress.instance := Self;
+      jc.common.progress := @jc.progress;
+
+      if FImage.FData <> nil then NewImage;
+      FImage.FData := TMemoryStream.Create;
+      FImage.FData.Position := 0;
+//      jpeg_stdio_dest(jc.c, FImage.FData);
+      jc.c.common.client_data := FImage;
+      jc.c.dest := @jpeg_std_dest;
+
+      if (FBitmap = nil) or (FBitmap.Width = 0) or (FBitmap.Height = 0) then Exit;
+      jc.c.image_width := FBitmap.Width;
+      FImage.FWidth := FBitmap.Width;
+      jc.c.image_height := FBitmap.Height;
+      FImage.FHeight := FBitmap.Height;
+      jc.c.input_components := 3;           // JPEG requires 24bit RGB input
+      jc.c.in_color_space := JCS_RGB;
+
+      Src := TBitmap.Create;
+      try
+        Src.Assign(FBitmap);
+        Src.PixelFormat := pf24bit;
+        SwapRedBlue(Src);
+
+        jpeg_set_defaults(jc.c);
+        jpeg_set_quality(jc.c, FQuality, True);
+
+        if FGrayscale then
+        begin
+          FImage.FGrayscale := True;
+          jpeg_set_colorspace(jc.c, JCS_GRAYSCALE);
+        end;
+
+        if ProgressiveEncoding then
+          jpeg_simple_progression(jc.c);
+
+        SrcScanline := Src.ScanLine[0];
+        PtrInc := Integer(Src.ScanLine[1]) - Integer(SrcScanline);
+
+          // if no dword padding required and source bitmap is top-down
+        if (PtrInc > 0) and ((PtrInc and 3) = 0) then
+          LinesPerCall := jc.c.image_height  // do whole bitmap in one call
+        else
+          LinesPerCall := 1;      // otherwise spoonfeed one row at a time
+
+        Progress(Self, psStarting, 0, False, Rect(0,0,0,0), ''); // do not localize
+        try
+          jpeg_start_compress(jc.c, True);
+
+          while (jc.c.next_scanline < jc.c.image_height) do
+          begin
+            LinesWritten := jpeg_write_scanlines(jc.c, @SrcScanline, LinesPerCall);
+            Inc(Integer(SrcScanline), PtrInc * LinesWritten);
+          end;
+
+          jpeg_finish_compress(jc.c);
+        finally
+          if ExceptObject = nil then
+            PtrInc := 100
+          else
+            PtrInc := 0;
+          Progress(Self, psEnding, PtrInc, False, Rect(0,0,0,0), ''); // do not localize
+        end;
+      finally
+        Src.Free;
+      end;
+    except
+      on EAbort do    // OnProgress can raise EAbort to cancel image save
+        NewImage;     // Throw away any partial jpg data
+    end;
+  finally
+    ReleaseContext(jc);
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.DIBNeeded;
+begin
+  GetBitmap;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.Draw(ACanvas: TCanvas; const Rect: TRect);
+begin
+  ACanvas.StretchDraw(Rect, Bitmap);
+end;
+
+{****************************************************************************}
+
+function TJPEGImage.Equals(Graphic: TGraphic): Boolean;
+begin
+  Result := ((Graphic is TJPEGImage) and
+    (FImage = TJPEGImage(Graphic).FImage)); //!!
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.FreeBitmap;
+begin
+  FBitmap.Free;
+  FBitmap := nil;
+end;
+
+{****************************************************************************}
+
+function BuildPalette(const cinfo: jpeg_decompress_struct): HPalette; stdcall;
+var
+  Pal: TMaxLogPalette;
+  I: Integer;
+  C: Byte;
+begin
+  Pal.palVersion := $300;
+  Pal.palNumEntries := cinfo.actual_number_of_colors;
+  if cinfo.out_color_space = JCS_GRAYSCALE then
+    for I := 0 to Pal.palNumEntries-1 do
+    begin
+      C := cinfo.colormap^[0]^[I];
+      Pal.palPalEntry[I].peRed := C;
+      Pal.palPalEntry[I].peGreen := C;
+      Pal.palPalEntry[I].peBlue := C;
+      Pal.palPalEntry[I].peFlags := 0;
+    end
+  else
+    for I := 0 to Pal.palNumEntries-1 do
+    begin
+      Pal.palPalEntry[I].peRed := cinfo.colormap^[2]^[I];
+      Pal.palPalEntry[I].peGreen := cinfo.colormap^[1]^[I];
+      Pal.palPalEntry[I].peBlue := cinfo.colormap^[0]^[I];
+      Pal.palPalEntry[I].peFlags := 0;
+    end;
+  Result := CreatePalette(PLogPalette(@Pal)^);
+end;
+
+{****************************************************************************}
+
+procedure BuildColorMap(var cinfo: jpeg_decompress_struct; P: HPalette); stdcall;
+var
+  Pal: TMaxLogPalette;
+  Count, I: Integer;
+begin
+  Count := GetPaletteEntries(P, 0, 256, Pal.palPalEntry);
+  if Count = 0 then Exit;       // jpeg_destroy will free colormap
+  cinfo.colormap := cinfo.common.mem.alloc_sarray(@cinfo.common, JPOOL_IMAGE, Count, 3);
+  cinfo.actual_number_of_colors := Count;
+  for I := 0 to Count-1 do
+  begin
+    Byte(cinfo.colormap^[2]^[I]) := Pal.palPalEntry[I].peRed;
+    Byte(cinfo.colormap^[1]^[I]) := Pal.palPalEntry[I].peGreen;
+    Byte(cinfo.colormap^[0]^[I]) := Pal.palPalEntry[I].peBlue;
+  end;
+end;
+
+{****************************************************************************}
+
+function TJPEGImage.GetBitmap: TBitmap;
+var
+  LinesPerCall, LinesRead: Integer;
+  DestScanLine: Pointer;
+  PtrInc: Integer;
+  jc: TJPEGContext;
+  GeneratePalette: Boolean;
+begin
+  Result := FBitmap;
+  if Result <> nil then Exit;
+  if (FBitmap = nil) then FBitmap := TBitmap.Create;
+  Result := FBitmap;
+  GeneratePalette := True;
+
+  InitDecompressor(Self, jc);
+  try
+    try
+      // Set the bitmap pixel format
+      FBitmap.Handle := 0;
+      if (PixelFormat = jf8Bit) or (jc.d.out_color_space = JCS_GRAYSCALE) then
+        FBitmap.PixelFormat := pf8bit
+      else
+        FBitmap.PixelFormat := pf24bit;
+
+      Progress(Self, psStarting, 0, False, Rect(0,0,0,0), ''); // do not localize
+      try
+        if (FTempPal <> 0) then
+        begin
+          if (FPixelFormat = jf8Bit) then
+          begin                        // Generate DIB using assigned palette
+            BuildColorMap(jc.d, FTempPal);
+            FBitmap.Palette := CopyPalette(FTempPal);  // Keep FTempPal around
+            GeneratePalette := False;
+          end
+          else
+          begin
+            DeleteObject(FTempPal);
+            FTempPal := 0;
+          end;
+        end;
+
+        jpeg_start_decompress(jc.d);
+
+        // Set bitmap width and height
+        with FBitmap do
+        begin
+          Handle := 0;
+          Width := jc.d.output_width;
+          Height := jc.d.output_height;
+          DestScanline := ScanLine[0];
+          PtrInc := Integer(ScanLine[1]) - Integer(DestScanline);
+          if (PtrInc > 0) and ((PtrInc and 3) = 0) then
+             // if no dword padding is required and output bitmap is top-down
+            LinesPerCall := jc.d.rec_outbuf_height // read multiple rows per call
+          else
+            LinesPerCall := 1;            // otherwise read one row at a time
+        end;
+
+        if jc.d.buffered_image then
+        begin  // decode progressive scans at low quality, high speed
+          while jpeg_consume_input(jc.d) <> JPEG_REACHED_EOI do
+          begin
+            jpeg_start_output(jc.d, jc.d.input_scan_number);
+            // extract color palette
+            if (jc.common.progress^.completed_passes = 0) and (jc.d.colormap <> nil)
+              and (FBitmap.PixelFormat = pf8bit) and GeneratePalette then
+            begin
+              FBitmap.Palette := BuildPalette(jc.d);
+              PaletteModified := True;
+            end;
+            DestScanLine := FBitmap.ScanLine[0];
+            while (jc.d.output_scanline < jc.d.output_height) do
+            begin
+              LinesRead := jpeg_read_scanlines(jc.d, @DestScanline, LinesPerCall);
+              Inc(Integer(DestScanline), PtrInc * LinesRead);
+            end;
+            jpeg_finish_output(jc.d);
+          end;
+          // reset options for final pass at requested quality
+          jc.d.dct_method := jc.FinalDCT;
+          jc.d.dither_mode := jc.FinalDitherMode;
+          if jc.FinalTwoPassQuant then
+          begin
+            jc.d.two_pass_quantize := True;
+            jc.d.colormap := nil;
+          end;
+          jpeg_start_output(jc.d, jc.d.input_scan_number);
+          DestScanLine := FBitmap.ScanLine[0];
+        end;
+
+        // build final color palette
+        if (not jc.d.buffered_image or jc.FinalTwoPassQuant) and
+          (jc.d.colormap <> nil) and GeneratePalette then
+        begin
+          FBitmap.Palette := BuildPalette(jc.d);
+          PaletteModified := True;
+          DestScanLine := FBitmap.ScanLine[0];
+        end;
+        // final image pass for progressive, first and only pass for baseline
+        while (jc.d.output_scanline < jc.d.output_height) do
+        begin
+          LinesRead := jpeg_read_scanlines(jc.d, @DestScanline, LinesPerCall);
+          Inc(Integer(DestScanline), PtrInc * LinesRead);
+        end;
+
+        if jc.d.buffered_image then jpeg_finish_output(jc.d);
+        jpeg_finish_decompress(jc.d);
+
+         if FBitmap.PixelFormat = pf24bit then
+           SwapRedBlue(FBitmap);
+
+      finally
+        if ExceptObject = nil then
+          PtrInc := 100
+        else
+          PtrInc := 0;
+        Progress(Self, psEnding, PtrInc, PaletteModified, Rect(0,0,0,0), ''); // do not localize
+        // Make sure new palette gets realized, in case OnProgress event didn't.
+        if PaletteModified then
+          Changed(Self);
+      end;
+    except
+      on EAbort do ;   // OnProgress can raise EAbort to cancel image load
+    end;
+  finally
+    ReleaseContext(jc);
+  end;
+end;
+
+{****************************************************************************}
+
+function TJPEGImage.GetEmpty: Boolean;
+begin
+  Result := (FImage.FData = nil) and FBitmap.Empty;
+end;
+
+{****************************************************************************}
+
+function TJPEGImage.GetGrayscale: Boolean;
+begin
+  Result := FGrayscale or FImage.FGrayscale;
+end;
+
+{****************************************************************************}
+
+function TJPEGImage.GetPalette: HPalette;
+var
+  DC: HDC;
+begin
+  Result := 0;
+  if FBitmap <> nil then
+    Result := FBitmap.Palette
+  else if FTempPal <> 0 then
+    Result := FTempPal
+  else if FPixelFormat = jf24Bit then   // check for 8 bit screen
+  begin
+    DC := GetDC(0);
+    if (GetDeviceCaps(DC, BITSPIXEL) * GetDeviceCaps(DC, PLANES)) <= 8 then
+    begin
+      FTempPal := CreateHalftonePalette(DC);
+      Result := FTempPal;
+    end;
+    ReleaseDC(0, DC);
+  end;
+end;
+
+{****************************************************************************}
+
+function TJPEGImage.GetHeight: Integer;
+begin
+  if (FBitmap <> nil) then
+    Result := FBitmap.Height
+  else if (FScale = jsFullSize) then
+    Result := FImage.FHeight
+  else
+  begin
+    CalcOutputDimensions;
+    Result := FScaledHeight;
+  end;
+end;
+
+{****************************************************************************}
+
+function TJPEGImage.GetWidth: Integer;
+begin
+  if (FBitmap <> nil) then
+    Result := FBitmap.Width
+  else if (FScale = jsFullSize) then
+    Result := FImage.FWidth
+  else
+  begin
+    CalcOutputDimensions;
+    Result := FScaledWidth;
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.JPEGNeeded;
+begin
+  if (FImage.FData = nil) then
+    Compress;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.LoadFromClipboardFormat(AFormat: Word; AData: THandle;
+  APalette: HPALETTE);
+begin
+  //!! check for jpeg clipboard data, mime type image/jpeg
+  FBitmap.LoadFromClipboardFormat(AFormat, AData, APalette);
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.LoadFromStream(Stream: TStream);
+begin
+  ReadStream(Stream.Size - Stream.Position, Stream);
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.NewBitmap;
+begin
+  FBitmap.Free;
+  FBitmap := TBitmap.Create;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.NewImage;
+begin
+  if (FImage <> nil) then
+     FImage.Release;
+
+  FImage := TJPEGData.Create;
+  FImage.Reference;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.ReadData(Stream: TStream);
+var
+  Size: Longint;
+begin
+  Stream.Read(Size, SizeOf(Size));
+  ReadStream(Size, Stream);
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.ReadStream(Size: Longint; Stream: TStream);
+var
+  jerr: jpeg_error_mgr;
+  cinfo: jpeg_decompress_struct;
+begin
+  NewImage;
+  with FImage do
+  begin
+    FData := TMemoryStream.Create;
+    FData.Size := Size;
+    Stream.ReadBuffer(FData.Memory^, Size);
+    if (Size > 0) then
+    begin
+      jerr := jpeg_std_error;  // use local var for thread isolation
+      cinfo.common.err := @jerr;
+      jpeg_CreateDecompress(cinfo, JPEG_LIB_VERSION, sizeof(cinfo));
+      try
+        FData.Position := 0;
+//        jpeg_stdio_src(cinfo, FData);
+        cinfo.common.client_data := FImage;
+        cinfo.src := @jpeg_std_src;
+        cinfo.src.resync_to_restart := jpeg_resync_to_restart;
+        jpeg_read_header(cinfo, TRUE);
+        FWidth := cinfo.image_width;
+        FHeight := cinfo.image_height;
+        FGrayscale := cinfo.jpeg_color_space = JCS_GRAYSCALE;
+        FProgressiveEncoding := jpeg_has_multiple_scans(cinfo);
+      finally
+        jpeg_destroy_decompress(cinfo);
+      end;
+    end;
+  end;
+  PaletteModified := True;
+  Changed(Self);
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.SaveToClipboardFormat(var AFormat: Word; var AData: THandle;
+  var APalette: HPALETTE);
+begin
+//!!  check for jpeg clipboard format, mime type image/jpeg
+  Bitmap.SaveToClipboardFormat(AFormat, AData, APalette);
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.SaveToStream(Stream: TStream);
+begin
+  JPEGNeeded;
+  Stream.Write(FImage.FData.Memory^, FImage.FData.Size);
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.SetGrayscale(Value: Boolean);
+begin
+  if (FGrayscale <> Value) then
+  begin
+    FreeBitmap;
+    FGrayscale := Value;
+    PaletteModified := True;
+    Changed(Self);
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.SetHeight(Value: Integer);
+begin
+  InvalidOperation(SChangeJPGSize);
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.SetPalette(Value: HPalette);
+var
+  SignalChange: Boolean;
+begin
+  if (Value <> FTempPal) then
+  begin
+    SignalChange := (FBitmap <> nil) and (Value <> FBitmap.Palette);
+    if SignalChange then FreeBitmap;
+    FTempPal := Value;
+    if SignalChange then
+    begin
+      PaletteModified := True;
+      Changed(Self);
+    end;
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.SetPerformance(Value: TJPEGPerformance);
+begin
+  if (FPerformance <> Value) then
+  begin
+    FreeBitmap;
+    FPerformance := Value;
+    PaletteModified := True;
+    Changed(Self);
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.SetPixelFormat(Value: TJPEGPixelFormat);
+begin
+  if (FPixelFormat <> Value) then
+  begin
+    FreeBitmap;
+    FPixelFormat := Value;
+    PaletteModified := True;
+    Changed(Self);
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.SetScale(Value: TJPEGScale);
+begin
+  if (FScale <> Value) then
+  begin
+    FreeBitmap;
+    FScale := Value;
+    FNeedRecalc := True;
+    Changed(Self);
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.SetSmoothing(Value: Boolean);
+begin
+  if (FSmoothing <> Value) then
+  begin
+    FreeBitmap;
+    FSmoothing := Value;
+    Changed(Self);
+  end;
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.SetWidth(Value: Integer);
+begin
+  InvalidOperation(SChangeJPGSize);
+end;
+
+{****************************************************************************}
+
+procedure TJPEGImage.WriteData(Stream: TStream);
+var
+  Size: Longint;
+begin
+  Size := 0;
+  if Assigned(FImage.FData) then
+     Size := FImage.FData.Size;
+
+  Stream.Write(Size, Sizeof(Size));
+  if (Size > 0) then
+     Stream.Write(FImage.FData.Memory^, Size);
+end;
+
+{****************************************************************************}
+
+procedure InitDefaults;
+var
+  DC: HDC;
+begin
+  DC := GetDC(0);
+  if ((GetDeviceCaps(DC, BITSPIXEL) * GetDeviceCaps(DC, PLANES)) <= 8) then
+    JPEGDefaults.PixelFormat := jf8Bit
+  else
+    JPEGDefaults.PixelFormat := jf24Bit;
+  ReleaseDC(0, DC);
+end;
+
+{****************************************************************************}
+
+{$IFDEF LATE_BINDING}
+Initialization
+  hLibmng:= 0;
+  @_jpeg_CreateDecompress       := nil;
+  @_jpeg_stdio_src              := nil;
+  @_jpeg_read_header            := nil;
+  @_jpeg_calc_output_dimensions := nil;
+  @_jpeg_start_decompress       := nil;
+  @_jpeg_read_scanlines         := nil;
+  @_jpeg_finish_decompress      := nil;
+  @_jpeg_destroy_decompress     := nil;
+  @_jpeg_has_multiple_scans     := nil;
+  @_jpeg_consume_input          := nil;
+  @_jpeg_start_output           := nil;
+  @_jpeg_finish_output          := nil;
+  @_jpeg_destroy                := nil;
+  @_jpeg_CreateCompress         := nil;
+  @_jpeg_stdio_dest             := nil;
+  @_jpeg_set_defaults           := nil;
+  @_jpeg_set_quality            := nil;
+  @_jpeg_set_colorspace         := nil;
+  @_jpeg_simple_progression     := nil;
+  @_jpeg_start_compress         := nil;
+  @_jpeg_write_scanlines        := nil;
+  @_jpeg_finish_compress        := nil;
+  @_jpeg_resync_to_restart      := nil;
+{$ENDIF}
+
+{****************************************************************************}
+
+end.

Added: branches/BCB5/TNGImage/Package/NGTypes.pas
===================================================================
--- branches/BCB5/TNGImage/Package/NGTypes.pas	                        (rev 0)
+++ branches/BCB5/TNGImage/Package/NGTypes.pas	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,4232 @@
+unit NGTypes;
+
+{****************************************************************************}
+{*                                                                          *}
+{*  for copyright and version information see header in NGImages.pas        *}
+{*                                                                          *}
+{****************************************************************************}
+{*                                                                          *}
+{*  Changelog:                            * reverse chronological order *   *}
+{*                                                                          *}
+{*  * 1.2.0  *                                                              *}
+{*  2002/10/16 - GJU - Fixed string (de)compression routines                *}
+{*  2002/10/03 - GJU - Updated to libmng 1.0.5                              *}
+{*                                                                          *}
+{*  * 1.0.1  *                                                              *}
+{*  2001/10/23 - GJU - Adapted to work with Kylix                           *}
+{*                                                                          *}
+{*  * 0.9.8 *                                                               *}
+{*  2001/07/16 - SPR - Added late binding for ZLIB                          *}
+{*  2001/06/26 - GJU - Changed most CheckLIBMNGLoaded to assigned/exception *}
+{*  2001/06/23 - SPR - Added stuff for late binding                         *}
+{*  2001/05/08 - SPR - Restructured for Maintainability                     *}
+{*             - SPR - Seperated original NGImage.pas into multiple units   *}
+{*                                                                          *}
+{****************************************************************************}
+
+
+{$INCLUDE NGDefs.inc}
+
+
+
+interface
+
+
+
+{****************************************************************************}
+{* LIBMNG interface definitions                                             *}
+{* (translated from libmng.h)                                               *}
+{****************************************************************************}
+
+
+uses { Borland Standard Units }
+{$IFDEF LINUX}
+     SysUtils, QGraphics;
+{$ELSE}
+     Windows, Graphics;
+{$ENDIF}
+
+
+type
+  { Exception Types }
+  ENGImageException = class (EInvalidGraphicOperation);
+  ENGDLLNotLoaded   = class (EInvalidGraphicOperation);
+  ENGFuncUnknown    = class (EInvalidGraphicOperation);
+
+  { Library Defined Data Types }
+  { Note:  Items ending with the following are pointer types
+      - The character "p"
+      - The characters "ptr" or "pchar" }
+  mng_uint32     = cardinal;
+  mng_uint32p    = ^mng_uint32;
+
+  mng_uint16     = word;
+  mng_uint16p    = ^mng_uint16;
+
+  mng_int32      = integer;
+  mng_int16      = smallint;
+
+  mng_uint8      = byte;
+  mng_uint8p     = ^mng_uint8;
+
+  mng_int8       = shortint;
+  mng_bool       = boolean;
+  mng_ptr        = pointer;
+  mng_pchar      = pchar;
+
+  mng_handle     = pointer;
+  mng_retcode    = mng_int32;
+  mng_chunkid    = mng_uint32;
+  mng_chunkidp   = ^mng_chunkid;
+
+  mng_size_t     = cardinal;
+
+  mng_imgtype    = (mng_it_unknown, mng_it_png, mng_it_mng, mng_it_jng);
+  mng_speedtype  = (mng_st_normal, mng_st_fast, mng_st_slow, mng_st_slowest);
+
+
+  mng_palette8e  = packed record             // 8-bit palette element
+                     iRed   : mng_uint8;
+                     iGreen : mng_uint8;
+                     iBlue  : mng_uint8;
+                   end;
+
+  mng_palette8   = packed array [0 .. 255] of mng_palette8e;
+
+  mng_uint8arr   = packed array [0 .. 255] of mng_uint8;
+  mng_uint8arr4  = packed array [0 ..   3] of mng_uint8;
+  mng_uint16arr  = packed array [0 .. 255] of mng_uint16;
+  mng_uint32arr  = packed array [0 .. 255] of mng_uint32;
+  mng_uint32arr2 = packed array [0 ..   1] of mng_uint32;
+
+{****************************************************************************}
+{ Call-Back Function Definitions }
+type
+  { Function Types Referenced by Other Function Definitions }
+  Tmng_memalloc            = function  (    iLen         : mng_size_t) : mng_ptr;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_memfree             = procedure (    iPtr         : mng_ptr;
+                                            iLen         : mng_size_t);
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_openstream          = function  (    hHandle      : mng_handle) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_closestream         = function  (    hHandle      : mng_handle) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_readdata            = function  (    hHandle      : mng_handle;
+                                            pBuf         : mng_ptr;
+                                            iBuflen      : mng_uint32;
+                                        var pRead        : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_writedata           = function  (    hHandle      : mng_handle;
+                                            pBuf         : mng_ptr;
+                                            iBuflen      : mng_uint32;
+                                        var pWritten     : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_errorproc           = function  (    hHandle      : mng_handle;
+                                            iErrorcode   : mng_retcode;
+                                            iSeverity    : mng_uint8;
+                                            iChunkname   : mng_chunkid;
+                                            iChunkseq    : mng_uint32;
+                                            iExtra1      : mng_int32;
+                                            iExtra2      : mng_int32;
+                                            zErrortext   : mng_pchar ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_traceproc           = function  (    hHandle      : mng_handle;
+                                            iFuncnr      : mng_int32;
+                                            iFuncseq     : mng_uint32;
+                                            zFuncname    : mng_pchar ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_processheader       = function  (    hHandle      : mng_handle;
+                                            iWidth       : mng_uint32;
+                                            iHeight      : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_processtext         = function  (    hHandle      : mng_handle;
+                                            iType        : mng_uint8;
+                                            zKeyword     : mng_pchar;
+                                            zText        : mng_pchar;
+                                            zLanguage    : mng_pchar;
+                                            zTranslation : mng_pchar ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_processsave         = function  (    hHandle      : mng_handle) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_processseek         = function  (    hHandle      : mng_handle;
+                                            zName        : mng_pchar ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_processneed         = function  (    hHandle      : mng_handle;
+                                            zName        : mng_pchar ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_processmend         = function  (    hHandle      : mng_handle;
+                                            iIterationsdone : mng_uint32;
+                                            iIterationsleft : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_processunknown      = function  (    hHandle      : mng_handle;
+                                            iChunkid     : mng_chunkid;
+                                            iRawlen      : mng_uint32;
+                                            pRawdata     : mng_ptr   ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_processterm         = function  (    hHandle      : mng_handle;
+                                            iTermaction  : mng_uint8;
+                                            iIteraction  : mng_uint8;
+                                            iDelay       : mng_uint32;
+                                            iItermax     : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_getcanvasline       = function  (    hHandle      : mng_handle;
+                                            iLinenr      : mng_uint32) : mng_ptr;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getalphaline        = function  (    hHandle      : mng_handle;
+                                            iLinenr      : mng_uint32) : mng_ptr;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getbkgdline         = function  (    hHandle      : mng_handle;
+                                            iLinenr      : mng_uint32) : mng_ptr;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_refresh             = function  (    hHandle      : mng_handle;
+                                            iX           : mng_uint32;
+                                            iY           : mng_uint32;
+                                            iWidth       : mng_uint32;
+                                            iHeight      : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_gettickcount        = function  (    hHandle      : mng_handle) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_settimer            = function  (    hHandle      : mng_handle;
+                                            iMsecs       : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_iteratechunk        = function  (    hHandle      : mng_handle;
+                                            hChunk       : mng_handle;
+                                            iChunkid     : mng_chunkid;
+                                            iChunkseq    : mng_uint32) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{****************************************************************************}
+  { Interface for either the Early or Late Binding to the DLL }
+  function mng_version_text    : mng_pchar;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_version_so      : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_version_dll     : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_version_major   : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_version_minor   : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_version_release : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_version_beta    : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+{****************************************************************************}
+
+  function mng_supports_func        (zFunction          : mng_pchar;
+                                     var iMajor         : mng_uint8;
+                                     var iMinor         : mng_uint8;
+                                     var iRelease       : mng_uint8         ) : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+{****************************************************************************}
+
+  function mng_initialize           (pUserdata          : mng_ptr;
+                                     fMemalloc          : Tmng_memalloc;
+                                     fMemfree           : Tmng_memfree;
+                                     fTraceproc         : Tmng_traceproc    ) : mng_handle;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_reset                (hHandle            : mng_handle        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_cleanup              (var hHandle        : mng_handle        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_read(hHandle                             : mng_handle        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_write(hHandle                            : mng_handle        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_create(hHandle                           : mng_handle        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_readdisplay          (hHandle            : mng_handle        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_display              (hHandle            : mng_handle        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_display_resume       (hHandle            : mng_handle        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_display_freeze       (hHandle            : mng_handle        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_display_reset        (hHandle            : mng_handle        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_trapevent            (hHandle            : mng_handle;
+                                     iEventtype         : mng_uint8;
+                                     iX                 : mng_int32;
+                                     iY                 : mng_int32         ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_getlasterror         (hHandle            : mng_handle;
+                                     var iSeverity      : mng_uint8;
+                                     var iChunkname     : mng_chunkid;
+                                     var iChunkseq      : mng_uint32;
+                                     var iExtra1        : mng_int32;
+                                     var iExtra2        : mng_int32;
+                                     var zErrortext     : mng_pchar         ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+{****************************************************************************}
+
+  function mng_setcb_memalloc       (hHandle            : mng_handle;
+                                     fProc              : Tmng_memalloc     ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_memfree        (hHandle            : mng_handle;
+                                     fProc              : Tmng_memfree      ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_setcb_openstream     (hHandle            : mng_handle;
+                                     fProc              : Tmng_openstream   ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_closestream    (hHandle            : mng_handle;
+                                     fProc              : Tmng_closestream  ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_setcb_readdata       (hHandle            : mng_handle;
+                                     fProc              : Tmng_readdata     ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_setcb_writedata      (hHandle            : mng_handle;
+                                     fProc              : Tmng_writedata    ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_setcb_errorproc      (hHandle            : mng_handle;
+                                     fProc              : Tmng_errorproc    ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_setcb_processheader  (hHandle            : mng_handle;
+                                     fProc              : Tmng_processheader) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_processtext    (hHandle            : mng_handle;
+                                     fProc              : Tmng_processtext  ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_processsave    (hHandle            : mng_handle;
+                                     fProc              : Tmng_processsave  ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_processseek    (hHandle            : mng_handle;
+                                     fProc              : Tmng_processseek  ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_processneed    (hHandle            : mng_handle;
+                                     fProc              : Tmng_processneed  ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_processmend    (hHandle            : mng_handle;
+                                     fProc              : Tmng_processmend  ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_processunknown (hHandle            : mng_handle;
+                                     fProc              : Tmng_processunknown) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_processterm    (hHandle            : mng_handle;
+                                     fProc              : Tmng_processterm  ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_setcb_getcanvasline  (hHandle            : mng_handle;
+                                     fProc              : Tmng_getcanvasline) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_getalphaline   (hHandle            : mng_handle;
+                                     fProc              : Tmng_getalphaline ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_getbkgdline    (hHandle            : mng_handle;
+                                     fProc              : Tmng_getbkgdline  ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_refresh        (hHandle            : mng_handle;
+                                     fProc              : Tmng_refresh      ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_setcb_gettickcount   (hHandle            : mng_handle;
+                                     fProc              : Tmng_gettickcount ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_setcb_settimer       (hHandle            : mng_handle;
+                                     fProc              : Tmng_settimer     ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+{****************************************************************************}
+
+  function mng_getcb_memalloc       (hHandle            : mng_handle       ) : Tmng_memalloc;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_memfree        (hHandle            : mng_handle       ) : Tmng_memfree;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_getcb_openstream     (hHandle            : mng_handle       ) : Tmng_openstream;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_closestream    (hHandle            : mng_handle       ) : Tmng_closestream;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_getcb_readdata       (hHandle            : mng_handle       ) : Tmng_readdata;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_getcb_writedata      (hHandle            : mng_handle       ) : Tmng_writedata;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_getcb_errorproc      (hHandle            : mng_handle       ) : Tmng_errorproc;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_getcb_processheader  (hHandle            : mng_handle       ) : Tmng_processheader;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_processtext    (hHandle            : mng_handle       ) : Tmng_processtext;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_processsave    (hHandle            : mng_handle       ) : Tmng_processsave;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_processseek    (hHandle            : mng_handle       ) : Tmng_processseek;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_processneed    (hHandle            : mng_handle       ) : Tmng_processneed;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_processmend    (hHandle            : mng_handle       ) : Tmng_processmend;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_processunknown (hHandle            : mng_handle       ) : Tmng_processunknown;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_processterm    (hHandle            : mng_handle       ) : Tmng_processterm;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_getcb_getcanvasline  (hHandle            : mng_handle       ) : Tmng_getcanvasline;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_getalphaline   (hHandle            : mng_handle       ) : Tmng_getalphaline;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_getbkgdline    (hHandle            : mng_handle       ) : Tmng_getbkgdline;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_refresh        (hHandle            : mng_handle       ) : Tmng_refresh;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_getcb_gettickcount   (hHandle            : mng_handle       ) : Tmng_gettickcount;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_getcb_settimer       (hHandle            : mng_handle       ) : Tmng_settimer;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+{****************************************************************************}
+
+  function mng_set_userdata         (hHandle            : mng_handle;
+                                     pUserdata          : mng_ptr          ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_set_canvasstyle      (hHandle            : mng_handle;
+                                     iStyle             : mng_uint32       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_set_bkgdstyle        (hHandle            : mng_handle;
+                                     iStyle             : mng_uint32       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_set_bgcolor          (hHandle            : mng_handle;
+                                     iRed               : mng_uint16;
+                                     iGreen             : mng_uint16;
+                                     iBlue              : mng_uint16       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_set_usebkgd          (hHandle            : mng_handle;
+                                     bUseBKGD           : mng_bool         ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_set_storechunks      (hHandle            : mng_handle;
+                                     bStorechunks       : mng_bool         ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_set_cacheplayback    (hHandle            : mng_handle;
+                                     bCacheplayback     : mng_bool         ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_set_viewgammaint     (hHandle            : mng_handle;
+                                     iGamma             : mng_uint32       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_set_displaygammaint  (hHandle            : mng_handle;
+                                     iGamma             : mng_uint32       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_set_dfltimggammaint  (hHandle            : mng_handle;
+                                     iGamma             : mng_uint32       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_set_srgb             (hHandle            : mng_handle;
+                                     bIssRGB            : mng_bool         ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_set_outputprofile    (hHandle            : mng_handle;
+                                     zFilename          : mng_pchar        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_set_outputprofile2   (hHandle            : mng_handle;
+                                     iProfilesize       : mng_uint32;
+                                     pProfile           : mng_ptr          ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_set_outputsrgb       (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_set_srgbprofile      (hHandle            : mng_handle;
+                                     zFilename          : mng_pchar        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_set_srgbprofile2     (hHandle            : mng_handle;
+                                     iProfilesize       : mng_uint32;
+                                     pProfile           : mng_ptr          ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_set_srgbimplicit     (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_set_maxcanvassize    (hHandle            : mng_handle;
+                                     iMaxwidth          : mng_uint32;
+                                     iMaxheight         : mng_uint32       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+{****************************************************************************}
+
+  function mng_get_userdata         (hHandle            : mng_handle       ) : mng_ptr;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_get_sigtype          (hHandle            : mng_handle       ) : mng_imgtype;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_imagetype        (hHandle            : mng_handle       ) : mng_imgtype;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_imagewidth       (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_imageheight      (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_ticks            (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_framecount       (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_layercount       (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_playtime         (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_simplicity       (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_get_bitdepth         (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_colortype        (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_compression      (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_filter           (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_interlace        (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_alphabitdepth    (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_alphacompression (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_alphafilter      (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_alphainterlace   (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_get_alphadepth       (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  procedure mng_get_bgcolor         (hHandle            : mng_handle;
+                                     var iRed           : mng_uint16;
+                                     var iGreen         : mng_uint16;
+                                     var iBlue          : mng_uint16       );
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_get_usebkgd          (hHandle            : mng_handle       ) : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_get_viewgammaint     (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_displaygammaint  (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_dfltimggammaint  (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_get_srgb             (hHandle            : mng_handle       ) : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_get_maxcanvaswidth   (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_maxcanvasheight  (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_get_starttime        (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_runtime          (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_currentframe     (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_currentlayer     (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_get_currentplaytime  (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+  function mng_status_error         (hHandle            : mng_handle       ) : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_status_reading       (hHandle            : mng_handle       ) : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_status_suspendbreak  (hHandle            : mng_handle       ) : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_status_creating      (hHandle            : mng_handle       ) : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_status_writing       (hHandle            : mng_handle       ) : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_status_displaying    (hHandle            : mng_handle       ) : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_status_running       (hHandle            : mng_handle       ) : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_status_timerbreak    (hHandle            : mng_handle       ) : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_status_dynamic       (hHandle            : mng_handle       ) : mng_bool;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+{****************************************************************************}
+
+  function mng_putchunk_ihdr        (hHandle            : mng_handle;
+                                     iWidth             : mng_uint32;
+                                     iHeight            : mng_uint32;
+                                     iBitdepth          : mng_uint8;
+                                     iColortype         : mng_uint8;
+                                     iCompression       : mng_uint8;
+                                     iFilter            : mng_uint8;
+                                     iInterlace         : mng_uint8        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_plte        (hHandle            : mng_handle;
+                                     iCount             : mng_uint32;
+                                     aPalette           : mng_palette8     ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_idat        (hHandle            : mng_handle;
+                                     iRawlen            : mng_uint32;
+                                     pRawdata           : mng_ptr          ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_iend        (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_trns        (hHandle            : mng_handle;
+                                     bEmpty             : mng_bool;
+                                     bGlobal            : mng_bool;
+                                     iType              : mng_uint8;
+                                     iCount             : mng_uint32;
+                                     aAlphas            : mng_uint8arr;
+                                     iGray              : mng_uint16;
+                                     iRed               : mng_uint16;
+                                     iGreen             : mng_uint16;
+                                     iBlue              : mng_uint16;
+                                     iRawlen            : mng_uint32;
+                                     aRawdata           : mng_uint8arr     ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_gama        (hHandle            : mng_handle;
+                                     bEmpty             : mng_bool;
+                                     iGamma             : mng_uint32       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_chrm        (hHandle            : mng_handle;
+                                     bEmpty             : mng_bool;
+                                     iWhitepointx       : mng_uint32;
+                                     iWhitepointy       : mng_uint32;
+                                     iRedx              : mng_uint32;
+                                     iRedy              : mng_uint32;
+                                     iGreenx            : mng_uint32;
+                                     iGreeny            : mng_uint32;
+                                     iBluex             : mng_uint32;
+                                     iBluey             : mng_uint32       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_srgb        (hHandle            : mng_handle;
+                                     bEmpty             : mng_bool;
+                                     iRenderingintent   : mng_uint8        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_iccp        (hHandle            : mng_handle;
+                                     bEmpty             : mng_bool;
+                                     iNamesize          : mng_uint32;
+                                     zName              : mng_pchar;
+                                     iCompression       : mng_uint8;
+                                     iProfilesize       : mng_uint32;
+                                     pProfile           : mng_ptr          ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_text        (hHandle            : mng_handle;
+                                     iKeywordsize       : mng_uint32;
+                                     zKeyword           : mng_pchar;
+                                     iTextsize          : mng_uint32;
+                                     zText              : mng_pchar        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_ztxt        (hHandle            : mng_handle;
+                                     iKeywordsize       : mng_uint32;
+                                     zKeyword           : mng_pchar;
+                                     iCompression       : mng_uint8;
+                                     iTextsize          : mng_uint32;
+                                     zText              : mng_pchar        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_itxt        (hHandle            : mng_handle;
+                                     iKeywordsize       : mng_uint32;
+                                     zKeyword           : mng_pchar;
+                                     iCompressionflag   : mng_uint8;
+                                     iCompressionmethod : mng_uint8;
+                                     iLanguagesize      : mng_uint32;
+                                     zLanguage          : mng_pchar;
+                                     iTranslationsize   : mng_uint32;
+                                     zTranslation       : mng_pchar;
+                                     iTextsize          : mng_uint32;
+                                     zText              : mng_pchar        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_bkgd        (hHandle            : mng_handle;
+                                     bEmpty             : mng_bool;
+                                     iType              : mng_uint8;
+                                     iIndex             : mng_uint8;
+                                     iGray              : mng_uint16;
+                                     iRed               : mng_uint16;
+                                     iGreen             : mng_uint16;
+                                     iBlue              : mng_uint16       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_phys        (hHandle            : mng_handle;
+                                     bEmpty             : mng_bool;
+                                     iSizex             : mng_uint32;
+                                     iSizey             : mng_uint32;
+                                     iUnit              : mng_uint8        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_sbit        (hHandle            : mng_handle;
+                                     bEmpty             : mng_bool;
+                                     iType              : mng_uint8;
+                                     aBits              : mng_uint8arr4    ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_splt        (hHandle            : mng_handle;
+                                     bEmpty             : mng_bool;
+                                     iNamesize          : mng_uint32;
+                                     zName              : mng_pchar;
+                                     iSampledepth       : mng_uint8;
+                                     iEntrycount        : mng_uint32;
+                                     pEntries           : mng_ptr          ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_hist        (hHandle            : mng_handle;
+                                     iEntrycount        : mng_uint32;
+                                     aEntries           : mng_uint16arr    ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_time        (hHandle            : mng_handle;
+                                     iYear              : mng_uint16;
+                                     iMonth             : mng_uint8;
+                                     iDay               : mng_uint8;
+                                     iHour              : mng_uint8;
+                                     iMinute            : mng_uint8;
+                                     iSecond            : mng_uint8        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_jhdr        (hHandle            : mng_handle;
+                                     iWidth             : mng_uint32;
+                                     iHeight            : mng_uint32;
+                                     iColortype         : mng_uint8;
+                                     iImagesampledepth  : mng_uint8;
+                                     iImagecompression  : mng_uint8;
+                                     iImageinterlace    : mng_uint8;
+                                     iAlphasampledepth  : mng_uint8;
+                                     iAlphacompression  : mng_uint8;
+                                     iAlphafilter       : mng_uint8;
+                                     iAlphainterlace    : mng_uint8        ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_jdat        (hHandle            : mng_handle;
+                                     iRawlen            : mng_uint32;
+                                     pRawdata           : mng_ptr          ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+  function mng_putchunk_jsep        (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFNDEF LATE_BINDING} {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} {$ENDIF}
+
+{****************************************************************************}
+{* LIBMNG interface definitions for ZLIB                                    *}
+{****************************************************************************}
+{*                                                                          *}
+{*  Uses "zlib" - a mighty, patent-free(!) (de)compression-library          *}
+{*  copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler                 *}
+{*  http://www.info-zip.org/pub/infozip/zlib                                *}
+{*                                                                          *}
+{****************************************************************************}
+
+{$IFDEF INCLUDE_ZLIB}
+
+{****************************************************************************}
+
+function InflateString  (    Input      : string;
+                         var Output     : string ) : integer;
+
+function DeflateString  (    Input      : string;
+                         var Output     : string ) : integer;
+
+function InflateString2 (    Input      : string;
+                         var Output     : string;
+                             windowBits : integer) : integer;
+
+function DeflateString2 (    Input      : string;
+                         var Output     : string;
+                             level      : integer;
+                             method     : integer;
+                             windowBits : integer;
+                             memLevel   : integer;
+                             strategy   : integer) : integer;
+
+{****************************************************************************}
+
+const
+  ZLIB_VERSION          = '1.1.4';                         // do not localize
+
+  { Return Values }
+  Z_NO_FLUSH            = 0;
+  Z_PARTIAL_FLUSH       = 1;
+  Z_SYNC_FLUSH          = 2;
+  Z_FULL_FLUSH          = 3;
+  Z_FINISH              = 4;
+
+  Z_OK                  = 0;
+  Z_STREAM_END          = 1;
+  Z_NEED_DICT           = 2;
+  Z_ERRNO               = -1;
+  Z_STREAM_ERROR        = -2;
+  Z_DATA_ERROR          = -3;
+  Z_MEM_ERROR           = -4;
+  Z_BUF_ERROR           = -5;
+  Z_VERSION_ERROR       = -6;
+
+  Z_NO_COMPRESSION      = 0;
+  Z_BEST_SPEED          = 1;
+  Z_BEST_COMPRESSION    = 9;
+  Z_DEFAULT_COMPRESSION = -1;
+
+  Z_FILTERED            = 1;
+  Z_HUFFMAN_ONLY        = 2;
+  Z_DEFAULT_STRATEGY    = 0;
+
+  Z_BINARY              = 0;
+  Z_ASCII               = 1;
+  Z_UNKNOWN             = 2;
+
+  Z_DEFLATED            = 8;
+
+  Z_NULL                = 0;
+
+  Z_MAX_MEM_LEVEL       = 9;
+  Z_DEF_MEM_LEVEL       = 8;
+
+{****************************************************************************}
+
+type
+  alloc_func = function  (opaque  : pointer;
+                          items   : integer;
+                          size    : integer) : pointer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  free_func  = procedure (opaque  : pointer;
+                          address : pointer);
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{****************************************************************************}
+
+type
+  z_stream   = packed record
+                 next_in   : pointer;
+                 avail_in  : integer;
+                 total_in  : cardinal;
+
+                 next_out  : pointer;
+                 avail_out : integer;
+                 total_out : cardinal;
+
+                 msg       : pchar;
+                 state     : pointer;    { reserved }
+
+                 zalloc    : alloc_func;
+                 zfree     : free_func;
+                 opaque    : pointer;
+
+                 data_type : integer;
+                 adler     : cardinal;
+                 reserved  : cardinal;
+               end;
+
+  z_streamp  = ^z_stream;
+
+{****************************************************************************}
+
+function zlibVersion : pchar;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function deflateInit          (strm        : z_streamp;
+                               level       : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function deflate              (strm        : z_streamp;
+                               flush       : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function deflateEnd           (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function inflateInit          (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function inflate              (strm        : z_streamp;
+                               flush       : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function inflateEnd           (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function deflateInit2         (strm        : z_streamp;
+                               level       : integer;
+                               method      : integer;
+                               windowBits  : integer;
+                               memLevel    : integer;
+                               strategy    : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function deflateSetDictionary (strm        : z_streamp;
+                               dictionary  : pointer;
+                               dictLength  : cardinal ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function deflateCopy          (dest        : z_streamp;
+                               source      : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function deflateReset         (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function deflateParams        (strm        : z_streamp;
+                               level       : integer;
+                               strategy    : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function inflateInit2         (strm        : z_streamp;
+                               windowBits  : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function inflateSetDictionary (strm        : z_streamp;
+                               dictionary  : pointer;
+                               dictLength  : cardinal ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function inflateSync          (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function inflateReset         (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function compress             (dest        : pointer;
+                               var destLen : cardinal;
+                               source      : pointer;
+                               sourceLen   : cardinal ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function compress2            (dest        : pointer;
+                               var destLen : cardinal;
+                               source      : pointer;
+                               sourceLen   : cardinal;
+                               level       : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function uncompress           (dest        : pointer;
+                               var destLen : cardinal;
+                               source      : pointer;
+                               sourceLen   : cardinal ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function adler32              (adler       : cardinal;
+                               buf         : pointer;
+                               len         : cardinal ) : cardinal;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function crc32                (crc         : cardinal;
+                               buf         : pointer;
+                               len         : cardinal ) : cardinal;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function zError               (err         : integer  ) : pchar;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function inflateSyncPoint     (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+function get_crc_table : pointer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{****************************************************************************}
+
+{$ENDIF} // INCLUDE_ZLIB
+
+
+{****************************************************************************}
+
+{$IFDEF LATE_BINDING}
+
+procedure BeginUseLibmng;
+procedure EndUseLibmng;
+procedure BeginUseZLib;
+procedure EndUseZLib;
+
+{$ENDIF}
+
+{****************************************************************************}
+
+
+implementation
+
+
+uses { Own Units }
+     NGConst;
+
+
+{****************************************************************************}
+
+  { Working Function Definitions for implementation of both Early and Late Binding to the DLL }
+type
+  Tmng_version_text        = function: mng_pchar;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_version_so          = function: mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_version_dll         = function: mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_version_major       = function: mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_version_minor       = function: mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_version_release     = function: mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_version_beta        = function: mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{****************************************************************************}
+
+  Tmng_supports_func       = function (zFunction          : mng_pchar;
+                                       var iMajor         : mng_uint8;
+                                       var iMinor         : mng_uint8;
+                                       var iRelease       : mng_uint8        ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{****************************************************************************}
+
+  Tmng_initialize          = function (pUserdata          : mng_ptr;
+                                       fMemalloc          : Tmng_memalloc;
+                                       fMemfree           : Tmng_memfree;
+                                       fTraceproc         : Tmng_traceproc   ) : mng_handle;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_reset               = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_cleanup             = function (var hHandle        : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_read                = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_write               = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_create              = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_readdisplay         = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_display             = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_display_resume      = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_display_freeze      = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_display_reset       = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_trapevent           = function (hHandle            : mng_handle;
+                                       iEventtype         : mng_uint8;
+                                       iX                 : mng_int32;
+                                       iY                 : mng_int32        ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_getlasterror        = function (hHandle            : mng_handle;
+                                       var iSeverity      : mng_uint8;
+                                       var iChunkname     : mng_chunkid;
+                                       var iChunkseq      : mng_uint32;
+                                       var iExtra1        : mng_int32;
+                                       var iExtra2        : mng_int32;
+                                       var zErrortext     : mng_pchar        ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{****************************************************************************}
+
+  Tmng_setcb_memalloc      = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_memalloc     ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_memfree       = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_memfree      ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_setcb_openstream    = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_openstream   ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_closestream   = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_closestream  ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_setcb_readdata      = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_readdata     ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_setcb_writedata     = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_writedata    ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_setcb_errorproc     = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_errorproc    ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_setcb_processheader = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_processheader) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_processtext   = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_processtext  ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_processsave   = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_processsave  ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_processseek   = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_processseek  ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_processneed   = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_processneed  ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_processmend   = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_processmend  ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_processunknown = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_processunknown) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_processterm   = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_processterm  ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_setcb_getcanvasline = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_getcanvasline) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_getalphaline  = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_getalphaline ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_getbkgdline   = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_getbkgdline  ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_refresh       = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_refresh      ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_setcb_gettickcount  = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_gettickcount ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_setcb_settimer      = function (hHandle            : mng_handle;
+                                       fProc              : Tmng_settimer     ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{****************************************************************************}
+
+  Tmng_getcb_memalloc      = function (hHandle            : mng_handle       ) : Tmng_memalloc;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_memfree       = function (hHandle            : mng_handle       ) : Tmng_memfree;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_getcb_openstream    = function (hHandle            : mng_handle       ) : Tmng_openstream;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_closestream   = function (hHandle            : mng_handle       ) : Tmng_closestream;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_getcb_readdata      = function (hHandle            : mng_handle       ) : Tmng_readdata;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_getcb_writedata     = function (hHandle            : mng_handle       ) : Tmng_writedata;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_getcb_errorproc     = function (hHandle            : mng_handle       ) : Tmng_errorproc;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_getcb_processheader = function (hHandle            : mng_handle       ) : Tmng_processheader;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_processtext   = function (hHandle            : mng_handle       ) : Tmng_processtext;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_processsave   = function (hHandle            : mng_handle       ) : Tmng_processsave;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_processseek   = function (hHandle            : mng_handle       ) : Tmng_processseek;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_processneed   = function (hHandle            : mng_handle       ) : Tmng_processneed;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_processmend   = function (hHandle            : mng_handle       ) : Tmng_processmend;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_processunknown = function (hHandle           : mng_handle       ) : Tmng_processunknown;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_processterm   = function (hHandle            : mng_handle       ) : Tmng_processterm;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_getcb_getcanvasline = function (hHandle            : mng_handle       ) : Tmng_getcanvasline;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_getalphaline  = function (hHandle            : mng_handle       ) : Tmng_getalphaline;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_getbkgdline   = function (hHandle            : mng_handle       ) : Tmng_getbkgdline;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_refresh       = function (hHandle            : mng_handle       ) : Tmng_refresh;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_getcb_gettickcount  = function (hHandle            : mng_handle       ) : Tmng_gettickcount;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_getcb_settimer      = function (hHandle            : mng_handle       ) : Tmng_settimer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{****************************************************************************}
+
+  Tmng_set_userdata        = function (hHandle            : mng_handle;
+                                       pUserdata          : mng_ptr          ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_set_canvasstyle     = function (hHandle            : mng_handle;
+                                       iStyle             : mng_uint32       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_set_bkgdstyle       = function (hHandle            : mng_handle;
+                                       iStyle             : mng_uint32       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_set_bgcolor         = function (hHandle            : mng_handle;
+                                       iRed               : mng_uint16;
+                                       iGreen             : mng_uint16;
+                                       iBlue              : mng_uint16       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_set_usebkgd         = function (hHandle            : mng_handle;
+                                       bUseBKGD           : mng_bool         ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_set_storechunks     = function (hHandle            : mng_handle;
+                                       bStorechunks       : mng_bool         ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_set_cacheplayback   = function (hHandle            : mng_handle;
+                                       bCacheplayback     : mng_bool         ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_set_viewgammaint    = function (hHandle            : mng_handle;
+                                       iGamma             : mng_uint32       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_set_displaygammaint = function (hHandle            : mng_handle;
+                                       iGamma             : mng_uint32       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_set_dfltimggammaint = function (hHandle            : mng_handle;
+                                       iGamma             : mng_uint32       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_set_srgb            = function (hHandle            : mng_handle;
+                                       bIssRGB            : mng_bool         ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_set_outputprofile   = function (hHandle            : mng_handle;
+                                       zFilename          : mng_pchar        ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_set_outputprofile2  = function (hHandle            : mng_handle;
+                                       iProfilesize       : mng_uint32;
+                                       pProfile           : mng_ptr          ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_set_outputsrgb      = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_set_srgbprofile     = function (hHandle            : mng_handle;
+                                       zFilename          : mng_pchar        ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_set_srgbprofile2    = function (hHandle            : mng_handle;
+                                       iProfilesize       : mng_uint32;
+                                       pProfile           : mng_ptr          ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_set_srgbimplicit    = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_set_maxcanvassize   = function (hHandle            : mng_handle;
+                                       iMaxwidth          : mng_uint32;
+                                       iMaxheight         : mng_uint32       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{****************************************************************************}
+
+  Tmng_get_userdata        = function (hHandle            : mng_handle       ) : mng_ptr;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_get_sigtype         = function (hHandle            : mng_handle       ) : mng_imgtype;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_imagetype       = function (hHandle            : mng_handle       ) : mng_imgtype;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_imagewidth      = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_imageheight     = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_ticks           = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_framecount      = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_layercount      = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_playtime        = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_simplicity      = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_get_bitdepth        = function (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_colortype       = function (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_compression     = function (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_filter          = function (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_interlace       = function (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_alphabitdepth   = function (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_alphacompression= function (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_alphafilter     = function (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_alphainterlace  = function (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_get_alphadepth      = function (hHandle            : mng_handle       ) : mng_uint8;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_get_bgcolor         = procedure (hHandle           : mng_handle;
+                                        var iRed          : mng_uint16;
+                                        var iGreen        : mng_uint16;
+                                        var iBlue         : mng_uint16       );
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_get_usebkgd         = function (hHandle            : mng_handle       ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_get_viewgammaint    = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_displaygammaint = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_dfltimggammaint = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_get_srgb            = function (hHandle            : mng_handle       ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_get_maxcanvaswidth  = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_maxcanvasheight = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_get_starttime       = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_runtime         = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_currentframe    = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_currentlayer    = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_get_currentplaytime = function (hHandle            : mng_handle       ) : mng_uint32;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_status_error        = function (hHandle            : mng_handle       ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_status_reading      = function (hHandle            : mng_handle       ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_status_suspendbreak = function (hHandle            : mng_handle       ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_status_creating     = function (hHandle            : mng_handle       ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_status_writing      = function (hHandle            : mng_handle       ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_status_displaying   = function (hHandle            : mng_handle       ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_status_running      = function (hHandle            : mng_handle       ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_status_timerbreak   = function (hHandle            : mng_handle       ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tmng_status_dynamic      = function (hHandle            : mng_handle       ) : mng_bool;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{****************************************************************************}
+
+  Tmng_putchunk_ihdr       = function (hHandle            : mng_handle;
+                                       iWidth             : mng_uint32;
+                                       iHeight            : mng_uint32;
+                                       iBitdepth          : mng_uint8;
+                                       iColortype         : mng_uint8;
+                                       iCompression       : mng_uint8;
+                                       iFilter            : mng_uint8;
+                                       iInterlace         : mng_uint8        ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_plte       = function (hHandle            : mng_handle;
+                                       iCount             : mng_uint32;
+                                       aPalette           : mng_palette8     ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_idat       = function (hHandle            : mng_handle;
+                                       iRawlen            : mng_uint32;
+                                       pRawdata           : mng_ptr          ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_iend       = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_trns       = function (hHandle            : mng_handle;
+                                       bEmpty             : mng_bool;
+                                       bGlobal            : mng_bool;
+                                       iType              : mng_uint8;
+                                       iCount             : mng_uint32;
+                                       aAlphas            : mng_uint8arr;
+                                       iGray              : mng_uint16;
+                                       iRed               : mng_uint16;
+                                       iGreen             : mng_uint16;
+                                       iBlue              : mng_uint16;
+                                       iRawlen            : mng_uint32;
+                                       aRawdata           : mng_uint8arr     ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_gama       = function (hHandle            : mng_handle;
+                                       bEmpty             : mng_bool;
+                                       iGamma             : mng_uint32       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_chrm       = function (hHandle            : mng_handle;
+                                       bEmpty             : mng_bool;
+                                       iWhitepointx       : mng_uint32;
+                                       iWhitepointy       : mng_uint32;
+                                       iRedx              : mng_uint32;
+                                       iRedy              : mng_uint32;
+                                       iGreenx            : mng_uint32;
+                                       iGreeny            : mng_uint32;
+                                       iBluex             : mng_uint32;
+                                       iBluey             : mng_uint32       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_srgb       = function (hHandle            : mng_handle;
+                                       bEmpty             : mng_bool;
+                                       iRenderingintent   : mng_uint8        ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_iccp       = function (hHandle            : mng_handle;
+                                       bEmpty             : mng_bool;
+                                       iNamesize          : mng_uint32;
+                                       zName              : mng_pchar;
+                                       iCompression       : mng_uint8;
+                                       iProfilesize       : mng_uint32;
+                                       pProfile           : mng_ptr          ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_text       = function (hHandle            : mng_handle;
+                                       iKeywordsize       : mng_uint32;
+                                       zKeyword           : mng_pchar;
+                                       iTextsize          : mng_uint32;
+                                       zText              : mng_pchar        ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_ztxt       = function (hHandle            : mng_handle;
+                                       iKeywordsize       : mng_uint32;
+                                       zKeyword           : mng_pchar;
+                                       iCompression       : mng_uint8;
+                                       iTextsize          : mng_uint32;
+                                       zText              : mng_pchar        ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_itxt       = function (hHandle            : mng_handle;
+                                       iKeywordsize       : mng_uint32;
+                                       zKeyword           : mng_pchar;
+                                       iCompressionflag   : mng_uint8;
+                                       iCompressionmethod : mng_uint8;
+                                       iLanguagesize      : mng_uint32;
+                                       zLanguage          : mng_pchar;
+                                       iTranslationsize   : mng_uint32;
+                                       zTranslation       : mng_pchar;
+                                       iTextsize          : mng_uint32;
+                                       zText              : mng_pchar        ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_bkgd       = function (hHandle            : mng_handle;
+                                       bEmpty             : mng_bool;
+                                       iType              : mng_uint8;
+                                       iIndex             : mng_uint8;
+                                       iGray              : mng_uint16;
+                                       iRed               : mng_uint16;
+                                       iGreen             : mng_uint16;
+                                       iBlue              : mng_uint16       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_phys       = function (hHandle            : mng_handle;
+                                       bEmpty             : mng_bool;
+                                       iSizex             : mng_uint32;
+                                       iSizey             : mng_uint32;
+                                       iUnit              : mng_uint8        ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_sbit       = function (hHandle            : mng_handle;
+                                       bEmpty             : mng_bool;
+                                       iType              : mng_uint8;
+                                       aBits              : mng_uint8arr4    ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_splt       = function (hHandle            : mng_handle;
+                                       bEmpty             : mng_bool;
+                                       iNamesize          : mng_uint32;
+                                       zName              : mng_pchar;
+                                       iSampledepth       : mng_uint8;
+                                       iEntrycount        : mng_uint32;
+                                       pEntries           : mng_ptr          ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_hist       = function (hHandle            : mng_handle;
+                                       iEntrycount        : mng_uint32;
+                                       aEntries           : mng_uint16arr    ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_time       = function (hHandle            : mng_handle;
+                                       iYear              : mng_uint16;
+                                       iMonth             : mng_uint8;
+                                       iDay               : mng_uint8;
+                                       iHour              : mng_uint8;
+                                       iMinute            : mng_uint8;
+                                       iSecond            : mng_uint8        ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_jhdr       = function (hHandle            : mng_handle;
+                                       iWidth             : mng_uint32;
+                                       iHeight            : mng_uint32;
+                                       iColortype         : mng_uint8;
+                                       iImagesampledepth  : mng_uint8;
+                                       iImagecompression  : mng_uint8;
+                                       iImageinterlace    : mng_uint8;
+                                       iAlphasampledepth  : mng_uint8;
+                                       iAlphacompression  : mng_uint8;
+                                       iAlphafilter       : mng_uint8;
+                                       iAlphainterlace    : mng_uint8        ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_jdat       = function (hHandle            : mng_handle;
+                                       iRawlen            : mng_uint32;
+                                       pRawdata           : mng_ptr          ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  Tmng_putchunk_jsep       = function (hHandle            : mng_handle       ) : mng_retcode;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{****************************************************************************}
+
+{$IFDEF INCLUDE_ZLIB}
+
+type
+  TdeflateInit_ = function (strm        : z_streamp;
+                            level       : integer;
+                            version     : pchar;
+                            stream_size : integer) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  TinflateInit_ = function (strm        : z_streamp;
+                            version     : pchar;
+                            stream_size : integer) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  TdeflateInit2_ = function (strm        : z_streamp;
+                             level       : integer;
+                             method      : integer;
+                             windowBits  : integer;
+                             memLevel    : integer;
+                             strategy    : integer;
+                             version     : pchar;
+                             stream_size : integer) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+  TinflateInit2_ = function (strm        : z_streamp;
+                             windowBits  : integer;
+                             version     : pchar;
+                             stream_size : integer) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{****************************************************************************}
+
+  TzLibVersion          = function: PChar;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TdeflateInit          = function (strm        : z_streamp;
+                                    level       : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tdeflate              = function (strm        : z_streamp;
+                                    flush       : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TdeflateEnd           = function (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TinflateInit          = function (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tinflate              = function (strm        : z_streamp;
+                                    flush       : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TinflateEnd           = function (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TdeflateInit2         = function (strm        : z_streamp;
+                                    level       : integer;
+                                    method      : integer;
+                                    windowBits  : integer;
+                                    memLevel    : integer;
+                                    strategy    : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TdeflateSetDictionary = function (strm        : z_streamp;
+                                    dictionary  : pointer;
+                                    dictLength  : cardinal ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TdeflateCopy          = function (dest        : z_streamp;
+                                    source      : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TdeflateReset         = function (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TdeflateParams        = function (strm        : z_streamp;
+                                    level       : integer;
+                                    strategy    : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TinflateInit2         = function (strm        : z_streamp;
+                                    windowBits  : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TinflateSetDictionary = function (strm        : z_streamp;
+                                    dictionary  : pointer;
+                                    dictLength  : cardinal ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TinflateSync          = function (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TinflateReset         = function (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tcompress             = function (dest        : pointer;
+                                    var destLen : cardinal;
+                                    source      : pointer;
+                                    sourceLen   : cardinal ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tcompress2            = function (dest        : pointer;
+                                    var destLen : cardinal;
+                                    source      : pointer;
+                                    sourceLen   : cardinal;
+                                    level       : integer  ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tuncompress           = function (dest        : pointer;
+                                    var destLen : cardinal;
+                                    source      : pointer;
+                                    sourceLen   : cardinal ) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tadler32              = function (adler       : cardinal;
+                                    buf         : pointer;
+                                    len         : cardinal ) : cardinal;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tcrc32                = function (crc         : cardinal;
+                                    buf         : pointer;
+                                    len         : cardinal ) : cardinal;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TzError               = function (err         : integer  ) : pchar;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  TinflateSyncPoint     = function (strm        : z_streamp) : integer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+  Tget_crc_table        = function : pointer;
+  {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF}
+
+{$ENDIF} // INCLUDE_ZLIB
+
+{****************************************************************************}
+
+{$IFDEF LATE_BINDING}
+
+type
+  TMNGFuncType = (lmf_unknown,
+                  lmf_version_text, lmf_version_so, lmf_version_dll,
+                  lmf_version_major, lmf_version_minor, lmf_version_release,
+                  lmf_version_beta, lmf_supports_func,
+                  lmf_initialize, lmf_reset, lmf_cleanup, lmf_read,
+                  lmf_write, lmf_create, lmf_readdisplay, lmf_display,
+                  lmf_display_resume, lmf_display_freeze, lmf_display_reset,
+                  lmf_trapevent, lmf_getlasterror,
+                  lmf_setcb_memalloc, lmf_setcb_memfree,
+                  lmf_setcb_openstream, lmf_setcb_closestream,
+                  lmf_setcb_readdata, lmf_setcb_writedata, lmf_setcb_errorproc,
+                  lmf_setcb_processheader, lmf_setcb_processtext,
+                  lmf_setcb_processsave, lmf_setcb_processseek, lmf_setcb_processneed,
+                  lmf_setcb_processmend, lmf_setcb_processunknown, lmf_setcb_processterm,
+                  lmf_setcb_getcanvasline, lmf_setcb_getalphaline, lmf_setcb_getbkgdline,
+                  lmf_setcb_refresh, lmf_setcb_gettickcount, lmf_setcb_settimer,
+                  lmf_getcb_memalloc, lmf_getcb_memfree,
+                  lmf_getcb_openstream, lmf_getcb_closestream,
+                  lmf_getcb_readdata, lmf_getcb_writedata, lmf_getcb_errorproc,
+                  lmf_getcb_processheader, lmf_getcb_processtext,
+                  lmf_getcb_processsave, lmf_getcb_processseek, lmf_getcb_processneed,
+                  lmf_getcb_processmend, lmf_getcb_processunknown, lmf_getcb_processterm,
+                  lmf_getcb_getcanvasline, lmf_getcb_getalphaline, lmf_getcb_getbkgdline,
+                  lmf_getcb_refresh, lmf_getcb_gettickcount, lmf_getcb_settimer,
+                  lmf_set_userdata, lmf_set_canvasstyle, lmf_set_bkgdstyle,
+                  lmf_set_bgcolor, lmf_set_usebkgd, lmf_set_storechunks,
+                  lmf_set_cacheplayback, lmf_set_viewgammaint,
+                  lmf_set_displaygammaint, lmf_set_dfltimggammaint,
+                  lmf_set_srgb, lmf_set_outputprofile, lmf_set_outputprofile2,
+                  lmf_set_outputsrgb, lmf_set_srgbprofile, lmf_set_srgbprofile2,
+                  lmf_set_srgbimplicit, lmf_set_maxcanvassize,
+                  lmf_get_userdata, lmf_get_sigtype, lmf_get_imagetype,
+                  lmf_get_imagewidth, lmf_get_imageheight,
+                  lmf_get_ticks, lmf_get_framecount, lmf_get_layercount,
+                  lmf_get_playtime, lmf_get_simplicity,
+                  lmf_get_bitdepth, lmf_get_colortype, lmf_get_compression,
+                  lmf_get_filter, lmf_get_interlace,
+                  lmf_get_alphabitdepth, lmf_get_alphacompression,
+                  lmf_get_alphafilter, lmf_get_alphainterlace, lmf_get_alphadepth,
+                  lmf_get_bgcolor, lmf_get_usebkgd,
+                  lmf_get_viewgammaint, lmf_get_displaygammaint, lmf_get_dfltimggammaint,
+                  lmf_get_srgb, lmf_get_maxcanvaswidth, lmf_get_maxcanvasheight,
+                  lmf_get_starttime, lmf_get_runtime,
+                  lmf_get_currentframe, lmf_get_currentlayer, lmf_get_currentplaytime,
+                  lmf_status_error, lmf_status_reading, lmf_status_suspendbreak,
+                  lmf_status_creating, lmf_status_writing, lmf_status_displaying,
+                  lmf_status_running, lmf_status_timerbreak, lmf_status_dynamic,
+                  lmf_putchunk_ihdr, lmf_putchunk_plte, lmf_putchunk_idat,
+                  lmf_putchunk_iend, lmf_putchunk_trns, lmf_putchunk_gama,
+                  lmf_putchunk_chrm, lmf_putchunk_srgb, lmf_putchunk_iccp,
+                  lmf_putchunk_text, lmf_putchunk_ztxt, lmf_putchunk_itxt,
+                  lmf_putchunk_bkgd, lmf_putchunk_phys, lmf_putchunk_sbit,
+                  lmf_putchunk_splt, lmf_putchunk_hist, lmf_putchunk_time,
+                  lmf_putchunk_jhdr, lmf_putchunk_jdat, lmf_putchunk_jsep);
+
+  TMNGFunc = record case TMNGFuncType of
+               lmf_unknown              : (f_ptr                  : pointer);
+               lmf_version_text         : (f_version_text         : Tmng_version_text);
+               lmf_version_so           : (f_version_so           : Tmng_version_so);
+               lmf_version_dll          : (f_version_dll          : Tmng_version_dll);
+               lmf_version_major        : (f_version_major        : Tmng_version_major);
+               lmf_version_minor        : (f_version_minor        : Tmng_version_minor);
+               lmf_version_release      : (f_version_release      : Tmng_version_release);
+               lmf_version_beta         : (f_version_beta         : Tmng_version_beta);
+               lmf_supports_func        : (f_supports_func        : Tmng_supports_func);
+               lmf_initialize           : (f_initialize           : Tmng_initialize);
+               lmf_reset                : (f_reset                : Tmng_reset);
+               lmf_cleanup              : (f_cleanup              : Tmng_cleanup);
+               lmf_read                 : (f_read                 : Tmng_read);
+               lmf_write                : (f_write                : Tmng_write);
+               lmf_create               : (f_create               : Tmng_create);
+               lmf_readdisplay          : (f_readdisplay          : Tmng_readdisplay);
+               lmf_display              : (f_display              : Tmng_display);
+               lmf_display_resume       : (f_display_resume       : Tmng_display_resume);
+               lmf_display_freeze       : (f_display_freeze       : Tmng_display_freeze);
+               lmf_display_reset        : (f_display_reset        : Tmng_display_reset);
+               lmf_trapevent            : (f_trapevent            : Tmng_trapevent);
+               lmf_getlasterror         : (f_getlasterror         : Tmng_getlasterror);
+               lmf_setcb_memalloc       : (f_setcb_memalloc       : Tmng_setcb_memalloc);
+               lmf_setcb_memfree        : (f_setcb_memfree        : Tmng_setcb_memfree);       
+               lmf_setcb_openstream     : (f_setcb_openstream     : Tmng_setcb_openstream);    
+               lmf_setcb_closestream    : (f_setcb_closestream    : Tmng_setcb_closestream);   
+               lmf_setcb_readdata       : (f_setcb_readdata       : Tmng_setcb_readdata);      
+               lmf_setcb_writedata      : (f_setcb_writedata      : Tmng_setcb_writedata);     
+               lmf_setcb_errorproc      : (f_setcb_errorproc      : Tmng_setcb_errorproc);     
+               lmf_setcb_processheader  : (f_setcb_processheader  : Tmng_setcb_processheader); 
+               lmf_setcb_processtext    : (f_setcb_processtext    : Tmng_setcb_processtext);   
+               lmf_setcb_processsave    : (f_setcb_processsave    : Tmng_setcb_processsave);
+               lmf_setcb_processseek    : (f_setcb_processseek    : Tmng_setcb_processseek);   
+               lmf_setcb_processneed    : (f_setcb_processneed    : Tmng_setcb_processneed);   
+               lmf_setcb_processmend    : (f_setcb_processmend    : Tmng_setcb_processmend);
+               lmf_setcb_processunknown : (f_setcb_processunknown : Tmng_setcb_processunknown);
+               lmf_setcb_processterm    : (f_setcb_processterm    : Tmng_setcb_processterm);   
+               lmf_setcb_getcanvasline  : (f_setcb_getcanvasline  : Tmng_setcb_getcanvasline); 
+               lmf_setcb_getalphaline   : (f_setcb_getalphaline   : Tmng_setcb_getalphaline);
+               lmf_setcb_getbkgdline    : (f_setcb_getbkgdline    : Tmng_setcb_getbkgdline);   
+               lmf_setcb_refresh        : (f_setcb_refresh        : Tmng_setcb_refresh);       
+               lmf_setcb_gettickcount   : (f_setcb_gettickcount   : Tmng_setcb_gettickcount);
+               lmf_setcb_settimer       : (f_setcb_settimer       : Tmng_setcb_settimer);      
+               lmf_getcb_memalloc       : (f_getcb_memalloc       : Tmng_getcb_memalloc);      
+               lmf_getcb_memfree        : (f_getcb_memfree        : Tmng_getcb_memfree);
+               lmf_getcb_openstream     : (f_getcb_openstream     : Tmng_getcb_openstream);    
+               lmf_getcb_closestream    : (f_getcb_closestream    : Tmng_getcb_closestream);   
+               lmf_getcb_readdata       : (f_getcb_readdata       : Tmng_getcb_readdata);      
+               lmf_getcb_writedata      : (f_getcb_writedata      : Tmng_getcb_writedata);     
+               lmf_getcb_errorproc      : (f_getcb_errorproc      : Tmng_getcb_errorproc);     
+               lmf_getcb_processheader  : (f_getcb_processheader  : Tmng_getcb_processheader);
+               lmf_getcb_processtext    : (f_getcb_processtext    : Tmng_getcb_processtext);   
+               lmf_getcb_processsave    : (f_getcb_processsave    : Tmng_getcb_processsave);   
+               lmf_getcb_processseek    : (f_getcb_processseek    : Tmng_getcb_processseek);
+               lmf_getcb_processneed    : (f_getcb_processneed    : Tmng_getcb_processneed);
+               lmf_getcb_processmend    : (f_getcb_processmend    : Tmng_getcb_processmend);
+               lmf_getcb_processunknown : (f_getcb_processunknown : Tmng_getcb_processunknown);
+               lmf_getcb_processterm    : (f_getcb_processterm    : Tmng_getcb_processterm);
+               lmf_getcb_getcanvasline  : (f_getcb_getcanvasline  : Tmng_getcb_getcanvasline); 
+               lmf_getcb_getalphaline   : (f_getcb_getalphaline   : Tmng_getcb_getalphaline);  
+               lmf_getcb_getbkgdline    : (f_getcb_getbkgdline    : Tmng_getcb_getbkgdline);   
+               lmf_getcb_refresh        : (f_getcb_refresh        : Tmng_getcb_refresh);
+               lmf_getcb_gettickcount   : (f_getcb_gettickcount   : Tmng_getcb_gettickcount);  
+               lmf_getcb_settimer       : (f_getcb_settimer       : Tmng_getcb_settimer);      
+               lmf_set_userdata         : (f_set_userdata         : Tmng_set_userdata);        
+               lmf_set_canvasstyle      : (f_set_canvasstyle      : Tmng_set_canvasstyle);     
+               lmf_set_bkgdstyle        : (f_set_bkgdstyle        : Tmng_set_bkgdstyle);
+               lmf_set_bgcolor          : (f_set_bgcolor          : Tmng_set_bgcolor);
+               lmf_set_usebkgd          : (f_set_usebkgd          : Tmng_set_usebkgd);         
+               lmf_set_storechunks      : (f_set_storechunks      : Tmng_set_storechunks);     
+               lmf_set_cacheplayback    : (f_set_cacheplayback    : Tmng_set_cacheplayback);
+               lmf_set_viewgammaint     : (f_set_viewgammaint     : Tmng_set_viewgammaint);    
+               lmf_set_displaygammaint  : (f_set_displaygammaint  : Tmng_set_displaygammaint); 
+               lmf_set_dfltimggammaint  : (f_set_dfltimggammaint  : Tmng_set_dfltimggammaint); 
+               lmf_set_srgb             : (f_set_srgb             : Tmng_set_srgb);            
+               lmf_set_outputprofile    : (f_set_outputprofile    : Tmng_set_outputprofile);   
+               lmf_set_outputprofile2   : (f_set_outputprofile2   : Tmng_set_outputprofile2);
+               lmf_set_outputsrgb       : (f_set_outputsrgb       : Tmng_set_outputsrgb);      
+               lmf_set_srgbprofile      : (f_set_srgbprofile      : Tmng_set_srgbprofile);     
+               lmf_set_srgbprofile2     : (f_set_srgbprofile2     : Tmng_set_srgbprofile2);
+               lmf_set_srgbimplicit     : (f_set_srgbimplicit     : Tmng_set_srgbimplicit);    
+               lmf_set_maxcanvassize    : (f_set_maxcanvassize    : Tmng_set_maxcanvassize);   
+               lmf_get_userdata         : (f_get_userdata         : Tmng_get_userdata);        
+               lmf_get_sigtype          : (f_get_sigtype          : Tmng_get_sigtype);         
+               lmf_get_imagetype        : (f_get_imagetype        : Tmng_get_imagetype);       
+               lmf_get_imagewidth       : (f_get_imagewidth       : Tmng_get_imagewidth);      
+               lmf_get_imageheight      : (f_get_imageheight      : Tmng_get_imageheight);     
+               lmf_get_ticks            : (f_get_ticks            : Tmng_get_ticks);           
+               lmf_get_framecount       : (f_get_framecount       : Tmng_get_framecount);
+               lmf_get_layercount       : (f_get_layercount       : Tmng_get_layercount);      
+               lmf_get_playtime         : (f_get_playtime         : Tmng_get_playtime);        
+               lmf_get_simplicity       : (f_get_simplicity       : Tmng_get_simplicity);      
+               lmf_get_bitdepth         : (f_get_bitdepth         : Tmng_get_bitdepth);        
+               lmf_get_colortype        : (f_get_colortype        : Tmng_get_colortype);       
+               lmf_get_compression      : (f_get_compression      : Tmng_get_compression);
+               lmf_get_filter           : (f_get_filter           : Tmng_get_filter);
+               lmf_get_interlace        : (f_get_interlace        : Tmng_get_interlace);       
+               lmf_get_alphabitdepth    : (f_get_alphabitdepth    : Tmng_get_alphabitdepth);   
+               lmf_get_alphacompression : (f_get_alphacompression : Tmng_get_alphacompression);
+               lmf_get_alphafilter      : (f_get_alphafilter      : Tmng_get_alphafilter);
+               lmf_get_alphainterlace   : (f_get_alphainterlace   : Tmng_get_alphainterlace);
+               lmf_get_alphadepth       : (f_get_alphadepth       : Tmng_get_alphadepth);      
+               lmf_get_bgcolor          : (f_get_bgcolor          : Tmng_get_bgcolor);         
+               lmf_get_usebkgd          : (f_get_usebkgd          : Tmng_get_usebkgd);         
+               lmf_get_viewgammaint     : (f_get_viewgammaint     : Tmng_get_viewgammaint);
+               lmf_get_displaygammaint  : (f_get_displaygammaint  : Tmng_get_displaygammaint); 
+               lmf_get_dfltimggammaint  : (f_get_dfltimggammaint  : Tmng_get_dfltimggammaint); 
+               lmf_get_srgb             : (f_get_srgb             : Tmng_get_srgb);            
+               lmf_get_maxcanvaswidth   : (f_get_maxcanvaswidth   : Tmng_get_maxcanvaswidth);  
+               lmf_get_maxcanvasheight  : (f_get_maxcanvasheight  : Tmng_get_maxcanvasheight);
+               lmf_get_starttime        : (f_get_starttime        : Tmng_get_starttime);
+               lmf_get_runtime          : (f_get_runtime          : Tmng_get_runtime);         
+               lmf_get_currentframe     : (f_get_currentframe     : Tmng_get_currentframe);    
+               lmf_get_currentlayer     : (f_get_currentlayer     : Tmng_get_currentlayer);    
+               lmf_get_currentplaytime  : (f_get_currentplaytime  : Tmng_get_currentplaytime); 
+               lmf_status_error         : (f_status_error         : Tmng_status_error);        
+               lmf_status_reading       : (f_status_reading       : Tmng_status_reading);      
+               lmf_status_suspendbreak  : (f_status_suspendbreak  : Tmng_status_suspendbreak); 
+               lmf_status_creating      : (f_status_creating      : Tmng_status_creating);     
+               lmf_status_writing       : (f_status_writing       : Tmng_status_writing);
+               lmf_status_displaying    : (f_status_displaying    : Tmng_status_displaying);   
+               lmf_status_running       : (f_status_running       : Tmng_status_running);
+               lmf_status_timerbreak    : (f_status_timerbreak    : Tmng_status_timerbreak);
+               lmf_status_dynamic       : (f_status_dynamic       : Tmng_status_dynamic);
+               lmf_putchunk_ihdr        : (f_putchunk_ihdr        : Tmng_putchunk_ihdr);
+               lmf_putchunk_plte        : (f_putchunk_plte        : Tmng_putchunk_plte);
+               lmf_putchunk_idat        : (f_putchunk_idat        : Tmng_putchunk_idat);
+               lmf_putchunk_iend        : (f_putchunk_iend        : Tmng_putchunk_iend);
+               lmf_putchunk_trns        : (f_putchunk_trns        : Tmng_putchunk_trns);
+               lmf_putchunk_gama        : (f_putchunk_gama        : Tmng_putchunk_gama);
+               lmf_putchunk_chrm        : (f_putchunk_chrm        : Tmng_putchunk_chrm);
+               lmf_putchunk_srgb        : (f_putchunk_srgb        : Tmng_putchunk_srgb);
+               lmf_putchunk_iccp        : (f_putchunk_iccp        : Tmng_putchunk_iccp);
+               lmf_putchunk_text        : (f_putchunk_text        : Tmng_putchunk_text);
+               lmf_putchunk_ztxt        : (f_putchunk_ztxt        : Tmng_putchunk_ztxt);
+               lmf_putchunk_itxt        : (f_putchunk_itxt        : Tmng_putchunk_itxt);
+               lmf_putchunk_bkgd        : (f_putchunk_bkgd        : Tmng_putchunk_bkgd);
+               lmf_putchunk_phys        : (f_putchunk_phys        : Tmng_putchunk_phys);
+               lmf_putchunk_sbit        : (f_putchunk_sbit        : Tmng_putchunk_sbit);
+               lmf_putchunk_splt        : (f_putchunk_splt        : Tmng_putchunk_splt);
+               lmf_putchunk_hist        : (f_putchunk_hist        : Tmng_putchunk_hist);
+               lmf_putchunk_time        : (f_putchunk_time        : Tmng_putchunk_time);
+               lmf_putchunk_jhdr        : (f_putchunk_jhdr        : Tmng_putchunk_jhdr);
+               lmf_putchunk_jdat        : (f_putchunk_jdat        : Tmng_putchunk_jdat);
+               lmf_putchunk_jsep        : (f_putchunk_jsep        : Tmng_putchunk_jsep);
+             end;
+
+  TMNGRec  = record
+               sName : string;
+               fPtr  : TMNGFunc;
+             end;
+
+{$IFDEF INCLUDE_ZLIB}
+  TZFuncType = (zlf_unknown,
+                zlf_deflateInit_, zlf_inflateInit_, zlf_deflateInit2_, zlf_inflateInit2_,
+                zlf_zlibVersion, zlf_deflateInit, zlf_deflate, zlf_deflateEnd,
+                zlf_inflateInit, zlf_inflate, zlf_inflateEnd,
+                zlf_deflateInit2, zlf_deflateSetDictionary,
+                zlf_deflateCopy, zlf_deflateReset, zlf_deflateParams,
+                zlf_inflateInit2, zlf_inflateSetDictionary,
+                zlf_inflateSync, zlf_inflateReset,
+                zlf_compress, zlf_compress2, zlf_uncompress,
+                zlf_adler32, zlf_crc32, zlf_zError,
+                zlf_inflateSyncPoint, zlf_get_crc_table);
+
+  TZFunc = record case TZFuncType of
+             zlf_unknown              : (f_ptr                  : pointer);
+             zlf_deflateInit_         : (f_deflateInit_         : TdeflateInit_);
+             zlf_inflateInit_         : (f_inflateInit_         : TinflateInit_);
+             zlf_deflateInit2_        : (f_deflateInit2_        : TdeflateInit2_);
+             zlf_inflateInit2_        : (f_inflateInit2_        : TinflateInit2_);
+             zlf_zlibVersion          : (f_zlibVersion          : TzlibVersion);
+             zlf_deflateInit          : (f_deflateInit          : TdeflateInit);
+             zlf_deflate              : (f_deflate              : Tdeflate);
+             zlf_deflateEnd           : (f_deflateEnd           : TdeflateEnd);
+             zlf_inflateInit          : (f_inflateInit          : TinflateInit);
+             zlf_inflate              : (f_inflate              : Tinflate);
+             zlf_inflateEnd           : (f_inflateEnd           : TinflateEnd);
+             zlf_deflateInit2         : (f_deflateInit2         : TdeflateInit2);
+             zlf_deflateSetDictionary : (f_deflateSetDictionary : TdeflateSetDictionary);
+             zlf_deflateCopy          : (f_deflateCopy          : TdeflateCopy);
+             zlf_deflateReset         : (f_deflateReset         : TdeflateReset);
+             zlf_deflateParams        : (f_deflateParams        : TdeflateParams);
+             zlf_inflateInit2         : (f_inflateInit2         : TinflateInit2);
+             zlf_inflateSetDictionary : (f_inflateSetDictionary : TinflateSetDictionary);
+             zlf_inflateSync          : (f_inflateSync          : TinflateSync);
+             zlf_inflateReset         : (f_inflateReset         : TinflateReset);
+             zlf_compress             : (f_compress             : Tcompress);
+             zlf_compress2            : (f_compress2            : Tcompress2);
+             zlf_uncompress           : (f_uncompress           : Tuncompress);
+             zlf_adler32              : (f_adler32              : Tadler32);
+             zlf_crc32                : (f_crc32                : Tcrc32);
+             zlf_zError               : (f_zError               : TzError);
+             zlf_inflateSyncPoint     : (f_inflateSyncPoint     : TinflateSyncPoint);
+             zlf_get_crc_table        : (f_get_crc_table        : Tget_crc_table);
+           end;
+
+  TZRec  = record
+             sName : string;
+             fPtr  : TZFunc;
+           end;
+
+{$ENDIF} // INCLUDE_ZLIB
+
+{****************************************************************************}
+
+var
+  hLibmng : THandle;
+{$IFDEF LINUX}
+  hLibz   : THandle;
+{$ENDIF}
+{****************************************************************************}
+  iMNGUse : Integer = 0;
+
+  aMNGFuncs: array[lmf_version_text..lmf_putchunk_jsep] of TMNGRec =
+             ((sName: 'mng_version_text';         fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_version_so';           fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_version_dll';          fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_version_major';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_version_minor';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_version_release';      fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_version_beta';         fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_supports_func';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_initialize';           fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_reset';                fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_cleanup';              fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_read';                 fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_write';                fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_create';               fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_readdisplay';          fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_display';              fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_display_resume';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_display_freeze';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_display_reset';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_trapevent';            fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getlasterror';         fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_memalloc';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_memfree';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_openstream';     fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_closestream';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_readdata';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_writedata';      fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_errorproc';      fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_processheader';  fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_processtext';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_processsave';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_processseek';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_processneed';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_processmend';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_processunknown'; fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_processterm';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_getcanvasline';  fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_getalphaline';   fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_getbkgdline';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_refresh';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_gettickcount';   fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_setcb_settimer';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_memalloc';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_memfree';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_openstream';     fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_closestream';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_readdata';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_writedata';      fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_errorproc';      fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_processheader';  fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_processtext';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_processsave';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_processseek';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_processneed';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_processmend';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_processunknown'; fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_processterm';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_getcanvasline';  fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_getalphaline';   fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_getbkgdline';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_refresh';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_gettickcount';   fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_getcb_settimer';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_userdata';         fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_canvasstyle';      fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_bkgdstyle';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_bgcolor';          fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_usebkgd';          fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_storechunks';      fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_cacheplayback';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_viewgammaint';     fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_displaygammaint';  fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_dfltimggammaint';  fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_srgb';             fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_outputprofile';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_outputprofile2';   fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_outputsrgb';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_srgbprofile';      fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_srgbprofile2';     fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_srgbimplicit';     fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_set_maxcanvassize';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_userdata';         fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_sigtype';          fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_imagetype';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_imagewidth';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_imageheight';      fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_ticks';            fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_framecount';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_layercount';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_playtime';         fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_simplicity';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_bitdepth';         fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_colortype';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_compression';      fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_filter';           fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_interlace';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_alphabitdepth';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_alphacompression'; fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_alphafilter';      fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_alphainterlace';   fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_alphadepth';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_bgcolor';          fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_usebkgd';          fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_viewgammaint';     fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_displaygammaint';  fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_dfltimggammaint';  fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_srgb';             fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_maxcanvaswidth';   fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_maxcanvasheight';  fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_starttime';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_runtime';          fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_currentframe';     fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_currentlayer';     fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_get_currentplaytime';  fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_status_error';         fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_status_reading';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_status_suspendbreak';  fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_status_creating';      fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_status_writing';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_status_displaying';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_status_running';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_status_timerbreak';    fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_status_dynamic';       fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_ihdr';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_plte';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_idat';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_iend';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_trns';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_gama';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_chrm';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_srgb';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_iccp';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_text';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_ztxt';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_itxt';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_bkgd';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_phys';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_sbit';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_splt';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_hist';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_time';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_jhdr';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_jdat';        fPtr: (f_Ptr: nil)), // do not localize
+              (sName: 'mng_putchunk_jsep';        fPtr: (f_Ptr: nil))); // do not localize
+
+{$IFDEF INCLUDE_ZLIB}
+  iZLIBUse : Integer = 0;
+
+  aZFuncs: array[zlf_deflateInit_..zlf_get_crc_table] of  TZRec =
+           ((sName: 'deflateInit_';         fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'inflateInit_';         fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'deflateInit2_';        fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'inflateInit2_';        fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'zlibVersion';          fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'deflateInit';          fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'deflate';              fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'deflateEnd';           fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'inflateInit';          fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'inflate';              fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'inflateEnd';           fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'deflateInit2';         fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'deflateSetDictionary'; fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'deflateCopy';          fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'deflateReset';         fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'deflateParams';        fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'inflateInit2';         fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'inflateSetDictionary'; fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'inflateSync';          fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'inflateReset';         fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'compress';             fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'compress2';            fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'uncompress';           fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'adler32';              fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'crc32';                fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'zError';               fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'inflateSyncPoint';     fPtr: (f_Ptr: nil)), // do not localize
+            (sName: 'get_crc_table';        fPtr: (f_Ptr: nil))); // do not localize
+{$ENDIF} // INCLUDE_ZLIB
+
+{$ENDIF} // LATE_BINDING
+
+{****************************************************************************}
+{* LIBMNG implementation definitions                                        *}
+{****************************************************************************}
+
+{$IFNDEF LATE_BINDING}
+function mng_version_text;         external mngdll;
+function mng_version_so;           external mngdll;
+function mng_version_dll;          external mngdll;
+function mng_version_major;        external mngdll;
+function mng_version_minor;        external mngdll;
+function mng_version_release;      external mngdll;
+function mng_version_beta;         external mngdll;
+
+{****************************************************************************}
+
+function mng_supports_func;        external mngdll;
+
+{****************************************************************************}
+
+function mng_initialize;           external mngdll;
+function mng_reset;                external mngdll;
+function mng_cleanup;              external mngdll;
+
+function mng_read;                 external mngdll;
+function mng_write;                external mngdll;
+function mng_create;               external mngdll;
+
+function mng_readdisplay;          external mngdll;
+function mng_display;              external mngdll;
+function mng_display_resume;       external mngdll;
+function mng_display_freeze;       external mngdll;
+function mng_display_reset;        external mngdll;
+
+function mng_trapevent;            external mngdll;
+
+function mng_getlasterror;         external mngdll;
+
+{****************************************************************************}
+
+function mng_setcb_memalloc;       external mngdll;
+function mng_setcb_memfree;        external mngdll;
+
+function mng_setcb_openstream;     external mngdll;
+function mng_setcb_closestream;    external mngdll;
+
+function mng_setcb_readdata;       external mngdll;
+
+function mng_setcb_writedata;      external mngdll;
+
+function mng_setcb_errorproc;      external mngdll;
+
+function mng_setcb_processheader;  external mngdll;
+function mng_setcb_processtext;    external mngdll;
+function mng_setcb_processsave;    external mngdll;
+function mng_setcb_processseek;    external mngdll;
+function mng_setcb_processneed;    external mngdll;
+function mng_setcb_processmend;    external mngdll;
+function mng_setcb_processunknown; external mngdll;
+function mng_setcb_processterm;    external mngdll;
+
+function mng_setcb_getcanvasline;  external mngdll;
+function mng_setcb_getalphaline;   external mngdll;
+function mng_setcb_getbkgdline;    external mngdll;
+function mng_setcb_refresh;        external mngdll;
+
+function mng_setcb_gettickcount;   external mngdll;
+function mng_setcb_settimer;       external mngdll;
+
+{****************************************************************************}
+
+function mng_getcb_memalloc;       external mngdll;
+function mng_getcb_memfree;        external mngdll;
+
+function mng_getcb_openstream;     external mngdll;
+function mng_getcb_closestream;    external mngdll;
+
+function mng_getcb_readdata;       external mngdll;
+
+function mng_getcb_writedata;      external mngdll;
+
+function mng_getcb_errorproc;      external mngdll;
+
+function mng_getcb_processheader;  external mngdll;
+function mng_getcb_processtext;    external mngdll;
+function mng_getcb_processsave;    external mngdll;
+function mng_getcb_processseek;    external mngdll;
+function mng_getcb_processneed;    external mngdll;
+function mng_getcb_processmend;    external mngdll;
+function mng_getcb_processunknown; external mngdll;
+function mng_getcb_processterm;    external mngdll;
+
+function mng_getcb_getcanvasline;  external mngdll;
+function mng_getcb_getalphaline;   external mngdll;
+function mng_getcb_getbkgdline;    external mngdll;
+function mng_getcb_refresh;        external mngdll;
+
+function mng_getcb_gettickcount;   external mngdll;
+function mng_getcb_settimer;       external mngdll;
+
+{****************************************************************************}
+
+function mng_set_userdata;         external mngdll;
+
+function mng_set_canvasstyle;      external mngdll;
+function mng_set_bkgdstyle;        external mngdll;
+
+function mng_set_bgcolor;          external mngdll;
+function mng_set_usebkgd;          external mngdll;
+
+function mng_set_storechunks;      external mngdll;
+function mng_set_cacheplayback;    external mngdll;
+
+function mng_set_viewgammaint;     external mngdll;
+function mng_set_displaygammaint;  external mngdll;
+function mng_set_dfltimggammaint;  external mngdll;
+
+function mng_set_srgb;             external mngdll;
+function mng_set_outputprofile;    external mngdll;
+function mng_set_outputprofile2;   external mngdll;
+function mng_set_outputsrgb;       external mngdll;
+function mng_set_srgbprofile;      external mngdll;
+function mng_set_srgbprofile2;     external mngdll;
+function mng_set_srgbimplicit;     external mngdll;
+
+function mng_set_maxcanvassize;    external mngdll;
+
+{****************************************************************************}
+
+function mng_get_userdata;         external mngdll;
+
+function mng_get_sigtype;          external mngdll;
+function mng_get_imagetype;        external mngdll;
+function mng_get_imagewidth;       external mngdll;
+function mng_get_imageheight;      external mngdll;
+function mng_get_ticks;            external mngdll;
+function mng_get_framecount;       external mngdll;
+function mng_get_layercount;       external mngdll;
+function mng_get_playtime;         external mngdll;
+function mng_get_simplicity;       external mngdll;
+
+function mng_get_bitdepth;         external mngdll;
+function mng_get_colortype;        external mngdll;
+function mng_get_compression;      external mngdll;
+function mng_get_filter;           external mngdll;
+function mng_get_interlace;        external mngdll;
+function mng_get_alphabitdepth;    external mngdll;
+function mng_get_alphacompression; external mngdll;
+function mng_get_alphafilter;      external mngdll;
+function mng_get_alphainterlace;   external mngdll;
+
+function mng_get_alphadepth;       external mngdll;
+
+procedure mng_get_bgcolor;         external mngdll;
+function mng_get_usebkgd;          external mngdll;
+
+function mng_get_viewgammaint;     external mngdll;
+function mng_get_displaygammaint;  external mngdll;
+function mng_get_dfltimggammaint;  external mngdll;
+
+function mng_get_srgb;             external mngdll;
+
+function mng_get_maxcanvaswidth;   external mngdll;
+function mng_get_maxcanvasheight;  external mngdll;
+
+function mng_get_starttime;        external mngdll;
+function mng_get_runtime;          external mngdll;
+function mng_get_currentframe;     external mngdll;
+function mng_get_currentlayer;     external mngdll;
+function mng_get_currentplaytime;  external mngdll;
+
+function mng_status_error;         external mngdll;
+function mng_status_reading;       external mngdll;
+function mng_status_suspendbreak;  external mngdll;
+
+function mng_status_creating;      external mngdll;
+function mng_status_writing;       external mngdll;
+function mng_status_displaying;    external mngdll;
+function mng_status_running;       external mngdll;
+function mng_status_timerbreak;    external mngdll;
+function mng_status_dynamic;       external mngdll;
+
+{****************************************************************************}
+
+function mng_putchunk_ihdr;        external mngdll;
+function mng_putchunk_plte;        external mngdll;
+function mng_putchunk_idat;        external mngdll;
+function mng_putchunk_iend;        external mngdll;
+function mng_putchunk_trns;        external mngdll;
+function mng_putchunk_gama;        external mngdll;
+function mng_putchunk_chrm;        external mngdll;
+function mng_putchunk_srgb;        external mngdll;
+function mng_putchunk_iccp;        external mngdll;
+function mng_putchunk_text;        external mngdll;
+function mng_putchunk_ztxt;        external mngdll;
+function mng_putchunk_itxt;        external mngdll;
+function mng_putchunk_bkgd;        external mngdll;
+function mng_putchunk_phys;        external mngdll;
+function mng_putchunk_sbit;        external mngdll;
+function mng_putchunk_splt;        external mngdll;
+function mng_putchunk_hist;        external mngdll;
+function mng_putchunk_time;        external mngdll;
+
+function mng_putchunk_jhdr;        external mngdll;
+function mng_putchunk_jdat;        external mngdll;
+function mng_putchunk_jsep;        external mngdll;
+
+
+{$ELSE}        // IFNDEF LATE_BINDING
+
+
+{****************************************************************************}
+{ Do the Late Binding Thing instead }
+
+procedure MNGFailed;
+begin
+  if (hLibmng <> 0) then
+    raise ENGFuncUnknown.Create(SCFuncUnknown)
+  else
+    raise ENGDLLNotLoaded.Create(SCDLLNotLoaded);
+end;
+
+{****************************************************************************}
+{$WARNINGS OFF}                        // prevent meaningless warnings here
+
+function mng_version_text: mng_pchar;
+begin
+  if not assigned(aMNGFuncs[lmf_version_text].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_version_text].fPtr.f_version_text;
+end;
+
+function mng_version_so: mng_uint8;
+begin
+  if not assigned(aMNGFuncs[lmf_version_so].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_version_so].fPtr.f_version_so;
+end;
+
+function mng_version_dll: mng_uint8;
+begin
+  if not assigned(aMNGFuncs[lmf_version_dll].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_version_dll].fPtr.f_version_dll;
+end;
+
+function mng_version_major: mng_uint8;
+begin
+  if not assigned(aMNGFuncs[lmf_version_major].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_version_major].fPtr.f_version_major;
+end;
+
+function mng_version_minor: mng_uint8;
+begin
+  if not assigned(aMNGFuncs[lmf_version_minor].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_version_minor].fPtr.f_version_minor;
+end;
+
+function mng_version_release: mng_uint8;
+begin
+  if not assigned(aMNGFuncs[lmf_version_release].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_version_release].fPtr.f_version_release;
+end;
+
+function mng_version_beta: mng_bool;
+begin
+  if not assigned(aMNGFuncs[lmf_version_beta].fPtr.f_Ptr) then
+    Result:= MNG_FALSE
+  else
+    Result:= aMNGFuncs[lmf_version_beta].fPtr.f_version_beta;
+end;
+
+{****************************************************************************}
+
+function mng_supports_func;            { available since libmng-1.0.5 }
+begin
+  if not assigned(aMNGFuncs[lmf_supports_func].fPtr.f_Ptr) then
+  begin
+    Result   := MNG_FALSE;
+    iMajor   := 0;
+    iMinor   := 0;
+    iRelease := 0;
+  end
+  else
+  begin
+    Result:= aMNGFuncs[lmf_supports_func].fPtr.f_supports_func(zFunction, iMajor,
+                                                               iMinor, iRelease);
+  end;
+end;
+
+{****************************************************************************}
+
+function mng_initialize;
+begin
+  if not assigned(aMNGFuncs[lmf_initialize].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_initialize].fPtr.f_initialize(pUserdata, fMemalloc,
+                                                         fMemfree, fTraceproc);
+end;
+
+function mng_reset;
+begin
+  if not assigned(aMNGFuncs[lmf_reset].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_reset].fPtr.f_reset(hHandle);
+end;
+
+function mng_cleanup;
+begin
+  if not assigned(aMNGFuncs[lmf_cleanup].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_cleanup].fPtr.f_cleanup(hHandle);
+end;
+
+function mng_read;
+begin
+  if not assigned(aMNGFuncs[lmf_read].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_read].fPtr.f_read(hHandle);
+end;
+
+function mng_write;
+begin
+  if not assigned(aMNGFuncs[lmf_write].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_write].fPtr.f_write(hHandle);
+end;
+
+function mng_create;
+begin
+  if not assigned(aMNGFuncs[lmf_create].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_create].fPtr.f_create(hHandle);
+end;
+
+function mng_readdisplay;
+begin
+  if not assigned(aMNGFuncs[lmf_readdisplay].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_readdisplay].fPtr.f_readdisplay(hHandle);
+end;
+
+function mng_display;
+begin
+  if not assigned(aMNGFuncs[lmf_display].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_display].fPtr.f_display(hHandle);
+end;
+
+function mng_display_resume;
+begin
+  if not assigned(aMNGFuncs[lmf_display_resume].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_display_resume].fPtr.f_display_resume(hHandle);
+end;
+
+function mng_display_freeze;
+begin
+  if not assigned(aMNGFuncs[lmf_display_freeze].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_display_freeze].fPtr.f_display_freeze(hHandle);
+end;
+
+function mng_display_reset;
+begin
+  if not assigned(aMNGFuncs[lmf_reset].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_display_reset].fPtr.f_reset(hHandle);
+end;
+
+function mng_trapevent;
+begin
+  if not assigned(aMNGFuncs[lmf_trapevent].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_trapevent].fPtr.f_trapevent(hHandle, iEventtype, iX, iY);
+end;
+
+function mng_getlasterror;
+begin
+  if not assigned(aMNGFuncs[lmf_getlasterror].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getlasterror].fPtr.f_getlasterror(hHandle, iSeverity,
+                                                             iChunkname, iChunkseq,
+                                                             iExtra1, iExtra2,
+                                                             zErrortext);
+end;
+
+{****************************************************************************}
+
+function mng_setcb_memalloc;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_memalloc].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_memalloc].fPtr.f_setcb_memalloc(hHandle, fProc);
+end;
+
+function mng_setcb_memfree;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_memfree].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_memfree].fPtr.f_setcb_memfree(hHandle, fProc);
+end;
+
+function mng_setcb_openstream;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_openstream].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_openstream].fPtr.f_setcb_openstream(hHandle, fProc);
+end;
+
+function mng_setcb_closestream;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_closestream].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_closestream].fPtr.f_setcb_closestream(hHandle, fProc);
+end;
+
+function mng_setcb_readdata;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_readdata].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_readdata].fPtr.f_setcb_readdata(hHandle, fProc);
+end;
+
+function mng_setcb_writedata;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_writedata].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_writedata].fPtr.f_setcb_writedata(hHandle, fProc);
+end;
+
+function mng_setcb_errorproc;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_errorproc].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_errorproc].fPtr.f_setcb_errorproc(hHandle, fProc);
+end;
+
+function mng_setcb_processheader;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_processheader].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_processheader].fPtr.f_setcb_processheader(hHandle, fProc);
+end;
+
+function mng_setcb_processtext;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_processtext].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_processtext].fPtr.f_setcb_processtext(hHandle, fProc);
+end;
+
+function mng_setcb_processsave;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_processsave].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_processsave].fPtr.f_setcb_processsave(hHandle, fProc);
+end;
+
+function mng_setcb_processseek;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_processseek].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_processseek].fPtr.f_setcb_processseek(hHandle, fProc);
+end;
+
+function mng_setcb_processmend;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_processmend].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_processmend].fPtr.f_setcb_processmend(hHandle, fProc);
+end;
+
+function mng_setcb_processneed;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_processneed].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_processneed].fPtr.f_setcb_processneed(hHandle, fProc);
+end;
+
+function mng_setcb_processunknown;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_processunknown].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_processunknown].fPtr.f_setcb_processunknown(hHandle, fProc);
+end;
+
+function mng_setcb_processterm;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_processterm].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_processterm].fPtr.f_setcb_processterm(hHandle, fProc);
+end;
+
+function mng_setcb_getcanvasline;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_getcanvasline].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_getcanvasline].fPtr.f_setcb_getcanvasline(hHandle, fProc);
+end;
+
+function mng_setcb_getalphaline;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_getalphaline].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_getalphaline].fPtr.f_setcb_getalphaline(hHandle, fProc);
+end;
+
+function mng_setcb_getbkgdline;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_getbkgdline].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_getbkgdline].fPtr.f_setcb_getbkgdline(hHandle, fProc);
+end;
+
+function mng_setcb_refresh;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_refresh].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_refresh].fPtr.f_setcb_refresh(hHandle, fProc);
+end;
+
+function mng_setcb_gettickcount;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_gettickcount].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_gettickcount].fPtr.f_setcb_gettickcount(hHandle, fProc);
+end;
+
+function mng_setcb_settimer;
+begin
+  if not assigned(aMNGFuncs[lmf_setcb_settimer].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_setcb_settimer].fPtr.f_setcb_settimer(hHandle, fProc);
+end;
+
+{****************************************************************************}
+
+function mng_getcb_memalloc;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_memalloc].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_memalloc].fPtr.f_getcb_memalloc(hHandle);
+end;
+
+function mng_getcb_memfree;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_memfree].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_memfree].fPtr.f_getcb_memfree(hHandle);
+end;
+
+function mng_getcb_openstream;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_openstream].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_openstream].fPtr.f_getcb_openstream(hHandle);
+end;
+
+function mng_getcb_closestream;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_closestream].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_closestream].fPtr.f_getcb_closestream(hHandle);
+end;
+
+function mng_getcb_readdata;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_readdata].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_readdata].fPtr.f_getcb_readdata(hHandle);
+end;
+
+function mng_getcb_writedata;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_writedata].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_writedata].fPtr.f_getcb_writedata(hHandle);
+end;
+
+function mng_getcb_errorproc;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_errorproc].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_errorproc].fPtr.f_getcb_errorproc(hHandle);
+end;
+
+function mng_getcb_processheader;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_processheader].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_processheader].fPtr.f_getcb_processheader(hHandle);
+end;
+
+function mng_getcb_processtext;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_processtext].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_processtext].fPtr.f_getcb_processtext(hHandle);
+end;
+
+function mng_getcb_processsave;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_processsave].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_processsave].fPtr.f_getcb_processsave(hHandle);
+end;
+
+function mng_getcb_processseek;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_processseek].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_processseek].fPtr.f_getcb_processseek(hHandle);
+end;
+
+function mng_getcb_processmend;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_processmend].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_processmend].fPtr.f_getcb_processmend(hHandle);
+end;
+
+function mng_getcb_processneed;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_processneed].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_processneed].fPtr.f_getcb_processneed(hHandle);
+end;
+
+function mng_getcb_processunknown;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_processunknown].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_processunknown].fPtr.f_getcb_processunknown(hHandle);
+end;
+
+function mng_getcb_processterm;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_processterm].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_processterm].fPtr.f_getcb_processterm(hHandle);
+end;
+
+function mng_getcb_getcanvasline;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_getcanvasline].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_getcanvasline].fPtr.f_getcb_getcanvasline(hHandle);
+end;
+
+function mng_getcb_getalphaline;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_getalphaline].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_getalphaline].fPtr.f_getcb_getalphaline(hHandle);
+end;
+
+function mng_getcb_getbkgdline;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_getbkgdline].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_getbkgdline].fPtr.f_getcb_getbkgdline(hHandle);
+end;
+
+function mng_getcb_refresh;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_refresh].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_refresh].fPtr.f_getcb_refresh(hHandle);
+end;
+
+function mng_getcb_gettickcount;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_gettickcount].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_gettickcount].fPtr.f_getcb_gettickcount(hHandle);
+end;
+
+function mng_getcb_settimer;
+begin
+  if not assigned(aMNGFuncs[lmf_getcb_settimer].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_getcb_settimer].fPtr.f_getcb_settimer(hHandle);
+end;
+
+{****************************************************************************}
+
+function mng_set_userdata;
+begin
+  if not assigned(aMNGFuncs[lmf_set_userdata].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_userdata].fPtr.f_set_userdata(hHandle, pUserdata);
+end;
+
+function mng_set_canvasstyle;
+begin
+  if not assigned(aMNGFuncs[lmf_set_canvasstyle].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_canvasstyle].fPtr.f_set_canvasstyle(hHandle, iStyle);
+end;
+
+function mng_set_bkgdstyle;
+begin
+  if not assigned(aMNGFuncs[lmf_set_bkgdstyle].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_bkgdstyle].fPtr.f_set_bkgdstyle(hHandle, iStyle);
+end;
+
+function mng_set_bgcolor;
+begin
+  if not assigned(aMNGFuncs[lmf_set_bgcolor].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_bgcolor].fPtr.f_set_bgcolor(hHandle, iRed, iGreen, iBlue);
+end;
+
+function mng_set_usebkgd;
+begin
+  if not assigned(aMNGFuncs[lmf_set_usebkgd].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_usebkgd].fPtr.f_set_usebkgd(hHandle, bUseBKGD);
+end;
+
+function mng_set_storechunks;
+begin
+  if not assigned(aMNGFuncs[lmf_set_storechunks].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_storechunks].fPtr.f_set_storechunks(hHandle, bStorechunks);
+end;
+
+function mng_set_cacheplayback;
+begin
+  if not assigned(aMNGFuncs[lmf_set_cacheplayback].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_cacheplayback].fPtr.f_set_cacheplayback(hHandle, bCacheplayback);
+end;
+
+function mng_set_viewgammaint;
+begin
+  if not assigned(aMNGFuncs[lmf_set_viewgammaint].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_viewgammaint].fPtr.f_set_viewgammaint(hHandle, iGamma);
+end;
+
+function mng_set_displaygammaint;
+begin
+  if not assigned(aMNGFuncs[lmf_set_displaygammaint].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_displaygammaint].fPtr.f_set_displaygammaint(hHandle, iGamma);
+end;
+
+function mng_set_dfltimggammaint;
+begin
+  if not assigned(aMNGFuncs[lmf_set_dfltimggammaint].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_dfltimggammaint].fPtr.f_set_dfltimggammaint(hHandle, iGamma);
+end;
+
+function mng_set_srgb;
+begin
+  if not assigned(aMNGFuncs[lmf_set_srgb].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_srgb].fPtr.f_set_srgb(hHandle, bIssRGB);
+end;
+
+function mng_set_outputprofile;
+begin
+  if not assigned(aMNGFuncs[lmf_set_outputprofile].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_outputprofile].fPtr.f_set_outputprofile(hHandle, zFilename);
+end;
+
+function mng_set_outputprofile2;
+begin
+  if not assigned(aMNGFuncs[lmf_set_outputprofile2].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_outputprofile2].fPtr.f_set_outputprofile2(hHandle, iProfilesize, pProfile);
+end;
+
+function mng_set_outputsrgb;
+begin
+  if not assigned(aMNGFuncs[lmf_set_outputsrgb].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_outputsrgb].fPtr.f_set_outputsrgb(hHandle);
+end;
+
+function mng_set_srgbprofile;
+begin
+  if not assigned(aMNGFuncs[lmf_set_srgbprofile].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_srgbprofile].fPtr.f_set_srgbprofile(hHandle, zFilename);
+end;
+
+function mng_set_srgbprofile2;
+begin
+  if not assigned(aMNGFuncs[lmf_set_srgbprofile2].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_srgbprofile2].fPtr.f_set_srgbprofile2(hHandle, iProfilesize, pProfile);
+end;
+
+function mng_set_srgbimplicit;
+begin
+  if not assigned(aMNGFuncs[lmf_set_srgbimplicit].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_srgbimplicit].fPtr.f_set_srgbimplicit(hHandle);
+end;
+
+function mng_set_maxcanvassize;
+begin
+  if not assigned(aMNGFuncs[lmf_set_maxcanvassize].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_set_maxcanvassize].fPtr.f_set_maxcanvassize(hHandle, iMaxwidth, iMaxheight);
+end;
+
+{****************************************************************************}
+
+function mng_get_userdata;
+begin
+  if not assigned(aMNGFuncs[lmf_get_userdata].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_userdata].fPtr.f_get_userdata(hHandle);
+end;
+
+function mng_get_sigtype;
+begin
+  if not assigned(aMNGFuncs[lmf_get_sigtype].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_sigtype].fPtr.f_get_sigtype(hHandle);
+end;
+
+function mng_get_imagetype;
+begin
+  if not assigned(aMNGFuncs[lmf_get_imagetype].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_imagetype].fPtr.f_get_imagetype(hHandle);
+end;
+
+function mng_get_imagewidth;
+begin
+  if not assigned(aMNGFuncs[lmf_get_imagewidth].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_imagewidth].fPtr.f_get_imagewidth(hHandle);
+end;
+
+function mng_get_imageheight;
+begin
+  if not assigned(aMNGFuncs[lmf_get_imageheight].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_imageheight].fPtr.f_get_imageheight(hHandle);
+end;
+
+function mng_get_ticks;
+begin
+  if not assigned(aMNGFuncs[lmf_get_ticks].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_ticks].fPtr.f_get_ticks(hHandle);
+end;
+
+function mng_get_framecount;
+begin
+  if not assigned(aMNGFuncs[lmf_get_framecount].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_framecount].fPtr.f_get_framecount(hHandle);
+end;
+
+function mng_get_layercount;
+begin
+  if not assigned(aMNGFuncs[lmf_get_layercount].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_layercount].fPtr.f_get_layercount(hHandle);
+end;
+
+function mng_get_playtime;
+begin
+  if not assigned(aMNGFuncs[lmf_get_playtime].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_playtime].fPtr.f_get_playtime(hHandle);
+end;
+
+function mng_get_simplicity;
+begin
+  if not assigned(aMNGFuncs[lmf_get_simplicity].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_simplicity].fPtr.f_get_simplicity(hHandle);
+end;
+
+function mng_get_bitdepth;
+begin
+  if not assigned(aMNGFuncs[lmf_get_bitdepth].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_bitdepth].fPtr.f_get_bitdepth(hHandle);
+end;
+
+function mng_get_colortype;
+begin
+  if not assigned(aMNGFuncs[lmf_get_colortype].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_colortype].fPtr.f_get_colortype(hHandle);
+end;
+
+function mng_get_compression;
+begin
+  if not assigned(aMNGFuncs[lmf_get_compression].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_compression].fPtr.f_get_compression(hHandle);
+end;
+
+function mng_get_filter;
+begin
+  if not assigned(aMNGFuncs[lmf_get_filter].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_filter].fPtr.f_get_filter(hHandle);
+end;
+
+function mng_get_interlace;
+begin
+  if not assigned(aMNGFuncs[lmf_get_interlace].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_interlace].fPtr.f_get_interlace(hHandle);
+end;
+
+function mng_get_alphabitdepth;
+begin
+  if not assigned(aMNGFuncs[lmf_get_alphabitdepth].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_alphabitdepth].fPtr.f_get_alphabitdepth(hHandle);
+end;
+
+function mng_get_alphacompression;
+begin
+  if not assigned(aMNGFuncs[lmf_get_alphacompression].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_alphacompression].fPtr.f_get_alphacompression(hHandle);
+end;
+
+function mng_get_alphafilter;
+begin
+  if not assigned(aMNGFuncs[lmf_get_alphafilter].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_alphafilter].fPtr.f_get_alphafilter(hHandle);
+end;
+
+function mng_get_alphainterlace;
+begin
+  if not assigned(aMNGFuncs[lmf_get_alphainterlace].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_alphainterlace].fPtr.f_get_alphainterlace(hHandle);
+end;
+
+function mng_get_alphadepth;
+begin
+  if not assigned(aMNGFuncs[lmf_get_alphadepth].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_alphadepth].fPtr.f_get_alphadepth(hHandle);
+end;
+
+procedure mng_get_bgcolor;
+begin
+  if not assigned(aMNGFuncs[lmf_get_bgcolor].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    aMNGFuncs[lmf_get_bgcolor].fPtr.f_get_bgcolor(hHandle, iRed, iGreen, iBlue);
+end;
+
+function mng_get_usebkgd;
+begin
+  if not assigned(aMNGFuncs[lmf_get_usebkgd].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_usebkgd].fPtr.f_get_usebkgd(hHandle);
+end;
+
+function mng_get_viewgammaint;
+begin
+  if not assigned(aMNGFuncs[lmf_get_viewgammaint].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_viewgammaint].fPtr.f_get_viewgammaint(hHandle);
+end;
+
+function mng_get_displaygammaint;
+begin
+  if not assigned(aMNGFuncs[lmf_get_displaygammaint].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_displaygammaint].fPtr.f_get_displaygammaint(hHandle);
+end;
+
+function mng_get_dfltimggammaint;
+begin
+  if not assigned(aMNGFuncs[lmf_get_dfltimggammaint].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_dfltimggammaint].fPtr.f_get_dfltimggammaint(hHandle);
+end;
+
+function mng_get_srgb;
+begin
+  if not assigned(aMNGFuncs[lmf_get_srgb].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_srgb].fPtr.f_get_srgb(hHandle);
+end;
+
+function mng_get_maxcanvaswidth;
+begin
+  if not assigned(aMNGFuncs[lmf_get_maxcanvaswidth].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_maxcanvaswidth].fPtr.f_get_maxcanvaswidth(hHandle);
+end;
+
+function mng_get_maxcanvasheight;
+begin
+  if not assigned(aMNGFuncs[lmf_get_maxcanvasheight].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_maxcanvasheight].fPtr.f_get_maxcanvasheight(hHandle);
+end;
+
+function mng_get_starttime;
+begin
+  if not assigned(aMNGFuncs[lmf_get_starttime].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_starttime].fPtr.f_get_starttime(hHandle);
+end;
+
+function mng_get_runtime;
+begin
+  if not assigned(aMNGFuncs[lmf_get_runtime].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_runtime].fPtr.f_get_runtime(hHandle);
+end;
+
+function mng_get_currentframe;
+begin
+  if not assigned(aMNGFuncs[lmf_get_currentframe].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_currentframe].fPtr.f_get_currentframe(hHandle);
+end;
+
+function mng_get_currentlayer;
+begin
+  if not assigned(aMNGFuncs[lmf_get_currentlayer].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_currentlayer].fPtr.f_get_currentlayer(hHandle);
+end;
+
+function mng_get_currentplaytime;
+begin
+  if not assigned(aMNGFuncs[lmf_get_currentplaytime].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_get_currentplaytime].fPtr.f_get_currentplaytime(hHandle);
+end;
+
+function mng_status_error;
+begin
+  if not assigned(aMNGFuncs[lmf_status_error].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_status_error].fPtr.f_status_error(hHandle);
+end;
+
+function mng_status_reading;
+begin
+  if not assigned(aMNGFuncs[lmf_status_reading].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_status_reading].fPtr.f_status_reading(hHandle);
+end;
+
+function mng_status_suspendbreak;
+begin
+  if not assigned(aMNGFuncs[lmf_status_suspendbreak].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_status_suspendbreak].fPtr.f_status_suspendbreak(hHandle);
+end;
+
+function mng_status_creating;
+begin
+  if not assigned(aMNGFuncs[lmf_status_creating].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_status_creating].fPtr.f_status_creating(hHandle);
+end;
+
+function mng_status_writing;
+begin
+  if not assigned(aMNGFuncs[lmf_status_writing].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_status_writing].fPtr.f_status_writing(hHandle);
+end;
+
+function mng_status_displaying;
+begin
+  if not assigned(aMNGFuncs[lmf_status_displaying].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_status_displaying].fPtr.f_status_displaying(hHandle);
+end;
+
+function mng_status_running;
+begin
+  if not assigned(aMNGFuncs[lmf_status_running].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_status_running].fPtr.f_status_running(hHandle);
+end;
+
+function mng_status_timerbreak;
+begin
+  if not assigned(aMNGFuncs[lmf_status_timerbreak].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_status_timerbreak].fPtr.f_status_timerbreak(hHandle);
+end;
+
+function mng_status_dynamic;           { available since libmng-1.0.5 }
+begin
+  if not assigned(aMNGFuncs[lmf_status_dynamic].fPtr.f_Ptr) then
+    Result:= MNG_FALSE
+  else
+    Result:= aMNGFuncs[lmf_status_dynamic].fPtr.f_status_dynamic(hHandle);
+end;
+
+{****************************************************************************}
+
+function mng_putchunk_ihdr;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_ihdr].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_ihdr].fPtr.f_putchunk_ihdr(hHandle, iWidth, iHeight,
+                                                               iBitdepth, iColortype,
+                                                               iCompression, iFilter,
+                                                               iInterlace);
+end;
+
+function mng_putchunk_plte;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_plte].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_plte].fPtr.f_putchunk_plte(hHandle, iCount, aPalette);
+end;
+
+function mng_putchunk_idat;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_idat].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_idat].fPtr.f_putchunk_idat(hHandle, iRawlen, pRawdata);
+end;
+
+function mng_putchunk_iend;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_iend].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_iend].fPtr.f_putchunk_iend(hHandle);
+end;
+
+function mng_putchunk_trns;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_trns].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_trns].fPtr.f_putchunk_trns(hHandle, bEmpty, bGlobal,
+                                                               iType, iCount, aAlphas,
+                                                               iGray, iRed, iGreen, iBlue,
+                                                               iRawlen, aRawdata);
+end;
+
+function mng_putchunk_gama;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_gama].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_gama].fPtr.f_putchunk_gama(hHandle, bEmpty, iGamma);
+end;
+
+function mng_putchunk_chrm;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_chrm].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_chrm].fPtr.f_putchunk_chrm(hHandle, bEmpty,
+                                                               iWhitepointx, iWhitepointy,
+                                                               iRedx, iRedy,
+                                                               iGreenx, iGreeny,
+                                                               iBluex, iBluey);
+end;
+
+function mng_putchunk_srgb;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_srgb].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_srgb].fPtr.f_putchunk_srgb(hHandle, bEmpty, iRenderingintent);
+end;
+
+function mng_putchunk_iccp;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_iccp].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_iccp].fPtr.f_putchunk_iccp(hHandle, bEmpty,
+                                                               iNamesize, zName,
+                                                               iCompression,
+                                                               iProfilesize, pProfile);
+end;
+
+function mng_putchunk_text;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_text].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_text].fPtr.f_putchunk_text(hHandle, iKeywordsize,
+                                                               zKeyword, iTextsize, zText);
+end;
+
+function mng_putchunk_ztxt;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_ztxt].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_ztxt].fPtr.f_putchunk_ztxt(hHandle, iKeywordsize,
+                                                               zKeyword, iCompression,
+                                                               iTextsize, zText);
+end;
+
+function mng_putchunk_itxt;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_itxt].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_itxt].fPtr.f_putchunk_itxt(hHandle, iKeywordsize,
+                                                               zKeyword, iCompressionflag,
+                                                               iCompressionmethod,
+                                                               iLanguagesize, zLanguage,
+                                                               iTranslationsize, zTranslation,
+                                                               iTextsize, zText);
+end;
+
+function mng_putchunk_bkgd;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_bkgd].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_bkgd].fPtr.f_putchunk_bkgd(hHandle, bEmpty,
+                                                               iType, iIndex, iGray,
+                                                               iRed, iGray, iBlue);
+end;
+
+function mng_putchunk_phys;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_phys].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_phys].fPtr.f_putchunk_phys(hHandle, bEmpty,
+                                                               iSizex, iSizey, iUnit);
+end;
+
+function mng_putchunk_sbit;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_sbit].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_sbit].fPtr.f_putchunk_sbit(hHandle, bEmpty, iType, aBits);
+end;
+
+function mng_putchunk_splt;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_splt].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_splt].fPtr.f_putchunk_splt(hHandle, bEmpty, iNamesize, zName,
+                                                               iSampledepth, iEntrycount, pEntries);
+end;
+
+function mng_putchunk_hist;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_hist].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_hist].fPtr.f_putchunk_hist(hHandle, iEntrycount, aEntries);
+end;
+
+function mng_putchunk_time;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_time].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_time].fPtr.f_putchunk_time(hHandle, iYear, iMonth,
+                                                               iDay, iHour, iMinute, iSecond);
+end;
+
+function mng_putchunk_jhdr;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_jhdr].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_jhdr].fPtr.f_putchunk_jhdr(hHandle, iWidth, iHeight,
+                                                               iColortype, iImagesampledepth,
+                                                               iImagecompression, iImageinterlace,
+                                                               iAlphasampledepth, iAlphacompression,
+                                                               iAlphafilter, iAlphainterlace)
+end;
+
+function mng_putchunk_jdat;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_jdat].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_jdat].fPtr.f_putchunk_jdat(hHandle, iRawlen, pRawdata);
+end;
+
+function mng_putchunk_jsep;
+begin
+  if not assigned(aMNGFuncs[lmf_putchunk_jsep].fPtr.f_Ptr) then
+    MNGFailed
+  else
+    Result:= aMNGFuncs[lmf_putchunk_jsep].fPtr.f_putchunk_jsep(hHandle);
+end;
+
+{$WARNINGS ON}                         // turn them back on
+
+{$ENDIF} //IFNDEF LATE_BINDING
+
+
+{****************************************************************************}
+{* LIBMNG implementation definitions for ZLIB                               *}
+{****************************************************************************}
+
+{$IFDEF INCLUDE_ZLIB}
+
+{$IFNDEF LATE_BINDING}
+{****************************************************************************}
+
+function deflateInit_  (strm        : z_streamp;
+                        level       : integer;
+                        version     : pchar;
+                        stream_size : integer) : integer;
+  {$IFDEF LINUX} cdecl; external zdll; {$ELSE} stdcall; external mngdll; {$ENDIF}
+
+function inflateInit_  (strm        : z_streamp;
+                        version     : pchar;
+                        stream_size : integer) : integer;
+  {$IFDEF LINUX} cdecl; external zdll; {$ELSE} stdcall; external mngdll; {$ENDIF}
+
+function deflateInit2_ (strm        : z_streamp;
+                        level       : integer;
+                        method      : integer;
+                        windowBits  : integer;
+                        memLevel    : integer;
+                        strategy    : integer;
+                        version     : pchar;
+                        stream_size : integer) : integer;
+  {$IFDEF LINUX} cdecl; external zdll; {$ELSE} stdcall; external mngdll; {$ENDIF}
+
+function inflateInit2_ (strm        : z_streamp;
+                        windowBits  : integer;
+                        version     : pchar;
+                        stream_size : integer) : integer;
+  {$IFDEF LINUX} cdecl; external zdll; {$ELSE} stdcall; external mngdll; {$ENDIF}
+
+{****************************************************************************}
+
+{$IFDEF LINUX}
+function zlibVersion;          external zdll;
+function deflate;              external zdll;
+function deflateEnd;           external zdll;
+function inflate;              external zdll;
+function inflateEnd;           external zdll;
+function deflateSetDictionary; external zdll;
+function deflateCopy;          external zdll;
+function deflateReset;         external zdll;
+function deflateParams;        external zdll;
+function inflateSetDictionary; external zdll;
+function inflateSync;          external zdll;
+function inflateReset;         external zdll;
+function compress;             external zdll;
+function compress2;            external zdll;
+function uncompress;           external zdll;
+function adler32;              external zdll;
+function crc32;                external zdll;
+function zError;               external zdll;
+function inflateSyncPoint;     external zdll;
+function get_crc_table;        external zdll;
+{$ELSE}
+function zlibVersion;          external mngdll;
+function deflate;              external mngdll;
+function deflateEnd;           external mngdll;
+function inflate;              external mngdll;
+function inflateEnd;           external mngdll;
+function deflateSetDictionary; external mngdll;
+function deflateCopy;          external mngdll;
+function deflateReset;         external mngdll;
+function deflateParams;        external mngdll;
+function inflateSetDictionary; external mngdll;
+function inflateSync;          external mngdll;
+function inflateReset;         external mngdll;
+function compress;             external mngdll;
+function compress2;            external mngdll;
+function uncompress;           external mngdll;
+function adler32;              external mngdll;
+function crc32;                external mngdll;
+function zError;               external mngdll;
+function inflateSyncPoint;     external mngdll;
+function get_crc_table;        external mngdll;
+{$ENDIF}
+
+{****************************************************************************}
+
+{$ELSE} // LATE_BINDING
+
+{****************************************************************************}
+
+procedure ZFailed;
+begin
+{$IFDEF LINUX}
+  if (hLibz <> 0) then
+{$ELSE}
+  if (hLibmng <> 0) then
+{$ENDIF}
+    raise ENGFuncUnknown.Create(SCFuncUnknown)
+  else
+{$IFDEF LINUX}
+    raise ENGDLLNotLoaded.Create(SCDLLNotLoaded2);
+{$ELSE}
+    raise ENGDLLNotLoaded.Create(SCDLLNotLoaded);
+{$ENDIF}
+end;
+
+{****************************************************************************}
+{$WARNINGS OFF}
+
+function deflateInit_ (strm        : z_streamp;
+                       level       : integer;
+                       version     : pchar;
+                       stream_size : integer) : integer;
+begin
+  if not assigned(aZFuncs[zlf_deflateInit_].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_deflateInit_].fPtr.f_deflateInit_(strm, level, version, stream_size);
+end;
+
+function inflateInit_ (strm        : z_streamp;
+                       version     : pchar;
+                       stream_size : integer) : integer;
+begin
+  if not assigned(aZFuncs[zlf_inflateInit_].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_inflateInit_].fPtr.f_inflateInit_(strm, version, stream_size);
+end;
+
+function deflateInit2_ (strm        : z_streamp;
+                        level       : integer;
+                        method      : integer;
+                        windowBits  : integer;
+                        memLevel    : integer;
+                        strategy    : integer;
+                        version     : pchar;
+                        stream_size : integer) : integer;
+begin
+  if not assigned(aZFuncs[zlf_deflateInit2_].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_deflateInit2_].fPtr.f_deflateInit2_(strm, level, method, windowBits,
+                                                             memLevel, strategy, version, stream_size);
+end;
+
+function inflateInit2_ (strm        : z_streamp;
+                        windowBits  : integer;
+                        version     : pchar;
+                        stream_size : integer) : integer;
+begin
+  if not assigned(aZFuncs[zlf_inflateInit2_].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_inflateInit2_].fPtr.f_inflateInit2_(strm, windowBits, version, stream_size);
+end;
+
+{****************************************************************************}
+
+function zlibVersion;
+begin
+  if not assigned(aZFuncs[zlf_zLibVersion].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_zLibVersion].fPtr.f_zLibVersion;
+end;
+
+function deflate;
+begin
+  if not assigned(aZFuncs[zlf_deflate].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_deflate].fPtr.f_deflate(strm, flush);
+end;
+
+function deflateEnd;
+begin
+  if not assigned(aZFuncs[zlf_deflateEnd].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_deflateEnd].fPtr.f_deflateEnd(strm);
+end;
+
+function inflate;
+begin
+  if not assigned(aZFuncs[zlf_inflate].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_inflate].fPtr.f_inflate(strm, flush);
+end;
+
+function inflateEnd;
+begin
+  if not assigned(aZFuncs[zlf_inflateEnd].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_inflateEnd].fPtr.f_inflateEnd(strm);
+end;
+
+function deflateSetDictionary;
+begin
+  if not assigned(aZFuncs[zlf_deflateSetDictionary].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_deflateSetDictionary].fPtr.f_deflateSetDictionary(strm, dictionary, dictLength);
+end;
+
+function deflateCopy;
+begin
+  if not assigned(aZFuncs[zlf_deflateCopy].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_deflateCopy].fPtr.f_deflateCopy(dest, source);
+end;
+
+function deflateReset;
+begin
+  if not assigned(aZFuncs[zlf_deflateReset].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_deflateReset].fPtr.f_deflateReset(strm);
+end;
+
+function deflateParams;
+begin
+  if not assigned(aZFuncs[zlf_deflateParams].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_deflateParams].fPtr.f_deflateParams(strm, level, strategy);
+end;
+
+function inflateSetDictionary;
+begin
+  if not assigned(aZFuncs[zlf_inflateSetDictionary].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_inflateSetDictionary].fPtr.f_inflateSetDictionary(strm, dictionary, dictLength);
+end;
+
+function inflateSync;
+begin
+  if not assigned(aZFuncs[zlf_inflateSync].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_inflateSync].fPtr.f_inflateSync(strm);
+end;
+
+function inflateReset;
+begin
+  if not assigned(aZFuncs[zlf_inflateReset].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_inflateReset].fPtr.f_inflateReset(strm);
+end;
+
+function compress;
+begin
+  if not assigned(aZFuncs[zlf_compress].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_compress].fPtr.f_compress(dest, destLen, source, sourceLen);
+end;
+
+function compress2;
+begin
+  if not assigned(aZFuncs[zlf_compress2].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_compress2].fPtr.f_compress2(dest, destLen, source, sourceLen, level);
+end;
+
+function uncompress;
+begin
+  if not assigned(aZFuncs[zlf_uncompress].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_uncompress].fPtr.f_uncompress(dest, destLen, source, sourceLen);
+end;
+
+function adler32;
+begin
+  if not assigned(aZFuncs[zlf_adler32].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_adler32].fPtr.f_adler32(adler, buf, len);
+end;
+
+function crc32;
+begin
+  if not assigned(aZFuncs[zlf_crc32].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_crc32].fPtr.f_crc32(crc, buf, len);
+end;
+
+function zError;
+begin
+  if not assigned(aZFuncs[zlf_zError].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_zError].fPtr.f_zError(err);
+end;
+
+function inflateSyncPoint;
+begin
+  if not assigned(aZFuncs[zlf_inflateSyncPoint].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_inflateSyncPoint].fPtr.f_inflateSyncPoint(strm);
+end;
+
+function get_crc_table;
+begin
+  if not assigned(aZFuncs[zlf_get_crc_table].fPtr.f_Ptr) then
+    ZFailed
+  else
+    Result:= aZFuncs[zlf_get_crc_table].fPtr.f_get_crc_table;
+end;
+
+{$WARNINGS OFF}
+{****************************************************************************}
+{$ENDIF}  //ifndef LATE_BINDING
+
+function deflateInit;
+begin
+  Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream));
+end;
+
+{****************************************************************************}
+
+function inflateInit;
+begin
+  Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream));
+end;
+
+{****************************************************************************}
+
+function deflateInit2;
+begin
+  Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
+                          ZLIB_VERSION, sizeof(z_stream));
+end;
+
+{****************************************************************************}
+
+function inflateInit2;
+begin
+  Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream));
+end;
+
+{****************************************************************************}
+
+function InflateString(Input: string; var Output: string): integer;
+var
+  stream: z_stream;
+  buflen: integer;
+  bufinc: integer;
+  nextpos: integer;
+begin
+  BeginUseZLib;
+
+  try
+    fillchar(stream, sizeof(stream), 0);
+
+    buflen           := round(length(Input) * 1.5);
+    bufinc           := round(length(Input) * 0.5);
+    Output           := StringOfChar(#0, buflen);
+
+    stream.next_in   := @Input[1];
+    stream.avail_in  := length(Input);
+    stream.next_out  := @Output[1];
+    stream.avail_out := buflen;
+
+    stream.zalloc    := nil;
+    stream.zfree     := nil;
+    stream.opaque    := nil;
+
+    Result := inflateInit(@stream);
+
+    if (Result <> Z_OK) then
+      Exit;
+
+    repeat
+      Result := inflate(@stream, Z_SYNC_FLUSH);
+
+      if Result = Z_OK then
+      begin
+        nextpos          := length(Output) + 1;
+        Output           := Output + StringOfChar(#0, bufinc);
+        stream.next_out  := @Output[nextpos];
+        stream.avail_out := bufinc;
+      end;
+
+    until (Result <> Z_OK);
+
+    if Result = Z_STREAM_END then
+    begin
+      Output := copy(Output, 1, stream.total_out);
+      Result := inflateEnd(@stream);
+    end
+    else
+    begin
+      Output := '';                                        // do not localize
+      inflateEnd(@stream);
+    end;
+
+  finally
+    EndUseZLib;
+  end;
+end;
+
+{***************************************************************************}
+
+function InflateString2(Input: string; var Output: string;
+  windowBits: integer): integer;
+var
+  stream: z_stream;
+  buflen: integer;
+  bufinc: integer;
+  nextpos: integer;
+begin
+  BeginUseZLib;
+
+  try
+    fillchar(stream, sizeof(stream), 0);
+
+    buflen           := round(length(Input) * 1.5);
+    bufinc           := round(length(Input) * 0.5);
+    Output           := StringOfChar(#0, buflen);
+
+    stream.next_in   := @Input[1];
+    stream.avail_in  := length(Input);
+    stream.next_out  := @Output[1];
+    stream.avail_out := buflen;
+
+    stream.zalloc    := nil;
+    stream.zfree     := nil;
+    stream.opaque    := nil;
+
+    Result := inflateInit2(@stream, windowBits);
+
+    if (Result <> Z_OK) then
+      Exit;
+
+    repeat
+      Result := inflate(@stream, Z_SYNC_FLUSH);
+
+      if Result = Z_OK then
+      begin
+        nextpos          := length(Output) + 1;
+        Output           := Output + StringOfChar(#0, bufinc);
+        stream.next_out  := @Output[nextpos];
+        stream.avail_out := bufinc;
+      end;
+
+    until (Result <> Z_OK);
+
+    if Result = Z_STREAM_END then
+    begin
+      Output := copy(Output, 1, stream.total_out);
+      Result := inflateEnd(@stream);
+    end
+    else
+    begin
+      Output := '';                                        // do not localize
+      inflateEnd(@stream);
+    end;
+
+  finally
+    EndUseZLib;
+  end;
+end;
+
+{***************************************************************************}
+
+function DeflateString(Input: string; var Output: string): integer;
+var
+  stream: z_stream;
+  buflen: integer;
+  bufinc: integer;
+  nextpos: integer;
+begin
+  BeginUseZLib;
+
+  try
+    fillchar(stream, sizeof(stream), 0);
+
+    buflen           := round(length(Input) * 1.1) + 12;
+    bufinc           := round(length(Input) * 0.2) + 64;
+    Output           := StringOfChar(#0, buflen);
+
+    stream.next_in   := @Input[1];
+    stream.avail_in  := length(Input);
+    stream.next_out  := @Output[1];
+    stream.avail_out := buflen;
+
+    stream.zalloc    := nil;
+    stream.zfree     := nil;
+    stream.opaque    := nil;
+
+    Result := deflateInit(@stream, Z_DEFAULT_COMPRESSION);
+
+    if (Result <> Z_OK) then
+      Exit;
+
+    repeat
+      Result := deflate(@stream, Z_FINISH);
+
+      if Result = Z_OK then
+      begin
+        nextpos          := length(Output) + 1;
+        Output           := Output + StringOfChar(#0, bufinc);
+        stream.next_out  := @Output[nextpos];
+        stream.avail_out := bufinc;
+      end;
+
+    until (Result <> Z_OK);
+
+    if Result = Z_STREAM_END then
+    begin
+      Output := copy(Output, 1, stream.total_out);
+      Result := deflateEnd(@stream);
+    end
+    else
+    begin
+      Output := '';                                        // do not localize
+      deflateEnd(@stream);
+    end;
+
+  finally
+    EndUseZLib;
+  end;
+end;
+
+{***************************************************************************}
+
+function DeflateString2 (Input: string; var Output: string;
+  level: integer; method: integer; windowBits: integer;
+  memLevel: integer; strategy: integer): integer;
+var
+  stream : z_stream;
+  buflen: integer;
+  bufinc: integer;
+  nextpos: integer;
+begin
+  BeginUseZLib;
+
+  try
+    fillchar(stream, sizeof(stream), 0);
+
+    buflen           := round(length(Input) * 1.1) + 12;
+    bufinc           := round(length(Input) * 0.2) + 64;
+    Output           := StringOfChar(#0, buflen);
+
+    stream.next_in   := @Input[1];
+    stream.avail_in  := length(Input);
+    stream.next_out  := @Output[1];
+    stream.avail_out := buflen;
+
+    stream.zalloc    := nil;
+    stream.zfree     := nil;
+    stream.opaque    := nil;
+
+    Result := deflateInit2(@stream, level, method, windowBits, memLevel, strategy);
+
+    if (Result <> Z_OK) then
+      Exit;
+
+    repeat
+      Result := deflate(@stream, Z_FINISH);
+
+      if Result = Z_OK then
+      begin
+        nextpos          := length(Output) + 1;
+        Output           := Output + StringOfChar(#0, bufinc);
+        stream.next_out  := @Output[nextpos];
+        stream.avail_out := bufinc;
+      end;
+
+    until (Result <> Z_OK);
+
+    if Result = Z_STREAM_END then
+    begin
+      Output := copy(Output, 1, stream.total_out);
+      Result := deflateEnd(@stream);
+    end
+    else
+    begin
+      Output := '';                                        // do not localize
+      deflateEnd(@stream);
+    end;
+
+  finally
+    EndUseZLib;
+  end;
+end;
+
+{****************************************************************************}
+
+{$ENDIF} // INCLUDE_ZLIB
+
+{****************************************************************************}
+
+{$IFDEF LATE_BINDING}
+
+procedure BeginUseLibmng;
+var iX : TMNGFuncType;
+{$IFNDEF LINUX}
+    iY : TZFuncType;
+{$ENDIF}
+begin
+  inc(iMNGUse);
+
+  if (hLibmng = 0) then
+  begin
+     hLibmng:= LoadLibrary(mngdll);
+{$IFDEF LINUX}
+     if (hLibmng = 0) then
+{$ELSE}
+     if (hLibmng < HINSTANCE_ERROR) then
+{$ENDIF}
+     begin
+       hLibmng := 0;
+       Exit;
+     end;
+
+     for iX := lmf_version_text to lmf_putchunk_jsep do
+       aMNGFuncs[iX].fPtr.f_ptr := GetProcAddress(hLibmng, pchar(aMNGFuncs[iX].sName));
+
+{$IFNDEF LINUX}
+     for iY := zlf_deflateInit_ to zlf_get_crc_table do
+       aZFuncs[iY].fPtr.f_ptr := GetProcAddress(hLibmng, pchar(aZFuncs[iY].sName));
+{$ENDIF}
+
+  end;
+end;
+
+procedure EndUseLibmng;
+var iX : TMNGFuncType;
+{$IFNDEF LINUX}
+    iY : TZFuncType;
+{$ENDIF}
+begin
+  if iMNGUse > 0 then
+    dec(iMNGUse);
+
+  if iMNGUse <= 0 then
+  begin
+{$IFNDEF LINUX}
+     for iY := zlf_deflateInit_ to zlf_get_crc_table do
+       aZFuncs[iY].fPtr.f_ptr := nil;
+{$ENDIF}
+
+     for iX := lmf_version_text to lmf_putchunk_jsep do
+       aMNGFuncs[iX].fPtr.f_ptr := nil;
+
+     if hLibmng <> 0 then
+     begin
+       FreeLibrary(hLibmng);
+       hLibmng := 0;
+     end;
+  end;
+end;
+
+{$IFDEF INCLUDE_ZLIB}
+
+
+{$IFDEF LINUX}
+
+procedure BeginUseZLib;
+var iX : TZFuncType;
+begin
+  inc(iZLIBUse);
+
+  if (hLibz = 0) then
+  begin
+     hLibz:= LoadLibrary(zdll);
+     if (hLibz = 0) then
+       Exit;
+
+     for iX := zlf_deflateInit_ to zlf_get_crc_table do
+       aZFuncs[iX].fPtr.f_ptr := GetProcAddress(hLibz, pchar(aZFuncs[iX].sName));
+  end;
+end;
+
+procedure EndUseZLib;
+var iX : TZFuncType;
+begin
+  if iZLIBUse > 0 then
+    dec(iZLIBUse);
+
+  if iZLIBUse <= 0 then
+  begin
+     for iX := zlf_deflateInit_ to zlf_get_crc_table do
+       aZFuncs[iX].fPtr.f_ptr := nil;
+
+     if hLibz <> 0 then
+     begin
+       FreeLibrary(hLibz);
+       hLibz := 0;
+     end;
+  end;
+end;
+
+{$ELSE}  // LINUX
+
+procedure BeginUseZLib;
+begin
+  BeginUseLibmng;
+end;
+
+procedure EndUseZLib;
+begin
+  EndUseLibmng;
+end;
+
+{$ENDIF} // LINUX
+
+{$ENDIF} // INCLUDE_ZLIB
+
+{****************************************************************************}
+
+Initialization
+  hLibmng     := 0;
+  iMNGUse     := 0;
+{$IFDEF LINUX}
+  hLibz		  := 0;
+  iZLIBUse    := 0;
+{$ENDIF}
+
+{$ENDIF} // LATE_BINDING
+
+{****************************************************************************}
+
+end.
+

Added: branches/BCB5/TNGImage/Package/RegNG.pas
===================================================================
--- branches/BCB5/TNGImage/Package/RegNG.pas	                        (rev 0)
+++ branches/BCB5/TNGImage/Package/RegNG.pas	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,67 @@
+unit RegNG;
+
+{****************************************************************************}
+{*                                                                          *}
+{*  for copyright and version information see header in NGImages.pas        *}
+{*                                                                          *}
+{****************************************************************************}
+{*                                                                          *}
+{*  Changelog:                            * reverse chronological order *   *}
+{*                                                                          *}
+{*  * 0.9.3 *                                                               *}
+{*  Revision, Based on 0.9.2 Third beta                                     *}
+{*  2001/05/08 - Restructured for Maintainability                           *}
+{*             - Seperated into multiple units                              *}
+{*                                                                          *}
+{****************************************************************************}
+{*                                                                          *}
+{*  TODO:                                                                   *}
+{*                                                                          *}
+{****************************************************************************}
+
+interface
+
+
+{$INCLUDE NGDefs.inc}
+
+
+
+uses NGConst, NGTypes, NGImages {$IFDEF INCLUDE_JPEG}, NGJPEG {$ENDIF};
+
+
+procedure Register;
+
+
+
+implementation
+
+
+
+uses Graphics;
+
+
+procedure Register;
+begin
+  { Register the Types in the IDE }
+{$IFDEF INCLUDE_JPEG}
+  InitDefaults;
+{$IFDEF REGISTER_JPEG}
+  TPicture.RegisterFileFormat (SCJPEGExt1, SCJPEGImageFile, TJPEGImage);
+  TPicture.RegisterFileFormat (SCJPEGExt2, SCJPEGImageFile, TJPEGImage);
+  TPicture.RegisterFileFormat (SCJPEGExt3, SCJPEGImageFile, TJPEGImage);
+  TPicture.RegisterFileFormat (SCJPEGExt4, SCJPEGImageFile, TJPEGImage);
+{$ENDIF}
+{$ENDIF}
+{$IFDEF REGISTER_MNG}
+  TPicture.RegisterFileFormat (SCMNGExt, SCMNGImageFile, TMNGImage);
+{$ENDIF}
+{$IFDEF REGISTER_JNG}
+  TPicture.RegisterFileFormat (SCJNGExt, SCJNGImageFile, TJNGImage);
+{$ENDIF}
+{$IFDEF REGISTER_PNG}
+  TPicture.RegisterFileFormat (SCPNGExt, SCPNGImageFile, TPNGImage);
+{$ENDIF}
+end;
+
+end.
+

Added: branches/BCB5/TNGImage/TNGImage.bpk
===================================================================
--- branches/BCB5/TNGImage/TNGImage.bpk	                        (rev 0)
+++ branches/BCB5/TNGImage/TNGImage.bpk	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,108 @@
+<?xml version='1.0' encoding='utf-8' ?>
+<!-- C++Builder XML Project -->
+<PROJECT>
+  <MACROS>
+    <VERSION value="BCB.05.03"/>
+    <PROJECT value="TNGImage.bpl"/>
+    <OBJFILES value="Package\RegNG.obj TNGImage.obj"/>
+    <RESFILES value="TNGImage.res"/>
+    <IDLFILES value=""/>
+    <IDLGENFILES value=""/>
+    <DEFFILE value=""/>
+    <RESDEPEN value="$(RESFILES)"/>
+    <LIBFILES value=""/>
+    <LIBRARIES value=""/>
+    <SPARELIBS value="Vcl50.lib"/>
+    <PACKAGES value="vcl50.bpi"/>
+    <PATHCPP value=".;"/>
+    <PATHPAS value=".;Package"/>
+    <PATHRC value=".;"/>
+    <PATHASM value=".;"/>
+    <DEBUGLIBPATH value="$(BCB)\lib\debug"/>
+    <RELEASELIBPATH value="$(BCB)\lib\release"/>
+    <LINKER value="tlink32"/>
+    <USERDEFINES value=""/>
+    <SYSDEFINES value="_RTLDLL;NO_STRICT;USEPACKAGES"/>
+    <MAINSOURCE value="TNGImage.cpp"/>
+    <INCLUDEPATH value="Package;$(BCB)\include;$(BCB)\include\vcl"/>
+    <LIBPATH value="Package;$(BCB)\lib\obj;$(BCB)\lib"/>
+    <WARNINGS value="-w-par"/>
+  </MACROS>
+  <OPTIONS>
+    <IDLCFLAGS value="-IPackage -I$(BCB)\include -I$(BCB)\include\vcl -src_suffix cpp -boa"/>
+    <CFLAG1 value="-O2 -H=$(BCB)\lib\vcl50.csm -Hc -Vx -Ve -X- -a8 -b- -k- -vi -c -tWM"/>
+    <PFLAGS value="-$Y- -$L- -$D- -v -JPHNE -M"/>
+    <RFLAGS value=""/>
+    <AFLAGS value="/mx /w2 /zn"/>
+    <LFLAGS value="-D&quot;&quot; -aa -Tpp -x -Gn -Gl -Gi"/>
+  </OPTIONS>
+  <LINKER>
+    <ALLOBJ value="c0pkg32.obj $(PACKAGES) Memmgr.Lib sysinit.obj $(OBJFILES)"/>
+    <ALLRES value="$(RESFILES)"/>
+    <ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cp32mti.lib"/>
+  </LINKER>
+  <IDEOPTIONS>
+[Version Info]
+IncludeVerInfo=1
+AutoIncBuild=0
+MajorVer=1
+MinorVer=0
+Release=0
+Build=0
+Debug=0
+PreRelease=0
+Special=0
+Private=0
+DLL=0
+Locale=1033
+CodePage=1252
+
+[Version Info Keys]
+CompanyName=
+FileDescription=
+FileVersion=1.0.0.0
+InternalName=
+LegalCopyright=
+LegalTrademarks=
+OriginalFilename=
+ProductName=
+ProductVersion=1.0.0.0
+Comments=
+
+[HistoryLists\hlIncludePath]
+Count=1
+Item0=Package;$(BCB)\include;$(BCB)\include\vcl
+
+[HistoryLists\hlLibraryPath]
+Count=1
+Item0=Package;$(BCB)\lib\obj;$(BCB)\lib
+
+[HistoryLists\hlDebugSourcePath]
+Count=1
+Item0=$(BCB)\source\vcl
+
+[HistoryLists\hlConditionals]
+Count=1
+Item0=_DEBUG
+
+[Debugging]
+DebugSourceDirs=$(BCB)\source\vcl
+
+[Parameters]
+RunParams=
+HostApplication=
+RemoteHost=
+RemotePath=
+RemoteDebug=0
+
+[Compiler]
+ShowInfoMsgs=0
+LinkDebugVcl=0
+LinkCGLIB=0
+
+[Language]
+ActiveLang=
+ProjectLang=
+RootDir=
+  </IDEOPTIONS>
+</PROJECT>

Added: branches/BCB5/TNGImage/TNGImage.cpp
===================================================================
--- branches/BCB5/TNGImage/TNGImage.cpp	                        (rev 0)
+++ branches/BCB5/TNGImage/TNGImage.cpp	2009-02-28 04:09:35 UTC (rev 492)
@@ -0,0 +1,20 @@
+//---------------------------------------------------------------------------
+
+#include <vcl.h>
+#pragma hdrstop
+USERES("TNGImage.res");
+USEPACKAGE("vcl50.bpi");
+USEUNIT("Package\RegNG.pas");
+//---------------------------------------------------------------------------
+#pragma package(smart_init)
+//---------------------------------------------------------------------------
+
+//   Package source.
+//---------------------------------------------------------------------------
+
+#pragma argsused
+int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
+{
+	return 1;
+}
+//---------------------------------------------------------------------------

Added: branches/BCB5/TNGImage/TNGImage.res
===================================================================
(Binary files differ)


Property changes on: branches/BCB5/TNGImage/TNGImage.res
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: branches/BCB5/TNGImage/libmng.dll
===================================================================
(Binary files differ)


Property changes on: branches/BCB5/TNGImage/libmng.dll
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: branches/BCB5/TNGImage/libmng.png
===================================================================
(Binary files differ)


Property changes on: branches/BCB5/TNGImage/libmng.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: branches/BCB5/stage/libmng.dll
===================================================================
(Binary files differ)


Property changes on: branches/BCB5/stage/libmng.dll
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: branches/BCB5/sword.bpr
===================================================================
--- branches/BCB5/sword.bpr	2009-02-14 17:15:14 UTC (rev 491)
+++ branches/BCB5/sword.bpr	2009-02-28 04:09:35 UTC (rev 492)
@@ -18,7 +18,7 @@
       TntUnicodeControls.attic\TntClasses.obj 
       TntUnicodeControls.attic\TntControls.obj 
       TntUnicodeControls.attic\TntForms.obj 
-      TntUnicodeControls.attic\TntStdCtrls.obj"/>
+      TntUnicodeControls.attic\TntStdCtrls.obj TNGImage\TNGImage.obj"/>
     <RESFILES value="sword.res"/>
     <IDLFILES value=""/>
     <IDLGENFILES value=""/>
@@ -31,15 +31,15 @@
     <LIBFILES value="..\icu-sword\as_is\borland\icudatab.lib 
       ..\icu-sword\as_is\borland\icuuc.lib ..\icu-sword\as_is\borland\icuin.lib 
       ..\sword\lib\libsword.lib clucene\clucene.lib"/>
-    <LIBRARIES value="bcbie50.lib vcljpg50.lib nmfast50.lib vclbde50.lib vcldb50.lib vclx50.lib 
-      vcl50.lib"/>
+    <LIBRARIES value="TNGImage.lib bcbie50.lib vcljpg50.lib nmfast50.lib vclbde50.lib 
+      vcldb50.lib vclx50.lib vcl50.lib"/>
     <SPARELIBS value="vcl50.lib vclx50.lib vcldb50.lib vclbde50.lib nmfast50.lib vcljpg50.lib 
-      bcbie50.lib"/>
+      bcbie50.lib TNGImage.lib"/>
     <PACKAGES value="Vcl50.bpi Vclx50.bpi bcbsmp50.bpi Qrpt50.bpi Vcldb50.bpi Vclbde50.bpi 
       ibsmp50.bpi vcldbx50.bpi TeeUI50.bpi TeeDB50.bpi Tee50.bpi TeeQR50.bpi 
       VCLIB50.bpi bcbie50.bpi vclie50.bpi Inetdb50.bpi Inet50.bpi NMFast50.bpi 
       dclocx50.bpi bcb2kaxserver50.bpi"/>
-    <PATHCPP value=".;rxlib;TntUnicodeControls.attic"/>
+    <PATHCPP value=".;rxlib;TntUnicodeControls.attic;TNGImage"/>
     <PATHPAS value=".;"/>
     <PATHRC value=".;"/>
     <PATHASM value=".;"/>
@@ -49,7 +49,7 @@
     <USERDEFINES value="_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;_CL_DISABLE_MULTITHREADING"/>
     <SYSDEFINES value="NO_STRICT"/>
     <MAINSOURCE value="sword.cpp"/>
-    <INCLUDEPATH value="..\sword\src\modules\filters;TntUnicodeControls.attic;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib"/>
+    <INCLUDEPATH value="..\sword\src\modules\filters;TntUnicodeControls.attic;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib;TNGImage\Package"/>
     <LIBPATH value="..\sword\src\modules\filters;TntUnicodeControls.attic;..\sword\lib;$(BCB)\Projects\Lib;rxlib;$(BCB)\lib\release;$(BCB)\lib\obj;$(BCB)\lib"/>
     <WARNINGS value="-w-par -w-8027 -w-8026"/>
     <WARNOPTSTR value=""/>
@@ -57,9 +57,9 @@
   <OPTIONS>
     <IDLCFLAGS value="-I..\sword\src\modules\filters -ITntUnicodeControls.attic 
       -I..\icu-sword\source\common -I..\icu-sword\source\i18n -I..\sword\include 
-      -I$(BCB)\include -I$(BCB)\include\vcl -Irxlib -src_suffix cpp -D_ICU_ 
-      -D_ICUSWORD_ -DUSBINARY -DU_HAVE_PLACEMENT_NEW=0 -DUSELUCENE 
-      -D_CL_DISABLE_MULTITHREADING"/>
+      -I$(BCB)\include -I$(BCB)\include\vcl -Irxlib -ITNGImage\Package 
+      -src_suffix cpp -D_ICU_ -D_ICUSWORD_ -DUSBINARY -DU_HAVE_PLACEMENT_NEW=0 
+      -DUSELUCENE -D_CL_DISABLE_MULTITHREADING"/>
     <CFLAG1 value="-O2 -H=$(BCB)\lib\vcl50.csm -Hc -Vx -X- -a8 -4 -b- -k- -vi -c -tW -tWM"/>
     <PFLAGS value="-N2obj -N0obj -$Y- -$L- -$D- -v -M -JPHNE"/>
     <RFLAGS value=""/>
@@ -100,26 +100,27 @@
 Comments=Seek Him and you will find Him
 
 [HistoryLists\hlIncludePath]
-Count=19
-Item0=..\sword\src\modules\filters;TntUnicodeControls.attic;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item1=..\sword\src\modules\filters;D:\;TntUnicodeControls.attic;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item2=..\sword\src\modules\filters;D:\;TntUnicodeControls;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item3=D:\;TntUnicodeControls;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item4=D:\;..\..;TntUnicodeControls;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item5=D:\;..\..;TntUnicodeControls;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item6=..\..;TntUnicodeControls;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item7=..\..;TntUnicodeControls;..\..\..\WINDOZE;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item8=TntUnicodeControls;..\..;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item9=TntUnicodeControls;..\..\..\WINDOZE;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item10=..\..\..\..\..\TntUnicodeControls;..\..;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item11=..\..;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item12=..\..\..\windoze;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item13=..\..;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\windoze;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item14=..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item15=..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\windoze;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item16=..\..\..\..\..\icu-sword\source\common\;..\..\..\..\..\icu-sword\source\i18n\;..\..;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item17=C:\icu-sword\source\common\;C:\icu-sword\source\i18n\;..\..;C:\Program Files\Borland\CBuilder5\RX\Units\;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
-Item18=..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..;C:\Program Files\Borland\CBuilder5\RX\Units\;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Count=20
+Item0=..\sword\src\modules\filters;TntUnicodeControls.attic;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib;TNGImage\Package
+Item1=..\sword\src\modules\filters;TntUnicodeControls.attic;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item2=..\sword\src\modules\filters;D:\;TntUnicodeControls.attic;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item3=..\sword\src\modules\filters;D:\;TntUnicodeControls;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item4=D:\;TntUnicodeControls;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item5=D:\;..\..;TntUnicodeControls;..\icu-sword\source\common;..\icu-sword\source\i18n;..\sword\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item6=D:\;..\..;TntUnicodeControls;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item7=..\..;TntUnicodeControls;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item8=..\..;TntUnicodeControls;..\..\..\WINDOZE;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item9=TntUnicodeControls;..\..;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item10=TntUnicodeControls;..\..\..\WINDOZE;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item11=..\..\..\..\..\TntUnicodeControls;..\..;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item12=..\..;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item13=..\..\..\windoze;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item14=..\..;..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\windoze;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item15=..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item16=..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..\..\windoze;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item17=..\..\..\..\..\icu-sword\source\common\;..\..\..\..\..\icu-sword\source\i18n\;..\..;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item18=C:\icu-sword\source\common\;C:\icu-sword\source\i18n\;..\..;C:\Program Files\Borland\CBuilder5\RX\Units\;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
+Item19=..\..\..\..\..\icu-sword\source\common;..\..\..\..\..\icu-sword\source\i18n;..\..;C:\Program Files\Borland\CBuilder5\RX\Units\;..\..\..\..\include;$(BCB)\include;$(BCB)\include\vcl;rxlib
 
 [HistoryLists\hlLibraryPath]
 Count=16
@@ -197,4 +198,4 @@
 ProjectLang=
 RootDir=
   </IDEOPTIONS>
-</PROJECT>
+</PROJECT>
\ No newline at end of file

Modified: branches/BCB5/sword.cpp
===================================================================
--- branches/BCB5/sword.cpp	2009-02-14 17:15:14 UTC (rev 491)
+++ branches/BCB5/sword.cpp	2009-02-28 04:09:35 UTC (rev 492)
@@ -53,6 +53,7 @@
 USEOBJ("TntUnicodeControls.attic\TntControls.obj");
 USEOBJ("TntUnicodeControls.attic\TntForms.obj");
 USEOBJ("TntUnicodeControls.attic\TntStdCtrls.obj");
+USEOBJ("TNGImage\TNGImage.obj");
 //---------------------------------------------------------------------------
 AnsiString startVerse = "";
 

Modified: branches/BCB5/sword.res
===================================================================
(Binary files differ)

Modified: branches/BCB5/swordprj.bpg
===================================================================
--- branches/BCB5/swordprj.bpg	2009-02-14 17:15:14 UTC (rev 491)
+++ branches/BCB5/swordprj.bpg	2009-02-28 04:09:35 UTC (rev 492)
@@ -9,8 +9,8 @@
 DCC = $(ROOT)\bin\dcc32.exe $**
 BRCC = $(ROOT)\bin\brcc32.exe $**
 #------------------------------------------------------------------------------
-PROJECTS = icuuc.lib icuin.lib clucene.lib libsword.lib TntLibR.bpl sword.exe \
-  libcurl.lib InstallManager.exe
+PROJECTS = icuuc.lib icuin.lib clucene.lib libsword.lib TntLibR.bpl \
+  TNGImage.bpl sword.exe libcurl.lib InstallManager.exe
 #------------------------------------------------------------------------------
 default: sword
 #------------------------------------------------------------------------------
@@ -47,4 +47,8 @@
   $(ROOT)\bin\bpr2mak $**
   $(ROOT)\bin\make -$(MAKEFLAGS) -f$*.mak
 
+TNGImage.bpl: TNGImage\TNGImage.bpk
+  $(ROOT)\bin\bpr2mak $**
+  $(ROOT)\bin\make -$(MAKEFLAGS) -f$*.mak
 
+




More information about the sword-cvs mailing list