Skip to content

Commit

Permalink
Merge pull request #1092 from alicevision/dev/viewerGainGamma
Browse files Browse the repository at this point in the history
[ui] Viewer: fix gain/gamma and use non-linear sliders
  • Loading branch information
fabiencastan authored Oct 15, 2020
2 parents 6b68079 + dd94bc8 commit 42913c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
43 changes: 22 additions & 21 deletions meshroom/ui/qml/Viewer/HdrImageToolbar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ FloatingPane {
padding: 5
radius: 0

property real gainDefaultValue: 1
property real gammaDefaultValue: 1
property real offsetDefaultValue: 0
property real gammaValue: gammaCtrl.value
property real offsetValue: offsetCtrl.value
property real slidersPowerValue: 4
property real gainValue: Math.pow(gainCtrl.value, slidersPowerValue)
property real gammaValue: Math.pow(gammaCtrl.value, slidersPowerValue)
property string channelModeValue: channelsCtrl.value
property variant colorRGBA: null

Expand Down Expand Up @@ -44,7 +45,7 @@ FloatingPane {
model: channels
}

// offset slider
// gain slider
RowLayout {
spacing: 5

Expand All @@ -56,30 +57,30 @@ FloatingPane {
ToolTip.text: "Reset Gain"

onClicked: {
offsetCtrl.value = offsetDefaultValue;
gainCtrl.value = gainDefaultValue;
}
}
TextField {
id: offsetLabel
id: gainLabel

ToolTip.visible: ToolTip.text && hovered
ToolTip.delay: 100
ToolTip.text: "Color Gain (in linear colorspace)"

text: offsetValue.toFixed(2)
Layout.preferredWidth: textMetrics_offsetValue.width
text: gainValue.toFixed(2)
Layout.preferredWidth: textMetrics_gainValue.width
selectByMouse: true
validator: doubleValidator
onAccepted: {
offsetCtrl.value = Number(offsetLabel.text)
gainCtrl.value = Math.pow(Number(gainLabel.text), 1.0/slidersPowerValue)
}
}
Slider {
id: offsetCtrl
id: gainCtrl
Layout.fillWidth: true
from: -1
to: 1
value: 0
from: 0.01
to: 2
value: gainDefaultValue
stepSize: 0.01
}
}
Expand Down Expand Up @@ -107,19 +108,19 @@ FloatingPane {
ToolTip.text: "Apply Gamma (after Gain and in linear colorspace)"

text: gammaValue.toFixed(2)
Layout.preferredWidth: textMetrics_offsetValue.width
Layout.preferredWidth: textMetrics_gainValue.width
selectByMouse: true
validator: doubleValidator
onAccepted: {
gammaCtrl.value = Number(offsetLabel.text)
gammaCtrl.value = Math.pow(Number(gammaLabel.text), 1.0/slidersPowerValue)
}
}
Slider {
id: gammaCtrl
Layout.fillWidth: true
from: 0.01
to: 16
value: 1
to: 2
value: gammaDefaultValue
stepSize: 0.01
}
}
Expand All @@ -131,7 +132,7 @@ FloatingPane {
color: root.colorRGBA ? Qt.rgba(red.value_gamma, green.value_gamma, blue.value_gamma, 1.0) : "black"
}

// gamma slider
// RGBA colors
RowLayout {
spacing: 1
TextField {
Expand Down Expand Up @@ -230,8 +231,8 @@ FloatingPane {
text: "1.2345" // use one more than expected to get the correct value (probably needed due to TextField margin)
}
TextMetrics {
id: textMetrics_offsetValue
font: offsetLabel.font
text: "-10.01"
id: textMetrics_gainValue
font: gainLabel.font
text: "1.2345"
}
}
2 changes: 1 addition & 1 deletion meshroom/ui/qml/Viewer/Viewer2D.qml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ FocusScope {
setSource("FloatImage.qml", {
'source': Qt.binding(function() { return getImageFile(imageType.type); }),
'gamma': Qt.binding(function() { return hdrImageToolbar.gammaValue; }),
'offset': Qt.binding(function() { return hdrImageToolbar.offsetValue; }),
'gain': Qt.binding(function() { return hdrImageToolbar.gainValue; }),
'channelModeString': Qt.binding(function() { return hdrImageToolbar.channelModeValue; }),
})
} else {
Expand Down

0 comments on commit 42913c2

Please sign in to comment.