void KColorTable::readNamedColor(void) { if (d->mNamedColorList->count() != 0) { return; // Strings already present } QString filename = QString(":/rgb.txt"); if (filename.isEmpty()) return; QFile paletteFile(filename); if (!paletteFile.open(QIODevice::ReadOnly)) { return; } QByteArray line; QStringList list; while (!paletteFile.atEnd()) { line = paletteFile.readLine(); int red, green, blue; int pos = 0; if (sscanf(line, "%d %d %d%n", &red, &green, &blue, &pos) == 3) { // // Remove duplicates. Every name with a space and every name // that start with "gray". // QString name = line.mid(pos).trimmed(); QByteArray s1 = line.mid(pos); if (name.isNull() || name.indexOf(' ') != -1 || name.indexOf("gray") != -1 || name.indexOf("grey") != -1) { continue; } const QColor color(red, green, blue); if (color.isValid()) { const QString colorName(tr(name.toLatin1().data())); list.append(colorName); d->m_namedColorMap[ colorName ] = color; } } } list.sort(); d->mNamedColorList->addItems(list); if (d->mNamedColorList->count() == 0) { // // Give the error dialog box a chance to center above the // widget (or dialog). If we had displayed it now we could get a // situation where the (modal) error dialog box pops up first // preventing the real dialog to become visible until the // error dialog box is removed (== bad UI). // QTimer::singleShot(10, this, SLOT(slotShowNamedColorReadError())); } }
int main(int argc, char *argv[]) { QApplication::setStyle("plastique"); QApplication app(argc, argv); QApplication::setWindowIcon( QIcon( ":/megatendb.ico") ); QTranslator translator; translator.load( QString("megatendb_%1").arg(settings->lang()) ); app.installTranslator(&translator); QFile paletteFile(":/dark.xml"); paletteFile.open(QIODevice::ReadOnly); QPalette palette = PaletteEditor::importPalette( paletteFile.readAll() ); paletteFile.close(); app.setPalette(palette); QFile cert_file(":/ca.crt"); cert_file.open(QIODevice::ReadOnly); QSslCertificate cert(&cert_file); QSslSocket::addDefaultCaCertificate(cert); if( settings->email().isEmpty() ) (new Register)->show(); else (new Taskbar)->show(); if( !app.arguments().contains("--no-check") ) VersionCheck::getSingletonPtr(); return app.exec(); }
int main(int argc, char **argv) { if (argc <= 2) { printUsage(); return EXIT_SUCCESS; } std::string fileName(argv[2]); std::string outputFileName = fileName.substr(0, fileName.length()-4); outputFileName.append(".png"); if (argv[1][0] == 'f') { if (argc <= 5) { printUsage(); return EXIT_SUCCESS; } std::ifstream inFile(fileName); ktftd::img::FontSize size; switch (argv[3][0]) { case 's': size = ktftd::img::FONTSIZE_SMALL; break; case 'b': size = ktftd::img::FONTSIZE_BIG; break; default: printUsage(); return EXIT_FAILURE; } auto font = ktftd::img::LoadFont(inFile, size); std::string paletteName(argv[4]); int paletteOffset = atoi(argv[5]); std::ifstream paletteFile(paletteName); auto palette = ktftd::img::LoadPalette(paletteFile, paletteOffset); for (unsigned int c = font.startASCII; c < font.endASCII; c++) { std::stringstream ss; ss << "char" << std::setw(3) << std::setfill('0') << c << ".png"; auto outputImage = font.characterImages[c-font.startASCII].getImage(palette); outputImage.writePNG(ss.str().c_str()); } } else if (argv[1][0] == 'i') { if (argc <= 2) { printUsage(); return EXIT_SUCCESS; } auto spk = fileName.rfind(".SPK"); auto bdy = fileName.rfind(".BDY"); auto scr = fileName.rfind(".SCR"); auto dat = fileName.rfind(".DAT"); auto lbm = fileName.rfind(".LBM"); bool requiresPalette; ktftd::img::Palette palette; ktftd::img::PaletteImage palettedImage; ktftd::img::Image outputImage; std::ifstream inFile(fileName); if (spk == fileName.length()-4) { std::cout << "Is SPK File\n"; requiresPalette = true; palettedImage = ktftd::img::LoadSPKImage(inFile); } else if (bdy == fileName.length()-4) { std::cout << "Is BDY file\n"; requiresPalette = true; palettedImage = ktftd::img::LoadBDYImage(inFile); } else if(scr == fileName.length()-4) { std::cout << "Is SCR file\n"; requiresPalette = true; palettedImage = ktftd::img::LoadSCRImage(inFile); } else if(dat == fileName.length()-4) { std::cout << "Is DAT file\n"; requiresPalette = true; //DAT files are the same as SCR palettedImage = ktftd::img::LoadSCRImage(inFile); } else if(lbm == fileName.length() - 4) { std::cout << "Is LBM file\n"; requiresPalette = false; auto lbmFile = ktftd::img::LoadLBMImage(inFile); assert(lbmFile.palette); assert(lbmFile.image); outputImage = lbmFile.image->getImage(*lbmFile.palette); } else { std::cerr << "Unknown file type: \"" << fileName << "\"\n"; printUsage(); return EXIT_FAILURE; } if (requiresPalette) { if (argc <= 3) { printUsage(); return EXIT_FAILURE; } std::string paletteName (argv[3]); auto dat = paletteName.rfind(".DAT"); auto lbm = paletteName.rfind(".LBM"); if (dat == paletteName.length() - 4) { std::cout << "Is dat palette\n"; if (argc != 5) { printUsage(); return EXIT_FAILURE; } else { int paletteOffset = atoi(argv[4]); std::ifstream paletteFile(paletteName); palette = ktftd::img::LoadPalette(paletteFile, paletteOffset); } } else if(lbm == paletteName.length()-4) { std::cout << "Is lbm palette\n"; std::ifstream paletteFile(paletteName); auto lbmImage = ktftd::img::LoadLBMImage(paletteFile); palette = *lbmImage.palette; } else { std::cerr << "Unknown palette type: \"" << paletteName << "\"\n"; printUsage(); return EXIT_FAILURE; } outputImage = palettedImage.getImage(palette); } outputImage.writePNG(outputFileName.c_str()); } else if (argv[1][0] == 'p') { if (argc < 3) { printUsage(); return EXIT_FAILURE; } std::string paletteName(argv[2]); ktftd::img::Palette palette; if (paletteName.rfind(".LBM") == paletteName.length()-4) { std::ifstream paletteFile(paletteName); auto lbmImage = ktftd::img::LoadLBMImage(paletteFile); palette = *lbmImage.palette; } else if (paletteName.rfind(".DAT") == paletteName.length()-4) { if (argc != 4) { printUsage(); return EXIT_FAILURE; } std::ifstream inFile(argv[2]); int paletteOffset = atoi(argv[3]); palette = ktftd::img::LoadPalette(inFile, paletteOffset); } else { std::cerr << "Unknown palette file type\n"; printUsage(); return EXIT_FAILURE; } auto image = palette.toImage(); image.writePNG(outputFileName.c_str()); } else { printUsage(); return EXIT_FAILURE; } }
C3DOTextureHandler::C3DOTextureHandler() { CFileHandler teamTexFile("unittextures/tatex/teamtex.txt"); CFileHandler paletteFile("unittextures/tatex/palette.pal"); CSimpleParser parser(teamTexFile); std::set<std::string> teamTexes; while (!parser.Eof()) { teamTexes.insert(StringToLower(parser.GetCleanLine())); } TexFile* texfiles[10000]; int numfiles = 0; int totalSize = 0; const std::vector<std::string>& filesBMP = CFileHandler::FindFiles("unittextures/tatex/", "*.bmp"); std::vector<std::string> files = CFileHandler::FindFiles("unittextures/tatex/", "*.tga"); files.insert(files.end(), filesBMP.begin(), filesBMP.end()); std::set<string> usedNames; for (std::vector<std::string>::iterator fi = files.begin(); fi != files.end(); ++fi) { const std::string& s = *fi; const std::string s2 = StringToLower(FileSystem::GetBasename(s)); // avoid duplicate names and give tga images priority if (usedNames.find(s2) != usedNames.end()) { continue; } usedNames.insert(s2); if(teamTexes.find(s2) == teamTexes.end()){ TexFile* tex = CreateTex(s, s2, false); texfiles[numfiles++] = tex; totalSize += tex->tex.xsize * tex->tex.ysize; } else { TexFile* tex = CreateTex(s, s2, true); texfiles[numfiles++] = tex; totalSize += tex->tex.xsize * tex->tex.ysize; } } if (paletteFile.FileExists()) { palette.Init(paletteFile); } for (unsigned a = 0; a < CTAPalette::NUM_PALETTE_ENTRIES; ++a) { const std::string name = "ta_color" + IntToString(a, "%i"); TexFile* tex = new TexFile; tex->name = name; tex->tex.Alloc(1, 1); tex->tex.mem[0] = palette[a][0]; tex->tex.mem[1] = palette[a][1]; tex->tex.mem[2] = palette[a][2]; tex->tex.mem[3] = 0; // teamcolor tex->tex2.Alloc(1, 1); tex->tex2.mem[0] = 0; // self illum tex->tex2.mem[1] = 30; // reflectivity tex->tex2.mem[2] = 0; tex->tex2.mem[3] = 255; texfiles[numfiles++] = tex; totalSize += tex->tex.xsize * tex->tex.ysize; } // pessimistic guess about how much space will be wasted totalSize = (int)(totalSize * 1.2f); if (totalSize < 1024*1024) { bigTexX = 1024; bigTexY = 1024; } else if (totalSize < 1024*2048) { bigTexX = 1024; bigTexY = 2048; } else if (totalSize < 2048*2048) { bigTexX = 2048; bigTexY = 2048; } else { bigTexX = 2048; bigTexY = 2048; throw content_error("Too many/large texture in 3do texture-atlas to fit in 2048*2048"); } qsort(texfiles,numfiles,sizeof(TexFile*), CompareTatex2); unsigned char* bigtex1 = new unsigned char[bigTexX * bigTexY * 4]; unsigned char* bigtex2 = new unsigned char[bigTexX * bigTexY * 4]; for (int a = 0; a < (bigTexX * bigTexY); ++a) { bigtex1[a*4 + 0] = 128; bigtex1[a*4 + 1] = 128; bigtex1[a*4 + 2] = 128; bigtex1[a*4 + 3] = 0; bigtex2[a*4 + 0] = 0; bigtex2[a*4 + 1] = 128; bigtex2[a*4 + 2] = 0; bigtex2[a*4 + 3] = 255; } int cury = 0; int maxy = 0; int foundx = 0; int foundy = 0; std::list<int2> nextSub; std::list<int2> thisSub; for (int a = 0; a < numfiles; ++a) { CBitmap* curtex1 = &texfiles[a]->tex; CBitmap* curtex2 = &texfiles[a]->tex2; bool done = false; while (!done) { // Find space for us if (thisSub.empty()) { if (nextSub.empty()) { cury = maxy; maxy += curtex1->ysize; if (maxy > bigTexY) { delete[] bigtex1; delete[] bigtex2; throw content_error("Too many/large texture in 3do texture-atlas to fit in 2048*2048"); } thisSub.push_back(int2(0, cury)); } else { thisSub = nextSub; nextSub.clear(); } } if (thisSub.front().x + curtex1->xsize>bigTexX) { thisSub.clear(); continue; } if(thisSub.front().y+curtex1->ysize>maxy){ thisSub.pop_front(); continue; } // ok found space for us foundx=thisSub.front().x; foundy=thisSub.front().y; done=true; if (thisSub.front().y + curtex1->ysize<maxy){ nextSub.push_back(int2(thisSub.front().x, thisSub.front().y + curtex1->ysize)); } thisSub.front().x += curtex1->xsize; while ((thisSub.size() > 1) && (thisSub.front().x >= (++thisSub.begin())->x)) { (++thisSub.begin())->x = thisSub.front().x; thisSub.erase(thisSub.begin()); } } for (int y = 0; y < curtex1->ysize; ++y) { for (int x = 0; x < curtex1->xsize; ++x) { for (int col = 0; col < 4; ++col) { bigtex1[(((foundy + y) * bigTexX + (foundx + x)) * 4) + col] = curtex1->mem[(((y * curtex1->xsize) + x) * 4) + col]; bigtex2[(((foundy + y) * bigTexX + (foundx + x)) * 4) + col] = curtex2->mem[(((y * curtex1->xsize) + x) * 4) + col]; } } } UnitTexture* unittex = new UnitTexture; unittex->xstart = (foundx + 0.5f) / (float)bigTexX; unittex->ystart = (foundy + 0.5f) / (float)bigTexY; unittex->xend = (foundx + curtex1->xsize - 0.5f) / (float)bigTexX; unittex->yend = (foundy + curtex1->ysize - 0.5f) / (float)bigTexY; textures[texfiles[a]->name] = unittex; delete texfiles[a]; } glGenTextures(1, &atlas3do1); glBindTexture(GL_TEXTURE_2D, atlas3do1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR/*_MIPMAP_NEAREST*/); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8 ,bigTexX, bigTexY, 0, GL_RGBA, GL_UNSIGNED_BYTE, bigtex1); //glBuildMipmaps(GL_TEXTURE_2D,GL_RGBA8 ,bigTexX, bigTexY, GL_RGBA, GL_UNSIGNED_BYTE, bigtex1); glGenTextures(1, &atlas3do2); glBindTexture(GL_TEXTURE_2D, atlas3do2); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR/*_MIPMAP_NEAREST*/); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, bigTexX, bigTexY, 0, GL_RGBA, GL_UNSIGNED_BYTE, bigtex2); //glBuildMipmaps(GL_TEXTURE_2D,GL_RGBA8, bigTexX, bigTexY, GL_RGBA, GL_UNSIGNED_BYTE, bigtex2); // CBitmap save(tex, bigTexX, bigTexY); // save.Save("unittex-1x.jpg"); UnitTexture* t = new UnitTexture(); t->xstart = 0.0f; t->ystart = 0.0f; t->xend = 1.0f; t->yend = 1.0f; textures["___dummy___"] = t; delete[] bigtex1; delete[] bigtex2; }
std::vector<TexFile*> C3DOTextureHandler::LoadTexFiles() { CFileHandler teamTexFile("unittextures/tatex/teamtex.txt"); CFileHandler paletteFile("unittextures/tatex/palette.pal"); CSimpleParser parser(teamTexFile); std::set<std::string> teamTexes; while (!parser.Eof()) { teamTexes.insert(StringToLower(parser.GetCleanLine())); } std::vector<TexFile*> texfiles; const std::vector<std::string>& filesBMP = CFileHandler::FindFiles("unittextures/tatex/", "*.bmp"); std::vector<std::string> files = CFileHandler::FindFiles("unittextures/tatex/", "*.tga"); files.insert(files.end(), filesBMP.begin(), filesBMP.end()); std::set<string> usedNames; for (std::vector<std::string>::iterator fi = files.begin(); fi != files.end(); ++fi) { const std::string& s = *fi; const std::string s2 = StringToLower(FileSystem::GetBasename(s)); // avoid duplicate names and give tga images priority if (usedNames.find(s2) != usedNames.end()) { continue; } usedNames.insert(s2); if(teamTexes.find(s2) == teamTexes.end()){ TexFile* tex = CreateTex(s, s2, false); texfiles.push_back(tex); } else { TexFile* tex = CreateTex(s, s2, true); texfiles.push_back(tex); } } if (paletteFile.FileExists()) { palette.Init(paletteFile); } for (unsigned a = 0; a < CTAPalette::NUM_PALETTE_ENTRIES; ++a) { TexFile* tex = new TexFile(); tex->name = "ta_color" + IntToString(a, "%i"); tex->tex.Alloc(1, 1); tex->tex.mem[0] = palette[a][0]; tex->tex.mem[1] = palette[a][1]; tex->tex.mem[2] = palette[a][2]; tex->tex.mem[3] = 0; // teamcolor tex->tex2.Alloc(1, 1); tex->tex2.mem[0] = 0; // self illum tex->tex2.mem[1] = 30; // reflectivity tex->tex2.mem[2] = 0; tex->tex2.mem[3] = 255; texfiles.push_back(tex); } return texfiles; }
void KPaletteTable::readNamedColor( void ) { if( mNamedColorList->count() != 0 ) { return; // Strings already present } TDEGlobal::locale()->insertCatalogue("tdelibs_colors"); // // Code somewhat inspired by KPalette. // const char * const *path = namedColorFilePath(); for( int i=0; path[i]; ++i ) { TQFile paletteFile( path[i] ); if( !paletteFile.open( IO_ReadOnly ) ) { continue; } TQString line; TQStringList list; while( paletteFile.readLine( line, 100 ) != -1 ) { int red, green, blue; int pos = 0; if( sscanf(line.ascii(), "%d %d %d%n", &red, &green, &blue, &pos ) == 3 ) { // // Remove duplicates. Every name with a space and every name // that start with "gray". // TQString name = line.mid(pos).stripWhiteSpace(); if( name.isNull() || name.find(' ') != -1 || name.find( "gray" ) != -1 || name.find( "grey" ) != -1 ) { continue; } const TQColor color ( red, green, blue ); if ( color.isValid() ) { const TQString colorName( i18n("color", name.latin1() ) ); list.append( colorName ); d->m_namedColorMap[ colorName ] = color; } } } list.sort(); mNamedColorList->insertStringList( list ); break; } if( mNamedColorList->count() == 0 ) { // // Give the error dialog box a chance to center above the // widget (or dialog). If we had displayed it now we could get a // situation where the (modal) error dialog box pops up first // preventing the real dialog to become visible until the // error dialog box is removed (== bad UI). // TQTimer::singleShot( 10, this, TQT_SLOT(slotShowNamedColorReadError()) ); } }