Creating, Viewing, and Merging Color Separations (C++ 5.0 and later)

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.

Go to the Project WorkSpace and click the ResourceView tab.

3.

Double-click Dialog and double-click IDD_TUTOR_DIALOG to bring up the application's dialog box.

4.

image\btncmd.gif Add a new button under the Cancel button. To do this, select the button control on the Controls toolbar. Then, click and drag to position the button on the dialog box.

5.

Double-click the button and change IDC_BUTTON1 to IDC_MERGE. Also, set the caption to Color Merge.

6.

Close all the windows until you reach the project window, answering yes when asked whether to save the changes.

7.

Press Ctrl-W to go to the MFC Class Wizard; then do the following:

 

a.

In the Class name combo box, select CTutorDlg.

 

b.

In the Object IDs list box, select IDC_MERGE.

 

c.

In the Messages list box, select BN_CLICKED.

 

d.

Click the Add function button. Choose OK for the default function name (OnMerge).

 

e.

Click the Edit Code button to start entering the code.

8.

Enter new code as follows:

void CTutorDlg::OnMerge() 
{
  // TODO: Add your control notification handler code here
  // Count the button clicks and take the next step with each click
  static int ClickCount;
  static ILEADRasterProcess *pRasterProc=NULL;
  if(!pRasterProc)
     CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL,
                      IID_ILEADRasterProcess, (void**)&pRasterProc);
  BeginWaitCursor();
  // Turn off the automatic display rectangles.
  m_LEADRasterView1.SetAutoSetRects( FALSE );
  switch(ClickCount)
  {
  case 0:
    pRasterProc->ColorSeparate(m_LEADRasterView1.GetRaster(), COLORSEP_CMYK);
    // Free the palette used by the original bitmap
    // Just for fun, add contrast to the K plane
    m_LEADRasterView1.GetRaster().SetBitmap(pRasterProc->GetColorPlanes(3));

    pRasterProc->Contrast(m_LEADRasterView1.GetRaster(), 300); // Increase the contrast
    pRasterProc->PutColorPlanes(3, m_LEADRasterView1.GetRaster().GetBitmap()); // Update the K plane
    m_LEADRasterView1.ForceRepaint();
    MessageBox(TEXT("Separated. Keep clicking to see separations, then merge"), TEXT("Merge"),MB_OK);
    break;
  case 1:
    m_LEADRasterView1.GetRaster().SetBitmap(pRasterProc->GetColorPlanes(0)); // Cyan
    m_LEADRasterView1.ForceRepaint();
    MessageBox(TEXT("First color plane--Cyan"));
    break;
  case 2:
    m_LEADRasterView1.GetRaster().SetBitmap(pRasterProc->GetColorPlanes(1)); //  Magenta
    m_LEADRasterView1.ForceRepaint();
    MessageBox(TEXT("Second color plane--Magenta"));
    break;
  case 3:
    m_LEADRasterView1.GetRaster().SetBitmap(pRasterProc->GetColorPlanes(2)); //  Yellow
    m_LEADRasterView1.ForceRepaint();
    MessageBox(TEXT("Third color plane--Yellow"));
    break;
  case 4:
    m_LEADRasterView1.GetRaster().SetBitmap(pRasterProc->GetColorPlanes(3)); //  K
    m_LEADRasterView1.ForceRepaint();
    MessageBox(TEXT("Fourth color plane--K"));
    break;
  case 5:
    pRasterProc->ColorMerge(m_LEADRasterView1.GetRaster(), COLORSEP_CMYK);
    m_LEADRasterView1.ForceRepaint();
    pRasterProc->PutColorPlanes(0, 0);   // free the color planes
    pRasterProc->PutColorPlanes(1, 0);
    pRasterProc->PutColorPlanes(2, 0);
    pRasterProc->PutColorPlanes(3, 0);
    MessageBox(TEXT("Merged, with more contrast in the K plane"), TEXT("Merge"),MB_OK);
    break;
  default:
    ClickCount = -1;
    MessageBox(TEXT("Cycle is finished"), TEXT("Merge"),MB_OK);
    pRasterProc->Release();
    break;
  };
  ClickCount = ClickCount + 1;
  EndWaitCursor();
}

9.

Rebuild and run the application.