jdk/src/share/native/sun/java2d/cmm/lcms/cmsps2.c
author prr
Tue, 24 Mar 2009 09:14:02 -0700
changeset 2394 404cbe399601
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6821031: Upgrade OpenJDK's LittleCMS version to 1.18 Reviewed-by: bae, igor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
// This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
// License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
// However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
// file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
//  Little cms
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
    32
//  Copyright (C) 1998-2007 Marti Maria
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
// Permission is hereby granted, free of charge, to any person obtaining
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
// a copy of this software and associated documentation files (the "Software"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
// to deal in the Software without restriction, including without limitation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
// and/or sell copies of the Software, and to permit persons to whom the Software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
// is furnished to do so, subject to the following conditions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
// The above copyright notice and this permission notice shall be included in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
// all copies or substantial portions of the Software.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
// Postscript level 2 operators
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#include "lcms.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#include <time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#include <stdarg.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
// PostScript ColorRenderingDictionary and ColorSpaceArray
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
LCMSAPI DWORD LCMSEXPORT cmsGetPostScriptCSA(cmsHPROFILE hProfile, int Intent, LPVOID Buffer, DWORD dwBufferLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
LCMSAPI DWORD LCMSEXPORT cmsGetPostScriptCRD(cmsHPROFILE hProfile, int Intent, LPVOID Buffer, DWORD dwBufferLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
LCMSAPI DWORD LCMSEXPORT cmsGetPostScriptCRDEx(cmsHPROFILE hProfile, int Intent, DWORD dwFlags, LPVOID Buffer, DWORD dwBufferLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
// -------------------------------------------------------------------- Implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#define MAXPSCOLS   60      // Columns on tables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    Implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    --------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  PostScript does use XYZ as its internal PCS. But since PostScript
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  interpolation tables are limited to 8 bits, I use Lab as a way to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  improve the accuracy, favoring perceptual results. So, for the creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  of each CRD, CSA the profiles are converted to Lab via a device
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  link between  profile -> Lab or Lab -> profile. The PS code necessary to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  convert Lab <-> XYZ is also included.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  Color Space Arrays (CSA)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  ==================================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  In order to obtain precission, code chooses between three ways to implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  the device -> XYZ transform. These cases identifies monochrome profiles (often
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  implemented as a set of curves), matrix-shaper and LUT-based.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  Monochrome
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  -----------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  This is implemented as /CIEBasedA CSA. The prelinearization curve is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  placed into /DecodeA section, and matrix equals to D50. Since here is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  no interpolation tables, I do the conversion directly to XYZ
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  NOTE: CLUT-based monochrome profiles are NOT supported. So, cmsFLAGS_MATRIXINPUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  flag is forced on such profiles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    [ /CIEBasedA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
      <<
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            /DecodeA { transfer function } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            /MatrixA [D50]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            /RangeLMN [ 0.0 D50X 0.0 D50Y 0.0 D50Z ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            /WhitePoint [D50]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            /BlackPoint [BP]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            /RenderingIntent (intent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      >>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
   On simpler profiles, the PCS is already XYZ, so no conversion is required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
   Matrix-shaper based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
   -------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
   This is implemented both with /CIEBasedABC or /CIEBasedDEF on dependig
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
   of profile implementation. Since here is no interpolation tables, I do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
   the conversion directly to XYZ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    [ /CIEBasedABC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            <<
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                /DecodeABC [ {transfer1} {transfer2} {transfer3} ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                /MatrixABC [Matrix]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                /RangeLMN [ 0.0 D50X 0.0 D50Y 0.0 D50Z ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                /DecodeLMN [ { / 2} dup dup ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                /WhitePoint [D50]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                /BlackPoint [BP]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                /RenderingIntent (intent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            >>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    CLUT based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    ----------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     Lab is used in such cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    [ /CIEBasedDEF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            <<
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            /DecodeDEF [ <prelinearization> ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            /Table [ p p p [<...>]]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            /RangeABC [ 0 1 0 1 0 1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            /DecodeABC[ <postlinearization> ]
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   147
            /RangeLMN [ -0.236 1.254 0 1 -0.635 1.640 ]
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   148
               % -128/500 1+127/500 0 1  -127/200 1+128/200
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            /MatrixABC [ 1 1 1 1 0 0 0 0 -1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            /WhitePoint [D50]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            /BlackPoint [BP]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            /RenderingIntent (intent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  Color Rendering Dictionaries (CRD)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
  ==================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
  These are always implemented as CLUT, and always are using Lab. Since CRD are expected to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
  be used as resources, the code adds the definition as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
  <<
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /ColorRenderingType 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /WhitePoint [ D50 ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /BlackPoint [BP]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /MatrixPQR [ Bradford ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /RangePQR [-0.125 1.375 -0.125 1.375 -0.125 1.375 ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /TransformPQR [
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    {4 index 3 get div 2 index 3 get mul exch pop exch pop exch pop exch pop } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    {4 index 4 get div 2 index 4 get mul exch pop exch pop exch pop exch pop } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    {4 index 5 get div 2 index 5 get mul exch pop exch pop exch pop exch pop } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /MatrixABC <...>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /EncodeABC <...>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /RangeABC  <.. used for  XYZ -> Lab>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /EncodeLMN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /RenderTable [ p p p [<...>]]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /RenderingIntent (Perceptual)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
  >>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
  /Current exch /ColorRendering defineresource pop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
  The following stages are used to convert from XYZ to Lab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
  --------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
  Input is given at LMN stage on X, Y, Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
  Encode LMN gives us f(X/Xn), f(Y/Yn), f(Z/Zn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
  /EncodeLMN [
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    { 0.964200  div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    { 1.000000  div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    { 0.824900  div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
  MatrixABC is used to compute f(Y/Yn), f(X/Xn) - f(Y/Yn), f(Y/Yn) - f(Z/Zn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
  | 0  1  0|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
  | 1 -1  0|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
  | 0  1 -1|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
  /MatrixABC [ 0 1 0 1 -1 1 0 0 -1 ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 EncodeABC finally gives Lab values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
  /EncodeABC [
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    { 116 mul  16 sub 100 div  } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    { 500 mul 128 add 255 div  } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    { 200 mul 128 add 255 div  } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
  The following stages are used to convert Lab to XYZ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
  ----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /RangeABC [ 0 1 0 1 0 1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /DecodeABC [ { 100 mul 16 add 116 div } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                 { 255 mul 128 sub 500 div } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                 { 255 mul 128 sub 200 div } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
               ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /MatrixABC [ 1 1 1 1 0 0 0 0 -1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /DecodeLMN [
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                {dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse 0.964200 mul} bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                {dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                {dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse 0.824900 mul} bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 PostScript algorithms discussion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 =========================================================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
  1D interpolation algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
  1D interpolation (float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
  ------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    val2 = Domain * Value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    cell0 = (int) floor(val2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    cell1 = (int) ceil(val2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    rest = val2 - cell0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    y0 = LutTable[cell0] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    y1 = LutTable[cell1] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    y = y0 + (y1 - y0) * rest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
  PostScript code                   Stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
  ================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
  {                                 % v
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    <check 0..1.0>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    [array]                         % v tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    dup                             % v tab tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    length 1 sub                    % v tab dom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    3 -1 roll                       % tab dom v
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    mul                             % tab val2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    dup                             % tab val2 val2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    dup                             % tab val2 val2 val2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    floor cvi                       % tab val2 val2 cell0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    exch                            % tab val2 cell0 val2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    ceiling cvi                     % tab val2 cell0 cell1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    3 index                         % tab val2 cell0 cell1 tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    exch                            % tab val2 cell0 tab cell1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    get                             % tab val2 cell0 y1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    4 -1 roll                       % val2 cell0 y1 tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    3 -1 roll                       % val2 y1 tab cell0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    get                             % val2 y1 y0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    dup                             % val2 y1 y0 y0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    3 1 roll                        % val2 y0 y1 y0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    sub                             % val2 y0 (y1-y0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    3 -1 roll                       % y0 (y1-y0) val2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    dup                             % y0 (y1-y0) val2 val2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    floor cvi                       % y0 (y1-y0) val2 floor(val2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    sub                             % y0 (y1-y0) rest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    mul                             % y0 t1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    add                             % y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    65535 div                       % result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
  } bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
static icTagSignature Device2PCSTab[] = {icSigAToB0Tag,       // Perceptual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                         icSigAToB1Tag,       // Relative colorimetric
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                                         icSigAToB2Tag,       // Saturation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                                         icSigAToB1Tag };     // Absolute colorimetric
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                                           // (Relative/WhitePoint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
// --------------------------------------------------------------- Memory Stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
// This struct holds the memory block currently being write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                LPBYTE Block;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                LPBYTE Ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                DWORD  dwMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                DWORD  dwUsed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                int    MaxCols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                int    Col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                int    HasError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            } MEMSTREAM, FAR* LPMEMSTREAM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                LPLUT Lut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                LPMEMSTREAM m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                int FirstComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                int SecondComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                int   bps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                const char* PreMaj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                const char* PostMaj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                const char* PreMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                const char* PostMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                int  lIsInput;    // Handle L* encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                int  FixWhite;    // Force mapping of pure white
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                icColorSpaceSignature  ColorSpace;  // ColorSpace of profile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            } SAMPLERCARGO, FAR* LPSAMPLERCARGO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
// Creates a ready to use memory stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
LPMEMSTREAM CreateMemStream(LPBYTE Buffer, DWORD dwMax, int MaxCols)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
{
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   352
    LPMEMSTREAM m = (LPMEMSTREAM) _cmsMalloc(sizeof(MEMSTREAM));
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   353
    if (m == NULL) return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    ZeroMemory(m, sizeof(MEMSTREAM));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    m -> Block   = m -> Ptr = Buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    m -> dwMax   = dwMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    m -> dwUsed  = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    m -> MaxCols = MaxCols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    m -> Col     = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    m -> HasError = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    return m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
// Convert to byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
BYTE Word2Byte(WORD w)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    return (BYTE) floor((double) w / 257.0 + 0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
// Convert to byte (using ICC2 notation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
BYTE L2Byte(WORD w)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
{
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   382
    int ww = w + 0x0080;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   384
    if (ww > 0xFFFF) return 0xFF;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    return (BYTE) ((WORD) (ww >> 8) & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
// Write a raw, uncooked byte. Check for space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
void WriteRawByte(LPMEMSTREAM m, BYTE b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    if (m -> dwUsed + 1 > m -> dwMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        m -> HasError = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    if (!m ->HasError && m ->Block) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        *m ->Ptr++ = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    m -> dwUsed++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
// Write a cooked byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
void WriteByte(LPMEMSTREAM m, BYTE b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    static const BYTE Hex[] = "0123456789ABCDEF";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    BYTE c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        c = Hex[(b >> 4) & 0x0f];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        WriteRawByte(m, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        c = Hex[b & 0x0f];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        WriteRawByte(m, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        m -> Col += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (m -> Col > m -> MaxCols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            WriteRawByte(m, '\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            m -> Col = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   427
// Does write a formatted string. Guaranteed to be 2048 bytes at most.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
void Writef(LPMEMSTREAM m, const char *frm, ...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        va_list args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        LPBYTE pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        BYTE Buffer[2048];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        va_start(args, frm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   437
        vsnprintf((char*) Buffer, 2048, frm, args);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        for (pt = Buffer; *pt; pt++)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            WriteRawByte(m, *pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        va_end(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
// ----------------------------------------------------------------- PostScript generation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
// Removes offending Carriage returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
char* RemoveCR(const char* txt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    static char Buffer[2048];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    char* pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    strncpy(Buffer, txt, 2047);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    Buffer[2047] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    for (pt = Buffer; *pt; pt++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            if (*pt == '\n' || *pt == '\r') *pt = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    return Buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
void EmitHeader(LPMEMSTREAM m, const char* Title, cmsHPROFILE hProfile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    time_t timer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    time(&timer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    Writef(m, "%%!PS-Adobe-3.0\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    Writef(m, "%%\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    Writef(m, "%% %s\n", Title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    Writef(m, "%% Source: %s\n", RemoveCR(cmsTakeProductName(hProfile)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    Writef(m, "%% Description: %s\n", RemoveCR(cmsTakeProductDesc(hProfile)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    Writef(m, "%% Created: %s", ctime(&timer)); // ctime appends a \n!!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    Writef(m, "%%\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    Writef(m, "%%%%BeginResource\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
// Emits White & Black point. White point is always D50, Black point is the device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
// Black point adapted to D50.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
void EmitWhiteBlackD50(LPMEMSTREAM m, LPcmsCIEXYZ BlackPoint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    Writef(m, "/BlackPoint [%f %f %f]\n", BlackPoint -> X,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                          BlackPoint -> Y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                          BlackPoint -> Z);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    Writef(m, "/WhitePoint [%f %f %f]\n", cmsD50_XYZ()->X,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                                          cmsD50_XYZ()->Y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                                          cmsD50_XYZ()->Z);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
void EmitRangeCheck(LPMEMSTREAM m)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    Writef(m, "dup 0.0 lt { pop 0.0 } if "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
              "dup 1.0 gt { pop 1.0 } if ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
// Does write the intent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
void EmitIntent(LPMEMSTREAM m, int RenderingIntent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    const char *intent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    switch (RenderingIntent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        case INTENT_PERCEPTUAL:            intent = "Perceptual"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        case INTENT_RELATIVE_COLORIMETRIC: intent = "RelativeColorimetric"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        case INTENT_ABSOLUTE_COLORIMETRIC: intent = "AbsoluteColorimetric"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        case INTENT_SATURATION:            intent = "Saturation"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        default: intent = "Undefined"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    Writef(m, "/RenderingIntent (%s)\n", intent );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
//  Convert L* to Y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
//      Y = Yn*[ (L* + 16) / 116] ^ 3   if (L*) >= 6 / 29
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
//        = Yn*( L* / 116) / 7.787      if (L*) < 6 / 29
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
void EmitL2Y(LPMEMSTREAM m)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    Writef(m,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            "{ "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                "100 mul 16 add 116 div "               // (L * 100 + 16) / 116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                 "dup 6 29 div ge "                     // >= 6 / 29 ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                 "{ dup dup mul mul } "                 // yes, ^3 and done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                 "{ 4 29 div sub 108 841 div mul } "    // no, slope limiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            "ifelse } bind ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
// Lab -> XYZ, see the discussion above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
void EmitLab2XYZ(LPMEMSTREAM m)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    Writef(m, "/RangeABC [ 0 1 0 1 0 1]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    Writef(m, "/DecodeABC [\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    Writef(m, "{100 mul  16 add 116 div } bind\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    Writef(m, "{255 mul 128 sub 500 div } bind\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    Writef(m, "{255 mul 128 sub 200 div } bind\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    Writef(m, "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    Writef(m, "/MatrixABC [ 1 1 1 1 0 0 0 0 -1]\n");
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   567
    Writef(m, "/RangeLMN [ -0.236 1.254 0 1 -0.635 1.640 ]\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    Writef(m, "/DecodeLMN [\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    Writef(m, "{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse 0.964200 mul} bind\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    Writef(m, "{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse } bind\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    Writef(m, "{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse 0.824900 mul} bind\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    Writef(m, "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
// Outputs a table of words. It does use 16 bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
void Emit1Gamma(LPMEMSTREAM m, LPWORD Table, int nEntries)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    double gamma;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    if (nEntries <= 0) return;  // Empty table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    // Suppress whole if identity
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   589
    if (cmsIsLinear(Table, nEntries)) {
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   590
            Writef(m, "{} ");
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   591
            return;
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   592
    }
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   593
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    // Check if is really an exponential. If so, emit "exp"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     gamma = cmsEstimateGammaEx(Table, nEntries, 0.001);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     if (gamma > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            Writef(m, "{ %g exp } bind ", gamma);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    Writef(m, "{ ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    // Bounds check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    EmitRangeCheck(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    // Emit intepolation code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    // PostScript code                      Stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    // ===============                      ========================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                                            // v
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    Writef(m, " [");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    // TODO: Check for endianess!!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    for (i=0; i < nEntries; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            Writef(m, "%d ", Table[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    Writef(m, "] ");                        // v tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    Writef(m, "dup ");                      // v tab tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    Writef(m, "length 1 sub ");             // v tab dom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    Writef(m, "3 -1 roll ");                // tab dom v
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    Writef(m, "mul ");                      // tab val2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    Writef(m, "dup ");                      // tab val2 val2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    Writef(m, "dup ");                      // tab val2 val2 val2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    Writef(m, "floor cvi ");                // tab val2 val2 cell0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    Writef(m, "exch ");                     // tab val2 cell0 val2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    Writef(m, "ceiling cvi ");              // tab val2 cell0 cell1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    Writef(m, "3 index ");                  // tab val2 cell0 cell1 tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    Writef(m, "exch ");                     // tab val2 cell0 tab cell1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    Writef(m, "get ");                      // tab val2 cell0 y1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    Writef(m, "4 -1 roll ");                // val2 cell0 y1 tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    Writef(m, "3 -1 roll ");                // val2 y1 tab cell0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    Writef(m, "get ");                      // val2 y1 y0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    Writef(m, "dup ");                      // val2 y1 y0 y0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    Writef(m, "3 1 roll ");                 // val2 y0 y1 y0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    Writef(m, "sub ");                      // val2 y0 (y1-y0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    Writef(m, "3 -1 roll ");                // y0 (y1-y0) val2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    Writef(m, "dup ");                      // y0 (y1-y0) val2 val2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    Writef(m, "floor cvi ");                // y0 (y1-y0) val2 floor(val2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    Writef(m, "sub ");                      // y0 (y1-y0) rest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    Writef(m, "mul ");                      // y0 t1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    Writef(m, "add ");                      // y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    Writef(m, "65535 div ");                // result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    Writef(m, " } bind ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
// Compare gamma table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
static
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   655
LCMSBOOL GammaTableEquals(LPWORD g1, LPWORD g2, int nEntries)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    return memcmp(g1, g2, nEntries* sizeof(WORD)) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
// Does write a set of gamma curves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
void EmitNGamma(LPMEMSTREAM m, int n, LPWORD g[], int nEntries)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    for( i=0; i < n; i++ )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        if (i > 0 && GammaTableEquals(g[i-1], g[i], nEntries)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            Writef(m, "dup ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            Emit1Gamma(m, g[i], nEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
// Check whatever a profile has CLUT tables (only on input)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
static
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   685
LCMSBOOL IsLUTbased(cmsHPROFILE hProfile, int Intent)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    icTagSignature Tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    // Check if adequate tag is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    Tag = Device2PCSTab[Intent];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    if (cmsIsTag(hProfile, Tag)) return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    // If not present, revert to default (perceptual)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    Tag = icSigAToB0Tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    // If no tag present, try matrix-shaper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    return cmsIsTag(hProfile, Tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
// Following code dumps a LUT onto memory stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
// This is the sampler. Intended to work in SAMPLER_INSPECT mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
// that is, the callback will be called for each knot with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
//          In[]  The grid location coordinates, normalized to 0..ffff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
//          Out[] The LUT values, normalized to 0..ffff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
//  Returning a value other than 0 does terminate the sampling process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
//  Each row contains LUT values for all but first component. So, I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
//  detect row changing by keeping a copy of last value of first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
//  component. -1 is used to mark begining of whole block.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
int OutputValueSampler(register WORD In[], register WORD Out[], register LPVOID Cargo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    LPSAMPLERCARGO sc = (LPSAMPLERCARGO) Cargo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    unsigned int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    if (sc -> FixWhite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   727
        if (In[0] == 0xFFFF) {  // Only in L* = 100, ab = [-8..8]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   729
            if ((In[1] >= 0x7800 && In[1] <= 0x8800) &&
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   730
                (In[2] >= 0x7800 && In[2] <= 0x8800)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                WORD* Black;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                WORD* White;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                int nOutputs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                if (!_cmsEndPointsBySpace(sc ->ColorSpace, &White, &Black, &nOutputs))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                for (i=0; i < (unsigned int) nOutputs; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                        Out[i] = White[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    // Hadle the parenthesis on rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    if (In[0] != sc ->FirstComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            if (sc ->FirstComponent != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                    Writef(sc ->m, sc ->PostMin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                    sc ->SecondComponent = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                    Writef(sc ->m, sc ->PostMaj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            // Begin block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            sc->m->Col = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            Writef(sc ->m, sc ->PreMaj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            sc ->FirstComponent = In[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
      if (In[1] != sc ->SecondComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            if (sc ->SecondComponent != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                    Writef(sc ->m, sc ->PostMin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            Writef(sc ->m, sc ->PreMin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            sc ->SecondComponent = In[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    // Dump table. Could be Word or byte based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    // depending on bps member (16 bps mode is not currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    // being used at all, but is here for future ampliations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    for (i=0; i < sc -> Lut ->OutputChan; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        WORD wWordOut = Out[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        if (sc ->bps == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            // Value as byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            BYTE wByteOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            // If is input, convert from Lab2 to Lab4 (just divide by 256)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            if (sc ->lIsInput) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                wByteOut = L2Byte(wWordOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                wByteOut = Word2Byte(wWordOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            WriteByte(sc -> m, wByteOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            // Value as word
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            WriteByte(sc -> m, (BYTE) (wWordOut & 0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            WriteByte(sc -> m, (BYTE) ((wWordOut >> 8) & 0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
// Writes a LUT on memstream. Could be 8 or 16 bits based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
void WriteCLUT(LPMEMSTREAM m, LPLUT Lut, int bps, const char* PreMaj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                                                  const char* PostMaj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                                                  const char* PreMin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                                                  const char* PostMin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                                                  int lIsInput,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                                                  int FixWhite,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                                                  icColorSpaceSignature ColorSpace)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    unsigned int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    SAMPLERCARGO sc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    sc.FirstComponent = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    sc.SecondComponent = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    sc.Lut = Lut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    sc.m   = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    sc.bps = bps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    sc.PreMaj = PreMaj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    sc.PostMaj= PostMaj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   838
    sc.PreMin   = PreMin;
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
   839
    sc.PostMin  = PostMin;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    sc.lIsInput = lIsInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    sc.FixWhite = FixWhite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    sc.ColorSpace = ColorSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    Writef(m, "[");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    for (i=0; i < Lut ->InputChan; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            Writef(m, " %d ", Lut ->cLutPoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    Writef(m, " [\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    cmsSample3DGrid(Lut, OutputValueSampler, (LPVOID) &sc, SAMPLER_INSPECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    Writef(m, PostMin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    Writef(m, PostMaj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    Writef(m, "] ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
// Dumps CIEBasedA Color Space Array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
int EmitCIEBasedA(LPMEMSTREAM m, LPWORD Tab, int nEntries, LPcmsCIEXYZ BlackPoint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        Writef(m, "[ /CIEBasedA\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        Writef(m, "  <<\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        Writef(m, "/DecodeA ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        Emit1Gamma(m,Tab, nEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        Writef(m, " \n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        Writef(m, "/MatrixA [ 0.9642 1.0000 0.8249 ]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        Writef(m, "/RangeLMN [ 0.0 0.9642 0.0 1.0000 0.0 0.8249 ]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        EmitWhiteBlackD50(m, BlackPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        EmitIntent(m, INTENT_PERCEPTUAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        Writef(m, ">>\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        Writef(m, "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
// Dumps CIEBasedABC Color Space Array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
int EmitCIEBasedABC(LPMEMSTREAM m, LPWORD L[], int nEntries, LPWMAT3 Matrix, LPcmsCIEXYZ BlackPoint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        Writef(m, "[ /CIEBasedABC\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        Writef(m, "<<\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        Writef(m, "/DecodeABC [ ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        EmitNGamma(m, 3, L, nEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        Writef(m, "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        Writef(m, "/MatrixABC [ " );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        for( i=0; i < 3; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            Writef(m, "%.6f %.6f %.6f ",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                        FIXED_TO_DOUBLE(Matrix->v[0].n[i]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                        FIXED_TO_DOUBLE(Matrix->v[1].n[i]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                        FIXED_TO_DOUBLE(Matrix->v[2].n[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        Writef(m, "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        Writef(m, "/RangeLMN [ 0.0 0.9642 0.0 1.0000 0.0 0.8249 ]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        EmitWhiteBlackD50(m, BlackPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        EmitIntent(m, INTENT_PERCEPTUAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        Writef(m, ">>\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        Writef(m, "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
int EmitCIEBasedDEF(LPMEMSTREAM m, LPLUT Lut, int Intent, LPcmsCIEXYZ BlackPoint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    const char* PreMaj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    const char* PostMaj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    const char* PreMin, *PostMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    switch (Lut ->InputChan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            Writef(m, "[ /CIEBasedDEF\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            PreMaj ="<";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            PostMaj= ">\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            PreMin = PostMin = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            Writef(m, "[ /CIEBasedDEFG\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            PreMaj = "[";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            PostMaj = "]\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            PreMin = "<";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            PostMin = ">\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    Writef(m, "<<\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    if (Lut ->wFlags & LUT_HASTL1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        Writef(m, "/DecodeDEF [ ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        EmitNGamma(m, Lut ->InputChan, Lut ->L1, Lut ->CLut16params.nSamples);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        Writef(m, "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    if (Lut ->wFlags & LUT_HAS3DGRID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            Writef(m, "/Table ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            WriteCLUT(m, Lut, 8, PreMaj, PostMaj, PreMin, PostMin, TRUE, FALSE, (icColorSpaceSignature) 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            Writef(m, "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    EmitLab2XYZ(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    EmitWhiteBlackD50(m, BlackPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    EmitIntent(m, Intent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    Writef(m, "   >>\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    Writef(m, "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
// Generates a curve from a gray profile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
LPGAMMATABLE ExtractGray2Y(cmsHPROFILE hProfile, int Intent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    LPGAMMATABLE Out = cmsAllocGamma(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    cmsHPROFILE hXYZ = cmsCreateXYZProfile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    cmsHTRANSFORM xform = cmsCreateTransform(hProfile, TYPE_GRAY_8, hXYZ, TYPE_XYZ_DBL, Intent, cmsFLAGS_NOTPRECALC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    for (i=0; i < 256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
      BYTE Gray = (BYTE) i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
      cmsCIEXYZ XYZ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        cmsDoTransform(xform, &Gray, &XYZ, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        Out ->GammaTable[i] =_cmsClampWord((int) floor(XYZ.Y * 65535.0 + 0.5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    cmsDeleteTransform(xform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    cmsCloseProfile(hXYZ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    return Out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
// Because PostScrip has only 8 bits in /Table, we should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
// a more perceptually uniform space... I do choose Lab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
int WriteInputLUT(LPMEMSTREAM m, cmsHPROFILE hProfile, int Intent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    cmsHPROFILE hLab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    cmsHTRANSFORM xform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    icColorSpaceSignature ColorSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    int nChannels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    DWORD InputFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    int rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    cmsHPROFILE Profiles[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    cmsCIEXYZ BlackPointAdaptedToD50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    // Does create a device-link based transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    // The DeviceLink is next dumped as working CSA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    hLab        = cmsCreateLabProfile(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    ColorSpace  =  cmsGetColorSpace(hProfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    nChannels   = _cmsChannelsOf(ColorSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    InputFormat = CHANNELS_SH(nChannels) | BYTES_SH(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    cmsDetectBlackPoint(&BlackPointAdaptedToD50, hProfile, Intent,LCMS_BPFLAGS_D50_ADAPTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    // Is a devicelink profile?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    if (cmsGetDeviceClass(hProfile) == icSigLinkClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        // if devicelink output already Lab, use it directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        if (cmsGetPCS(hProfile) == icSigLabData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            xform = cmsCreateTransform(hProfile, InputFormat, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                            TYPE_Lab_DBL, Intent, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            // Nope, adjust output to Lab if possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            Profiles[0] = hProfile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            Profiles[1] = hLab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            xform = cmsCreateMultiprofileTransform(Profiles, 2,  InputFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                                    TYPE_Lab_DBL, Intent, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        // This is a normal profile
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        xform = cmsCreateTransform(hProfile, InputFormat, hLab,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                            TYPE_Lab_DBL, Intent, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    if (xform == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            cmsSignalError(LCMS_ERRC_ABORTED, "Cannot create transform Profile -> Lab");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    // Only 1, 3 and 4 channels are allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    switch (nChannels) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    case 1: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            LPGAMMATABLE Gray2Y = ExtractGray2Y(hProfile, Intent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            EmitCIEBasedA(m, Gray2Y->GammaTable, Gray2Y ->nEntries, &BlackPointAdaptedToD50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            cmsFreeGamma(Gray2Y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    case 4: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            LPLUT DeviceLink;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            _LPcmsTRANSFORM v = (_LPcmsTRANSFORM) xform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            if (v ->DeviceLink)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                rc = EmitCIEBasedDEF(m, v->DeviceLink, Intent, &BlackPointAdaptedToD50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                DeviceLink = _cmsPrecalculateDeviceLink(xform, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                rc = EmitCIEBasedDEF(m, DeviceLink, Intent, &BlackPointAdaptedToD50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                cmsFreeLUT(DeviceLink);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            cmsSignalError(LCMS_ERRC_ABORTED, "Only 3, 4 channels supported for CSA. This profile has %d channels.", nChannels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    cmsDeleteTransform(xform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    cmsCloseProfile(hLab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
// Does create CSA based on matrix-shaper. Allowed types are gray and RGB based
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
int WriteInputMatrixShaper(LPMEMSTREAM m, cmsHPROFILE hProfile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    icColorSpaceSignature ColorSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    LPMATSHAPER MatShaper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    int rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    cmsCIEXYZ BlackPointAdaptedToD50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    ColorSpace = cmsGetColorSpace(hProfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    MatShaper  = cmsBuildInputMatrixShaper(hProfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    cmsDetectBlackPoint(&BlackPointAdaptedToD50, hProfile, INTENT_RELATIVE_COLORIMETRIC, LCMS_BPFLAGS_D50_ADAPTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    if (MatShaper == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                cmsSignalError(LCMS_ERRC_ABORTED, "This profile is not suitable for input");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    if (ColorSpace == icSigGrayData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            rc = EmitCIEBasedA(m, MatShaper ->L[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                                  MatShaper ->p16.nSamples,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                                  &BlackPointAdaptedToD50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        if (ColorSpace == icSigRgbData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            rc = EmitCIEBasedABC(m, MatShaper->L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                                        MatShaper ->p16.nSamples,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                                        &MatShaper ->Matrix,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                                        &BlackPointAdaptedToD50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        else  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            cmsSignalError(LCMS_ERRC_ABORTED, "Profile is not suitable for CSA. Unsupported colorspace.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    cmsFreeMatShaper(MatShaper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    return rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
// Creates a PostScript color list from a named profile data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
// This is a HP extension, and it works in Lab instead of XYZ
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
int WriteNamedColorCSA(LPMEMSTREAM m, cmsHPROFILE hNamedColor, int Intent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    cmsHTRANSFORM xform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    cmsHPROFILE   hLab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    int i, nColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    char ColorName[32];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    hLab  = cmsCreateLabProfile(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    xform = cmsCreateTransform(hNamedColor, TYPE_NAMED_COLOR_INDEX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                        hLab, TYPE_Lab_DBL, Intent, cmsFLAGS_NOTPRECALC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    if (xform == NULL) return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    Writef(m, "<<\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    Writef(m, "(colorlistcomment) (%s)\n", "Named color CSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    Writef(m, "(Prefix) [ (Pantone ) (PANTONE ) ]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    Writef(m, "(Suffix) [ ( CV) ( CVC) ( C) ]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    nColors   = cmsNamedColorCount(xform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
    for (i=0; i < nColors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        WORD In[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        cmsCIELab Lab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        In[0] = (WORD) i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        if (!cmsNamedColorInfo(xform, i, ColorName, NULL, NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        cmsDoTransform(xform, In, &Lab, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        Writef(m, "  (%s) [ %.3f %.3f %.3f ]\n", ColorName, Lab.L, Lab.a, Lab.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    Writef(m, ">>\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
    cmsDeleteTransform(xform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    cmsCloseProfile(hLab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
// Does create a Color Space Array on XYZ colorspace for PostScript usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
DWORD LCMSEXPORT cmsGetPostScriptCSA(cmsHPROFILE hProfile,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                              int Intent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                              LPVOID Buffer, DWORD dwBufferLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    LPMEMSTREAM mem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    DWORD dwBytesUsed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    // Set up the serialization engine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    mem = CreateMemStream((LPBYTE) Buffer, dwBufferLen, MAXPSCOLS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    if (!mem) return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    // Is a named color profile?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    if (cmsGetDeviceClass(hProfile) == icSigNamedColorClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        if (!WriteNamedColorCSA(mem, hProfile, Intent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1240
                    _cmsFree((void*) mem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
    // Any profile class are allowed (including devicelink), but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    // output (PCS) colorspace must be XYZ or Lab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    icColorSpaceSignature ColorSpace = cmsGetPCS(hProfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    if (ColorSpace != icSigXYZData &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        ColorSpace != icSigLabData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            cmsSignalError(LCMS_ERRC_ABORTED, "Invalid output color space");
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1255
            _cmsFree((void*) mem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    // Is there any CLUT?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    if (IsLUTbased(hProfile, Intent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        // Yes, so handle as LUT-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        if (!WriteInputLUT(mem, hProfile, Intent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1265
                    _cmsFree((void*) mem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        // No, try Matrix-shaper (this only works on XYZ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        if (!WriteInputMatrixShaper(mem, hProfile)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1275
                    _cmsFree((void*) mem);  // Something went wrong
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    // Done, keep memory usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    dwBytesUsed = mem ->dwUsed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    // Get rid of memory stream
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1286
    _cmsFree((void*) mem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    // Finally, return used byte count
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    return dwBytesUsed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
// ------------------------------------------------------ Color Rendering Dictionary (CRD)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
  Black point compensation plus chromatic adaptation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
  Step 1 - Chromatic adaptation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
  =============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
          WPout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    X = ------- PQR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
          Wpin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
  Step 2 - Black point compensation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
  =================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
          (WPout - BPout)*X - WPout*(BPin - BPout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    out = ---------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                        WPout - BPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
  Algorithm discussion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
  ====================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
  TransformPQR(WPin, BPin, WPout, BPout, PQR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
  Wpin,etc= { Xws Yws Zws Pws Qws Rws }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
  Algorithm             Stack 0...n
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
  ===========================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                        PQR BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
  4 index 3 get         WPin PQR BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
  div                   (PQR/WPin) BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
  2 index 3 get         WPout (PQR/WPin) BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
  mult                  WPout*(PQR/WPin) BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
  2 index 3 get         WPout WPout*(PQR/WPin) BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
  2 index 3 get         BPout WPout WPout*(PQR/WPin) BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
  sub                   (WPout-BPout) WPout*(PQR/WPin) BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
  mult                  (WPout-BPout)* WPout*(PQR/WPin) BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
  2 index 3 get         WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
  4 index 3 get         BPin WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
  3 index 3 get         BPout BPin WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
  sub                   (BPin-BPout) WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
  mult                  (BPin-BPout)*WPout (BPout-WPout)* WPout*(PQR/WPin) BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
  sub                   (BPout-WPout)* WPout*(PQR/WPin)-(BPin-BPout)*WPout BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
  3 index 3 get         BPin (BPout-WPout)* WPout*(PQR/WPin)-(BPin-BPout)*WPout BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
  3 index 3 get         WPout BPin (BPout-WPout)* WPout*(PQR/WPin)-(BPin-BPout)*WPout BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
  exch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
  sub                   (WPout-BPin) (BPout-WPout)* WPout*(PQR/WPin)-(BPin-BPout)*WPout BPout WPout BPin WPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
  div
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
  exch pop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
  exch pop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
  exch pop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
  exch pop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
static
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1359
void EmitPQRStage(LPMEMSTREAM m, cmsHPROFILE hProfile, int DoBPC, int lIsAbsolute)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1363
        if (lIsAbsolute) {
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1364
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1365
            // For absolute colorimetric intent, encode back to relative
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1366
            // and generate a relative LUT
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1367
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1368
            // Relative encoding is obtained across XYZpcs*(D50/WhitePoint)
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1369
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1370
            cmsCIEXYZ White;
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1371
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1372
            cmsTakeMediaWhitePoint(&White, hProfile);
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1373
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1374
            Writef(m,"/MatrixPQR [1 0 0 0 1 0 0 0 1 ]\n");
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1375
            Writef(m,"/RangePQR [ -0.5 2 -0.5 2 -0.5 2 ]\n");
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1376
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1377
            Writef(m, "%% Absolute colorimetric -- encode to relative to maximize LUT usage\n"
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1378
                      "/TransformPQR [\n"
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1379
                      "{0.9642 mul %g div exch pop exch pop exch pop exch pop} bind\n"
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1380
                      "{1.0000 mul %g div exch pop exch pop exch pop exch pop} bind\n"
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1381
                      "{0.8249 mul %g div exch pop exch pop exch pop exch pop} bind\n]\n",
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1382
                      White.X, White.Y, White.Z);
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1383
            return;
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1384
        }
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1385
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1386
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        Writef(m,"%% Bradford Cone Space\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                 "/MatrixPQR [0.8951 -0.7502 0.0389 0.2664 1.7135 -0.0685 -0.1614 0.0367 1.0296 ] \n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        Writef(m, "/RangePQR [ -0.5 2 -0.5 2 -0.5 2 ]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        // No BPC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        if (!DoBPC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
            Writef(m, "%% VonKries-like transform in Bradford Cone Space\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                      "/TransformPQR [\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                      "{exch pop exch 3 get mul exch pop exch 3 get div} bind\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                      "{exch pop exch 4 get mul exch pop exch 4 get div} bind\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                      "{exch pop exch 5 get mul exch pop exch 5 get div} bind\n]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            // BPC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            Writef(m, "%% VonKries-like transform in Bradford Cone Space plus BPC\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                      "/TransformPQR [\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
            Writef(m, "{4 index 3 get div 2 index 3 get mul "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                    "2 index 3 get 2 index 3 get sub mul "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                    "2 index 3 get 4 index 3 get 3 index 3 get sub mul sub "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                    "3 index 3 get 3 index 3 get exch sub div "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                    "exch pop exch pop exch pop exch pop } bind\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            Writef(m, "{4 index 4 get div 2 index 4 get mul "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                    "2 index 4 get 2 index 4 get sub mul "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                    "2 index 4 get 4 index 4 get 3 index 4 get sub mul sub "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                    "3 index 4 get 3 index 4 get exch sub div "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                    "exch pop exch pop exch pop exch pop } bind\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
            Writef(m, "{4 index 5 get div 2 index 5 get mul "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                    "2 index 5 get 2 index 5 get sub mul "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                    "2 index 5 get 4 index 5 get 3 index 5 get sub mul sub "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                    "3 index 5 get 3 index 5 get exch sub div "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                    "exch pop exch pop exch pop exch pop } bind\n]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
void EmitXYZ2Lab(LPMEMSTREAM m)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
{
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1436
    Writef(m, "/RangeLMN [ -0.635 2.0 0 2 -0.635 2.0 ]\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    Writef(m, "/EncodeLMN [\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    Writef(m, "{ 0.964200  div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    Writef(m, "{ 1.000000  div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
    Writef(m, "{ 0.824900  div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    Writef(m, "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    Writef(m, "/MatrixABC [ 0 1 0 1 -1 1 0 0 -1 ]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
    Writef(m, "/EncodeABC [\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
    Writef(m, "{ 116 mul  16 sub 100 div  } bind\n");
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1447
    Writef(m, "{ 500 mul 128 add 256 div  } bind\n");
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1448
    Writef(m, "{ 200 mul 128 add 256 div  } bind\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
    Writef(m, "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
// Due to impedance mismatch between XYZ and almost all RGB and CMYK spaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
// I choose to dump LUTS in Lab instead of XYZ. There is still a lot of wasted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
// space on 3D CLUT, but since space seems not to be a problem here, 33 points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
// would give a reasonable accurancy. Note also that CRD tables must operate in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
// 8 bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
int WriteOutputLUT(LPMEMSTREAM m, cmsHPROFILE hProfile, int Intent, DWORD dwFlags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    cmsHPROFILE hLab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    cmsHTRANSFORM xform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
    icColorSpaceSignature ColorSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    int i, nChannels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
    DWORD OutputFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    _LPcmsTRANSFORM v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
    LPLUT DeviceLink;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    cmsHPROFILE Profiles[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
    cmsCIEXYZ BlackPointAdaptedToD50;
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1474
    LCMSBOOL lFreeDeviceLink = FALSE;
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1475
    LCMSBOOL lDoBPC = (dwFlags & cmsFLAGS_BLACKPOINTCOMPENSATION);
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1476
    LCMSBOOL lFixWhite = !(dwFlags & cmsFLAGS_NOWHITEONWHITEFIXUP);
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1477
    int RelativeEncodingIntent;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1481
    hLab = cmsCreateLabProfile(NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
    ColorSpace  =  cmsGetColorSpace(hProfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    nChannels   = _cmsChannelsOf(ColorSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
    OutputFormat = CHANNELS_SH(nChannels) | BYTES_SH(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1487
    // For absolute colorimetric, the LUT is encoded as relative
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1488
    // in order to preserve precission.
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1489
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1490
    RelativeEncodingIntent = Intent;
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1491
    if (RelativeEncodingIntent == INTENT_ABSOLUTE_COLORIMETRIC)
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1492
        RelativeEncodingIntent = INTENT_RELATIVE_COLORIMETRIC;
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1493
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1494
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
    // Is a devicelink profile?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    if (cmsGetDeviceClass(hProfile) == icSigLinkClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        // if devicelink input already in Lab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        if (ColorSpace == icSigLabData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1502
              // adjust input to Lab to our v4
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            Profiles[0] = hLab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            Profiles[1] = hProfile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            xform = cmsCreateMultiprofileTransform(Profiles, 2, TYPE_Lab_DBL,
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1508
                                                        OutputFormat, RelativeEncodingIntent,
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1509
                                                        dwFlags|cmsFLAGS_NOWHITEONWHITEFIXUP|cmsFLAGS_NOPRELINEARIZATION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
          cmsSignalError(LCMS_ERRC_ABORTED, "Cannot use devicelink profile for CRD creation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        // This is a normal profile
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        xform = cmsCreateTransform(hLab, TYPE_Lab_DBL, hProfile,
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1523
                            OutputFormat, RelativeEncodingIntent, dwFlags|cmsFLAGS_NOWHITEONWHITEFIXUP|cmsFLAGS_NOPRELINEARIZATION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    if (xform == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
            cmsSignalError(LCMS_ERRC_ABORTED, "Cannot create transform Lab -> Profile in CRD creation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
    // Get the internal precalculated devicelink
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
    v = (_LPcmsTRANSFORM) xform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
    DeviceLink = v ->DeviceLink;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    if (!DeviceLink) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1539
        DeviceLink = _cmsPrecalculateDeviceLink(xform, cmsFLAGS_NOPRELINEARIZATION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        lFreeDeviceLink = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
    Writef(m, "<<\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
    Writef(m, "/ColorRenderingType 1\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
    cmsDetectBlackPoint(&BlackPointAdaptedToD50, hProfile, Intent, LCMS_BPFLAGS_D50_ADAPTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    // Emit headers, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    EmitWhiteBlackD50(m, &BlackPointAdaptedToD50);
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1551
    EmitPQRStage(m, hProfile, lDoBPC, Intent == INTENT_ABSOLUTE_COLORIMETRIC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    EmitXYZ2Lab(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
    if (DeviceLink ->wFlags & LUT_HASTL1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        // Shouldn't happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        cmsSignalError(LCMS_ERRC_ABORTED, "Internal error (prelinearization on CRD)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
    // FIXUP: map Lab (100, 0, 0) to perfect white, because the particular encoding for Lab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
    // does map a=b=0 not falling into any specific node. Since range a,b goes -128..127,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    // zero is slightly moved towards right, so assure next node (in L=100 slice) is mapped to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    // zero. This would sacrifice a bit of highlights, but failure to do so would cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    // scum dot. Ouch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1568
    if (Intent == INTENT_ABSOLUTE_COLORIMETRIC)
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1569
            lFixWhite = FALSE;
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1570
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
    Writef(m, "/RenderTable ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
    WriteCLUT(m, DeviceLink, 8, "<", ">\n", "", "", FALSE,
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1574
                lFixWhite, ColorSpace);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
    Writef(m, " %d {} bind ", nChannels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
    for (i=1; i < nChannels; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            Writef(m, "dup ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    Writef(m, "]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    EmitIntent(m, Intent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
    Writef(m, ">>\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
    if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
        Writef(m, "/Current exch /ColorRendering defineresource pop\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
    if (lFreeDeviceLink) cmsFreeLUT(DeviceLink);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    cmsDeleteTransform(xform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    cmsCloseProfile(hLab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
// Builds a ASCII string containing colorant list in 0..1.0 range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
void BuildColorantList(char *Colorant, int nColorant, WORD Out[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
    char Buff[32];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
    int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    Colorant[0] = 0;
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1609
    if (nColorant > MAXCHANNELS)
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1610
        nColorant = MAXCHANNELS;
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1611
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
    for (j=0; j < nColorant; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                sprintf(Buff, "%.3f", Out[j] / 65535.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                strcat(Colorant, Buff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                if (j < nColorant -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                        strcat(Colorant, " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
// Creates a PostScript color list from a named profile data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
// This is a HP extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
int WriteNamedColorCRD(LPMEMSTREAM m, cmsHPROFILE hNamedColor, int Intent, DWORD dwFlags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
    cmsHTRANSFORM xform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
    int i, nColors, nColorant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
    DWORD OutputFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
    char ColorName[32];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
    char Colorant[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
    nColorant = _cmsChannelsOf(cmsGetColorSpace(hNamedColor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
    OutputFormat = CHANNELS_SH(nColorant) | BYTES_SH(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    xform = cmsCreateTransform(hNamedColor, TYPE_NAMED_COLOR_INDEX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                        NULL, OutputFormat, Intent, cmsFLAGS_NOTPRECALC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
    if (xform == NULL) return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    Writef(m, "<<\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
    Writef(m, "(colorlistcomment) (%s) \n", "Named profile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
    Writef(m, "(Prefix) [ (Pantone ) (PANTONE ) ]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    Writef(m, "(Suffix) [ ( CV) ( CVC) ( C) ]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
    nColors   = cmsNamedColorCount(xform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    for (i=0; i < nColors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
        WORD In[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        WORD Out[MAXCHANNELS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        In[0] = (WORD) i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
        if (!cmsNamedColorInfo(xform, i, ColorName, NULL, NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        cmsDoTransform(xform, In, Out, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        BuildColorantList(Colorant, nColorant, Out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
        Writef(m, "  (%s) [ %s ]\n", ColorName, Colorant);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
    Writef(m, "   >>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
    Writef(m, " /Current exch /HPSpotTable defineresource pop\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
    cmsDeleteTransform(xform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
// This one does create a Color Rendering Dictionary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
// CRD are always LUT-Based, no matter if profile is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
// implemented as matrix-shaper.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
DWORD LCMSEXPORT cmsGetPostScriptCRDEx(cmsHPROFILE hProfile,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                              int Intent, DWORD dwFlags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                              LPVOID Buffer, DWORD dwBufferLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
    LPMEMSTREAM mem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
    DWORD dwBytesUsed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    // Set up the serialization artifact
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
    mem = CreateMemStream((LPBYTE) Buffer, dwBufferLen, MAXPSCOLS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    if (!mem) return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
    if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
    EmitHeader(mem, "Color Rendering Dictionary (CRD)", hProfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    // Is a named color profile?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
    if (cmsGetDeviceClass(hProfile) == icSigNamedColorClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        if (!WriteNamedColorCRD(mem, hProfile, Intent, dwFlags)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1707
                    _cmsFree((void*) mem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
    // CRD are always implemented as LUT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
    if (!WriteOutputLUT(mem, hProfile, Intent, dwFlags)) {
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1717
        _cmsFree((void*) mem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
    if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
    Writef(mem, "%%%%EndResource\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    Writef(mem, "\n%% CRD End\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
    // Done, keep memory usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
    dwBytesUsed = mem ->dwUsed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
    // Get rid of memory stream
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2
diff changeset
  1732
    _cmsFree((void*) mem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
    // Finally, return used byte count
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
    return dwBytesUsed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
// For compatibility with previous versions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
DWORD LCMSEXPORT cmsGetPostScriptCRD(cmsHPROFILE hProfile,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                              int Intent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                              LPVOID Buffer, DWORD dwBufferLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
    return cmsGetPostScriptCRDEx(hProfile, Intent, 0, Buffer, dwBufferLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
}