jdk/src/java.desktop/share/native/liblcms/cmsopt.c
author prr
Tue, 16 Sep 2014 09:26:06 -0700
changeset 26747 2a4b66b4d50a
parent 26609 de18f570018c
child 30491 ea1c291ee28f
permissions -rw-r--r--
8058248: LittleCMS: Missing checks for NULL returns from memory allocation Reviewed-by: bae, jchen, mschoene
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
     1
/*
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
     3
 *
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
     9
 *
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    14
 * accompanied this code).
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    15
 *
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    19
 *
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    22
 * questions.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    23
 */
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    24
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    25
// This file is available under and governed by the GNU General Public
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    26
// License version 2 only, as published by the Free Software Foundation.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    27
// However, the following notice accompanied the original version of this
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    28
// file:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    29
//
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
    30
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    31
//---------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    32
//
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    33
//  Little Color Management System
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
    34
//  Copyright (c) 1998-2011 Marti Maria Saguer
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    35
//
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    36
// Permission is hereby granted, free of charge, to any person obtaining
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    37
// a copy of this software and associated documentation files (the "Software"),
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    38
// to deal in the Software without restriction, including without limitation
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    39
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    40
// and/or sell copies of the Software, and to permit persons to whom the Software
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    41
// is furnished to do so, subject to the following conditions:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    42
//
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    43
// The above copyright notice and this permission notice shall be included in
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    44
// all copies or substantial portions of the Software.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    45
//
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    46
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    47
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    48
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    49
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    50
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    51
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    52
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    53
//
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    54
//---------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    55
//
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    56
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    57
#include "lcms2_internal.h"
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    58
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    59
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    60
//----------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    61
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    62
// Optimization for 8 bits, Shaper-CLUT (3 inputs only)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    63
typedef struct {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    64
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    65
    cmsContext ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    66
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    67
    const cmsInterpParams* p;   // Tetrahedrical interpolation parameters. This is a not-owned pointer.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    68
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    69
    cmsUInt16Number rx[256], ry[256], rz[256];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    70
    cmsUInt32Number X0[256], Y0[256], Z0[256];  // Precomputed nodes and offsets for 8-bit input data
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    71
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    72
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    73
} Prelin8Data;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    74
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    75
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    76
// Generic optimization for 16 bits Shaper-CLUT-Shaper (any inputs)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    77
typedef struct {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    78
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    79
    cmsContext ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    80
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    81
    // Number of channels
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    82
    int nInputs;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    83
    int nOutputs;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    84
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    85
    _cmsInterpFn16 EvalCurveIn16[MAX_INPUT_DIMENSIONS];       // The maximum number of input channels is known in advance
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    86
    cmsInterpParams*  ParamsCurveIn16[MAX_INPUT_DIMENSIONS];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    87
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    88
    _cmsInterpFn16 EvalCLUT;            // The evaluator for 3D grid
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    89
    const cmsInterpParams* CLUTparams;  // (not-owned pointer)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    90
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    91
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    92
    _cmsInterpFn16* EvalCurveOut16;       // Points to an array of curve evaluators in 16 bits (not-owned pointer)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    93
    cmsInterpParams**  ParamsCurveOut16;  // Points to an array of references to interpolation params (not-owned pointer)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    94
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    95
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    96
} Prelin16Data;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    97
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    98
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
    99
// Optimization for matrix-shaper in 8 bits. Numbers are operated in n.14 signed, tables are stored in 1.14 fixed
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   100
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   101
typedef cmsInt32Number cmsS1Fixed14Number;   // Note that this may hold more than 16 bits!
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   102
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   103
#define DOUBLE_TO_1FIXED14(x) ((cmsS1Fixed14Number) floor((x) * 16384.0 + 0.5))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   104
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   105
typedef struct {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   106
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   107
    cmsContext ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   108
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   109
    cmsS1Fixed14Number Shaper1R[256];  // from 0..255 to 1.14  (0.0...1.0)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   110
    cmsS1Fixed14Number Shaper1G[256];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   111
    cmsS1Fixed14Number Shaper1B[256];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   112
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   113
    cmsS1Fixed14Number Mat[3][3];     // n.14 to n.14 (needs a saturation after that)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   114
    cmsS1Fixed14Number Off[3];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   115
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   116
    cmsUInt16Number Shaper2R[16385];    // 1.14 to 0..255
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   117
    cmsUInt16Number Shaper2G[16385];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   118
    cmsUInt16Number Shaper2B[16385];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   119
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   120
} MatShaper8Data;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   121
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   122
// Curves, optimization is shared between 8 and 16 bits
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   123
typedef struct {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   124
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   125
    cmsContext ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   126
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   127
    int nCurves;                  // Number of curves
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   128
    int nElements;                // Elements in curves
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   129
    cmsUInt16Number** Curves;     // Points to a dynamically  allocated array
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   130
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   131
} Curves16Data;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   132
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   133
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   134
// Simple optimizations ----------------------------------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   135
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   136
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   137
// Remove an element in linked chain
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   138
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   139
void _RemoveElement(cmsStage** head)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   140
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   141
    cmsStage* mpe = *head;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   142
    cmsStage* next = mpe ->Next;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   143
    *head = next;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   144
    cmsStageFree(mpe);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   145
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   146
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   147
// Remove all identities in chain. Note that pt actually is a double pointer to the element that holds the pointer.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   148
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   149
cmsBool _Remove1Op(cmsPipeline* Lut, cmsStageSignature UnaryOp)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   150
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   151
    cmsStage** pt = &Lut ->Elements;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   152
    cmsBool AnyOpt = FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   153
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   154
    while (*pt != NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   155
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   156
        if ((*pt) ->Implements == UnaryOp) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   157
            _RemoveElement(pt);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   158
            AnyOpt = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   159
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   160
        else
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   161
            pt = &((*pt) -> Next);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   162
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   163
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   164
    return AnyOpt;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   165
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   166
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   167
// Same, but only if two adjacent elements are found
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   168
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   169
cmsBool _Remove2Op(cmsPipeline* Lut, cmsStageSignature Op1, cmsStageSignature Op2)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   170
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   171
    cmsStage** pt1;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   172
    cmsStage** pt2;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   173
    cmsBool AnyOpt = FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   174
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   175
    pt1 = &Lut ->Elements;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   176
    if (*pt1 == NULL) return AnyOpt;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   177
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   178
    while (*pt1 != NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   179
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   180
        pt2 = &((*pt1) -> Next);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   181
        if (*pt2 == NULL) return AnyOpt;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   182
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   183
        if ((*pt1) ->Implements == Op1 && (*pt2) ->Implements == Op2) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   184
            _RemoveElement(pt2);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   185
            _RemoveElement(pt1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   186
            AnyOpt = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   187
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   188
        else
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   189
            pt1 = &((*pt1) -> Next);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   190
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   191
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   192
    return AnyOpt;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   193
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   194
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   195
// Preoptimize just gets rif of no-ops coming paired. Conversion from v2 to v4 followed
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   196
// by a v4 to v2 and vice-versa. The elements are then discarded.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   197
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   198
cmsBool PreOptimize(cmsPipeline* Lut)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   199
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   200
    cmsBool AnyOpt = FALSE, Opt;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   201
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   202
    do {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   203
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   204
        Opt = FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   205
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   206
        // Remove all identities
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   207
        Opt |= _Remove1Op(Lut, cmsSigIdentityElemType);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   208
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   209
        // Remove XYZ2Lab followed by Lab2XYZ
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   210
        Opt |= _Remove2Op(Lut, cmsSigXYZ2LabElemType, cmsSigLab2XYZElemType);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   211
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   212
        // Remove Lab2XYZ followed by XYZ2Lab
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   213
        Opt |= _Remove2Op(Lut, cmsSigLab2XYZElemType, cmsSigXYZ2LabElemType);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   214
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   215
        // Remove V4 to V2 followed by V2 to V4
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   216
        Opt |= _Remove2Op(Lut, cmsSigLabV4toV2, cmsSigLabV2toV4);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   217
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   218
        // Remove V2 to V4 followed by V4 to V2
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   219
        Opt |= _Remove2Op(Lut, cmsSigLabV2toV4, cmsSigLabV4toV2);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   220
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   221
        // Remove float pcs Lab conversions
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   222
        Opt |= _Remove2Op(Lut, cmsSigLab2FloatPCS, cmsSigFloatPCS2Lab);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   223
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   224
        // Remove float pcs Lab conversions
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   225
        Opt |= _Remove2Op(Lut, cmsSigXYZ2FloatPCS, cmsSigFloatPCS2XYZ);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   226
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   227
        if (Opt) AnyOpt = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   228
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   229
    } while (Opt);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   230
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   231
    return AnyOpt;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   232
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   233
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   234
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   235
void Eval16nop1D(register const cmsUInt16Number Input[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   236
                 register cmsUInt16Number Output[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   237
                 register const struct _cms_interp_struc* p)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   238
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   239
    Output[0] = Input[0];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   240
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   241
    cmsUNUSED_PARAMETER(p);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   242
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   243
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   244
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   245
void PrelinEval16(register const cmsUInt16Number Input[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   246
                  register cmsUInt16Number Output[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   247
                  register const void* D)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   248
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   249
    Prelin16Data* p16 = (Prelin16Data*) D;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   250
    cmsUInt16Number  StageABC[MAX_INPUT_DIMENSIONS];
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   251
    cmsUInt16Number  StageDEF[cmsMAXCHANNELS];
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   252
    int i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   253
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   254
    for (i=0; i < p16 ->nInputs; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   255
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   256
        p16 ->EvalCurveIn16[i](&Input[i], &StageABC[i], p16 ->ParamsCurveIn16[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   257
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   258
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   259
    p16 ->EvalCLUT(StageABC, StageDEF, p16 ->CLUTparams);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   260
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   261
    for (i=0; i < p16 ->nOutputs; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   262
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   263
        p16 ->EvalCurveOut16[i](&StageDEF[i], &Output[i], p16 ->ParamsCurveOut16[i]);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   264
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   265
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   266
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   267
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   268
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   269
void PrelinOpt16free(cmsContext ContextID, void* ptr)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   270
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   271
    Prelin16Data* p16 = (Prelin16Data*) ptr;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   272
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   273
    _cmsFree(ContextID, p16 ->EvalCurveOut16);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   274
    _cmsFree(ContextID, p16 ->ParamsCurveOut16);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   275
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   276
    _cmsFree(ContextID, p16);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   277
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   278
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   279
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   280
void* Prelin16dup(cmsContext ContextID, const void* ptr)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   281
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   282
    Prelin16Data* p16 = (Prelin16Data*) ptr;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   283
    Prelin16Data* Duped = _cmsDupMem(ContextID, p16, sizeof(Prelin16Data));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   284
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   285
    if (Duped == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   286
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   287
    Duped ->EvalCurveOut16   = _cmsDupMem(ContextID, p16 ->EvalCurveOut16, p16 ->nOutputs * sizeof(_cmsInterpFn16));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   288
    Duped ->ParamsCurveOut16 = _cmsDupMem(ContextID, p16 ->ParamsCurveOut16, p16 ->nOutputs * sizeof(cmsInterpParams* ));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   289
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   290
    return Duped;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   291
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   292
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   293
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   294
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   295
Prelin16Data* PrelinOpt16alloc(cmsContext ContextID,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   296
                               const cmsInterpParams* ColorMap,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   297
                               int nInputs, cmsToneCurve** In,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   298
                               int nOutputs, cmsToneCurve** Out )
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   299
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   300
    int i;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   301
    Prelin16Data* p16 = _cmsMallocZero(ContextID, sizeof(Prelin16Data));
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   302
    if (p16 == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   303
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   304
    p16 ->nInputs = nInputs;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   305
    p16 -> nOutputs = nOutputs;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   306
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   307
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   308
    for (i=0; i < nInputs; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   309
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   310
        if (In == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   311
            p16 -> ParamsCurveIn16[i] = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   312
            p16 -> EvalCurveIn16[i] = Eval16nop1D;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   313
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   314
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   315
        else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   316
            p16 -> ParamsCurveIn16[i] = In[i] ->InterpParams;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   317
            p16 -> EvalCurveIn16[i] = p16 ->ParamsCurveIn16[i]->Interpolation.Lerp16;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   318
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   319
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   320
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   321
    p16 ->CLUTparams = ColorMap;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   322
    p16 ->EvalCLUT   = ColorMap ->Interpolation.Lerp16;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   323
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   324
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   325
    p16 -> EvalCurveOut16 = (_cmsInterpFn16*) _cmsCalloc(ContextID, nOutputs, sizeof(_cmsInterpFn16));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   326
    p16 -> ParamsCurveOut16 = (cmsInterpParams**) _cmsCalloc(ContextID, nOutputs, sizeof(cmsInterpParams* ));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   327
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   328
    for (i=0; i < nOutputs; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   329
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   330
        if (Out == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   331
            p16 ->ParamsCurveOut16[i] = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   332
            p16 -> EvalCurveOut16[i] = Eval16nop1D;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   333
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   334
        else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   335
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   336
            p16 ->ParamsCurveOut16[i] = Out[i] ->InterpParams;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   337
            p16 -> EvalCurveOut16[i] = p16 ->ParamsCurveOut16[i]->Interpolation.Lerp16;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   338
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   339
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   340
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   341
    return p16;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   342
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   343
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   344
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   345
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   346
// Resampling ---------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   347
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   348
#define PRELINEARIZATION_POINTS 4096
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   349
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   350
// Sampler implemented by another LUT. This is a clean way to precalculate the devicelink 3D CLUT for
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   351
// almost any transform. We use floating point precision and then convert from floating point to 16 bits.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   352
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   353
int XFormSampler16(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   354
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   355
    cmsPipeline* Lut = (cmsPipeline*) Cargo;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   356
    cmsFloat32Number InFloat[cmsMAXCHANNELS], OutFloat[cmsMAXCHANNELS];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   357
    cmsUInt32Number i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   358
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   359
    _cmsAssert(Lut -> InputChannels < cmsMAXCHANNELS);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   360
    _cmsAssert(Lut -> OutputChannels < cmsMAXCHANNELS);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   361
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   362
    // From 16 bit to floating point
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   363
    for (i=0; i < Lut ->InputChannels; i++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   364
        InFloat[i] = (cmsFloat32Number) (In[i] / 65535.0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   365
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   366
    // Evaluate in floating point
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   367
    cmsPipelineEvalFloat(InFloat, OutFloat, Lut);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   368
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   369
    // Back to 16 bits representation
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   370
    for (i=0; i < Lut ->OutputChannels; i++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   371
        Out[i] = _cmsQuickSaturateWord(OutFloat[i] * 65535.0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   372
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   373
    // Always succeed
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   374
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   375
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   376
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   377
// Try to see if the curves of a given MPE are linear
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   378
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   379
cmsBool AllCurvesAreLinear(cmsStage* mpe)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   380
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   381
    cmsToneCurve** Curves;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   382
    cmsUInt32Number i, n;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   383
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   384
    Curves = _cmsStageGetPtrToCurveSet(mpe);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   385
    if (Curves == NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   386
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   387
    n = cmsStageOutputChannels(mpe);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   388
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   389
    for (i=0; i < n; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   390
        if (!cmsIsToneCurveLinear(Curves[i])) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   391
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   392
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   393
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   394
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   395
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   396
// This function replaces a specific node placed in "At" by the "Value" numbers. Its purpose
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   397
// is to fix scum dot on broken profiles/transforms. Works on 1, 3 and 4 channels
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   398
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   399
cmsBool  PatchLUT(cmsStage* CLUT, cmsUInt16Number At[], cmsUInt16Number Value[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   400
                  int nChannelsOut, int nChannelsIn)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   401
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   402
    _cmsStageCLutData* Grid = (_cmsStageCLutData*) CLUT ->Data;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   403
    cmsInterpParams* p16  = Grid ->Params;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   404
    cmsFloat64Number px, py, pz, pw;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   405
    int        x0, y0, z0, w0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   406
    int        i, index;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   407
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   408
    if (CLUT -> Type != cmsSigCLutElemType) {
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   409
        cmsSignalError(CLUT->ContextID, cmsERROR_INTERNAL, "(internal) Attempt to PatchLUT on non-lut stage");
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   410
        return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   411
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   412
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   413
    if (nChannelsIn == 4) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   414
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   415
        px = ((cmsFloat64Number) At[0] * (p16->Domain[0])) / 65535.0;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   416
        py = ((cmsFloat64Number) At[1] * (p16->Domain[1])) / 65535.0;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   417
        pz = ((cmsFloat64Number) At[2] * (p16->Domain[2])) / 65535.0;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   418
        pw = ((cmsFloat64Number) At[3] * (p16->Domain[3])) / 65535.0;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   419
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   420
        x0 = (int) floor(px);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   421
        y0 = (int) floor(py);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   422
        z0 = (int) floor(pz);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   423
        w0 = (int) floor(pw);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   424
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   425
        if (((px - x0) != 0) ||
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   426
            ((py - y0) != 0) ||
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   427
            ((pz - z0) != 0) ||
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   428
            ((pw - w0) != 0)) return FALSE; // Not on exact node
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   429
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   430
        index = p16 -> opta[3] * x0 +
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   431
                p16 -> opta[2] * y0 +
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   432
                p16 -> opta[1] * z0 +
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   433
                p16 -> opta[0] * w0;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   434
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   435
    else
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   436
        if (nChannelsIn == 3) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   437
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   438
            px = ((cmsFloat64Number) At[0] * (p16->Domain[0])) / 65535.0;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   439
            py = ((cmsFloat64Number) At[1] * (p16->Domain[1])) / 65535.0;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   440
            pz = ((cmsFloat64Number) At[2] * (p16->Domain[2])) / 65535.0;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   441
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   442
            x0 = (int) floor(px);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   443
            y0 = (int) floor(py);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   444
            z0 = (int) floor(pz);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   445
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   446
            if (((px - x0) != 0) ||
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   447
                ((py - y0) != 0) ||
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   448
                ((pz - z0) != 0)) return FALSE;  // Not on exact node
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   449
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   450
            index = p16 -> opta[2] * x0 +
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   451
                    p16 -> opta[1] * y0 +
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   452
                    p16 -> opta[0] * z0;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   453
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   454
        else
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   455
            if (nChannelsIn == 1) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   456
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   457
                px = ((cmsFloat64Number) At[0] * (p16->Domain[0])) / 65535.0;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   458
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   459
                x0 = (int) floor(px);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   460
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   461
                if (((px - x0) != 0)) return FALSE; // Not on exact node
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   462
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   463
                index = p16 -> opta[0] * x0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   464
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   465
            else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   466
                cmsSignalError(CLUT->ContextID, cmsERROR_INTERNAL, "(internal) %d Channels are not supported on PatchLUT", nChannelsIn);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   467
                return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   468
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   469
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   470
            for (i=0; i < nChannelsOut; i++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   471
                Grid -> Tab.T[index + i] = Value[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   472
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   473
            return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   474
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   475
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   476
// Auxiliar, to see if two values are equal or very different
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   477
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   478
cmsBool WhitesAreEqual(int n, cmsUInt16Number White1[], cmsUInt16Number White2[] )
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   479
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   480
    int i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   481
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   482
    for (i=0; i < n; i++) {
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   483
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   484
        if (abs(White1[i] - White2[i]) > 0xf000) return TRUE;  // Values are so extremly different that the fixup should be avoided
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   485
        if (White1[i] != White2[i]) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   486
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   487
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   488
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   489
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   490
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   491
// Locate the node for the white point and fix it to pure white in order to avoid scum dot.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   492
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   493
cmsBool FixWhiteMisalignment(cmsPipeline* Lut, cmsColorSpaceSignature EntryColorSpace, cmsColorSpaceSignature ExitColorSpace)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   494
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   495
    cmsUInt16Number *WhitePointIn, *WhitePointOut;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   496
    cmsUInt16Number  WhiteIn[cmsMAXCHANNELS], WhiteOut[cmsMAXCHANNELS], ObtainedOut[cmsMAXCHANNELS];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   497
    cmsUInt32Number i, nOuts, nIns;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   498
    cmsStage *PreLin = NULL, *CLUT = NULL, *PostLin = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   499
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   500
    if (!_cmsEndPointsBySpace(EntryColorSpace,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   501
        &WhitePointIn, NULL, &nIns)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   502
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   503
    if (!_cmsEndPointsBySpace(ExitColorSpace,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   504
        &WhitePointOut, NULL, &nOuts)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   505
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   506
    // It needs to be fixed?
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   507
    if (Lut ->InputChannels != nIns) return FALSE;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   508
    if (Lut ->OutputChannels != nOuts) return FALSE;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   509
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   510
    cmsPipelineEval16(WhitePointIn, ObtainedOut, Lut);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   511
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   512
    if (WhitesAreEqual(nOuts, WhitePointOut, ObtainedOut)) return TRUE; // whites already match
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   513
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   514
    // Check if the LUT comes as Prelin, CLUT or Postlin. We allow all combinations
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   515
    if (!cmsPipelineCheckAndRetreiveStages(Lut, 3, cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType, &PreLin, &CLUT, &PostLin))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   516
        if (!cmsPipelineCheckAndRetreiveStages(Lut, 2, cmsSigCurveSetElemType, cmsSigCLutElemType, &PreLin, &CLUT))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   517
            if (!cmsPipelineCheckAndRetreiveStages(Lut, 2, cmsSigCLutElemType, cmsSigCurveSetElemType, &CLUT, &PostLin))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   518
                if (!cmsPipelineCheckAndRetreiveStages(Lut, 1, cmsSigCLutElemType, &CLUT))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   519
                    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   520
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   521
    // We need to interpolate white points of both, pre and post curves
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   522
    if (PreLin) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   523
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   524
        cmsToneCurve** Curves = _cmsStageGetPtrToCurveSet(PreLin);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   525
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   526
        for (i=0; i < nIns; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   527
            WhiteIn[i] = cmsEvalToneCurve16(Curves[i], WhitePointIn[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   528
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   529
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   530
    else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   531
        for (i=0; i < nIns; i++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   532
            WhiteIn[i] = WhitePointIn[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   533
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   534
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   535
    // If any post-linearization, we need to find how is represented white before the curve, do
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   536
    // a reverse interpolation in this case.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   537
    if (PostLin) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   538
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   539
        cmsToneCurve** Curves = _cmsStageGetPtrToCurveSet(PostLin);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   540
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   541
        for (i=0; i < nOuts; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   542
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   543
            cmsToneCurve* InversePostLin = cmsReverseToneCurve(Curves[i]);
18750
e06dee31a864 8014497: [parfait] Potential null pointer dereference in jdk/src/share/native/sun/java2d/cmm/lcms/cmsgamma.c
jchen
parents: 18200
diff changeset
   544
            if (InversePostLin == NULL) {
26609
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
   545
                WhiteOut[i] = WhitePointOut[i];
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
   546
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
   547
            } else {
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
   548
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
   549
                WhiteOut[i] = cmsEvalToneCurve16(InversePostLin, WhitePointOut[i]);
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
   550
                cmsFreeToneCurve(InversePostLin);
18750
e06dee31a864 8014497: [parfait] Potential null pointer dereference in jdk/src/share/native/sun/java2d/cmm/lcms/cmsgamma.c
jchen
parents: 18200
diff changeset
   551
            }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   552
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   553
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   554
    else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   555
        for (i=0; i < nOuts; i++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   556
            WhiteOut[i] = WhitePointOut[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   557
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   558
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   559
    // Ok, proceed with patching. May fail and we don't care if it fails
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   560
    PatchLUT(CLUT, WhiteIn, WhiteOut, nOuts, nIns);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   561
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   562
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   563
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   564
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   565
// -----------------------------------------------------------------------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   566
// This function creates simple LUT from complex ones. The generated LUT has an optional set of
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   567
// prelinearization curves, a CLUT of nGridPoints and optional postlinearization tables.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   568
// These curves have to exist in the original LUT in order to be used in the simplified output.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   569
// Caller may also use the flags to allow this feature.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   570
// LUTS with all curves will be simplified to a single curve. Parametric curves are lost.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   571
// This function should be used on 16-bits LUTS only, as floating point losses precision when simplified
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   572
// -----------------------------------------------------------------------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   573
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   574
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   575
cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   576
{
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   577
    cmsPipeline* Src = NULL;
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   578
    cmsPipeline* Dest = NULL;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   579
    cmsStage* mpe;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   580
    cmsStage* CLUT;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   581
    cmsStage *KeepPreLin = NULL, *KeepPostLin = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   582
    int nGridPoints;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   583
    cmsColorSpaceSignature ColorSpace, OutputColorSpace;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   584
    cmsStage *NewPreLin = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   585
    cmsStage *NewPostLin = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   586
    _cmsStageCLutData* DataCLUT;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   587
    cmsToneCurve** DataSetIn;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   588
    cmsToneCurve** DataSetOut;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   589
    Prelin16Data* p16;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   590
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   591
    // This is a loosy optimization! does not apply in floating-point cases
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   592
    if (_cmsFormatterIsFloat(*InputFormat) || _cmsFormatterIsFloat(*OutputFormat)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   593
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   594
    ColorSpace       = _cmsICCcolorSpace(T_COLORSPACE(*InputFormat));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   595
    OutputColorSpace = _cmsICCcolorSpace(T_COLORSPACE(*OutputFormat));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   596
    nGridPoints      = _cmsReasonableGridpointsByColorspace(ColorSpace, *dwFlags);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   597
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   598
    // For empty LUTs, 2 points are enough
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   599
    if (cmsPipelineStageCount(*Lut) == 0)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   600
        nGridPoints = 2;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   601
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   602
    Src = *Lut;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   603
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   604
    // Named color pipelines cannot be optimized either
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   605
    for (mpe = cmsPipelineGetPtrToFirstStage(Src);
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   606
        mpe != NULL;
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   607
        mpe = cmsStageNext(mpe)) {
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   608
            if (cmsStageType(mpe) == cmsSigNamedColorElemType) return FALSE;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   609
    }
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   610
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   611
    // Allocate an empty LUT
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   612
    Dest =  cmsPipelineAlloc(Src ->ContextID, Src ->InputChannels, Src ->OutputChannels);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   613
    if (!Dest) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   614
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   615
    // Prelinearization tables are kept unless indicated by flags
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   616
    if (*dwFlags & cmsFLAGS_CLUT_PRE_LINEARIZATION) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   617
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   618
        // Get a pointer to the prelinearization element
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   619
        cmsStage* PreLin = cmsPipelineGetPtrToFirstStage(Src);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   620
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   621
        // Check if suitable
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   622
        if (PreLin ->Type == cmsSigCurveSetElemType) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   623
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   624
            // Maybe this is a linear tram, so we can avoid the whole stuff
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   625
            if (!AllCurvesAreLinear(PreLin)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   626
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   627
                // All seems ok, proceed.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   628
                NewPreLin = cmsStageDup(PreLin);
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   629
                if(!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, NewPreLin))
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   630
                    goto Error;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   631
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   632
                // Remove prelinearization. Since we have duplicated the curve
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   633
                // in destination LUT, the sampling shoud be applied after this stage.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   634
                cmsPipelineUnlinkStage(Src, cmsAT_BEGIN, &KeepPreLin);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   635
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   636
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   637
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   638
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   639
    // Allocate the CLUT
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   640
    CLUT = cmsStageAllocCLut16bit(Src ->ContextID, nGridPoints, Src ->InputChannels, Src->OutputChannels, NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   641
    if (CLUT == NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   642
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   643
    // Add the CLUT to the destination LUT
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   644
    if (!cmsPipelineInsertStage(Dest, cmsAT_END, CLUT)) {
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   645
        goto Error;
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   646
    }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   647
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   648
    // Postlinearization tables are kept unless indicated by flags
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   649
    if (*dwFlags & cmsFLAGS_CLUT_POST_LINEARIZATION) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   650
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   651
        // Get a pointer to the postlinearization if present
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   652
        cmsStage* PostLin = cmsPipelineGetPtrToLastStage(Src);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   653
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   654
        // Check if suitable
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   655
        if (cmsStageType(PostLin) == cmsSigCurveSetElemType) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   656
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   657
            // Maybe this is a linear tram, so we can avoid the whole stuff
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   658
            if (!AllCurvesAreLinear(PostLin)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   659
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   660
                // All seems ok, proceed.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   661
                NewPostLin = cmsStageDup(PostLin);
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   662
                if (!cmsPipelineInsertStage(Dest, cmsAT_END, NewPostLin))
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   663
                    goto Error;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   664
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   665
                // In destination LUT, the sampling shoud be applied after this stage.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   666
                cmsPipelineUnlinkStage(Src, cmsAT_END, &KeepPostLin);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   667
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   668
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   669
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   670
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   671
    // Now its time to do the sampling. We have to ignore pre/post linearization
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   672
    // The source LUT whithout pre/post curves is passed as parameter.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   673
    if (!cmsStageSampleCLut16bit(CLUT, XFormSampler16, (void*) Src, 0)) {
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   674
Error:
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   675
        // Ops, something went wrong, Restore stages
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   676
        if (KeepPreLin != NULL) {
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   677
            if (!cmsPipelineInsertStage(Src, cmsAT_BEGIN, KeepPreLin)) {
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   678
                _cmsAssert(0); // This never happens
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   679
            }
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   680
        }
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   681
        if (KeepPostLin != NULL) {
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   682
            if (!cmsPipelineInsertStage(Src, cmsAT_END,   KeepPostLin)) {
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   683
                _cmsAssert(0); // This never happens
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   684
            }
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   685
        }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   686
        cmsPipelineFree(Dest);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   687
        return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   688
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   689
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   690
    // Done.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   691
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   692
    if (KeepPreLin != NULL) cmsStageFree(KeepPreLin);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   693
    if (KeepPostLin != NULL) cmsStageFree(KeepPostLin);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   694
    cmsPipelineFree(Src);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   695
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   696
    DataCLUT = (_cmsStageCLutData*) CLUT ->Data;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   697
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   698
    if (NewPreLin == NULL) DataSetIn = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   699
    else DataSetIn = ((_cmsStageToneCurvesData*) NewPreLin ->Data) ->TheCurves;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   700
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   701
    if (NewPostLin == NULL) DataSetOut = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   702
    else  DataSetOut = ((_cmsStageToneCurvesData*) NewPostLin ->Data) ->TheCurves;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   703
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   704
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   705
    if (DataSetIn == NULL && DataSetOut == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   706
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   707
        _cmsPipelineSetOptimizationParameters(Dest, (_cmsOPTeval16Fn) DataCLUT->Params->Interpolation.Lerp16, DataCLUT->Params, NULL, NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   708
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   709
    else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   710
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   711
        p16 = PrelinOpt16alloc(Dest ->ContextID,
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   712
            DataCLUT ->Params,
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   713
            Dest ->InputChannels,
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   714
            DataSetIn,
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   715
            Dest ->OutputChannels,
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
   716
            DataSetOut);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   717
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   718
        _cmsPipelineSetOptimizationParameters(Dest, PrelinEval16, (void*) p16, PrelinOpt16free, Prelin16dup);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   719
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   720
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   721
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   722
    // Don't fix white on absolute colorimetric
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   723
    if (Intent == INTENT_ABSOLUTE_COLORIMETRIC)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   724
        *dwFlags |= cmsFLAGS_NOWHITEONWHITEFIXUP;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   725
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   726
    if (!(*dwFlags & cmsFLAGS_NOWHITEONWHITEFIXUP)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   727
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   728
        FixWhiteMisalignment(Dest, ColorSpace, OutputColorSpace);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   729
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   730
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   731
    *Lut = Dest;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   732
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   733
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   734
    cmsUNUSED_PARAMETER(Intent);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   735
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   736
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   737
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   738
// -----------------------------------------------------------------------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   739
// Fixes the gamma balancing of transform. This is described in my paper "Prelinearization Stages on
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   740
// Color-Management Application-Specific Integrated Circuits (ASICs)" presented at NIP24. It only works
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   741
// for RGB transforms. See the paper for more details
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   742
// -----------------------------------------------------------------------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   743
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   744
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   745
// Normalize endpoints by slope limiting max and min. This assures endpoints as well.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   746
// Descending curves are handled as well.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   747
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   748
void SlopeLimiting(cmsToneCurve* g)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   749
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   750
    int BeginVal, EndVal;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   751
    int AtBegin = (int) floor((cmsFloat64Number) g ->nEntries * 0.02 + 0.5);   // Cutoff at 2%
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   752
    int AtEnd   = g ->nEntries - AtBegin - 1;                                  // And 98%
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   753
    cmsFloat64Number Val, Slope, beta;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   754
    int i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   755
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   756
    if (cmsIsToneCurveDescending(g)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   757
        BeginVal = 0xffff; EndVal = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   758
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   759
    else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   760
        BeginVal = 0; EndVal = 0xffff;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   761
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   762
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   763
    // Compute slope and offset for begin of curve
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   764
    Val   = g ->Table16[AtBegin];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   765
    Slope = (Val - BeginVal) / AtBegin;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   766
    beta  = Val - Slope * AtBegin;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   767
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   768
    for (i=0; i < AtBegin; i++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   769
        g ->Table16[i] = _cmsQuickSaturateWord(i * Slope + beta);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   770
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   771
    // Compute slope and offset for the end
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   772
    Val   = g ->Table16[AtEnd];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   773
    Slope = (EndVal - Val) / AtBegin;   // AtBegin holds the X interval, which is same in both cases
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   774
    beta  = Val - Slope * AtEnd;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   775
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   776
    for (i = AtEnd; i < (int) g ->nEntries; i++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   777
        g ->Table16[i] = _cmsQuickSaturateWord(i * Slope + beta);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   778
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   779
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   780
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   781
// Precomputes tables for 8-bit on input devicelink.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   782
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   783
Prelin8Data* PrelinOpt8alloc(cmsContext ContextID, const cmsInterpParams* p, cmsToneCurve* G[3])
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   784
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   785
    int i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   786
    cmsUInt16Number Input[3];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   787
    cmsS15Fixed16Number v1, v2, v3;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   788
    Prelin8Data* p8;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   789
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   790
    p8 = _cmsMallocZero(ContextID, sizeof(Prelin8Data));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   791
    if (p8 == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   792
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   793
    // Since this only works for 8 bit input, values comes always as x * 257,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   794
    // we can safely take msb byte (x << 8 + x)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   795
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   796
    for (i=0; i < 256; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   797
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   798
        if (G != NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   799
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   800
            // Get 16-bit representation
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   801
            Input[0] = cmsEvalToneCurve16(G[0], FROM_8_TO_16(i));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   802
            Input[1] = cmsEvalToneCurve16(G[1], FROM_8_TO_16(i));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   803
            Input[2] = cmsEvalToneCurve16(G[2], FROM_8_TO_16(i));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   804
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   805
        else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   806
            Input[0] = FROM_8_TO_16(i);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   807
            Input[1] = FROM_8_TO_16(i);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   808
            Input[2] = FROM_8_TO_16(i);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   809
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   810
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   811
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   812
        // Move to 0..1.0 in fixed domain
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   813
        v1 = _cmsToFixedDomain(Input[0] * p -> Domain[0]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   814
        v2 = _cmsToFixedDomain(Input[1] * p -> Domain[1]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   815
        v3 = _cmsToFixedDomain(Input[2] * p -> Domain[2]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   816
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   817
        // Store the precalculated table of nodes
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   818
        p8 ->X0[i] = (p->opta[2] * FIXED_TO_INT(v1));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   819
        p8 ->Y0[i] = (p->opta[1] * FIXED_TO_INT(v2));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   820
        p8 ->Z0[i] = (p->opta[0] * FIXED_TO_INT(v3));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   821
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   822
        // Store the precalculated table of offsets
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   823
        p8 ->rx[i] = (cmsUInt16Number) FIXED_REST_TO_INT(v1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   824
        p8 ->ry[i] = (cmsUInt16Number) FIXED_REST_TO_INT(v2);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   825
        p8 ->rz[i] = (cmsUInt16Number) FIXED_REST_TO_INT(v3);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   826
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   827
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   828
    p8 ->ContextID = ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   829
    p8 ->p = p;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   830
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   831
    return p8;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   832
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   833
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   834
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   835
void Prelin8free(cmsContext ContextID, void* ptr)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   836
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   837
    _cmsFree(ContextID, ptr);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   838
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   839
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   840
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   841
void* Prelin8dup(cmsContext ContextID, const void* ptr)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   842
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   843
    return _cmsDupMem(ContextID, ptr, sizeof(Prelin8Data));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   844
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   845
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   846
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   847
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   848
// A optimized interpolation for 8-bit input.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   849
#define DENS(i,j,k) (LutTable[(i)+(j)+(k)+OutChan])
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   850
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   851
void PrelinEval8(register const cmsUInt16Number Input[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   852
                  register cmsUInt16Number Output[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   853
                  register const void* D)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   854
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   855
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   856
    cmsUInt8Number         r, g, b;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   857
    cmsS15Fixed16Number    rx, ry, rz;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   858
    cmsS15Fixed16Number    c0, c1, c2, c3, Rest;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   859
    int                    OutChan;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   860
    register cmsS15Fixed16Number    X0, X1, Y0, Y1, Z0, Z1;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   861
    Prelin8Data* p8 = (Prelin8Data*) D;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   862
    register const cmsInterpParams* p = p8 ->p;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   863
    int                    TotalOut = p -> nOutputs;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   864
    const cmsUInt16Number* LutTable = p -> Table;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   865
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   866
    r = Input[0] >> 8;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   867
    g = Input[1] >> 8;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   868
    b = Input[2] >> 8;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   869
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   870
    X0 = X1 = p8->X0[r];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   871
    Y0 = Y1 = p8->Y0[g];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   872
    Z0 = Z1 = p8->Z0[b];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   873
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   874
    rx = p8 ->rx[r];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   875
    ry = p8 ->ry[g];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   876
    rz = p8 ->rz[b];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   877
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   878
    X1 = X0 + ((rx == 0) ? 0 : p ->opta[2]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   879
    Y1 = Y0 + ((ry == 0) ? 0 : p ->opta[1]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   880
    Z1 = Z0 + ((rz == 0) ? 0 : p ->opta[0]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   881
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   882
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   883
    // These are the 6 Tetrahedral
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   884
    for (OutChan=0; OutChan < TotalOut; OutChan++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   885
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   886
        c0 = DENS(X0, Y0, Z0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   887
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   888
        if (rx >= ry && ry >= rz)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   889
        {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   890
            c1 = DENS(X1, Y0, Z0) - c0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   891
            c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   892
            c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   893
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   894
        else
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   895
            if (rx >= rz && rz >= ry)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   896
            {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   897
                c1 = DENS(X1, Y0, Z0) - c0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   898
                c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   899
                c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   900
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   901
            else
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   902
                if (rz >= rx && rx >= ry)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   903
                {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   904
                    c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   905
                    c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   906
                    c3 = DENS(X0, Y0, Z1) - c0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   907
                }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   908
                else
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   909
                    if (ry >= rx && rx >= rz)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   910
                    {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   911
                        c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   912
                        c2 = DENS(X0, Y1, Z0) - c0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   913
                        c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   914
                    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   915
                    else
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   916
                        if (ry >= rz && rz >= rx)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   917
                        {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   918
                            c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   919
                            c2 = DENS(X0, Y1, Z0) - c0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   920
                            c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   921
                        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   922
                        else
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   923
                            if (rz >= ry && ry >= rx)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   924
                            {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   925
                                c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   926
                                c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   927
                                c3 = DENS(X0, Y0, Z1) - c0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   928
                            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   929
                            else  {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   930
                                c1 = c2 = c3 = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   931
                            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   932
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   933
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   934
                            Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   935
                            Output[OutChan] = (cmsUInt16Number)c0 + ((Rest + (Rest>>16))>>16);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   936
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   937
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   938
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   939
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   940
#undef DENS
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   941
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   942
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   943
// Curves that contain wide empty areas are not optimizeable
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   944
static
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   945
cmsBool IsDegenerated(const cmsToneCurve* g)
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   946
{
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   947
    int i, Zeros = 0, Poles = 0;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   948
    int nEntries = g ->nEntries;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   949
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   950
    for (i=0; i < nEntries; i++) {
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   951
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   952
        if (g ->Table16[i] == 0x0000) Zeros++;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   953
        if (g ->Table16[i] == 0xffff) Poles++;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   954
    }
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   955
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   956
    if (Zeros == 1 && Poles == 1) return FALSE;  // For linear tables
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   957
    if (Zeros > (nEntries / 4)) return TRUE;  // Degenerated, mostly zeros
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   958
    if (Poles > (nEntries / 4)) return TRUE;  // Degenerated, mostly poles
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   959
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   960
    return FALSE;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   961
}
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   962
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   963
// --------------------------------------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   964
// We need xput over here
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   965
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   966
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   967
cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   968
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   969
    cmsPipeline* OriginalLut;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   970
    int nGridPoints;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   971
    cmsToneCurve *Trans[cmsMAXCHANNELS], *TransReverse[cmsMAXCHANNELS];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   972
    cmsUInt32Number t, i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   973
    cmsFloat32Number v, In[cmsMAXCHANNELS], Out[cmsMAXCHANNELS];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   974
    cmsBool lIsSuitable, lIsLinear;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   975
    cmsPipeline* OptimizedLUT = NULL, *LutPlusCurves = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   976
    cmsStage* OptimizedCLUTmpe;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   977
    cmsColorSpaceSignature ColorSpace, OutputColorSpace;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   978
    cmsStage* OptimizedPrelinMpe;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   979
    cmsStage* mpe;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   980
    cmsToneCurve**   OptimizedPrelinCurves;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   981
    _cmsStageCLutData*     OptimizedPrelinCLUT;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   982
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   983
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   984
    // This is a loosy optimization! does not apply in floating-point cases
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   985
    if (_cmsFormatterIsFloat(*InputFormat) || _cmsFormatterIsFloat(*OutputFormat)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   986
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   987
    // Only on RGB
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   988
    if (T_COLORSPACE(*InputFormat)  != PT_RGB) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   989
    if (T_COLORSPACE(*OutputFormat) != PT_RGB) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   990
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   991
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   992
    // On 16 bits, user has to specify the feature
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   993
    if (!_cmsFormatterIs8bit(*InputFormat)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   994
        if (!(*dwFlags & cmsFLAGS_CLUT_PRE_LINEARIZATION)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   995
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   996
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
   997
    OriginalLut = *Lut;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   998
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
   999
   // Named color pipelines cannot be optimized either
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1000
   for (mpe = cmsPipelineGetPtrToFirstStage(OriginalLut);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1001
         mpe != NULL;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1002
         mpe = cmsStageNext(mpe)) {
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1003
            if (cmsStageType(mpe) == cmsSigNamedColorElemType) return FALSE;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1004
    }
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1005
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1006
    ColorSpace       = _cmsICCcolorSpace(T_COLORSPACE(*InputFormat));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1007
    OutputColorSpace = _cmsICCcolorSpace(T_COLORSPACE(*OutputFormat));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1008
    nGridPoints      = _cmsReasonableGridpointsByColorspace(ColorSpace, *dwFlags);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1009
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1010
    // Empty gamma containers
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1011
    memset(Trans, 0, sizeof(Trans));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1012
    memset(TransReverse, 0, sizeof(TransReverse));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1013
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1014
    for (t = 0; t < OriginalLut ->InputChannels; t++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1015
        Trans[t] = cmsBuildTabulatedToneCurve16(OriginalLut ->ContextID, PRELINEARIZATION_POINTS, NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1016
        if (Trans[t] == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1017
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1018
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1019
    // Populate the curves
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1020
    for (i=0; i < PRELINEARIZATION_POINTS; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1021
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1022
        v = (cmsFloat32Number) ((cmsFloat64Number) i / (PRELINEARIZATION_POINTS - 1));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1023
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1024
        // Feed input with a gray ramp
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1025
        for (t=0; t < OriginalLut ->InputChannels; t++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1026
            In[t] = v;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1027
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1028
        // Evaluate the gray value
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1029
        cmsPipelineEvalFloat(In, Out, OriginalLut);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1030
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1031
        // Store result in curve
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1032
        for (t=0; t < OriginalLut ->InputChannels; t++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1033
            Trans[t] ->Table16[i] = _cmsQuickSaturateWord(Out[t] * 65535.0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1034
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1035
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1036
    // Slope-limit the obtained curves
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1037
    for (t = 0; t < OriginalLut ->InputChannels; t++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1038
        SlopeLimiting(Trans[t]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1039
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1040
    // Check for validity
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1041
    lIsSuitable = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1042
    lIsLinear   = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1043
    for (t=0; (lIsSuitable && (t < OriginalLut ->InputChannels)); t++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1044
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1045
        // Exclude if already linear
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1046
        if (!cmsIsToneCurveLinear(Trans[t]))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1047
            lIsLinear = FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1048
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1049
        // Exclude if non-monotonic
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1050
        if (!cmsIsToneCurveMonotonic(Trans[t]))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1051
            lIsSuitable = FALSE;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1052
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1053
        if (IsDegenerated(Trans[t]))
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1054
            lIsSuitable = FALSE;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1055
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1056
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1057
    // If it is not suitable, just quit
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1058
    if (!lIsSuitable) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1059
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1060
    // Invert curves if possible
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1061
    for (t = 0; t < OriginalLut ->InputChannels; t++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1062
        TransReverse[t] = cmsReverseToneCurveEx(PRELINEARIZATION_POINTS, Trans[t]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1063
        if (TransReverse[t] == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1064
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1065
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1066
    // Now inset the reversed curves at the begin of transform
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1067
    LutPlusCurves = cmsPipelineDup(OriginalLut);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1068
    if (LutPlusCurves == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1069
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1070
    if (!cmsPipelineInsertStage(LutPlusCurves, cmsAT_BEGIN, cmsStageAllocToneCurves(OriginalLut ->ContextID, OriginalLut ->InputChannels, TransReverse)))
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1071
        goto Error;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1072
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1073
    // Create the result LUT
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1074
    OptimizedLUT = cmsPipelineAlloc(OriginalLut ->ContextID, OriginalLut ->InputChannels, OriginalLut ->OutputChannels);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1075
    if (OptimizedLUT == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1076
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1077
    OptimizedPrelinMpe = cmsStageAllocToneCurves(OriginalLut ->ContextID, OriginalLut ->InputChannels, Trans);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1078
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1079
    // Create and insert the curves at the beginning
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1080
    if (!cmsPipelineInsertStage(OptimizedLUT, cmsAT_BEGIN, OptimizedPrelinMpe))
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1081
        goto Error;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1082
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1083
    // Allocate the CLUT for result
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1084
    OptimizedCLUTmpe = cmsStageAllocCLut16bit(OriginalLut ->ContextID, nGridPoints, OriginalLut ->InputChannels, OriginalLut ->OutputChannels, NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1085
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1086
    // Add the CLUT to the destination LUT
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1087
    if (!cmsPipelineInsertStage(OptimizedLUT, cmsAT_END, OptimizedCLUTmpe))
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1088
        goto Error;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1089
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1090
    // Resample the LUT
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1091
    if (!cmsStageSampleCLut16bit(OptimizedCLUTmpe, XFormSampler16, (void*) LutPlusCurves, 0)) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1092
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1093
    // Free resources
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1094
    for (t = 0; t < OriginalLut ->InputChannels; t++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1095
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1096
        if (Trans[t]) cmsFreeToneCurve(Trans[t]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1097
        if (TransReverse[t]) cmsFreeToneCurve(TransReverse[t]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1098
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1099
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1100
    cmsPipelineFree(LutPlusCurves);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1101
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1102
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1103
    OptimizedPrelinCurves = _cmsStageGetPtrToCurveSet(OptimizedPrelinMpe);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1104
    OptimizedPrelinCLUT   = (_cmsStageCLutData*) OptimizedCLUTmpe ->Data;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1105
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1106
    // Set the evaluator if 8-bit
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1107
    if (_cmsFormatterIs8bit(*InputFormat)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1108
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1109
        Prelin8Data* p8 = PrelinOpt8alloc(OptimizedLUT ->ContextID,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1110
                                                OptimizedPrelinCLUT ->Params,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1111
                                                OptimizedPrelinCurves);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1112
        if (p8 == NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1113
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1114
        _cmsPipelineSetOptimizationParameters(OptimizedLUT, PrelinEval8, (void*) p8, Prelin8free, Prelin8dup);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1115
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1116
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1117
    else
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1118
    {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1119
        Prelin16Data* p16 = PrelinOpt16alloc(OptimizedLUT ->ContextID,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1120
            OptimizedPrelinCLUT ->Params,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1121
            3, OptimizedPrelinCurves, 3, NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1122
        if (p16 == NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1123
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1124
        _cmsPipelineSetOptimizationParameters(OptimizedLUT, PrelinEval16, (void*) p16, PrelinOpt16free, Prelin16dup);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1125
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1126
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1127
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1128
    // Don't fix white on absolute colorimetric
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1129
    if (Intent == INTENT_ABSOLUTE_COLORIMETRIC)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1130
        *dwFlags |= cmsFLAGS_NOWHITEONWHITEFIXUP;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1131
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1132
    if (!(*dwFlags & cmsFLAGS_NOWHITEONWHITEFIXUP)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1133
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1134
        if (!FixWhiteMisalignment(OptimizedLUT, ColorSpace, OutputColorSpace)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1135
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1136
            return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1137
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1138
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1139
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1140
    // And return the obtained LUT
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1141
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1142
    cmsPipelineFree(OriginalLut);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1143
    *Lut = OptimizedLUT;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1144
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1145
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1146
Error:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1147
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1148
    for (t = 0; t < OriginalLut ->InputChannels; t++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1149
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1150
        if (Trans[t]) cmsFreeToneCurve(Trans[t]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1151
        if (TransReverse[t]) cmsFreeToneCurve(TransReverse[t]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1152
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1153
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1154
    if (LutPlusCurves != NULL) cmsPipelineFree(LutPlusCurves);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1155
    if (OptimizedLUT != NULL) cmsPipelineFree(OptimizedLUT);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1156
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1157
    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1158
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1159
    cmsUNUSED_PARAMETER(Intent);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1160
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1161
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1162
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1163
// Curves optimizer ------------------------------------------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1164
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1165
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1166
void CurvesFree(cmsContext ContextID, void* ptr)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1167
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1168
     Curves16Data* Data = (Curves16Data*) ptr;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1169
     int i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1170
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1171
     for (i=0; i < Data -> nCurves; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1172
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1173
         _cmsFree(ContextID, Data ->Curves[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1174
     }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1175
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1176
     _cmsFree(ContextID, Data ->Curves);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1177
     _cmsFree(ContextID, ptr);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1178
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1179
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1180
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1181
void* CurvesDup(cmsContext ContextID, const void* ptr)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1182
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1183
    Curves16Data* Data = _cmsDupMem(ContextID, ptr, sizeof(Curves16Data));
26747
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1184
    int i, j;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1185
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1186
    if (Data == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1187
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1188
    Data ->Curves = _cmsDupMem(ContextID, Data ->Curves, Data ->nCurves * sizeof(cmsUInt16Number*));
26747
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1189
    if (Data -> Curves == NULL) {
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1190
        _cmsFree(ContextID, Data);
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1191
        return NULL;
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1192
    }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1193
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1194
    for (i=0; i < Data -> nCurves; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1195
        Data ->Curves[i] = _cmsDupMem(ContextID, Data ->Curves[i], Data -> nElements * sizeof(cmsUInt16Number));
26747
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1196
        if (Data->Curves[i] == NULL) {
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1197
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1198
            for (j=0; j < i; j++) {
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1199
                _cmsFree(ContextID, Data->Curves[j]);
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1200
            }
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1201
            _cmsFree(ContextID, Data->Curves);
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1202
            _cmsFree(ContextID, Data);
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1203
            return NULL;
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1204
        }
2a4b66b4d50a 8058248: LittleCMS: Missing checks for NULL returns from memory allocation
prr
parents: 26609
diff changeset
  1205
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1206
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1207
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1208
    return (void*) Data;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1209
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1210
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1211
// Precomputes tables for 8-bit on input devicelink.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1212
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1213
Curves16Data* CurvesAlloc(cmsContext ContextID, int nCurves, int nElements, cmsToneCurve** G)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1214
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1215
    int i, j;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1216
    Curves16Data* c16;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1217
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1218
    c16 = _cmsMallocZero(ContextID, sizeof(Curves16Data));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1219
    if (c16 == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1220
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1221
    c16 ->nCurves = nCurves;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1222
    c16 ->nElements = nElements;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1223
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1224
    c16 ->Curves = _cmsCalloc(ContextID, nCurves, sizeof(cmsUInt16Number*));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1225
    if (c16 ->Curves == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1226
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1227
    for (i=0; i < nCurves; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1228
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1229
        c16->Curves[i] = _cmsCalloc(ContextID, nElements, sizeof(cmsUInt16Number));
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1230
18200
7b3ae6f27043 8007929: Improve CurvesAlloc
jgodinez
parents: 14300
diff changeset
  1231
        if (c16->Curves[i] == NULL) {
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1232
18200
7b3ae6f27043 8007929: Improve CurvesAlloc
jgodinez
parents: 14300
diff changeset
  1233
            for (j=0; j < i; j++) {
7b3ae6f27043 8007929: Improve CurvesAlloc
jgodinez
parents: 14300
diff changeset
  1234
                _cmsFree(ContextID, c16->Curves[j]);
7b3ae6f27043 8007929: Improve CurvesAlloc
jgodinez
parents: 14300
diff changeset
  1235
            }
7b3ae6f27043 8007929: Improve CurvesAlloc
jgodinez
parents: 14300
diff changeset
  1236
            _cmsFree(ContextID, c16->Curves);
7b3ae6f27043 8007929: Improve CurvesAlloc
jgodinez
parents: 14300
diff changeset
  1237
            _cmsFree(ContextID, c16);
7b3ae6f27043 8007929: Improve CurvesAlloc
jgodinez
parents: 14300
diff changeset
  1238
            return NULL;
7b3ae6f27043 8007929: Improve CurvesAlloc
jgodinez
parents: 14300
diff changeset
  1239
        }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1240
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1241
        if (nElements == 256) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1242
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1243
            for (j=0; j < nElements; j++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1244
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1245
                c16 ->Curves[i][j] = cmsEvalToneCurve16(G[i], FROM_8_TO_16(j));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1246
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1247
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1248
        else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1249
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1250
            for (j=0; j < nElements; j++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1251
                c16 ->Curves[i][j] = cmsEvalToneCurve16(G[i], (cmsUInt16Number) j);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1252
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1253
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1254
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1255
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1256
    return c16;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1257
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1258
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1259
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1260
void FastEvaluateCurves8(register const cmsUInt16Number In[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1261
                          register cmsUInt16Number Out[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1262
                          register const void* D)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1263
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1264
    Curves16Data* Data = (Curves16Data*) D;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1265
    cmsUInt8Number x;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1266
    int i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1267
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1268
    for (i=0; i < Data ->nCurves; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1269
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1270
         x = (In[i] >> 8);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1271
         Out[i] = Data -> Curves[i][x];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1272
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1273
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1274
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1275
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1276
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1277
void FastEvaluateCurves16(register const cmsUInt16Number In[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1278
                          register cmsUInt16Number Out[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1279
                          register const void* D)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1280
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1281
    Curves16Data* Data = (Curves16Data*) D;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1282
    int i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1283
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1284
    for (i=0; i < Data ->nCurves; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1285
         Out[i] = Data -> Curves[i][In[i]];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1286
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1287
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1288
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1289
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1290
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1291
void FastIdentity16(register const cmsUInt16Number In[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1292
                    register cmsUInt16Number Out[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1293
                    register const void* D)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1294
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1295
    cmsPipeline* Lut = (cmsPipeline*) D;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1296
    cmsUInt32Number i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1297
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1298
    for (i=0; i < Lut ->InputChannels; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1299
         Out[i] = In[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1300
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1301
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1302
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1303
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1304
// If the target LUT holds only curves, the optimization procedure is to join all those
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1305
// curves together. That only works on curves and does not work on matrices.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1306
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1307
cmsBool OptimizeByJoiningCurves(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1308
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1309
    cmsToneCurve** GammaTables = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1310
    cmsFloat32Number InFloat[cmsMAXCHANNELS], OutFloat[cmsMAXCHANNELS];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1311
    cmsUInt32Number i, j;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1312
    cmsPipeline* Src = *Lut;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1313
    cmsPipeline* Dest = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1314
    cmsStage* mpe;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1315
    cmsStage* ObtainedCurves = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1316
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1317
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1318
    // This is a loosy optimization! does not apply in floating-point cases
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1319
    if (_cmsFormatterIsFloat(*InputFormat) || _cmsFormatterIsFloat(*OutputFormat)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1320
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1321
    //  Only curves in this LUT?
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1322
    for (mpe = cmsPipelineGetPtrToFirstStage(Src);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1323
         mpe != NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1324
         mpe = cmsStageNext(mpe)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1325
            if (cmsStageType(mpe) != cmsSigCurveSetElemType) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1326
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1327
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1328
    // Allocate an empty LUT
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1329
    Dest =  cmsPipelineAlloc(Src ->ContextID, Src ->InputChannels, Src ->OutputChannels);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1330
    if (Dest == NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1331
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1332
    // Create target curves
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1333
    GammaTables = (cmsToneCurve**) _cmsCalloc(Src ->ContextID, Src ->InputChannels, sizeof(cmsToneCurve*));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1334
    if (GammaTables == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1335
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1336
    for (i=0; i < Src ->InputChannels; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1337
        GammaTables[i] = cmsBuildTabulatedToneCurve16(Src ->ContextID, PRELINEARIZATION_POINTS, NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1338
        if (GammaTables[i] == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1339
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1340
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1341
    // Compute 16 bit result by using floating point
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1342
    for (i=0; i < PRELINEARIZATION_POINTS; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1343
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1344
        for (j=0; j < Src ->InputChannels; j++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1345
            InFloat[j] = (cmsFloat32Number) ((cmsFloat64Number) i / (PRELINEARIZATION_POINTS - 1));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1346
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1347
        cmsPipelineEvalFloat(InFloat, OutFloat, Src);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1348
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1349
        for (j=0; j < Src ->InputChannels; j++)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1350
            GammaTables[j] -> Table16[i] = _cmsQuickSaturateWord(OutFloat[j] * 65535.0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1351
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1352
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1353
    ObtainedCurves = cmsStageAllocToneCurves(Src ->ContextID, Src ->InputChannels, GammaTables);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1354
    if (ObtainedCurves == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1355
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1356
    for (i=0; i < Src ->InputChannels; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1357
        cmsFreeToneCurve(GammaTables[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1358
        GammaTables[i] = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1359
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1360
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1361
    if (GammaTables != NULL) _cmsFree(Src ->ContextID, GammaTables);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1362
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1363
    // Maybe the curves are linear at the end
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1364
    if (!AllCurvesAreLinear(ObtainedCurves)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1365
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1366
        if (!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, ObtainedCurves))
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1367
            goto Error;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1368
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1369
        // If the curves are to be applied in 8 bits, we can save memory
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1370
        if (_cmsFormatterIs8bit(*InputFormat)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1371
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1372
            _cmsStageToneCurvesData* Data = (_cmsStageToneCurvesData*) ObtainedCurves ->Data;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1373
             Curves16Data* c16 = CurvesAlloc(Dest ->ContextID, Data ->nCurves, 256, Data ->TheCurves);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1374
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1375
             if (c16 == NULL) goto Error;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1376
             *dwFlags |= cmsFLAGS_NOCACHE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1377
            _cmsPipelineSetOptimizationParameters(Dest, FastEvaluateCurves8, c16, CurvesFree, CurvesDup);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1378
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1379
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1380
        else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1381
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1382
            _cmsStageToneCurvesData* Data = (_cmsStageToneCurvesData*) cmsStageData(ObtainedCurves);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1383
             Curves16Data* c16 = CurvesAlloc(Dest ->ContextID, Data ->nCurves, 65536, Data ->TheCurves);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1384
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1385
             if (c16 == NULL) goto Error;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1386
             *dwFlags |= cmsFLAGS_NOCACHE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1387
            _cmsPipelineSetOptimizationParameters(Dest, FastEvaluateCurves16, c16, CurvesFree, CurvesDup);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1388
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1389
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1390
    else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1391
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1392
        // LUT optimizes to nothing. Set the identity LUT
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1393
        cmsStageFree(ObtainedCurves);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1394
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1395
        if (!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, cmsStageAllocIdentity(Dest ->ContextID, Src ->InputChannels)))
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1396
            goto Error;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1397
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1398
        *dwFlags |= cmsFLAGS_NOCACHE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1399
        _cmsPipelineSetOptimizationParameters(Dest, FastIdentity16, (void*) Dest, NULL, NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1400
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1401
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1402
    // We are done.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1403
    cmsPipelineFree(Src);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1404
    *Lut = Dest;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1405
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1406
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1407
Error:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1408
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1409
    if (ObtainedCurves != NULL) cmsStageFree(ObtainedCurves);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1410
    if (GammaTables != NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1411
        for (i=0; i < Src ->InputChannels; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1412
            if (GammaTables[i] != NULL) cmsFreeToneCurve(GammaTables[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1413
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1414
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1415
        _cmsFree(Src ->ContextID, GammaTables);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1416
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1417
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1418
    if (Dest != NULL) cmsPipelineFree(Dest);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1419
    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1420
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1421
    cmsUNUSED_PARAMETER(Intent);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1422
    cmsUNUSED_PARAMETER(InputFormat);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1423
    cmsUNUSED_PARAMETER(OutputFormat);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1424
    cmsUNUSED_PARAMETER(dwFlags);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1425
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1426
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1427
// -------------------------------------------------------------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1428
// LUT is Shaper - Matrix - Matrix - Shaper, which is very frequent when combining two matrix-shaper profiles
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1429
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1430
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1431
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1432
void  FreeMatShaper(cmsContext ContextID, void* Data)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1433
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1434
    if (Data != NULL) _cmsFree(ContextID, Data);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1435
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1436
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1437
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1438
void* DupMatShaper(cmsContext ContextID, const void* Data)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1439
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1440
    return _cmsDupMem(ContextID, Data, sizeof(MatShaper8Data));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1441
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1442
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1443
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1444
// A fast matrix-shaper evaluator for 8 bits. This is a bit ticky since I'm using 1.14 signed fixed point
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1445
// to accomplish some performance. Actually it takes 256x3 16 bits tables and 16385 x 3 tables of 8 bits,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1446
// in total about 50K, and the performance boost is huge!
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1447
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1448
void MatShaperEval16(register const cmsUInt16Number In[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1449
                     register cmsUInt16Number Out[],
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1450
                     register const void* D)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1451
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1452
    MatShaper8Data* p = (MatShaper8Data*) D;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1453
    cmsS1Fixed14Number l1, l2, l3, r, g, b;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1454
    cmsUInt32Number ri, gi, bi;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1455
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1456
    // In this case (and only in this case!) we can use this simplification since
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1457
    // In[] is assured to come from a 8 bit number. (a << 8 | a)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1458
    ri = In[0] & 0xFF;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1459
    gi = In[1] & 0xFF;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1460
    bi = In[2] & 0xFF;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1461
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1462
    // Across first shaper, which also converts to 1.14 fixed point
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1463
    r = p->Shaper1R[ri];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1464
    g = p->Shaper1G[gi];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1465
    b = p->Shaper1B[bi];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1466
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1467
    // Evaluate the matrix in 1.14 fixed point
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1468
    l1 =  (p->Mat[0][0] * r + p->Mat[0][1] * g + p->Mat[0][2] * b + p->Off[0] + 0x2000) >> 14;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1469
    l2 =  (p->Mat[1][0] * r + p->Mat[1][1] * g + p->Mat[1][2] * b + p->Off[1] + 0x2000) >> 14;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1470
    l3 =  (p->Mat[2][0] * r + p->Mat[2][1] * g + p->Mat[2][2] * b + p->Off[2] + 0x2000) >> 14;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1471
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1472
    // Now we have to clip to 0..1.0 range
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1473
    ri = (l1 < 0) ? 0 : ((l1 > 16384) ? 16384 : l1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1474
    gi = (l2 < 0) ? 0 : ((l2 > 16384) ? 16384 : l2);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1475
    bi = (l3 < 0) ? 0 : ((l3 > 16384) ? 16384 : l3);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1476
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1477
    // And across second shaper,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1478
    Out[0] = p->Shaper2R[ri];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1479
    Out[1] = p->Shaper2G[gi];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1480
    Out[2] = p->Shaper2B[bi];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1481
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1482
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1483
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1484
// This table converts from 8 bits to 1.14 after applying the curve
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1485
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1486
void FillFirstShaper(cmsS1Fixed14Number* Table, cmsToneCurve* Curve)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1487
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1488
    int i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1489
    cmsFloat32Number R, y;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1490
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1491
    for (i=0; i < 256; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1492
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1493
        R   = (cmsFloat32Number) (i / 255.0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1494
        y   = cmsEvalToneCurveFloat(Curve, R);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1495
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1496
        Table[i] = DOUBLE_TO_1FIXED14(y);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1497
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1498
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1499
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1500
// This table converts form 1.14 (being 0x4000 the last entry) to 8 bits after applying the curve
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1501
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1502
void FillSecondShaper(cmsUInt16Number* Table, cmsToneCurve* Curve, cmsBool Is8BitsOutput)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1503
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1504
    int i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1505
    cmsFloat32Number R, Val;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1506
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1507
    for (i=0; i < 16385; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1508
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1509
        R   = (cmsFloat32Number) (i / 16384.0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1510
        Val = cmsEvalToneCurveFloat(Curve, R);    // Val comes 0..1.0
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1511
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1512
        if (Is8BitsOutput) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1513
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1514
            // If 8 bits output, we can optimize further by computing the / 257 part.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1515
            // first we compute the resulting byte and then we store the byte times
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1516
            // 257. This quantization allows to round very quick by doing a >> 8, but
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1517
            // since the low byte is always equal to msb, we can do a & 0xff and this works!
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1518
            cmsUInt16Number w = _cmsQuickSaturateWord(Val * 65535.0);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1519
            cmsUInt8Number  b = FROM_16_TO_8(w);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1520
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1521
            Table[i] = FROM_8_TO_16(b);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1522
        }
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1523
        else Table[i]  = _cmsQuickSaturateWord(Val * 65535.0);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1524
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1525
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1526
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1527
// Compute the matrix-shaper structure
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1528
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1529
cmsBool SetMatShaper(cmsPipeline* Dest, cmsToneCurve* Curve1[3], cmsMAT3* Mat, cmsVEC3* Off, cmsToneCurve* Curve2[3], cmsUInt32Number* OutputFormat)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1530
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1531
    MatShaper8Data* p;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1532
    int i, j;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1533
    cmsBool Is8Bits = _cmsFormatterIs8bit(*OutputFormat);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1534
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1535
    // Allocate a big chuck of memory to store precomputed tables
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1536
    p = (MatShaper8Data*) _cmsMalloc(Dest ->ContextID, sizeof(MatShaper8Data));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1537
    if (p == NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1538
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1539
    p -> ContextID = Dest -> ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1540
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1541
    // Precompute tables
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1542
    FillFirstShaper(p ->Shaper1R, Curve1[0]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1543
    FillFirstShaper(p ->Shaper1G, Curve1[1]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1544
    FillFirstShaper(p ->Shaper1B, Curve1[2]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1545
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1546
    FillSecondShaper(p ->Shaper2R, Curve2[0], Is8Bits);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1547
    FillSecondShaper(p ->Shaper2G, Curve2[1], Is8Bits);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1548
    FillSecondShaper(p ->Shaper2B, Curve2[2], Is8Bits);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1549
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1550
    // Convert matrix to nFixed14. Note that those values may take more than 16 bits as
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1551
    for (i=0; i < 3; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1552
        for (j=0; j < 3; j++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1553
            p ->Mat[i][j] = DOUBLE_TO_1FIXED14(Mat->v[i].n[j]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1554
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1555
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1556
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1557
    for (i=0; i < 3; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1558
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1559
        if (Off == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1560
            p ->Off[i] = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1561
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1562
        else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1563
            p ->Off[i] = DOUBLE_TO_1FIXED14(Off->n[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1564
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1565
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1566
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1567
    // Mark as optimized for faster formatter
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1568
    if (Is8Bits)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1569
        *OutputFormat |= OPTIMIZED_SH(1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1570
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1571
    // Fill function pointers
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1572
    _cmsPipelineSetOptimizationParameters(Dest, MatShaperEval16, (void*) p, FreeMatShaper, DupMatShaper);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1573
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1574
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1575
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1576
//  8 bits on input allows matrix-shaper boot up to 25 Mpixels per second on RGB. That's fast!
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1577
// TODO: Allow a third matrix for abs. colorimetric
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1578
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1579
cmsBool OptimizeMatrixShaper(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1580
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1581
    cmsStage* Curve1, *Curve2;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1582
    cmsStage* Matrix1, *Matrix2;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1583
    _cmsStageMatrixData* Data1;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1584
    _cmsStageMatrixData* Data2;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1585
    cmsMAT3 res;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1586
    cmsBool IdentityMat;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1587
    cmsPipeline* Dest, *Src;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1588
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1589
    // Only works on RGB to RGB
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1590
    if (T_CHANNELS(*InputFormat) != 3 || T_CHANNELS(*OutputFormat) != 3) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1591
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1592
    // Only works on 8 bit input
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1593
    if (!_cmsFormatterIs8bit(*InputFormat)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1594
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1595
    // Seems suitable, proceed
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1596
    Src = *Lut;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1597
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1598
    // Check for shaper-matrix-matrix-shaper structure, that is what this optimizer stands for
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1599
    if (!cmsPipelineCheckAndRetreiveStages(Src, 4,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1600
        cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1601
        &Curve1, &Matrix1, &Matrix2, &Curve2)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1602
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1603
    // Get both matrices
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1604
    Data1 = (_cmsStageMatrixData*) cmsStageData(Matrix1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1605
    Data2 = (_cmsStageMatrixData*) cmsStageData(Matrix2);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1606
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1607
    // Input offset should be zero
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1608
    if (Data1 ->Offset != NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1609
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1610
    // Multiply both matrices to get the result
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1611
    _cmsMAT3per(&res, (cmsMAT3*) Data2 ->Double, (cmsMAT3*) Data1 ->Double);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1612
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1613
    // Now the result is in res + Data2 -> Offset. Maybe is a plain identity?
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1614
    IdentityMat = FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1615
    if (_cmsMAT3isIdentity(&res) && Data2 ->Offset == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1616
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1617
        // We can get rid of full matrix
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1618
        IdentityMat = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1619
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1620
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1621
      // Allocate an empty LUT
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1622
    Dest =  cmsPipelineAlloc(Src ->ContextID, Src ->InputChannels, Src ->OutputChannels);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1623
    if (!Dest) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1624
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1625
    // Assamble the new LUT
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1626
    if (!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, cmsStageDup(Curve1)))
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1627
        goto Error;
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1628
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1629
    if (!IdentityMat)
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1630
        if (!cmsPipelineInsertStage(Dest, cmsAT_END, cmsStageAllocMatrix(Dest ->ContextID, 3, 3, (const cmsFloat64Number*) &res, Data2 ->Offset)))
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1631
            goto Error;
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1632
    if (!cmsPipelineInsertStage(Dest, cmsAT_END, cmsStageDup(Curve2)))
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1633
        goto Error;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1634
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1635
    // If identity on matrix, we can further optimize the curves, so call the join curves routine
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1636
    if (IdentityMat) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1637
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1638
        OptimizeByJoiningCurves(&Dest, Intent, InputFormat, OutputFormat, dwFlags);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1639
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1640
    else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1641
        _cmsStageToneCurvesData* mpeC1 = (_cmsStageToneCurvesData*) cmsStageData(Curve1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1642
        _cmsStageToneCurvesData* mpeC2 = (_cmsStageToneCurvesData*) cmsStageData(Curve2);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1643
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1644
        // In this particular optimization, caché does not help as it takes more time to deal with
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1645
        // the caché that with the pixel handling
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1646
        *dwFlags |= cmsFLAGS_NOCACHE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1647
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1648
        // Setup the optimizarion routines
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1649
        SetMatShaper(Dest, mpeC1 ->TheCurves, &res, (cmsVEC3*) Data2 ->Offset, mpeC2->TheCurves, OutputFormat);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1650
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1651
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1652
    cmsPipelineFree(Src);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1653
    *Lut = Dest;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1654
    return TRUE;
23906
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1655
Error:
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1656
    // Leave Src unchanged
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1657
    cmsPipelineFree(Dest);
8f7f9cb6fe11 8029750: Enhance LCMS color processing
prr
parents: 18750
diff changeset
  1658
    return FALSE;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1659
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1660
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1661
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1662
// -------------------------------------------------------------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1663
// Optimization plug-ins
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1664
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1665
// List of optimizations
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1666
typedef struct _cmsOptimizationCollection_st {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1667
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1668
    _cmsOPToptimizeFn  OptimizePtr;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1669
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1670
    struct _cmsOptimizationCollection_st *Next;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1671
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1672
} _cmsOptimizationCollection;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1673
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1674
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1675
// The built-in list. We currently implement 4 types of optimizations. Joining of curves, matrix-shaper, linearization and resampling
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1676
static _cmsOptimizationCollection DefaultOptimization[] = {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1677
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1678
    { OptimizeByJoiningCurves,            &DefaultOptimization[1] },
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1679
    { OptimizeMatrixShaper,               &DefaultOptimization[2] },
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1680
    { OptimizeByComputingLinearization,   &DefaultOptimization[3] },
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1681
    { OptimizeByResampling,               NULL }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1682
};
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1683
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1684
// The linked list head
26609
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1685
_cmsOptimizationPluginChunkType _cmsOptimizationPluginChunk = { NULL };
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1686
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1687
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1688
// Duplicates the zone of memory used by the plug-in in the new context
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1689
static
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1690
void DupPluginOptimizationList(struct _cmsContext_struct* ctx,
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1691
                               const struct _cmsContext_struct* src)
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1692
{
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1693
   _cmsOptimizationPluginChunkType newHead = { NULL };
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1694
   _cmsOptimizationCollection*  entry;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1695
   _cmsOptimizationCollection*  Anterior = NULL;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1696
   _cmsOptimizationPluginChunkType* head = (_cmsOptimizationPluginChunkType*) src->chunks[OptimizationPlugin];
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1697
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1698
    _cmsAssert(ctx != NULL);
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1699
    _cmsAssert(head != NULL);
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1700
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1701
    // Walk the list copying all nodes
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1702
   for (entry = head->OptimizationCollection;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1703
        entry != NULL;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1704
        entry = entry ->Next) {
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1705
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1706
            _cmsOptimizationCollection *newEntry = ( _cmsOptimizationCollection *) _cmsSubAllocDup(ctx ->MemPool, entry, sizeof(_cmsOptimizationCollection));
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1707
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1708
            if (newEntry == NULL)
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1709
                return;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1710
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1711
            // We want to keep the linked list order, so this is a little bit tricky
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1712
            newEntry -> Next = NULL;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1713
            if (Anterior)
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1714
                Anterior -> Next = newEntry;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1715
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1716
            Anterior = newEntry;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1717
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1718
            if (newHead.OptimizationCollection == NULL)
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1719
                newHead.OptimizationCollection = newEntry;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1720
    }
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1721
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1722
  ctx ->chunks[OptimizationPlugin] = _cmsSubAllocDup(ctx->MemPool, &newHead, sizeof(_cmsOptimizationPluginChunkType));
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1723
}
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1724
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1725
void  _cmsAllocOptimizationPluginChunk(struct _cmsContext_struct* ctx,
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1726
                                         const struct _cmsContext_struct* src)
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1727
{
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1728
  if (src != NULL) {
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1729
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1730
        // Copy all linked list
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1731
       DupPluginOptimizationList(ctx, src);
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1732
    }
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1733
    else {
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1734
        static _cmsOptimizationPluginChunkType OptimizationPluginChunkType = { NULL };
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1735
        ctx ->chunks[OptimizationPlugin] = _cmsSubAllocDup(ctx ->MemPool, &OptimizationPluginChunkType, sizeof(_cmsOptimizationPluginChunkType));
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1736
    }
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1737
}
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1738
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1739
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1740
// Register new ways to optimize
26609
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1741
cmsBool  _cmsRegisterOptimizationPlugin(cmsContext ContextID, cmsPluginBase* Data)
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1742
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1743
    cmsPluginOptimization* Plugin = (cmsPluginOptimization*) Data;
26609
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1744
    _cmsOptimizationPluginChunkType* ctx = ( _cmsOptimizationPluginChunkType*) _cmsContextGetClientChunk(ContextID, OptimizationPlugin);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1745
    _cmsOptimizationCollection* fl;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1746
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1747
    if (Data == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1748
26609
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1749
        ctx->OptimizationCollection = NULL;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1750
        return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1751
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1752
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1753
    // Optimizer callback is required
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1754
    if (Plugin ->OptimizePtr == NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1755
26609
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1756
    fl = (_cmsOptimizationCollection*) _cmsPluginMalloc(ContextID, sizeof(_cmsOptimizationCollection));
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1757
    if (fl == NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1758
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1759
    // Copy the parameters
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1760
    fl ->OptimizePtr = Plugin ->OptimizePtr;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1761
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1762
    // Keep linked list
26609
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1763
    fl ->Next = ctx->OptimizationCollection;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1764
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1765
    // Set the head
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1766
    ctx ->OptimizationCollection = fl;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1767
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1768
    // All is ok
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1769
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1770
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1771
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1772
// The entry point for LUT optimization
26609
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1773
cmsBool _cmsOptimizePipeline(cmsContext ContextID,
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1774
                             cmsPipeline**    PtrLut,
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1775
                             int              Intent,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1776
                             cmsUInt32Number* InputFormat,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1777
                             cmsUInt32Number* OutputFormat,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1778
                             cmsUInt32Number* dwFlags)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1779
{
26609
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1780
    _cmsOptimizationPluginChunkType* ctx = ( _cmsOptimizationPluginChunkType*) _cmsContextGetClientChunk(ContextID, OptimizationPlugin);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1781
    _cmsOptimizationCollection* Opts;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1782
    cmsBool AnySuccess = FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1783
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1784
    // A CLUT is being asked, so force this specific optimization
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1785
    if (*dwFlags & cmsFLAGS_FORCE_CLUT) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1786
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1787
        PreOptimize(*PtrLut);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1788
        return OptimizeByResampling(PtrLut, Intent, InputFormat, OutputFormat, dwFlags);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1789
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1790
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1791
    // Anything to optimize?
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1792
    if ((*PtrLut) ->Elements == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1793
        _cmsPipelineSetOptimizationParameters(*PtrLut, FastIdentity16, (void*) *PtrLut, NULL, NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1794
        return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1795
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1796
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1797
    // Try to get rid of identities and trivial conversions.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1798
    AnySuccess = PreOptimize(*PtrLut);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1799
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1800
    // After removal do we end with an identity?
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1801
    if ((*PtrLut) ->Elements == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1802
        _cmsPipelineSetOptimizationParameters(*PtrLut, FastIdentity16, (void*) *PtrLut, NULL, NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1803
        return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1804
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1805
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1806
    // Do not optimize, keep all precision
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1807
    if (*dwFlags & cmsFLAGS_NOOPTIMIZE)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1808
        return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1809
26609
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1810
    // Try plug-in optimizations
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1811
    for (Opts = ctx->OptimizationCollection;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1812
         Opts != NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1813
         Opts = Opts ->Next) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1814
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1815
            // If one schema succeeded, we are done
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1816
            if (Opts ->OptimizePtr(PtrLut, Intent, InputFormat, OutputFormat, dwFlags)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1817
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1818
                return TRUE;    // Optimized!
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1819
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1820
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1821
26609
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1822
   // Try built-in optimizations
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1823
    for (Opts = DefaultOptimization;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1824
         Opts != NULL;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1825
         Opts = Opts ->Next) {
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1826
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1827
            if (Opts ->OptimizePtr(PtrLut, Intent, InputFormat, OutputFormat, dwFlags)) {
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1828
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1829
                return TRUE;
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1830
            }
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1831
    }
de18f570018c 8056122: Upgrade JDK to use LittleCMS 2.6
prr
parents: 25859
diff changeset
  1832
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1833
    // Only simple optimizations succeeded
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1834
    return AnySuccess;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1835
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
diff changeset
  1836
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1837
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 6482
diff changeset
  1838