mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-14 19:04:44 +00:00
Information is lost on a round trip through ColorPicker4 for applications that store colors as HSV #2383
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#2383
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Version/Branch of Dear ImGui:
Version: 1.68
Branch: I believe all, but definitely master and docking
Back-end/Renderer/Compiler/OS
Back-ends: all
Compiler: all
Operating System: all
My Issue/Question:
Applications that store colors as HSV values have a hard time using
ColorPickerandColorEditcorrectly, because they have to take the round trip of HSV -> RGB -> HSV. The map from HSV to RGB has two singularities: when S is 0 (grayscale values, where hue doesn't matter) and when V is 0 (black, hue and saturation both don't matter).Applications that store color values in HSV would like to maintain the H and S values when V goes to zero, or the H value when S goes to zero, even though the RGB color is the same. Otherwise, you get odd behavior where fading the saturation from a positive value down to zero and then back up will change the hue of the color you were editing.
From looking at the code of
ColorPicker4, it looks like internally the first thing that the picker does is convert from RGB to HSV, and then it uses those HSV values almost everywhere when drawing the UI. I believe this issue could be fixed by adding a ColorPicker flag that specifies that the inputfloat[3]of color is already in HSV format. This is because the problem is not really withColorPicker, but with the need for usingColorConvertHSVtoRGBandColorConvertRGBtoHSV, which are inherently lossy. If ColorPicker took and returned HSV values, then it would have the necessary information to maintain the state of hue and saturation when saturation or value went to zero.Unfortunately
ImGuiColorEditFlags_HSVis already taken, but maybe the flag could be namedImGuiColorEditFlags_HSV_IO, to mark that input and output color data are in HSV, or something similar? I'm happy to provide a PR to add a flag like this, but I wanted to make sure this sounded like a good approach before I started coding. Either way, I'm happy to do the work to get native HSV I/O support intoColorPicker; if you're willing to accept a patch, let me know what you'd like to see!Standalone, minimal, complete and verifiable example: (see https://github.com/ocornut/imgui/issues/2261)
A dumb example to show how a round-trip through
ColorConvertHSVtoRGBandColorConvertRGBtoHSVcan muck up your colors:Screenshots/Video
The hue starts at 0.5, but is reset to zero when the saturation is dropped to zero, because
ColorConvertRGBtoHSVturns(1, 1, 1)into(0, 0, 1), instead of the(0.5, 0, 1)we would like to have. We wouldn't need to call theColorConvert*functions ifColorEdit3could take HSV values natively.Hello,
Thanks for the detailed post. I agree with your suggestion and would very much appreciate a PR for it.
(
I suggest the flag could be called _InputHSV (corresponding _InputRGB may be added to make things cleared, as well as __InputDefault).
I also suggest __InputsMask (which is private) be renamed to __ShowMask. And we could later consider to rename _RGB/ _HSV/ _HEX to add the “Show” word in then (with redirecting enums for backward compatibility) but that could be done separately.
)
Thanks a lot!
Great! I'll start in on this and get you something in the next couple days. Thanks Omar!
Closing this as the PR itself is enough for tracking progress on this, Thanks again!