Commit Graph

5774 Commits

Author SHA1 Message Date
53fdd19d84 app: simpler code with gegl_node_blit().
No need to go through an intermediate GeglBuffer when unneeded.

(cherry picked from commit c32b0ecc92)
2018-12-19 15:51:14 +01:00
b00580d4b1 app: add "line-art-max-grow" property to the bucket fill options.
When flooding the line art, we may overflood it in sample merge (which
would use color in the line art computation). And if having all colors
on the same layer, this would go over other colors (making the wrong
impression that the line art leaked).
This new option is mostly to keep some control over the mask growth.
Usually a few pixels is enough for most styles of drawing (though we
could technically allow for very wide strokes).

(cherry picked from commit eb042e6c87)
2018-12-19 15:48:47 +01:00
19c1f2654e app: properly (bucket) fill created splines and segments in line art.
For this, I needed distmap of the closed version of the line art (after
splines and segments are created). This will result in invisible stroke
borders added when flooding in the end. These invisible borders will
have a thickness of 0.0, which means that flooding will stop at once
after these single pixels are filled, which makes it quick, and is
perfect since created splines and segments are 1-pixel thick anyway.
Only downside is having to run "gegl:distance-transform" a second time,
but this still stays fast.

(cherry picked from commit 5a4754f32b)
2018-12-19 15:48:15 +01:00
e5bea42b6f app: replace gegl:watershed-transform with custom algorithm.
We don't really need to flow every line art pixel and this new
implementation is simpler (because we don't actually need over-featured
watershedding), and a lot lot faster, making the line art bucket fill
now very reactive.
For this, I am keeping the computed distance map, as well as local
thickness map around to be used when flooding the line art pixels
(basically I try to flood half the stroke thickness).

Note that there are still some issues with this new implementation as it
doesn't properly flood yet created (i.e. invisible) splines and
segments, and in particular the ones between 2 colored sections. I am
going to fix this next.

(cherry picked from commit 3467acf096)
2018-12-19 15:48:04 +01:00
2934293664 app: priority map now unneeded for gegl:watershed-transform.
This commit is based on GEGL master as I just made the auxiliary buffer
of gegl:watershed-transform optional for basic cases.
It doesn't necessarily makes the whole operation that much faster
according to my tests, but it makes the code simpler as creating this
priority map was quite unnecessary.

(cherry picked from commit 963eef8207)
2018-12-19 15:47:34 +01:00
Ell
3c0f1307cc app: add gimp_pickable_contiguous_region_prepare_line_art_async() ...
... and use in bucket-fill tool

Add gimp_pickable_contiguous_region_prepare_line_art_async(), which
computes a line-art asynchronously, and use it in the bucket-fill
tool, instead of having the tool create the async op.

This allows the async to keep running even after the pickable dies,
since we only need the pickable's buffer, and not the pickable
itself.  Previously, we reffed the pickable for the duration of the
async, but we could still segfault when unreffing it, if the
pickable was a drawable, and its parent image had already died.

Furthermore, let the async work on a copy of the pickable's buffer,
rather than the pickable's buffer directly.  This avoids some race
conditions when the pickable is the image (i.e., when "sample
merged" is active), since then we're using image projection's
buffer, which is generally unsafe to use in different threads
concurrently.

Also, s/! has_alpha/has_alpha/ when looking for transparent pixels,
and quit early, at least during this stage, if the async in
canceled.

(cherry picked from commit b4e12fbbbb)
2018-12-19 15:36:10 +01:00
a83bbf8249 app: end point detection uses both the end point rate and clamped value.
(cherry picked from commit 79571231c5)
2018-12-19 15:34:01 +01:00
4c3fcdb6bb app: better handle drawable and image update for line art computation.
The "update" signal on drawable or projection can actually be emitted
many times for a single painting event. Just add new signals ("painted"
on GimpDrawable and "rendered" on GimpProjection) which are emitted once
for a single update (from user point of view), at the end, after actual
rendering is done (i.e. after the various "update" signals).

Also better support the sample merge vs current drawable paths for
bucket fill.

(cherry picked from commit 047265333c)
2018-12-19 15:33:40 +01:00
6155889315 app: remove now useless erosion size option.
Since commit b00037b850, erosion size is not used anymore, as this step
has been removed, and the end point detection now uses local thickness
of strokes instead.

(cherry picked from commit 3f58a38574)
2018-12-19 15:33:28 +01:00
c1c544f882 app: improve end point detection for smart colorization.
Previous algorithm was relying on strokes of small radius to detect
points of interest. In order to work with various sizes of strokes, we
were computing an approximate median stroke thickness, then using this
median value to erode the binary line art.

Unfortunately this was not working that well for very fat strokes, and
also it was potentially opening holes in the line art. These holes were
usually filled back later during the spline and segment creations. Yet
it could not be totally assured, and we had some experience where color
filling would leak out of line art zones without any holes from the
start (which is the opposite of where this new feature is supposed to
go)!

This updated code computes instead some radius estimate for every border
point of strokes, and the detection of end points uses this information
of local thickness. Using local approximation is obviously much more
accurate than a single thickness approximation for the whole drawing,
while not making the processing slower (in particular since we got rid
of the quite expensive erosion step).
This fixes the aforementionned issues (i.e. work better with fat strokes
and do not create invisible holes in closed lines), and also is not
subject to the problem of mistakenly increasing median radius when you
color fill in sample merge mode (i.e. using also the color data in the
input)!
Also it is algorithmically less intensive, which is obviously very good.

This new version of the algorithm is a reimplementation in GIMP of new
code by Sébastien Fourey and David Tschumperlé, as a result of our many
discussions and tests with the previous algorithm.

Note that we had various tests, experiments and propositions to try and
improve these issues. Skeletonization was evoked, but would have been
most likely much slower. Simpler erosion based solely on local radius
was also a possibility but it may have created too much noise (skeleton
barbs), with high curvature, hence may have created too many new
artificial endpoints.
This new version also creates more endpoints though (and does not seem
to lose any previously detected endpoints), which may be a bit annoying
yet acceptable with the new bucket fill stroking interaction. In any
case, on simple examples, it seems to do the job quite well.

(cherry picked from commit b00037b850)
2018-12-19 15:32:58 +01:00
8fb83d7751 app: fix uninitialized variables.
(cherry picked from commit 255f2e1cdf)
2018-12-19 15:31:30 +01:00
6b1d7969ed app: edit the bucket fill tool options with new line art options.
I have not added all the options for this new tool yet, but this sets
the base. I also added a bit of TODO for several places where we need to
make it settable, in particular the fuzzy select tool, but also simply
PDB calls (this will need to be a PDB context settings.

Maybe also I will want to make some LineArtOptions struct in order not
to have infinite list of parameters to functions. And at some point, it
may also be worth splitting a bit process with other type of
selection/fill (since they barely share any settings anyway).

Finally I take the opportunity to document a little more the parameters
to gimp_lineart_close(), which can still be improved later (I should
have documented these straight away when I re-implemented this all from
G'Mic code, as I am a bit fuzzy on some details now and will need to
re-understand code).

(cherry picked from commit 824af12438)
2018-12-19 15:26:42 +01:00
808cdc9880 app: bucket fill tool with a "paint-style" interaction.
Rather than just having a click interaction, let's allow to "paint" with
the bucket fill. This is very useful for the new "line art" colorization
since it tends to over-segment the drawing. Therefore being able to
stroke through the canvas (rather than click, up, move, click, etc.)
makes the process much simpler. This is also faster since we don't have
to recompute the line art while a filling is in-progress.
Note that this new behavior is not only for the line art mode, but also
any other fill criterion, for which it can also be useful.

Last change of behavior as a side effect: it is possible to cancel the
tool changes the usual GIMP way (for instance by right clicking when
releasing the mouse button).

(cherry picked from commit e1c4050617)
2018-12-19 15:26:42 +01:00
32f0a49ecc app: compute line art in advance.
Right now, this is mostly meaningless as it is still done sequentially.
But I am mostly preparing the field to pre-compute the line art as
background thread.

(cherry picked from commit f246f40494)
2018-12-19 15:26:38 +01:00
0cf524e351 app: fix line art labellization.
The older labelling based off CImg code was broken (probably because of
me, from my port). Anyway I realized what it was trying to do was too
generic, which is why we had to fix the result later (labeling all
non-stroke pixels as 0, etc.). Instead I just implemented a simpler
labelling and only look for stroke regions. It still over-label a bit
the painting but a lot less, and is much faster.

(cherry picked from commit 93a49951a0)
2018-12-19 15:20:19 +01:00
4da35468bc app: better use GeglBufferIterator!
I don't actually need to loop through borders first. This is what the
abyss policy is for, and I can simply check the iterator position to
verify I am within buffer boundaries or not.
This simplifies the code a lot.

(cherry picked from commit c4ff81540d)
2018-12-19 15:20:19 +01:00
8557cd8cfb app: directly update the mask buffer with gegl_node_blit_buffer().
No need to create a temporary buffer for this.

(cherry picked from commit f02993fb9c)
2018-12-19 15:20:18 +01:00
8dc6bcafa3 app: create a simple priority map for line art selection flooding.
We actually don't need to compute distance map. I just make the simplest
priority map, with 1 any line art pixel and 0 any other pixel (in mask
or not), lowest priority being propagated first.
And let the flooding begin!

(cherry picked from commit 410c747509)
2018-12-19 15:20:18 +01:00
687d058416 app: with recent gegl:watershed-transform, no need for intermediate...
... labels buffer.
We can watershed directly the mask buffer being correctly flagged.
This commit relies on merge request gegl!8 being accepted and merged.

(cherry picked from commit e905ea7ba2)
2018-12-19 15:20:18 +01:00
3b0a312e7e app: use char array for temporary data (rather than a GEGL buffer).
Also use more GeglBufferIterator on input GEGL buffer.
Using a char array is much less expensive and accelerated the line
erosion a lot!
Moving to GeglBufferIterator is not finished, but I do in steps.

(cherry picked from commit 0c80f8a718)
2018-12-19 15:20:17 +01:00
325398fcf9 app: use simpler allocated variables.
Allocating double-level arrays is just very inefficient.

(cherry picked from commit f975f15ec0)
2018-12-19 15:18:22 +01:00
95bbb26252 app: make visited into single-level allocated array.
(cherry picked from commit f19181dcf8)
2018-12-19 15:18:21 +01:00
71ec6a9849 app: fix stroke labels in gimp_lineart_estimate_stroke_width().
I must make sure that stroke pixels are labelled 0 and non-stroke other
than 0.

(cherry picked from commit 910d7934f5)
2018-12-19 15:18:21 +01:00
b1a3792aae app: use more GeglBufferIterator.
In this case, it makes the code a bit more messy, but hopefully more
efficient.

(cherry picked from commit 1822ea399a)
2018-12-19 15:18:21 +01:00
6dbd12a915 app: use GeglBufferIterator rather than gegl_buffer_sample|set().
(cherry picked from commit 041a8f1eec)
2018-12-19 15:18:20 +01:00
13466ba7e7 app: babl types returned by choose_format() must be float!
(cherry picked from commit fcd038eb16)
2018-12-19 15:18:20 +01:00
239be8ecc8 app: implement second step for line art selection/filling.
When filling colors in line arts, you don't want to leave space between
the strokes and the color, which usually happen with any of the current
selection methods.
A "KISS" trick is usually to grow your selection a few pixels before
filling (adding an additional step in colorization process), which
obviously does not handle all cases (depending on drawing style and
stroke size, you may need to grow more or less) as it doesn't take into
account actual stroke geometry.

Instead, I label the selection and the "rest" differently and leave the
pixel strokes unlabelled. Then I let these unlabelled pixels be flooded
by the "gegl:watershed-transform" operation.
Note that this second step is different from the second step from the
GREYC research paper, as they use their own watershed algorithm taking
color spots as sources to color the whole image at once. This is a
different workflow from the one using bucket fill with a single color
source.

(cherry picked from commit 8502b4e743)
2018-12-19 15:18:20 +01:00
bde56bdfdc app, libgimpbase: add GIMP_SELECT_CRITERION_LINE_ART selection type.
This commit implements part of the research paper "A Fast and Efficient
Semi-guided Algorithm for Flat Coloring Line-arts" from the GREYC (the
people from G'Mic). It is meant to select regions from drawn sketchs in
a "smart" way, in particular it tries to close non-perfectly closed
regions, which is a common headache for digital painters and colorists.

The implementation is not finished as it needs some watersheding as well
so that the selected area does not leave "holes" near stroke borders.
The research paper proposes a new watersheding algorithm, but I may not
have to implement it, as it is more focused on automatic colorization
with prepared spots (instead of bucket fill-type interaction).

This will be used in particular with the fuzzy select and bucket fill
tools.

Note that this first version is a bit slow once we get to big images,
but I hope to be able to optimize this.
Also no options from the algorithm are made available in the GUI yet.

(cherry picked from commit 8ed12b1b98)
2018-12-19 15:18:19 +01:00
48e14ef3b9 app, libgimpconfig: make various usage of g_file_replace() safer.
When an error occurs, we want to prevent overwriting any previous
version of the file by incomplete contents. So run
g_output_stream_close() with a cancelled GCancellable to do so.
See also discussion in #2565.

(cherry picked from commit 613bf7c5ab)
2018-12-07 00:51:05 +01:00
Ell
61a181933c app: in GimpProjection, fix reinit. of current row when chunk height changes
In GimpProjection's chunk renderer, when the chunk height changes
in the middle of a row, we need to merge the remainder of the
current render area back into the renderer's update region, and
refetch the remainder of the row as the new render area, so that we
don't miss any unrendered area, or re-render already-rendered area,
due to the change in chunk height.  However, we should previously
fail to verify that the fetched area is, in fact, the remainder of
the current row, which could cause us to render the wrong area,
missing parts of the update region.

Fix this, by breaking up some of the chunk-renderer fucntions into
smaller sub-functions, and using those in order to explicitly set
the new render area to the remainder of the current row when the
chunk height changes.  This also avoids erroneously merging the
unflushed update region of the projection into the renderer's
update region.

(cherry picked from commit c9c2397b0d)
2018-12-06 08:51:04 -05:00
Ell
09863478db Revert "app: save images with fractional grid coordinates as version-10 XCFs"
Actually, image grids are saved as parasites, so even though older
GIMP versions round their coordinates upon loading, they maintain
the fractional coordinates when re-saving the image, hence bumping
the XCF version is not really necessary.

This reverts commit 13119efda33a7aba323dc13e6a56207a15a9f000.

(cherry picked from commit 411ddb7e48)
2018-12-05 13:52:56 -05:00
Ell
6ca294abe0 app: save images with fractional grid coordinates as version-10 XCFs
Fractional-coordinate support for image grids was added in commit
1572bccc9f, right before the
introduction of XCF version 10.  While images with fractional grid
coordinates can be loaded with earilier versions of GIMP, the grid
coordinates are rounded to the nearest integer.

Bump the minimal XCF version when saving images with fractional
grid coordinates to 10, which should have been the case all along.

(cherry picked from commit a90322278d)
2018-12-05 13:33:42 -05:00
Ell
fa74fe78f9 app: don't use direct-buffer fill when some components are masked
(cherry picked from commit 83250eb57c)
2018-12-03 09:54:18 -05:00
Ell
5b857dbb4b libgimpcolor, app, modules, plug-ins: remove GEGL_ITERATOR2 define
... it's no longer needed, since GEGL commit
gegl@9dcd2cde63f95a080bf16a58c10e9ffbdd99aace.

Partially reverts commits:

6fca9959c7
cc10af72cc
49c53568d7
8edbc0d491
29f63616d2
3a2014984d
ee48ec6877
4165a315d5
764085278f
b7633c722e
6ab12061b7
754a3c5b18
22b4b647bd
55b3438328
c6d23add65
f03a84d607
822f9f0d2b
95358ca1fa
cdda37f4ee
41e8035635
6761da42b2
fb5d7832a8
97ed7817d8
46e9036578
ea9c5e6a49
24fbdfb591
beb4ecb238
4b77831e03
fcf113a39c
567ffe94ff

(cherry picked from commit 053e5edc93)
2018-12-02 11:21:36 -05:00
Ell
edbda43028 app: add "direct" parameter to gimp_projection_flush_now()
Add a boolean "direct" parameter to gimp_projection_flush_now(),
which specifies if the projection buffer should only be invalidated
(FALSE), or rendered directly (TRUE).

Pass TRUE when flushing the projection during painting, so that the
affected regions are rendered in a single step, instead of tile-by-
tile.  We previously only invalidated the projection buffer, but
since we synchronously flush the display right after that, the
invalidated regions would still get rendered, albeit less
efficiently.

Likewise, pass TRUE when benchmarking the projection through the
debug action, and avoid flushing the display, to more accurately
measure the render time.

(cherry picked from commit dac9bfe334)
2018-12-02 10:15:36 -05:00
Ell
98bf8319b6 app: another fix to drawable direct-fill criterion
Don't use a direct-buffer fill when filling using a pattern with
alpha, even when the mode is subtractive.

(cherry picked from commit 42b82419b1)
2018-12-02 03:43:28 -05:00
Ell
61b1e7a348 app: fix drawable direct-fill criterion
Don't use a direct-buffer fill if the mode is subtractive, and the
composite region includes the source.  Currently, this never
actually happens.

(cherry picked from commit 660f53d300)
2018-12-02 03:34:02 -05:00
Ell
8a131e97f1 app: optimize simple whole-drawable fill/clear
In gimp_drawable_edit_fill(), when filling/clearing the whole
drawable, without any special compositing (i.e., when there's no
selection, the opacity is 100%, and the layer mode is trivial),
fill/clear the drawable's buffer directly, without using an
applicator.  This makes such operations much faster, especially in
big images.

(cherry picked from commit dd8268c0a2)
2018-12-02 03:11:22 -05:00
Ell
5d536afded app: add gimp_fill_options_fill_buffer()
... which is similar to gimp_fill_options_create_buffer(), however,
it fills an existing buffer, instead of creating a new buffer.

Implement gimp_fill_options_create_buffer() in terms of the new
function.

(cherry picked from commit 45fc4cb4f9)
2018-12-02 03:11:21 -05:00
Ell
782d54a615 app: align drawable undo rectangle to tile grid
When creating a drawable undo from the drawable's buffer, align the
copied rectangle to the buffer's tile grid, so that all the copied
tiles are COWed, saving memory and gaining speed.

Add applied_x and applied_y fields to GimpDrawableUndo, specifying
the position at which to apply the applied_buffer, so that we apply
it in the right place, even if the undo rect has changed due to
alignment.

(cherry picked from commit bb9dd049fb)
2018-12-02 03:11:19 -05:00
Ell
0568490929 app: a few improvements to gimp-scratch
Simplify code a bit, and add branch-prediction annotations.

(cherry picked from commit f27b38808f)
2018-12-01 10:04:22 -05:00
Ell
806db2e64c app: #include <string.h> in gimp-scratch.h
... for memset().

(cherry picked from commit 8c9eb1c743)
2018-12-01 06:06:30 -05:00
Ell
59a3b9e5c0 app: fix definition signature of gimp_scratch_get_total()
(cherry picked from commit 5d1a79a34f)
2018-12-01 05:58:14 -05:00
Ell
c3ce696ce0 app: add scratch-total variable to the dashboard
Add a scratch-total variable to the dashboard's misc group, showing
the total amount of memory used by the scratch allocator.

(cherry picked from commit 698d1af798)
2018-12-01 05:55:24 -05:00
Ell
8593eb88fd app: add gimp-scratch allocator
gimp-scratch is a fast memory allocator (on the order of magnitude
of alloca()), suitable for small (up to a few megabytes), short-
lived (usually, bound to the current stack-frame) allocations.
Unlike alloca(), gimp-scratch doesn't use the stack, and is
therefore safer, and will also serve bigger requests, by falling-
back to malloc().

The allocator itself is very simple:  We keep a per-thread stack of
cached memory blocks (allocated using the normal allocator).  When
serving an allocation request, we simply pop the top block off the
stack, and return it. If the block is too small, we replace it with
a big-enough block.  When the block is freed, we push it back to
the top of the stack (note that even though each thread uses a
separate stack, blocks can be migrated between threads, i.e.,
allocated on one thread, and freed on another thread, although this
is not really an intended usage pattern.)  The idea is that the
stacks will ultimately stabalize to contain blocks that can serve
all the encountered allocation patterns, without needing to reisze
any of the blocks; as a consequence, the amount of scratch memory
allocated at any given time should really be kept to a minimum.

(cherry picked from commit a8a8655285)
2018-12-01 05:55:23 -05:00
Ell
d86d017980 app: in GimpBacktrace Linux backend, don't leak backtrace when dropping threads
Should have been part of commit
a29d040db5.

(cherry picked from commit 01f9409902)
2018-12-01 04:33:48 -05:00
Ell
31acea2cf7 app: in GimpBacktrace Linux backend, make blacklisted_thread_names const
(cherry picked from commit c749097dcc)
2018-12-01 03:52:36 -05:00
Ell
34cb63a048 app: add gimp_async_add_callback_for_object()
... which is similar to gimp_async_add_callback(), taking an
additional GObject argument.  The object is kept alive for the
duration of the callback, and the callback is automatically removed
when the object is destroyed (if it hasn't been already called).

This is analogous to g_signal_connect_object(), compared to
g_signal_connect().

(cherry picked from commit 49fd2847ac)
2018-11-30 04:15:44 -05:00
Ell
9001d65804 app: unref async when removing last callback if idle is pending
In gimp_async_remove_callback(), if removing the last callback
while the callback idle-source is already pending, cancel the idle
source and unref the async object (the async is reffed when adding
the idle source.)

(cherry picked from commit a779dd3849)
2018-11-30 04:15:44 -05:00
Ell
378dc07c7b app: use gimp_tile_handler_validate_validate() in GimpProjection
Use gimp_tile_handler_validate_validate(), added in the last
commit, in GimpProjection, in order to render the projection,
instead of separately invalidating the buffer, undoing the
invalidation, and then rendering the graph.  This is more
efficient, and more idiomatic.

(cherry picked from commit d6f0ca5531)
2018-11-28 13:27:00 -05:00