Commit Graph

3020 Commits

Author SHA1 Message Date
Rupert 91f7331125 libgimp: imagemetadata-save - static assert expr. not constant
Fixes #12588. depending on build parameters, the strlen()s weren't
necessarily considered constant.
Changed to use arrays + sizeof instead.
2024-12-29 22:01:30 +00:00
Jehan 61abcd7412 libgimp, plug-ins: update gimp_drawable_append_new_filter() signature.
Adding the mode and opacity arguments makes it very similar to
gimp_drawable_merge_new_filter() signature, but also to its own
Script-fu wrapper (gimp-drawable-append-new-filter).

It's just better to be consistent. Also if either of these args need to
be changed immediately afterwards, then we spare one additional
re-render for nothing (for instance in the PSD load plug-in!).
2024-12-23 15:35:10 +01:00
Øyvind Kolås 3f3b29ba12 app, libgimp, pdb: fix perceptual blend space for linear TRC ICC profiles
In previous versions what has been stored/specified as perceptual blending or
compositing spaces has really been the non-linear variant of the images babl
space.

To maintain loading of old files, the code has been updated to actually mean
non-linear and a new perceptual value has been added to the GimpLayerColorSpace
enum, while preserving all old enum values.

This change bumps XCF file version to 23
2024-12-19 23:23:50 +01:00
Jehan a6392ed84a app, libgimp, pdb, plug-ins: add a few Script-fu wrapper of libgimp filter API.
In particular (gimp-drawable-filter-configure),
(gimp-drawable-merge-filter) and (gimp-drawable-append-filter) are
proper Script-fu methods.

I had to rename the PDB procedures for the 2 latter because they were
clashing with these wrapper. I had not realized that private PDB
procedures are still visible by Script-fu. This is not so glop. :-/

Right now, it doesn't look so useful compared to the -new- one-liner
variant procedures. But it will make sense when I will add aux input C
procedure wrappers.
2024-12-17 16:24:54 +00:00
Jehan 6480ba2ad6 app, libgimp, pdb: new gimp_drawable_filter_set_aux_input() public API.
It is this way possible to set a drawable as auxiliary input to a filter
in C and GObject-Introspected bindings.

Note that such filters can only be merged, not appended
non-destructively for the time being.
2024-12-17 16:24:54 +00:00
Jehan 39c2b83746 libgimp: allow passing GeglParamSeed arguments from plug-ins.
In particular, I encountered some script-fu scripts calling some GEGL
ops with a seed, but this argument wouldn't be reproduced in the config
object. Technically it's just a uint. Let's just pass them as such.
2024-12-17 16:24:54 +00:00
Jehan f539f8fb62 app, libgimp, pdb, plug-ins: plug-in-c-astretch compat PDB proc removed.
For plug-in writers, here is how to replace it:

- (plug-in-c-astretch RUN-NONINTERACTIVE img drawable)
+ (gimp-drawable-merge-new-filter drawable "gegl:stretch-contrast" 0 LAYER-MODE-REPLACE 1.0 "keep-colors" FALSE)
2024-12-17 16:24:54 +00:00
Jehan e5134e67aa libgimp*, plug-ins: filter ID are now usable in script-fu.
Marshalled PDB procedures into script-fu can now convert a filter ID
into the proper object. For instance, here would be the code to append a
new gaussian blur filter to the drawable with ID 2 (with specific
settings), then making invisible:

```script-fu
(define filter (gimp-drawable-append-new-filter 2 "gegl:gaussian-blur" "hello" LAYER-MODE-COLOR-ERASE 1.0 "std-dev-x" 20 "abyss-policy" "none"))
(gimp-drawable-filter-set-visible filter FALSE)
(gimp-drawable-update 2 0 0 -1 -1)
```
2024-12-17 16:24:54 +00:00
Jehan 3da53852df app, libgimp, pdb: make sure default values of a filter's config are right.
When calling gimp_drawable_filter_get_config() the first time, we don't
want the config's properties to be at default values, but instead to be
set same as they are on core app.

On further calls though, we don't touch the values, because they may be
out-of-sync until the next call to gimp_drawable_filter_update().
2024-12-17 16:24:54 +00:00
Jehan 4c07529553 libgimp, pdb: gimp_drawable_(append|merge)_filter() run …
… gimp_drawable_filter_update() first.

Otherwise this is bug-prone. When people were to update the
configuration of the filter, they obviously intend this to be used when
appending/merging.
2024-12-17 16:24:54 +00:00
Jehan 58b11d9d98 app, extensions, libgimp: new convenient function gimp_drawable_merge_new_filter().
Also adding an example of using it in the C goat exercise, though I
leave it commented out because showing code for direct GEGL usage is
also of interest.

As a side update, I am adding proper support of the NULL or empty string
value for the filter name. In this case, the default human-readable
title of the operation will be used instead.
2024-12-17 16:24:54 +00:00
Jehan 0223694583 libgimp: C-utility gimp_drawable_append_new_filter().
Makes adding new filters a one-liner in C.
2024-12-17 16:24:54 +00:00
Jehan 57a8449646 app, libgimp, pdb: add gimp_drawable_merge_filter(). 2024-12-17 16:24:54 +00:00
Jehan b07a6986e0 app, libgimp, pdb: make GIMP_LAYER_MODE_REPLACE PDB-visible.
This is the actual default blend mode for filters so now that we have
API to set filters, this mode must be settable.
2024-12-17 16:24:54 +00:00
Jehan c310573021 app, libgimp, pdb: new gimp_drawable_filter_(g|s)et_blend_mode() and gimp_drawable_filter_(g|s)et_opacity().
Similarly to the config arguments, the set functions are not directly
calling core. Instead they are queuing changes until
gimp_drawable_filter_update() is run.
2024-12-17 16:24:54 +00:00
Jehan 1587a8ec54 app, libgimp, pdb: new libgimp functions gimp_drawable_filter_new() and gimp_drawable_append_filter(). 2024-12-17 16:24:54 +00:00
Jehan 7715a875e0 app, libgimp, pdb: new gimp_drawable_filter_update() public API.
It is now possible to sync the GimpDrawableFilterConfig with core.

Another (simpler on usage) possibility could have been to sync
automatically when a property is updated. But considering that some
filters can be quite slow to render (especially in real-life usage when
working on possibly very big files), and especially that on bindings
with no variable args, scripts will likely have to edit properties one
by one, it could make editing multiple properties very slow. Therefore
the chosen solution is that editing properties stay local on libgimp and
all changed properties are synced with core at once (with a frozen
render until the end for single computation) when calling
gimp_drawable_filter_update().
2024-12-17 16:24:54 +00:00
Jehan 2cf6b637e7 app, libgimp, pdb: new GimpDrawableFilterConfig class.
This is mostly an empty shell whose goal is to serve as base class for
specific dynamically generated per-operation subclasses, which will have
properties mimicking the arguments of the GEGL operation.

Most of the fundamental type args will just use the base GLib param spec
types instead of GEGL ones.

As a special case, the GeglParamEnum arguments are transformed into
GimpChoice param specs on libgimp side. The reason is that most of the
time, enum types are created within the scope of an operation code only
and cannot be properly reconstructed over the wire. I could just
transform these into an int type (which is mostly what is done in GEGL
right now when running an op with such arg), but GimpChoice allow much
nicer string-type args, which make much more semantic code. This class
was initially created for plug-ins, but it would work very well to run
GEGL ops on drawables. So let's do it.

Finally add a gimp_drawable_filter_get_config() to request the current
config of a filter.

Note that right now, we can't do much with this config object other than
observing an operation args and default values. Being able to update a
filter's settings will come up in further commits.
2024-12-17 16:24:54 +00:00
Jehan c49dec3416 app, libgimp, pdb: 4 new libgimp/PDB procedures for GimpDrawableFilter.
* gimp_drawable_filter_get_name
* gimp_drawable_filter_get_operation_name
* gimp_drawable_filter_get_visible
* gimp_drawable_filter_set_visible
2024-12-17 16:24:54 +00:00
Jehan 0c1da8f328 app, libgimp, pdb: new gimp_drawable_filter_delete() libgimp/PDB function. 2024-12-17 16:24:54 +00:00
Jehan 08362d1e7b app, libgimp, pdb: passing GimpDrawableFilter across the wire.
A few functions were added, but the main one is
gimp_drawable_get_filters() to request the list of filters applied
non-destructively on a drawable. We can't do much with these for the
time being, but this will come.
WIP.
2024-12-17 16:24:54 +00:00
Alx Sa 2770cce833 pdb, operations, tool: Replace GimpContext with GeglColor...
in gimp:offset filter.
Since gimp:offset is now an NDE filter,
always loading the background color from
context causes the color to change each
time the filter is redrawn. This is inconsistent
behavior.

This patch replaces the GimpContext
parameter with GeglColor, and updates
gimp_drawable_offset and related functions
to set the color directly. The libgimp version
loads the background color from context
and passes it on since the API is now
frozen.
2024-11-29 00:29:36 -05:00
Rupert 6c62856915 libgimp: avoid compiler warning in gimp_fix_xmp_tag() (#12127)
* compiler warned about terminating zero not copied
* removes all manual character counting
* static assert as a reminder that new string must be shorter, in case
  someone want to reuse the code with different strings
2024-11-20 17:30:30 +00:00
lloyd konneker 9e1d0d7642 PDB: improve doc string for gimp-image-reorder-item
Discuss requirements on args.

Discuss reordering in a group versus moving to top-level.
2024-11-19 09:21:09 -05:00
Alx Sa 8249151299 libgimp: Draw full gradient in GradientChooser button
When we converted to GeglColor arrays in 6327d1b3, we
didn't adjust the call to gimp_gradient_select_preview_draw ()
that still assumed we passed in 4 doubles per pixel instead
of 1 GeglColor. This patch removes the division operation so
that we see the full gradient in the chooser button.
2024-11-15 16:12:34 +00:00
Jehan 2559138931 libgimp*, pdb, plug-ins: remove deprecated GIMP_PRECISION_*_GAMMA.
These were the last deprecated values in libgimp AFAICS.
2024-11-03 20:18:52 +01:00
Jehan e9e7afa14f app, libgimp, pdb: removing gimp_fonts_get_by_name().
I realized it is redundant with gimp_fonts_get_list() which is a bit
more complicated to use but also more powerful. Let's see if we ever
need the simpler utility function in the future.
2024-11-03 17:45:10 +01:00
Jehan a7064a18c3 app, libgimp, pdb: renaming a few PDB functions.
- s/gimp_buffers_get_list/gimp_buffers_get_name_list/
- s/gimp_context_get_dynamics/gimp_context_get_dynamics_name/
- s/gimp_context_set_dynamics/gimp_context_set_dynamics_name/
- s/gimp_dynamics_get_list/gimp_dynamics_get_name_list/

Named buffers and dynamics don't have their own classes. Using
*_get_name_list() will make sure that *_get_list() is available so that
we have constant naming if we add the new types, even during the 3.0
series. Same for the gimp_context_*() functions.

Note that the buffer API in particular has a few more functions which
we'd like to be able to reuse (e.g. gimp_buffer_rename()) with a proper
type. But we'll probably name this type GimpNamedBuffer anyway
(GimpBuffer is too similarly-named with GeglBuffer IMO) so it will be
easy to create new API for the new type.

See also #12268.
2024-11-03 17:45:10 +01:00
Jehan 6541e4d8da app, libgimp, pdb: gimp_*_get_list() for various resource types return a resource array.
There are 2 *_get_list() for buffers and dynamics but since we don't
have clases for these, they still just return a list of names for now.
I opened #12268 for further thinking on these.
2024-11-03 17:45:10 +01:00
Jehan 5ed3bc33e0 app, libgimp, pdb: gimp_gradient_get_custom_samples() also returns an array of colors. 2024-11-03 13:35:16 +01:00
Jehan 6327d1b3ef app, libgimp, pdb, plug-ins: gimp_gradient_get_uniform_samples() returns an array of GeglColor. 2024-11-03 13:35:16 +01:00
Jehan dc3e815ff0 app, libgimp*, pdb, plug-ins: rename various public API name s/float/double/.
Several types functions were using the wording "float" historically to
mean double-precision, e.g. the float array type (which was in fact a
double array). Or the scanner function gimp_scanner_parse_float() was in
fact returning a double value. What if we wanted someday to actually add
float (usually this naming means in C the single-precision IEEE 754
floating point representation) support? How would we name this?

Now technically it's not entirely wrong (a double is still a floating
point). So I've been wondering if that is because maybe we never planned
to have float and double precision may be good enough for all usage in a
plug-in API (which doesn't have to be as generic so the higher precision
is enough)? But how can we be sure? Also we already had some functions
using the wording double (e.g. gimp_procedure_add_double_argument()), so
let's just go the safe route and use the accurate wording.

The additional change in PDB is internal, but there too, I was also
finding very confusing that we were naming double-precision float as
'float' type. So I took the opportunity to update this. It doesn't
change any signature.

In fact the whole commit doesn't change any type or code logic, only
naming, except for one bug fix in the middle which I encountered while
renaming: in gimp_scanner_parse_deprecated_color(), I discovered a
hidden bug in scanning (color-hsv*) values, which was mistakenly using a
double type for an array of float.
2024-11-02 15:00:03 +01:00
Jehan 519f0bf817 libgimp, libgimpbase: don't uselessly expose param spec structs when…
… they are the same as the parent struct.
2024-11-02 00:27:02 +01:00
Jehan 8075474fda libgimp, libgimpbase, libgimpconfig: GimpParamSpecChoise's parent should be GParamSpecString. 2024-11-02 00:27:02 +01:00
Jehan a0fa9cc191 app, libgimp*, pdb, plug-ins: capabilities should not be part of GimpParamSpecExportOptions.
The param option just contains an options object, not a separate
capabilities. Also even when passing the options object across the wire,
the capabilities within this object are not part of the "options". These
are actually handled separated by GimpExportProcedure.

Therefore the changes are:

* GimpExportCapabilities moved to gimpbaseenums.h with a proper GType.
* "capabilities" properties are changed to flags param spec with type
  GimpExportCapabilities.
* GimpParamSpecExportOptions doesn't have a capabilities variable
  anymore.
* Consequently gimp_param_spec_export_options() doesn't have a
  capabilities arg.
* Wire protocol updated as we don't need to pass any capabilities
  neither for the param definition, nor for the argument values.
* GimpExportOptionsEditFunc renamed GimpExportGetCapabilitiesFunc and
  returning GimpExportCapabilities flags, instead of setting the
  "capabilities" property. I believe it makes it much more obvious what
  this callback is for and how to use it.
* Annotations improved or completed.
* Don't make the GimpParamSpecExportOptions public anymore since it is
  the same as its parent.
2024-11-02 00:27:02 +01:00
Jehan 5f4464445f libgimp*: keep 10 reserved spots for future virtual functions in every derivable class.
Hopefully this should be enough to add new features in the future
without breaking ABI, at least until GIMP 4!
2024-11-01 17:22:07 +01:00
Jehan 86f588224b libgimp, libgimpbase: create special functions to get/set boxed array properties.
While the work on NULL-terminated array types make it much easier in C,
bindings don't have enough information to create native array/list types
in some generic functions such as g_object_get|set(), or else we just
don't know the right annotations to use for this to be possible. This is
report gobject-introspection#492.

So for the time being, we are creating dedicated functions for GeglColor
arrays and for other core object arrays (arrays of images, items, etc.).

E.g. in Python, while you can set a single GimpImage like this:

> config.set_property('image', image)

… you need to set a list of images like this:

> config.set_core_object_array('images', [image1, image2])
2024-10-28 22:08:45 +01:00
Jehan 8900967a81 extensions, libgimp, plug-ins: remove n_drawables arg from GimpImageProcedure's…
… run() function.

This is more consistent with recent changes in PDB, and now the
drawables argument is NULL-terminated.
2024-10-28 22:08:45 +01:00
Jehan ea5824ebd7 app, libgimp, pdb: fix other int sizes.
Avoid the stack smashing bug from yesterday in other functions.
Additionally to fixing other functions, do not cast the pointer to size
in the PDB generation scripts so that we can quickly spot such bugs in
the future, through compilation time warnings, instead of hiding them.
2024-10-28 22:08:45 +01:00
Jehan e02b8819e5 app, libgimp, pdb: fix “Stack smashing detected” crash.
Building with clang and various stack protection flags (as is done in
our flatpak apparently), we can trigger a crash when a gint on the stack
is set as a pointer to gsize.
Anyway now all array size must be gsize.

See: https://discourse.gnome.org/t/problem-with-select-polygon-in-gimp-2-99/24753
2024-10-28 02:03:57 +01:00
Jehan f490a8eb63 app, libgimp: fix crash when selecting a gradient from plug-in.
As reported by Anders in !1919. This is because
gimp_pdb_execute_procedure_by_name() now expects a proper GimpArray for
float and int arrays, not a C array preceded by a size value.
2024-10-25 23:31:42 +02:00
Jehan 48cb7e76d3 app, libgimp, pdb: add g_return*_if_fail() test for array size args.
Generated libgimp functions' arguments are normally tested through the
PDB, so that you get proper error messages when trying to call a
function with invalid arguments.
This is not true anymore for array arguments since the size argument is
not a PDB arg, only in the C function. Therefore I'm adding an
infrastructure asserting on invalid size, using the same PDB type
annotations as other args. It is important to assert valid input on
plug-in side (i.e. libgimp) so that the core doesn't make any assumption
on having received valid input when it has not.

Also changing size argument of gimppainttools PDB-generated functions to
proper gsize.
2024-10-25 23:31:06 +02:00
Jehan ac2bef4410 app, libgimp, pdb, plug-ins: array size's type should be gsize.
This changes the signature of generated functions in libgimp with array
arguments.
2024-10-25 23:28:42 +02:00
Jehan 3a2cbb4162 app, libgimp, pdb: array length are not PDB arguments anymore.
Yet they still are generated libgimp functions' arguments.

For instance gimp_context_get_line_dash_pattern() still has a num_dashes
integer argument and a dashes C array, but when calling the PDB
procedure "gimp-context-get-line-dash-pattern", we only set the
GimpArray.

This will allow simpler direct PDB calls too, included in script-fu,
where the size argument is really redundant.
2024-10-25 23:28:42 +02:00
Jehan 096c45599d app, libgimp*, pdb, plug-ins: float arrays don't need size arguments too. 2024-10-25 23:28:42 +02:00
Jehan 60eb27ab18 app, libgimp*, pdb, plug-ins: first step to make int32array PDB type aware of its length.
PDB code is now looking directly into the GimpArray length for
determining the data length.

Also adding a 'size' argument (number of elements, not bytes) to
gimp_value_(get|dup)_int32_array() to make it actually introspectable.
Until now, it was somehow introspected but was segfaulting on run.
I.e. that, e.g. in Python, calling Gimp.value_set_int32_array(v, [1, 2, 3])
followed by Gimp.value_get_int32_array(v) would actually make a
segmentation fault. Now the binding works flawlessly.

This will also make these functions much more usable in general.
2024-10-25 23:28:42 +02:00
Jehan 87d3d921da libgimp, pdb: improve free function information on array types.
Core object arrays must also be freed with g_free() (since elements are
not ref-ed).

Also color arrays must be freed with gimp_color_array_free().
2024-10-25 23:28:42 +02:00
Jehan 4137dce97b libgimp*: get rid of GimpObjectArray and GimpParamSpecObjectArray.
These have now been completely replace with the new GimpCoreObjectArray.
2024-10-25 23:28:42 +02:00
Jehan e1e2941d9e app, libgimp*, plug-ins: move all GimpObjectArray procedure args to GimpCoreObjectArray. 2024-10-25 23:28:42 +02:00
Jehan 08fd3a3f0d app, libgimp, pdb: imagearray PDB type as GimpCoreObjectArray. 2024-10-25 23:28:42 +02:00