Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hue wheel colors are wrong #5200

Closed
PanForPancakes opened this issue Apr 14, 2022 · 6 comments
Closed

Hue wheel colors are wrong #5200

PanForPancakes opened this issue Apr 14, 2022 · 6 comments

Comments

@PanForPancakes
Copy link
Contributor

Version/Branch of Dear ImGui:

Version: Dear ImGui 1.87 (18700)
Branch: master

Back-end/Renderer/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Operating System: Windows 11

My Question:

Hue wheel color picker colors doesn't seem right.

Screenshots

How you can see selected color has 0 saturation but on triangle it has some
image

Isn't it supposed to look more like this, where triangle gradually loses saturation?
image

@ocornut
Copy link
Owner

ocornut commented Apr 15, 2022

Thanks for reporting
I guess it could be improved indeed, would have to figure out how to rework that part.

// Render SV triangle (rotated according to hue)
ImVec2 tra = wheel_center + ImRotate(triangle_pa, cos_hue_angle, sin_hue_angle);
ImVec2 trb = wheel_center + ImRotate(triangle_pb, cos_hue_angle, sin_hue_angle);
ImVec2 trc = wheel_center + ImRotate(triangle_pc, cos_hue_angle, sin_hue_angle);
ImVec2 uv_white = GetFontTexUvWhitePixel();
draw_list->PrimReserve(6, 6);
draw_list->PrimVtx(tra, uv_white, hue_color32);
draw_list->PrimVtx(trb, uv_white, hue_color32);
draw_list->PrimVtx(trc, uv_white, col_white);
draw_list->PrimVtx(tra, uv_white, 0);
draw_list->PrimVtx(trb, uv_white, col_black);
draw_list->PrimVtx(trc, uv_white, 0);
draw_list->AddTriangle(tra, trb, trc, col_midgrey, 1.5f);

Fixes would be welcome.

@jamesthomasgriffin
Copy link

I changed the corresponding 7 lines above to the lines below:

draw_list->PrimReserve(3, 3);
draw_list->PrimVtx(tra, uv_white, hue_color32);
draw_list->PrimVtx(trb, uv_white, col_black);
draw_list->PrimVtx(trc, uv_white, col_white);

and that seemed to fix the issue, the preview color matches the triangle. However this seems too simple, is there something I'm missing? Why is the current code blending two triangles?

@rokups
Copy link
Contributor

rokups commented Jul 26, 2022

@jamesthomasgriffin looks like your version is correct. At least as far as Gimp is concerned. I did a test:

  1. Open Gimp's color picker
  2. Open Dear ImGui's color picker
  3. Select screen color picking tool in Gimp
  4. Double-click on Dear ImGui color picker triangle.

We end up with two colors, a color picked by Gimp color picker and a color selected by Dear ImGui color picker. Depending on where i click i am consistently getting about 20-30 color difference for two of RGB components. Version proposed by @jamesthomasgriffin produces difference of 1 in two-three RGB components.

tl;dr; New proposed version produces a triangle where clicked color is a lot closer to color actually produced by the picker.

@jamesthomasgriffin
Copy link

@rokups thank you for doing that test. I think my version is correct, however there may be something I'm overlooking with alpha channels / transparency.

(I believe you've also shown that Gimp is incorrect(!) because it should be using SRGB and I don't think ImGui does by default.)

@rokups
Copy link
Contributor

rokups commented Jul 28, 2022

Dear ImGui does not support SRGB in any way so far.. Your comment prompted me to compare Gimp to Krita. Sampled color and picked color of these two programs differs by 1-2, which is pretty close. While i am not familiar with color theory and peculiarities of color pickers, i suppose drawing application authors should know what they are doing. Krita especially, since it is geared towards drawing. Considering no SRGB support at this time, we probably should adopt your solution.

@ocornut
Copy link
Owner

ocornut commented Mar 21, 2023

Merged as 9ac94ff, thank you all !

@ocornut ocornut closed this as completed Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants