Commits

Christian Heimes  committed f316acd Merge

merge

  • Participants
  • Parent commits 90a30d3, 0be33fa

Comments (0)

Files changed (120)

-84de4f3ad04e7a28fc30a65df79bfdbef5d8d02e 3.15.3
+8c2ca1c88bc8ecde9defc6677f65548ad9aaec4e FINET_3-11-0_RC2_0-9
+cb6e7dcfc1ebf85f1d62dbb25b1d71bee02057cf FINET_3-10-0_RC1_0-8

File FreeImage.2008.vcproj

 				EnableIntrinsicFunctions="true"
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="true"
+				WholeProgramOptimization="true"
 				AdditionalIncludeDirectories="Source;Source\ZLib;Source\DeprecationManager;Source\OpenEXR\Half;Source\OpenEXR\Iex;Source\OpenEXR\IlmImf;Source\OpenEXR\Imath;Source\OpenEXR\IlmThread"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OPJ_STATIC;FREEIMAGE_EXPORTS;_CRT_SECURE_NO_DEPRECATE;LIBRAW_NODLL"
 				StringPooling="true"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				ProgramDatabaseFile=".\Release/FreeImage.pdb"
+				LinkTimeCodeGeneration="1"
 				RandomizedBaseAddress="1"
 				DataExecutionPrevention="0"
 				ImportLibrary=".\Release/FreeImage.lib"
 				EnableIntrinsicFunctions="true"
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="true"
+				WholeProgramOptimization="true"
 				AdditionalIncludeDirectories="Source;Source\ZLib;Source\DeprecationManager;Source\OpenEXR\Half;Source\OpenEXR\Iex;Source\OpenEXR\IlmImf;Source\OpenEXR\Imath;Source\OpenEXR\IlmThread"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OPJ_STATIC;FREEIMAGE_EXPORTS;_CRT_SECURE_NO_DEPRECATE;LIBRAW_NODLL"
 				StringPooling="true"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				ProgramDatabaseFile=".\Release/FreeImage.pdb"
+				LinkTimeCodeGeneration="1"
 				RandomizedBaseAddress="1"
 				DataExecutionPrevention="0"
 				ImportLibrary=".\Release/FreeImage.lib"

File Makefile.srcs

 VER_MAJOR = 3
 VER_MINOR = 15.4
 SRCS = ./Source/FreeImage/BitmapAccess.cpp ./Source/FreeImage/ColorLookup.cpp ./Source/FreeImage/FreeImage.cpp ./Source/FreeImage/FreeImageC.c ./Source/FreeImage/FreeImageIO.cpp ./Source/FreeImage/GetType.cpp ./Source/FreeImage/MemoryIO.cpp ./Source/FreeImage/PixelAccess.cpp ./Source/FreeImage/J2KHelper.cpp ././Source/FreeImage/MNGHelper.cpp ./Source/FreeImage/Plugin.cpp ./Source/FreeImage/PluginBMP.cpp ./Source/FreeImage/PluginCUT.cpp ./Source/FreeImage/PluginDDS.cpp ./Source/FreeImage/PluginEXR.cpp ./Source/FreeImage/PluginG3.cpp ./Source/FreeImage/PluginGIF.cpp ./Source/FreeImage/PluginHDR.cpp ./Source/FreeImage/PluginICO.cpp ./Source/FreeImage/PluginIFF.cpp ./Source/FreeImage/PluginJ2K.cpp ././Source/FreeImage/PluginJNG.cpp ./Source/FreeImage/PluginJP2.cpp ./Source/FreeImage/PluginJPEG.cpp ./Source/FreeImage/PluginKOALA.cpp ./Source/FreeImage/PluginMNG.cpp ./Source/FreeImage/PluginPCD.cpp ./Source/FreeImage/PluginPCX.cpp ./Source/FreeImage/PluginPFM.cpp ./Source/FreeImage/PluginPICT.cpp ./Source/FreeImage/PluginPNG.cpp ./Source/FreeImage/PluginPNM.cpp ./Source/FreeImage/PluginPSD.cpp ./Source/FreeImage/PluginRAS.cpp ./Source/FreeImage/PluginRAW.cpp ./Source/FreeImage/PluginSGI.cpp ./Source/FreeImage/PluginTARGA.cpp ./Source/FreeImage/PluginTIFF.cpp ./Source/FreeImage/PluginWBMP.cpp ./Source/FreeImage/PluginXBM.cpp ./Source/FreeImage/PluginXPM.cpp ./Source/FreeImage/PSDParser.cpp ./Source/FreeImage/TIFFLogLuv.cpp ./Source/FreeImage/Conversion.cpp ./Source/FreeImage/Conversion16_555.cpp ./Source/FreeImage/Conversion16_565.cpp ./Source/FreeImage/Conversion24.cpp ./Source/FreeImage/Conversion32.cpp ./Source/FreeImage/Conversion4.cpp ./Source/FreeImage/Conversion8.cpp ./Source/FreeImage/ConversionFloat.cpp ./Source/FreeImage/ConversionRGB16.cpp ./Source/FreeImage/ConversionRGBF.cpp ./Source/FreeImage/ConversionType.cpp ./Source/FreeImage/ConversionUINT16.cpp ./Source/FreeImage/Halftoning.cpp ./Source/FreeImage/tmoColorConvert.cpp ./Source/FreeImage/tmoDrago03.cpp ./Source/FreeImage/tmoFattal02.cpp ./Source/FreeImage/tmoReinhard05.cpp ./Source/FreeImage/ToneMapping.cpp ./Source/FreeImage/NNQuantizer.cpp ./Source/FreeImage/WuQuantizer.cpp ./Source/DeprecationManager/Deprecated.cpp ./Source/DeprecationManager/DeprecationMgr.cpp ./Source/FreeImage/CacheFile.cpp ./Source/FreeImage/MultiPage.cpp ./Source/FreeImage/ZLibInterface.cpp ./Source/Metadata/Exif.cpp ./Source/Metadata/FIRational.cpp ./Source/Metadata/FreeImageTag.cpp ./Source/Metadata/IPTC.cpp ./Source/Metadata/TagConversion.cpp ./Source/Metadata/TagLib.cpp ./Source/Metadata/XTIFF.cpp ./Source/FreeImageToolkit/Background.cpp ./Source/FreeImageToolkit/BSplineRotate.cpp ./Source/FreeImageToolkit/Channels.cpp ./Source/FreeImageToolkit/ClassicRotate.cpp ./Source/FreeImageToolkit/Colors.cpp ./Source/FreeImageToolkit/CopyPaste.cpp ./Source/FreeImageToolkit/Display.cpp ./Source/FreeImageToolkit/Flip.cpp ./Source/FreeImageToolkit/JPEGTransform.cpp ./Source/FreeImageToolkit/MultigridPoissonSolver.cpp ./Source/FreeImageToolkit/Rescale.cpp ./Source/FreeImageToolkit/Resize.cpp Source/LibJPEG/./jaricom.c Source/LibJPEG/jcapimin.c Source/LibJPEG/jcapistd.c Source/LibJPEG/./jcarith.c Source/LibJPEG/jccoefct.c Source/LibJPEG/jccolor.c Source/LibJPEG/jcdctmgr.c Source/LibJPEG/jchuff.c Source/LibJPEG/jcinit.c Source/LibJPEG/jcmainct.c Source/LibJPEG/jcmarker.c Source/LibJPEG/jcmaster.c Source/LibJPEG/jcomapi.c Source/LibJPEG/jcparam.c Source/LibJPEG/jcprepct.c Source/LibJPEG/jcsample.c Source/LibJPEG/jctrans.c Source/LibJPEG/jdapimin.c Source/LibJPEG/jdapistd.c Source/LibJPEG/./jdarith.c Source/LibJPEG/jdatadst.c Source/LibJPEG/jdatasrc.c Source/LibJPEG/jdcoefct.c Source/LibJPEG/jdcolor.c Source/LibJPEG/jddctmgr.c Source/LibJPEG/jdhuff.c Source/LibJPEG/jdinput.c Source/LibJPEG/jdmainct.c Source/LibJPEG/jdmarker.c Source/LibJPEG/jdmaster.c Source/LibJPEG/jdmerge.c Source/LibJPEG/jdpostct.c Source/LibJPEG/jdsample.c Source/LibJPEG/jdtrans.c Source/LibJPEG/jerror.c Source/LibJPEG/jfdctflt.c Source/LibJPEG/jfdctfst.c Source/LibJPEG/jfdctint.c Source/LibJPEG/jidctflt.c Source/LibJPEG/jidctfst.c Source/LibJPEG/jidctint.c Source/LibJPEG/jmemmgr.c Source/LibJPEG/jmemnobs.c Source/LibJPEG/jquant1.c Source/LibJPEG/jquant2.c Source/LibJPEG/jutils.c Source/LibJPEG/transupp.c Source/LibPNG/./png.c Source/LibPNG/./pngerror.c Source/LibPNG/./pngget.c Source/LibPNG/./pngmem.c Source/LibPNG/./pngpread.c Source/LibPNG/./pngread.c Source/LibPNG/./pngrio.c Source/LibPNG/./pngrtran.c Source/LibPNG/./pngrutil.c Source/LibPNG/./pngset.c Source/LibPNG/./pngtrans.c Source/LibPNG/./pngwio.c Source/LibPNG/./pngwrite.c Source/LibPNG/./pngwtran.c Source/LibPNG/./pngwutil.c Source/LibTIFF4/./tif_aux.c Source/LibTIFF4/./tif_close.c Source/LibTIFF4/./tif_codec.c Source/LibTIFF4/./tif_color.c Source/LibTIFF4/./tif_compress.c Source/LibTIFF4/./tif_dir.c Source/LibTIFF4/./tif_dirinfo.c Source/LibTIFF4/./tif_dirread.c Source/LibTIFF4/./tif_dirwrite.c Source/LibTIFF4/./tif_dumpmode.c Source/LibTIFF4/./tif_error.c Source/LibTIFF4/./tif_extension.c Source/LibTIFF4/./tif_fax3.c Source/LibTIFF4/./tif_fax3sm.c Source/LibTIFF4/./tif_flush.c Source/LibTIFF4/./tif_getimage.c Source/LibTIFF4/./tif_jpeg.c Source/LibTIFF4/./tif_luv.c Source/LibTIFF4/./tif_lzma.c Source/LibTIFF4/./tif_lzw.c Source/LibTIFF4/./tif_next.c Source/LibTIFF4/./tif_ojpeg.c Source/LibTIFF4/./tif_open.c Source/LibTIFF4/./tif_packbits.c Source/LibTIFF4/./tif_pixarlog.c Source/LibTIFF4/./tif_predict.c Source/LibTIFF4/./tif_print.c Source/LibTIFF4/./tif_read.c Source/LibTIFF4/./tif_strip.c Source/LibTIFF4/./tif_swab.c Source/LibTIFF4/./tif_thunder.c Source/LibTIFF4/./tif_tile.c Source/LibTIFF4/./tif_version.c Source/LibTIFF4/./tif_warning.c Source/LibTIFF4/./tif_write.c Source/LibTIFF4/./tif_zip.c Source/ZLib/./adler32.c Source/ZLib/./compress.c Source/ZLib/./crc32.c Source/ZLib/./deflate.c Source/ZLib/./gzclose.c Source/ZLib/./gzlib.c Source/ZLib/./gzread.c Source/ZLib/./gzwrite.c Source/ZLib/./infback.c Source/ZLib/./inffast.c Source/ZLib/./inflate.c Source/ZLib/./inftrees.c Source/ZLib/./trees.c Source/ZLib/./uncompr.c Source/ZLib/./zutil.c Source/LibOpenJPEG/bio.c Source/LibOpenJPEG/./cidx_manager.c Source/LibOpenJPEG/cio.c Source/LibOpenJPEG/dwt.c Source/LibOpenJPEG/event.c Source/LibOpenJPEG/image.c Source/LibOpenJPEG/j2k.c Source/LibOpenJPEG/j2k_lib.c Source/LibOpenJPEG/jp2.c Source/LibOpenJPEG/jpt.c Source/LibOpenJPEG/mct.c Source/LibOpenJPEG/mqc.c Source/LibOpenJPEG/openjpeg.c Source/LibOpenJPEG/./phix_manager.c Source/LibOpenJPEG/pi.c Source/LibOpenJPEG/./ppix_manager.c Source/LibOpenJPEG/raw.c Source/LibOpenJPEG/t1.c Source/LibOpenJPEG/t2.c Source/LibOpenJPEG/tcd.c Source/LibOpenJPEG/tgt.c Source/LibOpenJPEG/./thix_manager.c Source/LibOpenJPEG/./tpix_manager.c Source/OpenEXR/./IlmImf/ImfAttribute.cpp Source/OpenEXR/./IlmImf/ImfB44Compressor.cpp Source/OpenEXR/./IlmImf/ImfBoxAttribute.cpp Source/OpenEXR/./IlmImf/ImfChannelList.cpp Source/OpenEXR/./IlmImf/ImfChannelListAttribute.cpp Source/OpenEXR/./IlmImf/ImfChromaticities.cpp Source/OpenEXR/./IlmImf/ImfChromaticitiesAttribute.cpp Source/OpenEXR/./IlmImf/ImfCompressionAttribute.cpp Source/OpenEXR/./IlmImf/ImfCompressor.cpp Source/OpenEXR/./IlmImf/ImfConvert.cpp Source/OpenEXR/./IlmImf/ImfCRgbaFile.cpp Source/OpenEXR/./IlmImf/ImfDoubleAttribute.cpp Source/OpenEXR/./IlmImf/ImfEnvmap.cpp Source/OpenEXR/./IlmImf/ImfEnvmapAttribute.cpp Source/OpenEXR/./IlmImf/ImfFloatAttribute.cpp Source/OpenEXR/./IlmImf/ImfFrameBuffer.cpp Source/OpenEXR/./IlmImf/ImfFramesPerSecond.cpp Source/OpenEXR/./IlmImf/ImfHeader.cpp Source/OpenEXR/./IlmImf/ImfHuf.cpp Source/OpenEXR/./IlmImf/ImfInputFile.cpp Source/OpenEXR/./IlmImf/ImfIntAttribute.cpp Source/OpenEXR/./IlmImf/ImfIO.cpp Source/OpenEXR/./IlmImf/ImfKeyCode.cpp Source/OpenEXR/./IlmImf/ImfKeyCodeAttribute.cpp Source/OpenEXR/./IlmImf/ImfLineOrderAttribute.cpp Source/OpenEXR/./IlmImf/ImfLut.cpp Source/OpenEXR/./IlmImf/ImfMatrixAttribute.cpp Source/OpenEXR/./IlmImf/ImfMisc.cpp Source/OpenEXR/./IlmImf/ImfOpaqueAttribute.cpp Source/OpenEXR/./IlmImf/ImfOutputFile.cpp Source/OpenEXR/./IlmImf/ImfPizCompressor.cpp Source/OpenEXR/./IlmImf/ImfPreviewImage.cpp Source/OpenEXR/./IlmImf/ImfPreviewImageAttribute.cpp Source/OpenEXR/./IlmImf/ImfPxr24Compressor.cpp Source/OpenEXR/./IlmImf/ImfRational.cpp Source/OpenEXR/./IlmImf/ImfRationalAttribute.cpp Source/OpenEXR/./IlmImf/ImfRgbaFile.cpp Source/OpenEXR/./IlmImf/ImfRgbaYca.cpp Source/OpenEXR/./IlmImf/ImfRleCompressor.cpp Source/OpenEXR/./IlmImf/ImfScanLineInputFile.cpp Source/OpenEXR/./IlmImf/ImfStandardAttributes.cpp Source/OpenEXR/./IlmImf/ImfStdIO.cpp Source/OpenEXR/./IlmImf/ImfStringAttribute.cpp Source/OpenEXR/./IlmImf/ImfStringVectorAttribute.cpp Source/OpenEXR/./IlmImf/ImfTestFile.cpp Source/OpenEXR/./IlmImf/ImfThreading.cpp Source/OpenEXR/./IlmImf/ImfTileDescriptionAttribute.cpp Source/OpenEXR/./IlmImf/ImfTiledInputFile.cpp Source/OpenEXR/./IlmImf/ImfTiledMisc.cpp Source/OpenEXR/./IlmImf/ImfTiledOutputFile.cpp Source/OpenEXR/./IlmImf/ImfTiledRgbaFile.cpp Source/OpenEXR/./IlmImf/ImfTileOffsets.cpp Source/OpenEXR/./IlmImf/ImfTimeCode.cpp Source/OpenEXR/./IlmImf/ImfTimeCodeAttribute.cpp Source/OpenEXR/./IlmImf/ImfVecAttribute.cpp Source/OpenEXR/./IlmImf/ImfVersion.cpp Source/OpenEXR/./IlmImf/ImfWav.cpp Source/OpenEXR/./IlmImf/ImfZipCompressor.cpp Source/OpenEXR/./Imath/ImathBox.cpp Source/OpenEXR/./Imath/ImathColorAlgo.cpp Source/OpenEXR/./Imath/ImathFun.cpp Source/OpenEXR/./Imath/ImathMatrixAlgo.cpp Source/OpenEXR/./Imath/ImathRandom.cpp Source/OpenEXR/./Imath/ImathShear.cpp Source/OpenEXR/./Imath/ImathVec.cpp Source/OpenEXR/./Iex/IexBaseExc.cpp Source/OpenEXR/./Iex/IexThrowErrnoExc.cpp Source/OpenEXR/./Half/half.cpp Source/OpenEXR/./IlmThread/IlmThread.cpp Source/OpenEXR/./IlmThread/IlmThreadMutex.cpp Source/OpenEXR/./IlmThread/IlmThreadPool.cpp Source/OpenEXR/./IlmThread/IlmThreadSemaphore.cpp Source/LibRawLite/./internal/dcraw_common.cpp Source/LibRawLite/./internal/dcraw_fileio.cpp Source/LibRawLite/./internal/demosaic_packs.cpp Source/LibRawLite/./src/libraw_c_api.cpp Source/LibRawLite/./src/libraw_cxx.cpp Source/LibRawLite/./src/libraw_datastream.cpp 
-INCLS = ./Examples/OpenGL/TextureManager/TextureManager.h ./Examples/Plugin/PluginCradle.h ./Examples/Generic/FIIO_Mem.h ./Source/CacheFile.h ./Source/LibTIFF/tiffconf.vc.h ./Source/LibTIFF/tif_config.h ./Source/LibTIFF/tif_fax3.h ./Source/LibTIFF/tif_config.vc.h ./Source/LibTIFF/tiffvers.h ./Source/LibTIFF/tiffio.h ./Source/LibTIFF/tif_config.wince.h ./Source/LibTIFF/tiffconf.wince.h ./Source/LibTIFF/tiff.h ./Source/LibTIFF/uvcode.h ./Source/LibTIFF/tif_dir.h ./Source/LibTIFF/t4.h ./Source/LibTIFF/tif_predict.h ./Source/LibTIFF/tiffiop.h ./Source/LibJPEG/cderror.h ./Source/LibJPEG/jmorecfg.h ./Source/LibJPEG/transupp.h ./Source/LibJPEG/jpeglib.h ./Source/LibJPEG/jversion.h ./Source/LibJPEG/jinclude.h ./Source/LibJPEG/jerror.h ./Source/LibJPEG/jconfig.h ./Source/LibJPEG/jdct.h ./Source/LibJPEG/cdjpeg.h ./Source/LibJPEG/jmemsys.h ./Source/LibJPEG/jpegint.h ./Source/Plugin.h ./Source/Metadata/FreeImageTag.h ./Source/Metadata/FIRational.h ./Source/ToneMapping.h ./Source/LibTIFF4/tiffconf.vc.h ./Source/LibTIFF4/tif_config.h ./Source/LibTIFF4/tif_fax3.h ./Source/LibTIFF4/tif_config.vc.h ./Source/LibTIFF4/tiffvers.h ./Source/LibTIFF4/tiffio.h ./Source/LibTIFF4/tif_config.wince.h ./Source/LibTIFF4/tiffconf.wince.h ./Source/LibTIFF4/tiff.h ./Source/LibTIFF4/uvcode.h ./Source/LibTIFF4/tif_dir.h ./Source/LibTIFF4/t4.h ./Source/LibTIFF4/tif_predict.h ./Source/LibTIFF4/tiffiop.h ./Source/LibTIFF4/tiffconf.h ./Source/FreeImageIO.h ./Source/LibMNG/libmng_data.h ./Source/LibMNG/libmng_jpeg.h ./Source/LibMNG/libmng_conf.h ./Source/LibMNG/libmng.h ./Source/LibMNG/libmng_trace.h ./Source/LibMNG/libmng_zlib.h ./Source/LibMNG/libmng_read.h ./Source/LibMNG/libmng_chunk_io.h ./Source/LibMNG/libmng_filter.h ./Source/LibMNG/libmng_cms.h ./Source/LibMNG/libmng_chunks.h ./Source/LibMNG/libmng_write.h ./Source/LibMNG/libmng_error.h ./Source/LibMNG/libmng_types.h ./Source/LibMNG/libmng_objects.h ./Source/LibMNG/libmng_chunk_prc.h ./Source/LibMNG/libmng_chunk_descr.h ./Source/LibMNG/libmng_display.h ./Source/LibMNG/libmng_pixels.h ./Source/LibMNG/libmng_object_prc.h ./Source/LibMNG/libmng_memory.h ./Source/LibMNG/libmng_dither.h ./Source/FreeImage.h ./Source/FreeImage/PSDParser.h ./Source/ZLib/trees.h ./Source/ZLib/inffixed.h ./Source/ZLib/inflate.h ./Source/ZLib/zlib.h ./Source/ZLib/zconf.h ./Source/ZLib/inftrees.h ./Source/ZLib/zutil.h ./Source/ZLib/inffast.h ./Source/ZLib/crc32.h ./Source/ZLib/gzguts.h ./Source/ZLib/deflate.h ./Source/Quantizers.h ./Source/LibOpenJPEG/cio.h ./Source/LibOpenJPEG/mqc.h ./Source/LibOpenJPEG/cidx_manager.h ./Source/LibOpenJPEG/indexbox_manager.h ./Source/LibOpenJPEG/int.h ./Source/LibOpenJPEG/opj_config.h ./Source/LibOpenJPEG/event.h ./Source/LibOpenJPEG/pi.h ./Source/LibOpenJPEG/dwt.h ./Source/LibOpenJPEG/tgt.h ./Source/LibOpenJPEG/opj_malloc.h ./Source/LibOpenJPEG/raw.h ./Source/LibOpenJPEG/fix.h ./Source/LibOpenJPEG/jp2.h ./Source/LibOpenJPEG/bio.h ./Source/LibOpenJPEG/t2.h ./Source/LibOpenJPEG/mct.h ./Source/LibOpenJPEG/t1.h ./Source/LibOpenJPEG/t1_luts.h ./Source/LibOpenJPEG/j2k.h ./Source/LibOpenJPEG/j2k_lib.h ./Source/LibOpenJPEG/jpt.h ./Source/LibOpenJPEG/opj_includes.h ./Source/LibOpenJPEG/image.h ./Source/LibOpenJPEG/openjpeg.h ./Source/LibOpenJPEG/tcd.h ./Source/LibRawLite/libraw/libraw_version.h ./Source/LibRawLite/libraw/libraw_const.h ./Source/LibRawLite/libraw/libraw.h ./Source/LibRawLite/libraw/libraw_types.h ./Source/LibRawLite/libraw/libraw_alloc.h ./Source/LibRawLite/libraw/libraw_datastream.h ./Source/LibRawLite/libraw/libraw_internal.h ./Source/LibRawLite/internal/var_defines.h ./Source/LibRawLite/internal/defines.h ./Source/LibRawLite/internal/libraw_bytebuffer.h ./Source/LibRawLite/internal/libraw_internal_funcs.h ./Source/LibPNG/png.h ./Source/LibPNG/pngdebug.h ./Source/LibPNG/pnginfo.h ./Source/LibPNG/pnglibconf.h ./Source/LibPNG/pngstruct.h ./Source/LibPNG/pngpriv.h ./Source/LibPNG/pngconf.h ./Source/Utilities.h ./Source/FreeImageToolkit/Resize.h ./Source/FreeImageToolkit/Filters.h ./Source/OpenEXR/OpenEXRConfig.h ./Source/OpenEXR/IlmThread/IlmThread.h ./Source/OpenEXR/IlmThread/IlmThreadMutex.h ./Source/OpenEXR/IlmThread/IlmThreadSemaphore.h ./Source/OpenEXR/IlmThread/IlmThreadPool.h ./Source/OpenEXR/Iex/IexErrnoExc.h ./Source/OpenEXR/Iex/IexMacros.h ./Source/OpenEXR/Iex/IexThrowErrnoExc.h ./Source/OpenEXR/Iex/IexMathExc.h ./Source/OpenEXR/Iex/IexBaseExc.h ./Source/OpenEXR/Iex/Iex.h ./Source/OpenEXR/Imath/ImathColorAlgo.h ./Source/OpenEXR/Imath/ImathVec.h ./Source/OpenEXR/Imath/ImathGL.h ./Source/OpenEXR/Imath/ImathSphere.h ./Source/OpenEXR/Imath/ImathEuler.h ./Source/OpenEXR/Imath/ImathLimits.h ./Source/OpenEXR/Imath/ImathQuat.h ./Source/OpenEXR/Imath/ImathRoots.h ./Source/OpenEXR/Imath/ImathFun.h ./Source/OpenEXR/Imath/ImathShear.h ./Source/OpenEXR/Imath/ImathPlane.h ./Source/OpenEXR/Imath/ImathHalfLimits.h ./Source/OpenEXR/Imath/ImathMatrixAlgo.h ./Source/OpenEXR/Imath/ImathVecAlgo.h ./Source/OpenEXR/Imath/ImathInterval.h ./Source/OpenEXR/Imath/ImathBox.h ./Source/OpenEXR/Imath/ImathFrame.h ./Source/OpenEXR/Imath/ImathColor.h ./Source/OpenEXR/Imath/ImathMath.h ./Source/OpenEXR/Imath/ImathLine.h ./Source/OpenEXR/Imath/ImathBoxAlgo.h ./Source/OpenEXR/Imath/ImathFrustum.h ./Source/OpenEXR/Imath/ImathExc.h ./Source/OpenEXR/Imath/ImathLineAlgo.h ./Source/OpenEXR/Imath/ImathRandom.h ./Source/OpenEXR/Imath/ImathInt64.h ./Source/OpenEXR/Imath/ImathGLU.h ./Source/OpenEXR/Imath/ImathPlatform.h ./Source/OpenEXR/Imath/ImathMatrix.h ./Source/OpenEXR/IlmImf/ImfIO.h ./Source/OpenEXR/IlmImf/ImfStdIO.h ./Source/OpenEXR/IlmImf/ImfPreviewImage.h ./Source/OpenEXR/IlmImf/ImfAttribute.h ./Source/OpenEXR/IlmImf/ImfChannelList.h ./Source/OpenEXR/IlmImf/ImfInt64.h ./Source/OpenEXR/IlmImf/ImfHuf.h ./Source/OpenEXR/IlmImf/b44ExpLogTable.h ./Source/OpenEXR/IlmImf/ImfTileDescriptionAttribute.h ./Source/OpenEXR/IlmImf/ImfAcesFile.h ./Source/OpenEXR/IlmImf/ImfRgbaYca.h ./Source/OpenEXR/IlmImf/ImfThreading.h ./Source/OpenEXR/IlmImf/ImfWav.h ./Source/OpenEXR/IlmImf/ImfChromaticitiesAttribute.h ./Source/OpenEXR/IlmImf/ImfMatrixAttribute.h ./Source/OpenEXR/IlmImf/ImfTimeCodeAttribute.h ./Source/OpenEXR/IlmImf/ImfInputFile.h ./Source/OpenEXR/IlmImf/ImfFloatAttribute.h ./Source/OpenEXR/IlmImf/ImfPxr24Compressor.h ./Source/OpenEXR/IlmImf/ImfCompressor.h ./Source/OpenEXR/IlmImf/ImfCRgbaFile.h ./Source/OpenEXR/IlmImf/ImfOutputFile.h ./Source/OpenEXR/IlmImf/ImfRationalAttribute.h ./Source/OpenEXR/IlmImf/ImfTileOffsets.h ./Source/OpenEXR/IlmImf/ImfIntAttribute.h ./Source/OpenEXR/IlmImf/ImfTiledInputFile.h ./Source/OpenEXR/IlmImf/ImfStringAttribute.h ./Source/OpenEXR/IlmImf/ImfRleCompressor.h ./Source/OpenEXR/IlmImf/ImfChromaticities.h ./Source/OpenEXR/IlmImf/ImfTestFile.h ./Source/OpenEXR/IlmImf/ImfXdr.h ./Source/OpenEXR/IlmImf/ImfRgba.h ./Source/OpenEXR/IlmImf/ImfLineOrder.h ./Source/OpenEXR/IlmImf/ImfCompression.h ./Source/OpenEXR/IlmImf/ImfTiledMisc.h ./Source/OpenEXR/IlmImf/ImfFramesPerSecond.h ./Source/OpenEXR/IlmImf/ImfZipCompressor.h ./Source/OpenEXR/IlmImf/ImfKeyCodeAttribute.h ./Source/OpenEXR/IlmImf/ImfRational.h ./Source/OpenEXR/IlmImf/ImfChannelListAttribute.h ./Source/OpenEXR/IlmImf/ImfPreviewImageAttribute.h ./Source/OpenEXR/IlmImf/ImfFrameBuffer.h ./Source/OpenEXR/IlmImf/ImfOpaqueAttribute.h ./Source/OpenEXR/IlmImf/ImfEnvmapAttribute.h ./Source/OpenEXR/IlmImf/ImfPizCompressor.h ./Source/OpenEXR/IlmImf/ImfStringVectorAttribute.h ./Source/OpenEXR/IlmImf/ImfMultiView.h ./Source/OpenEXR/IlmImf/ImfAutoArray.h ./Source/OpenEXR/IlmImf/ImfLut.h ./Source/OpenEXR/IlmImf/ImfTiledOutputFile.h ./Source/OpenEXR/IlmImf/ImfBoxAttribute.h ./Source/OpenEXR/IlmImf/ImfCheckedArithmetic.h ./Source/OpenEXR/IlmImf/ImfB44Compressor.h ./Source/OpenEXR/IlmImf/ImfRgbaFile.h ./Source/OpenEXR/IlmImf/ImfTimeCode.h ./Source/OpenEXR/IlmImf/ImfVecAttribute.h ./Source/OpenEXR/IlmImf/ImfConvert.h ./Source/OpenEXR/IlmImf/ImfMisc.h ./Source/OpenEXR/IlmImf/ImfHeader.h ./Source/OpenEXR/IlmImf/ImfKeyCode.h ./Source/OpenEXR/IlmImf/ImfVersion.h ./Source/OpenEXR/IlmImf/ImfStandardAttributes.h ./Source/OpenEXR/IlmImf/ImfPixelType.h ./Source/OpenEXR/IlmImf/ImfName.h ./Source/OpenEXR/IlmImf/ImfArray.h ./Source/OpenEXR/IlmImf/ImfTiledRgbaFile.h ./Source/OpenEXR/IlmImf/ImfScanLineInputFile.h ./Source/OpenEXR/IlmImf/ImfDoubleAttribute.h ./Source/OpenEXR/IlmImf/ImfEnvmap.h ./Source/OpenEXR/IlmImf/ImfLineOrderAttribute.h ./Source/OpenEXR/IlmImf/ImfTileDescription.h ./Source/OpenEXR/IlmImf/ImfCompressionAttribute.h ./Source/OpenEXR/IlmBaseConfig.h ./Source/OpenEXR/Half/halfFunction.h ./Source/OpenEXR/Half/half.h ./Source/OpenEXR/Half/eLut.h ./Source/OpenEXR/Half/halfLimits.h ./Source/OpenEXR/Half/toFloat.h ./Source/DeprecationManager/DeprecationMgr.h ./Wrapper/FreeImage.NET/cpp/FreeImageIO/FreeImageIO.Net.h ./Wrapper/FreeImage.NET/cpp/FreeImageIO/Stdafx.h ./Wrapper/FreeImage.NET/cpp/FreeImageIO/resource.h ./Wrapper/FreeImagePlus/dist/FreeImagePlus.h ./Wrapper/FreeImagePlus/FreeImagePlus.h ./Wrapper/FreeImagePlus/test/fipTest.h ./TestAPI/TestSuite.h
+INCLS = ./Examples/OpenGL/TextureManager/TextureManager.h ./Examples/Plugin/PluginCradle.h ./Examples/Generic/FIIO_Mem.h ./Source/CacheFile.h ./Source/LibTIFF/tiffconf.vc.h ./Source/LibTIFF/tif_config.h ./Source/LibTIFF/tif_fax3.h ./Source/LibTIFF/tif_config.vc.h ./Source/LibTIFF/tiffvers.h ./Source/LibTIFF/tiffio.h ./Source/LibTIFF/tif_config.wince.h ./Source/LibTIFF/tiffconf.wince.h ./Source/LibTIFF/tiff.h ./Source/LibTIFF/uvcode.h ./Source/LibTIFF/tif_dir.h ./Source/LibTIFF/t4.h ./Source/LibTIFF/tif_predict.h ./Source/LibTIFF/tiffiop.h ./Source/LibJPEG/cderror.h ./Source/LibJPEG/jmorecfg.h ./Source/LibJPEG/transupp.h ./Source/LibJPEG/jpeglib.h ./Source/LibJPEG/jversion.h ./Source/LibJPEG/jinclude.h ./Source/LibJPEG/jerror.h ./Source/LibJPEG/jconfig.h ./Source/LibJPEG/jdct.h ./Source/LibJPEG/cdjpeg.h ./Source/LibJPEG/jmemsys.h ./Source/LibJPEG/jpegint.h ./Source/Plugin.h ./Source/Metadata/FreeImageTag.h ./Source/Metadata/FIRational.h ./Source/ToneMapping.h ./Source/LibTIFF4/tiffconf.vc.h ./Source/LibTIFF4/tif_config.h ./Source/LibTIFF4/tif_fax3.h ./Source/LibTIFF4/tif_config.vc.h ./Source/LibTIFF4/tiffvers.h ./Source/LibTIFF4/tiffio.h ./Source/LibTIFF4/tif_config.wince.h ./Source/LibTIFF4/tiffconf.wince.h ./Source/LibTIFF4/tiff.h ./Source/LibTIFF4/uvcode.h ./Source/LibTIFF4/tif_dir.h ./Source/LibTIFF4/t4.h ./Source/LibTIFF4/tif_predict.h ./Source/LibTIFF4/tiffiop.h ./Source/LibTIFF4/tiffconf.h ./Source/FreeImageIO.h ./Source/LibMNG/libmng_data.h ./Source/LibMNG/libmng_jpeg.h ./Source/LibMNG/libmng_conf.h ./Source/LibMNG/libmng.h ./Source/LibMNG/libmng_trace.h ./Source/LibMNG/libmng_zlib.h ./Source/LibMNG/libmng_read.h ./Source/LibMNG/libmng_chunk_io.h ./Source/LibMNG/libmng_filter.h ./Source/LibMNG/libmng_cms.h ./Source/LibMNG/libmng_chunks.h ./Source/LibMNG/libmng_write.h ./Source/LibMNG/libmng_error.h ./Source/LibMNG/libmng_types.h ./Source/LibMNG/libmng_objects.h ./Source/LibMNG/libmng_chunk_prc.h ./Source/LibMNG/libmng_chunk_descr.h ./Source/LibMNG/libmng_display.h ./Source/LibMNG/libmng_pixels.h ./Source/LibMNG/libmng_object_prc.h ./Source/LibMNG/libmng_memory.h ./Source/LibMNG/libmng_dither.h ./Source/FreeImage.h ./Source/FreeImage/PSDParser.h ./Source/ZLib/trees.h ./Source/ZLib/inffixed.h ./Source/ZLib/inflate.h ./Source/ZLib/zlib.h ./Source/ZLib/zconf.h ./Source/ZLib/inftrees.h ./Source/ZLib/zutil.h ./Source/ZLib/inffast.h ./Source/ZLib/crc32.h ./Source/ZLib/gzguts.h ./Source/ZLib/deflate.h ./Source/Quantizers.h ./Source/LibOpenJPEG/cio.h ./Source/LibOpenJPEG/mqc.h ./Source/LibOpenJPEG/cidx_manager.h ./Source/LibOpenJPEG/indexbox_manager.h ./Source/LibOpenJPEG/int.h ./Source/LibOpenJPEG/opj_config.h ./Source/LibOpenJPEG/event.h ./Source/LibOpenJPEG/pi.h ./Source/LibOpenJPEG/dwt.h ./Source/LibOpenJPEG/tgt.h ./Source/LibOpenJPEG/opj_malloc.h ./Source/LibOpenJPEG/raw.h ./Source/LibOpenJPEG/fix.h ./Source/LibOpenJPEG/jp2.h ./Source/LibOpenJPEG/bio.h ./Source/LibOpenJPEG/t2.h ./Source/LibOpenJPEG/mct.h ./Source/LibOpenJPEG/t1.h ./Source/LibOpenJPEG/t1_luts.h ./Source/LibOpenJPEG/j2k.h ./Source/LibOpenJPEG/j2k_lib.h ./Source/LibOpenJPEG/jpt.h ./Source/LibOpenJPEG/opj_includes.h ./Source/LibOpenJPEG/image.h ./Source/LibOpenJPEG/openjpeg.h ./Source/LibOpenJPEG/tcd.h ./Source/LibRawLite/libraw/libraw_version.h ./Source/LibRawLite/libraw/libraw_const.h ./Source/LibRawLite/libraw/libraw.h ./Source/LibRawLite/libraw/libraw_types.h ./Source/LibRawLite/libraw/libraw_alloc.h ./Source/LibRawLite/libraw/libraw_datastream.h ./Source/LibRawLite/libraw/libraw_internal.h ./Source/LibRawLite/internal/var_defines.h ./Source/LibRawLite/internal/defines.h ./Source/LibRawLite/internal/libraw_bytebuffer.h ./Source/LibRawLite/internal/libraw_internal_funcs.h ./Source/LibPNG/png.h ./Source/LibPNG/pngdebug.h ./Source/LibPNG/pnginfo.h ./Source/LibPNG/pnglibconf.h ./Source/LibPNG/pngstruct.h ./Source/LibPNG/pngpriv.h ./Source/LibPNG/pngconf.h ./Source/Utilities.h ./Source/FreeImageToolkit/Resize.h ./Source/FreeImageToolkit/Filters.h ./Source/OpenEXR/OpenEXRConfig.h ./Source/OpenEXR/IlmThread/IlmThread.h ./Source/OpenEXR/IlmThread/IlmThreadMutex.h ./Source/OpenEXR/IlmThread/IlmThreadSemaphore.h ./Source/OpenEXR/IlmThread/IlmThreadPool.h ./Source/OpenEXR/Iex/IexErrnoExc.h ./Source/OpenEXR/Iex/IexMacros.h ./Source/OpenEXR/Iex/IexThrowErrnoExc.h ./Source/OpenEXR/Iex/IexMathExc.h ./Source/OpenEXR/Iex/IexBaseExc.h ./Source/OpenEXR/Iex/Iex.h ./Source/OpenEXR/Imath/ImathColorAlgo.h ./Source/OpenEXR/Imath/ImathVec.h ./Source/OpenEXR/Imath/ImathGL.h ./Source/OpenEXR/Imath/ImathSphere.h ./Source/OpenEXR/Imath/ImathEuler.h ./Source/OpenEXR/Imath/ImathLimits.h ./Source/OpenEXR/Imath/ImathQuat.h ./Source/OpenEXR/Imath/ImathRoots.h ./Source/OpenEXR/Imath/ImathFun.h ./Source/OpenEXR/Imath/ImathShear.h ./Source/OpenEXR/Imath/ImathPlane.h ./Source/OpenEXR/Imath/ImathHalfLimits.h ./Source/OpenEXR/Imath/ImathFrustumTest.h ./Source/OpenEXR/Imath/ImathMatrixAlgo.h ./Source/OpenEXR/Imath/ImathVecAlgo.h ./Source/OpenEXR/Imath/ImathInterval.h ./Source/OpenEXR/Imath/ImathBox.h ./Source/OpenEXR/Imath/ImathFrame.h ./Source/OpenEXR/Imath/ImathColor.h ./Source/OpenEXR/Imath/ImathMath.h ./Source/OpenEXR/Imath/ImathLine.h ./Source/OpenEXR/Imath/ImathBoxAlgo.h ./Source/OpenEXR/Imath/ImathFrustum.h ./Source/OpenEXR/Imath/ImathExc.h ./Source/OpenEXR/Imath/ImathLineAlgo.h ./Source/OpenEXR/Imath/ImathRandom.h ./Source/OpenEXR/Imath/ImathInt64.h ./Source/OpenEXR/Imath/ImathGLU.h ./Source/OpenEXR/Imath/ImathPlatform.h ./Source/OpenEXR/Imath/ImathMatrix.h ./Source/OpenEXR/IlmImf/ImfIO.h ./Source/OpenEXR/IlmImf/ImfStdIO.h ./Source/OpenEXR/IlmImf/ImfPreviewImage.h ./Source/OpenEXR/IlmImf/ImfAttribute.h ./Source/OpenEXR/IlmImf/ImfChannelList.h ./Source/OpenEXR/IlmImf/ImfInt64.h ./Source/OpenEXR/IlmImf/ImfHuf.h ./Source/OpenEXR/IlmImf/b44ExpLogTable.h ./Source/OpenEXR/IlmImf/ImfTileDescriptionAttribute.h ./Source/OpenEXR/IlmImf/ImfAcesFile.h ./Source/OpenEXR/IlmImf/ImfRgbaYca.h ./Source/OpenEXR/IlmImf/ImfThreading.h ./Source/OpenEXR/IlmImf/ImfWav.h ./Source/OpenEXR/IlmImf/ImfChromaticitiesAttribute.h ./Source/OpenEXR/IlmImf/ImfMatrixAttribute.h ./Source/OpenEXR/IlmImf/ImfTimeCodeAttribute.h ./Source/OpenEXR/IlmImf/ImfInputFile.h ./Source/OpenEXR/IlmImf/ImfFloatAttribute.h ./Source/OpenEXR/IlmImf/ImfPxr24Compressor.h ./Source/OpenEXR/IlmImf/ImfCompressor.h ./Source/OpenEXR/IlmImf/ImfCRgbaFile.h ./Source/OpenEXR/IlmImf/ImfOutputFile.h ./Source/OpenEXR/IlmImf/ImfRationalAttribute.h ./Source/OpenEXR/IlmImf/ImfTileOffsets.h ./Source/OpenEXR/IlmImf/ImfIntAttribute.h ./Source/OpenEXR/IlmImf/ImfTiledInputFile.h ./Source/OpenEXR/IlmImf/ImfStringAttribute.h ./Source/OpenEXR/IlmImf/ImfRleCompressor.h ./Source/OpenEXR/IlmImf/ImfChromaticities.h ./Source/OpenEXR/IlmImf/ImfTestFile.h ./Source/OpenEXR/IlmImf/ImfXdr.h ./Source/OpenEXR/IlmImf/ImfRgba.h ./Source/OpenEXR/IlmImf/ImfLineOrder.h ./Source/OpenEXR/IlmImf/ImfCompression.h ./Source/OpenEXR/IlmImf/ImfTiledMisc.h ./Source/OpenEXR/IlmImf/ImfFramesPerSecond.h ./Source/OpenEXR/IlmImf/ImfZipCompressor.h ./Source/OpenEXR/IlmImf/ImfKeyCodeAttribute.h ./Source/OpenEXR/IlmImf/ImfRational.h ./Source/OpenEXR/IlmImf/ImfChannelListAttribute.h ./Source/OpenEXR/IlmImf/ImfPreviewImageAttribute.h ./Source/OpenEXR/IlmImf/ImfFrameBuffer.h ./Source/OpenEXR/IlmImf/ImfOpaqueAttribute.h ./Source/OpenEXR/IlmImf/ImfEnvmapAttribute.h ./Source/OpenEXR/IlmImf/ImfPizCompressor.h ./Source/OpenEXR/IlmImf/ImfStringVectorAttribute.h ./Source/OpenEXR/IlmImf/ImfMultiView.h ./Source/OpenEXR/IlmImf/ImfAutoArray.h ./Source/OpenEXR/IlmImf/ImfLut.h ./Source/OpenEXR/IlmImf/ImfTiledOutputFile.h ./Source/OpenEXR/IlmImf/ImfBoxAttribute.h ./Source/OpenEXR/IlmImf/ImfCheckedArithmetic.h ./Source/OpenEXR/IlmImf/ImfB44Compressor.h ./Source/OpenEXR/IlmImf/ImfRgbaFile.h ./Source/OpenEXR/IlmImf/ImfTimeCode.h ./Source/OpenEXR/IlmImf/ImfVecAttribute.h ./Source/OpenEXR/IlmImf/ImfConvert.h ./Source/OpenEXR/IlmImf/ImfMisc.h ./Source/OpenEXR/IlmImf/ImfHeader.h ./Source/OpenEXR/IlmImf/ImfKeyCode.h ./Source/OpenEXR/IlmImf/ImfVersion.h ./Source/OpenEXR/IlmImf/ImfStandardAttributes.h ./Source/OpenEXR/IlmImf/ImfPixelType.h ./Source/OpenEXR/IlmImf/ImfName.h ./Source/OpenEXR/IlmImf/ImfArray.h ./Source/OpenEXR/IlmImf/ImfTiledRgbaFile.h ./Source/OpenEXR/IlmImf/ImfScanLineInputFile.h ./Source/OpenEXR/IlmImf/ImfDoubleAttribute.h ./Source/OpenEXR/IlmImf/ImfEnvmap.h ./Source/OpenEXR/IlmImf/ImfLineOrderAttribute.h ./Source/OpenEXR/IlmImf/ImfTileDescription.h ./Source/OpenEXR/IlmImf/ImfCompressionAttribute.h ./Source/OpenEXR/IlmBaseConfig.h ./Source/OpenEXR/Half/halfFunction.h ./Source/OpenEXR/Half/half.h ./Source/OpenEXR/Half/eLut.h ./Source/OpenEXR/Half/halfLimits.h ./Source/OpenEXR/Half/toFloat.h ./Source/DeprecationManager/DeprecationMgr.h ./Wrapper/FreeImage.NET/cpp/FreeImageIO/FreeImageIO.Net.h ./Wrapper/FreeImage.NET/cpp/FreeImageIO/Stdafx.h ./Wrapper/FreeImage.NET/cpp/FreeImageIO/resource.h ./Wrapper/FreeImagePlus/FreeImagePlus.h ./Wrapper/FreeImagePlus/test/fipTest.h ./TestAPI/TestSuite.h
 
 INCLUDE = -I. -ISource -ISource/Metadata -ISource/FreeImageToolkit -ISource/LibJPEG -ISource/LibPNG -ISource/LibTIFF4 -ISource/ZLib -ISource/LibOpenJPEG -ISource/OpenEXR -ISource/OpenEXR/Half -ISource/OpenEXR/Iex -ISource/OpenEXR/IlmImf -ISource/OpenEXR/IlmThread -ISource/OpenEXR/Imath -ISource/LibRawLite -ISource/LibRawLite/dcraw -ISource/LibRawLite/internal -ISource/LibRawLite/libraw -ISource/LibRawLite/src

File Source/FreeImage.h

 typedef uint16_t WORD;
 typedef uint32_t DWORD;
 typedef int32_t LONG;
-typedef int64_t FIINT64;
-typedef uint64_t FIUINT64;
+typedef int64_t INT64;
+typedef uint64_t UINT64;
 #else
 // MS is not C99 ISO compliant
 typedef long BOOL;
 typedef unsigned short WORD;
 typedef unsigned long DWORD;
 typedef long LONG;
-typedef signed __int64 FIINT64;
-typedef unsigned __int64 FIUINT64;
+typedef signed __int64 INT64;
+typedef unsigned __int64 UINT64;
 #endif // _MSC_VER
 
 #if (defined(_WIN32) || defined(__WIN32__))
 
 // Load / Save flag constants -----------------------------------------------
 
-#define FIF_LOAD_NOPIXELS 0x8000 // loading: load the image header only (not supported by all plugins)
+#define FIF_LOAD_NOPIXELS 0x8000 // loading: load the image header only (not supported by all plugins, default to full loading)
 
 #define BMP_DEFAULT         0
 #define BMP_SAVE_RLE        1
 #define JPEG_ACCURATE       0x0002	// load the file with the best quality, sacrificing some speed
 #define JPEG_CMYK			0x0004	// load separated CMYK "as is" (use | to combine with other load flags)
 #define JPEG_EXIFROTATE		0x0008	// load and rotate according to Exif 'Orientation' tag if available
+#define JPEG_GREYSCALE		0x0010	// load and convert to a 8-bit greyscale image
 #define JPEG_QUALITYSUPERB  0x80	// save with superb quality (100:1)
 #define JPEG_QUALITYGOOD    0x0100	// save with good quality (75:1)
 #define JPEG_QUALITYNORMAL  0x0200	// save with normal quality (50:1)

File Source/FreeImage/BitmapAccess.cpp

 	// palette is aligned on a 16 bytes boundary
 	dib_size += sizeof(RGBQUAD) * CalculateUsedPaletteEntries(bpp);
 	// we both add palette size and masks size if need_masks is true, since CalculateUsedPaletteEntries
-	// always returns 0 if need_masks is true (which is only for 16 an 32 bit images).
+	// always returns 0 if need_masks is true (which is only true for 16 bit images).
 	dib_size += need_masks ? sizeof(DWORD) * 3 : 0;
 	dib_size += (dib_size % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - dib_size % FIBITMAP_ALIGNMENT : 0);  
 	if(!header_only) {
 }
 
 /**
-Just like FreeImage_GetPalette, this function returns a pointer to the masks.
-Since this function is also called from FreeImage_GetRed/Green/BlueMask, the
-tests for image type and bpp are all needed. 
-@param dib
-@return returns a pointer to the masks if successfull, returns NULL if no masks are present (e.g. for a 24 bit image).
+Helper for 16-bit FIT_BITMAP
+Returns a pointer to the bitmap's red-, green- and blue masks.
+@param dib The bitmap to obtain masks from.
+@return Returns a pointer to the bitmap's red-, green- and blue masks
+or NULL, if no masks are present (e.g. for 24 bit images).
 */
 static FREEIMAGERGBMASKS *
 FreeImage_GetRGBMasks(FIBITMAP *dib) {
-	if (!dib) {
-		return NULL;
-	}
-	if (FreeImage_GetImageType(dib) != FIT_BITMAP) {
-		return NULL;
-	}
-	unsigned bpp = FreeImage_GetBPP(dib);
-	if (bpp != 16 && bpp != 32) {
-		return NULL;
-	}
-	return (FREEIMAGERGBMASKS *)(((BYTE *)FreeImage_GetInfoHeader(dib)) + sizeof(BITMAPINFOHEADER));
+	return FreeImage_HasRGBMasks(dib) ? (FREEIMAGERGBMASKS *)(((BYTE *)FreeImage_GetInfoHeader(dib)) + sizeof(BITMAPINFOHEADER)) : NULL;
 }
 
 FIBITMAP * DLL_CALLCONV
 		return NULL;
 	}
 
-	// we only store the masks (and allocate memory for them) for 16 and 32 bit images
+	// we only store the masks (and allocate memory for
+	// them) for 16 images of type FIT_BITMAP
 	BOOL need_masks = FALSE;
 
 	// check pixel bit depth
 					need_masks = TRUE;
                     break;
 				case 24:
-					break;
 				case 32:
-					need_masks = TRUE;
 					break;
 				default:
 					bpp = 8;
 			bih->biPlanes           = 1;
 			bih->biCompression      = need_masks ? BI_BITFIELDS : BI_RGB;
 			bih->biBitCount         = (WORD)bpp;
-			bih->biClrUsed          = need_masks ? 3 : CalculateUsedPaletteEntries(bpp);
-			bih->biClrImportant     = need_masks ? 0 : bih->biClrUsed;
+			bih->biClrUsed          = CalculateUsedPaletteEntries(bpp);
+			bih->biClrImportant     = bih->biClrUsed;
 			bih->biXPelsPerMeter	= 2835;	// 72 dpi
 			bih->biYPelsPerMeter	= 2835;	// 72 dpi
 
 	// check for pixel availability ...
 	BOOL header_only = FreeImage_HasPixels(dib) ? FALSE : TRUE;
 	// check whether this image has masks defined ...
-	BOOL need_masks  = (type == FIT_BITMAP && (bpp == 16 || bpp == 32)) ? TRUE : FALSE;
+	BOOL need_masks  = (bpp == 16 && type == FIT_BITMAP) ? TRUE : FALSE;
 
 	// allocate a new dib
 	FIBITMAP *new_dib = FreeImage_AllocateHeaderT(header_only, type, width, height, bpp,
 			if (FreeImage_GetICCProfile(dib)->flags & FIICC_COLOR_IS_CMYK)
 				return FIC_CMYK;
 
-			for (unsigned y = 0; y < FreeImage_GetHeight(dib); y++) {
-				rgb = (RGBQUAD *)FreeImage_GetScanLine(dib, y);
+			if( FreeImage_HasPixels(dib) ) {
+				// check for fully opaque alpha layer
+				for (unsigned y = 0; y < FreeImage_GetHeight(dib); y++) {
+					rgb = (RGBQUAD *)FreeImage_GetScanLine(dib, y);
 
-				for (unsigned x = 0; x < FreeImage_GetWidth(dib); x++)
-					if (rgb[x].rgbReserved != 0xFF)
-						return FIC_RGBALPHA;			
+					for (unsigned x = 0; x < FreeImage_GetWidth(dib); x++)
+						if (rgb[x].rgbReserved != 0xFF)
+							return FIC_RGBALPHA;			
+				}
+				return FIC_RGB;
 			}
 
-			return FIC_RGB;
+			return FIC_RGBALPHA;
 		}
 				
 		default :
 
 // ----------------------------------------------------------
 
+BOOL DLL_CALLCONV
+FreeImage_HasRGBMasks(FIBITMAP *dib) {
+	return dib && FreeImage_GetInfoHeader(dib)->biCompression == BI_BITFIELDS;
+}
+
 unsigned DLL_CALLCONV
 FreeImage_GetRedMask(FIBITMAP *dib) {
 	FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(dib);
 void DLL_CALLCONV
 FreeImage_SetTransparencyTable(FIBITMAP *dib, BYTE *table, int count) {
 	if (dib) {
-		count = MIN(count, 256);
+		count = MAX(0, MIN(count, 256));
 		if (FreeImage_GetBPP(dib) <= 8) {
-			((FREEIMAGEHEADER *)dib->data)->transparent = TRUE;
+			((FREEIMAGEHEADER *)dib->data)->transparent = (count > 0) ? TRUE : FALSE;
 			((FREEIMAGEHEADER *)dib->data)->transparency_count = count;
 
 			if (table) {

File Source/FreeImage/Conversion24.cpp

 	if(!FreeImage_HasPixels(dib)) return NULL;
 
 	const unsigned bpp = FreeImage_GetBPP(dib);
+	const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
 
-	const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
-	if((image_type != FIT_BITMAP) && (image_type != FIT_RGB16)) {
+	if((image_type != FIT_BITMAP) && (image_type != FIT_RGB16) && (image_type != FIT_RGBA16)) {
 		return NULL;
 	}
+	
+	const int width = FreeImage_GetWidth(dib);
+	const int height = FreeImage_GetHeight(dib);
 
-	if (bpp != 24) {
-		const int width = FreeImage_GetWidth(dib);
-		const int height = FreeImage_GetHeight(dib);
+	if(image_type == FIT_BITMAP) {
+		if(bpp == 24) {
+			return FreeImage_Clone(dib);
+		}
+
 		FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
-
 		if(new_dib == NULL) {
 			return NULL;
 		}
 				}
 				return new_dib;
 			}
+		}
+	
+	} else if(image_type == FIT_RGB16) {
+		FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
+		if(new_dib == NULL) {
+			return NULL;
+		}
 
-			case 48:
-			{
-				const unsigned src_pitch = FreeImage_GetPitch(dib);
-				const unsigned dst_pitch = FreeImage_GetPitch(new_dib);
-				const BYTE *src_bits = FreeImage_GetBits(dib);
-				BYTE *dst_bits = FreeImage_GetBits(new_dib);
-				for (int rows = 0; rows < height; rows++) {
-					const FIRGB16 *src_pixel = (FIRGB16*)src_bits;
-					RGBTRIPLE *dst_pixel = (RGBTRIPLE*)dst_bits;
-					for(int cols = 0; cols < width; cols++) {
-						dst_pixel[cols].rgbtRed   = (BYTE)(src_pixel[cols].red   >> 8);
-						dst_pixel[cols].rgbtGreen = (BYTE)(src_pixel[cols].green >> 8);
-						dst_pixel[cols].rgbtBlue  = (BYTE)(src_pixel[cols].blue  >> 8);
-					}
-					src_bits += src_pitch;
-					dst_bits += dst_pitch;
-				}
-				return new_dib;
+		// copy metadata from src to dst
+		FreeImage_CloneMetadata(new_dib, dib);
+
+		const unsigned src_pitch = FreeImage_GetPitch(dib);
+		const unsigned dst_pitch = FreeImage_GetPitch(new_dib);
+		const BYTE *src_bits = FreeImage_GetBits(dib);
+		BYTE *dst_bits = FreeImage_GetBits(new_dib);
+		for (int rows = 0; rows < height; rows++) {
+			const FIRGB16 *src_pixel = (FIRGB16*)src_bits;
+			RGBTRIPLE *dst_pixel = (RGBTRIPLE*)dst_bits;
+			for(int cols = 0; cols < width; cols++) {
+				dst_pixel[cols].rgbtRed   = (BYTE)(src_pixel[cols].red   >> 8);
+				dst_pixel[cols].rgbtGreen = (BYTE)(src_pixel[cols].green >> 8);
+				dst_pixel[cols].rgbtBlue  = (BYTE)(src_pixel[cols].blue  >> 8);
 			}
+			src_bits += src_pitch;
+			dst_bits += dst_pitch;
 		}
+
+		return new_dib;
+
+	} else if(image_type == FIT_RGBA16) {
+		FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
+		if(new_dib == NULL) {
+			return NULL;
+		}
+
+		// copy metadata from src to dst
+		FreeImage_CloneMetadata(new_dib, dib);
+
+		const unsigned src_pitch = FreeImage_GetPitch(dib);
+		const unsigned dst_pitch = FreeImage_GetPitch(new_dib);
+		const BYTE *src_bits = FreeImage_GetBits(dib);
+		BYTE *dst_bits = FreeImage_GetBits(new_dib);
+		for (int rows = 0; rows < height; rows++) {
+			const FIRGBA16 *src_pixel = (FIRGBA16*)src_bits;
+			RGBTRIPLE *dst_pixel = (RGBTRIPLE*)dst_bits;
+			for(int cols = 0; cols < width; cols++) {
+				dst_pixel[cols].rgbtRed   = (BYTE)(src_pixel[cols].red   >> 8);
+				dst_pixel[cols].rgbtGreen = (BYTE)(src_pixel[cols].green >> 8);
+				dst_pixel[cols].rgbtBlue  = (BYTE)(src_pixel[cols].blue  >> 8);
+			}
+			src_bits += src_pitch;
+			dst_bits += dst_pitch;
+		}		
+
+		return new_dib;
 	}
 
-	return FreeImage_Clone(dib);
+	return NULL;
 }

File Source/FreeImage/Conversion8.cpp

 // - Herv� Drolon (drolon@infonie.fr)
 // - Jani Kajala (janik@remedy.fi)
 // - Karl-Heinz Bussian (khbussian@moss.de)
+// - Carsten Klein (cklein05@users.sourceforge.net)
 //
 // This file is part of FreeImage 3
 //
 
 void DLL_CALLCONV
 FreeImage_ConvertLine1To8(BYTE *target, BYTE *source, int width_in_pixels) {
-	for (int cols = 0; cols < width_in_pixels; cols++)
+	for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++)
 		target[cols] = (source[cols >> 3] & (0x80 >> (cols & 0x07))) != 0 ? 255 : 0;	
 }
 
 void DLL_CALLCONV
 FreeImage_ConvertLine4To8(BYTE *target, BYTE *source, int width_in_pixels) {
-	int count_new = 0;
-	int count_org = 0;
+	unsigned count_new = 0;
+	unsigned count_org = 0;
 	BOOL hinibble = TRUE;
 
-	while (count_new < width_in_pixels) {
+	while (count_new < (unsigned)width_in_pixels) {
 		if (hinibble) {
-			target[count_new] = (source[count_org] & 0xF0) >> 4;
+			target[count_new] = (source[count_org] >> 4);
 		} else {
 			target[count_new] = (source[count_org] & 0x0F);
-
 			count_org++;
 		}
-
 		hinibble = !hinibble;
-
 		count_new++;
 	}
 }
 
 void DLL_CALLCONV
 FreeImage_ConvertLine16To8_555(BYTE *target, BYTE *source, int width_in_pixels) {
-	WORD *bits = (WORD *)source;
-
-	for (int cols = 0; cols < width_in_pixels; cols++) {
+	const WORD *const bits = (WORD *)source;
+	for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) {
 		target[cols] = GREY((((bits[cols] & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT) * 0xFF) / 0x1F,
 			                (((bits[cols] & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT) * 0xFF) / 0x1F,
 							(((bits[cols] & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT) * 0xFF) / 0x1F);
 
 void DLL_CALLCONV
 FreeImage_ConvertLine16To8_565(BYTE *target, BYTE *source, int width_in_pixels) {
-	WORD *bits = (WORD *)source;
-
-	for (int cols = 0; cols < width_in_pixels; cols++)
+	const WORD *const bits = (WORD *)source;
+	for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) {
 		target[cols] = GREY((((bits[cols] & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT) * 0xFF) / 0x1F,
 			        (((bits[cols] & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT) * 0xFF) / 0x3F,
-					(((bits[cols] & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F);	
+					(((bits[cols] & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F);
+	}
 }
 
 void DLL_CALLCONV
 FreeImage_ConvertLine24To8(BYTE *target, BYTE *source, int width_in_pixels) {
-	for (int cols = 0; cols < width_in_pixels; cols++) {
+	for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) {
 		target[cols] = GREY(source[FI_RGBA_RED], source[FI_RGBA_GREEN], source[FI_RGBA_BLUE]);
-
 		source += 3;
 	}
 }
 
 void DLL_CALLCONV
 FreeImage_ConvertLine32To8(BYTE *target, BYTE *source, int width_in_pixels) {
-	for (int cols = 0; cols < width_in_pixels; cols++) {
+	for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) {
 		target[cols] = GREY(source[FI_RGBA_RED], source[FI_RGBA_GREEN], source[FI_RGBA_BLUE]);
-
 		source += 4;
 	}
 }
 
 FIBITMAP * DLL_CALLCONV
 FreeImage_ConvertTo8Bits(FIBITMAP *dib) {
-	if(!FreeImage_HasPixels(dib)) return NULL;
-
-	const int bpp = FreeImage_GetBPP(dib);
-
-	const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
-	if((image_type != FIT_BITMAP) && (image_type != FIT_UINT16)) {
+	if (!FreeImage_HasPixels(dib)) {
 		return NULL;
 	}
 
-	if(bpp != 8) {
-		const int width  = FreeImage_GetWidth(dib);
-		const int height = FreeImage_GetHeight(dib);
+	const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
+	if (image_type != FIT_BITMAP && image_type != FIT_UINT16) {
+		return NULL;
+	}
+
+	const unsigned bpp = FreeImage_GetBPP(dib);
+
+	if (bpp != 8) {
+
+		const unsigned width = FreeImage_GetWidth(dib);
+		const unsigned height = FreeImage_GetHeight(dib);
+
+		// Allocate a destination image
 		FIBITMAP *new_dib = FreeImage_Allocate(width, height, 8);
-
-		if(new_dib == NULL) {
+		if (new_dib == NULL) {
 			return NULL;
 		}
 
-		// copy metadata from src to dst
+		// Copy metadata from src to dst
 		FreeImage_CloneMetadata(new_dib, dib);
 
-		// Build a greyscale palette (*always* needed for image processing)
-
+		// Palette of destination image has already been initialized
 		RGBQUAD *new_pal = FreeImage_GetPalette(new_dib);
 
-		for(int i = 0; i < 256; i++) {
-			new_pal[i].rgbRed	= (BYTE)i;
-			new_pal[i].rgbGreen = (BYTE)i;
-			new_pal[i].rgbBlue	= (BYTE)i;
-		}
+		const FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib);
 
-		if(image_type == FIT_BITMAP) {
+		if (image_type == FIT_BITMAP) {
 
 			switch(bpp) {
 				case 1:
 				{
-					if(FreeImage_GetColorType(dib) == FIC_PALETTE) {
+					if (color_type == FIC_PALETTE) {
+						// Copy the palette
+						RGBQUAD *old_pal = FreeImage_GetPalette(dib);
+						new_pal[0] = old_pal[0];
+						new_pal[255] = old_pal[1];
 
-						// Copy the palette
-
-						RGBQUAD *old_pal = FreeImage_GetPalette(dib);
-						memcpy(&new_pal[0], &old_pal[0], sizeof(RGBQUAD));
-						memcpy(&new_pal[255], &old_pal[1], sizeof(RGBQUAD));
-
-					}
-					else if(FreeImage_GetColorType(dib) == FIC_MINISWHITE) {
-						
-						// Reverse the grayscale palette
-
-						for(int i = 0; i < 256; i++) {
-							new_pal[i].rgbRed = new_pal[i].rgbGreen = new_pal[i].rgbBlue = (BYTE)(255 - i);
-						}
+					} else if (color_type == FIC_MINISWHITE) {
+						// Create a reverse grayscale palette
+						CREATE_GREYSCALE_PALETTE_REVERSE(new_pal, 256);
 					}
 
-
 					// Expand and copy the bitmap data
-
-					for (int rows = 0; rows < height; rows++) {
+					for (unsigned rows = 0; rows < height; rows++) {
 						FreeImage_ConvertLine1To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width);
 					}
 					return new_dib;
 
 				case 4 :
 				{
-					if(FreeImage_GetColorType(dib) == FIC_PALETTE) {
-
+					if (color_type == FIC_PALETTE) {
 						// Copy the palette
-
-						RGBQUAD *old_pal = FreeImage_GetPalette(dib);
-
-						for (int i = 0; i < 16; i++) {
-							new_pal[i].rgbRed	= old_pal[i].rgbRed;
-							new_pal[i].rgbGreen = old_pal[i].rgbGreen;
-							new_pal[i].rgbBlue	= old_pal[i].rgbBlue;
-						}
+						memcpy(new_pal, FreeImage_GetPalette(dib), 16 * sizeof(RGBQUAD));
 					}
 
 					// Expand and copy the bitmap data
-
-					for (int rows = 0; rows < height; rows++) {
+					for (unsigned rows = 0; rows < height; rows++) {
 						FreeImage_ConvertLine4To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width);					
 					}
 					return new_dib;
 				case 16 :
 				{
 					// Expand and copy the bitmap data
-
-					for (int rows = 0; rows < height; rows++) {
-						if ((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) {
+					if (IS_FORMAT_RGB565(dib)) {
+						for (unsigned rows = 0; rows < height; rows++) {
 							FreeImage_ConvertLine16To8_565(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width);
-						} else {
+						}
+					} else {
+						for (unsigned rows = 0; rows < height; rows++) {
 							FreeImage_ConvertLine16To8_555(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width);
 						}
 					}
-					
 					return new_dib;
 				}
 
 				case 24 :
 				{
 					// Expand and copy the bitmap data
-
-					for (int rows = 0; rows < height; rows++) {
+					for (unsigned rows = 0; rows < height; rows++) {
 						FreeImage_ConvertLine24To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width);					
 					}
 					return new_dib;
 				case 32 :
 				{
 					// Expand and copy the bitmap data
-
-					for (int rows = 0; rows < height; rows++) {
+					for (unsigned rows = 0; rows < height; rows++) {
 						FreeImage_ConvertLine32To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width);
 					}
 					return new_dib;
 				}
 			}
 
-		} else if(image_type == FIT_UINT16) {
+		} else if (image_type == FIT_UINT16) {
 
 			const unsigned src_pitch = FreeImage_GetPitch(dib);
 			const unsigned dst_pitch = FreeImage_GetPitch(new_dib);
 			const BYTE *src_bits = FreeImage_GetBits(dib);
 			BYTE *dst_bits = FreeImage_GetBits(new_dib);
-			for (int rows = 0; rows < height; rows++) {
-				const WORD *src_pixel = (WORD*)src_bits;
+
+			for (unsigned rows = 0; rows < height; rows++) {
+				const WORD *const src_pixel = (WORD*)src_bits;
 				BYTE *dst_pixel = (BYTE*)dst_bits;
-				for(int cols = 0; cols < width; cols++) {
+				for(unsigned cols = 0; cols < width; cols++) {
 					dst_pixel[cols] = (BYTE)(src_pixel[cols] >> 8);
 				}
 				src_bits += src_pitch;
 				dst_bits += dst_pitch;
 			}
-
 			return new_dib;
-
 		} 
 
 	} // bpp != 8
 
 FIBITMAP * DLL_CALLCONV
 FreeImage_ConvertToGreyscale(FIBITMAP *dib) {
-	if(!FreeImage_HasPixels(dib)) return NULL;
+	if (!FreeImage_HasPixels(dib)) {
+		return NULL;
+	}
 
 	const FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib);
-	const int bpp = FreeImage_GetBPP(dib);
 
-	if((color_type == FIC_PALETTE) || (color_type == FIC_MINISWHITE)) {
-		const int width  = FreeImage_GetWidth(dib);
-		const int height = FreeImage_GetHeight(dib);
+	if (color_type == FIC_PALETTE || color_type == FIC_MINISWHITE) {
+
+		const unsigned bpp = FreeImage_GetBPP(dib);
+		const unsigned width  = FreeImage_GetWidth(dib);
+		const unsigned height = FreeImage_GetHeight(dib);
+
 		FIBITMAP *new_dib = FreeImage_Allocate(width, height, 8);
-
-		if(new_dib == NULL) {
+		if (new_dib == NULL) {
 			return NULL;
 		}
 
-		// copy metadata from src to dst
+		// Copy metadata from src to dst
 		FreeImage_CloneMetadata(new_dib, dib);
 
-		// Build a greyscale palette
-
-		RGBQUAD *new_pal = FreeImage_GetPalette(new_dib);
-
-		for(int i = 0; i < 256; i++) {
-			new_pal[i].rgbRed	= (BYTE)i;
-			new_pal[i].rgbGreen = (BYTE)i;
-			new_pal[i].rgbBlue	= (BYTE)i;
+		// Create a greyscale palette
+		BYTE grey_pal[256];
+		const RGBQUAD *pal = FreeImage_GetPalette(dib);
+		const unsigned size = CalculateUsedPaletteEntries(bpp);
+		for (unsigned i = 0; i < size; i++) {
+			grey_pal[i] = GREY(pal->rgbRed, pal->rgbGreen, pal->rgbBlue);
+			pal++;
 		}
 
-		// allocate a 24-bit buffer
+		const BYTE *src_bits = FreeImage_GetBits(dib);
+		BYTE *dst_bits = FreeImage_GetBits(new_dib);
 
-		BYTE *buffer = (BYTE*)malloc( CalculatePitch(CalculateLine(width, 24)) * sizeof(BYTE) );
-		if(NULL == buffer) {
-			FreeImage_Unload(new_dib);
-			return NULL;
-		}
-
-		// Convert the palette to 24-bit, then to 8-bit
+		const unsigned src_pitch = FreeImage_GetPitch(dib);
+		const unsigned dst_pitch = FreeImage_GetPitch(new_dib);
 
 		switch(bpp) {
 			case 1:
 			{
-				for (int rows = 0; rows < height; rows++) {
-					FreeImage_ConvertLine1To24(buffer, FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib));
-					FreeImage_ConvertLine24To8(FreeImage_GetScanLine(new_dib, rows), buffer, width);
+				for (unsigned y = 0; y < height; y++) {
+					for (unsigned x = 0; x < width; x++) {
+						const unsigned pixel = (src_bits[x >> 3] & (0x80 >> (x & 0x07))) != 0;
+						dst_bits[x] = grey_pal[pixel];
+					}
+					src_bits += src_pitch;
+					dst_bits += dst_pitch;
 				}
 			}
 			break;
 
 			case 4:
 			{
-				for (int rows = 0; rows < height; rows++) {
-					FreeImage_ConvertLine4To24(buffer, FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib));
-					FreeImage_ConvertLine24To8(FreeImage_GetScanLine(new_dib, rows), buffer, width);
+				for (unsigned y = 0; y < height; y++) {
+					for (unsigned x = 0; x < width; x++) {
+						const unsigned pixel = x & 0x01 ? src_bits[x >> 1] & 0x0F : src_bits[x >> 1] >> 4;
+						dst_bits[x] = grey_pal[pixel];
+					}
+					src_bits += src_pitch;
+					dst_bits += dst_pitch;
 				}
 			}
 			break;
 
 			case 8:
 			{
-				for (int rows = 0; rows < height; rows++) {
-					FreeImage_ConvertLine8To24(buffer, FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib));
-					FreeImage_ConvertLine24To8(FreeImage_GetScanLine(new_dib, rows), buffer, width);
+				for (unsigned y = 0; y < height; y++) {
+					for (unsigned x = 0; x < width; x++) {
+						dst_bits[x] = grey_pal[src_bits[x]];
+					}
+					src_bits += src_pitch;
+					dst_bits += dst_pitch;
 				}
 			}
 			break;
-
 		}
-		free(buffer);
-
 		return new_dib;
-
 	} 
 	
 	// Convert the bitmap to 8-bit greyscale

File Source/FreeImage/PixelAccess.cpp

 	// returns the pixels aligned on a FIBITMAP_ALIGNMENT bytes alignment boundary
 	size_t lp = (size_t)FreeImage_GetInfoHeader(dib);
 	lp += sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * FreeImage_GetColorsUsed(dib);
+	lp += FreeImage_HasRGBMasks(dib) ? sizeof(DWORD) * 3 : 0;
 	lp += (lp % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - lp % FIBITMAP_ALIGNMENT : 0);
 	return (BYTE *)lp;
 }

File Source/FreeImage/Plugin.cpp

 // FreeImage Plugin Interface
 //
 // Design and implementation by
-// - Floris van den Berg (flvdberg@wxs.nl)
+// - Floris van den Berg (floris@geekhq.nl)
 // - Rui Lopes (ruiglopes@yahoo.com)
 // - Detlev Vendt (detlev.vendt@brillit.de)
 // - Petr Pytelka (pyta@lightcomp.com)
 #include "FreeImageIO.h"
 #include "Plugin.h"
 
+#include "../Metadata/FreeImageTag.h"
+
 // =====================================================================
 
 using namespace std;
 FREE_IMAGE_FORMAT
 PluginList::AddNode(FI_InitProc init_proc, void *instance, const char *format, const char *description, const char *extension, const char *regexpr) {
 	if (init_proc != NULL) {
-		PluginNode *node = new PluginNode;
-		Plugin *plugin = new Plugin;
+		PluginNode *node = new(std::nothrow) PluginNode;
+		Plugin *plugin = new(std::nothrow) Plugin;
+		if(!node || !plugin) {
+			if(node) delete node;
+			if(plugin) delete plugin;
+			FreeImage_OutputMessageProc(FIF_UNKNOWN, FI_MSG_ERROR_MEMORY);
+			return FIF_UNKNOWN;
+		}
 
 		memset(plugin, 0, sizeof(Plugin));
 
-		// fill-in the plugin structure 
+		// fill-in the plugin structure
 		// note we have memset to 0, so all unset pointers should be NULL)
 
 		init_proc(plugin, (int)m_plugin_map.size());
 
 		const char *the_format = NULL;
 
-		if (format != NULL) 
+		if (format != NULL) {
 			the_format = format;
-		else if (plugin->format_proc != NULL)
+		} else if (plugin->format_proc != NULL) {
 			the_format = plugin->format_proc();
+		}
 
 		// add the node if it wasn't there already
 
 		if (the_format != NULL) {
-			if (FindNodeFromFormat(the_format) == NULL) {
-				node->m_id = (int)m_plugin_map.size();
-				node->m_instance = instance;
-				node->m_plugin = plugin;
-				node->m_format = format;
-				node->m_description = description;
-				node->m_extension = extension;
-				node->m_regexpr = regexpr;
-				node->m_enabled = TRUE;
+			node->m_id = (int)m_plugin_map.size();
+			node->m_instance = instance;
+			node->m_plugin = plugin;
+			node->m_format = format;
+			node->m_description = description;
+			node->m_extension = extension;
+			node->m_regexpr = regexpr;
+			node->m_enabled = TRUE;
 
-				m_plugin_map[(const int)m_plugin_map.size()] = node;
+			m_plugin_map[(const int)m_plugin_map.size()] = node;
 
-				return (FREE_IMAGE_FORMAT)node->m_id;
-			}
+			return (FREE_IMAGE_FORMAT)node->m_id;
 		}
 
 		// something went wrong while allocating the plugin... cleanup
 
 PluginNode *
 PluginList::FindNodeFromFormat(const char *format) {
-	int count = 0;
-
 	for (map<int, PluginNode *>::iterator i = m_plugin_map.begin(); i != m_plugin_map.end(); ++i) {
 		const char *the_format = ((*i).second->m_format != NULL) ? (*i).second->m_format : (*i).second->m_plugin->format_proc();
 
-		if (FreeImage_stricmp(the_format, format) == 0)
-			return (*i).second;		
-
-		count++;
+		if ((*i).second->m_enabled) {
+			if (FreeImage_stricmp(the_format, format) == 0) {
+				return (*i).second;
+			}
+		}
 	}
 
 	return NULL;
 
 PluginNode *
 PluginList::FindNodeFromMime(const char *mime) {
-	int count = 0;
-
 	for (map<int, PluginNode *>::iterator i = m_plugin_map.begin(); i != m_plugin_map.end(); ++i) {
 		const char *the_mime = ((*i).second->m_plugin->mime_proc != NULL) ? (*i).second->m_plugin->mime_proc() : "";
 
-		if ((the_mime != NULL) && (strcmp(the_mime, mime) == 0))
-			return (*i).second;		
-
-		count++;
+		if ((*i).second->m_enabled) {
+			if ((the_mime != NULL) && (strcmp(the_mime, mime) == 0)) {
+				return (*i).second;
+			}
+		}
 	}
 
 	return NULL;
 PluginList::FindNodeFromFIF(int node_id) {
 	map<int, PluginNode *>::iterator i = m_plugin_map.find(node_id);
 
-	if (i != m_plugin_map.end())
+	if (i != m_plugin_map.end()) {
 		return (*i).second;
+	}
 
 	return NULL;
 }
 PluginList::~PluginList() {
 	for (map<int, PluginNode *>::iterator i = m_plugin_map.begin(); i != m_plugin_map.end(); ++i) {
 #ifdef _WIN32
-		if ((*i).second->m_instance != NULL)
+		if ((*i).second->m_instance != NULL) {
 			FreeLibrary((HINSTANCE)(*i).second->m_instance);
+		}
 #endif
 		delete (*i).second->m_plugin;
 		delete ((*i).second);
 void DLL_CALLCONV
 FreeImage_Initialise(BOOL load_local_plugins_only) {
 	if (s_plugin_reference_count++ == 0) {
+		
+		// initialise the TagLib singleton
+		TagLib& s = TagLib::instance();
 
 		// internal plugin initialization
 
 		PluginNode *node = s_plugins->FindNodeFromFIF(fif);
 		
 		if (node != NULL) {
-			if (node->m_enabled) {
-				if(node->m_plugin->load_proc != NULL) {
-					FIBITMAP *bitmap = NULL;
+			if(node->m_plugin->load_proc != NULL) {
+				void *data = FreeImage_Open(node, io, handle, TRUE);
 					
-					void *data = FreeImage_Open(node, io, handle, TRUE);
+				FIBITMAP *bitmap = node->m_plugin->load_proc(io, handle, -1, flags, data);
 					
-					bitmap = node->m_plugin->load_proc(io, handle, -1, flags, data);
+				FreeImage_Close(node, io, handle, data);
 					
-					FreeImage_Close(node, io, handle, data);
-					
-					return bitmap;
-				}
+				return bitmap;
 			}
 		}
 	}
 		PluginNode *node = s_plugins->FindNodeFromFIF(fif);
 		
 		if (node) {
-			if (node->m_enabled) {
-				if(node->m_plugin->save_proc != NULL) {
-					BOOL result = FALSE;
-
-					void *data = FreeImage_Open(node, io, handle, FALSE);
+			if(node->m_plugin->save_proc != NULL) {
+				void *data = FreeImage_Open(node, io, handle, FALSE);
 					
-					result = node->m_plugin->save_proc(io, dib, handle, -1, flags, data);
+				BOOL result = node->m_plugin->save_proc(io, dib, handle, -1, flags, data);
 					
-					FreeImage_Close(node, io, handle, data);
+				FreeImage_Close(node, io, handle, data);
 					
-					return result;
-				}
+				return result;
 			}
 		}
 	}
 	if (s_plugins != NULL) {
 		PluginNode *node = s_plugins->FindNodeFromFormat(format);
 
-		return (node != NULL) ? (node->m_enabled) ? (FREE_IMAGE_FORMAT)node->m_id : FIF_UNKNOWN : FIF_UNKNOWN;
+		return (node != NULL) ? (FREE_IMAGE_FORMAT)node->m_id : FIF_UNKNOWN;
 	}
 
 	return FIF_UNKNOWN;
 	if (s_plugins != NULL) {
 		PluginNode *node = s_plugins->FindNodeFromMime(mime);
 
-		return (node != NULL) ? (node->m_enabled) ? (FREE_IMAGE_FORMAT)node->m_id : FIF_UNKNOWN : FIF_UNKNOWN;
+		return (node != NULL) ? (FREE_IMAGE_FORMAT)node->m_id : FIF_UNKNOWN;
 	}
 
 	return FIF_UNKNOWN;

File Source/FreeImage/PluginDDS.cpp

 		decoder.SetY (y);
 		for (int x = 0; x < bw; x++) {
 			decoder.GetColor (x, y, (Color8888 &)*dst);
+
+#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB 
+			INPLACESWAP(dst[FI_RGBA_RED], dst[FI_RGBA_BLUE]);
+#endif 
 			dst += 4;
 		}
 	}

File Source/FreeImage/PluginHDR.cpp

 Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
 	if(!dib) return FALSE;
 
-	if(FreeImage_GetImageType(dib) != FIT_RGBF) {
+	FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib);
+	if(src_type != FIT_RGBF) {
+		FreeImage_OutputMessageProc(s_format_id, "FREE_IMAGE_TYPE: Unable to convert from type %d to type %d.\n No such conversion exists.", src_type, FIT_RGBF);
 		return FALSE;
 	}
 

File Source/FreeImage/PluginJPEG.cpp

 				cinfo.do_fancy_upsampling = FALSE;
 			}
 
+			if ((flags & JPEG_GREYSCALE) == JPEG_GREYSCALE) {
+				// force loading as a 8-bit greyscale image
+				cinfo.out_color_space = JCS_GRAYSCALE;
+			}
+
 			// step 5a: start decompressor and calculate output width and height
 
 			jpeg_start_decompress(&cinfo);
 
 			// step 5b: allocate dib and init header
 
-			if((cinfo.num_components == 4) && (cinfo.out_color_space == JCS_CMYK)) {
+			if((cinfo.output_components == 4) && (cinfo.out_color_space == JCS_CMYK)) {
 				// CMYK image
 				if((flags & JPEG_CMYK) == JPEG_CMYK) {
 					// load as CMYK
 				}
 			} else {
 				// RGB or greyscale image
-				dib = FreeImage_AllocateHeader(header_only, cinfo.output_width, cinfo.output_height, 8 * cinfo.num_components, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
+				dib = FreeImage_AllocateHeader(header_only, cinfo.output_width, cinfo.output_height, 8 * cinfo.output_components, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
 				if(!dib) throw FI_MSG_ERROR_DIB_MEMORY;
 
-				if (cinfo.num_components == 1) {
+				if (cinfo.output_components == 1) {
 					// build a greyscale palette
 					RGBQUAD *colors = FreeImage_GetPalette(dib);
 

File Source/FreeImage/PluginPNG.cpp

 				bit_depth = 16;
 			}
 
+			// check for transparent images
+			BOOL bIsTransparent = 
+				(image_type == FIT_BITMAP) && FreeImage_IsTransparent(dib) && (FreeImage_GetTransparencyCount(dib) > 0) ? TRUE : FALSE;
+
 			switch (FreeImage_GetColorType(dib)) {
 				case FIC_MINISWHITE:
-					// Invert monochrome files to have 0 as black and 1 as white (no break here)
-					png_set_invert_mono(png_ptr);
+					if(!bIsTransparent) {
+						// Invert monochrome files to have 0 as black and 1 as white (no break here)
+						png_set_invert_mono(png_ptr);
+					}
+					// (fall through)
 
 				case FIC_MINISBLACK:
-					png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, 
-						PNG_COLOR_TYPE_GRAY, interlace_type, 
-						PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
-
-					break;
+					if(!bIsTransparent) {
+						png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, 
+							PNG_COLOR_TYPE_GRAY, interlace_type, 
+							PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+						break;
+					}
+					// If a monochrome image is transparent, save it with a palette
+					// (fall through)
 
 				case FIC_PALETTE:
 				{
 
 			// set the transparency table
 
-			if (FreeImage_IsTransparent(dib) && (FreeImage_GetTransparencyCount(dib) > 0)) {
+			if (bIsTransparent) {
 				png_set_tRNS(png_ptr, info_ptr, FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib), NULL);
 			}
 

File Source/FreeImage/PluginRAW.cpp

 	FreeImageIO *_io;
 	fi_handle _handle;
 	long _eof;
+	INT64 _fsize;
 
 public:
 	LibRaw_freeimage_datastream(FreeImageIO *io, fi_handle handle) : _io(io), _handle(handle) {
 		long start_pos = io->tell_proc(handle);
 		io->seek_proc(handle, 0, SEEK_END);
 		_eof = io->tell_proc(handle);
+		_fsize = _eof - start_pos;
 		io->seek_proc(handle, start_pos, SEEK_SET);
 	}
+
 	~LibRaw_freeimage_datastream() {
 	}
-	virtual void * make_jas_stream() {
-		return NULL;
-	}
-    virtual int valid() { 
+
+    int valid() { 
 		return (_io && _handle);
 	}
-    virtual int read(void *buffer, size_t size, size_t count) { 
+
+    int read(void *buffer, size_t size, size_t count) { 
 		if(substream) return substream->read(buffer, size, count);
 		return _io->read_proc(buffer, (unsigned)size, (unsigned)count, _handle);
-	}	
-    virtual int eof() { 
-        if(substream) return substream->eof();
-        return (_io->tell_proc(_handle) >= _eof);
-    }
-    virtual int seek(INT64 offset, int origin) { 
+	}
+
+    int seek(INT64 offset, int origin) { 
         if(substream) return substream->seek(offset, origin);
 		return _io->seek_proc(_handle, (long)offset, origin);
-	} 
-    virtual INT64 tell() { 
+	}
+
+    INT64 tell() { 
 		if(substream) return substream->tell();
         return _io->tell_proc(_handle);
     }
-    virtual int get_char() { 
+	
+	INT64 size() {
+		return _fsize;
+	}
+
+    int get_char() { 
 		int c = 0;
 		if(substream) return substream->get_char();
 		if(!_io->read_proc(&c, 1, 1, _handle)) return -1;
 		return c;
    }
-	virtual char* gets(char *buffer, int length) { 
+	
+	char* gets(char *buffer, int length) { 
 		if (substream) return substream->gets(buffer, length);
 		memset(buffer, 0, length);
 		for(int i = 0; i < length; i++) {
 		}
 		return buffer;
 	}
-	virtual int scanf_one(const char *fmt, void* val) {
+
+	int scanf_one(const char *fmt, void* val) {
 		std::string buffer;
 		char element = 0;
 		bool bDone = false;
 
 		return sscanf(buffer.c_str(), fmt, val);
 	}
+
+	int eof() { 
+		if(substream) return substream->eof();
+        return (_io->tell_proc(_handle) >= _eof);
+    }
+
+	void * make_jas_stream() {
+		return NULL;
+	}
 };
 
 // ----------------------------------------------------------

File Source/FreeImageLib/FreeImageLib.2008.vcproj

 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
+				WholeProgramOptimization="false"
 				AdditionalIncludeDirectories="..\;..\ZLib;..\DeprecationManager;..\OpenEXR\Half;..\OpenEXR\Iex;..\OpenEXR\IlmImf;..\OpenEXR\Imath;..\OpenEXR\IlmThread"
 				PreprocessorDefinitions="WIN32;_DEBUG;OPJ_STATIC;FREEIMAGE_LIB;_CRT_SECURE_NO_DEPRECATE;LIBRAW_NODLL"
 				StringPooling="true"
 				EnableIntrinsicFunctions="true"
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="true"
+				WholeProgramOptimization="true"
 				AdditionalIncludeDirectories="..\;..\ZLib;..\DeprecationManager;..\OpenEXR\Half;..\OpenEXR\Iex;..\OpenEXR\IlmImf;..\OpenEXR\Imath;..\OpenEXR\IlmThread"
 				PreprocessorDefinitions="WIN32;NDEBUG;OPJ_STATIC;FREEIMAGE_LIB;_CRT_SECURE_NO_DEPRECATE;LIBRAW_NODLL"
 				StringPooling="true"

File Source/FreeImageToolkit/Rescale.cpp

 //
 // Design and implementation by
 // - Herv� Drolon (drolon@infonie.fr)
+// - Carsten Klein (cklein05@users.sourceforge.net)
 //
 // This file is part of FreeImage 3
 //
 
 	// select the filter
 	CGenericFilter *pFilter = NULL;
-	switch(filter) {
+	switch (filter) {
 		case FILTER_BOX:
 			pFilter = new(std::nothrow) CBoxFilter();
 			break;
 			break;
 	}
 
-	if(!pFilter) {
+	if (!pFilter) {
 		return NULL;
 	}
 
 	CResizeEngine Engine(pFilter);
 
-	// perform upsampling or downsampling
-
-	if((FreeImage_GetBPP(src) == 4) || (FreeImage_GetColorType(src) == FIC_PALETTE)) {
-		// special case for 4-bit images or color map indexed images ...
-		if(FreeImage_IsTransparent(src) == FALSE) {
-			FIBITMAP *src24 = NULL;
-			FIBITMAP *dst24 = NULL;
-			try {
-				// transparent conversion to 24-bit (any transparency table will be destroyed)
-				src24 = FreeImage_ConvertTo24Bits(src);
-				if(!src24) throw(1);
-				// perform upsampling or downsampling
-				dst24 = Engine.scale(src24, dst_width, dst_height);
-				if(!dst24) throw(1);
-				FreeImage_Unload(src24); src24 = NULL;
-				// color quantize to 8-bit
-				dst = FreeImage_ColorQuantize(dst24, FIQ_NNQUANT);
-				// free and return
-				FreeImage_Unload(dst24);
-			} catch(int) {
-				if(src24) FreeImage_Unload(src24);
-				if(dst24) FreeImage_Unload(dst24);
-			}
-		} else {
-			FIBITMAP *src32 = NULL;
-			try {
-				// transparent conversion to 32-bit (keep transparency)
-				src32 = FreeImage_ConvertTo32Bits(src);
-				if(!src32) throw(1);
-				// perform upsampling or downsampling
-				dst = Engine.scale(src32, dst_width, dst_height);
-				if(!dst) throw(1);
-				// free and return
-				FreeImage_Unload(src32);
-			} catch(int) {
-				if(src32) FreeImage_Unload(src32);
-				if(dst) FreeImage_Unload(dst);
-			}
-		}
-	}
-	else if((FreeImage_GetBPP(src) == 16) && (FreeImage_GetImageType(src) == FIT_BITMAP)) {
-		// convert 16-bit RGB to 24-bit
-		FIBITMAP *src24 = NULL;
-		try {
-			// transparent conversion to 24-bit (any transparency table will be destroyed)
-			src24 = FreeImage_ConvertTo24Bits(src);
-			if(!src24) throw(1);
-			// perform upsampling or downsampling
-			dst = Engine.scale(src24, dst_width, dst_height);
-			if(!dst) throw(1);
-			// free and return
-			FreeImage_Unload(src24);
-		} catch(int) {
-			if(src24) FreeImage_Unload(src24);
-			if(dst) FreeImage_Unload(dst);
-		}
-	}
-	else {
-		// normal case : 
-		// 1- or 8-bit greyscale, 24- or 32-bit RGB(A) images
-		// 16-bit greyscale, 48- or 64-bit RGB(A) images
-		// 32-bit float, 96- or 128-bit RGB(A) float images
-		dst = Engine.scale(src, dst_width, dst_height);
-	}
-
+	dst = Engine.scale(src, dst_width, dst_height, 0, 0,
+			FreeImage_GetWidth(src), FreeImage_GetHeight(src));
 
 	delete pFilter;
 
 	return dst;
 }
 
-FIBITMAP * DLL_CALLCONV 
+FIBITMAP * DLL_CALLCONV
 FreeImage_MakeThumbnail(FIBITMAP *dib, int max_pixel_size, BOOL convert) {
 	FIBITMAP *thumbnail = NULL;
 	int new_width, new_height;

File Source/FreeImageToolkit/Resize.cpp

 // Design and implementation by
 // - Herv� Drolon (drolon@infonie.fr)
 // - Detlev Vendt (detlev.vendt@brillit.de)
+// - Carsten Klein (cklein05@users.sourceforge.net)
 //
 // This file is part of FreeImage 3
 //
 #include "Resize.h"
 
 /**
-  Filter weights table.
-  This class stores contribution information for an entire line (row or column).
+Returns the color type of a bitmap. In contrast to FreeImage_GetColorType,
+this function optionally supports a boolean OUT parameter, that receives TRUE,
+if the specified bitmap is greyscale, that is, it consists of grey colors only.
+Although it returns the same value as returned by FreeImage_GetColorType for all
+image types, this extended function primarily is intended for palletized images,
+since the boolean pointed to by 'bIsGreyscale' remains unchanged for RGB(A/F)
+images. However, the outgoing boolean is properly maintained for palletized images,
+as well as for any non-RGB image type, like FIT_UINTxx and FIT_DOUBLE, for example.
+@param dib A pointer to a FreeImage bitmap to calculate the extended color type for
+@param bIsGreyscale A pointer to a boolean, that receives TRUE, if the specified bitmap
+is greyscale, that is, it consists of grey colors only. This parameter can be NULL.
+@return the color type of the specified bitmap
 */
+static FREE_IMAGE_COLOR_TYPE
+GetExtendedColorType(FIBITMAP *dib, BOOL *bIsGreyscale) {
+	const unsigned bpp = FreeImage_GetBPP(dib);
+	const unsigned size = CalculateUsedPaletteEntries(bpp);
+	const RGBQUAD * const pal = FreeImage_GetPalette(dib);
+	FREE_IMAGE_COLOR_TYPE color_type = FIC_MINISBLACK;
+	BOOL bIsGrey = TRUE;
+
+	switch (bpp) {
+		case 1:
+		{
+			for (unsigned i = 0; i < size; i++) {
+				if ((pal[i].rgbRed != pal[i].rgbGreen) || (pal[i].rgbRed != pal[i].rgbBlue)) {
+					color_type = FIC_PALETTE;
+					bIsGrey = FALSE;
+					break;
+				}
+			}
+			if (bIsGrey) {
+				if (pal[0].rgbBlue == 255 && pal[1].rgbBlue == 0) {
+					color_type = FIC_MINISWHITE;
+				} else if (pal[0].rgbBlue != 0 || pal[1].rgbBlue != 255) {
+					color_type = FIC_PALETTE;
+				}
+			}
+			break;
+		}
+
+		case 4:
+		case 8:
+		{
+			for (unsigned i = 0; i < size; i++) {
+				if ((pal[i].rgbRed != pal[i].rgbGreen) || (pal[i].rgbRed != pal[i].rgbBlue)) {
+					color_type = FIC_PALETTE;
+					bIsGrey = FALSE;
+					break;
+				}
+				if (color_type != FIC_PALETTE && pal[i].rgbBlue != i) {
+					if ((size - i - 1) != pal[i].rgbBlue) {
+						color_type = FIC_PALETTE;
+						if (!bIsGreyscale) {
+							// exit loop if we're not setting
+							// bIsGreyscale parameter
+							break;
+						}
+					} else {
+						color_type = FIC_MINISWHITE;
+					}
+				}
+			}
+			break;
+		}
+
+		default:
+		{
+			color_type = FreeImage_GetColorType(dib);
+			bIsGrey = (color_type == FIC_MINISBLACK) ? TRUE : FALSE;
+			break;
+		}
+
+	}
+	if (bIsGreyscale) {
+		*bIsGreyscale = bIsGrey;
+	}
+
+	return color_type;
+}
+
+/**
+Returns a pointer to an RGBA palette, created from the specified bitmap.
+The RGBA palette is a copy of the specified bitmap's palette, that, additionally
+contains the bitmap's transparency information in the rgbReserved member
+of the palette's RGBQUAD elements.
+@param dib A pointer to a FreeImage bitmap to create the RGBA palette from.
+@param buffer A pointer to the buffer to store the RGBA palette.
+@return A pointer to the newly created RGBA palette or NULL, if the specified
+bitmap is no palletized standard bitmap. If non-NULL, the returned value is
+actually the pointer passed in parameter 'buffer'.
+*/
+static inline RGBQUAD *
+GetRGBAPalette(FIBITMAP *dib, RGBQUAD * const buffer) {
+	// clone the palette
+	const unsigned ncolors = FreeImage_GetColorsUsed(dib);
+	if (ncolors == 0) {
+		return NULL;
+	}
+	memcpy(buffer, FreeImage_GetPalette(dib), ncolors * sizeof(RGBQUAD));
+	// merge the transparency table
+	const unsigned ntransp = MIN(ncolors, FreeImage_GetTransparencyCount(dib));
+	const BYTE * const tt = FreeImage_GetTransparencyTable(dib);
+	for (unsigned i = 0; i < ntransp; i++) {
+		buffer[i].rgbReserved = tt[i];
+	}
+	for (unsigned i = ntransp; i < ncolors; i++) {
+		buffer[i].rgbReserved = 255;
+	}
+	return buffer;
+}
+
+// --------------------------------------------------------------------------
+
 CWeightsTable::CWeightsTable(CGenericFilter *pFilter, unsigned uDstSize, unsigned uSrcSize) {
 	unsigned u;
 	double dWidth;
 	// offset for discrete to continuous coordinate conversion
 	const double dOffset = (0.5 / dScale) - 0.5;
 
-
 	for(u = 0; u < m_LineLength; u++) {
 		// scan through line of contributions
 		const double dCenter = (double)u / dScale + dOffset;   // reverse mapping
 			}
 			// simplify the filter, discarding null weights at the right
 			iSrc = iRight - iLeft;
-			while(m_WeightTable[u].Weights[iSrc] == 0){
+			while(m_WeightTable[u].Weights[iSrc] == 0) {
 				m_WeightTable[u].Right--;
 				iSrc--;
-				if(m_WeightTable[u].Right == m_WeightTable[u].Left)
+				if(m_WeightTable[u].Right == m_WeightTable[u].Left) {
 					break;
+				}
 			}
 
 		}
-   } 
+	}
 }
 
 CWeightsTable::~CWeightsTable() {
 	free(m_WeightTable);
 }
 
-// ---------------------------------------------
+// --------------------------------------------------------------------------
 
-/**
- CResizeEngine<br>
- This class performs filtered zoom. It scales an image to the desired dimensions with 
- any of the CGenericFilter derived filter class.<br>
- It works with 8-, 24- and 32-bit buffers.<br><br>
+FIBITMAP* CResizeEngine::scale(FIBITMAP *src, unsigned dst_width, unsigned dst_height, unsigned src_left, unsigned src_top, unsigned src_width, unsigned src_height) {
 
- <b>References</b> : <br>
- [1] Paul Heckbert, C code to zoom raster images up or down, with nice filtering. 
- UC Berkeley, August 1989. [online] http://www-2.cs.cmu.edu/afs/cs.cmu.edu/Web/People/ph/heckbert.html
- [2] Eran Yariv, Two Pass Scaling using Filters. The Code Project, December 1999. 
- [online] http://www.codeproject.com/bitmap/2_pass_scaling.asp
+	const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(src);
+	const unsigned src_bpp = FreeImage_GetBPP(src);
 
-*/
-
-FIBITMAP* CResizeEngine::scale(FIBITMAP *src, unsigned dst_width, unsigned dst_height) { 
-	unsigned src_width  = FreeImage_GetWidth(src); 
-	unsigned src_height = FreeImage_GetHeight(src);
-
-	unsigned redMask	= FreeImage_GetRedMask(src);
-	unsigned greenMask	= FreeImage_GetGreenMask(src);
-	unsigned blueMask	= FreeImage_GetBlueMask(src);
-
-	unsigned bpp = FreeImage_GetBPP(src);
-	if(bpp == 1) {
-		// convert output to 8-bit
-		bpp = 8;
+	// determine the image's color type
+	BOOL bIsGreyscale = FALSE;
+	FREE_IMAGE_COLOR_TYPE color_type;
+	if (src_bpp <= 8) {
+		color_type = GetExtendedColorType(src, &bIsGreyscale);
+	} else {
+		color_type = FIC_RGB;
 	}
 
-	FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(src);
+	// determine the required bit depth of the destination image
+	unsigned dst_bpp;
+	if (color_type == FIC_PALETTE && !bIsGreyscale) {
+		// non greyscale FIC_PALETTE images require a high-color destination
+		// image (24- or 32-bits depending on the image's transparent state)
+		dst_bpp = FreeImage_IsTransparent(src) ? 32 : 24;
+	} else if (src_bpp <= 8) {
+		// greyscale images require an 8-bit destination image
+		// (or a 32-bit image if the image is transparent)
+		dst_bpp = FreeImage_IsTransparent(src) ? 32 : 8;
+	} else if (src_bpp == 16 && image_type == FIT_BITMAP) {
+		// 16-bit 555 and 565 RGB images require a high-color destination image
+		// (fixed to 24 bits, since 16-bit RGBs don't support transparency in FreeImage)
+		dst_bpp = 24;
+	} else {
+		// bit depth remains unchanged for all other images
+		dst_bpp = src_bpp;
+	}
 
-	// allocate the dst image
-	FIBITMAP *dst = FreeImage_AllocateT(image_type, dst_width, dst_height, bpp, redMask, greenMask, blueMask);
-	if(!dst) return NULL;
-	
-	if(bpp == 8) {
-		if(FreeImage_GetColorType(src) == FIC_MINISWHITE) {
-			// build an inverted greyscale palette
-			RGBQUAD *dst_pal = FreeImage_GetPalette(dst);
-			for(unsigned i = 0; i < 256; i++) {
-				dst_pal[i].rgbRed = dst_pal[i].rgbGreen = dst_pal[i].rgbBlue = (BYTE)(255 - i);
+	// early exit if destination size is equal to source size
+	if ((src_width == dst_width) && (src_height == dst_height)) {
+		FIBITMAP *out = src;
+		FIBITMAP *tmp = src;
+		if ((src_width != FreeImage_GetWidth(src)) || (src_height != FreeImage_GetHeight(src))) {
+			out = FreeImage_Copy(tmp, src_left, src_top, src_left + src_width, src_top + src_height);
+			tmp = out;
+		}
+		if (src_bpp != dst_bpp) {
+			switch (dst_bpp) {
+				case 8:
+					out = FreeImage_ConvertToGreyscale(tmp);
+					if (tmp != src) {
+						FreeImage_Unload(tmp);
+					}
+					break;
+
+				case 24:
+					out = FreeImage_ConvertTo24Bits(tmp);
+					if (tmp != src) {
+						FreeImage_Unload(tmp);
+					}
+					break;
+
+				case 32:
+					out = FreeImage_ConvertTo32Bits(tmp);
+					if (tmp != src) {
+						FreeImage_Unload(tmp);
+					}
+					break;
 			}
+		}
+
+		return (out != src) ? out : FreeImage_Clone(src);
+	}
+
+	RGBQUAD pal_buffer[256];
+	RGBQUAD *src_pal = NULL;
+
+	// provide the source image's palette to the rescaler for
+	// FIC_PALETTE type images (this includes palletized greyscale
+	// images with an unordered palette)
+	if (color_type == FIC_PALETTE) {
+		if (dst_bpp == 32) {
+			// a 32 bit destination image signals transparency, so
+			// create an RGBA palette from the source palette
+			src_pal = GetRGBAPalette(src, pal_buffer);
 		} else {
-			// build a greyscale palette
-			RGBQUAD *dst_pal = FreeImage_GetPalette(dst);
-			for(unsigned i = 0; i < 256; i++) {
-				dst_pal[i].rgbRed = dst_pal[i].rgbGreen = dst_pal[i].rgbBlue = (BYTE)i;
-			}
+			src_pal = FreeImage_GetPalette(src);
 		}
 	}
 
-	/**
+	// allocate the dst image
+	FIBITMAP *dst = FreeImage_AllocateT(image_type, dst_width, dst_height, dst_bpp, 0, 0, 0);
+	if (!dst) {
+		return NULL;
+	}
+	
+	if (dst_bpp == 8) {
+		RGBQUAD * const dst_pal = FreeImage_GetPalette(dst);
+		if (color_type == FIC_MINISWHITE) {
+			// build an inverted greyscale palette
+			CREATE_GREYSCALE_PALETTE_REVERSE(dst_pal, 256);
+		} 
+		/*
+		else {
+			// build a default greyscale palette
+			// Currently, FreeImage_AllocateT already creates a default
+			// greyscale palette for 8 bpp images, so we can skip this here.
+			CREATE_GREYSCALE_PALETTE(dst_pal, 256);
+		}
+		*/
+	}
+
+	// calculate x and y offsets; since FreeImage uses bottom-up bitmaps, the
+	// value of src_offset_y is measured from the bottom of the image
+	unsigned src_offset_x = src_left;
+	unsigned src_offset_y;
+	if (src_top > 0) {
+		src_offset_y = FreeImage_GetHeight(src) - src_height - src_top;
+	} else {
+		src_offset_y = 0;
+	}
+
+	/*
 	Decide which filtering order (xy or yx) is faster for this mapping. 
 	--- The theory ---
 	Try to minimize calculations by counting the number of convolution multiplies
 	}
 	*/
 
-	if(dst_width <= src_width) {
+	if (dst_width <= src_width) {
 		// xy filtering
 		// -------------
 
-		// allocate a temporary image
-		FIBITMAP *tmp = FreeImage_AllocateT(image_type, dst_width, src_height, bpp, redMask, greenMask, blueMask);
-		if(!tmp) {
-			FreeImage_Unload(dst);
-			return NULL;
+		FIBITMAP *tmp = NULL;
+
+		if (src_width != dst_width) {
+			// source and destination widths are different so, we must
+			// filter horizontally
+			if (src_height != dst_height) {
+				// source and destination heights are also different so, we need
+				// a temporary image
+				tmp = FreeImage_AllocateT(image_type, dst_width, src_height, dst_bpp, 0, 0, 0);
+				if (!tmp) {
+					FreeImage_Unload(dst);
+					return NULL;
+				}
+			} else {
+				// source and destination heights are equal so, we can directly
+				// scale into destination image (second filter method will not
+				// be invoked)
+				tmp = dst;
+			}
+
+			// scale source image horizontally into temporary (or destination) image
+			horizontalFilter(src, src_height, src_width, src_offset_x, src_offset_y, src_pal, tmp, dst_width);
+
+			// set x and y offsets to zero for the second filter method
+			// invocation (the temporary image only contains the portion of
+			// the image to be rescaled with no offsets)
+			src_offset_x = 0;
+			src_offset_y = 0;
+
+			// also ensure, that the second filter method gets no source
+			// palette (the temporary image is palletized only, if it is
+			// greyscale; in that case, it is an 8-bit image with a linear
+			// palette so, the source palette is not needed or will even be
+			// mismatching, if the source palette is unordered)
+			src_pal = NULL;
+		} else {
+			// source and destination widths are equal so, just copy the
+			// image pointer
+			tmp = src;
 		}
 
-		// scale source image horizontally into temporary image
-		horizontalFilter(src, src_width, src_height, tmp, dst_width, src_height);
+		if (src_height != dst_height) {
+			// source and destination heights are different so, scale
+			// temporary (or source) image vertically into destination image
+			verticalFilter(tmp, dst_width, src_height, src_offset_x, src_offset_y, src_pal, dst, dst_height);
+		}
 
-		// scale temporary image vertically into result image    
-		verticalFilter(tmp, dst_width, src_height, dst, dst_width, dst_height);
-
-		// free temporary image
-		FreeImage_Unload(tmp);
+		// free temporary image, if not pointing to either src or dst
+		if (tmp != src && tmp != dst) {
+			FreeImage_Unload(tmp);
+		}
 
 	} else {
 		// yx filtering
 		// -------------
 
-		// allocate a temporary image
-		FIBITMAP *tmp = FreeImage_AllocateT(image_type, src_width, dst_height, bpp, redMask, greenMask, blueMask);
-		if(!tmp) {
-			FreeImage_Unload(dst);
-			return NULL;
+		// Remark:
+		// The yx filtering branch could be more optimized by taking into,
+		// account that (src_width != dst_width) is always true, which
+		// follows from the above condition, which selects filtering order.
+		// Since (dst_width <= src_width) == TRUE selects xy filtering,
+		// both widths must be different when performing yx filtering.
+		// However, to make the code more robust, not depending on that
+		// condition and more symmetric to the xy filtering case, these
+		// (src_width != dst_width) conditions are still in place.
+
+		FIBITMAP *tmp = NULL;
+
+		if (src_height != dst_height) {
+			// source and destination heights are different so, we must
+			// filter vertically
+			if (src_width != dst_width) {
+				// source and destination widths are also different so, we need
+				// a temporary image
+				tmp = FreeImage_AllocateT(image_type, src_width, dst_height, dst_bpp, 0, 0, 0);
+				if (!tmp) {
+					FreeImage_Unload(dst);
+					return NULL;
+				}
+			} else {
+				// source and destination widths are equal so, we can directly
+				// scale into destination image (second filter method will not
+				// be invoked)
+				tmp = dst;
+			}
+
+			// scale source image vertically into temporary (or destination) image
+			verticalFilter(src, src_width, src_height, src_offset_x, src_offset_y, src_pal, tmp, dst_height);
+
+			// set x and y offsets to zero for the second filter method
+			// invocation (the temporary image only contains the portion of
+			// the image to be rescaled with no offsets)
+			src_offset_x = 0;
+			src_offset_y = 0;
+
+			// also ensure, that the second filter method gets no source
+			// palette (the temporary image is palletized only, if it is
+			// greyscale; in that case, it is an 8-bit image with a linear
+			// palette so, the source palette is not needed or will even be
+			// mismatching, if the source palette is unordered)
+			src_pal = NULL;
+
+		} else {
+			// source and destination heights are equal so, just copy the
+			// image pointer
+			tmp = src;
 		}
 
-		// scale source image vertically into temporary image
-		verticalFilter(src, src_width, src_height, tmp, src_width, dst_height);
+		if (src_width != dst_width) {
+			// source and destination heights are different so, scale
+			// temporary (or source) image horizontally into destination image
+			horizontalFilter(tmp, dst_height, src_width, src_offset_x, src_offset_y, src_pal, dst, dst_width);
+		}
 
-		// scale temporary image horizontally into result image    
-		horizontalFilter(tmp, src_width, dst_height, dst, dst_width, dst_height);
-
-		// free temporary image
-		FreeImage_Unload(tmp);
+		// free temporary image, if not pointing to either src or dst
+		if (tmp != src && tmp != dst) {
+			FreeImage_Unload(tmp);
+		}
 	}
 
 	return dst;
 } 
 
+void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsigned src_width, unsigned src_offset_x, unsigned src_offset_y, const RGBQUAD *const src_pal, FIBITMAP *const dst, unsigned dst_width) {
 
-/// Performs horizontal image filtering
-void CResizeEngine::horizontalFilter(FIBITMAP *src, unsigned src_width, unsigned src_height, FIBITMAP *dst, unsigned dst_width, unsigned dst_height) { 
-	if(dst_width == src_width) {
-		// no scaling required, just copy
-		switch(FreeImage_GetBPP(src)) {
-			case 1:
-			{
-				if(FreeImage_GetBPP(dst) != 8) break;
-				for(unsigned y = 0; y < dst_height; y++) {
-					// convert each row 
-					BYTE *src_bits = FreeImage_GetScanLine(src, y);
-					BYTE *dst_bits = FreeImage_GetScanLine(dst, y);
-					FreeImage_ConvertLine1To8(dst_bits, src_bits, dst_width);
+	// allocate and calculate the contributions
+	CWeightsTable weightsTable(m_pFilter, dst_width, src_width);
+
+	// step through rows
+	switch(FreeImage_GetImageType(src)) {
+		case FIT_BITMAP:
+		{
+			switch(FreeImage_GetBPP(src)) {
+				case 1:
+				{
+					switch(FreeImage_GetBPP(dst)) {
+						case 8:
+						{
+							// transparently convert the 1-bit non-transparent greyscale
+							// image to 8 bpp
+							src_offset_x >>= 3;
+							if (src_pal) {
+								// we have got a palette
+								for (unsigned y = 0; y < height; y++) {
+									// scale each row
+									const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x;
+									BYTE * const dst_bits = FreeImage_GetScanLine(dst, y);
+
+									for (unsigned x = 0; x < dst_width; x++) {
+										// loop through row
+										const unsigned iLeft = weightsTable.getLeftBoundary(x);		// retrieve left boundary