-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathImageStretching.js
More file actions
286 lines (226 loc) · 10.8 KB
/
ImageStretching.js
File metadata and controls
286 lines (226 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// ****************************************************************************
// ImageStretching — Standalone version of AutoIntegrate image stretching
// ****************************************************************************
#feature-id AutoIntegrate > Image Stretching
#feature-info Image Stretching using AutoIntegrate tools.
#ifndef NO_SOLVER_LIBRARY
#define NO_SOLVER_LIBRARY
#endif
#ifndef AUTOINTEGRATE_STANDALONE
#define AUTOINTEGRATE_STANDALONE
#endif
#include "AutoIntegrateGlobal.js"
#include "AutoIntegrateUtil.js"
#include "AutoIntegrateGUITools.js"
#include "AutoIntegrateEnhancementsGUI.js"
#include "AutoIntegrateEngine.js"
#include "AutoIntegratePreview.js"
// =============================================================================
// Dummy self.flowchart routines
// =============================================================================
#ifndef AUTOINTEGRATEDUMMYFLOWCHART
#define AUTOINTEGRATEDUMMYFLOWCHART
function AutoIntegrateDummyFlowchart()
{
this.__base__ = Object;
this.__base__();
this.flowchartOperation = function () {};
this.flowchartOperationEnd = function () {};
this.flowchartParentBegin = function () {};
this.flowchartParentEnd = function () {};
this.flowchartChildBegin = function () {};
this.flowchartChildEnd = function () {};
this.flowchartMaskBegin = function () {};
this.flowchartMaskEnd = function () {};
this.flowchartInit = function () {};
this.flowchartDone = function () {};
this.flowchartReset = function () {};
this.flowchartPrint = function () {};
}
AutoIntegrateDummyFlowchart.prototype = new Object;
#endif /* AUTOINTEGRATEDUMMYFLOWCHART */
// =============================================================================
// DIALOG WITH PREVIEW
// =============================================================================
function AutoIntegrateImageStretchingDialog() {
this.__base__ = Dialog;
this.__base__();
var self = this;
var debug = false;
this.TITLE = "Image Stretching";
this.VERSION = "1.01";
this.windowTitle = this.TITLE + " v" + this.VERSION;
// this.minWidth = 1000;
this.global = new AutoIntegrateGlobal();
this.global.debug = debug;
for (let i = 0; i < jsArguments.length; i++) {
if (jsArguments[i] == "do_not_read_settings") {
console.writeln("do_not_read_settings");
this.global.do_not_read_settings = true;
}
}
this.util = new AutoIntegrateUtil(this.global);
this.flowchart = new AutoIntegrateDummyFlowchart();
this.engine = new AutoIntegrateEngine(this.global, this.util, this.flowchart);
this.guitools = new AutoIntegrateGUITools(this, this.global, this.util, this.engine);
// Read parameter default settings from persistent module settings.
// These can be saved using the AutoIntegrate script.
this.util.initStandalone();
// We do stretching here so we set the value to true
this.global.par.enhancements_stretch.val = true;
// -------------------------------------------------------------------------
// Preview functions
// -------------------------------------------------------------------------
function setPreviewIdReset(id, keep_zoom, histogramInfo)
{
if (debug) console.writeln("AutoIntegrateImageStretchingDialog::updatePreviewIdReset: id = " + id);
var win = ImageWindow.windowById(id);
self.previewControl.SetImage(win.mainView.image, win.mainView.id + " [Preview]");
}
function updatePreviewIdReset(id, keep_zoom, histogramInfo)
{
if (debug) console.writeln("AutoIntegrateImageStretchingDialog::updatePreviewIdReset: id = " + id);
updatePreviewWin(ImageWindow.windowById(id));
}
function updatePreviewNoImage()
{
if (debug) console.writeln("AutoIntegrateImageStretchingDialog::updatePreviewNoImage");
self.statusLabel.text = "No image available for preview.";
}
function updatePreviewTxt(txt)
{
if (debug) console.writeln("AutoIntegrateImageStretchingDialog::updatePreviewTxt: " + txt);
}
function updatePreviewWin(imgWin)
{
if (debug) console.writeln("AutoIntegrateImageStretchingDialog::updatePreviewWin: imgWin = " + imgWin);
self.previewControl.UpdateImage(imgWin.mainView.image);
}
function updatePreviewWinTxt(imgWin, txt)
{
if (debug) console.writeln("AutoIntegrateImageStretchingDialog::updatePreviewWinTxt: imgWin = " + imgWin);
updatePreviewWin(imgWin);
}
var preview_functions = {
setPreviewIdReset: setPreviewIdReset,
updatePreviewIdReset: updatePreviewIdReset,
updatePreviewTxt: updatePreviewTxt,
updatePreviewNoImage: updatePreviewNoImage,
createCombinedMosaicPreviewWin: null,
updatePreviewWin: updatePreviewWin,
updatePreviewWinTxt: updatePreviewWinTxt,
};
// -------------------------------------------------------------------------
// Left Side: Preview Control
// -------------------------------------------------------------------------
this.previewControl = new AutoIntegratePreviewControl(this, "stretch_preview", self.engine, self.util, self.global, 600, 600, false);
this.leftSizer = new VerticalSizer;
this.leftSizer.spacing = 4;
this.leftSizer.add(this.previewControl, 600);
// -------------------------------------------------------------------------
// Status
// -------------------------------------------------------------------------
this.statusLabel = new Label(this);
this.statusLabel.text = "";
this.statusLabel.textAlignment = TextAlign_Center;
this.statusLabel.styleSheet = "color: #AAAAAA;";
// -------------------------------------------------------------------------
// Right Side: Title and Controls
// -------------------------------------------------------------------------
this.titleLabel = new Label(this);
this.titleLabel.text = this.TITLE + " v" + this.VERSION;
this.titleLabel.textAlignment = TextAlign_Center;
this.titleLabel.styleSheet = "font-size: 14pt; font-weight: bold; color: #4488FF;";
this.subtitleLabel = new Label(this);
this.subtitleLabel.text = "Select image and apply stretching";
this.subtitleLabel.textAlignment = TextAlign_Center;
this.subtitleLabel.styleSheet = "font-size: 9pt; color: #888888; font-style: italic;";
this.enhancements_gui = new AutoIntegrateEnhancementsGUI(this, self.guitools, self.util, self.global, self.engine, preview_functions);
this.stretchingChoiceSizer = self.guitools.createStrechingChoiceSizer(this, null);
this.stretchingChoiceGroupBox = new GroupBox(this);
this.stretchingChoiceGroupBox.title = "Stretching type";
this.stretchingChoiceGroupBox.sizer = this.stretchingChoiceSizer;
this.targetImageSizer = this.enhancements_gui.createTargetImageSizer(this);
this.enhancements_gui.apply_completed_callback = function(apply_ok) {
// We do stretching here so we set the value to true
// With reset option it may have been reset to false (default)
self.global.par.enhancements_stretch.val = true;
};
this.targetImageGroupBox = new GroupBox(this);
this.targetImageGroupBox.title = "Target image";
this.targetImageGroupBox.sizer = this.targetImageSizer;
this.stretchingSettingsSizer = self.guitools.createStretchingSettingsSizer(this, self.engine, 1, this.previewControl);
this.stretchingSettingsControl = new Control( this );
this.stretchingSettingsControl.sizer = new HorizontalSizer;
this.stretchingSettingsControl.sizer.margin = 6;
this.stretchingSettingsControl.sizer.spacing = 4;
this.stretchingSettingsControl.sizer.add( this.stretchingSettingsSizer );
this.stretchingSettingsControl.sizer.addStretch();
this.stretchingSettingsControl.visible = true;
// -------------------------------------------------------------------------
// Load and save JSON controls
// -------------------------------------------------------------------------
var obj = self.guitools.newJsonSizerObj(this, null, "ImageStretchingSettings.json");
this.loadSaveSizer = obj.sizer;
// -------------------------------------------------------------------------
// Stretching Group Box
// -------------------------------------------------------------------------
if (self.global.debug) console.writeln("AutoIntegrateImageStretchingDialog:: creating stretchingGroupBox");
this.stretchingGroupBox = self.guitools.newGroupBoxSizer(this);
this.stretchingGroupBox.title = "Settings";
this.stretchingGroupBox.sizer.add(this.stretchingSettingsControl);
this.stretchingGroupBox.sizer.addStretch();
// -------------------------------------------------------------------------
// Buttons
// -------------------------------------------------------------------------
this.resetButton = new PushButton(this);
this.resetButton.text = "Reset";
this.resetButton.toolTip = "Reset all parameters to defaults.";
this.resetButton.onClick = function() {
self.util.setParameterDefaults();
};
this.closeButton = new PushButton(this);
this.closeButton.text = "Close";
this.closeButton.icon = this.scaledResource(":/icons/close.png");
this.closeButton.onClick = function() {
self.ok();
};
this.buttonsSizer = new HorizontalSizer;
this.buttonsSizer.spacing = 6;
this.buttonsSizer.add(this.resetButton);
this.buttonsSizer.addStretch();
this.buttonsSizer.add(this.closeButton);
// -------------------------------------------------------------------------
// Right Side Layout
// -------------------------------------------------------------------------
this.rightSizer = new VerticalSizer;
this.rightSizer.spacing = 8;
this.rightSizer.add(this.titleLabel);
this.rightSizer.add(this.subtitleLabel);
this.rightSizer.add(this.statusLabel);
this.rightSizer.add(this.loadSaveSizer);
this.rightSizer.add(this.targetImageGroupBox);
this.rightSizer.add(this.stretchingChoiceGroupBox);
this.rightSizer.add(this.stretchingGroupBox);
this.rightSizer.add(this.buttonsSizer);
// -------------------------------------------------------------------------
// Main Layout (Preview on Left, Controls on Right)
// -------------------------------------------------------------------------
this.sizer = new HorizontalSizer;
this.sizer.margin = 8;
this.sizer.spacing = 8;
this.sizer.add(this.leftSizer);
this.sizer.add(this.rightSizer);
}
AutoIntegrateImageStretchingDialog.prototype = new Dialog;
// =============================================================================
// MAIN ENTRY POINT
// =============================================================================
#ifndef AUTOINTEGRATE_NO_MAIN
function main() {
console.show();
var dialog = new AutoIntegrateImageStretchingDialog();
dialog.execute();
}
main();
#endif /* AUTOINTEGRATE_NO_MAIN */