DynaPDF Manual - Page 259

Function Reference
Page 259 of 839
The tint transformation function for such a color space must be able to compute one color from
arbitrary combinations of these three colors. So, we need essentially a blend function expressed in
PostScript syntax.
The definition of a blend function is not difficult but long because the entire code is stack based.
However, let us first keep in mind what we need to do. We have already three values on the stack
when the function is executed. These are the tint values which were passed to the DeviceN color
space. We need to multiply the tint values with the four components of the alternate color
representations of all three channels and finally we need to combine these three colors so that we get
the resulting output color. This sounds difficult, because a lot of multiplications and additions are
required to produce the wished result, but you'll see it's easier as it looks like.
The used colors in the DeviceN color space are defined as follows:
Colorant name
CMYK representation
PANTONE 345 CVC (coated)
{0.38, 0.00, 0.34, 0.0} or { 97,
0,
87, 0}
PANTONE 293 CVC (coated)
{1.00, 0.56, 0.00, 0.0} or {255, 143,
0, 0}
Yellow
{0.00, 0.00, 1.00, 0.0} or {
0,
0, 255, 0}
The CMYK color values of the spot colors are taken from the color picker of Adobe's Photoshop.
Now, we have all information we need to create the PostScript calculator function.
The multiplication of the color channels with the tint values must be done for all three colors
included in the color space. Because these are repeating operations we can easily develop a function
that creates the necessary code for us:
// The following function creates the PostScript code to multiply the tint
// values with the components of the CMYK color representation. 0 and 1
// color values are optimized to more efficient code.
UI32 AddOperator(char* Dest, float Value, UI32 Index)
{
if (Value == 0.0f)
// Zero is always zero
return sprintf(Dest, "0 ");
else if (Value == 1.0f) // 1.0 represents the tint value
return sprintf(Dest, "%d index ", Index);
else // Other color values must be multiplied with the tint value
return sprintf(Dest, "%d index %.2f mul ", Index, Value);
}
// Note that this function does not allocate memory. The string must be long enough to hold the
// resulting PostScript code. The function can be used to create the blend function for DeviceN color
// spaces with up to 32 color channels. The alternate color space must be DeviceCMYK or an ICCBased
// color space whose base color space is in turn DeviceCMYK. Since the alternate color space must be
// DeviceCMYK, NumColorants is always a multiple of 4!
void CreateBlendFunction(
char* Dest,
// Destination string buffer
float* Colorants,
// Array of color values
UI32 NumColorants) // Must be a multiple of 4!
{
UI32 i, j, len = 1;
UI32 numColors = NumColorants / 4;
UI32
index = numColors - 1;
Dest[0] = '{'; // The PostScript code must be enclosed in braces
for (i = 0; i < 4; i++, index++)
{
for (j = 0; j < NumColorants; j += 4)
{
// Create code to multiply the tint values with the color values

Previous topic: Example 1:, Example 2:

Next topic: CreateDPartRoot