jdk/src/share/native/sun/java2d/cmm/lcms/cmscam02.c
author bae
Thu, 09 Sep 2010 16:20:55 +0400
changeset 6482 0f6a4442b29e
parent 5506 202f599c92aa
child 14300 117dc9b98a7b
permissions -rw-r--r--
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library Reviewed-by: igor, prr
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
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    33
//  Copyright (c) 1998-2010 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
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
    58
// CIECAM 02 appearance model. Many thanks to Jordi Vilar for the debugging.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
// ---------- Implementation --------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
typedef struct  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    64
    cmsFloat64Number XYZ[3];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    65
    cmsFloat64Number RGB[3];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    66
    cmsFloat64Number RGBc[3];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    67
    cmsFloat64Number RGBp[3];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    68
    cmsFloat64Number RGBpa[3];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    69
    cmsFloat64Number a, b, h, e, H, A, J, Q, s, t, C, M;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    70
    cmsFloat64Number abC[2];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    71
    cmsFloat64Number abs[2];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    72
    cmsFloat64Number abM[2];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    74
} CAM02COLOR;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
typedef struct  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    CAM02COLOR adoptedWhite;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    79
    cmsFloat64Number LA, Yb;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    80
    cmsFloat64Number F, c, Nc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    81
    cmsUInt32Number surround;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    82
    cmsFloat64Number n, Nbb, Ncb, z, FL, D;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    84
       cmsContext ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    85
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    86
} cmsCIECAM02;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    90
cmsFloat64Number compute_n(cmsCIECAM02* pMod)
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
    return (pMod -> Yb / pMod -> adoptedWhite.XYZ[1]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    96
cmsFloat64Number compute_z(cmsCIECAM02* pMod)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    98
    return (1.48 + pow(pMod -> n, 0.5));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   102
cmsFloat64Number computeNbb(cmsCIECAM02* pMod)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   104
    return (0.725 * pow((1.0 / pMod -> n), 0.2));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   108
cmsFloat64Number computeFL(cmsCIECAM02* pMod)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   110
    cmsFloat64Number k, FL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    k = 1.0 / ((5.0 * pMod->LA) + 1.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    FL = 0.2 * pow(k, 4.0) * (5.0 * pMod->LA) + 0.1 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        (pow((1.0 - pow(k, 4.0)), 2.0)) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        (pow((5.0 * pMod->LA), (1.0 / 3.0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    return FL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   121
cmsFloat64Number computeD(cmsCIECAM02* pMod)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   123
    cmsFloat64Number D;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    D = pMod->F - (1.0/3.6)*(exp(((-pMod ->LA-42) / 92.0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    return D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
CAM02COLOR XYZtoCAT02(CAM02COLOR clr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    clr.RGB[0] = (clr.XYZ[0] *  0.7328) + (clr.XYZ[1] *  0.4296) + (clr.XYZ[2] * -0.1624);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    clr.RGB[1] = (clr.XYZ[0] * -0.7036) + (clr.XYZ[1] *  1.6975) + (clr.XYZ[2] *  0.0061);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    clr.RGB[2] = (clr.XYZ[0] *  0.0030) + (clr.XYZ[1] *  0.0136) + (clr.XYZ[2] *  0.9834);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    return clr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   142
CAM02COLOR ChromaticAdaptation(CAM02COLOR clr, cmsCIECAM02* pMod)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   144
    cmsUInt32Number i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   145
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    for (i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        clr.RGBc[i] = ((pMod -> adoptedWhite.XYZ[1] *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            (pMod->D / pMod -> adoptedWhite.RGB[i])) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            (1.0 - pMod->D)) * clr.RGB[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    return clr;
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
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   157
CAM02COLOR CAT02toHPE(CAM02COLOR clr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   159
    cmsFloat64Number M[9];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    M[0] =(( 0.38971 *  1.096124) + (0.68898 * 0.454369) + (-0.07868 * -0.009628));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    M[1] =(( 0.38971 * -0.278869) + (0.68898 * 0.473533) + (-0.07868 * -0.005698));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    M[2] =(( 0.38971 *  0.182745) + (0.68898 * 0.072098) + (-0.07868 *  1.015326));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    M[3] =((-0.22981 *  1.096124) + (1.18340 * 0.454369) + ( 0.04641 * -0.009628));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    M[4] =((-0.22981 * -0.278869) + (1.18340 * 0.473533) + ( 0.04641 * -0.005698));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    M[5] =((-0.22981 *  0.182745) + (1.18340 * 0.072098) + ( 0.04641 *  1.015326));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    M[6] =(-0.009628);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    M[7] =(-0.005698);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    M[8] =( 1.015326);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    clr.RGBp[0] = (clr.RGBc[0] * M[0]) +  (clr.RGBc[1] * M[1]) + (clr.RGBc[2] * M[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    clr.RGBp[1] = (clr.RGBc[0] * M[3]) +  (clr.RGBc[1] * M[4]) + (clr.RGBc[2] * M[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    clr.RGBp[2] = (clr.RGBc[0] * M[6]) +  (clr.RGBc[1] * M[7]) + (clr.RGBc[2] * M[8]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    return  clr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   179
CAM02COLOR NonlinearCompression(CAM02COLOR clr, cmsCIECAM02* pMod)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   181
    cmsUInt32Number i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   182
    cmsFloat64Number temp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    for (i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (clr.RGBp[i] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            temp = pow((-1.0 * pMod->FL * clr.RGBp[i] / 100.0), 0.42);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            clr.RGBpa[i] = (-1.0 * 400.0 * temp) / (temp + 27.13) + 0.1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            temp = pow((pMod->FL * clr.RGBp[i] / 100.0), 0.42);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            clr.RGBpa[i] = (400.0 * temp) / (temp + 27.13) + 0.1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   195
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   196
    clr.A = (((2.0 * clr.RGBpa[0]) + clr.RGBpa[1] +
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   197
        (clr.RGBpa[2] / 20.0)) - 0.305) * pMod->Nbb;
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   198
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    return clr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   203
CAM02COLOR ComputeCorrelates(CAM02COLOR clr, cmsCIECAM02* pMod)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   205
    cmsFloat64Number a, b, temp, e, t, r2d, d2r;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    a = clr.RGBpa[0] - (12.0 * clr.RGBpa[1] / 11.0) + (clr.RGBpa[2] / 11.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    b = (clr.RGBpa[0] + clr.RGBpa[1] - (2.0 * clr.RGBpa[2])) / 9.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    r2d = (180.0 / 3.141592654);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    if (a == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (b == 0)     clr.h = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        else if (b > 0) clr.h = 90;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        else            clr.h = 270;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    else if (a > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        temp = b / a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (b > 0)       clr.h = (r2d * atan(temp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        else if (b == 0) clr.h = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        else             clr.h = (r2d * atan(temp)) + 360;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        temp = b / a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        clr.h = (r2d * atan(temp)) + 180;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    d2r = (3.141592654 / 180.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    e = ((12500.0 / 13.0) * pMod->Nc * pMod->Ncb) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        (cos((clr.h * d2r + 2.0)) + 3.8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    if (clr.h < 20.14) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        temp = ((clr.h + 122.47)/1.2) + ((20.14 - clr.h)/0.8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        clr.H = 300 + (100*((clr.h + 122.47)/1.2)) / temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    else if (clr.h < 90.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        temp = ((clr.h - 20.14)/0.8) + ((90.00 - clr.h)/0.7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        clr.H = (100*((clr.h - 20.14)/0.8)) / temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    else if (clr.h < 164.25) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        temp = ((clr.h - 90.00)/0.7) + ((164.25 - clr.h)/1.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        clr.H = 100 + ((100*((clr.h - 90.00)/0.7)) / temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    else if (clr.h < 237.53) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        temp = ((clr.h - 164.25)/1.0) + ((237.53 - clr.h)/1.2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        clr.H = 200 + ((100*((clr.h - 164.25)/1.0)) / temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        temp = ((clr.h - 237.53)/1.2) + ((360 - clr.h + 20.14)/0.8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        clr.H = 300 + ((100*((clr.h - 237.53)/1.2)) / temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    clr.J = 100.0 * pow((clr.A / pMod->adoptedWhite.A),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        (pMod->c * pMod->z));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    clr.Q = (4.0 / pMod->c) * pow((clr.J / 100.0), 0.5) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        (pMod->adoptedWhite.A + 4.0) * pow(pMod->FL, 0.25);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    t = (e * pow(((a * a) + (b * b)), 0.5)) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        (clr.RGBpa[0] + clr.RGBpa[1] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        ((21.0 / 20.0) * clr.RGBpa[2]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    clr.C = pow(t, 0.9) * pow((clr.J / 100.0), 0.5) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        pow((1.64 - pow(0.29, pMod->n)), 0.73);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    clr.M = clr.C * pow(pMod->FL, 0.25);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    clr.s = 100.0 * pow((clr.M / clr.Q), 0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    return clr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   273
CAM02COLOR InverseCorrelates(CAM02COLOR clr, cmsCIECAM02* pMod)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   276
    cmsFloat64Number t, e, p1, p2, p3, p4, p5, hr, d2r;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    d2r = 3.141592654 / 180.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    t = pow( (clr.C / (pow((clr.J / 100.0), 0.5) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        (pow((1.64 - pow(0.29, pMod->n)), 0.73)))),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        (1.0 / 0.9) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    e = ((12500.0 / 13.0) * pMod->Nc * pMod->Ncb) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        (cos((clr.h * d2r + 2.0)) + 3.8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    clr.A = pMod->adoptedWhite.A * pow(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
           (clr.J / 100.0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
           (1.0 / (pMod->c * pMod->z)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    p1 = e / t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    p2 = (clr.A / pMod->Nbb) + 0.305;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    p3 = 21.0 / 20.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    hr = clr.h * d2r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    if (fabs(sin(hr)) >= fabs(cos(hr))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        p4 = p1 / sin(hr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        clr.b = (p2 * (2.0 + p3) * (460.0 / 1403.0)) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            (p4 + (2.0 + p3) * (220.0 / 1403.0) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            (cos(hr) / sin(hr)) - (27.0 / 1403.0) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            p3 * (6300.0 / 1403.0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        clr.a = clr.b * (cos(hr) / sin(hr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        p5 = p1 / cos(hr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        clr.a = (p2 * (2.0 + p3) * (460.0 / 1403.0)) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            (p5 + (2.0 + p3) * (220.0 / 1403.0) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            ((27.0 / 1403.0) - p3 * (6300.0 / 1403.0)) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            (sin(hr) / cos(hr)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        clr.b = clr.a * (sin(hr) / cos(hr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    clr.RGBpa[0] = ((460.0 / 1403.0) * p2) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
              ((451.0 / 1403.0) * clr.a) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
              ((288.0 / 1403.0) * clr.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    clr.RGBpa[1] = ((460.0 / 1403.0) * p2) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
              ((891.0 / 1403.0) * clr.a) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
              ((261.0 / 1403.0) * clr.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    clr.RGBpa[2] = ((460.0 / 1403.0) * p2) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
              ((220.0 / 1403.0) * clr.a) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
              ((6300.0 / 1403.0) * clr.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    return clr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   326
CAM02COLOR InverseNonlinearity(CAM02COLOR clr, cmsCIECAM02* pMod)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   328
    cmsUInt32Number i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   329
    cmsFloat64Number c1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    for (i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if ((clr.RGBpa[i] - 0.1) < 0) c1 = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        else                               c1 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        clr.RGBp[i] = c1 * (100.0 / pMod->FL) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            pow(((27.13 * fabs(clr.RGBpa[i] - 0.1)) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            (400.0 - fabs(clr.RGBpa[i] - 0.1))),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            (1.0 / 0.42));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    return clr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
CAM02COLOR HPEtoCAT02(CAM02COLOR clr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   346
    cmsFloat64Number M[9];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    M[0] = (( 0.7328 *  1.910197) + (0.4296 * 0.370950));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    M[1] = (( 0.7328 * -1.112124) + (0.4296 * 0.629054));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    M[2] = (( 0.7328 *  0.201908) + (0.4296 * 0.000008) - 0.1624);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    M[3] = ((-0.7036 *  1.910197) + (1.6975 * 0.370950));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    M[4] = ((-0.7036 * -1.112124) + (1.6975 * 0.629054));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    M[5] = ((-0.7036 *  0.201908) + (1.6975 * 0.000008) + 0.0061);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    M[6] = (( 0.0030 *  1.910197) + (0.0136 * 0.370950));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    M[7] = (( 0.0030 * -1.112124) + (0.0136 * 0.629054));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    M[8] = (( 0.0030 *  0.201908) + (0.0136 * 0.000008) + 0.9834);;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    clr.RGBc[0] = (clr.RGBp[0] * M[0]) + (clr.RGBp[1] * M[1]) + (clr.RGBp[2] * M[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    clr.RGBc[1] = (clr.RGBp[0] * M[3]) + (clr.RGBp[1] * M[4]) + (clr.RGBp[2] * M[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    clr.RGBc[2] = (clr.RGBp[0] * M[6]) + (clr.RGBp[1] * M[7]) + (clr.RGBp[2] * M[8]);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   361
    return clr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   366
CAM02COLOR InverseChromaticAdaptation(CAM02COLOR clr,  cmsCIECAM02* pMod)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   368
    cmsUInt32Number i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    for (i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        clr.RGB[i] = clr.RGBc[i] /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            ((pMod->adoptedWhite.XYZ[1] * pMod->D / pMod->adoptedWhite.RGB[i]) + 1.0 - pMod->D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   373
    return clr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
CAM02COLOR CAT02toXYZ(CAM02COLOR clr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    clr.XYZ[0] = (clr.RGB[0] *  1.096124) + (clr.RGB[1] * -0.278869) + (clr.RGB[2] *  0.182745);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    clr.XYZ[1] = (clr.RGB[0] *  0.454369) + (clr.RGB[1] *  0.473533) + (clr.RGB[2] *  0.072098);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    clr.XYZ[2] = (clr.RGB[0] * -0.009628) + (clr.RGB[1] * -0.005698) + (clr.RGB[2] *  1.015326);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   384
    return clr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   388
cmsHANDLE  CMSEXPORT cmsCIECAM02Init(cmsContext ContextID, const cmsViewingConditions* pVC)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   390
    cmsCIECAM02* lpMod;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   392
    _cmsAssert(pVC != NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   393
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   394
    if((lpMod = (cmsCIECAM02*) _cmsMallocZero(ContextID, sizeof(cmsCIECAM02))) == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   395
        return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   398
    lpMod ->ContextID = ContextID;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    lpMod ->adoptedWhite.XYZ[0] = pVC ->whitePoint.X;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    lpMod ->adoptedWhite.XYZ[1] = pVC ->whitePoint.Y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    lpMod ->adoptedWhite.XYZ[2] = pVC ->whitePoint.Z;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    lpMod -> LA       = pVC ->La;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    lpMod -> Yb       = pVC ->Yb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    lpMod -> D        = pVC ->D_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    lpMod -> surround = pVC ->surround;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    switch (lpMod -> surround) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   412
      case CUTSHEET_SURROUND:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   413
          lpMod->F = 0.8;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   414
          lpMod->c = 0.41;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   415
          lpMod->Nc = 0.8;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   416
          break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   418
      case DARK_SURROUND:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   419
          lpMod -> F  = 0.8;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   420
          lpMod -> c  = 0.525;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   421
          lpMod -> Nc = 0.8;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   422
          break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   424
      case DIM_SURROUND:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   425
          lpMod -> F  = 0.9;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   426
          lpMod -> c  = 0.59;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   427
          lpMod -> Nc = 0.95;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   428
          break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   430
      default:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   431
          // Average surround
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   432
          lpMod -> F  = 1.0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   433
          lpMod -> c  = 0.69;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   434
          lpMod -> Nc = 1.0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    lpMod -> n   = compute_n(lpMod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    lpMod -> z   = compute_z(lpMod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    lpMod -> Nbb = computeNbb(lpMod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    lpMod -> FL  = computeFL(lpMod);
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   441
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   442
    if (lpMod -> D == D_CALCULATE) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   443
        lpMod -> D   = computeD(lpMod);
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   444
    }
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   445
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    lpMod -> Ncb = lpMod -> Nbb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    lpMod -> adoptedWhite = XYZtoCAT02(lpMod -> adoptedWhite);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    lpMod -> adoptedWhite = ChromaticAdaptation(lpMod -> adoptedWhite, lpMod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    lpMod -> adoptedWhite = CAT02toHPE(lpMod -> adoptedWhite);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    lpMod -> adoptedWhite = NonlinearCompression(lpMod -> adoptedWhite, lpMod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   453
    return (cmsHANDLE) lpMod;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   457
void CMSEXPORT cmsCIECAM02Done(cmsHANDLE hModel)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   459
    cmsCIECAM02* lpMod = (cmsCIECAM02*) hModel;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   460
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   461
    if (lpMod) _cmsFree(lpMod ->ContextID, lpMod);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   465
void CMSEXPORT cmsCIECAM02Forward(cmsHANDLE hModel, const cmsCIEXYZ* pIn, cmsJCh* pOut)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    CAM02COLOR clr;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   468
    cmsCIECAM02* lpMod = (cmsCIECAM02*) hModel;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   469
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   470
    _cmsAssert(lpMod != NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   471
    _cmsAssert(pIn != NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   472
    _cmsAssert(pOut != NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    clr.XYZ[0] = pIn ->X;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    clr.XYZ[1] = pIn ->Y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    clr.XYZ[2] = pIn ->Z;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    clr = XYZtoCAT02(clr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    clr = ChromaticAdaptation(clr, lpMod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    clr = CAT02toHPE(clr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    clr = NonlinearCompression(clr, lpMod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    clr = ComputeCorrelates(clr, lpMod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    pOut ->J = clr.J;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    pOut ->C = clr.C;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    pOut ->h = clr.h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   489
void CMSEXPORT cmsCIECAM02Reverse(cmsHANDLE hModel, const cmsJCh* pIn, cmsCIEXYZ* pOut)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    CAM02COLOR clr;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   492
    cmsCIECAM02* lpMod = (cmsCIECAM02*) hModel;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   494
    _cmsAssert(lpMod != NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   495
    _cmsAssert(pIn != NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   496
    _cmsAssert(pOut != NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    clr.J = pIn -> J;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    clr.C = pIn -> C;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    clr.h = pIn -> h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    clr = InverseCorrelates(clr, lpMod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    clr = InverseNonlinearity(clr, lpMod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    clr = HPEtoCAT02(clr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    clr = InverseChromaticAdaptation(clr, lpMod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    clr = CAT02toXYZ(clr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    pOut ->X = clr.XYZ[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    pOut ->Y = clr.XYZ[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    pOut ->Z = clr.XYZ[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
}
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   512