/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// This file is available under and governed by the GNU General Public
// License version 2 only, as published by the Free Software Foundation.
// However, the following notice accompanied the original version of this
// file:
//
//---------------------------------------------------------------------------------
//
// Little Color Management System
// Copyright (c) 1998-2011 Marti Maria Saguer
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//---------------------------------------------------------------------------------
//
#include "lcms2_internal.h"
// PostScript ColorRenderingDictionary and ColorSpaceArray
/*
Implementation
--------------
PostScript does use XYZ as its internal PCS. But since PostScript
interpolation tables are limited to 8 bits, I use Lab as a way to
improve the accuracy, favoring perceptual results. So, for the creation
of each CRD, CSA the profiles are converted to Lab via a device
link between profile -> Lab or Lab -> profile. The PS code necessary to
convert Lab <-> XYZ is also included.
Color Space Arrays (CSA)
==================================================================================
In order to obtain precision, code chooses between three ways to implement
the device -> XYZ transform. These cases identifies monochrome profiles (often
implemented as a set of curves), matrix-shaper and Pipeline-based.
Monochrome
-----------
This is implemented as /CIEBasedA CSA. The prelinearization curve is
placed into /DecodeA section, and matrix equals to D50. Since here is
no interpolation tables, I do the conversion directly to XYZ
NOTE: CLUT-based monochrome profiles are NOT supported. So, cmsFLAGS_MATRIXINPUT
flag is forced on such profiles.
[ /CIEBasedA
<<
/DecodeA { transfer function } bind
/MatrixA [D50]
/RangeLMN [ 0.0 cmsD50X 0.0 cmsD50Y 0.0 cmsD50Z ]
/WhitePoint [D50]
/BlackPoint [BP]
/RenderingIntent (intent)
>>
]
On simpler profiles, the PCS is already XYZ, so no conversion is required.
Matrix-shaper based
-------------------
This is implemented both with /CIEBasedABC or /CIEBasedDEF on dependig
of profile implementation. Since here there are no interpolation tables, I do
the conversion directly to XYZ
[ /CIEBasedABC
<<
/DecodeABC [ {transfer1} {transfer2} {transfer3} ]
/MatrixABC [Matrix]
/RangeLMN [ 0.0 cmsD50X 0.0 cmsD50Y 0.0 cmsD50Z ]
/DecodeLMN [ { / 2} dup dup ]
/WhitePoint [D50]
/BlackPoint [BP]
/RenderingIntent (intent)
>>
]
CLUT based
----------
Lab is used in such cases.
[ /CIEBasedDEF
<<
/DecodeDEF [ <prelinearization> ]
/Table [ p p p [<...>]]
/RangeABC [ 0 1 0 1 0 1]
/DecodeABC[ <postlinearization> ]
/RangeLMN [ -0.236 1.254 0 1 -0.635 1.640 ]
% -128/500 1+127/500 0 1 -127/200 1+128/200
/MatrixABC [ 1 1 1 1 0 0 0 0 -1]
/WhitePoint [D50]
/BlackPoint [BP]
/RenderingIntent (intent)
]
Color Rendering Dictionaries (CRD)
==================================
These are always implemented as CLUT, and always are using Lab. Since CRD are expected to
be used as resources, the code adds the definition as well.
<<
/ColorRenderingType 1
/WhitePoint [ D50 ]
/BlackPoint [BP]
/MatrixPQR [ Bradford ]
/RangePQR [-0.125 1.375 -0.125 1.375 -0.125 1.375 ]
/TransformPQR [
{4 index 3 get div 2 index 3 get mul exch pop exch pop exch pop exch pop } bind
{4 index 4 get div 2 index 4 get mul exch pop exch pop exch pop exch pop } bind
{4 index 5 get div 2 index 5 get mul exch pop exch pop exch pop exch pop } bind
]
/MatrixABC <...>
/EncodeABC <...>
/RangeABC <.. used for XYZ -> Lab>
/EncodeLMN
/RenderTable [ p p p [<...>]]
/RenderingIntent (Perceptual)
>>
/Current exch /ColorRendering defineresource pop
The following stages are used to convert from XYZ to Lab
--------------------------------------------------------
Input is given at LMN stage on X, Y, Z
/EncodeLMN [
{ 0.964200 div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind
{ 1.000000 div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind
{ 0.824900 div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind
]
| 0 1 0|
| 1 -1 0|
| 0 1 -1|
/MatrixABC [ 0 1 0 1 -1 1 0 0 -1 ]
EncodeABC finally gives Lab values.
/EncodeABC [
{ 116 mul 16 sub 100 div } bind
{ 500 mul 128 add 255 div } bind
{ 200 mul 128 add 255 div } bind
]
The following stages are used to convert Lab to XYZ
----------------------------------------------------
/RangeABC [ 0 1 0 1 0 1]
/DecodeABC [ { 100 mul 16 add 116 div } bind
{ 255 mul 128 sub 500 div } bind
{ 255 mul 128 sub 200 div } bind
]
/MatrixABC [ 1 1 1 1 0 0 0 0 -1]
/DecodeLMN [
{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse 0.964200 mul} bind
{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse } bind
{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse 0.824900 mul} bind
]
*/
/*
PostScript algorithms discussion.
=========================================================================================================
1D interpolation algorithm
1D interpolation (float)
------------------------
val2 = Domain * Value;
cell0 = (int) floor(val2);
cell1 = (int) ceil(val2);
rest = val2 - cell0;
y0 = LutTable[cell0] ;
y1 = LutTable[cell1] ;
y = y0 + (y1 - y0) * rest;
PostScript code Stack
================================================
{ % v
<check 0..1.0>
[array] % v tab
dup % v tab tab
length 1 sub % v tab dom
3 -1 roll % tab dom v
mul % tab val2
dup % tab val2 val2
dup % tab val2 val2 val2
floor cvi % tab val2 val2 cell0
exch % tab val2 cell0 val2
ceiling cvi % tab val2 cell0 cell1
3 index % tab val2 cell0 cell1 tab
exch % tab val2 cell0 tab cell1
get % tab val2 cell0 y1
4 -1 roll % val2 cell0 y1 tab
3 -1 roll % val2 y1 tab cell0
get % val2 y1 y0
dup % val2 y1 y0 y0
3 1 roll % val2 y0 y1 y0
sub % val2 y0 (y1-y0)
3 -1 roll % y0 (y1-y0) val2
dup % y0 (y1-y0) val2 val2
floor cvi % y0 (y1-y0) val2 floor(val2)
sub % y0 (y1-y0) rest
mul % y0 t1
add % y
65535 div % result
} bind
*/
// This struct holds the memory block currently being write
typedef struct {
cmsIOHANDLER* m;
int FirstComponent;
int SecondComponent;
const char* PreMaj;
const char* PostMaj;
const char* PreMin;
const char* PostMin;
static int _cmsPSActualColumn = 0;
// Convert to byte
static
{
}
// Convert to byte (using ICC2 notation)
/*
static
cmsUInt8Number L2Byte(cmsUInt16Number w)
{
int ww = w + 0x0080;
if (ww > 0xFFFF) return 0xFF;
return (cmsUInt8Number) ((cmsUInt16Number) (ww >> 8) & 0xFF);
}
*/
// Write a cooked byte
static
{
_cmsIOPrintf(m, "%02x", b);
_cmsPSActualColumn += 2;
if (_cmsPSActualColumn > MAXPSCOLS) {
_cmsIOPrintf(m, "\n");
_cmsPSActualColumn = 0;
}
}
// ----------------------------------------------------------------- PostScript generation
// Removes offending Carriage returns
static
{
char* pt;
Buffer[2047] = 0;
return Buffer;
}
static
{
_cmsIOPrintf(m, "%%!PS-Adobe-3.0\n");
_cmsIOPrintf(m, "%%\n");
_cmsIOPrintf(m, "%%\n");
_cmsIOPrintf(m, "%%%%BeginResource\n");
}
// Emits White & Black point. White point is always D50, Black point is the device
// Black point adapted to D50.
static
{
BlackPoint -> Y,
BlackPoint -> Z);
cmsD50_XYZ()->Y,
cmsD50_XYZ()->Z);
}
static
{
_cmsIOPrintf(m, "dup 0.0 lt { pop 0.0 } if "
"dup 1.0 gt { pop 1.0 } if ");
}
// Does write the intent
static
{
const char *intent;
switch (RenderingIntent) {
default: intent = "Undefined"; break;
}
}
//
// Convert L* to Y
//
// Y = Yn*[ (L* + 16) / 116] ^ 3 if (L*) >= 6 / 29
// = Yn*( L* / 116) / 7.787 if (L*) < 6 / 29
//
/*
static
void EmitL2Y(cmsIOHANDLER* m)
{
_cmsIOPrintf(m,
"{ "
"100 mul 16 add 116 div " // (L * 100 + 16) / 116
"dup 6 29 div ge " // >= 6 / 29 ?
"{ dup dup mul mul } " // yes, ^3 and done
"{ 4 29 div sub 108 841 div mul } " // no, slope limiting
"ifelse } bind ");
}
*/
// Lab -> XYZ, see the discussion above
static
{
_cmsIOPrintf(m, "/RangeABC [ 0 1 0 1 0 1]\n");
_cmsIOPrintf(m, "/DecodeABC [\n");
_cmsIOPrintf(m, "{100 mul 16 add 116 div } bind\n");
_cmsIOPrintf(m, "{255 mul 128 sub 500 div } bind\n");
_cmsIOPrintf(m, "{255 mul 128 sub 200 div } bind\n");
_cmsIOPrintf(m, "]\n");
_cmsIOPrintf(m, "/MatrixABC [ 1 1 1 1 0 0 0 0 -1]\n");
_cmsIOPrintf(m, "/RangeLMN [ -0.236 1.254 0 1 -0.635 1.640 ]\n");
_cmsIOPrintf(m, "/DecodeLMN [\n");
_cmsIOPrintf(m, "{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse 0.964200 mul} bind\n");
_cmsIOPrintf(m, "{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse } bind\n");
_cmsIOPrintf(m, "{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse 0.824900 mul} bind\n");
_cmsIOPrintf(m, "]\n");
}
// Outputs a table of words. It does use 16 bits
static
{
// Suppress whole if identity
if (cmsIsToneCurveLinear(Table)) return;
// Check if is really an exponential. If so, emit "exp"
if (gamma > 0) {
return;
}
_cmsIOPrintf(m, "{ ");
// Bounds check
EmitRangeCheck(m);
// Emit intepolation code
// PostScript code Stack
// =============== ========================
// v
_cmsIOPrintf(m, " [");
}
_cmsIOPrintf(m, " } bind ");
}
// Compare gamma table
static
{
}
// Does write a set of gamma curves
static
{
int i;
for( i=0; i < n; i++ )
{
if (g[i] == NULL) return; // Error
_cmsIOPrintf(m, "dup ");
}
else {
Emit1Gamma(m, g[i]);
}
}
}
// Following code dumps a LUT onto memory stream
// This is the sampler. Intended to work in SAMPLER_INSPECT mode,
// that is, the callback will be called for each knot with
//
// In[] The grid location coordinates, normalized to 0..ffff
// Out[] The Pipeline values, normalized to 0..ffff
//
// Returning a value other than 0 does terminate the sampling process
//
// Each row contains Pipeline values for all but first component. So, I
// detect row changing by keeping a copy of last value of first
// component. -1 is used to mark begining of whole block.
static
int OutputValueSampler(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
{
return 0;
for (i=0; i < nOutputs; i++)
}
}
}
// Hadle the parenthesis on rows
}
// Begin block
_cmsPSActualColumn = 0;
}
}
}
// Dump table.
// We always deal with Lab4
}
return 1;
}
// Writes a Pipeline on memstream. Could be 8 or 16 bits based
static
const char* PostMaj,
const char* PreMin,
const char* PostMin,
int FixWhite,
{
sc.m = m;
_cmsIOPrintf(m, "[");
_cmsIOPrintf(m, " [\n");
_cmsIOPrintf(m, PostMin);
_cmsIOPrintf(m, PostMaj);
_cmsIOPrintf(m, "] ");
}
// Dumps CIEBasedA Color Space Array
static
{
_cmsIOPrintf(m, "[ /CIEBasedA\n");
_cmsIOPrintf(m, " <<\n");
_cmsIOPrintf(m, "/DecodeA ");
Emit1Gamma(m, Curve);
_cmsIOPrintf(m, " \n");
_cmsIOPrintf(m, "/MatrixA [ 0.9642 1.0000 0.8249 ]\n");
_cmsIOPrintf(m, "/RangeLMN [ 0.0 0.9642 0.0 1.0000 0.0 0.8249 ]\n");
_cmsIOPrintf(m, ">>\n");
_cmsIOPrintf(m, "]\n");
return 1;
}
// Dumps CIEBasedABC Color Space Array
static
int EmitCIEBasedABC(cmsIOHANDLER* m, cmsFloat64Number* Matrix, cmsToneCurve** CurveSet, cmsCIEXYZ* BlackPoint)
{
int i;
_cmsIOPrintf(m, "[ /CIEBasedABC\n");
_cmsIOPrintf(m, "<<\n");
_cmsIOPrintf(m, "/DecodeABC [ ");
_cmsIOPrintf(m, "]\n");
_cmsIOPrintf(m, "/MatrixABC [ " );
for( i=0; i < 3; i++ ) {
}
_cmsIOPrintf(m, "]\n");
_cmsIOPrintf(m, "/RangeLMN [ 0.0 0.9642 0.0 1.0000 0.0 0.8249 ]\n");
_cmsIOPrintf(m, ">>\n");
_cmsIOPrintf(m, "]\n");
return 1;
}
static
{
const char* PreMaj;
const char* PostMaj;
switch (cmsStageInputChannels(mpe)) {
case 3:
_cmsIOPrintf(m, "[ /CIEBasedDEF\n");
PreMaj ="<";
PostMaj= ">\n";
break;
case 4:
_cmsIOPrintf(m, "[ /CIEBasedDEFG\n");
PreMaj = "[";
PostMaj = "]\n";
PreMin = "<";
PostMin = ">\n";
break;
default:
return 0;
}
_cmsIOPrintf(m, "<<\n");
_cmsIOPrintf(m, "/DecodeDEF [ ");
_cmsIOPrintf(m, "]\n");
}
_cmsIOPrintf(m, "/Table ");
_cmsIOPrintf(m, "]\n");
}
EmitLab2XYZ(m);
EmitIntent(m, Intent);
_cmsIOPrintf(m, " >>\n");
_cmsIOPrintf(m, "]\n");
return 1;
}
// Generates a curve from a gray profile
static
{
cmsHTRANSFORM xform = cmsCreateTransformTHR(ContextID, hProfile, TYPE_GRAY_8, hXYZ, TYPE_XYZ_DBL, Intent, cmsFLAGS_NOOPTIMIZE);
int i;
for (i=0; i < 256; i++) {
}
}
return Out;
}
// Because PostScript has only 8 bits in /Table, we should use
// a more perceptually uniform space... I do choose Lab.
static
{
int rc;
// Does create a device-link based transform.
// The DeviceLink is next dumped as working CSA.
// Adjust output to Lab4
return 0;
}
// Only 1, 3 and 4 channels are allowed
switch (nChannels) {
case 1: {
}
break;
case 3:
case 4: {
if (DeviceLink == NULL) return 0;
}
break;
default:
cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Only 3, 4 channels supported for CSA. This profile has %d channels.", nChannels);
return 0;
}
return 1;
}
static
{
}
// Does create CSA based on matrix-shaper. Allowed types are gray and RGB based
static
int WriteInputMatrixShaper(cmsIOHANDLER* m, cmsHPROFILE hProfile, cmsStage* Matrix, cmsStage* Shaper)
{
int rc;
if (ColorSpace == cmsSigGrayData) {
}
else
if (ColorSpace == cmsSigRgbData) {
int i, j;
for (i=0; i < 3; i++)
for (j=0; j < 3; j++)
Mat.v[i].n[j] *= MAX_ENCODEABLE_XYZ;
}
else {
cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Profile is not suitable for CSA. Unsupported colorspace.");
return 0;
}
return rc;
}
// Creates a PostScript color list from a named profile data.
// This is a HP extension, and it works in Lab instead of XYZ
static
{
int i, nColors;
if (NamedColorList == NULL) return 0;
_cmsIOPrintf(m, "<<\n");
_cmsIOPrintf(m, "(Prefix) [ (Pantone ) (PANTONE ) ]\n");
_cmsIOPrintf(m, "(Suffix) [ ( CV) ( CVC) ( C) ]\n");
for (i=0; i < nColors; i++) {
In[0] = (cmsUInt16Number) i;
continue;
}
_cmsIOPrintf(m, ">>\n");
return 1;
}
// Does create a Color Space Array on XYZ colorspace for PostScript usage
static
{
// Is a named color profile?
}
else {
// Any profile class are allowed (including devicelink), but
// output (PCS) colorspace must be XYZ or Lab
if (ColorSpace != cmsSigXYZData &&
ColorSpace != cmsSigLabData) {
goto Error;
}
// Read the lut with all necessary conversion stages
// Tone curves + matrix can be implemented without any LUT
if (cmsPipelineCheckAndRetreiveStages(lut, 2, cmsSigCurveSetElemType, cmsSigMatrixElemType, &Shaper, &Matrix)) {
}
else {
// We need a LUT for the rest
}
}
// Done, keep memory usage
// Get rid of LUT
// Finally, return used byte count
return dwBytesUsed;
return 0;
}
// ------------------------------------------------------ Color Rendering Dictionary (CRD)
/*
Black point compensation plus chromatic adaptation:
Step 1 - Chromatic adaptation
=============================
WPout
X = ------- PQR
Wpin
Step 2 - Black point compensation
=================================
(WPout - BPout)*X - WPout*(BPin - BPout)
out = ---------------------------------------
WPout - BPin
Algorithm discussion
====================
TransformPQR(WPin, BPin, WPout, BPout, PQR)
Wpin,etc= { Xws Yws Zws Pws Qws Rws }
Algorithm Stack 0...n
===========================================================
PQR BPout WPout BPin WPin
4 index 3 get WPin PQR BPout WPout BPin WPin
exch
div
exch pop
exch pop
exch pop
exch pop
*/
static
{
if (lIsAbsolute) {
// For absolute colorimetric intent, encode back to relative
// and generate a relative Pipeline
// Relative encoding is obtained across XYZpcs*(D50/WhitePoint)
_cmsIOPrintf(m,"/MatrixPQR [1 0 0 0 1 0 0 0 1 ]\n");
_cmsIOPrintf(m,"/RangePQR [ -0.5 2 -0.5 2 -0.5 2 ]\n");
_cmsIOPrintf(m, "%% Absolute colorimetric -- encode to relative to maximize LUT usage\n"
"/TransformPQR [\n"
"{0.9642 mul %g div exch pop exch pop exch pop exch pop} bind\n"
"{1.0000 mul %g div exch pop exch pop exch pop exch pop} bind\n"
"{0.8249 mul %g div exch pop exch pop exch pop exch pop} bind\n]\n",
return;
}
_cmsIOPrintf(m,"%% Bradford Cone Space\n"
"/MatrixPQR [0.8951 -0.7502 0.0389 0.2664 1.7135 -0.0685 -0.1614 0.0367 1.0296 ] \n");
_cmsIOPrintf(m, "/RangePQR [ -0.5 2 -0.5 2 -0.5 2 ]\n");
// No BPC
if (!DoBPC) {
_cmsIOPrintf(m, "%% VonKries-like transform in Bradford Cone Space\n"
"/TransformPQR [\n"
"{exch pop exch 3 get mul exch pop exch 3 get div} bind\n"
"{exch pop exch 4 get mul exch pop exch 4 get div} bind\n"
"{exch pop exch 5 get mul exch pop exch 5 get div} bind\n]\n");
} else {
// BPC
_cmsIOPrintf(m, "%% VonKries-like transform in Bradford Cone Space plus BPC\n"
"/TransformPQR [\n");
_cmsIOPrintf(m, "{4 index 3 get div 2 index 3 get mul "
"2 index 3 get 2 index 3 get sub mul "
"2 index 3 get 4 index 3 get 3 index 3 get sub mul sub "
"3 index 3 get 3 index 3 get exch sub div "
"exch pop exch pop exch pop exch pop } bind\n");
_cmsIOPrintf(m, "{4 index 4 get div 2 index 4 get mul "
"2 index 4 get 2 index 4 get sub mul "
"2 index 4 get 4 index 4 get 3 index 4 get sub mul sub "
"3 index 4 get 3 index 4 get exch sub div "
"exch pop exch pop exch pop exch pop } bind\n");
_cmsIOPrintf(m, "{4 index 5 get div 2 index 5 get mul "
"2 index 5 get 2 index 5 get sub mul "
"2 index 5 get 4 index 5 get 3 index 5 get sub mul sub "
"3 index 5 get 3 index 5 get exch sub div "
"exch pop exch pop exch pop exch pop } bind\n]\n");
}
}
static
{
_cmsIOPrintf(m, "/RangeLMN [ -0.635 2.0 0 2 -0.635 2.0 ]\n");
_cmsIOPrintf(m, "/EncodeLMN [\n");
_cmsIOPrintf(m, "{ 0.964200 div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind\n");
_cmsIOPrintf(m, "{ 1.000000 div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind\n");
_cmsIOPrintf(m, "{ 0.824900 div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind\n");
_cmsIOPrintf(m, "]\n");
_cmsIOPrintf(m, "/MatrixABC [ 0 1 0 1 -1 1 0 0 -1 ]\n");
_cmsIOPrintf(m, "/EncodeABC [\n");
_cmsIOPrintf(m, "{ 116 mul 16 sub 100 div } bind\n");
_cmsIOPrintf(m, "{ 500 mul 128 add 256 div } bind\n");
_cmsIOPrintf(m, "{ 200 mul 128 add 256 div } bind\n");
_cmsIOPrintf(m, "]\n");
}
// Due to impedance mismatch between XYZ and almost all RGB and CMYK spaces
// I choose to dump LUTS in Lab instead of XYZ. There is still a lot of wasted
// space on 3D CLUT, but since space seems not to be a problem here, 33 points
// would give a reasonable accurancy. Note also that CRD tables must operate in
// 8 bits.
static
{
int i, nChannels;
_cmsTRANSFORM* v;
// For absolute colorimetric, the LUT is encoded as relative in order to preserve precision.
// Use V4 Lab always
cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Cannot create transform Lab -> Profile in CRD creation");
return 0;
}
// Get a copy of the internal devicelink
v = (_cmsTRANSFORM*) xform;
if (DeviceLink == NULL) return 0;
// We need a CLUT
_cmsIOPrintf(m, "<<\n");
_cmsIOPrintf(m, "/ColorRenderingType 1\n");
// Emit headers, etc.
EmitXYZ2Lab(m);
// FIXUP: map Lab (100, 0, 0) to perfect white, because the particular encoding for Lab
// does map a=b=0 not falling into any specific node. Since range a,b goes -128..127,
// zero is slightly moved towards right, so assure next node (in L=100 slice) is mapped to
// zero. This would sacrifice a bit of highlights, but failure to do so would cause
// scum dot. Ouch.
if (Intent == INTENT_ABSOLUTE_COLORIMETRIC)
_cmsIOPrintf(m, "/RenderTable ");
for (i=1; i < nChannels; i++)
_cmsIOPrintf(m, "dup ");
_cmsIOPrintf(m, "]\n");
EmitIntent(m, Intent);
_cmsIOPrintf(m, ">>\n");
if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) {
_cmsIOPrintf(m, "/Current exch /ColorRendering defineresource pop\n");
}
return 1;
}
// Builds a ASCII string containing colorant list in 0..1.0 range
static
{
int j;
Colorant[0] = 0;
if (nColorant > cmsMAXCHANNELS)
for (j=0; j < nColorant; j++) {
if (j < nColorant -1)
}
}
// Creates a PostScript color list from a named profile data.
// This is a HP extension.
static
int WriteNamedColorCRD(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, int Intent, cmsUInt32Number dwFlags)
{
xform = cmsCreateTransform(hNamedColor, TYPE_NAMED_COLOR_INDEX, NULL, OutputFormat, Intent, dwFlags);
if (NamedColorList == NULL) return 0;
_cmsIOPrintf(m, "<<\n");
_cmsIOPrintf(m, "(Prefix) [ (Pantone ) (PANTONE ) ]\n");
_cmsIOPrintf(m, "(Suffix) [ ( CV) ( CVC) ( C) ]\n");
for (i=0; i < nColors; i++) {
In[0] = (cmsUInt16Number) i;
continue;
}
_cmsIOPrintf(m, " >>");
if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) {
_cmsIOPrintf(m, " /Current exch /HPSpotTable defineresource pop\n");
}
return 1;
}
// This one does create a Color Rendering Dictionary.
// CRD are always LUT-Based, no matter if profile is
// implemented as matrix-shaper.
static
{
if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) {
}
// Is a named color profile?
return 0;
}
}
else {
// CRD are always implemented as LUT
return 0;
}
}
if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) {
}
// Done, keep memory usage
// Finally, return used byte count
return dwBytesUsed;
}
{
switch (Type) {
case cmsPS_RESOURCE_CSA:
break;
default:
case cmsPS_RESOURCE_CRD:
break;
}
return rc;
}
{
// Set up the serialization engine
else
if (!mem) return 0;
dwBytesUsed = cmsGetPostScriptColorResource(ContextID, cmsPS_RESOURCE_CRD, hProfile, Intent, dwFlags, mem);
// Get rid of memory stream
return dwBytesUsed;
}
// Does create a Color Space Array on XYZ colorspace for PostScript usage
void* Buffer,
{
else
if (!mem) return 0;
dwBytesUsed = cmsGetPostScriptColorResource(ContextID, cmsPS_RESOURCE_CSA, hProfile, Intent, dwFlags, mem);
// Get rid of memory stream
return dwBytesUsed;
}