Creating, Viewing, and Merging Color Separations (C++ Builder 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 Unit1.h file private declarations section.

LEADRasterProcess * pRasterProc;
//Count the button clicks and take the next step with each click
int ClickCount;

4.

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

 //Create the RasterProcess Object
CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, IID_ILEADRasterProcess, (void**)&pRasterProc);
ClickCount= 0;

5.

Code the Form’s Close event as the following:

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
 if(pRasterProc)
 pRasterProc->Release ();
}

6.

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.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString Msg;

 Cursor = crHourGlass;
//Turn off the automatic display rectangles.
LEADRasterView1->AutoSetRects = False;
LEADRasterView1->Raster->RefBitmap = False;
switch (ClickCount)
{
 case 0:
{
 pRasterProc->ColorSeparate ( LEADRasterView1->Raster, COLORSEP_CMYK ) ;
 //Just for fun, add contrast to the K plane
 LEADRasterView1->Raster->Bitmap = pRasterProc->get_ColorPlanes (3) ;//Copy the K plane
 pRasterProc->Contrast (LEADRasterView1->Raster, 300) ;//Increase the contrast
 pRasterProc->set_ColorPlanes (3, LEADRasterView1->Raster->Bitmap) ;//Update the K plane
 Msg = "Separated. Keep clicking to see separations, then merge";
 ShowMessage (Msg) ;
}
break;
 case 1:
{
 LEADRasterView1->Raster->Bitmap = pRasterProc->get_ColorPlanes(0); //Cyan
 LEADRasterView1->ForceRepaint ( );
}
break;
 case 2:
{
 LEADRasterView1->Raster->Bitmap = pRasterProc->get_ColorPlanes(1); //Magenta
 LEADRasterView1->ForceRepaint ( ) ;
}
break;
 case 3:
{
 LEADRasterView1->Raster->Bitmap = pRasterProc->get_ColorPlanes (2); //Yellow
 LEADRasterView1->ForceRepaint ( );
}
break;

 case 4:
{
 LEADRasterView1->Raster->Bitmap = pRasterProc->get_ColorPlanes(3); // K
 LEADRasterView1->ForceRepaint ( );
}
break;

 case 5:
{
 pRasterProc->ColorMerge ( LEADRasterView1->Raster, COLORSEP_CMYK ) ;
 LEADRasterView1->ForceRepaint ( );
 pRasterProc->set_ColorPlanes(0, 0);
 pRasterProc->set_ColorPlanes(1, 0);
 pRasterProc->set_ColorPlanes(2, 0);
 pRasterProc->set_ColorPlanes (3, 0);
 Msg = "Merged, with more contrast in the K plane";
 ShowMessage (Msg);
}
break;

 default:
{
ClickCount = -1;
Msg = "Cycle is finished";
ShowMessage ( Msg ) ;
}
}
ClickCount++;
Cursor= crDefault;
}

7.

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

8.

At the beginning of Unit1.h file, include this file

#include "LTRASTERPROCLib_TLB.h"

9.

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.