Creating, Viewing, and Merging Color Separations (Delphi 4)

Take the following steps to add code that creates CMYK color separations, displays each of the color planes, merges the planes, and displays the result. The code increases the contrast of the K plane to demonstrate how you can manipulate the color separations.

1.

Start with the project that you created in Loading and Displaying an Image.

2.

image\btncmd.gif Add a button to your form and name it as follows:

 

Name

Caption

 

Button1

Do Separations

 

Put it at the top of the form to keep it away from the image.

3.

Add the following variables to the Main Form’s private declarations section.

RasterProc: LEADRasterProcess;
//Count the button clicks and take the next step with each click
ClickCount: Integer;

4.

Add the following code to the end of the form's Create procedure.

   //Create the RasterProcess Object
   RasterProc:= CreateComObject(CLASS_LEADRasterProcess) as LEADRasterProcess;
   ClickCount:= 0 ;

5.

Code the Buuton1 click’s procedure as the following. In online help, you can use the Edit pull-down menu to copy the block of code.

procedure TForm1.Button1Click(Sender: TObject);
var
   Msg: String;
   sRet: smallint;
begin
   Cursor := crHourGlass;
   //Turn off the automatic display rectangles.
   LEADRasterView1.AutoSetRects := False;
   LEADRasterView1.Raster.RefBitmap := False;
   Case ClickCount of
      0:
      begin
         RasterProc.ColorSeparate ( LEADRasterView1.Raster, COLORSEP_CMYK ) ;
           //Just for fun, add contrast to the K plane
           LEADRasterView1.Raster.Bitmap := RasterProc.ColorPlanes [3] ;//Copy the K plane
           RasterProc.Contrast (LEADRasterView1.Raster, 300) ;//Increase the contrast
           RasterProc.ColorPlanes[3] := LEADRasterView1.Raster.Bitmap ;//Update the K plane
           Msg := 'Separated. Keep clicking to see separations, then merge';
           ShowMessage ( Msg ) ;
      end;
      1:
      begin
         LEADRasterView1.Raster.Bitmap := RasterProc.ColorPlanes [0]; //Cyan
           LEADRasterView1.ForceRepaint ( sRet ) ;
      end;
      2:
      begin
         LEADRasterView1.Raster.Bitmap := RasterProc.ColorPlanes[1]; //Magenta
           LEADRasterView1.ForceRepaint ( sRet ) ;
      end;
      3:
      begin
         LEADRasterView1.Raster.Bitmap := RasterProc.ColorPlanes[2]; //Yellow
           LEADRasterView1.ForceRepaint (sRet);
      end;
      4:
      begin
         LEADRasterView1.Raster.Bitmap := RasterProc.ColorPlanes[3]; // K
           LEADRasterView1.ForceRepaint (sRet);
      end;
      5:
      begin
         RasterProc.ColorMerge ( LEADRasterView1.Raster, COLORSEP_CMYK ) ;
           LEADRasterView1.ForceRepaint (sRet);
           RasterProc.ColorPlanes[0] := 0;
           RasterProc.ColorPlanes[1] := 0;
           RasterProc.ColorPlanes[2] := 0;
           RasterProc.ColorPlanes [3] := 0;
           msg := 'Merged, with more contrast in the K plane';
           ShowMessage (Msg);
      end;
      else
      begin
        ClickCount := -1;
        msg := 'Cycle is finished';
        ShowMessage ( Msg ) ;
      end;
   end;
   ClickCount:= ClickCount + 1;
   Cursor:= crDefault;

end;

6.

On the Project pull-down menu, use the Import Type library… and select the LEAD Raster Process object library (14.5).

7.

At the beginning of the Unit1 file, add LTRASTERPROCLib_TLB to the uses section. For example:

Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, LTRASTERPROCLib_TLB;

8.

Run your program to test it. Notice that you can click the button several times to create the separations, view each of them, and merge them to recreate the original bitmap.