imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Hue wheel colors are wrong

Open PanForPancakes opened this issue 3 years ago • 5 comments

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

PanForPancakes avatar Apr 14 '22 21:04 PanForPancakes

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.

ocornut avatar Apr 15 '22 13:04 ocornut

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?

jamesthomasgriffin avatar Apr 19 '22 14:04 jamesthomasgriffin

@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.

rokups avatar Jul 26 '22 13:07 rokups

@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.)

jamesthomasgriffin avatar Jul 26 '22 15:07 jamesthomasgriffin

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.

rokups avatar Jul 28 '22 08:07 rokups

Merged as 9ac94ff, thank you all !

ocornut avatar Mar 21 '23 16:03 ocornut