CreatePdfLittleCmsColourTransform 为原始 Gray、RGB、CMYK 和 ICCBased 分量缓冲区实现 IPdfColourTransform,也可供文档颜色转换辅助函数使用
必须明确指定与进程架构匹配的库绝对路径;原生库须导出 LittleCMS 2 的 cdecl API,随附构建工具从采用 MIT 许可证的 LittleCMS 2.19 源码生成该 ABI
采用 Microsoft stdcall 构建配置的 DLL 与 Win32 提供器不兼容;不能仅凭未修饰的导出名称可靠判断调用约定
TryCreatePdfLittleCmsColourTransform 返回依赖诊断,失败时转换对象保持 nil,不修改进程搜索路径
每次调用独立拥有原生上下文、配置文件和转换对象;提供器可以共享,但调用期间采样缓冲区必须保持不变
缓冲区由紧密排列的完整像素组成,每像素含 1、3 或 4 个分量,采用 8-bit 字节或原生字节序的 16-bit 无符号字;文档辅助函数会先转换 PDF 大端图像采样,再调用本提供器
没有配置文件的 DeviceRGB 使用 sRGB,DeviceGray 使用 D50 gamma-2.2 配置文件;DeviceCMYK 和 ICCBased 必须明确提供源 ICC 配置文件,且每个配置文件的数据色彩空间须匹配其声明的分量数
目标为 DeviceGray、DeviceRGB 或 DeviceCMYK,并配有匹配的 ICC 配置文件;只有提供器默认的 Gray 和 RGB 目标允许省略目标配置文件
Default 使用相对色度意图、黑点补偿、256 MiB 采样数据预算和 16 MiB ICC 配置文件预算;配置文件上限不得超过 16 MiB
原生初始化前后及每个最多 65,536 像素的处理块之间都会检查取消请求;原生配置文件打开过程和单个转换块没有取消 Callback
转换失败会清空目标缓冲区并抛出 EPdfColourBackendError;取消操作保留 EPdfOperationCancelled
实际 LittleCMS 2.19 转换及 PDF 保存、重新打开和渲染测试已在 Delphi 和 FPC 的 Win32、Win64 目标上验证
type
EPdfColourBackendError = class(EPdfProduction);
TPdfLittleCmsOptions = record
RenderingIntent: Cardinal;
BlackPointCompensation: Boolean;
MaxSampleBytes: Integer;
MaxProfileBytes: Integer;
CancellationToken: IPdfCancellationToken;
class function Default: TPdfLittleCmsOptions; static;
end;
function CreatePdfLittleCmsColourTransform(const LibraryPath: string;
const Options: TPdfLittleCmsOptions): IPdfColourTransform;
function TryCreatePdfLittleCmsColourTransform(const LibraryPath: string;
const Options: TPdfLittleCmsOptions; out Transform: IPdfColourTransform;
out ErrorText: string): Boolean;
function CreatePdfLittleCmsGrayProfile(const LibraryPath: string;
Gamma: Double = 2.2): TBytes;
function CreatePdfLittleCmsSrgbProfile(const LibraryPath: string): TBytes;
CreatePdfLittleCmsGrayProfile 接受 0.1 到 10 的有限 gamma 值;两个配置文件辅助函数都序列化真实的原生 ICC 配置文件,供嵌入或复用
pwsh Native/ColourLittleCms/Build-LittleCms.ps1 -SourceDirectory C:/deps/lcms2.19 -OutputDirectory C:/deps/lcms-bin -Platform Win64
构建工具要求兼容的 MinGW GCC 安装和已有的 LittleCMS 2.19 源码目录,会将适用的原生许可证声明复制到输出目录,不下载或安装依赖