[Rawstudio-commit] r4146 - in trunk: . plugins/colorspace-transform plugins/load-dcraw plugins/load-gdk

Klaus Post klauspost at gmail.com
Sat Feb 18 11:58:35 CET 2012


Author: post
Date: 2012-02-18 11:58:35 +0100 (Sat, 18 Feb 2012)
New Revision: 4146

Modified:
   trunk/configure.in
   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
Log:
Switch to liblcms2.

Modified: trunk/configure.in
===================================================================
--- trunk/configure.in	2012-02-18 10:43:54 UTC (rev 4145)
+++ trunk/configure.in	2012-02-18 10:58:35 UTC (rev 4146)
@@ -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/plugins/colorspace-transform/Makefile.am
===================================================================
--- trunk/plugins/colorspace-transform/Makefile.am	2012-02-18 10:43:54 UTC (rev 4145)
+++ trunk/plugins/colorspace-transform/Makefile.am	2012-02-18 10:58:35 UTC (rev 4146)
@@ -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 10:43:54 UTC (rev 4145)
+++ trunk/plugins/colorspace-transform/rs-cmm.c	2012-02-18 10:58:35 UTC (rev 4146)
@@ -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;
 	}
 }
 
@@ -286,36 +320,6 @@
 	g_free(t);
 }
 
-static guchar *
-pack_rgb_w4(void *info, register WORD wOut[], register LPBYTE output)
-{
-	*(LPWORD) output = wOut[0]; output+= 2;
-	*(LPWORD) output = wOut[1]; output+= 2;
-	*(LPWORD) output = wOut[2]; output+= 4;
-
-	return(output);
-}
-
-static guchar *
-unroll_rgb_w4(void *info, register WORD wIn[], register LPBYTE accum)
-{
-	wIn[0] = *(LPWORD) accum; accum+= 2;
-	wIn[1] = *(LPWORD) accum; accum+= 2;
-	wIn[2] = *(LPWORD) accum; accum+= 4;
-
-	return(accum);
-}
-
-static guchar *
-unroll_rgb_w4_gammatable22(void *info, register WORD wIn[], register LPBYTE accum)
-{
-	wIn[0] = gammatable22[*(LPWORD) accum]; accum+= 2;
-	wIn[1] = gammatable22[*(LPWORD) accum]; accum+= 2;
-	wIn[2] = gammatable22[*(LPWORD) accum]; accum+= 4;
-
-	return(accum);
-}
-
 static void
 load_profile(RSCmm *cmm, const RSIccProfile *profile, const RSIccProfile **profile_target, cmsHPROFILE *lcms_target)
 {
@@ -399,10 +403,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,23 +441,16 @@
 		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 */
-	if (is_profile_gamma_22_corrected(cmm->lcms_input_profile))
-		cmsSetUserFormatters(cmm->lcms_transform16,
-			TYPE_RGB_16, unroll_rgb_w4_gammatable22,
-			TYPE_RGB_16, pack_rgb_w4);
-	else
-		cmsSetUserFormatters(cmm->lcms_transform16,
-			TYPE_RGB_16, unroll_rgb_w4,
-			TYPE_RGB_16, pack_rgb_w4);
+	cmm->is_gamma_corrected = is_profile_gamma_22_corrected(cmm->lcms_input_profile);
 
 	cmm->dirty16 = FALSE;
 }

Modified: trunk/plugins/load-dcraw/Makefile.am
===================================================================
--- trunk/plugins/load-dcraw/Makefile.am	2012-02-18 10:43:54 UTC (rev 4145)
+++ trunk/plugins/load-dcraw/Makefile.am	2012-02-18 10:58:35 UTC (rev 4146)
@@ -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 10:43:54 UTC (rev 4145)
+++ trunk/plugins/load-dcraw/dcraw.cc	2012-02-18 10:58:35 UTC (rev 4146)
@@ -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 10:43:54 UTC (rev 4145)
+++ trunk/plugins/load-gdk/Makefile.am	2012-02-18 10:58:35 UTC (rev 4146)
@@ -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 10:43:54 UTC (rev 4145)
+++ trunk/plugins/load-gdk/load-gdk.c	2012-02-18 10:58:35 UTC (rev 4146)
@@ -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;
 				}




More information about the Rawstudio-commit mailing list