343 if(!aXPM.size())
return 0;
345 std::vector<int> vals;
346 tools::values<int>(aXPM[0],
" ",
false,vals);
347 if(vals.size()!=4)
return 0;
349 int height = vals[1];
350 int numcol = vals[2];
351 int numchars = vals[3];
352 if(width<=0)
return 0;
353 if(height<=0)
return 0;
354 if(numcol<=0)
return 0;
355 if(numchars<=0)
return 0;
358 if((height+numcol)!=aXPM.size()-1)
return 0;
362 for (i = 0; i < numcol; i++) {
363 std::string::size_type pos = aXPM[i+1].rfind(
"c #");
364 if(pos==std::string::npos)
continue;
365 lcolor = aXPM[i+1].size()-(pos+3);
370 if( (lcolor!=6) && (lcolor!=12) )
return 0;
373 char* charlookuptable =
new char[numcol * numchars];
375 int* rlookuptable =
new int[numcol];
376 int* glookuptable =
new int[numcol];
377 int* blookuptable =
new int[numcol];
381 for (i = 0; i < numcol; i++) {
383 const std::string& line = aXPM[i+1];
386 if((
int)line.size()<numchars) {
391 for (
int j = 0; j < numchars; j ++) {
392 charlookuptable[(i * numchars) + j] = line[j];
396 std::string::size_type pos = line.find(
"c #",numchars);
397 if(pos!=std::string::npos) {
398 size_t lc = line.size()-(pos+3);
419 rlookuptable[i] = -1;
420 glookuptable[i] = -1;
421 blookuptable[i] = -1;
429 unsigned char pixelsize = 4;
431 if(!done) pixelsize = 0;
435 HBITMAP hbmp =
CreateDIB(aDC,width,height,pixelsize * 8,&dest);
438 int noneColor = ::GetSysColor(COLOR_3DFACE);
441 for (i = 0; i < height; i++) {
443 const std::string& line = aXPM[i + 1 + numcol];
446 if((
int)line.size()!=(numchars*width)) {
451 int y = i * width * pixelsize;
453 for (
int j = 0; j < width; j++) {
455 int x = j * pixelsize;
458 for (
int k = 0; k < numcol; k++) {
461 for (
int l = 0; l < numchars; l++) {
462 if (charlookuptable[(k * numchars) + l]
463 != line[(j * numchars) + l]) {
472 if (rlookuptable[k] == -1) {
473 r = (noneColor & 0x00FF0000)>>16;
474 g = (noneColor & 0x0000FF00)>>8;
475 b = noneColor & 0x000000FF;
483 ((
unsigned char*)dest)[y + x + 0] = b;
484 ((
unsigned char*)dest)[y + x + 1] = g;
485 ((
unsigned char*)dest)[y + x + 2] = r;
486 ((
unsigned char*)dest)[y + x + 3] = 0;
488 ((
unsigned char*)dest)[y + x + 0] = b;
489 ((
unsigned char*)dest)[y + x + 1] = g;
490 ((
unsigned char*)dest)[y + x + 2] = r;
505 ::DeleteObject(hbmp);
511 delete [] charlookuptable;
512 delete [] rlookuptable;
513 delete [] glookuptable;
514 delete [] blookuptable;