[gimp] app: consolidate all metadata syncing code into gimpimage-metadata.c
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: consolidate all metadata syncing code into gimpimage-metadata.c
- Date: Thu, 20 Jun 2019 14:18:58 +0000 (UTC)
commit b9829eddfe98b6ef34957cc728e48544bb4a9286
Author: Michael Natterer <mitch gimp org>
Date: Thu Jun 20 16:13:19 2019 +0200
app: consolidate all metadata syncing code into gimpimage-metadata.c
Add gimp_image_metadata_update_pixel_size(), _bits_per_sample(),
_resolution() and use them from gimp_image_set_metadata() and from
various places in gimpimage.c which had identical copies of the same
code.
Also add gimp_image_metadata_update_colorspace() which syncs the color
space stored in the image's metadata with the color space of the
image's actual color profile. Call the function from the right places.
The body of gimp_image_metadata_update_colorspace() is currently
disabled because the syncing of color space information is
controversial, see issue ##3532 and issue #301.
app/core/gimpimage-metadata.c | 146 +++++++++++++++++++++++++++++++++---------
app/core/gimpimage-metadata.h | 13 ++--
app/core/gimpimage.c | 66 +++----------------
3 files changed, 134 insertions(+), 91 deletions(-)
---
diff --git a/app/core/gimpimage-metadata.c b/app/core/gimpimage-metadata.c
index 71c490014e..9141e1513a 100644
--- a/app/core/gimpimage-metadata.c
+++ b/app/core/gimpimage-metadata.c
@@ -17,14 +17,17 @@
#include "config.h"
+#include <cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
+#include "libgimpcolor/gimpcolor.h"
#include "core-types.h"
#include "gimpimage.h"
+#include "gimpimage-color-profile.h"
#include "gimpimage-metadata.h"
#include "gimpimage-private.h"
#include "gimpimage-undo-push.h"
@@ -65,38 +68,121 @@ gimp_image_set_metadata (GimpImage *image,
if (private->metadata)
{
- gdouble xres, yres;
-
- gimp_metadata_set_pixel_size (metadata,
- gimp_image_get_width (image),
- gimp_image_get_height (image));
-
- switch (gimp_image_get_component_type (image))
- {
- case GIMP_COMPONENT_TYPE_U8:
- gimp_metadata_set_bits_per_sample (metadata, 8);
- break;
-
- case GIMP_COMPONENT_TYPE_U16:
- case GIMP_COMPONENT_TYPE_HALF:
- gimp_metadata_set_bits_per_sample (metadata, 16);
- break;
-
- case GIMP_COMPONENT_TYPE_U32:
- case GIMP_COMPONENT_TYPE_FLOAT:
- gimp_metadata_set_bits_per_sample (metadata, 32);
- break;
-
- case GIMP_COMPONENT_TYPE_DOUBLE:
- gimp_metadata_set_bits_per_sample (metadata, 64);
- break;
- }
-
- gimp_image_get_resolution (image, &xres, &yres);
- gimp_metadata_set_resolution (metadata, xres, yres,
- gimp_image_get_unit (image));
+ gimp_image_metadata_update_pixel_size (image);
+ gimp_image_metadata_update_bits_per_sample (image);
+ gimp_image_metadata_update_resolution (image);
+ gimp_image_metadata_update_colorspace (image);
}
g_object_notify (G_OBJECT (image), "metadata");
}
}
+
+void
+gimp_image_metadata_update_pixel_size (GimpImage *image)
+{
+ GimpMetadata *metadata;
+
+ g_return_if_fail (GIMP_IS_IMAGE (image));
+
+ metadata = gimp_image_get_metadata (image);
+
+ if (metadata)
+ {
+ gimp_metadata_set_pixel_size (metadata,
+ gimp_image_get_width (image),
+ gimp_image_get_height (image));
+ }
+}
+
+void
+gimp_image_metadata_update_bits_per_sample (GimpImage *image)
+{
+ GimpMetadata *metadata;
+
+ g_return_if_fail (GIMP_IS_IMAGE (image));
+
+ metadata = gimp_image_get_metadata (image);
+
+ if (metadata)
+ {
+ switch (gimp_image_get_component_type (image))
+ {
+ case GIMP_COMPONENT_TYPE_U8:
+ gimp_metadata_set_bits_per_sample (metadata, 8);
+ break;
+
+ case GIMP_COMPONENT_TYPE_U16:
+ case GIMP_COMPONENT_TYPE_HALF:
+ gimp_metadata_set_bits_per_sample (metadata, 16);
+ break;
+
+ case GIMP_COMPONENT_TYPE_U32:
+ case GIMP_COMPONENT_TYPE_FLOAT:
+ gimp_metadata_set_bits_per_sample (metadata, 32);
+ break;
+
+ case GIMP_COMPONENT_TYPE_DOUBLE:
+ gimp_metadata_set_bits_per_sample (metadata, 64);
+ break;
+ }
+ }
+}
+
+void
+gimp_image_metadata_update_resolution (GimpImage *image)
+{
+ GimpMetadata *metadata;
+
+ g_return_if_fail (GIMP_IS_IMAGE (image));
+
+ metadata = gimp_image_get_metadata (image);
+
+ if (metadata)
+ {
+ gdouble xres, yres;
+
+ gimp_image_get_resolution (image, &xres, &yres);
+ gimp_metadata_set_resolution (metadata, xres, yres,
+ gimp_image_get_unit (image));
+ }
+}
+
+void
+gimp_image_metadata_update_colorspace (GimpImage *image)
+{
+ GimpMetadata *metadata;
+
+ g_return_if_fail (GIMP_IS_IMAGE (image));
+
+ metadata = gimp_image_get_metadata (image);
+
+ if (metadata)
+ {
+ /* This seems to be controversial, see the discussions in issue
+ * #3532 and issue #301. Enable the code below to test the
+ * proposed syncing of color profile and DCF info.
+ */
+#if 0
+ GimpColorProfile *profile = gimp_image_get_color_profile (image);
+ GimpMetadataColorspace space = GIMP_METADATA_COLORSPACE_UNSPECIFIED;
+
+ if (profile)
+ {
+ static GimpColorProfile *adobe = NULL;
+
+ if (! adobe)
+ adobe = gimp_color_profile_new_rgb_adobe ();
+
+ if (gimp_color_profile_is_equal (profile, adobe))
+ space = GIMP_METADATA_COLORSPACE_ADOBERGB;
+ }
+ else
+ {
+ space = GIMP_METADATA_COLORSPACE_SRGB;
+ }
+
+ gimp_metadata_set_colorspace (metadata, space);
+#endif
+ }
+}
diff --git a/app/core/gimpimage-metadata.h b/app/core/gimpimage-metadata.h
index 03eaf13914..2a74be8c88 100644
--- a/app/core/gimpimage-metadata.h
+++ b/app/core/gimpimage-metadata.h
@@ -19,10 +19,15 @@
#define __GIMP_IMAGE_METADATA_H__
-GimpMetadata * gimp_image_get_metadata (GimpImage *image);
-void gimp_image_set_metadata (GimpImage *image,
- GimpMetadata *metadata,
- gboolean push_undo);
+GimpMetadata * gimp_image_get_metadata (GimpImage *image);
+void gimp_image_set_metadata (GimpImage *image,
+ GimpMetadata *metadata,
+ gboolean push_undo);
+
+void gimp_image_metadata_update_pixel_size (GimpImage *image);
+void gimp_image_metadata_update_bits_per_sample (GimpImage *image);
+void gimp_image_metadata_update_resolution (GimpImage *image);
+void gimp_image_metadata_update_colorspace (GimpImage *image);
#endif /* __GIMP_IMAGE_METADATA_H__ */
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index deb0bc43e3..e3dfb7435d 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -1204,10 +1204,9 @@ gimp_image_get_size (GimpViewable *viewable,
static void
gimp_image_size_changed (GimpViewable *viewable)
{
- GimpImage *image = GIMP_IMAGE (viewable);
- GimpMetadata *metadata;
- GList *all_items;
- GList *list;
+ GimpImage *image = GIMP_IMAGE (viewable);
+ GList *all_items;
+ GList *list;
if (GIMP_VIEWABLE_CLASS (parent_class)->size_changed)
GIMP_VIEWABLE_CLASS (parent_class)->size_changed (viewable);
@@ -1232,11 +1231,7 @@ gimp_image_size_changed (GimpViewable *viewable)
gimp_viewable_size_changed (GIMP_VIEWABLE (gimp_image_get_mask (image)));
- metadata = gimp_image_get_metadata (image);
- if (metadata)
- gimp_metadata_set_pixel_size (metadata,
- gimp_image_get_width (image),
- gimp_image_get_height (image));
+ gimp_image_metadata_update_pixel_size (image);
gimp_projectable_structure_changed (GIMP_PROJECTABLE (image));
}
@@ -1264,32 +1259,7 @@ gimp_image_real_mode_changed (GimpImage *image)
static void
gimp_image_real_precision_changed (GimpImage *image)
{
- GimpMetadata *metadata;
-
- metadata = gimp_image_get_metadata (image);
- if (metadata)
- {
- switch (gimp_image_get_component_type (image))
- {
- case GIMP_COMPONENT_TYPE_U8:
- gimp_metadata_set_bits_per_sample (metadata, 8);
- break;
-
- case GIMP_COMPONENT_TYPE_U16:
- case GIMP_COMPONENT_TYPE_HALF:
- gimp_metadata_set_bits_per_sample (metadata, 16);
- break;
-
- case GIMP_COMPONENT_TYPE_U32:
- case GIMP_COMPONENT_TYPE_FLOAT:
- gimp_metadata_set_bits_per_sample (metadata, 32);
- break;
-
- case GIMP_COMPONENT_TYPE_DOUBLE:
- gimp_metadata_set_bits_per_sample (metadata, 64);
- break;
- }
- }
+ gimp_image_metadata_update_bits_per_sample (image);
gimp_projectable_structure_changed (GIMP_PROJECTABLE (image));
}
@@ -1297,17 +1267,7 @@ gimp_image_real_precision_changed (GimpImage *image)
static void
gimp_image_real_resolution_changed (GimpImage *image)
{
- GimpMetadata *metadata;
-
- metadata = gimp_image_get_metadata (image);
- if (metadata)
- {
- gdouble xres, yres;
-
- gimp_image_get_resolution (image, &xres, &yres);
- gimp_metadata_set_resolution (metadata, xres, yres,
- gimp_image_get_unit (image));
- }
+ gimp_image_metadata_update_resolution (image);
}
static void
@@ -1327,17 +1287,7 @@ gimp_image_real_size_changed_detailed (GimpImage *image,
static void
gimp_image_real_unit_changed (GimpImage *image)
{
- GimpMetadata *metadata;
-
- metadata = gimp_image_get_metadata (image);
- if (metadata)
- {
- gdouble xres, yres;
-
- gimp_image_get_resolution (image, &xres, &yres);
- gimp_metadata_set_resolution (metadata, xres, yres,
- gimp_image_get_unit (image));
- }
+ gimp_image_metadata_update_resolution (image);
}
static void
@@ -1387,6 +1337,8 @@ gimp_image_color_managed_profile_changed (GimpColorManaged *managed)
GimpImage *image = GIMP_IMAGE (managed);
GimpItemStack *layers = GIMP_ITEM_STACK (gimp_image_get_layers (image));
+ gimp_image_metadata_update_colorspace (image);
+
gimp_projectable_structure_changed (GIMP_PROJECTABLE (image));
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (image));
gimp_item_stack_profile_changed (layers);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]