Index: plug-ins/jpeg/jpeg-load.c
===================================================================
--- plug-ins/jpeg/jpeg-load.c	(revision 24236)
+++ plug-ins/jpeg/jpeg-load.c	(working copy)
@@ -380,16 +380,26 @@ load_image (const gchar *filename,
         {
           cmyk_transform = jpeg_load_cmyk_transform (profile, profile_size);
         }
-      else if (profile) /* don't attach the profile if we are transforming */
+      else /* don't attach the profile if we are transforming */
         {
-          GimpParasite *parasite;
+#ifdef HAVE_EXIF
+          if (! profile && exif_data)
+            {
+              jpeg_exif_get_color_space (exif_data, &profile, &profile_size);
+            }
+#endif
 
-          parasite = gimp_parasite_new ("icc-profile",
-                                        GIMP_PARASITE_PERSISTENT |
-                                        GIMP_PARASITE_UNDOABLE,
-                                        profile_size, profile);
-          gimp_image_parasite_attach (image_ID, parasite);
-          gimp_parasite_free (parasite);
+          if (profile)
+            {
+              GimpParasite *parasite;
+
+              parasite = gimp_parasite_new ("icc-profile",
+                                            GIMP_PARASITE_PERSISTENT |
+                                            GIMP_PARASITE_UNDOABLE,
+                                            profile_size, profile);
+              gimp_image_parasite_attach (image_ID, parasite);
+              gimp_parasite_free (parasite);
+            }
         }
 
       g_free (profile);
Index: plug-ins/jpeg/jpeg-exif.c
===================================================================
--- plug-ins/jpeg/jpeg-exif.c	(revision 24236)
+++ plug-ins/jpeg/jpeg-exif.c	(working copy)
@@ -39,6 +39,14 @@
 
 #define EXIF_HEADER_SIZE 8
 
+#ifdef HAVE_LCMS
+#ifdef HAVE_LCMS_LCMS_H
+#include <lcms/lcms.h>
+#else
+#include <lcms.h>
+#endif
+#endif
+
 #include <libgimp/gimp.h>
 #include <libgimp/gimpui.h>
 
@@ -86,10 +94,8 @@ jpeg_exif_data_new_from_file (const gcha
 gint
 jpeg_exif_get_orientation (ExifData *exif_data)
 {
-  ExifEntry *entry;
-  gint       byte_order;
-
-  byte_order = exif_data_get_byte_order (exif_data);
+  ExifEntry  *entry;
+  const gint  byte_order = exif_data_get_byte_order (exif_data);
 
   /* get orientation and rotate image accordingly if necessary */
   if ((entry = exif_content_get_entry (exif_data->ifd[EXIF_IFD_0],
@@ -97,9 +103,106 @@ jpeg_exif_get_orientation (ExifData *exi
     {
       return exif_get_short (entry->data, byte_order);
     }
+
   return 0;
 }
 
+/*  Retrieve the Exif ColorSpace information as ICC profile  */
+gboolean
+jpeg_exif_get_color_space (ExifData  *exif_data,
+                           guchar   **profile_data,
+                           gsize     *profile_len)
+{
+#ifdef HAVE_LCMS
+  ExifEntry   *entry;
+  cmsHPROFILE  profile    = NULL;
+  const gint   byte_order = exif_data_get_byte_order (exif_data);
+
+  entry = exif_content_get_entry (exif_data->ifd [EXIF_IFD_EXIF],
+                                  EXIF_TAG_COLOR_SPACE);
+
+  if (entry && exif_get_short (entry->data, byte_order) != 1)
+    {
+      cmsCIExyY        whitepoint;
+      cmsCIExyYTRIPLE  primaries;
+      LPGAMMATABLE     gamma[3];
+      const int        offset = exif_format_get_size (EXIF_FORMAT_RATIONAL);
+
+      entry = exif_content_get_entry (exif_data->ifd [EXIF_IFD_0],
+                                      EXIF_TAG_WHITE_POINT);
+
+      if (entry && entry->components == 2)
+        {
+          ExifRational r;
+
+          r = exif_get_rational (entry->data, byte_order);
+          whitepoint.x = (gdouble) r.numerator / r.denominator;
+
+          r = exif_get_rational (entry->data + offset, byte_order);
+          whitepoint.y = (gdouble) r.numerator / r.denominator;
+
+          whitepoint.Y = 1.0;
+        }
+      else
+        {
+          return FALSE;
+        }
+
+      entry = exif_content_get_entry (exif_data->ifd [EXIF_IFD_0],
+                                      EXIF_TAG_PRIMARY_CHROMATICITIES);
+      if (entry && entry->components == 6)
+        {
+          ExifRational r;
+
+          r = exif_get_rational (entry->data + 0 * offset, byte_order);
+          primaries.Red.x = (gdouble) r.numerator / r.denominator;
+
+          r = exif_get_rational (entry->data + 1 * offset, byte_order);
+          primaries.Red.y = (gdouble) r.numerator / r.denominator;
+
+          r = exif_get_rational (entry->data + 2 * offset, byte_order);
+          primaries.Green.x = (gdouble) r.numerator / r.denominator;
+
+          r = exif_get_rational (entry->data + 3 * offset, byte_order);
+          primaries.Green.y = (gdouble) r.numerator / r.denominator;
+
+          r = exif_get_rational (entry->data + 4 * offset, byte_order);
+          primaries.Blue.x = (gdouble) r.numerator / r.denominator;
+
+          r = exif_get_rational (entry->data + 5 * offset, byte_order);
+          primaries.Blue.y = (gdouble) r.numerator / r.denominator;
+
+          primaries.Red.Y = primaries.Green.Y = primaries.Blue.Y = 1.0;
+        }
+      else
+        {
+          return FALSE;
+        }
+
+      gamma[0] = gamma[1] = gamma[2] = cmsBuildGamma(256, 2.2);
+
+      profile = cmsCreateRGBProfile (&whitepoint, &primaries, gamma);
+
+      cmsFreeGamma (gamma[0]);
+    }
+
+  if (profile)
+    {
+      _cmsSaveProfileToMem (profile, NULL, profile_len);
+
+      *profile_data = g_malloc (*profile_len);
+
+      _cmsSaveProfileToMem (profile, *profile_data, profile_len);
+
+      cmsCloseProfile (profile);
+
+      return TRUE;
+    }
+
+#endif /* HAVE_LCMS */
+
+  return FALSE;
+}
 
 void
 jpeg_setup_exif_for_save (ExifData     *exif_data,
@@ -108,7 +211,7 @@ jpeg_setup_exif_for_save (ExifData     *
   ExifRational  r;
   gdouble       xres, yres;
   ExifEntry    *entry;
-  gint          byte_order = exif_data_get_byte_order (exif_data);
+  const gint    byte_order = exif_data_get_byte_order (exif_data);
 
   /* set orientation to top - left */
   if ((entry = exif_content_get_entry (exif_data->ifd[EXIF_IFD_0],
@@ -144,7 +247,7 @@ jpeg_setup_exif_for_save (ExifData     *
   if ((entry = exif_content_get_entry (exif_data->ifd[EXIF_IFD_0],
                                        EXIF_TAG_SOFTWARE)))
     {
-      const gchar *name = "GIMP " GIMP_VERSION;
+      const gchar name[] = "GIMP " GIMP_VERSION;
 
       entry->data = (guchar *) g_strdup (name);
       entry->size = strlen (name) + 1;
Index: plug-ins/jpeg/jpeg-icc.c
===================================================================
--- plug-ins/jpeg/jpeg-icc.c	(revision 24236)
+++ plug-ins/jpeg/jpeg-icc.c	(working copy)
@@ -261,3 +261,4 @@ jpeg_icc_read_profile (j_decompress_ptr 
 
   return TRUE;
 }
+
Index: plug-ins/jpeg/jpeg.h
===================================================================
--- plug-ins/jpeg/jpeg.h	(revision 24236)
+++ plug-ins/jpeg/jpeg.h	(working copy)
@@ -76,6 +76,9 @@ ExifData * jpeg_exif_data_new_from_file 
                                          GError       **error);
 
 gint      jpeg_exif_get_orientation     (ExifData      *exif_data);
+gboolean  jpeg_exif_get_color_space     (ExifData      *exif_data,
+                                         guchar       **profile_data,
+                                         gsize         *profile_len);
 
 void      jpeg_setup_exif_for_save      (ExifData      *exif_data,
                                          const gint32   image_ID);
