/* Gets the path to a texture by first checking if the texture exists in texture_path and if not, using the data path. Checks all supported extensions by replacing the original extension. If not found, returns "". Utilizes a thread-safe cache. */ std::string getTexturePath(const std::string &filename) { std::string fullpath = ""; /* Check from cache */ bool incache = g_texturename_to_path_cache.get(filename, &fullpath); if(incache) return fullpath; /* Check from texture_path */ std::string texture_path = g_settings->get("texture_path"); if(texture_path != "") { std::string testpath = texture_path + DIR_DELIM + filename; // Check all filename extensions. Returns "" if not found. fullpath = getImagePath(testpath); } /* Check from $user/textures/all */ if(fullpath == "") { std::string texture_path = porting::path_user + DIR_DELIM + "textures" + DIR_DELIM + "all"; std::string testpath = texture_path + DIR_DELIM + filename; // Check all filename extensions. Returns "" if not found. fullpath = getImagePath(testpath); } /* Check from default data directory */ if(fullpath == "") { std::string base_path = porting::path_share + DIR_DELIM + "textures" + DIR_DELIM + "base" + DIR_DELIM + "pack"; std::string testpath = base_path + DIR_DELIM + filename; // Check all filename extensions. Returns "" if not found. fullpath = getImagePath(testpath); } // Add to cache (also an empty result is cached) g_texturename_to_path_cache.set(filename, fullpath); // Finally return it return fullpath; }
SubgameSpec findSubgame(const std::string &id) { if(id == "") return SubgameSpec(); std::string share = porting::path_share; std::string user = porting::path_user; std::vector<GameFindPath> find_paths; find_paths.push_back(GameFindPath( user + DIR_DELIM + "games" + DIR_DELIM + id + "_game", true)); find_paths.push_back(GameFindPath( user + DIR_DELIM + "games" + DIR_DELIM + id, true)); find_paths.push_back(GameFindPath( share + DIR_DELIM + "games" + DIR_DELIM + id + "_game", false)); find_paths.push_back(GameFindPath( share + DIR_DELIM + "games" + DIR_DELIM + id, false)); // Find game directory std::string game_path; bool user_game = true; // Game is in user's directory for(u32 i=0; i<find_paths.size(); i++){ const std::string &try_path = find_paths[i].path; if(fs::PathExists(try_path)){ game_path = try_path; user_game = find_paths[i].user_specific; break; } } if(game_path == "") return SubgameSpec(); std::string gamemod_path = game_path + DIR_DELIM + "mods"; // Find mod directories std::set<std::string> mods_paths; if(!user_game) mods_paths.insert(share + DIR_DELIM + "mods" + DIR_DELIM + id); if(user != share || user_game) mods_paths.insert(user + DIR_DELIM + "mods" + DIR_DELIM + id); std::string game_name = getGameName(game_path); if(game_name == "") game_name = id; std::string menubackground_path; std::string menuoverlay_path; std::string menuicon_path; #ifndef SERVER menubackground_path = getImagePath(game_path + DIR_DELIM + "menu" + DIR_DELIM + "background.png"); menuoverlay_path = getImagePath(game_path + DIR_DELIM + "menu" + DIR_DELIM + "overlay.png"); menuicon_path = getImagePath(game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png"); #endif return SubgameSpec(id, game_path, gamemod_path, mods_paths, game_name, menubackground_path, menuoverlay_path, menuicon_path); }
bool CameraFile::isValid() { FILE *f; bool status = false; #ifdef _WIN32 status = (fopen_s(&f, getImagePath().c_str(), "r") == 0); #else status = ((f = fopen(getImagePath().c_str(), "r")) != 0); #endif if (status) { fclose(f); } return status; }
Item* Gold::copy(ISceneNode * parent, ISceneManager * manager) { Item* item = new Gold(parent, manager, getNamex(), getModelPath().data(), getImagePath().data(), randomBetween(1, DEFAULT_MAX_GOLD)); cout<<"vo loadamesh"<<endl; IAnimatedMesh * mesh = item->getSceneManager()->getMesh(item->getModelPath().data()); cout<<"vo loada texture "<< getImagePath() <<endl; image_ = item->getSceneManager()->getVideoDriver()->getTexture(getImagePath().data()); item->setImage(image_); printf("%Ponteiro da textura: %p\n",image_); cout<<"vo loada node"<<endl; item->setNode(item->getSceneManager()->addAnimatedMeshSceneNode(mesh, item, ISceneNode::getID())); cout<<"vo geta node"<<endl; item->getAnimatedNode()->setMaterialFlag(video::EMF_LIGHTING, false); item->setScale(core::vector3df(0.02,0.02,0.02)); item->setRotation(core::vector3df(90, 0, 0)); item->setPosition(item->getPosition() + core::vector3df(50,50,50)); return item; }
void CityLordView::repaintView(){ QPixmap pixmap; for(int row=0;row<clientManager->getMap()->getNumberOfRows();row++){ for(int col=0;col<clientManager->getMap()->getNumberOfCols();col++){ pixmap = QPixmap(getImagePath(clientManager->getMap()->getCase(Location(row, col))->getImageName())); itemArray[row][col]->setPixmap(pixmap); itemArray[row][col]->setOffset(carToIso(Location(row, col), pixmap)); } } scene->update(); }
chartaken::chartaken(int x_pos, int y_pos, QWidget *parent) { this->setParent(parent); this->setAttribute(Qt::WA_TransparentForMouseEvents); this->move(x_pos, y_pos); this->resize(60, 60); QString path = getImagePath("char_taken.png"); if (fileExists(path)) this->setPixmap(path); }
CityLordView::CityLordView(QWidget* parent, ClientManagerGUI* cm, bool* sabotage): QGraphicsView(parent), px(0), py(0), BASE(getImagePath("base")), scene(new QGraphicsScene(this)), sabotageActive(sabotage), previousSelectedLocation(-1, -1), clientManager(cm), numberOfRows(0), \ numberOfCols(0), itemArray(nullptr), visitorItemMap(), qtimer(new QTimer(this)){ setGeometry(0, 60, WIDTH, HEIGHT); resize(WIDTH, HEIGHT); setScene(scene); setSceneRect(-((WIDTH/2)-(BASE.width()/2)), 0, WIDTH-2, HEIGHT-2); this->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); ZOOMLEVEL=DEFAULTZOOMLEVEL; COORDX=1520; COORDY=0; connect(qtimer, SIGNAL(timeout()), scene, SLOT(advance())); qtimer->start(8); }
charicon::charicon(int x_pos, int y_pos, QWidget *parent) { this->setParent(parent); this->resize(60, 60); this->move(x_pos, y_pos); //connect(this, SIGNAL (clicked()), this, SLOT (handleButton())); m_parent = parent; //connect(this, SIGNAL(clicked()), this, SLOT(handleClick())); char_selector = new QLabel(parent); //char_selector->setParent(parent); char_selector->setStyleSheet("border-image:url(" + getImagePath("char_selector.png") + ")"); char_selector->setAttribute(Qt::WA_TransparentForMouseEvents); char_selector->resize(62, 62); char_selector->move(x_pos - 1, y_pos - 1); char_selector->hide(); }
QImage PictureHelper::loadQImage(QString url) { QImageReader reader; reader.setFileName(getImagePath(url)); // Resize img if too large (1280x768) QSize imgSize = reader.size(); if (imgSize.width()<imgSize.height()) { if (imgSize.height()>720) { imgSize.setWidth((int)imgSize.width() * 720 / imgSize.height()); imgSize.setHeight(720); reader.setScaledSize(imgSize); } } else if (imgSize.width()>imgSize.height()) { if (imgSize.width() > 720) { imgSize.setHeight((int)imgSize.height() * 720 / imgSize.width()); imgSize.setWidth(720); reader.setScaledSize(imgSize); } } return reader.read(); }
photo* db::getImage(int imageId){ QSqlQuery query(database); query.prepare("SELECT DISTINCT Fid,Pid FROM HasFaces WHERE Iid = :imageId "); query.bindValue(":imageId", imageId); bool k=query.exec(); QList<face*>* fl = new QList<face*>(); QString imagePath = getImagePath(imageId); string path = QStringToString(imagePath); while(query.next()){ int faceId = query.value(0).toInt(); int personId = query.value(1).toInt(); face* f = getFace(faceId); f->setLabel(QStringToString(getPersonName(personId))); f->setPhotoID(imageId); f->setPath(path); fl->append(f); } photo* p = new photo(imagePath,fl); p->setID(imageId); return p; }
void LinuxAppPlatform::loadPNG(ImageData& imgData, const std::string& path, bool b) { std::cout << "loadPNG: " << path << "(from assets: " << b << ")" << "\n"; FILE* file = fopen(getImagePath(path, b).c_str(), "rb"); if (file == NULL) { std::cout << "failed to open file\n"; return; } png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png) { std::cout << "png_create_read_struct failed\n"; abort(); return; } png_infop info = png_create_info_struct(png); if (!info) { std::cout << "png_create_info_struct failed\n"; abort(); return; } unsigned char header[8]; if(fread(header, 8, 1, file) != 1) { std::cout << "failed to read png header\n"; return; } if(png_sig_cmp(header, 0, 8)) { std::cout << "header is invalid\n"; return; } if (setjmp(png_jmpbuf(png))) { std::cout << "failed to load png\n"; abort(); return; } png_init_io(png, file); png_set_sig_bytes(png, 8); png_read_info(png, info); imgData.w = (int) png_get_image_width(png, info); imgData.h = (int) png_get_image_height(png, info); imgData.format = TextureFormat::U8888; imgData.mipLevel = 0; png_byte bitDepth = png_get_bit_depth(png, info); png_byte colorType = png_get_color_type(png, info); switch(colorType){ case PNG_COLOR_TYPE_PALETTE: png_set_palette_to_rgb(png); break; case PNG_COLOR_TYPE_RGB: if(png_get_valid(png, info, PNG_INFO_tRNS)) { png_set_tRNS_to_alpha(png); } else { png_set_filler(png, 0xff, PNG_FILLER_AFTER); } break; case PNG_COLOR_TYPE_RGB_ALPHA: break; case PNG_COLOR_TYPE_GRAY: if(bitDepth < 8) { png_set_expand_gray_1_2_4_to_8(png); } default: std::cout << "png: unsupported color type\n"; } if(bitDepth == 16) { png_set_strip_16(png); } png_read_update_info(png, info); png_size_t rowBytes = png_get_rowbytes(png, info); std::vector<char> data(rowBytes * imgData.h); png_byte* rows[imgData.h]; for (int i = 0; i < imgData.h; i++) { rows[i] = (png_byte*) &data[i * rowBytes]; } png_read_image(png, rows); fclose(file); { std::string empty; ((void **) &imgData.data)[0] = ((void **) &empty)[0]; imgData.data = " "; } imgData.data = std::string(&data[0], rowBytes * imgData.h); }
void Slideshow::nextSlide() { rootObject->setProperty("src", getImagePath()); }
string getImageManifestPath( const string& storeDir, const string& imageId) { return path::join(getImagePath(storeDir, imageId), "manifest"); }
string getImageRootfsPath( const string& storeDir, const string& imageId) { return path::join(getImagePath(storeDir, imageId), "rootfs"); }
SubgameSpec findSubgame(const std::string &id) { if (id.empty()) return SubgameSpec(); std::string share = porting::path_share; std::string user = porting::path_user; // Get games install locations Strfnd search_paths(getSubgamePathEnv()); // Get all possible paths fo game std::vector<GameFindPath> find_paths; while (!search_paths.at_end()) { std::string path = search_paths.next(PATH_DELIM); find_paths.emplace_back(path + DIR_DELIM + id, false); find_paths.emplace_back(path + DIR_DELIM + id + "_game", false); } find_paths.emplace_back( user + DIR_DELIM + "games" + DIR_DELIM + id + "_game", true); find_paths.emplace_back(user + DIR_DELIM + "games" + DIR_DELIM + id, true); find_paths.emplace_back( share + DIR_DELIM + "games" + DIR_DELIM + id + "_game", false); find_paths.emplace_back(share + DIR_DELIM + "games" + DIR_DELIM + id, false); // Find game directory std::string game_path; bool user_game = true; // Game is in user's directory for (const GameFindPath &find_path : find_paths) { const std::string &try_path = find_path.path; if (fs::PathExists(try_path)) { game_path = try_path; user_game = find_path.user_specific; break; } } if (game_path.empty()) return SubgameSpec(); std::string gamemod_path = game_path + DIR_DELIM + "mods"; // Find mod directories std::set<std::string> mods_paths; if (!user_game) mods_paths.insert(share + DIR_DELIM + "mods"); if (user != share || user_game) mods_paths.insert(user + DIR_DELIM + "mods"); // Get meta std::string conf_path = game_path + DIR_DELIM + "game.conf"; Settings conf; conf.readConfigFile(conf_path.c_str()); std::string game_name; if (conf.exists("name")) game_name = conf.get("name"); else game_name = id; std::string game_author; if (conf.exists("author")) game_author = conf.get("author"); int game_release = 0; if (conf.exists("release")) game_release = conf.getS32("release"); std::string menuicon_path; #ifndef SERVER menuicon_path = getImagePath( game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png"); #endif return SubgameSpec(id, game_path, gamemod_path, mods_paths, game_name, menuicon_path, game_author, game_release); }
void TopologyNode::paintSubIcons(QPainter *painter,const QRectF &itemRect) { if(mNodeFlags & NF_ISVM) { QPixmap vmPixmap(getImagePath(MII_VMFLAG)); painter->drawPixmap(itemRect.left() + itemRect.width() - vmPixmap.width() - 5 ,itemRect.top() + (itemRect.height() - vmPixmap.height()) / 2 , vmPixmap); } if(!sBDM) { sBDM=BlockDeviceManager::GetSingletonPtr(); } if((mNodeFlags & NF_BLOCKED) && sBDM && (sBDM->state()!=BLOCKDEVICE_FSM::FS_CLOSED &&sBDM->state()!=BLOCKDEVICE_FSM::FS_CLOSED_ADMIN) ) { QPixmap vmPixmap(getImagePath(MII_BLOCKFLAG)); painter->drawPixmap(itemRect.left() + /*itemRect.width() - vmPixmap.width() -*/+ 5 ,itemRect.top() + (itemRect.height() - vmPixmap.height()) / 2 , vmPixmap); } if(!(mNodeFlags & (NF_ISLOCALHOST|NF_ISCENTRALROUTER))) { #ifdef USE_RDP if((mNodeFlags & NF_RDP_ENABLED) &&(sMapFlags & MF_USE_RDP_SCAN)) { QPixmap vmPixmap(getImagePath(MII_RDPFLAG)); painter->drawPixmap(itemRect.left() + itemRect.width()/2-vmPixmap.width()/2 ,itemRect.top() + (itemRect.height() - vmPixmap.height()) / 2 , vmPixmap); } else { #endif #ifdef USE_PUTTY if((mNodeFlags & NF_PUTTY_ENABLED) && (sMapFlags & MF_USE_PUTTY_SCAN)) { QPixmap vmPixmap(getImagePath(MII_PUTTYFLAG)); painter->drawPixmap(itemRect.left() + itemRect.width()/2-vmPixmap.width()/2 ,itemRect.top() + (itemRect.height() - vmPixmap.height()) / 2 , vmPixmap); } #endif #ifdef USE_RDP } #endif } // if((false //#ifdef USE_RDP // || ((mNodeFlags & NF_RDP_ENABLED) &&(sMapFlags & MF_USE_RDP_SCAN)) //#endif //#ifdef USE_PUTTY // || ((mNodeFlags & NF_PUTTY_ENABLED) && (sMapFlags & MF_USE_PUTTY_SCAN)) //#endif // )&& !(mNodeFlags & (NF_ISLOCALHOST|NF_ISCENTRALROUTER))) // { // int img_idx=-1; //#ifdef USE_RDP // img_idx=MII_RDPFLAG; //#endif //#ifdef USE_PUTTY // img_idx=MII_PUTTYFLAG; //#endif // Q_ASSERT(img_idx != -1); // QPixmap vmPixmap(getImagePath(img_idx)); // painter->drawPixmap(itemRect.left() + itemRect.width()/2-vmPixmap.width()/2 // ,itemRect.top() + (itemRect.height() - vmPixmap.height()) / 2 , vmPixmap); // } }
/* * Load an image from a QUrl. * We need to load the image from the corresponding path */ QImage loadImage(QUrl url) { QString where = getImagePath(url); return QImage(where); }