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