Creating, Viewing, and Merging Color Separations (C++ 4.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;

  BeginWaitCursor();
  // Turn off the automatic display rectangles.
  m_Lead1.SetAutoSetRects( FALSE );

  switch(ClickCount)
  {
  case 0:
    m_Lead1.ColorSeparate(COLORSEP_CMYK);
    // Free the palette used by the original bitmap

    // Just for fun, add contrast to the K plane
    m_Lead1.SetBitmap(m_Lead1.GetColorPlanes(3));
    m_Lead1.Contrast(300); // Increase the contrast

    m_Lead1.SetColorPlanes(3, m_Lead1.GetBitmap()); // Update the K plane

    m_Lead1.ForceRepaint();
    MessageBox("Separated. Keep clicking to see separations, then merge","Merge",MB_OK);
    break;
  case 1:
    m_Lead1.SetBitmap(m_Lead1.GetColorPlanes(0)); // Cyan
    m_Lead1.ForceRepaint();
    break;
  case 2:
    m_Lead1.SetBitmap(m_Lead1.GetColorPlanes(1)); //  Magenta
    m_Lead1.ForceRepaint();
    break;
  case 3:
    m_Lead1.SetBitmap(m_Lead1.GetColorPlanes(2)); //  Yellow
    m_Lead1.ForceRepaint();
    break;
  case 4:
    m_Lead1.SetBitmap(m_Lead1.GetColorPlanes(3)); //  K
    m_Lead1.ForceRepaint();
    break;
  case 5:
    m_Lead1.ColorMerge(COLORSEP_CMYK);
    m_Lead1.ForceRepaint();
    m_Lead1.SetColorPlanes(0, 0);   // free the color planes
    m_Lead1.SetColorPlanes(1, 0);
    m_Lead1.SetColorPlanes(2, 0);
    m_Lead1.SetColorPlanes(3, 0);
    MessageBox("Merged, with more contrast in the K plane","Merge",MB_OK);
    break;
  default:
    ClickCount = -1;
    MessageBox("Cycle is finished","Merge",MB_OK);
    break;
  };

  ClickCount = ClickCount + 1;
  EndWaitCursor();
}

9. Rebuild and run the application.