Added Color Correction mapping input

Map image processing source callbacks to key inputs.
This commit is contained in:
Bruno Herbelin
2022-10-15 00:26:16 +02:00
parent 48001a660b
commit 2fc52e673f
4 changed files with 199 additions and 35 deletions

View File

@@ -325,27 +325,13 @@ void ImGuiVisitor::visit(ImageProcessingShader &n)
}
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
ImGui::SliderFloat("Hue shift", &n.hueshift, 0.0, 1.0);
ImGui::SliderFloat("Hue", &n.hueshift, 0.0, 1.0);
if (ImGui::IsItemDeactivatedAfterEdit()){
std::ostringstream oss;
oss << "Hue shift " << std::setprecision(2) << n.hueshift;
Action::manager().store(oss.str());
}
if (ImGuiToolkit::IconButton(18, 1)) {
n.nbColors = 0;
Action::manager().store("Posterize None");
}
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
ImGui::SliderInt("Posterize", &n.nbColors, 0, 16, n.nbColors == 0 ? "None" : "%d colors");
if (ImGui::IsItemDeactivatedAfterEdit()){
std::ostringstream oss;
oss << "Posterize ";
if (n.nbColors == 0) oss << "None"; else oss << n.nbColors;
Action::manager().store(oss.str());
}
if (ImGuiToolkit::IconButton(8, 1)) {
n.threshold = 0.f;
Action::manager().store("Threshold None");
@@ -360,6 +346,20 @@ void ImGuiVisitor::visit(ImageProcessingShader &n)
Action::manager().store(oss.str());
}
if (ImGuiToolkit::IconButton(18, 1)) {
n.nbColors = 0;
Action::manager().store("Posterize None");
}
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
ImGui::SliderInt("Posterize", &n.nbColors, 0, 16, n.nbColors == 0 ? "None" : "%d colors");
if (ImGui::IsItemDeactivatedAfterEdit()){
std::ostringstream oss;
oss << "Posterize ";
if (n.nbColors == 0) oss << "None"; else oss << n.nbColors;
Action::manager().store(oss.str());
}
if (ImGuiToolkit::IconButton(6, 16)) {
n.invert = 0;
Action::manager().store("Invert None");
@@ -446,16 +446,10 @@ void ImGuiVisitor::visit (Source& s)
// Filter
bool on = s.imageProcessingEnabled();
ImGui::SetCursorPos( ImVec2( pos.x, pos.y + preview_height));
if (on) {
ImGuiToolkit::Icon(6, 2);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("Color correction");
}
else {
ImGuiToolkit::Indication("Color correction disabled", 6, 2);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::TextDisabled("Color correction");
}
if (on)
ImGui::Text(ICON_FA_PALETTE " Color correction");
else
ImGuiToolkit::Indication("Color correction filter is disabled", ICON_FA_PALETTE " Color correction");
pos = ImGui::GetCursorPos();
// menu icon for image processing
@@ -527,6 +521,7 @@ void ImGuiVisitor::visit (Source& s)
// full panel for image processing
ImGui::SetCursorPos( pos );
ImGui::Spacing();
if (s.processingshader_link_.connected()) {
Source *target = s.processingshader_link_.source();

View File

@@ -77,10 +77,10 @@ SourceCallback *SourceCallback::create(CallbackType type)
loadedcallback = new SetContrast;
break;
case SourceCallback::CALLBACK_SATURATION:
loadedcallback = new SetBrightness;
loadedcallback = new SetSaturation;
break;
case SourceCallback::CALLBACK_HUE:
loadedcallback = new SetContrast;
loadedcallback = new SetHue;
break;
case SourceCallback::CALLBACK_THRESHOLD:
loadedcallback = new SetThreshold;

View File

@@ -4632,9 +4632,9 @@ Source *InputMappingInterface::ComboSelectSource(Source *current)
return selected;
}
uint InputMappingInterface::ComboSelectCallback(uint current)
uint InputMappingInterface::ComboSelectCallback(uint current, bool imageprocessing)
{
const char* callback_names[9] = { "Select",
const char* callback_names[21] = { "Select",
ICON_FA_BULLSEYE " Alpha",
ICON_FA_BULLSEYE " Loom",
ICON_FA_OBJECT_UNGROUP " Geometry",
@@ -4642,16 +4642,35 @@ uint InputMappingInterface::ComboSelectCallback(uint current)
ICON_FA_OBJECT_UNGROUP " Resize",
ICON_FA_OBJECT_UNGROUP " Turn",
ICON_FA_LAYER_GROUP " Depth",
ICON_FA_PLAY_CIRCLE " Play"
};
ICON_FA_PLAY_CIRCLE " Play",
" None",
" None",
" None",
" None",
ICON_FA_PALETTE " Brightness",
ICON_FA_PALETTE " Contrast",
ICON_FA_PALETTE " Saturation",
ICON_FA_PALETTE " Hue",
ICON_FA_PALETTE " Threshold",
ICON_FA_PALETTE " Gamma",
" None",
" None"
};
int selected = 0;
uint selected = 0;
if (ImGui::BeginCombo("##ComboSelectCallback", callback_names[current]) ) {
for (uint i = SourceCallback::CALLBACK_ALPHA; i <= SourceCallback::CALLBACK_PLAY; ++i){
if ( ImGui::Selectable( callback_names[i]) ) {
selected = i;
}
}
if (imageprocessing) {
for (uint i = SourceCallback::CALLBACK_BRIGHTNESS; i <= SourceCallback::CALLBACK_THRESHOLD; ++i){
if ( ImGui::Selectable( callback_names[i]) ) {
selected = i;
}
}
}
ImGui::EndCombo();
}
@@ -4830,6 +4849,156 @@ void InputMappingInterface::SliderParametersCallback(SourceCallback *callback, S
ImGuiToolkit::Indication("Play or pause the source.", 16, 7);
}
break;
case SourceCallback::CALLBACK_BRIGHTNESS:
{
SetBrightness *edited = static_cast<SetBrightness*>(callback);
bool bd = edited->bidirectional();
if ( ImGuiToolkit::IconToggle(2, 13, 3, 13, &bd, press_tooltip ) )
edited->setBidirectional(bd);
ClosestIndex d = std::for_each(speed_values.begin(), speed_values.end(), ClosestIndex(edited->duration()));
int speed_index = d.index;
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
if (ImGuiToolkit::IconMultistate(speed_icon, &speed_index, speed_tooltip ))
edited->setDuration(speed_values[speed_index]);
float val = edited->value();
ImGui::SetNextItemWidth(right_align);
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
if (ImGui::SliderFloat("##CALLBACK_BRIGHTNESS", &val, -1.f, 1.f, "%.1f"))
edited->setValue(val);
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
ImGuiToolkit::Indication("Set Brightness color correction.", 5, 16);
}
break;
case SourceCallback::CALLBACK_CONTRAST:
{
SetContrast *edited = static_cast<SetContrast*>(callback);
bool bd = edited->bidirectional();
if ( ImGuiToolkit::IconToggle(2, 13, 3, 13, &bd, press_tooltip ) )
edited->setBidirectional(bd);
ClosestIndex d = std::for_each(speed_values.begin(), speed_values.end(), ClosestIndex(edited->duration()));
int speed_index = d.index;
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
if (ImGuiToolkit::IconMultistate(speed_icon, &speed_index, speed_tooltip ))
edited->setDuration(speed_values[speed_index]);
float val = edited->value();
ImGui::SetNextItemWidth(right_align);
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
if (ImGui::SliderFloat("##CALLBACK_CONTRAST", &val, -1.f, 1.f, "%.1f"))
edited->setValue(val);
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
ImGuiToolkit::Indication("Set Contrast color correction.", 5, 16);
}
break;
case SourceCallback::CALLBACK_SATURATION:
{
SetSaturation *edited = static_cast<SetSaturation*>(callback);
bool bd = edited->bidirectional();
if ( ImGuiToolkit::IconToggle(2, 13, 3, 13, &bd, press_tooltip ) )
edited->setBidirectional(bd);
ClosestIndex d = std::for_each(speed_values.begin(), speed_values.end(), ClosestIndex(edited->duration()));
int speed_index = d.index;
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
if (ImGuiToolkit::IconMultistate(speed_icon, &speed_index, speed_tooltip ))
edited->setDuration(speed_values[speed_index]);
float val = edited->value();
ImGui::SetNextItemWidth(right_align);
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
if (ImGui::SliderFloat("##CALLBACK_SATURATION", &val, -1.f, 1.f, "%.1f"))
edited->setValue(val);
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
ImGuiToolkit::Indication("Set Saturation color correction.", 9, 16);
}
break;
case SourceCallback::CALLBACK_HUE:
{
SetHue *edited = static_cast<SetHue*>(callback);
bool bd = edited->bidirectional();
if ( ImGuiToolkit::IconToggle(2, 13, 3, 13, &bd, press_tooltip ) )
edited->setBidirectional(bd);
ClosestIndex d = std::for_each(speed_values.begin(), speed_values.end(), ClosestIndex(edited->duration()));
int speed_index = d.index;
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
if (ImGuiToolkit::IconMultistate(speed_icon, &speed_index, speed_tooltip ))
edited->setDuration(speed_values[speed_index]);
float val = edited->value();
ImGui::SetNextItemWidth(right_align);
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
if (ImGui::SliderFloat("##CALLBACK_HUE", &val, 0.f, 1.f, "%.1f"))
edited->setValue(val);
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
ImGuiToolkit::Indication("Set Hue shift color correction.", 12, 4);
}
break;
case SourceCallback::CALLBACK_THRESHOLD:
{
SetThreshold *edited = static_cast<SetThreshold*>(callback);
bool bd = edited->bidirectional();
if ( ImGuiToolkit::IconToggle(2, 13, 3, 13, &bd, press_tooltip ) )
edited->setBidirectional(bd);
ClosestIndex d = std::for_each(speed_values.begin(), speed_values.end(), ClosestIndex(edited->duration()));
int speed_index = d.index;
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
if (ImGuiToolkit::IconMultistate(speed_icon, &speed_index, speed_tooltip ))
edited->setDuration(speed_values[speed_index]);
float val = edited->value();
ImGui::SetNextItemWidth(right_align);
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
if (ImGui::SliderFloat("##CALLBACK_THRESHOLD", &val, 0.f, 1.f, "%.1f"))
edited->setValue(val);
ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
ImGuiToolkit::Indication("Set Threshold color correction.", 8, 1);
}
break;
case SourceCallback::CALLBACK_GAMMA:
{
// SetGamma *edited = static_cast<SetGamma*>(callback);
// bool bd = edited->bidirectional();
// if ( ImGuiToolkit::IconToggle(2, 13, 3, 13, &bd, press_tooltip ) )
// edited->setBidirectional(bd);
// ClosestIndex d = std::for_each(speed_values.begin(), speed_values.end(), ClosestIndex(edited->duration()));
// int speed_index = d.index;
// ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
// if (ImGuiToolkit::IconMultistate(speed_icon, &speed_index, speed_tooltip ))
// edited->setDuration(speed_values[speed_index]);
// float val = edited->value();
// ImGui::SetNextItemWidth(right_align);
// ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
// if (ImGui::SliderFloat("##CALLBACK_GAMMA", &val, -1.f, 1.f, "%.1f"))
// edited->setValue(val);
// ImGui::SameLine(0, IMGUI_SAME_LINE / 2);
// ImGuiToolkit::Indication("Set Gamma color correction.", 5, 16);
}
break;
default:
break;
}
@@ -5393,7 +5562,7 @@ void InputMappingInterface::Render()
// Select Reaction
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::SetNextItemWidth(w);
uint type = ComboSelectCallback( callback->type() );
uint type = ComboSelectCallback( callback->type(), source->imageProcessingEnabled() );
if (type > 0) {
// remove previous callback
S->deleteSourceCallback(callback);
@@ -5451,7 +5620,7 @@ void InputMappingInterface::Render()
// step 3: Get input for callback type
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::SetNextItemWidth(w);
temp_new_callback = ComboSelectCallback( temp_new_callback );
temp_new_callback = ComboSelectCallback( temp_new_callback, temp_new_source->imageProcessingEnabled() );
// user selected a callback type
if (temp_new_callback > 0) {
// step 4 : create new callback and add it to source

View File

@@ -383,7 +383,7 @@ class InputMappingInterface : public WorkspaceWindow
uint current_input_;
Source *ComboSelectSource(Source *current = nullptr);
uint ComboSelectCallback(uint current);
uint ComboSelectCallback(uint current, bool imageprocessing);
void SliderParametersCallback(SourceCallback *callback, Source *source);
public: