[Rawstudio-commit] r4144 - in trunk: . librawstudio plugins/colorspace-transform plugins/load-dcraw plugins/load-gdk plugins/meta-x3f src

Klaus Post klauspost at gmail.com
Sat Feb 18 11:21:44 CET 2012


Author: post
Date: 2012-02-18 11:21:44 +0100 (Sat, 18 Feb 2012)
New Revision: 4144

Modified:
   trunk/configure.in
   trunk/librawstudio/rs-settings.c
   trunk/plugins/colorspace-transform/Makefile.am
   trunk/plugins/colorspace-transform/rs-cmm.c
   trunk/plugins/load-dcraw/Makefile.am
   trunk/plugins/load-dcraw/dcraw.cc
   trunk/plugins/load-gdk/Makefile.am
   trunk/plugins/load-gdk/load-gdk.c
   trunk/plugins/meta-x3f/x3f-meta.c
   trunk/src/application.c
   trunk/src/rs-cache.c
   trunk/src/rs-preview-widget.c
   trunk/src/rs-preview-widget.h
Log:


Modified: trunk/configure.in
===================================================================
--- trunk/configure.in	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/configure.in	2012-02-18 10:21:44 UTC (rev 4144)
@@ -100,9 +100,9 @@
 AC_SUBST(LENSFUN_CFLAGS)
 AC_SUBST(LENSFUN_LIBS)
 
-PKG_CHECK_MODULES(LCMS, [lcms])
-AC_SUBST(LCMS_CFLAGS)
-AC_SUBST(LCMS_LIBS)
+PKG_CHECK_MODULES(LCMS2, [lcms2])
+AC_SUBST(LCMS2_CFLAGS)
+AC_SUBST(LCMS2_LIBS)
 
 PKG_CHECK_MODULES(LIBGPHOTO2, [libgphoto2])
 AC_SUBST(LIBGPHOTO2_CFLAGS)

Modified: trunk/librawstudio/rs-settings.c
===================================================================
--- trunk/librawstudio/rs-settings.c	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/librawstudio/rs-settings.c	2012-02-18 10:21:44 UTC (rev 4144)
@@ -115,7 +115,7 @@
 		PROP_DCP_TEMP, g_param_spec_float(
 			/* @TRANSLATORS: "Temp" is short version of "Temperature". You cannot use more than 5 characters for this! */
 			"dcp-temp", _("Temp"), _("Temperature"),
-			2000.0, 12000.0, 5000.0, G_PARAM_READWRITE)
+			1700.0, 60000.0, 5000.0, G_PARAM_READWRITE)
 	);
 	g_object_class_install_property(object_class,
 		PROP_DCP_TINT, g_param_spec_float(

Modified: trunk/plugins/colorspace-transform/Makefile.am
===================================================================
--- trunk/plugins/colorspace-transform/Makefile.am	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/plugins/colorspace-transform/Makefile.am	2012-02-18 10:21:44 UTC (rev 4144)
@@ -9,7 +9,7 @@
 INCLUDES = \
 	-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
 	-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
-	@PACKAGE_CFLAGS@ @LCMS_CFLAGS@ \
+	@PACKAGE_CFLAGS@ @LCMS2_CFLAGS@ \
 	-I$(top_srcdir)/librawstudio/ \
 	-I$(top_srcdir)/
 
@@ -17,7 +17,7 @@
 
 libdir = $(datadir)/rawstudio/plugins/
 
-colorspace_transform_la_LIBADD = @PACKAGE_LIBS@ @LCMS_LIBS@ colorspace_transform_avx.lo colorspace_transform_sse2.lo rs-cmm.lo colorspace_transform-c.lo
+colorspace_transform_la_LIBADD = @PACKAGE_LIBS@ @LCMS2_LIBS@ colorspace_transform_avx.lo colorspace_transform_sse2.lo rs-cmm.lo colorspace_transform-c.lo
 colorspace_transform_la_LDFLAGS = -module -avoid-version
 colorspace_transform_la_SOURCES = 
 

Modified: trunk/plugins/colorspace-transform/rs-cmm.c
===================================================================
--- trunk/plugins/colorspace-transform/rs-cmm.c	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/plugins/colorspace-transform/rs-cmm.c	2012-02-18 10:21:44 UTC (rev 4144)
@@ -17,7 +17,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
-#include <lcms.h>
+#include <lcms2.h>
+#include <math.h>
+#include <stdlib.h>
 #include "rs-cmm.h"
 
 static gushort gammatable22[65536];
@@ -41,6 +43,7 @@
 	cmsHTRANSFORM lcms_transform8;
 	cmsHTRANSFORM lcms_transform16;
 	const GdkRectangle *roi;
+	gboolean is_gamma_corrected;
 };
 
 G_DEFINE_TYPE (RSCmm, rs_cmm, G_TYPE_OBJECT)
@@ -170,29 +173,59 @@
 		gushort *in = GET_PIXEL(input, start_x, y);
 		gushort *out = GET_PIXEL(output, start_x, y);
 		gushort *buffer_pointer = buffer;
-		for(x=start_x; x<end_x;x++)
+		if (cmm->is_gamma_corrected)
 		{
-			register gfloat r = (gfloat) MIN(*in, cmm->clip[R]); in++;
-			register gfloat g = (gfloat) MIN(*in, cmm->clip[G]); in++;
-			register gfloat b = (gfloat) MIN(*in, cmm->clip[B]); in++;
-			in++;
+			for(x=start_x; x<end_x;x++)
+			{
+				register gfloat r = (gfloat) MIN(*in, cmm->clip[R]); in++;
+				register gfloat g = (gfloat) MIN(*in, cmm->clip[G]); in++;
+				register gfloat b = (gfloat) MIN(*in, cmm->clip[B]); in++;
+				in++;
 
-			r = MIN(r, cmm->clip[R]);
-			g = MIN(g, cmm->clip[G]);
-			b = MIN(b, cmm->clip[B]);
+				r = MIN(r, cmm->clip[R]);
+				g = MIN(g, cmm->clip[G]);
+				b = MIN(b, cmm->clip[B]);
 
-			r = r * cmm->premul[R];
-			g = g * cmm->premul[G];
-			b = b * cmm->premul[B];
+				r = r * cmm->premul[R];
+				g = g * cmm->premul[G];
+				b = b * cmm->premul[B];
 
-			r = MIN(r, 65535.0);
-			g = MIN(g, 65535.0);
-			b = MIN(b, 65535.0);
+				r = MIN(r, 65535.0);
+				g = MIN(g, 65535.0);
+				b = MIN(b, 65535.0);
 
-			*(buffer_pointer++) = (gushort) r;
-			*(buffer_pointer++) = (gushort) g;
-			*(buffer_pointer++) = (gushort) b;
-			buffer_pointer++;
+				*(buffer_pointer++) = gammatable22[(gushort) r];
+				*(buffer_pointer++) = gammatable22[(gushort) g];
+				*(buffer_pointer++) = gammatable22[(gushort) b];
+				buffer_pointer++;
+			}
+		} 
+		else
+		{
+			for(x=start_x; x<end_x;x++)
+			{
+				register gfloat r = (gfloat) MIN(*in, cmm->clip[R]); in++;
+				register gfloat g = (gfloat) MIN(*in, cmm->clip[G]); in++;
+				register gfloat b = (gfloat) MIN(*in, cmm->clip[B]); in++;
+				in++;
+
+				r = MIN(r, cmm->clip[R]);
+				g = MIN(g, cmm->clip[G]);
+				b = MIN(b, cmm->clip[B]);
+
+				r = r * cmm->premul[R];
+				g = g * cmm->premul[G];
+				b = b * cmm->premul[B];
+
+				r = MIN(r, 65535.0);
+				g = MIN(g, 65535.0);
+				b = MIN(b, 65535.0);
+
+				*(buffer_pointer++) = (gushort) r;
+				*(buffer_pointer++) = (gushort) g;
+				*(buffer_pointer++) = (gushort) b;
+				buffer_pointer++;
+			}
 		}
 		cmsDoTransform(cmm->lcms_transform16, buffer, out, w);
 	}
@@ -218,8 +251,9 @@
 		guchar *out = GET_PIXBUF_PIXEL(output, start_x, y);
 		cmsDoTransform(cmm->lcms_transform8, in, out, w);
 		/* Set alpha */
+		guint *outi = (guint*) out;
 		for (i = 0; i < w; i++)
-			out[i*4+3] = 0xff;
+			outi[i] &= 0xff000000;
 	}
 }
 
@@ -285,9 +319,9 @@
 
 	g_free(t);
 }
-
+#if 0
 static guchar *
-pack_rgb_w4(void *info, register WORD wOut[], register LPBYTE output)
+pack_rgb_w4(void *info, register cmsUInt16Number wOut[], register LPBYTE output)
 {
 	*(LPWORD) output = wOut[0]; output+= 2;
 	*(LPWORD) output = wOut[1]; output+= 2;
@@ -315,7 +349,7 @@
 
 	return(accum);
 }
-
+#endif
 static void
 load_profile(RSCmm *cmm, const RSIccProfile *profile, const RSIccProfile **profile_target, cmsHPROFILE *lcms_target)
 {
@@ -399,10 +433,11 @@
 			{0.115, 0.826, 0.724938},
 			{0.157, 0.018, 0.016875}};
 		cmsCIExyY D65;
-		LPGAMMATABLE gamma[3];
+		cmsToneCurve* gamma[3];
+		gint context = 1337;
 
-		cmsWhitePointFromTemp(6504, &D65);
-		gamma[0] = gamma[1] = gamma[2] = cmsBuildGamma(2,1.0);
+		cmsWhitePointFromTemp(&D65, 6504);
+		gamma[0] = gamma[1] = gamma[2] = cmsBuildGamma(&context,1.0);
 		linear = cmsCreateRGBProfile(&D65, &srgb_primaries, gamma);
 	}
 	g_mutex_unlock(is_profile_gamma_22_corrected_linear_lock);
@@ -436,15 +471,17 @@
 		cmsDeleteTransform(cmm->lcms_transform16);
 
 	cmm->lcms_transform16 = cmsCreateTransform(
-		cmm->lcms_input_profile, TYPE_RGB_16,
-		cmm->lcms_output_profile, TYPE_RGB_16,
-		INTENT_PERCEPTUAL, 0);
+		cmm->lcms_input_profile, TYPE_RGBA_16,
+		cmm->lcms_output_profile, TYPE_RGBA_16,
+		INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
 
 	g_warn_if_fail(cmm->lcms_transform16 != NULL);
 
 	/* Enable packing/unpacking for pixelsize==4 */
 	/* If we estimate that the input profile will apply gamma correction,
 	   we try to undo it in 16 bit transform */
+	cmm->is_gamma_corrected = is_profile_gamma_22_corrected(cmm->lcms_input_profile);
+/*
 	if (is_profile_gamma_22_corrected(cmm->lcms_input_profile))
 		cmsSetUserFormatters(cmm->lcms_transform16,
 			TYPE_RGB_16, unroll_rgb_w4_gammatable22,
@@ -453,6 +490,6 @@
 		cmsSetUserFormatters(cmm->lcms_transform16,
 			TYPE_RGB_16, unroll_rgb_w4,
 			TYPE_RGB_16, pack_rgb_w4);
-
+*/
 	cmm->dirty16 = FALSE;
 }

Modified: trunk/plugins/load-dcraw/Makefile.am
===================================================================
--- trunk/plugins/load-dcraw/Makefile.am	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/plugins/load-dcraw/Makefile.am	2012-02-18 10:21:44 UTC (rev 4144)
@@ -12,7 +12,7 @@
 INCLUDES = \
 	-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
 	-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
-	@PACKAGE_CFLAGS@ @LCMS_CFLAGS@\
+	@PACKAGE_CFLAGS@ @LCMS2_CFLAGS@\
 	-I$(top_srcdir)/librawstudio/ \
 	-I$(top_srcdir)/
 
@@ -20,6 +20,6 @@
 
 libdir = $(datadir)/rawstudio/plugins/
 
-load_dcraw_la_LIBADD = @PACKAGE_LIBS@ @LCMS_LIBS@
+load_dcraw_la_LIBADD = @PACKAGE_LIBS@ @LCMS2_LIBS@
 load_dcraw_la_LDFLAGS = -module -avoid-version
 load_dcraw_la_SOURCES =  dcrawloader.c dcraw.cc dcraw.h dcraw_api.cc dcraw_api.h mmap-hack.c mmap-hack.h

Modified: trunk/plugins/load-dcraw/dcraw.cc
===================================================================
--- trunk/plugins/load-dcraw/dcraw.cc	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/plugins/load-dcraw/dcraw.cc	2012-02-18 10:21:44 UTC (rev 4144)
@@ -62,7 +62,7 @@
    NO_LCMS disables the "-p" option.
  */
 #ifndef NO_LCMS
-#include <lcms.h>
+#include <lcms2.h>
 #endif
 #ifdef HAVE_LIBJPEG
 extern "C" {
@@ -5040,8 +5040,10 @@
   double cc[4][4], cm[4][3], cam_xyz[4][3], num;
   double ab[]={ 1,1,1,1 }, asn[] = { 0,0,0,0 }, xyz[] = { 1,1,1 };
   int sony_curve[] = { 0,0,0,0,0,4095 };
+#ifndef WITH_MMAP_HACK
   unsigned sony_offset=0, sony_length=0, sony_key=0;
-  struct jhead jh;
+#endif
+	struct jhead jh;
 #ifndef WITH_MMAP_HACK
   unsigned *buf;
   FILE *sfp;
@@ -5206,10 +5208,12 @@
 	  for (j = sony_curve[i]+1; j <= sony_curve[i+1]; j++)
 	    curve[j] = curve[j-1] + (1 << i);
 	break;
+#ifndef WITH_MMAP_HACK
       case 29184: sony_offset = get4();  break;
       case 29185: sony_length = get4();  break;
       case 29217: sony_key    = get4();  break;
-      case 29264:
+#endif
+		case 29264:
 	parse_minolta (ftell(ifp));
 	raw_width = 0;
 	break;
@@ -8576,7 +8580,7 @@
   FILE *fp;
   unsigned size;
 
-  cmsErrorAction (LCMS_ERROR_SHOW);
+//  cmsErrorAction (LCMS_ERROR_SHOW);
   if (strcmp (input, "embed"))
     hInProfile = cmsOpenProfileFromFile (input, "r");
   else if (profile_length) {

Modified: trunk/plugins/load-gdk/Makefile.am
===================================================================
--- trunk/plugins/load-gdk/Makefile.am	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/plugins/load-gdk/Makefile.am	2012-02-18 10:21:44 UTC (rev 4144)
@@ -9,7 +9,7 @@
 INCLUDES = \
 	-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
 	-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
-	@PACKAGE_CFLAGS@ @LCMS_CFLAGS@ @EXIV2_CFLAGS@ \
+	@PACKAGE_CFLAGS@ @LCMS2_CFLAGS@ @EXIV2_CFLAGS@ \
 	-I$(top_srcdir)/librawstudio/ \
 	-I$(top_srcdir)/
 
@@ -17,6 +17,6 @@
 
 libdir = $(datadir)/rawstudio/plugins/
 
-load_gdk_la_LIBADD = @PACKAGE_LIBS@ @LCMS_LIBS@ @EXIV2_LIBS@ @LIBJPEG@
+load_gdk_la_LIBADD = @PACKAGE_LIBS@ @LCMS2_LIBS@ @EXIV2_LIBS@ @LIBJPEG@
 load_gdk_la_LDFLAGS = -module -avoid-version
 load_gdk_la_SOURCES =  load-gdk.c exiv2-colorspace.cpp exiv2-colorspace.h

Modified: trunk/plugins/load-gdk/load-gdk.c
===================================================================
--- trunk/plugins/load-gdk/load-gdk.c	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/plugins/load-gdk/load-gdk.c	2012-02-18 10:21:44 UTC (rev 4144)
@@ -20,7 +20,7 @@
 #include <rawstudio.h>
 #include <math.h> /* pow() */
 #include "exiv2-colorspace.h"
-#include <lcms.h>
+#include <lcms2.h>
 
 
 /**
@@ -56,15 +56,15 @@
 			cmsHPROFILE *lcms_target = cmsOpenProfileFromMem(data, length);
 			if (lcms_target)
 			{
-				LPGAMMATABLE curve = NULL;
-				if (cmsIsTag(lcms_target, icSigGrayTRCTag))
-					curve = cmsReadICCGamma(lcms_target, icSigGrayTRCTag);
+				cmsToneCurve *curve = NULL;
+				if (cmsIsTag(lcms_target, cmsSigGrayTRCTag))
+					curve = cmsReadTag(lcms_target, cmsSigGrayTRCTag);
 
-				if (NULL== curve && cmsIsTag(lcms_target, icSigRedTRCTag))
-					curve = cmsReadICCGamma(lcms_target, icSigRedTRCTag);
+				if (NULL== curve && cmsIsTag(lcms_target, cmsSigRedTRCTag))
+					curve = cmsReadTag(lcms_target, cmsSigRedTRCTag);
 				if (curve)
 				{
-					double gamma = cmsEstimateGamma(curve);
+					double gamma = cmsEstimateGamma(curve, 0.01);
 					if (gamma>0.0)
 						gamma_guess = gamma;
 				}

Modified: trunk/plugins/meta-x3f/x3f-meta.c
===================================================================
--- trunk/plugins/meta-x3f/x3f-meta.c	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/plugins/meta-x3f/x3f-meta.c	2012-02-18 10:21:44 UTC (rev 4144)
@@ -15,6 +15,13 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * * 2011-09
+ * * Tâm Merlant <tam.ille at free.fr>: 
+ * * - Added thumbnailing and properties extraction for SD15, DP1, DP2 and SD1
+ * * - Modified the way the embedded thumbnails were found 
+ * * - Made sure we load the embedded thumbnail and not the fullsize preview
+ *
  */
 
 #include <rawstudio.h>
@@ -39,10 +46,16 @@
 
 typedef enum x3f_data_format {
 	X3F_DATA_FORMAT_UNCOMPRESSED = 3,
+	X3F_DATA_FORMAT_HUFFMAN_WITH_TABLE = 6,
 	X3F_DATA_FORMAT_HUFFMAN = 11,
 	X3F_DATA_FORMAT_JPEG = 18,
 } X3F_DATA_FORMAT;
 
+typedef enum x3f_type_of_image_data {
+	X3F_DATA_TYPE_PROCESSED = 2,
+	X3F_DATA_TYPE_RAW = 3,
+} X3F_TYPE_OF_IMAGE_DATA;
+
 /*
  * These structs is mostly used to define the file format - they can not
  * be directly mapped to file because of endian differences on some platforms
@@ -108,6 +121,29 @@
 	guint value_offset; /* offset from start of CHARACTER data */
 } __attribute__ ((packed)) X3F_PROPERTY_ENTRY;
 
+
+static GdkPixbuf * 
+jpeg_load (guchar *content, gsize length)
+{
+	GdkPixbufLoader *pl;
+	GdkPixbuf *pixbuf = NULL;
+	gboolean cont = TRUE; /* Are we good to continue? */
+	gint pos = 0;
+
+	pl = gdk_pixbuf_loader_new();
+	while((length > 100000) && cont)
+	{
+		cont = gdk_pixbuf_loader_write(pl, &content[pos], 80000, NULL);
+		length -= 80000;
+		pos += 80000;
+	}
+	if (cont)
+		gdk_pixbuf_loader_write(pl, &content[pos], length, NULL);
+	pixbuf = gdk_pixbuf_loader_get_pixbuf(pl);
+	gdk_pixbuf_loader_close(pl, NULL);
+	return(pixbuf);
+}
+
 static gboolean
 x3f_load_meta(const gchar *service, RAWFILE *rawfile, guint offset, RSMetadata *meta)
 {
@@ -115,10 +151,12 @@
 	X3F_FILE file;
 	X3F_DIRECTORY_SECTION directory;
 	X3F_DIRECTORY_ENTRY directory_entry;
-	X3F_IMAGE_DATA image_data;
-	guint start=0, width=0, height=0, rowstride=0;
+  guint start=0, width=0, height=0, rowstride=0, length=0;
+  X3F_TYPE_OF_IMAGE_DATA type_of_image_data;
+  X3F_DATA_FORMAT data_format;
 	GdkPixbuf *pixbuf = NULL, *pixbuf2 = NULL;
 	gdouble ratio=1.0;
+  gboolean thumb_ok=FALSE, prop_ok=FALSE;
 
 	/* Check if this is infact a Sigma-file */
 	if (!raw_strcmp(rawfile, G_STRUCT_OFFSET(X3F_FILE, identifier), "FOVb", 4))
@@ -178,22 +216,33 @@
 				file.directory_start+G_STRUCT_OFFSET(X3F_DIRECTORY_SECTION, number_of_entries),
 				&directory.number_of_entries);
 
-			for(i=0;i<directory.number_of_entries;i++)
+	  while (!(thumb_ok && prop_ok)) {
+	    /* parse in reverse order to make sure the last added thumbnail and prop section get found first. See X3F spec for more info */
+	    for(i=directory.number_of_entries;i>=0;i--)
 			{
 				gint offset = file.directory_start + sizeof(X3F_DIRECTORY_SECTION) + i * sizeof(X3F_DIRECTORY_ENTRY);
 				raw_get_uint(rawfile, offset+G_STRUCT_OFFSET(X3F_DIRECTORY_ENTRY, offset), &directory_entry.offset);
-				raw_get_uint(rawfile, offset+G_STRUCT_OFFSET(X3F_DIRECTORY_ENTRY, length), &directory_entry.length);
-
-				if (raw_strcmp(rawfile, offset+G_STRUCT_OFFSET(X3F_DIRECTORY_ENTRY, type), "IMA", 3))
+				if (raw_strcmp(rawfile, offset+G_STRUCT_OFFSET(X3F_DIRECTORY_ENTRY, type), "IMA", 3) && !thumb_ok)
 				{
 					/* Image Data */
-					raw_get_uint(rawfile, directory_entry.offset+G_STRUCT_OFFSET(X3F_IMAGE_DATA, data_format), &image_data.data_format);
-					if (image_data.data_format == X3F_DATA_FORMAT_UNCOMPRESSED)
+					raw_get_uint(rawfile, directory_entry.offset+G_STRUCT_OFFSET(X3F_IMAGE_DATA, type_of_image_data), &type_of_image_data);
+					if (type_of_image_data == X3F_DATA_TYPE_PROCESSED)
 					{
-						start = directory_entry.offset+G_STRUCT_OFFSET(X3F_IMAGE_DATA, image_data);
 						raw_get_uint(rawfile, directory_entry.offset+G_STRUCT_OFFSET(X3F_IMAGE_DATA, columns), &width);
-						raw_get_uint(rawfile, directory_entry.offset+G_STRUCT_OFFSET(X3F_IMAGE_DATA, rows), &height);
-						raw_get_uint(rawfile, directory_entry.offset+G_STRUCT_OFFSET(X3F_IMAGE_DATA, rowstride), &rowstride);
+						if (width < 500) /* assume thumbnails are always less than 500pixels wide */
+						{
+							raw_get_uint(rawfile, directory_entry.offset+G_STRUCT_OFFSET(X3F_IMAGE_DATA, data_format), &data_format);
+							raw_get_uint(rawfile, directory_entry.offset+G_STRUCT_OFFSET(X3F_IMAGE_DATA, rows), &height);
+							raw_get_uint(rawfile, directory_entry.offset+G_STRUCT_OFFSET(X3F_IMAGE_DATA, rowstride), &rowstride);
+							raw_get_uint(rawfile, directory_entry.offset+G_STRUCT_OFFSET(X3F_DIRECTORY_ENTRY, length), &length);
+							start = directory_entry.offset+G_STRUCT_OFFSET(X3F_IMAGE_DATA, image_data);
+							if (data_format == X3F_DATA_FORMAT_UNCOMPRESSED)
+								pixbuf = gdk_pixbuf_new_from_data(raw_get_map(rawfile)+start, GDK_COLORSPACE_RGB, FALSE, 8,
+									width, height, rowstride, NULL, NULL);
+							else if (data_format == X3F_DATA_FORMAT_JPEG)
+								pixbuf = jpeg_load (raw_get_map(rawfile)+start, length-28);
+							thumb_ok = (NULL != pixbuf);
+						}
 					}
 				}
 				else if (raw_strcmp(rawfile, offset+G_STRUCT_OFFSET(X3F_DIRECTORY_ENTRY, type), "PROP", 4))
@@ -244,7 +293,7 @@
 						}
 						else if (g_str_equal(name, "CAMMODEL"))
 							meta->model_ascii = g_strdup(value);
-						else if (g_str_equal(name, "APERTURE")) /* Example: 8.000 */
+						else if (g_str_equal(name, "AP_DESC")) /* Example: 8.000 */
 							meta->aperture = rs_atof(value);
 						else if (g_str_equal(name, "SH_DESC")) /* Example: 1/60 */
 						{
@@ -264,16 +313,14 @@
 							g_free(name);
 						if (value)
 							g_free(value);
+						}
+					prop_ok=TRUE;
 					}
 				}
 			}
 		}
 	}
 
-	if (width > 0)
-		pixbuf = gdk_pixbuf_new_from_data(raw_get_map(rawfile)+start, GDK_COLORSPACE_RGB, FALSE, 8,
-			width, height, rowstride, NULL, NULL);
-
 	if (pixbuf)
 	{
 		if (file.rotation > 0)

Modified: trunk/src/application.c
===================================================================
--- trunk/src/application.c	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/src/application.c	2012-02-18 10:21:44 UTC (rev 4144)
@@ -72,6 +72,7 @@
 {
 	g_assert(rs != NULL);
 
+	rs_preview_widget_lock_renderer(RS_PREVIEW_WIDGET(rs->preview));
 	/* Unref old photo if any */
 	if (rs->photo)
 		g_object_unref(rs->photo);
@@ -92,6 +93,7 @@
 		g_signal_connect(G_OBJECT(rs->photo), "spatial-changed", G_CALLBACK(photo_spatial_changed), rs);
 		g_signal_connect(G_OBJECT(rs->photo), "profile-changed", G_CALLBACK(photo_profile_changed), rs);
 	}
+	rs_preview_widget_unlock_renderer(RS_PREVIEW_WIDGET(rs->preview));
 }
 
 static void
@@ -99,12 +101,14 @@
 {
 	if (photo == rs->photo)
 	{
+//		rs_preview_widget_lock_renderer(RS_PREVIEW_WIDGET(rs->preview));
 		/* Update crop and rotate filters */
 		rs_filter_set_recursive(rs->filter_end,
 			"rectangle", rs_photo_get_crop(photo),
 			"angle", rs_photo_get_angle(photo),
 			"orientation", rs->photo->orientation,
 			NULL);
+//		rs_preview_widget_unlock_renderer(RS_PREVIEW_WIDGET(rs->preview));
 	}
 
 }
@@ -114,6 +118,7 @@
 {
 	if (photo == rs->photo)
 	{
+//		rs_preview_widget_lock_renderer(RS_PREVIEW_WIDGET(rs->preview));
 		if (RS_IS_ICC_PROFILE(profile))
 		{
 			RSColorSpace *cs = rs_color_space_icc_new_from_icc(profile);
@@ -130,6 +135,7 @@
 			   anything - this works because RSDcp is requesting Prophoto. */
 			g_object_set(rs->filter_input, "color-space", rs_color_space_new_singleton("RSProphoto"), NULL);
 		}
+//		rs_preview_widget_unlock_renderer(RS_PREVIEW_WIDGET(rs->preview));
 	}
 }
 

Modified: trunk/src/rs-cache.c
===================================================================
--- trunk/src/rs-cache.c	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/src/rs-cache.c	2012-02-18 10:21:44 UTC (rev 4144)
@@ -17,6 +17,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
+#include <config.h>
 #include <rawstudio.h>
 #include <glib.h>
 #include <libxml/encoding.h>

Modified: trunk/src/rs-preview-widget.c
===================================================================
--- trunk/src/rs-preview-widget.c	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/src/rs-preview-widget.c	2012-02-18 10:21:44 UTC (rev 4144)
@@ -266,18 +266,13 @@
 static gboolean make_cbdata(RSPreviewWidget *preview, const gint view, RS_PREVIEW_CALLBACK_DATA *cbdata, gint screen_x, gint screen_y, gint real_x, gint real_y);
 static gpointer render_thread_func(gpointer _thread_info);
 static void rs_preview_do_render(RSPreviewWidget *preview, GdkRectangle *dirty_area);
-
+static void rs_preview_wait_for_render(RSPreviewWidget *preview);
 /**
  * Class initializer
  */
 static void
 rs_preview_widget_class_init(RSPreviewWidgetClass *klass)
 {
-	GtkWidgetClass *widget_class;
-	GtkObjectClass *object_class;
-	widget_class = GTK_WIDGET_CLASS(klass);
-	object_class = GTK_OBJECT_CLASS(klass);
-
 	signals[WB_PICKED] = g_signal_new ("wb-picked",
 		G_TYPE_FROM_CLASS (klass),
 		G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
@@ -496,6 +491,20 @@
 	return widget;
 }
 
+extern void
+rs_preview_widget_lock_renderer(RSPreviewWidget *preview)
+{
+	g_assert(RS_IS_PREVIEW_WIDGET(preview));
+	g_mutex_lock(preview->render_thread->render_mutex);
+}
+
+extern void
+rs_preview_widget_unlock_renderer(RSPreviewWidget *preview)
+{
+	g_assert(RS_IS_PREVIEW_WIDGET(preview));
+	g_mutex_unlock(preview->render_thread->render_mutex);
+}
+
 void
 rs_preview_widget_update_display_colorspace(RSPreviewWidget *preview, gboolean force)
 {
@@ -2183,6 +2192,7 @@
 {
 	gint view;
 
+	preview->last_required_direct_redraw  = TRUE;
 	if (photo == preview->photo)
 	{
 		/* Set view profile */
@@ -2453,9 +2463,9 @@
 	rs_filter_param_set_object(RS_FILTER_PARAM(request), "colorspace", preview->exposure_color_space);
 
 	/* We set input to the cache placed before exposure mask */
-	gdk_threads_leave();
+	rs_preview_wait_for_render(preview);
 	response = rs_filter_get_image8(preview->filter_cache3[view], request);
-	gdk_threads_enter();
+	g_mutex_unlock(preview->render_thread->render_mutex);	
 	GdkPixbuf *buffer = rs_filter_response_get_image8(response);
 	g_object_unref(response);
 	g_object_unref(request);
@@ -2932,7 +2942,25 @@
 	g_mutex_unlock(preview->render_thread->render_mutex);
 }
 
+/* Waits for the renderer to finish and keeps the render_mutex */
+/* gdk_threads must be held, and will be retained */
+static void 
+rs_preview_wait_for_render(RSPreviewWidget *preview)
+{
+	preview->render_thread->finish_rendering = TRUE;
+	gdk_threads_leave();
+	g_mutex_lock(preview->render_thread->render_mutex);
+	while (preview->render_thread->render_pending) 
+	{
+		g_cond_signal(preview->render_thread->render);
+		g_mutex_unlock(preview->render_thread->render_mutex);
+		g_usleep(1000);
+		g_mutex_lock(preview->render_thread->render_mutex);
+	}
+	gdk_threads_enter();
+}
 
+
 static gpointer
 render_thread_func(gpointer _thread_info)
 {

Modified: trunk/src/rs-preview-widget.h
===================================================================
--- trunk/src/rs-preview-widget.h	2012-02-18 01:43:58 UTC (rev 4143)
+++ trunk/src/rs-preview-widget.h	2012-02-18 10:21:44 UTC (rev 4144)
@@ -178,6 +178,12 @@
 extern void 
 rs_preview_widget_update_display_colorspace(RSPreviewWidget *preview, gboolean force);
 
+extern void
+rs_preview_widget_lock_renderer(RSPreviewWidget *preview);
+
+extern void
+rs_preview_widget_unlock_renderer(RSPreviewWidget *preview);
+
 #define RS_PREVIEW_TYPE_WIDGET             (rs_preview_widget_get_type ())
 #define RS_PREVIEW_WIDGET(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), RS_PREVIEW_TYPE_WIDGET, RSPreviewWidget))
 #define RS_PREVIEW_WIDGET_CLASS(obj)       (G_TYPE_CHECK_CLASS_CAST ((obj), RS_PREVIEW_WIDGET, RSPreviewWidgetClass))




More information about the Rawstudio-commit mailing list