[gimp/gimp-attributes-wip: 91/91] metadata/attributes corrections after merge
- From: Hartmut Kuhse <hartmutkuhse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-attributes-wip: 91/91] metadata/attributes corrections after merge
- Date: Sun, 18 Oct 2015 15:34:30 +0000 (UTC)
commit 029eae21bb3aa07522550609207916fb07de9e40
Author: Hartmut Kuhse <hk_priv gmx de>
Date: Sun Oct 18 13:10:47 2015 +0200
metadata/attributes corrections after merge
libgimp/gimpimagemetadata.c | 39 +++-----
libgimpbase/gimpattributes-image.c | 189 ++++++++++++++++++++++++++++++++++++
libgimpbase/gimpattributes-image.h | 46 ++++++---
libgimpbase/gimpbase.def | 4 +-
4 files changed, 236 insertions(+), 42 deletions(-)
---
diff --git a/libgimp/gimpimagemetadata.c b/libgimp/gimpimagemetadata.c
index 8370400..3468451 100644
--- a/libgimp/gimpimagemetadata.c
+++ b/libgimp/gimpimagemetadata.c
@@ -185,13 +185,6 @@ gimp_image_metadata_load_finish (gint32 image_ID,
gimp_image_set_unit (image_ID, unit);
}
}
-
- gimp_image_set_attributes (image_ID, attributes);
- if (layer_ID > 0)
- {
- gimp_item_set_attributes (layer_ID, attributes);
- }
-
}
if (flags & GIMP_METADATA_LOAD_COLORSPACE)
@@ -199,27 +192,21 @@ gimp_image_metadata_load_finish (gint32 image_ID,
GimpColorProfile *profile = gimp_image_get_color_profile (image_ID);
GimpAttribute *attribute = NULL;
- attribute = gimp_attributes_get_attribute (attributes, "Exif.Iop.InteroperabilityIndex");
- if (attribute)
- value = gimp_attribute_get_string (attribute);
- value = gexiv2_metadata_get_tag_interpreted_string (metadata,
- "Exif.Iop.InteroperabilityIndex");
-
- if (! g_strcmp0 (value, "R03"))
+ if (! profile)
{
- GimpMetadataColorspace colorspace;
+ GimpAttributesColorspace colorspace;
- colorspace = gimp_metadata_get_colorspace (metadata);
+ colorspace = gimp_attributes_get_colorspace (attributes);
switch (colorspace)
{
- case GIMP_METADATA_COLORSPACE_UNSPECIFIED:
- case GIMP_METADATA_COLORSPACE_UNCALIBRATED:
- case GIMP_METADATA_COLORSPACE_SRGB:
+ case GIMP_ATTRIBUTES_COLORSPACE_UNSPECIFIED:
+ case GIMP_ATTRIBUTES_COLORSPACE_UNCALIBRATED:
+ case GIMP_ATTRIBUTES_COLORSPACE_SRGB:
/* use sRGB, a NULL profile will do the right thing */
break;
- case GIMP_METADATA_COLORSPACE_ADOBERGB:
+ case GIMP_ATTRIBUTES_COLORSPACE_ADOBERGB:
profile = gimp_color_profile_new_adobe_rgb ();
break;
}
@@ -232,7 +219,13 @@ gimp_image_metadata_load_finish (gint32 image_ID,
g_object_unref (profile);
}
- g_object_unref (attributes);
+ gimp_image_set_attributes (image_ID, attributes);
+ if (layer_ID > 0)
+ {
+ gimp_item_set_attributes (layer_ID, attributes);
+ }
+
+ g_object_unref (attributes);
}
/**
@@ -242,7 +235,7 @@ gimp_image_metadata_load_finish (gint32 image_ID,
* @suggested_flags: Suggested default values for the @flags passed to
* gimp_image_metadata_save_finish()
*
- * Gets the image metadata for saving it using
+ * Gets the image attributes for saving using
* gimp_image_metadata_save_finish().
*
* The @suggested_flags are determined from what kind of metadata
@@ -250,7 +243,7 @@ gimp_image_metadata_load_finish (gint32 image_ID,
* value for GIMP_METADATA_SAVE_THUMBNAIL is determined by whether
* there was a thumbnail in the previously imported image.
*
- * Returns: The image's metadata, prepared for saving.
+ * Returns: The image's attributes, prepared for saving.
*
* Since: 2.10
*/
diff --git a/libgimpbase/gimpattributes-image.c b/libgimpbase/gimpattributes-image.c
index b8918fa..668bf48 100644
--- a/libgimpbase/gimpattributes-image.c
+++ b/libgimpbase/gimpattributes-image.c
@@ -280,3 +280,192 @@ gimp_attributes_set_pixel_size (GimpAttributes *attributes,
g_snprintf (buffer, sizeof (buffer), "%d", height);
gimp_attributes_new_attribute (attributes, "Exif.Image.ImageLength", buffer, TYPE_LONG);
}
+
+/**
+ * gimp_metadata_get_colorspace:
+ * @attributes: Ab #GimpAttributes instance.
+ *
+ * Returns values based on Exif.Photo.ColorSpace, Xmp.exif.ColorSpace,
+ * Exif.Iop.InteroperabilityIndex, Exif.Nikon3.ColorSpace,
+ * Exif.Canon.ColorSpace of @metadata.
+ *
+ * Return value: The colorspace specified by above tags.
+ *
+ * Since: 2.10
+ */
+GimpAttributesColorspace
+gimp_attributes_get_colorspace (GimpAttributes *attributes)
+{
+ glong exif_cs = -1;
+ GimpAttribute *attribute = NULL;
+ GValue val;
+
+ g_return_val_if_fail (GIMP_IS_ATTRIBUTES (attributes),
+ GIMP_ATTRIBUTES_COLORSPACE_UNSPECIFIED);
+
+ /* the logic here was mostly taken from darktable and libkexiv2 */
+
+ attribute = gimp_attributes_get_attribute (attributes, "Exif.Photo.ColorSpace");
+ if ( ! attribute)
+ {
+ attribute = gimp_attributes_get_attribute (attributes, "Xmp.exif.ColorSpace");
+ }
+
+ if (attribute)
+ {
+ if (gimp_attribute_get_value_type (attribute) == TYPE_LONG || gimp_attribute_get_value_type
(attribute) == TYPE_SLONG)
+ {
+ val = gimp_attribute_get_value (attribute);
+ exif_cs = g_value_get_long (&val);
+ }
+ }
+
+ if (exif_cs == 0x01)
+ {
+ return GIMP_ATTRIBUTES_COLORSPACE_SRGB;
+ }
+ else if (exif_cs == 0x02)
+ {
+ return GIMP_ATTRIBUTES_COLORSPACE_ADOBERGB;
+ }
+ else
+ {
+ if (exif_cs == 0xffff)
+ {
+ gchar *iop_index;
+
+ attribute = gimp_attributes_get_attribute (attributes, "Exif.Iop.InteroperabilityIndex");
+ if (attribute)
+ iop_index = gimp_attribute_get_string (attribute);
+
+ if (! g_strcmp0 (iop_index, "R03"))
+ {
+ g_free (iop_index);
+
+ return GIMP_ATTRIBUTES_COLORSPACE_ADOBERGB;
+ }
+ else if (! g_strcmp0 (iop_index, "R98"))
+ {
+ g_free (iop_index);
+
+ return GIMP_ATTRIBUTES_COLORSPACE_SRGB;
+ }
+
+ g_free (iop_index);
+ }
+
+ attribute = gimp_attributes_get_attribute (attributes, "Exif.Nikon3.ColorSpace");
+ if (attribute)
+ {
+ if (gimp_attribute_get_value_type (attribute) == TYPE_LONG || gimp_attribute_get_value_type
(attribute) == TYPE_SLONG)
+ {
+ glong nikon_cs;
+
+ val = gimp_attribute_get_value (attribute);
+ nikon_cs = g_value_get_long (&val);
+
+ if (nikon_cs == 0x01)
+ {
+ return GIMP_ATTRIBUTES_COLORSPACE_SRGB;
+ }
+ else if (nikon_cs == 0x02)
+ {
+ return GIMP_ATTRIBUTES_COLORSPACE_ADOBERGB;
+ }
+ }
+ }
+
+ attribute = gimp_attributes_get_attribute (attributes, "Exif.Canon.ColorSpace");
+ if (attribute)
+ {
+ if (gimp_attribute_get_value_type (attribute) == TYPE_LONG || gimp_attribute_get_value_type
(attribute) == TYPE_SLONG)
+ {
+ glong canon_cs;
+
+ val = gimp_attribute_get_value (attribute);
+ canon_cs = g_value_get_long (&val);
+
+ if (canon_cs == 0x01)
+ {
+ return GIMP_ATTRIBUTES_COLORSPACE_SRGB;
+ }
+ else if (canon_cs == 0x02)
+ {
+ return GIMP_ATTRIBUTES_COLORSPACE_ADOBERGB;
+ }
+ }
+ }
+
+ if (exif_cs == 0xffff)
+ return GIMP_ATTRIBUTES_COLORSPACE_UNCALIBRATED;
+ }
+
+ return GIMP_ATTRIBUTES_COLORSPACE_UNSPECIFIED;
+}
+
+/**
+ * gimp_metadata_set_colorspace:
+ * @metadata: A #GimpMetadata instance.
+ * @colorspace: The color space.
+ *
+ * Sets Exif.Photo.ColorSpace, Xmp.exif.ColorSpace,
+ * Exif.Iop.InteroperabilityIndex, Exif.Nikon3.ColorSpace,
+ * Exif.Canon.ColorSpace of @metadata.
+ *
+ * Since: 2.10
+ */
+void
+gimp_attributes_set_colorspace (GimpAttributes *attributes,
+ GimpAttributesColorspace colorspace)
+{
+ g_return_if_fail (GIMP_IS_ATTRIBUTES (attributes));
+
+ gimp_attributes_remove_attribute (attributes, "Exif.Photo.ColorSpace");
+ gimp_attributes_remove_attribute (attributes, "Xmp.exif.ColorSpace");
+ gimp_attributes_remove_attribute (attributes, "Exif.Iop.InteroperabilityIndex");
+
+ switch (colorspace)
+ {
+ case GIMP_ATTRIBUTES_COLORSPACE_UNSPECIFIED:
+ gimp_attributes_remove_attribute (attributes, "Exif.Nikon3.ColorSpace");
+ gimp_attributes_remove_attribute (attributes, "Exif.Canon.ColorSpace");
+ break;
+
+ case GIMP_ATTRIBUTES_COLORSPACE_UNCALIBRATED:
+ gimp_attributes_new_attribute (attributes, "Exif.Photo.ColorSpace", "0xffff", TYPE_LONG);
+ gimp_attributes_new_attribute (attributes, "Xmp.exif.ColorSpace", "0xffff", TYPE_LONG);
+ break;
+
+ case GIMP_ATTRIBUTES_COLORSPACE_SRGB:
+ gimp_attributes_new_attribute (attributes, "Exif.Photo.ColorSpace", "0x01", TYPE_LONG);
+ gimp_attributes_new_attribute (attributes, "Xmp.exif.ColorSpace", "0x01", TYPE_LONG);
+ gimp_attributes_new_attribute (attributes, "Exif.Iop.InteroperabilityIndex", "R98", TYPE_ASCII);
+ if (gimp_attributes_has_attribute (attributes, "Exif.Nikon3.ColorSpace"))
+ {
+ gimp_attributes_remove_attribute (attributes, "Exif.Nikon3.ColorSpace");
+ gimp_attributes_new_attribute (attributes, "Exif.Nikon3.ColorSpace", "0x01", TYPE_LONG);
+ }
+ if (gimp_attributes_has_attribute (attributes, "Exif.Canon.ColorSpace"))
+ {
+ gimp_attributes_remove_attribute (attributes, "Exif.Canon.ColorSpace");
+ gimp_attributes_new_attribute (attributes, "Exif.Canon.ColorSpace", "0x01", TYPE_LONG);
+ }
+ break;
+
+ case GIMP_ATTRIBUTES_COLORSPACE_ADOBERGB:
+ gimp_attributes_new_attribute (attributes, "Exif.Photo.ColorSpace", "0x02", TYPE_LONG);
+ gimp_attributes_new_attribute (attributes, "Xmp.exif.ColorSpace", "0x02", TYPE_LONG);
+ gimp_attributes_new_attribute (attributes, "Exif.Iop.InteroperabilityIndex", "R03", TYPE_ASCII);
+ if (gimp_attributes_has_attribute (attributes, "Exif.Nikon3.ColorSpace"))
+ {
+ gimp_attributes_remove_attribute (attributes, "Exif.Nikon3.ColorSpace");
+ gimp_attributes_new_attribute (attributes, "Exif.Nikon3.ColorSpace", "0x02", TYPE_LONG);
+ }
+ if (gimp_attributes_has_attribute (attributes, "Exif.Canon.ColorSpace"))
+ {
+ gimp_attributes_remove_attribute (attributes, "Exif.Canon.ColorSpace");
+ gimp_attributes_new_attribute (attributes, "Exif.Canon.ColorSpace", "0x02", TYPE_LONG);
+ }
+ break;
+ }
+}
diff --git a/libgimpbase/gimpattributes-image.h b/libgimpbase/gimpattributes-image.h
index 711a902..20157f3 100644
--- a/libgimpbase/gimpattributes-image.h
+++ b/libgimpbase/gimpattributes-image.h
@@ -25,23 +25,35 @@
G_BEGIN_DECLS
-gboolean gimp_attributes_get_resolution (GimpAttributes *attributes,
- gdouble *xres,
- gdouble *yres,
- GimpUnit *unit);
-
-void gimp_attributes_set_resolution (GimpAttributes *attributes,
- gdouble xres,
- gdouble yres,
- GimpUnit unit);
-
-void gimp_attributes_set_bits_per_sample (GimpAttributes *attributes,
- gint bps);
-
-void gimp_attributes_set_pixel_size (GimpAttributes *attributes,
- gint width,
- gint height);
-
+typedef enum
+{
+ GIMP_ATTRIBUTES_COLORSPACE_UNSPECIFIED,
+ GIMP_ATTRIBUTES_COLORSPACE_UNCALIBRATED,
+ GIMP_ATTRIBUTES_COLORSPACE_SRGB,
+ GIMP_ATTRIBUTES_COLORSPACE_ADOBERGB
+} GimpAttributesColorspace;
+
+gboolean gimp_attributes_get_resolution (GimpAttributes *attributes,
+ gdouble *xres,
+ gdouble *yres,
+ GimpUnit *unit);
+
+void gimp_attributes_set_resolution (GimpAttributes *attributes,
+ gdouble xres,
+ gdouble yres,
+ GimpUnit unit);
+
+void gimp_attributes_set_bits_per_sample (GimpAttributes *attributes,
+ gint bps);
+
+void gimp_attributes_set_pixel_size (GimpAttributes *attributes,
+ gint width,
+ gint height);
+
+GimpAttributesColorspace gimp_attributes_get_colorspace (GimpAttributes *attributes);
+
+void gimp_attributes_set_colorspace (GimpAttributes *attributes,
+ GimpAttributesColorspace colorspace);
G_END_DECLS
#endif
diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def
index a339991..53c51dc 100644
--- a/libgimpbase/gimpbase.def
+++ b/libgimpbase/gimpbase.def
@@ -29,6 +29,7 @@ EXPORTS
gimp_attributes_duplicate
gimp_attributes_from_metadata
gimp_attributes_get_attribute
+ gimp_attributes_get_colorspace
gimp_attributes_get_resolution
gimp_attributes_get_table
gimp_attributes_has_tag_type
@@ -41,6 +42,7 @@ EXPORTS
gimp_attributes_has_attribute
gimp_attributes_serialize
gimp_attributes_set_bits_per_sample
+ gimp_attributes_set_colorspace
gimp_attributes_set_pixel_size
gimp_attributes_set_resolution
gimp_attributes_size
@@ -112,8 +114,6 @@ EXPORTS
gimp_memsize_to_string
gimp_merge_type_get_type
gimp_message_handler_type_get_type
- gimp_metadata_deserialize
- gimp_metadata_duplicate
gimp_metadata_get_colorspace
gimp_metadata_get_resolution
gimp_metadata_is_tag_supported
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]