The RISC OS Printing System (part 12)

Colour separation revisited

You might have noticed I didn't manage to beat the deadline for last month's Archive. This was due to not being able to teach myself PostScript (I blame it on my age!!) in the tim available. Anyway, without claiming to be an expert in the said language, I've managed to modify PostScript printer files so that they produce a better set of colour separations which I hope wi l be of use to all of you who send these files to printing bureaux for publication.

In Part 8 (Archive 13.11 p82), I described a method of generating colour separations using my add-on application, !ColSep. While this worked well, it had one drawback: sprites containing more th n 256 colours and JPEG images couldn't be used. This limitation has haunted me ever since - then the penny dropped. I had approached the problem from the wrong direction. Colsep produced its sep rations by intercepting RISC OS Colour SWIs and Font SWIs, changing their colour values to suit the required separation. But there are simpler ways to produce colour separations using bitmap and PostScript printers.

For bitmap printers

Way back in Part 2, in the description of the structure of the RISC OS printing system, I mentioned a module called PDumperSupport. This module takes care of a set of utilities common to bi map printer drivers, one of which processes a bitmap strip for printing. SWI PDumper_Prepare-Strip receives the bitmap data in 32-bit sprite format &00BBGGRR for RISC OS 3.6+ and 24­ bit &BBGGRR for multi-pass colour in RISC OS 3.1. If we intercept this SWI, and colour separate the bit image data, all colour matching can be modified. No need to intercept the ont or colourtrans SWIs.

The modification of PDumperSupport needed a bit of thought since the strip data is built differently under RISC OS 3.1 because this operating system doesn't support sprites with more than 256 co ours. To build up a 24­bit colour image (in !Printers versions 1.53 onwards) the PDriverDP module, under RISC OS 3.1, produces three 256 greyscale sprite type image strips, one for each prim ry colour. The PDumperSupport module then produces a composite bit image strip from these. I have had to modify this code so that the composite bit image is colour separated as it is produc d from the three primary colour image strips. Looking into !Printers version 1.24, I found this method isn't used, so I have had to limit the compatibility of ColSep2 to !Printers vers ons 1.53 onwards.

For PostScript printers

This is more involved since these don't use the support module. At first sight, the PostScript output requires modification. This was the method used in Colsep. All the colour commands in the file&nb p;were found, and their data was modified to produce the required separation. This was fine for sprites with 256 or fewer colours since the PostScript printer driver breaks these up into hunks using the colour command, but all other images are stored in a different way.

What is required is a way of changing the PostScript file so that the commands (not the data) are modified to produce the colour separations. This is why I had to learn some PostSc ipt! For those of you who have never dealt with PostScript, but have a programming background, here is a very much simplified description of the PostScript Language.

The PostScript language

PostScript is an interpreted language (as is BBC Basic). No compiling is required. A PostScript program has both its data and commands together in its file. As the program is 'run' (or more correctly interpreted) data and commands are read and placed on last in first out stacks. No variables are used! Procedure, array and string structures are used.

Consider the setrgbcolor command. When this is encountered in the program, the command (known as an operand in PostScript) is placed on the operand stack. This operand then takes the last three alues off the data stack and uses them as its parameters. This is how all operands get their data. So the interpreter must have correctly read three values and placed them on the data stack before it encountered this operand or else an error will occur.

If you look into a PostScript file you will see there is a structure. Near the start there is a prolog. This is where the programmer can define procedures, etc and assign them names. These def nitions are placed on a dictionary stack so they can be looked up when required. It all looks a jumble because PostScript doesn't recognise linefeeds or carriage returns as ends of lines. The / (forw rd slash) is used to denote the start of a structure definition. For example, the prolog contains the following structures.

/BD{def }bind def
/C{255. div 3 1 roll 255. div 3 1

roll 255. div 3 1 roll setrgbcolor}BD

Here BD is the dictionary name given to a procedure structure that will execute the bind def operands. The bind def operands basically take a procedure and all its values and binds it onto the dictio ary stack. Next, C is defined as a procedure that reads and alters data then calls the setrgbcolor operand.

Now, in the main body of the PostScript file, you will find lines similar to this.

255 255 255 C

This line has a C so the above procedure will be called. The numbers will have been read and placed on the data stack. I'm not going to go into the workings of all the operands in the procedure but s ffice it to say that they turn this data into a real number with a value from 0 to 1. This is the value range setrgbcolor requires. Different from Basic isn't it?!

Back to the plot

To produce colour separations, Colsep searched through the whole PostScript file for C then changed the three numbers to produce the correct separation. It would be quicker to change the C procedure efinition in the prolog so it altered its data to produce the required separation. Using this method also means all images can be made to produce their separations by changing their procedures in the prolog.

Any limitations

Use the PoScript2 printer driver definition, since this produces better PostScript output. There is one slight limitation. The image data produced by the PostScript printer driver only uses RGB value which are coded so they can be safely transmitted over any network. It would have been better if the driver had produced CMYK data since the procedure modification would have been trivial. The ay the image operand works in PostScript is to take this data and alter its value to real numbers in the required range.

You can alter the range for each of the red, green and blue components. This will produce CMY separations, but I haven't been able to find a way to generate the Key component. This means colour PEGs (and sprite images with more than 256 colours) will only give CMY separations. However, these separations do include the K component (C+M+Y=Black). Also, each component will be printed in shades of its own colour, not shades of black, but this shouldn't be a problem on B/W PostScript printers. If any of you out there, who are expert in PostScript, can outline a method of getting the 1 o erand dictionary version of the image operand to produce proper separations from RGB data, please let me know.

Changes to Colsep

On this month's disc is the new version of !Colsep called !Colsep2. It completely replaces the original version. From the user's view its workings are similar. Before !Colsep2 is started, your comput r must have seen a version of !Printers. Set up !Printers as required before using !Colsep2, e.g. if PostScript printing to file required etc. On start-up, !Colsep2 also loads and runs !Printers. On he iconbar are your normal printer icons with the !Colsep2 icon (if you alter any !Printer settings while using !Colsep2, they won't be saved).

On clicking on the !Colsep2 icon, the required colour separation is displayed under the icon. Using any application to print will now produce the required colour separation output. For PostScript pri tout files only, you can drag a Printout file onto the !Colsep icon and the required separation will be generated. A Saveas window will open for you to direct the output to your required disc directo y. I have included a new drawfile test page containing the 'wolf' image in all the different common formats.

Colsep2 summary

  1. Use !Printers versions 1.53 onwards.
  2. Colour Separation is correct for bit image printers under RISC OS 3.1 onwards.
  3. Use a PostScript version 2 (PoScript2) printer driver for PostScript.
  4. In PostScript, the colour separation of sprites (32k colours+) and JPEGs are only in CMY with the K component included in each separation. The separation is printed in its colour not in blac (on a colour printer).

Getting PostScript info

I have managed to download a lot of PostScript info from the web. For those of you interested, point your browser to the Google search engine with the search parameter 'PostScript Language', and you will find a lot of matches. If you find any matches containing adobe.com, they are very good. For example, you can download the full PostScript Language Manual (vers on 3) in PDF format.


Source: Archive Magazine 14.4
Publication: Archive Magazine
Contributor: Brian Pickard