gfxconversion/mifconv/inc/mifconv_mbmgenerator.h
branchRCL_3
changeset 9 1f6339ced17d
equal deleted inserted replaced
4:23f0e6a5b752 9:1f6339ced17d
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Mifconv's bitmap converters class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __MIFCONVMBMGENERATOR_H__
       
    20 #define __MIFCONVMBMGENERATOR_H__
       
    21 
       
    22 #include "mifconv.h"
       
    23 #include "mifconv_util.h"
       
    24 
       
    25 #ifdef __linux__
       
    26     #define GNUPACK __attribute__((packed)) 
       
    27     #define OPTCHAR '-'
       
    28     /* on Linux the '/' optchar cannot be supported as filenames can start with '/'. */
       
    29     #define ALTERNATE_OPTCHAR '-'
       
    30 #else
       
    31     #define GNUPACK
       
    32     #define OPTCHAR '-' 
       
    33     #define ALTERNATE_OPTCHAR '/'
       
    34 #endif
       
    35 
       
    36 const long int KWriteOnceFileStoreUid=268435511;
       
    37 const long int KCBitwiseBitmapUid=268435520;
       
    38 const long int KMultiBitmapRomImageUid=268435521;
       
    39 const long int KMultiBitmapFileImageUid=268435522;
       
    40 const long int KMultiBitmapFileImageChecksum=1194943545;
       
    41 
       
    42 enum TBitmapColor
       
    43     {
       
    44     EMonochromeBitmap,
       
    45     EColorBitmap,
       
    46     EColorBitmapAlpha,  
       
    47     EColorBitmapUndefined   
       
    48     };
       
    49 
       
    50 struct TBitmapInfoHeader
       
    51     {
       
    52     unsigned long biSize;
       
    53     long biWidth;
       
    54     long biHeight;
       
    55     unsigned short biPlanes;
       
    56     unsigned short biBitCount;
       
    57     unsigned long biCompression;
       
    58     unsigned long biSizeImage;
       
    59     long biXPelsPerMeter;
       
    60     long biYPelsPerMeter;
       
    61     unsigned long biClrUsed;
       
    62     unsigned long biClrImportant;
       
    63     };
       
    64 
       
    65 #ifndef __linux__ 
       
    66 #include <pshpack2.h>
       
    67 #endif 
       
    68 
       
    69 enum Errors
       
    70     {
       
    71     NoCompression=-1,
       
    72     NoError=0,
       
    73     NoMemory,
       
    74     Files,
       
    75     SourceFile,
       
    76     DestFile,
       
    77     OutOfRange,
       
    78     TooManyArgs,
       
    79     UnknownCompression,
       
    80     CompressionError,
       
    81     DecompressionError,
       
    82     Bpp,
       
    83     PaletteFile,
       
    84     PaletteSupportNotImplemented,
       
    85     AlphaFiles,
       
    86     AlphaDimensions,
       
    87     AlphaBpp
       
    88     };
       
    89 
       
    90 /** 
       
    91 Defines the types of file compression. 
       
    92 */
       
    93 enum TBitmapfileCompression
       
    94     {
       
    95     /** Bitmap file is not compressed. */
       
    96     ENoBitmapCompression=0,
       
    97     /** File is compressed using run-length encoding compression. */
       
    98     EByteRLECompression,
       
    99     /** File is compressed using twelve bit run-length encoding compression. */
       
   100     ETwelveBitRLECompression,
       
   101     /** File is compressed using sixteen bit run-length encoding compression. */
       
   102     ESixteenBitRLECompression,
       
   103     /** File is compressed using twenty four bit run-length encoding compression. */
       
   104     ETwentyFourBitRLECompression,
       
   105     /** File is compressed using unsigned thirty two bit run-length encoding compression. */
       
   106     EThirtyTwoUBitRLECompression,
       
   107     /** File is compressed using unsigned thirty two bit run-length encoding compression and includes an alpha channel. */
       
   108     EThirtyTwoABitRLECompression,
       
   109     /** Insert new compression types here */
       
   110     ERLECompressionLast = 255
       
   111     };
       
   112 
       
   113 struct SEpocBitmapHeader
       
   114 /** Contains information about the bitmap when streaming bitmaps to stores. */
       
   115     {
       
   116     /** The size of the bitmap data, in bytes. */
       
   117     long iBitmapSize;
       
   118     /** The size of the structure in which the bitmap data is stored. */
       
   119     long iStructSize;
       
   120     long iWidthInPixels;
       
   121     long iHeightInPixels;
       
   122     long iWidthInTwips;
       
   123     long iHeightInTwips;
       
   124     /** The bitmaps number of bits per pixel */
       
   125     long iBitsPerPixel;
       
   126     /** Whether or not the bitmap is colour. A true value means that the bitmap 
       
   127     is colour. */
       
   128     TBitmapColor iColor;
       
   129     /** The number of entries in the bitmap's palette. */
       
   130     long iPaletteEntries;   // always 0 in current implementations
       
   131     /** The type of compression used to store the bitmap. */
       
   132     TBitmapfileCompression iCompression;
       
   133     };
       
   134 
       
   135 #ifndef __linux__ 
       
   136 #include <pshpack2.h>
       
   137 #endif 
       
   138 
       
   139 struct TBitmapFileHeader
       
   140     {
       
   141     unsigned short bfType;
       
   142     unsigned long bfSize;
       
   143     unsigned short bfReserved1;
       
   144     unsigned short bfReserved2;
       
   145     unsigned long bfOffBits;
       
   146     } GNUPACK;
       
   147 #ifndef __linux__ 
       
   148 #include <poppack.h>
       
   149 #endif 
       
   150     
       
   151 struct TRgbTriple
       
   152     {
       
   153     unsigned char rgbtBlue;
       
   154     unsigned char rgbtGreen;
       
   155     unsigned char rgbtRed;
       
   156     } GNUPACK;
       
   157 #ifndef __linux__ 
       
   158 #include <poppack.h>
       
   159 #endif 
       
   160 
       
   161 class TRgb
       
   162 /** 
       
   163 24-bit RGB colour value with 8 bits each for red, green and blue.
       
   164 
       
   165 All Graphics drawing functions are specified in terms of a 32-bit TRgb colour 
       
   166 containing the three colour values plus 8 unused bits. For hardware which 
       
   167 does not support 24-bit colour, a mapping from TRgb to display colours is 
       
   168 performed. 
       
   169 
       
   170 The supported display modes are enumerated in the TDisplayMode type. In each 
       
   171 display mode a unique index can represent each physical colours supported, 
       
   172 and which can be mapped onto a full RGB value. The mappings are as follows: 
       
   173 
       
   174 16-colour displays use the EGA colour set: black, white, and then both light 
       
   175 and dark versions of grey, red, green, blue, cyan, magenta and yellow
       
   176 
       
   177 256-colour displays support 216 colours made up of 6x6x6 RGB values, each 
       
   178 containing all possible multiples of 51 for R,G,B values. Additionally, all 
       
   179 remaining 10 shades of pure red, green, blue and grey are represented, by 
       
   180 adding all remaining multiples of 17. This use of 256 colours is sometimes 
       
   181 known as the Netscape colour cube.
       
   182 
       
   183 4096-colour displays effectively support RGB values with 4 bits per primary 
       
   184 colour
       
   185 
       
   186 64k-colour displays effectively support RGB values with 5 bits allocated to 
       
   187 red, 6 to green and 5 to blue
       
   188 
       
   189 16 million-colour displays support true colour with 8 bits allocated to each 
       
   190 primary colour
       
   191 
       
   192 @see TDisplayMode
       
   193 @see DynamicPalette 
       
   194 */
       
   195     {
       
   196 public:
       
   197     TRgb();
       
   198     TRgb(long unsigned int val);
       
   199     TRgb(int aRed,int aGreen,int aBlue);
       
   200     TRgb &operator=(const TRgb& aColor);
       
   201     int operator==(const TRgb& aColor);
       
   202     int Difference(const TRgb& col) const;
       
   203     int Gray2() const;
       
   204     int Gray4() const;
       
   205     int Gray16() const;
       
   206     int Gray256() const;
       
   207     int Color16() const;
       
   208     int Color256() const;
       
   209     int Color4K() const;
       
   210     int Color64K() const;
       
   211     long int Color16M() const;
       
   212     static TRgb Gray2(int aGray2);
       
   213     static TRgb Gray4(int aGray4);
       
   214     static TRgb Gray16(int aGray16);
       
   215     static TRgb Gray256(int aGray256);
       
   216     static TRgb Color16(int aColor16);
       
   217     static TRgb Color256(int aColor256);
       
   218     static TRgb Color4K(int aColor64K);
       
   219     static TRgb Color64K(int aColor64K);
       
   220     static TRgb Color16M(long int aColor16M);
       
   221 public:
       
   222     unsigned char iRed;
       
   223     unsigned char iGreen;
       
   224     unsigned char iBlue;
       
   225     unsigned char iSpare;
       
   226     };
       
   227 
       
   228 /**
       
   229  * Converter class for converting .bmp files to .mbm file.
       
   230  */
       
   231 class BmConv
       
   232 {
       
   233 public:
       
   234 
       
   235     /**
       
   236      * Default constructor
       
   237      * @param aSourcefilenames Source file names to be compiled.
       
   238      */ 
       
   239     BmConv(MifConvSourceFileList aSourcefilenames);
       
   240 
       
   241     /**
       
   242      * Destructor
       
   243      */
       
   244     ~BmConv();
       
   245    
       
   246     /**
       
   247      * Compile source files given in constructor to destination file using a given palette.
       
   248      * @param aDestfilename Location of destination file.
       
   249      * @param aPaletteFilename Location of palette file.
       
   250      */
       
   251     int Compile(const MifConvString& aDestfilename, const MifConvString& aPaletteFilename);
       
   252 
       
   253 protected:
       
   254 
       
   255     MifConvString ErrorMessage(int aErrorNumber, MifConvString aDestfile, bool aDestCreated);
       
   256     void Report(int aError);
       
   257     
       
   258 private:
       
   259     
       
   260     /**
       
   261      * List os source files.
       
   262      */
       
   263     MifConvSourceFileList iSourcefilenames;
       
   264 };
       
   265 
       
   266 #endif