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