Commit Graph

47 Commits

Author SHA1 Message Date
Jacob Boerema 85561c7ff0 libgimp: fix #6126 Invalid charset: InvalidCharsetId
Some apps that write EXIF metadata, forgot to add the charset to
certain tags that require it. The main case is Exif.Photo.UserComment.
This caused us to show a warning about an invalid charset, in addition
to not showing it in our Metdata Viewer.

We fix this by reading the raw data for that tag when we encounter the
above error. The raw data is then validated as utf-8 and converted
to a string if valid.

We then resave this tag to our metadata to force it to have the
correct charset; that way we don't have to do any checking in other
places in our code.

Note: there are a few other tags that also use a charset. We may have
to check those too, eventually.
2024-05-26 14:46:20 -04:00
Jacob Boerema 7a8f465b2d Issue #10588: enumerations for RotationType can't be used in Python
Due to GObject Introspection we can't have the last part of an
identifier start with a digit, since that part will be used in Python
as the identifier, and Python doesn't allow that to start with a digit.
e.g. GIMP_ROTATE_90 would be used in Python as
image.rotate(Gimp.RotationType.90)

To fix this we add DEGREES in front of the number, without a '_',
even though that looks ugly.
2024-01-05 13:28:49 -05:00
Jehan af644b1950 libgimp, libgimpbase: new gimp_load_procedure_new2() for run() function using…
… a GimpProcedureConfig for arguments.

This also factorizes the code to load metadata. By default, a GimpLoadProcedure
will try and load metadata from a file (if Exiv2 knows the format). The run()
function will be allowed to edit the GimpMetadata object but also the load flags
before it is actually attached to the image, allowing plug-ins to have custom
metadata handling code when needed.
2023-10-01 20:52:02 +02:00
Simon Budig 71b46d5a0b gimpimagemetadata: ...so that we can remove that ugly hack here. 2023-05-21 01:58:16 +02:00
Jacob Boerema b37f0a3182 libgimp, plug-ins: remove obsolete XmpStructs 2023-05-20 12:39:29 -04:00
Simon Budig 27af306a8a libgimp: un-deprecate and fix gexiv2 usage. 2023-05-20 18:06:21 +02:00
Jacob Boerema a96dc81ee5 plug-ins: fix #7613 overwrite export creates thumbnail when it shouldn't
When overwriting the same file when exporting, we didn't check if the
image previously had a thumbnail. If the default setting in Preferences
is to add a thumbnail, then it would add one where it shouldn't.

Since thumbnails get saves as part of the EXIF metadata, we need to check
that to see if there was a thumbnail in the original image.
However, we were always removing the thumbnail from the metadata on import.

Let's delay removing this metadata until we need to, which has the
advantage that the metadata in our viewer is more complete.

When exporting starts, we add a check in gimp_image_metadata_save_prepare
to see if there was a thumbnail in the EXIF metadata. If not, then we
disable the thumbnail flag.

In gimp_image_metadata_save_filter we remove the thumbnail metadata when
the user doesn't want to save a thumbnail, or when the image format
does not support EXIF.
2022-05-22 14:00:36 -04:00
Jehan 96e25b7817 libgimp: fix and workaround Exif.Photo.UserComment interpretation.
Here are the changes:
- Separate the check for comment contents and the one of whether or not
  it starts with "charset=Ascii ". Indeed in my tests, we still want to
  handle the empty string case or the "binary comment" case even without
  the charset prefix (currently it was both or none, so I encountered
  cases with a broken "binary comment" comment because the charset
  prefix was absent).
- Add some #warning in order not to forget to remove the bogus "binary
  comment" test. Indeed after some digging in Exiv2 code, I could
  confirm this return value got removed in commit 9b510858 of Exiv2
  repository, i.e. since Exiv2 0.27.4. Now in my test case where I had a
  tag containing only 0s, Exiv2 returns an empty string, which is
  perfectly fine (and it's up to us to keep or ignore it).
- Use gexiv2_metadata_try_get_tag_interpreted_string() instead of their
  deprecate non-try counterparses. Right now, I am just outputting any
  error message to stderr, as I'm not sure if this is the kind of errors
  we want to warn people about. I guess it would depend on which type of
  errors exactly are returned, so let's see if we encounter some case in
  the future. For now stderr is fine to detect these.
2022-01-20 16:47:04 +01:00
Jacob Boerema 352b5885b1 libgimp: fix issue #6050 Phantom comments on pictures.
Since version 0.27.3 exiv2 has changed how it returns
comments for Exif.Photo.UserComment. We now get
the comment including the charset=Ascii value.

Let's remove anything that's not part of the actual
comment. To not complicate things we will  only
handle charset=Ascii for now since I've never seen
any other charset used.
2021-03-22 16:06:54 -04:00
Jehan 67e2e1b5bb app, libgimp, plug-ins: move Orientation metadata handling into core.
Orientation is now handled by core code, just next to profile conversion
handling.

One of the first consequence is that we don't need to have a non-GUI
version gimp_image_metadata_load_finish_batch() in libgimp, next to a
GUI version of the gimp_image_metadata_load_finish() function in
libgimpui. This makes for simpler API.
Also a plug-in which wishes to get access to the rotation dialog
provided by GIMP without loading ligimpui/GTK+ (for whatever reason)
will still have the feature.

The main advantage is that the "Don't ask me again" feature is now
handled by a settings in `Preferences > Image Import & Export` as the
"Metadata rotation policy". Until now it was saved as a global parasite,
which made it virtually non-editable once you checked it once (no easy
way to edit parasites except by scripts). So say you refused the
rotation once while checking "Don't ask again", and GIMP will forever
discard the rotation metadata without giving you a sane way to change
your mind. Of course, I could have passed the settings to plug-ins
through the PDB, but I find it a lot better to simply handle such
settings core-side.

The dialog code is basically the same as an app/dialogs/ as it was in
libgimp, with the minor improvement that it now takes the scale ratio
into account (basically the maximum thumbnail size will be bigger on
higher density displays).

Only downside of the move to the core is that this rotation dialog is
raised only when you open an image from the core, not as a PDB call. So
a plug-in which makes say a "file-jpeg-load" PDB call, even in
INTERACTIVE run mode, won't have rotation processed. Note that this was
already the same for embedded color profile conversion. This can be
wanted or not. Anyway some additional libgimp calls might be of interest
to explicitly call the core dialogs.
2020-09-24 12:43:41 +02:00
Jehan 1b4834126f libgimp: better organization of gimp_image_metadata_*() API.
gimpimagemetadata.[ch] was built into libgimpui because GTK+ was used
for dialog query for rotation metadata. gimpimagemetadata-save.c only
was built into libgimp, which made no sense as the declaration for its
public function was inside gimpimagemetadata.h!
That was a weird situation and somehow only made visible in the build
system because GIR build was complaining about missing annotations to
gimp_image_metadata_save_prepare() (the annotation was actually present
but in the implementation which was not in the same library as the
header, how weird!):

> Warning: GimpUi: gimp_image_metadata_save_prepare: return value: Missing (transfer) annotation

Moreover it means that only plug-ins linking libgimpui had access to the
gimp_image_metadata*() API, which is obviously not cool (that should be
a core API).

Instead I moved everything into libgimp and replaced
gimp_image_metadata_load_finish() with
gimp_image_metadata_load_finish_batch(), which is essentially the same
function except that it's not interactive (it will proceed to rotate the
image without user confirmation, provided the right flag is present).
Then I add gimpimagemetadata-interactive.[ch] which contains only
gimp_image_metadata_load_finish() and is the alternative interactive
version of gimp_image_metadata_load_finish_batch(). Most plug-ins won't
even have to be changed (at least none in core GIMP) and would still
work as before, whereas now a non-interactive version exists, which
doesn't mandate to link GTK+.
2020-09-13 13:36:51 +02:00
Michael Natterer 8219092a6c libgimp: start integrating image export with GimpProcedureConfig
Add gimp_procedure_config_begin_export() and end_export() which
are wrappers around begin_run() and end_run() and additionally
pretty much completely manage GimpMetadata handling.

A GimpProcedureConfig can provide boolean properties "save-exif",
"save-xmp" etc. in order to have them automatically managed by
begin_export() and end_export(). This also restores the feature of
overriding the procedure's saved default values with export
preferences, but not the values from the last export, like it
used to be in 2.10.

Move gimp_image_metadata_save_prepare() and save_finish() (which are
now completely handled by GimpProcedureConfig) from libgimpui to
libgimp, but keep their declarations in the libgimpui header. Not
perfect, but not finished either.

Also fix gimp_image_metadata_save_prepare() to set the affected
GimpMetadataSaveFlags to 0 when the image has no metadata at all.
2019-10-09 22:50:03 +02:00
Michael Natterer 70ac0e9d9a libgimp: fix gimp_image_metadata_save_prepare()'s check for IPTC flags
it was checking gimp_export_xmp() not gimp_export_iptc(), probably a
copy/paste error.
2019-09-24 12:11:59 +02:00
Michael Natterer 96c1f754ba libgimp: remove a ton of deprecated API that is unused 2019-08-27 16:32:25 +02:00
Jehan 08849a584c libgimp: GimpItem now also belong to libgimp. 2019-08-22 15:54:36 +02:00
Jehan cfd30ec62a libgimp: s/gimp_image_new_by_id()/gimp_image_get_by_id()/
This means that images' ownership is not given to caller in particular.
libgimp will now keep a reference of all GimpImage-s it creates and
return this same reference if called again. It also means that you can
now compare images by pointer comparison (as 2 GimpImage objects
representing the same image ID will be equal).
Obviously as a side effect, gimp_image_list() is changed to (transfer
container) as you must only free the container now, not the elements.
Also various other functions creating new images are now (transfer none)
too.

Long-time plug-ins will have to be taken in consideration in a further
step (we currently never free GimpImage for destroyed images in
particular).
2019-08-22 15:54:36 +02:00
Jehan 3f1491e572 libgimp: update non-generated API using GimpItem/GimpDrawable/GimpLayer.
I did the same trick with GIMP_DEPRECATED_REPLACE_NEW_API macro, apart
for some minor widget API to preview drawable, which I will fix right
away in our plug-ins.
2019-08-22 15:54:36 +02:00
Jehan 09f0530dab libgimp: update non-generated API to allow old and new API.
Same as previous commit: by default the new API will be used. But if a
plug-in builds with GIMP_DEPRECATED_REPLACE_NEW_API macro, then the same
function names will call the old API with ids.
2019-08-22 15:54:36 +02:00
Jehan bb72504ea9 libgimp: change all non-generated API to use GimpImage.
We shouldn't pass as parameter nor return gint32 anymore.
2019-08-22 15:54:36 +02:00
Niels De Graef 1dda60154c Use "Returns:" to annotate return values
To be able to annotate return values through GObject-introspection, you
need to make sure it is tagged with `Returns:` and not something else.
2019-08-03 07:53:47 +00:00
Jehan 6fe2508301 libgimp*: fix various missing (transfer) annotations. 2019-08-01 01:52:07 +02:00
Michael Natterer d708ac0b21 Issue #1437 - 2.10 Image Metadata "keywords" corrupt
We were not taking into account tags that can appear multiple times,
such as "keyword", they are handled by gexiv2 with the
get_tag_multiple() and set_tag_multiple() functions.

gimp_metadata_deserialize_text(): when deserializing our XML format,
check if a tag is already set on the metadata as "multiple" and if yes
retrieve it, append the new value and set it again.

gimp_image_metadata_save_finish(): take care of "multiple" values when
copying tags to new metadata created for saving.

This should preserve all values across an "import, edit, export".

Thing will still break when using the metadata editor, it doesn't
handle multiple values at all, but that code is very hard to
understand.
2019-01-06 17:52:19 +01:00
Michael Natterer d873290915 libgimp: use G_N_ELEMENTS() in gimp_image_metadata_save_finish()
intead of hardcoding the array length.
2019-01-01 20:26:07 +01:00
Michael Natterer c667fdc5c0 Integrate the logic of profile saving with metadata saving
Add flag GIMP_METADATA_SAVE_COLOR_PROFILE to GimpMetadataSaveFlags and
initialize it from gimp_export_color_profile() in
gimp_image_metadata_save_prepare().

Adapt all plug-ins to use the bit from the suggested export flags and
pass the actually used value back to
gimp_image_metadata_save_finish().

This changes no behavior at all but creates hooks on the libgimp side
that are called with the context of an image before and after the
actual export, which might become useful later. Also, consistency
is good even though the color profile is not strictly "metadata".
2018-12-04 17:28:24 +01:00
Michael Natterer 5f700549e7 Change the license URL from http://www.gnu.org/licenses/ to https:// 2018-07-11 23:29:46 +02:00
Michael Natterer bdbec7941c Use the new macros from the last commit in all files
...and gone are the annoying warnings.
2018-05-20 21:06:34 +02:00
Michael Natterer b0b381b6c8 libgimp*: don't say "2.9" in metadata 2018-04-26 16:06:32 +02:00
Jehan 3061268e25 libgimp: gimp_image_metadata_save_prepare() uses metadata preferences.
gimp_image_metadata_save_prepare() now back to suggesting metadata
flags, but this time with reasonnable base. It indeed uses the presence
of particular metadata, but also whether the preferences asks for this
metadata to be exported by default or not.
2018-01-11 22:17:32 +01:00
Jehan 5e3d4cf131 libgimp: update gimp_image_metadata_save_prepare() description.
The returned flags should not be called "suggested" flags anymore.
Having metadata available in the work image does not mean we want them
exported absolutely, which can be a security risk, especially for the
metadata which are there from the imported image.
2018-01-11 00:44:46 +01: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 838449254a plug-ins: use gimp_get_default_new_layer_mode() for most new layers
instead of hardcoding NORMAL_LEGACY.
2017-08-20 17:12:46 +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
Michael Natterer 747b3768ef libgimpbase: remove gimp_metadata_register_xmp_namespace[s]()
and do the same in gimp_metadata_class_init(). Also fix all compiler
warnings and other stuff.
2017-07-07 19:11:12 +02:00
Michael Natterer 945a695f2d libgimp: clean up metadata patch to not warn and other minor changes 2017-07-07 18:25:56 +02:00
Ben Touchette dc9856cfe1 Bug 769820 - Cannot enter Iptc information when no metadata is available...
...and fails to write it to file when it is

Completely redo metadata editor and viewer code, adds support for
Xmp.xmpMM.History and more.
2017-07-07 18:11:39 +02:00
Michael Natterer 3cf423f0cd *: rename NORMAL to NORMAL_LEGACY and NORMAL_LINEAR to NORMAL
and make NORMAL_LEGACY immutable.
2017-02-26 16:26:34 +01:00
Michael Natterer eeebd98005 libgimp: need to cast GimpMetadata when calling GExiv2Metadata API 2017-02-20 01:31:16 +01:00
Debarshi Ray 9fd139efad Bug 778896 - Make effective use of gexiv2 to remove the orientation
Usually, it is enough to reset the Exif.Image.Orientation and
Xmp.tiff.Orientation tags to neutralize the orientation of an image.
However, some cameras may use non-standard tags. In such cases, merely
setting the standard tags will make the metadata inconsistent. Hence,
it is better to use gexiv2_metadata_set_orientation because it will
take care of the non-standard tags.
2017-02-19 21:33:59 +01:00
Michael Natterer 40981f43cf libgimp*: get rid of icons in dialog buttons (use labels not stock IDs) 2017-02-12 16:18:54 +01:00
Simon Budig 884edf56ca libgimpbase: make GimpMetadata its own type derived from GExiv2Metadata 2017-01-30 16:43:59 +01:00
Michael Natterer 66060e3307 app, libgimp*, plug-ins: replace enum GimpLayerModeEffects by GimpLayerMode
with proper value names. Mark most values as _BROKEN because they use
weird alpha compositing that has to die. Move GimpLayerModeEffects to
libgimpbase, deprecate it, and set it as compat enum for GimpLayerMode.
Add the GimpLayerModeEffects values as compat constants to script-fu
and pygimp.
2017-01-08 23:00:19 +01:00
Hartmut Kuhse 66bc98d299 Revert "New GimpMetadata as subclass of GExiv2Metadata"
This reverts commit 3ab08c8bfd.
2017-01-03 19:36:22 +01:00
Hartmut Kuhse 3ab08c8bfd New GimpMetadata as subclass of GExiv2Metadata 2017-01-03 19:26:35 +01:00
Michael Natterer a33daf99fe libgimpcolor: rename RGB and GRAY gimp_color_profile_new_*() functions
to be more consistent, as discussed in bug #756389.
2015-12-15 20:42:21 +01:00
Michael Natterer 15b7b17b12 Bug 492048 - Detect color space in Exif 2.21/DCF 2.0 option files
Some refactoring: add gimp_metadata_get,set_colorspace() and a new
enum GimpMetadataColorspace which so far can be one of { UNSPECIFIED,
UNCALIBRATED, SRGB, ADOBERGB }. The setter is untested and I don't
know if it's doing the right thing, please review. Use the getter in
gimp_image_metadata_load_finish(), so complex metadata logic and
profile creation/setting are separated.
2015-09-30 20:51:40 +02:00
Michael Natterer 7e9957851e Bug 492048 - Detect color space in Exif 2.21/DCF 2.0 option files
Copy a ton of logic from darktable and libkexiv2 and parse more
metadata tags which contain colorspace information, namely:

Exif.Photo.ColorSpace
Xmp.exif.ColorSpace
Exif.Nikon3.ColorSpace
Exif.Canon.ColorSpace
2015-09-28 19:54:18 +02:00
Michael Natterer f0814dcf33 libgimp: rename gimpmetadata.[ch] to gimpimagemetadata.[ch]
so the filenames match the contained namespace. Sort includes in
gimpui.h alphabetically.
2015-09-25 00:40:57 +02:00