uint32_t __stdcall pdfConvColor(double* Color, uint32_t NumComps, int32_t SourceCS, void* IColorSpace, int32_t DestCS);
uint32_t __stdcall pdfConvColorEx(double* Color, uint32_t NumComps, int32_t SourceCS, void* IColorSpace, int32_t DestCS, int32_t Intent);
function pdfConvColor(Color: PDouble; NumComps: Cardinal; SourceCS: Integer; const IColorSpace: Pointer; DestCS: Integer): Cardinal; stdcall;
function pdfConvColorEx(Color: PDouble; NumComps: Cardinal; SourceCS: Integer; const IColorSpace: Pointer; DestCS: Integer; Intent: Integer): Cardinal; stdcall;
Purpose. Convert one color value (up to 4 components) from a source color-space kind to a destination color-space kind, returning the result as a packed value. Notably, unlike every other color API in this volume, this one takes no IPDF document handle — it is a pure math utility.
Description. SourceCS/DestCS are small integer kind codes (0=RGB, 1=CMYK, 2=Gray, 5=Lab, 6=ICCBased — verified from the internal ConvColorI case statement; any other source code falls back to treating Color[0] as gray). Stage 1 converts the source value to linear device RGB in 0.0..1.0: RGB passes through; CMYK uses the standard (1-C)*(1-K)-style formula; Gray replicates the single component; Lab uses LabToRGB; ICCBased (6) is the only source kind that consults IColorSpace — it is expected to point directly at raw ICC profile bytes (self-describing via its own header, parsed on the fly via IccParsePtrIntent), and a real device-to-sRGB transform is applied via IccDeviceToSRGB; if the profile fails to parse, silently falls back to treating Color[0] as gray rather than failing the call. Stage 2 converts that linear RGB to DestCS's packed representation: 0→packed RGB, 1→CMYK via classic UCR-and-black-generation math, 2→luminance-weighted gray (0.30R+0.59G+0.11B), 5→packed Lab bytes, anything else falls back to packed RGB. pdfConvColorEx is identical except it additionally passes an Intent (0=Perceptual, 1=RelativeColorimetric, 2=Saturation, 3=AbsoluteColorimetric) through to the ICC parse/transform stage — pdfConvColor always uses intent 0.
Parameters.
| Parameter | Description |
|---|---|
Color | Pointer to up to 4 source-space component doubles. |
NumComps | Number of valid components in Color (capped internally at 4). |
SourceCS | Source kind code: 0=RGB, 1=CMYK, 2=Gray, 5=Lab, 6=ICCBased (needs IColorSpace); other values treated as gray from Color[0]. |
IColorSpace | Raw ICC profile bytes, used only when SourceCS = 6; ignored otherwise. |
DestCS | Destination kind code, same numbering as SourceCS (only 0/1/2/5 recognized; else falls back to RGB). |
Intent | *(Ex only)* Rendering intent for the ICC path; pdfConvColor is hardwired to 0 (Perceptual). |
Return value. The packed destination-space color value (0 if Color is null).
Remarks. All device-space math (CMYK↔RGB, Lab↔RGB) is a fixed approximation (naive UCR/black-generation, standard Lab formulas) — not a full color-managed transform except on the SourceCS=6 ICC path.
See also. pdfInitColorManagement.
C# (P/Invoke)
public static extern uint pdfConvColor(double[] Color, uint NumComps, int SourceCS, IntPtr IColorSpace, int DestCS);
Conversion
pdfConvColor
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.