Commit Graph

357 Commits

Author SHA1 Message Date
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
Alx Sa c093837bda scripts, pdb: Consolidate gauss and pixelize compat functions
Currently there are 5 separate plug-in-gauss
functions. IIR2 and RLE2 are not used, and
IIR and RLE are identical to each other.
Additionally, they all call a separate
gaussian_blur () function which multiples
two parameters by 0.32 to convert to the
actual GEGL operation.

This patch removes all functions except
for plug-in-gauss. It converts each
existing script that used one of the other
variants to use plug-in-gauss, and
multiples the coefficients by 0.32 so that
plug-in-gauss behaves the same as calling
gegl:gaussian-blur with a C plug-in.

There also exists a plug_in_pixelize2 ()
function in the PDB which allows the user to set
both the pixel width and height.
This patch converts this to become
plug_in_pixelize (), and removes the older
function which used a single width
parameter for both values.
2024-10-28 04:39:39 +00: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 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 08fd3a3f0d app, libgimp, pdb: imagearray PDB type as GimpCoreObjectArray. 2024-10-25 23:28:42 +02:00
Jehan 64f9c71ad5 app, libgimp, pdb: all resource (and subtype) array PDB types as GimpCoreObjectArray. 2024-10-25 23:28:42 +02:00
Jehan 59c040323c app, libgimp, pdb, plug-ins: patharray PDB type as GimpCoreObjectArray. 2024-10-25 23:28:42 +02:00
Jehan 255cda73c1 app, libgimp, pdb: channelarray PDB type as GimpCoreObjectArray. 2024-10-25 23:28:42 +02:00
Jehan d484b591d9 app, libgimp, pdb, plug-ins: layerarray PDB type is now a GimpCoreObjectArray. 2024-10-25 23:28:42 +02:00
Jehan 318f7451cd app, libgimp*, pdb, plug-ins: change itemarray PDB type to use GimpCoreObjectArray. 2024-10-25 23:28:42 +02:00
Jehan 38c2cd3b15 app, libgimp, pdb, plug-ins: new GimpCoreObjectArray type and drawablearray…
… PDB type.

This is a first step for #7369. Clearly our GimpObjectArray was meant to
be used with C arrays, hence the wrapper function
gimp_value_set_object_array() which was taking a C array and actually
creating and setting a GimpObjectArray.

This is why our new type is actually a C array aliased as a boxed type
and containing its own size (thanks to NULL-termination).

Eventually GimpCoreObjectArray is meant to replace GimpObjectArray.

The only issue is that such a type does not allow NULL as a valid
element in such an array, but fact is that I don't think we currently
have any use case where this matters. If ever such a case arise in the
future, we may introduce back GimpObjectArray.

In this first commit, I replaced all itemarray PDB types with a new
drawablearray using this new boxed type when relevant.
2024-10-25 23:28:42 +02:00
Massimo Valentini 542d2af2a5 pdb, libgimp: Add API to get/set Emulate Brush Dynamics
This patch adds a pdb getter/setter for GimpStrokeOptions'
emulate-brush-dynamics property. This allows users to change
the "Direction" of strokes via Script-fu/Python API calls.
2024-10-21 10:55:27 +00:00
Jehan 3051796f3e app, libgimp, pdb, plug-ins: merge gimp_channel_new() in libgimp and PDB.
Why have 2 functions if one is basically just redirecting to the other.
All we needed to do was to reorder the PDB args.
2024-09-29 12:27:49 +02:00
Alx Sa 01af0f78c8 app, libgimp, pdb: Fix generation warnings
On generating our PDB files, we were
getting warnings about uninitialized strings.
This is because descriptions and authors
had been left off three .pdb files. Adding
these in resolved the warnings.
A new PDB author entry was also added
for Idriss Fekir.
2024-09-24 22:56:44 +00:00
Jehan 33ec5b70b1 app, libgimp, pdb: fix our PDB script to try to interpret gi-docgen syntax.
Fixes:

> Possible unintended interpolation of @palette in string at /builds/GNOME/gimp/pdb/groups/image.pdb line 1692.
2024-09-24 23:29:33 +02:00
Jehan 151cb9c40c app, libgimp, pdb, plug-ins: rename gimp_palette_entry_[gs]et_*().
These function names look like they should be applied to a
GimpPaletteEntry, which is a type which doesn't exist in libgimp. This
naming is much more appropriate.
2024-09-23 18:37:27 +02:00
Jehan 3bfda4f119 Issue #9477: remove gimp_image_[gs]et_colormap() from libgimp API.
They are now replaced by the more generic gimp_palette_[gs]et_colormap(),
hence making less of a particular concept of "image colormap". It's just
a palette attached to the image (and restricted to the image format).
2024-09-23 18:20:14 +02:00
Jehan 9ad05ee6fa app, libgimp, pdb, plug-ins: change gimp_palette_set_colormap() to take a C array.
Similar to previous commit.
2024-09-23 00:01:06 +02:00
Jehan c60512514c app, libgimp, pdb: change gimp_palette_get_colormap() to return a C array.
GBytes are a bit annoying to handle, so I'm renaming the PDB procedure
to a private _gimp_palette_get_bytes() instead, and making a wrapper
function which returns a C array and both the number of colors or number
of bytes. The latter is needed for introspection (otherwise the binding
can't know the size of the C array), but for the C API, both these
returned integers can be considered redundant (since one can be computed
from the oher), so only one at a time is mandatory.
2024-09-23 00:01:06 +02:00
Jehan 9bd69498ca app, libgimp, pdb: new gimp_image_set_palette() procedure.
When we want to set a full palette based on an existing one, no need to
request the full colormap from core to libgimp then back. Just set the
palette which is nothing more than an empty shell around a resource ID.
2024-09-22 23:26:33 +02:00
Jehan 6a35118a8f app, libgimp, pdb: new gimp_palette_set_colormap() PDB procedure. 2024-09-22 23:26:33 +02:00
Jehan 4708609395 app, libgimp, pdb: new gimp_palette_get_colormap() function. 2024-09-22 23:26:33 +02:00
Jehan b8712b27de Issue #12011: gimp-path-import-from-file etc. are misnamed. 2024-09-11 16:26:45 +02:00
Alx Sa fd091bc005 pdb: Check number of arguments for gimp_file_save ()
gimp_file_save () is used to save both XCF
and export formats like PNG. XCF does
not have a GimpExportOption parameter,
but we were unconditionally copying it.
This patch adds a check for this.
2024-09-01 18:29:04 +00:00
Jehan 82c607d4a8 app, libgimp, pdb: support triple-backticks unformatted desc sections.
The previous PDB generation was losing pre-formatting inside
triple-backticked blocks. In particular we were losing indentation
(which was already ugly in C, but even syntactically wrong when
displaying Python code samples). And it was also making us add
double-newlines between every code lines, which was annoying.

This updated code now leaves triple-backticked sections as-is.

Unfortunately I was completely unable to do this by modifying the
existing functions, which were modifying the input arg in-place. So I
made them into functions returning the result. But then there is another
part of code (niceargs()) where changing array contents doesn't work
properly, and worse it seems to corrupt the array somehow (because I
have generation breakage in completely-different pieces of the PDB
generation code). I believe there is some passing-by reference/value
concepts in perl which I don't quite get (they use `&`, `\` and other
symbols and even searching for these, I don't quite understand how to
use them the right way) but I've spent already too much time on this. So
since I've got something working now by having duplicate functions, I'll
let someone else from the future, who knows better perl, re-merge these
functions if they know how.
2024-08-27 11:48:49 +02:00
Jehan 0fe66771da app, libgimp, pdb: fixing broken GIR links.
The 'help' field needs to be single-quoted so that @-values do not look
like perl variables, hence breaking GIR annotations.

Fixing:

> Possible unintended interpolation of @Gimp in string at /home/jehan/dev/src/gimp/pdb/groups/item.pdb line 64.
2024-08-27 00:26:59 +02:00
Jehan d1c8e5efb9 app, libgimp, pdb: prettify the previous commit.
I double-checked the gi-docgen docs and realized the "Note:" were all on
the same line as previous text. I had forgotten it just removed one
newline. So if I want a new paragraph (double-newline in markdown), I
need 3 newlines in the pdb file.
2024-08-26 22:48:45 +02:00
Jehan 890a3c715f Issue #10673: make clearer API docs for _id*() functions.
All the functions working with object's IDs are mostly internal. They
are still made public because they can be useful and are relevant in
specific use cases (i.e. using IDs to reference items in specific
widgets, such as drop-down lists, or when temporarily storing an item as
integer, etc.).
Yet it should be made clear that these usages are the exception rather
than the norm.
2024-08-26 15:03:24 +02:00
Jehan ddcaa99264 app, libgimp*, pdb, plug-ins: review and enhance MR !1549.
- Fix annotations for gimp_export_options_get_image() to make it
  actually introspectable with the GimpImage being both input and
  output. Even though the logic doesn't change much (the input image may
  be overriden or not), it doesn't matter for introspection because
  images are handled centrally by libgimp and therefore must not be
  freed. Actually deleting the image from the central list of images
  though remains a manual action depending on code logic, not some
  automatic action to be handled by binding engines.
- Add G_GNUC_WARN_UNUSED_RESULT to gimp_export_options_get_image()
  because ignoring the returned value is rarely a good idea (as you
  usually want to delete the image).
- Remove gimp_export_options_new(): we don't need this constructor
  because at this point, the best is to tell plug-in developers to just
  pass NULL everywhere. This leaves us free to create a more useful
  default constructor if needed, in the future. Main description for
  GimpExportOptions has also been updated to say this.
- Add a data_destroy callback for the user data passed in
  gimp_export_procedure_set_capabilities().
- Fixing annotations of 'export_options' object from pdb/pdb.pl: input
  args would actually be (nullable) and would not transfer ownership
  (calling code must still free the object). Return value's ownership on
  the other hand is fully transfered.
- Add C and Python unit testing for GimpExportOptions and
  gimp_export_options_get_image() in particular.
- Fix or improve various details.

Note that I have also considered for a long time changing the signature
of gimp_export_options_get_image() to return a boolean indicating
whether `image` had been replaced (hence needed deletion) or not. This
also meant getting rid of the GimpExportReturn enum. Right now it would
work because there are no third case, but I was considering the future
possibility that for instance we got some impossible conversion for some
future capability. I'm not sure it would ever happen; and for sure, this
is not desirable because it implies an export failure a bit late in the
workflow. But just in case, let's keep the enum return value. It does
not even make the using code that much more complicated (well just a
value comparison instead of a simple boolean test).
2024-08-18 22:46:47 +02:00
Alx Sa bcdd4974bb core, pdb, plug-ins: Create GimpExportOptions class
This patch creates a GimpExportOptions class in both
libgimpbase and in libgimp. Currently it is a mostly empty
object, but it will be added to after 3.0 to allow for
additional export options (like resizing on export while
leaving the original image intact)

libgimp/gimpexport.c was removed, and most of its content
was copied into libgimp/gimpexportoptions.c. gimp_export_image ()
was replaced with gimp_export_options_get_image () in all
export plug-ins.

GimpExportProcedure has a new function to set the default
image capabilities for each plug-in on creation. It also sets up
a new callback function, which allows the options to respond to
user setting changes (such as toggling 'Save as Animation' in the
GIF or WEBP Plug-in).
2024-08-18 22:03:14 +02:00
Jehan 518052a105 app, pdb: gimp_text_layer_new() allows pixel unit.
As reported by NikcDC: 624e3772e9 (note_2199852)
2024-08-18 17:44:06 +02:00
bootchk b5a8f46b37 pdb, libgimp: Fix return type of gimp-buffer-get-image-type
gimp-buffer-get-image-type returns the output of
gimp_babl_format_get_image_type (), which itself returns
a GimpImageType enum. However, the PDB claims that
it's a GimpImageBaseType enum instead. This patch fixes
the documentation to match the actual output enum type.
2024-08-17 23:23:51 -04:00
Jehan d0be4828ce app, pdb: improve cut error message and fix return value.
This fixes 2 issues:

1. Since gimp_edit_cut() uses gimp_edit_copy(), it had the same error
   message when no selected drawables were within the selection.
2. When there was a previously existing clipboard image, gimp_edit_cut()
   could return it as though the cut succeded, even when it did not.
2024-08-09 20:39:26 +02:00
Jehan d5ff0360b1 app, libgimp, pdb: also tweak a bit gimp_edit_copy|cut() docs per…
… Lloyd comment in #10471.
2024-08-09 20:10:06 +02:00
Jehan 2a00a9e60a Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!

Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).

As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.

So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-06 11:39:57 +02:00
Jehan d493f0537f Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!

Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.

As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.

Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.

Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-08-02 10:46:38 +02:00
Alx Sa d701b70336 pdb, libgimpbase: Rename GIMP_VECTORS_STROKE_TYPE...
...to GIMP_PATH_STROKE_TYPE as part of
the GimpVectors -> GimpPath API
update.
2024-07-19 15:07:43 +00:00
bootchk f4f71e4296 PDB: fix #11815 CRITCALS from defaulted args for gegl wrapper procs
Revise the tests that can't default the args.

Actual args default to the min value formal declared in the PDB.
The declared min value must correspond with declaration in GEGL.
2024-07-16 10:25:41 +00:00
Alx Sa ba635d83a7 pdb: Remove item_is_attached restriction from NDE filters
As of fcdddad2, the requirement for layers
to be attached before NDE filters can be
applied has been removed on app/core. 
This patch removes the restriction from 
the PDB call for filters as well.
2024-07-15 21:12:17 +00:00
Alx Sa d8b984a4eb pdb: Add check for indexed image to gimp_image_get_colormap ()
The description promises that we return
NULL if the image is not in indexed mode,
but we didn't actually verify that it was
before continuing with the colormap
code. This patch adds that verification step.
2024-07-15 12:31:58 +00:00
Alx Sa 2e6938b3da app: Rename app/core GimpVectors vectors API...
...to path.
Changes the names of
gimp_vectors_* () API to
gimp_path[s]_* (). Renames related files
to [path] instead of [vectors], along with
relevant enums and functions.
2024-07-13 05:07:57 +00:00
Alx Sa e8df68fb65 libgimp, app, pdb: Rename GimpVectors to GimpPath
This commit renames the GimpVectors
object to GimpPath in both app/core and
in libgimp. It also renames the files
to gimppath.[ch] and updates the relevant
build and translation files.
There are still outstanding gimp_vectors_* ()
functions on the app side that need to be renamed
in a subsequent commit.
2024-07-12 06:16:25 +00:00
Alx Sa 853f37bed9 app: Rename app/core GimpImage vectors API...
...to paths.
Similar to d0bdbdfd, but covering the
app/core versions of the API instead of
libgimp. Changes the names of
gimp_image_*_vectors () API to
gimp_image_*_path[s] ().
Also renames some related functions such
as gimp_image_pick_path (). The next step
will be to rename the gimp_vectors_* () to
gimp_path_* ().
2024-07-11 01:17:49 +00:00
Alx Sa b90b6bce00 pdb, libgimp: Rename libgimp GimpVectors vectors API...
...to paths
Follow-up to d0bdbdfd. Changes all
gimp_vectors_* () PDB to gimp_path_* ()
and renames relevant PDB files from
vectors to path.
The next step will be to rename
GimpVectors in libgimp to GimpPath,
removing the last (public) trace of it.
2024-07-08 23:39:51 +00:00
Alx Sa d0bdbdfdf6 pdb, libgimp: Rename libgimp GimpImage vectors API...
...to paths

The first step in converting GimpVectors
to GimpPath. The PDB API for any
gimp_image_*_vectors () is now
gimp_image_*_paths ().
This commit only covers libgimp, and
the app/core versions will be renamed in
a following commit.
2024-07-08 02:09:42 +00:00
Alx Sa 8e6fb3d0e4 pdb: Remove uchar type
Resolves #10855
Replaces the uchar arguments in
plug_in_exchange () with floats to better
match gegl:color-exchange's arguments.
Since this was the last plug-in that used
uchar, we also remove the datatype from
PDB.
2024-07-07 11:14:41 +00:00
Jehan b1736a6736 app, libgimp, pdb, plug-ins: new GimpGroupLayer class in libgimp.
Also:

- renaming gimp_layer_group_new() to gimp_group_layer_new() in order to keep the
  same name as in core code (i.e. GimpGroupLayer, not GimpLayerGroup).
- renaming gimp_image_merge_layer_group() to gimp_group_layer_merge()
- new functions: gimp_procedure_add_group_layer_argument(),
  gimp_procedure_add_group_layer_aux_argument() and
  gimp_procedure_add_group_layer_return_value().

This can be tested, e.g. in Python with these calls:

```py
i = Gimp.get_images()[0]
g = Gimp.GroupLayer.new(i, "hello")
i.insert_layer(g, None, 1)
g2 = Gimp.GroupLayer.new(i, "world")
i.insert_layer(g2, g, 1)
g.merge()
```

This was work started long ago, stored in an old stash which I finally
finish now! :-)
2024-07-07 10:27:04 +02:00
Jehan 8b6d90700a libgimp, pdb, plug-ins: don't skip gimp_*get_*() API from GObject Introspection anymore.
The original reason to skip these was because the new _list_ API were
introspected basically to a similar function signature, except with a
useless return value, at least in pygobject binding where the list size
was also returned.
Though it seems that in fact, only the docstring was wrong. The real
signature was apparently already the same.
See: https://gitlab.gnome.org/GNOME/pygobject/-/issues/352

Therefore since the _get_ naming is more consistent compared to other
existing function, let's re-integrate the _get_ functions for array of
items or images.

This basically reverts commit 15ec254148.
2024-07-06 14:44:45 +02:00
Jehan cca637135b app, libgimp, pdb, plug-ins: fix failure to set plug-in as transient.
While setting a plug-in as transient usually worked, it was failing in
cases the plug-in's progress bar was not initialized (i.e. if
progress_init() was not called before setting the dialog transient).

This commit stores the calling display, core side too (libgimp side, the
plug-in already had the calling display ID information), and we use this
when a GimpProgress has not been created yet.
2024-06-08 21:54:21 +02:00