00001
00002
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "hugin/PanoOutputDialog.h"
00028 #include "base_wx/wxPlatform.h"
00029 #include "panoinc.h"
00030
00031 #include "hugin/huginApp.h"
00032 #include "base_wx/platform.h"
00033 #include "hugin/config_defaults.h"
00034
00035 BEGIN_EVENT_TABLE(PanoOutputDialog,wxDialog)
00036 EVT_BUTTON(wxID_OK, PanoOutputDialog::OnOk)
00037 EVT_CHECKBOX(XRCID("output_normal"), PanoOutputDialog::OnOutputChanged)
00038 EVT_CHECKBOX(XRCID("output_fused_blended"), PanoOutputDialog::OnOutputChanged)
00039 EVT_CHECKBOX(XRCID("output_blended_fused"), PanoOutputDialog::OnOutputChanged)
00040 EVT_CHECKBOX(XRCID("output_hdr"), PanoOutputDialog::OnOutputChanged)
00041 EVT_CHOICE(XRCID("output_ldr_format"), PanoOutputDialog::OnLDRFormatChanged)
00042 EVT_CHOICE(XRCID("output_hdr_format"), PanoOutputDialog::OnHDRFormatChanged)
00043 EVT_SPINCTRL(XRCID("output_width"), PanoOutputDialog::OnWidthChanged)
00044 EVT_SPINCTRL(XRCID("output_height"), PanoOutputDialog::OnHeightChanged)
00045 END_EVENT_TABLE()
00046
00047 PanoOutputDialog::PanoOutputDialog(wxWindow *parent, PT::Panorama& pano, GuiLevel guiLevel) : m_pano(pano), m_aspect(0)
00048 {
00049
00050
00051 wxXmlResource::Get()->LoadDialog(this, parent, wxT("pano_output_dialog"));
00052
00053 #ifdef __WXMSW__
00054 wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.ico"),wxBITMAP_TYPE_ICO);
00055 #else
00056 wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.png"),wxBITMAP_TYPE_PNG);
00057 #endif
00058 SetIcon(myIcon);
00059
00060 wxConfigBase * cfg = wxConfigBase::Get();
00061
00062 int x = cfg->Read(wxT("/PanoOutputDialog/positionX"),-1l);
00063 int y = cfg->Read(wxT("/PanoOutputDialog/positionY"),-1l);
00064 if ( y >= 0 && x >= 0)
00065 {
00066 this->Move(x, y);
00067 }
00068 else
00069 {
00070 this->Move(0, 44);
00071 };
00072
00073 m_guiLevel=guiLevel;
00074 m_stacks=getHDRStacks(m_pano, m_pano.getActiveImages(), m_pano.getOptions());
00075 m_exposureLayers=getExposureLayers(m_pano, m_pano.getActiveImages(), m_pano.getOptions());
00076
00077 long opt_width=m_pano.calcOptimalWidth();
00078 m_newOpt=m_pano.getOptions();
00079 double sizeFactor = HUGIN_ASS_PANO_DOWNSIZE_FACTOR;
00080 wxConfigBase* config = wxConfigBase::Get();
00081 config->Read(wxT("/Assistant/panoDownsizeFactor"), &sizeFactor, HUGIN_ASS_PANO_DOWNSIZE_FACTOR);
00082 m_newOpt.setWidth(hugin_utils::floori(sizeFactor*opt_width), true);
00083 m_initalWidth=m_newOpt.getWidth();
00084 m_initalROIWidth=m_newOpt.getROI().width();
00085 m_aspect=(double)m_newOpt.getROI().height()/m_newOpt.getROI().width();
00086 m_edit_width=XRCCTRL(*this, "output_width", wxSpinCtrl);
00087 m_edit_height=XRCCTRL(*this, "output_height", wxSpinCtrl);
00088 m_edit_width->SetValue(m_newOpt.getROI().width());
00089 m_edit_height->SetValue(m_newOpt.getROI().height());
00090
00091
00092 int i = config->Read(wxT("/output/jpeg_quality"),HUGIN_JPEG_QUALITY);
00093 XRCCTRL(*this, "output_jpeg_quality", wxSpinCtrl)->SetValue(i);
00094 i=config->Read(wxT("/output/tiff_compression"), HUGIN_TIFF_COMPRESSION);
00095 XRCCTRL(*this, "output_tiff_compression", wxChoice)->SetSelection(i);
00096 i=config->Read(wxT("/output/ldr_format"), HUGIN_LDR_OUTPUT_FORMAT);
00097 XRCCTRL(*this, "output_ldr_format", wxChoice)->SetSelection(i);
00098
00099 if (m_newOpt.outputImageTypeHDR == "exr")
00100 {
00101 XRCCTRL(*this, "output_hdr_format", wxChoice)->SetSelection(0);
00102 XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->SetSelection(2);
00103 }
00104 else
00105 {
00106 XRCCTRL(*this, "output_hdr_format", wxChoice)->SetSelection(1);
00107 if (m_newOpt.outputImageTypeHDRCompression == "PACKBITS")
00108 {
00109 XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->SetSelection(1);
00110 }
00111 else
00112 {
00113 if (m_newOpt.outputImageTypeHDRCompression == "LZW")
00114 {
00115 XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->SetSelection(2);
00116 }
00117 else
00118 {
00119 if (m_newOpt.outputImageTypeHDRCompression == "DEFLATE")
00120 {
00121 XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->SetSelection(3);
00122 }
00123 else
00124 {
00125 XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->SetSelection(0);
00126 };
00127 };
00128 };
00129 };
00130 EnableOutputOptions();
00131 wxCommandEvent dummy;
00132 OnOutputChanged(dummy);
00133 OnLDRFormatChanged(dummy);
00134 OnHDRFormatChanged(dummy);
00135 };
00136
00137 PanoOutputDialog::~PanoOutputDialog()
00138 {
00139 wxConfigBase * cfg = wxConfigBase::Get();
00140 wxPoint ps = this->GetPosition();
00141 cfg->Write(wxT("/PanoOutputDialog/positionX"), ps.x);
00142 cfg->Write(wxT("/PanoOutputDialog/positionY"), ps.y);
00143 cfg->Flush();
00144 };
00145
00146 void PanoOutputDialog::EnableOutputOptions()
00147 {
00148
00149 wxFileName file1(wxString(m_pano.getImage(0).getFilename().c_str(), HUGIN_CONV_FILENAME));
00150 wxString ext1=file1.GetExt().Lower();
00151 if(ext1==wxT(".hdr") || ext1==wxT(".exr"))
00152 {
00153 XRCCTRL(*this, "output_hdr", wxCheckBox)->SetValue(true);
00154 XRCCTRL(*this, "output_hdr", wxCheckBox)->Enable(true);
00155 XRCCTRL(*this, "output_hdr_bitmap", wxCheckBox)->Enable(true);
00156 return;
00157 }
00158
00159 if(m_guiLevel==GUI_SIMPLE)
00160 {
00161 XRCCTRL(*this, "output_hdr", wxCheckBox)->Hide();
00162 XRCCTRL(*this, "output_hdr_bitmap", wxCheckBox)->Hide();
00163 XRCCTRL(*this, "output_hdr_format_label", wxStaticText)->Hide();
00164 XRCCTRL(*this, "output_hdr_format", wxChoice)->Hide();
00165 XRCCTRL(*this, "output_hdr_compression_label", wxStaticText)->Hide();
00166 XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->Hide();
00167 Layout();
00168 GetSizer()->Fit(this);
00169 };
00170
00171 if(m_pano.getNrOfImages()==1 || m_stacks.size() >= 0.8 * m_pano.getNrOfImages())
00172 {
00173 XRCCTRL(*this, "output_normal", wxCheckBox)->SetValue(true);
00174 XRCCTRL(*this, "output_normal", wxCheckBox)->Enable(true);
00175 XRCCTRL(*this, "output_normal_bitmap", wxCheckBox)->Enable(true);
00176 if(m_pano.getNrOfImages()==1 || m_stacks.size()==m_pano.getNrOfImages())
00177 {
00178 return;
00179 };
00180 };
00181 XRCCTRL(*this, "output_fused_blended", wxCheckBox)->Enable(true);
00182 XRCCTRL(*this, "output_fused_blended_bitmap", wxCheckBox)->Enable(true);
00183 XRCCTRL(*this, "output_blended_fused", wxCheckBox)->Enable(true);
00184 XRCCTRL(*this, "output_blended_fused_bitmap", wxCheckBox)->Enable(true);
00185 if(m_guiLevel!=GUI_SIMPLE)
00186 {
00187 XRCCTRL(*this, "output_hdr", wxCheckBox)->Enable(true);
00188 XRCCTRL(*this, "output_hdr_bitmap", wxCheckBox)->Enable(true);
00189 };
00190 if(m_pano.getNrOfImages() % m_stacks.size() == 0)
00191 {
00192 XRCCTRL(*this, "output_fused_blended", wxCheckBox)->SetValue(true);
00193 }
00194 else
00195 {
00196 if(m_exposureLayers.size()==1)
00197 {
00198 XRCCTRL(*this, "output_normal", wxCheckBox)->SetValue(true);
00199 }
00200 else
00201 {
00202 XRCCTRL(*this, "output_blended_fused", wxCheckBox)->SetValue(true);
00203 };
00204 };
00205 };
00206
00207 void PanoOutputDialog::OnOk(wxCommandEvent & e)
00208 {
00209 bool output_normal=XRCCTRL(*this, "output_normal", wxCheckBox)->GetValue();
00210 bool output_fused_blended=XRCCTRL(*this, "output_fused_blended", wxCheckBox)->GetValue();
00211 bool output_blended_fused=XRCCTRL(*this, "output_blended_fused", wxCheckBox)->GetValue();
00212 bool output_hdr=XRCCTRL(*this, "output_hdr", wxCheckBox)->GetValue();
00213 bool keep_intermediate=XRCCTRL(*this, "output_keep_intermediate", wxCheckBox)->GetValue();
00214
00215 m_newOpt.outputLDRBlended=output_normal;
00216 m_newOpt.outputLDRLayers=output_normal && keep_intermediate;
00217
00218 m_newOpt.outputLDRExposureBlended=output_fused_blended;
00219 m_newOpt.outputLDRExposureRemapped=(output_fused_blended || output_blended_fused) && keep_intermediate;
00220 m_newOpt.outputLDRStacks=output_fused_blended && keep_intermediate;
00221
00222 m_newOpt.outputLDRExposureLayersFused=output_blended_fused;
00223 m_newOpt.outputLDRExposureLayers=output_blended_fused && keep_intermediate;
00224
00225 m_newOpt.outputHDRBlended=output_hdr;
00226 m_newOpt.outputHDRLayers=output_hdr && keep_intermediate;
00227 m_newOpt.outputHDRStacks=output_hdr && keep_intermediate;
00228
00229 if(output_normal || output_fused_blended || output_blended_fused)
00230 {
00231 if(m_newOpt.outputImageType=="jpg")
00232 {
00233 m_newOpt.quality=XRCCTRL(*this, "output_jpeg_quality", wxSpinCtrl)->GetValue();
00234 }
00235 else
00236 {
00237 if(m_newOpt.outputImageType=="tif")
00238 {
00239 switch(XRCCTRL(*this, "output_tiff_compression", wxChoice)->GetSelection())
00240 {
00241 case 0:
00242 default:
00243 m_newOpt.outputImageTypeCompression = "NONE";
00244 m_newOpt.tiffCompression = "NONE";
00245 break;
00246 case 1:
00247 m_newOpt.outputImageTypeCompression = "PACKBITS";
00248 m_newOpt.tiffCompression = "PACKBITS";
00249 break;
00250 case 2:
00251 m_newOpt.outputImageTypeCompression = "LZW";
00252 m_newOpt.tiffCompression = "LZW";
00253 break;
00254 case 3:
00255 m_newOpt.outputImageTypeCompression = "DEFLATE";
00256 m_newOpt.tiffCompression = "DEFLATE";
00257 break;
00258 };
00259 };
00260 };
00261 };
00262
00263 if(output_hdr)
00264 {
00265 if(m_newOpt.outputImageTypeHDR=="tif")
00266 {
00267 switch(XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->GetSelection())
00268 {
00269 case 0:
00270 default:
00271 m_newOpt.outputImageTypeHDRCompression = "NONE";
00272 break;
00273 case 1:
00274 m_newOpt.outputImageTypeHDRCompression = "PACKBITS";
00275 break;
00276 case 2:
00277 m_newOpt.outputImageTypeHDRCompression = "LZW";
00278 break;
00279 case 3:
00280 m_newOpt.outputImageTypeHDRCompression = "DEFLATE";
00281 break;
00282 };
00283 };
00284 }
00285
00286 double scale=m_edit_width->GetValue()/m_initalROIWidth;
00287 m_newOpt.setWidth(hugin_utils::roundi(m_initalWidth*scale), true);
00288
00289 if(m_initalROIWidth < m_initalWidth)
00290 {
00291 if(m_newOpt.getROI().width()<m_edit_width->GetValue() || m_newOpt.getROI().height()<m_edit_height->GetValue())
00292 {
00293 m_newOpt.setWidth(m_newOpt.getWidth()+1, true);
00294 };
00295 vigra::Rect2D roi=m_newOpt.getROI();
00296 if(roi.width()>m_edit_width->GetValue() || roi.height()>m_edit_height->GetValue())
00297 {
00298 roi.setSize(m_edit_width->GetValue(), m_edit_height->GetValue());
00299 m_newOpt.setROI(roi);
00300 };
00301 };
00302
00303 EndModal(wxID_OK);
00304 };
00305
00306 void PanoOutputDialog::OnOutputChanged(wxCommandEvent & e)
00307 {
00308 bool output_normal=XRCCTRL(*this, "output_normal", wxCheckBox)->GetValue();
00309 bool output_fused_blended=XRCCTRL(*this, "output_fused_blended", wxCheckBox)->GetValue();
00310 bool output_blended_fused=XRCCTRL(*this, "output_blended_fused", wxCheckBox)->GetValue();
00311 bool output_hdr=XRCCTRL(*this, "output_hdr", wxCheckBox)->GetValue();
00312
00313 XRCCTRL(*this, "wxID_OK", wxButton)->Enable(output_normal || output_fused_blended || output_blended_fused || output_hdr);
00314 XRCCTRL(*this, "output_ldr_format_label", wxStaticText)->Enable(output_normal || output_fused_blended || output_blended_fused);
00315 XRCCTRL(*this, "output_ldr_format", wxChoice)->Enable(output_normal || output_fused_blended || output_blended_fused);
00316 XRCCTRL(*this, "output_ldr_compression_label", wxStaticText)->Enable(output_normal || output_fused_blended || output_blended_fused);
00317 XRCCTRL(*this, "output_jpeg_quality", wxSpinCtrl)->Enable(output_normal || output_fused_blended || output_blended_fused);
00318 XRCCTRL(*this, "output_tiff_compression", wxChoice)->Enable(output_normal || output_fused_blended || output_blended_fused);
00319 XRCCTRL(*this, "output_hdr_format_label", wxStaticText)->Enable(output_hdr);
00320 XRCCTRL(*this, "output_hdr_format", wxChoice)->Enable(output_hdr);
00321 XRCCTRL(*this, "output_hdr_compression_label", wxStaticText)->Enable(output_hdr);
00322 XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->Enable(output_hdr);
00323 GetSizer()->Layout();
00324 };
00325
00326 void PanoOutputDialog::OnLDRFormatChanged(wxCommandEvent & e)
00327 {
00328 int sel = XRCCTRL(*this, "output_ldr_format", wxChoice)->GetSelection();
00329 switch (sel)
00330 {
00331 case 1:
00332 m_newOpt.outputImageType ="jpg";
00333 XRCCTRL(*this, "output_ldr_compression_label", wxStaticText)->Show();
00334 XRCCTRL(*this, "output_ldr_compression_label", wxStaticText)->SetLabel(_("Quality:"));
00335 XRCCTRL(*this, "output_jpeg_quality", wxSpinCtrl)->Show();
00336 XRCCTRL(*this, "output_tiff_compression", wxChoice)->Hide();
00337 break;
00338 case 2:
00339 m_newOpt.outputImageType ="png";
00340 XRCCTRL(*this, "output_ldr_compression_label", wxStaticText)->Hide();
00341 XRCCTRL(*this, "output_jpeg_quality", wxSpinCtrl)->Hide();
00342 XRCCTRL(*this, "output_tiff_compression", wxChoice)->Hide();
00343 break;
00344 default:
00345 case 0:
00346 m_newOpt.outputImageType ="tif";
00347 XRCCTRL(*this, "output_ldr_compression_label", wxStaticText)->Show();
00348 XRCCTRL(*this, "output_ldr_compression_label", wxStaticText)->SetLabel(_("Compression:"));
00349 XRCCTRL(*this, "output_jpeg_quality", wxSpinCtrl)->Hide();
00350 XRCCTRL(*this, "output_tiff_compression", wxChoice)->Show();
00351 break;
00352 };
00353 GetSizer()->Layout();
00354 };
00355
00356
00357 void PanoOutputDialog::OnHDRFormatChanged(wxCommandEvent & e)
00358 {
00359 int sel = XRCCTRL(*this, "output_hdr_format", wxChoice)->GetSelection();
00360 switch (sel)
00361 {
00362 case 1:
00363 m_newOpt.outputImageTypeHDR="tif";
00364 XRCCTRL(*this, "output_hdr_compression_label", wxStaticText)->Show();
00365 XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->Show();
00366 break;
00367 case 0:
00368 default:
00369 m_newOpt.outputImageTypeHDR="exr";
00370 XRCCTRL(*this, "output_hdr_compression_label", wxStaticText)->Hide();
00371 XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->Hide();
00372 break;
00373 };
00374 GetSizer()->Layout();
00375 };
00376
00377 void PanoOutputDialog::OnWidthChanged(wxSpinEvent & e)
00378 {
00379 if(m_aspect>0)
00380 {
00381 m_edit_height->SetValue(m_edit_width->GetValue()*m_aspect);
00382 };
00383 };
00384
00385 void PanoOutputDialog::OnHeightChanged(wxSpinEvent & e)
00386 {
00387 if(m_aspect>0)
00388 {
00389 m_edit_width->SetValue(m_edit_height->GetValue()/m_aspect);
00390 };
00391 };