-
Notifications
You must be signed in to change notification settings - Fork 0
/
EZ_HDR.js
222 lines (187 loc) · 7.21 KB
/
EZ_HDR.js
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
// Copyright (C) 2020-2023 S Dimant (aka darkarchon#4313)
// File name: EZ_HDR.js
#feature-id EZ Processing Suite > EZ HDR
var NAME = 'EZ HDR';
var VERSION = '0.1';
var AUTHOR = "S. Dimant";
#include "EZ_Common.js"
function saveSettings() {
Settings.write("EZHDR.HDRAmount", 10, CurrentProcessingInfo.hdrAmount);
Settings.write("EZHDR.HDRLayers", 1, CurrentProcessingInfo.hdrLayers);
}
function generateProcessingInfo() {
let info = new ProcessingInfo();
info.hdrLayers = readFromSettingsOrDefault("EZHDR.HDRLayers", 1, 5);
info.hdrAmount = readFromSettingsOrDefault("EZHDR.HDRAmount", 10, 0.3);
info.currentHDRRun = 0;
info.rangeMaskId = null;
return info;
}
function execute(window, bringToFront = true, runOnMain = false) {
startProcessing();
writeMessageStart("Running EZ HDR on " + window.mainView.id);
CurrentProcessingInfo.rangeMaskId = createBackgroundMask(View.viewById(window.mainView.id),
"_ez_HDR_" + window.mainView.id + "_bg", false);
let hdrClone = cloneView(window.mainView, "_ez_HDR_" + window.mainView.id + "_HDR", true, false);
writeMessageBlock("Applying HDR to " + hdrClone.window.mainView.id);
let hdr = new HDRMultiscaleTransform();
hdr.numberOfLayers = CurrentProcessingInfo.hdrLayers;
hdr.executeOn(hdrClone);
window.removeMask();
window.setMask(View.viewById(CurrentProcessingInfo.rangeMaskId).window, true);
writeMessageBlock("Blending HDR image with " + window.mainView.id);
doPixelMath(window.mainView,
"(1-{0})*{1}+{0}*{2}".format(CurrentProcessingInfo.hdrAmount, window.mainView.id, hdrClone.window.mainView.id), true);
window.removeMask();
if(!runOnMain) {
hdrClone.window.forceClose();
} else {
hdrClone.window.iconize();
}
stopProcessing();
writeMessageEnd("EZ HDR run complete");
return window.mainView;
}
function onExit() {
// is called on exiting module
}
function onInit() {
// is called on initializing module
}
function customizeDialog() {
// customize dialog appearance and everything
dialog.infoBox.text = "<b>EZ HDR</b>: This script attempts to bring back details from bright galaxy and nebula cores.";
dialog.tutorialPrerequisites = ["Non-Linear image"];
dialog.tutorialSteps = [
"Set blend strength, this sets how much of the HDR image is blended into the image",
"Set the amount of layers that you want to be affected by the HDR process, the smaller the finer the HDR will be"
]
// custom binding for the dialog only, use .bindings for everything else!
dialog.customBindings = function() { }
// uncomment if evaluate button should be shown
// dialog.onEvaluateButton.show()
dialog.onExit = function() {
// called on exiting the dialog
}
// uncomment if previews should be allowed to be chosen
// dialog.allowPreviews();
dialog.onSelectedMainView = function(view, prevMainViewId) {
if(view.computeOrFetchProperty("Median").at(0) < 0.1) {
let result = dialog.showWarningDialog("Median lower 0.1. Unlikely this is a linear image. This script only works on non-linear images.", "Failed to load", "Continue anyway", true);
if(result != 1) {
dialog.mainViewSelector.remove(view);
CurrentProcessingInfo.mainViewId = null;
return;
}
}
if(prevMainViewId == CurrentProcessingInfo.mainViewId) return;
if(CurrentProcessingInfo.rangeMaskId != null) {
View.viewById(CurrentProcessingInfo.rangeMaskId).window.forceClose();
}
for (let i = dialog.tabBox.numberOfPages - 1; i >= 0; i--) {
dialog.tabBox.pageControlByIndex(i).dispose();
dialog.tabBox.removePage(i);
}
/* // not used for first iteration
dialog.addMainControl(CurrentProcessingInfo.workingViewId);
dialog.tabBox.show();
if (prevMainViewId == null)
{
dialog.width *= 3;
dialog.setScaledMinWidth(dialog.width);
}
*/
}
/* // not used for first iteration
dialog.addMainControl = function(viewId) {
let viewControl = new PreviewControl(dialog, true, true);
viewControl.STF = DEFAULT_STF;
viewControl.SetView(View.viewById(viewId), false);
viewControl.swap = function () {
dialog.tabBox.currentPageIndex = dialog.tabBox.numberOfPages - 1;
}
let swapToLatestButton = new PushButton(viewControl);
swapToLatestButton.text = "Change Tab to Latest Run";
swapToLatestButton.onClick = function () {
viewControl.swap.call(viewControl);
}
swapToLatestButton.bindings = function () {
swapToLatestButton.text = "Change Tab to " + dialog.tabBox.pageLabel(dialog.tabBox.numberOfPages - 1);
}
viewControl.infoFrame.sizer.insertItem(0, swapToLatestButton);
dialog.tabBox.insertPage(0, viewControl, viewId);
} */
dialog.onEmptyMainView = function() {
/* // not used for first iteration
for (let i = dialog.tabBox.numberOfPages - 1; i >= 0; i--) {
dialog.tabBox.pageControlByIndex(i).dispose();
dialog.tabBox.removePage(i);
}
dialog.tabBox.hide();
dialog.adjustToContents();
dialog.setScaledMinWidth(dialog.width);
*/
}
dialog.canRun = function() {
return CurrentProcessingInfo.mainViewId != null;
}
dialog.canEvaluate = function() {
return CurrentProcessingInfo.mainViewId != null;
}
dialog.onEvaluate = function () {
}
dialog.amountSlider = new NumericControl(dialog);
with (dialog.amountSlider) {
label.text = "HDR Blend";
label.minWidth = 100;
setRange(0.01, 0.4);
slider.setRange(0, 100);
slider.scaledMinWidth = 60;
setPrecision(2);
edit.scaledMinWidth = 60;
bindings = function() {
this.setValue(CurrentProcessingInfo.hdrAmount);
}
onValueUpdated = function (value) {
CurrentProcessingInfo.hdrAmount = value;
}
}
dialog.layerSlider = new NumericControl(dialog);
with (dialog.layerSlider) {
label.text = "HDR Layers";
label.minWidth = 100;
setRange(3, 7);
slider.setRange(0, 100);
slider.scaledMinWidth = 60;
setPrecision(0);
edit.scaledMinWidth = 60;
bindings = function() {
this.setValue(CurrentProcessingInfo.hdrLayers);
}
onValueUpdated = function (value) {
CurrentProcessingInfo.hdrLayers = value;
}
}
dialog.resetButton = new PushButton(dialog);
with(dialog.resetButton) {
text = "Reset EZ HDR Settings";
toolTip = "Reset EZ HDR to default settings";
icon = dialog.scaledResource(":/icons/debug-restart.png");
onClick = function () {
CurrentProcessingInfo.hdrLayers = 5;
CurrentProcessingInfo.hdrAmount = 0.3;
}
}
dialog.mainControl.sizer.addItem(dialog.amountSlider);
dialog.mainControl.sizer.addItem(dialog.layerSlider);
dialog.mainControl.sizer.addItem(dialog.resetButton);
dialog.mainControl.bindings = function() {
this.enabled = dialog.canRun();
}
dialog.setScaledMaxWidth(300);
dialog.control.setScaledMaxWidth(300);
dialog.setScaledMinWidth(300);
dialog.control.setScaledMinWidth(300);
dialog.adjustToContents();
}
main();