Commit Graph

5086 Commits

Author SHA1 Message Date
Ell 35b0f6102e app: update group-layer item offset after updating offset node
When the group's offset changes, update the item's offset *after*
updating the group's offset node, so that the item's offset nodes
and the group's offset node are in sync when the corresponding
"notify" signals are emitted.
2017-11-24 12:34:25 -05:00
Tobias Stoeckmann 30d29e03f8 Bug 789614 - Fix heap overflow in pattern handling
It is possible to trigger a heap overflow while opening a malicious
pattern due to integer overflows.

The validation is adopted from plugin-parser. It also takes a proper
cast to gsize to avoid integer overflow in size calculation.
2017-11-20 23:10:36 +01:00
Michael Natterer 7e613516a2 Bug 788403 - When importing an image, don't change to "untitled"...
...after exporting the image

Call gimp_image_name_changed() in both gimp_image_clean_all() and
gimp_image_export_clean_all() so we clear the cached displayed URI in
all cases, even if this means we're emitting "name-changed"
redundantly some times.
2017-11-19 19:21:15 +01:00
Ell e19958c5f1 app: use SAFE_CLAMP() in histogram bin calculation
The current code relies on undefined behavior, which, while seems
to work, is fragile.  Use SAFE_CLAMP() instead.
2017-11-19 07:13:24 -05:00
Ell 6036217d20 app: improve elimination of trivial blend-tool edit actions
... from the undo stack

When a blend-tool edit action modifies the gradient, do a deep
comparison of the original gradient against the current gradient,
to test if anything changed, instead of just assuming that
something did change.
2017-11-16 11:55:13 -05:00
Michael Natterer 19a28cc709 Revert "app: do not add undo step when clearing an already empty channel."
This reverts commit 9c94072213.

Such things do not belong into the core but into the GUI.
2017-11-12 23:42:43 +01:00
Michael Natterer f12d0d8c29 Bug 789764 - Please add Paste In Place feature
Add "In Place" variants for all sorts of pasting:

- extend the GimpPasteType enum with IN_PLACE values
- add the needed actions and menu items
- merge the action callbacks into one, taking an enum value as parameter
- refactor the pasting code in gimp-edit.c into smaller functions

We probably have too menu items in the "Edit" menu now, needs to be
sorted out.
2017-11-12 18:41:05 +01:00
Ell 4ded26c4f1 app: update group layer offset before calling gimp_pickable_flush()
In gimp_group_layer_update_size(), when the layer's bounds have
changed, update the group layer's offset before the call to
gimp_pickable_flush() when reallocating the projection.  Otherwise,
if the group layer's graph isn't constructed yet, it will get
constructed during the call to gimp_pickable_flush(), however,
gimp_group_layer_get_graph() will pick up the old coordinates for
the offset node.
2017-11-11 17:51:02 -05:00
Ell c49a21d95c app: improve histogram bin calculation
A fix to last commit: map values greater than G_MAXINT to the top
bin, not the bottom bin.
2017-11-08 04:58:04 -05:00
Ell b2b6552f1f Bug 788394 - Crash (segmentation fault) when calculating a histogram ...
... upon NaN values

Make the histogram bin calculation NaN-safe, by mapping NaNs to 0.
Ideally, NaNs should probably not be counted at all, but since we
already count negative values as 0, and > 1 values as 1, we might
as well not pessimize performance over it, at least until we add
support for unbounded histograms.

At the same time, improve rounding in the bin calculation, so that
the result is more accurate.
2017-11-07 18:21:31 -05:00
Ell bc9f179edf app: add gimp_data_is_{copyable,duplicatable}() to gimp_data.h
Forgot to add it to last commit :P
2017-11-04 22:13:31 -04:00
Ell 2fe6575d7e Bug 789901 - Gimp allows duplicating non-duplicatable data objects ...
... leading to a crash

Add gimp_data_is_copyable() and gimp_data_is_dulicatable().

Use gimp_data_is_duplicatable() when setting the sensitivity of the
various "foo-duplicate" actions, instead of inspecting the object's
GimpDataClass::duplicate pointer directly, since this is no longer
an indication of whether a GimpData object is duplicatable or not
(since commit 33de4d5530).
2017-11-04 22:00:29 -04:00
Ell 089bfe4e3d app: copy brush spacing when copying generated brushes
When copying a generated brush, copy its "spacing" property, in
addition to the other properties, which hasn't been previously
copied by ::duplicate().
2017-11-04 22:00:29 -04:00
Ell 880d3bd182 app: port GimpData subclasses from ::duplicate() to ::copy()
Finish up commit 17583ff04a, which
ported GimpGradient from ::duplicate() to ::copy(), by doing the
same for the rest of the GimpData subclasses that implement
::duplicate().

We still keep GimpData's ::duplicate() virtual function around,
even though it now points to the default implementation (which uses
::copy()) for all subclasses, since ::copy() is stronger than
::duplicate(), and we might want to have certain GimpData types
that are duplicatable, but not copyable.
2017-11-04 22:00:29 -04:00
Ell bccef43049 app, pdb: prevent custom gradient from being renamed
Make internal data objects non-renamable, even if they're writable,
through gimp_data_is_name_editable().  Currently, the only such
object is the custom gradient.

Prevent changing the name of non-renamable data by making the name
entry of GimpDataEditor non-editable whenever
gimp_viewable_is_name_editable() is FALSE, even if the data is
otherwise editable.

Prevent the vairous PDB -rename() functions from renaming non-
renamable data, by adding a GimpPDBDataAccess flags type,
specifying the desired access mode for the data -- any combination
of READ, WRITE, and RENAME -- and replacing the 'writable'
parameter of the gimp_pdb_get_foo() functions with an 'access'
parameter.  Change the various .pdb files to use READ where they'd
used FALSE, and WRITE where they'd used TRUE; use RENAME, isntead
of WRITE, in the -rename() functions.
2017-10-30 17:22:29 -04:00
Ell 9eb75cde00 app: use G_FILE_CREATE_NONE for saved internal data files
Use G_FILE_CREATE_NONE, instead of G_FILE_CREATE_REPLACE_DESTINATION,
when saving internal data files, for consistency with the other files
we save.
2017-10-30 07:40:53 -04:00
Ell e4440e3fdb app: save custom gradient across sessions
Add a framework for saving and restoring internal data objects, in
gimp-internal-data.c.  Internal data objects are saved in separate
files under a new "internal-data" subdirectory of the user's gimp
directory.  The internal data is saved, restored, and cleared
together with the tool options.

Use this to save and restore the custom gradient.  In the future,
we might add similar writable internal data objects that we'd want
to save.
2017-10-29 10:19:07 -04:00
Ell 3b15ff5d30 app: convert bg color to image color space when removing alpha
When removing a layer's alpha channel, convert the background color
from sRGB to the image color space before compositing the layer on
top of it.
2017-10-24 14:35:05 -04:00
Ell d027a059ef app: respond to viewable expanded state changes in container views
Add an "expanded-changed" signal to GimpViewable, which should be
emitted by subclasses when the viewable's expanded state changes.
Emit this signal when the expanded state of group layers changes.
Respond to this signal in GimpContainerView, by calling a new
expand_item() virtual function.  Implement expand_item() in
GimpContainerTreeView, expanding or collapsing the item as
necessary.
2017-10-22 12:30:21 -04:00
Ell 0c305bdb0f app: use the layer's composite space when flattening it
Add a composite_space parameter to gimp_gegl_create_flatten_node()
and gimp_gegl_apply_flatten(), which controld the color space --
linear or perceptual RGB -- used for the operation (instead of
hardcoding it to linear).

When removing a layer's alpha channel, use the layer's composite
space for the flattening.  When flattening an image, use the bottom
layer's composite space.  Keep using linear space when creating a
channel or a mask from a drawable with alpha.
2017-10-21 11:44:27 -04:00
Ell 96efde0f22 app: add gimp_layer_get_real_{blend,composite}_{space,mode}()
... which return the layer's blend/composite space/mode.  However,
unlike the non-"_real" versions, these functions never return AUTO
-- instead, they return the actual space/mode that AUTO maps to for
the current layer mode.

When changing a layer's blend/composite space/mode, avoid
updating the drawable if the real space/mode didn't change (i.e.,
if changing from AUTO to the concrete value, or vice versa.)
2017-10-21 11:42:39 -04:00
Ell 8d12fada8a app: implement blend tool gui for gradient endpoints
Allows setting the endpoint's position, its color, and its color
type.
2017-10-09 12:48:55 -04:00
Ell 1f3030eb41 app: improve curved gradient segment sampling
Improve the sampling performance of curved gradient segments, and
its behavior when the segment's midpoint is close to one of its
limits.
2017-10-09 12:48:52 -04:00
Ell 1b2a395e88 app: improve num. stability of gimp_gradient_segment_range_compress()
When using gimp_gradient_segment_range_compress() to expand a 0-
length segment, redistribute the range's endpoints and midpoints
uniformly, rather than using the regular code path, which would
result in NaN values.

Make sure that the left and right endpoints of the range are
*exactly* equal to the new left and right values.  Previously,
they could be slightly off due to numerical errors.
2017-10-09 12:48:52 -04:00
Ell 3aff0a1a0e app: treat gradient segments as clopen ranges
Treat gradient segment exents as [left, right) ranges, instead of
[left, right], so that they don't overlap, and each point
corresponds to a unique color.

Perform less comparisons in gimp_gradient_get_segment_at_internal().
2017-10-09 12:48:52 -04:00
Ell d710773aba app: add gimp_gradient_segment_range_merge()
... which merges a segment range into a single segment, that spans
the entire range, and has the same endpoint colors.  The merged
segment's midpoint is at its center, and its blend function and
coloring type are those of the range's segments if they're uniform,
or the default ones otherwise.
2017-10-09 12:48:51 -04:00
Ell 082f6a4122 app: add gimp_gradient_segment_range_get_n_segments()
... which returns the number of segments in a range.
2017-10-09 12:48:51 -04:00
Ell c5faf02759 app: add gimp_gradient_split_at()
... which splits a gradient segment at an arbitrary position.

Implement gimp_gradient_segment_split_midpoint() in terms of the new
function.
2017-10-09 12:48:51 -04:00
Ell 6840dabad4 app: add gimp_gradient_segment_get_{left,right}_flat_color()
... which returns the flat (context-independent) left and right
colors of a egment.  Replace code that calculates the flat color
explicitly with calls to these functions.
2017-10-09 12:48:51 -04:00
Ell 6971b89397 app: implement compare() for GimpGradient
Order the custom gradient before all the other gradients, and use
the default ordering for the rest.
2017-10-09 12:48:51 -04:00
Ell 17583ff04a app: implement copy() for GimpGradient
... instead of duplicate().
2017-10-09 12:48:51 -04:00
Ell 2ad9f40dbe app: add "custom" gradient
An internal gradient object, that will be used by the blend tool
when editing a gradient.  By default, the active gradient will not
be edited directly, but rather, upon editing, the active gradient's
contents will be copied to the custom gradient, which will then
become the active gradient and be edited.  This allows editing both
writable and nonwritable gradients without modifying them, and
without having to duplicate them.
2017-10-09 12:48:50 -04:00
Ell f36f234fc0 app: add compare() virtual function to GimpData
... which subclasses can override to refine comparison.  Provide a
default implementation that uses the current logic.
2017-10-09 12:48:50 -04:00
Ell 33de4d5530 app: add gimp_data_copy()
... which copies the contents of a GimpData into an existing GimpData,
without creating a new instance.

Add a copy() virtual function to GimpData, which subclasses can
override to implement copying; gimp_data_copy() may only be called
for types that implement copy().  Keep the duplicate() virtual
function around, but provide a default implementation that creates
a new object of the source type, and uses copy() to copy the source
object into it.
2017-10-09 12:48:50 -04:00
Ell 9e26d7ea5f app: add handle-clicked signal to GimpToolLine
... which is emitted when a handle is single/double/tripple clicked.

The signal handler returns a boolean value.  A return value of TRUE
stops further event processing, while a return value of FALSE allows
it.
2017-10-09 12:48:50 -04:00
Ell 50acb6690d app: add prepare-to-remove-slider signal to GimpToolLine
The signal is emitted when a slider is dragged away from the line,
and will be removed when the button is released, and when the
slider is dragged back to the vicinity of the line, and won't be
removed.  The last parameter of the signal is a boolean flag
differentiating between the two cases.

Note that a remove-slider signal may be emitted without a preceeding
prepare-to-remove-slider signal, however, is a prepare-to-remove-
slider signal is emitted with a TRUE last parameter, it must be
eventually followed by a remove-slider signal, or by another
prepare-to-remove-slider signal with a FALSE last parameter.
2017-10-09 12:48:49 -04:00
Ell bac7dac4ba app: allow adding and removing sliders to/from a GimpToolLine
Add support for adding and removing sliders to/from a GimpToolLine,
using three new signals:

  - can-add-slider:  Takes a double argument in the range [0,1],
    indicating a location along the line, and returns a boolean
    value, indicating whether a slider can be added at that
    location.

  - add-slider:  Takes a double argument in the range [0,1],
    indicating a location along the line, for which can-add-slider
    returned TRUE.  In response, should add a new slider at that
    location, and return its index, or a negative value if no
    slider was added.

  - remove-slider:  Takes a slider index.  In response, may remove
    the slider.

On the UI side, when the cursor is close enough to the line, but
not within the hit area of an existing handle, GimpToolLine checks
if a slider can be added at the cursor position, using can-add-
slider.  If a slider can be added, a dashed circle appears at the
cursor position along the line, indicating where a slider will be
added.  The cursor is added by clicking, which emits an add-slider
signal; if the signal returns a slider index, the new slider is
selected, and can be subsequently dragged.

Removing a slider is done by either selecting the slider and
pressing backspace (or delete, although we don't actually forward
it to the tool atm,) or by "tearing" the slider: when dragging
the slider, if the cursor is far enough from the liner, a dashed
circle appears around the slider, and releasing the mouse removes
the slider.
2017-10-09 12:48:49 -04:00
Michael Natterer ebbcaddae7 app: enable XCF version 12 which finally saves big-endian tile data only 2017-10-01 17:28:20 +02:00
Michael Natterer 6dfe04e928 Bug 787848 - Duplicate image crashes if there is an empty layer group
An empty gorup layer has no extent, so we fake its extents to be at
least 1x1 whenever its projection is being recreated, because we can't
have a 0x0 buffer in a drawable. This safeguard was forgotten in
gimp_group_layer_convert_type() which gets called on image duplicate.
2017-09-18 20:31:21 +02:00
Jehan 9c94072213 app: do not add undo step when clearing an already empty channel.
See also bug 787545 about single-clicking with a selection tool creating
an undo step even when there were already no selections.
2017-09-13 13:02:00 +02:00
Michael Natterer c63d812be8 libgimpcolor: rename gimp_color_profile_get_format() to _get_lcms_format() 2017-09-02 18:47:04 +02:00
Ell 0ef3795f0a */Makefile.am: work around a bug in the new glib-genmarshal
glib-genmarshal was rewritten in glib 2.53.4, and as of now (2.53.6)
it has a bug where it unconditionally generates marshaler bodies,
even for standard marshalers, even with --stdinc.  This causes
libgimpwidgets to define and export g_cclosure_marshal_VOID__INT()
and g_cclosure_marshal_VOID__OBJECT(), which upsets defcheck, and
breaks the build.

Work around this for now by using --header --body when generating
the marshal.c files, which includes the prototypes in the source,
instead of including the header ourselves.  This is the only code
path where the new glib-genmarshal doesn't generate bodies for
standard marshalers.  Note, however, that this usage is deprecated,
so we'll probably want to change it back once it's fixed.
2017-08-27 15:33:09 -04:00
Ell 58fdaae3ad enums: add intermediate generated enum files to .gitignore 2017-08-24 15:35:27 -04:00
Michael Natterer e16c8a2352 Move the new "default_new_layer_mode" APIs to the image...
...in both the core and libgimp.

Images now know what the default mode for new layers is:

- NORMAL for empty images
- NORMAL for images with any non-legacy layer
- NORMAL_LEGAVY for images with only legacy layers

This changes behavior when layers are created from the UI, but *also*
when created by plug-ins (yes there is a compat issue here):

- Most (all?) single-layer file importers now create NORMAL layers
- Screenshot, Webpage etc also create NORMAL layers

Scripts that create images from scratch (logos etc) should not be
affected because they usually have NORMAL_LEGACY hardcoded.

3rd party plug-ins and scripts will also behave old-style unless they
get ported to gimp_image_get_default_new_layer_mode().
2017-08-21 20:18:00 +02:00
Michael Natterer 7ce77c47cc app: stop hardcoding NORMAL_LEGACY for new layers/images
Use GimpCoreConfig::default-new-layer-mode instead.
2017-08-20 15:02:46 +02:00
Michael Natterer b89d10a830 app: fix compositing of non-LEGACY layers in "show mask" mode
gimp_layer_update_mode_node(): when showing the mask, set mode to
NORMAL, and make sure that the composite space is PERCEPTUAL for
LEGACY layers, and LINEAR (or whatever is chosen in layer attibutes)
otherwise.
2017-08-20 14:09:35 +02:00
Michael Natterer 0cfe550639 app, pdb: change a lot of GIMP_LAYER_MODE_NORMAL_LEGACY to just NORMAL
this commit changes just those which make no difference to
functionality: property and object member defaults that get overridden
anyway, return values of g_return_val_if_fail(), some other stuff.
2017-08-19 20:33:47 +02:00
Ell 67fc418c3c app: adapt gimp_image_merge_layers() to handle pass-through groups ...
... and fix flatten-image along the way.  *And* do some cleanup.

Currently, gimp_image_merge_layers() combines the layers on its own,
one by one.  This is incompatible with pass-through groups, because
the group's buffer is rendered independently of its backdrop, while
we need to take the backdrop into account when mergeing the group.

Instead, render the subgraph of the parent graph, corresponding to
the set of merged layers, directly into the new layer.  Since the
layers we merge are always visible and continuous, all we need is a
minor massage to the parent graph to make it work.  This takes care
of pass-through groups intrinsicly.

This commit also changes the behavior of flatten-image:  Currently,
the flattened layers are rendered directly on top of the opaque
background, which can make previously-hidden areas (due to layers
using composite modes other than src-over, or legacy layer modes)
visible.  This is almost certainly not desirable.

Instead, construct the graph such that the flattened layers are
combined with the background only after being merged with one
another.
2017-08-08 15:39:28 -04:00
Ell 3635cf04ab app: move bottom-layer special casing to GimpOperationLayerMode
GimpFilter's is_last_node field only reflects the item's position
within the parent stack.  When a layer is contained in a pass-
through group, it can be the last layer of the group, while not
being the last layer in the graph as a whole (paticularly, if
there are visible layers below the group).  In fact, when we have
nested pass-through groups, whether or not a layer is the last
node depends on which group we're considering as the root (since
we exclude the backdrop from the group's projection, resulting in
different graphs for different groups).

Instead of rolling our own graph traversal, just move the relevant
logic to GimpOperationLayerMode, and let GEGL do the work for us.
At processing time, we can tell if we're the last node by checking
if we have any input.

For this to work, GimpOperationLayerMode's process() function needs
to have control over what's going on.  Replace the derived op
classes, which override process(), with a call to the layer mode's
function (as per gimp_layer_mode_get_function()) in
GimpOperationLayerMode's process() function.  (Well, actually, this
commit keeps the ops around, and just hacks around them in
gimp_layer_mode_get_operation(), because laziness :P)

Keep using the layer's is_last_node property to do the invalidation.
2017-08-08 15:39:28 -04:00
Ell 1ca1e15dd0 app: implement {begin,end}_render() for GimpGroupLayer
Use them to connect/disconnect the stack graph when the group is
in pass-through mode.
2017-08-08 15:39:28 -04:00