ButcherImage *ButcherProjectAreaConfigPreview::GetPreview() { if (ConfigChanged()) { if (GetProject()->Views().Exists(viewid_) && NeedImage()) { ButcherProjectBaseAutoProgress progress(this, wxString::Format(_("Generating preview for %s, please wait..."), areaconfig_->GetArea()->GetDescription().c_str())); try { std::auto_ptr<ButcherImage> simage(GetProject()->Views()[viewid_]->CreateAreaImage(areaconfig_->GetArea())); if (HavePreview() && simage.get()) SetPreview(simage->Save(areaconfig_->ImageInfo().GetSaveParams())); else SetPreview(simage.release()); } catch(...) { //lasterror_=true; //throw; SetPreview(GetProject()->Views()[viewid_]->CreateAreaErrorImage(areaconfig_->GetArea())); } } else SetPreview(NULL); } return preview_; }
wxBitmap butil_loadxmlrcbitmap(const wxString &resname) { wxLogNull lnull; wxBitmap rbitmap(wxXmlResource::Get()->LoadBitmap(resname)); wxImage simage(rbitmap.ConvertToImage()); simage.ConvertAlphaToMask(); wxBitmap bitmap(simage); return bitmap; }
bool HTMLButcherApp::OnInit() { if (!wxApp::OnInit()) return false; #if defined(__WXMSW__) || !defined(HTMLBUTCHER_DEMO) SetAppName(wxT("HTMLButcher")); #else SetAppName(wxT("HTMLButcher-Demo")); #endif #ifdef HTMLBUTCHER_DEBUG wxFileName kf(wxStandardPaths::Get().GetExecutablePath()); kf.SetFullName(wxT("default.po")); kf.AppendDir(wxT("..")); kf.AppendDir(wxT("..")); kf.AppendDir(wxT("locale")); kf.Normalize(); locale_.AddCatalogLookupPathPrefix(kf.GetPath()); #endif locale_.AddCatalogLookupPathPrefix(wxStandardPaths::Get().GetDataDir() + wxT("/share/locale")); locale_.Init(GetUILanguage()); locale_.AddCatalog(wxT("htmlbutcher")); #ifdef __WXGTK__ wxFileName::Mkdir(wxStandardPaths::Get().GetUserDataDir(), 0777, wxPATH_MKDIR_FULL); // must create dir for wxConfig wxConfig::Set(new wxFileConfig(wxString::Format(wxT("%s/config"), wxTheApp->GetAppName().c_str()))); #endif extern void InitXmlResource(); // defined in htmlbutcher_resources.cpp wxXmlResource::Get()->InitAllHandlers(); InitXmlResource(); wxInitAllImageHandlers(); wxFileSystem::AddHandler(new wxArchiveFSHandler); //::wxHandleFatalExceptions(true); wxFreeImage::Initialize(); #ifdef BUTCHER_USE_HELP // help wxHelpControllerHelpProvider* provider = new wxHelpControllerHelpProvider; wxHelpProvider::Set(provider); provider->SetHelpController(&help_); #ifdef __WXMSW__ wxFileName fn(wxStandardPaths::Get().GetExecutablePath()); fn.SetFullName(wxT("htmlbutcher.chm")); #else #ifdef HTMLBUTCHER_DEBUG wxFileName fn(wxStandardPaths::Get().GetExecutablePath()); fn.SetFullName(wxT("htmlbutcher.htb")); #else wxFileName fn(wxStandardPaths::Get().GetResourcesDir().Lower(), wxEmptyString); fn.SetFullName(wxT("htmlbutcher.htb")); if (!fn.FileExists()) { fn.AssignDir(wxString::Format(wxT("/usr/share/%s"), wxTheApp->GetAppName().Lower().c_str())); fn.SetFullName(wxT("htmlbutcher.htb")); } #endif #endif if (!help_.Initialize(fn.GetFullPath())) { wxLogError(wxT("Cannot initialize the help system, aborting.")); return false; } #endif // main frame HTMLButcherFrame* frame = new HTMLButcherFrame(0L, wxT("HTMLButcher")); // splash screen { wxLogNull logNo; wxBitmap rbitmap(wxXmlResource::Get()->LoadBitmap(wxT("b_splash"))); wxImage simage(rbitmap.ConvertToImage()); simage.ConvertAlphaToMask(); wxBitmap bitmap(simage); HTMLButcherSplashScreen *splash = new HTMLButcherSplashScreen(bitmap, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 4000, frame, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxSPLASH_CENTRE_ON_SCREEN|wxFRAME_SHAPED); splash->Update(); } //wxYield(); #ifdef __WXMSW__ frame->SetIcon(wxICON(HTMLBUTCHERICON)); // To Set App Icon #elif defined(__WXGTK__) frame->SetIcon(wxICON(htmlbutcher)); // To Set App Icon #endif //__WXMSW__ frame->Show(); SetTopWindow(frame); //#ifndef __WXMAC__ frame->Maximize(); //#endif #ifndef HTMLBUTCHER_DEMO if (!openfile_.IsEmpty()) frame->DoOpenProject(openfile_); #endif return true; }
/** * Process a GdkPixbuf, according to which areas have been * obscured in the GUI. */ Glib::RefPtr<Gdk::Pixbuf> Tracer::sioxProcessImage(SPImage *img, Glib::RefPtr<Gdk::Pixbuf>origPixbuf) { if (!sioxEnabled) return origPixbuf; if (origPixbuf == lastOrigPixbuf) return lastSioxPixbuf; //g_message("siox: start"); //Convert from gdk, so a format we know. By design, the pixel //format in PackedPixelMap is identical to what is needed by SIOX SioxImage simage(origPixbuf->gobj()); SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (!desktop) { g_warning(_("Trace: No active desktop")); return Glib::RefPtr<Gdk::Pixbuf>(NULL); } Inkscape::MessageStack *msgStack = sp_desktop_message_stack(desktop); Inkscape::Selection *sel = sp_desktop_selection(desktop); if (!sel) { char *msg = _("Select an <b>image</b> to trace"); msgStack->flash(Inkscape::ERROR_MESSAGE, msg); //g_warning(msg); return Glib::RefPtr<Gdk::Pixbuf>(NULL); } NRArenaItem *aImg = sp_item_get_arenaitem(img, desktop->dkey); //g_message("img: %d %d %d %d\n", aImg->bbox.x0, aImg->bbox.y0, // aImg->bbox.x1, aImg->bbox.y1); double width = (double)(aImg->bbox.x1 - aImg->bbox.x0); double height = (double)(aImg->bbox.y1 - aImg->bbox.y0); double iwidth = (double)simage.getWidth(); double iheight = (double)simage.getHeight(); double iwscale = width / iwidth; double ihscale = height / iheight; std::vector<NRArenaItem *> arenaItems; std::vector<SPShape *>::iterator iter; for (iter = sioxShapes.begin() ; iter!=sioxShapes.end() ; iter++) { SPItem *item = *iter; NRArenaItem *aItem = sp_item_get_arenaitem(item, desktop->dkey); arenaItems.push_back(aItem); } //g_message("%d arena items\n", arenaItems.size()); //PackedPixelMap *dumpMap = PackedPixelMapCreate( // simage.getWidth(), simage.getHeight()); //g_message("siox: start selection"); for (int row=0 ; row<iheight ; row++) { double ypos = ((double)aImg->bbox.y0) + ihscale * (double) row; for (int col=0 ; col<simage.getWidth() ; col++) { //Get absolute X,Y position double xpos = ((double)aImg->bbox.x0) + iwscale * (double)col; Geom::Point point(xpos, ypos); point *= *aImg->transform; //point *= imgMat; //point = desktop->doc2dt(point); //g_message("x:%f y:%f\n", point[0], point[1]); bool weHaveAHit = false; std::vector<NRArenaItem *>::iterator aIter; for (aIter = arenaItems.begin() ; aIter!=arenaItems.end() ; aIter++) { NRArenaItem *arenaItem = *aIter; NRArenaItemClass *arenaClass = (NRArenaItemClass *) NR_OBJECT_GET_CLASS (arenaItem); if (arenaClass->pick(arenaItem, point, 1.0f, 1)) { weHaveAHit = true; break; } } if (weHaveAHit) { //g_message("hit!\n"); //dumpMap->setPixelLong(dumpMap, col, row, 0L); simage.setConfidence(col, row, Siox::UNKNOWN_REGION_CONFIDENCE); } else { //g_message("miss!\n"); //dumpMap->setPixelLong(dumpMap, col, row, // simage.getPixel(col, row)); simage.setConfidence(col, row, Siox::CERTAIN_BACKGROUND_CONFIDENCE); } } } //g_message("siox: selection done"); //dumpMap->writePPM(dumpMap, "siox1.ppm"); //dumpMap->destroy(dumpMap); //## ok we have our pixel buf TraceSioxObserver observer(this); Siox sengine(&observer); SioxImage result = sengine.extractForeground(simage, 0xffffff); if (!result.isValid()) { g_warning(_("Invalid SIOX result")); return Glib::RefPtr<Gdk::Pixbuf>(NULL); } //result.writePPM("siox2.ppm"); /* Free Arena and ArenaItem */ /* std::vector<NRArenaItem *>::iterator aIter; for (aIter = arenaItems.begin() ; aIter!=arenaItems.end() ; aIter++) { NRArenaItem *arenaItem = *aIter; nr_arena_item_unref(arenaItem); } nr_object_unref((NRObject *) arena); */ Glib::RefPtr<Gdk::Pixbuf> newPixbuf = Glib::wrap(result.getGdkPixbuf()); //g_message("siox: done"); lastSioxPixbuf = newPixbuf; return newPixbuf; }