Author: post
Date: 2010-01-16 13:03:03 +0100 (Sat, 16 Jan 2010)
New Revision: 3005

Modified:
   branches/rawstudio-ng-color/librawstudio/rs-color-transform.c
   branches/rawstudio-ng-color/librawstudio/rs-math.c
   branches/rawstudio-ng-color/librawstudio/rs-math.h
Log:
Adjust integer colorspace conversion precision [part1/2].

Modified: branches/rawstudio-ng-color/librawstudio/rs-color-transform.c
===================================================================
--- branches/rawstudio-ng-color/librawstudio/rs-color-transform.c       
2010-01-16 10:08:20 UTC (rev 3004)
+++ branches/rawstudio-ng-color/librawstudio/rs-color-transform.c       
2010-01-16 12:03:03 UTC (rev 3005)
@@ -922,13 +922,13 @@
                        _CLAMP65535_TRIPLET(rr,gg,bb);
                        r = (rr*mati.coeff[0][0]
                                + gg*mati.coeff[0][1]
-                               + bb*mati.coeff[0][2])>>MATRIX_RESOLUTION;
+                               + bb*mati.coeff[0][2] + 
MATRIX_RESOLUTION_ROUNDER)>>MATRIX_RESOLUTION;
                        g = (rr*mati.coeff[1][0]
                                + gg*mati.coeff[1][1]
-                               + bb*mati.coeff[1][2])>>MATRIX_RESOLUTION;
+                               + bb*mati.coeff[1][2] + 
MATRIX_RESOLUTION_ROUNDER)>>MATRIX_RESOLUTION;
                        b = (rr*mati.coeff[2][0]
                                + gg*mati.coeff[2][1]
-                               + bb*mati.coeff[2][2])>>MATRIX_RESOLUTION;
+                               + bb*mati.coeff[2][2] + 
MATRIX_RESOLUTION_ROUNDER)>>MATRIX_RESOLUTION;
                        _CLAMP65535_TRIPLET(r,g,b);
                        buffer[destoffset++] = rct->table16[r];
                        buffer[destoffset++] = rct->table16[g];
@@ -969,13 +969,13 @@
                        _CLAMP65535_TRIPLET(rr,gg,bb);
                        r = (rr*mati.coeff[0][0]
                                + gg*mati.coeff[0][1]
-                               + bb*mati.coeff[0][2])>>MATRIX_RESOLUTION;
+                               + bb*mati.coeff[0][2] + 
MATRIX_RESOLUTION_ROUNDER)>>MATRIX_RESOLUTION;
                        g = (rr*mati.coeff[1][0]
                                + gg*mati.coeff[1][1]
-                               + bb*mati.coeff[1][2])>>MATRIX_RESOLUTION;
+                               + bb*mati.coeff[1][2] + 
MATRIX_RESOLUTION_ROUNDER)>>MATRIX_RESOLUTION;
                        b = (rr*mati.coeff[2][0]
                                + gg*mati.coeff[2][1]
-                               + bb*mati.coeff[2][2])>>MATRIX_RESOLUTION;
+                               + bb*mati.coeff[2][2] + 
MATRIX_RESOLUTION_ROUNDER)>>MATRIX_RESOLUTION;
                        _CLAMP65535_TRIPLET(r,g,b);
                        d[destoffset++] = rct->table8[r];
                        d[destoffset++] = rct->table8[g];

Modified: branches/rawstudio-ng-color/librawstudio/rs-math.c
===================================================================
--- branches/rawstudio-ng-color/librawstudio/rs-math.c  2010-01-16 10:08:20 UTC 
(rev 3004)
+++ branches/rawstudio-ng-color/librawstudio/rs-math.c  2010-01-16 12:03:03 UTC 
(rev 3005)
@@ -202,11 +202,16 @@
 void
 matrix4_to_matrix4int(RS_MATRIX4 *matrix, RS_MATRIX4Int *matrixi)
 {
-  int a,b;
-  for(a=0;a<4;a++)
-    for(b=0;b<4;b++)
-      matrixi->coeff[a][b] = (int) (matrix->coeff[a][b] * (double) 
(1<<MATRIX_RESOLUTION));
-  return;
+       int a,b;
+       for(a=0;a<4;a++)
+               for(b=0;b<4;b++)
+               {
+                       /* Check that a (unsigned 16 bit) x (matrix coeff 
shifted up RESOLUTION) fits within signed 32 bit value */
+                       /* Adjust this if MATRIX_RESOLUTION is adjusted */
+                       g_assert((matrix->coeff[a][b] < 16.0) && 
(matrix->coeff[a][b] > -16.0));
+
+                       matrixi->coeff[a][b] = (int) (matrix->coeff[a][b] * 
(double) (1<<MATRIX_RESOLUTION));
+               }
 }
 
 static void
@@ -548,11 +553,16 @@
 void
 matrix3_to_matrix3int(RS_MATRIX3 *matrix, RS_MATRIX3Int *matrixi)
 {
-  int a,b;
-  for(a=0;a<3;a++)
-    for(b=0;b<3;b++)
-      matrixi->coeff[a][b] = (int) (matrix->coeff[a][b] * (double) 
(1<<MATRIX_RESOLUTION));
-  return;
+       int a,b;
+       for(a=0;a<3;a++)
+               for(b=0;b<3;b++)
+               {
+                       /* Check that a (unsigned 16 bit) x (matrix coeff 
shifted up RESOLUTION) fits within signed 32 bit value */
+                       /* Adjust this if MATRIX_RESOLUTION is adjusted */
+                       g_assert((matrix->coeff[a][b] < 16.0) && 
(matrix->coeff[a][b] > -16.0));
+
+                       matrixi->coeff[a][b] = (int) (matrix->coeff[a][b] * 
(double) (1<<MATRIX_RESOLUTION));
+               }
 }
 
 /*

Modified: branches/rawstudio-ng-color/librawstudio/rs-math.h
===================================================================
--- branches/rawstudio-ng-color/librawstudio/rs-math.h  2010-01-16 10:08:20 UTC 
(rev 3004)
+++ branches/rawstudio-ng-color/librawstudio/rs-math.h  2010-01-16 12:03:03 UTC 
(rev 3005)
@@ -22,7 +22,8 @@
 
 #include "rs-types.h"
 
-#define MATRIX_RESOLUTION (8) /* defined in bits! */
+#define MATRIX_RESOLUTION (11) /* defined in bits! */
+#define MATRIX_RESOLUTION_ROUNDER (1024) /* Half of fixed point precision */
 
 extern void printmat3(RS_MATRIX3 *mat);
 extern void printmat(RS_MATRIX4 *mat);


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to