-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphicsTemp.py
230 lines (196 loc) · 9.01 KB
/
graphicsTemp.py
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
"""
This File is part of bLUe software.
Copyright (C) 2017 Bernard Virot <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Lesser Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import weakref
from PySide2 import QtCore
from PySide2.QtCore import Qt
from PySide2.QtGui import QFontMetrics
from PySide2.QtWidgets import QSizePolicy, QVBoxLayout, QLabel, QHBoxLayout
from bLUeGui.colorCIE import sRGBWP
from bLUeGui.graphicsForm import baseForm
from bLUeGui.memory import weakProxy
from utils import optionsWidget, QbLUeSlider, QbLUeLabel
class temperatureForm (baseForm):
# dataChanged = QtCore.Signal()
@classmethod
def getNewWindow(cls, targetImage=None, axeSize=500, layer=None, parent=None, mainForm=None):
wdgt = temperatureForm(axeSize=axeSize, layer=layer, parent=parent, mainForm=mainForm)
wdgt.setWindowTitle(layer.name)
return wdgt
def __init__(self, targetImage=None, axeSize=500, layer=None, parent=None, mainForm=None):
super().__init__(parent=parent)
self.tempCorrection = 6500
self.tintCorrection = 1.0
self.setStyleSheet('QRangeSlider * {border: 0px; padding: 0px; margin: 0px}')
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
self.setMinimumSize(axeSize, axeSize)
self.setAttribute(Qt.WA_DeleteOnClose)
# link back to image layer
self.layer = weakProxy(layer)
"""
# using weak ref for back links
if type(layer) in weakref.ProxyTypes:
self.layer = layer
else:
self.layer = weakref.proxy(layer)
"""
self.defaultTemp = sRGBWP # ref temperature D65
self.defaultTint = 0
# options
optionList, optionNames = ['Photo Filter', 'Chromatic Adaptation'], ['Photo Filter', 'Chromatic Adaptation']
self.listWidget1 = optionsWidget(options=optionList, optionNames=optionNames, exclusive=True, changed=lambda: self.dataChanged.emit())
self.listWidget1.checkOption(self.listWidget1.intNames[1])
self.options = self.listWidget1.options
# temp slider
self.sliderTemp = QbLUeSlider(Qt.Horizontal)
self.sliderTemp.setStyleSheet(QbLUeSlider.bLueSliderDefaultIColorStylesheet)
self.sliderTemp.setRange(17, 100) # 250) # valid range for spline approximation is 1667..25000, cf. colorConv.temperature2xyWP
self.sliderTemp.setSingleStep(1)
tempLabel = QbLUeLabel()
tempLabel.setMaximumSize(150, 30)
tempLabel.setText("Color temperature")
tempLabel.doubleClicked.connect(lambda: self.sliderTemp.setValue(self.temp2Slider(self.defaultTemp)))
self.tempValue = QLabel()
font = self.tempValue.font()
metrics = QFontMetrics(font)
w = metrics.width("0000")
h = metrics.height()
self.tempValue.setMinimumSize(w, h)
self.tempValue.setMaximumSize(w, h)
self.tempValue.setText(str("{:d}".format(self.sliderTemp2User(self.sliderTemp.value()))))
# tint slider
self.sliderTint = QbLUeSlider(Qt.Horizontal)
self.sliderTint.setStyleSheet(QbLUeSlider.bLueSliderDefaultMGColorStylesheet)
self.sliderTint.setRange(0, 100) # 250) # valid range for spline approximation is 1667..25000, cf. colorConv.temperature2xyWP
self.sliderTint.setSingleStep(1)
tintLabel = QbLUeLabel()
tintLabel.setMaximumSize(150, 30)
tintLabel.setText("Tint")
tintLabel.doubleClicked.connect(lambda: self.sliderTint.setValue(self.tint2Slider(self.defaultTint)))
self.tintValue = QLabel()
font = self.tintValue.font()
metrics = QFontMetrics(font)
w = metrics.width("0000")
h = metrics.height()
self.tintValue.setMinimumSize(w, h)
self.tintValue.setMaximumSize(w, h)
self.tintValue.setText(str("{:d}".format(self.sliderTint2User(self.sliderTint.value()))))
# temp change event handler
def tempUpdate(value):
self.tempValue.setText(str("{:d}".format(self.sliderTemp2User(value))))
# move not yet terminated or values not modified
if self.sliderTemp.isSliderDown() or self.slider2Temp(value) == self.tempCorrection :
return
self.sliderTemp.valueChanged.disconnect()
self.sliderTemp.sliderReleased.disconnect()
self.tempCorrection = self.slider2Temp(value)
self.dataChanged.emit()
self.sliderTemp.valueChanged.connect(tempUpdate)
self.sliderTemp.sliderReleased.connect(lambda: tempUpdate(self.sliderTemp.value()))
# tint change event handler
def tintUpdate(value):
self.tintValue.setText(str("{:d}".format(self.sliderTint2User(value))))
# move not yet terminated or values not modified
if self.sliderTint.isSliderDown() or self.slider2Tint(value) == self.tintCorrection:
return
self.sliderTint.valueChanged.disconnect()
self.sliderTint.sliderReleased.disconnect()
self.tintCorrection = self.slider2Tint(value)
self.dataChanged.emit()
self.sliderTint.valueChanged.connect(tintUpdate)
self.sliderTint.sliderReleased.connect(lambda: tintUpdate(self.sliderTint.value()))
self.sliderTemp.valueChanged.connect(tempUpdate)
self.sliderTemp.sliderReleased.connect(lambda: tempUpdate(self.sliderTemp.value()))
self.sliderTint.valueChanged.connect(tintUpdate)
self.sliderTint.sliderReleased.connect(lambda: tintUpdate(self.sliderTint.value()))
# layout
l = QVBoxLayout()
l.setAlignment(Qt.AlignTop)
l.addWidget(self.listWidget1)
l.addWidget(tempLabel)
hl = QHBoxLayout()
hl.addWidget(self.tempValue)
hl.addWidget(self.sliderTemp)
l.addLayout(hl)
l.addWidget(tintLabel)
hl1 = QHBoxLayout()
hl1.addWidget(self.tintValue)
hl1.addWidget(self.sliderTint)
l.addLayout(hl1)
self.setLayout(l)
self.adjustSize()
self.dataChanged.connect(self.updateLayer) # TODO move to setDefaults 3/12/18
self.setStyleSheet("QListWidget, QLabel {font : 7pt;}")
self.setDefaults()
self.setWhatsThis(
"""<b>Color Temperature</b><br>
<b>Photo Filter</b> uses the multiply blending mode to mimic a color filter
in front of the camera lens.<br>
<b>Chromatic Adaptation</b> uses multipliers in the linear sRGB
color space to adjust <b>temperature</b> and <b>tint</b>.
"""
) # end of setWhatsThis
def enableSliders(self):
self.sliderTemp.setEnabled(True)
self.sliderTint.setEnabled(self.options['Chromatic Adaptation'])
def setDefaults(self):
# prevent multiple updates
try:
self.dataChanged.disconnect()
except RuntimeError:
pass
self.listWidget1.unCheckAll()
self.listWidget1.checkOption(self.listWidget1.intNames[0])
self.enableSliders()
self.sliderTemp.setValue(round(self.temp2Slider(self.tempCorrection)))
self.sliderTint.setValue(round(self.tint2Slider(self.defaultTint)))
self.dataChanged.connect(self.updateLayer)
# self.dataChanged.emit() # removed 30/10/18
def updateLayer(self):
"""
data changed event handler.
"""
self.enableSliders()
self.layer.applyToStack()
self.layer.parentImage.onImageChanged()
def slider2Temp(self, v):
return v * 100
def temp2Slider(self, v):
return int(v /100)
def sliderTemp2User(selfself, v):
return v * 100
def slider2Tint(self, v):
return (v - 50) / 50
def tint2Slider(self, v):
return int( (1.0 + v) *50.0)
def sliderTint2User(selfself, v):
return int((v - 50) / 5.0)
def writeToStream(self, outStream):
layer = self.layer
outStream.writeQString(layer.actionName)
outStream.writeQString(layer.name)
outStream.writeQString(self.listWidget1.selectedItems()[0].text())
outStream.writeInt32(self.sliderTemp.value()*100)
return outStream
def readFromStream(self, inStream):
actionName = inStream.readQString()
name = inStream.readQString()
sel = inStream.readQString()
temp = inStream.readInt32()
for r in range(self.listWidget1.count()):
currentItem = self.listWidget1.item(r)
if currentItem.text() == sel:
self.listWidget.select(currentItem)
self.sliderTemp.setValue(temp//100)
self.update()
return inStream