Creating, Viewing, and Merging Color Separations (C++ Builder)

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.

Add the following global declaration at the top of the Unit1 file:

int ClickCount; //Used with the Color Separations example

3.

image\btndbtn.gif Select the Button control; then add the control to your main form. Put the control at the top of the form to keep it away from the image.

4.

Change the Button control's Caption property to Do Separations.

5.

Code the Do Separations button's Click procedure as follows. In online help, you can copy the block of code and paste it into your application.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   Screen->Cursor = crHourGlass;
   //Turn off the automatic display rectangles.
   Lead1->AutoSetRects = False;
   //Use the ClickCount form variable to step through the actions.
   switch(ClickCount)
   {
   case 0:
      Lead1->ColorSeparate(COLORSEP_CMYK);
      //Just for fun, add contrast to the K plane
      Lead1->Bitmap = Lead1->ColorPlanes[3]; //Copy the K plane
      Lead1->Contrast(300); //Increase the contrast
      Lead1->ColorPlanes[3] = Lead1->Bitmap; //Update the K plane
      ShowMessage("Separated. Keep clicking to see separations, then merge");
      break;
   case 1:
      Lead1->Bitmap = Lead1->ColorPlanes[0]; //Cyan
      Lead1->ForceRepaint();
      break;
   case 2:
      Lead1->Bitmap = Lead1->ColorPlanes[1]; // Magenta
      Lead1->ForceRepaint();
      break;
   case 3:
      Lead1->Bitmap = Lead1->ColorPlanes[2]; // Yellow
      Lead1->ForceRepaint();
      break;
   case 4:
      Lead1->Bitmap = Lead1->ColorPlanes[3]; // K
      Lead1->ForceRepaint();
      break;
   case 5:
      Lead1->ColorMerge(COLORSEP_CMYK);
      Lead1->ForceRepaint();
      Lead1->ColorPlanes[0] = 0;
      Lead1->ColorPlanes[1] = 0;
      Lead1->ColorPlanes[2] = 0;
      Lead1->ColorPlanes[3] = 0;
      ShowMessage("Merged, with more contrast in the K plane");
      break;
   case 6:
      ClickCount = -1;
      ShowMessage("Cycle is finished");
   }

   ClickCount++;
   Screen->Cursor = crDefault;
}

6.

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.