GLuint CDImageLoader::createOpenGLTextureFromImage(const string& filename, int &width, int &height) { Fl_Shared_Image* image = Fl_Shared_Image::get(filename.c_str()); if ( !image ) { return 0; } width = image->w(); height = image->h(); return CDImageLoader::createOpenGLTextureFromImage( image ); }
FltkImage * FltkImage::load(char const * filename) const { if (SLStringUtil::empty(filename)) return 0; Fl_Shared_Image *sharedImage = Fl_Shared_Image::get(filename); Fl_Image * image = sharedImage->copy(); sharedImage->release(); if ( image->h() == 0 ) { delete image; return 0; } FltkImage * result = new FltkImage(image); result->setFilename(filename); return result; }
void CInstaller::Init(int argc, char **argv) { const int buttonsy = WindowH()-ButtonHeight()-ButtonHSpacing(); m_pMainWindow = new Fl_Double_Window(WindowW(), WindowH(), "Nixstaller"); m_pMainWindow->callback(CancelCB, this); Fl_Group *maingroup = new Fl_Group(0, 0, WindowW(), WindowH()); maingroup->resizable(NULL); maingroup->box(FL_FLAT_BOX); maingroup->color(fl_lighter(FL_BACKGROUND_COLOR)); Fl_Pack *mainpack = new Fl_Pack(0, 0, WindowW(), WindowH()-90); mainpack->resizable(NULL); mainpack->type(Fl_Pack::VERTICAL); CreateHeader(); m_pWizard = new Fl_Wizard(0, m_pHeaderGroup->h(), WindowW(), (buttonsy-m_pHeaderGroup->h()-ButtonHSpacing())); m_pWizard->box(FL_ENGRAVED_BOX); m_pWizard->end(); mainpack->end(); m_pCancelButton = new Fl_Button(ButtonWOffset(), buttonsy, 0, ButtonHeight(), GetTranslation("Cancel")); SetButtonWidth(m_pCancelButton); m_pCancelButton->callback(CancelCB, this); m_pButtonPack = new Fl_Pack(0, buttonsy, 0, ButtonHeight()); m_pButtonPack->type(Fl_Pack::HORIZONTAL); m_pButtonPack->spacing(ButtonWSpacing()); m_pBackButton = new Fl_Button(0, buttonsy, 0, ButtonHeight(), CreateText("@<- %s", GetTranslation("Back"))); SetButtonWidth(m_pBackButton); m_pBackButton->callback(BackCB, this); m_pNextButton = new Fl_Button(0, buttonsy, 0, ButtonHeight(), CreateText("%s @->", GetTranslation("Next"))); SetButtonWidth(m_pNextButton); m_pNextButton->callback(NextCB, this); m_pButtonPack->end(); UpdateButtonPack(); maingroup->end(); CBaseInstall::Init(argc, argv); Fl_Shared_Image *img = Fl_Shared_Image::get(GetLogoFName()); if (img) { m_pLogoBox = new Fl_Box(HeaderSpacing(), HeaderSpacing(), img->w()+HeaderSpacing(), img->h()); m_pLogoBox->align(FL_ALIGN_TOP | FL_ALIGN_INSIDE); m_pLogoBox->image(img); m_pHeaderGroup->add(m_pLogoBox); } int size = m_pWizard->children(); for (int i=0; i<size; i++) { CInstallScreen *screen = GetScreen(m_pWizard->child(i)); if (screen->CanActivate()) { ActivateScreen(screen); break; } } m_pMainWindow->end(); m_pMainWindow->show(argc, argv); }
void UserInterface::doGenJob(void* d) { UserInterface* ui = static_cast<UserInterface*>(d); if (!ProgressDialog::isVisible()) { // canceled by user ui->genJobs_.clear(); ProgressDialog::close(); ui->openMapsWindow_ = false; } else if (ui->genJobs_.empty()) { if (ui->openMapsWindow_) { ProgressDialog::close(); ui->mapsWindow_->show(); ui->openMapsWindow_ = false; } else { // show Done for a short time ProgressDialog::progress(100, "Done"); Fl::add_timeout(0.5, closeProgressDialog, d); } } else { float const percentage = 100*static_cast<float>(ui->genJobsCount_ - ui->genJobs_.size())/ui->genJobsCount_; GenJob const job = ui->genJobs_.front(); ui->genJobs_.pop_front(); ProgressDialog::progress(percentage, job.name_); Fl::check(); try { Fl_Shared_Image * img; switch (job.type_) { case GEN_INFO: ui->cache_->getMapInfo(job.name_); break; case GEN_MAP: img = ui->cache_->getMapImage(job.name_); if (img) img->release(); break; case GEN_METAL: img = ui->cache_->getMetalImage(job.name_); if (img) img->release(); break; case GEN_HEIGHT: img = ui->cache_->getHeightImage(job.name_); if (img) img->release(); break; } } catch (std::exception const & e) { LOG(WARNING) << e.what(); } Fl::add_timeout(0.01, doGenJob, d); } }
void OnStartCalib(class Fl_Button* b, void*) { CalibUI* ui = reinterpret_cast<CalibUI*>(b->window()->user_data()); if (ui != nullptr) { ui->calibImageBox->SetImagePoints(nullptr); cv::Size imageSize; cv::Size boardSize(static_cast<int>(ui->vertCornersInput->value()), static_cast<int>(ui->horizCornersInput->value())); ui->appData->imagesPoints.clear(); ui->appData->imagesPointsMap.clear(); ui->calibTextResult->buffer(ui->appData->resultTextBuff.get()); ui->appData->resultTextBuff->text("Calibration in progress ..."); ui->calibTextResult->redraw(); Fl::wait(); for (int i = 1; i <= ui->calibImageBrowser->size(); ++i) { Fl::wait(); const char* fileName = ui->calibImageBrowser->text(i); Fl_Shared_Image *img = Fl_Shared_Image::get(fileName); cv::Mat mat = FLImageToMat(img); imageSize = mat.size(); std::vector<cv::Point2f> pointbuf; bool found = cv::findChessboardCorners(mat, boardSize, pointbuf, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS); Fl::wait(); cv::Mat matGray; cv::cvtColor(mat, matGray, CV_BGR2GRAY); if(found) { cv::cornerSubPix(matGray, pointbuf, cv::Size(11,11), cv::Size(-1,-1), cv::TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 )); ui->appData->imagesPoints.push_back(pointbuf); ui->appData->imagesPointsMap.insert(std::make_pair(fileName, ui->appData->imagesPoints.size() - 1)); } img->release(); } if (!ui->appData->imagesPoints.empty()) { double squareSize = ui->cellSizeInput->value(); bool ok = runCalibration(ui->appData->imagesPoints, imageSize, boardSize, squareSize, ui->appData->cameraMatrix, ui->appData->distCoeffs); if (ok) { std::stringstream buf; double pixelSize = 0; buf << "Focal length X (pixel rel. units) : " << ui->appData->cameraMatrix.at<double>(0,0) << "\n"; buf << "Focal length Y (pixel rel. units) : " << ui->appData->cameraMatrix.at<double>(1,1) << "\n"; buf << "Principal point x : " << ui->appData->cameraMatrix.at<double>(0,2) << "\n"; buf << "Principal point y : " << ui->appData->cameraMatrix.at<double>(1,2) << "\n"; buf << "K1 : " << ui->appData->distCoeffs.at<double>(0, 0) << "\n"; buf << "K2 : " << ui->appData->distCoeffs.at<double>(1, 0) << "\n"; buf << "K3 : " << ui->appData->distCoeffs.at<double>(4, 0) << "\n"; buf << "P1 : " << ui->appData->distCoeffs.at<double>(2, 0) << "\n"; buf << "P2 : " << ui->appData->distCoeffs.at<double>(3, 0) << "\n"; ui->appData->resultTextBuff->text(buf.str().c_str()); OnCalibImageSelected(ui->calibImageBrowser, nullptr); return; } } } ui->appData->resultTextBuff->text("Calibration failed!"); }
int DeRotatorGraphics::load_texture(const char* fname, GLuint& tex_id) { using namespace logging::trivial; src::severity_logger< severity_level > lg; // initialize the texture map glGenTextures(1, &tex_id); glBindTexture(GL_TEXTURE_2D, tex_id); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); Fl_Shared_Image *image; // check that the fname exists using namespace boost::filesystem; path p(fname); if(exists(p)){ image = Fl_Shared_Image::get(fname); } else { // fname does not exist in the current directory. // Check whether this file exists in the Resources directory of // a Mac bundle #ifdef __APPLE__ unsigned short ufname[64]; for(int i=0; i<strlen(fname); i++){ ufname[i] = fname[i]; } CFStringRef s = CFStringCreateWithCharacters(NULL, ufname, strlen(fname)); CFURLRef appUrlRef; appUrlRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), s, NULL, NULL); CFStringRef filePathRef = CFURLCopyPath(appUrlRef); const char* filePath = CFStringGetCStringPtr(filePathRef, kCFStringEncodingUTF8); path p1(filePath); if(exists(p1)){ image = Fl_Shared_Image::get(filePath); CFRelease(filePathRef); CFRelease(appUrlRef); } else { LOG_ERROR << "DeRotator::load_texture(): " << filePath << " does not exist\n"; CFRelease(filePathRef); CFRelease(appUrlRef); return -1; } #endif } if(image == NULL){ LOG_ERROR << "DeRotator::load_texture(): " << fname << " has an unknown format\n"; return -1; } glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image->w(), image->h(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image->data()[0]); image->release(); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glEnable(GL_TEXTURE_2D); return 0; }
void IconChooser::load_from_list(list<String>& lst) { if(lst.empty()) return; Fl_Shared_Image* img = NULL; int imax_w = 0; int imax_h = 0; int iw, ih; bool show_progress = false; list<String>::iterator it = lst.begin(), it_end = lst.end(); /* * lst_info contains coresponding indexes with list<String> so we can deduce what * files to skip (not readable image or dimensions greater than allowed); skippable are marked as 0 */ int* lst_info = new int[lst.size()]; for(int n = 0; it != it_end; ++it, n++){ img = Fl_Shared_Image::get((*it).c_str()); if(!img) { lst_info[n] = 0; continue; } iw = img->w(); ih = img->h(); if(iw > MAX_ICON_W || ih > MAX_ICON_H) { lst_info[n] = 0; continue; } imax_w = MAX(imax_w, iw); imax_h = MAX(imax_h, ih); lst_info[n] = 1; } /* clear potential content of ExpandableGroup */ if(icongrp->children()) icongrp->clear(); if(lst.size() > 10) { show_progress = true; progress->minimum(0); progress->maximum(lst.size()); progress->show(); } if(imax_w < 64) imax_w = 64; else imax_w += 10; if(imax_h < 64) imax_h = 64; else imax_h += 10; imax_w += 5; imax_h += 5; /* * focus_index() is only valid on childs before we show them and that is what we need * so other childs don't mess it when they are added */ //icongrp->focus(child(0)); icongrp->set_visible_focus(); IconBox* preview; it = lst.begin(); for(int n = 0; it != it_end; ++it, n++) { img = Fl_Shared_Image::get((*it).c_str()); if(img && lst_info[n] == 1) { preview = new IconBox(0, 0, imax_w, imax_h); preview->set_icon_path((*it)); /* use background/selection from ExpandableGroup */ preview->color(icongrp->color()); preview->selection_color(icongrp->color()); if(show_progress) progress->value(int((n * 100) / int(progress->maximum()))); preview->image(img); preview->callback(iconbox_cb, this); icongrp->add(preview); Fl::check(); } } progress->hide(); delete [] lst_info; }
CLuaImage::CLuaImage(const char *file) : CBaseLuaWidget(""), m_iImageW(0), m_iImageH(0) { Fl_Shared_Image *img = Fl_Shared_Image::get(file); if (img) { if ((img->w() > MaxImageW()) || (img->h() > MaxImageH())) { int neww, newh; GetScaledImageSize(img->w(), img->h(), MaxImageW(), MaxImageH(), neww, newh); Fl_Image *temp = img->copy(neww, newh); img->release(); img = (Fl_Shared_Image *)temp; } Fl_Box *imgbox = new Fl_Box(0, 0, img->w(), img->h()); imgbox->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); imgbox->image(img); GetGroup()->add(imgbox); m_iImageW = img->w(); m_iImageH = img->h(); } else GetGroup()->hide(); }