Commit Graph

22 Commits

Author SHA1 Message Date
Jehan 77a30bfd28 app, libgimp: core loads thumbnail from metadata if no GimpThumbnailProcedure…
… is set.

The order for thumbnail creation in gimp_imagefile_create_thumbnail() is now:

1. If there is a GimpThumbnailProcedure, it is run first.
2. Otherwise we check if a thumbnail is in the metadata.
3. As last resort, we just load the full image.

Part of the fix was to copy gimp_image_metadata_load_thumbnail() into the core
code. I have been wondering if we could not drop the same function from libgimp
and remove the GimpThumbnailProcedure frome file-jpeg, since it just uses the
metadata thumbnail and it is the only plug-in using this code.
Also it is much faster to run this in core and it's generic function which makes
thumbnail loading from Exif data working for every format supported by Exiv2.

On the other hand, the file-jpeg thumbnail procedure also gathers a few more
useful information, such as the color model (in a reliably manner, since based
on JPEG header, unlike from metadata which may be wrong).
2023-10-01 21:02:33 +02:00
Jacob Boerema 97a71cfd41 libgimp: fix resource leak in gimpimagemetadata-save 2023-07-10 14:19:07 -04:00
Jacob Boerema c8739aa494 libgimp: fix failure to write XMP metadata
Certain XMP metadata tags currently can't be saved by us until we get
support in gexiv2 for adding new structs not present in exiv2.
We remove these tags from the exported metadata because the XMPSDK in
exiv2 would otherwise fail to write all XMP metadata.

Examples are the newer (2019, 2021, 2022) sample images from the
IPTC Photo Metadata Standard.

We also add all the static functions present in gimpimagemetadata-save
at the top, which had been forgotten in the past.
2023-05-20 12:39:29 -04:00
Jacob Boerema b37f0a3182 libgimp, plug-ins: remove obsolete XmpStructs 2023-05-20 12:39:29 -04:00
Jacob Boerema 9accaad0b6 libgimp: replace deprecated functions ...
1. gexiv2_metadata_has_tag with gexiv2_metadata_try_has_tag;
2. gexiv2_metadata_set_exif_thumbnail_from_buffer with the "try" version.

For a while now the minimum gexiv2 version for the master branch is 0.14.0,
which means we can replace these deprecated functions, since the new
versions were added in 0.14.0.
2023-05-18 15:23:59 -04:00
Jacob Boerema 7231ea54f8 libgimp: fix #1632 GIMP should not write to IPTC tag DateCreated
GIMP was saving the last changed/saved date to IPTC tag DateCreated,
which should only be used for the original creating date of the image
and thus should not be changed by GIMP.

After discussion in the cited issue, there is no tag in IPTC that we can
use, so we remove saving modified date from the IPTC metadata.

Instead we add two XMP tags, one for modified date and the other for the
date that metadata was changed. Since we do both when exporting, both are
saved with the same date/time in ISO 8601 format.

This also fixes another issue where we were not storing the timezone offset
for Xmp.tiff.DateTime. Since this has the same format as the other
XMP tags, we fix this together with this issue.
2022-06-06 19:03:13 -04: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 7fc963decb libgimp: fix annotations for gimp_image_metadata_save_filter().
Fixes:

> libgimp/gimpimagemetadata-save.c:541: Warning: Gimp: gimp_image_metadata_save_filter: return value: Missing (transfer) annotation
2022-03-18 16:26:18 +01:00
Daniel Novomeský ff87bc8d4d libgimp: new gimp_image_metadata_save_filter API
This new function is an alternative to existing
gimp_image_metadata_save_finish, when you want to save metadata
yourself and you need only filtering processing.
It returns filtered metadata allowing the caller
to save the finalized metadata via other means
(via native format’s library for example)
This API can be used to support metadata saving of image formats
not directly supported by gexiv2/exiv2.
2022-03-16 13:00:03 +00:00
Jehan c76172d971 libgimp: more un-deprecating GExiv2.
Last deprecated usages in this file. Actually there are a few other
calls but deprecated on GExiv2 0.14.0, hence over our current
requirement. So we'll have to handle these later.
2022-01-20 18:45:08 +01:00
Jehan 0d33ede670 libgimp: undeprecate some more GExiv2 calls.
Replace functions gexiv2_metadata_set_xmp_tag_struct() and
gexiv2_metadata_get_tag_type() with their _try_ variants.

Note that I print to stderr rather than raising a warning here as I am
quite unsure where the list of XMP metadata we are gathering comes from.
Is it fully validated by GExiv2, and therefore no errors are ever
supposed to happen? (in such case, we should raise a warning if it does)
Or is it user-provided data (e.g. from a file loaded in GIMP which can
contain broken metadata)? In such a case, we should probably handle the
error slightly differently to warn for non-processable data (hence
possibly metadata loss at export time).

For the time being, then go with this weak handling and take care of
this better when we can look further into this.
2022-01-20 18:26:07 +01:00
Jehan e3c803299a libgimp: port a bunch of gexiv2_metadata_set_tag_string() to …
… gexiv2_metadata_try_set_tag_string().

These are usage where we have full control over tag names and values so
no error is supposed to happen. This is why we use them as code warnings
and not returned error (because if an error did happen, this would be a
bug rather than a user error or a system error).
2022-01-20 17:56:28 +01:00
Jacob Boerema 352ef68c46 app, libgimp: Add metadata preference for saving thumbnail by default
Saving a thumbnail is closely related to the other metadata preferences,
but so far this was the only one that didn't have a preference for a
default user value.
This commit adds a preference in the metadata section where a user can
select whether thumbnail saving is enabled by default or not.
2021-10-12 13:20:47 -04:00
Jacob Boerema d577e516c5 libgimp: set subfiletype to FILETYPE_REDUCEDIMAGE when saving EXIF thumbnails.
Setting the type to reduced image for a thumbnail makes it easier when
loading TIFF images to recognize a page as a thumbnail.
2021-08-27 15:36:49 -04:00
Jehan fa16152757 app, libgimp, pdb, plug-ins: update some more functions to get|set().
s/gimp_image_base_type/gimp_image_get_base_type/
s/gimp_image_width/gimp_image_get_width/
s/gimp_image_height/gimp_image_get_height/

Sorry plug-in developers, more porting work! But really this seems like
the right thing to do in order not to get stuck with inconsistent naming
for many more years to come.
2021-04-06 00:49:07 +02:00
Jacob Boerema 5eb9a998bb libgimp: improve saving xmp metadata.
1. Convert xmp /Iptc4xmpExt tag parts to /iptcExt because
exiv2 fails when we try to use the default namespace.

2. Don't only set structs from a fixed list but find all
xmp array elements and check what the best struct
type is: bag or seq.

3. Work around a sorting issue in (g)exiv2 by using a natural
sorting algorithm ourselves.

4. Added some g_debug statements to make it easier to
determine the cause of issues.
2021-03-21 13:04:30 -04:00
Jehan 3e4407a315 libgimp, libgimpconfig: use gimp_parasite_get_data().
As previously do not trust that parasite contents is proper text ending
with nul character by always using the parasite size info.
2021-01-30 08:57:43 +01:00
Jehan 4485296bdc libgimp: fix timezone in IPTC tag Iptc.Application2.TimeCreated.
Existing implementation was repeating the hours and minutes. This was
obviously not what the format asked. The last hour and minutes are the
ones from the timezone offset. Also rather than playing with snprintf()
and various calls to get each component, let's use g_date_time_format()
which is done exactly for such use case.

It is to be noted that there seems to be a bug in Exiv2 such that the
date and time set through Exiv2 return an error when read back, still
with Exiv2. Read and write use different format. I have reported this
issue, together with a patch (hopefully a good one).
https://dev.exiv2.org/issues/1380

So once this patch (or another) gets merged upstream, the following
warnings (e.g. when reopening a PNG created by GIMP) should disappear:

> ** (file-png:176245): WARNING **: 02:43:25.204: Unsupported date format
> ** (file-png:176245): WARNING **: 02:43:25.204: Unsupported time format
2020-11-15 02:44:47 +01:00
Jacob Boerema 8e97d56d1e libgimp, libgimpbase: don't use a fixed GIMP 2.10 version number in exif metadata. 2020-10-24 14:23:53 -04:00
Michael Natterer 2409b6f219 libgimp: manage boolean "save-comment" properties automatically
using the GimpProcedureConfig/GimpMetadata mechanism.
2019-10-10 01:30:29 +02:00
Michael Natterer 7f2995d568 libgimp: improve docs for gimp_image_metadata_save_prepare()/finish() 2019-10-10 00:05:49 +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