[gimp/metadata-wip-rebased] app: make sure the image's metadata always has the right properties



commit 77f9c3e8f1b5cb9febfe534c595b32b6bf751d12
Author: Michael Natterer <mitch gimp org>
Date:   Tue Oct 22 21:38:56 2013 +0200

    app: make sure the image's metadata always has the right properties

 app/core/gimpimage-metadata.c |   31 +++++++++++++++++++++++++-
 app/core/gimpimage.c          |   48 +++++++++++++++++++++++++++++++++-------
 2 files changed, 69 insertions(+), 10 deletions(-)
---
diff --git a/app/core/gimpimage-metadata.c b/app/core/gimpimage-metadata.c
index 24c6a56..9c8cc5e 100644
--- a/app/core/gimpimage-metadata.c
+++ b/app/core/gimpimage-metadata.c
@@ -62,7 +62,36 @@ gimp_image_set_metadata (GimpImage    *image,
       private->metadata = metadata;
 
       if (private->metadata)
-        g_object_ref (private->metadata);
+        {
+          gdouble xres, yres;
+
+          g_object_ref (private->metadata);
+
+          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;
+            }
+
+          gimp_image_get_resolution (image, &xres, &yres);
+          gimp_metadata_set_resolution (metadata, xres, yres,
+                                        gimp_image_get_unit (image));
+        }
 
       g_object_notify (G_OBJECT (image), "metadata");
     }
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index c20552a..62f37f7 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -168,12 +168,14 @@ static gchar  * gimp_image_get_description       (GimpViewable      *viewable,
 
 static void     gimp_image_real_mode_changed     (GimpImage         *image);
 static void     gimp_image_real_precision_changed(GimpImage         *image);
+static void     gimp_image_real_resolution_changed(GimpImage        *image);
 static void     gimp_image_real_size_changed_detailed
                                                  (GimpImage         *image,
                                                   gint               previous_origin_x,
                                                   gint               previous_origin_y,
                                                   gint               previous_width,
                                                   gint               previous_height);
+static void     gimp_image_real_unit_changed     (GimpImage         *image);
 static void     gimp_image_real_colormap_changed (GimpImage         *image,
                                                   gint               color_index);
 
@@ -555,9 +557,9 @@ gimp_image_class_init (GimpImageClass *klass)
   klass->component_visibility_changed = NULL;
   klass->component_active_changed     = NULL;
   klass->mask_changed                 = NULL;
-  klass->resolution_changed           = NULL;
+  klass->resolution_changed           = gimp_image_real_resolution_changed;
   klass->size_changed_detailed        = gimp_image_real_size_changed_detailed;
-  klass->unit_changed                 = NULL;
+  klass->unit_changed                 = gimp_image_real_unit_changed;
   klass->quick_mask_changed           = NULL;
   klass->selection_invalidate         = NULL;
 
@@ -1216,32 +1218,44 @@ gimp_image_real_precision_changed (GimpImage *image)
   metadata = gimp_image_get_metadata (image);
   if (metadata)
     {
-      gint bps = 8;
-
       switch (gimp_image_get_component_type (image))
         {
         case GIMP_COMPONENT_TYPE_U8:
-          bps = 8;
+          gimp_metadata_set_bits_per_sample (metadata, 8);
           break;
 
         case GIMP_COMPONENT_TYPE_U16:
         case GIMP_COMPONENT_TYPE_HALF:
-          bps = 16;
+          gimp_metadata_set_bits_per_sample (metadata, 16);
           break;
 
         case GIMP_COMPONENT_TYPE_U32:
         case GIMP_COMPONENT_TYPE_FLOAT:
-          bps = 32;
+          gimp_metadata_set_bits_per_sample (metadata, 32);
           break;
         }
-
-      gimp_metadata_set_bits_per_sample (metadata, bps);
     }
 
   gimp_projectable_structure_changed (GIMP_PROJECTABLE (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));
+    }
+}
+
+static void
 gimp_image_real_size_changed_detailed (GimpImage *image,
                                        gint       previous_origin_x,
                                        gint       previous_origin_y,
@@ -1256,6 +1270,22 @@ 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));
+    }
+}
+
+static void
 gimp_image_real_colormap_changed (GimpImage *image,
                                   gint       color_index)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]