pdfCreateIndexedColorSpace
Register a new Indexed color space over a palette of
int32_t __stdcall pdfCreateIndexedColorSpace(PPDF IPDF, int32_t Base, int32_t Handle, void* ColorTable, uint32_t NumColors);
function pdfCreateIndexedColorSpace(const IPDF: PPDF; Base, Handle: Integer; ColorTable: Pointer; NumColors: Cardinal): Integer; stdcall;
Purpose. Register a new Indexed color space over a palette of NumColors base-space colors.
Description. Base must be a device ordinal 0..2 (RGB/CMYK/Gray); anything else, including a registered non-device handle, fails — an Indexed space's base cannot itself be an ICC/CIE/DeviceN/Separation space through this entry point. Computes the expected per-color component count from Base (1 for Gray, 4 for CMYK, 3 otherwise) purely to size the byte copy; ColorTable must be non-null and NumColors > 0. CreateIndexedColorSpace copies NumColors * BaseComps bytes verbatim from ColorTable into the registered entry's Table field — there is no check that the caller's buffer is actually that large; a ColorTable shorter than NumColors * BaseComps bytes causes an out-of-bounds read during the Move. The Handle parameter is accepted but never read — same dropped- parameter pattern as pdfCreateDeviceNColorSpace; a fresh handle is always auto-allocated.
Parameters.
| Parameter | Description | ||
|---|---|---|---|
IPDF | Document handle. | ||
Base | Base device space: 0=RGB, 1=CMYK, 2=Gray. Any other value (including a registered handle) fails. | ||
Handle | Accepted but ignored — a new handle is always auto-allocated. | ||
ColorTable | Palette bytes, `NumColors * (1 | 3 | 4) bytes (component count implied by Base`) — caller must size this correctly; it is not validated. |
NumColors | Palette entry count (1..256; internally becomes HiVal = NumColors - 1, which must fit 0..255). |
Return value. The new color-space handle on success; -1 if Base is invalid, ColorTable is null, NumColors is 0, or NumColors - 1 falls outside 0..255.
Remarks. Because the byte count isn't validated against the actual buffer size, callers must compute NumColors * BaseComps themselves exactly as this function does internally (Gray=1, CMYK=4, RGB=3 bytes/entry) to avoid reading past the end of ColorTable.
See also. pdfCreateICCBasedColorSpace.
C# (P/Invoke)
public static extern int pdfCreateIndexedColorSpace(IntPtr IPDF, int @Base, int Handle, IntPtr ColorTable, uint NumColors);
Object Creation
pdfCreateIndexedColorSpace
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.