Revision: 201009
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 16 Apr 2010 15:32:00 +0300
changeset 12 9b222d6b819d
parent 0 f453ebb75370
child 14 fb7380a082a0
child 18 b196ca449a75
Revision: 201009 Kit: 201015
gfxconversion/mifconv/group/ReleaseNotes_Mifconv.txt
gfxconversion/mifconv/group/mifconv.mmp
gfxconversion/mifconv/inc/mifconv.h
gfxconversion/mifconv/inc/mifconv_bitmapconverter.h
gfxconversion/mifconv/inc/mifconv_mbmgenerator.h
gfxconversion/mifconv/inc/mifconv_mbmgenerator_bmtopbm.h
gfxconversion/mifconv/inc/mifconv_mbmgenerator_pbmcomp.h
gfxconversion/mifconv/inc/mifconv_mbmgenerator_rgb.h
gfxconversion/mifconv/inc/mifconv_sourcefile.h
gfxconversion/mifconv/inc/mifconv_util.h
gfxconversion/mifconv/makefile_templates/mifconv_step3.make
gfxconversion/mifconv/src/mifconv_argumentmanager.cpp
gfxconversion/mifconv/src/mifconv_bitmapconverter.cpp
gfxconversion/mifconv/src/mifconv_mbmgenerator.cpp
gfxconversion/mifconv/src/mifconv_mbmgenerator_bmtopbm.cpp
gfxconversion/mifconv/src/mifconv_mbmgenerator_pbmcomp.cpp
gfxconversion/mifconv/src/mifconv_mbmgenerator_rgb.cpp
gfxconversion/mifconv/src/mifconv_sourcefile.cpp
gfxconversion/mifconv/src/mifconv_util.cpp
package_definition.xml
--- a/gfxconversion/mifconv/group/ReleaseNotes_Mifconv.txt	Tue Feb 02 01:11:11 2010 +0200
+++ b/gfxconversion/mifconv/group/ReleaseNotes_Mifconv.txt	Fri Apr 16 15:32:00 2010 +0300
@@ -1,7 +1,7 @@
 ===============================================================================
 
-RELEASE NOTES - MIFCONV v3.1.7
-RELEASED 10th July 2009 
+RELEASE NOTES - MIFCONV v3.2.0
+RELEASED 24th February 2010 
 
 SUPPORTS S60 3.2+
 
@@ -21,19 +21,16 @@
   ABLD build system and FLM syntax for SBSv2 build system
 - Generating MIF files from SVG/SVGB icon sources and BMP file ids
 - Converting SVG to SVGB with the Svgtbinencode utility
-- Generating MBM files with the Bmconv utility
+- Generating MBM files (alternatively with Bmconv utility given with -B parameter)
 - Generating icon id enumeration MBG header files from the given source files
 
 ===============================================================================
 
-What's New in v3.1.7
+What's New in v3.2.0
 ====================
-- Fix: MIF-file is created also when no input files are given.
-- Fix: Correct build directory used with mifconv.flm.
-- Fix: MBM-file is included in RELEASABLES macro in mifconv.flm.
-- Fix: '/' is not a valid option prefix in Linux. Only '-' is allowed.
-- Change: If SBS_BUILD_DIR environment variable is defined, it is used as 
-  a base of temporary icon folder.
+- Change: Removed dependencies to BMCONV tool by adding the BMCONV encoding 
+  functionality as a part of MifConv functionality. External BMCONV tool can still 
+  be used by giving -B parameter.
 
 ===============================================================================
 
@@ -59,6 +56,7 @@
 
 Known Issues:
 =============
+- There must not be any spaces in a path given with -B parameter
 - Depth parameter must always be given for each bitmap
 - Heavier components, such as avkon2.mif, are not supported in ABLD build
   system due to restrictions in GNU make in the SDK
@@ -70,6 +68,15 @@
 Version History:
 ================
 
+Version 3.1.7 - 10th July 2009
+====================
+- Fix: MIF-file is created also when no input files are given.
+- Fix: Correct build directory used with mifconv.flm.
+- Fix: MBM-file is included in RELEASABLES macro in mifconv.flm.
+- Fix: '/' is not a valid option prefix in Linux. Only '-' is allowed.
+- Change: If SBS_BUILD_DIR environment variable is defined, it is used as 
+  a base of temporary icon folder.
+
 Version 3.1.6 - 22nd June 2009
 ------------------------------
 - Fix: Mifconv.xml updated to schema version 2.0
@@ -136,7 +143,7 @@
 
 ===============================================================================
 
-Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 All rights reserved.
 
 This component and the accompanying materials are made available
--- a/gfxconversion/mifconv/group/mifconv.mmp	Tue Feb 02 01:11:11 2010 +0200
+++ b/gfxconversion/mifconv/group/mifconv.mmp	Fri Apr 16 15:32:00 2010 +0300
@@ -35,4 +35,7 @@
 SOURCE                      mifconv_mifconverter.cpp
 SOURCE                      mifconv_sourcefile.cpp
 SOURCE                      mifconv_util.cpp
-
+SOURCE                      mifconv_mbmgenerator.cpp
+SOURCE                      mifconv_mbmgenerator_pbmcomp.cpp
+SOURCE                      mifconv_mbmgenerator_bmtopbm.cpp
+SOURCE                      mifconv_mbmgenerator_rgb.cpp
\ No newline at end of file
--- a/gfxconversion/mifconv/inc/mifconv.h	Tue Feb 02 01:11:11 2010 +0200
+++ b/gfxconversion/mifconv/inc/mifconv.h	Fri Apr 16 15:32:00 2010 +0300
@@ -38,9 +38,9 @@
 using namespace MifConvDefs;
 
 // Mifconv version
-static const MifConvString MifConvVersion("3.1.7");
-static const MifConvString MifConvDate("10th July 2009");
-static const MifConvString MifConvYears("2009");
+static const MifConvString MifConvVersion("3.2.0");
+static const MifConvString MifConvDate("24th February 2010");
+static const MifConvString MifConvYears("2010");
 
 // Mifconv return values:
 #define MIFCONV_ERROR       1
--- a/gfxconversion/mifconv/inc/mifconv_bitmapconverter.h	Tue Feb 02 01:11:11 2010 +0200
+++ b/gfxconversion/mifconv/inc/mifconv_bitmapconverter.h	Fri Apr 16 15:32:00 2010 +0300
@@ -60,10 +60,23 @@
 	virtual void CleanupTempFiles();
 
     /**
-     * Runs external bmconv application, which builds the .mbm file.     
+     * Runs external bmconv application, which builds the .mbm file.
+     * @param bmconvPath location of bmconv
+     */
+    void RunExternalBmconv( const MifConvString& aBmconvPath );
+       
+    /**
+     * Check first from argument manager if palette name has been given.
+     * If not, use default palette file name.
      */
-    void RunBmconv();
-
+    const MifConvString MifConvBitmapConverter::GetPaletteFileName();
+    
+    /**
+     * Returns defaulta palette file name.
+     * @param aBuf used to return the reference constant.
+     */
+    const MifConvString& DefaultPaletteFileName(MifConvString& aBuf);
+    
     /**
      * Creates and initializes the temporary file.     
      */
@@ -74,18 +87,12 @@
      * @param stream file stream for temporary file
      * @param bmpFile Source file object representing the bitmap file.
      */
-    void AppendBmpToTempFile(fstream& stream, const MifConvSourceFile& bmpFile);
+    void AppendBmpToTempFile(fstream& aStream, const MifConvSourceFile& aBmpFile);
 
-    /**
-     * Returns the default path for the external bmconv executable.
-     * @return Default bmconv path.
-     */
-    const MifConvString& GetDefaultBmConvPath();
 private:
-    
+        
     MifConvString iTempDir;
     MifConvString iTempFilename;
-    MifConvString iDefaultBmConvPath;
     MifConvString iTargetFilename;
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gfxconversion/mifconv/inc/mifconv_mbmgenerator.h	Fri Apr 16 15:32:00 2010 +0300
@@ -0,0 +1,266 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  Mifconv's bitmap converters class.
+*
+*/
+
+
+#ifndef __MIFCONVMBMGENERATOR_H__
+#define __MIFCONVMBMGENERATOR_H__
+
+#include "mifconv.h"
+#include "mifconv_util.h"
+
+#ifdef __linux__
+    #define GNUPACK __attribute__((packed)) 
+    #define OPTCHAR '-'
+    /* on Linux the '/' optchar cannot be supported as filenames can start with '/'. */
+    #define ALTERNATE_OPTCHAR '-'
+#else
+    #define GNUPACK
+    #define OPTCHAR '-' 
+    #define ALTERNATE_OPTCHAR '/'
+#endif
+
+const long int KWriteOnceFileStoreUid=268435511;
+const long int KCBitwiseBitmapUid=268435520;
+const long int KMultiBitmapRomImageUid=268435521;
+const long int KMultiBitmapFileImageUid=268435522;
+const long int KMultiBitmapFileImageChecksum=1194943545;
+
+enum TBitmapColor
+    {
+    EMonochromeBitmap,
+    EColorBitmap,
+    EColorBitmapAlpha,  
+    EColorBitmapUndefined   
+    };
+
+struct TBitmapInfoHeader
+    {
+    unsigned long biSize;
+    long biWidth;
+    long biHeight;
+    unsigned short biPlanes;
+    unsigned short biBitCount;
+    unsigned long biCompression;
+    unsigned long biSizeImage;
+    long biXPelsPerMeter;
+    long biYPelsPerMeter;
+    unsigned long biClrUsed;
+    unsigned long biClrImportant;
+    };
+
+#ifndef __linux__ 
+#include <pshpack2.h>
+#endif 
+
+enum Errors
+    {
+    NoCompression=-1,
+    NoError=0,
+    NoMemory,
+    Files,
+    SourceFile,
+    DestFile,
+    OutOfRange,
+    TooManyArgs,
+    UnknownCompression,
+    CompressionError,
+    DecompressionError,
+    Bpp,
+    PaletteFile,
+    PaletteSupportNotImplemented,
+    AlphaFiles,
+    AlphaDimensions,
+    AlphaBpp
+    };
+
+/** 
+Defines the types of file compression. 
+*/
+enum TBitmapfileCompression
+    {
+    /** Bitmap file is not compressed. */
+    ENoBitmapCompression=0,
+    /** File is compressed using run-length encoding compression. */
+    EByteRLECompression,
+    /** File is compressed using twelve bit run-length encoding compression. */
+    ETwelveBitRLECompression,
+    /** File is compressed using sixteen bit run-length encoding compression. */
+    ESixteenBitRLECompression,
+    /** File is compressed using twenty four bit run-length encoding compression. */
+    ETwentyFourBitRLECompression,
+    /** File is compressed using unsigned thirty two bit run-length encoding compression. */
+    EThirtyTwoUBitRLECompression,
+    /** File is compressed using unsigned thirty two bit run-length encoding compression and includes an alpha channel. */
+    EThirtyTwoABitRLECompression,
+    /** Insert new compression types here */
+    ERLECompressionLast = 255
+    };
+
+struct SEpocBitmapHeader
+/** Contains information about the bitmap when streaming bitmaps to stores. */
+    {
+    /** The size of the bitmap data, in bytes. */
+    long iBitmapSize;
+    /** The size of the structure in which the bitmap data is stored. */
+    long iStructSize;
+    long iWidthInPixels;
+    long iHeightInPixels;
+    long iWidthInTwips;
+    long iHeightInTwips;
+    /** The bitmaps number of bits per pixel */
+    long iBitsPerPixel;
+    /** Whether or not the bitmap is colour. A true value means that the bitmap 
+    is colour. */
+    TBitmapColor iColor;
+    /** The number of entries in the bitmap's palette. */
+    long iPaletteEntries;   // always 0 in current implementations
+    /** The type of compression used to store the bitmap. */
+    TBitmapfileCompression iCompression;
+    };
+
+#ifndef __linux__ 
+#include <pshpack2.h>
+#endif 
+
+struct TBitmapFileHeader
+    {
+    unsigned short bfType;
+    unsigned long bfSize;
+    unsigned short bfReserved1;
+    unsigned short bfReserved2;
+    unsigned long bfOffBits;
+    } GNUPACK;
+#ifndef __linux__ 
+#include <poppack.h>
+#endif 
+    
+struct TRgbTriple
+    {
+    unsigned char rgbtBlue;
+    unsigned char rgbtGreen;
+    unsigned char rgbtRed;
+    } GNUPACK;
+#ifndef __linux__ 
+#include <poppack.h>
+#endif 
+
+class TRgb
+/** 
+24-bit RGB colour value with 8 bits each for red, green and blue.
+
+All Graphics drawing functions are specified in terms of a 32-bit TRgb colour 
+containing the three colour values plus 8 unused bits. For hardware which 
+does not support 24-bit colour, a mapping from TRgb to display colours is 
+performed. 
+
+The supported display modes are enumerated in the TDisplayMode type. In each 
+display mode a unique index can represent each physical colours supported, 
+and which can be mapped onto a full RGB value. The mappings are as follows: 
+
+16-colour displays use the EGA colour set: black, white, and then both light 
+and dark versions of grey, red, green, blue, cyan, magenta and yellow
+
+256-colour displays support 216 colours made up of 6x6x6 RGB values, each 
+containing all possible multiples of 51 for R,G,B values. Additionally, all 
+remaining 10 shades of pure red, green, blue and grey are represented, by 
+adding all remaining multiples of 17. This use of 256 colours is sometimes 
+known as the Netscape colour cube.
+
+4096-colour displays effectively support RGB values with 4 bits per primary 
+colour
+
+64k-colour displays effectively support RGB values with 5 bits allocated to 
+red, 6 to green and 5 to blue
+
+16 million-colour displays support true colour with 8 bits allocated to each 
+primary colour
+
+@see TDisplayMode
+@see DynamicPalette 
+*/
+    {
+public:
+    TRgb();
+    TRgb(long unsigned int val);
+    TRgb(int aRed,int aGreen,int aBlue);
+    TRgb &operator=(const TRgb& aColor);
+    int operator==(const TRgb& aColor);
+    int Difference(const TRgb& col) const;
+    int Gray2() const;
+    int Gray4() const;
+    int Gray16() const;
+    int Gray256() const;
+    int Color16() const;
+    int Color256() const;
+    int Color4K() const;
+    int Color64K() const;
+    long int Color16M() const;
+    static TRgb Gray2(int aGray2);
+    static TRgb Gray4(int aGray4);
+    static TRgb Gray16(int aGray16);
+    static TRgb Gray256(int aGray256);
+    static TRgb Color16(int aColor16);
+    static TRgb Color256(int aColor256);
+    static TRgb Color4K(int aColor64K);
+    static TRgb Color64K(int aColor64K);
+    static TRgb Color16M(long int aColor16M);
+public:
+    unsigned char iRed;
+    unsigned char iGreen;
+    unsigned char iBlue;
+    unsigned char iSpare;
+    };
+
+/**
+ * Converter class for converting .bmp files to .mbm file.
+ */
+class BmConv
+{
+public:
+
+    /**
+     * Default constructor
+     * @param aSourcefilenames Source file names to be compiled.
+     */ 
+    BmConv(MifConvSourceFileList aSourcefilenames);
+
+    /**
+     * Destructor
+     */
+    ~BmConv();
+   
+    /**
+     * Compile source files given in constructor to destination file using a given palette.
+     * @param aDestfilename Location of destination file.
+     * @param aPaletteFilename Location of palette file.
+     */
+    int Compile(const MifConvString& aDestfilename, const MifConvString& aPaletteFilename);
+
+protected:
+
+    MifConvString ErrorMessage(int aErrorNumber, MifConvString aDestfile, bool aDestCreated);
+    void Report(int aError);
+    
+private:
+    
+    /**
+     * List os source files.
+     */
+    MifConvSourceFileList iSourcefilenames;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gfxconversion/mifconv/inc/mifconv_mbmgenerator_bmtopbm.h	Fri Apr 16 15:32:00 2010 +0300
@@ -0,0 +1,53 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+#ifndef __MIFCONVMBMGENERATORBMTOPBM_H__
+#define __MIFCONVMBMGENERATORBMTOPBM_H__
+
+#include "mifconv_mbmgenerator.h"
+#include "mifconv.h"
+
+struct TRgbQuad
+    {
+    unsigned char iBlue;
+    unsigned char iGreen;
+    unsigned char iRed;
+    unsigned char iReserved;
+    };
+
+class BitmapLoader
+    {
+public:
+    BitmapLoader();
+    ~BitmapLoader();
+    int LoadBitmap(MifConvSourceFile& aFileName,int aBpp,TBitmapColor aColor,SEpocBitmapHeader*& aPbm);
+private:
+    int DoLoad(const char* aFileName);
+    int DoLoadAlpha(MifConvString& aAlphaFileName);
+    int DoConvert(int aBpp,TBitmapColor aColor,SEpocBitmapHeader*& aPbm);
+    TRgb GetBmpPixel(long aXCoord,long aYCoord);
+    unsigned char GetAlphaPixel(long aXCoord,long aYCoord);
+private:
+    MifConvSourceFile* iSourceFile;
+    TBitmapInfoHeader iBmpHeader;
+    int iNumBmpColors;
+    TRgbQuad* iBmpColors;
+    char* iBmpBits;
+    char* iAlphaBits;
+    };
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gfxconversion/mifconv/inc/mifconv_mbmgenerator_pbmcomp.h	Fri Apr 16 15:32:00 2010 +0300
@@ -0,0 +1,76 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  
+*
+*/
+
+
+#ifndef __MIFCONVMBMGENERATORPBMCOMP_H__
+#define __MIFCONVMBMGENERATORPBMCOMP_H__
+
+#include "mifconv_mbmgenerator.h"
+#include "mifconv_util.h"
+
+class BitmapCompiler
+/**
+Historical note - Pbm is an abbreviation for "Symbian Bitmap"
+*/
+    {
+public:
+    BitmapCompiler(MifConvSourceFileList aSourcefilenames);
+    ~BitmapCompiler();
+    int Compile(const MifConvString& aDestfilename, const MifConvString& aPaletteFilename);
+private:
+    int AllocatePbmSourcesArray();
+    int LoadSourcefiles();
+    int FileImage();
+    int WriteFileheader();
+    int WriteFilebitmap(SEpocBitmapHeader* aPbm);
+    int WriteHeadStream();
+    int LoadPalette(const char* aPaletteFilename);
+    void CalculateInversePalette();
+    int CompressBitmap(SEpocBitmapHeader*& aPbm);
+    int CompressByteData(char*& aDest,char* aSrce,int aSize);
+    int WriteCompressedByteData(char*& aDest,char* aData,int aLength, const char* aDestEnd);
+    int WriteCompressedByteValues(char*& aDest,char aValue,int aLength, const char* aDestEnd);
+    int CompressTwelveBitData(char*& aDest,char* aSrce,int aSizeInBytes);
+    int WriteCompressedTwelveBitData(unsigned short*& aDest,unsigned short aData,int aLength);
+    int CompressSixteenBitData(char*& aDest,char* aSrce,int aSize);
+    int WriteCompressedSixteenBitData(char*& aDest,unsigned short* aData,int aLength, const char* aDestEnd);
+    int WriteCompressedSixteenBitValues(char*& aDest,unsigned short aValue,int aLength, const char* aDestEnd);
+    int CompressTwentyFourBitData(char*& aDest,char* aSrce,int aSizeInBytes);
+    int WriteCompressedTwentyFourBitData(char*& aDest,char* aData,int aLength, const char* aDestEnd);
+    int WriteCompressedTwentyFourBitValues(char*& aDest,char aComponent1,char aComponent2,char aComponent3,int aLength, const char* aDestEnd);
+    int CompressThirtyTwoUBitData(char*& aDest,char* aSrce,int aSizeInBytes);
+    int WriteCompressedThirtyTwoUBitData(char*& aDest,char* aData, int aLength, const char* aDestEnd);
+    int WriteCompressedThirtyTwoUBitValues(char*& aDest,char aComponent1, char aComponent2,char aComponent3, int aLength, const char* aDestEnd);
+    int TrueColorPointerCompare(char* aColorPointer,char aComponent1,char aComponent2,char aComponent3);
+    int CompressThirtyTwoABitData(char*& aDest,char* aSrce,int aSizeInBytes);
+    int WriteCompressedThirtyTwoABitData(char*& aDest,char* aData,int aLength,const char* aDestEnd);
+    int WriteCompressedThirtyTwoABitValues(char*& aDest,char aComponent1,char aComponent2,char aComponent3,char aComponent4,int aLength,const char* aDestEnd);
+    int ColorAlphaPointerCompare(char* aColorPointer,char aComponent1,char aComponent2,char aComponent3,char aComponent4);
+    int ReadHexString(char aHexBuf[10],char*& aDataPtr,char* aDataPtrLimit);
+    int HexToInt(char aHighNibble,char aLowNibble);
+    int HexToInt(char aNibble);
+private:
+    fstream iDestFile;
+    MifConvSourceFileList iSourcefilenames;
+    SEpocBitmapHeader** iPbmSources;
+    int iNumSources;
+    int iDefaultPalette;
+    TRgb iPalette[256];
+    char iInversePalette[4096];
+    };
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gfxconversion/mifconv/inc/mifconv_mbmgenerator_rgb.h	Fri Apr 16 15:32:00 2010 +0300
@@ -0,0 +1,364 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+const unsigned char color16inverse[512] = {
+	0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x05, 0x05,	0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x05, 0x05,
+	0x04, 0x04, 0x01, 0x03, 0x03, 0x03, 0x05, 0x05,	0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x05,
+	0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x06,	0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x06, 0x06,
+	0x07, 0x07, 0x07, 0x03, 0x03, 0x06, 0x06, 0x06,	0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06, 0x06,
+	0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x05, 0x05,	0x00, 0x00, 0x01, 0x02, 0x02, 0x02, 0x05, 0x05,
+	0x04, 0x01, 0x01, 0x01, 0x03, 0x03, 0x05, 0x05,	0x04, 0x04, 0x01, 0x03, 0x03, 0x03, 0x03, 0x05,
+	0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x06,	0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x06, 0x06,
+	0x07, 0x07, 0x07, 0x03, 0x03, 0x06, 0x06, 0x06,	0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06, 0x06,
+	0x0c, 0x0c, 0x01, 0x0b, 0x0b, 0x0b, 0x05, 0x05,	0x0c, 0x01, 0x01, 0x01, 0x0b, 0x0b, 0x05, 0x05,
+	0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x05,	0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x05,
+	0x0d, 0x0d, 0x01, 0x01, 0x03, 0x0e, 0x0e, 0x06,	0x0d, 0x0d, 0x01, 0x01, 0x0e, 0x0e, 0x0e, 0x06,
+	0x07, 0x07, 0x01, 0x01, 0x0e, 0x0e, 0x06, 0x06,	0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06, 0x06,
+	0x0c, 0x0c, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x05,	0x0c, 0x0c, 0x01, 0x0b, 0x0b, 0x0b, 0x0b, 0x05,
+	0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x05,	0x0d, 0x0d, 0x01, 0x01, 0x01, 0x0e, 0x0e, 0x0e,
+	0x0d, 0x0d, 0x01, 0x01, 0x0e, 0x0e, 0x0e, 0x0e,	0x0d, 0x0d, 0x01, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
+	0x0d, 0x0d, 0x01, 0x0e, 0x0e, 0x0e, 0x0e, 0x06,	0x07, 0x07, 0x07, 0x0e, 0x0e, 0x0e, 0x06, 0x06,
+	0x0c, 0x0c, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x08,	0x0c, 0x0c, 0x0b, 0x0b, 0x0b, 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, 0x0a, 0x0a, 0x0f, 0x0f, 0x0f, 0x0f,
+	0x09, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08,	0x09, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08,
+	0x09, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08,	0x09, 0x09, 0x09, 0x0e, 0x0e, 0x0e, 0x08, 0x08,
+	0x0a, 0x0a, 0x0a, 0x0e, 0x0e, 0x0e, 0x0f, 0x0f,	0x0a, 0x0a, 0x0a, 0x0e, 0x0e, 0x0e, 0x0f, 0x0f,
+	0x0a, 0x0a, 0x0a, 0x0a, 0x0f, 0x0f, 0x0f, 0x0f,	0x0a, 0x0a, 0x0a, 0x0a, 0x0f, 0x0f, 0x0f, 0x0f
+	};
+
+const long unsigned int color256array[256] = {
+	0x00000000,	0x00000033,	0x00000066,	0x00000099,	0x000000cc,	0x000000ff,
+	0x00003300,	0x00003333,	0x00003366,	0x00003399,	0x000033cc,	0x000033ff,
+	0x00006600,	0x00006633,	0x00006666,	0x00006699,	0x000066cc,	0x000066ff,
+	0x00009900,	0x00009933,	0x00009966,	0x00009999,	0x000099cc,	0x000099ff,
+	0x0000cc00,	0x0000cc33,	0x0000cc66,	0x0000cc99,	0x0000cccc,	0x0000ccff,
+	0x0000ff00,	0x0000ff33,	0x0000ff66,	0x0000ff99,	0x0000ffcc,	0x0000ffff,
+
+	0x00330000,	0x00330033,	0x00330066,	0x00330099,	0x003300cc,	0x003300ff,
+	0x00333300,	0x00333333,	0x00333366,	0x00333399,	0x003333cc,	0x003333ff,
+	0x00336600,	0x00336633,	0x00336666,	0x00336699,	0x003366cc,	0x003366ff,
+	0x00339900,	0x00339933,	0x00339966,	0x00339999,	0x003399cc,	0x003399ff,
+	0x0033cc00,	0x0033cc33,	0x0033cc66,	0x0033cc99,	0x0033cccc,	0x0033ccff,
+	0x0033ff00,	0x0033ff33,	0x0033ff66,	0x0033ff99,	0x0033ffcc,	0x0033ffff,
+
+	0x00660000,	0x00660033,	0x00660066,	0x00660099,	0x006600cc,	0x006600ff,
+	0x00663300,	0x00663333,	0x00663366,	0x00663399,	0x006633cc,	0x006633ff,
+	0x00666600,	0x00666633,	0x00666666,	0x00666699,	0x006666cc,	0x006666ff,
+	0x00669900,	0x00669933,	0x00669966,	0x00669999,	0x006699cc,	0x006699ff,
+	0x0066cc00,	0x0066cc33,	0x0066cc66,	0x0066cc99,	0x0066cccc,	0x0066ccff,
+	0x0066ff00,	0x0066ff33,	0x0066ff66,	0x0066ff99,	0x0066ffcc,	0x0066ffff,
+
+	0x00111111, 0x00222222, 0x00444444, 0x00555555, 0x00777777,
+	0x00000011, 0x00000022, 0x00000044, 0x00000055, 0x00000077,
+	0x00001100,	0x00002200,	0x00004400,	0x00005500,	0x00007700,
+	0x00110000,	0x00220000,	0x00440000,	0x00550000,	0x00770000,
+
+	0x00880000,	0x00aa0000,	0x00bb0000,	0x00dd0000,	0x00ee0000,
+	0x00008800,	0x0000aa00,	0x0000bb00,	0x0000dd00,	0x0000ee00,
+	0x00000088,	0x000000aa,	0x000000bb,	0x000000dd,	0x000000ee,
+	0x00888888, 0x00aaaaaa, 0x00bbbbbb, 0x00dddddd, 0x00eeeeee,
+
+	0x00990000,	0x00990033,	0x00990066,	0x00990099,	0x009900cc,	0x009900ff,
+	0x00993300,	0x00993333,	0x00993366,	0x00993399,	0x009933cc,	0x009933ff,
+	0x00996600,	0x00996633,	0x00996666,	0x00996699,	0x009966cc,	0x009966ff,
+	0x00999900,	0x00999933,	0x00999966,	0x00999999,	0x009999cc,	0x009999ff,
+	0x0099cc00,	0x0099cc33,	0x0099cc66,	0x0099cc99,	0x0099cccc,	0x0099ccff,
+	0x0099ff00,	0x0099ff33,	0x0099ff66,	0x0099ff99,	0x0099ffcc,	0x0099ffff,
+
+	0x00cc0000,	0x00cc0033,	0x00cc0066,	0x00cc0099,	0x00cc00cc,	0x00cc00ff,
+	0x00cc3300,	0x00cc3333,	0x00cc3366,	0x00cc3399,	0x00cc33cc,	0x00cc33ff,
+	0x00cc6600,	0x00cc6633,	0x00cc6666,	0x00cc6699,	0x00cc66cc,	0x00cc66ff,
+	0x00cc9900,	0x00cc9933,	0x00cc9966,	0x00cc9999,	0x00cc99cc,	0x00cc99ff,
+	0x00cccc00,	0x00cccc33,	0x00cccc66,	0x00cccc99,	0x00cccccc,	0x00ccccff,
+	0x00ccff00,	0x00ccff33,	0x00ccff66,	0x00ccff99,	0x00ccffcc,	0x00ccffff,
+
+	0x00ff0000,	0x00ff0033,	0x00ff0066,	0x00ff0099,	0x00ff00cc,	0x00ff00ff,
+	0x00ff3300,	0x00ff3333,	0x00ff3366,	0x00ff3399,	0x00ff33cc,	0x00ff33ff,
+	0x00ff6600,	0x00ff6633,	0x00ff6666,	0x00ff6699,	0x00ff66cc,	0x00ff66ff,
+	0x00ff9900,	0x00ff9933,	0x00ff9966,	0x00ff9999,	0x00ff99cc,	0x00ff99ff,
+	0x00ffcc00,	0x00ffcc33,	0x00ffcc66,	0x00ffcc99,	0x00ffcccc,	0x00ffccff,
+	0x00ffff00,	0x00ffff33,	0x00ffff66,	0x00ffff99,	0x00ffffcc,	0x00ffffff
+	};
+
+const unsigned char color256inverse[4096] = {
+	0x00, 0x71, 0x72, 0x01, 0x73, 0x74, 0x02, 0x75,	0x8a, 0x03, 0x8b, 0x8c, 0x04, 0x8d, 0x8e, 0x05,
+	0x76, 0x6c, 0x72, 0x01, 0x73, 0x74, 0x02, 0x75,	0x8a, 0x03, 0x8b, 0x8c, 0x04, 0x8d, 0x8e, 0x05,
+	0x77, 0x77, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08,	0x09, 0x09, 0x09, 0x0a, 0x0a, 0x0a, 0x0b, 0x0b,
+	0x06, 0x06, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08,	0x09, 0x09, 0x09, 0x0a, 0x0a, 0x0a, 0x0b, 0x0b,
+	0x78, 0x78, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08,	0x09, 0x09, 0x09, 0x0a, 0x0a, 0x0a, 0x0b, 0x0b,
+	0x79, 0x79, 0x0d, 0x0d, 0x0d, 0x0e, 0x0e, 0x0e,	0x0f, 0x0f, 0x0f, 0x10, 0x10, 0x10, 0x11, 0x11,
+	0x0c, 0x0c, 0x0d, 0x0d, 0x0d, 0x0e, 0x0e, 0x0e,	0x0f, 0x0f, 0x0f, 0x10, 0x10, 0x10, 0x11, 0x11,
+	0x7a, 0x7a, 0x0d, 0x0d, 0x0d, 0x0e, 0x0e, 0x0e,	0x0f, 0x0f, 0x0f, 0x10, 0x10, 0x10, 0x11, 0x11,
+	0x85, 0x85, 0x13, 0x13, 0x13, 0x14, 0x14, 0x14,	0x15, 0x15, 0x15, 0x16, 0x16, 0x16, 0x17, 0x17,
+	0x12, 0x12, 0x13, 0x13, 0x13, 0x14, 0x14, 0x14,	0x15, 0x15, 0x15, 0x16, 0x16, 0x16, 0x17, 0x17,
+	0x86, 0x86, 0x13, 0x13, 0x13, 0x14, 0x14, 0x14,	0x15, 0x15, 0x15, 0x16, 0x16, 0x16, 0x17, 0x17,
+	0x87, 0x87, 0x19, 0x19, 0x19, 0x1a, 0x1a, 0x1a,	0x1b, 0x1b, 0x1b, 0x1c, 0x1c, 0x1c, 0x1d, 0x1d,
+	0x18, 0x18, 0x19, 0x19, 0x19, 0x1a, 0x1a, 0x1a,	0x1b, 0x1b, 0x1b, 0x1c, 0x1c, 0x1c, 0x1d, 0x1d,
+	0x88, 0x88, 0x19, 0x19, 0x19, 0x1a, 0x1a, 0x1a,	0x1b, 0x1b, 0x1b, 0x1c, 0x1c, 0x1c, 0x1d, 0x1d,
+	0x89, 0x89, 0x1f, 0x1f, 0x1f, 0x20, 0x20, 0x20,	0x21, 0x21, 0x21, 0x22, 0x22, 0x22, 0x23, 0x23,
+	0x1e, 0x1e, 0x1f, 0x1f, 0x1f, 0x20, 0x20, 0x20,	0x21, 0x21, 0x21, 0x22, 0x22, 0x22, 0x23, 0x23,
+	0x7b, 0x6c, 0x72, 0x01, 0x73, 0x74, 0x02, 0x75,	0x8a, 0x03, 0x8b, 0x8c, 0x04, 0x8d, 0x8e, 0x05,
+	0x6c, 0x6c, 0x6c, 0x01, 0x73, 0x74, 0x02, 0x75,	0x8a, 0x03, 0x8b, 0x8c, 0x04, 0x8d, 0x8e, 0x05,
+	0x77, 0x6c, 0x6d, 0x07, 0x07, 0x08, 0x08, 0x08,	0x09, 0x09, 0x09, 0x0a, 0x0a, 0x0a, 0x0b, 0x0b,
+	0x06, 0x06, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08,	0x09, 0x09, 0x09, 0x0a, 0x0a, 0x0a, 0x0b, 0x0b,
+	0x78, 0x78, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08,	0x09, 0x09, 0x09, 0x0a, 0x0a, 0x0a, 0x0b, 0x0b,
+	0x79, 0x79, 0x0d, 0x0d, 0x0d, 0x0e, 0x0e, 0x0e,	0x0f, 0x0f, 0x0f, 0x10, 0x10, 0x10, 0x11, 0x11,
+	0x0c, 0x0c, 0x0d, 0x0d, 0x0d, 0x0e, 0x0e, 0x0e,	0x0f, 0x0f, 0x0f, 0x10, 0x10, 0x10, 0x11, 0x11,
+	0x7a, 0x7a, 0x0d, 0x0d, 0x0d, 0x0e, 0x0e, 0x0e,	0x0f, 0x0f, 0x0f, 0x10, 0x10, 0x10, 0x11, 0x11,
+	0x85, 0x85, 0x13, 0x13, 0x13, 0x14, 0x14, 0x14,	0x15, 0x15, 0x15, 0x16, 0x16, 0x16, 0x17, 0x17,
+	0x12, 0x12, 0x13, 0x13, 0x13, 0x14, 0x14, 0x14,	0x15, 0x15, 0x15, 0x16, 0x16, 0x16, 0x17, 0x17,
+	0x86, 0x86, 0x13, 0x13, 0x13, 0x14, 0x14, 0x14,	0x15, 0x15, 0x15, 0x16, 0x16, 0x16, 0x17, 0x17,
+	0x87, 0x87, 0x19, 0x19, 0x19, 0x1a, 0x1a, 0x1a,	0x1b, 0x1b, 0x1b, 0x1c, 0x1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x31, 0x31, 0x32, 0x32, 0x32,	0x33, 0x33, 0x33, 0x34, 0x34, 0x34, 0x35, 0x35,
+	0x36, 0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x38,	0x39, 0x39, 0x39, 0x3a, 0x3a, 0x3a, 0x3b, 0x3b,
+	0x36, 0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x38,	0x39, 0x39, 0x39, 0x3a, 0x3a, 0x3a, 0x3b, 0x3b,
+	0x36, 0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x38,	0x39, 0x39, 0x39, 0x3a, 0x3a, 0x3a, 0x3b, 0x3b,
+	0x3c, 0x3c, 0x3d, 0x3d, 0x3d, 0x3e, 0x3e, 0x3e,	0x3f, 0x3f, 0x3f, 0x40, 0x40, 0x40, 0x41, 0x41,
+	0x3c, 0x3c, 0x3d, 0x3d, 0x3d, 0x3e, 0x3e, 0x3e,	0x3f, 0x3f, 0x3f, 0x40, 0x40, 0x40, 0x41, 0x41,
+	0x3c, 0x3c, 0x3d, 0x3d, 0x3d, 0x3e, 0x3e, 0x3e,	0x3f, 0x3f, 0x3f, 0x40, 0x40, 0x40, 0x41, 0x41,
+	0x42, 0x42, 0x43, 0x43, 0x43, 0x44, 0x44, 0x44,	0x45, 0x45, 0x45, 0x46, 0x46, 0x46, 0x47, 0x47,
+	0x42, 0x42, 0x43, 0x43, 0x43, 0x44, 0x44, 0x44,	0x45, 0x45, 0x45, 0x46, 0x46, 0x46, 0x47, 0x47,
+	0x24, 0x24, 0x25, 0x25, 0x25, 0x26, 0x26, 0x26,	0x27, 0x27, 0x27, 0x28, 0x28, 0x28, 0x29, 0x29,
+	0x24, 0x24, 0x25, 0x25, 0x25, 0x26, 0x26, 0x26,	0x27, 0x27, 0x27, 0x28, 0x28, 0x28, 0x29, 0x29,
+	0x2a, 0x2a, 0x6d, 0x2b, 0x2b, 0x2c, 0x2c, 0x2c,	0x2d, 0x2d, 0x2d, 0x2e, 0x2e, 0x2e, 0x2f, 0x2f,
+	0x2a, 0x2a, 0x2b, 0x2b, 0x2b, 0x2c, 0x2c, 0x2c,	0x2d, 0x2d, 0x2d, 0x2e, 0x2e, 0x2e, 0x2f, 0x2f,
+	0x2a, 0x2a, 0x2b, 0x2b, 0x6e, 0x2c, 0x2c, 0x2c,	0x2d, 0x2d, 0x2d, 0x2e, 0x2e, 0x2e, 0x2f, 0x2f,
+	0x30, 0x30, 0x31, 0x31, 0x31, 0x32, 0x32, 0x32,	0x33, 0x33, 0x33, 0x34, 0x34, 0x34, 0x35, 0x35,
+	0x30, 0x30, 0x31, 0x31, 0x31, 0x32, 0x32, 0x32,	0x33, 0x33, 0x33, 0x34, 0x34, 0x34, 0x35, 0x35,
+	0x30, 0x30, 0x31, 0x31, 0x31, 0x32, 0x32, 0x32,	0x33, 0x33, 0x33, 0x34, 0x34, 0x34, 0x35, 0x35,
+	0x36, 0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x38,	0x39, 0x39, 0x39, 0x3a, 0x3a, 0x3a, 0x3b, 0x3b,
+	0x36, 0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x38,	0x39, 0x39, 0x39, 0x3a, 0x3a, 0x3a, 0x3b, 0x3b,
+	0x36, 0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x38,	0x39, 0x39, 0x39, 0x3a, 0x3a, 0x3a, 0x3b, 0x3b,
+	0x3c, 0x3c, 0x3d, 0x3d, 0x3d, 0x3e, 0x3e, 0x3e,	0x3f, 0x3f, 0x3f, 0x40, 0x40, 0x40, 0x41, 0x41,
+	0x3c, 0x3c, 0x3d, 0x3d, 0x3d, 0x3e, 0x3e, 0x3e,	0x3f, 0x3f, 0x3f, 0x40, 0x40, 0x40, 0x41, 0x41,
+	0x3c, 0x3c, 0x3d, 0x3d, 0x3d, 0x3e, 0x3e, 0x3e,	0x3f, 0x3f, 0x3f, 0x40, 0x40, 0x40, 0x41, 0x41,
+	0x42, 0x42, 0x43, 0x43, 0x43, 0x44, 0x44, 0x44,	0x45, 0x45, 0x45, 0x46, 0x46, 0x46, 0x47, 0x47,
+	0x42, 0x42, 0x43, 0x43, 0x43, 0x44, 0x44, 0x44,	0x45, 0x45, 0x45, 0x46, 0x46, 0x46, 0x47, 0x47,
+	0x7d, 0x7d, 0x25, 0x25, 0x25, 0x26, 0x26, 0x26,	0x27, 0x27, 0x27, 0x28, 0x28, 0x28, 0x29, 0x29,
+	0x7d, 0x7d, 0x25, 0x25, 0x25, 0x26, 0x26, 0x26,	0x27, 0x27, 0x27, 0x28, 0x28, 0x28, 0x29, 0x29,
+	0x2a, 0x2a, 0x6d, 0x2b, 0x6e, 0x2c, 0x2c, 0x2c,	0x2d, 0x2d, 0x2d, 0x2e, 0x2e, 0x2e, 0x2f, 0x2f,
+	0x2a, 0x2a, 0x2b, 0x2b, 0x6e, 0x2c, 0x2c, 0x2c,	0x2d, 0x2d, 0x2d, 0x2e, 0x2e, 0x2e, 0x2f, 0x2f,
+	0x2a, 0x2a, 0x6e, 0x6e, 0x6e, 0x6e, 0x2c, 0x2c,	0x2d, 0x2d, 0x2d, 0x2e, 0x2e, 0x2e, 0x2f, 0x2f,
+	0x30, 0x30, 0x31, 0x31, 0x6e, 0x6f, 0x32, 0x32,	0x33, 0x33, 0x33, 0x34, 0x34, 0x34, 0x35, 0x35,
+	0x30, 0x30, 0x31, 0x31, 0x31, 0x32, 0x32, 0x32,	0x33, 0x33, 0x33, 0x34, 0x34, 0x34, 0x35, 0x35,
+	0x30, 0x30, 0x31, 0x31, 0x31, 0x32, 0x32, 0x32,	0x33, 0x33, 0x33, 0x34, 0x34, 0x34, 0x35, 0x35,
+	0x36, 0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x38,	0x39, 0x39, 0x39, 0x3a, 0x3a, 0x3a, 0x3b, 0x3b,
+	0x36, 0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x38,	0x39, 0x39, 0x39, 0x3a, 0x3a, 0x3a, 0x3b, 0x3b,
+	0x36, 0x36, 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, 0x57, 0x58, 0x58, 0x58, 0x59, 0x59,
+	0x54, 0x54, 0x55, 0x55, 0x55, 0x6f, 0x56, 0x56,	0x57, 0x57, 0x57, 0x58, 0x58, 0x58, 0x59, 0x59,
+	0x54, 0x54, 0x55, 0x55, 0x55, 0x6f, 0x56, 0x70,	0x57, 0x57, 0x57, 0x58, 0x58, 0x58, 0x59, 0x59,
+	0x5a, 0x5a, 0x5b, 0x5b, 0x5b, 0x5c, 0x5c, 0x5c,	0x5d, 0x5d, 0x5d, 0x5e, 0x5e, 0x5e, 0x5f, 0x5f,
+	0x5a, 0x5a, 0x5b, 0x5b, 0x5b, 0x5c, 0x5c, 0x5c,	0x5d, 0x5d, 0x5d, 0x5e, 0x5e, 0x5e, 0x5f, 0x5f,
+	0x5a, 0x5a, 0x5b, 0x5b, 0x5b, 0x5c, 0x5c, 0x5c,	0x5d, 0x5d, 0x5d, 0x5e, 0x5e, 0x5e, 0x5f, 0x5f,
+	0x60, 0x60, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62,	0x63, 0x63, 0x63, 0x64, 0x64, 0x64, 0x65, 0x65,
+	0x60, 0x60, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62,	0x63, 0x63, 0x63, 0x64, 0x64, 0x64, 0x65, 0x65,
+	0x60, 0x60, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62,	0x63, 0x63, 0x63, 0x64, 0x64, 0x64, 0x65, 0x65,
+	0x66, 0x66, 0x67, 0x67, 0x67, 0x68, 0x68, 0x68,	0x69, 0x69, 0x69, 0x6a, 0x6a, 0x6a, 0x6b, 0x6b,
+	0x66, 0x66, 0x67, 0x67, 0x67, 0x68, 0x68, 0x68,	0x69, 0x69, 0x69, 0x6a, 0x6a, 0x6a, 0x6b, 0x6b,
+	0x48, 0x48, 0x49, 0x49, 0x49, 0x4a, 0x4a, 0x4a,	0x4b, 0x4b, 0x4b, 0x4c, 0x4c, 0x4c, 0x4d, 0x4d,
+	0x48, 0x48, 0x49, 0x49, 0x49, 0x4a, 0x4a, 0x4a,	0x4b, 0x4b, 0x4b, 0x4c, 0x4c, 0x4c, 0x4d, 0x4d,
+	0x4e, 0x4e, 0x4f, 0x4f, 0x4f, 0x50, 0x50, 0x50,	0x51, 0x51, 0x51, 0x52, 0x52, 0x52, 0x53, 0x53,
+	0x4e, 0x4e, 0x4f, 0x4f, 0x4f, 0x50, 0x50, 0x50,	0x51, 0x51, 0x51, 0x52, 0x52, 0x52, 0x53, 0x53,
+	0x4e, 0x4e, 0x4f, 0x4f, 0x4f, 0x50, 0x50, 0x50,	0x51, 0x51, 0x51, 0x52, 0x52, 0x52, 0x53, 0x53,
+	0x54, 0x54, 0x55, 0x55, 0x55, 0x6f, 0x56, 0x56,	0x57, 0x57, 0x57, 0x58, 0x58, 0x58, 0x59, 0x59,
+	0x54, 0x54, 0x55, 0x55, 0x55, 0x56, 0x56, 0x56,	0x57, 0x57, 0x57, 0x58, 0x58, 0x58, 0x59, 0x59,
+	0x54, 0x54, 0x55, 0x55, 0x55, 0x56, 0x56, 0x70,	0x57, 0x57, 0x57, 0x58, 0x58, 0x58, 0x59, 0x59,
+	0x5a, 0x5a, 0x5b, 0x5b, 0x5b, 0x5c, 0x5c, 0x5c,	0x5d, 0x5d, 0x5d, 0x5e, 0x5e, 0x5e, 0x5f, 0x5f,
+	0x5a, 0x5a, 0x5b, 0x5b, 0x5b, 0x5c, 0x5c, 0x5c,	0x5d, 0x5d, 0x5d, 0x5e, 0x5e, 0x5e, 0x5f, 0x5f,
+	0x5a, 0x5a, 0x5b, 0x5b, 0x5b, 0x5c, 0x5c, 0x5c,	0x5d, 0x5d, 0x5d, 0x5e, 0x5e, 0x5e, 0x5f, 0x5f,
+	0x60, 0x60, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62,	0x63, 0x63, 0x63, 0x64, 0x64, 0x64, 0x65, 0x65,
+	0x60, 0x60, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62,	0x63, 0x63, 0x63, 0x64, 0x64, 0x64, 0x65, 0x65,
+	0x60, 0x60, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62,	0x63, 0x63, 0x63, 0x64, 0x64, 0x64, 0x65, 0x65,
+	0x66, 0x66, 0x67, 0x67, 0x67, 0x68, 0x68, 0x68,	0x69, 0x69, 0x69, 0x6a, 0x6a, 0x6a, 0x6b, 0x6b,
+	0x66, 0x66, 0x67, 0x67, 0x67, 0x68, 0x68, 0x68,	0x69, 0x69, 0x69, 0x6a, 0x6a, 0x6a, 0x6b, 0x6b,
+	0x7f, 0x7f, 0x49, 0x49, 0x49, 0x4a, 0x4a, 0x4a,	0x4b, 0x4b, 0x4b, 0x4c, 0x4c, 0x4c, 0x4d, 0x4d,
+	0x7f, 0x7f, 0x49, 0x49, 0x49, 0x4a, 0x4a, 0x4a,	0x4b, 0x4b, 0x4b, 0x4c, 0x4c, 0x4c, 0x4d, 0x4d,
+	0x4e, 0x4e, 0x4f, 0x4f, 0x4f, 0x50, 0x50, 0x50,	0x51, 0x51, 0x51, 0x52, 0x52, 0x52, 0x53, 0x53,
+	0x4e, 0x4e, 0x4f, 0x4f, 0x4f, 0x50, 0x50, 0x50,	0x51, 0x51, 0x51, 0x52, 0x52, 0x52, 0x53, 0x53,
+	0x4e, 0x4e, 0x4f, 0x4f, 0x4f, 0x50, 0x50, 0x50,	0x51, 0x51, 0x51, 0x52, 0x52, 0x52, 0x53, 0x53,
+	0x54, 0x54, 0x55, 0x55, 0x55, 0x6f, 0x56, 0x70,	0x57, 0x57, 0x57, 0x58, 0x58, 0x58, 0x59, 0x59,
+	0x54, 0x54, 0x55, 0x55, 0x55, 0x56, 0x56, 0x70,	0x57, 0x57, 0x57, 0x58, 0x58, 0x58, 0x59, 0x59,
+	0x54, 0x54, 0x55, 0x55, 0x55, 0x70, 0x70, 0x70,	0x70, 0x57, 0x57, 0x58, 0x58, 0x58, 0x59, 0x59,
+	0x5a, 0x5a, 0x5b, 0x5b, 0x5b, 0x5c, 0x5c, 0x70,	0x8f, 0x5d, 0x5d, 0x5e, 0x5e, 0x5e, 0x5f, 0x5f,
+	0x5a, 0x5a, 0x5b, 0x5b, 0x5b, 0x5c, 0x5c, 0x5c,	0x5d, 0x5d, 0x5d, 0x5e, 0x5e, 0x5e, 0x5f, 0x5f,
+	0x5a, 0x5a, 0x5b, 0x5b, 0x5b, 0x5c, 0x5c, 0x5c,	0x5d, 0x5d, 0x5d, 0x5e, 0x5e, 0x5e, 0x5f, 0x5f,
+	0x60, 0x60, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62,	0x63, 0x63, 0x63, 0x64, 0x64, 0x64, 0x65, 0x65,
+	0x60, 0x60, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62,	0x63, 0x63, 0x63, 0x64, 0x64, 0x64, 0x65, 0x65,
+	0x60, 0x60, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62,	0x63, 0x63, 0x63, 0x64, 0x64, 0x64, 0x65, 0x65,
+	0x66, 0x66, 0x67, 0x67, 0x67, 0x68, 0x68, 0x68,	0x69, 0x69, 0x69, 0x6a, 0x6a, 0x6a, 0x6b, 0x6b,
+	0x66, 0x66, 0x67, 0x67, 0x67, 0x68, 0x68, 0x68,	0x69, 0x69, 0x69, 0x6a, 0x6a, 0x6a, 0x6b, 0x6b,
+	0x80, 0x80, 0x80, 0x95, 0x95, 0x96, 0x96, 0x96,	0x97, 0x97, 0x97, 0x98, 0x98, 0x98, 0x99, 0x99,
+	0x80, 0x80, 0x80, 0x95, 0x95, 0x96, 0x96, 0x96,	0x97, 0x97, 0x97, 0x98, 0x98, 0x98, 0x99, 0x99,
+	0x80, 0x80, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c, 0x9c,	0x9d, 0x9d, 0x9d, 0x9e, 0x9e, 0x9e, 0x9f, 0x9f,
+	0x9a, 0x9a, 0x9b, 0x9b, 0x9b, 0x9c, 0x9c, 0x9c,	0x9d, 0x9d, 0x9d, 0x9e, 0x9e, 0x9e, 0x9f, 0x9f,
+	0x9a,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xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9,
+	0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6,	0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9,
+	0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6,	0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0x92, 0x93, 0xf9,
+	0xfa, 0xfa, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc,	0xfd, 0xfd, 0xfd, 0xfe, 0xfe, 0x93, 0x93, 0xff,
+	0xfa, 0xfa, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc,	0xfd, 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xff, 0xff
+	};
--- a/gfxconversion/mifconv/inc/mifconv_sourcefile.h	Tue Feb 02 01:11:11 2010 +0200
+++ b/gfxconversion/mifconv/inc/mifconv_sourcefile.h	Fri Apr 16 15:32:00 2010 +0300
@@ -25,6 +25,13 @@
 {
 public:
 
+    enum TCompileInfo
+        {
+        EFormatNotImportant,
+        ENokiaBitmap,
+        EThirdPartyBitmap
+        };
+    
 	/**
 	 * Default constructor
 	 */
@@ -174,6 +181,9 @@
      */
     IconDisplayMode MaskDisplayMode() const;
 
+    void SetCompileInfo(TCompileInfo aInfo);
+    void WriteCompileInfo(ostream& aOut);
+    
 protected:
  
     /**
@@ -203,6 +213,7 @@
     MifConvString iMaskFilename;
     char* iContent;
     unsigned int iContentLen;
+    TCompileInfo iInfo;
 };
 
 typedef std::vector<MifConvSourceFile> MifConvSourceFileList;
--- a/gfxconversion/mifconv/inc/mifconv_util.h	Tue Feb 02 01:11:11 2010 +0200
+++ b/gfxconversion/mifconv/inc/mifconv_util.h	Fri Apr 16 15:32:00 2010 +0300
@@ -27,6 +27,8 @@
 {
 public:
 
+    static int ByteWidth(int aPixelWidth,int aBitsPerPixel);
+    
     /**
      * Returns file extension of the given filename
      * @return String representing the file extension
--- a/gfxconversion/mifconv/makefile_templates/mifconv_step3.make	Tue Feb 02 01:11:11 2010 +0200
+++ b/gfxconversion/mifconv/makefile_templates/mifconv_step3.make	Fri Apr 16 15:32:00 2010 +0300
@@ -132,7 +132,8 @@
 
 
 ##########################################################################################
-# MBM file name resolution. BMCONV is called by mifconv.
+# MBM file name resolution. BMCONV is called by mifconv if -B is defined. Otherwise 
+# mifconv uses puilt-in logic for BMP to MBM -conversion.
 #
 
 # Check if we have any bitmap sources available
--- a/gfxconversion/mifconv/src/mifconv_argumentmanager.cpp	Tue Feb 02 01:11:11 2010 +0200
+++ b/gfxconversion/mifconv/src/mifconv_argumentmanager.cpp	Fri Apr 16 15:32:00 2010 +0300
@@ -835,7 +835,6 @@
 	{
 		return i->second.Value();
 	}
-	
 	return iDummyString;
 }
 
--- a/gfxconversion/mifconv/src/mifconv_bitmapconverter.cpp	Tue Feb 02 01:11:11 2010 +0200
+++ b/gfxconversion/mifconv/src/mifconv_bitmapconverter.cpp	Fri Apr 16 15:32:00 2010 +0300
@@ -21,9 +21,28 @@
 #include "mifconv_util.h"
 #include "mifconv_exception.h"
 #include "mifconv_argumentmanager.h"
+#include "mifconv_mbmgenerator.h"
+#include "mifconv_mbmgenerator_pbmcomp.h"
 #include <stdio.h>
+#include <sys/stat.h>
+
+using namespace std;
 
-const MifConvString BMCONV_DEFAULT_PATH(EPOC_TOOLS_PATH);
+#ifdef __linux__
+const char* DefaultPaletteFileSearchLocations[] =
+{
+    "/epoc32/include/mw/ThirdPartyBitmap.pal",
+    "/epoc32/include/middleware/ThirdPartyBitmap.pal",
+    "/epoc32/include/ThirdPartyBitmap.pal"
+};
+#else
+const char* DefaultPaletteFileSearchLocations[] =
+{
+    "\\epoc32\\include\\mw\\ThirdPartyBitmap.pal",
+    "\\epoc32\\include\\middleware\\ThirdPartyBitmap.pal",
+    "\\epoc32\\include\\ThirdPartyBitmap.pal"
+};
+#endif
 
 /**
  *
@@ -31,8 +50,8 @@
 MifConvBitmapConverter::MifConvBitmapConverter()
 {
     MifConvArgumentManager* argMgr = MifConvArgumentManager::Instance();
-	// Output file:
-	iTargetFilename = MifConvUtil::FilenameWithoutExtension(argMgr->TargetFile()) + "." + MifConvString(MBM_FILE_EXTENSION);
+    // Output file:
+    iTargetFilename = MifConvUtil::FilenameWithoutExtension(argMgr->TargetFile()) + "." + MifConvString(MBM_FILE_EXTENSION);
 }
 
 /**
@@ -55,22 +74,22 @@
  */
 void MifConvBitmapConverter::CleanupTargetFiles()
 {
-	if( MifConvUtil::FileExists(iTargetFilename) )
-	{
+    if( MifConvUtil::FileExists(iTargetFilename) )
+    {
         // Try to remove file MIFCONV_MAX_REMOVE_TRIES times, no exception in case of failure:
         MifConvUtil::RemoveFile(iTargetFilename, MIFCONV_MAX_REMOVE_TRIES, true);
-	}
+    }
 }
 
 /**
  *
  */
-void MifConvBitmapConverter::AppendFile( const MifConvSourceFile& sourcefile )
+void MifConvBitmapConverter::AppendFile( const MifConvSourceFile& aSourcefile )
 {    
-	if( MifConvUtil::FileExtension( sourcefile.Filename() ) == BMP_FILE_EXTENSION )
-	{
-		iSourceFiles.push_back( sourcefile );
-	}
+    if( MifConvUtil::FileExtension( aSourcefile.Filename() ) == BMP_FILE_EXTENSION )
+    {
+        iSourceFiles.push_back( aSourcefile );
+    }
 }
 
 /**
@@ -80,7 +99,7 @@
 {
     if( iSourceFiles.size() > 0 )
     {
-	    ConvertToMbm();
+        ConvertToMbm();
     }
 }
 
@@ -89,29 +108,144 @@
  */
 void MifConvBitmapConverter::Cleanup(bool err)
 {
-	CleanupTempFiles();
-	if( err )
-	{
-	    CleanupTargetFiles();
-	}
+    CleanupTempFiles();
+    if( err )
+    {
+        CleanupTargetFiles();
+    }
 }
 
 /**
  *
  */
 void MifConvBitmapConverter::ConvertToMbm()
-{    
-    RunBmconv();
+{   
+    MifConvArgumentManager* argMgr = MifConvArgumentManager::Instance();
+    const MifConvString& bmconvPath = argMgr->StringValue(MifConvBmconvPathArg);
+    
+    // If bmconv.exe's location is given.
+    if( bmconvPath.length() > 0 ) 
+    {
+        // Create and initialize the temp file.  
+        InitTempFile();
+    
+        // Run external bmconv.
+        RunExternalBmconv(bmconvPath);
+    }
+    else // Use internal logic.
+    {
+        // Create the path if not existing.
+        MifConvUtil::EnsurePathExists(iTargetFilename, true);
+        
+        cout << "Writing mbm: " << iTargetFilename << endl; 
+    
+        // Variable for source files.
+        MifConvSourceFileList sourceFiles;
+        
+        // Get palette file name from either arguments or default values.
+        MifConvString palettefilename = GetPaletteFileName();
+        
+        // Add filenames to the temp file.
+        // Sourcefiles and their mask files are considered as same.
+        for( MifConvSourceFileList::iterator i = iSourceFiles.begin(); i != iSourceFiles.end(); ++i )
+            {               
+            cout << "Loading file: " << i->Filename() << endl;
+            sourceFiles.push_back( *i );              
+            // Prepare also for the case that mask is not used at all.
+            if (i->BmpMaskFilename().length() > 0 )
+                {
+                cout << "Loading file: " << i->BmpMaskFilename() << endl;
+                MifConvSourceFile maskFile;
+                maskFile.SetFilename(i->BmpMaskFilename());
+                maskFile.SetDepthString(i->MaskDepthString());
+                sourceFiles.push_back( maskFile );
+                }
+            }
+       
+        // Create internal bmconv to handle compiling.
+        BmConv bmConv = BmConv(sourceFiles);
+        int ret = bmConv.Compile(iTargetFilename.c_str(), palettefilename); 
+        if (ret) {
+            THROW_ERROR_COMMON("BMP to MBM conversion failed", MifConvString(__FILE__), __LINE__);
+        }
+
+    }
 }
 
+const MifConvString MifConvBitmapConverter::GetPaletteFileName() 
+    {
+    
+    // Get palette argument.
+    MifConvArgumentManager* argMgr = MifConvArgumentManager::Instance();
+    const MifConvString& paletteArg = argMgr->StringValue(MifConvPaletteFileArg);
+    
+    MifConvString palettefilename;       
+    MifConvString paletteBuf;
+    
+    // If palette argument has been given.
+    if( paletteArg.length() == 0 )
+        {
+        // Default palette file.
+        const MifConvString& defaultPalettefile = DefaultPaletteFileName(paletteBuf);
+        
+        // Palette file not given in arguments. If the default palette file
+        // was found, use it, otherwise throw error.
+        if( defaultPalettefile.length() > 0 )
+            {
+            palettefilename = defaultPalettefile;           
+            }
+        else
+            {
+            // Palettefile not given in arguments nor found from default locations:
+            THROW_ERROR_COMMON("Unable to open palette file from default locations! ", MifConvString(__FILE__), __LINE__ );
+            }
+        } else {
+        palettefilename = paletteArg;           
+        }   
+    
+    // Check that palette file exists.
+    if( !MifConvUtil::FileExists(palettefilename) )
+    {
+        THROW_ERROR_COMMON("Unable to open palette file! " + paletteArg, MifConvString(__FILE__), __LINE__ );
+    }
+    
+    return palettefilename;
+    }
+
+const MifConvString& MifConvBitmapConverter::DefaultPaletteFileName(MifConvString& aBuf)
+    {
+    int numOfSearchLocations = sizeof(DefaultPaletteFileSearchLocations)/sizeof(char*);
+    
+    // Get epocroot.
+    MifConvString epocRoot(MifConvArgumentManager::Instance()->EpocRoot());
+    
+    for( int i = 0; i < numOfSearchLocations; ++i )
+        {
+        aBuf = epocRoot;
+        aBuf += DefaultPaletteFileSearchLocations[i];
+        
+        // Remove possible double-\.
+        if ((aBuf.at(1) == '\\') && (aBuf.at(0) == '\\')) aBuf = aBuf.substr(1, aBuf.length()-1);
+        if( MifConvUtil::FileExists(aBuf))
+            {
+            return aBuf;
+            }
+        }
+    aBuf = "";
+    return aBuf;
+    }
+
 /**
  *
  */
 void MifConvBitmapConverter::InitTempFile()
 {
+    // Take an instance from the argument manager.
     MifConvArgumentManager* argMgr = MifConvArgumentManager::Instance();
-    // Construct temp file name
+
+    // Construct temp file name.
     iTempDir = MifConvUtil::DefaultTempDirectory();
+    
     const MifConvString& tempDirArg = argMgr->StringValue(MifConvTempPathArg);
     if( tempDirArg.length() > 0 )
     {
@@ -137,26 +271,30 @@
 
     iTempFilename = iTempDir + MifConvUtil::FilenameWithoutExtension(MifConvUtil::FilenameWithoutPath(argMgr->TargetFile()));
     iTempFilename += BMCONV_TEMP_FILE_POSTFIX;
-
+    
     // Create temp file
     fstream tempFile(iTempFilename.c_str(), ios::out|ios::binary|ios::trunc);
     if (!tempFile.is_open())
     {        
-        throw MifConvException(MifConvString("Unable to create tmp file! ") + iTempFilename);        
+        throw MifConvException(MifConvString("Unable to create tmp file! ") + iTempFilename);    
     }
 
     try {
-        // quiet mode        
+        // quiet mode
+        // ex. "-q"
         tempFile << BMCONV_OPTION_PREFIX << BMCONV_QUIET_PARAMETER << " ";
+        
         // Palette argument
         const MifConvString& paletteArg = argMgr->StringValue(MifConvPaletteFileArg);
         if( paletteArg.length() > 0 )
         {
+            // ex. "-p"
             tempFile << BMCONV_OPTION_PREFIX << BMCONV_PALETTE_PARAMETER;            
             tempFile << MifConvString(paletteArg + " ");
         }
 
-        tempFile << iTargetFilename << " ";                
+        tempFile << iTargetFilename << " ";
+        
         // Add filenames to the temp file
         for( MifConvSourceFileList::iterator i = iSourceFiles.begin(); i != iSourceFiles.end(); ++i )
         {
@@ -166,34 +304,20 @@
     catch(...) {
         tempFile.close();
         throw;
-    }        
-
+    }    
     tempFile.close();
 }
 
 /**
- *
+ * Run external bmconv from given path.
  */
-void MifConvBitmapConverter::RunBmconv()
-{
-    MifConvArgumentManager* argMgr = MifConvArgumentManager::Instance();
-    // Create and initialize the temp file:    
-    InitTempFile();
-
+void MifConvBitmapConverter::RunExternalBmconv( const MifConvString& aBmconvPath )
+{    
     // Build bmconv command    
     MifConvString bmconvCommand("\""); // Open " mark
     
-    const MifConvString& bmconvPath = argMgr->StringValue(MifConvBmconvPathArg);
-    const MifConvString& defaultBmconvPath = GetDefaultBmConvPath();
-    if( bmconvPath.length() > 0 )
-    {
-        bmconvCommand += bmconvPath; // If the path is given, use it.
-    }
-    else
-    {
-        bmconvCommand += defaultBmconvPath; // Use default path
-    }
-
+    bmconvCommand += aBmconvPath; // If the path is given, use it.
+        
     // Ensure that the last char of the path is dir-separator:
     if( bmconvCommand.length() > 1 && bmconvCommand.at(bmconvCommand.length()-1) != DIR_SEPARATOR2 )
         bmconvCommand += DIR_SEPARATOR;
@@ -201,19 +325,19 @@
     // Then add bmconv executable call and close the " mark
     bmconvCommand += BMCONV_EXECUTABLE_NAME + MifConvString("\" ");  
     bmconvCommand += "\"" + iTempFilename + "\"";
-        
+            
     MifConvUtil::EnsurePathExists(iTargetFilename, true);
-    
+        
     cout << "Writing mbm: " << iTargetFilename << endl;           
     int err = 0;
-    
+      
 #ifdef __linux__
     if ((err = system (MifConvString(bmconvCommand).c_str())) != 0)   // Returns 0 if success
 #else
     if ((err = system (MifConvString("\""+bmconvCommand+"\"").c_str())) != 0)   // Returns 0 if success
 #endif
     {
-    	THROW_ERROR_COMMON("Executing BMCONV failed", MifConvString(__FILE__), __LINE__);
+            THROW_ERROR_COMMON("Executing BMCONV failed", MifConvString(__FILE__), __LINE__);
     }
 }
 
@@ -236,42 +360,26 @@
 /**
  *
  */
-const MifConvString& MifConvBitmapConverter::GetDefaultBmConvPath()
-{
-    if( iDefaultBmConvPath.length() == 0 )
-    {        
-        // Check if the EPOCROOT is given
-        MifConvString epocRoot(MifConvArgumentManager::Instance()->EpocRoot());
-        if( epocRoot.length() > 0 )
-        {
-            // EPOCROOT environment variable defined.
-            iDefaultBmConvPath = epocRoot + BMCONV_DEFAULT_PATH;
-        }        
-    }
-
-    return iDefaultBmConvPath;
-}
-
-/**
- *
- */
-void MifConvBitmapConverter::AppendBmpToTempFile(fstream& aStream, const MifConvSourceFile& bmpFile)
+void MifConvBitmapConverter::AppendBmpToTempFile(fstream& aStream, const MifConvSourceFile& aBmpFile)
     {
-    cout << "Loading file: " << bmpFile.Filename() << endl;
-
+    cout << "Loading file: " << aBmpFile.Filename() << endl;
+    
+    // ex. "-8..\..\bitmaps\mifconv_test_bitmap_01.bmp"
     aStream << BMCONV_OPTION_PREFIX;
-    aStream << bmpFile.DepthString();
-    aStream << bmpFile.Filename();
+    aStream << aBmpFile.DepthString();
+    aStream << aBmpFile.Filename();
     aStream << " ";
         
     // Prepare also for the case that mask is not used at all.
-    const MifConvString& maskName = bmpFile.BmpMaskFilename();
+    const MifConvString& maskName = aBmpFile.BmpMaskFilename();
     if (maskName.length() > 0 )
     {
         cout << "Loading file: " << maskName << endl;
+        
+        // ex. -8..\..\bitmaps\mifconv_test_bitmap_01_mask_soft.bmp 
         aStream << BMCONV_OPTION_PREFIX;
-        aStream << bmpFile.MaskDepthString();
-        aStream << maskName;        
+        aStream << aBmpFile.MaskDepthString();
+        aStream << maskName;      
     }
     aStream << " ";    
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gfxconversion/mifconv/src/mifconv_mbmgenerator.cpp	Fri Apr 16 15:32:00 2010 +0300
@@ -0,0 +1,100 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+#include "mifconv_mbmgenerator.h"
+#include "mifconv_mbmgenerator_pbmcomp.h"
+#include "mifconv_util.h"
+
+#include <stdio.h>
+#include <sys/stat.h>
+
+BmConv::BmConv(MifConvSourceFileList aSourcefilenames):
+    iSourcefilenames(aSourcefilenames)
+    {}
+
+BmConv::~BmConv() { 
+}
+
+int BmConv::Compile(const MifConvString& aDestfilename, const MifConvString& aPaletteFilename)
+    {     
+    int ret = OutOfRange;
+           
+    BitmapCompiler bmcomp(iSourcefilenames);
+    ret = bmcomp.Compile(aDestfilename, aPaletteFilename);
+    
+    Report(ret);
+    return ret;
+    }
+
+/**
+Returns an informative error message, the result of the program actions performed.
+@return Informative error string
+@param aErrorNumber The error returned from the actions performed
+@param aDestfile The multiple bitmap store file name
+@param aDestCreated True if the multiple bitmap store has been created/modified
+*/
+MifConvString BmConv::ErrorMessage(int aErrorNumber, MifConvString aDestfile="", bool aDestCreated=false)
+    {
+    // Remove the multiple bitmap store if it has been created/modified during an fstream session and there has been an error
+    if((aDestfile.length() > 0) && (aErrorNumber != NoError) && (aDestCreated == true))
+        {
+        remove(aDestfile.c_str());
+        }
+
+    switch(aErrorNumber)
+        {
+        case NoError:
+            return "Success.";
+        case NoMemory:
+            return "Out of memory.";
+        case Files:
+            return "File does not exist";
+        case SourceFile:
+            return "Bad source file(s).";
+        case DestFile:
+            return "Bad destination file(s).";
+        case OutOfRange:
+            return "Number of sources/targets mismatch.";
+        case UnknownCompression:
+            return "Unknown source compression type.";
+        case CompressionError:
+            return "Compression error.";
+        case Bpp:
+            return "Invalid bitmap mode specified.";
+        case PaletteFile:
+            return "Bad palette file.";
+        case PaletteSupportNotImplemented:
+            return "Palettes not supported";
+        case AlphaFiles:
+            return "Alpha bitmap file does not exist";
+        case AlphaDimensions:
+            return "Alpha channel bitmap's dimensions don't match pixel bitmap's dimensions.";
+        case AlphaBpp:
+            return "Alpha channel bitmap must be 8bpp.";
+        default:
+            return "Unknown error!";
+        };
+    }
+
+void BmConv::Report(int aError)
+    {
+    if (aError > 0) 
+        {
+        cout << "BMP to MBM conversion error: ";
+        cout << ErrorMessage(aError) << "\n";
+        }
+    }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gfxconversion/mifconv/src/mifconv_mbmgenerator_bmtopbm.cpp	Fri Apr 16 15:32:00 2010 +0300
@@ -0,0 +1,494 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+#include "mifconv_mbmgenerator_bmtopbm.h"
+#include "mifconv_util.h"
+
+const TRgbQuad KNokiaBrandBlue = {0xcc,0x33,0,0};
+const TRgbQuad KNokiaBrandGreen = {0x33,0x99,0,0};
+const int KNokiaBrandBlueIndex = 254;
+const int KNokiaBrandGreenIndex = 253;
+
+const unsigned char ColorRemapTable[256] = 
+	{
+	0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+	0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+	0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+	0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+	0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+	0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+	0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+	0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+	0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+	0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+	0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+	0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0x00, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+	0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xd7
+	};
+
+BitmapLoader::BitmapLoader():
+	iNumBmpColors(0),
+	iBmpColors(NULL),
+	iBmpBits(NULL),
+	iAlphaBits(NULL)
+	{}
+
+BitmapLoader::~BitmapLoader()
+	{
+	delete [] iBmpColors;
+	delete [] iBmpBits;
+	delete [] iAlphaBits;
+	}
+
+int BitmapLoader::LoadBitmap(MifConvSourceFile& aFilename,int aBpp,TBitmapColor aColor,SEpocBitmapHeader*& aPbm)
+	{
+	iSourceFile = &aFilename;
+	char sig[2];
+	
+	fstream file(aFilename.Filename().c_str(), FILE_IN_BINARY_NOCREATE_FLAGS);
+	
+	if (file.is_open()==0)
+		return Files;
+	file.read(sig,2);
+	file.close();
+	if (file.gcount()!=2)
+		return SourceFile ;
+	if (sig[0]!='B'||sig[1]!='M')
+		return SourceFile;
+
+	int ret = DoLoad(aFilename.Filename().c_str());
+
+    // If we have >8bit color BMP file and c8, change to c16
+    if( (aColor==EColorBitmap) && (aBpp==8) && 
+        (iBmpHeader.biBitCount>8) )
+        {
+        // cout << "Note: " << aFilename.Filename() << " changed c8 -> c16" << "\n";
+        aBpp = 16;
+        }
+	if (!ret && aColor==EColorBitmapAlpha)
+		{
+		int filenameLen = aFilename.Filename().length();
+		MifConvString alphaFilename = "";
+		
+		int dotPos = -1;
+		for (int i = 0; i < filenameLen; ++i)
+			if (aFilename.Filename()[i]=='.')
+				dotPos=i;
+		// Prefix length.
+		int prefixLen = (dotPos>=0?dotPos:filenameLen);
+		alphaFilename = aFilename.Filename().substr(0,prefixLen);
+		alphaFilename += "-alpha";
+		if (dotPos>=0)
+		    alphaFilename += aFilename.Filename().substr(prefixLen,aFilename.Filename().length());
+		alphaFilename += '\0';
+		ret = DoLoadAlpha(alphaFilename); // overlay alpha data from separate file
+		}
+	if (!ret)
+		ret = DoConvert(aBpp,aColor,aPbm);
+	return ret;
+	}
+
+int BitmapLoader::DoLoad(const char* aFileName)
+	{
+    
+    fstream file(aFileName, FILE_IN_BINARY_NOCREATE_FLAGS);
+    
+	if (file.is_open()==0)
+		return Files;
+	TBitmapFileHeader bmpfile;
+	long size=sizeof(TBitmapFileHeader);
+	
+	file.read((char *)&bmpfile,size);
+	if (file.gcount()!=size)
+		return SourceFile;
+	size=sizeof(TBitmapInfoHeader);
+	file.read((char *)&iBmpHeader,size);
+	if (file.gcount()!=size)
+		return SourceFile;
+	if (iBmpHeader.biCompression != 0)
+	    {
+		return UnknownCompression;
+	    }
+	size=bmpfile.bfSize-sizeof(TBitmapInfoHeader)-sizeof(TBitmapFileHeader);
+	long bitcount=iBmpHeader.biBitCount;
+	long colors=iBmpHeader.biClrUsed;
+	if (colors==0)
+		{
+		if (bitcount==24)
+			iNumBmpColors=0;
+		else if (bitcount==32)
+			iNumBmpColors=0;//See MSDN - BITMAPFILEHEADER and BITMAPINFOHEADER structures.
+                            //If biCompression is 0 - we don't have TRgbQuad array! 
+		else
+			iNumBmpColors=1<<bitcount;
+		}
+	else
+		iNumBmpColors=colors;
+	if (iNumBmpColors > 256)
+		return SourceFile;
+	if (iNumBmpColors>0)
+		{
+		iBmpColors = new TRgbQuad[iNumBmpColors];
+		if (iBmpColors == NULL)
+			return NoMemory;
+		memset(iBmpColors,0,iNumBmpColors*sizeof(TRgbQuad));
+		}
+	size-=iNumBmpColors*sizeof(TRgbQuad);
+	iBmpBits = new char[size];
+	if (iBmpBits == NULL)
+		return NoMemory;
+	memset(iBmpBits,0xff,size);
+
+	if(iBmpColors != NULL)
+	    {
+		file.read((char *)iBmpColors,iNumBmpColors*sizeof(TRgbQuad));
+		if (file.gcount()!=(int)(iNumBmpColors*sizeof(TRgbQuad)))
+			return SourceFile;
+	    }
+	file.read(iBmpBits,size);
+	file.close();
+	if (file.gcount()!=size)
+		return SourceFile;
+	return NoError;
+	}
+
+int BitmapLoader::DoLoadAlpha(MifConvString& aAlphaFileName)
+	{
+    
+    fstream file(aAlphaFileName.c_str(), FILE_IN_BINARY_NOCREATE_FLAGS);
+    
+	if (file.is_open()==0)
+		return AlphaFiles;
+	TBitmapFileHeader alphaBmpfile;
+	long size=sizeof(TBitmapFileHeader);
+	file.read((char *)&alphaBmpfile,size);
+	if (file.gcount()!=size)
+		return SourceFile;
+	size=sizeof(TBitmapInfoHeader);
+	TBitmapInfoHeader alphaBmpInfo;
+	file.read((char *)&alphaBmpInfo,size);
+	if (file.gcount()!=size)
+		return SourceFile;
+	if (alphaBmpInfo.biCompression != 0)
+		return UnknownCompression;
+	if (alphaBmpInfo.biWidth != iBmpHeader.biWidth || alphaBmpInfo.biHeight != iBmpHeader.biHeight)
+		return AlphaDimensions;
+	if (alphaBmpInfo.biBitCount != 8)
+		return AlphaBpp;
+	size=alphaBmpfile.bfSize-sizeof(TBitmapInfoHeader)-sizeof(TBitmapFileHeader);
+	long numBmpColors=alphaBmpInfo.biClrUsed;
+	if (numBmpColors == 0)
+		numBmpColors = 256;
+	if (numBmpColors != 256)
+		return SourceFile;
+	size-=numBmpColors*sizeof(TRgbQuad);
+	iAlphaBits = new char[size];
+	if (iAlphaBits == NULL)
+		{
+		return NoMemory;
+		}
+	memset(iAlphaBits,0xff,size);
+	char* bmpColors = new char[numBmpColors*sizeof(TRgbQuad)];
+	file.read((char *)bmpColors,numBmpColors*sizeof(TRgbQuad));
+	delete [] bmpColors; // we aren't interested in the palette data for the 8bpp grayscale alpha bmp
+	if (file.gcount()!=(int)(numBmpColors*sizeof(TRgbQuad)))
+		return SourceFile;
+	file.read(iAlphaBits,size);
+	file.close();
+	if (file.gcount()!=size)
+		return SourceFile;
+	return NoError;
+	}
+
+TRgb BitmapLoader::GetBmpPixel(long aXCoord,long aYCoord)
+	{
+	TRgb darkgray(128,128,128);
+	TRgb darkgrayex(127,127,127);
+	TRgb lightgray(192,192,192);
+	TRgb lightgrayex(187,187,187);
+	unsigned char col;
+	TRgb color;
+
+	switch(iBmpHeader.biBitCount)
+		{
+		case 1:
+			col=iBmpBits[(iBmpHeader.biHeight-aYCoord-1)*(((iBmpHeader.biWidth+31)>>5)<<2)+(aXCoord>>3)];
+			col&=(0x80>>(aXCoord%8));
+			if (iBmpColors)
+				{
+				TRgbQuad rgbq;
+				if (col)
+					rgbq = iBmpColors[1];
+				else
+					rgbq = iBmpColors[0];
+				color = TRgb(rgbq.iRed,rgbq.iGreen,rgbq.iBlue);
+				}
+			else
+				{
+				if (col)
+					color = TRgb(0x00ffffff);
+				else
+					color = TRgb(0);
+				}
+			break;
+		case 4:
+			col=iBmpBits[(iBmpHeader.biHeight-aYCoord-1)*(((iBmpHeader.biWidth+7)>>3)<<2)+(aXCoord>>1)];
+			if (aXCoord%2==0)
+				col=(unsigned char)(col>>4);
+			col&=0x0f;
+			if (iBmpColors)
+				{
+				TRgbQuad rgbq = iBmpColors[col];
+				color = TRgb(rgbq.iRed,rgbq.iGreen,rgbq.iBlue);
+				}
+			else
+				{
+				col *= 17;
+				color = TRgb(col,col,col);
+				}
+			break;
+		case 8:
+			col=iBmpBits[(iBmpHeader.biHeight-aYCoord-1)*((iBmpHeader.biWidth+3)&~3)+aXCoord];
+			if (iBmpColors)
+				{
+				TRgbQuad rgbq = iBmpColors[col];
+				color = TRgb(rgbq.iRed,rgbq.iGreen,rgbq.iBlue);
+				}
+			else
+				color = TRgb(col,col,col);
+			break;
+		case 16:
+			{
+			unsigned short int* wordptr = (unsigned short int*)&iBmpBits[(iBmpHeader.biHeight-aYCoord-1)*(((iBmpHeader.biWidth+1)&~1)<<1)+(aXCoord<<1)];
+			color = TRgb((*wordptr&0x7c)>>10,(*wordptr&0x3e)>>5,(*wordptr&0x1f));
+			}
+			break;
+		case 24:
+			{
+			TRgbTriple rgbcol = *((TRgbTriple *)&(iBmpBits[(iBmpHeader.biHeight-aYCoord-1)*((3*iBmpHeader.biWidth+3)&~3)+aXCoord+(aXCoord<<1)]));
+			color = TRgb(rgbcol.rgbtRed,rgbcol.rgbtGreen,rgbcol.rgbtBlue);
+			}
+			break;
+		case 32:
+			{
+			unsigned long int* dwordptr = (unsigned long int*)&iBmpBits[(iBmpHeader.biHeight-aYCoord-1)*((iBmpHeader.biWidth)<<2)+(aXCoord<<2)];
+			color = TRgb((*dwordptr&0xff0000)>>16,(*dwordptr&0xff00)>>8,*dwordptr&0xff);
+			}
+			break;
+		default:
+			break;
+		}
+	if (color == darkgray)
+		color = darkgrayex;
+	else if (color == lightgray)
+		color = lightgrayex;
+	return color;
+	}
+
+unsigned char BitmapLoader::GetAlphaPixel(long aXCoord,long aYCoord)
+	{
+	return iAlphaBits[(iBmpHeader.biHeight-aYCoord-1)*((iBmpHeader.biWidth+3)&~3)+aXCoord];
+	}
+
+int BitmapLoader::DoConvert(int aBpp,TBitmapColor aColor,SEpocBitmapHeader*& aPbm)
+	{
+	bool useAlpha = (aColor==EColorBitmapAlpha);
+	long desttwipswidth = 0;
+	long desttwipsheight = 0;
+
+	long bytewidth = MifConvUtil::ByteWidth(iBmpHeader.biWidth,aBpp);
+	long destlength = iBmpHeader.biHeight * bytewidth;
+
+	if (iBmpHeader.biXPelsPerMeter>0)
+		desttwipswidth = iBmpHeader.biWidth*1440000/254/iBmpHeader.biXPelsPerMeter;
+	if (iBmpHeader.biYPelsPerMeter>0)
+		desttwipsheight = iBmpHeader.biHeight*1440000/254/iBmpHeader.biYPelsPerMeter;
+
+	aPbm = (SEpocBitmapHeader*)new char[sizeof(SEpocBitmapHeader) + destlength];
+	if (aPbm == NULL)
+		return NoMemory;
+	memset(aPbm,0,sizeof(SEpocBitmapHeader));
+
+	// aBitmap->iByteWidth = bytewidth;
+	// aBitmap->iDataOffset = sizeof(Bitmap);
+
+	aPbm->iBitmapSize = sizeof(SEpocBitmapHeader) + destlength;
+	aPbm->iStructSize = sizeof(SEpocBitmapHeader);
+	aPbm->iWidthInPixels = iBmpHeader.biWidth;
+	aPbm->iHeightInPixels = iBmpHeader.biHeight;
+	aPbm->iWidthInTwips = desttwipswidth;
+	aPbm->iHeightInTwips = desttwipsheight;
+	aPbm->iBitsPerPixel = aBpp;
+	aPbm->iColor = aColor;
+	aPbm->iPaletteEntries = 0;
+	aPbm->iCompression = ENoBitmapCompression;
+
+	char* pbmBits = ((char*)aPbm) + sizeof(SEpocBitmapHeader);
+	memset(pbmBits,0xff,destlength);
+
+	long col = 0;
+	char* pixadd = 0;
+	bool indicesOnly = false;
+	if (aColor == EColorBitmap && aBpp == 8)
+		{
+		indicesOnly =
+			(iNumBmpColors==256 &&
+			 iBmpColors[KNokiaBrandGreenIndex].iRed == KNokiaBrandGreen.iRed &&
+			 iBmpColors[KNokiaBrandGreenIndex].iBlue == KNokiaBrandGreen.iBlue &&
+			 iBmpColors[KNokiaBrandGreenIndex].iGreen == KNokiaBrandGreen.iGreen &&
+			 iBmpColors[KNokiaBrandBlueIndex].iRed == KNokiaBrandBlue.iRed &&
+			 iBmpColors[KNokiaBrandBlueIndex].iBlue == KNokiaBrandBlue.iBlue &&
+			 iBmpColors[KNokiaBrandBlueIndex].iGreen == KNokiaBrandBlue.iGreen);
+		}
+
+	switch(aBpp)
+		{
+	case 1:
+		{
+		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
+			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
+				{
+				TRgb color=GetBmpPixel(xcrd,ycrd);
+				col=color.Gray2();
+				pixadd=&(pbmBits[ycrd*bytewidth+(xcrd>>3)]);
+				(*pixadd)&=~(1<<((xcrd&7)));
+				(*pixadd)|=(unsigned char)(col<<(xcrd&7));
+				}
+		}
+		break;
+	case 2:
+		{
+		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
+			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
+				{
+				TRgb color=GetBmpPixel(xcrd,ycrd);
+				col=color.Gray4();
+				pixadd=&(pbmBits[ycrd*bytewidth+(xcrd>>2)]);
+				(*pixadd)&=~(0x3<<(2*(xcrd%4)));
+				(*pixadd)|=(unsigned char)(col<<(2*(xcrd%4)));
+				}
+		}
+		break;
+	case 4:
+		{
+		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
+			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
+				{
+				TRgb color=GetBmpPixel(xcrd,ycrd);
+				if (aColor == EMonochromeBitmap)
+					col = color.Gray16();
+				else
+					col = color.Color16();
+				pixadd=&(pbmBits[ycrd*bytewidth+(xcrd>>1)]);
+				if (xcrd%2!=0)
+					*pixadd=(unsigned char)((unsigned char)((col<<4)|(*pixadd&0x0f)));
+				else
+					*pixadd=(unsigned char)((unsigned char)(col|(*pixadd&0xf0)));
+				}
+		}
+		break;
+	case 8:
+		{
+		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
+			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
+				{
+				if (indicesOnly)
+					{
+					unsigned char pixel = iBmpBits[(iBmpHeader.biHeight-ycrd-1)*((iBmpHeader.biWidth+3)&~3)+xcrd];
+					col = ColorRemapTable[pixel];
+					iSourceFile->SetCompileInfo(MifConvSourceFile::ENokiaBitmap);
+					}
+				else
+					{
+					TRgb color=GetBmpPixel(xcrd,ycrd);
+					if (aColor == EMonochromeBitmap)
+						col = color.Gray256();
+					else
+						col = color.Color256();
+					iSourceFile->SetCompileInfo(MifConvSourceFile::EThirdPartyBitmap);
+					}
+				pixadd=&(pbmBits[ycrd*((iBmpHeader.biWidth+3)&~3)+xcrd]);
+				*pixadd=(unsigned char)col;
+				}
+		}
+		break;
+	case 12:
+		{
+		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
+			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
+				{
+				TRgb color=GetBmpPixel(xcrd,ycrd);
+				col=color.Color4K();
+				pixadd=&(pbmBits[ycrd*bytewidth+(xcrd<<1)]);
+				unsigned short* wordadd=(unsigned short*)pixadd;
+				*wordadd=(unsigned short)col;
+				}
+		}
+		break;
+	case 16:
+		{
+		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
+			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
+				{
+				TRgb color=GetBmpPixel(xcrd,ycrd);
+				col=color.Color64K();
+				pixadd=&(pbmBits[ycrd*bytewidth+(xcrd<<1)]);
+				unsigned short* wordadd=(unsigned short*)pixadd;
+				*wordadd=(unsigned short)col;
+				}
+		}
+		break;
+	case 24:
+		{
+		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
+			{
+			unsigned char* bytePtr = (unsigned char*)&pbmBits[ycrd*bytewidth];
+			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
+				{
+				TRgb col = GetBmpPixel(xcrd,ycrd);
+				*bytePtr++ = (unsigned char) col.iBlue;
+				*bytePtr++ = (unsigned char) col.iGreen;
+				*bytePtr++ = (unsigned char) col.iRed;
+				}
+			}
+		}
+		break;
+	case 32:
+		{
+		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
+			{
+			unsigned char* bytePtr = (unsigned char*)&pbmBits[ycrd*bytewidth];
+			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
+				{
+				TRgb col = GetBmpPixel(xcrd,ycrd);
+				unsigned char alpha = useAlpha?GetAlphaPixel(xcrd,ycrd):(unsigned char)0;
+				*bytePtr++ = (unsigned char) col.iBlue;
+				*bytePtr++ = (unsigned char) col.iGreen;
+				*bytePtr++ = (unsigned char) col.iRed;
+				*bytePtr++ = alpha;	
+				}
+			}
+		}
+		break;
+		};
+
+	return NoError;
+	}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gfxconversion/mifconv/src/mifconv_mbmgenerator_pbmcomp.cpp	Fri Apr 16 15:32:00 2010 +0300
@@ -0,0 +1,1048 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+#include "mifconv_mbmgenerator_pbmcomp.h"
+#include "mifconv_mbmgenerator_bmtopbm.h"
+#include "mifconv_util.h"
+#include <stdlib.h>
+#include <ctype.h>
+#include <sys/stat.h>
+
+extern TRgb* color256Palette;
+extern char* color256InversePalette;
+
+static inline bool CanCopy16bppData(const char* aDest, const char* aDestEnd, int aDataSize)
+	{
+	const char* aDestNew = 	aDest + (aDataSize / 128) * (256 + 1) + //(2 * 128) bytes data + 1 leading byte
+		                            (aDataSize % 128 ? (aDataSize % 128) * 2 + 1 : 0);
+	return aDestNew <= aDestEnd;
+	}
+
+static inline bool CanWrite16bppValue(const char* aDest, const char* aDestEnd, int aDataSize)
+	{
+	const char* aDestNew = 	aDest + (aDataSize / 128) * (2 + 1) + //2 bytes data + 1 leading byte
+		                            (aDataSize % 128 ? 2 + 1 : 0);
+	return aDestNew <= aDestEnd;
+	}
+
+static inline bool CanCopy8bppData(const char* aDest, const char* aDestEnd, int aDataSize)
+	{
+	const char* aDestNew = 	aDest + (aDataSize / 128) * (128 + 1) + //128 bytes data + 1 leading byte
+		                            (aDataSize % 128 ? (aDataSize % 128) + 1 : 0);
+	return aDestNew <= aDestEnd;
+	}
+
+static inline bool CanWrite8bppValue(const char* aDest, const char* aDestEnd, int aDataSize)
+	{
+	const char* aDestNew = 	aDest + (aDataSize / 128) * (1 + 1) + //1 byte data + 1 leading byte
+		                            (aDataSize % 128 ? 1 + 1 : 0);
+	return aDestNew <= aDestEnd;
+	}
+
+static inline bool CanCopy24bppData(const char* aDest, const char* aDestEnd, int aDataSize)
+	{
+	const char* aDestNew = 	aDest + (aDataSize / 128) * (384 + 1) + //(128 * 3) bytes data + 1 leading byte
+		                            (aDataSize % 128 ? (aDataSize % 128) * 3 + 1 : 0);
+	return aDestNew <= aDestEnd;
+	}
+
+static inline bool CanWrite24bppValue(const char* aDest, const char* aDestEnd, int aDataSize)
+	{
+	const char* aDestNew = 	aDest + (aDataSize / 128) * (3 + 1) + //3 bytes data + 1 leading byte
+		                            (aDataSize % 128 ? 3 + 1 : 0);
+	return aDestNew <= aDestEnd;
+	}
+
+static inline bool CanCopy32bppData(const char* aDest, const char* aDestEnd, int aDataSize)
+	{
+	const char* aDestNew = 	aDest + (aDataSize / 128) * (512 + 1) + //(128 * 4) bytes data + 1 leading byte
+		                            (aDataSize % 128 ? (aDataSize % 128) * 4 + 1 : 0);
+	return aDestNew <= aDestEnd;
+	}
+
+static inline bool CanWrite32bppValue(const char* aDest, const char* aDestEnd, int aDataSize)
+	{
+	const char* aDestNew = 	aDest + (aDataSize / 128) * (4 + 1) + //4 bytes data + 1 leading byte
+		                            (aDataSize % 128 ? 4 + 1 : 0);
+	return aDestNew <= aDestEnd;
+	}
+
+BitmapCompiler::BitmapCompiler(MifConvSourceFileList aSourcefilenames):
+	iSourcefilenames(aSourcefilenames),
+	iPbmSources(NULL),
+	iNumSources(aSourcefilenames.size())
+	{}
+
+BitmapCompiler::~BitmapCompiler()
+	{
+	iDestFile.close();
+	if(iPbmSources)
+		for(int count=0;count<iNumSources;count++)
+			delete iPbmSources[count];
+	delete [] iPbmSources;
+	iPbmSources = NULL;
+	}
+
+int BitmapCompiler::Compile(const MifConvString& aDestfilename, const MifConvString& aPaletteFilename)
+	{    
+        
+	int ret = LoadPalette(aPaletteFilename.c_str());
+	if (ret)
+		return ret;
+	
+	iDestFile.open(aDestfilename.c_str(), ios::out | ios::binary);
+	if(iDestFile.is_open()==0)
+		return DestFile;
+	if (iNumSources < 1)
+		return SourceFile;
+
+	// Read the usual list of [OPT]bmp_n source bitmaps.
+	ret = LoadSourcefiles();
+	
+	if (ret)
+		return ret;
+
+	return FileImage();
+	};
+
+int BitmapCompiler::AllocatePbmSourcesArray()
+	{
+	iPbmSources = new SEpocBitmapHeader*[iNumSources];
+	if(iPbmSources == NULL)
+		return NoMemory;
+
+	memset(iPbmSources,0xff,sizeof(SEpocBitmapHeader*)*iNumSources);
+	int count;
+	for(count=0;count<iNumSources;count++)
+		iPbmSources[count]=NULL;
+	return NoError;
+	}
+
+int BitmapCompiler::LoadSourcefiles()
+	{
+    //Initialize iPbmSources.
+	int ret = AllocatePbmSourcesArray();
+	if (ret)
+		return ret;
+
+    int count = 0;	
+    for( MifConvSourceFileList::iterator i = iSourcefilenames.begin(); i != iSourcefilenames.end(); ++i, ++count )
+        {
+        bool useAlpha = false;
+        int bpp = 2;
+        TBitmapColor color = EMonochromeBitmap;
+        BitmapLoader bmpload;
+        int loc = 0;
+                    
+        if(i->DepthString().length() > 0)
+            {
+            if(i->DepthString()[loc]=='c')
+                {
+                color = EColorBitmap;
+                loc++;
+                }
+            bpp=i->DepthString()[loc]-'0';
+            loc++;
+            int next=i->DepthString()[loc]-'0';
+            if(next==2 || next==6 || next==4)
+                {
+                bpp=bpp*10+next;
+                loc++;
+                }
+            if(i->DepthString()[loc]=='a')
+                {
+                useAlpha = true;
+                loc++;
+                if (color!=EColorBitmap || bpp!=32)
+                    return Bpp;
+                }
+            if (color == EColorBitmap && bpp!=4 && bpp!=8 && bpp!=12 && bpp!=16 && bpp!=24 && bpp!=32)
+                return Bpp;
+            if (color == EMonochromeBitmap && bpp!=1 && bpp!=2 && bpp!=4 && bpp!=8)
+                return Bpp;
+            }
+                    
+        if (color == EColorBitmap && useAlpha)
+            color = EColorBitmapAlpha;
+                   
+        ret = bmpload.LoadBitmap(*i,bpp,color,iPbmSources[count]);
+                        
+        // If error.
+        if (ret)
+            return ret;
+        }
+    return NoError;
+	}
+
+int BitmapCompiler::FileImage()
+	{    
+	int count = 0;
+	
+	// Compress
+    for(;count<iNumSources;count++)
+        {
+        int ret = CompressBitmap(iPbmSources[count]);
+        if(ret)
+            return ret;
+        }
+    
+	int ret = WriteFileheader();
+	if (ret)
+		return ret;
+	for (count=0;count<iNumSources;count++)
+		{
+		ret = WriteFilebitmap(iPbmSources[count]);
+		if (ret)
+			return ret;
+		}
+	ret = WriteHeadStream();
+	return ret;
+	}
+
+int BitmapCompiler::WriteFileheader()
+	{
+	int zero=0;
+	iDestFile.write((char*)&KWriteOnceFileStoreUid,4);
+	iDestFile.write((char*)&KMultiBitmapFileImageUid,4);
+	iDestFile.write((char*)&zero,4);
+	iDestFile.write((char*)&KMultiBitmapFileImageChecksum,4);
+	int byteswritten=16;
+	for(int count=0;count<iNumSources;count++)
+		{
+		byteswritten+=iPbmSources[count]->iBitmapSize;
+		}
+	byteswritten+=4;
+	iDestFile.write((char*)&byteswritten,4);
+	return NoError;
+	}
+
+int BitmapCompiler::WriteHeadStream()
+	{
+	iDestFile.write((char*)&iNumSources,4);
+	int byteswritten=20;
+	for(int count=0;count<iNumSources;count++)
+		{
+		iDestFile.write((char*)&byteswritten,4);
+		byteswritten+=iPbmSources[count]->iBitmapSize;
+		}
+	return NoError;
+	}
+
+int BitmapCompiler::WriteFilebitmap(SEpocBitmapHeader* aPbm)
+	{
+	if (aPbm->iPaletteEntries != 0)
+		return PaletteSupportNotImplemented;
+
+	int dataSize = aPbm->iBitmapSize - sizeof(SEpocBitmapHeader);
+
+	iDestFile.write((char*)(aPbm),sizeof(SEpocBitmapHeader));
+	iDestFile.write(((char*)(aPbm)) + sizeof(SEpocBitmapHeader),dataSize);
+
+	return NoError;
+	}
+
+int BitmapCompiler::LoadPalette(const char* aPaletteFilename)
+	{
+	if (!aPaletteFilename)
+		{
+		iDefaultPalette = 1;
+		return NoError;
+		}
+
+	iDefaultPalette = 0;
+	color256Palette = iPalette;
+	color256InversePalette = iInversePalette;
+
+	struct stat fileinfo;
+	if (stat(aPaletteFilename,&fileinfo)==-1)
+		return PaletteFile;
+
+	int filesize = fileinfo.st_size;
+	if (filesize == 0)
+		return PaletteFile;
+
+	fstream paletteFile(aPaletteFilename, FILE_IN_BINARY_NOCREATE_FLAGS);
+	
+	if(!paletteFile.is_open())
+		return PaletteFile;
+
+	char* paletteData = new char[filesize];
+	if (!paletteData)
+		return NoMemory;
+
+	memset(paletteData,0,filesize);
+	paletteFile.read(paletteData,filesize);
+	paletteFile.close();
+
+	char* dataPtr = (char*)paletteData;
+	char* dataPtrLimit = dataPtr + filesize;
+
+	for (int index = 0; index < 256; index++)
+		{
+		char hexBuf[10];
+		int ret = ReadHexString(hexBuf,dataPtr,dataPtrLimit);
+		if (ret)
+			{
+			delete paletteData;
+			return ret;
+			}
+
+		int red = HexToInt(hexBuf[8],hexBuf[9]);
+		int green = HexToInt(hexBuf[6],hexBuf[7]);
+		int blue = HexToInt(hexBuf[4],hexBuf[5]);
+
+		iPalette[index] = TRgb(red,green,blue);
+		}
+
+	delete paletteData;
+	CalculateInversePalette();
+	return NoError;
+	}
+
+void BitmapCompiler::CalculateInversePalette()
+	{
+	for (int index = 0; index < 4096; index++)
+		{
+		TRgb color = TRgb((index & 0x00f) * 17,((index & 0x0f0) >> 4) * 17,((index & 0xf00) >> 8) * 17);
+
+		int nearest = 0;
+		int distance = iPalette[0].Difference(color);
+
+		for (int paletteIndex = 0; paletteIndex < 256; paletteIndex++)
+			{
+			TRgb paletteColor = iPalette[paletteIndex];
+
+			if (paletteColor == color)
+				{
+				nearest = paletteIndex;
+				break;
+				}
+
+			int paletteDistance = paletteColor.Difference(color);
+			if (paletteDistance < distance)
+				{
+				nearest = paletteIndex;
+				distance = paletteDistance;
+				}
+			}
+
+		iInversePalette[index] = (char)nearest;
+		TRgb palColor = iPalette[nearest];
+		color = palColor;
+		}
+	}
+
+int BitmapCompiler::CompressBitmap(SEpocBitmapHeader*& aPbm)
+	{
+       
+	int originalsize = aPbm->iBitmapSize-sizeof(SEpocBitmapHeader);
+	char* newbits=new char[originalsize+sizeof(SEpocBitmapHeader)];
+	if(!newbits)
+		return NoMemory;
+
+	memset(newbits,0xff,sizeof(SEpocBitmapHeader)+originalsize);
+	memcpy(newbits,aPbm,sizeof(SEpocBitmapHeader));
+	char* newbitsptr=newbits+sizeof(SEpocBitmapHeader);
+	char* oldbits=((char*)(aPbm))+sizeof(SEpocBitmapHeader);
+
+	TBitmapfileCompression compression = ENoBitmapCompression;
+	int ret = NoCompression;
+
+	if (aPbm->iBitsPerPixel <= 8)
+		{
+		compression = EByteRLECompression;
+		ret = CompressByteData(newbitsptr,oldbits,originalsize);
+		}
+	else if (aPbm->iBitsPerPixel == 12)
+		{
+		compression = ETwelveBitRLECompression;
+		ret = CompressTwelveBitData(newbitsptr,oldbits,originalsize);
+		}
+	else if (aPbm->iBitsPerPixel == 16)
+		{
+		compression = ESixteenBitRLECompression;
+		ret = CompressSixteenBitData(newbitsptr,oldbits,originalsize);
+		}
+	else if (aPbm->iBitsPerPixel == 24)
+		{
+		compression = ETwentyFourBitRLECompression;
+		ret = CompressTwentyFourBitData(newbitsptr,oldbits,originalsize);
+		}
+	else if (aPbm->iBitsPerPixel == 32 && (aPbm->iColor == EColorBitmap))
+		{
+		compression = EThirtyTwoUBitRLECompression;
+		ret = CompressThirtyTwoUBitData(newbitsptr,oldbits,originalsize);
+		}
+	else if (aPbm->iBitsPerPixel == 32 && (aPbm->iColor == EColorBitmapAlpha))
+		{
+		compression = EThirtyTwoABitRLECompression;
+		ret = CompressThirtyTwoABitData(newbitsptr,oldbits,originalsize);
+		}
+
+	if(ret)
+		{
+		delete [] newbits;
+		if(ret>0)
+			return ret;
+		return NoError;
+		}
+
+	delete aPbm;
+	aPbm = (SEpocBitmapHeader*)newbits;
+	aPbm->iBitmapSize = newbitsptr-(newbits+sizeof(SEpocBitmapHeader))+sizeof(SEpocBitmapHeader);
+	aPbm->iCompression = compression;
+	return NoError;
+	}
+
+int BitmapCompiler::CompressByteData(char*& aDest,char* aSrce,int aSize)
+	{
+	const char* destEnd = aDest + aSize;
+	char* bytepointer=aSrce;
+	char* limitpointer=bytepointer+aSize;
+	int margin = (aSize>>6);
+	char* limitmargin = limitpointer - ((margin > 4) ? margin : 4);
+	char* cutoffpointer=aDest+(aSize>>1)+(aSize>>2);
+	int ret=NoError;
+	char* oldbytepointer=NULL;
+	while(bytepointer<limitmargin)
+		{
+		char value=*bytepointer;
+		if(*(bytepointer+1)==value && *(bytepointer+2)==value)
+			{
+			oldbytepointer=bytepointer;
+			bytepointer+=3;
+			while ( ( bytepointer < limitmargin ) && ( *bytepointer == value ) )
+				bytepointer++;
+			ret = WriteCompressedByteValues(aDest,value,bytepointer-oldbytepointer, destEnd);
+			if(ret) return ret;
+			}
+		else
+			{
+			oldbytepointer=bytepointer;
+			while((bytepointer<limitmargin) && (*(bytepointer+1)!=value || *(bytepointer+2)!=value))
+				{
+				bytepointer++;
+				value=*bytepointer;
+				}
+			ret = WriteCompressedByteData(aDest,oldbytepointer,bytepointer-oldbytepointer, destEnd);
+			if(ret) return ret;
+			}
+		if(aDest>cutoffpointer)
+			return NoCompression;
+		}
+
+	int remaining = limitpointer-bytepointer;
+	if(remaining > 0)
+		{
+		if (aDest + remaining > cutoffpointer)
+			return NoCompression;
+		ret=WriteCompressedByteData(aDest,bytepointer,remaining, destEnd);
+		if(ret) return ret;
+		}
+	return NoError;
+	}
+
+int BitmapCompiler::WriteCompressedByteData(char*& aDest,char* aData,int aLength, const char* aDestEnd)
+	{
+	if(!CanCopy8bppData(aDest, aDestEnd, aLength))
+		return NoCompression;
+	while(aLength>128)
+		{
+		*aDest++=-128;
+		for(int count=0;count<128;count++)
+			*aDest++=*aData++;
+		aLength-=128;
+		}
+	if(aLength>128 || aLength<1) return CompressionError;
+	*aDest++=char(-aLength);
+	for(int count=0;count<aLength;count++)
+		*aDest++=*aData++;
+	return NoError;
+	}
+
+
+int BitmapCompiler::WriteCompressedByteValues(char*& aDest,char aValue,int aLength, const char* aDestEnd)
+	{
+	if (aLength < 1)
+		return CompressionError;
+
+	if(!CanWrite8bppValue(aDest, aDestEnd, aLength))
+		return NoCompression;
+
+	while (aLength > 128)
+		{
+		*aDest++ = 127;
+		*aDest++ = aValue;
+		aLength -= 128;
+		}
+
+	*aDest++ = char(aLength-1);
+	*aDest++ = aValue;
+
+	return NoError;
+	}
+
+int BitmapCompiler::CompressTwelveBitData(char*& aDest,char* aSrce,int aSizeInBytes)
+	{
+	unsigned short* srcePtr = (unsigned short*)aSrce;
+	unsigned short* srceLimitPtr = srcePtr + (aSizeInBytes / 2);
+	unsigned short* dest = (unsigned short*)aDest;
+
+	while (srcePtr < srceLimitPtr)
+		{
+		unsigned short* runStartPtr = srcePtr;
+		unsigned short value = *srcePtr;
+		do
+			srcePtr++;
+		while (srcePtr < srceLimitPtr && *srcePtr == value);
+		WriteCompressedTwelveBitData(dest,*runStartPtr,srcePtr - runStartPtr); // Ignore error return as 12bpp compression never fails
+		}
+
+	aDest = (char*)dest;
+	return NoError;
+	}
+
+int BitmapCompiler::WriteCompressedTwelveBitData(unsigned short*& aDest,unsigned short aData,int aLength)
+	{
+	// The run length l is stored as l-1 in the top 4 bits of each 16-bit word (between 1 and 16)
+	aData &= 0x0fff;
+	unsigned short maxLengthData = (unsigned short)(aData | 0xf000);
+
+	while(aLength>16)
+		{
+		*aDest++ = maxLengthData;
+		aLength -= 16;
+		}
+
+	if (aLength > 0)
+		*aDest++ = (unsigned short)(aData | ((aLength - 1) << 12));
+
+	return NoError;
+	}
+
+int BitmapCompiler::CompressSixteenBitData(char*& aDest,char* aSrce,int aSizeInBytes)
+	{
+	char* destEnd = aDest + aSizeInBytes;
+	unsigned short* srcePtr = (unsigned short*)aSrce;
+	unsigned short* srceLimitPtr = srcePtr + (aSizeInBytes / 2);
+	unsigned short* srceLimitPtrMinusOne = srceLimitPtr - 1;
+	char* destCompressedLimitPtr = aDest + (aSizeInBytes * 7 / 8);
+	int ret = NoError;
+
+	while (srcePtr < srceLimitPtrMinusOne)
+		{
+		unsigned short value = *srcePtr;
+		unsigned short* runStartPtr = srcePtr++;
+
+		if(*srcePtr == value)
+			{
+			do
+				srcePtr++;
+			while ( ( srcePtr < srceLimitPtr ) && ( *srcePtr == value ) );
+
+			ret = WriteCompressedSixteenBitValues(aDest,value,srcePtr-runStartPtr, destEnd);
+			if (ret)
+				return ret;
+			}
+		else
+			{
+			value = *srcePtr;
+			while (srcePtr < srceLimitPtrMinusOne && *(srcePtr + 1) != value)
+				{
+				srcePtr++;
+				value = *srcePtr;
+				}
+
+			ret = WriteCompressedSixteenBitData(aDest,runStartPtr,srcePtr - runStartPtr, destEnd);
+			if (ret)
+				return ret;
+			}
+		if (aDest > destCompressedLimitPtr)
+			return NoCompression;
+		}
+
+	if (srcePtr < srceLimitPtr)
+		{
+		ret = WriteCompressedSixteenBitData(aDest,srcePtr,srceLimitPtr - srcePtr, destEnd);
+		if (ret)
+			return ret;
+		}
+
+	if (aDest > destCompressedLimitPtr)
+		return NoCompression;
+	return NoError;
+	}
+
+int BitmapCompiler::WriteCompressedSixteenBitData(char*& aDest,unsigned short* aData,
+												  int aLength, const char* aDestEnd)
+	{
+	if (aLength < 1)
+		return CompressionError;
+
+	if(!CanCopy16bppData(aDest, aDestEnd, aLength))
+		return NoCompression;
+
+	char* srcePtr = (char*)aData;
+
+	while (aLength > 128)
+		{
+		*aDest++ = -128;
+		memcpy(aDest,srcePtr,256);
+		aDest += 256;
+		srcePtr += 256;
+		aLength -= 128;
+		}
+
+	*aDest++ = char(-aLength);
+
+	int remainingBytes = aLength * 2;
+	memcpy(aDest,srcePtr,remainingBytes);
+	aDest += remainingBytes;
+
+	return NoError;
+	}
+
+int BitmapCompiler::WriteCompressedSixteenBitValues(char*& aDest,unsigned short aValue,
+													int aLength, const char* aDestEnd)
+	{
+	if (aLength < 1)
+		return CompressionError;
+
+	if(!CanWrite16bppValue(aDest, aDestEnd, aLength))
+		return NoCompression;
+
+	char lowByte = char(aValue);
+	char highByte = char(aValue >> 8);
+
+	while (aLength > 128)
+		{
+		*aDest++ = 127;
+		*aDest++ = lowByte;
+		*aDest++ = highByte;
+		aLength -= 128;
+		}
+
+	*aDest++ = char(aLength-1);
+	*aDest++ = lowByte;
+	*aDest++ = highByte;
+
+	return NoError;
+	}
+
+int BitmapCompiler::CompressTwentyFourBitData(char*& aDest,char* aSrce,int aSizeInBytes)
+	{
+	const char* destEnd = aDest + aSizeInBytes; 
+	char* srceLimitPtr = aSrce + aSizeInBytes;
+	char* srceLimitPtrMinusThree = srceLimitPtr - 3; // three bytes == one pixel
+	char* destCompressedLimitPtr = aDest + (aSizeInBytes * 7 / 8);
+	int ret = NoError;
+
+	while (aSrce < srceLimitPtrMinusThree)
+		{
+		char* runStartPtr = aSrce;
+		char component1 = *aSrce++;
+		char component2 = *aSrce++;
+		char component3 = *aSrce++;
+
+		if (TrueColorPointerCompare(aSrce,component1,component2,component3))
+			{
+			do
+				aSrce += 3;
+			while (aSrce < srceLimitPtr && TrueColorPointerCompare(aSrce,component1,component2,component3));
+
+			ret = WriteCompressedTwentyFourBitValues(aDest,component1,component2,component3,(aSrce - runStartPtr) / 3, destEnd);
+			if (ret)
+				return ret;
+			}
+		else
+			{
+			bool more  = true;
+			bool eqRun = false;
+			do
+				{
+				component1 = *aSrce++;
+				component2 = *aSrce++;
+				component3 = *aSrce++;
+				more = (aSrce < srceLimitPtr);
+				eqRun = more && TrueColorPointerCompare(aSrce,component1,component2,component3);
+				}
+			while (more && !eqRun);
+			if (eqRun)
+				aSrce -= 3;
+			int pixelLength = (aSrce - runStartPtr) / 3;
+			ret = WriteCompressedTwentyFourBitData(aDest,runStartPtr,pixelLength,destEnd);
+			if (ret)
+				return ret;
+			}
+		if (aDest > destCompressedLimitPtr)
+			return NoCompression;
+		}
+
+	if (aSrce < srceLimitPtr)
+		{
+		ret = WriteCompressedTwentyFourBitData(aDest,aSrce,(srceLimitPtr - aSrce) / 3, destEnd);
+		if (ret)
+			return ret;
+		}
+
+	if (aDest > destCompressedLimitPtr)
+		return NoCompression;
+	return NoError;
+	}
+
+int BitmapCompiler::WriteCompressedTwentyFourBitData(char*& aDest,char* aData,
+													 int aLength, const char* aDestEnd)
+	{
+	if (aLength < 1)
+		return CompressionError;
+
+	if(!CanCopy24bppData(aDest, aDestEnd, aLength))
+		return NoCompression;
+
+	while (aLength > 128)
+		{
+		*aDest++ = -128;
+		memcpy(aDest,aData,384);
+		aDest += 384;
+		aData += 384;
+		aLength -= 128;
+		}
+
+	*aDest++ = char(-aLength);
+
+	int remainingBytes = aLength * 3;
+	memcpy(aDest,aData,remainingBytes);
+	aDest += remainingBytes;
+
+	return NoError;
+	}
+
+int BitmapCompiler::WriteCompressedTwentyFourBitValues(char*& aDest,char aComponent1,
+													   char aComponent2,char aComponent3,
+													   int aLength, const char* aDestEnd)
+	{
+	if (aLength < 1)
+		return CompressionError;
+
+	if(!CanWrite24bppValue(aDest, aDestEnd, aLength))
+		return NoCompression;
+
+	while (aLength > 128)
+		{
+		*aDest++ = 127;
+		*aDest++ = aComponent1;
+		*aDest++ = aComponent2;
+		*aDest++ = aComponent3;
+		aLength -= 128;
+		}
+
+	*aDest++ = char(aLength-1);
+	*aDest++ = aComponent1;
+	*aDest++ = aComponent2;
+	*aDest++ = aComponent3;
+
+	return NoError;
+	}
+
+/** The function encodes 32-bit buffer into 24-bit stream by using RLE compression algorithm*/
+int BitmapCompiler::CompressThirtyTwoUBitData(char*& aDest,char* aSrce,int aSizeInBytes)
+	{
+	const char* destEnd = aDest + aSizeInBytes; 
+	char* srceLimitPtr = aSrce + aSizeInBytes;
+	char* srceLimitPtrMinusFour = srceLimitPtr - 4; // four bytes == one pixel
+	char* destCompressedLimitPtr = aDest + (aSizeInBytes * 7 / 8);
+	int ret = NoError;
+
+	while (aSrce < srceLimitPtrMinusFour)
+		{
+		char* runStartPtr = aSrce;
+		char component1 = *aSrce++;
+		char component2 = *aSrce++;
+		char component3 = *aSrce++;
+		aSrce++;
+
+		if (TrueColorPointerCompare(aSrce,component1,component2,component3))
+			{
+			do
+				aSrce += 4;
+			while (aSrce < srceLimitPtr && TrueColorPointerCompare(aSrce,component1,component2,component3));
+
+			ret = WriteCompressedThirtyTwoUBitValues(aDest,component1,component2,component3,(aSrce - runStartPtr) / 4, destEnd);
+			if (ret)
+				return ret;
+			}
+		else //non repeating pixel buffer
+			{
+			bool more  = true;
+			bool eqRun = false;
+			do {
+				component1 = *aSrce++;
+				component2 = *aSrce++;
+				component3 = *aSrce++;
+				aSrce++; //last byte is unused (no alpha component)
+				more = (aSrce < srceLimitPtr);
+				eqRun = more && TrueColorPointerCompare(aSrce,component1,component2,component3);
+				} while (more && !eqRun);
+			if (eqRun)
+				aSrce -= 4;
+			int pixelLength = (aSrce - runStartPtr) / 4;
+			ret = WriteCompressedThirtyTwoUBitData(aDest,runStartPtr,pixelLength,destEnd);
+ 			if (ret)
+				return ret;
+			}
+		if (aDest > destCompressedLimitPtr)
+			return NoCompression;
+		}
+
+	if (aSrce < srceLimitPtr)
+		{
+		ret = WriteCompressedThirtyTwoUBitData(aDest,aSrce,(srceLimitPtr - aSrce) / 4, destEnd);
+		if (ret)
+			return ret;
+		}
+
+	if (aDest > destCompressedLimitPtr)
+		return NoCompression;
+	return NoError;
+	}
+
+/** The function copies non repeating 32-bit buffer to 24-bit compressed buffer*/
+int BitmapCompiler::WriteCompressedThirtyTwoUBitData(char*& aDest,char* aData,
+													 int aLength, const char* aDestEnd)
+	{
+	if (aLength < 1)
+		return CompressionError;
+
+	if(!CanCopy24bppData(aDest, aDestEnd, aLength))
+		return NoCompression;
+
+	while (aLength > 128)
+		{
+		*aDest++ = -128;
+		for(int ii = 0; ii < 128; ii++)
+			{
+			memcpy(aDest,aData, 3);
+			aDest += 3;
+			aData += 4;
+			}
+		aLength -= 128;
+		}
+
+	*aDest++ = char(-aLength);
+
+	while(aLength--)
+		{
+		memcpy(aDest,aData, 3);
+		aDest += 3;
+		aData += 4;
+		}
+
+	return NoError;
+	}
+
+/** The function copies repeating colour to the 24-bit compressed buffer */
+int BitmapCompiler::WriteCompressedThirtyTwoUBitValues(char*& aDest,char aComponent1,
+													   char aComponent2,char aComponent3,
+													   int aLength, const char* aDestEnd)
+	{
+	if (aLength < 1)
+		return CompressionError;
+
+	if(!CanWrite24bppValue(aDest, aDestEnd, aLength))
+		return NoCompression;
+	while (aLength > 128)
+		{
+		*aDest++ = 127;
+		*aDest++ = aComponent1;
+		*aDest++ = aComponent2;
+		*aDest++ = aComponent3;
+		aLength -= 128;
+		}
+
+	*aDest++ = char(aLength-1);
+	*aDest++ = aComponent1;
+	*aDest++ = aComponent2;
+	*aDest++ = aComponent3;
+
+	return NoError;
+	}
+
+int BitmapCompiler::TrueColorPointerCompare(char* aColorPointer,char aComponent1,char aComponent2,char aComponent3)
+	{
+	return (*aColorPointer == aComponent1 && *(aColorPointer + 1) == aComponent2 && *(aColorPointer + 2) == aComponent3);
+	}
+
+/** The function encodes 32-bit buffer into 32-bit stream by using RLE compression algorithm*/
+int BitmapCompiler::CompressThirtyTwoABitData(char*& aDest,char* aSrce,int aSizeInBytes)
+	{
+	const char* destEnd = aDest + aSizeInBytes; 
+	char* srceLimitPtr = aSrce + aSizeInBytes;
+	char* srceLimitPtrMinusFour = srceLimitPtr - 4; // four bytes == one pixel
+	char* destCompressedLimitPtr = aDest + (aSizeInBytes * 7 / 8);
+	int ret = NoError;
+
+	while (aSrce < srceLimitPtrMinusFour)
+		{
+		char* runStartPtr = aSrce;
+		char component1 = *aSrce++;
+		char component2 = *aSrce++;
+		char component3 = *aSrce++;
+		char component4 = *aSrce++;
+
+		if (ColorAlphaPointerCompare(aSrce,component1,component2,component3,component4))
+			{
+			do
+				aSrce += 4;
+			while (aSrce < srceLimitPtr && ColorAlphaPointerCompare(aSrce,component1,component2,component3,component4));
+			int eqPixelLength = (aSrce - runStartPtr) / 4;
+			ret = WriteCompressedThirtyTwoABitValues(aDest,component1,component2,component3,component4,eqPixelLength,destEnd);
+			if (ret)
+				return ret;
+			}
+		else //non repeating pixel buffer
+			{
+			bool more  = true;
+			bool eqRun = false;
+			do {
+				component1 = *aSrce++;
+				component2 = *aSrce++;
+				component3 = *aSrce++;
+				component4 = *aSrce++;
+				more = (aSrce < srceLimitPtr);
+				eqRun = more && ColorAlphaPointerCompare(aSrce,component1,component2,component3,component4);
+				} while (more && !eqRun);
+			if (eqRun)
+				aSrce -= 4;
+			int nePixelLength = (aSrce - runStartPtr) / 4;
+			ret = WriteCompressedThirtyTwoABitData(aDest,runStartPtr,nePixelLength,destEnd);
+			if (ret)
+				return ret;
+			}
+		if (aDest > destCompressedLimitPtr)
+			return NoCompression;
+		}
+
+	if (aSrce < srceLimitPtr)
+		{
+		ret = WriteCompressedThirtyTwoABitData(aDest,aSrce,(srceLimitPtr - aSrce) / 4, destEnd);
+		if (ret)
+			return ret;
+		}
+
+	if (aDest > destCompressedLimitPtr)
+		return NoCompression;
+	return NoError;
+	}
+
+/** The function copies non repeating 32-bit buffer to 32-bit compressed buffer*/
+int BitmapCompiler::WriteCompressedThirtyTwoABitData(char*& aDest,char* aData,
+													 int aLength, const char* aDestEnd)
+	{
+	if (aLength < 1)
+		return CompressionError;
+
+	if(!CanCopy32bppData(aDest, aDestEnd, aLength))
+		return NoCompression;
+
+	while (aLength > 128)
+		{
+		*aDest++ = -128;
+		memcpy(aDest,aData,512);
+		aDest += 512;
+		aData += 512;
+		aLength -= 128;
+		}
+
+	*aDest++ = char(-aLength);
+	memcpy(aDest,aData, aLength*4);
+	aDest += aLength*4;
+	return NoError;
+	}
+
+/** The function copies repeating pixels including alpha to a 32-bit compressed buffer */
+int BitmapCompiler::WriteCompressedThirtyTwoABitValues(char*& aDest,char aComponent1,
+													   char aComponent2,char aComponent3,
+													   char aComponent4,int aLength,
+													   const char* aDestEnd)
+
+	{
+	if (aLength < 1)
+		return CompressionError;
+
+	if(!CanWrite32bppValue(aDest, aDestEnd, aLength))
+		return NoCompression;
+	while (aLength > 128)
+		{
+		*aDest++ = 127;
+		*aDest++ = aComponent1;
+		*aDest++ = aComponent2;
+		*aDest++ = aComponent3;
+		*aDest++ = aComponent4;
+		aLength -= 128;
+		}
+
+	*aDest++ = char(aLength-1);
+	*aDest++ = aComponent1;
+	*aDest++ = aComponent2;
+	*aDest++ = aComponent3;
+	*aDest++ = aComponent4;
+
+	return NoError;
+	}
+
+int BitmapCompiler::ColorAlphaPointerCompare(char* aColorPointer,char aComponent1,char aComponent2,char aComponent3,char aComponent4)
+	{
+	return (*aColorPointer == aComponent1 && *(aColorPointer + 1) == aComponent2 && *(aColorPointer + 2) == aComponent3 && *(aColorPointer + 3) == aComponent4);
+	}
+
+int BitmapCompiler::ReadHexString(char aHexBuf[10],char*& aDataPtr,char* aDataPtrLimit)
+	{
+	while (aDataPtr < aDataPtrLimit)
+		{
+		if (aDataPtr[0] == '0')
+			{
+			if (aDataPtr[1] == 'x' || aDataPtr[1] == 'X')
+				{
+				memcpy(aHexBuf,aDataPtr,10);
+				aDataPtr += 10;
+				return NoError;
+				}
+			}
+		aDataPtr++;
+		}
+
+	return PaletteFile;
+	}
+
+int BitmapCompiler::HexToInt(char aHighNibble,char aLowNibble)
+	{
+	return (HexToInt(aHighNibble) << 4) + HexToInt(aLowNibble);
+	}
+
+int BitmapCompiler::HexToInt(char aNibble)
+	{
+	int value = 0;
+
+	if (aNibble >= '0' && aNibble <= '9')
+		value = aNibble - '0';
+	else if (aNibble >= 'a' && aNibble <= 'f')
+		value = aNibble - 'a' + 10;
+	else if (aNibble >= 'A' && aNibble <= 'F')
+		value = aNibble - 'A' + 10;
+
+	return value;
+	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gfxconversion/mifconv/src/mifconv_mbmgenerator_rgb.cpp	Fri Apr 16 15:32:00 2010 +0300
@@ -0,0 +1,251 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+#include "mifconv_mbmgenerator.h"
+#include "mifconv_mbmgenerator_rgb.h"
+
+extern TRgb* color256Palette;
+extern char* color256InversePalette;
+
+TRgb* color256Palette = NULL;
+char* color256InversePalette = NULL;
+
+TRgb::TRgb()
+	: iRed(255),iGreen(255),iBlue(255),iSpare(0)
+/** Constructs default TRgb with all 3 colour components set to 255. */
+	{}
+
+TRgb::TRgb(long unsigned int val)
+	: iRed((unsigned char)(val&0xff)),iGreen((unsigned char)((val>>8)&0xff)),iBlue((unsigned char)((val>>16)&0xff)),iSpare(0)
+	{}
+
+TRgb::TRgb(int r,int g,int b)
+	: iRed((unsigned char)r),iGreen((unsigned char)g),iBlue((unsigned char)b),iSpare(0)
+/** Constructs a TRgb from its three component colours.
+	
+Each colour has a value between 0 and 255.
+	
+@param aRed Red component of the colour (0 - 255). 
+@param aGreen Green component of the colour (0 - 255). 
+@param aBlue Blue component of the colour (0 - 255). */
+	{}
+
+TRgb &TRgb::operator=(const TRgb &col)
+	{
+	iRed=col.iRed;
+	iGreen=col.iGreen;
+	iBlue=col.iBlue;
+	return(*this);
+	}
+
+int TRgb::operator==(const TRgb &col)
+	{
+	return(iRed==col.iRed && iGreen==col.iGreen && iBlue==col.iBlue);
+	}
+
+int TRgb::Difference(const TRgb& col) const
+	{
+	return abs(iRed-col.iRed) + abs(iGreen-col.iGreen) + abs(iBlue-col.iBlue);
+	}
+
+int TRgb::Gray2() const
+/** Gets a 2 level grayscale value from this TRgb. 
+
+@return Equivalent 2 level grayscale value. The greyscale value is 0 or 1, 
+and is calculated using c=(2*r+5*g+b)/1024. Note that the return value is 
+rounded down to the nearest integer. */
+	{
+	return Gray256() / 128;
+	}
+
+int TRgb::Gray4() const
+/** Gets a 4 level grayscale value from this TRgb.
+
+@return Equivalent 4 level grayscale value. The greyscale value is calculated 
+using c=(2*r+5*g+b)/512. Note that the return value is rounded down to the 
+nearest integer. */
+	{
+	return Gray256() / 64;
+	}
+
+int TRgb::Gray16() const
+/** Gets a 16 level grayscale value from this TRgb.
+
+@return The greyscale value is calculated using c=(2*r+5*g+b)/128. Note that 
+the return value is rounded down to the nearest integer. */
+	{
+	return Gray256() / 16;
+	}
+
+int TRgb::Gray256() const
+/** Gets a 256 level grayscale value from this TRgb.
+
+@return The greyscale value is calculated using c=(2*r+5*g+b)/8. Note that 
+the return value is rounded down to the nearest integer. */
+	{
+	return((2*iRed+5*iGreen+iBlue)/8);
+	}
+
+int TRgb::Color16() const
+/** Gets a 4 bit index into a colour palette from this TRgb.
+
+@return The EGA low colour constant closest to the TRgb. */
+	{
+	int index = (iRed >> 5) & 0x007;
+	index |= (iGreen  >> 2) & 0x038;
+	index |= (iBlue << 1) & 0x1c0;
+	return color16inverse[index];
+	}
+
+int TRgb::Color256() const
+/** Gets an 8 bit index into a colour palette from this TRgb.
+
+@return An 8 bit index. */
+	{
+	int index = (iRed >> 4) & 0x00f;
+	index |= iGreen & 0x0f0;
+	index |= (iBlue << 4) & 0xf00;
+
+	if (color256InversePalette)
+		return color256InversePalette[index];
+	else
+		return color256inverse[index];
+	}
+
+int TRgb::Color4K() const
+/** Gets a 12 bit index into a colour palette from this TRgb.
+
+@return A 12 bit index. */
+	{
+	return(((iRed&0xf0)<<4)|(iGreen&0xf0)|((iBlue&0xf0)>>4));
+	}
+
+int TRgb::Color64K() const
+/** Gets a 24 bit index into a colour palette from this TRgb.
+
+@return A 24 bit index. */
+	{
+	return(((iRed&0xf8)<<8)|((iGreen&0xfc)<<3)|((iBlue&0xf8)>>3));
+	}
+
+long int TRgb::Color16M() const
+/** Gets a 16 bit index into a colour palette from this TRgb.
+
+@return A 16 bit index. */
+	{
+	return((iRed<<16)|(iGreen<<8)|iBlue);
+	}
+
+TRgb TRgb::Gray2(int aGray2)
+/** Gets TRgb from 2 level grayscale. 
+
+The function takes a grayscale argument and return a TRgb whose red, green 
+and blue values are set to an appropriate level. 
+
+@param aGray2 Grayscale value to be converted. 
+@return Equivalent 24 bit colour. Gray2 has only 2 levels (black and white), -
+the function returns r=g=b=0 or r=g=b=255. */
+	{
+	aGray2 *= 255;
+	return TRgb(aGray2,aGray2,aGray2);
+	}
+
+TRgb TRgb::Gray4(int aGray4)
+/** Gets TRgb from 4 level grayscale. 
+
+The function takes a grayscale argument and return a TRgb whose red, green 
+and blue values are set to an appropriate level.
+
+@param aGray4 Grayscale value to be converted. 
+@return Equivalent 24 bit colour. Gray4 has 4 levels- the function returns 
+r=g=b=85*c, where c=0,1,2, or 3. */
+	{
+	aGray4 *= 85;
+	return TRgb(aGray4,aGray4,aGray4);
+	}
+
+TRgb TRgb::Gray16(int aGray16)
+/** Gets TRgb from 16 level grayscale. 
+
+The function takes a grayscale argument and return a TRgb whose red, green 
+and blue values are set to an appropriate level.
+
+@param aGray16 Grayscale value to be converted. 
+@return Equivalent 24 bit colour. Gray16 has 16 levels- the function returns 
+r=g=b=17*c, where c=0, 1, ... 15. */
+	{
+	aGray16 *= 17;
+	return TRgb(aGray16,aGray16,aGray16);
+	}
+
+TRgb TRgb::Gray256(int aGray256)
+/** Gets TRgb from 256 level grayscale. 
+
+The function takes a grayscale argument and return a TRgb whose red, green 
+and blue values are set to an appropriate level.
+
+@param aGray256 Grayscale value to be converted. 
+@return Equivalent 24 bit colour. Gray256 has 256 levels- the function 
+returns r=g=b=c, where c=0, 1, ... 255. */
+	{
+	return TRgb(aGray256,aGray256,aGray256);
+	}
+
+TRgb TRgb::Color256(int aColor256)
+/** Gets TRgb from 8 bit colour index.
+
+The function takes an 8 bit index into a colour palette and returns a TRgb 
+whose red, green and blue values are set to an appropriate level.
+
+@param aColor256 8 bit index into a colour palette. 
+@return Equivalent 24 bit colour. */
+	{
+	if (color256Palette)
+		return color256Palette[aColor256&0xff];
+	else
+		return TRgb(color256array[aColor256&0xff]);
+	}
+
+TRgb TRgb::Color4K(int aColor4K)
+	{
+	return TRgb(((aColor4K>>8)&0xf)*17,((aColor4K>>4)&0xf)*17,(aColor4K&0xf)*17);
+	}
+
+TRgb TRgb::Color64K(int aColor64K)
+/** Gets TRgb from 64K colour index.
+
+The function takes a 16 bit index into a colour palette and returns a TRgb 
+whose red, green and blue values are set to an appropriate level.
+
+@param aColor64K 16 bit index into a colour palette 
+@return Equivalent 24 bit colour. */
+	{
+	return TRgb(((aColor64K>>11)&0x1f)*255/31,((aColor64K>>5)&0x3f)*255/63,(aColor64K&0x1f)*255/31);
+	}
+
+TRgb TRgb::Color16M(long int aColor16M)
+/** Gets TRgb from 16M colour index.
+
+The function takes a 24 bit index into a colour palette and returns the TRgb 
+whose red, green and blue values represent it exactly.
+
+@param aColor16M 24 bit index into a colour palette 
+@return The TRgb which represents the index exactly. */
+	{
+	return TRgb(((aColor16M>>16)&0xff),(aColor16M>>8)&0xff,aColor16M&0xff);
+	}
+
--- a/gfxconversion/mifconv/src/mifconv_sourcefile.cpp	Tue Feb 02 01:11:11 2010 +0200
+++ b/gfxconversion/mifconv/src/mifconv_sourcefile.cpp	Fri Apr 16 15:32:00 2010 +0300
@@ -47,7 +47,8 @@
 iAnimated( src.IsAnimated() ),
 iMaskFilename( src.iMaskFilename ),
 iContent(src.iContent),
-iContentLen(src.iContentLen)
+iContentLen(src.iContentLen),
+iInfo(EFormatNotImportant)
 {
 }
 
@@ -177,3 +178,16 @@
     iDepth = MifConvArgumentManager::Instance()->ConvertToDepth(iDepthString); 
 }
 
+void MifConvSourceFile::SetCompileInfo(TCompileInfo aInfo)
+    {
+    iInfo = aInfo;
+    }
+
+void MifConvSourceFile::WriteCompileInfo(ostream& aOut)
+    {
+    aOut << iFilename;
+    if (iInfo == ENokiaBitmap)
+        aOut << " (Nokia format)";
+    else if (iInfo == EThirdPartyBitmap)
+        aOut << " (Third party format)";
+    }
--- a/gfxconversion/mifconv/src/mifconv_util.cpp	Tue Feb 02 01:11:11 2010 +0200
+++ b/gfxconversion/mifconv/src/mifconv_util.cpp	Fri Apr 16 15:32:00 2010 +0300
@@ -37,6 +37,41 @@
 MifConvString MifConvUtil::iDebugFile = "";
 MifConvString MifConvUtil::iTempDirectory = "";
 
+int MifConvUtil::ByteWidth(int aPixelWidth,int aBitsPerPixel)
+    {
+    int wordWidth = 0;
+
+    switch (aBitsPerPixel)
+        {
+    case 1:
+        wordWidth = (aPixelWidth + 31) / 32;
+        break;
+    case 2:
+        wordWidth = (aPixelWidth + 15) / 16;
+        break;
+    case 4:
+        wordWidth = (aPixelWidth + 7) / 8;
+        break;
+    case 8:
+        wordWidth = (aPixelWidth + 3) / 4;
+        break;
+    case 12:
+    case 16:
+        wordWidth = (aPixelWidth + 1) / 2;
+        break;
+    case 24:
+        wordWidth = (((aPixelWidth * 3) + 11) / 12) * 3;
+        break;
+    case 32:
+        wordWidth = aPixelWidth;
+        break;
+    default:
+        break;
+        };
+
+    return wordWidth * 4;
+    }
+
 /**
  *
  */
@@ -353,6 +388,12 @@
         {
             fixedname[0] = (char) toupper( fixedname[0] );
         }
+        
+        // Replace spaces (if any) with "_" in source filename.
+        size_t found;
+        while ((found = fixedname.rfind(" ")) != string::npos) {
+            fixedname.replace (found,1,"_");
+        }  
     }
     return fixedname;
 }
--- a/package_definition.xml	Tue Feb 02 01:11:11 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<SystemDefinition schema="3.0.0">
-  <package id="platformtools" name="Platform Tools">
-    <collection id="gfxconversion" name="Graphics Conversion">
-      <component id="bmconv_s60" filter="s60" name="S60 Bitmap Converter">
-			<!-- component need to be moved to appropriate location -->
-        <unit bldFile="/tools/platformtools/gfxconversion/bmconv_s60/group"/>
-      </component>
-      <component id="mifconv" filter="s60" name="Multi Icon File Converter">
-			<!-- component need to be moved to appropriate location -->
-        <unit bldFile="/tools/platformtools/gfxconversion/mifconv/group"/>
-      </component>
-    </collection>
-  </package>
-</SystemDefinition>