jdk/src/java.desktop/share/native/liblcms/cmsmtrx.c
author martin
Wed, 02 Sep 2015 14:11:50 -0700
changeset 32427 c22b7e41adf3
parent 25859 3317bb8137f4
child 40152 35cbab101a76
permissions -rw-r--r--
8134984: Text files should end in exactly one newline Summary: automated fixup of newlines at end-of-file via the usual perl one-liner Reviewed-by: chegar, sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2394
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2394
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2394
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2394
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2394
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
// This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
// License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
// However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
// file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
//
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    30
//---------------------------------------------------------------------------------
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
//
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    32
//  Little Color Management System
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
    33
//  Copyright (c) 1998-2012 Marti Maria Saguer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
// Permission is hereby granted, free of charge, to any person obtaining
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
// a copy of this software and associated documentation files (the "Software"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
// to deal in the Software without restriction, including without limitation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
// and/or sell copies of the Software, and to permit persons to whom the Software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
// is furnished to do so, subject to the following conditions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
// The above copyright notice and this permission notice shall be included in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
// all copies or substantial portions of the Software.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    52
//
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    53
//---------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    54
//
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    56
#include "lcms2_internal.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    59
#define DSWAP(x, y)     {cmsFloat64Number tmp = (x); (x)=(y); (y)=tmp;}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    62
// Initiate a vector
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    63
void CMSEXPORT _cmsVEC3init(cmsVEC3* r, cmsFloat64Number x, cmsFloat64Number y, cmsFloat64Number z)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    65
    r -> n[VX] = x;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    66
    r -> n[VY] = y;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    67
    r -> n[VZ] = z;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    70
// Vector substraction
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    71
void CMSEXPORT _cmsVEC3minus(cmsVEC3* r, const cmsVEC3* a, const cmsVEC3* b)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  r -> n[VX] = a -> n[VX] - b -> n[VX];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  r -> n[VY] = a -> n[VY] - b -> n[VY];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  r -> n[VZ] = a -> n[VZ] - b -> n[VZ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    78
// Vector cross product
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    79
void CMSEXPORT _cmsVEC3cross(cmsVEC3* r, const cmsVEC3* u, const cmsVEC3* v)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    r ->n[VX] = u->n[VY] * v->n[VZ] - v->n[VY] * u->n[VZ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    r ->n[VY] = u->n[VZ] * v->n[VX] - v->n[VZ] * u->n[VX];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    r ->n[VZ] = u->n[VX] * v->n[VY] - v->n[VX] * u->n[VY];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    86
// Vector dot product
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    87
cmsFloat64Number CMSEXPORT _cmsVEC3dot(const cmsVEC3* u, const cmsVEC3* v)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    88
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    89
    return u->n[VX] * v->n[VX] + u->n[VY] * v->n[VY] + u->n[VZ] * v->n[VZ];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    90
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    92
// Euclidean length
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    93
cmsFloat64Number CMSEXPORT _cmsVEC3length(const cmsVEC3* a)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    return sqrt(a ->n[VX] * a ->n[VX] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                a ->n[VY] * a ->n[VY] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                a ->n[VZ] * a ->n[VZ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   100
// Euclidean distance
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   101
cmsFloat64Number CMSEXPORT _cmsVEC3distance(const cmsVEC3* a, const cmsVEC3* b)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   103
    cmsFloat64Number d1 = a ->n[VX] - b ->n[VX];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   104
    cmsFloat64Number d2 = a ->n[VY] - b ->n[VY];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   105
    cmsFloat64Number d3 = a ->n[VZ] - b ->n[VZ];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    return sqrt(d1*d1 + d2*d2 + d3*d3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   112
// 3x3 Identity
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   113
void CMSEXPORT _cmsMAT3identity(cmsMAT3* a)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   115
    _cmsVEC3init(&a-> v[0], 1.0, 0.0, 0.0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   116
    _cmsVEC3init(&a-> v[1], 0.0, 1.0, 0.0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   117
    _cmsVEC3init(&a-> v[2], 0.0, 0.0, 1.0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   118
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   119
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   120
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   121
cmsBool CloseEnough(cmsFloat64Number a, cmsFloat64Number b)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   122
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   123
    return fabs(b - a) < (1.0 / 65535.0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   127
cmsBool CMSEXPORT _cmsMAT3isIdentity(const cmsMAT3* a)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   128
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   129
    cmsMAT3 Identity;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   130
    int i, j;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   131
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   132
    _cmsMAT3identity(&Identity);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   133
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   134
    for (i=0; i < 3; i++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   135
        for (j=0; j < 3; j++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   136
            if (!CloseEnough(a ->v[i].n[j], Identity.v[i].n[j])) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   137
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   138
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   139
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
// Multiply two matrices
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   143
void CMSEXPORT _cmsMAT3per(cmsMAT3* r, const cmsMAT3* a, const cmsMAT3* b)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
#define ROWCOL(i, j) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    a->v[i].n[0]*b->v[0].n[j] + a->v[i].n[1]*b->v[1].n[j] + a->v[i].n[2]*b->v[2].n[j]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   148
    _cmsVEC3init(&r-> v[0], ROWCOL(0,0), ROWCOL(0,1), ROWCOL(0,2));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   149
    _cmsVEC3init(&r-> v[1], ROWCOL(1,0), ROWCOL(1,1), ROWCOL(1,2));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   150
    _cmsVEC3init(&r-> v[2], ROWCOL(2,0), ROWCOL(2,1), ROWCOL(2,2));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
#undef ROWCOL //(i, j)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
// Inverse of a matrix b = a^(-1)
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   158
cmsBool  CMSEXPORT _cmsMAT3inverse(const cmsMAT3* a, cmsMAT3* b)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   160
   cmsFloat64Number det, c0, c1, c2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   162
   c0 =  a -> v[1].n[1]*a -> v[2].n[2] - a -> v[1].n[2]*a -> v[2].n[1];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   163
   c1 = -a -> v[1].n[0]*a -> v[2].n[2] + a -> v[1].n[2]*a -> v[2].n[0];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   164
   c2 =  a -> v[1].n[0]*a -> v[2].n[1] - a -> v[1].n[1]*a -> v[2].n[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   166
   det = a -> v[0].n[0]*c0 + a -> v[0].n[1]*c1 + a -> v[0].n[2]*c2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   168
   if (fabs(det) < MATRIX_DET_TOLERANCE) return FALSE;  // singular matrix; can't invert
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   170
   b -> v[0].n[0] = c0/det;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   171
   b -> v[0].n[1] = (a -> v[0].n[2]*a -> v[2].n[1] - a -> v[0].n[1]*a -> v[2].n[2])/det;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   172
   b -> v[0].n[2] = (a -> v[0].n[1]*a -> v[1].n[2] - a -> v[0].n[2]*a -> v[1].n[1])/det;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   173
   b -> v[1].n[0] = c1/det;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   174
   b -> v[1].n[1] = (a -> v[0].n[0]*a -> v[2].n[2] - a -> v[0].n[2]*a -> v[2].n[0])/det;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   175
   b -> v[1].n[2] = (a -> v[0].n[2]*a -> v[1].n[0] - a -> v[0].n[0]*a -> v[1].n[2])/det;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   176
   b -> v[2].n[0] = c2/det;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   177
   b -> v[2].n[1] = (a -> v[0].n[1]*a -> v[2].n[0] - a -> v[0].n[0]*a -> v[2].n[1])/det;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   178
   b -> v[2].n[2] = (a -> v[0].n[0]*a -> v[1].n[1] - a -> v[0].n[1]*a -> v[1].n[0])/det;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   180
   return TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
// Solve a system in the form Ax = b
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   185
cmsBool  CMSEXPORT _cmsMAT3solve(cmsVEC3* x, cmsMAT3* a, cmsVEC3* b)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   187
    cmsMAT3 m, a_1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   189
    memmove(&m, a, sizeof(cmsMAT3));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   191
    if (!_cmsMAT3inverse(&m, &a_1)) return FALSE;  // Singular matrix
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   193
    _cmsMAT3eval(x, &a_1, b);
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   194
    return TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   197
// Evaluate a vector across a matrix
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   198
void CMSEXPORT _cmsMAT3eval(cmsVEC3* r, const cmsMAT3* a, const cmsVEC3* v)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    r->n[VX] = a->v[0].n[VX]*v->n[VX] + a->v[0].n[VY]*v->n[VY] + a->v[0].n[VZ]*v->n[VZ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    r->n[VY] = a->v[1].n[VX]*v->n[VX] + a->v[1].n[VY]*v->n[VY] + a->v[1].n[VZ]*v->n[VZ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    r->n[VZ] = a->v[2].n[VX]*v->n[VX] + a->v[2].n[VY]*v->n[VY] + a->v[2].n[VZ]*v->n[VZ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
}