gfxconversion/mifconv/src/mifconv_mbmgenerator_bmtopbm.cpp
changeset 12 9b222d6b819d
equal deleted inserted replaced
0:f453ebb75370 12:9b222d6b819d
       
     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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "mifconv_mbmgenerator_bmtopbm.h"
       
    19 #include "mifconv_util.h"
       
    20 
       
    21 const TRgbQuad KNokiaBrandBlue = {0xcc,0x33,0,0};
       
    22 const TRgbQuad KNokiaBrandGreen = {0x33,0x99,0,0};
       
    23 const int KNokiaBrandBlueIndex = 254;
       
    24 const int KNokiaBrandGreenIndex = 253;
       
    25 
       
    26 const unsigned char ColorRemapTable[256] = 
       
    27 	{
       
    28 	0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
       
    29 	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
       
    30 	0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
       
    31 	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
       
    32 	0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
       
    33 	0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
       
    34 	0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
       
    35 	0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
       
    36 	0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
       
    37 	0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
       
    38 	0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
       
    39 	0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
       
    40 	0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
       
    41 	0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0x00, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
       
    42 	0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
       
    43 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xd7
       
    44 	};
       
    45 
       
    46 BitmapLoader::BitmapLoader():
       
    47 	iNumBmpColors(0),
       
    48 	iBmpColors(NULL),
       
    49 	iBmpBits(NULL),
       
    50 	iAlphaBits(NULL)
       
    51 	{}
       
    52 
       
    53 BitmapLoader::~BitmapLoader()
       
    54 	{
       
    55 	delete [] iBmpColors;
       
    56 	delete [] iBmpBits;
       
    57 	delete [] iAlphaBits;
       
    58 	}
       
    59 
       
    60 int BitmapLoader::LoadBitmap(MifConvSourceFile& aFilename,int aBpp,TBitmapColor aColor,SEpocBitmapHeader*& aPbm)
       
    61 	{
       
    62 	iSourceFile = &aFilename;
       
    63 	char sig[2];
       
    64 	
       
    65 	fstream file(aFilename.Filename().c_str(), FILE_IN_BINARY_NOCREATE_FLAGS);
       
    66 	
       
    67 	if (file.is_open()==0)
       
    68 		return Files;
       
    69 	file.read(sig,2);
       
    70 	file.close();
       
    71 	if (file.gcount()!=2)
       
    72 		return SourceFile ;
       
    73 	if (sig[0]!='B'||sig[1]!='M')
       
    74 		return SourceFile;
       
    75 
       
    76 	int ret = DoLoad(aFilename.Filename().c_str());
       
    77 
       
    78     // If we have >8bit color BMP file and c8, change to c16
       
    79     if( (aColor==EColorBitmap) && (aBpp==8) && 
       
    80         (iBmpHeader.biBitCount>8) )
       
    81         {
       
    82         // cout << "Note: " << aFilename.Filename() << " changed c8 -> c16" << "\n";
       
    83         aBpp = 16;
       
    84         }
       
    85 	if (!ret && aColor==EColorBitmapAlpha)
       
    86 		{
       
    87 		int filenameLen = aFilename.Filename().length();
       
    88 		MifConvString alphaFilename = "";
       
    89 		
       
    90 		int dotPos = -1;
       
    91 		for (int i = 0; i < filenameLen; ++i)
       
    92 			if (aFilename.Filename()[i]=='.')
       
    93 				dotPos=i;
       
    94 		// Prefix length.
       
    95 		int prefixLen = (dotPos>=0?dotPos:filenameLen);
       
    96 		alphaFilename = aFilename.Filename().substr(0,prefixLen);
       
    97 		alphaFilename += "-alpha";
       
    98 		if (dotPos>=0)
       
    99 		    alphaFilename += aFilename.Filename().substr(prefixLen,aFilename.Filename().length());
       
   100 		alphaFilename += '\0';
       
   101 		ret = DoLoadAlpha(alphaFilename); // overlay alpha data from separate file
       
   102 		}
       
   103 	if (!ret)
       
   104 		ret = DoConvert(aBpp,aColor,aPbm);
       
   105 	return ret;
       
   106 	}
       
   107 
       
   108 int BitmapLoader::DoLoad(const char* aFileName)
       
   109 	{
       
   110     
       
   111     fstream file(aFileName, FILE_IN_BINARY_NOCREATE_FLAGS);
       
   112     
       
   113 	if (file.is_open()==0)
       
   114 		return Files;
       
   115 	TBitmapFileHeader bmpfile;
       
   116 	long size=sizeof(TBitmapFileHeader);
       
   117 	
       
   118 	file.read((char *)&bmpfile,size);
       
   119 	if (file.gcount()!=size)
       
   120 		return SourceFile;
       
   121 	size=sizeof(TBitmapInfoHeader);
       
   122 	file.read((char *)&iBmpHeader,size);
       
   123 	if (file.gcount()!=size)
       
   124 		return SourceFile;
       
   125 	if (iBmpHeader.biCompression != 0)
       
   126 	    {
       
   127 		return UnknownCompression;
       
   128 	    }
       
   129 	size=bmpfile.bfSize-sizeof(TBitmapInfoHeader)-sizeof(TBitmapFileHeader);
       
   130 	long bitcount=iBmpHeader.biBitCount;
       
   131 	long colors=iBmpHeader.biClrUsed;
       
   132 	if (colors==0)
       
   133 		{
       
   134 		if (bitcount==24)
       
   135 			iNumBmpColors=0;
       
   136 		else if (bitcount==32)
       
   137 			iNumBmpColors=0;//See MSDN - BITMAPFILEHEADER and BITMAPINFOHEADER structures.
       
   138                             //If biCompression is 0 - we don't have TRgbQuad array! 
       
   139 		else
       
   140 			iNumBmpColors=1<<bitcount;
       
   141 		}
       
   142 	else
       
   143 		iNumBmpColors=colors;
       
   144 	if (iNumBmpColors > 256)
       
   145 		return SourceFile;
       
   146 	if (iNumBmpColors>0)
       
   147 		{
       
   148 		iBmpColors = new TRgbQuad[iNumBmpColors];
       
   149 		if (iBmpColors == NULL)
       
   150 			return NoMemory;
       
   151 		memset(iBmpColors,0,iNumBmpColors*sizeof(TRgbQuad));
       
   152 		}
       
   153 	size-=iNumBmpColors*sizeof(TRgbQuad);
       
   154 	iBmpBits = new char[size];
       
   155 	if (iBmpBits == NULL)
       
   156 		return NoMemory;
       
   157 	memset(iBmpBits,0xff,size);
       
   158 
       
   159 	if(iBmpColors != NULL)
       
   160 	    {
       
   161 		file.read((char *)iBmpColors,iNumBmpColors*sizeof(TRgbQuad));
       
   162 		if (file.gcount()!=(int)(iNumBmpColors*sizeof(TRgbQuad)))
       
   163 			return SourceFile;
       
   164 	    }
       
   165 	file.read(iBmpBits,size);
       
   166 	file.close();
       
   167 	if (file.gcount()!=size)
       
   168 		return SourceFile;
       
   169 	return NoError;
       
   170 	}
       
   171 
       
   172 int BitmapLoader::DoLoadAlpha(MifConvString& aAlphaFileName)
       
   173 	{
       
   174     
       
   175     fstream file(aAlphaFileName.c_str(), FILE_IN_BINARY_NOCREATE_FLAGS);
       
   176     
       
   177 	if (file.is_open()==0)
       
   178 		return AlphaFiles;
       
   179 	TBitmapFileHeader alphaBmpfile;
       
   180 	long size=sizeof(TBitmapFileHeader);
       
   181 	file.read((char *)&alphaBmpfile,size);
       
   182 	if (file.gcount()!=size)
       
   183 		return SourceFile;
       
   184 	size=sizeof(TBitmapInfoHeader);
       
   185 	TBitmapInfoHeader alphaBmpInfo;
       
   186 	file.read((char *)&alphaBmpInfo,size);
       
   187 	if (file.gcount()!=size)
       
   188 		return SourceFile;
       
   189 	if (alphaBmpInfo.biCompression != 0)
       
   190 		return UnknownCompression;
       
   191 	if (alphaBmpInfo.biWidth != iBmpHeader.biWidth || alphaBmpInfo.biHeight != iBmpHeader.biHeight)
       
   192 		return AlphaDimensions;
       
   193 	if (alphaBmpInfo.biBitCount != 8)
       
   194 		return AlphaBpp;
       
   195 	size=alphaBmpfile.bfSize-sizeof(TBitmapInfoHeader)-sizeof(TBitmapFileHeader);
       
   196 	long numBmpColors=alphaBmpInfo.biClrUsed;
       
   197 	if (numBmpColors == 0)
       
   198 		numBmpColors = 256;
       
   199 	if (numBmpColors != 256)
       
   200 		return SourceFile;
       
   201 	size-=numBmpColors*sizeof(TRgbQuad);
       
   202 	iAlphaBits = new char[size];
       
   203 	if (iAlphaBits == NULL)
       
   204 		{
       
   205 		return NoMemory;
       
   206 		}
       
   207 	memset(iAlphaBits,0xff,size);
       
   208 	char* bmpColors = new char[numBmpColors*sizeof(TRgbQuad)];
       
   209 	file.read((char *)bmpColors,numBmpColors*sizeof(TRgbQuad));
       
   210 	delete [] bmpColors; // we aren't interested in the palette data for the 8bpp grayscale alpha bmp
       
   211 	if (file.gcount()!=(int)(numBmpColors*sizeof(TRgbQuad)))
       
   212 		return SourceFile;
       
   213 	file.read(iAlphaBits,size);
       
   214 	file.close();
       
   215 	if (file.gcount()!=size)
       
   216 		return SourceFile;
       
   217 	return NoError;
       
   218 	}
       
   219 
       
   220 TRgb BitmapLoader::GetBmpPixel(long aXCoord,long aYCoord)
       
   221 	{
       
   222 	TRgb darkgray(128,128,128);
       
   223 	TRgb darkgrayex(127,127,127);
       
   224 	TRgb lightgray(192,192,192);
       
   225 	TRgb lightgrayex(187,187,187);
       
   226 	unsigned char col;
       
   227 	TRgb color;
       
   228 
       
   229 	switch(iBmpHeader.biBitCount)
       
   230 		{
       
   231 		case 1:
       
   232 			col=iBmpBits[(iBmpHeader.biHeight-aYCoord-1)*(((iBmpHeader.biWidth+31)>>5)<<2)+(aXCoord>>3)];
       
   233 			col&=(0x80>>(aXCoord%8));
       
   234 			if (iBmpColors)
       
   235 				{
       
   236 				TRgbQuad rgbq;
       
   237 				if (col)
       
   238 					rgbq = iBmpColors[1];
       
   239 				else
       
   240 					rgbq = iBmpColors[0];
       
   241 				color = TRgb(rgbq.iRed,rgbq.iGreen,rgbq.iBlue);
       
   242 				}
       
   243 			else
       
   244 				{
       
   245 				if (col)
       
   246 					color = TRgb(0x00ffffff);
       
   247 				else
       
   248 					color = TRgb(0);
       
   249 				}
       
   250 			break;
       
   251 		case 4:
       
   252 			col=iBmpBits[(iBmpHeader.biHeight-aYCoord-1)*(((iBmpHeader.biWidth+7)>>3)<<2)+(aXCoord>>1)];
       
   253 			if (aXCoord%2==0)
       
   254 				col=(unsigned char)(col>>4);
       
   255 			col&=0x0f;
       
   256 			if (iBmpColors)
       
   257 				{
       
   258 				TRgbQuad rgbq = iBmpColors[col];
       
   259 				color = TRgb(rgbq.iRed,rgbq.iGreen,rgbq.iBlue);
       
   260 				}
       
   261 			else
       
   262 				{
       
   263 				col *= 17;
       
   264 				color = TRgb(col,col,col);
       
   265 				}
       
   266 			break;
       
   267 		case 8:
       
   268 			col=iBmpBits[(iBmpHeader.biHeight-aYCoord-1)*((iBmpHeader.biWidth+3)&~3)+aXCoord];
       
   269 			if (iBmpColors)
       
   270 				{
       
   271 				TRgbQuad rgbq = iBmpColors[col];
       
   272 				color = TRgb(rgbq.iRed,rgbq.iGreen,rgbq.iBlue);
       
   273 				}
       
   274 			else
       
   275 				color = TRgb(col,col,col);
       
   276 			break;
       
   277 		case 16:
       
   278 			{
       
   279 			unsigned short int* wordptr = (unsigned short int*)&iBmpBits[(iBmpHeader.biHeight-aYCoord-1)*(((iBmpHeader.biWidth+1)&~1)<<1)+(aXCoord<<1)];
       
   280 			color = TRgb((*wordptr&0x7c)>>10,(*wordptr&0x3e)>>5,(*wordptr&0x1f));
       
   281 			}
       
   282 			break;
       
   283 		case 24:
       
   284 			{
       
   285 			TRgbTriple rgbcol = *((TRgbTriple *)&(iBmpBits[(iBmpHeader.biHeight-aYCoord-1)*((3*iBmpHeader.biWidth+3)&~3)+aXCoord+(aXCoord<<1)]));
       
   286 			color = TRgb(rgbcol.rgbtRed,rgbcol.rgbtGreen,rgbcol.rgbtBlue);
       
   287 			}
       
   288 			break;
       
   289 		case 32:
       
   290 			{
       
   291 			unsigned long int* dwordptr = (unsigned long int*)&iBmpBits[(iBmpHeader.biHeight-aYCoord-1)*((iBmpHeader.biWidth)<<2)+(aXCoord<<2)];
       
   292 			color = TRgb((*dwordptr&0xff0000)>>16,(*dwordptr&0xff00)>>8,*dwordptr&0xff);
       
   293 			}
       
   294 			break;
       
   295 		default:
       
   296 			break;
       
   297 		}
       
   298 	if (color == darkgray)
       
   299 		color = darkgrayex;
       
   300 	else if (color == lightgray)
       
   301 		color = lightgrayex;
       
   302 	return color;
       
   303 	}
       
   304 
       
   305 unsigned char BitmapLoader::GetAlphaPixel(long aXCoord,long aYCoord)
       
   306 	{
       
   307 	return iAlphaBits[(iBmpHeader.biHeight-aYCoord-1)*((iBmpHeader.biWidth+3)&~3)+aXCoord];
       
   308 	}
       
   309 
       
   310 int BitmapLoader::DoConvert(int aBpp,TBitmapColor aColor,SEpocBitmapHeader*& aPbm)
       
   311 	{
       
   312 	bool useAlpha = (aColor==EColorBitmapAlpha);
       
   313 	long desttwipswidth = 0;
       
   314 	long desttwipsheight = 0;
       
   315 
       
   316 	long bytewidth = MifConvUtil::ByteWidth(iBmpHeader.biWidth,aBpp);
       
   317 	long destlength = iBmpHeader.biHeight * bytewidth;
       
   318 
       
   319 	if (iBmpHeader.biXPelsPerMeter>0)
       
   320 		desttwipswidth = iBmpHeader.biWidth*1440000/254/iBmpHeader.biXPelsPerMeter;
       
   321 	if (iBmpHeader.biYPelsPerMeter>0)
       
   322 		desttwipsheight = iBmpHeader.biHeight*1440000/254/iBmpHeader.biYPelsPerMeter;
       
   323 
       
   324 	aPbm = (SEpocBitmapHeader*)new char[sizeof(SEpocBitmapHeader) + destlength];
       
   325 	if (aPbm == NULL)
       
   326 		return NoMemory;
       
   327 	memset(aPbm,0,sizeof(SEpocBitmapHeader));
       
   328 
       
   329 	// aBitmap->iByteWidth = bytewidth;
       
   330 	// aBitmap->iDataOffset = sizeof(Bitmap);
       
   331 
       
   332 	aPbm->iBitmapSize = sizeof(SEpocBitmapHeader) + destlength;
       
   333 	aPbm->iStructSize = sizeof(SEpocBitmapHeader);
       
   334 	aPbm->iWidthInPixels = iBmpHeader.biWidth;
       
   335 	aPbm->iHeightInPixels = iBmpHeader.biHeight;
       
   336 	aPbm->iWidthInTwips = desttwipswidth;
       
   337 	aPbm->iHeightInTwips = desttwipsheight;
       
   338 	aPbm->iBitsPerPixel = aBpp;
       
   339 	aPbm->iColor = aColor;
       
   340 	aPbm->iPaletteEntries = 0;
       
   341 	aPbm->iCompression = ENoBitmapCompression;
       
   342 
       
   343 	char* pbmBits = ((char*)aPbm) + sizeof(SEpocBitmapHeader);
       
   344 	memset(pbmBits,0xff,destlength);
       
   345 
       
   346 	long col = 0;
       
   347 	char* pixadd = 0;
       
   348 	bool indicesOnly = false;
       
   349 	if (aColor == EColorBitmap && aBpp == 8)
       
   350 		{
       
   351 		indicesOnly =
       
   352 			(iNumBmpColors==256 &&
       
   353 			 iBmpColors[KNokiaBrandGreenIndex].iRed == KNokiaBrandGreen.iRed &&
       
   354 			 iBmpColors[KNokiaBrandGreenIndex].iBlue == KNokiaBrandGreen.iBlue &&
       
   355 			 iBmpColors[KNokiaBrandGreenIndex].iGreen == KNokiaBrandGreen.iGreen &&
       
   356 			 iBmpColors[KNokiaBrandBlueIndex].iRed == KNokiaBrandBlue.iRed &&
       
   357 			 iBmpColors[KNokiaBrandBlueIndex].iBlue == KNokiaBrandBlue.iBlue &&
       
   358 			 iBmpColors[KNokiaBrandBlueIndex].iGreen == KNokiaBrandBlue.iGreen);
       
   359 		}
       
   360 
       
   361 	switch(aBpp)
       
   362 		{
       
   363 	case 1:
       
   364 		{
       
   365 		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
       
   366 			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
       
   367 				{
       
   368 				TRgb color=GetBmpPixel(xcrd,ycrd);
       
   369 				col=color.Gray2();
       
   370 				pixadd=&(pbmBits[ycrd*bytewidth+(xcrd>>3)]);
       
   371 				(*pixadd)&=~(1<<((xcrd&7)));
       
   372 				(*pixadd)|=(unsigned char)(col<<(xcrd&7));
       
   373 				}
       
   374 		}
       
   375 		break;
       
   376 	case 2:
       
   377 		{
       
   378 		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
       
   379 			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
       
   380 				{
       
   381 				TRgb color=GetBmpPixel(xcrd,ycrd);
       
   382 				col=color.Gray4();
       
   383 				pixadd=&(pbmBits[ycrd*bytewidth+(xcrd>>2)]);
       
   384 				(*pixadd)&=~(0x3<<(2*(xcrd%4)));
       
   385 				(*pixadd)|=(unsigned char)(col<<(2*(xcrd%4)));
       
   386 				}
       
   387 		}
       
   388 		break;
       
   389 	case 4:
       
   390 		{
       
   391 		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
       
   392 			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
       
   393 				{
       
   394 				TRgb color=GetBmpPixel(xcrd,ycrd);
       
   395 				if (aColor == EMonochromeBitmap)
       
   396 					col = color.Gray16();
       
   397 				else
       
   398 					col = color.Color16();
       
   399 				pixadd=&(pbmBits[ycrd*bytewidth+(xcrd>>1)]);
       
   400 				if (xcrd%2!=0)
       
   401 					*pixadd=(unsigned char)((unsigned char)((col<<4)|(*pixadd&0x0f)));
       
   402 				else
       
   403 					*pixadd=(unsigned char)((unsigned char)(col|(*pixadd&0xf0)));
       
   404 				}
       
   405 		}
       
   406 		break;
       
   407 	case 8:
       
   408 		{
       
   409 		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
       
   410 			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
       
   411 				{
       
   412 				if (indicesOnly)
       
   413 					{
       
   414 					unsigned char pixel = iBmpBits[(iBmpHeader.biHeight-ycrd-1)*((iBmpHeader.biWidth+3)&~3)+xcrd];
       
   415 					col = ColorRemapTable[pixel];
       
   416 					iSourceFile->SetCompileInfo(MifConvSourceFile::ENokiaBitmap);
       
   417 					}
       
   418 				else
       
   419 					{
       
   420 					TRgb color=GetBmpPixel(xcrd,ycrd);
       
   421 					if (aColor == EMonochromeBitmap)
       
   422 						col = color.Gray256();
       
   423 					else
       
   424 						col = color.Color256();
       
   425 					iSourceFile->SetCompileInfo(MifConvSourceFile::EThirdPartyBitmap);
       
   426 					}
       
   427 				pixadd=&(pbmBits[ycrd*((iBmpHeader.biWidth+3)&~3)+xcrd]);
       
   428 				*pixadd=(unsigned char)col;
       
   429 				}
       
   430 		}
       
   431 		break;
       
   432 	case 12:
       
   433 		{
       
   434 		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
       
   435 			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
       
   436 				{
       
   437 				TRgb color=GetBmpPixel(xcrd,ycrd);
       
   438 				col=color.Color4K();
       
   439 				pixadd=&(pbmBits[ycrd*bytewidth+(xcrd<<1)]);
       
   440 				unsigned short* wordadd=(unsigned short*)pixadd;
       
   441 				*wordadd=(unsigned short)col;
       
   442 				}
       
   443 		}
       
   444 		break;
       
   445 	case 16:
       
   446 		{
       
   447 		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
       
   448 			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
       
   449 				{
       
   450 				TRgb color=GetBmpPixel(xcrd,ycrd);
       
   451 				col=color.Color64K();
       
   452 				pixadd=&(pbmBits[ycrd*bytewidth+(xcrd<<1)]);
       
   453 				unsigned short* wordadd=(unsigned short*)pixadd;
       
   454 				*wordadd=(unsigned short)col;
       
   455 				}
       
   456 		}
       
   457 		break;
       
   458 	case 24:
       
   459 		{
       
   460 		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
       
   461 			{
       
   462 			unsigned char* bytePtr = (unsigned char*)&pbmBits[ycrd*bytewidth];
       
   463 			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
       
   464 				{
       
   465 				TRgb col = GetBmpPixel(xcrd,ycrd);
       
   466 				*bytePtr++ = (unsigned char) col.iBlue;
       
   467 				*bytePtr++ = (unsigned char) col.iGreen;
       
   468 				*bytePtr++ = (unsigned char) col.iRed;
       
   469 				}
       
   470 			}
       
   471 		}
       
   472 		break;
       
   473 	case 32:
       
   474 		{
       
   475 		for(long ycrd=0;ycrd<iBmpHeader.biHeight;ycrd++)
       
   476 			{
       
   477 			unsigned char* bytePtr = (unsigned char*)&pbmBits[ycrd*bytewidth];
       
   478 			for(long xcrd=0;xcrd<iBmpHeader.biWidth;xcrd++)
       
   479 				{
       
   480 				TRgb col = GetBmpPixel(xcrd,ycrd);
       
   481 				unsigned char alpha = useAlpha?GetAlphaPixel(xcrd,ycrd):(unsigned char)0;
       
   482 				*bytePtr++ = (unsigned char) col.iBlue;
       
   483 				*bytePtr++ = (unsigned char) col.iGreen;
       
   484 				*bytePtr++ = (unsigned char) col.iRed;
       
   485 				*bytePtr++ = alpha;	
       
   486 				}
       
   487 			}
       
   488 		}
       
   489 		break;
       
   490 		};
       
   491 
       
   492 	return NoError;
       
   493 	}
       
   494