Index: libeog/Makefile.am =================================================================== RCS file: /cvs/gnome/eog/libeog/Makefile.am,v retrieving revision 1.44 diff -u -r1.44 Makefile.am --- libeog/Makefile.am 21 Mar 2005 20:59:37 -0000 1.44 +++ libeog/Makefile.am 12 Jun 2005 11:52:47 -0000 @@ -118,7 +118,7 @@ -leog \ $(jpeg_LIB) \ $(X_LIBS) \ - $(EOG_LIBS) + $(EOG_LIBS) -llcms test_image_load_DEPENDENCIES = libeog.a @@ -130,7 +130,7 @@ -leog \ $(jpeg_LIB) \ $(X_LIBS) \ - $(EOG_LIBS) + $(EOG_LIBS) -llcms CLEANFILES = $(BUILT_SOURCES) Index: libeog/eog-image-private.h =================================================================== RCS file: /cvs/gnome/eog/libeog/eog-image-private.h,v retrieving revision 1.11 diff -u -r1.11 eog-image-private.h --- libeog/eog-image-private.h 14 Mar 2005 20:35:13 -0000 1.11 +++ libeog/eog-image-private.h 12 Jun 2005 11:52:47 -0000 @@ -6,7 +6,7 @@ #include #endif #include "eog-image.h" - +#include typedef enum { EOG_IMAGE_STATUS_UNKNOWN, @@ -36,7 +36,8 @@ * either of these are not NULL: */ #endif - + cmsHPROFILE profile; + gint thumbnail_id; gboolean modified; Index: libeog/eog-image.c =================================================================== RCS file: /cvs/gnome/eog/libeog/eog-image.c,v retrieving revision 1.47 diff -u -r1.47 eog-image.c --- libeog/eog-image.c 10 May 2005 19:04:44 -0000 1.47 +++ libeog/eog-image.c 12 Jun 2005 11:52:47 -0000 @@ -26,6 +26,8 @@ #include "eog-image-jpeg.h" #endif +#include + enum { SIGNAL_LOADING_UPDATE, SIGNAL_LOADING_SIZE_PREPARED, @@ -252,6 +254,7 @@ #if HAVE_EXIF priv->exif = NULL; #endif + priv->profile = NULL; priv->data_ref_count = 0; img->priv = priv; @@ -679,8 +682,93 @@ if (format != NULL) { priv->file_type = gdk_pixbuf_format_get_name (format); } + + /* Perform the colour transformation */ + { + ExifEntry *entry; + const ExifByteOrder o = exif_data_get_byte_order (priv->exif); + + if (priv->exif == NULL) goto what_a_hack; + + entry = exif_content_get_entry (priv->exif->ifd [EXIF_IFD_EXIF], EXIF_TAG_COLOR_SPACE); + if (entry && exif_get_short (entry->data, o) != 1) { +#if 1 + cmsCIExyY whitepoint; + cmsCIExyYTRIPLE primaries; + LPGAMMATABLE gamma[3]; + + const int offset = exif_format_get_size (EXIF_FORMAT_RATIONAL); + ExifRational r; + + entry = exif_content_get_entry (priv->exif->ifd [EXIF_IFD_0], EXIF_TAG_WHITE_POINT); + if (entry && entry->components == 2) { + r = exif_get_rational (entry->data, o); + whitepoint.x = (double)r.numerator/r.denominator; + r = exif_get_rational (entry->data + offset, o); + whitepoint.y = (double)r.numerator/r.denominator; + whitepoint.Y = 1.0; + } else { + g_printerr("No whitepoint found\n"); + } + + entry = exif_content_get_entry (priv->exif->ifd [EXIF_IFD_0], EXIF_TAG_PRIMARY_CHROMATICITIES); + if (entry && entry->components == 6) { + r = exif_get_rational (entry->data + 0 * offset, o); + primaries.Red.x = (double)r.numerator/r.denominator; + r = exif_get_rational (entry->data + 1 * offset, o); + primaries.Red.y = (double)r.numerator/r.denominator; + + r = exif_get_rational (entry->data + 2 * offset, o); + primaries.Green.x = (double)r.numerator/r.denominator; + r = exif_get_rational (entry->data + 3 * offset, o); + primaries.Green.y = (double)r.numerator/r.denominator; + + r = exif_get_rational (entry->data + 4 * offset, o); + primaries.Blue.x = (double)r.numerator/r.denominator; + r = exif_get_rational (entry->data + 5 * offset, o); + primaries.Blue.y = (double)r.numerator/r.denominator; + + primaries.Red.Y = primaries.Green.Y = primaries.Blue.Y = 1.0; + } else { + g_printerr("No primary chromaticities found\n"); + } + + /* Assume gamma 2.2...? */ + gamma[0] = gamma[1] = gamma[2] = cmsBuildGamma(256, 2.2); + + priv->profile = cmsCreateRGBProfile(&whitepoint, &primaries, gamma); + cmsFreeGamma(gamma[0]); +#else + g_printerr("Loading AdobeRGB profile\n"); + priv->profile = cmsOpenProfileFromFile("/home/ross/tmp/ICM/AdobeRGB.icm", "r"); +#endif + } + } + + if (priv->profile) { + cmsHPROFILE *srgb; + cmsHTRANSFORM transform; + int row; + int width, rows, stride; + guchar *pixels, *p; + + srgb = cmsCreate_sRGBProfile(); + transform = cmsCreateTransform(priv->profile, TYPE_RGB_8, srgb, TYPE_RGB_8, INTENT_PERCEPTUAL, 0); + + /* Do on rows */ + rows = gdk_pixbuf_get_height(priv->image); + width = gdk_pixbuf_get_width (priv->image); + stride = gdk_pixbuf_get_rowstride (priv->image); + pixels = gdk_pixbuf_get_pixels (priv->image); + for (row = 0; row < rows; ++row) { + p = pixels + (row * stride); + cmsDoTransform(transform, p, p, width); + } + cmsDeleteTransform(transform); + cmsCloseProfile(srgb); + } } - + what_a_hack: /* clean up */ g_object_unref (loader); if (md_reader != NULL) { @@ -844,6 +932,15 @@ return image; } +cmsHPROFILE +eog_image_get_profile (EogImage *img) +{ + g_return_val_if_fail (EOG_IS_IMAGE (img), NULL); + + return img->priv->profile; +} + + GdkPixbuf* eog_image_get_pixbuf_thumbnail (EogImage *img) { @@ -1460,6 +1557,10 @@ } priv->exif_chunk_len = 0; + if (priv->profile != NULL) { + cmsCloseProfile (priv->profile); + } + priv->status = EOG_IMAGE_STATUS_UNKNOWN; } } Index: libeog/eog-image.h =================================================================== RCS file: /cvs/gnome/eog/libeog/eog-image.h,v retrieving revision 1.21 diff -u -r1.21 eog-image.h --- libeog/eog-image.h 14 Mar 2005 20:35:13 -0000 1.21 +++ libeog/eog-image.h 12 Jun 2005 11:52:47 -0000 @@ -5,6 +5,7 @@ #include #include #include +#include #include "eog-transform.h" #include "eog-image-save-info.h" #include "eog-job.h" @@ -114,6 +115,7 @@ GnomeVFSURI* eog_image_get_uri (EogImage *img); gchar* eog_image_get_uri_for_display (EogImage *img); gboolean eog_image_has_metadata (EogImage *img); +cmsHPROFILE eog_image_get_profile (EogImage *img); /* modification API */ void eog_image_transform (EogImage *img, EogTransform *trans, EogJob *job); Index: shell/Makefile.am =================================================================== RCS file: /cvs/gnome/eog/shell/Makefile.am,v retrieving revision 1.33 diff -u -r1.33 Makefile.am --- shell/Makefile.am 23 Oct 2004 12:10:32 -0000 1.33 +++ shell/Makefile.am 12 Jun 2005 11:52:47 -0000 @@ -42,7 +42,8 @@ $(jpeg_LIB) \ $(POPT_LIBS) \ $(X_LIBS) \ - $(EOG_LIBS) + $(EOG_LIBS) \ + -llcms uidir = $(datadir)/eog UI_FILES = eog-gtk-ui.xml