michael vrhel, ph.d. color scientist artifex software inc ...pdf – essentially same as psl3, but...

34
Ghostscript’s ICC-based Color Architecture Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc. San Rafael CA

Upload: others

Post on 07-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Ghostscript’s ICC-based Color Architecture

Michael Vrhel, Ph.D.Color Scientist

Artifex Software Inc.San Rafael CA

Page 2: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Outline

• Ghostscript Overview

• PDLs & Color Spaces

• Existing Ghostscript ICC Flow

• New Architecture

Page 3: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

About Ghostscript

• Ghostscript is a document conversion and rendering engine.

• Essential component of the Linux printing pipeline.

• Dual GPL/Proprietary licensed. Artifex owns the copyright.

• Source and documentation available at www.ghostscript.com

Page 4: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Ghostscript Overview

PDF 1.7 XPS PostScriptlevel 3

PCL5e/c withGL/2 and RTL PCLXL

GhostscriptGraphics Library

High level Printer drivers: Raster output API:goutput drivers:

PSwrite PDFwriteXPSwrite Custom

InkjetLaseretc.

pTIFFJPEGPNG

Page 5: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

PDLs and Color Spaces: Overview

PostScript Level 3 – DeviceGray, DeviceRGB, DeviceCMYK, Deviceindependent color spaces 1, 3,and 4 componentp p p(CIEXYZ based), Separation, N-Device, Indexed, and Pattern.

PDF – Essentially same as PSL3, but adds ICCBased as input type and losessome PS CIE based spaces Adds a LAB type Only supports 1 3 or 4some PS CIE based spaces. Adds a LAB type. Only supports 1, 3 or 4channel ICC profiles.

PCL – RGB based. Color assumed to be sRGB.

XPS, OpenXPS, SVG – All color defined by ICC profiles. XPS allows up to 8channels.

Ghostscript supports ALL.

Page 6: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Current code base and ICC Color Spaces

T d t i t/di l l t i h dl d l t lToday, most print/display color management is handled completelythrough the use of ICC profiles.

Ghostscript supports all color spaces defined by PSL3 and PDF1.7 withp pp p ythe exception of support of V4 ICC profiles. Ghostscript supports ICC.1:1998-09 (vers 3.4).

The existing architecture is inefficient in its use of ICC profiles due to theirThe existing architecture is inefficient in its use of ICC profiles due to theirlate addition into the code. (Last color space added).

Page 7: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Primary Color Flows in Ghostscript

Gray

Joint CIE CacheGrayRGBCMYKN-ChannelNamed Color

ICC Profile orPostscript/PDFCIE mapping

CIEXYZColor RenderingDictionary (CRD)Process color model

DeviceColors

DeviceColors

A Color Rendering Dictionary (CRD) is PostScript’s method for defininga mapping from CIEXYZ to a device color. It can be defined withPS procedures (functions) and/or multi-dimensional look-up-tables.

Page 8: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Current ICC Usage in Ghostscript. No Linking!

For each image pixel……

CIELABMap toCIELAB

Map toCIEXYZ

RGB ImageCIEXYZ

Scanner M LUTICC ProfilePCS is CIELAB

via MLUT via Function

MPCS is CIELAB Map todevice spaceusing CRD.Default is

RGBMap to deviceprocess colorCMYK

Default issRGB based

space

Note: If CRD is also an MLUT, we end up going through two MLUTS!

Page 9: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Desired Color Flows

Color ManagementModule(CMM)

ICC profile ICC profile

GrayRGB Linked transform

D iCMYKN-ChannelNamed Color

from source todevice color

DeviceColors

DeviceColorsCo o s

Even if it is ICC centric, Ghostscript will continue to support the non-ICC color spaces of PDF and PostScript.

Page 10: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Goals of New Ghostscript Color Architecture

• Easy to interface different CMM with Ghostscript.

• Define ALL color spaces in terms of ICC profiles.Define ALL color spaces in terms of ICC profiles.

• Cache linked transformations and internally generated profiles.

• Easily accessed manager for ICC profiles.

• Devices communicate their ICC profiles and have their ICC profile set.

• Include object type (e.g. image, graphic, text) and rendering intent into the

comp tation of the linked transformcomputation of the linked transform.

• Operate efficiently in a multithreaded environment.

• Handle named colors with ICC named color profile or proprietary format.p p p y

• Color management of Device-N colors.

• Flexibility for proofing, profile override, default settings and device link profiles.

Page 11: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

gs_get_device_profilegs_get_device_named_color_profile

gs_set_device_profile

default_gray.icc

iccprofiles

ICC ManagerDevice Profile Device

gs_set_device_named_color_profile

DeviceProfile.iccdefault_rgb.icc

Named Color Profile

DeviceN Profiles [ ]

DefaultGray Profile

DefaultRGB Profile

Proofing ProfileDevice

DeviceLinkProfile.icc

NamedColor.iccdefault_cmyk.icc

Link Cache

DefaultRGB Profile

DefaultCMYK Profile

lab iccgsicc_init_buffer

gsicc_get_linkgsicc_release_link

gsicc_set_icc_directorygsicc_set_profile

gsicc init device profile

Profile Cachelab.icc

ICC Manager and cachesare member variables of sRGB.icc

gsicc_init_device_profilegsicc_set_gscs_profilegsicc_get_gscs_profile

gsicc_profile_newgsicc_get_profile_handle_buffer

CMM

graphics library imager state.s-gray.icc

GraphicsLibrary

&Interpreter

CMMgscms_creategscms_destroygscms_get_profile_handle_memgscms_release_profilegscms_get_channel_countgscms get link

gsicc_set_icc_directorygsicc_set_profilegsicc_init_device_profile

Each thread couldhave access to a

common ICC cacheor create its own

gscms_get_linkgscms_get_link_proofgscms_release_linkgscms_transform_color_buffergscms_transform_colorgscms_get_name2device_linkgscms_transform_named_color

User profile directory

Page 12: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Typical Graphics Library Usage

• Graphics library will request link from link cache.

• Once link obtained, graphics library will apply link to buffers.Typical buffer may be a single scan line.

• When done graphics library will notify cache• When done, graphics library will notify cache.

• Ideal buffer transform case occurs in transparency codewhen transforming from blending color space during transparencygroup pop.

Page 13: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Link Cache

gsicc get link(* pis, *input colorspace, *output colorspace, *rendering params,

GRAPHICS LIBRARY

Link Cache

Hash Code Ref Count Link Structure

gsicc_get_link( pis, input_colorspace, output_colorspace, rendering_params,*memory, include_softproof)

Hash Code Ref Count Link Structure

.

.

.

Compute hash ofinput CS, output CS,rendering params

Hash CodeHash CodeHash Code

Ref CountRef Count Link Structure

Link StructureLink Structure

.

Search cache formatch. If found

t li k If t

Ref CountHash Code Link Structure

Link entries are reference counted.

return link. If notrequest new link

Links are only released if we are at maximum number (or memory),new request is made and a Ref Count is one.

Page 14: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Named Colors

A look-up-table.

There is an ICCprofile format for named colors

Required Optional

Device Value

Device ValueCIELAB

CIELAB

Pantone Uncoated Yellow

Toyo Rednamed colors.

In many applications,a custom formati d

.

.

.

Device ValueCIELABPantone Coated Green

is used.

For some companies this is their value

Device ValueCIELABToyo Coated Blue

Missing from ICC profile is ability to useti t i f ti W id t it added. tint information. We provide opportunityfor CMM to use. If it cannot, then alternatetint transform is used.

int gscms_transform_named_color(gsicc_link_t *icclink, float tint_value,

const char *ColorName,gx_color_value device_values[]);

Page 15: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Conversion of PS and PDF Color Spaces

• PS and PDF CIE color spaces are converted to ICC formsthat the CMM can handle.

• PS mappings are all 1-way. Device to CIEXYZ or CIEXYZ to Device.

• Procedural mappings are sampled.

• Because of the multiple matrix operations and procedural mappings, some PS color spaces that do not include MLUTs will give rise to ICC profiles that do include MLUTsICC profiles that do include MLUTs.

Page 16: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Example PS CIEABC

3x3Matri

3x3Matri

XA 1f

f

1g

Matrix Matrix Y

Z

B

C

2f

3f

2g

3g

Page 17: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Profile Cache

• Ghostscript creates ICC profiles from PDF and PS CIE colorspace definitions(e.g. CalRGB, CIEABC, CIEDEFG)

• To avoid repeated creations, these profiles are cached based upon a hashcode that is related to the resource ID.

• Cache is designed such that MRU item is at the top of the list.

• Profiles are only released if we are at maximum number (or memory),new request is made and a reference count is onenew request is made and a reference count is one.

Page 18: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Device N color spaces (PDF and PS)

For Device N output, very simple to provide capability for N -colorICC profile.

Many desire to have CM with CMYK and to pass additional spotcolors unmolestedcolors unmolested.

For DeviceN input color, XPS requires ICC profile. PDF and PS use analternate tint transform.

New architecture provides capability to define N-color ICC profile for DeviceNinput colors to replace the alternate tint transform if desired.

Page 19: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Ghostscript’s Command List

• Ghostscript normally renders in immediate mode.G os sc p o a y e de s ed a e ode

• Can also generate a command list for asynchronous processing.

Subdividing a job into bands reduces peak memory usage• Subdividing a job into bands reduces peak memory usage.

• Threads can process bands simultaneously.

Page 20: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Ghostscript Multithreaded

Thread 1

Thread 2

Command List

Thread 4

Thread 3

Page 21: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Command List and ICC Profiles

• Due to table look-ups and interpolations color conversion is expensive.

• Would like to distribute the load in threaded rendering.

• ICC profiles are embedded in the command list.

Page 22: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Multi-Threaded Environment

• During command list read phase, each thread obtains the same initialimaging state that incl des a pointer to the primar link cacheimaging state that includes a pointer to the primary link cache.

• In a single page, it is very likely that similar links will be needed.

• This suggests sharing a common cache amongst the threads.

• Links are reference counted to ensure only unreferenced ones are removed.

• Necessary to have a lock and release feature on the cache.

Page 23: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

CMM API

Get Profile Operations

gcmmhprofile_t gscms_get_profile_handle_mem(unsigned char *buffer, unsigned int input_size);

Ge o e Ope a o s

gcmmhprofile_t gscms_get_profile_handle_file(const char *filename);

Page 24: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

CMM API

Get Link Operations

gcmmhlink_t gscms_get_link(gcmmhprofile_t lcms_srchandle, gcmmhprofile_t lcms_deshandle, gsicc rendering param t *rendering params);gsicc_rendering_param_t rendering_params);

gcmmhlink_t gscms_get_link_proof(gcmmhprofile_t lcms_srchandle, gcmmhprofile_t lcms_deshandle, gcmmhprofile t lcms proofhandle,gcmmhprofile_t lcms_proofhandle,

gsicc_rendering_param_t *rendering_params);

gcmmhlink_t gscms_get_name2device_link(gcmmhprofile_t lcms_srchandle, gcmmhprofile t lcms deshandle,gcmmhprofile_t lcms_deshandle, gcmmhprofile_t lcms_proofhandle,

gsicc_rendering_param_t *rendering_params)

Page 25: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

CMM API

i t t f l ( i li k t *i li k id *i t l

Transform Color Operations

int gscms_transform_color(gsicc_link_t *icclink, void *inputcolor,void *outputcolor, int wordwidth);

id t f l b ff ( i li k t *i li kvoid gscms_transform_color_buffer(gsicc_link_t *icclink,gsicc_bufferdesc_t *input_buff_desc,gsicc_bufferdesc_t *output_buff_desc, void *inputbuffer, void *outputbuffer);

int gscms_transform_named_color(gsicc_link_t *icclink, float tint_value, const char* ColorName,

l l d i l [])gx_color_value device_values[]);

Page 26: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

CMM API

Information Operations

int gscms_get_channel_count(gcmmhprofile_t profile);

gsicc_colorbuffer_t gscms_get_profile_data_space(gcmmhprofile_t profile);

int gscms_get_pcs_channel_count(gcmmhprofile_t profile);

char* gscms_get_clrtname(gcmmhprofile_t profile, int colorcount);

int gscms_get_numberclrtnames(gcmmhprofile_t profile);

Page 27: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

CMM API

Overhead and Cleanup OperationsO e ead a d C ea up Ope a o s

void gscms_create(void **contextptr);void gscms_destroy(void **contextptr);oid gscms release link(gsicc link t *icclink)void gscms_release_link(gsicc_link_t *icclink);void gscms_release_profile(gcmmhprofile_t *profile);

Page 28: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Command Line Interface

Source Default Profiles-sDefaultGrayProfile = my_gray_profile.icc-sDefaultRGBProfile = my_rgb_profile.icc-sDefaultCMYKProfile = my_cmyk_profile.icc-sDeviceNProfile = my_devicen.icc

Device ProfileDevice Profile-sOutputICCProfile = my_device_profile.icc

ICC Search Directory-sICCProfilesDir = c:/my_iccprofiles/

Other Settings-sProofProfile = my proof profile.iccsProofProfile my_proof_profile.icc-sNamedProfile = my_namedcolor_profile.icc-sDeviceLinkProfile = my_link_profile.icc

Page 29: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Performance

Image with ICC source profile RGB MLUT

Renders twice as fast with new architecture

Page 30: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Performance

CIELAB Image

Renders three times as fast with new architecture

Page 31: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Performance

Rendering intent test with trunk

Page 32: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Performance

Rendering intent test with new architecture

Page 33: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Performance

CIELABCIELAB

MLUT TrunkICC Branch

Intent

0 1 2 3 4 Seconds

Page 34: Michael Vrhel, Ph.D. Color Scientist Artifex Software Inc ...PDF – Essentially same as PSL3, but adds ICCBased as input type and loses some PS CIE based spaces Adds a LAB type Only

Current Status

• ICC branch in SVN. http://svn ghostscript com/ghostscript/branches/icc workhttp://svn.ghostscript.com/ghostscript/branches/icc_work

• Currently interfacing to littleCMS http://www.littlecms.com/ Marti Maria.

M i h k f A l• Merge soon with trunk for August release.

• Reviewing regression differences.