Hugin trunk 0.1
Loading...
Searching...
No Matches
PreviewWindow.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
10/* This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This software is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this software. If not, see
22 * <http://www.gnu.org/licenses/>.
23 *
24 */
25
26#include "PreviewWindow.h"
27#include <wx/dcbuffer.h>
28#include <wx/dcclient.h>
29#include "ToolboxApp.h"
30#include "base_wx/platform.h"
31
32// our image control
33bool PreviewWindow::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
34{
35 wxScrolledWindow::Create(parent, id, pos, size, style, name);
36 m_scaleFactor = 1.0;
37 m_fitToWindow = true;
39 // bind event handler
42
43 return true;
44}
45
47{
48 if(!file.IsEmpty() && wxFileExists(file))
49 {
50 m_iccProfile.clear();
51 try
52 {
53 m_image.LoadFile(file);
54 // load also icc profile
55 vigra::ImageImportInfo info(file.mb_str(HUGIN_CONV_FILENAME));
56 m_iccProfile = info.getICCProfile();
57 }
58 catch (...)
59 {
60 m_image.Destroy();
61 SetVirtualSize(100, 100);
62 Refresh(true);
63 return;
64 }
66 Refresh();
67 }
68 else
69 {
70 m_image.Destroy();
71 SetVirtualSize(100,100);
72 Refresh(true);
73 }
74}
75
77{
80 dc.SetBackground(GetBackgroundColour());
81 dc.Clear();
82 if (m_bitmap.IsOk())
83 {
84 // draw bitmap
85 dc.DrawBitmap(m_bitmap, 0, 0);
86 };
87}
88
90{
91 // rescale m_bitmap if needed.
92 if (m_image.IsOk())
93 {
94 if (m_fitToWindow)
95 {
96 setScale(0);
97 }
98 }
99 e.Skip();
100}
101
103{
104 if (m_image.GetWidth() == 0)
105 {
106 return;
107 }
108 wxSize realSize = m_image.GetSize();
109 if (m_fitToWindow)
110 {
112 };
113
114 //scaling image to screen size
115 wxImage img;
116 if (getScaleFactor()!=1.0)
117 {
118 realSize.SetWidth(scale(m_image.GetWidth()));
119 realSize.SetHeight(scale(m_image.GetHeight()));
121 if (std::max(m_image.GetWidth(), m_image.GetHeight()) > (ULONG_MAX >> 16))
122 {
123 // wxIMAGE_QUALITY_NORMAL resizes the image with ResampleNearest
124 // this algorithm works only if image dimensions are smaller then
125 // ULONG_MAX >> 16 (actual size of unsigned long differ from system
126 // to system)
128 };
129 img=m_image.Scale(realSize.GetWidth(), realSize.GetHeight(), resizeQuality);
130 }
131 else
132 {
133 //therefore we need to create a copy to work on it
134 img=m_image.Copy();
135 };
136 // do color correction only if input image has icc profile or if we found a monitor profile
137 if (!m_iccProfile.empty() || wxGetApp().GetToolboxFrame()->HasMonitorProfile())
138 {
139 HuginBase::Color::CorrectImage(img, m_iccProfile, wxGetApp().GetToolboxFrame()->GetMonitorProfile());
140 };
141 m_bitmap=wxBitmap(img);
143 SetScrollRate(1, 1);
144 Refresh(true);
145}
146
147void PreviewWindow::setScale(double factor)
148{
149 if (factor == 0)
150 {
151 m_fitToWindow = true;
152 factor = calcAutoScaleFactor(m_image.GetSize());
153 }
154 else
155 {
156 m_fitToWindow = false;
157 }
158 // update if factor changed
159 if (factor != m_scaleFactor)
160 {
161 m_scaleFactor = factor;
162 // keep existing scale focussed.
163 rescaleImage();
164 }
165}
166
168{
169 return m_fitToWindow ? 0 : m_scaleFactor;
170}
171
172
174{
175 const int w = size.GetWidth();
176 const int h = size.GetHeight();
177 const wxSize csize = GetSize();
178 const double s1 = (double)csize.GetWidth() / w;
179 const double s2 = (double)csize.GetHeight() / h;
180 return s1 < s2 ? s1 : s2;
181}
182
184{
185 return m_scaleFactor;
186}
187
188int PreviewWindow::scale(int x) const
189{
190 return (int) (x * getScaleFactor() + 0.5);
191}
192
193double PreviewWindow::scale(double x) const
194{
195 return x * getScaleFactor();
196}
197
198IMPLEMENT_DYNAMIC_CLASS(PreviewWindow, wxScrolledWindow)
declaration of PreviewWindow class
preview window
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name="panel")
create the control
void setImage(const wxString &filename)
set the current image and mask list, this loads also the image from cache
vigra::ImageImportInfo::ICCProfile m_iccProfile
remember icc profile of currently loaded file
double calcAutoScaleFactor(wxSize size)
calculate new scale factor for this image
double m_scaleFactor
store current scale factor
int scale(int x) const
helper function to scale of width/height
double getScale()
return scale factor, 0 for autoscale
wxBitmap m_bitmap
void OnSize(wxSizeEvent &e)
handler called when size of control was changed
void OnPaint(wxPaintEvent &e)
drawing routine
double getScaleFactor() const
get scale factor (calculates factor when fit to window is active)
void setScale(double factor)
set the scaling factor f.
void rescaleImage()
rescale the image
implementation of huginApp Class
#define HUGIN_CONV_FILENAME
Definition platform.h:40
void CorrectImage(wxImage &image, const vigra::ImageImportInfo::ICCProfile &iccProfile, const cmsHPROFILE &monitorProfile)
apply color correction to given image using input iccProfile and monitor profile
Definition wxcms.cpp:218
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41