Skip to content

color picker: misc. improvements - #9925

Merged
TurboGit merged 19 commits into
darktable-org:masterfrom
dtorop:color-picker-improvements-post-9835
Sep 3, 2021
Merged

TurboGit merged 19 commits into
darktable-org:masterfrom
dtorop:color-picker-improvements-post-9835

Conversation

@dtorop

@dtorop dtorop commented Sep 3, 2021 •

Copy link
Copy Markdown
Contributor

These are some improvements/fixes to the color picker code, meant as a follow-up to #9835.

User-visible changes:

  • When create a new point primary colorpicker, its center swatch could display black until it is moved or an iop is changed. The center swatch will now update once the preview pipe is completed.
  • When dragging a point picker, the cursor would flicker. This was because the code was trying to hide the cursor so that the the mouse would appear to be dragging the point picker as a "cursor". There's a bug somewhere which breaks this which I haven't yet found. As a compromise, the cursor stays on all the time now. The cursor for dragging a corner of the box picker is now a "fleur" cursor (four directional arrows). The cursor for dragging the point picker remains the left arrow cursor.
  • When switching between images or from/to darkroom view, the color picker would turn off, but the eyedropper widget would still be drawn as active. Now the eyedropper is drawn as inactive in this case.

Internal fixes:

  • Store picker results as an array of results by statistic type (mean/min/max). This folds together some quite-similar variables (e.g. picked_color_rgb_{mean,min,max}) and turns a bunch of switch statements by statistic into one line array lookups.
  • Don't raise a DT_SIGNAL_CONTROL_PICKERDATA_READY when the primary picker is changed. It's enough to catch DT_SIGNAL_DEVELOP_PREVIEW_PIPE_FINISHED.
  • Eliminate DT_LIB_COLORPICKER_SIZE_NONE as a picker state. Now pickers can either be point or box. An inactive picker is signified by darktable.lib->proxy.colorpicker.picker_proxy being NULL.
  • A separate path for primary and live sample picking depending on whether a box or a point sample, to make for minimal operations for point sample (as in this case mean/min/max are the same value).
  • Some other misc. minor fixups/tidying.

Go from pleasing compiler and producing potential NULL dereference to
just using a default on the default case. In reality the default case
should never happen.
If turn the primary colorpicker on after an image has loaded, it can
initially appears with a blank central swatch. This is because the
preview pipe is still executing when the center view is redrawn, and
there is no sample. To fix this, redraw the center view yet again once
the sample is calculated.

This should also guarantee that the sample swatch at the center of the
picker keeps up with most recent pixelpipe output.
Previously every time the center view was drawn the colorpicker widget
in the left panel would be redrawn. Now that
DT_SIGNAL_CONTROL_PICKERDATA_READY is raised when the primary picker
and live samples are recalculated, just use that signal as the cue to
redraw.
Previously the picker was turned off but the eyedropper widget may not
have been turned off.

Also dt_iop_color_picker_reset() now sets sample size to none. This
was done by hand in image change/leave code. It should be the right
thing to do this in general when the picker proxy is reset.
No need to test for non-NULL sample twice. Use extant pointer to
primary sample later in the function.
When iop picker is initally started, its swatch is blank due to a
recent commit. Fix so that the swatch has data.

Always update swatch and live samples in lib when receive signal that
the pixelpipe has done the primary picking, regardless of whether
sample area has changed -- this could have been a pixelpipe run due to
a change to an iop. Trigger redraw of center whenever we have new
point picker data.

Remove unneeded center view redraw. This presumably happens elsewhere
due to DT_SIGNAL_DEVELOP_PREVIEW_PIPE_FINISHED.
It's enough to catch DT_SIGNAL_DEVELOP_PREVIEW_PIPE_FINISHED and do
the updates needed there.

Also, make _iop_record_point_area() return whether the picker has been
changed, and only pay attention to that for iop pickers.
If the preview pipe is valid, we can trust the swatch, otherwise it is
stale.
There's a bug since c259208 that the cursor flickers on/off when
dragging the point picker. This is because it keeps re-appearing as a
GDK_LEFT_PTR then disappears when set to GDK_BLANK_CURSOR. This is
only with point samples.

I can't find the bug, but to work around, now only change the cursor
for a box sample. Use a GDK_CROSSHAIR in that case rather than
GDK_BLANK_CURSOR.

Also, invalidate the pixelpipe via dt_dev_invalidate_from_gui() if we
only need the primary picker and live samples, not an iop picker.
The current picker is off when
darktable.lib->proxy.colorpicker.picker_proxy is off. Don't double up
and expect the size of the primary picker to contain overlapping
information.

Also, in pixelpipe, iop sampler doesn't have to check if there is an
extant sample -- it won't be called if there isn't one.

Also reset the primary picker when gui_cleanup() for primary picker --
though presumably this only gets called on shutdown so isn't urgent.
Cursor reflects which corner is being dragged.

Change area cursor for initial area from crosshair to fleur.
Rather than separate arrays for each sort of picker result by
statistic, make one array for each indexed by statistic.

Allows for more succinct code.

Also now clamp hex values in label display to 00-FF, as negative hex
values in particular are confusing to display.
Just use GDK_FLEUR. Using cursors based on corners when dragging
corners doesn't make sense as they can cross center line and be
meaningless.
Make a typedef for a dt_aligned_pixel_t for each statistic
type (mean, max, min).

Then simplify the _pixelpipe_pick_from_image() used for primary picker
and live samples. Eliminates some temporary rgb/lab value
buffers. Also generally tidy this code.
So that won't do colorspace conversions mean/min/max when only need to
do one and copy over the rest. Eliminate temp variables in point
sample path. Use memcpy(), which may be slower than
for_each_channel().

This code may be slightly faster, but may be illegible in its
succinctness.

Fix bug where mean/min/max initializers for point sample were in wrong
order.

Clamp hex readout in tooltip to 0-255.
Remove _iop_ from proxy internal functions: As the color picker proxy
may work for iop or for the lib colorpicker. And as it sits in the gui
subdirectory. Don't change the public facing API, those, these still
are dt_iop_*.

When applying an iop color picker, we should always be in the preview
pipe, and hence piece->pipe == dev->preview_pipe. So don't need to
figure out dev from module -- saves one reference/test.

Note how when the preview pipe updates and hence the picker data
updates, that it appears that we don't need to redraw center view by
hand as the center view will redraw when preview pipe changes.

It makes sense to call the current sample primary_sample as it will
always be shown as the primary sample.

Leave in mouse move optimization to limit colorpicker calls -- it
actually is helpful.

Don't think about pulling new picker data from output_backbuf, which
is 8-bit rather than float.
Just set the preview pipe to dirty. These updates are fast. Don't need
optimization to detect if mouse moved past a preview pipe pixel, which
also is wrong for iops.

The dt_dev_invalidate_from_gui() path is slow -- remove it. Also
simplifes/clarifies the code.

Always draw a center swatch of picker, even if pixelpipe is invalid,
to avoid flickering.
@johnny-bit

Copy link
Copy Markdown
Member

0.o weird... the CI crashed on trying to run darktable-cli this is very very weird... I'll try testing this later today since I have no idea why would ci fail on that unless there's some additional problem.

@Mark-64

Mark-64 commented Sep 3, 2021 •

Copy link
Copy Markdown
Contributor

@dtorop I will test this PR as soon I have time.
In the meantime I have a question for you: it seems we have a problem of incorrect sampling or shift (see #9920). It is particularly evident when geometry manipulation modules like crop are active, but there seems to be a shift of few pixels even without those.
I couldn't figure out if the shift is real or it is just an effect of picker sampling the preview image.
The question is: could it be possible to sample the full image instead? That would at least imake easier to detect if we have a shift.

@dtorop

dtorop commented Sep 3, 2021

Copy link
Copy Markdown
Contributor Author

0.o weird... the CI crashed on trying to run darktable-cli this is very very weird... I'll try testing this later today since I have no idea why would ci fail on that unless there's some additional problem.

I tested and it crashed here as well. So that's why CI is helpful... I'll look into it...

could it be possible to sample the full image instead?

Wrote a note on #9920 about this...

If there's no GUI, darktable.lib will be NULL. Hence test for GUI
before dereferencing darktable.lib to see if there's an active picker
widget.
@TurboGit
TurboGit self-requested a review September 3, 2021 17:45
@TurboGit TurboGit added this to the 3.8 milestone Sep 3, 2021
@TurboGit TurboGit added bugfix pull request fixing a bug feature: enhancement current features to improve labels Sep 3, 2021

@TurboGit TurboGit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks !

@TurboGit
TurboGit merged commit 014b447 into darktable-org:master Sep 3, 2021
@johnny-bit

Copy link
Copy Markdown
Member

YAY for CI :D

@dtorop
dtorop deleted the color-picker-improvements-post-9835 branch September 3, 2021 21:54
@dtorop

dtorop commented Sep 3, 2021

Copy link
Copy Markdown
Contributor Author

Great! This should be the major part of tidying the color picker code.

Still possible to do:

  • Make dt_iop_module_t use lib_colorpicker_sample_statistics to store the picked colors. Could make some more code succinct/clear. It'd add another include to imageop.h, which is probably ok...?
  • Figure out why the mouse cursor changes back to left pointer when dragging the point sample. I know the commit which caused this, but it'll take some more time to sort this out. Then it should be possible to hide the cursor when dragging the point sample.
  • Maybe get rid of the DT_SIGNAL_CONTROL_PICKERDATA_READY signal entirely, and handle both the iop and final data on DT_SIGNAL_DEVELOP_PREVIEW_PIPE_FINISHED.

Probably a few other things, as always...

@TurboGit TurboGit added documentation: pending a documentation work is required release notes: pending labels Sep 5, 2021
@todd-prior

Copy link
Copy Markdown

@dtorop Dan what is the whole status on the processing of data from the working profile through the display profile to get to the histogram and hence provide the data for the pickers...is this still something that is being worked on to avoid the colorspace clipping introduced by the display profile in this pathway or have there been some changes introduced??

@elstoc elstoc removed the documentation: pending a documentation work is required label Oct 16, 2021
@dtorop

dtorop commented Nov 27, 2021

Copy link
Copy Markdown
Contributor Author

@dtorop Dan what is the whole status on the processing of data from the working profile through the display profile to get to the histogram and hence provide the data for the pickers.

@todd-prior Belatedly -- I haven't worked on this. My memory is that it'll take a bunch more work on colorout and module order to make this work. My guess is that if that display profile is unbounded, that the work -> display -> histogram conversion doesn't lose data, it just wastes a step and introduces a tiny error.

piratenpanda pushed a commit to piratenpanda/darktable that referenced this pull request Aug 23, 2026
…ements-post-9835

color picker: misc. improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix pull request fixing a bug feature: enhancement current features to improve

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants