Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
CUPS Colour Calibration HOW(NOT)TO
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Ian Goldby

Joined: 18 May 2002
Posts: 539
Location: (Inactive member)

PostPosted: Mon Jan 19, 2004 8:13 pm    Post subject: CUPS Colour Calibration HOW(NOT)TO Reply with quote

Accurate Colour Printing HOW(NOT)TO

This tip describes the process of printing to an ink jet printer from KDE or the command line via CUPS and GIMP-print, and explains why adjusting colours and setting up profiles is not as obvious as you might have thought. After reading this, I hope you will have a better idea of how the various stages of the printing process fit together, and a better idea of how to get accurate colour output.

I spent several days battling with CUPS, searching for relevant documentation, generally barking up the wrong tree, and finally reading the source code to see how it really works. I've written this down so you won't have to.

(I'm not going to discus foomatic here. Although the Gentoo Printing Guide advocates installing it along with CUPS, I have found it to be entirely unnecessary.)

The Printing Process

First, open this diagram in a separate window so you can refer to it while you continue to read this. The diagram is based on the one in chapter 4 of the KDE Printing Manager help, but for clarity I've omitted printers other than Epson inkjets and the details of the physical printer connection, but added GIMP-print. (Of course, if you are using a Canon, or HP printer, etc, just mentally substitute it where you see Epson.)

The programs (or filters) pstops, texttops, pdftops, imagetops, pstoraster, and rastertoepson are all part of the CUPS package and live in /usr/lib/cups/filter/. The filter rastertoprinter is part of the GIMP-print package, but lives in the same directory as the other filters. We'll come back to these in a moment.

When you print a file with a KDE application, KDEprint, or from the command line with lp or lpr, the file is passed first to the CUPS spooler. CUPS looks to see what kind of file you have sent it, and uses a MIME type to record this. (It discovers the MIME type by looking inside the file and finding a matching pattern in /etc/cups/mime.types.) It then looks inside /etc/cups/mime.convs to see which filters it should use to get the file into CUPS' generic raster format ready to send to the printer driver for your specific printer. Each entry in this file consists of a 'from' and a 'to' MIME type, a 'cost', and the filter to use. For most paths, several filters will be involved to get the file into the final CUPS raster format. If there is more than one possible path (e.g. imagetops->pstops->pstoraster or imagetoraster) then CUPS choses the one with the lowest total cost.

(Incidently, most KDE applications produce their output in PostScript, the far left route on the diagram.)

Once the file is converted to the CUPS raster format, CUPS consults the printer PPD file to see what to do with it next. PPD files are kept in /etc/cups/ppd/, and are named after the printer they belong to. If you examine the PPD file for your printer, you'll see a line similar to
*cupsFilter:    "application/vnd.cups-raster 100 rastertoprinter"
This tells CUPS that for this destination printer, it should use the GIMP-print filter rastertoprinter to convert the raster file into the exact printer commands needed for that model of printer. (If you were using the CUPS 'ESP' built-in Epson driver, then it would specify rastertoepson instead.)

Some applications, such as the GIMP, contain their own printer drivers and output raw data (far right on the diagram). The GIMP actually uses the GIMP-print library internally, so its own conversion to printer commands is exactly the same as the rastertoprinter filter.

Colour Models

Most images that you display on your monitor have their colours specified in terms of the red, green, and blue components (RGB). An inkjet printer creates colours out of black, magenta, cyan and yellow inks (CMYK). Sometimes there are additional light cyan and light magenta inks, but I'll ignore these for now. At some point, the printing system has to convert RGB colours to CMYK. The PPD file tells CUPS what to do about this. Herein lies a significant difference between the built-in CUPS drivers and the GIMP-print drivers.

The PPD files of the built-in drivers contain a line of the form
*DefaultColorModel: CMYK
which tells CUPS to convert the RGB image to CMYK format early on, in imagetoraster or pstoraster. Then rastertoepson receives its colours in CMYK format and is responsible only for converting these to the required dither patterns in the printer's own command language.

GIMP-print takes a different approach. The GIMP-print PPD files tell CUPS to send it the raster data in RGB format, and then GIMP-print itself does the conversion to CMYK (and dither patterns), using a sophisticated heuristic method, and calibrated individually for each model of printer. This is a bit of a simplification though, as we'll see in a minute.

Colour Calibration

The current version (4.2.x) of the GIMP-print library has limited colour adjustment settings. Version 5 is promised to have full colour profiling capabilities, but that is for the future.

cups-calibrate, -o profile=... and cupsColorProfile

(This section is basically for information. If you are impatient, just read the last paragraph and go straight on to 'Calibrating the GIMP-print drivers'.)

There is a tool called cups-calibrate that is part of the GIMP-print package that can be used to create a CUPS calibration profile for a printer. A CUPS calibration profile consists of eleven numbers. The first two are the density and gamma of the calibration, and the remaining nine are a colour transformation matrix. With inkjet printers, you don't need to fill every possible dot position with ink to get a solid colour. The density setting is the minimum amount of ink to lay down to get a solid colour. Gamma is like a brightness control, but it affects the mid-tones most and doesn't change pure black or pure white at all.

cups-calibrate generates a profile that can either be stored in the /etc/cups/lpoptions file, supplied on the command line to lp/lpr, e.g.
# lp -o profile=1000,1000,1000,0,0,-100,1000,0,0,0,1000 printfile
or put in the PPD file. You'll notice that PPD files for the built-in drivers already have a line such as
*cupsColorProfile 360dpi/Plain: "1.0 1.5 1.0 0.0 -0.2 -0.4 1.0 0.0 -0.2 0.0 1.0"
which is the default colour profile for the printer at that resolution on that type of paper. Generally, the profile will be different for different resolution and paper type.

GIMP-print PPD files don't have a cupsColorProfile, and if you try to supply one on the command line with -o profile=... CUPS won't use it. That is because CUPS sends raw RGB data to GIMP-print for the latter to do its own conversion to CMYK.

(There is an anomoly though. There are two other lp/lpr options that you can use to adjust the colours - hue and saturation. These adjustments are always made regardless of the driver you are using.)

Actually, there is a way to force CUPS to apply the cupsColorProfile before it sends data to the GIMP-print drivers. If you specify the output mode as 'Raw CMYK' in the KDE print settings dialog, or -o ColorModel=CMYK on the command line, then CUPS itself will do the conversion to CMYK and apply the colour profile before sending the data to GIMP-print, and GIMP-print will process the input as raw CMYK.

If you use the GIMP-print driver, it is probably best not to bother with CUPS colour profiles and cups-calibrate. (The cups-calibrate tool is not exactly easy to use in any case and you can probably get a better calibration by trial and error.)

Calibrating the GIMP-print drivers

The GIMP-print drivers come ready-calibrated for a wide range of paper types. However, I've consistently found the output to be too dark on photo-quality paper, with colours looking 'dirty' and loss of details in the shadows.

The settings in the GIMP and in the KDE print settings dialog are essentially the same. I recommend the GIMP for doing test prints. You have (in KDE under Properties.../DriverSettings/STP, in the GIMP under Image/Output Settings/Adjust Output...):
  • Brightness
  • Contrast
  • Saturation
  • Density
  • Gamma
  • Cyan
  • Magenta
  • Yellow
Cyan, magenta, and yellow are actually gamma controls, so they have most effect in the mid-tones and don't change the colour of white or black areas at all. Gamma is an overall gamma control and affects all the inks. Density we've mentioned before. These settings don't override the driver's built-in defaults - they are combined with the defaults to give the total gamma adjustment etc.

Contrast is interesting - reducing contrast works totally differently to increasing contrast. When you reduce contrast, the whole image is compressed into a smaller range of brightness values. A contrast of 0 sets the entire image to mid-gray. When you increase contrast however, it avoids burning out highlights or losing detail in shadows by affecting the mid-tones most strongly, and the very lightest and darkest regions not at all. It's like the 'S'-shaped curves adjustment often used in the GIMP if that means anything to you. (In the approaching version 1.5 of GIMP-print, contrast reduction is to be changed to work the same way as contrast enhancement, that is, applying a 'reverse S' curve.)

I've tried adjusting these settings and printing out sample pictures until the 'look right', but I find it very hard to judge what 'looks right' is. A much better method is to get a few digital photographs with a good range of colours and dark and light areas professionally printed, and then try to produce prints on your inkjet that match the professional prints as closely as possible. These days, you can get 6x4 digital prints for as little as 10p each at your local photo processing lab. Their printers are calibrated, one hopes, to the sRGB colorspace, which is what your camera uses and should match the display on your monitor. You'll never get your inkjet prints to exactly match, because the gamut (or colour range) from inks is smaller than that from the photographic process. This is most noticable with pure reds and greens, which your inkjet will probably render somewhat paler. But you can normally get reasonably close.

Note: When you are assessing the colours of a print, you must do it in daylight. This is not a job for those long winter evenings. Colours that look well-matched under artificial lighting can look badly out in neutral daylight.

The gamma and cyan, magenta, and yellow controls are your main tools for improving brightness and colour balance. Increasing one of the cyan, magenta, or yellow settings makes that colour more pronounced, and also makes the image darker. Increasing the gamma makes the image lighter.

For example, knowing that my prints are usually too dark, I did a test print with gamma=1.5. This gave pretty good results (still slightly dark), but the shadows were rather green. To reduce green, I need either to put more magenta ink down, or less yellow+cyan (since yellow+cyan=green). So I did a second print with magenta=1.2, yellow=1.1, and gamma increased to 1.7 to compensate. (These numbers are just guestimates.) That gave a distinctly pink cast to the picture, but the shadows were still green. The green shadows are indicative of poor-quality third-party inks, and there's nothing I can do about them other than buy Epson's own inks. Next I tried gamma=1.6, magenta=1.1. Judging that the best match lay somewhere between this and my first attempt, I settled on gamma=1.6, magenta=1.05.

(Edit: I've since discovered that the optimum setting for gamma depends on the picture I am printing. 1.6 is good for photos that are mainly darker shades. But for photos with a lot of lighter shades in them 1.6 makes it look very over-exposed, and a smaller value is more appropriate. I don't think a gamma curve gives enough control to make a 'universal' calibration possible.)

To save these settings in KDE, it's best to create a new instance of your printer with these settings as defaults. Go into the KDE Printing Manager and select your printer. In the Instances tab below, create a new instance with a suitable name. Then in Settings..., go to the Driver tab, enter the settings, and save. To use this printer instance from the KDE print dialog box, just select it from the list of printers. From the command line, assuming I called the instance 720cal and the printer itself is called Stylus740, I would type
# lp -d Stylus740/720cal image.png

I've no experience of other window/desktop managers, but assuming they use CUPS for printing, you'll find similar settings. To set up printer instances from the command line, the lpoptions command is used. ('man lpoptions' for more information.)

If you are printing from the command line, the relevant option names are stpBrightness, stpGamma, stpContrast, stpCyan, stpMagenta, stpYellow, stpSaturation, and stpDensity. The numeric value must be multiplied by 1000 and rounded to the nearest integer. For example, to set the gamma to 1.5, use -o stpGamma=1500.

The Future

Version 5 of GIMP-print promises to incorporate full colour profiling. I hope that this will include the facility to generate an accurate colour profile by scanning the inkjet's output back in using a calibrated scanner. Calibrating a scanner is much easier than calibrating a printer, and can almost be done by eye. In principle, one could adopt a strategy of 'if you want this RGB colour, then these are the C, M, Y, and K values you need to send the printer', based purely on a database of what RGB colours were produced when that combination of CMYK was printed in the calibration image.

It ought to be possible to write a new filter to convert RGB data to CMYK using a fully empirical conversion process like that outlined above and place this in the chain ahead of rastertoprinter. I may look into this possibility, time permitting (it should completely solve the green shadows problem), although having said that, such an approach would probably become obsolete as soon as GIMP-print 5 is released.

Last edited by Ian Goldby on Sat Jan 24, 2004 9:13 pm; edited 3 times in total
Back to top
View user's profile Send private message

Joined: 15 Apr 2003
Posts: 1317
Location: UK

PostPosted: Mon Jan 19, 2004 9:52 pm    Post subject: Reply with quote

seems like a nice howto, maybe a little to dependant ok KDE though.
Back to top
View user's profile Send private message
Tux's lil' helper
Tux's lil' helper

Joined: 28 Jun 2003
Posts: 116
Location: Sudbury, ON Canada

PostPosted: Wed Jan 21, 2004 1:38 am    Post subject: Reply with quote

Wonderful HowTo. Thank You. I've been playing with the settings of my color inkjet for a long time and have never figured out exactly what each setting was doing. Needless to say I think this will save me some ink.

Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum