[Rawstudio-commit] r3157 - trunk/plugins/dcp

Klaus Post klauspost at gmail.com
Wed Feb 3 22:33:30 CET 2010


Author: post
Date: 2010-02-03 22:33:30 +0100 (Wed, 03 Feb 2010)
New Revision: 3157

Modified:
   trunk/plugins/dcp/dcp.c
Log:
DCP: Add gamma-corrected curve, and don't calculate curve if it is flat.

Modified: trunk/plugins/dcp/dcp.c
===================================================================
--- trunk/plugins/dcp/dcp.c	2010-02-03 17:56:05 UTC (rev 3156)
+++ trunk/plugins/dcp/dcp.c	2010-02-03 21:33:30 UTC (rev 3157)
@@ -183,15 +183,35 @@
 			if (knots)
 			{
 				dcp->nknots = nknots;
-				RSSpline *spline = rs_spline_new(knots, dcp->nknots, NATURAL);
-				rs_spline_sample(spline, dcp->curve_samples, 65536);
-				g_object_unref(spline);
+				dcp->curve_is_flat = FALSE;
+				if (nknots == 2)
+					if (ABS(knots[0]) < 0.0001 && ABS(knots[1]) < 0.0001)
+						if (ABS(1.0 - knots[2]) < 0.0001 && ABS(1.0 - knots[3]) < 0.0001)
+							dcp->curve_is_flat = TRUE;
+
+				if (!dcp->curve_is_flat)
+				{
+					gfloat sampled[65536];
+					RSSpline *spline = rs_spline_new(knots, dcp->nknots, NATURAL);
+					rs_spline_sample(spline, sampled, sizeof(sampled) / sizeof(gfloat));
+					g_object_unref(spline);
+					for (i = 0; i < 65536; i++)
+					{
+						gfloat value = (gfloat)i * (1.0 / 65535.0f);
+						/* Gamma correct value */
+						value = powf(value, 1.0f / 2.2f);
+						
+						/*Lookup curve corrected value */
+						value = sampled[(int)(value * 65535.0f + 0.49999f)];
+
+						/* Convert from gamma 2.2 back to linear */
+						value = powf(value, 2.2f);
+
+						/* Store in table */
+						dcp->curve_samples[i] = value;
+					}
+				}
 			}
-			dcp->curve_is_flat = FALSE;
-			if (nknots == 2)
-				if (ABS(knots[0]) < 0.0001 && ABS(knots[1]) < 0.0001)
-					if (ABS(1.0 - knots[2]) < 0.0001 && ABS(1.0 - knots[3]) < 0.0001)
-						dcp->curve_is_flat = TRUE;
 			if (knots)
 				g_free(knots);
 		}




More information about the Rawstudio-commit mailing list