summaryrefslogtreecommitdiff
path: root/icc
diff options
context:
space:
mode:
Diffstat (limited to 'icc')
-rwxr-xr-xicc/Jamfile2
-rwxr-xr-xicc/icc.c240
-rwxr-xr-xicc/icc.h62
3 files changed, 124 insertions, 180 deletions
diff --git a/icc/Jamfile b/icc/Jamfile
index 4bedbba..21b9dcb 100755
--- a/icc/Jamfile
+++ b/icc/Jamfile
@@ -41,7 +41,7 @@ MainsFromSources icctest.c lutest.c iccdump.c icclu.c iccrw.c ;
# This is an example program for making a matrix display profile
MainsFromSources mkDispProf.c ;
-#MainsFromSources t.c ;
+#MainsFromSources t2.c ;
if $(BUILD_JUNK) {
diff --git a/icc/icc.c b/icc/icc.c
index de8c539..9c49081 100755
--- a/icc/icc.c
+++ b/icc/icc.c
@@ -13560,7 +13560,7 @@ void icmClamp3(double out[3], double in[3]) {
out[i] = in[i] < 0.0 ? 0.0 : in[i];
}
-/* Invert a 3 vector */
+/* Invert (negate) a 3 vector */
void icmInv3(double out[3], double in[3]) {
int i;
for (i = 0; i < 3; i++)
@@ -13858,7 +13858,7 @@ double in[3][3]
*/
det = icmDet3x3(in);
- if ( fabs(det) < ICM_SMALL_NUMBER)
+ if (fabs(det) < ICM_SMALL_NUMBER)
return 1;
/* calculate the adjoint matrix */
@@ -13871,6 +13871,23 @@ double in[3][3]
return 0;
}
+/* Invert a 2x2 transform matrix. Return 1 if error. */
+int icmInverse2x2(double out[2][2], double in[2][2]) {
+ double det = det2x2(in[0][0], in[0][1], in[1][0], in[1][1]);
+
+ if (fabs(det) < ICM_SMALL_NUMBER)
+ return 1;
+
+ det = 1.0/det;
+
+ out[0][0] = det * in[1][1];
+ out[0][1] = det * -in[0][1];
+ out[1][0] = det * -in[1][0];
+ out[1][1] = det * in[0][0];
+
+ return 0;
+}
+
/* - - - - - - - - - - - - - - - - - - - - - - - - */
/* Transpose a 3x3 matrix */
void icmTranspose3x3(double out[3][3], double in[3][3]) {
@@ -14006,17 +14023,6 @@ int icmNormalize3(double out[3], double in[3], double len) {
return 0;
}
-/* Compute the norm (length) of a vector define by two points */
-double icmNorm22(double in1[2], double in0[2]) {
- int j;
- double rv;
- for (rv = 0.0, j = 0; j < 2; j++) {
- double tt = in1[j] - in0[j];
- rv += tt * tt;
- }
- return sqrt(rv);
-}
-
/* Compute the norm (length) squared of a vector define by two points */
double icmNorm33sq(double in1[3], double in0[3]) {
int j;
@@ -14232,143 +14238,6 @@ double icmClip4marg(double out[4], double in[4]) {
/* - - - - - - - - - - - - - - - - - - - - - - - - */
-/*
-
- mat in out
-
-[ ] [] []
-[ ] [] []
-[ ] * [] => []
-[ ] [] []
-[ ] [] []
-
- */
-
-/* Multiply 5 array by 5x5 transform matrix */
-void icmMulBy5x5(double out[5], double mat[5][5], double in[5]) {
- int i, j;
- double tt[5];
-
- for (i = 0; i < 5; i++) {
- tt[i] = 0.0;
- for (j = 0; j < 5; j++)
- tt[i] += mat[i][j] * in[j];
- }
-
- for (i = 0; i < 5; i++)
- out[i] = tt[i];
-}
-
-/* Transpose a 5x5 matrix */
-void icmTranspose5x5(double out[5][5], double in[5][5]) {
- int i, j;
- if (out != in) {
- for (i = 0; i < 5; i++)
- for (j = 0; j < 5; j++)
- out[i][j] = in[j][i];
- } else {
- double tt[5][5];
- for (i = 0; i < 5; i++)
- for (j = 0; j < 5; j++)
- tt[i][j] = in[j][i];
- for (i = 0; i < 5; i++)
- for (j = 0; j < 5; j++)
- out[i][j] = tt[i][j];
- }
-}
-
-/* Clip a vector to the range 0.0 .. 1.0 */
-/* and return any clipping margine */
-double icmClip5marg(double out[5], double in[5]) {
- int j;
- double tt, marg = 0.0;
- for (j = 0; j < 5; j++) {
- out[j] = in[j];
- if (out[j] < 0.0) {
- tt = 0.0 - out[j];
- out[j] = 0.0;
- if (tt > marg)
- marg = tt;
- } else if (out[j] > 1.0) {
- tt = out[j] - 1.0;
- out[j] = 1.0;
- if (tt > marg)
- marg = tt;
- }
- }
- return marg;
-}
-
-
-/* Multiply 6 array by 6x6 transform matrix */
-void icmMulBy6x6(double out[6], double mat[6][6], double in[6]) {
- int i, j;
- double tt[6];
-
- for (i = 0; i < 6; i++) {
- tt[i] = 0.0;
- for (j = 0; j < 6; j++)
- tt[i] += mat[i][j] * in[j];
- }
-
- for (i = 0; i < 6; i++)
- out[i] = tt[i];
-}
-
-/* Transpose a 6x6 matrix */
-void icmTranspose6x6(double out[6][6], double in[6][6]) {
- int i, j;
- if (out != in) {
- for (i = 0; i < 6; i++)
- for (j = 0; j < 6; j++)
- out[i][j] = in[j][i];
- } else {
- double tt[6][6];
- for (i = 0; i < 6; i++)
- for (j = 0; j < 6; j++)
- tt[i][j] = in[j][i];
- for (i = 0; i < 6; i++)
- for (j = 0; j < 6; j++)
- out[i][j] = tt[i][j];
- }
-}
-
-/* Clip a vector to the range 0.0 .. 1.0 */
-/* and return any clipping margine */
-double icmClip6marg(double out[6], double in[6]) {
- int j;
- double tt, marg = 0.0;
- for (j = 0; j < 6; j++) {
- out[j] = in[j];
- if (out[j] < 0.0) {
- tt = 0.0 - out[j];
- out[j] = 0.0;
- if (tt > marg)
- marg = tt;
- } else if (out[j] > 1.0) {
- tt = out[j] - 1.0;
- out[j] = 1.0;
- if (tt > marg)
- marg = tt;
- }
- }
- return marg;
-}
-
-/* - - - - - - - - - - - - - - - - - - - - - - - - */
-/* Multiply 2 array by 2x2 transform matrix */
-void icmMulBy2x2(double out[2], double mat[2][2], double in[2]) {
- double tt[2];
-
- tt[0] = mat[0][0] * in[0] + mat[0][1] * in[1];
- tt[1] = mat[1][0] * in[0] + mat[1][1] * in[1];
-
- out[0] = tt[0];
- out[1] = tt[1];
-}
-
-/* - - - - - - - - - - - - - - - - - - - - - - - - */
-
/* Copy a 3x4 transform matrix */
void icmCpy3x4(double dst[3][4], double src[3][4]) {
int i, j;
@@ -14638,6 +14507,52 @@ double icmPlaneDist3(double eq[4], double p[3]) {
}
/* - - - - - - - - - - - - - - - - - - - - - - - - */
+
+/* Compute the norm (length) of a vector define by two points */
+double icmNorm22(double in1[2], double in0[2]) {
+ int j;
+ double rv;
+ for (rv = 0.0, j = 0; j < 2; j++) {
+ double tt = in1[j] - in0[j];
+ rv += tt * tt;
+ }
+ return sqrt(rv);
+}
+
+/* Compute the norm (length) squared of of a vector defined by two points */
+double icmNorm22sq(double in1[2], double in0[2]) {
+ int j;
+ double rv;
+ for (rv = 0.0, j = 0; j < 2; j++) {
+ double tt = in1[j] - in0[j];
+ rv += tt * tt;
+ }
+ return rv;
+}
+
+/* Multiply 2 array by 2x2 transform matrix */
+void icmMulBy2x2(double out[2], double mat[2][2], double in[2]) {
+ double tt[2];
+
+ tt[0] = mat[0][0] * in[0] + mat[0][1] * in[1];
+ tt[1] = mat[1][0] * in[0] + mat[1][1] * in[1];
+
+ out[0] = tt[0];
+ out[1] = tt[1];
+}
+
+/* Compute the dot product of two 2 vectors */
+double icmDot2(double in1[2], double in2[2]) {
+ return in1[0] * in2[0] + in1[1] * in2[1];
+}
+
+/* Compute the dot product of two 2 vectors defined by 4 points */
+/* 1->2 and 3->4 */
+double icmDot22(double in1[2], double in2[2], double in3[2], double in4[2]) {
+ return (in2[0] - in1[0]) * (in4[0] - in3[0])
+ + (in2[1] - in1[1]) * (in4[1] - in3[1]);
+}
+
/* Given 2 2D points, compute a plane equation (implicit line equation). */
/* The normal will be right handed given the order of the points */
/* The plane equation will be the 2 normal components and the constant. */
@@ -14769,7 +14684,7 @@ int icmLineIntersect2(double res[2], double p1[2], double p2[2], double p3[2], d
}
/* Given two finite 2D lines define by 4 points, compute their paramaterized intersection. */
-/* aprm may be NULL */
+/* aprm may be NULL. Param is prop. from p1 -> p2, p3 -> p4 */
/* Return 2 if there is no intersection (lines are parallel) */
/* Return 1 lines do not cross within their length */
int icmParmLineIntersect2(double res[2], double aprm[2], double p1[2], double p2[2], double p3[2], double p4[2]) {
@@ -14803,6 +14718,23 @@ int icmParmLineIntersect2(double res[2], double aprm[2], double p1[2], double p2
return 0;
}
+/* Compute a blend between in0 and in1 */
+void icmBlend2(double out[2], double in0[2], double in1[2], double bf) {
+ out[0] = (1.0 - bf) * in0[0] + bf * in1[0];
+ out[1] = (1.0 - bf) * in0[1] + bf * in1[1];
+}
+
+/* Scale a 2 vector by the given ratio */
+void icmScale2(double out[2], double in[2], double rat) {
+ out[0] = in[0] * rat;
+ out[1] = in[1] * rat;
+}
+
+/* Scale a 2 vector by the given ratio and add it */
+void icmScaleAdd2(double out[3], double in2[2], double in1[2], double rat) {
+ out[0] = in2[0] + in1[0] * rat;
+ out[1] = in2[1] + in1[1] * rat;
+}
/* - - - - - - - - - - - - - - - - - - - - - - - - */
/* CIE Y (range 0 .. 1) to perceptual CIE 1976 L* (range 0 .. 100) */
@@ -14893,12 +14825,14 @@ icmLab2XYZ(icmXYZNumber *w, double *out, double *in) {
* This is a modern update to L*a*b*, based on IPT space.
*
* Differences to L*a*b* and IPT:
- * Using inverse CIE 2012 2degree LMS to XYZ matrix instead of Hunt-Pointer-Estevez
+ * Using inverse CIE 2012 2degree LMS to XYZ matrix instead of Hunt-Pointer-Estevez.
* Von Kries chromatic adapation in LMS space.
* Using L* compression rather than IPT pure 0.43 power.
* Tweaked LMS' to IPT matrix to account for change in XYZ to LMS matrix.
* Output scaled to L*a*b* type ranges, to maintain 1 JND scale.
- * (Watch out - L* value is not a non-linear Y value though!).
+ * (Watch out - L* value is not a non-linear Y value though!
+ * - Interesting that Dolby force L to be just dependent on Y
+ * by making L = 0.5 L | 0.5 M in ICtCp space).
*/
/* CIE XYZ to perceptual Lpt */
diff --git a/icc/icc.h b/icc/icc.h
index 1e2caf8..75b7736 100755
--- a/icc/icc.h
+++ b/icc/icc.h
@@ -1784,6 +1784,12 @@ extern ICCLIB_API unsigned int icmCSSig2chanNames( icColorSpaceSignature sig, ch
/* Copy a 2 vector */
#define icmCpy2(d_ary, s_ary) ((d_ary)[0] = (s_ary)[0], (d_ary)[1] = (s_ary)[1])
+#define icmAdd2(d_ary, s1_ary, s2_ary) ((d_ary)[0] = (s1_ary)[0] + (s2_ary)[0], \
+ (d_ary)[1] = (s1_ary)[1] + (s2_ary)[1])
+
+#define icmSub2(d_ary, s1_ary, s2_ary) ((d_ary)[0] = (s1_ary)[0] - (s2_ary)[0], \
+ (d_ary)[1] = (s1_ary)[1] - (s2_ary)[1])
+
/* Copy a 3 vector */
#define icmCpy3(d_ary, s_ary) ((d_ary)[0] = (s_ary)[0], (d_ary)[1] = (s_ary)[1], \
(d_ary)[2] = (s_ary)[2])
@@ -1792,10 +1798,12 @@ extern ICCLIB_API unsigned int icmCSSig2chanNames( icColorSpaceSignature sig, ch
#define icmCpy4(d_ary, s_ary) ((d_ary)[0] = (s_ary)[0], (d_ary)[1] = (s_ary)[1], \
(d_ary)[2] = (s_ary)[2], (d_ary)[3] = (s_ary)[3])
+/* - - - - - - - - - - - - - - */
+
/* Clamp a 3 vector to be +ve */
void icmClamp3(double out[3], double in[3]);
-/* Invert a 3 vector */
+/* Invert (negate) a 3 vector */
void icmInv3(double out[3], double in[3]);
/* Add two 3 vectors */
@@ -1832,8 +1840,6 @@ double icmDot3(double in1[3], double in2[3]);
/* Compute the cross product of two 3D vectors, out = in1 x in2 */
void icmCross3(double out[3], double in1[3], double in2[3]);
-#define icmNorm2(i) sqrt((i)[0] * (i)[0] + (i)[1] * (i)[1])
-
/* Compute the norm squared (length squared) of a 3 vector */
double icmNorm3sq(double in[3]);
@@ -1869,9 +1875,6 @@ double icmClip3marg(double out[3], double in[3]);
/* Normalise a 3 vector to the given length. Return nz if not normalisable */
int icmNormalize3(double out[3], double in[3], double len);
-/* Compute the norm (length) of of a vector defined by two points */
-double icmNorm22(double in1[2], double in0[2]);
-
/* Compute the norm squared (length squared) of a vector defined by two points */
double icmNorm33sq(double in1[3], double in0[3]);
@@ -1983,30 +1986,24 @@ double icmClip4marg(double out[4], double in[4]);
/* - - - - - - - - - - - - - - - - - - - - - - - */
-/* Multiply 5 vector by 5x5 transform matrix */
-/* Organization is mat[out][in] */
-void icmMulBy5x5(double out[5], double mat[5][5], double in[5]);
+#define icmNorm2(i) sqrt((i)[0] * (i)[0] + (i)[1] * (i)[1])
-/* Transpose a 5x5 matrix */
-void icmTranspose5x5(double out[5][5], double in[5][5]);
-
-/* Clip a vector to the range 0.0 .. 1.0 */
-/* and return any clipping margine */
-double icmClip5marg(double out[5], double in[5]);
+#define icmNorm2sq(i) ((i)[0] * (i)[0] + (i)[1] * (i)[1])
+/* Compute the norm (length) of of a vector defined by two points */
+double icmNorm22(double in1[2], double in0[2]);
-/* Multiply 6 vector by 6x6 transform matrix */
-/* Organization is mat[out][in] */
-void icmMulBy6x6(double out[6], double mat[6][6], double in[6]);
+/* Compute the norm (length) squared of of a vector defined by two points */
+double icmNorm22sq(double in1[2], double in0[2]);
-/* Transpose a 6x6 matrix */
-void icmTranspose6x6(double out[6][6], double in[6][6]);
+/* Compute the dot product of two 2 vectors */
+double icmDot2(double in1[2], double in2[2]);
-/* Clip a vector to the range 0.0 .. 1.0 */
-/* and return any clipping margine */
-double icmClip6marg(double out[6], double in[6]);
+#define ICMDOT2(o, i, j) ((o) = (i)[0] * (j)[0] + (i)[1] * (j)[1])
-/* - - - - - - - - - - - - - - - - - - - - - - - */
+/* Compute the dot product of two 2 vectors defined by 4 points */
+/* 1->2 and 3->4 */
+double icmDot22(double in1[2], double in2[2], double in3[2], double in4[2]);
/* Given 2 2D points, compute a plane equation. */
/* The normal will be right handed given the order of the points */
@@ -2038,13 +2035,26 @@ int icmLinePointClosest2(double cp[2], double *pa,
int icmLineIntersect2(double res[2], double p1[2], double p2[2], double p3[2], double p4[2]);
/* Given two finite 2D lines define by 4 points, compute their paramaterized intersection. */
-/* aprm may be NULL */
-/* Return nz if there is no intersection (lines are parallel or do not cross in length) */
+/* aprm may be NULL. Param is prop. from p1 -> p2, p3 -> p4 */
+/* Return 2 if there is no intersection (lines are parallel) */
+/* Return 1 lines do not cross within their length */
int icmParmLineIntersect2(double ares[2], double aprm[2], double p1[2], double p2[2], double p3[2], double p4[2]);
+/* Invert a 2x2 transform matrix. Return 1 if error. */
+int icmInverse2x2(double out[2][2], double in[2][2]);
+
/* Multiply 2 array by 2x2 transform matrix */
void icmMulBy2x2(double out[2], double mat[2][2], double in[2]);
+/* Compute a blend between in0 and in1 */
+void icmBlend2(double out[2], double in0[2], double in1[2], double bf);
+
+/* Scale a 2 vector by the given ratio */
+void icmScale2(double out[2], double in[2], double rat);
+
+/* Scale a 2 vector by the given ratio and add it */
+void icmScaleAdd2(double out[2], double in2[3], double in1[2], double rat);
+
/* - - - - - - - - - - - - - - */
/* Simple macro to transfer an array to an XYZ number */